From f1311e6d488de9f807947c04db83d57c04d65302 Mon Sep 17 00:00:00 2001 From: Adekunle Adedotun Date: Wed, 13 Apr 2022 13:08:52 -0400 Subject: [PATCH 01/49] Add Cloudformation template for Event base autorefresh --- src/EventBasedAutoRefresh/autorefresh.py | 146 +++++++ .../cloudformation/autorefresh.yaml | 396 ++++++++++++++++++ 2 files changed, 542 insertions(+) create mode 100644 src/EventBasedAutoRefresh/autorefresh.py create mode 100644 src/EventBasedAutoRefresh/cloudformation/autorefresh.yaml diff --git a/src/EventBasedAutoRefresh/autorefresh.py b/src/EventBasedAutoRefresh/autorefresh.py new file mode 100644 index 00000000..7b95aac4 --- /dev/null +++ b/src/EventBasedAutoRefresh/autorefresh.py @@ -0,0 +1,146 @@ +import json +import logging +import boto3 +import os +import time + + +logger = logging.getLogger() +logger.setLevel(logging.INFO) +rsapi = boto3.client('redshift-data') +kfhose = boto3.client('firehose') +snsclient = boto3.client('sns') +dynamodb = boto3.resource('dynamodb') +tablename = os.environ['DDBTABLE'] +ddbtable = dynamodb.Table(tablename) +snstopic = os.getenv('SNSTOPIC',None) +maxfailures = 5 + + +def check_refresh_status(ddbitem): + checksql = f"select query from stv_recents where status <> 'Done' and db_name = '{ddbitem['database_name']}' and user_name='IAM:{ddbitem['username']}' and query = '{ddbitem['sql']}'" + logger.debug(checksql) + response = rsapi.execute_statement(ClusterIdentifier=ddbitem['clusterid'], Database=ddbitem['database_name'], DbUser=ddbitem['username'], + Sql=checksql, StatementName=f"Check {ddbitem['mvname']} refresh status") + logger.info(json.dumps(response, default=str)) + queryid = response['Id'] + status = None + while status not in ['FAILED','FINISHED']: + status = rsapi.describe_statement(Id=queryid)['Status'] + logger.debug(status) + time.sleep(5) + numrows = rsapi.get_statement_result(Id=queryid)['TotalNumRows'] + logger.info(f"Check status query: {queryid} \nNumrows: {numrows} \n{json.dumps(response, default=str)}") + return(numrows) + + +def execute_statement(ddbitem): + if ddbitem: + if ddbitem['autorefresh']: + response = rsapi.execute_statement(ClusterIdentifier=ddbitem['clusterid'], Database=ddbitem['database_name'], DbUser=ddbitem['username'], + Sql=ddbitem['sql'], StatementName=ddbitem['mvname'], WithEvent=True) + logger.info(f"Redshift api response: {json.dumps(response, default=str)}") + logger.info(f"Sent query to {ddbitem['clusterid']} to refresh {ddbitem['mvname']} in database {ddbitem['database_name']}") + else: + msg = f"Auto Refresh is disabled on MV {ddbitem['mvname']} in database {ddbitem['database_name']} for cluster {ddbitem['clusterid']}" + logger.info(f"{msg} Skipping...") + if snstopic: + snsclient.publish(TopicArn=snstopic, + Message=msg, Subject=f"{ddbitem['mvname']} MV Refresh on {ddbitem['clusterid']}") + else: + logger.info("Item not found!") + + +def trigger_first_refresh(record): + try: + eventName = record['eventName'] + logger.info(f"Event type is {eventName}...") + if eventName != 'REMOVE': + if eventName == 'MODIFY': + oldimage = record['dynamodb']['OldImage'] + prevautorefresh = oldimage['autorefresh']['BOOL'] + else: + prevautorefresh = None + newimage = record['dynamodb']['NewImage'] + ddbitem = {'failure_cnt': newimage['failure_cnt']['N'], 'clusterid': newimage['clusterid']['S'] + , 'database_name': newimage['database_name']['S'], 'autorefresh': newimage['autorefresh']['BOOL'] + , 'username': newimage['username']['S'], 'mvname': newimage['mvname']['S'] + , 'sql': newimage['sql']['S'] } + logger.info(f"Extracted {ddbitem['mvname']} attributes from dynamodb event: {ddbitem}") + if (ddbitem['autorefresh'] and not prevautorefresh) or eventName == 'INSERT': + msg = f"Starting Auto Refresh on MV {ddbitem['mvname']} in database {ddbitem['database_name']} for cluster {ddbitem['clusterid']}" + logger.info(msg) + if snstopic: + snsclient.publish(TopicArn=snstopic, Message=msg, Subject=f"{ddbitem['mvname']} MV Refresh on {ddbitem['clusterid']}") + execute_statement(ddbitem) + elif ddbitem['autorefresh'] is False: + execute_statement(ddbitem) + except KeyError as e: + logger.error(f"Key Error: {e} is missing in dynamodb response") + except Exception as e: + logger.exception(e) + + +def trigger_next_refresh(record): + msgbody = json.loads(record['body']) + caller_function = msgbody['detail']['principal'].split('/')[-1] + logger.info(json.dumps(msgbody, default=str)) + mvname = msgbody['detail']['statementName'] + clusterid = msgbody['resources'][0].split(':')[-1] + logger.info(f"MV: {mvname} Clusterid: {clusterid}") + ddbresponse = ddbtable.get_item(Key={'mvname': mvname, 'clusterid': clusterid}, ConsistentRead=True) + logger.debug(f"Get item DDB response: {json.dumps(ddbresponse, default=str)}") + ddbitem = ddbresponse['Item'] + msgsubject = f"{mvname} MV Refresh on {clusterid}" + # Check and ensure that message received was generated by this Lambda function + if caller_function == record['function_name'] and ddbitem: + dbname = ddbitem['database_name'] + numrows = check_refresh_status(ddbitem) + if numrows == 0: + dbname = ddbitem['database_name'] + failure_cnt = int(ddbitem['failure_cnt']) + if msgbody['detail']['state'] == 'FINISHED': + execute_statement(ddbitem) + if failure_cnt > 0: + logger.info(f"Refresh succeeded. Resetting failure_cnt for MV {mvname} in cluster {clusterid} to 0.") + dynamodb.Table(tablename).update_item(Key={'mvname': mvname, 'clusterid': clusterid}, UpdateExpression="set failure_cnt = :val" + ,ExpressionAttributeValues={':val': 0}, ReturnValues="UPDATED_NEW") + else: + failure_cnt += 1 + msg = f"Auto Refresh on MV {mvname} in database {dbname} for cluster {clusterid} failed {failure_cnt} times. " + if failure_cnt < maxfailures: + dynamodb.Table(tablename).update_item(Key={'mvname': mvname, 'clusterid': clusterid}, UpdateExpression="set failure_cnt = :val" + ,ExpressionAttributeValues={':val': failure_cnt}, ReturnValues="UPDATED_NEW") + errormsg = f"{msg}. Retrying refresh...\n {msgbody}" + logger.info(errormsg) + execute_statement(ddbitem) + if snstopic: + snsclient.publish(TopicArn=snstopic, Message=errormsg, Subject=msgsubject) + else: + dynamodb.Table(tablename).update_item(Key={'mvname': mvname, 'clusterid': clusterid}, UpdateExpression="set autorefresh = :val, failure_cnt = :cnt" + ,ExpressionAttributeValues={':val': False, ':cnt': failure_cnt}, ReturnValues="UPDATED_NEW") + errormsg = msg + f"Autorefresh disabled. Check the materialized view on your Redshift cluster.\n {msgbody}" + logger.info(errormsg) + if snstopic: + snsclient.publish(TopicArn=snstopic, Message=errormsg, Subject=msgsubject) + else: + msg = f"There is at least one refresh already running on MV {mvname} in database {dbname} on cluster {clusterid}. Refresh count: {numrows}" + logger.info(msg) + if snstopic: + snsclient.publish(TopicArn=snstopic, Message=msg, Subject=msgsubject) + + +def lambda_handler(event, context): + logger.debug(json.dumps(event, default=str)) + for record in event['Records']: + logger.info(json.dumps(record, default=str)) + eventsource = record['eventSource'] + if eventsource == 'aws:dynamodb': + logger.info('Eventsource is dynamodb...') + trigger_first_refresh(record) + elif eventsource == 'aws:sqs': + logger.info('Eventsource is sqs...') + record['function_name'] = context.function_name + trigger_next_refresh(record) + else: + logger.info(f"No handling for events from {eventsource}!") diff --git a/src/EventBasedAutoRefresh/cloudformation/autorefresh.yaml b/src/EventBasedAutoRefresh/cloudformation/autorefresh.yaml new file mode 100644 index 00000000..167411e2 --- /dev/null +++ b/src/EventBasedAutoRefresh/cloudformation/autorefresh.yaml @@ -0,0 +1,396 @@ +Parameters: + LambdaLogRetention: + Type: Number + Default: 90 + MinValue: 1 + MaxValue: 3653 + Description: Number of days to retain logs from the Lambda function. Default is 90 days. + LambdaExecutionTimeout: + Type: Number + Default: 300 + MinValue: 15 + MaxValue: 900 + Description: Number of seconds before Lambda function times out. Default is 300 seconds. Range is 15 to 900 seconds. + RefreshDelaySecs: + Type: Number + Default: 5 + MinValue: 2 + MaxValue: 900 + Description: Number of seconds to delay after finishing a refresh before triggering a new refresh. Default is 5 seconds. Range is 2 to 900 seconds. + ClusterDBUser: + Type: String + Default: "stream_mv_user" + Description: Username to use for connecting to Redshift cluster. Default is stream_mv_user. You can set to * if you want to connect as any database user. + LambdaBatchSize: + Type: Number + Default: 5 + MinValue: 1 + MaxValue: 30 + Description: Number of items for Lambda function to batch from SQS before processing. Default is 5. Range is 1 to 30. + +Resources: + MVRefreshLambdaLogGroup: + Type: AWS::Logs::LogGroup + Properties: + LogGroupName: + Fn::Sub: + - "/aws/lambda/${lambdafunctionname}" + - lambdafunctionname: + Ref: MVRefreshLambda + RetentionInDays: + Ref: LambdaLogRetention + DependsOn: MVRefreshLambda + + MVRefreshSQSQueue: + Type: AWS::SQS::Queue + Properties: + DelaySeconds: + Ref: RefreshDelaySecs + VisibilityTimeout: + Ref: LambdaExecutionTimeout + + MVRefreshSQSPolicy: + Type: AWS::SQS::QueuePolicy + Properties: + PolicyDocument: + Statement: + - Action: + - "SQS:SendMessage" + Effect: "Allow" + Resource: + - Fn::GetAtt: + - MVRefreshSQSQueue + - Arn + Principal: + Service: "events.amazonaws.com" + Queues: + - Ref: MVRefreshSQSQueue + + + MVRefreshEventRule: + Type: AWS::Events::Rule + Properties: + EventPattern: + source: + - "aws.redshift-data" + detail-type: + - "Redshift Data Statement Status Change" + State: ENABLED + Targets: + - + Arn: + Fn::GetAtt: + - MVRefreshSQSQueue + - Arn + Id: MVRefreshLambdaTarget + + MVRefreshSNS: + Type: AWS::SNS::Topic + Properties: + DisplayName: MVRefreshSNS-notifications + + MVRefreshDDBTable: + # mvname autorefresh clusterid database_name sql username + Type: AWS::DynamoDB::Table + Properties: + AttributeDefinitions: + - + AttributeName: "mvname" + AttributeType: "S" + - + AttributeName: "clusterid" + AttributeType: "S" + BillingMode: PAY_PER_REQUEST + KeySchema: + - + AttributeName: "mvname" + KeyType: HASH + - + AttributeName: "clusterid" + KeyType: RANGE + StreamSpecification: + StreamViewType: NEW_AND_OLD_IMAGES + + MVRefreshLambdaRole: + Type: AWS::IAM::Role + Properties: + AssumeRolePolicyDocument: + Statement: + - Action: sts:AssumeRole + Effect: Allow + Principal: + Service: "lambda.amazonaws.com" + Version: "2012-10-17" + + MVRefreshLambdaPolicy: + Type: AWS::IAM::Policy + Properties: + PolicyDocument: + Statement: + - Action: + - redshift:GetClusterCredentials + Effect: Allow + Resource: + - Fn::Sub: "arn:aws:redshift:${AWS::Region}:${AWS::AccountId}:dbuser:*/${ClusterDBUser}" + - Fn::Sub: "arn:aws:redshift:${AWS::Region}:${AWS::AccountId}:dbname:*" + - Action: + - redshift-data:ExecuteStatement + - redshift-data:DescribeStatement + - redshift-data:GetStatementResult + Effect: Allow + Resource: "*" + - Action: + - dynamodb:GetItem + - dynamodb:UpdateItem + Effect: Allow + Resource: + - Fn::GetAtt: + - MVRefreshDDBTable + - Arn + - Action: + - sqs:DeleteMessage + - sqs:ReceiveMessage + - sqs:GetQueueAttributes + Effect: Allow + Resource: + - Fn::GetAtt: + - MVRefreshSQSQueue + - Arn + - Action: + - sns:Publish + Effect: Allow + Resource: + - Ref: MVRefreshSNS + - Action: + - logs:CreateLogStream + - logs:PutLogEvents + Effect: Allow + Resource: + - Fn::GetAtt: + - MVRefreshLambdaLogGroup + - Arn + - Action: + - firehose:* + Effect: Allow + Resource: + - "arn:aws:firehose:us-east-1:757848091413:deliverystream/data_api" + - "arn:aws:firehose:us-east-1:757848091413:deliverystream/sqslogs" + - Action: + - dynamodb:ListStreams + Effect: Allow + Resource: + - Fn::GetAtt: + - MVRefreshDDBTable + - StreamArn + - Action: + - dynamodb:GetRecords + - dynamodb:GetShardIterator + - dynamodb:DescribeStream + Effect: Allow + Resource: + - Fn::GetAtt: + - MVRefreshDDBTable + - StreamArn + Version: "2012-10-17" + PolicyName: MVRefreshLambdaRolePolicy + Roles: + - Ref: MVRefreshLambdaRole + + MVLambdaSQSTrigger: + Type: AWS::Lambda::EventSourceMapping + Properties: + BatchSize: + Ref: LambdaBatchSize + Enabled: True + EventSourceArn: + Fn::GetAtt: + - MVRefreshSQSQueue + - Arn + FunctionName: + Fn::GetAtt: + - MVRefreshLambda + - Arn + DependsOn: MVRefreshLambdaPolicy + + MVLambdaDynamodbStreamsTrigger: + Type: AWS::Lambda::EventSourceMapping + Properties: + BatchSize: + Ref: LambdaBatchSize + Enabled: True + EventSourceArn: + Fn::GetAtt: + - MVRefreshDDBTable + - StreamArn + FunctionName: + Fn::GetAtt: + - MVRefreshLambda + - Arn + StartingPosition: LATEST + DependsOn: MVRefreshLambdaPolicy + + MVRefreshLambda: + Type: AWS::Lambda::Function + Properties: + Code: + ZipFile: | + import json + import logging + import boto3 + import os + import time + + + logger = logging.getLogger() + logger.setLevel(logging.INFO) + rsapi = boto3.client('redshift-data') + kfhose = boto3.client('firehose') + snsclient = boto3.client('sns') + dynamodb = boto3.resource('dynamodb') + tablename = os.environ['DDBTABLE'] + ddbtable = dynamodb.Table(tablename) + snstopic = os.getenv('SNSTOPIC',None) + maxfailures = 5 + + + def check_refresh_status(ddbitem): + checksql = f"select query from stv_recents where status <> 'Done' and db_name = '{ddbitem['database_name']}' and user_name='IAM:{ddbitem['username']}' and query = '{ddbitem['sql']}'" + logger.debug(checksql) + response = rsapi.execute_statement(ClusterIdentifier=ddbitem['clusterid'], Database=ddbitem['database_name'], DbUser=ddbitem['username'], + Sql=checksql, StatementName=f"Check {ddbitem['mvname']} refresh status") + logger.info(json.dumps(response, default=str)) + queryid = response['Id'] + status = None + while status not in ['FAILED','FINISHED']: + status = rsapi.describe_statement(Id=queryid)['Status'] + logger.debug(status) + time.sleep(5) + numrows = rsapi.get_statement_result(Id=queryid)['TotalNumRows'] + logger.info(f"Check status query: {queryid} \nNumrows: {numrows} \n{json.dumps(response, default=str)}") + return(numrows) + + + def execute_statement(ddbitem): + if ddbitem: + if ddbitem['autorefresh']: + response = rsapi.execute_statement(ClusterIdentifier=ddbitem['clusterid'], Database=ddbitem['database_name'], DbUser=ddbitem['username'], + Sql=ddbitem['sql'], StatementName=ddbitem['mvname'], WithEvent=True) + logger.info(f"Redshift api response: {json.dumps(response, default=str)}") + logger.info(f"Sent query to {ddbitem['clusterid']} to refresh {ddbitem['mvname']} in database {ddbitem['database_name']}") + else: + msg = f"Auto Refresh is disabled on MV {ddbitem['mvname']} in database {ddbitem['database_name']} for cluster {ddbitem['clusterid']}" + logger.info(f"{msg} Skipping...") + if snstopic: + snsclient.publish(TopicArn=snstopic, + Message=msg, Subject=f"{ddbitem['mvname']} MV Refresh on {ddbitem['clusterid']}") + else: + logger.info("Item not found!") + + + def trigger_first_refresh(record): + try: + eventName = record['eventName'] + logger.info(f"Event type is {eventName}...") + if eventName != 'REMOVE': + if eventName == 'MODIFY': + oldimage = record['dynamodb']['OldImage'] + prevautorefresh = oldimage['autorefresh']['BOOL'] + else: + prevautorefresh = None + newimage = record['dynamodb']['NewImage'] + ddbitem = {'failure_cnt': newimage['failure_cnt']['N'], 'clusterid': newimage['clusterid']['S'] + , 'database_name': newimage['database_name']['S'], 'autorefresh': newimage['autorefresh']['BOOL'] + , 'username': newimage['username']['S'], 'mvname': newimage['mvname']['S'] + , 'sql': newimage['sql']['S'] } + logger.info(f"Extracted {ddbitem['mvname']} attributes from dynamodb event: {ddbitem}") + if (ddbitem['autorefresh'] and not prevautorefresh) or eventName == 'INSERT': + msg = f"Starting Auto Refresh on MV {ddbitem['mvname']} in database {ddbitem['database_name']} for cluster {ddbitem['clusterid']}" + logger.info(msg) + if snstopic: + snsclient.publish(TopicArn=snstopic, Message=msg, Subject=f"{ddbitem['mvname']} MV Refresh on {ddbitem['clusterid']}") + execute_statement(ddbitem) + elif ddbitem['autorefresh'] is False: + execute_statement(ddbitem) + except KeyError as e: + logger.error(f"Key Error: {e} is missing in dynamodb response") + except Exception as e: + logger.exception(e) + + + def trigger_next_refresh(record): + msgbody = json.loads(record['body']) + caller_function = msgbody['detail']['principal'].split('/')[-1] + logger.info(json.dumps(msgbody, default=str)) + mvname = msgbody['detail']['statementName'] + clusterid = msgbody['resources'][0].split(':')[-1] + logger.info(f"MV: {mvname} Clusterid: {clusterid}") + ddbresponse = ddbtable.get_item(Key={'mvname': mvname, 'clusterid': clusterid}, ConsistentRead=True) + logger.debug(f"Get item DDB response: {json.dumps(ddbresponse, default=str)}") + ddbitem = ddbresponse['Item'] + msgsubject = f"{mvname} MV Refresh on {clusterid}" + # Check and ensure that message received was generated by this Lambda function + if caller_function == record['function_name'] and ddbitem: + dbname = ddbitem['database_name'] + numrows = check_refresh_status(ddbitem) + if numrows == 0: + dbname = ddbitem['database_name'] + failure_cnt = int(ddbitem['failure_cnt']) + if msgbody['detail']['state'] == 'FINISHED': + execute_statement(ddbitem) + if failure_cnt > 0: + logger.info(f"Refresh succeeded. Resetting failure_cnt for MV {mvname} in cluster {clusterid} to 0.") + dynamodb.Table(tablename).update_item(Key={'mvname': mvname, 'clusterid': clusterid}, UpdateExpression="set failure_cnt = :val" + ,ExpressionAttributeValues={':val': 0}, ReturnValues="UPDATED_NEW") + else: + failure_cnt += 1 + msg = f"Auto Refresh on MV {mvname} in database {dbname} for cluster {clusterid} failed {failure_cnt} times. " + if failure_cnt < maxfailures: + dynamodb.Table(tablename).update_item(Key={'mvname': mvname, 'clusterid': clusterid}, UpdateExpression="set failure_cnt = :val" + ,ExpressionAttributeValues={':val': failure_cnt}, ReturnValues="UPDATED_NEW") + errormsg = f"{msg}. Retrying refresh...\n {msgbody}" + logger.info(errormsg) + execute_statement(ddbitem) + if snstopic: + snsclient.publish(TopicArn=snstopic, Message=errormsg, Subject=msgsubject) + else: + dynamodb.Table(tablename).update_item(Key={'mvname': mvname, 'clusterid': clusterid}, UpdateExpression="set autorefresh = :val, failure_cnt = :cnt" + ,ExpressionAttributeValues={':val': False, ':cnt': failure_cnt}, ReturnValues="UPDATED_NEW") + errormsg = msg + f"Autorefresh disabled. Check the materialized view on your Redshift cluster.\n {msgbody}" + logger.info(errormsg) + if snstopic: + snsclient.publish(TopicArn=snstopic, Message=errormsg, Subject=msgsubject) + else: + msg = f"There is at least one refresh already running on MV {mvname} in database {dbname} on cluster {clusterid}. Refresh count: {numrows}" + logger.info(msg) + if snstopic: + snsclient.publish(TopicArn=snstopic, Message=msg, Subject=msgsubject) + + + def lambda_handler(event, context): + logger.debug(json.dumps(event, default=str)) + for record in event['Records']: + logger.info(json.dumps(record, default=str)) + eventsource = record['eventSource'] + if eventsource == 'aws:dynamodb': + logger.info('Eventsource is dynamodb...') + trigger_first_refresh(record) + elif eventsource == 'aws:sqs': + logger.info('Eventsource is sqs...') + record['function_name'] = context.function_name + trigger_next_refresh(record) + else: + logger.info(f"No handling for events from {eventsource}!") + Environment: + Variables: + DDBTABLE: + Ref: MVRefreshDDBTable + SNSTOPIC: + Ref: MVRefreshSNS + Handler: index.lambda_handler + Role: + Fn::GetAtt: + - MVRefreshLambdaRole + - Arn + Runtime: "python3.9" + Timeout: + Ref: LambdaExecutionTimeout From 3ae4fd838a761dcfbf96812de3d186650cfb0e68 Mon Sep 17 00:00:00 2001 From: Yota Hamaoka Date: Thu, 23 Jun 2022 18:44:11 +0900 Subject: [PATCH 02/49] fix: added count(*) --- .../Cloud-DWB-Derived-from-TPCH/10GB/ddl.sql | 9 +++++++++ .../Cloud-DWB-Derived-from-TPCH/30TB/ddl.sql | 9 +++++++++ .../Cloud-DWB-Derived-from-TPCH/3TB/ddl.sql | 9 +++++++++ 3 files changed, 27 insertions(+) diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/10GB/ddl.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/10GB/ddl.sql index a568703d..6dd5152c 100644 --- a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/10GB/ddl.sql +++ b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/10GB/ddl.sql @@ -118,3 +118,12 @@ copy part from 's3://redshift-downloads/TPC-H/2.18/10GB/part.tbl' iam_role defau copy supplier from 's3://redshift-downloads/TPC-H/2.18/10GB/supplier.tbl' iam_role default delimiter '|'; copy partsupp from 's3://redshift-downloads/TPC-H/2.18/10GB/partsupp.tbl' iam_role default delimiter '|'; copy customer from 's3://redshift-downloads/TPC-H/2.18/10GB/customer.tbl' iam_role default delimiter '|'; + +select count(*) from customer; -- 1500000 +select count(*) from lineitem; -- 59986052 +select count(*) from nation; -- 25 +select count(*) from orders; -- 15000000 +select count(*) from part; -- 2000000 +select count(*) from partsupp; -- 8000000 +select count(*) from region; -- 5 +select count(*) from supplier; -- 100000 diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/30TB/ddl.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/30TB/ddl.sql index 03a9af87..e0599468 100644 --- a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/30TB/ddl.sql +++ b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/30TB/ddl.sql @@ -118,3 +118,12 @@ copy part from 's3://redshift-downloads/TPC-H/2.18/30TB/part/' iam_role default copy supplier from 's3://redshift-downloads/TPC-H/2.18/30TB/supplier/' iam_role default gzip delimiter '|'; copy partsupp from 's3://redshift-downloads/TPC-H/2.18/30TB/partsupp/' iam_role default gzip delimiter '|'; copy customer from 's3://redshift-downloads/TPC-H/2.18/30TB/customer/' iam_role default gzip delimiter '|'; + +select count(*) from customer; -- 4500000000 +select count(*) from lineitem; -- 179999978268 +select count(*) from nation; -- 25 +select count(*) from orders; -- 45000000000 +select count(*) from part; -- 6000000000 +select count(*) from partsupp; -- 24000000000 +select count(*) from region; -- 5 +select count(*) from supplier; -- 300000000 diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/3TB/ddl.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/3TB/ddl.sql index 242b39a4..03b818dd 100644 --- a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/3TB/ddl.sql +++ b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/3TB/ddl.sql @@ -118,3 +118,12 @@ copy part from 's3://redshift-downloads/TPC-H/2.18/3TB/part/' iam_role default d copy supplier from 's3://redshift-downloads/TPC-H/2.18/3TB/supplier/' iam_role default delimiter '|'; copy partsupp from 's3://redshift-downloads/TPC-H/2.18/3TB/partsupp/' iam_role default delimiter '|'; copy customer from 's3://redshift-downloads/TPC-H/2.18/3TB/customer/' iam_role default delimiter '|'; + +select count(*) from customer; -- 450000000 +select count(*) from lineitem; -- 18000048306 +select count(*) from nation; -- 25 +select count(*) from orders; -- 4500000000 +select count(*) from part; -- 600000000 +select count(*) from partsupp; -- 2400000000 +select count(*) from region; -- 5 +select count(*) from supplier; -- 30000000 From c3094bc946be7e5e7743266741488829f50faeaa Mon Sep 17 00:00:00 2001 From: adedotua Date: Thu, 9 Feb 2023 23:33:21 -0600 Subject: [PATCH 03/49] Fix Issue #660 and update v_connection_summary --- src/AdminViews/v_connection_summary.sql | 58 +-- .../v_generate_user_grant_revoke_ddl.sql | 126 +++--- src/EventBasedAutoRefresh/autorefresh.py | 146 ------- .../cloudformation/autorefresh.yaml | 396 ------------------ 4 files changed, 96 insertions(+), 630 deletions(-) delete mode 100644 src/EventBasedAutoRefresh/autorefresh.py delete mode 100644 src/EventBasedAutoRefresh/cloudformation/autorefresh.yaml diff --git a/src/AdminViews/v_connection_summary.sql b/src/AdminViews/v_connection_summary.sql index f84a6437..8e17e992 100644 --- a/src/AdminViews/v_connection_summary.sql +++ b/src/AdminViews/v_connection_summary.sql @@ -5,34 +5,40 @@ Purpose: View to flatten stl_connection_log table and provide details like terminated by admin, active or connection lost History: 2017-12-29 adedotua created +2023-02-09 updated view to use sessionid for joins. added new columns + os_version, driver_version and sessionid. fully qualified table names. + **********************************************************************************************/ -CREATE OR REPLACE VIEW admin.V_CONNECTION_SUMMARY as -select trim(a.username) as username, -a.pid, -a.recordtime as authentication_time, -b.recordtime as session_starttime, -d.recordtime session_endtime, -trim(a.dbname) as dbname, -trim(c.application_name) as app_name, -trim(b.authmethod) as authmethod, -case when d.duration > 0 then (d.duration/1000000)/86400||' days '||((d.duration/1000000)%86400)/3600||'hrs ' +CREATE OR REPLACE VIEW admin.V_CONNECTION_SUMMARY AS +SELECT a.username::varchar +,a.pid +,a.recordtime as authentication_time +,b.recordtime as session_starttime +,d.recordtime as session_endtime +,a.dbname::varchar +,c.application_name::varchar as app_name +,b.authmethod::varchar +,case when d.duration > 0 then (d.duration/1000000)/86400||' days '||((d.duration/1000000)%86400)/3600||'hrs ' ||((d.duration/1000000)%3600)/60||'mins '||(d.duration/1000000%60)||'secs' when f.process is null then null else datediff(s,a.recordtime,getdate())/86400||' days '||(datediff(s,a.recordtime,getdate())%86400)/3600||'hrs ' -||(datediff(s,a.recordtime,getdate())%3600)/60||'mins '||(datediff(s,a.recordtime,getdate())%60)||'secs' end as duration, -b.mtu, -trim(b.sslversion) as sslversion, -trim(b.sslcipher) as sslcipher, -trim(b.remotehost) as remotehost, -trim(b.remoteport) as remoteport, -case when e.recordtime is not null then 'Terminated by administrator' +||(datediff(s,a.recordtime,getdate())%3600)/60||'mins '||(datediff(s,a.recordtime,getdate())%60)||'secs' end as duration +,b.mtu +,b.sslversion::varchar +,b.sslcipher::varchar +,b.remotehost::varchar +,b.remoteport::varchar +,case when e.recordtime is not null then 'Terminated by administrator' when d.recordtime is not null then 'Disconnected' when f.process is not null then 'Active' else 'Connection Lost' end as current_state -from -(select * from stl_connection_log where event='authenticated') a -left join (select * from stl_connection_log where event='initiating session') b using (pid,dbname,remotehost,remoteport,username) -left join (select * from stl_connection_log where event='set application_name') c using (pid,dbname,remotehost,remoteport,username) -left join (select * from stl_connection_log where event='disconnecting session') d using (pid,dbname,remotehost,remoteport,username) -left join (select * from stl_connection_log where event='Terminating backend on administrator''s request') e using (pid,dbname,remotehost,remoteport,username) -left join stv_sessions f on a.pid=f.process and a.dbname=f.db_name and a.username=f.user_name +,a.sessionid::varchar +,nvl(a.os_version,b.os_version)::varchar as os_version +,nvl(a.driver_version,b.driver_version)::varchar as driver_version +FROM +(SELECT * FROM pg_catalog.stl_connection_log WHERE event='authenticated') a +LEFT JOIN (SELECT * FROM pg_catalog.stl_connection_log WHERE event='initiating session') b using (sessionid) +LEFT JOIN (SELECT * FROM pg_catalog.stl_connection_log WHERE event='set application_name') c using (sessionid) +LEFT JOIN (SELECT * FROM pg_catalog.stl_connection_log WHERE event='disconnecting session') d using (sessionid) +LEFT JOIN (SELECT * FROM pg_catalog.stl_connection_log WHERE event='Terminating backend on administrator''s request') e using (sessionid) +LEFT JOIN pg_catalog.stv_sessions f on a.pid=f.process and a.dbname=f.db_name and a.username=f.user_name and datediff(s,f.starttime,a.recordtime) < 5 -where a.username<>'rdsdb' -order by 3; +WHERE a.username <> 'rdsdb' +ORDER BY 3; diff --git a/src/AdminViews/v_generate_user_grant_revoke_ddl.sql b/src/AdminViews/v_generate_user_grant_revoke_ddl.sql index 66abe9d6..466c8400 100644 --- a/src/AdminViews/v_generate_user_grant_revoke_ddl.sql +++ b/src/AdminViews/v_generate_user_grant_revoke_ddl.sql @@ -44,7 +44,9 @@ Version 1.08 2020-02-22 adedotua added support for generating grants for column privileges (requires patch 1.0.13059 and above). added schemanames to catalog tables to allow creating this view as a late binding view Version 1.09 - 2021-07-27 adedotua added support for generating 'DROP' grants and revokes for tables/views. + 2021-07-27 adedotua added support for generating 'DROP' grants and revokes for tables/views. +Version 1.10 + 2023-02-08 Fix for issue #660 Steps to revoking grants before dropping a user: 1. Find all grants by granted by user to drop and regrant them as another user (superuser preferably). @@ -60,13 +62,13 @@ SELECT objowner, schemaname, objname, objtype, - CASE WHEN split_part(aclstring,'=',1)='' THEN 'PUBLIC' ELSE translate(trim(split_part(aclstring,'=',1)),'"','') END::text AS grantee, - translate(trim(split_part(aclstring,'/',2)),'"','')::text AS grantor, + CASE WHEN split_part(aclstring,'=',1)='' THEN 'PUBLIC'::text ELSE translate(trim(split_part(aclstring,'=',1)::text),'"','')::text END::text AS grantee, + translate(trim(split_part(aclstring,'/',2)::text),'"','')::text AS grantor, trim(split_part(split_part(aclstring,'=',2),'/',1))::text AS privilege, - CASE WHEN objtype = 'default acl' THEN objname - WHEN objtype in ('procedure','function') AND regexp_instr(objname, schemaname) > 0 THEN objname - WHEN objtype in ('procedure','function','column') THEN QUOTE_IDENT(schemaname)||'.'||objname - ELSE nvl(QUOTE_IDENT(schemaname)||'.'||QUOTE_IDENT(objname),QUOTE_IDENT(objname)) END::text as fullobjname, + CASE WHEN objtype = 'default acl' THEN QUOTE_IDENT(objname) + WHEN objtype in ('procedure','function') AND regexp_instr(objname, schemaname) > 0 THEN QUOTE_IDENT(objname) + WHEN objtype in ('procedure','function','column') THEN QUOTE_IDENT(schemaname)||'.'||QUOTE_IDENT(objname) + ELSE nvl(QUOTE_IDENT(schemaname)||'.'||QUOTE_IDENT(objname),QUOTE_IDENT(objname)) END::varchar(5000) as fullobjname, CASE WHEN split_part(aclstring,'=',1)='' THEN 'PUBLIC' ELSE trim(split_part(aclstring,'=',1)) END::text as splitgrantee, @@ -76,9 +78,9 @@ SELECT objowner, -- TABLE AND VIEW privileges SELECT pg_get_userbyid(b.relowner)::text AS objowner, trim(c.nspname)::text AS schemaname, - b.relname::text AS objname, + b.relname::varchar(5000) AS objname, CASE WHEN relkind='r' THEN 'table' ELSE 'view' END::text AS objtype, - TRIM(SPLIT_PART(array_to_string(b.relacl,','), ',', NS.n))::text AS aclstring, + TRIM(SPLIT_PART(array_to_string(b.relacl,','), ',', NS.n))::varchar(500) AS aclstring, NS.n as grantseq, null::text as colname FROM @@ -90,9 +92,9 @@ SELECT objowner, -- TABLE AND VIEW column privileges SELECT pg_get_userbyid(c.relowner)::text AS objowner, trim(d.nspname)::text AS schemaname, - c.relname::text AS objname, + c.relname::varchar(5000) AS objname, 'column'::text AS objtype, - TRIM(SPLIT_PART(array_to_string(b.attacl,','), ',', NS.n))::text AS aclstring, + TRIM(SPLIT_PART(array_to_string(b.attacl,','), ',', NS.n))::varchar(500) AS aclstring, NS.n as grantseq, b.attname::text as colname FROM @@ -105,9 +107,9 @@ SELECT objowner, -- SCHEMA privileges SELECT pg_get_userbyid(b.nspowner)::text AS objowner, null::text AS schemaname, - b.nspname::text AS objname, + b.nspname::varchar(5000) AS objname, 'schema'::text AS objtype, - TRIM(SPLIT_PART(array_to_string(b.nspacl,','), ',', NS.n))::text AS aclstring, + TRIM(SPLIT_PART(array_to_string(b.nspacl,','), ',', NS.n))::varchar(500) AS aclstring, NS.n as grantseq, null::text as colname FROM @@ -117,9 +119,9 @@ SELECT objowner, -- DATABASE privileges SELECT pg_get_userbyid(b.datdba)::text AS objowner, null::text AS schemaname, - b.datname::text AS objname, + b.datname::varchar(5000) AS objname, 'database'::text AS objtype, - TRIM(SPLIT_PART(array_to_string(b.datacl,','), ',', NS.n))::text AS aclstring, + TRIM(SPLIT_PART(array_to_string(b.datacl,','), ',', NS.n))::varchar(500) AS aclstring, NS.n as grantseq, null::text as colname FROM @@ -129,9 +131,9 @@ SELECT objowner, -- FUNCTION privileges SELECT pg_get_userbyid(b.proowner)::text AS objowner, trim(c.nspname)::text AS schemaname, - textin(regprocedureout(b.oid::regprocedure))::text AS objname, + textin(regprocedureout(b.oid::regprocedure))::varchar(5000) AS objname, decode(prorettype,0,'procedure','function')::text AS objtype, - TRIM(SPLIT_PART(array_to_string(b.proacl,','), ',', NS.n))::text AS aclstring, + TRIM(SPLIT_PART(array_to_string(b.proacl,','), ',', NS.n))::varchar(500) AS aclstring, NS.n as grantseq, null::text as colname FROM @@ -142,9 +144,9 @@ SELECT objowner, -- LANGUAGE privileges SELECT null::text AS objowner, null::text AS schemaname, - lanname::text AS objname, + lanname::varchar(5000) AS objname, 'language'::text AS objtype, - TRIM(SPLIT_PART(array_to_string(b.lanacl,','), ',', NS.n))::text AS aclstring, + TRIM(SPLIT_PART(array_to_string(b.lanacl,','), ',', NS.n))::varchar(500) AS aclstring, NS.n as grantseq, null::text as colname FROM @@ -154,9 +156,9 @@ SELECT objowner, -- DEFAULT ACL privileges SELECT pg_get_userbyid(b.defacluser)::text AS objowner, trim(c.nspname)::text AS schemaname, - decode(b.defaclobjtype,'r','tables','f','functions','p','procedures')::text AS objname, + decode(b.defaclobjtype,'r','tables','f','functions','p','procedures')::varchar(5000) AS objname, 'default acl'::text AS objtype, - TRIM(SPLIT_PART(array_to_string(b.defaclacl,','), ',', NS.n))::text AS aclstring, + TRIM(SPLIT_PART(array_to_string(b.defaclacl,','), ',', NS.n))::varchar(500) AS aclstring, NS.n as grantseq, null::text as colname FROM @@ -170,78 +172,78 @@ SELECT objowner, AND NOT (split_part(aclstring,'=',1)='' AND split_part(aclstring,'/',2) = 'rdsdb')) ) -- Extract object GRANTS -SELECT objowner::text, schemaname::text, objname::text, objtype::text, grantor::text, grantee::text, 'grant'::text AS ddltype, grantseq, +SELECT objowner::text, schemaname::text, objname::varchar(5000), objtype::text, grantor::text, grantee::text, 'grant'::text AS ddltype, grantseq, decode(objtype,'database',0,'schema',1,'language',1,'table',2,'view',2,'column',2,'function',2,'procedure',2,'default acl',3) AS objseq, CASE WHEN (grantor <> current_user AND grantor <> 'rdsdb' AND objtype <> 'default acl') -THEN 'SET SESSION AUTHORIZATION '||QUOTE_IDENT(grantor)||';' ELSE '' END::varchar(4000)|| +THEN 'SET SESSION AUTHORIZATION '||QUOTE_IDENT(grantor)||';' ELSE '' END::varchar(5000)|| (CASE WHEN privilege = 'arwdRxtD' OR privilege = 'a*r*w*d*R*x*t*D*' THEN (CASE WHEN objtype = 'default acl' THEN 'ALTER DEFAULT PRIVILEGES for user '||QUOTE_IDENT(grantor)||nvl(' in schema '||QUOTE_IDENT(schemaname)||' ',' ') -ELSE '' END::varchar(4000))||'GRANT ALL on '||fullobjname||' to '||splitgrantee|| -(CASE WHEN privilege = 'a*r*w*d*R*x*t*D*' THEN ' WITH GRANT OPTION;' ELSE ';' END::varchar(4000)) +ELSE '' END::varchar(5000))||'GRANT ALL on '||fullobjname||' to '||splitgrantee|| +(CASE WHEN privilege = 'a*r*w*d*R*x*t*D*' THEN ' WITH GRANT OPTION;' ELSE ';' END::varchar(5000)) when privilege = 'UC' OR privilege = 'U*C*' THEN (CASE WHEN objtype = 'default acl' THEN 'ALTER DEFAULT PRIVILEGES for user '||QUOTE_IDENT(grantor)||nvl(' in schema '||QUOTE_IDENT(schemaname)||' ',' ') -ELSE '' END::varchar(4000))||'GRANT ALL on '||objtype||' '||fullobjname||' to '||splitgrantee|| -(CASE WHEN privilege = 'U*C*' THEN ' WITH GRANT OPTION;' ELSE ';' END::varchar(4000)) +ELSE '' END::varchar(5000))||'GRANT ALL on '||objtype||' '||fullobjname||' to '||splitgrantee|| +(CASE WHEN privilege = 'U*C*' THEN ' WITH GRANT OPTION;' ELSE ';' END::varchar(5000)) when privilege = 'CT' OR privilege = 'U*C*' THEN (CASE WHEN objtype = 'default acl' THEN 'ALTER DEFAULT PRIVILEGES for user '||QUOTE_IDENT(grantor)||nvl(' in schema '||QUOTE_IDENT(schemaname)||' ',' ') -ELSE '' END::varchar(4000))||'GRANT ALL on '||objtype||' '||fullobjname||' to '||splitgrantee|| -(CASE WHEN privilege = 'C*T*' THEN ' WITH GRANT OPTION;' ELSE ';' END::varchar(4000)) +ELSE '' END::varchar(5000))||'GRANT ALL on '||objtype||' '||fullobjname||' to '||splitgrantee|| +(CASE WHEN privilege = 'C*T*' THEN ' WITH GRANT OPTION;' ELSE ';' END::varchar(5000)) ELSE ( CASE WHEN charindex('a',privilege) > 0 THEN (CASE WHEN objtype = 'default acl' THEN 'ALTER DEFAULT PRIVILEGES for user '||QUOTE_IDENT(grantor)||nvl(' in schema '||QUOTE_IDENT(schemaname)||' ',' ') -ELSE '' END::varchar(4000))||'GRANT INSERT on '||fullobjname||' to '||splitgrantee|| -(CASE WHEN charindex('a*',privilege) > 0 THEN ' WITH GRANT OPTION;' ELSE ';' END::varchar(4000)) ELSE '' END::varchar(4000)|| +ELSE '' END::varchar(5000))||'GRANT INSERT on '||fullobjname||' to '||splitgrantee|| +(CASE WHEN charindex('a*',privilege) > 0 THEN ' WITH GRANT OPTION;' ELSE ';' END::varchar(5000)) ELSE '' END::varchar(5000)|| CASE WHEN charindex('r',privilege) > 0 THEN (CASE WHEN objtype = 'default acl' THEN 'ALTER DEFAULT PRIVILEGES for user '||QUOTE_IDENT(grantor)||nvl(' in schema '||QUOTE_IDENT(schemaname)||' ',' ') -ELSE '' END::varchar(4000))||'GRANT SELECT '||CASE WHEN objtype='column' then '('||colname||')' else '' END::text||' on '||fullobjname||' to '||splitgrantee|| -(CASE WHEN charindex('r*',privilege) > 0 THEN ' WITH GRANT OPTION;' ELSE ';' END::varchar(4000)) ELSE '' END::varchar(4000)|| +ELSE '' END::varchar(5000))||'GRANT SELECT '||CASE WHEN objtype='column' then '('||colname||')' else '' END::text||' on '||fullobjname||' to '||splitgrantee|| +(CASE WHEN charindex('r*',privilege) > 0 THEN ' WITH GRANT OPTION;' ELSE ';' END::varchar(5000)) ELSE '' END::varchar(5000)|| CASE WHEN charindex('w',privilege) > 0 THEN (CASE WHEN objtype = 'default acl' THEN 'ALTER DEFAULT PRIVILEGES for user '||QUOTE_IDENT(grantor)||nvl(' in schema '||QUOTE_IDENT(schemaname)||' ',' ') -ELSE '' END::varchar(4000))||'GRANT UPDATE '||CASE WHEN objtype='column' then '('||colname||')' else '' END::text||' on '||fullobjname||' to '||splitgrantee|| -(CASE WHEN charindex('w*',privilege) > 0 THEN ' WITH GRANT OPTION;' ELSE ';' END::varchar(4000)) ELSE '' END::varchar(4000)|| +ELSE '' END::varchar(5000))||'GRANT UPDATE '||CASE WHEN objtype='column' then '('||colname||')' else '' END::text||' on '||fullobjname||' to '||splitgrantee|| +(CASE WHEN charindex('w*',privilege) > 0 THEN ' WITH GRANT OPTION;' ELSE ';' END::varchar(5000)) ELSE '' END::varchar(5000)|| CASE WHEN charindex('d',privilege) > 0 THEN (CASE WHEN objtype = 'default acl' THEN 'ALTER DEFAULT PRIVILEGES for user '||QUOTE_IDENT(grantor)||nvl(' in schema '||QUOTE_IDENT(schemaname)||' ',' ') -ELSE '' END::varchar(4000))||'GRANT DELETE on '||fullobjname||' to '||splitgrantee|| -(CASE WHEN charindex('d*',privilege) > 0 THEN ' WITH GRANT OPTION;' ELSE ';' END::varchar(4000)) ELSE '' END::varchar(4000)|| +ELSE '' END::varchar(5000))||'GRANT DELETE on '||fullobjname||' to '||splitgrantee|| +(CASE WHEN charindex('d*',privilege) > 0 THEN ' WITH GRANT OPTION;' ELSE ';' END::varchar(5000)) ELSE '' END::varchar(5000)|| CASE WHEN charindex('D',privilege) > 0 THEN (CASE WHEN objtype = 'default acl' THEN '-- ALTER DEFAULT PRIVILEGES for user '||QUOTE_IDENT(grantor)||nvl(' in schema '||QUOTE_IDENT(schemaname)||' ',' ') -ELSE '' END::varchar(4000))||'GRANT DROP on '||fullobjname||' to '||splitgrantee|| -(CASE WHEN charindex('d*',privilege) > 0 THEN ' WITH GRANT OPTION;' ELSE ';' END::varchar(4000)) ELSE '' END::varchar(4000)|| +ELSE '' END::varchar(5000))||'GRANT DROP on '||fullobjname||' to '||splitgrantee|| +(CASE WHEN charindex('d*',privilege) > 0 THEN ' WITH GRANT OPTION;' ELSE ';' END::varchar(5000)) ELSE '' END::varchar(5000)|| CASE WHEN charindex('R',privilege) > 0 THEN (CASE WHEN objtype = 'default acl' THEN 'ALTER DEFAULT PRIVILEGES for user '||QUOTE_IDENT(grantor)||nvl(' in schema '||QUOTE_IDENT(schemaname)||' ',' ') -ELSE '' END::varchar(4000))||'GRANT RULE on '||fullobjname||' to '||splitgrantee|| -(CASE WHEN charindex('R*',privilege) > 0 THEN ' WITH GRANT OPTION;' ELSE ';' END::varchar(4000)) ELSE '' END::varchar(4000)|| +ELSE '' END::varchar(5000))||'GRANT RULE on '||fullobjname||' to '||splitgrantee|| +(CASE WHEN charindex('R*',privilege) > 0 THEN ' WITH GRANT OPTION;' ELSE ';' END::varchar(5000)) ELSE '' END::varchar(5000)|| CASE WHEN charindex('x',privilege) > 0 THEN (CASE WHEN objtype = 'default acl' THEN 'ALTER DEFAULT PRIVILEGES for user '||QUOTE_IDENT(grantor)||nvl(' in schema '||QUOTE_IDENT(schemaname)||' ',' ') -ELSE '' END::varchar(4000))||'GRANT REFERENCES on '||fullobjname||' to '||splitgrantee|| -(CASE WHEN charindex('x*',privilege) > 0 THEN ' WITH GRANT OPTION;' ELSE ';' END::varchar(4000)) ELSE '' END::varchar(4000)|| +ELSE '' END::varchar(5000))||'GRANT REFERENCES on '||fullobjname||' to '||splitgrantee|| +(CASE WHEN charindex('x*',privilege) > 0 THEN ' WITH GRANT OPTION;' ELSE ';' END::varchar(5000)) ELSE '' END::varchar(5000)|| CASE WHEN charindex('t',privilege) > 0 THEN (CASE WHEN objtype = 'default acl' THEN 'ALTER DEFAULT PRIVILEGES for user '||QUOTE_IDENT(grantor)||nvl(' in schema '||QUOTE_IDENT(schemaname)||' ',' ') -ELSE '' END::varchar(4000))||'GRANT TRIGGER on '||fullobjname||' to '||splitgrantee|| -(CASE WHEN charindex('t*',privilege) > 0 THEN ' WITH GRANT OPTION;' ELSE ';' END::varchar(4000)) ELSE '' END::varchar(4000)|| +ELSE '' END::varchar(5000))||'GRANT TRIGGER on '||fullobjname||' to '||splitgrantee|| +(CASE WHEN charindex('t*',privilege) > 0 THEN ' WITH GRANT OPTION;' ELSE ';' END::varchar(5000)) ELSE '' END::varchar(5000)|| CASE WHEN charindex('U',privilege) > 0 THEN (CASE WHEN objtype = 'default acl' THEN 'ALTER DEFAULT PRIVILEGES for user '||QUOTE_IDENT(grantor)||nvl(' in schema '||QUOTE_IDENT(schemaname)||' ',' ') -ELSE '' END::varchar(4000))||'GRANT USAGE on '||objtype||' '||fullobjname||' to '||splitgrantee|| -(CASE WHEN charindex('U*',privilege) > 0 THEN ' WITH GRANT OPTION;' ELSE ';' END::varchar(4000)) ELSE '' END::varchar(4000)|| +ELSE '' END::varchar(5000))||'GRANT USAGE on '||objtype||' '||fullobjname||' to '||splitgrantee|| +(CASE WHEN charindex('U*',privilege) > 0 THEN ' WITH GRANT OPTION;' ELSE ';' END::varchar(5000)) ELSE '' END::varchar(5000)|| CASE WHEN charindex('C',privilege) > 0 THEN (CASE WHEN objtype = 'default acl' THEN 'ALTER DEFAULT PRIVILEGES for user '||QUOTE_IDENT(grantor)||nvl(' in schema '||QUOTE_IDENT(schemaname)||' ',' ') -ELSE '' END::varchar(4000))||'GRANT CREATE on '||objtype||' '||fullobjname||' to '||splitgrantee|| -(CASE WHEN charindex('C*',privilege) > 0 THEN ' WITH GRANT OPTION;' ELSE ';' END::varchar(4000)) ELSE '' END::varchar(4000)|| +ELSE '' END::varchar(5000))||'GRANT CREATE on '||objtype||' '||fullobjname||' to '||splitgrantee|| +(CASE WHEN charindex('C*',privilege) > 0 THEN ' WITH GRANT OPTION;' ELSE ';' END::varchar(5000)) ELSE '' END::varchar(5000)|| CASE WHEN charindex('T',privilege) > 0 THEN (CASE WHEN objtype = 'default acl' THEN 'ALTER DEFAULT PRIVILEGES for user '||QUOTE_IDENT(grantor)||nvl(' in schema '||QUOTE_IDENT(schemaname)||' ',' ') -ELSE '' END::varchar(4000))||'GRANT TEMP on '||objtype||' '||fullobjname||' to '||splitgrantee|| -(CASE WHEN charindex('T*',privilege) > 0 THEN ' WITH GRANT OPTION;' ELSE ';' END::varchar(4000)) ELSE '' END::varchar(4000)|| +ELSE '' END::varchar(5000))||'GRANT TEMP on '||objtype||' '||fullobjname||' to '||splitgrantee|| +(CASE WHEN charindex('T*',privilege) > 0 THEN ' WITH GRANT OPTION;' ELSE ';' END::varchar(5000)) ELSE '' END::varchar(5000)|| CASE WHEN charindex('X',privilege) > 0 THEN (CASE WHEN objtype = 'default acl' THEN 'ALTER DEFAULT PRIVILEGES for user '||QUOTE_IDENT(grantor)||nvl(' in schema '||QUOTE_IDENT(schemaname)||' ',' ') -ELSE '' END::varchar(4000))||'GRANT EXECUTE on '|| -(CASE WHEN objtype = 'default acl' THEN '' ELSE objtype||' ' END::varchar(4000))||fullobjname||' to '||splitgrantee|| -(CASE WHEN charindex('X*',privilege) > 0 THEN ' WITH GRANT OPTION;' ELSE ';' END::varchar(4000)) ELSE '' END::varchar(4000) -) END::varchar(4000))|| -CASE WHEN (grantor <> current_user AND grantor <> 'rdsdb' AND objtype <> 'default acl') THEN 'RESET SESSION AUTHORIZATION;' ELSE '' END::varchar(4000) AS ddl, colname +ELSE '' END::varchar(5000))||'GRANT EXECUTE on '|| +(CASE WHEN objtype = 'default acl' THEN '' ELSE objtype||' ' END::varchar(5000))||fullobjname||' to '||splitgrantee|| +(CASE WHEN charindex('X*',privilege) > 0 THEN ' WITH GRANT OPTION;' ELSE ';' END::varchar(5000)) ELSE '' END::varchar(5000) +) END::varchar(5000))|| +CASE WHEN (grantor <> current_user AND grantor <> 'rdsdb' AND objtype <> 'default acl') THEN 'RESET SESSION AUTHORIZATION;' ELSE '' END::varchar(5000) AS ddl, colname FROM objprivs UNION ALL -- Extract object REVOKES -SELECT objowner::text, schemaname::text, objname::text, objtype::text, grantor::text, grantee::text, 'revoke'::text AS ddltype, grantseq, +SELECT objowner::text, schemaname::text, objname::varchar(5000), objtype::text, grantor::text, grantee::text, 'revoke'::text AS ddltype, grantseq, decode(objtype,'default acl',0,'function',0,'procedure',1,'table',1,'view',1,'column',1,'schema',2,'language',2,'database',3) AS objseq, -CASE WHEN (grantor <> current_user AND grantor <> 'rdsdb' AND objtype <> 'default acl' AND grantor <> objowner) THEN 'SET SESSION AUTHORIZATION '||QUOTE_IDENT(grantor)||';' ELSE '' END::varchar(4000)|| +CASE WHEN (grantor <> current_user AND grantor <> 'rdsdb' AND objtype <> 'default acl' AND grantor <> objowner) THEN 'SET SESSION AUTHORIZATION '||QUOTE_IDENT(grantor)||';' ELSE '' END::varchar(5000)|| (CASE WHEN objtype = 'default acl' THEN 'ALTER DEFAULT PRIVILEGES for user '||QUOTE_IDENT(grantor)||nvl(' in schema '||QUOTE_IDENT(schemaname)||' ',' ') ||'REVOKE ALL on '||fullobjname||' FROM '||splitgrantee||';' -ELSE 'REVOKE ALL on '||(CASE WHEN objtype in ('table', 'view', 'column') THEN '' ELSE objtype||' ' END::varchar(4000))||fullobjname||' FROM '||splitgrantee||';' END::varchar(4000))|| -CASE WHEN (grantor <> current_user AND grantor <> 'rdsdb' AND objtype <> 'default acl' AND grantor <> objowner) THEN 'RESET SESSION AUTHORIZATION;' ELSE '' END::varchar(4000) AS ddl, colname +ELSE 'REVOKE ALL on '||(CASE WHEN objtype in ('table', 'view', 'column') THEN '' ELSE objtype||' ' END::varchar(5000))||fullobjname||' FROM '||splitgrantee||';' END::varchar(5000))|| +CASE WHEN (grantor <> current_user AND grantor <> 'rdsdb' AND objtype <> 'default acl' AND grantor <> objowner) THEN 'RESET SESSION AUTHORIZATION;' ELSE '' END::varchar(5000) AS ddl, colname FROM objprivs WHERE NOT (objtype = 'default acl' AND grantee = 'PUBLIC' and objname in ('functions')) UNION ALL -- Eliminate empty default ACLs -SELECT null::text AS objowner, null::text AS schemaname, decode(b.defaclobjtype,'r','tables','f','functions','p','procedures')::text AS objname, +SELECT null::text AS objowner, null::text AS schemaname, decode(b.defaclobjtype,'r','tables','f','functions','p','procedures')::varchar(5000) AS objname, 'default acl'::text AS objtype, pg_get_userbyid(b.defacluser)::text AS grantor, null::text AS grantee, 'revoke'::text AS ddltype, 5 as grantseq, 5 AS objseq, 'ALTER DEFAULT PRIVILEGES for user '||QUOTE_IDENT(pg_get_userbyid(b.defacluser))||' GRANT ALL on '||decode(b.defaclobjtype,'r','tables','f','functions','p','procedures')||' TO '||QUOTE_IDENT(pg_get_userbyid(b.defacluser))|| -CASE WHEN b.defaclobjtype = 'f' then ', PUBLIC;' ELSE ';' END::varchar(4000) AS ddl, null::text as colname FROM pg_catalog.pg_default_acl b where b.defaclacl = '{}'::aclitem[] or (defaclnamespace=0 and defaclobjtype='f'); +CASE WHEN b.defaclobjtype = 'f' THEN ', PUBLIC;' ELSE ';' END::varchar(5000) AS ddl, null::text as colname FROM pg_catalog.pg_default_acl b where b.defaclacl = '{}'::aclitem[] or (defaclnamespace=0 and defaclobjtype='f'); diff --git a/src/EventBasedAutoRefresh/autorefresh.py b/src/EventBasedAutoRefresh/autorefresh.py deleted file mode 100644 index 7b95aac4..00000000 --- a/src/EventBasedAutoRefresh/autorefresh.py +++ /dev/null @@ -1,146 +0,0 @@ -import json -import logging -import boto3 -import os -import time - - -logger = logging.getLogger() -logger.setLevel(logging.INFO) -rsapi = boto3.client('redshift-data') -kfhose = boto3.client('firehose') -snsclient = boto3.client('sns') -dynamodb = boto3.resource('dynamodb') -tablename = os.environ['DDBTABLE'] -ddbtable = dynamodb.Table(tablename) -snstopic = os.getenv('SNSTOPIC',None) -maxfailures = 5 - - -def check_refresh_status(ddbitem): - checksql = f"select query from stv_recents where status <> 'Done' and db_name = '{ddbitem['database_name']}' and user_name='IAM:{ddbitem['username']}' and query = '{ddbitem['sql']}'" - logger.debug(checksql) - response = rsapi.execute_statement(ClusterIdentifier=ddbitem['clusterid'], Database=ddbitem['database_name'], DbUser=ddbitem['username'], - Sql=checksql, StatementName=f"Check {ddbitem['mvname']} refresh status") - logger.info(json.dumps(response, default=str)) - queryid = response['Id'] - status = None - while status not in ['FAILED','FINISHED']: - status = rsapi.describe_statement(Id=queryid)['Status'] - logger.debug(status) - time.sleep(5) - numrows = rsapi.get_statement_result(Id=queryid)['TotalNumRows'] - logger.info(f"Check status query: {queryid} \nNumrows: {numrows} \n{json.dumps(response, default=str)}") - return(numrows) - - -def execute_statement(ddbitem): - if ddbitem: - if ddbitem['autorefresh']: - response = rsapi.execute_statement(ClusterIdentifier=ddbitem['clusterid'], Database=ddbitem['database_name'], DbUser=ddbitem['username'], - Sql=ddbitem['sql'], StatementName=ddbitem['mvname'], WithEvent=True) - logger.info(f"Redshift api response: {json.dumps(response, default=str)}") - logger.info(f"Sent query to {ddbitem['clusterid']} to refresh {ddbitem['mvname']} in database {ddbitem['database_name']}") - else: - msg = f"Auto Refresh is disabled on MV {ddbitem['mvname']} in database {ddbitem['database_name']} for cluster {ddbitem['clusterid']}" - logger.info(f"{msg} Skipping...") - if snstopic: - snsclient.publish(TopicArn=snstopic, - Message=msg, Subject=f"{ddbitem['mvname']} MV Refresh on {ddbitem['clusterid']}") - else: - logger.info("Item not found!") - - -def trigger_first_refresh(record): - try: - eventName = record['eventName'] - logger.info(f"Event type is {eventName}...") - if eventName != 'REMOVE': - if eventName == 'MODIFY': - oldimage = record['dynamodb']['OldImage'] - prevautorefresh = oldimage['autorefresh']['BOOL'] - else: - prevautorefresh = None - newimage = record['dynamodb']['NewImage'] - ddbitem = {'failure_cnt': newimage['failure_cnt']['N'], 'clusterid': newimage['clusterid']['S'] - , 'database_name': newimage['database_name']['S'], 'autorefresh': newimage['autorefresh']['BOOL'] - , 'username': newimage['username']['S'], 'mvname': newimage['mvname']['S'] - , 'sql': newimage['sql']['S'] } - logger.info(f"Extracted {ddbitem['mvname']} attributes from dynamodb event: {ddbitem}") - if (ddbitem['autorefresh'] and not prevautorefresh) or eventName == 'INSERT': - msg = f"Starting Auto Refresh on MV {ddbitem['mvname']} in database {ddbitem['database_name']} for cluster {ddbitem['clusterid']}" - logger.info(msg) - if snstopic: - snsclient.publish(TopicArn=snstopic, Message=msg, Subject=f"{ddbitem['mvname']} MV Refresh on {ddbitem['clusterid']}") - execute_statement(ddbitem) - elif ddbitem['autorefresh'] is False: - execute_statement(ddbitem) - except KeyError as e: - logger.error(f"Key Error: {e} is missing in dynamodb response") - except Exception as e: - logger.exception(e) - - -def trigger_next_refresh(record): - msgbody = json.loads(record['body']) - caller_function = msgbody['detail']['principal'].split('/')[-1] - logger.info(json.dumps(msgbody, default=str)) - mvname = msgbody['detail']['statementName'] - clusterid = msgbody['resources'][0].split(':')[-1] - logger.info(f"MV: {mvname} Clusterid: {clusterid}") - ddbresponse = ddbtable.get_item(Key={'mvname': mvname, 'clusterid': clusterid}, ConsistentRead=True) - logger.debug(f"Get item DDB response: {json.dumps(ddbresponse, default=str)}") - ddbitem = ddbresponse['Item'] - msgsubject = f"{mvname} MV Refresh on {clusterid}" - # Check and ensure that message received was generated by this Lambda function - if caller_function == record['function_name'] and ddbitem: - dbname = ddbitem['database_name'] - numrows = check_refresh_status(ddbitem) - if numrows == 0: - dbname = ddbitem['database_name'] - failure_cnt = int(ddbitem['failure_cnt']) - if msgbody['detail']['state'] == 'FINISHED': - execute_statement(ddbitem) - if failure_cnt > 0: - logger.info(f"Refresh succeeded. Resetting failure_cnt for MV {mvname} in cluster {clusterid} to 0.") - dynamodb.Table(tablename).update_item(Key={'mvname': mvname, 'clusterid': clusterid}, UpdateExpression="set failure_cnt = :val" - ,ExpressionAttributeValues={':val': 0}, ReturnValues="UPDATED_NEW") - else: - failure_cnt += 1 - msg = f"Auto Refresh on MV {mvname} in database {dbname} for cluster {clusterid} failed {failure_cnt} times. " - if failure_cnt < maxfailures: - dynamodb.Table(tablename).update_item(Key={'mvname': mvname, 'clusterid': clusterid}, UpdateExpression="set failure_cnt = :val" - ,ExpressionAttributeValues={':val': failure_cnt}, ReturnValues="UPDATED_NEW") - errormsg = f"{msg}. Retrying refresh...\n {msgbody}" - logger.info(errormsg) - execute_statement(ddbitem) - if snstopic: - snsclient.publish(TopicArn=snstopic, Message=errormsg, Subject=msgsubject) - else: - dynamodb.Table(tablename).update_item(Key={'mvname': mvname, 'clusterid': clusterid}, UpdateExpression="set autorefresh = :val, failure_cnt = :cnt" - ,ExpressionAttributeValues={':val': False, ':cnt': failure_cnt}, ReturnValues="UPDATED_NEW") - errormsg = msg + f"Autorefresh disabled. Check the materialized view on your Redshift cluster.\n {msgbody}" - logger.info(errormsg) - if snstopic: - snsclient.publish(TopicArn=snstopic, Message=errormsg, Subject=msgsubject) - else: - msg = f"There is at least one refresh already running on MV {mvname} in database {dbname} on cluster {clusterid}. Refresh count: {numrows}" - logger.info(msg) - if snstopic: - snsclient.publish(TopicArn=snstopic, Message=msg, Subject=msgsubject) - - -def lambda_handler(event, context): - logger.debug(json.dumps(event, default=str)) - for record in event['Records']: - logger.info(json.dumps(record, default=str)) - eventsource = record['eventSource'] - if eventsource == 'aws:dynamodb': - logger.info('Eventsource is dynamodb...') - trigger_first_refresh(record) - elif eventsource == 'aws:sqs': - logger.info('Eventsource is sqs...') - record['function_name'] = context.function_name - trigger_next_refresh(record) - else: - logger.info(f"No handling for events from {eventsource}!") diff --git a/src/EventBasedAutoRefresh/cloudformation/autorefresh.yaml b/src/EventBasedAutoRefresh/cloudformation/autorefresh.yaml deleted file mode 100644 index 167411e2..00000000 --- a/src/EventBasedAutoRefresh/cloudformation/autorefresh.yaml +++ /dev/null @@ -1,396 +0,0 @@ -Parameters: - LambdaLogRetention: - Type: Number - Default: 90 - MinValue: 1 - MaxValue: 3653 - Description: Number of days to retain logs from the Lambda function. Default is 90 days. - LambdaExecutionTimeout: - Type: Number - Default: 300 - MinValue: 15 - MaxValue: 900 - Description: Number of seconds before Lambda function times out. Default is 300 seconds. Range is 15 to 900 seconds. - RefreshDelaySecs: - Type: Number - Default: 5 - MinValue: 2 - MaxValue: 900 - Description: Number of seconds to delay after finishing a refresh before triggering a new refresh. Default is 5 seconds. Range is 2 to 900 seconds. - ClusterDBUser: - Type: String - Default: "stream_mv_user" - Description: Username to use for connecting to Redshift cluster. Default is stream_mv_user. You can set to * if you want to connect as any database user. - LambdaBatchSize: - Type: Number - Default: 5 - MinValue: 1 - MaxValue: 30 - Description: Number of items for Lambda function to batch from SQS before processing. Default is 5. Range is 1 to 30. - -Resources: - MVRefreshLambdaLogGroup: - Type: AWS::Logs::LogGroup - Properties: - LogGroupName: - Fn::Sub: - - "/aws/lambda/${lambdafunctionname}" - - lambdafunctionname: - Ref: MVRefreshLambda - RetentionInDays: - Ref: LambdaLogRetention - DependsOn: MVRefreshLambda - - MVRefreshSQSQueue: - Type: AWS::SQS::Queue - Properties: - DelaySeconds: - Ref: RefreshDelaySecs - VisibilityTimeout: - Ref: LambdaExecutionTimeout - - MVRefreshSQSPolicy: - Type: AWS::SQS::QueuePolicy - Properties: - PolicyDocument: - Statement: - - Action: - - "SQS:SendMessage" - Effect: "Allow" - Resource: - - Fn::GetAtt: - - MVRefreshSQSQueue - - Arn - Principal: - Service: "events.amazonaws.com" - Queues: - - Ref: MVRefreshSQSQueue - - - MVRefreshEventRule: - Type: AWS::Events::Rule - Properties: - EventPattern: - source: - - "aws.redshift-data" - detail-type: - - "Redshift Data Statement Status Change" - State: ENABLED - Targets: - - - Arn: - Fn::GetAtt: - - MVRefreshSQSQueue - - Arn - Id: MVRefreshLambdaTarget - - MVRefreshSNS: - Type: AWS::SNS::Topic - Properties: - DisplayName: MVRefreshSNS-notifications - - MVRefreshDDBTable: - # mvname autorefresh clusterid database_name sql username - Type: AWS::DynamoDB::Table - Properties: - AttributeDefinitions: - - - AttributeName: "mvname" - AttributeType: "S" - - - AttributeName: "clusterid" - AttributeType: "S" - BillingMode: PAY_PER_REQUEST - KeySchema: - - - AttributeName: "mvname" - KeyType: HASH - - - AttributeName: "clusterid" - KeyType: RANGE - StreamSpecification: - StreamViewType: NEW_AND_OLD_IMAGES - - MVRefreshLambdaRole: - Type: AWS::IAM::Role - Properties: - AssumeRolePolicyDocument: - Statement: - - Action: sts:AssumeRole - Effect: Allow - Principal: - Service: "lambda.amazonaws.com" - Version: "2012-10-17" - - MVRefreshLambdaPolicy: - Type: AWS::IAM::Policy - Properties: - PolicyDocument: - Statement: - - Action: - - redshift:GetClusterCredentials - Effect: Allow - Resource: - - Fn::Sub: "arn:aws:redshift:${AWS::Region}:${AWS::AccountId}:dbuser:*/${ClusterDBUser}" - - Fn::Sub: "arn:aws:redshift:${AWS::Region}:${AWS::AccountId}:dbname:*" - - Action: - - redshift-data:ExecuteStatement - - redshift-data:DescribeStatement - - redshift-data:GetStatementResult - Effect: Allow - Resource: "*" - - Action: - - dynamodb:GetItem - - dynamodb:UpdateItem - Effect: Allow - Resource: - - Fn::GetAtt: - - MVRefreshDDBTable - - Arn - - Action: - - sqs:DeleteMessage - - sqs:ReceiveMessage - - sqs:GetQueueAttributes - Effect: Allow - Resource: - - Fn::GetAtt: - - MVRefreshSQSQueue - - Arn - - Action: - - sns:Publish - Effect: Allow - Resource: - - Ref: MVRefreshSNS - - Action: - - logs:CreateLogStream - - logs:PutLogEvents - Effect: Allow - Resource: - - Fn::GetAtt: - - MVRefreshLambdaLogGroup - - Arn - - Action: - - firehose:* - Effect: Allow - Resource: - - "arn:aws:firehose:us-east-1:757848091413:deliverystream/data_api" - - "arn:aws:firehose:us-east-1:757848091413:deliverystream/sqslogs" - - Action: - - dynamodb:ListStreams - Effect: Allow - Resource: - - Fn::GetAtt: - - MVRefreshDDBTable - - StreamArn - - Action: - - dynamodb:GetRecords - - dynamodb:GetShardIterator - - dynamodb:DescribeStream - Effect: Allow - Resource: - - Fn::GetAtt: - - MVRefreshDDBTable - - StreamArn - Version: "2012-10-17" - PolicyName: MVRefreshLambdaRolePolicy - Roles: - - Ref: MVRefreshLambdaRole - - MVLambdaSQSTrigger: - Type: AWS::Lambda::EventSourceMapping - Properties: - BatchSize: - Ref: LambdaBatchSize - Enabled: True - EventSourceArn: - Fn::GetAtt: - - MVRefreshSQSQueue - - Arn - FunctionName: - Fn::GetAtt: - - MVRefreshLambda - - Arn - DependsOn: MVRefreshLambdaPolicy - - MVLambdaDynamodbStreamsTrigger: - Type: AWS::Lambda::EventSourceMapping - Properties: - BatchSize: - Ref: LambdaBatchSize - Enabled: True - EventSourceArn: - Fn::GetAtt: - - MVRefreshDDBTable - - StreamArn - FunctionName: - Fn::GetAtt: - - MVRefreshLambda - - Arn - StartingPosition: LATEST - DependsOn: MVRefreshLambdaPolicy - - MVRefreshLambda: - Type: AWS::Lambda::Function - Properties: - Code: - ZipFile: | - import json - import logging - import boto3 - import os - import time - - - logger = logging.getLogger() - logger.setLevel(logging.INFO) - rsapi = boto3.client('redshift-data') - kfhose = boto3.client('firehose') - snsclient = boto3.client('sns') - dynamodb = boto3.resource('dynamodb') - tablename = os.environ['DDBTABLE'] - ddbtable = dynamodb.Table(tablename) - snstopic = os.getenv('SNSTOPIC',None) - maxfailures = 5 - - - def check_refresh_status(ddbitem): - checksql = f"select query from stv_recents where status <> 'Done' and db_name = '{ddbitem['database_name']}' and user_name='IAM:{ddbitem['username']}' and query = '{ddbitem['sql']}'" - logger.debug(checksql) - response = rsapi.execute_statement(ClusterIdentifier=ddbitem['clusterid'], Database=ddbitem['database_name'], DbUser=ddbitem['username'], - Sql=checksql, StatementName=f"Check {ddbitem['mvname']} refresh status") - logger.info(json.dumps(response, default=str)) - queryid = response['Id'] - status = None - while status not in ['FAILED','FINISHED']: - status = rsapi.describe_statement(Id=queryid)['Status'] - logger.debug(status) - time.sleep(5) - numrows = rsapi.get_statement_result(Id=queryid)['TotalNumRows'] - logger.info(f"Check status query: {queryid} \nNumrows: {numrows} \n{json.dumps(response, default=str)}") - return(numrows) - - - def execute_statement(ddbitem): - if ddbitem: - if ddbitem['autorefresh']: - response = rsapi.execute_statement(ClusterIdentifier=ddbitem['clusterid'], Database=ddbitem['database_name'], DbUser=ddbitem['username'], - Sql=ddbitem['sql'], StatementName=ddbitem['mvname'], WithEvent=True) - logger.info(f"Redshift api response: {json.dumps(response, default=str)}") - logger.info(f"Sent query to {ddbitem['clusterid']} to refresh {ddbitem['mvname']} in database {ddbitem['database_name']}") - else: - msg = f"Auto Refresh is disabled on MV {ddbitem['mvname']} in database {ddbitem['database_name']} for cluster {ddbitem['clusterid']}" - logger.info(f"{msg} Skipping...") - if snstopic: - snsclient.publish(TopicArn=snstopic, - Message=msg, Subject=f"{ddbitem['mvname']} MV Refresh on {ddbitem['clusterid']}") - else: - logger.info("Item not found!") - - - def trigger_first_refresh(record): - try: - eventName = record['eventName'] - logger.info(f"Event type is {eventName}...") - if eventName != 'REMOVE': - if eventName == 'MODIFY': - oldimage = record['dynamodb']['OldImage'] - prevautorefresh = oldimage['autorefresh']['BOOL'] - else: - prevautorefresh = None - newimage = record['dynamodb']['NewImage'] - ddbitem = {'failure_cnt': newimage['failure_cnt']['N'], 'clusterid': newimage['clusterid']['S'] - , 'database_name': newimage['database_name']['S'], 'autorefresh': newimage['autorefresh']['BOOL'] - , 'username': newimage['username']['S'], 'mvname': newimage['mvname']['S'] - , 'sql': newimage['sql']['S'] } - logger.info(f"Extracted {ddbitem['mvname']} attributes from dynamodb event: {ddbitem}") - if (ddbitem['autorefresh'] and not prevautorefresh) or eventName == 'INSERT': - msg = f"Starting Auto Refresh on MV {ddbitem['mvname']} in database {ddbitem['database_name']} for cluster {ddbitem['clusterid']}" - logger.info(msg) - if snstopic: - snsclient.publish(TopicArn=snstopic, Message=msg, Subject=f"{ddbitem['mvname']} MV Refresh on {ddbitem['clusterid']}") - execute_statement(ddbitem) - elif ddbitem['autorefresh'] is False: - execute_statement(ddbitem) - except KeyError as e: - logger.error(f"Key Error: {e} is missing in dynamodb response") - except Exception as e: - logger.exception(e) - - - def trigger_next_refresh(record): - msgbody = json.loads(record['body']) - caller_function = msgbody['detail']['principal'].split('/')[-1] - logger.info(json.dumps(msgbody, default=str)) - mvname = msgbody['detail']['statementName'] - clusterid = msgbody['resources'][0].split(':')[-1] - logger.info(f"MV: {mvname} Clusterid: {clusterid}") - ddbresponse = ddbtable.get_item(Key={'mvname': mvname, 'clusterid': clusterid}, ConsistentRead=True) - logger.debug(f"Get item DDB response: {json.dumps(ddbresponse, default=str)}") - ddbitem = ddbresponse['Item'] - msgsubject = f"{mvname} MV Refresh on {clusterid}" - # Check and ensure that message received was generated by this Lambda function - if caller_function == record['function_name'] and ddbitem: - dbname = ddbitem['database_name'] - numrows = check_refresh_status(ddbitem) - if numrows == 0: - dbname = ddbitem['database_name'] - failure_cnt = int(ddbitem['failure_cnt']) - if msgbody['detail']['state'] == 'FINISHED': - execute_statement(ddbitem) - if failure_cnt > 0: - logger.info(f"Refresh succeeded. Resetting failure_cnt for MV {mvname} in cluster {clusterid} to 0.") - dynamodb.Table(tablename).update_item(Key={'mvname': mvname, 'clusterid': clusterid}, UpdateExpression="set failure_cnt = :val" - ,ExpressionAttributeValues={':val': 0}, ReturnValues="UPDATED_NEW") - else: - failure_cnt += 1 - msg = f"Auto Refresh on MV {mvname} in database {dbname} for cluster {clusterid} failed {failure_cnt} times. " - if failure_cnt < maxfailures: - dynamodb.Table(tablename).update_item(Key={'mvname': mvname, 'clusterid': clusterid}, UpdateExpression="set failure_cnt = :val" - ,ExpressionAttributeValues={':val': failure_cnt}, ReturnValues="UPDATED_NEW") - errormsg = f"{msg}. Retrying refresh...\n {msgbody}" - logger.info(errormsg) - execute_statement(ddbitem) - if snstopic: - snsclient.publish(TopicArn=snstopic, Message=errormsg, Subject=msgsubject) - else: - dynamodb.Table(tablename).update_item(Key={'mvname': mvname, 'clusterid': clusterid}, UpdateExpression="set autorefresh = :val, failure_cnt = :cnt" - ,ExpressionAttributeValues={':val': False, ':cnt': failure_cnt}, ReturnValues="UPDATED_NEW") - errormsg = msg + f"Autorefresh disabled. Check the materialized view on your Redshift cluster.\n {msgbody}" - logger.info(errormsg) - if snstopic: - snsclient.publish(TopicArn=snstopic, Message=errormsg, Subject=msgsubject) - else: - msg = f"There is at least one refresh already running on MV {mvname} in database {dbname} on cluster {clusterid}. Refresh count: {numrows}" - logger.info(msg) - if snstopic: - snsclient.publish(TopicArn=snstopic, Message=msg, Subject=msgsubject) - - - def lambda_handler(event, context): - logger.debug(json.dumps(event, default=str)) - for record in event['Records']: - logger.info(json.dumps(record, default=str)) - eventsource = record['eventSource'] - if eventsource == 'aws:dynamodb': - logger.info('Eventsource is dynamodb...') - trigger_first_refresh(record) - elif eventsource == 'aws:sqs': - logger.info('Eventsource is sqs...') - record['function_name'] = context.function_name - trigger_next_refresh(record) - else: - logger.info(f"No handling for events from {eventsource}!") - Environment: - Variables: - DDBTABLE: - Ref: MVRefreshDDBTable - SNSTOPIC: - Ref: MVRefreshSNS - Handler: index.lambda_handler - Role: - Fn::GetAtt: - - MVRefreshLambdaRole - - Arn - Runtime: "python3.9" - Timeout: - Ref: LambdaExecutionTimeout From b41c5e6fe7c28995a75d3409fb48ad59793ca274 Mon Sep 17 00:00:00 2001 From: adedotua Date: Fri, 10 Feb 2023 00:09:10 -0600 Subject: [PATCH 04/49] Add is_recluster and aborted columns to v_vacuum_summary --- src/AdminViews/v_vacuum_summary.sql | 68 ++++++++++++++++------------- 1 file changed, 37 insertions(+), 31 deletions(-) diff --git a/src/AdminViews/v_vacuum_summary.sql b/src/AdminViews/v_vacuum_summary.sql index eca7a214..3ed8815e 100644 --- a/src/AdminViews/v_vacuum_summary.sql +++ b/src/AdminViews/v_vacuum_summary.sql @@ -14,43 +14,49 @@ Version 1.03 Version 1.04 2019-04-30 adedotua added is_auto_vacuum flag to indicate whether vacuum was auto vacuum Version 1.05 - 2019-10-09 adedotua set vac_end_status as null for autovacuum if end status is unknown + 2019-10-09 adedotua set vac_end_status as null for autovacuum if end status is unknown +Version 1.06 + 2023-02-09 add is_recluster and aborted columns **********************************************************************************************/ -CREATE OR REPLACE VIEW admin.v_vacuum_summary as SELECT a.userid, - a.xid, - BTRIM(d.datname) AS database_name, - a.table_id, - BTRIM(c.name) AS tablename, - BTRIM(a.status) AS vac_start_status, - CASE - WHEN (a.status ilike 'skipped%'::TEXT) THEN null - WHEN (f.xid IS NOT NULL) THEN 'Running'::TEXT - WHEN (b.status IS NULL) and a.status not ilike '%[VacuumBG]%' THEN 'Failed'::TEXT - ELSE BTRIM((b.status)::TEXT) - END AS vac_end_status, - a.eventtime AS vac_start_time, - b.eventtime AS vac_end_time, - CASE - WHEN f.xid IS NOT NULL THEN datediff(s,a.eventtime,getdate()) - WHEN b.eventtime IS NOT NULL THEN datediff(s,a.eventtime,b.eventtime) - ELSE NULL - END AS vac_duration_secs, - a."rows" AS vac_start_rows, - b."rows" AS vac_end_rows, - a."rows" - b."rows" AS vac_deleted_rows, - a.sortedrows AS vac_start_sorted_rows, - b.sortedrows AS vac_end_sorted_rows, - a."blocks" AS vac_start_blocks, - b."blocks" AS vac_end_blocks, - (b."blocks" - a."blocks") AS vac_block_diff, - NVL(e.empty_blk_cnt,0) AS empty_blk_cnt, - case when a.status ilike '%[VacuumBG]%' then true else false end is_auto_vacuum +CREATE OR REPLACE VIEW admin.v_vacuum_summary as SELECT a.userid + ,a.xid + ,d.datname::varchar AS database_name + ,a.table_id + ,c.name::varchar AS tablename + ,a.status::varchar AS vac_start_status + ,CASE WHEN a.status ilike 'skipped%' THEN null::TEXT + WHEN f.xid IS NOT NULL THEN 'Running'::TEXT + WHEN g.aborted = 1 THEN 'Aborted'::TEXT + WHEN b.status IS NULL and a.status not ilike '%[VacuumBG]%' THEN 'Failed'::TEXT + ELSE b.status::TEXT + END::TEXT AS vac_end_status + ,a.eventtime AS vac_start_time + ,CASE WHEN g.aborted = 1 THEN g.endtime + ELSE b.eventtime + END AS vac_end_time + ,CASE WHEN f.xid IS NOT NULL THEN datediff(s,vac_start_time,getdate()) + WHEN b.eventtime IS NOT NULL THEN datediff(s,vac_start_time,vac_end_time) + ELSE NULL + END AS vac_duration_secs + ,a."rows" AS vac_start_rows + ,b."rows" AS vac_end_rows + ,a."rows" - b."rows" AS vac_deleted_rows + ,a.sortedrows AS vac_start_sorted_rows + ,b.sortedrows AS vac_end_sorted_rows + ,a."blocks" AS vac_start_blocks + ,b."blocks" AS vac_end_blocks + ,(b."blocks" - a."blocks") AS vac_block_diff + ,NVL(e.empty_blk_cnt,0) AS empty_blk_cnt + ,CASE WHEN a.status ilike '%[VacuumBG]%' THEN true ELSE false END is_auto_vacuum + ,a.is_recluster + ,g.aborted FROM (SELECT * FROM stl_vacuum WHERE status not ilike '%Finished%') a - LEFT JOIN stl_vacuum b on a.xid=b.xid and a.table_id=b.table_id and a.eventtime < b.eventtime + LEFT JOIN stl_vacuum b on (a.xid,a.table_id) = (b.xid,b.table_id) and a.eventtime < b.eventtime LEFT JOIN (SELECT id,name,db_id FROM stv_tbl_perm WHERE slice = 0) c ON a.table_id = c.id LEFT JOIN pg_database d ON c.db_id::oid = d.oid LEFT JOIN (SELECT tbl,COUNT(*) AS empty_blk_cnt FROM stv_blocklist WHERE num_values = 0 GROUP BY tbl) e ON a.table_id = e.tbl LEFT JOIN (SELECT xid FROM svv_transactions WHERE lockable_object_type = 'transactionid') f on a.xid=f.xid + LEFT JOIN (select xid,max(endtime) as endtime,max(aborted) as aborted from stl_query group by 1) g on a.xid = g.xid ORDER BY a.xid; From 278cb4333289e73ba54f7df0ff92bf21a1777a11 Mon Sep 17 00:00:00 2001 From: Sathiish Kumar Date: Mon, 13 Feb 2023 15:14:38 -0800 Subject: [PATCH 05/49] Default database to cluster endpoint if not passed --- src/SimpleReplay/replay.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/SimpleReplay/replay.py b/src/SimpleReplay/replay.py index d783374e..a569f613 100644 --- a/src/SimpleReplay/replay.py +++ b/src/SimpleReplay/replay.py @@ -1342,6 +1342,7 @@ def get_connection_credentials(username, database=None, max_attempts=10, skip_ca cluster_host = cluster_endpoint.split(":")[0] cluster_port = cluster_endpoint_split[5].split("/")[0][4:] + database = cluster_endpoint_split[5].split("/")[1] if database is None else database additional_args = {} if os.environ.get('ENDPOINT_URL'): From 03264860e835c249db279d3523c2628b7115d3ca Mon Sep 17 00:00:00 2001 From: Saeed Mallak <105469500+saeedma8@users.noreply.github.com> Date: Tue, 21 Feb 2023 14:24:45 +1100 Subject: [PATCH 06/49] fix Issue #655 - stored proc params serverless --- src/.DS_Store | Bin 12292 -> 12292 bytes src/AdminViews/v_get_stored_proc_params.sql | 7 ++++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/.DS_Store b/src/.DS_Store index 06ba9822be7e123b6487e0b69e998dd527d76fa6..8e507b3aa992bb3f38be83091318a04160142a2f 100644 GIT binary patch delta 66 zcmZokXi1ph&*-x;U^hRb#>5F$lkcl?Zw?d)WS)FUL~(PsNCWp|1;!JbxfMRLv*$46 SGbA#kY-ZN@$<6`gFaQ7&9Th|X delta 256 zcmZokXi1ph&ls>VU^hRb&cq2;lkcl?Zw?d)WUl9D2xiD*NMtBrC}zlD$Y&^F@CEWf zBIyjN3`IHVhQZ1CxdjX$&}8NWBnjxq&3AE0DJ@B6V7Mvl_5h>}pAJ`$CAs-2BxnKY kD9Au^Rq==2b9AA0EO^8NdN!< diff --git a/src/AdminViews/v_get_stored_proc_params.sql b/src/AdminViews/v_get_stored_proc_params.sql index bdc76ebb..c4f195dc 100644 --- a/src/AdminViews/v_get_stored_proc_params.sql +++ b/src/AdminViews/v_get_stored_proc_params.sql @@ -2,6 +2,7 @@ Purpose: List all stored procedures with their input parameters History: 2020-04-15 joeharris76 Created +2023-02-20 saeedma8 added serverless prolang id **********************************************************************************************/ CREATE OR REPLACE VIEW admin.v_get_stored_proc_params AS @@ -17,7 +18,7 @@ AS (SELECT oid, arg_num , pronargs AS arg_count FROM pg_proc WHERE proowner != 1 - AND prolang = 100356 ) t) t) + AND prolang in (100356, 101857) ) t) t) SELECT n.nspname AS schema_name , p.proname AS proc_name , p.oid::INT AS proc_id @@ -28,5 +29,5 @@ FROM pg_proc p LEFT JOIN pg_namespace n ON n.oid = p.pronamespace LEFT JOIN arguments a ON a.oid = p.oid WHERE p.proowner != 1 - AND p.prolang = 100356 -ORDER BY 1,2,3,4; \ No newline at end of file + AND p.prolang in (100356, 101857) +ORDER BY 1,2,3,4; From b356fc69ee6022e54aff442253f491dd1f61e6ab Mon Sep 17 00:00:00 2001 From: sgromoll Date: Sat, 11 Mar 2023 17:20:39 -0500 Subject: [PATCH 07/49] Add TPC-H SF100 (#672) --- .../Cloud-DWB-Derived-from-TPCH/100GB/ddl.sql | 129 ++++ .../100GB/queries/query_0.sql | 675 ++++++++++++++++++ .../100GB/queries/query_1.sql | 675 ++++++++++++++++++ .../100GB/queries/query_10.sql | 675 ++++++++++++++++++ .../100GB/queries/query_2.sql | 675 ++++++++++++++++++ .../100GB/queries/query_3.sql | 675 ++++++++++++++++++ .../100GB/queries/query_4.sql | 675 ++++++++++++++++++ .../100GB/queries/query_5.sql | 675 ++++++++++++++++++ .../100GB/queries/query_6.sql | 675 ++++++++++++++++++ .../100GB/queries/query_7.sql | 675 ++++++++++++++++++ .../100GB/queries/query_8.sql | 675 ++++++++++++++++++ .../100GB/queries/query_9.sql | 675 ++++++++++++++++++ 12 files changed, 7554 insertions(+) create mode 100644 src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/100GB/ddl.sql create mode 100644 src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/100GB/queries/query_0.sql create mode 100644 src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/100GB/queries/query_1.sql create mode 100644 src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/100GB/queries/query_10.sql create mode 100644 src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/100GB/queries/query_2.sql create mode 100644 src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/100GB/queries/query_3.sql create mode 100644 src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/100GB/queries/query_4.sql create mode 100644 src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/100GB/queries/query_5.sql create mode 100644 src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/100GB/queries/query_6.sql create mode 100644 src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/100GB/queries/query_7.sql create mode 100644 src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/100GB/queries/query_8.sql create mode 100644 src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/100GB/queries/query_9.sql diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/100GB/ddl.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/100GB/ddl.sql new file mode 100644 index 00000000..b50df397 --- /dev/null +++ b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/100GB/ddl.sql @@ -0,0 +1,129 @@ +create table customer ( + c_custkey int8 not null , + c_name varchar(25) not null, + c_address varchar(40) not null, + c_nationkey int4 not null, + c_phone char(15) not null, + c_acctbal numeric(12,2) not null, + c_mktsegment char(10) not null, + c_comment varchar(117) not null, + Primary Key(C_CUSTKEY) +) distkey(c_custkey) sortkey(c_custkey); + +create table lineitem ( + l_orderkey int8 not null , + l_partkey int8 not null, + l_suppkey int4 not null, + l_linenumber int4 not null, + l_quantity numeric(12,2) not null, + l_extendedprice numeric(12,2) not null, + l_discount numeric(12,2) not null, + l_tax numeric(12,2) not null, + l_returnflag char(1) not null, + l_linestatus char(1) not null, + l_shipdate date not null , + l_commitdate date not null, + l_receiptdate date not null, + l_shipinstruct char(25) not null, + l_shipmode char(10) not null, + l_comment varchar(44) not null, + Primary Key(L_ORDERKEY, L_LINENUMBER) +) distkey(l_orderkey) sortkey(l_shipdate,l_orderkey) ; + +create table nation ( + n_nationkey int4 not null, + n_name char(25) not null , + n_regionkey int4 not null, + n_comment varchar(152) not null, + Primary Key(N_NATIONKEY) +) distkey(n_nationkey) sortkey(n_nationkey) ; + +create table orders ( + o_orderkey int8 not null, + o_custkey int8 not null, + o_orderstatus char(1) not null, + o_totalprice numeric(12,2) not null, + o_orderdate date not null, + o_orderpriority char(15) not null, + o_clerk char(15) not null, + o_shippriority int4 not null, + o_comment varchar(79) not null, + Primary Key(O_ORDERKEY) +) distkey(o_orderkey) sortkey(o_orderdate, o_orderkey) ; + +create table part ( + p_partkey int8 not null , + p_name varchar(55) not null, + p_mfgr char(25) not null, + p_brand char(10) not null, + p_type varchar(25) not null, + p_size int4 not null, + p_container char(10) not null, + p_retailprice numeric(12,2) not null, + p_comment varchar(23) not null, + PRIMARY KEY (P_PARTKEY) +) distkey(p_partkey) sortkey(p_partkey); + +create table partsupp ( + ps_partkey int8 not null, + ps_suppkey int4 not null, + ps_availqty int4 not null, + ps_supplycost numeric(12,2) not null, + ps_comment varchar(199) not null, + Primary Key(PS_PARTKEY, PS_SUPPKEY) +) distkey(ps_partkey) sortkey(ps_partkey); + +create table region ( + r_regionkey int4 not null, + r_name char(25) not null , + r_comment varchar(152) not null, + Primary Key(R_REGIONKEY) +) distkey(r_regionkey) sortkey(r_regionkey); + +create table supplier ( + s_suppkey int4 not null, + s_name char(25) not null, + s_address varchar(40) not null, + s_nationkey int4 not null, + s_phone char(15) not null, + s_acctbal numeric(12,2) not null, + s_comment varchar(101) not null, + Primary Key(S_SUPPKEY) +) distkey(s_suppkey) sortkey(s_suppkey) +; + +/* +Text files needed to load test data under s3://redshift-downloads/TPC-H/100GB are publicly available. Any valid credentials can be used to access the files. + +To load the sample data, you must provide authentication for your cluster to access Amazon S3 on your behalf. + +You can provide authentication by referencing an IAM role that you have created. You can set an IAM_Role as the default for your cluster or you can directly provide the ARN of an IAM_Role. +For more information https://docs.aws.amazon.com/redshift/latest/mgmt/authorizing-redshift-service.html + +The COPY commands include a placeholder for IAM_Role, in this code IAM_Role clause is set to use the default IAM_Role. If your cluster does not have a IAM_Role set as default then please follow the instructions provided here: + +https://docs.aws.amazon.com/redshift/latest/mgmt/default-iam-role.html + +For more information check samples in https://docs.aws.amazon.com/redshift/latest/gsg/rs-gsg-create-sample-db.html + +**Note** another option to provide IAM_Role is to provide IAM_Role ARN in IAM_Role clause. For example +copy region from's3://redshift-downloads/TPC-H/100GB/region/' IAM_Role 'Replace text inside the quotes with Redshift cluster IAM_Role ARN' gzip delimiter '|'; +*/ + +copy region from 's3://redshift-downloads/TPC-H/2.18/100GB/region/' iam_role default delimiter '|'; +copy nation from 's3://redshift-downloads/TPC-H/2.18/100GB/nation/' iam_role default delimiter '|'; +copy lineitem from 's3://redshift-downloads/TPC-H/2.18/100GB/lineitem/' iam_role default delimiter '|'; +copy orders from 's3://redshift-downloads/TPC-H/2.18/100GB/orders/' iam_role default delimiter '|'; +copy part from 's3://redshift-downloads/TPC-H/2.18/100GB/part/' iam_role default delimiter '|'; +copy supplier from 's3://redshift-downloads/TPC-H/2.18/100GB/supplier/' iam_role default delimiter '|'; +copy partsupp from 's3://redshift-downloads/TPC-H/2.18/100GB/partsupp/' iam_role default delimiter '|'; +copy customer from 's3://redshift-downloads/TPC-H/2.18/100GB/customer/' iam_role default delimiter '|'; + +select count(*) from customer; +select count(*) from lineitem; +select count(*) from nation; +select count(*) from orders; +select count(*) from part; +select count(*) from partsupp; +select count(*) from region; +select count(*) from supplier; diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/100GB/queries/query_0.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/100GB/queries/query_0.sql new file mode 100644 index 00000000..83671387 --- /dev/null +++ b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/100GB/queries/query_0.sql @@ -0,0 +1,675 @@ +-- using default substitutions + + +select /* TPC-H Q14 */ + 100.00 * sum(case + when p_type like 'PROMO%' + then l_extendedprice * (1 - l_discount) + else 0 + end) / sum(l_extendedprice * (1 - l_discount)) as promo_revenue +from + lineitem, + part +where + l_partkey = p_partkey + and l_shipdate >= date '1995-09-01' + and l_shipdate < dateadd(month, 1, cast('1995-09-01' as date)) +; + + +select /* TPC-H Q2 */ + s_acctbal, + s_name, + n_name, + p_partkey, + p_mfgr, + s_address, + s_phone, + s_comment +from + part, + supplier, + partsupp, + nation, + region +where + p_partkey = ps_partkey + and s_suppkey = ps_suppkey + and p_size = 15 + and p_type like '%BRASS' + and s_nationkey = n_nationkey + and n_regionkey = r_regionkey + and r_name = 'EUROPE' + and ps_supplycost = ( + select + min(ps_supplycost) + from + partsupp, + supplier, + nation, + region + where + p_partkey = ps_partkey + and s_suppkey = ps_suppkey + and s_nationkey = n_nationkey + and n_regionkey = r_regionkey + and r_name = 'EUROPE' + ) +order by + s_acctbal desc, + n_name, + s_name, + p_partkey +limit 100; + + +select /* TPC-H Q9 */ + nation, + o_year, + sum(amount) as sum_profit +from + ( + select + n_name as nation, + extract(year from o_orderdate) as o_year, + l_extendedprice * (1 - l_discount) - ps_supplycost * l_quantity as amount + from + part, + supplier, + lineitem, + partsupp, + orders, + nation + where + s_suppkey = l_suppkey + and ps_suppkey = l_suppkey + and ps_partkey = l_partkey + and p_partkey = l_partkey + and o_orderkey = l_orderkey + and s_nationkey = n_nationkey + and p_name like '%green%' + ) as profit +group by + nation, + o_year +order by + nation, + o_year desc; + + +select /* TPC-H Q20 */ + s_name, + s_address +from + supplier, + nation +where + s_suppkey in ( + select + ps_suppkey + from + partsupp + where + ps_partkey in ( + select + p_partkey + from + part + where + p_name like 'forest%' + ) + and ps_availqty > ( + select + 0.5 * sum(l_quantity) + from + lineitem + where + l_partkey = ps_partkey + and l_suppkey = ps_suppkey + and l_shipdate >= date '1994-01-01' + and l_shipdate < dateadd(year, 1, cast('1994-01-01' as date)) + ) + ) + and s_nationkey = n_nationkey + and n_name = 'CANADA' +order by + s_name; + + +select /* TPC-H Q6 */ + sum(l_extendedprice * l_discount) as revenue +from + lineitem +where + l_shipdate >= date '1994-01-01' + and l_shipdate < dateadd(year, 1, cast('1994-01-01' as date)) + and l_discount between .06 - 0.01 and .06 + 0.01 + and l_quantity < 24; + + +select /* TPC-H Q17 */ + sum(l_extendedprice) / 7.0 as avg_yearly +from + lineitem, + part +where + p_partkey = l_partkey + and p_brand = 'Brand#23' + and p_container = 'MED BOX' + and l_quantity < ( + select + 0.2 * avg(l_quantity) + from + lineitem + where + l_partkey = p_partkey + ); + + +select /* TPC-H Q18 */ + c_name, + c_custkey, + o_orderkey, + o_orderdate, + o_totalprice, + sum(l_quantity) +from + customer, + orders, + lineitem +where + o_orderkey in ( + select + l_orderkey + from + lineitem + group by + l_orderkey having + sum(l_quantity) > 300 + ) + and c_custkey = o_custkey + and o_orderkey = l_orderkey +group by + c_name, + c_custkey, + o_orderkey, + o_orderdate, + o_totalprice +order by + o_totalprice desc, + o_orderdate +limit 100; + + +select /* TPC-H Q8 */ + o_year, + sum(case + when nation = 'BRAZIL' then volume + else 0 + end) / sum(volume) as mkt_share +from + ( + select + extract(year from o_orderdate) as o_year, + l_extendedprice * (1 - l_discount) as volume, + n2.n_name as nation + from + part, + supplier, + lineitem, + orders, + customer, + nation n1, + nation n2, + region + where + p_partkey = l_partkey + and s_suppkey = l_suppkey + and l_orderkey = o_orderkey + and o_custkey = c_custkey + and c_nationkey = n1.n_nationkey + and n1.n_regionkey = r_regionkey + and r_name = 'AMERICA' + and s_nationkey = n2.n_nationkey + and o_orderdate between date '1995-01-01' and date '1996-12-31' + and p_type = 'ECONOMY ANODIZED STEEL' + ) as all_nations +group by + o_year +order by + o_year; + + +select /* TPC-H Q21 */ + s_name, + count(*) as numwait +from + supplier, + lineitem l1, + orders, + nation +where + s_suppkey = l1.l_suppkey + and o_orderkey = l1.l_orderkey + and o_orderstatus = 'F' + and l1.l_receiptdate > l1.l_commitdate + and exists ( + select + * + from + lineitem l2 + where + l2.l_orderkey = l1.l_orderkey + and l2.l_suppkey <> l1.l_suppkey + ) + and not exists ( + select + * + from + lineitem l3 + where + l3.l_orderkey = l1.l_orderkey + and l3.l_suppkey <> l1.l_suppkey + and l3.l_receiptdate > l3.l_commitdate + ) + and s_nationkey = n_nationkey + and n_name = 'SAUDI ARABIA' +group by + s_name +order by + numwait desc, + s_name +limit 100; + + +select /* TPC-H Q13 */ + c_count, + count(*) as custdist +from + ( + select + c_custkey, + count(o_orderkey) + from + customer left outer join orders on + c_custkey = o_custkey + and o_comment not like '%special%requests%' + group by + c_custkey + ) as c_orders (c_custkey, c_count) +group by + c_count +order by + custdist desc, + c_count desc; + + +select /* TPC-H Q3 */ + l_orderkey, + sum(l_extendedprice * (1 - l_discount)) as revenue, + o_orderdate, + o_shippriority +from + customer, + orders, + lineitem +where + c_mktsegment = 'BUILDING' + and c_custkey = o_custkey + and l_orderkey = o_orderkey + and o_orderdate < date '1995-03-15' + and l_shipdate > date '1995-03-15' +group by + l_orderkey, + o_orderdate, + o_shippriority +order by + revenue desc, + o_orderdate +limit 10; + + +select /* TPC-H Q22 */ + cntrycode, + count(*) as numcust, + sum(c_acctbal) as totacctbal +from + ( + select + substring(c_phone,1,2) as cntrycode, + c_acctbal + from + customer + where + substring(c_phone,1,2) in + ('13', '31', '23', '29', '30', '18', '17') + and c_acctbal > ( + select + avg(c_acctbal) + from + customer + where + c_acctbal > 0.00 + and substring(c_phone,1,2) in + ('13', '31', '23', '29', '30', '18', '17') + ) + and not exists ( + select + * + from + orders + where + o_custkey = c_custkey + ) + ) as custsale +group by + cntrycode +order by + cntrycode; + + +select /* TPC-H Q16 */ + p_brand, + p_type, + p_size, + count(distinct ps_suppkey) as supplier_cnt +from + partsupp, + part +where + p_partkey = ps_partkey + and p_brand <> 'Brand#45' + and p_type not like 'MEDIUM POLISHED%' + and p_size in (49, 14, 23, 45, 19, 3, 36, 9) + and ps_suppkey not in ( + select + s_suppkey + from + supplier + where + s_comment like '%Customer%Complaints%' + ) +group by + p_brand, + p_type, + p_size +order by + supplier_cnt desc, + p_brand, + p_type, + p_size; + + +select /* TPC-H Q4 */ + o_orderpriority, + count(*) as order_count +from + orders +where + o_orderdate >= date '1993-07-01' + and o_orderdate < dateadd(month, 3, cast('1993-07-01' as date)) + and exists ( + select + * + from + lineitem + where + l_orderkey = o_orderkey + and l_commitdate < l_receiptdate + ) +group by + o_orderpriority +order by + o_orderpriority; + + +select /* TPC-H Q11 */ + ps_partkey, + sum(ps_supplycost * ps_availqty) as value +from + partsupp, + supplier, + nation +where + ps_suppkey = s_suppkey + and s_nationkey = n_nationkey + and n_name = 'GERMANY' +group by + ps_partkey having + sum(ps_supplycost * ps_availqty) > ( + select + sum(ps_supplycost * ps_availqty) * 0.0000010000 + from + partsupp, + supplier, + nation + where + ps_suppkey = s_suppkey + and s_nationkey = n_nationkey + and n_name = 'GERMANY' + ) +order by + value desc; + +with revenue as ( + select + l_suppkey as supplier_no, + sum(l_extendedprice * (1-l_discount)) as total_revenue + from + lineitem + where + l_shipdate >= date '1996-01-01' + and l_shipdate < dateadd(month, 3, cast('1996-01-01' as date)) + group by + l_suppkey +) +select /* TPC-H Q15 */ + s_suppkey, + s_name, + s_address, + s_phone, + total_revenue +from + supplier, + revenue +where + s_suppkey = supplier_no + and total_revenue = ( + select + max(total_revenue) + from + revenue + ) +order by + s_suppkey; + + +select /* TPC-H Q1 */ + l_returnflag, + l_linestatus, + sum(l_quantity) as sum_qty, + sum(l_extendedprice) as sum_base_price, + sum(l_extendedprice * (1 - l_discount)) as sum_disc_price, + sum(l_extendedprice * (1 - l_discount) * (1 + l_tax)) as sum_charge, + avg(l_quantity) as avg_qty, + avg(l_extendedprice) as avg_price, + avg(l_discount) as avg_disc, + count(*) as count_order +from + lineitem +where + l_shipdate <= dateadd(day, -90, cast('1998-12-01' as date)) +group by + l_returnflag, + l_linestatus +order by + l_returnflag, + l_linestatus; + + +select /* TPC-H Q10 */ + c_custkey, + c_name, + sum(l_extendedprice * (1 - l_discount)) as revenue, + c_acctbal, + n_name, + c_address, + c_phone, + c_comment +from + customer, + orders, + lineitem, + nation +where + c_custkey = o_custkey + and l_orderkey = o_orderkey + and o_orderdate >= date '1993-10-01' + and o_orderdate < dateadd(month, 3, cast('1993-10-01' as date)) + and l_returnflag = 'R' + and c_nationkey = n_nationkey +group by + c_custkey, + c_name, + c_acctbal, + c_phone, + n_name, + c_address, + c_comment +order by + revenue desc +limit 20; + + +select /* TPC-H Q19 */ + sum(l_extendedprice* (1 - l_discount)) as revenue +from + lineitem, + part +where + ( + p_partkey = l_partkey + and p_brand = 'Brand#12' + and p_container in ('SM CASE', 'SM BOX', 'SM PACK', 'SM PKG') + and l_quantity >= 1 and l_quantity <= 1 + 10 + and p_size between 1 and 5 + and l_shipmode in ('AIR', 'AIR REG') + and l_shipinstruct = 'DELIVER IN PERSON' + ) + or + ( + p_partkey = l_partkey + and p_brand = 'Brand#23' + and p_container in ('MED BAG', 'MED BOX', 'MED PKG', 'MED PACK') + and l_quantity >= 10 and l_quantity <= 10 + 10 + and p_size between 1 and 10 + and l_shipmode in ('AIR', 'AIR REG') + and l_shipinstruct = 'DELIVER IN PERSON' + ) + or + ( + p_partkey = l_partkey + and p_brand = 'Brand#34' + and p_container in ('LG CASE', 'LG BOX', 'LG PACK', 'LG PKG') + and l_quantity >= 20 and l_quantity <= 20 + 10 + and p_size between 1 and 15 + and l_shipmode in ('AIR', 'AIR REG') + and l_shipinstruct = 'DELIVER IN PERSON' + ); + + +select /* TPC-H Q5 */ + n_name, + sum(l_extendedprice * (1 - l_discount)) as revenue +from + customer, + orders, + lineitem, + supplier, + nation, + region +where + c_custkey = o_custkey + and l_orderkey = o_orderkey + and l_suppkey = s_suppkey + and c_nationkey = s_nationkey + and s_nationkey = n_nationkey + and n_regionkey = r_regionkey + and r_name = 'ASIA' + and o_orderdate >= date '1994-01-01' + and o_orderdate < dateadd(year, 1, cast('1994-01-01' as date)) +group by + n_name +order by + revenue desc; + + +select /* TPC-H Q7 */ + supp_nation, + cust_nation, + l_year, + sum(volume) as revenue +from + ( + select + n1.n_name as supp_nation, + n2.n_name as cust_nation, + extract(year from l_shipdate) as l_year, + l_extendedprice * (1 - l_discount) as volume + from + supplier, + lineitem, + orders, + customer, + nation n1, + nation n2 + where + s_suppkey = l_suppkey + and o_orderkey = l_orderkey + and c_custkey = o_custkey + and s_nationkey = n1.n_nationkey + and c_nationkey = n2.n_nationkey + and ( + (n1.n_name = 'FRANCE' and n2.n_name = 'GERMANY') + or (n1.n_name = 'GERMANY' and n2.n_name = 'FRANCE') + ) + and l_shipdate between date '1995-01-01' and date '1996-12-31' + ) as shipping +group by + supp_nation, + cust_nation, + l_year +order by + supp_nation, + cust_nation, + l_year; + + +select /* TPC-H Q12 */ + l_shipmode, + sum(case + when o_orderpriority = '1-URGENT' + or o_orderpriority = '2-HIGH' + then 1 + else 0 + end) as high_line_count, + sum(case + when o_orderpriority <> '1-URGENT' + and o_orderpriority <> '2-HIGH' + then 1 + else 0 + end) as low_line_count +from + orders, + lineitem +where + o_orderkey = l_orderkey + and l_shipmode in ('MAIL', 'SHIP') + and l_commitdate < l_receiptdate + and l_shipdate < l_commitdate + and l_receiptdate >= date '1994-01-01' + and l_receiptdate < dateadd(year, 1, cast('1994-01-01' as date)) +group by + l_shipmode +order by + l_shipmode; diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/100GB/queries/query_1.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/100GB/queries/query_1.sql new file mode 100644 index 00000000..5a1f2f76 --- /dev/null +++ b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/100GB/queries/query_1.sql @@ -0,0 +1,675 @@ +-- using 1 as a seed to the RNG + + +select /* TPC-H Q21 */ + s_name, + count(*) as numwait +from + supplier, + lineitem l1, + orders, + nation +where + s_suppkey = l1.l_suppkey + and o_orderkey = l1.l_orderkey + and o_orderstatus = 'F' + and l1.l_receiptdate > l1.l_commitdate + and exists ( + select + * + from + lineitem l2 + where + l2.l_orderkey = l1.l_orderkey + and l2.l_suppkey <> l1.l_suppkey + ) + and not exists ( + select + * + from + lineitem l3 + where + l3.l_orderkey = l1.l_orderkey + and l3.l_suppkey <> l1.l_suppkey + and l3.l_receiptdate > l3.l_commitdate + ) + and s_nationkey = n_nationkey + and n_name = 'PERU' +group by + s_name +order by + numwait desc, + s_name +limit 100; + + +select /* TPC-H Q3 */ + l_orderkey, + sum(l_extendedprice * (1 - l_discount)) as revenue, + o_orderdate, + o_shippriority +from + customer, + orders, + lineitem +where + c_mktsegment = 'FURNITURE' + and c_custkey = o_custkey + and l_orderkey = o_orderkey + and o_orderdate < date '1995-03-17' + and l_shipdate > date '1995-03-17' +group by + l_orderkey, + o_orderdate, + o_shippriority +order by + revenue desc, + o_orderdate +limit 10; + + +select /* TPC-H Q18 */ + c_name, + c_custkey, + o_orderkey, + o_orderdate, + o_totalprice, + sum(l_quantity) +from + customer, + orders, + lineitem +where + o_orderkey in ( + select + l_orderkey + from + lineitem + group by + l_orderkey having + sum(l_quantity) > 313 + ) + and c_custkey = o_custkey + and o_orderkey = l_orderkey +group by + c_name, + c_custkey, + o_orderkey, + o_orderdate, + o_totalprice +order by + o_totalprice desc, + o_orderdate +limit 100; + + +select /* TPC-H Q5 */ + n_name, + sum(l_extendedprice * (1 - l_discount)) as revenue +from + customer, + orders, + lineitem, + supplier, + nation, + region +where + c_custkey = o_custkey + and l_orderkey = o_orderkey + and l_suppkey = s_suppkey + and c_nationkey = s_nationkey + and s_nationkey = n_nationkey + and n_regionkey = r_regionkey + and r_name = 'AMERICA' + and o_orderdate >= date '1993-01-01' + and o_orderdate < dateadd(year, 1, cast('1993-01-01' as date)) +group by + n_name +order by + revenue desc; + + +select /* TPC-H Q11 */ + ps_partkey, + sum(ps_supplycost * ps_availqty) as value +from + partsupp, + supplier, + nation +where + ps_suppkey = s_suppkey + and s_nationkey = n_nationkey + and n_name = 'JAPAN' +group by + ps_partkey having + sum(ps_supplycost * ps_availqty) > ( + select + sum(ps_supplycost * ps_availqty) * 0.0000010000 + from + partsupp, + supplier, + nation + where + ps_suppkey = s_suppkey + and s_nationkey = n_nationkey + and n_name = 'JAPAN' + ) +order by + value desc; + + +select /* TPC-H Q7 */ + supp_nation, + cust_nation, + l_year, + sum(volume) as revenue +from + ( + select + n1.n_name as supp_nation, + n2.n_name as cust_nation, + extract(year from l_shipdate) as l_year, + l_extendedprice * (1 - l_discount) as volume + from + supplier, + lineitem, + orders, + customer, + nation n1, + nation n2 + where + s_suppkey = l_suppkey + and o_orderkey = l_orderkey + and c_custkey = o_custkey + and s_nationkey = n1.n_nationkey + and c_nationkey = n2.n_nationkey + and ( + (n1.n_name = 'MOZAMBIQUE' and n2.n_name = 'UNITED KINGDOM') + or (n1.n_name = 'UNITED KINGDOM' and n2.n_name = 'MOZAMBIQUE') + ) + and l_shipdate between date '1995-01-01' and date '1996-12-31' + ) as shipping +group by + supp_nation, + cust_nation, + l_year +order by + supp_nation, + cust_nation, + l_year; + + +select /* TPC-H Q6 */ + sum(l_extendedprice * l_discount) as revenue +from + lineitem +where + l_shipdate >= date '1993-01-01' + and l_shipdate < dateadd(year, 1, cast('1993-01-01' as date)) + and l_discount between 0.07 - 0.01 and 0.07 + 0.01 + and l_quantity < 25; + + +select /* TPC-H Q20 */ + s_name, + s_address +from + supplier, + nation +where + s_suppkey in ( + select + ps_suppkey + from + partsupp + where + ps_partkey in ( + select + p_partkey + from + part + where + p_name like 'ivory%' + ) + and ps_availqty > ( + select + 0.5 * sum(l_quantity) + from + lineitem + where + l_partkey = ps_partkey + and l_suppkey = ps_suppkey + and l_shipdate >= date '1996-01-01' + and l_shipdate < dateadd(year, 1, cast('1996-01-01' as date)) + ) + ) + and s_nationkey = n_nationkey + and n_name = 'KENYA' +order by + s_name; + + +select /* TPC-H Q17 */ + sum(l_extendedprice) / 7.0 as avg_yearly +from + lineitem, + part +where + p_partkey = l_partkey + and p_brand = 'Brand#12' + and p_container = 'SM BAG' + and l_quantity < ( + select + 0.2 * avg(l_quantity) + from + lineitem + where + l_partkey = p_partkey + ); + + +select /* TPC-H Q12 */ + l_shipmode, + sum(case + when o_orderpriority = '1-URGENT' + or o_orderpriority = '2-HIGH' + then 1 + else 0 + end) as high_line_count, + sum(case + when o_orderpriority <> '1-URGENT' + and o_orderpriority <> '2-HIGH' + then 1 + else 0 + end) as low_line_count +from + orders, + lineitem +where + o_orderkey = l_orderkey + and l_shipmode in ('FOB', 'REG AIR') + and l_commitdate < l_receiptdate + and l_shipdate < l_commitdate + and l_receiptdate >= date '1993-01-01' + and l_receiptdate < dateadd(year, 1, cast('1993-01-01' as date)) +group by + l_shipmode +order by + l_shipmode; + + +select /* TPC-H Q16 */ + p_brand, + p_type, + p_size, + count(distinct ps_suppkey) as supplier_cnt +from + partsupp, + part +where + p_partkey = ps_partkey + and p_brand <> 'Brand#41' + and p_type not like 'MEDIUM BURNISHED%' + and p_size in (4, 22, 35, 31, 47, 44, 30, 11) + and ps_suppkey not in ( + select + s_suppkey + from + supplier + where + s_comment like '%Customer%Complaints%' + ) +group by + p_brand, + p_type, + p_size +order by + supplier_cnt desc, + p_brand, + p_type, + p_size; + +with revenue as ( + select + l_suppkey as supplier_no, + sum(l_extendedprice * (1-l_discount)) as total_revenue + from + lineitem + where + l_shipdate >= date '1995-07-01' + and l_shipdate < dateadd(month, 3, cast('1995-07-01' as date)) + group by + l_suppkey +) +select /* TPC-H Q15 */ + s_suppkey, + s_name, + s_address, + s_phone, + total_revenue +from + supplier, + revenue +where + s_suppkey = supplier_no + and total_revenue = ( + select + max(total_revenue) + from + revenue + ) +order by + s_suppkey; + + +select /* TPC-H Q13 */ + c_count, + count(*) as custdist +from + ( + select + c_custkey, + count(o_orderkey) + from + customer left outer join orders on + c_custkey = o_custkey + and o_comment not like '%special%packages%' + group by + c_custkey + ) as c_orders (c_custkey, c_count) +group by + c_count +order by + custdist desc, + c_count desc; + + +select /* TPC-H Q10 */ + c_custkey, + c_name, + sum(l_extendedprice * (1 - l_discount)) as revenue, + c_acctbal, + n_name, + c_address, + c_phone, + c_comment +from + customer, + orders, + lineitem, + nation +where + c_custkey = o_custkey + and l_orderkey = o_orderkey + and o_orderdate >= date '1993-11-01' + and o_orderdate < dateadd(month, 3, cast('1993-11-01' as date)) + and l_returnflag = 'R' + and c_nationkey = n_nationkey +group by + c_custkey, + c_name, + c_acctbal, + c_phone, + n_name, + c_address, + c_comment +order by + revenue desc +limit 20; + + +select /* TPC-H Q2 */ + s_acctbal, + s_name, + n_name, + p_partkey, + p_mfgr, + s_address, + s_phone, + s_comment +from + part, + supplier, + partsupp, + nation, + region +where + p_partkey = ps_partkey + and s_suppkey = ps_suppkey + and p_size = 38 + and p_type like '%STEEL' + and s_nationkey = n_nationkey + and n_regionkey = r_regionkey + and r_name = 'ASIA' + and ps_supplycost = ( + select + min(ps_supplycost) + from + partsupp, + supplier, + nation, + region + where + p_partkey = ps_partkey + and s_suppkey = ps_suppkey + and s_nationkey = n_nationkey + and n_regionkey = r_regionkey + and r_name = 'ASIA' + ) +order by + s_acctbal desc, + n_name, + s_name, + p_partkey +limit 100; + + +select /* TPC-H Q8 */ + o_year, + sum(case + when nation = 'MOZAMBIQUE' then volume + else 0 + end) / sum(volume) as mkt_share +from + ( + select + extract(year from o_orderdate) as o_year, + l_extendedprice * (1 - l_discount) as volume, + n2.n_name as nation + from + part, + supplier, + lineitem, + orders, + customer, + nation n1, + nation n2, + region + where + p_partkey = l_partkey + and s_suppkey = l_suppkey + and l_orderkey = o_orderkey + and o_custkey = c_custkey + and c_nationkey = n1.n_nationkey + and n1.n_regionkey = r_regionkey + and r_name = 'AFRICA' + and s_nationkey = n2.n_nationkey + and o_orderdate between date '1995-01-01' and date '1996-12-31' + and p_type = 'PROMO POLISHED TIN' + ) as all_nations +group by + o_year +order by + o_year; + + +select /* TPC-H Q14 */ + 100.00 * sum(case + when p_type like 'PROMO%' + then l_extendedprice * (1 - l_discount) + else 0 + end) / sum(l_extendedprice * (1 - l_discount)) as promo_revenue +from + lineitem, + part +where + l_partkey = p_partkey + and l_shipdate >= date '1993-04-01' + and l_shipdate < dateadd(month, 1, cast('1993-04-01' as date)) +; + + +select /* TPC-H Q19 */ + sum(l_extendedprice* (1 - l_discount)) as revenue +from + lineitem, + part +where + ( + p_partkey = l_partkey + and p_brand = 'Brand#13' + and p_container in ('SM CASE', 'SM BOX', 'SM PACK', 'SM PKG') + and l_quantity >= 6 and l_quantity <= 6 + 10 + and p_size between 1 and 5 + and l_shipmode in ('AIR', 'AIR REG') + and l_shipinstruct = 'DELIVER IN PERSON' + ) + or + ( + p_partkey = l_partkey + and p_brand = 'Brand#43' + and p_container in ('MED BAG', 'MED BOX', 'MED PKG', 'MED PACK') + and l_quantity >= 11 and l_quantity <= 11 + 10 + and p_size between 1 and 10 + and l_shipmode in ('AIR', 'AIR REG') + and l_shipinstruct = 'DELIVER IN PERSON' + ) + or + ( + p_partkey = l_partkey + and p_brand = 'Brand#55' + and p_container in ('LG CASE', 'LG BOX', 'LG PACK', 'LG PKG') + and l_quantity >= 27 and l_quantity <= 27 + 10 + and p_size between 1 and 15 + and l_shipmode in ('AIR', 'AIR REG') + and l_shipinstruct = 'DELIVER IN PERSON' + ); + + +select /* TPC-H Q9 */ + nation, + o_year, + sum(amount) as sum_profit +from + ( + select + n_name as nation, + extract(year from o_orderdate) as o_year, + l_extendedprice * (1 - l_discount) - ps_supplycost * l_quantity as amount + from + part, + supplier, + lineitem, + partsupp, + orders, + nation + where + s_suppkey = l_suppkey + and ps_suppkey = l_suppkey + and ps_partkey = l_partkey + and p_partkey = l_partkey + and o_orderkey = l_orderkey + and s_nationkey = n_nationkey + and p_name like '%thistle%' + ) as profit +group by + nation, + o_year +order by + nation, + o_year desc; + + +select /* TPC-H Q22 */ + cntrycode, + count(*) as numcust, + sum(c_acctbal) as totacctbal +from + ( + select + substring(c_phone,1,2) as cntrycode, + c_acctbal + from + customer + where + substring(c_phone,1,2) in + ('24', '33', '31', '10', '15', '28', '23') + and c_acctbal > ( + select + avg(c_acctbal) + from + customer + where + c_acctbal > 0.00 + and substring(c_phone,1,2) in + ('24', '33', '31', '10', '15', '28', '23') + ) + and not exists ( + select + * + from + orders + where + o_custkey = c_custkey + ) + ) as custsale +group by + cntrycode +order by + cntrycode; + + +select /* TPC-H Q1 */ + l_returnflag, + l_linestatus, + sum(l_quantity) as sum_qty, + sum(l_extendedprice) as sum_base_price, + sum(l_extendedprice * (1 - l_discount)) as sum_disc_price, + sum(l_extendedprice * (1 - l_discount) * (1 + l_tax)) as sum_charge, + avg(l_quantity) as avg_qty, + avg(l_extendedprice) as avg_price, + avg(l_discount) as avg_disc, + count(*) as count_order +from + lineitem +where + l_shipdate <= dateadd(day, -68, cast('1998-12-01' as date)) +group by + l_returnflag, + l_linestatus +order by + l_returnflag, + l_linestatus; + + +select /* TPC-H Q4 */ + o_orderpriority, + count(*) as order_count +from + orders +where + o_orderdate >= date '1995-07-01' + and o_orderdate < dateadd(month, 3, cast('1995-07-01' as date)) + and exists ( + select + * + from + lineitem + where + l_orderkey = o_orderkey + and l_commitdate < l_receiptdate + ) +group by + o_orderpriority +order by + o_orderpriority; diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/100GB/queries/query_10.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/100GB/queries/query_10.sql new file mode 100644 index 00000000..7ae32ae4 --- /dev/null +++ b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/100GB/queries/query_10.sql @@ -0,0 +1,675 @@ +-- using 10 as a seed to the RNG + + +select /* TPC-H Q6 */ + sum(l_extendedprice * l_discount) as revenue +from + lineitem +where + l_shipdate >= date '1995-01-01' + and l_shipdate < dateadd(year, 1, cast('1995-01-01' as date)) + and l_discount between 0.08 - 0.01 and 0.08 + 0.01 + and l_quantity < 25; + +with revenue as ( + select + l_suppkey as supplier_no, + sum(l_extendedprice * (1-l_discount)) as total_revenue + from + lineitem + where + l_shipdate >= date '1994-06-01' + and l_shipdate < dateadd(month, 3, cast('1994-06-01' as date)) + group by + l_suppkey +) +select /* TPC-H Q15 */ + s_suppkey, + s_name, + s_address, + s_phone, + total_revenue +from + supplier, + revenue +where + s_suppkey = supplier_no + and total_revenue = ( + select + max(total_revenue) + from + revenue + ) +order by + s_suppkey; + + +select /* TPC-H Q18 */ + c_name, + c_custkey, + o_orderkey, + o_orderdate, + o_totalprice, + sum(l_quantity) +from + customer, + orders, + lineitem +where + o_orderkey in ( + select + l_orderkey + from + lineitem + group by + l_orderkey having + sum(l_quantity) > 315 + ) + and c_custkey = o_custkey + and o_orderkey = l_orderkey +group by + c_name, + c_custkey, + o_orderkey, + o_orderdate, + o_totalprice +order by + o_totalprice desc, + o_orderdate +limit 100; + + +select /* TPC-H Q17 */ + sum(l_extendedprice) / 7.0 as avg_yearly +from + lineitem, + part +where + p_partkey = l_partkey + and p_brand = 'Brand#15' + and p_container = 'JUMBO BAG' + and l_quantity < ( + select + 0.2 * avg(l_quantity) + from + lineitem + where + l_partkey = p_partkey + ); + + +select /* TPC-H Q12 */ + l_shipmode, + sum(case + when o_orderpriority = '1-URGENT' + or o_orderpriority = '2-HIGH' + then 1 + else 0 + end) as high_line_count, + sum(case + when o_orderpriority <> '1-URGENT' + and o_orderpriority <> '2-HIGH' + then 1 + else 0 + end) as low_line_count +from + orders, + lineitem +where + o_orderkey = l_orderkey + and l_shipmode in ('RAIL', 'TRUCK') + and l_commitdate < l_receiptdate + and l_shipdate < l_commitdate + and l_receiptdate >= date '1994-01-01' + and l_receiptdate < dateadd(year, 1, cast('1994-01-01' as date)) +group by + l_shipmode +order by + l_shipmode; + + +select /* TPC-H Q1 */ + l_returnflag, + l_linestatus, + sum(l_quantity) as sum_qty, + sum(l_extendedprice) as sum_base_price, + sum(l_extendedprice * (1 - l_discount)) as sum_disc_price, + sum(l_extendedprice * (1 - l_discount) * (1 + l_tax)) as sum_charge, + avg(l_quantity) as avg_qty, + avg(l_extendedprice) as avg_price, + avg(l_discount) as avg_disc, + count(*) as count_order +from + lineitem +where + l_shipdate <= dateadd(day, -79, cast('1998-12-01' as date)) +group by + l_returnflag, + l_linestatus +order by + l_returnflag, + l_linestatus; + + +select /* TPC-H Q7 */ + supp_nation, + cust_nation, + l_year, + sum(volume) as revenue +from + ( + select + n1.n_name as supp_nation, + n2.n_name as cust_nation, + extract(year from l_shipdate) as l_year, + l_extendedprice * (1 - l_discount) as volume + from + supplier, + lineitem, + orders, + customer, + nation n1, + nation n2 + where + s_suppkey = l_suppkey + and o_orderkey = l_orderkey + and c_custkey = o_custkey + and s_nationkey = n1.n_nationkey + and c_nationkey = n2.n_nationkey + and ( + (n1.n_name = 'ROMANIA' and n2.n_name = 'INDIA') + or (n1.n_name = 'INDIA' and n2.n_name = 'ROMANIA') + ) + and l_shipdate between date '1995-01-01' and date '1996-12-31' + ) as shipping +group by + supp_nation, + cust_nation, + l_year +order by + supp_nation, + cust_nation, + l_year; + + +select /* TPC-H Q2 */ + s_acctbal, + s_name, + n_name, + p_partkey, + p_mfgr, + s_address, + s_phone, + s_comment +from + part, + supplier, + partsupp, + nation, + region +where + p_partkey = ps_partkey + and s_suppkey = ps_suppkey + and p_size = 28 + and p_type like '%BRASS' + and s_nationkey = n_nationkey + and n_regionkey = r_regionkey + and r_name = 'AMERICA' + and ps_supplycost = ( + select + min(ps_supplycost) + from + partsupp, + supplier, + nation, + region + where + p_partkey = ps_partkey + and s_suppkey = ps_suppkey + and s_nationkey = n_nationkey + and n_regionkey = r_regionkey + and r_name = 'AMERICA' + ) +order by + s_acctbal desc, + n_name, + s_name, + p_partkey +limit 100; + + +select /* TPC-H Q22 */ + cntrycode, + count(*) as numcust, + sum(c_acctbal) as totacctbal +from + ( + select + substring(c_phone,1,2) as cntrycode, + c_acctbal + from + customer + where + substring(c_phone,1,2) in + ('32', '18', '22', '11', '33', '25', '19') + and c_acctbal > ( + select + avg(c_acctbal) + from + customer + where + c_acctbal > 0.00 + and substring(c_phone,1,2) in + ('32', '18', '22', '11', '33', '25', '19') + ) + and not exists ( + select + * + from + orders + where + o_custkey = c_custkey + ) + ) as custsale +group by + cntrycode +order by + cntrycode; + + +select /* TPC-H Q13 */ + c_count, + count(*) as custdist +from + ( + select + c_custkey, + count(o_orderkey) + from + customer left outer join orders on + c_custkey = o_custkey + and o_comment not like '%pending%accounts%' + group by + c_custkey + ) as c_orders (c_custkey, c_count) +group by + c_count +order by + custdist desc, + c_count desc; + + +select /* TPC-H Q21 */ + s_name, + count(*) as numwait +from + supplier, + lineitem l1, + orders, + nation +where + s_suppkey = l1.l_suppkey + and o_orderkey = l1.l_orderkey + and o_orderstatus = 'F' + and l1.l_receiptdate > l1.l_commitdate + and exists ( + select + * + from + lineitem l2 + where + l2.l_orderkey = l1.l_orderkey + and l2.l_suppkey <> l1.l_suppkey + ) + and not exists ( + select + * + from + lineitem l3 + where + l3.l_orderkey = l1.l_orderkey + and l3.l_suppkey <> l1.l_suppkey + and l3.l_receiptdate > l3.l_commitdate + ) + and s_nationkey = n_nationkey + and n_name = 'VIETNAM' +group by + s_name +order by + numwait desc, + s_name +limit 100; + + +select /* TPC-H Q10 */ + c_custkey, + c_name, + sum(l_extendedprice * (1 - l_discount)) as revenue, + c_acctbal, + n_name, + c_address, + c_phone, + c_comment +from + customer, + orders, + lineitem, + nation +where + c_custkey = o_custkey + and l_orderkey = o_orderkey + and o_orderdate >= date '1994-10-01' + and o_orderdate < dateadd(month, 3, cast('1994-10-01' as date)) + and l_returnflag = 'R' + and c_nationkey = n_nationkey +group by + c_custkey, + c_name, + c_acctbal, + c_phone, + n_name, + c_address, + c_comment +order by + revenue desc +limit 20; + + +select /* TPC-H Q14 */ + 100.00 * sum(case + when p_type like 'PROMO%' + then l_extendedprice * (1 - l_discount) + else 0 + end) / sum(l_extendedprice * (1 - l_discount)) as promo_revenue +from + lineitem, + part +where + l_partkey = p_partkey + and l_shipdate >= date '1995-09-01' + and l_shipdate < dateadd(month, 1, cast('1995-09-01' as date)) +; + + +select /* TPC-H Q9 */ + nation, + o_year, + sum(amount) as sum_profit +from + ( + select + n_name as nation, + extract(year from o_orderdate) as o_year, + l_extendedprice * (1 - l_discount) - ps_supplycost * l_quantity as amount + from + part, + supplier, + lineitem, + partsupp, + orders, + nation + where + s_suppkey = l_suppkey + and ps_suppkey = l_suppkey + and ps_partkey = l_partkey + and p_partkey = l_partkey + and o_orderkey = l_orderkey + and s_nationkey = n_nationkey + and p_name like '%ghost%' + ) as profit +group by + nation, + o_year +order by + nation, + o_year desc; + + +select /* TPC-H Q3 */ + l_orderkey, + sum(l_extendedprice * (1 - l_discount)) as revenue, + o_orderdate, + o_shippriority +from + customer, + orders, + lineitem +where + c_mktsegment = 'FURNITURE' + and c_custkey = o_custkey + and l_orderkey = o_orderkey + and o_orderdate < date '1995-03-11' + and l_shipdate > date '1995-03-11' +group by + l_orderkey, + o_orderdate, + o_shippriority +order by + revenue desc, + o_orderdate +limit 10; + + +select /* TPC-H Q16 */ + p_brand, + p_type, + p_size, + count(distinct ps_suppkey) as supplier_cnt +from + partsupp, + part +where + p_partkey = ps_partkey + and p_brand <> 'Brand#41' + and p_type not like 'PROMO ANODIZED%' + and p_size in (34, 10, 44, 45, 19, 26, 18, 47) + and ps_suppkey not in ( + select + s_suppkey + from + supplier + where + s_comment like '%Customer%Complaints%' + ) +group by + p_brand, + p_type, + p_size +order by + supplier_cnt desc, + p_brand, + p_type, + p_size; + + +select /* TPC-H Q20 */ + s_name, + s_address +from + supplier, + nation +where + s_suppkey in ( + select + ps_suppkey + from + partsupp + where + ps_partkey in ( + select + p_partkey + from + part + where + p_name like 'coral%' + ) + and ps_availqty > ( + select + 0.5 * sum(l_quantity) + from + lineitem + where + l_partkey = ps_partkey + and l_suppkey = ps_suppkey + and l_shipdate >= date '1997-01-01' + and l_shipdate < dateadd(year, 1, cast('1997-01-01' as date)) + ) + ) + and s_nationkey = n_nationkey + and n_name = 'RUSSIA' +order by + s_name; + + +select /* TPC-H Q19 */ + sum(l_extendedprice* (1 - l_discount)) as revenue +from + lineitem, + part +where + ( + p_partkey = l_partkey + and p_brand = 'Brand#41' + and p_container in ('SM CASE', 'SM BOX', 'SM PACK', 'SM PKG') + and l_quantity >= 3 and l_quantity <= 3 + 10 + and p_size between 1 and 5 + and l_shipmode in ('AIR', 'AIR REG') + and l_shipinstruct = 'DELIVER IN PERSON' + ) + or + ( + p_partkey = l_partkey + and p_brand = 'Brand#55' + and p_container in ('MED BAG', 'MED BOX', 'MED PKG', 'MED PACK') + and l_quantity >= 20 and l_quantity <= 20 + 10 + and p_size between 1 and 10 + and l_shipmode in ('AIR', 'AIR REG') + and l_shipinstruct = 'DELIVER IN PERSON' + ) + or + ( + p_partkey = l_partkey + and p_brand = 'Brand#23' + and p_container in ('LG CASE', 'LG BOX', 'LG PACK', 'LG PKG') + and l_quantity >= 25 and l_quantity <= 25 + 10 + and p_size between 1 and 15 + and l_shipmode in ('AIR', 'AIR REG') + and l_shipinstruct = 'DELIVER IN PERSON' + ); + + +select /* TPC-H Q11 */ + ps_partkey, + sum(ps_supplycost * ps_availqty) as value +from + partsupp, + supplier, + nation +where + ps_suppkey = s_suppkey + and s_nationkey = n_nationkey + and n_name = 'EGYPT' +group by + ps_partkey having + sum(ps_supplycost * ps_availqty) > ( + select + sum(ps_supplycost * ps_availqty) * 0.0000010000 + from + partsupp, + supplier, + nation + where + ps_suppkey = s_suppkey + and s_nationkey = n_nationkey + and n_name = 'EGYPT' + ) +order by + value desc; + + +select /* TPC-H Q4 */ + o_orderpriority, + count(*) as order_count +from + orders +where + o_orderdate >= date '1994-08-01' + and o_orderdate < dateadd(month, 3, cast('1994-08-01' as date)) + and exists ( + select + * + from + lineitem + where + l_orderkey = o_orderkey + and l_commitdate < l_receiptdate + ) +group by + o_orderpriority +order by + o_orderpriority; + + +select /* TPC-H Q8 */ + o_year, + sum(case + when nation = 'ROMANIA' then volume + else 0 + end) / sum(volume) as mkt_share +from + ( + select + extract(year from o_orderdate) as o_year, + l_extendedprice * (1 - l_discount) as volume, + n2.n_name as nation + from + part, + supplier, + lineitem, + orders, + customer, + nation n1, + nation n2, + region + where + p_partkey = l_partkey + and s_suppkey = l_suppkey + and l_orderkey = o_orderkey + and o_custkey = c_custkey + and c_nationkey = n1.n_nationkey + and n1.n_regionkey = r_regionkey + and r_name = 'EUROPE' + and s_nationkey = n2.n_nationkey + and o_orderdate between date '1995-01-01' and date '1996-12-31' + and p_type = 'MEDIUM ANODIZED BRASS' + ) as all_nations +group by + o_year +order by + o_year; + + +select /* TPC-H Q5 */ + n_name, + sum(l_extendedprice * (1 - l_discount)) as revenue +from + customer, + orders, + lineitem, + supplier, + nation, + region +where + c_custkey = o_custkey + and l_orderkey = o_orderkey + and l_suppkey = s_suppkey + and c_nationkey = s_nationkey + and s_nationkey = n_nationkey + and n_regionkey = r_regionkey + and r_name = 'AFRICA' + and o_orderdate >= date '1995-01-01' + and o_orderdate < dateadd(year, 1, cast('1995-01-01' as date)) +group by + n_name +order by + revenue desc; diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/100GB/queries/query_2.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/100GB/queries/query_2.sql new file mode 100644 index 00000000..a6610fdc --- /dev/null +++ b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/100GB/queries/query_2.sql @@ -0,0 +1,675 @@ +-- using 2 as a seed to the RNG + + +select /* TPC-H Q6 */ + sum(l_extendedprice * l_discount) as revenue +from + lineitem +where + l_shipdate >= date '1993-01-01' + and l_shipdate < dateadd(year, 1, cast('1993-01-01' as date)) + and l_discount between 0.04 - 0.01 and 0.04 + 0.01 + and l_quantity < 24; + + +select /* TPC-H Q17 */ + sum(l_extendedprice) / 7.0 as avg_yearly +from + lineitem, + part +where + p_partkey = l_partkey + and p_brand = 'Brand#14' + and p_container = 'SM PKG' + and l_quantity < ( + select + 0.2 * avg(l_quantity) + from + lineitem + where + l_partkey = p_partkey + ); + + +select /* TPC-H Q14 */ + 100.00 * sum(case + when p_type like 'PROMO%' + then l_extendedprice * (1 - l_discount) + else 0 + end) / sum(l_extendedprice * (1 - l_discount)) as promo_revenue +from + lineitem, + part +where + l_partkey = p_partkey + and l_shipdate >= date '1993-07-01' + and l_shipdate < dateadd(month, 1, cast('1993-07-01' as date)) +; + + +select /* TPC-H Q16 */ + p_brand, + p_type, + p_size, + count(distinct ps_suppkey) as supplier_cnt +from + partsupp, + part +where + p_partkey = ps_partkey + and p_brand <> 'Brand#21' + and p_type not like 'ECONOMY POLISHED%' + and p_size in (7, 42, 20, 12, 44, 37, 9, 15) + and ps_suppkey not in ( + select + s_suppkey + from + supplier + where + s_comment like '%Customer%Complaints%' + ) +group by + p_brand, + p_type, + p_size +order by + supplier_cnt desc, + p_brand, + p_type, + p_size; + + +select /* TPC-H Q19 */ + sum(l_extendedprice* (1 - l_discount)) as revenue +from + lineitem, + part +where + ( + p_partkey = l_partkey + and p_brand = 'Brand#15' + and p_container in ('SM CASE', 'SM BOX', 'SM PACK', 'SM PKG') + and l_quantity >= 1 and l_quantity <= 1 + 10 + and p_size between 1 and 5 + and l_shipmode in ('AIR', 'AIR REG') + and l_shipinstruct = 'DELIVER IN PERSON' + ) + or + ( + p_partkey = l_partkey + and p_brand = 'Brand#21' + and p_container in ('MED BAG', 'MED BOX', 'MED PKG', 'MED PACK') + and l_quantity >= 12 and l_quantity <= 12 + 10 + and p_size between 1 and 10 + and l_shipmode in ('AIR', 'AIR REG') + and l_shipinstruct = 'DELIVER IN PERSON' + ) + or + ( + p_partkey = l_partkey + and p_brand = 'Brand#54' + and p_container in ('LG CASE', 'LG BOX', 'LG PACK', 'LG PKG') + and l_quantity >= 23 and l_quantity <= 23 + 10 + and p_size between 1 and 15 + and l_shipmode in ('AIR', 'AIR REG') + and l_shipinstruct = 'DELIVER IN PERSON' + ); + + +select /* TPC-H Q10 */ + c_custkey, + c_name, + sum(l_extendedprice * (1 - l_discount)) as revenue, + c_acctbal, + n_name, + c_address, + c_phone, + c_comment +from + customer, + orders, + lineitem, + nation +where + c_custkey = o_custkey + and l_orderkey = o_orderkey + and o_orderdate >= date '1994-08-01' + and o_orderdate < dateadd(month, 3, cast('1994-08-01' as date)) + and l_returnflag = 'R' + and c_nationkey = n_nationkey +group by + c_custkey, + c_name, + c_acctbal, + c_phone, + n_name, + c_address, + c_comment +order by + revenue desc +limit 20; + + +select /* TPC-H Q9 */ + nation, + o_year, + sum(amount) as sum_profit +from + ( + select + n_name as nation, + extract(year from o_orderdate) as o_year, + l_extendedprice * (1 - l_discount) - ps_supplycost * l_quantity as amount + from + part, + supplier, + lineitem, + partsupp, + orders, + nation + where + s_suppkey = l_suppkey + and ps_suppkey = l_suppkey + and ps_partkey = l_partkey + and p_partkey = l_partkey + and o_orderkey = l_orderkey + and s_nationkey = n_nationkey + and p_name like '%slate%' + ) as profit +group by + nation, + o_year +order by + nation, + o_year desc; + + +select /* TPC-H Q2 */ + s_acctbal, + s_name, + n_name, + p_partkey, + p_mfgr, + s_address, + s_phone, + s_comment +from + part, + supplier, + partsupp, + nation, + region +where + p_partkey = ps_partkey + and s_suppkey = ps_suppkey + and p_size = 26 + and p_type like '%BRASS' + and s_nationkey = n_nationkey + and n_regionkey = r_regionkey + and r_name = 'AFRICA' + and ps_supplycost = ( + select + min(ps_supplycost) + from + partsupp, + supplier, + nation, + region + where + p_partkey = ps_partkey + and s_suppkey = ps_suppkey + and s_nationkey = n_nationkey + and n_regionkey = r_regionkey + and r_name = 'AFRICA' + ) +order by + s_acctbal desc, + n_name, + s_name, + p_partkey +limit 100; + +with revenue as ( + select + l_suppkey as supplier_no, + sum(l_extendedprice * (1-l_discount)) as total_revenue + from + lineitem + where + l_shipdate >= date '1993-04-01' + and l_shipdate < dateadd(month, 3, cast('1993-04-01' as date)) + group by + l_suppkey +) +select /* TPC-H Q15 */ + s_suppkey, + s_name, + s_address, + s_phone, + total_revenue +from + supplier, + revenue +where + s_suppkey = supplier_no + and total_revenue = ( + select + max(total_revenue) + from + revenue + ) +order by + s_suppkey; + + +select /* TPC-H Q8 */ + o_year, + sum(case + when nation = 'INDIA' then volume + else 0 + end) / sum(volume) as mkt_share +from + ( + select + extract(year from o_orderdate) as o_year, + l_extendedprice * (1 - l_discount) as volume, + n2.n_name as nation + from + part, + supplier, + lineitem, + orders, + customer, + nation n1, + nation n2, + region + where + p_partkey = l_partkey + and s_suppkey = l_suppkey + and l_orderkey = o_orderkey + and o_custkey = c_custkey + and c_nationkey = n1.n_nationkey + and n1.n_regionkey = r_regionkey + and r_name = 'ASIA' + and s_nationkey = n2.n_nationkey + and o_orderdate between date '1995-01-01' and date '1996-12-31' + and p_type = 'PROMO BURNISHED TIN' + ) as all_nations +group by + o_year +order by + o_year; + + +select /* TPC-H Q5 */ + n_name, + sum(l_extendedprice * (1 - l_discount)) as revenue +from + customer, + orders, + lineitem, + supplier, + nation, + region +where + c_custkey = o_custkey + and l_orderkey = o_orderkey + and l_suppkey = s_suppkey + and c_nationkey = s_nationkey + and s_nationkey = n_nationkey + and n_regionkey = r_regionkey + and r_name = 'ASIA' + and o_orderdate >= date '1993-01-01' + and o_orderdate < dateadd(year, 1, cast('1993-01-01' as date)) +group by + n_name +order by + revenue desc; + + +select /* TPC-H Q22 */ + cntrycode, + count(*) as numcust, + sum(c_acctbal) as totacctbal +from + ( + select + substring(c_phone,1,2) as cntrycode, + c_acctbal + from + customer + where + substring(c_phone,1,2) in + ('14', '31', '27', '10', '17', '21', '11') + and c_acctbal > ( + select + avg(c_acctbal) + from + customer + where + c_acctbal > 0.00 + and substring(c_phone,1,2) in + ('14', '31', '27', '10', '17', '21', '11') + ) + and not exists ( + select + * + from + orders + where + o_custkey = c_custkey + ) + ) as custsale +group by + cntrycode +order by + cntrycode; + + +select /* TPC-H Q12 */ + l_shipmode, + sum(case + when o_orderpriority = '1-URGENT' + or o_orderpriority = '2-HIGH' + then 1 + else 0 + end) as high_line_count, + sum(case + when o_orderpriority <> '1-URGENT' + and o_orderpriority <> '2-HIGH' + then 1 + else 0 + end) as low_line_count +from + orders, + lineitem +where + o_orderkey = l_orderkey + and l_shipmode in ('MAIL', 'REG AIR') + and l_commitdate < l_receiptdate + and l_shipdate < l_commitdate + and l_receiptdate >= date '1993-01-01' + and l_receiptdate < dateadd(year, 1, cast('1993-01-01' as date)) +group by + l_shipmode +order by + l_shipmode; + + +select /* TPC-H Q7 */ + supp_nation, + cust_nation, + l_year, + sum(volume) as revenue +from + ( + select + n1.n_name as supp_nation, + n2.n_name as cust_nation, + extract(year from l_shipdate) as l_year, + l_extendedprice * (1 - l_discount) as volume + from + supplier, + lineitem, + orders, + customer, + nation n1, + nation n2 + where + s_suppkey = l_suppkey + and o_orderkey = l_orderkey + and c_custkey = o_custkey + and s_nationkey = n1.n_nationkey + and c_nationkey = n2.n_nationkey + and ( + (n1.n_name = 'INDIA' and n2.n_name = 'VIETNAM') + or (n1.n_name = 'VIETNAM' and n2.n_name = 'INDIA') + ) + and l_shipdate between date '1995-01-01' and date '1996-12-31' + ) as shipping +group by + supp_nation, + cust_nation, + l_year +order by + supp_nation, + cust_nation, + l_year; + + +select /* TPC-H Q13 */ + c_count, + count(*) as custdist +from + ( + select + c_custkey, + count(o_orderkey) + from + customer left outer join orders on + c_custkey = o_custkey + and o_comment not like '%special%packages%' + group by + c_custkey + ) as c_orders (c_custkey, c_count) +group by + c_count +order by + custdist desc, + c_count desc; + + +select /* TPC-H Q18 */ + c_name, + c_custkey, + o_orderkey, + o_orderdate, + o_totalprice, + sum(l_quantity) +from + customer, + orders, + lineitem +where + o_orderkey in ( + select + l_orderkey + from + lineitem + group by + l_orderkey having + sum(l_quantity) > 315 + ) + and c_custkey = o_custkey + and o_orderkey = l_orderkey +group by + c_name, + c_custkey, + o_orderkey, + o_orderdate, + o_totalprice +order by + o_totalprice desc, + o_orderdate +limit 100; + + +select /* TPC-H Q1 */ + l_returnflag, + l_linestatus, + sum(l_quantity) as sum_qty, + sum(l_extendedprice) as sum_base_price, + sum(l_extendedprice * (1 - l_discount)) as sum_disc_price, + sum(l_extendedprice * (1 - l_discount) * (1 + l_tax)) as sum_charge, + avg(l_quantity) as avg_qty, + avg(l_extendedprice) as avg_price, + avg(l_discount) as avg_disc, + count(*) as count_order +from + lineitem +where + l_shipdate <= dateadd(day, -76, cast('1998-12-01' as date)) +group by + l_returnflag, + l_linestatus +order by + l_returnflag, + l_linestatus; + + +select /* TPC-H Q4 */ + o_orderpriority, + count(*) as order_count +from + orders +where + o_orderdate >= date '1993-04-01' + and o_orderdate < dateadd(month, 3, cast('1993-04-01' as date)) + and exists ( + select + * + from + lineitem + where + l_orderkey = o_orderkey + and l_commitdate < l_receiptdate + ) +group by + o_orderpriority +order by + o_orderpriority; + + +select /* TPC-H Q20 */ + s_name, + s_address +from + supplier, + nation +where + s_suppkey in ( + select + ps_suppkey + from + partsupp + where + ps_partkey in ( + select + p_partkey + from + part + where + p_name like 'seashell%' + ) + and ps_availqty > ( + select + 0.5 * sum(l_quantity) + from + lineitem + where + l_partkey = ps_partkey + and l_suppkey = ps_suppkey + and l_shipdate >= date '1994-01-01' + and l_shipdate < dateadd(year, 1, cast('1994-01-01' as date)) + ) + ) + and s_nationkey = n_nationkey + and n_name = 'EGYPT' +order by + s_name; + + +select /* TPC-H Q3 */ + l_orderkey, + sum(l_extendedprice * (1 - l_discount)) as revenue, + o_orderdate, + o_shippriority +from + customer, + orders, + lineitem +where + c_mktsegment = 'MACHINERY' + and c_custkey = o_custkey + and l_orderkey = o_orderkey + and o_orderdate < date '1995-03-03' + and l_shipdate > date '1995-03-03' +group by + l_orderkey, + o_orderdate, + o_shippriority +order by + revenue desc, + o_orderdate +limit 10; + + +select /* TPC-H Q11 */ + ps_partkey, + sum(ps_supplycost * ps_availqty) as value +from + partsupp, + supplier, + nation +where + ps_suppkey = s_suppkey + and s_nationkey = n_nationkey + and n_name = 'ALGERIA' +group by + ps_partkey having + sum(ps_supplycost * ps_availqty) > ( + select + sum(ps_supplycost * ps_availqty) * 0.0000010000 + from + partsupp, + supplier, + nation + where + ps_suppkey = s_suppkey + and s_nationkey = n_nationkey + and n_name = 'ALGERIA' + ) +order by + value desc; + + +select /* TPC-H Q21 */ + s_name, + count(*) as numwait +from + supplier, + lineitem l1, + orders, + nation +where + s_suppkey = l1.l_suppkey + and o_orderkey = l1.l_orderkey + and o_orderstatus = 'F' + and l1.l_receiptdate > l1.l_commitdate + and exists ( + select + * + from + lineitem l2 + where + l2.l_orderkey = l1.l_orderkey + and l2.l_suppkey <> l1.l_suppkey + ) + and not exists ( + select + * + from + lineitem l3 + where + l3.l_orderkey = l1.l_orderkey + and l3.l_suppkey <> l1.l_suppkey + and l3.l_receiptdate > l3.l_commitdate + ) + and s_nationkey = n_nationkey + and n_name = 'INDONESIA' +group by + s_name +order by + numwait desc, + s_name +limit 100; diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/100GB/queries/query_3.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/100GB/queries/query_3.sql new file mode 100644 index 00000000..56b6546b --- /dev/null +++ b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/100GB/queries/query_3.sql @@ -0,0 +1,675 @@ +-- using 3 as a seed to the RNG + + +select /* TPC-H Q8 */ + o_year, + sum(case + when nation = 'ALGERIA' then volume + else 0 + end) / sum(volume) as mkt_share +from + ( + select + extract(year from o_orderdate) as o_year, + l_extendedprice * (1 - l_discount) as volume, + n2.n_name as nation + from + part, + supplier, + lineitem, + orders, + customer, + nation n1, + nation n2, + region + where + p_partkey = l_partkey + and s_suppkey = l_suppkey + and l_orderkey = o_orderkey + and o_custkey = c_custkey + and c_nationkey = n1.n_nationkey + and n1.n_regionkey = r_regionkey + and r_name = 'AFRICA' + and s_nationkey = n2.n_nationkey + and o_orderdate between date '1995-01-01' and date '1996-12-31' + and p_type = 'ECONOMY BRUSHED TIN' + ) as all_nations +group by + o_year +order by + o_year; + + +select /* TPC-H Q5 */ + n_name, + sum(l_extendedprice * (1 - l_discount)) as revenue +from + customer, + orders, + lineitem, + supplier, + nation, + region +where + c_custkey = o_custkey + and l_orderkey = o_orderkey + and l_suppkey = s_suppkey + and c_nationkey = s_nationkey + and s_nationkey = n_nationkey + and n_regionkey = r_regionkey + and r_name = 'EUROPE' + and o_orderdate >= date '1993-01-01' + and o_orderdate < dateadd(year, 1, cast('1993-01-01' as date)) +group by + n_name +order by + revenue desc; + + +select /* TPC-H Q4 */ + o_orderpriority, + count(*) as order_count +from + orders +where + o_orderdate >= date '1995-11-01' + and o_orderdate < dateadd(month, 3, cast('1995-11-01' as date)) + and exists ( + select + * + from + lineitem + where + l_orderkey = o_orderkey + and l_commitdate < l_receiptdate + ) +group by + o_orderpriority +order by + o_orderpriority; + + +select /* TPC-H Q6 */ + sum(l_extendedprice * l_discount) as revenue +from + lineitem +where + l_shipdate >= date '1993-01-01' + and l_shipdate < dateadd(year, 1, cast('1993-01-01' as date)) + and l_discount between 0.02 - 0.01 and 0.02 + 0.01 + and l_quantity < 24; + + +select /* TPC-H Q17 */ + sum(l_extendedprice) / 7.0 as avg_yearly +from + lineitem, + part +where + p_partkey = l_partkey + and p_brand = 'Brand#11' + and p_container = 'LG CASE' + and l_quantity < ( + select + 0.2 * avg(l_quantity) + from + lineitem + where + l_partkey = p_partkey + ); + + +select /* TPC-H Q7 */ + supp_nation, + cust_nation, + l_year, + sum(volume) as revenue +from + ( + select + n1.n_name as supp_nation, + n2.n_name as cust_nation, + extract(year from l_shipdate) as l_year, + l_extendedprice * (1 - l_discount) as volume + from + supplier, + lineitem, + orders, + customer, + nation n1, + nation n2 + where + s_suppkey = l_suppkey + and o_orderkey = l_orderkey + and c_custkey = o_custkey + and s_nationkey = n1.n_nationkey + and c_nationkey = n2.n_nationkey + and ( + (n1.n_name = 'ALGERIA' and n2.n_name = 'SAUDI ARABIA') + or (n1.n_name = 'SAUDI ARABIA' and n2.n_name = 'ALGERIA') + ) + and l_shipdate between date '1995-01-01' and date '1996-12-31' + ) as shipping +group by + supp_nation, + cust_nation, + l_year +order by + supp_nation, + cust_nation, + l_year; + + +select /* TPC-H Q1 */ + l_returnflag, + l_linestatus, + sum(l_quantity) as sum_qty, + sum(l_extendedprice) as sum_base_price, + sum(l_extendedprice * (1 - l_discount)) as sum_disc_price, + sum(l_extendedprice * (1 - l_discount) * (1 + l_tax)) as sum_charge, + avg(l_quantity) as avg_qty, + avg(l_extendedprice) as avg_price, + avg(l_discount) as avg_disc, + count(*) as count_order +from + lineitem +where + l_shipdate <= dateadd(day, -84, cast('1998-12-01' as date)) +group by + l_returnflag, + l_linestatus +order by + l_returnflag, + l_linestatus; + + +select /* TPC-H Q18 */ + c_name, + c_custkey, + o_orderkey, + o_orderdate, + o_totalprice, + sum(l_quantity) +from + customer, + orders, + lineitem +where + o_orderkey in ( + select + l_orderkey + from + lineitem + group by + l_orderkey having + sum(l_quantity) > 312 + ) + and c_custkey = o_custkey + and o_orderkey = l_orderkey +group by + c_name, + c_custkey, + o_orderkey, + o_orderdate, + o_totalprice +order by + o_totalprice desc, + o_orderdate +limit 100; + + +select /* TPC-H Q22 */ + cntrycode, + count(*) as numcust, + sum(c_acctbal) as totacctbal +from + ( + select + substring(c_phone,1,2) as cntrycode, + c_acctbal + from + customer + where + substring(c_phone,1,2) in + ('29', '10', '24', '25', '19', '34', '20') + and c_acctbal > ( + select + avg(c_acctbal) + from + customer + where + c_acctbal > 0.00 + and substring(c_phone,1,2) in + ('29', '10', '24', '25', '19', '34', '20') + ) + and not exists ( + select + * + from + orders + where + o_custkey = c_custkey + ) + ) as custsale +group by + cntrycode +order by + cntrycode; + + +select /* TPC-H Q14 */ + 100.00 * sum(case + when p_type like 'PROMO%' + then l_extendedprice * (1 - l_discount) + else 0 + end) / sum(l_extendedprice * (1 - l_discount)) as promo_revenue +from + lineitem, + part +where + l_partkey = p_partkey + and l_shipdate >= date '1993-10-01' + and l_shipdate < dateadd(month, 1, cast('1993-10-01' as date)) +; + + +select /* TPC-H Q9 */ + nation, + o_year, + sum(amount) as sum_profit +from + ( + select + n_name as nation, + extract(year from o_orderdate) as o_year, + l_extendedprice * (1 - l_discount) - ps_supplycost * l_quantity as amount + from + part, + supplier, + lineitem, + partsupp, + orders, + nation + where + s_suppkey = l_suppkey + and ps_suppkey = l_suppkey + and ps_partkey = l_partkey + and p_partkey = l_partkey + and o_orderkey = l_orderkey + and s_nationkey = n_nationkey + and p_name like '%saddle%' + ) as profit +group by + nation, + o_year +order by + nation, + o_year desc; + + +select /* TPC-H Q10 */ + c_custkey, + c_name, + sum(l_extendedprice * (1 - l_discount)) as revenue, + c_acctbal, + n_name, + c_address, + c_phone, + c_comment +from + customer, + orders, + lineitem, + nation +where + c_custkey = o_custkey + and l_orderkey = o_orderkey + and o_orderdate >= date '1993-05-01' + and o_orderdate < dateadd(month, 3, cast('1993-05-01' as date)) + and l_returnflag = 'R' + and c_nationkey = n_nationkey +group by + c_custkey, + c_name, + c_acctbal, + c_phone, + n_name, + c_address, + c_comment +order by + revenue desc +limit 20; + +with revenue as ( + select + l_suppkey as supplier_no, + sum(l_extendedprice * (1-l_discount)) as total_revenue + from + lineitem + where + l_shipdate >= date '1995-11-01' + and l_shipdate < dateadd(month, 3, cast('1995-11-01' as date)) + group by + l_suppkey +) +select /* TPC-H Q15 */ + s_suppkey, + s_name, + s_address, + s_phone, + total_revenue +from + supplier, + revenue +where + s_suppkey = supplier_no + and total_revenue = ( + select + max(total_revenue) + from + revenue + ) +order by + s_suppkey; + + +select /* TPC-H Q11 */ + ps_partkey, + sum(ps_supplycost * ps_availqty) as value +from + partsupp, + supplier, + nation +where + ps_suppkey = s_suppkey + and s_nationkey = n_nationkey + and n_name = 'JORDAN' +group by + ps_partkey having + sum(ps_supplycost * ps_availqty) > ( + select + sum(ps_supplycost * ps_availqty) * 0.0000010000 + from + partsupp, + supplier, + nation + where + ps_suppkey = s_suppkey + and s_nationkey = n_nationkey + and n_name = 'JORDAN' + ) +order by + value desc; + + +select /* TPC-H Q20 */ + s_name, + s_address +from + supplier, + nation +where + s_suppkey in ( + select + ps_suppkey + from + partsupp + where + ps_partkey in ( + select + p_partkey + from + part + where + p_name like 'dim%' + ) + and ps_availqty > ( + select + 0.5 * sum(l_quantity) + from + lineitem + where + l_partkey = ps_partkey + and l_suppkey = ps_suppkey + and l_shipdate >= date '1993-01-01' + and l_shipdate < dateadd(year, 1, cast('1993-01-01' as date)) + ) + ) + and s_nationkey = n_nationkey + and n_name = 'ROMANIA' +order by + s_name; + + +select /* TPC-H Q2 */ + s_acctbal, + s_name, + n_name, + p_partkey, + p_mfgr, + s_address, + s_phone, + s_comment +from + part, + supplier, + partsupp, + nation, + region +where + p_partkey = ps_partkey + and s_suppkey = ps_suppkey + and p_size = 14 + and p_type like '%NICKEL' + and s_nationkey = n_nationkey + and n_regionkey = r_regionkey + and r_name = 'ASIA' + and ps_supplycost = ( + select + min(ps_supplycost) + from + partsupp, + supplier, + nation, + region + where + p_partkey = ps_partkey + and s_suppkey = ps_suppkey + and s_nationkey = n_nationkey + and n_regionkey = r_regionkey + and r_name = 'ASIA' + ) +order by + s_acctbal desc, + n_name, + s_name, + p_partkey +limit 100; + + +select /* TPC-H Q21 */ + s_name, + count(*) as numwait +from + supplier, + lineitem l1, + orders, + nation +where + s_suppkey = l1.l_suppkey + and o_orderkey = l1.l_orderkey + and o_orderstatus = 'F' + and l1.l_receiptdate > l1.l_commitdate + and exists ( + select + * + from + lineitem l2 + where + l2.l_orderkey = l1.l_orderkey + and l2.l_suppkey <> l1.l_suppkey + ) + and not exists ( + select + * + from + lineitem l3 + where + l3.l_orderkey = l1.l_orderkey + and l3.l_suppkey <> l1.l_suppkey + and l3.l_receiptdate > l3.l_commitdate + ) + and s_nationkey = n_nationkey + and n_name = 'ARGENTINA' +group by + s_name +order by + numwait desc, + s_name +limit 100; + + +select /* TPC-H Q19 */ + sum(l_extendedprice* (1 - l_discount)) as revenue +from + lineitem, + part +where + ( + p_partkey = l_partkey + and p_brand = 'Brand#22' + and p_container in ('SM CASE', 'SM BOX', 'SM PACK', 'SM PKG') + and l_quantity >= 6 and l_quantity <= 6 + 10 + and p_size between 1 and 5 + and l_shipmode in ('AIR', 'AIR REG') + and l_shipinstruct = 'DELIVER IN PERSON' + ) + or + ( + p_partkey = l_partkey + and p_brand = 'Brand#14' + and p_container in ('MED BAG', 'MED BOX', 'MED PKG', 'MED PACK') + and l_quantity >= 13 and l_quantity <= 13 + 10 + and p_size between 1 and 10 + and l_shipmode in ('AIR', 'AIR REG') + and l_shipinstruct = 'DELIVER IN PERSON' + ) + or + ( + p_partkey = l_partkey + and p_brand = 'Brand#43' + and p_container in ('LG CASE', 'LG BOX', 'LG PACK', 'LG PKG') + and l_quantity >= 30 and l_quantity <= 30 + 10 + and p_size between 1 and 15 + and l_shipmode in ('AIR', 'AIR REG') + and l_shipinstruct = 'DELIVER IN PERSON' + ); + + +select /* TPC-H Q13 */ + c_count, + count(*) as custdist +from + ( + select + c_custkey, + count(o_orderkey) + from + customer left outer join orders on + c_custkey = o_custkey + and o_comment not like '%special%packages%' + group by + c_custkey + ) as c_orders (c_custkey, c_count) +group by + c_count +order by + custdist desc, + c_count desc; + + +select /* TPC-H Q16 */ + p_brand, + p_type, + p_size, + count(distinct ps_suppkey) as supplier_cnt +from + partsupp, + part +where + p_partkey = ps_partkey + and p_brand <> 'Brand#11' + and p_type not like 'STANDARD BRUSHED%' + and p_size in (11, 14, 5, 40, 41, 30, 32, 19) + and ps_suppkey not in ( + select + s_suppkey + from + supplier + where + s_comment like '%Customer%Complaints%' + ) +group by + p_brand, + p_type, + p_size +order by + supplier_cnt desc, + p_brand, + p_type, + p_size; + + +select /* TPC-H Q12 */ + l_shipmode, + sum(case + when o_orderpriority = '1-URGENT' + or o_orderpriority = '2-HIGH' + then 1 + else 0 + end) as high_line_count, + sum(case + when o_orderpriority <> '1-URGENT' + and o_orderpriority <> '2-HIGH' + then 1 + else 0 + end) as low_line_count +from + orders, + lineitem +where + o_orderkey = l_orderkey + and l_shipmode in ('TRUCK', 'REG AIR') + and l_commitdate < l_receiptdate + and l_shipdate < l_commitdate + and l_receiptdate >= date '1993-01-01' + and l_receiptdate < dateadd(year, 1, cast('1993-01-01' as date)) +group by + l_shipmode +order by + l_shipmode; + + +select /* TPC-H Q3 */ + l_orderkey, + sum(l_extendedprice * (1 - l_discount)) as revenue, + o_orderdate, + o_shippriority +from + customer, + orders, + lineitem +where + c_mktsegment = 'BUILDING' + and c_custkey = o_custkey + and l_orderkey = o_orderkey + and o_orderdate < date '1995-03-19' + and l_shipdate > date '1995-03-19' +group by + l_orderkey, + o_orderdate, + o_shippriority +order by + revenue desc, + o_orderdate +limit 10; diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/100GB/queries/query_4.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/100GB/queries/query_4.sql new file mode 100644 index 00000000..22abb06f --- /dev/null +++ b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/100GB/queries/query_4.sql @@ -0,0 +1,675 @@ +-- using 4 as a seed to the RNG + + +select /* TPC-H Q5 */ + n_name, + sum(l_extendedprice * (1 - l_discount)) as revenue +from + customer, + orders, + lineitem, + supplier, + nation, + region +where + c_custkey = o_custkey + and l_orderkey = o_orderkey + and l_suppkey = s_suppkey + and c_nationkey = s_nationkey + and s_nationkey = n_nationkey + and n_regionkey = r_regionkey + and r_name = 'MIDDLE EAST' + and o_orderdate >= date '1993-01-01' + and o_orderdate < dateadd(year, 1, cast('1993-01-01' as date)) +group by + n_name +order by + revenue desc; + + +select /* TPC-H Q21 */ + s_name, + count(*) as numwait +from + supplier, + lineitem l1, + orders, + nation +where + s_suppkey = l1.l_suppkey + and o_orderkey = l1.l_orderkey + and o_orderstatus = 'F' + and l1.l_receiptdate > l1.l_commitdate + and exists ( + select + * + from + lineitem l2 + where + l2.l_orderkey = l1.l_orderkey + and l2.l_suppkey <> l1.l_suppkey + ) + and not exists ( + select + * + from + lineitem l3 + where + l3.l_orderkey = l1.l_orderkey + and l3.l_suppkey <> l1.l_suppkey + and l3.l_receiptdate > l3.l_commitdate + ) + and s_nationkey = n_nationkey + and n_name = 'CHINA' +group by + s_name +order by + numwait desc, + s_name +limit 100; + + +select /* TPC-H Q14 */ + 100.00 * sum(case + when p_type like 'PROMO%' + then l_extendedprice * (1 - l_discount) + else 0 + end) / sum(l_extendedprice * (1 - l_discount)) as promo_revenue +from + lineitem, + part +where + l_partkey = p_partkey + and l_shipdate >= date '1994-01-01' + and l_shipdate < dateadd(month, 1, cast('1994-01-01' as date)) +; + + +select /* TPC-H Q19 */ + sum(l_extendedprice* (1 - l_discount)) as revenue +from + lineitem, + part +where + ( + p_partkey = l_partkey + and p_brand = 'Brand#24' + and p_container in ('SM CASE', 'SM BOX', 'SM PACK', 'SM PKG') + and l_quantity >= 2 and l_quantity <= 2 + 10 + and p_size between 1 and 5 + and l_shipmode in ('AIR', 'AIR REG') + and l_shipinstruct = 'DELIVER IN PERSON' + ) + or + ( + p_partkey = l_partkey + and p_brand = 'Brand#42' + and p_container in ('MED BAG', 'MED BOX', 'MED PKG', 'MED PACK') + and l_quantity >= 14 and l_quantity <= 14 + 10 + and p_size between 1 and 10 + and l_shipmode in ('AIR', 'AIR REG') + and l_shipinstruct = 'DELIVER IN PERSON' + ) + or + ( + p_partkey = l_partkey + and p_brand = 'Brand#42' + and p_container in ('LG CASE', 'LG BOX', 'LG PACK', 'LG PKG') + and l_quantity >= 26 and l_quantity <= 26 + 10 + and p_size between 1 and 15 + and l_shipmode in ('AIR', 'AIR REG') + and l_shipinstruct = 'DELIVER IN PERSON' + ); + +with revenue as ( + select + l_suppkey as supplier_no, + sum(l_extendedprice * (1-l_discount)) as total_revenue + from + lineitem + where + l_shipdate >= date '1993-07-01' + and l_shipdate < dateadd(month, 3, cast('1993-07-01' as date)) + group by + l_suppkey +) +select /* TPC-H Q15 */ + s_suppkey, + s_name, + s_address, + s_phone, + total_revenue +from + supplier, + revenue +where + s_suppkey = supplier_no + and total_revenue = ( + select + max(total_revenue) + from + revenue + ) +order by + s_suppkey; + + +select /* TPC-H Q17 */ + sum(l_extendedprice) / 7.0 as avg_yearly +from + lineitem, + part +where + p_partkey = l_partkey + and p_brand = 'Brand#13' + and p_container = 'LG BAG' + and l_quantity < ( + select + 0.2 * avg(l_quantity) + from + lineitem + where + l_partkey = p_partkey + ); + + +select /* TPC-H Q12 */ + l_shipmode, + sum(case + when o_orderpriority = '1-URGENT' + or o_orderpriority = '2-HIGH' + then 1 + else 0 + end) as high_line_count, + sum(case + when o_orderpriority <> '1-URGENT' + and o_orderpriority <> '2-HIGH' + then 1 + else 0 + end) as low_line_count +from + orders, + lineitem +where + o_orderkey = l_orderkey + and l_shipmode in ('RAIL', 'REG AIR') + and l_commitdate < l_receiptdate + and l_shipdate < l_commitdate + and l_receiptdate >= date '1994-01-01' + and l_receiptdate < dateadd(year, 1, cast('1994-01-01' as date)) +group by + l_shipmode +order by + l_shipmode; + + +select /* TPC-H Q6 */ + sum(l_extendedprice * l_discount) as revenue +from + lineitem +where + l_shipdate >= date '1993-01-01' + and l_shipdate < dateadd(year, 1, cast('1993-01-01' as date)) + and l_discount between 0.07 - 0.01 and 0.07 + 0.01 + and l_quantity < 25; + + +select /* TPC-H Q4 */ + o_orderpriority, + count(*) as order_count +from + orders +where + o_orderdate >= date '1993-08-01' + and o_orderdate < dateadd(month, 3, cast('1993-08-01' as date)) + and exists ( + select + * + from + lineitem + where + l_orderkey = o_orderkey + and l_commitdate < l_receiptdate + ) +group by + o_orderpriority +order by + o_orderpriority; + + +select /* TPC-H Q9 */ + nation, + o_year, + sum(amount) as sum_profit +from + ( + select + n_name as nation, + extract(year from o_orderdate) as o_year, + l_extendedprice * (1 - l_discount) - ps_supplycost * l_quantity as amount + from + part, + supplier, + lineitem, + partsupp, + orders, + nation + where + s_suppkey = l_suppkey + and ps_suppkey = l_suppkey + and ps_partkey = l_partkey + and p_partkey = l_partkey + and o_orderkey = l_orderkey + and s_nationkey = n_nationkey + and p_name like '%puff%' + ) as profit +group by + nation, + o_year +order by + nation, + o_year desc; + + +select /* TPC-H Q8 */ + o_year, + sum(case + when nation = 'PERU' then volume + else 0 + end) / sum(volume) as mkt_share +from + ( + select + extract(year from o_orderdate) as o_year, + l_extendedprice * (1 - l_discount) as volume, + n2.n_name as nation + from + part, + supplier, + lineitem, + orders, + customer, + nation n1, + nation n2, + region + where + p_partkey = l_partkey + and s_suppkey = l_suppkey + and l_orderkey = o_orderkey + and o_custkey = c_custkey + and c_nationkey = n1.n_nationkey + and n1.n_regionkey = r_regionkey + and r_name = 'AMERICA' + and s_nationkey = n2.n_nationkey + and o_orderdate between date '1995-01-01' and date '1996-12-31' + and p_type = 'ECONOMY PLATED TIN' + ) as all_nations +group by + o_year +order by + o_year; + + +select /* TPC-H Q16 */ + p_brand, + p_type, + p_size, + count(distinct ps_suppkey) as supplier_cnt +from + partsupp, + part +where + p_partkey = ps_partkey + and p_brand <> 'Brand#41' + and p_type not like 'LARGE BURNISHED%' + and p_size in (14, 34, 38, 20, 3, 23, 11, 6) + and ps_suppkey not in ( + select + s_suppkey + from + supplier + where + s_comment like '%Customer%Complaints%' + ) +group by + p_brand, + p_type, + p_size +order by + supplier_cnt desc, + p_brand, + p_type, + p_size; + + +select /* TPC-H Q11 */ + ps_partkey, + sum(ps_supplycost * ps_availqty) as value +from + partsupp, + supplier, + nation +where + ps_suppkey = s_suppkey + and s_nationkey = n_nationkey + and n_name = 'ARGENTINA' +group by + ps_partkey having + sum(ps_supplycost * ps_availqty) > ( + select + sum(ps_supplycost * ps_availqty) * 0.0000010000 + from + partsupp, + supplier, + nation + where + ps_suppkey = s_suppkey + and s_nationkey = n_nationkey + and n_name = 'ARGENTINA' + ) +order by + value desc; + + +select /* TPC-H Q2 */ + s_acctbal, + s_name, + n_name, + p_partkey, + p_mfgr, + s_address, + s_phone, + s_comment +from + part, + supplier, + partsupp, + nation, + region +where + p_partkey = ps_partkey + and s_suppkey = ps_suppkey + and p_size = 2 + and p_type like '%TIN' + and s_nationkey = n_nationkey + and n_regionkey = r_regionkey + and r_name = 'AFRICA' + and ps_supplycost = ( + select + min(ps_supplycost) + from + partsupp, + supplier, + nation, + region + where + p_partkey = ps_partkey + and s_suppkey = ps_suppkey + and s_nationkey = n_nationkey + and n_regionkey = r_regionkey + and r_name = 'AFRICA' + ) +order by + s_acctbal desc, + n_name, + s_name, + p_partkey +limit 100; + + +select /* TPC-H Q10 */ + c_custkey, + c_name, + sum(l_extendedprice * (1 - l_discount)) as revenue, + c_acctbal, + n_name, + c_address, + c_phone, + c_comment +from + customer, + orders, + lineitem, + nation +where + c_custkey = o_custkey + and l_orderkey = o_orderkey + and o_orderdate >= date '1994-02-01' + and o_orderdate < dateadd(month, 3, cast('1994-02-01' as date)) + and l_returnflag = 'R' + and c_nationkey = n_nationkey +group by + c_custkey, + c_name, + c_acctbal, + c_phone, + n_name, + c_address, + c_comment +order by + revenue desc +limit 20; + + +select /* TPC-H Q18 */ + c_name, + c_custkey, + o_orderkey, + o_orderdate, + o_totalprice, + sum(l_quantity) +from + customer, + orders, + lineitem +where + o_orderkey in ( + select + l_orderkey + from + lineitem + group by + l_orderkey having + sum(l_quantity) > 314 + ) + and c_custkey = o_custkey + and o_orderkey = l_orderkey +group by + c_name, + c_custkey, + o_orderkey, + o_orderdate, + o_totalprice +order by + o_totalprice desc, + o_orderdate +limit 100; + + +select /* TPC-H Q1 */ + l_returnflag, + l_linestatus, + sum(l_quantity) as sum_qty, + sum(l_extendedprice) as sum_base_price, + sum(l_extendedprice * (1 - l_discount)) as sum_disc_price, + sum(l_extendedprice * (1 - l_discount) * (1 + l_tax)) as sum_charge, + avg(l_quantity) as avg_qty, + avg(l_extendedprice) as avg_price, + avg(l_discount) as avg_disc, + count(*) as count_order +from + lineitem +where + l_shipdate <= dateadd(day, -92, cast('1998-12-01' as date)) +group by + l_returnflag, + l_linestatus +order by + l_returnflag, + l_linestatus; + + +select /* TPC-H Q13 */ + c_count, + count(*) as custdist +from + ( + select + c_custkey, + count(o_orderkey) + from + customer left outer join orders on + c_custkey = o_custkey + and o_comment not like '%special%packages%' + group by + c_custkey + ) as c_orders (c_custkey, c_count) +group by + c_count +order by + custdist desc, + c_count desc; + + +select /* TPC-H Q7 */ + supp_nation, + cust_nation, + l_year, + sum(volume) as revenue +from + ( + select + n1.n_name as supp_nation, + n2.n_name as cust_nation, + extract(year from l_shipdate) as l_year, + l_extendedprice * (1 - l_discount) as volume + from + supplier, + lineitem, + orders, + customer, + nation n1, + nation n2 + where + s_suppkey = l_suppkey + and o_orderkey = l_orderkey + and c_custkey = o_custkey + and s_nationkey = n1.n_nationkey + and c_nationkey = n2.n_nationkey + and ( + (n1.n_name = 'PERU' and n2.n_name = 'CHINA') + or (n1.n_name = 'CHINA' and n2.n_name = 'PERU') + ) + and l_shipdate between date '1995-01-01' and date '1996-12-31' + ) as shipping +group by + supp_nation, + cust_nation, + l_year +order by + supp_nation, + cust_nation, + l_year; + + +select /* TPC-H Q22 */ + cntrycode, + count(*) as numcust, + sum(c_acctbal) as totacctbal +from + ( + select + substring(c_phone,1,2) as cntrycode, + c_acctbal + from + customer + where + substring(c_phone,1,2) in + ('18', '28', '20', '15', '21', '27', '11') + and c_acctbal > ( + select + avg(c_acctbal) + from + customer + where + c_acctbal > 0.00 + and substring(c_phone,1,2) in + ('18', '28', '20', '15', '21', '27', '11') + ) + and not exists ( + select + * + from + orders + where + o_custkey = c_custkey + ) + ) as custsale +group by + cntrycode +order by + cntrycode; + + +select /* TPC-H Q3 */ + l_orderkey, + sum(l_extendedprice * (1 - l_discount)) as revenue, + o_orderdate, + o_shippriority +from + customer, + orders, + lineitem +where + c_mktsegment = 'MACHINERY' + and c_custkey = o_custkey + and l_orderkey = o_orderkey + and o_orderdate < date '1995-03-05' + and l_shipdate > date '1995-03-05' +group by + l_orderkey, + o_orderdate, + o_shippriority +order by + revenue desc, + o_orderdate +limit 10; + + +select /* TPC-H Q20 */ + s_name, + s_address +from + supplier, + nation +where + s_suppkey in ( + select + ps_suppkey + from + partsupp + where + ps_partkey in ( + select + p_partkey + from + part + where + p_name like 'papaya%' + ) + and ps_availqty > ( + select + 0.5 * sum(l_quantity) + from + lineitem + where + l_partkey = ps_partkey + and l_suppkey = ps_suppkey + and l_shipdate >= date '1996-01-01' + and l_shipdate < dateadd(year, 1, cast('1996-01-01' as date)) + ) + ) + and s_nationkey = n_nationkey + and n_name = 'INDIA' +order by + s_name; diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/100GB/queries/query_5.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/100GB/queries/query_5.sql new file mode 100644 index 00000000..6ad5d1d1 --- /dev/null +++ b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/100GB/queries/query_5.sql @@ -0,0 +1,675 @@ +-- using 5 as a seed to the RNG + + +select /* TPC-H Q21 */ + s_name, + count(*) as numwait +from + supplier, + lineitem l1, + orders, + nation +where + s_suppkey = l1.l_suppkey + and o_orderkey = l1.l_orderkey + and o_orderstatus = 'F' + and l1.l_receiptdate > l1.l_commitdate + and exists ( + select + * + from + lineitem l2 + where + l2.l_orderkey = l1.l_orderkey + and l2.l_suppkey <> l1.l_suppkey + ) + and not exists ( + select + * + from + lineitem l3 + where + l3.l_orderkey = l1.l_orderkey + and l3.l_suppkey <> l1.l_suppkey + and l3.l_receiptdate > l3.l_commitdate + ) + and s_nationkey = n_nationkey + and n_name = 'IRAN' +group by + s_name +order by + numwait desc, + s_name +limit 100; + +with revenue as ( + select + l_suppkey as supplier_no, + sum(l_extendedprice * (1-l_discount)) as total_revenue + from + lineitem + where + l_shipdate >= date '1996-02-01' + and l_shipdate < dateadd(month, 3, cast('1996-02-01' as date)) + group by + l_suppkey +) +select /* TPC-H Q15 */ + s_suppkey, + s_name, + s_address, + s_phone, + total_revenue +from + supplier, + revenue +where + s_suppkey = supplier_no + and total_revenue = ( + select + max(total_revenue) + from + revenue + ) +order by + s_suppkey; + + +select /* TPC-H Q4 */ + o_orderpriority, + count(*) as order_count +from + orders +where + o_orderdate >= date '1996-03-01' + and o_orderdate < dateadd(month, 3, cast('1996-03-01' as date)) + and exists ( + select + * + from + lineitem + where + l_orderkey = o_orderkey + and l_commitdate < l_receiptdate + ) +group by + o_orderpriority +order by + o_orderpriority; + + +select /* TPC-H Q6 */ + sum(l_extendedprice * l_discount) as revenue +from + lineitem +where + l_shipdate >= date '1994-01-01' + and l_shipdate < dateadd(year, 1, cast('1994-01-01' as date)) + and l_discount between 0.05 - 0.01 and 0.05 + 0.01 + and l_quantity < 24; + + +select /* TPC-H Q7 */ + supp_nation, + cust_nation, + l_year, + sum(volume) as revenue +from + ( + select + n1.n_name as supp_nation, + n2.n_name as cust_nation, + extract(year from l_shipdate) as l_year, + l_extendedprice * (1 - l_discount) as volume + from + supplier, + lineitem, + orders, + customer, + nation n1, + nation n2 + where + s_suppkey = l_suppkey + and o_orderkey = l_orderkey + and c_custkey = o_custkey + and s_nationkey = n1.n_nationkey + and c_nationkey = n2.n_nationkey + and ( + (n1.n_name = 'INDONESIA' and n2.n_name = 'MOZAMBIQUE') + or (n1.n_name = 'MOZAMBIQUE' and n2.n_name = 'INDONESIA') + ) + and l_shipdate between date '1995-01-01' and date '1996-12-31' + ) as shipping +group by + supp_nation, + cust_nation, + l_year +order by + supp_nation, + cust_nation, + l_year; + + +select /* TPC-H Q16 */ + p_brand, + p_type, + p_size, + count(distinct ps_suppkey) as supplier_cnt +from + partsupp, + part +where + p_partkey = ps_partkey + and p_brand <> 'Brand#21' + and p_type not like 'PROMO PLATED%' + and p_size in (17, 6, 23, 48, 35, 16, 34, 27) + and ps_suppkey not in ( + select + s_suppkey + from + supplier + where + s_comment like '%Customer%Complaints%' + ) +group by + p_brand, + p_type, + p_size +order by + supplier_cnt desc, + p_brand, + p_type, + p_size; + + +select /* TPC-H Q19 */ + sum(l_extendedprice* (1 - l_discount)) as revenue +from + lineitem, + part +where + ( + p_partkey = l_partkey + and p_brand = 'Brand#21' + and p_container in ('SM CASE', 'SM BOX', 'SM PACK', 'SM PKG') + and l_quantity >= 7 and l_quantity <= 7 + 10 + and p_size between 1 and 5 + and l_shipmode in ('AIR', 'AIR REG') + and l_shipinstruct = 'DELIVER IN PERSON' + ) + or + ( + p_partkey = l_partkey + and p_brand = 'Brand#35' + and p_container in ('MED BAG', 'MED BOX', 'MED PKG', 'MED PACK') + and l_quantity >= 15 and l_quantity <= 15 + 10 + and p_size between 1 and 10 + and l_shipmode in ('AIR', 'AIR REG') + and l_shipinstruct = 'DELIVER IN PERSON' + ) + or + ( + p_partkey = l_partkey + and p_brand = 'Brand#42' + and p_container in ('LG CASE', 'LG BOX', 'LG PACK', 'LG PKG') + and l_quantity >= 22 and l_quantity <= 22 + 10 + and p_size between 1 and 15 + and l_shipmode in ('AIR', 'AIR REG') + and l_shipinstruct = 'DELIVER IN PERSON' + ); + + +select /* TPC-H Q18 */ + c_name, + c_custkey, + o_orderkey, + o_orderdate, + o_totalprice, + sum(l_quantity) +from + customer, + orders, + lineitem +where + o_orderkey in ( + select + l_orderkey + from + lineitem + group by + l_orderkey having + sum(l_quantity) > 315 + ) + and c_custkey = o_custkey + and o_orderkey = l_orderkey +group by + c_name, + c_custkey, + o_orderkey, + o_orderdate, + o_totalprice +order by + o_totalprice desc, + o_orderdate +limit 100; + + +select /* TPC-H Q14 */ + 100.00 * sum(case + when p_type like 'PROMO%' + then l_extendedprice * (1 - l_discount) + else 0 + end) / sum(l_extendedprice * (1 - l_discount)) as promo_revenue +from + lineitem, + part +where + l_partkey = p_partkey + and l_shipdate >= date '1994-05-01' + and l_shipdate < dateadd(month, 1, cast('1994-05-01' as date)) +; + + +select /* TPC-H Q22 */ + cntrycode, + count(*) as numcust, + sum(c_acctbal) as totacctbal +from + ( + select + substring(c_phone,1,2) as cntrycode, + c_acctbal + from + customer + where + substring(c_phone,1,2) in + ('33', '26', '17', '11', '23', '20', '12') + and c_acctbal > ( + select + avg(c_acctbal) + from + customer + where + c_acctbal > 0.00 + and substring(c_phone,1,2) in + ('33', '26', '17', '11', '23', '20', '12') + ) + and not exists ( + select + * + from + orders + where + o_custkey = c_custkey + ) + ) as custsale +group by + cntrycode +order by + cntrycode; + + +select /* TPC-H Q11 */ + ps_partkey, + sum(ps_supplycost * ps_availqty) as value +from + partsupp, + supplier, + nation +where + ps_suppkey = s_suppkey + and s_nationkey = n_nationkey + and n_name = 'KENYA' +group by + ps_partkey having + sum(ps_supplycost * ps_availqty) > ( + select + sum(ps_supplycost * ps_availqty) * 0.0000010000 + from + partsupp, + supplier, + nation + where + ps_suppkey = s_suppkey + and s_nationkey = n_nationkey + and n_name = 'KENYA' + ) +order by + value desc; + + +select /* TPC-H Q13 */ + c_count, + count(*) as custdist +from + ( + select + c_custkey, + count(o_orderkey) + from + customer left outer join orders on + c_custkey = o_custkey + and o_comment not like '%special%requests%' + group by + c_custkey + ) as c_orders (c_custkey, c_count) +group by + c_count +order by + custdist desc, + c_count desc; + + +select /* TPC-H Q3 */ + l_orderkey, + sum(l_extendedprice * (1 - l_discount)) as revenue, + o_orderdate, + o_shippriority +from + customer, + orders, + lineitem +where + c_mktsegment = 'BUILDING' + and c_custkey = o_custkey + and l_orderkey = o_orderkey + and o_orderdate < date '1995-03-21' + and l_shipdate > date '1995-03-21' +group by + l_orderkey, + o_orderdate, + o_shippriority +order by + revenue desc, + o_orderdate +limit 10; + + +select /* TPC-H Q1 */ + l_returnflag, + l_linestatus, + sum(l_quantity) as sum_qty, + sum(l_extendedprice) as sum_base_price, + sum(l_extendedprice * (1 - l_discount)) as sum_disc_price, + sum(l_extendedprice * (1 - l_discount) * (1 + l_tax)) as sum_charge, + avg(l_quantity) as avg_qty, + avg(l_extendedprice) as avg_price, + avg(l_discount) as avg_disc, + count(*) as count_order +from + lineitem +where + l_shipdate <= dateadd(day, -100, cast('1998-12-01' as date)) +group by + l_returnflag, + l_linestatus +order by + l_returnflag, + l_linestatus; + + +select /* TPC-H Q2 */ + s_acctbal, + s_name, + n_name, + p_partkey, + p_mfgr, + s_address, + s_phone, + s_comment +from + part, + supplier, + partsupp, + nation, + region +where + p_partkey = ps_partkey + and s_suppkey = ps_suppkey + and p_size = 39 + and p_type like '%STEEL' + and s_nationkey = n_nationkey + and n_regionkey = r_regionkey + and r_name = 'EUROPE' + and ps_supplycost = ( + select + min(ps_supplycost) + from + partsupp, + supplier, + nation, + region + where + p_partkey = ps_partkey + and s_suppkey = ps_suppkey + and s_nationkey = n_nationkey + and n_regionkey = r_regionkey + and r_name = 'EUROPE' + ) +order by + s_acctbal desc, + n_name, + s_name, + p_partkey +limit 100; + + +select /* TPC-H Q5 */ + n_name, + sum(l_extendedprice * (1 - l_discount)) as revenue +from + customer, + orders, + lineitem, + supplier, + nation, + region +where + c_custkey = o_custkey + and l_orderkey = o_orderkey + and l_suppkey = s_suppkey + and c_nationkey = s_nationkey + and s_nationkey = n_nationkey + and n_regionkey = r_regionkey + and r_name = 'AFRICA' + and o_orderdate >= date '1994-01-01' + and o_orderdate < dateadd(year, 1, cast('1994-01-01' as date)) +group by + n_name +order by + revenue desc; + + +select /* TPC-H Q8 */ + o_year, + sum(case + when nation = 'INDONESIA' then volume + else 0 + end) / sum(volume) as mkt_share +from + ( + select + extract(year from o_orderdate) as o_year, + l_extendedprice * (1 - l_discount) as volume, + n2.n_name as nation + from + part, + supplier, + lineitem, + orders, + customer, + nation n1, + nation n2, + region + where + p_partkey = l_partkey + and s_suppkey = l_suppkey + and l_orderkey = o_orderkey + and o_custkey = c_custkey + and c_nationkey = n1.n_nationkey + and n1.n_regionkey = r_regionkey + and r_name = 'ASIA' + and s_nationkey = n2.n_nationkey + and o_orderdate between date '1995-01-01' and date '1996-12-31' + and p_type = 'ECONOMY ANODIZED NICKEL' + ) as all_nations +group by + o_year +order by + o_year; + + +select /* TPC-H Q20 */ + s_name, + s_address +from + supplier, + nation +where + s_suppkey in ( + select + ps_suppkey + from + partsupp + where + ps_partkey in ( + select + p_partkey + from + part + where + p_name like 'blue%' + ) + and ps_availqty > ( + select + 0.5 * sum(l_quantity) + from + lineitem + where + l_partkey = ps_partkey + and l_suppkey = ps_suppkey + and l_shipdate >= date '1995-01-01' + and l_shipdate < dateadd(year, 1, cast('1995-01-01' as date)) + ) + ) + and s_nationkey = n_nationkey + and n_name = 'UNITED KINGDOM' +order by + s_name; + + +select /* TPC-H Q12 */ + l_shipmode, + sum(case + when o_orderpriority = '1-URGENT' + or o_orderpriority = '2-HIGH' + then 1 + else 0 + end) as high_line_count, + sum(case + when o_orderpriority <> '1-URGENT' + and o_orderpriority <> '2-HIGH' + then 1 + else 0 + end) as low_line_count +from + orders, + lineitem +where + o_orderkey = l_orderkey + and l_shipmode in ('AIR', 'MAIL') + and l_commitdate < l_receiptdate + and l_shipdate < l_commitdate + and l_receiptdate >= date '1994-01-01' + and l_receiptdate < dateadd(year, 1, cast('1994-01-01' as date)) +group by + l_shipmode +order by + l_shipmode; + + +select /* TPC-H Q17 */ + sum(l_extendedprice) / 7.0 as avg_yearly +from + lineitem, + part +where + p_partkey = l_partkey + and p_brand = 'Brand#15' + and p_container = 'LG PKG' + and l_quantity < ( + select + 0.2 * avg(l_quantity) + from + lineitem + where + l_partkey = p_partkey + ); + + +select /* TPC-H Q10 */ + c_custkey, + c_name, + sum(l_extendedprice * (1 - l_discount)) as revenue, + c_acctbal, + n_name, + c_address, + c_phone, + c_comment +from + customer, + orders, + lineitem, + nation +where + c_custkey = o_custkey + and l_orderkey = o_orderkey + and o_orderdate >= date '1994-12-01' + and o_orderdate < dateadd(month, 3, cast('1994-12-01' as date)) + and l_returnflag = 'R' + and c_nationkey = n_nationkey +group by + c_custkey, + c_name, + c_acctbal, + c_phone, + n_name, + c_address, + c_comment +order by + revenue desc +limit 20; + + +select /* TPC-H Q9 */ + nation, + o_year, + sum(amount) as sum_profit +from + ( + select + n_name as nation, + extract(year from o_orderdate) as o_year, + l_extendedprice * (1 - l_discount) - ps_supplycost * l_quantity as amount + from + part, + supplier, + lineitem, + partsupp, + orders, + nation + where + s_suppkey = l_suppkey + and ps_suppkey = l_suppkey + and ps_partkey = l_partkey + and p_partkey = l_partkey + and o_orderkey = l_orderkey + and s_nationkey = n_nationkey + and p_name like '%papaya%' + ) as profit +group by + nation, + o_year +order by + nation, + o_year desc; diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/100GB/queries/query_6.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/100GB/queries/query_6.sql new file mode 100644 index 00000000..03374f78 --- /dev/null +++ b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/100GB/queries/query_6.sql @@ -0,0 +1,675 @@ +-- using 6 as a seed to the RNG + + +select /* TPC-H Q10 */ + c_custkey, + c_name, + sum(l_extendedprice * (1 - l_discount)) as revenue, + c_acctbal, + n_name, + c_address, + c_phone, + c_comment +from + customer, + orders, + lineitem, + nation +where + c_custkey = o_custkey + and l_orderkey = o_orderkey + and o_orderdate >= date '1993-09-01' + and o_orderdate < dateadd(month, 3, cast('1993-09-01' as date)) + and l_returnflag = 'R' + and c_nationkey = n_nationkey +group by + c_custkey, + c_name, + c_acctbal, + c_phone, + n_name, + c_address, + c_comment +order by + revenue desc +limit 20; + + +select /* TPC-H Q3 */ + l_orderkey, + sum(l_extendedprice * (1 - l_discount)) as revenue, + o_orderdate, + o_shippriority +from + customer, + orders, + lineitem +where + c_mktsegment = 'HOUSEHOLD' + and c_custkey = o_custkey + and l_orderkey = o_orderkey + and o_orderdate < date '1995-03-07' + and l_shipdate > date '1995-03-07' +group by + l_orderkey, + o_orderdate, + o_shippriority +order by + revenue desc, + o_orderdate +limit 10; + +with revenue as ( + select + l_suppkey as supplier_no, + sum(l_extendedprice * (1-l_discount)) as total_revenue + from + lineitem + where + l_shipdate >= date '1993-11-01' + and l_shipdate < dateadd(month, 3, cast('1993-11-01' as date)) + group by + l_suppkey +) +select /* TPC-H Q15 */ + s_suppkey, + s_name, + s_address, + s_phone, + total_revenue +from + supplier, + revenue +where + s_suppkey = supplier_no + and total_revenue = ( + select + max(total_revenue) + from + revenue + ) +order by + s_suppkey; + + +select /* TPC-H Q13 */ + c_count, + count(*) as custdist +from + ( + select + c_custkey, + count(o_orderkey) + from + customer left outer join orders on + c_custkey = o_custkey + and o_comment not like '%special%requests%' + group by + c_custkey + ) as c_orders (c_custkey, c_count) +group by + c_count +order by + custdist desc, + c_count desc; + + +select /* TPC-H Q6 */ + sum(l_extendedprice * l_discount) as revenue +from + lineitem +where + l_shipdate >= date '1994-01-01' + and l_shipdate < dateadd(year, 1, cast('1994-01-01' as date)) + and l_discount between 0.02 - 0.01 and 0.02 + 0.01 + and l_quantity < 24; + + +select /* TPC-H Q8 */ + o_year, + sum(case + when nation = 'ARGENTINA' then volume + else 0 + end) / sum(volume) as mkt_share +from + ( + select + extract(year from o_orderdate) as o_year, + l_extendedprice * (1 - l_discount) as volume, + n2.n_name as nation + from + part, + supplier, + lineitem, + orders, + customer, + nation n1, + nation n2, + region + where + p_partkey = l_partkey + and s_suppkey = l_suppkey + and l_orderkey = o_orderkey + and o_custkey = c_custkey + and c_nationkey = n1.n_nationkey + and n1.n_regionkey = r_regionkey + and r_name = 'AMERICA' + and s_nationkey = n2.n_nationkey + and o_orderdate between date '1995-01-01' and date '1996-12-31' + and p_type = 'LARGE POLISHED NICKEL' + ) as all_nations +group by + o_year +order by + o_year; + + +select /* TPC-H Q9 */ + nation, + o_year, + sum(amount) as sum_profit +from + ( + select + n_name as nation, + extract(year from o_orderdate) as o_year, + l_extendedprice * (1 - l_discount) - ps_supplycost * l_quantity as amount + from + part, + supplier, + lineitem, + partsupp, + orders, + nation + where + s_suppkey = l_suppkey + and ps_suppkey = l_suppkey + and ps_partkey = l_partkey + and p_partkey = l_partkey + and o_orderkey = l_orderkey + and s_nationkey = n_nationkey + and p_name like '%navajo%' + ) as profit +group by + nation, + o_year +order by + nation, + o_year desc; + + +select /* TPC-H Q7 */ + supp_nation, + cust_nation, + l_year, + sum(volume) as revenue +from + ( + select + n1.n_name as supp_nation, + n2.n_name as cust_nation, + extract(year from l_shipdate) as l_year, + l_extendedprice * (1 - l_discount) as volume + from + supplier, + lineitem, + orders, + customer, + nation n1, + nation n2 + where + s_suppkey = l_suppkey + and o_orderkey = l_orderkey + and c_custkey = o_custkey + and s_nationkey = n1.n_nationkey + and c_nationkey = n2.n_nationkey + and ( + (n1.n_name = 'ARGENTINA' and n2.n_name = 'MOROCCO') + or (n1.n_name = 'MOROCCO' and n2.n_name = 'ARGENTINA') + ) + and l_shipdate between date '1995-01-01' and date '1996-12-31' + ) as shipping +group by + supp_nation, + cust_nation, + l_year +order by + supp_nation, + cust_nation, + l_year; + + +select /* TPC-H Q4 */ + o_orderpriority, + count(*) as order_count +from + orders +where + o_orderdate >= date '1993-12-01' + and o_orderdate < dateadd(month, 3, cast('1993-12-01' as date)) + and exists ( + select + * + from + lineitem + where + l_orderkey = o_orderkey + and l_commitdate < l_receiptdate + ) +group by + o_orderpriority +order by + o_orderpriority; + + +select /* TPC-H Q11 */ + ps_partkey, + sum(ps_supplycost * ps_availqty) as value +from + partsupp, + supplier, + nation +where + ps_suppkey = s_suppkey + and s_nationkey = n_nationkey + and n_name = 'BRAZIL' +group by + ps_partkey having + sum(ps_supplycost * ps_availqty) > ( + select + sum(ps_supplycost * ps_availqty) * 0.0000010000 + from + partsupp, + supplier, + nation + where + ps_suppkey = s_suppkey + and s_nationkey = n_nationkey + and n_name = 'BRAZIL' + ) +order by + value desc; + + +select /* TPC-H Q22 */ + cntrycode, + count(*) as numcust, + sum(c_acctbal) as totacctbal +from + ( + select + substring(c_phone,1,2) as cntrycode, + c_acctbal + from + customer + where + substring(c_phone,1,2) in + ('23', '24', '13', '16', '25', '33', '14') + and c_acctbal > ( + select + avg(c_acctbal) + from + customer + where + c_acctbal > 0.00 + and substring(c_phone,1,2) in + ('23', '24', '13', '16', '25', '33', '14') + ) + and not exists ( + select + * + from + orders + where + o_custkey = c_custkey + ) + ) as custsale +group by + cntrycode +order by + cntrycode; + + +select /* TPC-H Q18 */ + c_name, + c_custkey, + o_orderkey, + o_orderdate, + o_totalprice, + sum(l_quantity) +from + customer, + orders, + lineitem +where + o_orderkey in ( + select + l_orderkey + from + lineitem + group by + l_orderkey having + sum(l_quantity) > 313 + ) + and c_custkey = o_custkey + and o_orderkey = l_orderkey +group by + c_name, + c_custkey, + o_orderkey, + o_orderdate, + o_totalprice +order by + o_totalprice desc, + o_orderdate +limit 100; + + +select /* TPC-H Q12 */ + l_shipmode, + sum(case + when o_orderpriority = '1-URGENT' + or o_orderpriority = '2-HIGH' + then 1 + else 0 + end) as high_line_count, + sum(case + when o_orderpriority <> '1-URGENT' + and o_orderpriority <> '2-HIGH' + then 1 + else 0 + end) as low_line_count +from + orders, + lineitem +where + o_orderkey = l_orderkey + and l_shipmode in ('SHIP', 'AIR') + and l_commitdate < l_receiptdate + and l_shipdate < l_commitdate + and l_receiptdate >= date '1994-01-01' + and l_receiptdate < dateadd(year, 1, cast('1994-01-01' as date)) +group by + l_shipmode +order by + l_shipmode; + + +select /* TPC-H Q1 */ + l_returnflag, + l_linestatus, + sum(l_quantity) as sum_qty, + sum(l_extendedprice) as sum_base_price, + sum(l_extendedprice * (1 - l_discount)) as sum_disc_price, + sum(l_extendedprice * (1 - l_discount) * (1 + l_tax)) as sum_charge, + avg(l_quantity) as avg_qty, + avg(l_extendedprice) as avg_price, + avg(l_discount) as avg_disc, + count(*) as count_order +from + lineitem +where + l_shipdate <= dateadd(day, -108, cast('1998-12-01' as date)) +group by + l_returnflag, + l_linestatus +order by + l_returnflag, + l_linestatus; + + +select /* TPC-H Q5 */ + n_name, + sum(l_extendedprice * (1 - l_discount)) as revenue +from + customer, + orders, + lineitem, + supplier, + nation, + region +where + c_custkey = o_custkey + and l_orderkey = o_orderkey + and l_suppkey = s_suppkey + and c_nationkey = s_nationkey + and s_nationkey = n_nationkey + and n_regionkey = r_regionkey + and r_name = 'AMERICA' + and o_orderdate >= date '1994-01-01' + and o_orderdate < dateadd(year, 1, cast('1994-01-01' as date)) +group by + n_name +order by + revenue desc; + + +select /* TPC-H Q16 */ + p_brand, + p_type, + p_size, + count(distinct ps_suppkey) as supplier_cnt +from + partsupp, + part +where + p_partkey = ps_partkey + and p_brand <> 'Brand#11' + and p_type not like 'SMALL BRUSHED%' + and p_size in (21, 26, 8, 29, 31, 9, 14, 5) + and ps_suppkey not in ( + select + s_suppkey + from + supplier + where + s_comment like '%Customer%Complaints%' + ) +group by + p_brand, + p_type, + p_size +order by + supplier_cnt desc, + p_brand, + p_type, + p_size; + + +select /* TPC-H Q2 */ + s_acctbal, + s_name, + n_name, + p_partkey, + p_mfgr, + s_address, + s_phone, + s_comment +from + part, + supplier, + partsupp, + nation, + region +where + p_partkey = ps_partkey + and s_suppkey = ps_suppkey + and p_size = 27 + and p_type like '%BRASS' + and s_nationkey = n_nationkey + and n_regionkey = r_regionkey + and r_name = 'AFRICA' + and ps_supplycost = ( + select + min(ps_supplycost) + from + partsupp, + supplier, + nation, + region + where + p_partkey = ps_partkey + and s_suppkey = ps_suppkey + and s_nationkey = n_nationkey + and n_regionkey = r_regionkey + and r_name = 'AFRICA' + ) +order by + s_acctbal desc, + n_name, + s_name, + p_partkey +limit 100; + + +select /* TPC-H Q14 */ + 100.00 * sum(case + when p_type like 'PROMO%' + then l_extendedprice * (1 - l_discount) + else 0 + end) / sum(l_extendedprice * (1 - l_discount)) as promo_revenue +from + lineitem, + part +where + l_partkey = p_partkey + and l_shipdate >= date '1994-08-01' + and l_shipdate < dateadd(month, 1, cast('1994-08-01' as date)) +; + + +select /* TPC-H Q19 */ + sum(l_extendedprice* (1 - l_discount)) as revenue +from + lineitem, + part +where + ( + p_partkey = l_partkey + and p_brand = 'Brand#33' + and p_container in ('SM CASE', 'SM BOX', 'SM PACK', 'SM PKG') + and l_quantity >= 2 and l_quantity <= 2 + 10 + and p_size between 1 and 5 + and l_shipmode in ('AIR', 'AIR REG') + and l_shipinstruct = 'DELIVER IN PERSON' + ) + or + ( + p_partkey = l_partkey + and p_brand = 'Brand#13' + and p_container in ('MED BAG', 'MED BOX', 'MED PKG', 'MED PACK') + and l_quantity >= 16 and l_quantity <= 16 + 10 + and p_size between 1 and 10 + and l_shipmode in ('AIR', 'AIR REG') + and l_shipinstruct = 'DELIVER IN PERSON' + ) + or + ( + p_partkey = l_partkey + and p_brand = 'Brand#31' + and p_container in ('LG CASE', 'LG BOX', 'LG PACK', 'LG PKG') + and l_quantity >= 30 and l_quantity <= 30 + 10 + and p_size between 1 and 15 + and l_shipmode in ('AIR', 'AIR REG') + and l_shipinstruct = 'DELIVER IN PERSON' + ); + + +select /* TPC-H Q20 */ + s_name, + s_address +from + supplier, + nation +where + s_suppkey in ( + select + ps_suppkey + from + partsupp + where + ps_partkey in ( + select + p_partkey + from + part + where + p_name like 'linen%' + ) + and ps_availqty > ( + select + 0.5 * sum(l_quantity) + from + lineitem + where + l_partkey = ps_partkey + and l_suppkey = ps_suppkey + and l_shipdate >= date '1993-01-01' + and l_shipdate < dateadd(year, 1, cast('1993-01-01' as date)) + ) + ) + and s_nationkey = n_nationkey + and n_name = 'JORDAN' +order by + s_name; + + +select /* TPC-H Q17 */ + sum(l_extendedprice) / 7.0 as avg_yearly +from + lineitem, + part +where + p_partkey = l_partkey + and p_brand = 'Brand#12' + and p_container = 'MED CASE' + and l_quantity < ( + select + 0.2 * avg(l_quantity) + from + lineitem + where + l_partkey = p_partkey + ); + + +select /* TPC-H Q21 */ + s_name, + count(*) as numwait +from + supplier, + lineitem l1, + orders, + nation +where + s_suppkey = l1.l_suppkey + and o_orderkey = l1.l_orderkey + and o_orderstatus = 'F' + and l1.l_receiptdate > l1.l_commitdate + and exists ( + select + * + from + lineitem l2 + where + l2.l_orderkey = l1.l_orderkey + and l2.l_suppkey <> l1.l_suppkey + ) + and not exists ( + select + * + from + lineitem l3 + where + l3.l_orderkey = l1.l_orderkey + and l3.l_suppkey <> l1.l_suppkey + and l3.l_receiptdate > l3.l_commitdate + ) + and s_nationkey = n_nationkey + and n_name = 'CANADA' +group by + s_name +order by + numwait desc, + s_name +limit 100; diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/100GB/queries/query_7.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/100GB/queries/query_7.sql new file mode 100644 index 00000000..396ded6e --- /dev/null +++ b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/100GB/queries/query_7.sql @@ -0,0 +1,675 @@ +-- using 7 as a seed to the RNG + + +select /* TPC-H Q18 */ + c_name, + c_custkey, + o_orderkey, + o_orderdate, + o_totalprice, + sum(l_quantity) +from + customer, + orders, + lineitem +where + o_orderkey in ( + select + l_orderkey + from + lineitem + group by + l_orderkey having + sum(l_quantity) > 314 + ) + and c_custkey = o_custkey + and o_orderkey = l_orderkey +group by + c_name, + c_custkey, + o_orderkey, + o_orderdate, + o_totalprice +order by + o_totalprice desc, + o_orderdate +limit 100; + + +select /* TPC-H Q8 */ + o_year, + sum(case + when nation = 'CHINA' then volume + else 0 + end) / sum(volume) as mkt_share +from + ( + select + extract(year from o_orderdate) as o_year, + l_extendedprice * (1 - l_discount) as volume, + n2.n_name as nation + from + part, + supplier, + lineitem, + orders, + customer, + nation n1, + nation n2, + region + where + p_partkey = l_partkey + and s_suppkey = l_suppkey + and l_orderkey = o_orderkey + and o_custkey = c_custkey + and c_nationkey = n1.n_nationkey + and n1.n_regionkey = r_regionkey + and r_name = 'ASIA' + and s_nationkey = n2.n_nationkey + and o_orderdate between date '1995-01-01' and date '1996-12-31' + and p_type = 'LARGE BURNISHED NICKEL' + ) as all_nations +group by + o_year +order by + o_year; + + +select /* TPC-H Q20 */ + s_name, + s_address +from + supplier, + nation +where + s_suppkey in ( + select + ps_suppkey + from + partsupp + where + ps_partkey in ( + select + p_partkey + from + part + where + p_name like 'tan%' + ) + and ps_availqty > ( + select + 0.5 * sum(l_quantity) + from + lineitem + where + l_partkey = ps_partkey + and l_suppkey = ps_suppkey + and l_shipdate >= date '1997-01-01' + and l_shipdate < dateadd(year, 1, cast('1997-01-01' as date)) + ) + ) + and s_nationkey = n_nationkey + and n_name = 'CANADA' +order by + s_name; + + +select /* TPC-H Q21 */ + s_name, + count(*) as numwait +from + supplier, + lineitem l1, + orders, + nation +where + s_suppkey = l1.l_suppkey + and o_orderkey = l1.l_orderkey + and o_orderstatus = 'F' + and l1.l_receiptdate > l1.l_commitdate + and exists ( + select + * + from + lineitem l2 + where + l2.l_orderkey = l1.l_orderkey + and l2.l_suppkey <> l1.l_suppkey + ) + and not exists ( + select + * + from + lineitem l3 + where + l3.l_orderkey = l1.l_orderkey + and l3.l_suppkey <> l1.l_suppkey + and l3.l_receiptdate > l3.l_commitdate + ) + and s_nationkey = n_nationkey + and n_name = 'SAUDI ARABIA' +group by + s_name +order by + numwait desc, + s_name +limit 100; + + +select /* TPC-H Q2 */ + s_acctbal, + s_name, + n_name, + p_partkey, + p_mfgr, + s_address, + s_phone, + s_comment +from + part, + supplier, + partsupp, + nation, + region +where + p_partkey = ps_partkey + and s_suppkey = ps_suppkey + and p_size = 15 + and p_type like '%NICKEL' + and s_nationkey = n_nationkey + and n_regionkey = r_regionkey + and r_name = 'EUROPE' + and ps_supplycost = ( + select + min(ps_supplycost) + from + partsupp, + supplier, + nation, + region + where + p_partkey = ps_partkey + and s_suppkey = ps_suppkey + and s_nationkey = n_nationkey + and n_regionkey = r_regionkey + and r_name = 'EUROPE' + ) +order by + s_acctbal desc, + n_name, + s_name, + p_partkey +limit 100; + + +select /* TPC-H Q4 */ + o_orderpriority, + count(*) as order_count +from + orders +where + o_orderdate >= date '1996-07-01' + and o_orderdate < dateadd(month, 3, cast('1996-07-01' as date)) + and exists ( + select + * + from + lineitem + where + l_orderkey = o_orderkey + and l_commitdate < l_receiptdate + ) +group by + o_orderpriority +order by + o_orderpriority; + + +select /* TPC-H Q22 */ + cntrycode, + count(*) as numcust, + sum(c_acctbal) as totacctbal +from + ( + select + substring(c_phone,1,2) as cntrycode, + c_acctbal + from + customer + where + substring(c_phone,1,2) in + ('13', '23', '33', '28', '27', '26', '12') + and c_acctbal > ( + select + avg(c_acctbal) + from + customer + where + c_acctbal > 0.00 + and substring(c_phone,1,2) in + ('13', '23', '33', '28', '27', '26', '12') + ) + and not exists ( + select + * + from + orders + where + o_custkey = c_custkey + ) + ) as custsale +group by + cntrycode +order by + cntrycode; + + +select /* TPC-H Q17 */ + sum(l_extendedprice) / 7.0 as avg_yearly +from + lineitem, + part +where + p_partkey = l_partkey + and p_brand = 'Brand#14' + and p_container = 'MED BAG' + and l_quantity < ( + select + 0.2 * avg(l_quantity) + from + lineitem + where + l_partkey = p_partkey + ); + + +select /* TPC-H Q1 */ + l_returnflag, + l_linestatus, + sum(l_quantity) as sum_qty, + sum(l_extendedprice) as sum_base_price, + sum(l_extendedprice * (1 - l_discount)) as sum_disc_price, + sum(l_extendedprice * (1 - l_discount) * (1 + l_tax)) as sum_charge, + avg(l_quantity) as avg_qty, + avg(l_extendedprice) as avg_price, + avg(l_discount) as avg_disc, + count(*) as count_order +from + lineitem +where + l_shipdate <= dateadd(day, -116, cast('1998-12-01' as date)) +group by + l_returnflag, + l_linestatus +order by + l_returnflag, + l_linestatus; + + +select /* TPC-H Q11 */ + ps_partkey, + sum(ps_supplycost * ps_availqty) as value +from + partsupp, + supplier, + nation +where + ps_suppkey = s_suppkey + and s_nationkey = n_nationkey + and n_name = 'MOROCCO' +group by + ps_partkey having + sum(ps_supplycost * ps_availqty) > ( + select + sum(ps_supplycost * ps_availqty) * 0.0000010000 + from + partsupp, + supplier, + nation + where + ps_suppkey = s_suppkey + and s_nationkey = n_nationkey + and n_name = 'MOROCCO' + ) +order by + value desc; + + +select /* TPC-H Q9 */ + nation, + o_year, + sum(amount) as sum_profit +from + ( + select + n_name as nation, + extract(year from o_orderdate) as o_year, + l_extendedprice * (1 - l_discount) - ps_supplycost * l_quantity as amount + from + part, + supplier, + lineitem, + partsupp, + orders, + nation + where + s_suppkey = l_suppkey + and ps_suppkey = l_suppkey + and ps_partkey = l_partkey + and p_partkey = l_partkey + and o_orderkey = l_orderkey + and s_nationkey = n_nationkey + and p_name like '%medium%' + ) as profit +group by + nation, + o_year +order by + nation, + o_year desc; + + +select /* TPC-H Q19 */ + sum(l_extendedprice* (1 - l_discount)) as revenue +from + lineitem, + part +where + ( + p_partkey = l_partkey + and p_brand = 'Brand#35' + and p_container in ('SM CASE', 'SM BOX', 'SM PACK', 'SM PKG') + and l_quantity >= 7 and l_quantity <= 7 + 10 + and p_size between 1 and 5 + and l_shipmode in ('AIR', 'AIR REG') + and l_shipinstruct = 'DELIVER IN PERSON' + ) + or + ( + p_partkey = l_partkey + and p_brand = 'Brand#51' + and p_container in ('MED BAG', 'MED BOX', 'MED PKG', 'MED PACK') + and l_quantity >= 17 and l_quantity <= 17 + 10 + and p_size between 1 and 10 + and l_shipmode in ('AIR', 'AIR REG') + and l_shipinstruct = 'DELIVER IN PERSON' + ) + or + ( + p_partkey = l_partkey + and p_brand = 'Brand#35' + and p_container in ('LG CASE', 'LG BOX', 'LG PACK', 'LG PKG') + and l_quantity >= 26 and l_quantity <= 26 + 10 + and p_size between 1 and 15 + and l_shipmode in ('AIR', 'AIR REG') + and l_shipinstruct = 'DELIVER IN PERSON' + ); + + +select /* TPC-H Q3 */ + l_orderkey, + sum(l_extendedprice * (1 - l_discount)) as revenue, + o_orderdate, + o_shippriority +from + customer, + orders, + lineitem +where + c_mktsegment = 'BUILDING' + and c_custkey = o_custkey + and l_orderkey = o_orderkey + and o_orderdate < date '1995-03-23' + and l_shipdate > date '1995-03-23' +group by + l_orderkey, + o_orderdate, + o_shippriority +order by + revenue desc, + o_orderdate +limit 10; + + +select /* TPC-H Q13 */ + c_count, + count(*) as custdist +from + ( + select + c_custkey, + count(o_orderkey) + from + customer left outer join orders on + c_custkey = o_custkey + and o_comment not like '%special%requests%' + group by + c_custkey + ) as c_orders (c_custkey, c_count) +group by + c_count +order by + custdist desc, + c_count desc; + + +select /* TPC-H Q5 */ + n_name, + sum(l_extendedprice * (1 - l_discount)) as revenue +from + customer, + orders, + lineitem, + supplier, + nation, + region +where + c_custkey = o_custkey + and l_orderkey = o_orderkey + and l_suppkey = s_suppkey + and c_nationkey = s_nationkey + and s_nationkey = n_nationkey + and n_regionkey = r_regionkey + and r_name = 'ASIA' + and o_orderdate >= date '1994-01-01' + and o_orderdate < dateadd(year, 1, cast('1994-01-01' as date)) +group by + n_name +order by + revenue desc; + + +select /* TPC-H Q7 */ + supp_nation, + cust_nation, + l_year, + sum(volume) as revenue +from + ( + select + n1.n_name as supp_nation, + n2.n_name as cust_nation, + extract(year from l_shipdate) as l_year, + l_extendedprice * (1 - l_discount) as volume + from + supplier, + lineitem, + orders, + customer, + nation n1, + nation n2 + where + s_suppkey = l_suppkey + and o_orderkey = l_orderkey + and c_custkey = o_custkey + and s_nationkey = n1.n_nationkey + and c_nationkey = n2.n_nationkey + and ( + (n1.n_name = 'CHINA' and n2.n_name = 'JORDAN') + or (n1.n_name = 'JORDAN' and n2.n_name = 'CHINA') + ) + and l_shipdate between date '1995-01-01' and date '1996-12-31' + ) as shipping +group by + supp_nation, + cust_nation, + l_year +order by + supp_nation, + cust_nation, + l_year; + + +select /* TPC-H Q10 */ + c_custkey, + c_name, + sum(l_extendedprice * (1 - l_discount)) as revenue, + c_acctbal, + n_name, + c_address, + c_phone, + c_comment +from + customer, + orders, + lineitem, + nation +where + c_custkey = o_custkey + and l_orderkey = o_orderkey + and o_orderdate >= date '1994-06-01' + and o_orderdate < dateadd(month, 3, cast('1994-06-01' as date)) + and l_returnflag = 'R' + and c_nationkey = n_nationkey +group by + c_custkey, + c_name, + c_acctbal, + c_phone, + n_name, + c_address, + c_comment +order by + revenue desc +limit 20; + + +select /* TPC-H Q16 */ + p_brand, + p_type, + p_size, + count(distinct ps_suppkey) as supplier_cnt +from + partsupp, + part +where + p_partkey = ps_partkey + and p_brand <> 'Brand#41' + and p_type not like 'ECONOMY ANODIZED%' + and p_size in (24, 47, 41, 9, 28, 2, 37, 35) + and ps_suppkey not in ( + select + s_suppkey + from + supplier + where + s_comment like '%Customer%Complaints%' + ) +group by + p_brand, + p_type, + p_size +order by + supplier_cnt desc, + p_brand, + p_type, + p_size; + + +select /* TPC-H Q6 */ + sum(l_extendedprice * l_discount) as revenue +from + lineitem +where + l_shipdate >= date '1994-01-01' + and l_shipdate < dateadd(year, 1, cast('1994-01-01' as date)) + and l_discount between 0.08 - 0.01 and 0.08 + 0.01 + and l_quantity < 25; + + +select /* TPC-H Q14 */ + 100.00 * sum(case + when p_type like 'PROMO%' + then l_extendedprice * (1 - l_discount) + else 0 + end) / sum(l_extendedprice * (1 - l_discount)) as promo_revenue +from + lineitem, + part +where + l_partkey = p_partkey + and l_shipdate >= date '1994-11-01' + and l_shipdate < dateadd(month, 1, cast('1994-11-01' as date)) +; + +with revenue as ( + select + l_suppkey as supplier_no, + sum(l_extendedprice * (1-l_discount)) as total_revenue + from + lineitem + where + l_shipdate >= date '1996-06-01' + and l_shipdate < dateadd(month, 3, cast('1996-06-01' as date)) + group by + l_suppkey +) +select /* TPC-H Q15 */ + s_suppkey, + s_name, + s_address, + s_phone, + total_revenue +from + supplier, + revenue +where + s_suppkey = supplier_no + and total_revenue = ( + select + max(total_revenue) + from + revenue + ) +order by + s_suppkey; + + +select /* TPC-H Q12 */ + l_shipmode, + sum(case + when o_orderpriority = '1-URGENT' + or o_orderpriority = '2-HIGH' + then 1 + else 0 + end) as high_line_count, + sum(case + when o_orderpriority <> '1-URGENT' + and o_orderpriority <> '2-HIGH' + then 1 + else 0 + end) as low_line_count +from + orders, + lineitem +where + o_orderkey = l_orderkey + and l_shipmode in ('FOB', 'AIR') + and l_commitdate < l_receiptdate + and l_shipdate < l_commitdate + and l_receiptdate >= date '1994-01-01' + and l_receiptdate < dateadd(year, 1, cast('1994-01-01' as date)) +group by + l_shipmode +order by + l_shipmode; diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/100GB/queries/query_8.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/100GB/queries/query_8.sql new file mode 100644 index 00000000..b37894ad --- /dev/null +++ b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/100GB/queries/query_8.sql @@ -0,0 +1,675 @@ +-- using 8 as a seed to the RNG + + +select /* TPC-H Q19 */ + sum(l_extendedprice* (1 - l_discount)) as revenue +from + lineitem, + part +where + ( + p_partkey = l_partkey + and p_brand = 'Brand#32' + and p_container in ('SM CASE', 'SM BOX', 'SM PACK', 'SM PKG') + and l_quantity >= 3 and l_quantity <= 3 + 10 + and p_size between 1 and 5 + and l_shipmode in ('AIR', 'AIR REG') + and l_shipinstruct = 'DELIVER IN PERSON' + ) + or + ( + p_partkey = l_partkey + and p_brand = 'Brand#34' + and p_container in ('MED BAG', 'MED BOX', 'MED PKG', 'MED PACK') + and l_quantity >= 18 and l_quantity <= 18 + 10 + and p_size between 1 and 10 + and l_shipmode in ('AIR', 'AIR REG') + and l_shipinstruct = 'DELIVER IN PERSON' + ) + or + ( + p_partkey = l_partkey + and p_brand = 'Brand#34' + and p_container in ('LG CASE', 'LG BOX', 'LG PACK', 'LG PKG') + and l_quantity >= 22 and l_quantity <= 22 + 10 + and p_size between 1 and 15 + and l_shipmode in ('AIR', 'AIR REG') + and l_shipinstruct = 'DELIVER IN PERSON' + ); + + +select /* TPC-H Q1 */ + l_returnflag, + l_linestatus, + sum(l_quantity) as sum_qty, + sum(l_extendedprice) as sum_base_price, + sum(l_extendedprice * (1 - l_discount)) as sum_disc_price, + sum(l_extendedprice * (1 - l_discount) * (1 + l_tax)) as sum_charge, + avg(l_quantity) as avg_qty, + avg(l_extendedprice) as avg_price, + avg(l_discount) as avg_disc, + count(*) as count_order +from + lineitem +where + l_shipdate <= dateadd(day, -63, cast('1998-12-01' as date)) +group by + l_returnflag, + l_linestatus +order by + l_returnflag, + l_linestatus; + +with revenue as ( + select + l_suppkey as supplier_no, + sum(l_extendedprice * (1-l_discount)) as total_revenue + from + lineitem + where + l_shipdate >= date '1994-02-01' + and l_shipdate < dateadd(month, 3, cast('1994-02-01' as date)) + group by + l_suppkey +) +select /* TPC-H Q15 */ + s_suppkey, + s_name, + s_address, + s_phone, + total_revenue +from + supplier, + revenue +where + s_suppkey = supplier_no + and total_revenue = ( + select + max(total_revenue) + from + revenue + ) +order by + s_suppkey; + + +select /* TPC-H Q17 */ + sum(l_extendedprice) / 7.0 as avg_yearly +from + lineitem, + part +where + p_partkey = l_partkey + and p_brand = 'Brand#11' + and p_container = 'MED PKG' + and l_quantity < ( + select + 0.2 * avg(l_quantity) + from + lineitem + where + l_partkey = p_partkey + ); + + +select /* TPC-H Q5 */ + n_name, + sum(l_extendedprice * (1 - l_discount)) as revenue +from + customer, + orders, + lineitem, + supplier, + nation, + region +where + c_custkey = o_custkey + and l_orderkey = o_orderkey + and l_suppkey = s_suppkey + and c_nationkey = s_nationkey + and s_nationkey = n_nationkey + and n_regionkey = r_regionkey + and r_name = 'EUROPE' + and o_orderdate >= date '1994-01-01' + and o_orderdate < dateadd(year, 1, cast('1994-01-01' as date)) +group by + n_name +order by + revenue desc; + + +select /* TPC-H Q8 */ + o_year, + sum(case + when nation = 'IRAN' then volume + else 0 + end) / sum(volume) as mkt_share +from + ( + select + extract(year from o_orderdate) as o_year, + l_extendedprice * (1 - l_discount) as volume, + n2.n_name as nation + from + part, + supplier, + lineitem, + orders, + customer, + nation n1, + nation n2, + region + where + p_partkey = l_partkey + and s_suppkey = l_suppkey + and l_orderkey = o_orderkey + and o_custkey = c_custkey + and c_nationkey = n1.n_nationkey + and n1.n_regionkey = r_regionkey + and r_name = 'MIDDLE EAST' + and s_nationkey = n2.n_nationkey + and o_orderdate between date '1995-01-01' and date '1996-12-31' + and p_type = 'MEDIUM BRUSHED NICKEL' + ) as all_nations +group by + o_year +order by + o_year; + + +select /* TPC-H Q9 */ + nation, + o_year, + sum(amount) as sum_profit +from + ( + select + n_name as nation, + extract(year from o_orderdate) as o_year, + l_extendedprice * (1 - l_discount) - ps_supplycost * l_quantity as amount + from + part, + supplier, + lineitem, + partsupp, + orders, + nation + where + s_suppkey = l_suppkey + and ps_suppkey = l_suppkey + and ps_partkey = l_partkey + and p_partkey = l_partkey + and o_orderkey = l_orderkey + and s_nationkey = n_nationkey + and p_name like '%lemon%' + ) as profit +group by + nation, + o_year +order by + nation, + o_year desc; + + +select /* TPC-H Q12 */ + l_shipmode, + sum(case + when o_orderpriority = '1-URGENT' + or o_orderpriority = '2-HIGH' + then 1 + else 0 + end) as high_line_count, + sum(case + when o_orderpriority <> '1-URGENT' + and o_orderpriority <> '2-HIGH' + then 1 + else 0 + end) as low_line_count +from + orders, + lineitem +where + o_orderkey = l_orderkey + and l_shipmode in ('MAIL', 'AIR') + and l_commitdate < l_receiptdate + and l_shipdate < l_commitdate + and l_receiptdate >= date '1995-01-01' + and l_receiptdate < dateadd(year, 1, cast('1995-01-01' as date)) +group by + l_shipmode +order by + l_shipmode; + + +select /* TPC-H Q14 */ + 100.00 * sum(case + when p_type like 'PROMO%' + then l_extendedprice * (1 - l_discount) + else 0 + end) / sum(l_extendedprice * (1 - l_discount)) as promo_revenue +from + lineitem, + part +where + l_partkey = p_partkey + and l_shipdate >= date '1995-02-01' + and l_shipdate < dateadd(month, 1, cast('1995-02-01' as date)) +; + + +select /* TPC-H Q7 */ + supp_nation, + cust_nation, + l_year, + sum(volume) as revenue +from + ( + select + n1.n_name as supp_nation, + n2.n_name as cust_nation, + extract(year from l_shipdate) as l_year, + l_extendedprice * (1 - l_discount) as volume + from + supplier, + lineitem, + orders, + customer, + nation n1, + nation n2 + where + s_suppkey = l_suppkey + and o_orderkey = l_orderkey + and c_custkey = o_custkey + and s_nationkey = n1.n_nationkey + and c_nationkey = n2.n_nationkey + and ( + (n1.n_name = 'IRAN' and n2.n_name = 'IRAQ') + or (n1.n_name = 'IRAQ' and n2.n_name = 'IRAN') + ) + and l_shipdate between date '1995-01-01' and date '1996-12-31' + ) as shipping +group by + supp_nation, + cust_nation, + l_year +order by + supp_nation, + cust_nation, + l_year; + + +select /* TPC-H Q4 */ + o_orderpriority, + count(*) as order_count +from + orders +where + o_orderdate >= date '1994-04-01' + and o_orderdate < dateadd(month, 3, cast('1994-04-01' as date)) + and exists ( + select + * + from + lineitem + where + l_orderkey = o_orderkey + and l_commitdate < l_receiptdate + ) +group by + o_orderpriority +order by + o_orderpriority; + + +select /* TPC-H Q3 */ + l_orderkey, + sum(l_extendedprice * (1 - l_discount)) as revenue, + o_orderdate, + o_shippriority +from + customer, + orders, + lineitem +where + c_mktsegment = 'HOUSEHOLD' + and c_custkey = o_custkey + and l_orderkey = o_orderkey + and o_orderdate < date '1995-03-09' + and l_shipdate > date '1995-03-09' +group by + l_orderkey, + o_orderdate, + o_shippriority +order by + revenue desc, + o_orderdate +limit 10; + + +select /* TPC-H Q20 */ + s_name, + s_address +from + supplier, + nation +where + s_suppkey in ( + select + ps_suppkey + from + partsupp + where + ps_partkey in ( + select + p_partkey + from + part + where + p_name like 'ghost%' + ) + and ps_availqty > ( + select + 0.5 * sum(l_quantity) + from + lineitem + where + l_partkey = ps_partkey + and l_suppkey = ps_suppkey + and l_shipdate >= date '1995-01-01' + and l_shipdate < dateadd(year, 1, cast('1995-01-01' as date)) + ) + ) + and s_nationkey = n_nationkey + and n_name = 'PERU' +order by + s_name; + + +select /* TPC-H Q16 */ + p_brand, + p_type, + p_size, + count(distinct ps_suppkey) as supplier_cnt +from + partsupp, + part +where + p_partkey = ps_partkey + and p_brand <> 'Brand#21' + and p_type not like 'STANDARD PLATED%' + and p_size in (27, 18, 26, 37, 25, 40, 16, 39) + and ps_suppkey not in ( + select + s_suppkey + from + supplier + where + s_comment like '%Customer%Complaints%' + ) +group by + p_brand, + p_type, + p_size +order by + supplier_cnt desc, + p_brand, + p_type, + p_size; + + +select /* TPC-H Q6 */ + sum(l_extendedprice * l_discount) as revenue +from + lineitem +where + l_shipdate >= date '1994-01-01' + and l_shipdate < dateadd(year, 1, cast('1994-01-01' as date)) + and l_discount between 0.05 - 0.01 and 0.05 + 0.01 + and l_quantity < 24; + + +select /* TPC-H Q22 */ + cntrycode, + count(*) as numcust, + sum(c_acctbal) as totacctbal +from + ( + select + substring(c_phone,1,2) as cntrycode, + c_acctbal + from + customer + where + substring(c_phone,1,2) in + ('27', '21', '29', '17', '12', '19', '22') + and c_acctbal > ( + select + avg(c_acctbal) + from + customer + where + c_acctbal > 0.00 + and substring(c_phone,1,2) in + ('27', '21', '29', '17', '12', '19', '22') + ) + and not exists ( + select + * + from + orders + where + o_custkey = c_custkey + ) + ) as custsale +group by + cntrycode +order by + cntrycode; + + +select /* TPC-H Q10 */ + c_custkey, + c_name, + sum(l_extendedprice * (1 - l_discount)) as revenue, + c_acctbal, + n_name, + c_address, + c_phone, + c_comment +from + customer, + orders, + lineitem, + nation +where + c_custkey = o_custkey + and l_orderkey = o_orderkey + and o_orderdate >= date '1993-03-01' + and o_orderdate < dateadd(month, 3, cast('1993-03-01' as date)) + and l_returnflag = 'R' + and c_nationkey = n_nationkey +group by + c_custkey, + c_name, + c_acctbal, + c_phone, + n_name, + c_address, + c_comment +order by + revenue desc +limit 20; + + +select /* TPC-H Q13 */ + c_count, + count(*) as custdist +from + ( + select + c_custkey, + count(o_orderkey) + from + customer left outer join orders on + c_custkey = o_custkey + and o_comment not like '%pending%requests%' + group by + c_custkey + ) as c_orders (c_custkey, c_count) +group by + c_count +order by + custdist desc, + c_count desc; + + +select /* TPC-H Q2 */ + s_acctbal, + s_name, + n_name, + p_partkey, + p_mfgr, + s_address, + s_phone, + s_comment +from + part, + supplier, + partsupp, + nation, + region +where + p_partkey = ps_partkey + and s_suppkey = ps_suppkey + and p_size = 3 + and p_type like '%TIN' + and s_nationkey = n_nationkey + and n_regionkey = r_regionkey + and r_name = 'AMERICA' + and ps_supplycost = ( + select + min(ps_supplycost) + from + partsupp, + supplier, + nation, + region + where + p_partkey = ps_partkey + and s_suppkey = ps_suppkey + and s_nationkey = n_nationkey + and n_regionkey = r_regionkey + and r_name = 'AMERICA' + ) +order by + s_acctbal desc, + n_name, + s_name, + p_partkey +limit 100; + + +select /* TPC-H Q21 */ + s_name, + count(*) as numwait +from + supplier, + lineitem l1, + orders, + nation +where + s_suppkey = l1.l_suppkey + and o_orderkey = l1.l_orderkey + and o_orderstatus = 'F' + and l1.l_receiptdate > l1.l_commitdate + and exists ( + select + * + from + lineitem l2 + where + l2.l_orderkey = l1.l_orderkey + and l2.l_suppkey <> l1.l_suppkey + ) + and not exists ( + select + * + from + lineitem l3 + where + l3.l_orderkey = l1.l_orderkey + and l3.l_suppkey <> l1.l_suppkey + and l3.l_receiptdate > l3.l_commitdate + ) + and s_nationkey = n_nationkey + and n_name = 'JAPAN' +group by + s_name +order by + numwait desc, + s_name +limit 100; + + +select /* TPC-H Q18 */ + c_name, + c_custkey, + o_orderkey, + o_orderdate, + o_totalprice, + sum(l_quantity) +from + customer, + orders, + lineitem +where + o_orderkey in ( + select + l_orderkey + from + lineitem + group by + l_orderkey having + sum(l_quantity) > 312 + ) + and c_custkey = o_custkey + and o_orderkey = l_orderkey +group by + c_name, + c_custkey, + o_orderkey, + o_orderdate, + o_totalprice +order by + o_totalprice desc, + o_orderdate +limit 100; + + +select /* TPC-H Q11 */ + ps_partkey, + sum(ps_supplycost * ps_availqty) as value +from + partsupp, + supplier, + nation +where + ps_suppkey = s_suppkey + and s_nationkey = n_nationkey + and n_name = 'CANADA' +group by + ps_partkey having + sum(ps_supplycost * ps_availqty) > ( + select + sum(ps_supplycost * ps_availqty) * 0.0000010000 + from + partsupp, + supplier, + nation + where + ps_suppkey = s_suppkey + and s_nationkey = n_nationkey + and n_name = 'CANADA' + ) +order by + value desc; diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/100GB/queries/query_9.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/100GB/queries/query_9.sql new file mode 100644 index 00000000..4e345b82 --- /dev/null +++ b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/100GB/queries/query_9.sql @@ -0,0 +1,675 @@ +-- using 9 as a seed to the RNG + + +select /* TPC-H Q8 */ + o_year, + sum(case + when nation = 'BRAZIL' then volume + else 0 + end) / sum(volume) as mkt_share +from + ( + select + extract(year from o_orderdate) as o_year, + l_extendedprice * (1 - l_discount) as volume, + n2.n_name as nation + from + part, + supplier, + lineitem, + orders, + customer, + nation n1, + nation n2, + region + where + p_partkey = l_partkey + and s_suppkey = l_suppkey + and l_orderkey = o_orderkey + and o_custkey = c_custkey + and c_nationkey = n1.n_nationkey + and n1.n_regionkey = r_regionkey + and r_name = 'AMERICA' + and s_nationkey = n2.n_nationkey + and o_orderdate between date '1995-01-01' and date '1996-12-31' + and p_type = 'MEDIUM PLATED NICKEL' + ) as all_nations +group by + o_year +order by + o_year; + + +select /* TPC-H Q13 */ + c_count, + count(*) as custdist +from + ( + select + c_custkey, + count(o_orderkey) + from + customer left outer join orders on + c_custkey = o_custkey + and o_comment not like '%pending%requests%' + group by + c_custkey + ) as c_orders (c_custkey, c_count) +group by + c_count +order by + custdist desc, + c_count desc; + + +select /* TPC-H Q2 */ + s_acctbal, + s_name, + n_name, + p_partkey, + p_mfgr, + s_address, + s_phone, + s_comment +from + part, + supplier, + partsupp, + nation, + region +where + p_partkey = ps_partkey + and s_suppkey = ps_suppkey + and p_size = 41 + and p_type like '%COPPER' + and s_nationkey = n_nationkey + and n_regionkey = r_regionkey + and r_name = 'EUROPE' + and ps_supplycost = ( + select + min(ps_supplycost) + from + partsupp, + supplier, + nation, + region + where + p_partkey = ps_partkey + and s_suppkey = ps_suppkey + and s_nationkey = n_nationkey + and n_regionkey = r_regionkey + and r_name = 'EUROPE' + ) +order by + s_acctbal desc, + n_name, + s_name, + p_partkey +limit 100; + + +select /* TPC-H Q20 */ + s_name, + s_address +from + supplier, + nation +where + s_suppkey in ( + select + ps_suppkey + from + partsupp + where + ps_partkey in ( + select + p_partkey + from + part + where + p_name like 'red%' + ) + and ps_availqty > ( + select + 0.5 * sum(l_quantity) + from + lineitem + where + l_partkey = ps_partkey + and l_suppkey = ps_suppkey + and l_shipdate >= date '1993-01-01' + and l_shipdate < dateadd(year, 1, cast('1993-01-01' as date)) + ) + ) + and s_nationkey = n_nationkey + and n_name = 'GERMANY' +order by + s_name; + + +select /* TPC-H Q17 */ + sum(l_extendedprice) / 7.0 as avg_yearly +from + lineitem, + part +where + p_partkey = l_partkey + and p_brand = 'Brand#13' + and p_container = 'JUMBO CASE' + and l_quantity < ( + select + 0.2 * avg(l_quantity) + from + lineitem + where + l_partkey = p_partkey + ); + + +select /* TPC-H Q3 */ + l_orderkey, + sum(l_extendedprice * (1 - l_discount)) as revenue, + o_orderdate, + o_shippriority +from + customer, + orders, + lineitem +where + c_mktsegment = 'AUTOMOBILE' + and c_custkey = o_custkey + and l_orderkey = o_orderkey + and o_orderdate < date '1995-03-25' + and l_shipdate > date '1995-03-25' +group by + l_orderkey, + o_orderdate, + o_shippriority +order by + revenue desc, + o_orderdate +limit 10; + + +select /* TPC-H Q6 */ + sum(l_extendedprice * l_discount) as revenue +from + lineitem +where + l_shipdate >= date '1995-01-01' + and l_shipdate < dateadd(year, 1, cast('1995-01-01' as date)) + and l_discount between 0.02 - 0.01 and 0.02 + 0.01 + and l_quantity < 24; + + +select /* TPC-H Q21 */ + s_name, + count(*) as numwait +from + supplier, + lineitem l1, + orders, + nation +where + s_suppkey = l1.l_suppkey + and o_orderkey = l1.l_orderkey + and o_orderstatus = 'F' + and l1.l_receiptdate > l1.l_commitdate + and exists ( + select + * + from + lineitem l2 + where + l2.l_orderkey = l1.l_orderkey + and l2.l_suppkey <> l1.l_suppkey + ) + and not exists ( + select + * + from + lineitem l3 + where + l3.l_orderkey = l1.l_orderkey + and l3.l_suppkey <> l1.l_suppkey + and l3.l_receiptdate > l3.l_commitdate + ) + and s_nationkey = n_nationkey + and n_name = 'EGYPT' +group by + s_name +order by + numwait desc, + s_name +limit 100; + + +select /* TPC-H Q18 */ + c_name, + c_custkey, + o_orderkey, + o_orderdate, + o_totalprice, + sum(l_quantity) +from + customer, + orders, + lineitem +where + o_orderkey in ( + select + l_orderkey + from + lineitem + group by + l_orderkey having + sum(l_quantity) > 313 + ) + and c_custkey = o_custkey + and o_orderkey = l_orderkey +group by + c_name, + c_custkey, + o_orderkey, + o_orderdate, + o_totalprice +order by + o_totalprice desc, + o_orderdate +limit 100; + + +select /* TPC-H Q11 */ + ps_partkey, + sum(ps_supplycost * ps_availqty) as value +from + partsupp, + supplier, + nation +where + ps_suppkey = s_suppkey + and s_nationkey = n_nationkey + and n_name = 'MOZAMBIQUE' +group by + ps_partkey having + sum(ps_supplycost * ps_availqty) > ( + select + sum(ps_supplycost * ps_availqty) * 0.0000010000 + from + partsupp, + supplier, + nation + where + ps_suppkey = s_suppkey + and s_nationkey = n_nationkey + and n_name = 'MOZAMBIQUE' + ) +order by + value desc; + + +select /* TPC-H Q19 */ + sum(l_extendedprice* (1 - l_discount)) as revenue +from + lineitem, + part +where + ( + p_partkey = l_partkey + and p_brand = 'Brand#44' + and p_container in ('SM CASE', 'SM BOX', 'SM PACK', 'SM PKG') + and l_quantity >= 8 and l_quantity <= 8 + 10 + and p_size between 1 and 5 + and l_shipmode in ('AIR', 'AIR REG') + and l_shipinstruct = 'DELIVER IN PERSON' + ) + or + ( + p_partkey = l_partkey + and p_brand = 'Brand#12' + and p_container in ('MED BAG', 'MED BOX', 'MED PKG', 'MED PACK') + and l_quantity >= 19 and l_quantity <= 19 + 10 + and p_size between 1 and 10 + and l_shipmode in ('AIR', 'AIR REG') + and l_shipinstruct = 'DELIVER IN PERSON' + ) + or + ( + p_partkey = l_partkey + and p_brand = 'Brand#24' + and p_container in ('LG CASE', 'LG BOX', 'LG PACK', 'LG PKG') + and l_quantity >= 29 and l_quantity <= 29 + 10 + and p_size between 1 and 15 + and l_shipmode in ('AIR', 'AIR REG') + and l_shipinstruct = 'DELIVER IN PERSON' + ); + + +select /* TPC-H Q10 */ + c_custkey, + c_name, + sum(l_extendedprice * (1 - l_discount)) as revenue, + c_acctbal, + n_name, + c_address, + c_phone, + c_comment +from + customer, + orders, + lineitem, + nation +where + c_custkey = o_custkey + and l_orderkey = o_orderkey + and o_orderdate >= date '1993-12-01' + and o_orderdate < dateadd(month, 3, cast('1993-12-01' as date)) + and l_returnflag = 'R' + and c_nationkey = n_nationkey +group by + c_custkey, + c_name, + c_acctbal, + c_phone, + n_name, + c_address, + c_comment +order by + revenue desc +limit 20; + +with revenue as ( + select + l_suppkey as supplier_no, + sum(l_extendedprice * (1-l_discount)) as total_revenue + from + lineitem + where + l_shipdate >= date '1996-09-01' + and l_shipdate < dateadd(month, 3, cast('1996-09-01' as date)) + group by + l_suppkey +) +select /* TPC-H Q15 */ + s_suppkey, + s_name, + s_address, + s_phone, + total_revenue +from + supplier, + revenue +where + s_suppkey = supplier_no + and total_revenue = ( + select + max(total_revenue) + from + revenue + ) +order by + s_suppkey; + + +select /* TPC-H Q4 */ + o_orderpriority, + count(*) as order_count +from + orders +where + o_orderdate >= date '1996-11-01' + and o_orderdate < dateadd(month, 3, cast('1996-11-01' as date)) + and exists ( + select + * + from + lineitem + where + l_orderkey = o_orderkey + and l_commitdate < l_receiptdate + ) +group by + o_orderpriority +order by + o_orderpriority; + + +select /* TPC-H Q22 */ + cntrycode, + count(*) as numcust, + sum(c_acctbal) as totacctbal +from + ( + select + substring(c_phone,1,2) as cntrycode, + c_acctbal + from + customer + where + substring(c_phone,1,2) in + ('17', '19', '26', '29', '31', '32', '30') + and c_acctbal > ( + select + avg(c_acctbal) + from + customer + where + c_acctbal > 0.00 + and substring(c_phone,1,2) in + ('17', '19', '26', '29', '31', '32', '30') + ) + and not exists ( + select + * + from + orders + where + o_custkey = c_custkey + ) + ) as custsale +group by + cntrycode +order by + cntrycode; + + +select /* TPC-H Q1 */ + l_returnflag, + l_linestatus, + sum(l_quantity) as sum_qty, + sum(l_extendedprice) as sum_base_price, + sum(l_extendedprice * (1 - l_discount)) as sum_disc_price, + sum(l_extendedprice * (1 - l_discount) * (1 + l_tax)) as sum_charge, + avg(l_quantity) as avg_qty, + avg(l_extendedprice) as avg_price, + avg(l_discount) as avg_disc, + count(*) as count_order +from + lineitem +where + l_shipdate <= dateadd(day, -71, cast('1998-12-01' as date)) +group by + l_returnflag, + l_linestatus +order by + l_returnflag, + l_linestatus; + + +select /* TPC-H Q7 */ + supp_nation, + cust_nation, + l_year, + sum(volume) as revenue +from + ( + select + n1.n_name as supp_nation, + n2.n_name as cust_nation, + extract(year from l_shipdate) as l_year, + l_extendedprice * (1 - l_discount) as volume + from + supplier, + lineitem, + orders, + customer, + nation n1, + nation n2 + where + s_suppkey = l_suppkey + and o_orderkey = l_orderkey + and c_custkey = o_custkey + and s_nationkey = n1.n_nationkey + and c_nationkey = n2.n_nationkey + and ( + (n1.n_name = 'BRAZIL' and n2.n_name = 'IRAN') + or (n1.n_name = 'IRAN' and n2.n_name = 'BRAZIL') + ) + and l_shipdate between date '1995-01-01' and date '1996-12-31' + ) as shipping +group by + supp_nation, + cust_nation, + l_year +order by + supp_nation, + cust_nation, + l_year; + + +select /* TPC-H Q12 */ + l_shipmode, + sum(case + when o_orderpriority = '1-URGENT' + or o_orderpriority = '2-HIGH' + then 1 + else 0 + end) as high_line_count, + sum(case + when o_orderpriority <> '1-URGENT' + and o_orderpriority <> '2-HIGH' + then 1 + else 0 + end) as low_line_count +from + orders, + lineitem +where + o_orderkey = l_orderkey + and l_shipmode in ('TRUCK', 'RAIL') + and l_commitdate < l_receiptdate + and l_shipdate < l_commitdate + and l_receiptdate >= date '1995-01-01' + and l_receiptdate < dateadd(year, 1, cast('1995-01-01' as date)) +group by + l_shipmode +order by + l_shipmode; + + +select /* TPC-H Q9 */ + nation, + o_year, + sum(amount) as sum_profit +from + ( + select + n_name as nation, + extract(year from o_orderdate) as o_year, + l_extendedprice * (1 - l_discount) - ps_supplycost * l_quantity as amount + from + part, + supplier, + lineitem, + partsupp, + orders, + nation + where + s_suppkey = l_suppkey + and ps_suppkey = l_suppkey + and ps_partkey = l_partkey + and p_partkey = l_partkey + and o_orderkey = l_orderkey + and s_nationkey = n_nationkey + and p_name like '%indian%' + ) as profit +group by + nation, + o_year +order by + nation, + o_year desc; + + +select /* TPC-H Q14 */ + 100.00 * sum(case + when p_type like 'PROMO%' + then l_extendedprice * (1 - l_discount) + else 0 + end) / sum(l_extendedprice * (1 - l_discount)) as promo_revenue +from + lineitem, + part +where + l_partkey = p_partkey + and l_shipdate >= date '1995-05-01' + and l_shipdate < dateadd(month, 1, cast('1995-05-01' as date)) +; + + +select /* TPC-H Q5 */ + n_name, + sum(l_extendedprice * (1 - l_discount)) as revenue +from + customer, + orders, + lineitem, + supplier, + nation, + region +where + c_custkey = o_custkey + and l_orderkey = o_orderkey + and l_suppkey = s_suppkey + and c_nationkey = s_nationkey + and s_nationkey = n_nationkey + and n_regionkey = r_regionkey + and r_name = 'MIDDLE EAST' + and o_orderdate >= date '1995-01-01' + and o_orderdate < dateadd(year, 1, cast('1995-01-01' as date)) +group by + n_name +order by + revenue desc; + + +select /* TPC-H Q16 */ + p_brand, + p_type, + p_size, + count(distinct ps_suppkey) as supplier_cnt +from + partsupp, + part +where + p_partkey = ps_partkey + and p_brand <> 'Brand#11' + and p_type not like 'MEDIUM POLISHED%' + and p_size in (31, 39, 11, 18, 22, 33, 2, 43) + and ps_suppkey not in ( + select + s_suppkey + from + supplier + where + s_comment like '%Customer%Complaints%' + ) +group by + p_brand, + p_type, + p_size +order by + supplier_cnt desc, + p_brand, + p_type, + p_size; From a590f8137eb1e874f6a8b8fbbd54645c08665185 Mon Sep 17 00:00:00 2001 From: sgromoll Date: Sun, 12 Mar 2023 09:48:03 -0400 Subject: [PATCH 08/49] Explicitly set region for TPC-H data load (#673) --- .../Cloud-DWB-Derived-from-TPCH/100GB/ddl.sql | 16 ++++++++-------- .../Cloud-DWB-Derived-from-TPCH/10GB/ddl.sql | 16 ++++++++-------- .../Cloud-DWB-Derived-from-TPCH/30TB/ddl.sql | 16 ++++++++-------- .../Cloud-DWB-Derived-from-TPCH/3TB/ddl.sql | 16 ++++++++-------- 4 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/100GB/ddl.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/100GB/ddl.sql index b50df397..f7814af3 100644 --- a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/100GB/ddl.sql +++ b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/100GB/ddl.sql @@ -110,14 +110,14 @@ For more information check samples in https://docs.aws.amazon.com/redshift/lates copy region from's3://redshift-downloads/TPC-H/100GB/region/' IAM_Role 'Replace text inside the quotes with Redshift cluster IAM_Role ARN' gzip delimiter '|'; */ -copy region from 's3://redshift-downloads/TPC-H/2.18/100GB/region/' iam_role default delimiter '|'; -copy nation from 's3://redshift-downloads/TPC-H/2.18/100GB/nation/' iam_role default delimiter '|'; -copy lineitem from 's3://redshift-downloads/TPC-H/2.18/100GB/lineitem/' iam_role default delimiter '|'; -copy orders from 's3://redshift-downloads/TPC-H/2.18/100GB/orders/' iam_role default delimiter '|'; -copy part from 's3://redshift-downloads/TPC-H/2.18/100GB/part/' iam_role default delimiter '|'; -copy supplier from 's3://redshift-downloads/TPC-H/2.18/100GB/supplier/' iam_role default delimiter '|'; -copy partsupp from 's3://redshift-downloads/TPC-H/2.18/100GB/partsupp/' iam_role default delimiter '|'; -copy customer from 's3://redshift-downloads/TPC-H/2.18/100GB/customer/' iam_role default delimiter '|'; +copy region from 's3://redshift-downloads/TPC-H/2.18/100GB/region/' iam_role default delimiter '|' region 'us-east-1'; +copy nation from 's3://redshift-downloads/TPC-H/2.18/100GB/nation/' iam_role default delimiter '|' region 'us-east-1'; +copy lineitem from 's3://redshift-downloads/TPC-H/2.18/100GB/lineitem/' iam_role default delimiter '|' region 'us-east-1'; +copy orders from 's3://redshift-downloads/TPC-H/2.18/100GB/orders/' iam_role default delimiter '|' region 'us-east-1'; +copy part from 's3://redshift-downloads/TPC-H/2.18/100GB/part/' iam_role default delimiter '|' region 'us-east-1'; +copy supplier from 's3://redshift-downloads/TPC-H/2.18/100GB/supplier/' iam_role default delimiter '|' region 'us-east-1'; +copy partsupp from 's3://redshift-downloads/TPC-H/2.18/100GB/partsupp/' iam_role default delimiter '|' region 'us-east-1'; +copy customer from 's3://redshift-downloads/TPC-H/2.18/100GB/customer/' iam_role default delimiter '|' region 'us-east-1'; select count(*) from customer; select count(*) from lineitem; diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/10GB/ddl.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/10GB/ddl.sql index 6dd5152c..a39e780a 100644 --- a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/10GB/ddl.sql +++ b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/10GB/ddl.sql @@ -110,14 +110,14 @@ For more information check samples in https://docs.aws.amazon.com/redshift/lates copy region from's3://redshift-downloads/TPC-H/10GB/region/' IAM_Role 'Replace text inside the quotes with Redshift cluster IAM_Role ARN' gzip delimiter '|'; */ -copy region from 's3://redshift-downloads/TPC-H/2.18/10GB/region.tbl' iam_role default delimiter '|'; -copy nation from 's3://redshift-downloads/TPC-H/2.18/10GB/nation.tbl' iam_role default delimiter '|'; -copy lineitem from 's3://redshift-downloads/TPC-H/2.18/10GB/lineitem.tbl' iam_role default delimiter '|'; -copy orders from 's3://redshift-downloads/TPC-H/2.18/10GB/orders.tbl' iam_role default delimiter '|'; -copy part from 's3://redshift-downloads/TPC-H/2.18/10GB/part.tbl' iam_role default delimiter '|'; -copy supplier from 's3://redshift-downloads/TPC-H/2.18/10GB/supplier.tbl' iam_role default delimiter '|'; -copy partsupp from 's3://redshift-downloads/TPC-H/2.18/10GB/partsupp.tbl' iam_role default delimiter '|'; -copy customer from 's3://redshift-downloads/TPC-H/2.18/10GB/customer.tbl' iam_role default delimiter '|'; +copy region from 's3://redshift-downloads/TPC-H/2.18/10GB/region.tbl' iam_role default delimiter '|' region 'us-east-1'; +copy nation from 's3://redshift-downloads/TPC-H/2.18/10GB/nation.tbl' iam_role default delimiter '|' region 'us-east-1'; +copy lineitem from 's3://redshift-downloads/TPC-H/2.18/10GB/lineitem.tbl' iam_role default delimiter '|' region 'us-east-1'; +copy orders from 's3://redshift-downloads/TPC-H/2.18/10GB/orders.tbl' iam_role default delimiter '|' region 'us-east-1'; +copy part from 's3://redshift-downloads/TPC-H/2.18/10GB/part.tbl' iam_role default delimiter '|' region 'us-east-1'; +copy supplier from 's3://redshift-downloads/TPC-H/2.18/10GB/supplier.tbl' iam_role default delimiter '|' region 'us-east-1'; +copy partsupp from 's3://redshift-downloads/TPC-H/2.18/10GB/partsupp.tbl' iam_role default delimiter '|' region 'us-east-1'; +copy customer from 's3://redshift-downloads/TPC-H/2.18/10GB/customer.tbl' iam_role default delimiter '|' region 'us-east-1'; select count(*) from customer; -- 1500000 select count(*) from lineitem; -- 59986052 diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/30TB/ddl.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/30TB/ddl.sql index e0599468..bfcac274 100644 --- a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/30TB/ddl.sql +++ b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/30TB/ddl.sql @@ -110,14 +110,14 @@ For more information check samples in https://docs.aws.amazon.com/redshift/lates copy region from's3://redshift-downloads/TPC-H/3TB/region/' IAM_Role 'Replace text inside the quotes with Redshift cluster IAM_Role ARN' gzip delimiter '|'; */ -copy region from 's3://redshift-downloads/TPC-H/2.18/30TB/region/' iam_role default delimiter '|'; -copy nation from 's3://redshift-downloads/TPC-H/2.18/30TB/nation/' iam_role default delimiter '|'; -copy lineitem from 's3://redshift-downloads/TPC-H/2.18/30TB/lineitem/' iam_role default gzip delimiter '|'; -copy orders from 's3://redshift-downloads/TPC-H/2.18/30TB/orders/' iam_role default gzip delimiter '|'; -copy part from 's3://redshift-downloads/TPC-H/2.18/30TB/part/' iam_role default gzip delimiter '|'; -copy supplier from 's3://redshift-downloads/TPC-H/2.18/30TB/supplier/' iam_role default gzip delimiter '|'; -copy partsupp from 's3://redshift-downloads/TPC-H/2.18/30TB/partsupp/' iam_role default gzip delimiter '|'; -copy customer from 's3://redshift-downloads/TPC-H/2.18/30TB/customer/' iam_role default gzip delimiter '|'; +copy region from 's3://redshift-downloads/TPC-H/2.18/30TB/region/' iam_role default delimiter '|' region 'us-east-1'; +copy nation from 's3://redshift-downloads/TPC-H/2.18/30TB/nation/' iam_role default delimiter '|' region 'us-east-1'; +copy lineitem from 's3://redshift-downloads/TPC-H/2.18/30TB/lineitem/' iam_role default gzip delimiter '|' region 'us-east-1'; +copy orders from 's3://redshift-downloads/TPC-H/2.18/30TB/orders/' iam_role default gzip delimiter '|' region 'us-east-1'; +copy part from 's3://redshift-downloads/TPC-H/2.18/30TB/part/' iam_role default gzip delimiter '|' region 'us-east-1'; +copy supplier from 's3://redshift-downloads/TPC-H/2.18/30TB/supplier/' iam_role default gzip delimiter '|' region 'us-east-1'; +copy partsupp from 's3://redshift-downloads/TPC-H/2.18/30TB/partsupp/' iam_role default gzip delimiter '|' region 'us-east-1'; +copy customer from 's3://redshift-downloads/TPC-H/2.18/30TB/customer/' iam_role default gzip delimiter '|' region 'us-east-1'; select count(*) from customer; -- 4500000000 select count(*) from lineitem; -- 179999978268 diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/3TB/ddl.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/3TB/ddl.sql index 03b818dd..62f7570b 100644 --- a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/3TB/ddl.sql +++ b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/3TB/ddl.sql @@ -110,14 +110,14 @@ For more information check samples in https://docs.aws.amazon.com/redshift/lates copy region from's3://redshift-downloads/TPC-H/3TB/region/' IAM_Role 'Replace text inside the quotes with Redshift cluster IAM_Role ARN' gzip delimiter '|'; */ -copy region from 's3://redshift-downloads/TPC-H/2.18/3TB/region/' iam_role default delimiter '|'; -copy nation from 's3://redshift-downloads/TPC-H/2.18/3TB/nation/' iam_role default delimiter '|'; -copy lineitem from 's3://redshift-downloads/TPC-H/2.18/3TB/lineitem/' iam_role default delimiter '|'; -copy orders from 's3://redshift-downloads/TPC-H/2.18/3TB/orders/' iam_role default delimiter '|'; -copy part from 's3://redshift-downloads/TPC-H/2.18/3TB/part/' iam_role default delimiter '|'; -copy supplier from 's3://redshift-downloads/TPC-H/2.18/3TB/supplier/' iam_role default delimiter '|'; -copy partsupp from 's3://redshift-downloads/TPC-H/2.18/3TB/partsupp/' iam_role default delimiter '|'; -copy customer from 's3://redshift-downloads/TPC-H/2.18/3TB/customer/' iam_role default delimiter '|'; +copy region from 's3://redshift-downloads/TPC-H/2.18/3TB/region/' iam_role default delimiter '|' region 'us-east-1'; +copy nation from 's3://redshift-downloads/TPC-H/2.18/3TB/nation/' iam_role default delimiter '|' region 'us-east-1'; +copy lineitem from 's3://redshift-downloads/TPC-H/2.18/3TB/lineitem/' iam_role default delimiter '|' region 'us-east-1'; +copy orders from 's3://redshift-downloads/TPC-H/2.18/3TB/orders/' iam_role default delimiter '|' region 'us-east-1'; +copy part from 's3://redshift-downloads/TPC-H/2.18/3TB/part/' iam_role default delimiter '|' region 'us-east-1'; +copy supplier from 's3://redshift-downloads/TPC-H/2.18/3TB/supplier/' iam_role default delimiter '|' region 'us-east-1'; +copy partsupp from 's3://redshift-downloads/TPC-H/2.18/3TB/partsupp/' iam_role default delimiter '|' region 'us-east-1'; +copy customer from 's3://redshift-downloads/TPC-H/2.18/3TB/customer/' iam_role default delimiter '|' region 'us-east-1'; select count(*) from customer; -- 450000000 select count(*) from lineitem; -- 18000048306 From 866a2d7d937a6cd837bfc3dcded7844506c04e74 Mon Sep 17 00:00:00 2001 From: Amneet Bector Date: Mon, 13 Mar 2023 16:17:40 -0400 Subject: [PATCH 09/49] Update v_get_tbl_priv_by_group.sql --- src/AdminViews/v_get_tbl_priv_by_group.sql | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/AdminViews/v_get_tbl_priv_by_group.sql b/src/AdminViews/v_get_tbl_priv_by_group.sql index 1d3099eb..b4753f3e 100644 --- a/src/AdminViews/v_get_tbl_priv_by_group.sql +++ b/src/AdminViews/v_get_tbl_priv_by_group.sql @@ -7,12 +7,12 @@ History: create or replace view admin.v_get_tbl_priv_by_group as select t.namespace as schemaname, t.item as object, pu.groname as groupname - , decode(charindex('r',split_part(split_part(array_to_string(t.relacl, '|'),pu.groname,2 ) ,'/',1)),0,false,true) as sel - , decode(charindex('w',split_part(split_part(array_to_string(t.relacl, '|'),pu.groname,2 ) ,'/',1)),0,false,true) as upd - , decode(charindex('a',split_part(split_part(array_to_string(t.relacl, '|'),pu.groname,2 ) ,'/',1)),0,false,true) as ins - , decode(charindex('d',split_part(split_part(array_to_string(t.relacl, '|'),pu.groname,2 ) ,'/',1)),0,false,true) as del - , decode(charindex('D',split_part(split_part(array_to_string(t.relacl, '|'),pu.groname,2 ) ,'/',1)),0,false,true) as drp - , decode(charindex('R',split_part(split_part(array_to_string(t.relacl, '|'),pu.groname,2 ) ,'/',1)),0,false,true) as ref + , decode(charindex('r',split_part(split_part(array_to_string(t.relacl, '|'), 'group '||pu.groname||'=',2 ) ,'/',1)),0,false,true) as sel + , decode(charindex('w',split_part(split_part(array_to_string(t.relacl, '|'), 'group '||pu.groname||'=',2 ) ,'/',1)),0,false,true) as upd + , decode(charindex('a',split_part(split_part(array_to_string(t.relacl, '|'), 'group '||pu.groname||'=',2 ) ,'/',1)),0,false,true) as ins + , decode(charindex('d',split_part(split_part(array_to_string(t.relacl, '|'), 'group '||pu.groname||'=',2 ) ,'/',1)),0,false,true) as del + , decode(charindex('D',split_part(split_part(array_to_string(t.relacl, '|'), 'group '||pu.groname||'=',2 ) ,'/',1)),0,false,true) as drp + , decode(charindex('R',split_part(split_part(array_to_string(t.relacl, '|'), 'group '||pu.groname||'=',2 ) ,'/',1)),0,false,true) as ref from (select use.usename as subject, @@ -29,5 +29,4 @@ from where c.relowner = use.usesysid and nsp.nspname !~ '^information_schema|catalog_history|pg_' ) t -join pg_group pu on array_to_string(t.relacl, '|') like '%'||pu.groname||'%' -; \ No newline at end of file +join pg_group pu on array_to_string(t.relacl, '|') like '%group '||pu.groname||'=%'; From 664bb5adc58665b56fd212d14ecc505a23f90f20 Mon Sep 17 00:00:00 2001 From: Amneet Bector Date: Mon, 13 Mar 2023 16:25:21 -0400 Subject: [PATCH 10/49] Update v_get_tbl_priv_by_group.sql --- src/AdminViews/v_get_tbl_priv_by_group.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AdminViews/v_get_tbl_priv_by_group.sql b/src/AdminViews/v_get_tbl_priv_by_group.sql index b4753f3e..8775b5e2 100644 --- a/src/AdminViews/v_get_tbl_priv_by_group.sql +++ b/src/AdminViews/v_get_tbl_priv_by_group.sql @@ -2,7 +2,7 @@ Purpose: View to get the tables that a user group has access to History: 2021-09-27 milindo Created -2022-08-15 saeedma8 excluded system tables +2023-03-13 amneet13 return results specific for groups. **********************************************************************************************/ create or replace view admin.v_get_tbl_priv_by_group as select From 0f9e47c1125b62102fe162e861f0e53bd98bf443 Mon Sep 17 00:00:00 2001 From: Devanathan Sabapathy <123671658+DevanathanSabapathy1@users.noreply.github.com> Date: Thu, 6 Apr 2023 15:50:09 -0700 Subject: [PATCH 11/49] adding a fix for pagination of log groups (#678) * adding a fix for pagination of log groups * removing redundant variable --- src/SimpleReplay/helper/aws_service.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/SimpleReplay/helper/aws_service.py b/src/SimpleReplay/helper/aws_service.py index 31e09e3c..bfc47c5e 100644 --- a/src/SimpleReplay/helper/aws_service.py +++ b/src/SimpleReplay/helper/aws_service.py @@ -64,7 +64,14 @@ def cw_describe_log_groups(log_group_name=None, region=None): logGroupNamePrefix=log_group_name ) else: - return cloudwatch_client.describe_log_groups() + logs = cloudwatch_client.describe_log_groups() + + token = logs.get('nextToken','') + while token != '': + response_itr = cloudwatch_client.describe_log_groups(nextToken=token) + logs['logGroups'].extend(response_itr['logGroups']) + token = response_itr['nextToken'] if 'nextToken' in response_itr.keys() else '' + return logs def cw_describe_log_streams(log_group_name, region): From a53c38f29b1cc5b4b05077195031763e3c94d655 Mon Sep 17 00:00:00 2001 From: karlnish Date: Mon, 24 Apr 2023 17:16:14 -0700 Subject: [PATCH 12/49] Fix for severless secret manager --- src/SimpleReplay/replay.py | 1215 +++++++++++++++++---------- src/SimpleReplay/replay_analysis.py | 389 ++++++--- src/SimpleReplay/requirements.txt | 4 +- src/SimpleReplay/util.py | 374 +++++---- 4 files changed, 1245 insertions(+), 737 deletions(-) diff --git a/src/SimpleReplay/replay.py b/src/SimpleReplay/replay.py index a569f613..f4afaf7e 100644 --- a/src/SimpleReplay/replay.py +++ b/src/SimpleReplay/replay.py @@ -29,8 +29,21 @@ from queue import Empty, Full from urllib.parse import urlparse -from util import init_logging, set_log_level, prepend_ids_to_logs, add_logfile, log_version, db_connect, cluster_dict, \ - load_config, load_file, retrieve_compressed_json, get_secret, parse_error, bucket_dict +from util import ( + init_logging, + set_log_level, + prepend_ids_to_logs, + add_logfile, + log_version, + db_connect, + cluster_dict, + load_config, + load_file, + retrieve_compressed_json, + get_secret, + parse_error, + bucket_dict, +) from replay_analysis import run_replay_analysis import redshift_connector @@ -47,28 +60,33 @@ g_workers = [] g_exit = False -g_copy_replacements_filename = 'copy_replacements.csv' +g_copy_replacements_filename = "copy_replacements.csv" g_config = {} g_replay_timestamp = None g_is_serverless = False -g_serverless_cluster_endpoint_pattern = r"(.+)\.(.+)\.(.+).redshift-serverless(-dev)?\.amazonaws\.com:[0-9]{4}\/(.)+" -g_cluster_endpoint_pattern = r"(.+)\.(.+)\.(.+).redshift(-serverless)?\.amazonaws\.com:[0-9]{4}\/(.)+" +g_serverless_cluster_endpoint_pattern = ( + r"(.+)\.(.+)\.(.+).redshift-serverless(-dev)?\.amazonaws\.com:[0-9]{4}\/(.)+" +) +g_cluster_endpoint_pattern = ( + r"(.+)\.(.+)\.(.+).redshift(-serverless)?\.amazonaws\.com:[0-9]{4}\/(.)+" +) + class ConnectionLog: def __init__( - self, - session_initiation_time, - disconnection_time, - application_name, - database_name, - username, - pid, - time_interval_between_transactions, - time_interval_between_queries, - connection_key, + self, + session_initiation_time, + disconnection_time, + application_name, + database_name, + username, + pid, + time_interval_between_transactions, + time_interval_between_queries, + connection_key, ): self.session_initiation_time = session_initiation_time self.disconnection_time = disconnection_time @@ -84,20 +102,20 @@ def __init__( def __str__(self): return ( - "Session initiation time: %s, Disconnection time: %s, Application name: %s, Database name: %s, " - "Username; %s, PID: %s, Time interval between transactions: %s, Time interval between queries: %s, " - "Number of transactions: %s" - % ( - self.session_initiation_time.isoformat(), - self.disconnection_time.isoformat(), - self.application_name, - self.database_name, - self.username, - self.pid, - self.time_interval_between_transactions, - self.time_interval_between_queries, - len(self.transactions), - ) + "Session initiation time: %s, Disconnection time: %s, Application name: %s, Database name: %s, " + "Username; %s, PID: %s, Time interval between transactions: %s, Time interval between queries: %s, " + "Number of transactions: %s" + % ( + self.session_initiation_time.isoformat(), + self.disconnection_time.isoformat(), + self.application_name, + self.database_name, + self.username, + self.pid, + self.time_interval_between_transactions, + self.time_interval_between_queries, + len(self.transactions), + ) ) def offset_ms(self, ref_time): @@ -105,11 +123,13 @@ def offset_ms(self, ref_time): @staticmethod def supported_filters(): - return {'database_name', 'username', 'pid'} + return {"database_name", "username", "pid"} class Transaction: - def __init__(self, time_interval, database_name, username, pid, xid, queries, transaction_key): + def __init__( + self, time_interval, database_name, username, pid, xid, queries, transaction_key + ): self.time_interval = time_interval self.database_name = database_name self.username = username @@ -120,20 +140,20 @@ def __init__(self, time_interval, database_name, username, pid, xid, queries, tr def __str__(self): return ( - "Time interval: %s, Database name: %s, Username: %s, PID: %s, XID: %s, Num queries: %s" - % ( - self.time_interval, - self.database_name, - self.username, - self.pid, - self.xid, - len(self.queries), - ) + "Time interval: %s, Database name: %s, Username: %s, PID: %s, XID: %s, Num queries: %s" + % ( + self.time_interval, + self.database_name, + self.username, + self.pid, + self.xid, + len(self.queries), + ) ) def get_base_filename(self): return ( - self.database_name + "-" + self.username + "-" + self.pid + "-" + self.xid + self.database_name + "-" + self.username + "-" + self.pid + "-" + self.xid ) def start_time(self): @@ -147,7 +167,7 @@ def offset_ms(self, replay_start_time): @staticmethod def supported_filters(): - return {'database_name', 'username', 'pid'} + return {"database_name", "username", "pid"} class Query: @@ -184,7 +204,7 @@ def __init__( num_connections, peak_connections, connection_semaphore, - perf_lock + perf_lock, ): threading.Thread.__init__(self) self.process_idx = process_idx @@ -208,60 +228,84 @@ def initiate_connection(self, username): conn = None # check if this connection is happening at the right time - expected_elapsed_sec = (self.connection_log.session_initiation_time - self.first_event_time).total_seconds() - elapsed_sec = (datetime.datetime.now(tz=datetime.timezone.utc) - self.replay_start).total_seconds() + expected_elapsed_sec = ( + self.connection_log.session_initiation_time - self.first_event_time + ).total_seconds() + elapsed_sec = ( + datetime.datetime.now(tz=datetime.timezone.utc) - self.replay_start + ).total_seconds() connection_diff_sec = elapsed_sec - expected_elapsed_sec - connection_duration_sec = (self.connection_log.disconnection_time - - self.connection_log.session_initiation_time).total_seconds() + connection_duration_sec = ( + self.connection_log.disconnection_time + - self.connection_log.session_initiation_time + ).total_seconds() - logger.debug(f"Establishing connection {self.job_id + 1} of {g_total_connections} at {elapsed_sec:.3f} " - f"(expected: {expected_elapsed_sec:.3f}, {connection_diff_sec:+.3f}). " - f"Pid: {self.connection_log.pid}, Connection times: {self.connection_log.session_initiation_time} " - f"to {self.connection_log.disconnection_time}, {connection_duration_sec} sec") + logger.debug( + f"Establishing connection {self.job_id + 1} of {g_total_connections} at {elapsed_sec:.3f} " + f"(expected: {expected_elapsed_sec:.3f}, {connection_diff_sec:+.3f}). " + f"Pid: {self.connection_log.pid}, Connection times: {self.connection_log.session_initiation_time} " + f"to {self.connection_log.disconnection_time}, {connection_duration_sec} sec" + ) # save the connection difference - self.thread_stats['connection_diff_sec'] = connection_diff_sec + self.thread_stats["connection_diff_sec"] = connection_diff_sec # and emit a warning if we're behind - if abs(connection_diff_sec) > g_config.get('connection_tolerance_sec', 300): - logger.warning("Connection at {} offset by {:+.3f} sec".format(self.connection_log.session_initiation_time, - connection_diff_sec)) + if abs(connection_diff_sec) > g_config.get("connection_tolerance_sec", 300): + logger.warning( + "Connection at {} offset by {:+.3f} sec".format( + self.connection_log.session_initiation_time, connection_diff_sec + ) + ) interface = self.default_interface if "psql" in self.connection_log.application_name.lower(): interface = "psql" - elif "odbc" in self.connection_log.application_name.lower() and self.odbc_driver is not None: + elif ( + "odbc" in self.connection_log.application_name.lower() + and self.odbc_driver is not None + ): interface = "odbc" elif self.default_interface == "odbc" and self.odbc_driver is None: - logger.warning("Default driver is set to ODBC. But no ODBC DSN provided. Replay will use PSQL as " - "default driver.") + logger.warning( + "Default driver is set to ODBC. But no ODBC DSN provided. Replay will use PSQL as " + "default driver." + ) interface = "psql" else: interface = "psql" - credentials = get_connection_credentials(username, database=self.connection_log.database_name) + credentials = get_connection_credentials( + username, database=self.connection_log.database_name + ) try: try: - conn = db_connect(interface, - host=credentials['host'], - port=int(credentials['port']), - username=credentials['username'], - password=credentials['password'], - database=credentials['database'], - odbc_driver=credentials['odbc_driver'], - drop_return=g_config.get('drop_return')) - logger.debug(f"Connected using {interface} for PID: {self.connection_log.pid}") + conn = db_connect( + interface, + host=credentials["host"], + port=int(credentials["port"]), + username=credentials["username"], + password=credentials["password"], + database=credentials["database"], + odbc_driver=credentials["odbc_driver"], + drop_return=g_config.get("drop_return"), + ) + logger.debug( + f"Connected using {interface} for PID: {self.connection_log.pid}" + ) self.num_connections.value += 1 except Exception as err: hashed_cluster_url = copy.deepcopy(credentials) hashed_cluster_url["password"] = "***" logger.error( - f'({self.job_id + 1}) Failed to initiate connection for {self.connection_log.database_name}-' - f'{self.connection_log.username}-{self.connection_log.pid} ({hashed_cluster_url}): {err}') - self.thread_stats['connection_error_log'][ - f"{self.connection_log.database_name}-{self.connection_log.username}-{self.connection_log.pid}"] = f"{self.connection_log}\n\n{err}" + f"({self.job_id + 1}) Failed to initiate connection for {self.connection_log.database_name}-" + f"{self.connection_log.username}-{self.connection_log.pid} ({hashed_cluster_url}): {err}" + ) + self.thread_stats["connection_error_log"][ + f"{self.connection_log.database_name}-{self.connection_log.username}-{self.connection_log.pid}" + ] = f"{self.connection_log}\n\n{err}" yield conn except Exception as e: logger.error(f"Exception in connect: {e}") @@ -272,8 +316,10 @@ def initiate_connection(self, username): logger.debug(f"Disconnected for PID: {self.connection_log.pid}") self.num_connections.value -= 1 if self.connection_semaphore is not None: - logger.debug(f"Releasing semaphore ({self.num_connections.value} / " - f"{g_config['limit_concurrent_connections']} active connections)") + logger.debug( + f"Releasing semaphore ({self.num_connections.value} / " + f"{g_config['limit_concurrent_connections']} active connections)" + ) self.connection_semaphore.release() def run(self): @@ -282,11 +328,15 @@ def run(self): if connection: self.execute_transactions(connection) if self.connection_log.time_interval_between_transactions is True: - disconnect_offset_sec = (self.connection_log.disconnection_time - - self.first_event_time).total_seconds() + disconnect_offset_sec = ( + self.connection_log.disconnection_time + - self.first_event_time + ).total_seconds() if disconnect_offset_sec > current_offset_ms(self.replay_start): - logger.debug(f"Waiting to disconnect {time_until_disconnect_sec} sec (pid " - f"{self.connection_log.pid})") + logger.debug( + f"Waiting to disconnect {time_until_disconnect_sec} sec (pid " + f"{self.connection_log.pid})" + ) time.sleep(time_until_disconnect_sec) else: logger.warning("Failed to connect") @@ -302,26 +352,34 @@ def execute_transactions(self, connection): # or use this to preserve the time between transactions if idx == 0: - time_until_start_ms = (transaction.start_time() - - self.connection_log.session_initiation_time).total_seconds() * 1000.0 + time_until_start_ms = ( + transaction.start_time() + - self.connection_log.session_initiation_time + ).total_seconds() * 1000.0 else: prev_transaction = self.connection_log.transactions[idx - 1] - time_until_start_ms = (transaction.start_time() - - prev_transaction.end_time()).total_seconds() * 1000.0 + time_until_start_ms = ( + transaction.start_time() - prev_transaction.end_time() + ).total_seconds() * 1000.0 # wait for the transaction to start if time_until_start_ms > 10: - logger.debug(f"Waiting {time_until_start_ms / 1000:.1f} sec for transaction to start") + logger.debug( + f"Waiting {time_until_start_ms / 1000:.1f} sec for transaction to start" + ) time.sleep(time_until_start_ms / 1000.0) self.execute_transaction(transaction, connection) else: for transaction in self.connection_log.transactions: self.execute_transaction(transaction, connection) - def save_query_stats(self, starttime, endtime, xid, query_idx): with self.perf_lock: - sr_dir = g_config.get("logging_dir", "simplereplay_logs") + '/' + g_replay_timestamp.isoformat() + sr_dir = ( + g_config.get("logging_dir", "simplereplay_logs") + + "/" + + g_replay_timestamp.isoformat() + ) Path(sr_dir).mkdir(parents=True, exist_ok=True) filename = f"{sr_dir}/{self.process_idx}_times.csv" elapsed_sec = 0 @@ -331,13 +389,18 @@ def save_query_stats(self, starttime, endtime, xid, query_idx): if fp.tell() == 0: fp.write("# process,query,start_time,end_time,elapsed_sec,rows\n") query_id = f"{xid}-{query_idx}" - fp.write("{},{},{},{},{},{}\n".format(self.process_idx, query_id, starttime, endtime, elapsed_sec, 0)) - + fp.write( + "{},{},{},{},{},{}\n".format( + self.process_idx, query_id, starttime, endtime, elapsed_sec, 0 + ) + ) def get_tagged_sql(self, query_text, idx, transaction, connection): - json_tags = {"xid": transaction.xid, - "query_idx": idx, - "replay_start": g_replay_timestamp.isoformat()} + json_tags = { + "xid": transaction.xid, + "query_idx": idx, + "replay_start": g_replay_timestamp.isoformat(), + } return "/* {} */ {}".format(json.dumps(json_tags), query_text) def execute_transaction(self, transaction, connection): @@ -346,9 +409,15 @@ def execute_transaction(self, transaction, connection): transaction_query_idx = 0 for idx, query in enumerate(transaction.queries): - time_until_start_ms = query.offset_ms(self.first_event_time) - current_offset_ms(self.replay_start) - truncated_query = (query.text[:60] + '...' if len(query.text) > 60 else query.text).replace("\n", " ") - logger.debug(f"Executing [{truncated_query}] in {time_until_start_ms/1000.0:.1f} sec") + time_until_start_ms = query.offset_ms( + self.first_event_time + ) - current_offset_ms(self.replay_start) + truncated_query = ( + query.text[:60] + "..." if len(query.text) > 60 else query.text + ).replace("\n", " ") + logger.debug( + f"Executing [{truncated_query}] in {time_until_start_ms/1000.0:.1f} sec" + ) if time_until_start_ms > 10: time.sleep(time_until_start_ms / 1000.0) @@ -357,35 +426,48 @@ def execute_transaction(self, transaction, connection): split_statements = sqlparse.split(query.text) # exclude empty statements. Some customers' queries have been # found to end in multiple ; characters; - split_statements = [_ for _ in split_statements if _ != ';'] + split_statements = [_ for _ in split_statements if _ != ";"] else: split_statements = [query.text] if len(split_statements) > 1: - self.thread_stats['multi_statements'] += 1 - self.thread_stats['executed_queries'] += len(split_statements) + self.thread_stats["multi_statements"] += 1 + self.thread_stats["executed_queries"] += len(split_statements) success = True for s_idx, sql_text in enumerate(split_statements): - sql_text = self.get_tagged_sql(sql_text, transaction_query_idx, transaction, connection) + sql_text = self.get_tagged_sql( + sql_text, transaction_query_idx, transaction, connection + ) transaction_query_idx += 1 substatement_txt = "" if len(split_statements) > 1: - substatement_txt = f", Multistatement: {s_idx+1}/{len(split_statements)}" + substatement_txt = ( + f", Multistatement: {s_idx+1}/{len(split_statements)}" + ) exec_start = datetime.datetime.now(tz=datetime.timezone.utc) exec_end = None try: - status = '' - if (g_config["execute_copy_statements"] == "true" and "from 's3:" in sql_text.lower()): + status = "" + if ( + g_config["execute_copy_statements"] == "true" + and "from 's3:" in sql_text.lower() + ): cursor.execute(sql_text) - elif (g_config["execute_unload_statements"] == "true" and "to 's3:" in sql_text.lower() and g_config["replay_output"] is not None): + elif ( + g_config["execute_unload_statements"] == "true" + and "to 's3:" in sql_text.lower() + and g_config["replay_output"] is not None + ): cursor.execute(sql_text) - elif ("from 's3:" not in sql_text.lower()) and ("to 's3:" not in sql_text.lower()): ## removed condition to exclude bind variables + elif ("from 's3:" not in sql_text.lower()) and ( + "to 's3:" not in sql_text.lower() + ): ## removed condition to exclude bind variables cursor.execute(sql_text) else: - status = 'Not ' + status = "Not " exec_end = datetime.datetime.now(tz=datetime.timezone.utc) exec_sec = (exec_end - exec_start).total_seconds() @@ -400,16 +482,22 @@ def execute_transaction(self, transaction, connection): f"Failed DB={transaction.database_name}, USER={transaction.username}, PID={transaction.pid}, " f"XID:{transaction.xid}, Query: {idx + 1}/{len(transaction.queries)}{substatement_txt}: {err}" ) - self.error_logger.append(parse_error(err, - transaction.username, - g_config["target_cluster_endpoint"].split('/')[-1], - query.text)) + self.error_logger.append( + parse_error( + err, + transaction.username, + g_config["target_cluster_endpoint"].split("/")[-1], + query.text, + ) + ) - self.save_query_stats(exec_start, exec_end, transaction.xid, transaction_query_idx) + self.save_query_stats( + exec_start, exec_end, transaction.xid, transaction_query_idx + ) if success: - self.thread_stats['query_success'] += 1 + self.thread_stats["query_success"] += 1 else: - self.thread_stats['query_error'] += 1 + self.thread_stats["query_error"] += 1 if query.time_interval > 0.0: logger.debug(f"Waiting {query.time_interval} sec between queries") @@ -418,11 +506,13 @@ def execute_transaction(self, transaction, connection): cursor.close() connection.commit() - if self.thread_stats['query_error'] == 0: - self.thread_stats['transaction_success'] += 1 + if self.thread_stats["query_error"] == 0: + self.thread_stats["transaction_success"] += 1 else: - self.thread_stats['transaction_error'] += 1 - self.thread_stats['transaction_error_log'][transaction.get_base_filename()] = errors + self.thread_stats["transaction_error"] += 1 + self.thread_stats["transaction_error_log"][ + transaction.get_base_filename() + ] = errors # exception thrown if any filters are invalid @@ -441,59 +531,67 @@ class ClusterNotExist(Exception): def validate_and_normalize_filters(object, filters): - """ validate filters and set defaults. The object just needs to - provide a supported_filters() function. """ + """validate filters and set defaults. The object just needs to + provide a supported_filters() function.""" normalized_filters = copy.deepcopy(filters) - if 'include' not in normalized_filters: - normalized_filters['include'] = {} - if 'exclude' not in normalized_filters: - normalized_filters['exclude'] = {} + if "include" not in normalized_filters: + normalized_filters["include"] = {} + if "exclude" not in normalized_filters: + normalized_filters["exclude"] = {} - for f in object.supported_filters(): - normalized_filters['include'].setdefault(f, ['*']) - normalized_filters['exclude'].setdefault(f, []) + for f in object.supported_filters(): + normalized_filters["include"].setdefault(f, ["*"]) + normalized_filters["exclude"].setdefault(f, []) - include_overlap = set(normalized_filters['include'].keys()) - set(object.supported_filters()) + include_overlap = set(normalized_filters["include"].keys()) - set( + object.supported_filters() + ) if len(include_overlap) > 0: raise InvalidFilterException(f"Unknown filters: {include_overlap}") - exclude_overlap = set(normalized_filters['exclude'].keys()) - set(object.supported_filters()) + exclude_overlap = set(normalized_filters["exclude"].keys()) - set( + object.supported_filters() + ) if len(exclude_overlap) > 0: raise InvalidFilterException(f"Unknown filters: {exclude_overlap}") for f in object.supported_filters(): - include = normalized_filters['include'][f] - exclude = normalized_filters['exclude'][f] + include = normalized_filters["include"][f] + exclude = normalized_filters["exclude"][f] if len(include) == 0: raise InvalidFilterException("Include filter must not be empty") overlap = set(include).intersection(set(exclude)) if len(overlap) > 0: - raise InvalidFilterException(f"Can't include the same values in both include and exclude for filter: " - f"{overlap}") + raise InvalidFilterException( + f"Can't include the same values in both include and exclude for filter: " + f"{overlap}" + ) for x in (include, exclude): - if len(x) > 1 and '*' in x: - raise InvalidFilterException("'*' can not be used with other filter values filter") + if len(x) > 1 and "*" in x: + raise InvalidFilterException( + "'*' can not be used with other filter values filter" + ) return normalized_filters def matches_filters(object, filters): - """ Check if the object matches the filters. The object just needs to - provide a supported_filters() function. This also assumes filters has already - been validated """ + """Check if the object matches the filters. The object just needs to + provide a supported_filters() function. This also assumes filters has already + been validated""" included = 0 for field in object.supported_filters(): - include = filters['include'][field] - exclude = filters['exclude'][field] + include = filters["include"][field] + exclude = filters["exclude"][field] # if include values were passed and its not a wildcard, check against it - if '*' in include or getattr(object, field) in include: + if "*" in include or getattr(object, field) in include: included += 1 # if include = * and the user is in the exclude list, reject if getattr(object, field) in exclude: @@ -508,10 +606,16 @@ def matches_filters(object, filters): def current_offset_ms(ref_time): - return (datetime.datetime.now(tz=datetime.timezone.utc) - ref_time).total_seconds() * 1000.0 + return ( + datetime.datetime.now(tz=datetime.timezone.utc) - ref_time + ).total_seconds() * 1000.0 -def parse_connections(workload_directory, time_interval_between_transactions, time_interval_between_queries): +def parse_connections( + workload_directory, + time_interval_between_transactions, + time_interval_between_queries, +): connections = [] # total number of connections before filters are applied @@ -521,10 +625,9 @@ def parse_connections(workload_directory, time_interval_between_transactions, ti workload_s3_location = workload_directory[5:].partition("/") bucket_name = workload_s3_location[0] prefix = workload_s3_location[2] - s3_object = client("s3").get_object( - Bucket=bucket_name, Key=prefix.rstrip('/') + "/connections.json" + Bucket=bucket_name, Key=prefix.rstrip("/") + "/connections.json" ) connections_json = json.loads(s3_object["Body"].read()) else: @@ -543,7 +646,7 @@ def parse_connections(workload_directory, time_interval_between_transactions, ti "all on": "all on", "all off": "all off", }[time_interval_between_queries] - + try: if connection_json["session_initiation_time"]: session_initiation_time = dateutil.parser.isoparse( @@ -558,8 +661,10 @@ def parse_connections(workload_directory, time_interval_between_transactions, ti ).replace(tzinfo=datetime.timezone.utc) else: disconnection_time = None - connection_key = f'{connection_json["database_name"]}_{connection_json["username"]}_' \ - f'{connection_json["pid"]}' + connection_key = ( + f'{connection_json["database_name"]}_{connection_json["username"]}_' + f'{connection_json["pid"]}' + ) connection = ConnectionLog( session_initiation_time, disconnection_time, @@ -571,7 +676,7 @@ def parse_connections(workload_directory, time_interval_between_transactions, ti is_time_interval_between_queries, connection_key, ) - if matches_filters(connection, g_config['filters']): + if matches_filters(connection, g_config["filters"]): connections.append(connection) total_connections += 1 except Exception as err: @@ -579,7 +684,7 @@ def parse_connections(workload_directory, time_interval_between_transactions, ti connections.sort( key=lambda connection: connection.session_initiation_time - or datetime.datetime.utcfromtimestamp(0).replace(tzinfo=datetime.timezone.utc) + or datetime.datetime.utcfromtimestamp(0).replace(tzinfo=datetime.timezone.utc) ) return connections, total_connections @@ -590,9 +695,11 @@ def parse_transactions(workload_directory): gz_path = workload_directory.rstrip("/") + "/SQLs.json.gz" sql_json = retrieve_compressed_json(gz_path) - for xid, transaction_dict in sql_json['transactions'].items(): + for xid, transaction_dict in sql_json["transactions"].items(): transaction = parse_transaction(transaction_dict) - if transaction.start_time() and matches_filters(transaction, g_config['filters']): + if transaction.start_time() and matches_filters( + transaction, g_config["filters"] + ): transactions.append(transaction) transactions.sort( @@ -601,6 +708,7 @@ def parse_transactions(workload_directory): return transactions + def parse_transactions_old(workload_directory): transactions = [] @@ -611,20 +719,24 @@ def parse_transactions_old(workload_directory): conn = client("s3") s3 = resource("s3") - paginator = conn.get_paginator('list_objects_v2') - page_iterator = paginator.paginate(Bucket=bucket_name, Prefix=prefix.rstrip('/') + "/SQLs/") + paginator = conn.get_paginator("list_objects_v2") + page_iterator = paginator.paginate( + Bucket=bucket_name, Prefix=prefix.rstrip("/") + "/SQLs/" + ) for page in page_iterator: - for log in page.get('Contents'): + for log in page.get("Contents"): filename = log["Key"].split("/")[-1] if filename.endswith(".sql"): sql_file_text = ( s3.Object(bucket_name, log["Key"]) - .get()["Body"] - .read() - .decode("utf-8") + .get()["Body"] + .read() + .decode("utf-8") ) transaction = parse_transaction(filename, sql_file_text) - if transaction.start_time() and matches_filters(transaction, g_config['filters']): + if transaction.start_time() and matches_filters( + transaction, g_config["filters"] + ): transactions.append(transaction) else: sqls_directory = os.listdir(workload_directory + "/SQLs/") @@ -634,7 +746,9 @@ def parse_transactions_old(workload_directory): workload_directory + "/SQLs/" + sql_filename, "r" ).read() transaction = parse_transaction(sql_filename, sql_file_text) - if transaction.start_time() and matches_filters(transaction, g_config['filters']): + if transaction.start_time() and matches_filters( + transaction, g_config["filters"] + ): transactions.append(transaction) transactions.sort( @@ -651,19 +765,28 @@ def get_connection_key(database_name, username, pid): def parse_transaction(transaction_dict): queries = [] - for q in transaction_dict['queries']: - start_time = dateutil.parser.isoparse(q['record_time']) - if q['start_time'] is not None: - start_time = dateutil.parser.isoparse(q['start_time']) - end_time = dateutil.parser.isoparse(q['record_time']) - if q['end_time'] is not None: - end_time = dateutil.parser.isoparse(q['end_time']) - queries.append(Query(start_time, end_time, q['text'])) + for q in transaction_dict["queries"]: + start_time = dateutil.parser.isoparse(q["record_time"]) + if q["start_time"] is not None: + start_time = dateutil.parser.isoparse(q["start_time"]) + end_time = dateutil.parser.isoparse(q["record_time"]) + if q["end_time"] is not None: + end_time = dateutil.parser.isoparse(q["end_time"]) + queries.append(Query(start_time, end_time, q["text"])) queries.sort(key=lambda query: query.start_time) - transaction_key = get_connection_key(transaction_dict['db'], transaction_dict['user'], transaction_dict['pid']) - return Transaction(transaction_dict['time_interval'], transaction_dict['db'], transaction_dict['user'], - transaction_dict['pid'], transaction_dict['xid'], queries, transaction_key) + transaction_key = get_connection_key( + transaction_dict["db"], transaction_dict["user"], transaction_dict["pid"] + ) + return Transaction( + transaction_dict["time_interval"], + transaction_dict["db"], + transaction_dict["user"], + transaction_dict["pid"], + transaction_dict["xid"], + queries, + transaction_key, + ) def parse_transaction_old(sql_filename, sql_file_text): @@ -716,7 +839,9 @@ def parse_transaction_old(sql_filename, sql_file_text): queries.sort(key=lambda query: query.start_time) transaction_key = get_connection_key(database_name, username, pid) - return Transaction(time_interval, database_name, username, pid, xid, queries, transaction_key) + return Transaction( + time_interval, database_name, username, pid, xid, queries, transaction_key + ) def parse_filename(filename): @@ -734,16 +859,14 @@ def parse_copy_replacements(workload_directory): copy_replacements = {} copy_replacements_reader = None - replacements_path = workload_directory + '/' + g_copy_replacements_filename + replacements_path = workload_directory + "/" + g_copy_replacements_filename if replacements_path.startswith("s3://"): workload_s3_location = replacements_path[5:].partition("/") bucket_name = workload_s3_location[0] prefix = workload_s3_location[2] - s3_object = client("s3").get_object( - Bucket=bucket_name, Key=prefix - ) + s3_object = client("s3").get_object(Bucket=bucket_name, Key=prefix) csv_string = s3_object["Body"].read().decode("utf-8") copy_replacements_reader = csv.reader(csv_string.splitlines()) @@ -752,12 +875,14 @@ def parse_copy_replacements(workload_directory): if len(row) == 3 and row[2]: copy_replacements[row[0]] = [row[1], row[2]] else: - with open(replacements_path, 'r') as csvfile: + with open(replacements_path, "r") as csvfile: copy_replacements_reader = csv.reader(csvfile) next(copy_replacements_reader) # Skip header for idx, row in enumerate(copy_replacements_reader): if len(row) != 3: - logger.error(f"Replacements file {replacements_path} is malformed (row {idx}, line:\n{row}") + logger.error( + f"Replacements file {replacements_path} is malformed (row {idx}, line:\n{row}" + ) sys.exit() copy_replacements[row[0]] = [row[1], row[2]] @@ -768,21 +893,28 @@ def parse_copy_replacements(workload_directory): def collect_stats(aggregated_stats, stats): - """ Aggregate the per-thread stats into the overall stats for this aggregated process """ + """Aggregate the per-thread stats into the overall stats for this aggregated process""" if not stats: return # take the maximum absolute connection difference between actual and expected - if abs(stats['connection_diff_sec']) >= abs(aggregated_stats.get('connection_diff_sec', 0)): - aggregated_stats['connection_diff_sec'] = stats['connection_diff_sec'] + if abs(stats["connection_diff_sec"]) >= abs( + aggregated_stats.get("connection_diff_sec", 0) + ): + aggregated_stats["connection_diff_sec"] = stats["connection_diff_sec"] # for each aggregated, add up these scalars across all threads - for stat in ('transaction_success', 'transaction_error', 'query_success', 'query_error'): + for stat in ( + "transaction_success", + "transaction_error", + "query_success", + "query_error", + ): aggregated_stats[stat] += stats[stat] # same for arrays. - for stat in ('transaction_error_log', 'connection_error_log'): + for stat in ("transaction_error_log", "connection_error_log"): # note that per the Manager python docs, this extra copy is required to # get manager to notice the update new_stats = aggregated_stats[stat] @@ -798,22 +930,30 @@ def percent(num, den): def init_stats(stats_dict): # init by key to ensure Manager is notified of change, if applicable - stats_dict['connection_diff_sec'] = 0 - stats_dict['transaction_success'] = 0 - stats_dict['transaction_error'] = 0 - stats_dict['query_success'] = 0 - stats_dict['query_error'] = 0 - stats_dict['connection_error_log'] = {} # map filename to array of connection errors - stats_dict['transaction_error_log'] = {} # map filename to array of transaction errors - stats_dict['multi_statements'] = 0 - stats_dict['executed_queries'] = 0 # includes multi-statement queries + stats_dict["connection_diff_sec"] = 0 + stats_dict["transaction_success"] = 0 + stats_dict["transaction_error"] = 0 + stats_dict["query_success"] = 0 + stats_dict["query_error"] = 0 + stats_dict[ + "connection_error_log" + ] = {} # map filename to array of connection errors + stats_dict[ + "transaction_error_log" + ] = {} # map filename to array of transaction errors + stats_dict["multi_statements"] = 0 + stats_dict["executed_queries"] = 0 # includes multi-statement queries return stats_dict -def display_stats(stats, total_connections, total_transactions, total_queries, peak_connections): +def display_stats( + stats, total_connections, total_transactions, total_queries, peak_connections +): stats_str = "" - stats_str += f"Queries executed: {stats['query_success'] + stats['query_error']} of {total_queries} " \ - f"({percent(stats['query_success'] + stats['query_error'], total_queries):.1f}%)" + stats_str += ( + f"Queries executed: {stats['query_success'] + stats['query_error']} of {total_queries} " + f"({percent(stats['query_success'] + stats['query_error'], total_queries):.1f}%)" + ) stats_str += " [" stats_str += f"Success: {stats['query_success']} ({percent(stats['query_success'], stats['query_success'] + stats['query_error']):.1f}%), " stats_str += f"Failed: {stats['query_error']} ({percent(stats['query_error'], stats['query_success'] + stats['query_error']):.1f}%), " @@ -837,23 +977,35 @@ def join_finished_threads(connection_threads, worker_stats, wait=False): for t in finished_threads: del connection_threads[t] - logger.debug(f"Joined {len(finished_threads)} threads, {len(connection_threads)} still active.") + logger.debug( + f"Joined {len(finished_threads)} threads, {len(connection_threads)} still active." + ) return len(finished_threads) -def replay_worker(process_idx, replay_start_time, first_event_time, queue, error_logger, worker_stats, default_interface, odbc_driver, - connection_semaphore, - num_connections, peak_connections): - """ Worker process to distribute the work among several processes. Each - worker pulls a connection off the queue, waits until its time to start - it, spawns a thread to execute the actual connection and associated - transactions, and then repeats. """ +def replay_worker( + process_idx, + replay_start_time, + first_event_time, + queue, + error_logger, + worker_stats, + default_interface, + odbc_driver, + connection_semaphore, + num_connections, + peak_connections, +): + """Worker process to distribute the work among several processes. Each + worker pulls a connection off the queue, waits until its time to start + it, spawns a thread to execute the actual connection and associated + transactions, and then repeats.""" # map thread to stats dict connection_threads = {} connections_processed = 0 - threading.current_thread().name = '0' + threading.current_thread().name = "0" perf_lock = threading.Lock() @@ -876,7 +1028,8 @@ def replay_worker(process_idx, replay_start_time, first_event_time, queue, error try: if connection_semaphore is not None: logger.debug( - f"Checking for connection throttling ({num_connections.value} / {g_config['limit_concurrent_connections']} active connections)") + f"Checking for connection throttling ({num_connections.value} / {g_config['limit_concurrent_connections']} active connections)" + ) sem_start = time.time() connection_semaphore.acquire() sem_elapsed = time.time() - sem_start @@ -887,11 +1040,17 @@ def replay_worker(process_idx, replay_start_time, first_event_time, queue, error if connection_semaphore is not None: connection_semaphore.release() - elapsed = int(time.time() - last_empty_queue_time) if last_empty_queue_time else 0 + elapsed = ( + int(time.time() - last_empty_queue_time) + if last_empty_queue_time + else 0 + ) # take into account the initial timeout elapsed += timeout_sec empty_queue_timeout_sec = g_config.get("empty_queue_timeout_sec", 120) - logger.debug(f"No jobs for {elapsed} seconds (timeout {empty_queue_timeout_sec})") + logger.debug( + f"No jobs for {elapsed} seconds (timeout {empty_queue_timeout_sec})" + ) # normally processes exit when they get a False on the queue, # but in case of some error we exit if the queue is empty for some time if elapsed > empty_queue_timeout_sec: @@ -913,11 +1072,12 @@ def replay_worker(process_idx, replay_start_time, first_event_time, queue, error time_elapsed_ms = current_offset_ms(replay_start_time) # what is the time offset of this connection job relative to the first event - connection_offset_ms = job['connection'].offset_ms(first_event_time) + connection_offset_ms = job["connection"].offset_ms(first_event_time) delay_sec = (connection_offset_ms - time_elapsed_ms) / 1000.0 logger.debug( - f"Got job {job['job_id'] + 1}, delay {delay_sec:+.3f} sec (extracted connection time: {job['connection'].session_initiation_time})") + f"Got job {job['job_id'] + 1}, delay {delay_sec:+.3f} sec (extracted connection time: {job['connection'].session_initiation_time})" + ) # if connection time is more than a few ms in the future, sleep until its due. # this is approximate and we use "a few ms" here due to the imprecision of @@ -927,12 +1087,13 @@ def replay_worker(process_idx, replay_start_time, first_event_time, queue, error time.sleep(delay_sec) logger.debug( - f"Starting job {job['job_id'] + 1} (extracted connection time: {job['connection'].session_initiation_time}). {len(threading.enumerate())}, {threading.active_count()} connections active.") + f"Starting job {job['job_id'] + 1} (extracted connection time: {job['connection'].session_initiation_time}). {len(threading.enumerate())}, {threading.active_count()} connections active." + ) connection_thread = ConnectionThread( process_idx, - job['job_id'], - job['connection'], + job["job_id"], + job["connection"], default_interface, odbc_driver, replay_start_time, @@ -942,7 +1103,7 @@ def replay_worker(process_idx, replay_start_time, first_event_time, queue, error num_connections, peak_connections, connection_semaphore, - perf_lock + perf_lock, ) connection_thread.name = f"{job['job_id']}" connection_thread.start() @@ -959,14 +1120,16 @@ def replay_worker(process_idx, replay_start_time, first_event_time, queue, error logger.debug("".join(traceback.format_exception(*sys.exc_info()))) if connections_processed: - logger.debug(f"Max connection offset for this process: {worker_stats['connection_diff_sec']:.3f} sec") + logger.debug( + f"Max connection offset for this process: {worker_stats['connection_diff_sec']:.3f} sec" + ) logger.debug(f"Process {process_idx} finished") def put_and_retry(job, queue, timeout=10, non_workers=0): - """ Retry adding to the queue indefinitely until it succeeds. This - should only raise an exception and retry if the queue limit is hit. """ + """Retry adding to the queue indefinitely until it succeeds. This + should only raise an exception and retry if the queue limit is hit.""" attempt = 0 while True: try: @@ -976,7 +1139,9 @@ def put_and_retry(job, queue, timeout=10, non_workers=0): # check to make sure child processes are alive active_workers = len(multiprocessing.active_children()) - non_workers if active_workers == 0: - logger.error("Queue full, but there don't appear to be any active workers. Giving up.") + logger.error( + "Queue full, but there don't appear to be any active workers. Giving up." + ) return False attempt += 1 logger.info(f"Queue full, retrying attempt {attempt}") @@ -997,10 +1162,21 @@ def sigint_handler(signum, frame): raise KeyboardInterrupt -def start_replay(connection_logs, default_interface, odbc_driver, first_event_time, last_event_time, - num_workers, manager, error_logger, per_process_stats, total_transactions, total_queries): - """ create a queue for passing jobs to the workers. the limit will cause - put() to block if the queue is full """ +def start_replay( + connection_logs, + default_interface, + odbc_driver, + first_event_time, + last_event_time, + num_workers, + manager, + error_logger, + per_process_stats, + total_transactions, + total_queries, +): + """create a queue for passing jobs to the workers. the limit will cause + put() to block if the queue is full""" queue = manager.Queue(maxsize=1000000) if not num_workers: @@ -1011,7 +1187,8 @@ def start_replay(connection_logs, default_interface, odbc_driver, first_event_ti else: num_workers = 4 logger.warning( - f"Couldn't determine the number of cpus, defaulting to {num_workers} processes. Use the configuration parameter num_workers to change this.") + f"Couldn't determine the number of cpus, defaulting to {num_workers} processes. Use the configuration parameter num_workers to change this." + ) logger.debug(f"Running with {num_workers} workers") @@ -1025,17 +1202,33 @@ def start_replay(connection_logs, default_interface, odbc_driver, first_event_ti connection_semaphore = None num_connections = manager.Value(int, 0) peak_connections = manager.Value(int, 0) - if g_config.get('limit_concurrent_connections'): + if g_config.get("limit_concurrent_connections"): # create an IPC semaphore to limit the total concurrency - connection_semaphore = manager.Semaphore(g_config.get('limit_concurrent_connections')) + connection_semaphore = manager.Semaphore( + g_config.get("limit_concurrent_connections") + ) for idx in range(num_workers): per_process_stats[idx] = manager.dict() init_stats(per_process_stats[idx]) - g_workers.append(multiprocessing.Process(target=replay_worker, - args=(idx, g_replay_timestamp, first_event_time, queue, error_logger, - per_process_stats[idx], default_interface, odbc_driver, - connection_semaphore, num_connections, peak_connections))) + g_workers.append( + multiprocessing.Process( + target=replay_worker, + args=( + idx, + g_replay_timestamp, + first_event_time, + queue, + error_logger, + per_process_stats[idx], + default_interface, + odbc_driver, + connection_semaphore, + num_connections, + peak_connections, + ), + ) + ) g_workers[-1].start() signal.signal(signal.SIGINT, sigint_handler) @@ -1046,7 +1239,11 @@ def start_replay(connection_logs, default_interface, odbc_driver, first_event_ti for idx, connection in enumerate(connection_logs): # if idx > 5: # break - if not put_and_retry({"job_id": idx, "connection": connection}, queue, non_workers=initial_processes): + if not put_and_retry( + {"job_id": idx, "connection": connection}, + queue, + non_workers=initial_processes, + ): break # and add one termination "job"/signal for each worker so signal them to exit when @@ -1080,8 +1277,13 @@ def start_replay(connection_logs, default_interface, odbc_driver, first_event_ti for idx, stat in per_process_stats.items(): collect_stats(aggregated_stats, stat) if cnt % 5 == 0: - display_stats(aggregated_stats, len(connection_logs), total_transactions, total_queries, - peak_connections) + display_stats( + aggregated_stats, + len(connection_logs), + total_transactions, + total_queries, + peak_connections, + ) peak_connections.value = num_connections.value except KeyError: logger.debug("No stats to display yet.") @@ -1105,20 +1307,24 @@ def start_replay(connection_logs, default_interface, odbc_driver, first_event_ti return True -def export_errors(connection_errors, transaction_errors, workload_location, replay_name): - """ Save any errors that occurred during replay to a local directory or s3 """ +def export_errors( + connection_errors, transaction_errors, workload_location, replay_name +): + """Save any errors that occurred during replay to a local directory or s3""" if len(connection_errors) == len(transaction_errors) == 0: logger.info("No errors, nothing to save") return - logger.info(f"Saving {len(connection_errors)} connection errors, {len(transaction_errors)} transaction_errors") + logger.info( + f"Saving {len(connection_errors)} connection errors, {len(transaction_errors)} transaction_errors" + ) connection_error_location = ( - workload_location + "/" + replay_name + "/connection_errors" + workload_location + "/" + replay_name + "/connection_errors" ) transaction_error_location = ( - workload_location + "/" + replay_name + "/transaction_errors" + workload_location + "/" + replay_name + "/transaction_errors" ) logger.info(f"Exporting connection errors to {connection_error_location}/") logger.info(f"Exporting transaction errors to {transaction_error_location}/") @@ -1135,7 +1341,11 @@ def export_errors(connection_errors, transaction_errors, workload_location, repl for filename, connection_error_text in connection_errors.items(): if workload_location.startswith("s3://"): if prefix: - key_loc = "%s/%s/connection_errors/%s.txt" % (prefix, replay_name, filename) + key_loc = "%s/%s/connection_errors/%s.txt" % ( + prefix, + replay_name, + filename, + ) else: key_loc = "%s/connection_errors/%s.txt" % (replay_name, filename) s3_client.put_object( @@ -1155,7 +1365,11 @@ def export_errors(connection_errors, transaction_errors, workload_location, repl if workload_location.startswith("s3://"): if prefix: - key_loc = "%s/%s/transaction_errors/%s.txt" % (prefix, replay_name, filename) + key_loc = "%s/%s/transaction_errors/%s.txt" % ( + prefix, + replay_name, + filename, + ) else: key_loc = "%s/transaction_errors/%s.txt" % (replay_name, filename) s3_client.put_object( @@ -1174,24 +1388,32 @@ def assign_copy_replacements(connection_logs, replacements): for transaction in connection_log.transactions: for query in transaction.queries: if "copy " in query.text.lower() and "from 's3:" in query.text.lower(): - - from_text = re.search(r"from 's3:\/\/[^']*", query.text, re.IGNORECASE) + from_text = re.search( + r"from 's3:\/\/[^']*", query.text, re.IGNORECASE + ) if from_text: existing_copy_location = from_text.group()[6:] try: - replacement_copy_location = replacements[existing_copy_location][0] + replacement_copy_location = replacements[ + existing_copy_location + ][0] except KeyError: - logger.info(f"No COPY replacement found for {existing_copy_location}") + logger.info( + f"No COPY replacement found for {existing_copy_location}" + ) continue if not replacement_copy_location: replacement_copy_location = existing_copy_location - replacement_copy_iam_role = replacements[existing_copy_location][1] + replacement_copy_iam_role = replacements[ + existing_copy_location + ][1] if not replacement_copy_iam_role: logger.error( - f"COPY replacement {existing_copy_location} is missing IAM role or credentials in {g_copy_replacements_filename}. Please add credentials or remove replacement.") + f"COPY replacement {existing_copy_location} is missing IAM role or credentials in {g_copy_replacements_filename}. Please add credentials or remove replacement." + ) sys.exit() query.text = query.text.replace( @@ -1199,35 +1421,53 @@ def assign_copy_replacements(connection_logs, replacements): ) iam_replacements = [ - (r"IAM_ROLE 'arn:aws:iam::\d+:role/\S+'", f" IAM_ROLE '{replacement_copy_iam_role}'"), - (r"credentials ''", f" IAM_ROLE '{replacement_copy_iam_role}'"), - (r"with credentials as ''", f" IAM_ROLE '{replacement_copy_iam_role}'"), - (r"IAM_ROLE ''", f" IAM_ROLE '{replacement_copy_iam_role}'"), - (r"ACCESS_KEY_ID '' SECRET_ACCESS_KEY '' SESSION_TOKEN ''", - f" IAM_ROLE '{replacement_copy_iam_role}'"), - (r"ACCESS_KEY_ID '' SECRET_ACCESS_KEY ''", f" IAM_ROLE '{replacement_copy_iam_role}'") + ( + r"IAM_ROLE 'arn:aws:iam::\d+:role/\S+'", + f" IAM_ROLE '{replacement_copy_iam_role}'", + ), + ( + r"credentials ''", + f" IAM_ROLE '{replacement_copy_iam_role}'", + ), + ( + r"with credentials as ''", + f" IAM_ROLE '{replacement_copy_iam_role}'", + ), + ( + r"IAM_ROLE ''", + f" IAM_ROLE '{replacement_copy_iam_role}'", + ), + ( + r"ACCESS_KEY_ID '' SECRET_ACCESS_KEY '' SESSION_TOKEN ''", + f" IAM_ROLE '{replacement_copy_iam_role}'", + ), + ( + r"ACCESS_KEY_ID '' SECRET_ACCESS_KEY ''", + f" IAM_ROLE '{replacement_copy_iam_role}'", + ), ] for r in iam_replacements: - query.text = re.sub(r[0], r[1], query.text, flags=re.IGNORECASE) + query.text = re.sub( + r[0], r[1], query.text, flags=re.IGNORECASE + ) def assign_unloads(connection_logs, replay_output, replay_name, unload_iam_role): for connection_log in connection_logs: for transaction in connection_log.transactions: for query in transaction.queries: - if "unload" in query.text.lower() and "to 's3:" in query.text.lower(): - to_text = re.search(r"to 's3:\/\/[^']*", query.text, re.IGNORECASE).group()[9:] + to_text = re.search( + r"to 's3:\/\/[^']*", query.text, re.IGNORECASE + ).group()[9:] if to_text: - existing_unload_location = re.search(r"to 's3:\/\/[^']*", query.text, re.IGNORECASE).group()[4:] + existing_unload_location = re.search( + r"to 's3:\/\/[^']*", query.text, re.IGNORECASE + ).group()[4:] replacement_unload_location = ( - replay_output - + "/" - + replay_name - + "/UNLOADs/" - + to_text + replay_output + "/" + replay_name + "/UNLOADs/" + to_text ) new_query_text = query.text.replace( @@ -1281,14 +1521,14 @@ def assign_time_intervals(connection_logs): elif connection_log.time_interval_between_queries == "all off": is_calculate_time_interval = False else: - is_calculate_time_interval = str(transaction.time_interval).lower() == "true" + is_calculate_time_interval = ( + str(transaction.time_interval).lower() == "true" + ) if is_calculate_time_interval: for index, sql in enumerate(transaction.queries[1:]): - prev_sql = transaction.queries[ - index - ] + prev_sql = transaction.queries[index] prev_sql.time_interval = ( - sql.start_time - prev_sql.end_time + sql.start_time - prev_sql.end_time ).total_seconds() @@ -1313,7 +1553,9 @@ def assign_create_user_password(connection_logs): ) -def get_connection_credentials(username, database=None, max_attempts=10, skip_cache=False): +def get_connection_credentials( + username, database=None, max_attempts=10, skip_cache=False +): credentials_timeout_sec = 3600 retry_delay_sec = 10 @@ -1323,10 +1565,11 @@ def get_connection_credentials(username, database=None, max_attempts=10, skip_ca # check the cache if not skip_cache and g_credentials_cache.get(username) is not None: record = g_credentials_cache.get(username) - if (datetime.datetime.now(tz=datetime.timezone.utc) - record[ - 'last_update']).total_seconds() < cache_timeout_sec: - logger.debug(f'Using {username} credentials from cache') - return record['target_cluster_urls'] + if ( + datetime.datetime.now(tz=datetime.timezone.utc) - record["last_update"] + ).total_seconds() < cache_timeout_sec: + logger.debug(f"Using {username} credentials from cache") + return record["target_cluster_urls"] del g_credentials_cache[username] cluster_endpoint = g_config["target_cluster_endpoint"] @@ -1336,8 +1579,8 @@ def get_connection_credentials(username, database=None, max_attempts=10, skip_ca cluster_id = cluster_endpoint_split[0] # Keeping NLB just for Serverless for now - if g_config['nlb_nat_dns'] is not None and g_is_serverless: - cluster_host = g_config['nlb_nat_dns'] + if g_config["nlb_nat_dns"] is not None and g_is_serverless: + cluster_host = g_config["nlb_nat_dns"] else: cluster_host = cluster_endpoint.split(":")[0] @@ -1345,85 +1588,121 @@ def get_connection_credentials(username, database=None, max_attempts=10, skip_ca database = cluster_endpoint_split[5].split("/")[1] if database is None else database additional_args = {} - if os.environ.get('ENDPOINT_URL'): + if os.environ.get("ENDPOINT_URL"): import urllib3 + # disable insecure warnings when testing endpoint is used urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) - additional_args = {'endpoint_url': os.environ.get('ENDPOINT_URL'), - 'verify': False} + additional_args = { + "endpoint_url": os.environ.get("ENDPOINT_URL"), + "verify": False, + } response = None db_user = None db_password = None - secret_keys = ['admin_username', 'admin_password'] + secret_keys = ["admin_username", "admin_password"] if g_is_serverless: - if g_config['secret_name'] is not None: + if g_config["secret_name"] is not None: logger.info(f"Fetching secrets from: {g_config['secret_name']}") - secret_name = get_secret(g_config["secret_name"], g_config["target_cluster_region"]) + secret_name = get_secret( + g_config["secret_name"], g_config["target_cluster_region"] + ) if len(set(secret_keys) - set(secret_name.keys())) == 0: - response = {'DbUser': secret_name["admin_username"], 'DbPassword': secret_name["admin_password"]} + response = { + "DbUser": secret_name["admin_username"], + "DbPassword": secret_name["admin_password"], + } else: logger.error(f"Required secrets not found: {secret_keys}") exit(-1) else: # Using backward compatibility method to fetch user credentials for serverless workgroup # rs_client = client('redshift-serverless', region_name=g_config.get("target_cluster_region", None)) - rs_client = client('redshift', region_name=g_config.get("target_cluster_region", None)) + rs_client = client( + "redshift", region_name=g_config.get("target_cluster_region", None) + ) for attempt in range(1, max_attempts + 1): try: # response = rs_client.get_credentials(dbName=database, durationSeconds = 3600, workgroupName=cluster_id) serverless_cluster_id = f"redshift-serverless-{cluster_id}" - logger.debug(f"Serverless cluster id {serverless_cluster_id} passed to get_cluster_credentials") + logger.debug( + f"Serverless cluster id {serverless_cluster_id} passed to get_cluster_credentials" + ) response = rs_client.get_cluster_credentials( - DbUser=username, ClusterIdentifier=serverless_cluster_id, AutoCreate=False, - DurationSeconds=credentials_timeout_sec + DbUser=username, + ClusterIdentifier=serverless_cluster_id, + AutoCreate=False, + DurationSeconds=credentials_timeout_sec, ) except rs_client.exceptions.ClientError as e: - if e.response['Error']['Code'] == 'ExpiredToken': - logger.error(f"Error retrieving credentials for {cluster_id}: IAM credentials have expired.") + if e.response["Error"]["Code"] == "ExpiredToken": + logger.error( + f"Error retrieving credentials for {cluster_id}: IAM credentials have expired." + ) exit(-1) - elif e.response['Error']['Code'] == 'ResourceNotFoundException': - logger.error(f"Serverless endpoint could not be found " - f"RedshiftServerless:GetCredentials. {e}") + elif e.response["Error"]["Code"] == "ResourceNotFoundException": + logger.error( + f"Serverless endpoint could not be found " + f"RedshiftServerless:GetCredentials. {e}" + ) exit(-1) else: - logger.error(f"Got exception retrieving credentials ({e.response['Error']['Code']})") + logger.error( + f"Got exception retrieving credentials ({e.response['Error']['Code']})" + ) raise e - if response is None or response.get('DbPassword') is None: - logger.warning(f"Failed to retrieve credentials for db {database} (attempt {attempt}/{max_attempts})") + if response is None or response.get("DbPassword") is None: + logger.warning( + f"Failed to retrieve credentials for db {database} (attempt {attempt}/{max_attempts})" + ) logger.debug(response) response = None if attempt < max_attempts: time.sleep(retry_delay_sec) else: break - db_user = response['DbUser'] - db_password = response['DbPassword'] + db_user = response["DbUser"] + db_password = response["DbPassword"] else: - rs_client = client("redshift", region_name=g_config.get("target_cluster_region", None), **additional_args) + rs_client = client( + "redshift", + region_name=g_config.get("target_cluster_region", None), + **additional_args, + ) for attempt in range(1, max_attempts + 1): try: response = rs_client.get_cluster_credentials( - DbUser=username, ClusterIdentifier=cluster_id, AutoCreate=False, - DurationSeconds=credentials_timeout_sec + DbUser=username, + ClusterIdentifier=cluster_id, + AutoCreate=False, + DurationSeconds=credentials_timeout_sec, ) except NoCredentialsError: raise CredentialsException("No credentials found") except rs_client.exceptions.ClientError as e: - if e.response['Error']['Code'] == 'ExpiredToken': - logger.error(f"Error retrieving credentials for {cluster_id}: IAM credentials have expired.") + if e.response["Error"]["Code"] == "ExpiredToken": + logger.error( + f"Error retrieving credentials for {cluster_id}: IAM credentials have expired." + ) exit(-1) else: - logger.error(f"Got exception retrieving credentials ({e.response['Error']['Code']})") + logger.error( + f"Got exception retrieving credentials ({e.response['Error']['Code']})" + ) raise e except rs_client.exceptions.ClusterNotFoundFault: - logger.error(f"Cluster {cluster_id} not found. Please confirm cluster endpoint, account, and region.") + logger.error( + f"Cluster {cluster_id} not found. Please confirm cluster endpoint, account, and region." + ) exit(-1) - if response is None or response.get('DbPassword') is None: - logger.warning(f"Failed to retrieve credentials for user {username} (attempt {attempt}/{max_attempts})") + if response is None or response.get("DbPassword") is None: + logger.warning( + f"Failed to retrieve credentials for user {username} (attempt {attempt}/{max_attempts})" + ) logger.debug(response) response = None if attempt < max_attempts: @@ -1437,15 +1716,13 @@ def get_connection_credentials(username, database=None, max_attempts=10, skip_ca msg = f"Failed to retrieve credentials for {username}" raise CredentialsException(msg) - cluster_odbc_url = ( - "Driver={}; Server={}; Database={}; IAM=1; DbUser={}; DbPassword={}; Port={}".format( - odbc_driver, - cluster_host, - database, - db_user.split(":")[1] if ":" in db_user else db_user, - db_password, - cluster_port, - ) + cluster_odbc_url = "Driver={}; Server={}; Database={}; IAM=1; DbUser={}; DbPassword={}; Port={}".format( + odbc_driver, + cluster_host, + database, + db_user.split(":")[1] if ":" in db_user else db_user, + db_password, + cluster_port, ) cluster_psql = { @@ -1457,37 +1734,43 @@ def get_connection_credentials(username, database=None, max_attempts=10, skip_ca } credentials = { # old params - 'odbc': cluster_odbc_url, - 'psql': cluster_psql, + "odbc": cluster_odbc_url, + "psql": cluster_psql, # new params - 'username': db_user, - 'password': db_password, - 'host': cluster_host, - 'port': cluster_port, - 'database': database, - 'odbc_driver': g_config["odbc_driver"] + "username": db_user, + "password": db_password, + "host": cluster_host, + "port": cluster_port, + "database": database, + "odbc_driver": g_config["odbc_driver"], } logger.debug("Successfully retrieved database credentials for {}".format(username)) - g_credentials_cache[username] = {'last_update': datetime.datetime.now(tz=datetime.timezone.utc), - 'target_cluster_urls': credentials} + g_credentials_cache[username] = { + "last_update": datetime.datetime.now(tz=datetime.timezone.utc), + "target_cluster_urls": credentials, + } return credentials def unload_system_table( - default_interface, - unload_system_table_queries_file, - unload_location, - unload_iam_role, + default_interface, + unload_system_table_queries_file, + unload_location, + unload_iam_role, ): # TODO: wrap this in retries and proper logging - credentials = get_connection_credentials(g_config["master_username"], max_attempts=3) - conn = db_connect(default_interface, - host=credentials['host'], - port=int(credentials['port']), - username=credentials['username'], - password=credentials['password'], - database=credentials['database'], - odbc_driver=credentials['odbc_driver']) + credentials = get_connection_credentials( + g_config["master_username"], max_attempts=3 + ) + conn = db_connect( + default_interface, + host=credentials["host"], + port=int(credentials["port"]), + username=credentials["username"], + password=credentials["password"], + database=credentials["database"], + odbc_driver=credentials["odbc_driver"], + ) unload_queries = {} table_name = "" @@ -1526,16 +1809,16 @@ def unload_system_table( def validate_config(config): - if not bool(re.fullmatch(g_cluster_endpoint_pattern, config["target_cluster_endpoint"])): + if not bool( + re.fullmatch(g_cluster_endpoint_pattern, config["target_cluster_endpoint"]) + ): logger.error( 'Config file value for "target_cluster_endpoint" is not a valid endpoint. Endpoints must be in the format ' - 'of :/.' + "of :/." ) exit(-1) if not config["target_cluster_region"]: - logger.error( - 'Config file value for "target_cluster_region" is required.' - ) + logger.error('Config file value for "target_cluster_region" is required.') exit(-1) if not config["odbc_driver"]: config["odbc_driver"] = None @@ -1548,13 +1831,12 @@ def validate_config(config): import pyodbc except ValueError: logger.error( - 'Import of pyodbc failed. Please install pyodbc library to use ODBC as default driver. Please refer ' - 'to REAME.md' + "Import of pyodbc failed. Please install pyodbc library to use ODBC as default driver. Please refer " + "to REAME.md" ) exit(-1) if not ( - config["default_interface"] == "psql" - or config["default_interface"] == "odbc" + config["default_interface"] == "psql" or config["default_interface"] == "odbc" ): logger.error( 'Config file value for "default_interface" must be either "psql" or "odbc". Please change the value for ' @@ -1562,9 +1844,9 @@ def validate_config(config): ) exit(-1) if not ( - config["time_interval_between_transactions"] == "" - or config["time_interval_between_transactions"] == "all on" - or config["time_interval_between_transactions"] == "all off" + config["time_interval_between_transactions"] == "" + or config["time_interval_between_transactions"] == "all on" + or config["time_interval_between_transactions"] == "all off" ): logger.error( 'Config file value for "time_interval_between_transactions" must be either "", "all on", or "all off". ' @@ -1572,9 +1854,9 @@ def validate_config(config): ) exit(-1) if not ( - config["time_interval_between_queries"] == "" - or config["time_interval_between_queries"] == "all on" - or config["time_interval_between_queries"] == "all off" + config["time_interval_between_queries"] == "" + or config["time_interval_between_queries"] == "all on" + or config["time_interval_between_queries"] == "all off" ): logger.error( 'Config file value for "time_interval_between_queries" must be either "", "all on", or "all off". Please ' @@ -1582,8 +1864,8 @@ def validate_config(config): ) exit(-1) if not ( - config["execute_copy_statements"] == "true" - or config["execute_copy_statements"] == "false" + config["execute_copy_statements"] == "true" + or config["execute_copy_statements"] == "false" ): logger.error( 'Config file value for "execute_copy_statements" must be either "true" or "false". Please change the value ' @@ -1591,20 +1873,18 @@ def validate_config(config): ) exit(-1) if not ( - config["execute_unload_statements"] == "true" - or config["execute_unload_statements"] == "false" + config["execute_unload_statements"] == "true" + or config["execute_unload_statements"] == "false" ): logger.error( 'Config file value for "execute_unload_statements" must be either "true" or "false". Please change the ' 'value for "execute_unload_statements" to either "true" or "false".' ) exit(-1) - if config["replay_output"] and not config["replay_output"].startswith( - "s3://" - ): + if config["replay_output"] and not config["replay_output"].startswith("s3://"): logger.error( 'Config file value for "replay_output" must be an S3 location (starts with "s3://"). Please remove this ' - 'value or put in an S3 location.' + "value or put in an S3 location." ) exit(-1) if not config["replay_output"] and config["execute_unload_statements"] == "true": @@ -1614,9 +1894,9 @@ def validate_config(config): ) exit(-1) if ( - config["replay_output"] - and config["target_cluster_system_table_unload_iam_role"] - and not config["unload_system_table_queries"] + config["replay_output"] + and config["target_cluster_system_table_unload_iam_role"] + and not config["unload_system_table_queries"] ): logger.error( 'Config file missing value for "unload_system_table_queries". Please provide a value for ' @@ -1624,10 +1904,10 @@ def validate_config(config): ) exit(-1) if ( - config["replay_output"] - and config["target_cluster_system_table_unload_iam_role"] - and config["unload_system_table_queries"] - and not config["unload_system_table_queries"].endswith(".sql") + config["replay_output"] + and config["target_cluster_system_table_unload_iam_role"] + and config["unload_system_table_queries"] + and not config["unload_system_table_queries"].endswith(".sql") ): logger.error( 'Config file value for "unload_system_table_queries" does not end with ".sql". Please ensure the value for ' @@ -1642,15 +1922,15 @@ def validate_config(config): if not config["nlb_nat_dns"]: config["nlb_nat_dns"] = None logger.debug( - 'No NLB / NAT endpoint specified. Replay will use target_cluster_endpoint to connect.' + "No NLB / NAT endpoint specified. Replay will use target_cluster_endpoint to connect." ) if not config["secret_name"]: config["secret_name"] = None - logger.debug( - 'SECRET_NAME property not specified.' - ) + logger.debug("SECRET_NAME property not specified.") - config['filters'] = validate_and_normalize_filters(ConnectionLog, config.get('filters', {})) + config["filters"] = validate_and_normalize_filters( + ConnectionLog, config.get("filters", {}) + ) def print_stats(stats): @@ -1660,10 +1940,13 @@ def print_stats(stats): max_connection_diff = 0 for process_idx in stats.keys(): - if abs(stats[process_idx].get('connection_diff_sec', 0)) > abs(max_connection_diff): - max_connection_diff = stats[process_idx]['connection_diff_sec'] + if abs(stats[process_idx].get("connection_diff_sec", 0)) > abs( + max_connection_diff + ): + max_connection_diff = stats[process_idx]["connection_diff_sec"] logger.debug( - f"[{process_idx}] Max connection offset: {stats[process_idx].get('connection_diff_sec', 0):+.3f} sec") + f"[{process_idx}] Max connection offset: {stats[process_idx].get('connection_diff_sec', 0):+.3f} sec" + ) logger.debug(f"Max connection offset: {max_connection_diff:+.3f} sec") @@ -1675,7 +1958,11 @@ def main(): global g_is_serverless parser = argparse.ArgumentParser() - parser.add_argument("config_file", type=str, help="Location of replay config file.",) + parser.add_argument( + "config_file", + type=str, + help="Location of replay config file.", + ) args = parser.parse_args() g_config = load_config(args.config_file) @@ -1684,27 +1971,37 @@ def main(): sys.exit(-1) validate_config(g_config) - level = logging.getLevelName(g_config.get('log_level', 'INFO').upper()) + level = logging.getLevelName(g_config.get("log_level", "INFO").upper()) set_log_level(level) if g_config.get("logfile_level") != "none": - level = logging.getLevelName(g_config.get('logfile_level', 'DEBUG').upper()) - log_file = 'replay.log' + level = logging.getLevelName(g_config.get("logfile_level", "DEBUG").upper()) + log_file = "replay.log" logging_dir = g_config.get("logging_dir", "simplereplay_logs") logger.info(f"Saving SimpleReplay logs to {logging_dir}") - add_logfile(log_file, level=level, dir=logging_dir, - preamble=yaml.dump(g_config), backup_count=g_config.get("backup_count", 2)) + add_logfile( + log_file, + level=level, + dir=logging_dir, + preamble=yaml.dump(g_config), + backup_count=g_config.get("backup_count", 2), + ) # print the version log_version() # populate the global is_serverless variable - if bool(re.fullmatch(g_serverless_cluster_endpoint_pattern, g_config['target_cluster_endpoint'])): - logger.info(f"Replaying on Redshift Serverless Cluster {g_config['target_cluster_endpoint']}") + if bool( + re.fullmatch( + g_serverless_cluster_endpoint_pattern, g_config["target_cluster_endpoint"] + ) + ): + logger.info( + f"Replaying on Redshift Serverless Cluster {g_config['target_cluster_endpoint']}" + ) g_is_serverless = True else: g_is_serverless = False - cluster = cluster_dict(g_config["target_cluster_endpoint"], g_is_serverless) # generate replay id/hash @@ -1712,7 +2009,9 @@ def main(): g_replay_timestamp = datetime.datetime.now(tz=datetime.timezone.utc) logger.info(f"Replay start time: {g_replay_timestamp}") - id_hash = hashlib.sha1(g_replay_timestamp.isoformat().encode("UTF-8")).hexdigest()[:5] + id_hash = hashlib.sha1(g_replay_timestamp.isoformat().encode("UTF-8")).hexdigest()[ + :5 + ] if g_config.get("tag", "") != "": replay_id = f'{g_replay_timestamp.isoformat()}_{cluster.get("id")}_{g_config["tag"]}_{id_hash}' else: @@ -1734,7 +2033,8 @@ def init_manager(): g_config["time_interval_between_queries"], ) logger.info( - f"Found {total_connections} total connections, {total_connections - len(connection_logs)} are excluded by filters. Replaying {len(connection_logs)}.") + f"Found {total_connections} total connections, {total_connections - len(connection_logs)} are excluded by filters. Replaying {len(connection_logs)}." + ) # Associate transactions with connections logger.info( @@ -1761,19 +2061,25 @@ def init_manager(): best_match_idx = None for c_idx in possible_connections: # truncate session start time, since query/transaction time is truncated to seconds - if connection_logs[c_idx].session_initiation_time.replace(microsecond=0) > t.start_time(): + if ( + connection_logs[c_idx].session_initiation_time.replace(microsecond=0) + > t.start_time() + ): break best_match_idx = c_idx if best_match_idx is None: logger.warning( - f"Couldn't find matching connection in {len(possible_connections)} connections for transaction {t}, skipping") + f"Couldn't find matching connection in {len(possible_connections)} connections for transaction {t}, skipping" + ) continue connection_logs[best_match_idx].transactions.append(t) query_count += len(t.queries) logger.info(f"Found {transaction_count} transactions, {query_count} queries") connection_logs = [_ for _ in connection_logs if len(_.transactions) > 0] - logger.info(f"{len(connection_logs)} connections contain transactions and will be replayed ") + logger.info( + f"{len(connection_logs)} connections contain transactions and will be replayed " + ) global g_total_connections g_total_connections = len(connection_logs) @@ -1785,21 +2091,25 @@ def init_manager(): for connection in connection_logs: if ( - connection.session_initiation_time - and connection.session_initiation_time < first_event_time + connection.session_initiation_time + and connection.session_initiation_time < first_event_time ): first_event_time = connection.session_initiation_time if ( - connection.disconnection_time - and connection.disconnection_time > last_event_time + connection.disconnection_time + and connection.disconnection_time > last_event_time ): last_event_time = connection.disconnection_time - if connection.transactions[0].queries[0].start_time and connection.transactions[0].queries[ - 0].start_time < first_event_time: + if ( + connection.transactions[0].queries[0].start_time + and connection.transactions[0].queries[0].start_time < first_event_time + ): first_event_time = connection.transactions[0].queries[0].start_time - if connection.transactions[-1].queries[-1].end_time and connection.transactions[-1].queries[ - -1].end_time > last_event_time: + if ( + connection.transactions[-1].queries[-1].end_time + and connection.transactions[-1].queries[-1].end_time > last_event_time + ): last_event_time = connection.transactions[-1].queries[-1].end_time logger.info( @@ -1836,10 +2146,16 @@ def init_manager(): # test connection try: # use the first user as a test - get_connection_credentials(connection_logs[0].username, database=connection_logs[0].database_name, max_attempts=1) + get_connection_credentials( + connection_logs[0].username, + database=connection_logs[0].database_name, + max_attempts=1, + ) except CredentialsException as e: - logger.error(f"Unable to retrieve credentials using GetClusterCredentials ({str(e)}). " - f"Please verify that an IAM policy exists granting access. See the README for more details.") + logger.error( + f"Unable to retrieve credentials using GetClusterCredentials ({str(e)}). " + f"Please verify that an IAM policy exists granting access. See the README for more details." + ) sys.exit(-1) if len(connection_logs) == 0: @@ -1853,23 +2169,25 @@ def init_manager(): complete = False try: - start_replay(connection_logs, - g_config["default_interface"], - g_config["odbc_driver"], - first_event_time, - last_event_time, - g_config.get("num_workers"), - manager, - error_list, - per_process_stats, - transaction_count, - query_count) + start_replay( + connection_logs, + g_config["default_interface"], + g_config["odbc_driver"], + first_event_time, + last_event_time, + g_config.get("num_workers"), + manager, + error_list, + per_process_stats, + transaction_count, + query_count, + ) complete = True except KeyboardInterrupt: - replay_id += '_INCOMPLETE' + replay_id += "_INCOMPLETE" logger.warning("Got CTRL-C, exiting...") except Exception as e: - replay_id += '_INCOMPLETE' + replay_id += "_INCOMPLETE" logger.error(f"Replay terminated. {e}") logger.debug("Aggregating stats") @@ -1879,8 +2197,10 @@ def init_manager(): replay_summary = [] logger.info("Replay summary:") - replay_summary.append(f"Attempted to replay {query_count} queries, {transaction_count} transactions, " - f"{len(connection_logs)} connections.") + replay_summary.append( + f"Attempted to replay {query_count} queries, {transaction_count} transactions, " + f"{len(connection_logs)} connections." + ) try: replay_summary.append( f"Successfully replayed {aggregated_stats.get('transaction_success', 0)} out of {transaction_count} " @@ -1895,38 +2215,45 @@ def init_manager(): error_location = g_config.get("error_location", g_config["workload_location"]) - replay_summary.append(f"Encountered {len(aggregated_stats['connection_error_log'])} " - f"connection errors and {len(aggregated_stats['transaction_error_log'])} transaction errors") + replay_summary.append( + f"Encountered {len(aggregated_stats['connection_error_log'])} " + f"connection errors and {len(aggregated_stats['transaction_error_log'])} transaction errors" + ) # and save them export_errors( - aggregated_stats['connection_error_log'], - aggregated_stats['transaction_error_log'], + aggregated_stats["connection_error_log"], + aggregated_stats["transaction_error_log"], error_location, replay_id, ) - summary_stats = {"query_count": query_count, - "connection_count": len(connection_logs), - "transaction_count": transaction_count, - "query_success": aggregated_stats.get('query_success', 0), - "connection_errors": len(aggregated_stats['connection_error_log']), - "transaction_errors": len(aggregated_stats['transaction_error_log']), - } + summary_stats = { + "query_count": query_count, + "connection_count": len(connection_logs), + "transaction_count": transaction_count, + "query_success": aggregated_stats.get("query_success", 0), + "connection_errors": len(aggregated_stats["connection_error_log"]), + "transaction_errors": len(aggregated_stats["transaction_error_log"]), + } if len(error_list) != 0: bucket = bucket_dict(g_config["analysis_output"]) - with open('replayerrors000', 'w', newline='') as output_file: + with open("replayerrors000", "w", newline="") as output_file: try: - dict_writer = csv.DictWriter(output_file, fieldnames=error_list[0].keys()) + dict_writer = csv.DictWriter( + output_file, fieldnames=error_list[0].keys() + ) dict_writer.writeheader() dict_writer.writerows(error_list) except Exception as e: logger.debug(f"Failed to write replay errors to CSV. {e}") try: - boto3.resource('s3').Bucket(bucket.get('bucket_name')) \ - .upload_file(output_file.name, f"{bucket['prefix']}analysis/{replay_id}/raw_data/{output_file.name}") + boto3.resource("s3").Bucket(bucket.get("bucket_name")).upload_file( + output_file.name, + f"{bucket['prefix']}analysis/{replay_id}/raw_data/{output_file.name}", + ) except Exception as e: logger.debug(f"Error upload to S3 {bucket['bucket_name']} failed. {e}") @@ -1935,34 +2262,38 @@ def init_manager(): for line in replay_summary: logger.info(line) - logger.info(f"Replay finished in {datetime.datetime.now(tz=datetime.timezone.utc) - g_replay_timestamp}.") - + logger.info( + f"Replay finished in {datetime.datetime.now(tz=datetime.timezone.utc) - g_replay_timestamp}." + ) + if g_config.get("analysis_iam_role") and g_config.get("analysis_output"): try: - run_replay_analysis(replay=replay_id, - cluster_endpoint=g_config["target_cluster_endpoint"], - start_time=g_replay_timestamp, - end_time=replay_end_time, - bucket_url=g_config["analysis_output"], - iam_role=g_config["analysis_iam_role"], - user=g_config["master_username"], - tag=g_config["tag"], - workload=g_config["workload_location"], - is_serverless=g_is_serverless, - secret_name=g_config["secret_name"], - nlb_nat_dns=g_config["nlb_nat_dns"], - complete=complete, - stats=summary_stats, - summary=replay_summary) + run_replay_analysis( + replay=replay_id, + cluster_endpoint=g_config["target_cluster_endpoint"], + start_time=g_replay_timestamp, + end_time=replay_end_time, + bucket_url=g_config["analysis_output"], + iam_role=g_config["analysis_iam_role"], + user=g_config["master_username"], + tag=g_config["tag"], + workload=g_config["workload_location"], + is_serverless=g_is_serverless, + secret_name=g_config["secret_name"], + nlb_nat_dns=g_config["nlb_nat_dns"], + complete=complete, + stats=summary_stats, + summary=replay_summary, + ) except Exception as e: logger.error(f"Could not complete replay analysis. {e}") else: logger.info("Analysis not enabled for this replay.") if ( - g_config["replay_output"] - and g_config["unload_system_table_queries"] - and g_config["target_cluster_system_table_unload_iam_role"] + g_config["replay_output"] + and g_config["unload_system_table_queries"] + and g_config["target_cluster_system_table_unload_iam_role"] ): logger.info(f'Exporting system tables to {g_config["replay_output"]}') diff --git a/src/SimpleReplay/replay_analysis.py b/src/SimpleReplay/replay_analysis.py index b732562a..a7d64643 100644 --- a/src/SimpleReplay/replay_analysis.py +++ b/src/SimpleReplay/replay_analysis.py @@ -15,10 +15,18 @@ from report_gen import pdf_gen from report_util import Report, styles from tabulate import tabulate -from util import db_connect, init_logging, cluster_dict, bucket_dict, get_secret, create_json +from util import ( + db_connect, + init_logging, + cluster_dict, + bucket_dict, + get_secret, + create_json, + redshift_get_cluster_credentials, +) g_stylesheet = styles() -g_columns = g_stylesheet.get('columns') +g_columns = g_stylesheet.get("columns") def launch_analysis_v2(): @@ -27,7 +35,7 @@ def launch_analysis_v2(): # add explicit instructions for user os.system("pip install -r requirements.txt") - os.chdir(f'{os.getcwd()}/gui') + os.chdir(f"{os.getcwd()}/gui") # explicit version checking if os.system("node -v") != 0: @@ -41,10 +49,23 @@ def launch_analysis_v2(): os.system("npm start") -def run_replay_analysis(replay, cluster_endpoint, start_time, end_time, bucket_url, iam_role, user, tag='', - workload="", - is_serverless=False, secret_name=None, nlb_nat_dns=None, complete=True, stats=None, - summary=None): +def run_replay_analysis( + replay, + cluster_endpoint, + start_time, + end_time, + bucket_url, + iam_role, + user, + tag="", + workload="", + is_serverless=False, + secret_name=None, + nlb_nat_dns=None, + complete=True, + stats=None, + summary=None, +): """End to end data collection, parsing, analysis and pdf generation @param replay: str, replay id from replay.py @@ -63,8 +84,7 @@ def run_replay_analysis(replay, cluster_endpoint, start_time, end_time, bucket_u @param summary: str list, replay output summary from replay.py """ - logger = logging.getLogger("SimpleReplayLogger") - s3_client = boto3.client('s3') + logger = logging.getLogger("WorkloadReplicatorLogger") cluster = cluster_dict(cluster_endpoint, is_serverless, start_time, end_time) cluster["is_serverless"] = is_serverless cluster["secret_name"] = secret_name @@ -82,44 +102,48 @@ def run_replay_analysis(replay, cluster_endpoint, start_time, end_time, bucket_u queries = unload(bucket, iam_role, cluster, user, replay) info = create_json(replay, cluster, workload, complete, stats, tag) try: - boto3.resource('s3').Bucket(bucket.get('bucket_name')).upload_file(info, f"{replay_path}/{info}") + boto3.resource("s3").Bucket(bucket.get("bucket_name")).upload_file( + info, f"{replay_path}/{info}" + ) except ClientError as e: - logger.error(f"{e} Could not upload info. Confirm IAM permissions include S3::PutObject.") + logger.error( + f"{e} Could not upload info. Confirm IAM permissions include S3::PutObject." + ) + exit(-1) - if is_serverless: - exit(0) - else: - report = Report(cluster, replay, bucket, replay_path, tag, complete) + report = Report(cluster, replay, bucket, replay_path, tag, complete) - try: - # iterate through query csv results and import - for q in queries: - get_raw_data(report, bucket, replay_path, q) + try: + # iterate through query csv results and import + for q in queries: + get_raw_data(report, bucket, replay_path, q) - except s3_client.exceptions.NoSuchKey as e: - logger.error(f"{e} Raw data does not exist in S3. Error in replay analysis.") - exit(-1) - except Exception as e: - logger.error(f"{e}: Data read failed. Error in replay analysis.") - exit(-1) + except Exception as e: + logger.error(f"{e}: Data read failed. Error in replay analysis.") + exit(-1) - # generate replay_id_report.pdf and info.json - logger.info(f"Generating report.") - pdf = pdf_gen(report, summary) + # generate replay_id_report.pdf and info.json + logger.info(f"Generating report.") + pdf = pdf_gen(report, summary) - s3_resource = boto3.resource('s3') - # upload to s3 and output presigned urls - try: - s3_resource.Bucket(bucket.get('bucket_name')).upload_file(pdf, f"{replay_path}/out/{pdf}") - s3_resource.Bucket(bucket.get('bucket_name')).upload_file(info, f"{replay_path}/out/{info}") - analysis_summary(bucket.get('url'), replay) - except ClientError as e: - logger.error(f"{e} Could not upload report. Confirm IAM permissions include S3::PutObject.") - exit(-1) + # upload to s3 and output presigned urls + try: + boto3.resource("s3").Bucket(bucket.get("bucket_name")).upload_file( + pdf, f"{replay_path}/out/{pdf}" + ) + boto3.resource("s3").Bucket(bucket.get("bucket_name")).upload_file( + info, f"{replay_path}/out/{info}" + ) + analysis_summary(bucket.get("url"), replay) + except ClientError as e: + logger.error( + f"{e} Could not upload report. Confirm IAM permissions include S3::PutObject." + ) + exit(-1) def run_comparison_analysis(bucket, replay1, replay2): - """ Compares two given replays using aggregated_data/ from S3 + """Compares two given replays using aggregated_data/ from S3 @param bucket: str, S3 bucket location @param replay1: str, replay id 1 @@ -135,44 +159,60 @@ def run_comparison_analysis(bucket, replay1, replay2): # print summary -@contextmanager def initiate_connection(username, cluster): - """ Initiate connection with Redshift cluster + """Initiate connection with Redshift cluster @param username: master username from replay.yaml @param cluster: cluster dictionary """ response = None - logger = logging.getLogger("SimpleReplayLogger") + logger = logging.getLogger("WorkloadReplicatorLogger") + secret_keys = ["admin_username", "admin_password"] if cluster.get("is_serverless"): - secret_name = get_secret(cluster.get('secret_name'), cluster.get("region")) - response = {'DbUser': secret_name["admin_username"], 'DbPassword': secret_name["admin_password"]} + if cluster.get("secret_name"): + logger.info(f"Fetching secrets from: {cluster.get['secret_name']}") + secret_name = get_secret(cluster.get("secret_name"), cluster.get("region")) + if not len(set(secret_keys) - set(secret_name.keys())): + response = { + "DbUser": secret_name["admin_username"], + "DbPassword": secret_name["admin_password"], + } + else: + logger.error(f"Required secrets not found: {secret_keys}") + exit(-1) + else: + serverless_cluster_id = f"redshift-serverless-{cluster.get('id')}" + logger.debug( + f"Serverless cluster id {serverless_cluster_id} passed to get_cluster_credentials" + ) + response = redshift_get_cluster_credentials( + cluster.get("region"), + username, + cluster.get("database"), + serverless_cluster_id, + ) + else: - rs_client = client('redshift', region_name=cluster.get("region")) - # get response from redshift to get cluster credentials using provided cluster info try: - response = rs_client.get_cluster_credentials( - DbUser=username, - DbName=cluster.get("database"), - ClusterIdentifier=cluster.get("id"), - DurationSeconds=900, - AutoCreate=False, + response = redshift_get_cluster_credentials( + cluster.get("region"), + username, + cluster.get("database"), + cluster.get("id"), ) - except rs_client.exceptions.ClusterNotFoundFault: - logger.error( - f"Cluster {cluster.get('id')} not found. Please confirm cluster endpoint, account, and region.") - exit(-1) except Exception as e: logger.error( f"Unable to connect to Redshift. Confirm IAM permissions include Redshift::GetClusterCredentials." - f" {e}") + f" {e}" + ) exit(-1) - if response is None or response.get('DbPassword') is None: + if response is None or response.get("DbPassword") is None: logger.error(f"Failed to retrieve credentials for user {username} ") response = None + exit(-1) # define cluster string/dict cluster_string = { @@ -186,15 +226,16 @@ def initiate_connection(username, cluster): conn = None try: logger.info(f"Connecting to {cluster.get('id')}") - conn = db_connect(host=cluster_string["host"], port=int(cluster_string["port"]), - username=cluster_string["username"], password=cluster_string["password"], - database=cluster_string["database"]) # yield to reuse connection + conn = db_connect( + host=cluster_string["host"], + port=int(cluster_string["port"]), + username=cluster_string["username"], + password=cluster_string["password"], + database=cluster_string["database"], + ) # yield to reuse connection yield conn - except redshift_connector.error.Error as e: - logger.error(f"Unable to connect to Redshift. Please confirm credentials. {e} ") - exit(-1) except Exception as e: - logger.error(f"Unable to connect to Redshift. {e}") + logger.error(f"Unable to connect to Redshift. {e}", exc_info=True) exit(-1) finally: if conn is not None: @@ -215,35 +256,45 @@ def unload(unload_location, iam_role, cluster, user, replay): logger = logging.getLogger("SimpleReplayLogger") - directory = r'sql/serverless' + directory = r"sql/serverless" queries = [] # used to return query names - with initiate_connection(username=user, cluster=cluster) as conn: # initiate connection + with initiate_connection( + username=user, cluster=cluster + ) as conn: # initiate connection cursor = conn.cursor() logger.info(f"Querying {cluster.get('id')}. This may take some time.") for file in sorted(os.listdir(directory)): # iterate local sql/ directory - if not file.endswith('.sql'): # validity check + if not file.endswith(".sql"): # validity check continue with open(f"{directory}/{file}", "r") as query_file: # open sql file # get file name prefix for s3 files - query_name = os.path.splitext(file)[0] # get file/query name for reference + query_name = os.path.splitext(file)[ + 0 + ] # get file/query name for reference logger.debug(f"Query: {query_name}") queries.append(query_name) query = query_file.read() # read file contents as string # replace start and end times in sql with variables - query = re.sub(r"{{START_TIME}}", f"'{cluster.get('start_time')}'", query) + query = re.sub( + r"{{START_TIME}}", f"'{cluster.get('start_time')}'", query + ) query = re.sub(r"{{END_TIME}}", f"'{cluster.get('end_time')}'", query) # format unload query with actual query from sql/ - unload_query = f"unload ($${query}$$) to '{unload_location.get('url')}/analysis/{replay}/raw_data/" \ - f"{query_name}' iam_role '{iam_role}' CSV header allowoverwrite parallel off;" + unload_query = ( + f"unload ($${query}$$) to '{unload_location.get('url')}/analysis/{replay}/raw_data/" + f"{query_name}' iam_role '{iam_role}' CSV header allowoverwrite parallel off;" + ) try: cursor.execute(unload_query) # execute unload except Exception as e: - logger.error(f"Could not unload {query_name} results. Confirm IAM permissions include UNLOAD " - f"access for Redshift. {e}") + logger.error( + f"Could not unload {query_name} results. Confirm IAM permissions include UNLOAD " + f"access for Redshift. {e}" + ) exit(-1) logger.info(f"Query results available in {unload_location.get('url')}") @@ -260,19 +311,23 @@ def get_raw_data(report, bucket, replay_path, query): """ logger = logging.getLogger("SimpleReplayLogger") - s3_client = boto3.client('s3') + s3_client = boto3.client("s3") try: - response = s3_client.get_object(Bucket=bucket.get('bucket_name'), Key=f"{replay_path}/raw_data/{query}000") + response = s3_client.get_object( + Bucket=bucket.get("bucket_name"), Key=f"{replay_path}/raw_data/{query}000" + ) except Exception as e: - logger.error(f"Unable to get raw data from S3. Results for {query} not found. {e}") + logger.error( + f"Unable to get raw data from S3. Results for {query} not found. {e}" + ) df = pd.read_csv(response.get("Body")).fillna(0) logger.debug(f"Parsing results from '{query}' query.") - if query == 'latency_distribution': + if query == "latency_distribution": report.feature_graph = df else: for t, vals in report.tables.items(): - if vals.get('sql') == query: - vals['data'] = read_data(t, df, vals.get('columns'), report) + if vals.get("sql") == query: + vals["data"] = read_data(t, df, vals.get("columns"), report) def read_data(table_name, df, report_columns, report): @@ -291,35 +346,49 @@ def read_data(table_name, df, report_columns, report): logger.error("Data is empty. Failed to generate report.") exit(-1) cols = [g_columns[x] for x in report_columns] - table_type = report.tables.get(table_name).get('type') + table_type = report.tables.get(table_name).get("type") report_table = None - if table_type == 'breakdown': + if table_type == "breakdown": report_table = df[cols] - elif table_type == 'metric': - order = CategoricalDtype(['Query Latency', 'Compile Time', 'Queue Time', 'Execution Time', - 'Commit Queue Time', 'Commit Time'], ordered=True) - df[g_columns.get('Measure')] = df[g_columns.get('Measure')].astype(order) - frame = df.sort_values(g_columns.get('Measure')) + elif table_type == "metric": + order = CategoricalDtype( + [ + "Query Latency", + "Compile Time", + "Queue Time", + "Execution Time", + "Commit Queue Time", + "Commit Time", + ], + ordered=True, + ) + df[g_columns.get("Measure")] = df[g_columns.get("Measure")].astype(order) + frame = df.sort_values(g_columns.get("Measure")) report_table = frame[cols] - elif table_type == 'measure': # filter for specific measure type + elif table_type == "measure": # filter for specific measure type report_table = df[cols][df[g_columns.get("Measure")] == table_name] - report_table = pd.DataFrame(report_table).round(2) # round values in dataframe to thousandths place - report_table.reindex(columns=report_columns) # add columns names to dataframe + report_table = pd.DataFrame(report_table).round( + 2 + ) # round values in dataframe to thousandths place + report_table.reindex(columns=report_columns) # add columns names to dataframe # upload formatted dataframe to S3 as csv try: - s3_resource = boto3.resource('s3') + s3_resource = boto3.resource("s3") file = f"{table_name.replace(' ', '')}.csv" # set filename for saving csv_buffer = StringIO() report_table.to_csv(csv_buffer) logger.debug(report.bucket) - s3_resource.Object(report.bucket.get("bucket_name"), - f'{report.path}/aggregated_data/{file}').put(Body=csv_buffer.getvalue()) + s3_resource.Object( + report.bucket.get("bucket_name"), f"{report.path}/aggregated_data/{file}" + ).put(Body=csv_buffer.getvalue()) except Exception as e: - logger.error(f"Could not upload aggregated data. Please confirm bucket. Error occurred while processing " - f"data. {e}") + logger.error( + f"Could not upload aggregated data. Please confirm bucket. Error occurred while processing " + f"data. {e}" + ) exit(-1) return report_table @@ -334,14 +403,17 @@ def create_presigned_url(bucket_name, object_name): logger = logging.getLogger("SimpleReplayLogger") - s3_client = boto3.client('s3') + s3_client = boto3.client("s3") try: - response = s3_client.generate_presigned_url('get_object', - Params={'Bucket': bucket_name, - 'Key': object_name}, - ExpiresIn=604800) + response = s3_client.generate_presigned_url( + "get_object", + Params={"Bucket": bucket_name, "Key": object_name}, + ExpiresIn=604800, + ) except ClientError as e: - logger.error(f"Unable to generate presigned url for object {object_name} in bucket {bucket_name}. {e}") + logger.error( + f"Unable to generate presigned url for object {object_name} in bucket {bucket_name}. {e}" + ) return None return response @@ -358,10 +430,14 @@ def analysis_summary(bucket_url, replay): bucket = bucket_dict(bucket_url) logger.info(f"Simple Replay Workload Analysis: {replay}") - replay_path = f'analysis/{replay}/out/' - output_str = f"\nBelow is the presigned URLs for the analysis performed for replay: {replay}. " \ - f"Click or copy/paste the link into your browser to download." - r_url = create_presigned_url(bucket.get('bucket_name'), f'{replay_path}{replay}_report.pdf') + replay_path = f"analysis/{replay}/out/" + output_str = ( + f"\nBelow is the presigned URLs for the analysis performed for replay: {replay}. " + f"Click or copy/paste the link into your browser to download." + ) + r_url = create_presigned_url( + bucket.get("bucket_name"), f"{replay_path}{replay}_report.pdf" + ) output_str += f"\n\nReplay Analysis Report | Click to Download:\n{r_url}\n" logger.info(output_str) @@ -377,39 +453,60 @@ def list_replays(bucket_url): table = [] bucket = bucket_dict(bucket_url) try: - resp = client("s3").list_objects_v2(Bucket=bucket.get('bucket_name'), Delimiter='/', Prefix='analysis/') - if resp['KeyCount'] == 0: - logger.error(f"No replays available in S3. Please run a replay with replay analysis to access replays " - f"from the command line.") + resp = client("s3").list_objects_v2( + Bucket=bucket.get("bucket_name"), Delimiter="/", Prefix="analysis/" + ) + if resp["KeyCount"] == 0: + logger.error( + f"No replays available in S3. Please run a replay with replay analysis to access replays " + f"from the command line." + ) exit(-1) except Exception as e: logger.error(f"Unable to access replays in S3. Please confirm bucket. {e}") exit(-1) - s3 = boto3.resource('s3') - print(f"Listed below are all the replay reports located in the S3 bucket: {bucket_url}.\n") + s3 = boto3.resource("s3") + print( + f"Listed below are all the replay reports located in the S3 bucket: {bucket_url}.\n" + ) - for x in resp['CommonPrefixes']: + for x in resp["CommonPrefixes"]: try: - s3.Object(bucket.get('bucket_name'), f'{x.get("Prefix")}out/info.json').load() + s3.Object( + bucket.get("bucket_name"), f'{x.get("Prefix")}out/info.json' + ).load() except ClientError as e: - if e.response['Error']['Code'] == "404": # if info.json does not exist in folder, do not add to list + if ( + e.response["Error"]["Code"] == "404" + ): # if info.json does not exist in folder, do not add to list continue else: logger.error(f"Unable to access replay. {e}") - content_object = s3.Object(bucket.get('bucket_name'), f'{x.get("Prefix")}out/info.json') - file_content = content_object.get()['Body'].read().decode('utf-8') + content_object = s3.Object( + bucket.get("bucket_name"), f'{x.get("Prefix")}out/info.json' + ) + file_content = content_object.get()["Body"].read().decode("utf-8") json_content = json.loads(file_content) - table.append([json_content['replay_id'], - json_content['id'], - json_content['start_time'], - json_content['end_time'], - json_content['replay_tag']]) + table.append( + [ + json_content["replay_id"], + json_content["id"], + json_content["start_time"], + json_content["end_time"], + json_content["replay_tag"], + ] + ) # use tabulate lib to format output - print(tabulate(table, headers=["Replay", "Cluster ID", "Start Time", "End Time", "Replay Tag"])) + print( + tabulate( + table, + headers=["Replay", "Cluster ID", "Start Time", "End Time", "Replay Tag"], + ) + ) def list_sql(bucket_url, replay): @@ -422,19 +519,23 @@ def list_sql(bucket_url, replay): logger = logging.getLogger("SimpleReplayLogger") bucket = bucket_dict(bucket_url) try: - resp = client("s3").list_objects_v2(Bucket=bucket.get('bucket_name'), - Delimiter='/', - Prefix=f'analysis/{replay}/raw_data/') + resp = client("s3").list_objects_v2( + Bucket=bucket.get("bucket_name"), + Delimiter="/", + Prefix=f"analysis/{replay}/raw_data/", + ) except Exception as e: logger.error(f"Unable to access raw data in S3. Please confirm bucket. {e}") exit(-1) - output_str = f"Below are presigned URLs for the raw data for replay id: {replay}. " \ - f"Click or copy/paste the link into your browser to download." - for x in resp['Contents']: + output_str = ( + f"Below are presigned URLs for the raw data for replay id: {replay}. " + f"Click or copy/paste the link into your browser to download." + ) + for x in resp["Contents"]: try: - prefix = x.get('Key') - d_url = create_presigned_url(bucket.get('bucket_name'), x.get('Key')) - query_result = prefix.split('/')[-1] + prefix = x.get("Key") + d_url = create_presigned_url(bucket.get("bucket_name"), x.get("Key")) + query_result = prefix.split("/")[-1] output_str += f"\nQuery Results: {query_result}\n{d_url}" except Exception as e: logger.error(f"Unable to access raw data in S3. Please confirm bucket. {e}") @@ -447,14 +548,24 @@ def main(): parser = argparse.ArgumentParser( description="This script analyzes a Redshift cluster and outputs a summary report with statistics" - "its performance." + "its performance." ) - parser.add_argument('-b', '--bucket', nargs=1, type=str, help='location of replay outputs') - parser.add_argument('-r1', '--replay_id1', nargs='?', type=str, default='', help='replay id 1') - parser.add_argument('-r2', '--replay_id2', nargs='?', type=str, default='', help='replay id 2, required for ' - 'comparison') - parser.add_argument('-s', '--sql', action='store_true', help='sql') + parser.add_argument( + "-b", "--bucket", nargs=1, type=str, help="location of replay outputs" + ) + parser.add_argument( + "-r1", "--replay_id1", nargs="?", type=str, default="", help="replay id 1" + ) + parser.add_argument( + "-r2", + "--replay_id2", + nargs="?", + type=str, + default="", + help="replay id 2, required for " "comparison", + ) + parser.add_argument("-s", "--sql", action="store_true", help="sql") args = parser.parse_args() @@ -469,7 +580,9 @@ def main(): analysis_summary(args.bucket[0], args.replay_id1) elif args.bucket and args.replay_id1 and args.replay_id2: if args.replay_id1 == args.replay_id2: - logger.error("Cannot compare same replay, please choose two distinct replay ids.") + logger.error( + "Cannot compare same replay, please choose two distinct replay ids." + ) exit(-1) else: print(f"Compare replays {args.replay_id1} and {args.replay_id2}.") @@ -479,5 +592,5 @@ def main(): exit(-1) -if __name__ == '__main__': +if __name__ == "__main__": main() diff --git a/src/SimpleReplay/requirements.txt b/src/SimpleReplay/requirements.txt index 767187cf..191082f1 100644 --- a/src/SimpleReplay/requirements.txt +++ b/src/SimpleReplay/requirements.txt @@ -1,5 +1,5 @@ -boto3==1.24.24 -botocore==1.27.24 +boto3>=1.26.118 +botocore>=1.29.118 Flask==2.1.2 matplotlib==3.5.2 moto==3.1.16 diff --git a/src/SimpleReplay/util.py b/src/SimpleReplay/util.py index 015deb63..677a5008 100644 --- a/src/SimpleReplay/util.py +++ b/src/SimpleReplay/util.py @@ -19,8 +19,9 @@ LOG_DATE_FORMAT = "%Y-%m-%d %H:%M:%S" + def init_logging(level=logging.INFO): - """ Initialize logging to stdio """ + """Initialize logging to stdio""" logger = logging.getLogger("SimpleReplayLogger") logger.setLevel(logging.DEBUG) logging.Formatter.converter = time.gmtime @@ -32,15 +33,17 @@ def init_logging(level=logging.INFO): def set_log_level(level): - """ Change the log level for the default (stdio) logger. Logfile always logs DEBUG. """ + """Change the log level for the default (stdio) logger. Logfile always logs DEBUG.""" logger = logging.getLogger("SimpleReplayLogger") for handler in logger.handlers: if type(handler) == logging.StreamHandler: handler.setLevel(level) -def add_logfile(filename, dir="simplereplay_logs", level=logging.DEBUG, backup_count=2, preamble=''): - """ Additionally log to a logfile """ +def add_logfile( + filename, dir="simplereplay_logs", level=logging.DEBUG, backup_count=2, preamble="" +): + """Additionally log to a logfile""" os.makedirs(dir, exist_ok=True) filename = f"{dir}/{filename}" file_exists = os.path.isfile(filename) @@ -53,7 +56,7 @@ def add_logfile(filename, dir="simplereplay_logs", level=logging.DEBUG, backup_c # dump the preamble to the file first if preamble: with open(filename, "w") as fp: - fp.write(preamble.rstrip() + '\n\n' + '-' * 40 + "\n") + fp.write(preamble.rstrip() + "\n\n" + "-" * 40 + "\n") fh.setLevel(level) fh.setFormatter(get_log_formatter()) @@ -64,7 +67,7 @@ def add_logfile(filename, dir="simplereplay_logs", level=logging.DEBUG, backup_c def get_log_formatter(process_idx=None, job_id=None): - """ Define the log format, with the option to prepend process and job/thread to each message """ + """Define the log format, with the option to prepend process and job/thread to each message""" format = "[%(levelname)s] %(asctime)s" if process_idx is not None: format += f" [{process_idx}]" @@ -77,14 +80,14 @@ def get_log_formatter(process_idx=None, job_id=None): def prepend_ids_to_logs(process_idx=None, job_id=None): - """ Update logging to prepend process_id and / or job_id to all emitted logs """ + """Update logging to prepend process_id and / or job_id to all emitted logs""" logger = logging.getLogger("SimpleReplayLogger") for handler in logger.handlers: handler.setFormatter(get_log_formatter(process_idx, job_id)) def log_version(): - """ Read the VERSION file and log it """ + """Read the VERSION file and log it""" logger = logging.getLogger("SimpleReplayLogger") try: with open("VERSION", "r") as fp: @@ -93,19 +96,27 @@ def log_version(): logger.warning(f"Version unknown") -def db_connect(interface="psql", - host=None, port=5439, username=None, password=None, database=None, - odbc_driver=None, - drop_return=False): - """ Connect to the database using the method specified by interface (either psql or odbc) - :param drop_return: if True, don't store returned value. +def db_connect( + interface="psql", + host=None, + port=5439, + username=None, + password=None, + database=None, + odbc_driver=None, + drop_return=False, +): + """Connect to the database using the method specified by interface (either psql or odbc) + :param drop_return: if True, don't store returned value. """ if interface == "psql": - conn = redshift_connector.connect(user=username, password=password, host=host, - port=port, database=database) + conn = redshift_connector.connect( + user=username, password=password, host=host, port=port, database=database + ) # if drop_return is set, monkey patch driver to not store result set in memory if drop_return: + def drop_data(self, data) -> None: pass @@ -114,6 +125,7 @@ def drop_data(self, data) -> None: elif interface == "odbc": import pyodbc + if drop_return: raise Exception("drop_return not supported for odbc") @@ -128,34 +140,37 @@ def drop_data(self, data) -> None: def retrieve_compressed_json(location): - """ Load a gzipped json file from the specified location, either local or s3 """ + """Load a gzipped json file from the specified location, either local or s3""" sql_gz = load_file(location) - json_content = gzip.GzipFile(fileobj=io.BytesIO(sql_gz), mode='rb').read().decode('utf-8') + json_content = ( + gzip.GzipFile(fileobj=io.BytesIO(sql_gz), mode="rb").read().decode("utf-8") + ) return json.loads(json_content) def load_file(location, decode=False): - """ load a file from s3 or local. decode if the file should be interpreted as text rather than binary """ + """load a file from s3 or local. decode if the file should be interpreted as text rather than binary""" try: if location.startswith("s3://"): url = urlparse(location, allow_fragments=False) - s3 = boto3.resource('s3') - content = s3.Object(url.netloc, url.path.lstrip('/')).get()["Body"].read() + s3 = boto3.resource("s3") + content = s3.Object(url.netloc, url.path.lstrip("/")).get()["Body"].read() else: - with open(location, 'rb') as data: + with open(location, "rb") as data: content = data.read() if decode: - content = content.decode('utf-8') + content = content.decode("utf-8") except Exception as e: logger.error( - f"Unable to load file from {location}. Does the file exist and do you have correct permissions? {str(e)}") + f"Unable to load file from {location}. Does the file exist and do you have correct permissions? {str(e)}" + ) raise (e) return content def load_config(location): - """ Load a yaml config file from a local file or from s3 """ + """Load a yaml config file from a local file or from s3""" logger.info(f"Loading config file from {location}") config = load_file(location, decode=True) @@ -168,8 +183,19 @@ def load_config(location): return config_yaml +def redshift_get_serverless_workgroup(workgroup_name, region): + rs_client = boto3.client("redshift-serverless", region_name=region) + return rs_client.get_workgroup(workgroupName=workgroup_name) + + +def redshift_describe_clusters(cluster_id, region): + rs_client = boto3.client("redshift", region_name=region) + response = rs_client.describe_clusters(ClusterIdentifier=cluster_id) + return response + + def cluster_dict(endpoint, is_serverless=False, start_time=None, end_time=None): - '''Create a object-like dictionary from cluster endpoint''' + """Create a object-like dictionary from cluster endpoint""" parsed = urlparse(endpoint) url_split = parsed.scheme.split(".") port_database = parsed.path.split("/") @@ -184,7 +210,7 @@ def cluster_dict(endpoint, is_serverless=False, start_time=None, end_time=None): "region": url_split[2], "port": port_database[0], "database": port_database[1], - "is_serverless": is_serverless + "is_serverless": is_serverless, } if start_time is not None: @@ -192,38 +218,47 @@ def cluster_dict(endpoint, is_serverless=False, start_time=None, end_time=None): if end_time is not None: cluster["end_time"] = end_time - logger = logging.getLogger("SimpleReplayLogger") - - if not is_serverless: - rs_client = boto3.client('redshift', region_name=cluster.get("region")) - try: - response = rs_client.describe_clusters(ClusterIdentifier=cluster.get('id')) - - cluster["num_nodes"] = (response['Clusters'][0]['NumberOfNodes']) - cluster["instance"] = (response['Clusters'][0]['NodeType']) - except Exception as e: - logger.warning(f"Unable to get cluster information. Please ensure IAM permissions include " - f"Redshift:DescribeClusters. {e}") - cluster["num_nodes"] = "N/A" - cluster["instance"] = "N/A" - else: - rs_client = boto3.client('redshift-serverless', region_name=cluster.get("region")) + if is_serverless: try: - response = rs_client.get_workgroup(workgroupName=workgroup_name) + response = redshift_get_serverless_workgroup( + workgroup_name, cluster.get("region") + ) cluster["num_nodes"] = "N/A" cluster["instance"] = "Serverless" - cluster["base_rpu"] = response['workgroup']['baseCapacity'] + cluster["base_rpu"] = response["workgroup"]["baseCapacity"] except Exception as e: - if e.response['Error']['Code'] == 'ResourceNotFoundException': - logger.warning(f"Serverless endpoint could not be found " - f"RedshiftServerless:GetWorkGroup. {e}") + if e.response["Error"]["Code"] == "ResourceNotFoundException": + logger.warning( + f"Serverless endpoint could not be found " + f"RedshiftServerless:GetWorkGroup. {e}" + ) + raise e else: - logger.warning(f"Exception during fetching work group details for Serverless endpoint " - f"RedshiftServerless:GetWorkGroup. {e}") + import traceback + print(traceback.format_exc()) + logger.warning( + f"Exception during fetching work group details for Serverless endpoint " + f"RedshiftServerless:GetWorkGroup. {e}" + ) cluster["num_nodes"] = "N/A" cluster["instance"] = "Serverless" cluster["base_rpu"] = "N/A" + else: + try: + response = redshift_describe_clusters( + cluster.get("id"), cluster.get("region") + ) + + cluster["num_nodes"] = response["Clusters"][0]["NumberOfNodes"] + cluster["instance"] = response["Clusters"][0]["NodeType"] + except Exception as e: + logger.warning( + f"Unable to get cluster information. Please ensure IAM permissions include " + f"Redshift:DescribeClusters. {e}" + ) + cluster["num_nodes"] = "N/A" + cluster["instance"] = "N/A" return cluster @@ -235,116 +270,112 @@ def bucket_dict(bucket_url): parsed = urlparse(bucket_url) bucket, path = parsed.netloc, parsed.path except ValueError as e: - logger.error(f'{e}\nPlease enter a valid S3 url following one of the following style conventions: ' - f'S3://bucket-name/key-name') + logger.error( + f"{e}\nPlease enter a valid S3 url following one of the following style conventions: " + f"S3://bucket-name/key-name" + ) exit(-1) - if path.startswith('/'): + if path.startswith("/"): path = path[1:] - if not path == '' and not path.endswith('/'): + if not path == "" and not path.endswith("/"): path = f"{path}/" - if path == 'replays/': - path = '' - return {'url': bucket_url, - 'bucket_name': bucket, - 'prefix': path} + if path == "replays/": + path = "" + return {"url": bucket_url, "bucket_name": bucket, "prefix": path} def get_secret(secret_name, region_name): # Create a Secrets Manager client session = boto3.session.Session() - client = session.client( - service_name='secretsmanager', - region_name=region_name - ) + client = session.client(service_name="secretsmanager", region_name=region_name) get_secret_value_response = None try: - get_secret_value_response = client.get_secret_value( - SecretId=secret_name - ) + get_secret_value_response = client.get_secret_value(SecretId=secret_name) # secret_string = json.loads(get_secret_value_response['SecretString']) except ClientError as e: - if e.response['Error']['Code'] == 'DecryptionFailureException': + if e.response["Error"]["Code"] == "DecryptionFailureException": # Secrets Manager can't decrypt the protected secret text using the provided KMS key. # Deal with the exception here, and/or rethrow at your discretion. raise e - elif e.response['Error']['Code'] == 'InternalServiceErrorException': + elif e.response["Error"]["Code"] == "InternalServiceErrorException": # An error occurred on the server side. # Deal with the exception here, and/or rethrow at your discretion. raise e - elif e.response['Error']['Code'] == 'InvalidParameterException': + elif e.response["Error"]["Code"] == "InvalidParameterException": # You provided an invalid value for a parameter. # Deal with the exception here, and/or rethrow at your discretion. raise e - elif e.response['Error']['Code'] == 'InvalidRequestException': + elif e.response["Error"]["Code"] == "InvalidRequestException": # You provided a parameter value that is not valid for the current state of the resource. # Deal with the exception here, and/or rethrow at your discretion. raise e - elif e.response['Error']['Code'] == 'ResourceNotFoundException': + elif e.response["Error"]["Code"] == "ResourceNotFoundException": # We can't find the resource that you asked for. # Deal with the exception here, and/or rethrow at your discretion. raise e - elif e.response['Error']['Code'] == 'AccessDeniedException': + elif e.response["Error"]["Code"] == "AccessDeniedException": # Use is not authorized to perform secretsmanager:GetSecretValue on requested resource raise e # Decrypts secret using the associated KMS key. # Depending on whether the secret is a string or binary, one of these fields will be populated. - if 'SecretString' in get_secret_value_response: - secret = json.loads(get_secret_value_response['SecretString']) + if "SecretString" in get_secret_value_response: + secret = json.loads(get_secret_value_response["SecretString"]) else: - secret = json.loads(base64.b64decode(get_secret_value_response['SecretBinary'])) + secret = json.loads(base64.b64decode(get_secret_value_response["SecretBinary"])) return secret def categorize_error(err_code): # https://www.postgresql.org/docs/current/errcodes-appendix.html - err_class = {'00': 'Successful Completion', - '01': 'Warning', - '02': 'No Data', - '03': 'SQL Statement Not Yet Complete', - '08': 'Connection Exception', - '09': 'Triggered Action Exception', - '0A': 'Feature Not Supported', - '0B': 'Invalid Transaction Initiation', - '0F': 'Locator Exception', - '0L': 'Invalid Grantor', - '0P': 'Invalid Role Specification', - '0Z': 'Diagnostics Exception', - '20': 'Case Not Found', - '21': 'Cardinality Violation', - '22': 'Data Exception', - '23': 'Integrity Constraint Violation', - '24': 'Invalid Cursor State', - '25': 'Invalid Transaction State', - '26': 'Invalid SQL Statement Name', - '27': 'Triggered Data Change Violation', - '28': 'Invalid Authorization Specification', - '2B': 'Dependent Privilege Descriptors Still Exist', - '2D': 'Invalid Transaction Termination', - '2F': 'SQL Routine Exception', - '34': 'Invalid Cursor Name', - '38': 'External Routine Exception', - '39': 'External Routine Invocation Exception', - '3B': 'Savepoint Exception', - '3D': 'Invalid Catalog Name', - '3F': 'Invalid Schema Name', - '40': 'Transaction Rollback', - '42': 'Syntax Error or Access Rule Violation', - '44': 'WITH CHECK OPTION Violation', - '53': 'Insufficient Resources', - '54': 'Program Limit Exceeded', - '55': 'Object Not In Prerequisite State', - '57': 'Operator Intervention', - '58': 'System Error', - '72': 'Snapshot Failure', - 'F0': 'Configuration File Error', - 'HV': 'Foreign Data Wrapper Error (SQL/MED)', - 'P0': 'PL/pgSQL Error', - 'XX': 'Internal Error', - } + err_class = { + "00": "Successful Completion", + "01": "Warning", + "02": "No Data", + "03": "SQL Statement Not Yet Complete", + "08": "Connection Exception", + "09": "Triggered Action Exception", + "0A": "Feature Not Supported", + "0B": "Invalid Transaction Initiation", + "0F": "Locator Exception", + "0L": "Invalid Grantor", + "0P": "Invalid Role Specification", + "0Z": "Diagnostics Exception", + "20": "Case Not Found", + "21": "Cardinality Violation", + "22": "Data Exception", + "23": "Integrity Constraint Violation", + "24": "Invalid Cursor State", + "25": "Invalid Transaction State", + "26": "Invalid SQL Statement Name", + "27": "Triggered Data Change Violation", + "28": "Invalid Authorization Specification", + "2B": "Dependent Privilege Descriptors Still Exist", + "2D": "Invalid Transaction Termination", + "2F": "SQL Routine Exception", + "34": "Invalid Cursor Name", + "38": "External Routine Exception", + "39": "External Routine Invocation Exception", + "3B": "Savepoint Exception", + "3D": "Invalid Catalog Name", + "3F": "Invalid Schema Name", + "40": "Transaction Rollback", + "42": "Syntax Error or Access Rule Violation", + "44": "WITH CHECK OPTION Violation", + "53": "Insufficient Resources", + "54": "Program Limit Exceeded", + "55": "Object Not In Prerequisite State", + "57": "Operator Intervention", + "58": "System Error", + "72": "Snapshot Failure", + "F0": "Configuration File Error", + "HV": "Foreign Data Wrapper Error (SQL/MED)", + "P0": "PL/pgSQL Error", + "XX": "Internal Error", + } if err_code[0:2] in err_class.keys(): return err_class[err_code[0:2]] @@ -355,70 +386,82 @@ def remove_comments(string): pattern = r"(\".*?\"|\'.*?\')|(/\*.*?\*/|//[^\r\n]*$)" # first group captures quoted strings (double or single) # second group captures comments (//single-line or /* multi-line */) - regex = re.compile(pattern, re.MULTILINE|re.DOTALL) + regex = re.compile(pattern, re.MULTILINE | re.DOTALL) + def _replacer(match): # if the 2nd group (capturing comments) is not None, # it means we have captured a non-quoted (real) comment string. if match.group(2) is not None: - return "" # so we will return empty to remove the comment - else: # otherwise, we will return the 1st group - return match.group(1) # captured quoted-string + return "" # so we will return empty to remove the comment + else: # otherwise, we will return the 1st group + return match.group(1) # captured quoted-string + return regex.sub(_replacer, string) def parse_error(error, user, db, qtxt): - err_entry = {'timestamp': datetime.datetime.now(tz=datetime.timezone.utc).isoformat(timespec='seconds'), - 'user': user, - 'db': db, - 'query_text': remove_comments(qtxt) - } - - temp = error.__str__().replace("\"", r"\"") - raw_error_string = json.loads(temp.replace("\'", "\"")) - err_entry['detail'] = "" - - if 'D' in raw_error_string: - detail_string = raw_error_string['D'] + err_entry = { + "timestamp": datetime.datetime.now(tz=datetime.timezone.utc).isoformat( + timespec="seconds" + ), + "user": user, + "db": db, + "query_text": remove_comments(qtxt), + } + + temp = error.__str__().replace('"', r"\"") + raw_error_string = json.loads(temp.replace("'", '"')) + err_entry["detail"] = "" + + if "D" in raw_error_string: + detail_string = raw_error_string["D"] try: - detail = detail_string[detail_string.find("context:"):detail_string.find("query")].split(":", maxsplit=1)[-1].strip() - err_entry['detail'] = detail + detail = ( + detail_string[ + detail_string.find("context:") : detail_string.find("query") + ] + .split(":", maxsplit=1)[-1] + .strip() + ) + err_entry["detail"] = detail except Exception as e: print(e) - err_entry['detail'] = "" + err_entry["detail"] = "" - err_entry['code'] = raw_error_string['C'] - err_entry['message'] = raw_error_string['M'] - err_entry['severity'] = raw_error_string['S'] - err_entry['category'] = categorize_error(err_entry['code']) + err_entry["code"] = raw_error_string["C"] + err_entry["message"] = raw_error_string["M"] + err_entry["severity"] = raw_error_string["S"] + err_entry["category"] = categorize_error(err_entry["code"]) return err_entry def create_json(replay, cluster, workload, complete, stats, tag=""): - """Generates a JSON containing cluster details for the replay - """ + """Generates a JSON containing cluster details for the replay""" - if cluster['start_time'] and cluster['end_time']: - duration = cluster['end_time'] - cluster['start_time'] + if cluster["start_time"] and cluster["end_time"]: + duration = cluster["end_time"] - cluster["start_time"] duration = duration - datetime.timedelta(microseconds=duration.microseconds) - cluster['start_time'] = str(cluster['start_time'].isoformat(timespec='seconds')) - cluster['end_time'] = str(cluster['end_time'].isoformat(timespec='seconds')) - cluster['duration'] = str(duration) + cluster["start_time"] = str(cluster["start_time"].isoformat(timespec="seconds")) + cluster["end_time"] = str(cluster["end_time"].isoformat(timespec="seconds")) + cluster["duration"] = str(duration) if complete: - cluster['status'] = "Complete" + cluster["status"] = "Complete" else: - cluster['status'] = "Incomplete" + cluster["status"] = "Incomplete" - cluster['replay_id'] = replay - cluster['replay_tag'] = tag - cluster['workload'] = workload + cluster["replay_id"] = replay + cluster["replay_tag"] = tag + cluster["workload"] = workload for k, v in enumerate(stats): cluster[v] = stats[v] - cluster["connection_success"] = cluster['connection_count'] - cluster['connection_errors'] + cluster["connection_success"] = ( + cluster["connection_count"] - cluster["connection_errors"] + ) json_object = json.dumps(cluster, indent=4) with open(f"info.json", "w") as outfile: @@ -426,3 +469,24 @@ def create_json(replay, cluster, workload, complete, stats, tag=""): return outfile.name +def redshift_get_cluster_credentials( + region, user, database_name, cluster_id, duration=900, auto_create=False +): + rs_client = boto3.client("redshift", region) + try: + response = rs_client.get_cluster_credentials( + DbUser=user, + DbName=database_name, + ClusterIdentifier=cluster_id, + DurationSeconds=duration, + AutoCreate=auto_create, + ) + except Exception as e: + if e == rs_client.exceptions.ClusterNotFoundFault: + logger.error( + f"Cluster {cluster_id} not found. Please confirm cluster endpoint, account, and region." + ) + else: + logger.error(f"Error while getting cluster credentials: {e}", exc_info=True) + exit(-1) + return response From 18afa6ac4eb685d68dae316e7373a9b05293702f Mon Sep 17 00:00:00 2001 From: karle-nishi <123670211+karle-nishi@users.noreply.github.com> Date: Mon, 24 Apr 2023 18:01:00 -0700 Subject: [PATCH 13/49] Fix to support 4 or 5 digit port (#682) --- src/SimpleReplay/replay.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/SimpleReplay/replay.py b/src/SimpleReplay/replay.py index a569f613..12410b56 100644 --- a/src/SimpleReplay/replay.py +++ b/src/SimpleReplay/replay.py @@ -54,8 +54,8 @@ g_replay_timestamp = None g_is_serverless = False -g_serverless_cluster_endpoint_pattern = r"(.+)\.(.+)\.(.+).redshift-serverless(-dev)?\.amazonaws\.com:[0-9]{4}\/(.)+" -g_cluster_endpoint_pattern = r"(.+)\.(.+)\.(.+).redshift(-serverless)?\.amazonaws\.com:[0-9]{4}\/(.)+" +g_serverless_cluster_endpoint_pattern = r"(.+)\.(.+)\.(.+).redshift-serverless(-dev)?\.amazonaws\.com:[0-9]{4,5}\/(.)+" +g_cluster_endpoint_pattern = r"(.+)\.(.+)\.(.+).redshift(-serverless)?\.amazonaws\.com:[0-9]{4,5}\/(.)+" class ConnectionLog: def __init__( From a4b62bb4105ec61373d5407be3e2fc4eb6d844aa Mon Sep 17 00:00:00 2001 From: karle-nishi <123670211+karle-nishi@users.noreply.github.com> Date: Tue, 25 Apr 2023 14:06:29 -0700 Subject: [PATCH 14/49] Update replay_analysis.py --- src/SimpleReplay/replay_analysis.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/SimpleReplay/replay_analysis.py b/src/SimpleReplay/replay_analysis.py index a7d64643..85790412 100644 --- a/src/SimpleReplay/replay_analysis.py +++ b/src/SimpleReplay/replay_analysis.py @@ -159,6 +159,7 @@ def run_comparison_analysis(bucket, replay1, replay2): # print summary +@contextmanager def initiate_connection(username, cluster): """Initiate connection with Redshift cluster From 8ff5d2b260e0713163a4f5b81a0d7ebc5dfe090f Mon Sep 17 00:00:00 2001 From: sathiish-kumar <118481523+sathiish-kumar@users.noreply.github.com> Date: Mon, 8 May 2023 10:21:50 -0700 Subject: [PATCH 15/49] Update reportlab version to prevent errors with pycairo --- src/SimpleReplay/requirements.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/SimpleReplay/requirements.txt b/src/SimpleReplay/requirements.txt index 191082f1..9ad285d9 100644 --- a/src/SimpleReplay/requirements.txt +++ b/src/SimpleReplay/requirements.txt @@ -8,9 +8,9 @@ pandas==1.3.5 python-dateutil==2.8.1 PyYAML==6.0 redshift-connector -reportlab +reportlab=3.6.13 sqlparse==0.4.2 tabulate==0.8.10 tqdm==4.59.0 maya -coverage \ No newline at end of file +coverage From ca79aea55acf9d3ac90346b6f5737f4445c3fe7e Mon Sep 17 00:00:00 2001 From: sathiish-kumar <118481523+sathiish-kumar@users.noreply.github.com> Date: Mon, 8 May 2023 11:18:23 -0700 Subject: [PATCH 16/49] Fix typo in requirements.txt --- src/SimpleReplay/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SimpleReplay/requirements.txt b/src/SimpleReplay/requirements.txt index 9ad285d9..4219ef22 100644 --- a/src/SimpleReplay/requirements.txt +++ b/src/SimpleReplay/requirements.txt @@ -8,7 +8,7 @@ pandas==1.3.5 python-dateutil==2.8.1 PyYAML==6.0 redshift-connector -reportlab=3.6.13 +reportlab==3.6.13 sqlparse==0.4.2 tabulate==0.8.10 tqdm==4.59.0 From 864edbc2c49151cfcae96535b15abc747ca49a0d Mon Sep 17 00:00:00 2001 From: karlnish Date: Mon, 8 May 2023 15:32:29 -0700 Subject: [PATCH 17/49] Added query tags depending upon Simple Replay or Node Config --- src/SimpleReplay/replay.py | 30 ++++++++++++++++++++++-------- src/SimpleReplay/replay.yaml | 34 ++++++++++++++++++---------------- 2 files changed, 40 insertions(+), 24 deletions(-) diff --git a/src/SimpleReplay/replay.py b/src/SimpleReplay/replay.py index 35e0f6f1..cc285c78 100644 --- a/src/SimpleReplay/replay.py +++ b/src/SimpleReplay/replay.py @@ -68,8 +68,12 @@ g_is_serverless = False -g_serverless_cluster_endpoint_pattern = r"(.+)\.(.+)\.(.+).redshift-serverless(-dev)?\.amazonaws\.com:[0-9]{4,5}\/(.)+" -g_cluster_endpoint_pattern = r"(.+)\.(.+)\.(.+).redshift(-serverless)?\.amazonaws\.com:[0-9]{4,5}\/(.)+" +g_serverless_cluster_endpoint_pattern = ( + r"(.+)\.(.+)\.(.+).redshift-serverless(-dev)?\.amazonaws\.com:[0-9]{4,5}\/(.)+" +) +g_cluster_endpoint_pattern = ( + r"(.+)\.(.+)\.(.+).redshift(-serverless)?\.amazonaws\.com:[0-9]{4,5}\/(.)+" +) class ConnectionLog: @@ -393,11 +397,21 @@ def save_query_stats(self, starttime, endtime, xid, query_idx): ) def get_tagged_sql(self, query_text, idx, transaction, connection): - json_tags = { - "xid": transaction.xid, - "query_idx": idx, - "replay_start": g_replay_timestamp.isoformat(), - } + if g_config["source_tag"]: + json_tags = { + "xid": transaction.xid, + "query_idx": idx, + "replay_start": g_replay_timestamp.isoformat(), + "source": g_config.get(["source_tag"]), + } + else: + json_tags = { + "xid": transaction.xid, + "query_idx": idx, + "replay_start": g_replay_timestamp.isoformat(), + "source": "SimpleReplay", + } + return "/* {} */ {}".format(json.dumps(json_tags), query_text) def execute_transaction(self, transaction, connection): @@ -2262,7 +2276,7 @@ def init_manager(): logger.info( f"Replay finished in {datetime.datetime.now(tz=datetime.timezone.utc) - g_replay_timestamp}." ) - + if g_config.get("analysis_iam_role") and g_config.get("analysis_output"): try: run_replay_analysis( diff --git a/src/SimpleReplay/replay.yaml b/src/SimpleReplay/replay.yaml index a5405442..c27e3ff9 100644 --- a/src/SimpleReplay/replay.yaml +++ b/src/SimpleReplay/replay.yaml @@ -1,14 +1,16 @@ # Optional - Custom identifier for this replay run tag: "" +# Optional - Identifier for queries executed +source_tag: "" + # Directory location of extracted workload, relative to current directory -workload_location: "" +workload_location: "test-location/Edited_10_Extraction_devsaba-sr-test_2023-01-23T09:46:24.784062+00:00" # Endpoint and username of target cluster to replay queries on -target_cluster_endpoint: "host:port/database" -target_cluster_region: "" -master_username: "" - +target_cluster_endpoint: "replay-dev.254137219717.us-east-1.redshift-serverless.amazonaws.com:5439/dev" +target_cluster_region: "us-east-1" +master_username: "awsuser" # NLB or NAT endpoint for Simple Replay to connect to. This NLB or NAT should have connectivity to target_cluster_endpoint nlb_nat_dns: "" @@ -22,37 +24,37 @@ default_interface: "psql" # Optional - Leaving it empty defers to connections.json. "all on" preserves # time between transactions. "all off" disregards time between transactions, # executing them as a batch. -time_interval_between_transactions: "all on" +time_interval_between_transactions: "" # Optional - Leaving it empty defers to connections.json. "all on" preserves # time between queries. "all off" disregards time between queries, executing # them as a batch. -time_interval_between_queries: "all on" +time_interval_between_queries: "" # Should COPY statements be executed? execute_copy_statements: "false" # Should UNLOAD statements be executed? -execute_unload_statements: "false" +execute_unload_statements: "true" # Optional - Where the UNLOADs and system table unload goes. -replay_output: "" +replay_output: "s3://simplereplay-v2.2.5-testing/test-drive-testing/provisioned/replay" # Optional - Where the analysis data and summary report will be uploaded. Example: s3://bucket_name/path -analysis_output: "" +analysis_output: "s3://simplereplay-v2.2.5-testing/test-drive-testing/provisioned" # Optional - Leaving this blank means UNLOADs will not be replayed. IAM role for UNLOADs to be performed with. -unload_iam_role: "" +unload_iam_role: "arn:aws:iam::254137219717:role/RedshiftFullAccess" # Optional - Leaving this blank means analysis will not be run. IAM role for analysis needs UNLOAD access. -analysis_iam_role: "" +analysis_iam_role: "arn:aws:iam::254137219717:role/RedshiftFullAccess" # Location of the SQL file containing queries to unload system tables unload_system_table_queries: "unload_system_tables.sql" # IAM role to UNLOAD system tables from source cluster to S3 location for later # analysis -target_cluster_system_table_unload_iam_role: "" +target_cluster_system_table_unload_iam_role: "arn:aws:iam::254137219717:role/RedshiftFullAccess" # Include filters will work as "db AND user AND pid". Exclude filters will work as "db OR user OR pid". # In case of multiple values for any specific filter, please enclose each in single quotes @@ -71,7 +73,7 @@ filters: ## # Set the amount of logging -log_level: "info" +log_level: "INFO" # number of proceses to use to parallelize the work. If omitted or null, uses # one process per cpu - 1 @@ -81,7 +83,7 @@ num_workers: ~ # their expected time. connection_tolerance_sec: 300 -# Number of simplereplay logfiles to maintain +# Number of TestDrive logfiles to maintain backup_count: 1 # Should we discard the returned data @@ -95,4 +97,4 @@ split_multi: true # In case of Serverless, set up a secret to store admin username and password. Specify the name of the secret below # Note: This admin username maps to the username specified as `master_username` in this file. This will be updated to `admin_username` in a future release. -secret_name: "" \ No newline at end of file +secret_name: "" From 8dbdf5ad83806ef56d55e1e717b8acef78bde917 Mon Sep 17 00:00:00 2001 From: karlnish Date: Tue, 9 May 2023 10:46:37 -0700 Subject: [PATCH 18/49] changes made according to the comments --- src/SimpleReplay/replay.py | 12 +++--------- src/SimpleReplay/replay.yaml | 20 ++++++++++---------- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/src/SimpleReplay/replay.py b/src/SimpleReplay/replay.py index cc285c78..25bd7c96 100644 --- a/src/SimpleReplay/replay.py +++ b/src/SimpleReplay/replay.py @@ -397,21 +397,15 @@ def save_query_stats(self, starttime, endtime, xid, query_idx): ) def get_tagged_sql(self, query_text, idx, transaction, connection): - if g_config["source_tag"]: + if g_config.get("source_tag", None): json_tags = { "xid": transaction.xid, "query_idx": idx, "replay_start": g_replay_timestamp.isoformat(), - "source": g_config.get(["source_tag"]), - } - else: - json_tags = { - "xid": transaction.xid, - "query_idx": idx, - "replay_start": g_replay_timestamp.isoformat(), - "source": "SimpleReplay", + "source": g_config.get('source_tag', 'SimpleReplay'), } + return "/* {} */ {}".format(json.dumps(json_tags), query_text) def execute_transaction(self, transaction, connection): diff --git a/src/SimpleReplay/replay.yaml b/src/SimpleReplay/replay.yaml index c27e3ff9..a97616c9 100644 --- a/src/SimpleReplay/replay.yaml +++ b/src/SimpleReplay/replay.yaml @@ -5,12 +5,12 @@ tag: "" source_tag: "" # Directory location of extracted workload, relative to current directory -workload_location: "test-location/Edited_10_Extraction_devsaba-sr-test_2023-01-23T09:46:24.784062+00:00" +workload_location: "" # Endpoint and username of target cluster to replay queries on -target_cluster_endpoint: "replay-dev.254137219717.us-east-1.redshift-serverless.amazonaws.com:5439/dev" -target_cluster_region: "us-east-1" -master_username: "awsuser" +target_cluster_endpoint: "" +target_cluster_region: "" +master_username: "" # NLB or NAT endpoint for Simple Replay to connect to. This NLB or NAT should have connectivity to target_cluster_endpoint nlb_nat_dns: "" @@ -35,26 +35,26 @@ time_interval_between_queries: "" execute_copy_statements: "false" # Should UNLOAD statements be executed? -execute_unload_statements: "true" +execute_unload_statements: "false" # Optional - Where the UNLOADs and system table unload goes. -replay_output: "s3://simplereplay-v2.2.5-testing/test-drive-testing/provisioned/replay" +replay_output: "" # Optional - Where the analysis data and summary report will be uploaded. Example: s3://bucket_name/path -analysis_output: "s3://simplereplay-v2.2.5-testing/test-drive-testing/provisioned" +analysis_output: "" # Optional - Leaving this blank means UNLOADs will not be replayed. IAM role for UNLOADs to be performed with. -unload_iam_role: "arn:aws:iam::254137219717:role/RedshiftFullAccess" +unload_iam_role: "" # Optional - Leaving this blank means analysis will not be run. IAM role for analysis needs UNLOAD access. -analysis_iam_role: "arn:aws:iam::254137219717:role/RedshiftFullAccess" +analysis_iam_role: "" # Location of the SQL file containing queries to unload system tables unload_system_table_queries: "unload_system_tables.sql" # IAM role to UNLOAD system tables from source cluster to S3 location for later # analysis -target_cluster_system_table_unload_iam_role: "arn:aws:iam::254137219717:role/RedshiftFullAccess" +target_cluster_system_table_unload_iam_role: "" # Include filters will work as "db AND user AND pid". Exclude filters will work as "db OR user OR pid". # In case of multiple values for any specific filter, please enclose each in single quotes From 66e7ef64507cb53ce4f921615086293423746fa9 Mon Sep 17 00:00:00 2001 From: karlnish Date: Tue, 9 May 2023 10:49:25 -0700 Subject: [PATCH 19/49] Fix replay.yaml --- src/SimpleReplay/replay.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/SimpleReplay/replay.yaml b/src/SimpleReplay/replay.yaml index a97616c9..4e4898e8 100644 --- a/src/SimpleReplay/replay.yaml +++ b/src/SimpleReplay/replay.yaml @@ -8,7 +8,7 @@ source_tag: "" workload_location: "" # Endpoint and username of target cluster to replay queries on -target_cluster_endpoint: "" +target_cluster_endpoint: "host:port/database" target_cluster_region: "" master_username: "" # NLB or NAT endpoint for Simple Replay to connect to. This NLB or NAT should have connectivity to target_cluster_endpoint @@ -24,12 +24,12 @@ default_interface: "psql" # Optional - Leaving it empty defers to connections.json. "all on" preserves # time between transactions. "all off" disregards time between transactions, # executing them as a batch. -time_interval_between_transactions: "" +time_interval_between_transactions: "all on" # Optional - Leaving it empty defers to connections.json. "all on" preserves # time between queries. "all off" disregards time between queries, executing # them as a batch. -time_interval_between_queries: "" +time_interval_between_queries: "all on" # Should COPY statements be executed? execute_copy_statements: "false" @@ -83,7 +83,7 @@ num_workers: ~ # their expected time. connection_tolerance_sec: 300 -# Number of TestDrive logfiles to maintain +# Number of simplereplay logfiles to maintain backup_count: 1 # Should we discard the returned data From 0bc707e390244b7a7dc48870a3b3811cc0d2a8bc Mon Sep 17 00:00:00 2001 From: luzonghaoa Date: Wed, 10 May 2023 10:47:58 +0200 Subject: [PATCH 20/49] Update replay.py Remove the IF condition to avoid bug when `source_tag` is not provided --- src/SimpleReplay/replay.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/SimpleReplay/replay.py b/src/SimpleReplay/replay.py index 25bd7c96..1076ca9d 100644 --- a/src/SimpleReplay/replay.py +++ b/src/SimpleReplay/replay.py @@ -397,7 +397,6 @@ def save_query_stats(self, starttime, endtime, xid, query_idx): ) def get_tagged_sql(self, query_text, idx, transaction, connection): - if g_config.get("source_tag", None): json_tags = { "xid": transaction.xid, "query_idx": idx, From a335044b27ceeb9c3d4fdd147ecfe5dbc613343e Mon Sep 17 00:00:00 2001 From: luzonghaoa Date: Wed, 10 May 2023 10:50:04 +0200 Subject: [PATCH 21/49] Update replay.py fix format issue --- src/SimpleReplay/replay.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/SimpleReplay/replay.py b/src/SimpleReplay/replay.py index 1076ca9d..0dd4a2ba 100644 --- a/src/SimpleReplay/replay.py +++ b/src/SimpleReplay/replay.py @@ -397,13 +397,12 @@ def save_query_stats(self, starttime, endtime, xid, query_idx): ) def get_tagged_sql(self, query_text, idx, transaction, connection): - json_tags = { - "xid": transaction.xid, - "query_idx": idx, - "replay_start": g_replay_timestamp.isoformat(), - "source": g_config.get('source_tag', 'SimpleReplay'), - } - + json_tags = { + "xid": transaction.xid, + "query_idx": idx, + "replay_start": g_replay_timestamp.isoformat(), + "source": g_config.get('source_tag', 'SimpleReplay'), + } return "/* {} */ {}".format(json.dumps(json_tags), query_text) From b168bea2e6d2c7c6a7b27dab2164cdcfcba2cb46 Mon Sep 17 00:00:00 2001 From: karlnish Date: Fri, 16 Jun 2023 10:31:11 -0700 Subject: [PATCH 22/49] fix for the iam_role being blank for the copy_replacements --- src/SimpleReplay/replay.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/SimpleReplay/replay.py b/src/SimpleReplay/replay.py index 0dd4a2ba..7d3ab283 100644 --- a/src/SimpleReplay/replay.py +++ b/src/SimpleReplay/replay.py @@ -401,7 +401,7 @@ def get_tagged_sql(self, query_text, idx, transaction, connection): "xid": transaction.xid, "query_idx": idx, "replay_start": g_replay_timestamp.isoformat(), - "source": g_config.get('source_tag', 'SimpleReplay'), + "source": g_config.get("source_tag", "SimpleReplay"), } return "/* {} */ {}".format(json.dumps(json_tags), query_text) @@ -1424,6 +1424,7 @@ def assign_copy_replacements(connection_logs, replacements): ) iam_replacements = [ + (r"iam_role''", f" IAM_ROLE '{replacement_copy_iam_role}'"), ( r"IAM_ROLE 'arn:aws:iam::\d+:role/\S+'", f" IAM_ROLE '{replacement_copy_iam_role}'", From 8d756e729bc21dd67c768af6d01e9a2f523f040b Mon Sep 17 00:00:00 2001 From: DevanathanSabapathy1 Date: Tue, 20 Jun 2023 13:59:36 -0700 Subject: [PATCH 23/49] fixing error for workload location with trailing '/' --- src/SimpleReplay/replay.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SimpleReplay/replay.py b/src/SimpleReplay/replay.py index 7d3ab283..19db0e15 100644 --- a/src/SimpleReplay/replay.py +++ b/src/SimpleReplay/replay.py @@ -862,7 +862,7 @@ def parse_copy_replacements(workload_directory): copy_replacements = {} copy_replacements_reader = None - replacements_path = workload_directory + "/" + g_copy_replacements_filename + replacements_path = workload_directory.rstrip("/") + "/" + g_copy_replacements_filename if replacements_path.startswith("s3://"): workload_s3_location = replacements_path[5:].partition("/") From 65c7fc0fb5df507abbaf7fa11b4c8d564e3e56f8 Mon Sep 17 00:00:00 2001 From: DevanathanSabapathy1 Date: Wed, 21 Jun 2023 11:54:14 -0700 Subject: [PATCH 24/49] Fixing the readme --- src/SimpleReplay/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SimpleReplay/README.md b/src/SimpleReplay/README.md index b74c4284..8377fd80 100644 --- a/src/SimpleReplay/README.md +++ b/src/SimpleReplay/README.md @@ -12,7 +12,7 @@ This enables the replay to be as close to the source run. It is **strongly recom If you want to experiment with different Amazon Redshift cluster configurations to evaluate and compare how your workload performs you can use Amazon Redshift Node Configuration Comparison utility (https://github.com/aws-samples/amazon-redshift-config-compare) which invokes Simple Replay utility. It provides ability to configure the necessary resources and will automatically execute the workload across N number of clusters. For more details about this utility please check https://aws.amazon.com/blogs/big-data/compare-different-node-types-for-your-workload-using-amazon-redshift/ -**NOTE:** Simple Replay now supports both Redshift Provisioned and Serverless. But Amazon Redshift Node Configuration Comparison utility currently supports only Redshift Provisioned clusters; support for Serverless is coming soon. +**NOTE:** Simple Replay and Node Configuration Comparison utility supports both Redshift Provisioned clusters and Serverless clusters. ## Preparation From 130a5093003732605bccf02378383d0a243b5a40 Mon Sep 17 00:00:00 2001 From: Sathiish <118481523+sathiish-kumar@users.noreply.github.com> Date: Mon, 18 Sep 2023 09:58:49 -0700 Subject: [PATCH 25/49] Update README.md --- src/SimpleReplay/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/SimpleReplay/README.md b/src/SimpleReplay/README.md index 8377fd80..ab0f3402 100644 --- a/src/SimpleReplay/README.md +++ b/src/SimpleReplay/README.md @@ -1,3 +1,5 @@ +## NOTE: SimpleReplay has now been moved to [Redshift Test-Drive](https://github.com/aws/redshift-test-drive). While you can still use SimpleReplay, switch to test-drive to get more frequent updates for this tool. [This blog](https://aws.amazon.com/blogs/big-data/find-the-best-amazon-redshift-configuration-for-your-workload-using-redshift-test-drive/) explains how to use Test-Drive + # Simple Replay README ## Introduction From 89f6d22c2e9d2394f6309b3870c775c8635ee5fc Mon Sep 17 00:00:00 2001 From: Sathiish <118481523+sathiish-kumar@users.noreply.github.com> Date: Mon, 18 Sep 2023 10:44:42 -0700 Subject: [PATCH 26/49] Update README.md --- src/SimpleReplay/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SimpleReplay/README.md b/src/SimpleReplay/README.md index ab0f3402..0a914245 100644 --- a/src/SimpleReplay/README.md +++ b/src/SimpleReplay/README.md @@ -1,4 +1,4 @@ -## NOTE: SimpleReplay has now been moved to [Redshift Test-Drive](https://github.com/aws/redshift-test-drive). While you can still use SimpleReplay, switch to test-drive to get more frequent updates for this tool. [This blog](https://aws.amazon.com/blogs/big-data/find-the-best-amazon-redshift-configuration-for-your-workload-using-redshift-test-drive/) explains how to use Test-Drive +## NOTE: SimpleReplay has now been moved to [Redshift Test-Drive](https://github.com/aws/redshift-test-drive). While you can still use SimpleReplay, switch to test-drive to get more frequent updates for this tool. [This blog](https://aws.amazon.com/blogs/big-data/find-the-best-amazon-redshift-configuration-for-your-workload-using-redshift-test-drive/) explains how to use Test-Drive. SimpleReplay (this) will be deprecated in favor of Test-Drive by the end of 2023. # Simple Replay README From fa7312c6f5405a480e47dd6517d293da7d38af42 Mon Sep 17 00:00:00 2001 From: sgromoll Date: Thu, 26 Oct 2023 20:08:50 -0400 Subject: [PATCH 27/49] Update queries to support ROLLUP (#705) --- .../100TB/ddl.sql | 621 -- .../100TB/queries/query_0.sql | 5027 ----------------- .../100TB/queries/query_1.sql | 5027 ----------------- .../100TB/queries/query_10.sql | 5027 ----------------- .../100TB/queries/query_2.sql | 5027 ----------------- .../100TB/queries/query_3.sql | 5027 ----------------- .../100TB/queries/query_4.sql | 5027 ----------------- .../100TB/queries/query_5.sql | 5027 ----------------- .../100TB/queries/query_6.sql | 5027 ----------------- .../100TB/queries/query_7.sql | 5027 ----------------- .../100TB/queries/query_8.sql | 5027 ----------------- .../100TB/queries/query_9.sql | 5027 ----------------- .../Cloud-DWB-Derived-from-TPCDS/30TB/ddl.sql | 620 -- .../30TB/queries/query_0.sql | 5027 ----------------- .../30TB/queries/query_1.sql | 5027 ----------------- .../30TB/queries/query_10.sql | 5027 ----------------- .../30TB/queries/query_2.sql | 5027 ----------------- .../30TB/queries/query_3.sql | 5027 ----------------- .../30TB/queries/query_4.sql | 5027 ----------------- .../30TB/queries/query_5.sql | 5027 ----------------- .../30TB/queries/query_6.sql | 5027 ----------------- .../30TB/queries/query_7.sql | 5027 ----------------- .../30TB/queries/query_8.sql | 5027 ----------------- .../30TB/queries/query_9.sql | 5027 ----------------- .../3TB/queries/query_0.sql | 535 +- .../3TB/queries/query_1.sql | 5027 ----------------- .../3TB/queries/query_10.sql | 5027 ----------------- .../3TB/queries/query_2.sql | 5027 ----------------- .../3TB/queries/query_3.sql | 5027 ----------------- .../3TB/queries/query_4.sql | 5027 ----------------- .../3TB/queries/query_5.sql | 5027 ----------------- .../3TB/queries/query_6.sql | 5027 ----------------- .../3TB/queries/query_7.sql | 5027 ----------------- .../3TB/queries/query_8.sql | 5027 ----------------- .../3TB/queries/query_9.sql | 5027 ----------------- .../Cloud-DWB-Derived-from-TPCDS/README.md | 11 +- .../Cloud-DWB-Derived-from-TPCH/README.md | 2 +- 37 files changed, 189 insertions(+), 162464 deletions(-) delete mode 100644 src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/100TB/ddl.sql delete mode 100644 src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/100TB/queries/query_0.sql delete mode 100644 src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/100TB/queries/query_1.sql delete mode 100644 src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/100TB/queries/query_10.sql delete mode 100644 src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/100TB/queries/query_2.sql delete mode 100644 src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/100TB/queries/query_3.sql delete mode 100644 src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/100TB/queries/query_4.sql delete mode 100644 src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/100TB/queries/query_5.sql delete mode 100644 src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/100TB/queries/query_6.sql delete mode 100644 src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/100TB/queries/query_7.sql delete mode 100644 src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/100TB/queries/query_8.sql delete mode 100644 src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/100TB/queries/query_9.sql delete mode 100644 src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/30TB/ddl.sql delete mode 100644 src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/30TB/queries/query_0.sql delete mode 100644 src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/30TB/queries/query_1.sql delete mode 100644 src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/30TB/queries/query_10.sql delete mode 100644 src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/30TB/queries/query_2.sql delete mode 100644 src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/30TB/queries/query_3.sql delete mode 100644 src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/30TB/queries/query_4.sql delete mode 100644 src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/30TB/queries/query_5.sql delete mode 100644 src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/30TB/queries/query_6.sql delete mode 100644 src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/30TB/queries/query_7.sql delete mode 100644 src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/30TB/queries/query_8.sql delete mode 100644 src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/30TB/queries/query_9.sql delete mode 100644 src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/3TB/queries/query_1.sql delete mode 100644 src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/3TB/queries/query_10.sql delete mode 100644 src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/3TB/queries/query_2.sql delete mode 100644 src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/3TB/queries/query_3.sql delete mode 100644 src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/3TB/queries/query_4.sql delete mode 100644 src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/3TB/queries/query_5.sql delete mode 100644 src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/3TB/queries/query_6.sql delete mode 100644 src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/3TB/queries/query_7.sql delete mode 100644 src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/3TB/queries/query_8.sql delete mode 100644 src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/3TB/queries/query_9.sql diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/100TB/ddl.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/100TB/ddl.sql deleted file mode 100644 index 0014a666..00000000 --- a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/100TB/ddl.sql +++ /dev/null @@ -1,621 +0,0 @@ -create table dbgen_version -( - dv_version varchar(32), - dv_create_date date , - dv_create_time timestamp, - dv_cmdline_args varchar(200) -); - -create table customer_address -( - ca_address_sk int4 not null , - ca_address_id char(16) not null , - ca_street_number char(10) , - ca_street_name varchar(60) , - ca_street_type char(15) , - ca_suite_number char(10) , - ca_city varchar(60) , - ca_county varchar(30) , - ca_state char(2) , - ca_zip char(10) , - ca_country varchar(20) , - ca_gmt_offset numeric(5,2) , - ca_location_type char(20) - ,primary key (ca_address_sk) -) distkey(ca_address_sk); - -create table customer_demographics -( - cd_demo_sk int4 not null , - cd_gender char(1) , - cd_marital_status char(1) , - cd_education_status char(20) , - cd_purchase_estimate int4 , - cd_credit_rating char(10) , - cd_dep_count int4 , - cd_dep_employed_count int4 , - cd_dep_college_count int4 - ,primary key (cd_demo_sk) -)distkey (cd_demo_sk); - -create table date_dim -( - d_date_sk integer not null, - d_date_id char(16) not null, - d_date date, - d_month_seq integer , - d_week_seq integer , - d_quarter_seq integer , - d_year integer , - d_dow integer , - d_moy integer , - d_dom integer , - d_qoy integer , - d_fy_year integer , - d_fy_quarter_seq integer , - d_fy_week_seq integer , - d_day_name char(9) , - d_quarter_name char(6) , - d_holiday char(1) , - d_weekend char(1) , - d_following_holiday char(1) , - d_first_dom integer , - d_last_dom integer , - d_same_day_ly integer , - d_same_day_lq integer , - d_current_day char(1) , - d_current_week char(1) , - d_current_month char(1) , - d_current_quarter char(1) , - d_current_year char(1) , - primary key (d_date_sk) -) diststyle all; - -create table warehouse -( - w_warehouse_sk integer not null, - w_warehouse_id char(16) not null, - w_warehouse_name varchar(20) , - w_warehouse_sq_ft integer , - w_street_number char(10) , - w_street_name varchar(60) , - w_street_type char(15) , - w_suite_number char(10) , - w_city varchar(60) , - w_county varchar(30) , - w_state char(2) , - w_zip char(10) , - w_country varchar(20) , - w_gmt_offset decimal(5,2) , - primary key (w_warehouse_sk) -) diststyle all; - -create table ship_mode -( - sm_ship_mode_sk integer not null, - sm_ship_mode_id char(16) not null, - sm_type char(30) , - sm_code char(10) , - sm_carrier char(20) , - sm_contract char(20) , - primary key (sm_ship_mode_sk) -) diststyle all; - -create table time_dim -( - t_time_sk integer not null, - t_time_id char(16) not null, - t_time integer , - t_hour integer , - t_minute integer , - t_second integer , - t_am_pm char(2) , - t_shift char(20) , - t_sub_shift char(20) , - t_meal_time char(20) , - primary key (t_time_sk) -) diststyle all; - -create table reason -( - r_reason_sk integer not null, - r_reason_id char(16) not null, - r_reason_desc char(100) , - primary key (r_reason_sk) -) diststyle all ; - -create table income_band -( - ib_income_band_sk integer not null, - ib_lower_bound integer , - ib_upper_bound integer , - primary key (ib_income_band_sk) -) diststyle all; - -create table item -( -i_item_sk int4 not null, - i_item_id char(16) not null , - i_rec_start_date date, - i_rec_end_date date, - i_item_desc varchar(200) , - i_current_price numeric(7,2), - i_wholesale_cost numeric(7,2), - i_brand_id int4, - i_brand char(50) , - i_class_id int4, - i_class char(50) , - i_category_id int4, - i_category char(50) , - i_manufact_id int4, - i_manufact char(50) , - i_size char(20) , - i_formulation char(20) , - i_color char(20) , - i_units char(10), - i_container char(10), - i_manager_id int4, - i_product_name char(50) - ,primary key (i_item_sk) -) distkey(i_item_sk) sortkey(i_category); - -create table store -( - s_store_sk integer not null, - s_store_id char(16) not null, - s_rec_start_date date, - s_rec_end_date date, - s_closed_date_sk integer , - s_store_name varchar(50) , - s_number_employees integer , - s_floor_space integer , - s_hours char(20) , - s_manager varchar(40) , - s_market_id integer , - s_geography_class varchar(100) , - s_market_desc varchar(100) , - s_market_manager varchar(40) , - s_division_id integer , - s_division_name varchar(50) , - s_company_id integer , - s_company_name varchar(50) , - s_street_number varchar(10) , - s_street_name varchar(60) , - s_street_type char(15) , - s_suite_number char(10) , - s_city varchar(60) , - s_county varchar(30) , - s_state char(2) , - s_zip char(10) , - s_country varchar(20) , - s_gmt_offset decimal(5,2) , - s_tax_precentage decimal(5,2) , - primary key (s_store_sk) -) diststyle all; - -create table call_center -( - cc_call_center_sk integer not null, - cc_call_center_id char(16) not null, - cc_rec_start_date date, - cc_rec_end_date date, - cc_closed_date_sk integer , - cc_open_date_sk integer , - cc_name varchar(50) , - cc_class varchar(50) , - cc_employees integer , - cc_sq_ft integer , - cc_hours char(20) , - cc_manager varchar(40) , - cc_mkt_id integer , - cc_mkt_class char(50) , - cc_mkt_desc varchar(100) , - cc_market_manager varchar(40) , - cc_division integer , - cc_division_name varchar(50) , - cc_company integer , - cc_company_name char(50) , - cc_street_number char(10) , - cc_street_name varchar(60) , - cc_street_type char(15) , - cc_suite_number char(10) , - cc_city varchar(60) , - cc_county varchar(30) , - cc_state char(2) , - cc_zip char(10) , - cc_country varchar(20) , - cc_gmt_offset decimal(5,2) , - cc_tax_percentage decimal(5,2) , - primary key (cc_call_center_sk) -) diststyle all; - -create table customer -( - c_customer_sk int4 not null , - c_customer_id char(16) not null , - c_current_cdemo_sk int4 , - c_current_hdemo_sk int4 , - c_current_addr_sk int4 , - c_first_shipto_date_sk int4 , - c_first_sales_date_sk int4 , - c_salutation char(10) , - c_first_name char(20) , - c_last_name char(30) , - c_preferred_cust_flag char(1) , - c_birth_day int4 , - c_birth_month int4 , - c_birth_year int4 , - c_birth_country varchar(20) , - c_login char(13) , - c_email_address char(50) , - c_last_review_date_sk int4 , - primary key (c_customer_sk) -) distkey(c_customer_sk); - -create table web_site -( - web_site_sk integer not null, - web_site_id char(16) not null, - web_rec_start_date date, - web_rec_end_date date, - web_name varchar(50) , - web_open_date_sk integer , - web_close_date_sk integer , - web_class varchar(50) , - web_manager varchar(40) , - web_mkt_id integer , - web_mkt_class varchar(50) , - web_mkt_desc varchar(100) , - web_market_manager varchar(40) , - web_company_id integer , - web_company_name char(50) , - web_street_number char(10) , - web_street_name varchar(60) , - web_street_type char(15) , - web_suite_number char(10) , - web_city varchar(60) , - web_county varchar(30) , - web_state char(2) , - web_zip char(10) , - web_country varchar(20) , - web_gmt_offset decimal(5,2) , - web_tax_percentage decimal(5,2) , - primary key (web_site_sk) -) diststyle all; - -create table store_returns -( -sr_returned_date_sk int4 , - sr_return_time_sk int4 , - sr_item_sk int4 not null , - sr_customer_sk int4 , - sr_cdemo_sk int4 , - sr_hdemo_sk int4 , - sr_addr_sk int4 , - sr_store_sk int4 , - sr_reason_sk int4 , - sr_ticket_number int8 not null, - sr_return_quantity int4 , - sr_return_amt numeric(7,2) , - sr_return_tax numeric(7,2) , - sr_return_amt_inc_tax numeric(7,2) , - sr_fee numeric(7,2) , - sr_return_ship_cost numeric(7,2) , - sr_refunded_cash numeric(7,2) , - sr_reversed_charge numeric(7,2) , - sr_store_credit numeric(7,2) , - sr_net_loss numeric(7,2) - ,primary key (sr_item_sk, sr_ticket_number) -) distkey(sr_item_sk) sortkey(sr_returned_date_sk); - -create table household_demographics -( - hd_demo_sk integer not null, - hd_income_band_sk integer , - hd_buy_potential char(15) , - hd_dep_count integer , - hd_vehicle_count integer , - primary key (hd_demo_sk) -) diststyle all; - -create table web_page -( - wp_web_page_sk integer not null, - wp_web_page_id char(16) not null, - wp_rec_start_date date, - wp_rec_end_date date, - wp_creation_date_sk integer , - wp_access_date_sk integer , - wp_autogen_flag char(1) , - wp_customer_sk integer , - wp_url varchar(100) , - wp_type char(50) , - wp_char_count integer , - wp_link_count integer , - wp_image_count integer , - wp_max_ad_count integer , - primary key (wp_web_page_sk) -) diststyle all; - -create table promotion -( - p_promo_sk integer not null, - p_promo_id char(16) not null, - p_start_date_sk integer , - p_end_date_sk integer , - p_item_sk integer , - p_cost decimal(15,2) , - p_response_target integer , - p_promo_name char(50) , - p_channel_dmail char(1) , - p_channel_email char(1) , - p_channel_catalog char(1) , - p_channel_tv char(1) , - p_channel_radio char(1) , - p_channel_press char(1) , - p_channel_event char(1) , - p_channel_demo char(1) , - p_channel_details varchar(100) , - p_purpose char(15) , - p_discount_active char(1) , - primary key (p_promo_sk) -) diststyle all; - -create table catalog_page -( - cp_catalog_page_sk integer not null, - cp_catalog_page_id char(16) not null, - cp_start_date_sk integer , - cp_end_date_sk integer , - cp_department varchar(50) , - cp_catalog_number integer , - cp_catalog_page_number integer , - cp_description varchar(100) , - cp_type varchar(100) , - primary key (cp_catalog_page_sk) -) diststyle all; - -create table inventory -( - inv_date_sk int4 not null , - inv_item_sk int4 not null , - inv_warehouse_sk int4 not null , - inv_quantity_on_hand int4 - ,primary key (inv_date_sk, inv_item_sk, inv_warehouse_sk) -) distkey(inv_item_sk) sortkey(inv_date_sk); - -create table catalog_returns -( - cr_returned_date_sk int4 , - cr_returned_time_sk int4 , - cr_item_sk int4 not null , - cr_refunded_customer_sk int4 , - cr_refunded_cdemo_sk int4 , - cr_refunded_hdemo_sk int4 , - cr_refunded_addr_sk int4 , - cr_returning_customer_sk int4 , - cr_returning_cdemo_sk int4 , - cr_returning_hdemo_sk int4 , - cr_returning_addr_sk int4 , - cr_call_center_sk int4 , - cr_catalog_page_sk int4 , - cr_ship_mode_sk int4 , - cr_warehouse_sk int4 , - cr_reason_sk int4 , - cr_order_number int8 not null, - cr_return_quantity int4 , - cr_return_amount numeric(7,2) , - cr_return_tax numeric(7,2) , - cr_return_amt_inc_tax numeric(7,2) , - cr_fee numeric(7,2) , - cr_return_ship_cost numeric(7,2) , - cr_refunded_cash numeric(7,2) , - cr_reversed_charge numeric(7,2) , - cr_store_credit numeric(7,2) , - cr_net_loss numeric(7,2) - ,primary key (cr_item_sk, cr_order_number) -) distkey(cr_item_sk) sortkey(cr_returned_date_sk); - -create table web_returns -( -wr_returned_date_sk int4 , - wr_returned_time_sk int4 , - wr_item_sk int4 not null , - wr_refunded_customer_sk int4 , - wr_refunded_cdemo_sk int4 , - wr_refunded_hdemo_sk int4 , - wr_refunded_addr_sk int4 , - wr_returning_customer_sk int4 , - wr_returning_cdemo_sk int4 , - wr_returning_hdemo_sk int4 , - wr_returning_addr_sk int4 , - wr_web_page_sk int4 , - wr_reason_sk int4 , - wr_order_number int8 not null, - wr_return_quantity int4 , - wr_return_amt numeric(7,2) , - wr_return_tax numeric(7,2) , - wr_return_amt_inc_tax numeric(7,2) , - wr_fee numeric(7,2) , - wr_return_ship_cost numeric(7,2) , - wr_refunded_cash numeric(7,2) , - wr_reversed_charge numeric(7,2) , - wr_account_credit numeric(7,2) , - wr_net_loss numeric(7,2) - ,primary key (wr_item_sk, wr_order_number) -) distkey(wr_order_number) sortkey(wr_returned_date_sk); - -create table web_sales -( - ws_sold_date_sk int4 , - ws_sold_time_sk int4 , - ws_ship_date_sk int4 , - ws_item_sk int4 not null , - ws_bill_customer_sk int4 , - ws_bill_cdemo_sk int4 , - ws_bill_hdemo_sk int4 , - ws_bill_addr_sk int4 , - ws_ship_customer_sk int4 , - ws_ship_cdemo_sk int4 , - ws_ship_hdemo_sk int4 , - ws_ship_addr_sk int4 , - ws_web_page_sk int4 , - ws_web_site_sk int4 , - ws_ship_mode_sk int4 , - ws_warehouse_sk int4 , - ws_promo_sk int4 , - ws_order_number int8 not null, - ws_quantity int4 , - ws_wholesale_cost numeric(7,2) , - ws_list_price numeric(7,2) , - ws_sales_price numeric(7,2) , - ws_ext_discount_amt numeric(7,2) , - ws_ext_sales_price numeric(7,2) , - ws_ext_wholesale_cost numeric(7,2) , - ws_ext_list_price numeric(7,2) , - ws_ext_tax numeric(7,2) , - ws_coupon_amt numeric(7,2) , - ws_ext_ship_cost numeric(7,2) , - ws_net_paid numeric(7,2) , - ws_net_paid_inc_tax numeric(7,2) , - ws_net_paid_inc_ship numeric(7,2) , - ws_net_paid_inc_ship_tax numeric(7,2) , - ws_net_profit numeric(7,2) - ,primary key (ws_item_sk, ws_order_number) -) distkey(ws_order_number) sortkey(ws_sold_date_sk); - -create table catalog_sales -( - cs_sold_date_sk int4 , - cs_sold_time_sk int4 , - cs_ship_date_sk int4 , - cs_bill_customer_sk int4 , - cs_bill_cdemo_sk int4 , - cs_bill_hdemo_sk int4 , - cs_bill_addr_sk int4 , - cs_ship_customer_sk int4 , - cs_ship_cdemo_sk int4 , - cs_ship_hdemo_sk int4 , - cs_ship_addr_sk int4 , - cs_call_center_sk int4 , - cs_catalog_page_sk int4 , - cs_ship_mode_sk int4 , - cs_warehouse_sk int4 , - cs_item_sk int4 not null , - cs_promo_sk int4 , - cs_order_number int8 not null , - cs_quantity int4 , - cs_wholesale_cost numeric(7,2) , - cs_list_price numeric(7,2) , - cs_sales_price numeric(7,2) , - cs_ext_discount_amt numeric(7,2) , - cs_ext_sales_price numeric(7,2) , - cs_ext_wholesale_cost numeric(7,2) , - cs_ext_list_price numeric(7,2) , - cs_ext_tax numeric(7,2) , - cs_coupon_amt numeric(7,2) , - cs_ext_ship_cost numeric(7,2) , - cs_net_paid numeric(7,2) , - cs_net_paid_inc_tax numeric(7,2) , - cs_net_paid_inc_ship numeric(7,2) , - cs_net_paid_inc_ship_tax numeric(7,2) , - cs_net_profit numeric(7,2) - ,primary key (cs_item_sk, cs_order_number) -) distkey(cs_item_sk) sortkey(cs_sold_date_sk); - -create table store_sales -( -ss_sold_date_sk int4 , - ss_sold_time_sk int4 , - ss_item_sk int4 not null , - ss_customer_sk int4 , - ss_cdemo_sk int4 , - ss_hdemo_sk int4 , - ss_addr_sk int4 , - ss_store_sk int4 , - ss_promo_sk int4 , - ss_ticket_number int8 not null, - ss_quantity int4 , - ss_wholesale_cost numeric(7,2) , - ss_list_price numeric(7,2) , - ss_sales_price numeric(7,2) , - ss_ext_discount_amt numeric(7,2) , - ss_ext_sales_price numeric(7,2) , - ss_ext_wholesale_cost numeric(7,2) , - ss_ext_list_price numeric(7,2) , - ss_ext_tax numeric(7,2) , - ss_coupon_amt numeric(7,2) , - ss_net_paid numeric(7,2) , - ss_net_paid_inc_tax numeric(7,2) , - ss_net_profit numeric(7,2) - ,primary key (ss_item_sk, ss_ticket_number) -) distkey(ss_item_sk) sortkey(ss_sold_date_sk); - -/* -/* - Text files needed to load test data under s3://redshift-downloads/TPC-DS/2.13/100TB are publicly available. - - To load the sample data, you must provide authentication for your cluster to access Amazon S3 on your behalf. - - You can provide authentication by referencing an IAM role that you have created. You can set an IAM_Role as the default for your cluster or you can directly provide the ARN of an IAM_Role. - For more information https://docs.aws.amazon.com/redshift/latest/mgmt/authorizing-redshift-service.html - - The COPY commands include a placeholder for IAM_Role, in this code IAM_Role clause is set to use the default IAM_Role. If your cluster does not have a IAM_Role set as default then please follow the instructions provided here: - - https://docs.aws.amazon.com/redshift/latest/mgmt/default-iam-role.html - - For more information check samples in https://docs.aws.amazon.com/redshift/latest/gsg/rs-gsg-create-sample-db.html - - **Note** another option to provide IAM_Role is to provide IAM_Role ARN in IAM_Role clause. For example - copy call_center from 's3://redshift-downloads/TPC-DS/2.13/100TB/call_center/' IAM_Role 'Replace text inside the quotes with Redshift cluster IAM_Role ARN' gzip delimiter '|' EMPTYASNULL region 'us-east-1'; -*/ - -copy call_center from 's3://redshift-downloads/TPC-DS/2.13/100TB/call_center/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1'; -copy catalog_page from 's3://redshift-downloads/TPC-DS/2.13/100TB/catalog_page/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1'; -copy catalog_returns from 's3://redshift-downloads/TPC-DS/2.13/100TB/catalog_returns/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1'; -copy catalog_sales from 's3://redshift-downloads/TPC-DS/2.13/100TB/catalog_sales/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1'; -copy customer_address from 's3://redshift-downloads/TPC-DS/2.13/100TB/customer_address/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1'; -copy customer_demographics from 's3://redshift-downloads/TPC-DS/2.13/100TB/customer_demographics/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1'; -copy customer from 's3://redshift-downloads/TPC-DS/2.13/100TB/customer/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1'; -copy date_dim from 's3://redshift-downloads/TPC-DS/2.13/100TB/date_dim/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1'; -copy household_demographics from 's3://redshift-downloads/TPC-DS/2.13/100TB/household_demographics/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1'; -copy income_band from 's3://redshift-downloads/TPC-DS/2.13/100TB/income_band/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1'; -copy inventory from 's3://redshift-downloads/TPC-DS/2.13/100TB/inventory/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1'; -copy item from 's3://redshift-downloads/TPC-DS/2.13/100TB/item/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1'; -copy promotion from 's3://redshift-downloads/TPC-DS/2.13/100TB/promotion/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1'; -copy reason from 's3://redshift-downloads/TPC-DS/2.13/100TB/reason/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1'; -copy ship_mode from 's3://redshift-downloads/TPC-DS/2.13/100TB/ship_mode/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1'; -copy store from 's3://redshift-downloads/TPC-DS/2.13/100TB/store/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1'; -copy store_returns from 's3://redshift-downloads/TPC-DS/2.13/100TB/store_returns/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1'; -copy store_sales from 's3://redshift-downloads/TPC-DS/2.13/100TB/store_sales/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1'; -copy time_dim from 's3://redshift-downloads/TPC-DS/2.13/100TB/time_dim/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1'; -copy warehouse from 's3://redshift-downloads/TPC-DS/2.13/100TB/warehouse/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1'; -copy web_page from 's3://redshift-downloads/TPC-DS/2.13/100TB/web_page/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1'; -copy web_returns from 's3://redshift-downloads/TPC-DS/2.13/100TB/web_returns/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1'; -copy web_sales from 's3://redshift-downloads/TPC-DS/2.13/100TB/web_sales/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1'; -copy web_site from 's3://redshift-downloads/TPC-DS/2.13/100TB/web_site/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1'; - -select count(*) from call_center; -- 60 -select count(*) from catalog_page; -- 50000 -select count(*) from catalog_returns; -- 14407487006 -select count(*) from catalog_sales; -- 144065709209 -select count(*) from customer; -- 100000000 -select count(*) from customer_address; -- 50000000 -select count(*) from customer_demographics; -- 1920800 -select count(*) from date_dim; -- 73049 -select count(*) from household_demographics; -- 7200 -select count(*) from income_band; -- 20 -select count(*) from inventory; -- 1965337830 -select count(*) from item; -- 502000 -select count(*) from promotion; -- 2500 -select count(*) from reason; -- 75 -select count(*) from ship_mode; -- 20 -select count(*) from store; -- 1902 -select count(*) from store_returns; -- 28770721279 -select count(*) from store_sales; -- 288056582818 -select count(*) from time_dim; -- 86400 -select count(*) from warehouse; -- 30 -select count(*) from web_page; -- 5004 -select count(*) from web_returns; -- 7191501511 -select count(*) from web_sales; -- 71983449467 -select count(*) from web_site; -- 96 diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/100TB/queries/query_0.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/100TB/queries/query_0.sql deleted file mode 100644 index 841ded01..00000000 --- a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/100TB/queries/query_0.sql +++ /dev/null @@ -1,5027 +0,0 @@ --- start template query96.tpl query 1 in stream 0 -select /* TPC-DS query96.tpl 0.1 */ count(*) -from store_sales - ,household_demographics - ,time_dim, store -where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and household_demographics.hd_dep_count = 5 - and store.s_store_name = 'ese' -order by count(*) -limit 100; - --- end template query96.tpl query 1 in stream 0 --- start template query7.tpl query 2 in stream 0 -select /* TPC-DS query7.tpl 0.2 */ i_item_id, - avg(ss_quantity) agg1, - avg(ss_list_price) agg2, - avg(ss_coupon_amt) agg3, - avg(ss_sales_price) agg4 - from store_sales, customer_demographics, date_dim, item, promotion - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_cdemo_sk = cd_demo_sk and - ss_promo_sk = p_promo_sk and - cd_gender = 'M' and - cd_marital_status = 'M' and - cd_education_status = '4 yr Degree' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 2001 - group by i_item_id - order by i_item_id - limit 100; - --- end template query7.tpl query 2 in stream 0 --- start template query75.tpl query 3 in stream 0 -WITH /* TPC-DS query75.tpl 0.3 */ all_sales AS ( - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,SUM(sales_cnt) AS sales_cnt - ,SUM(sales_amt) AS sales_amt - FROM (SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,cs_quantity - COALESCE(cr_return_quantity,0) AS sales_cnt - ,cs_ext_sales_price - COALESCE(cr_return_amount,0.0) AS sales_amt - FROM catalog_sales JOIN item ON i_item_sk=cs_item_sk - JOIN date_dim ON d_date_sk=cs_sold_date_sk - LEFT JOIN catalog_returns ON (cs_order_number=cr_order_number - AND cs_item_sk=cr_item_sk) - WHERE i_category='Shoes' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ss_quantity - COALESCE(sr_return_quantity,0) AS sales_cnt - ,ss_ext_sales_price - COALESCE(sr_return_amt,0.0) AS sales_amt - FROM store_sales JOIN item ON i_item_sk=ss_item_sk - JOIN date_dim ON d_date_sk=ss_sold_date_sk - LEFT JOIN store_returns ON (ss_ticket_number=sr_ticket_number - AND ss_item_sk=sr_item_sk) - WHERE i_category='Shoes' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ws_quantity - COALESCE(wr_return_quantity,0) AS sales_cnt - ,ws_ext_sales_price - COALESCE(wr_return_amt,0.0) AS sales_amt - FROM web_sales JOIN item ON i_item_sk=ws_item_sk - JOIN date_dim ON d_date_sk=ws_sold_date_sk - LEFT JOIN web_returns ON (ws_order_number=wr_order_number - AND ws_item_sk=wr_item_sk) - WHERE i_category='Shoes') sales_detail - GROUP BY d_year, i_brand_id, i_class_id, i_category_id, i_manufact_id) - SELECT prev_yr.d_year AS prev_year - ,curr_yr.d_year AS year - ,curr_yr.i_brand_id - ,curr_yr.i_class_id - ,curr_yr.i_category_id - ,curr_yr.i_manufact_id - ,prev_yr.sales_cnt AS prev_yr_cnt - ,curr_yr.sales_cnt AS curr_yr_cnt - ,curr_yr.sales_cnt-prev_yr.sales_cnt AS sales_cnt_diff - ,curr_yr.sales_amt-prev_yr.sales_amt AS sales_amt_diff - FROM all_sales curr_yr, all_sales prev_yr - WHERE curr_yr.i_brand_id=prev_yr.i_brand_id - AND curr_yr.i_class_id=prev_yr.i_class_id - AND curr_yr.i_category_id=prev_yr.i_category_id - AND curr_yr.i_manufact_id=prev_yr.i_manufact_id - AND curr_yr.d_year=2000 - AND prev_yr.d_year=2000-1 - AND CAST(curr_yr.sales_cnt AS DECIMAL(17,2))/CAST(prev_yr.sales_cnt AS DECIMAL(17,2))<0.9 - ORDER BY sales_cnt_diff,sales_amt_diff - limit 100; - --- end template query75.tpl query 3 in stream 0 --- start template query44.tpl query 4 in stream 0 -select /* TPC-DS query44.tpl 0.4 */ asceding.rnk, i1.i_product_name best_performing, i2.i_product_name worst_performing -from(select * - from (select item_sk,rank() over (order by rank_col asc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 246 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 246 - and ss_hdemo_sk is null - group by ss_store_sk))V1)V11 - where rnk < 11) asceding, - (select * - from (select item_sk,rank() over (order by rank_col desc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 246 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 246 - and ss_hdemo_sk is null - group by ss_store_sk))V2)V21 - where rnk < 11) descending, -item i1, -item i2 -where asceding.rnk = descending.rnk - and i1.i_item_sk=asceding.item_sk - and i2.i_item_sk=descending.item_sk -order by asceding.rnk -limit 100; - --- end template query44.tpl query 4 in stream 0 --- start template query39.tpl query 5 in stream 0 -with /* TPC-DS query39.tpl 0.5 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =2001 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=1 - and inv2.d_moy=1+1 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; -with /* TPC-DS query39.tpl 0.5 part2 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =2001 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=1 - and inv2.d_moy=1+1 - and inv1.cov > 1.5 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; - --- end template query39.tpl query 5 in stream 0 --- start template query80a.tpl query 6 in stream 0 -with /* TPC-DS query80a.tpl 0.6 */ ssr as - (select s_store_id as store_id, - sum(ss_ext_sales_price) as sales, - sum(coalesce(sr_return_amt, 0)) as returns, - sum(ss_net_profit - coalesce(sr_net_loss, 0)) as profit - from store_sales left outer join store_returns on - (ss_item_sk = sr_item_sk and ss_ticket_number = sr_ticket_number), - date_dim, - store, - item, - promotion - where ss_sold_date_sk = d_date_sk - and d_date between cast('2002-08-04' as date) - and dateadd(day,30,cast('2002-08-04' as date)) - and ss_store_sk = s_store_sk - and ss_item_sk = i_item_sk - and i_current_price > 50 - and ss_promo_sk = p_promo_sk - and p_channel_tv = 'N' - group by s_store_id) - , - csr as - (select cp_catalog_page_id as catalog_page_id, - sum(cs_ext_sales_price) as sales, - sum(coalesce(cr_return_amount, 0)) as returns, - sum(cs_net_profit - coalesce(cr_net_loss, 0)) as profit - from catalog_sales left outer join catalog_returns on - (cs_item_sk = cr_item_sk and cs_order_number = cr_order_number), - date_dim, - catalog_page, - item, - promotion - where cs_sold_date_sk = d_date_sk - and d_date between cast('2002-08-04' as date) - and dateadd(day,30,cast('2002-08-04' as date)) - and cs_catalog_page_sk = cp_catalog_page_sk - and cs_item_sk = i_item_sk - and i_current_price > 50 - and cs_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(ws_ext_sales_price) as sales, - sum(coalesce(wr_return_amt, 0)) as returns, - sum(ws_net_profit - coalesce(wr_net_loss, 0)) as profit - from web_sales left outer join web_returns on - (ws_item_sk = wr_item_sk and ws_order_number = wr_order_number), - date_dim, - web_site, - item, - promotion - where ws_sold_date_sk = d_date_sk - and d_date between cast('2002-08-04' as date) - and dateadd(day,30,cast('2002-08-04' as date)) - and ws_web_site_sk = web_site_sk - and ws_item_sk = i_item_sk - and i_current_price > 50 - and ws_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by web_site_id) -, -results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || store_id as id - , sales - , returns - , profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || catalog_page_id as id - , sales - , returns - , profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , profit - from wsr - ) x - group by channel, id) - - select channel - , id - , sales - , returns - , profit - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results - ) foo - order by channel, id - limit 100; - --- end template query80a.tpl query 6 in stream 0 --- start template query32.tpl query 7 in stream 0 -select /* TPC-DS query32.tpl 0.7 */ sum(cs_ext_discount_amt) as "excess discount amount" -from - catalog_sales - ,item - ,date_dim -where -i_manufact_id = 283 -and i_item_sk = cs_item_sk -and d_date between '1999-02-22' and - dateadd(day,90,cast('1999-02-22' as date)) -and d_date_sk = cs_sold_date_sk -and cs_ext_discount_amt - > ( - select - 1.3 * avg(cs_ext_discount_amt) - from - catalog_sales - ,date_dim - where - cs_item_sk = i_item_sk - and d_date between '1999-02-22' and - dateadd(day,90,cast('1999-02-22' as date)) - and d_date_sk = cs_sold_date_sk - ) -limit 100; - --- end template query32.tpl query 7 in stream 0 --- start template query19.tpl query 8 in stream 0 -select /* TPC-DS query19.tpl 0.8 */ i_brand_id brand_id, i_brand brand, i_manufact_id, i_manufact, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item,customer,customer_address,store - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=8 - and d_moy=11 - and d_year=1999 - and ss_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and substring(ca_zip,1,5) <> substring(s_zip,1,5) - and ss_store_sk = s_store_sk - group by i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact - order by ext_price desc - ,i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact -limit 100 ; - --- end template query19.tpl query 8 in stream 0 --- start template query25.tpl query 9 in stream 0 -select /* TPC-DS query25.tpl 0.9 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,min(ss_net_profit) as store_sales_profit - ,min(sr_net_loss) as store_returns_loss - ,min(cs_net_profit) as catalog_sales_profit - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 2002 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 10 - and d2.d_year = 2002 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_moy between 4 and 10 - and d3.d_year = 2002 - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query25.tpl query 9 in stream 0 --- start template query78.tpl query 10 in stream 0 -with /* TPC-DS query78.tpl 0.10 */ ws as - (select d_year AS ws_sold_year, ws_item_sk, - ws_bill_customer_sk ws_customer_sk, - sum(ws_quantity) ws_qty, - sum(ws_wholesale_cost) ws_wc, - sum(ws_sales_price) ws_sp - from web_sales - left join web_returns on wr_order_number=ws_order_number and ws_item_sk=wr_item_sk - join date_dim on ws_sold_date_sk = d_date_sk - where wr_order_number is null - group by d_year, ws_item_sk, ws_bill_customer_sk - ), -cs as - (select d_year AS cs_sold_year, cs_item_sk, - cs_bill_customer_sk cs_customer_sk, - sum(cs_quantity) cs_qty, - sum(cs_wholesale_cost) cs_wc, - sum(cs_sales_price) cs_sp - from catalog_sales - left join catalog_returns on cr_order_number=cs_order_number and cs_item_sk=cr_item_sk - join date_dim on cs_sold_date_sk = d_date_sk - where cr_order_number is null - group by d_year, cs_item_sk, cs_bill_customer_sk - ), -ss as - (select d_year AS ss_sold_year, ss_item_sk, - ss_customer_sk, - sum(ss_quantity) ss_qty, - sum(ss_wholesale_cost) ss_wc, - sum(ss_sales_price) ss_sp - from store_sales - left join store_returns on sr_ticket_number=ss_ticket_number and ss_item_sk=sr_item_sk - join date_dim on ss_sold_date_sk = d_date_sk - where sr_ticket_number is null - group by d_year, ss_item_sk, ss_customer_sk - ) - select -ss_customer_sk, -round(ss_qty/(coalesce(ws_qty,0)+coalesce(cs_qty,0)),2) ratio, -ss_qty store_qty, ss_wc store_wholesale_cost, ss_sp store_sales_price, -coalesce(ws_qty,0)+coalesce(cs_qty,0) other_chan_qty, -coalesce(ws_wc,0)+coalesce(cs_wc,0) other_chan_wholesale_cost, -coalesce(ws_sp,0)+coalesce(cs_sp,0) other_chan_sales_price -from ss -left join ws on (ws_sold_year=ss_sold_year and ws_item_sk=ss_item_sk and ws_customer_sk=ss_customer_sk) -left join cs on (cs_sold_year=ss_sold_year and cs_item_sk=ss_item_sk and cs_customer_sk=ss_customer_sk) -where (coalesce(ws_qty,0)>0 or coalesce(cs_qty, 0)>0) and ss_sold_year=2001 -order by - ss_customer_sk, - ss_qty desc, ss_wc desc, ss_sp desc, - other_chan_qty, - other_chan_wholesale_cost, - other_chan_sales_price, - ratio -limit 100; - --- end template query78.tpl query 10 in stream 0 --- start template query86a.tpl query 11 in stream 0 -with /* TPC-DS query86a.tpl 0.11 */ results as -( select sum(ws_net_paid) as total_sum, i_category, i_class, 0 as g_category, 0 as g_class - from - web_sales - ,date_dim d1 - ,item - where - d1.d_month_seq between 1205 and 1205+11 - and d1.d_date_sk = ws_sold_date_sk - and i_item_sk = ws_item_sk - group by i_category,i_class - ) , - - results_rollup as -( select total_sum ,i_category ,i_class, g_category, g_class, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum, i_category, NULL as i_class, 0 as g_category, 1 as g_class, 1 as lochierarchy from results group by i_category - union - select sum(total_sum) as total_sum, NULL as i_category, NULL as i_class, 1 as g_category, 1 as g_class, 2 as lochierarchy from results) - select - total_sum ,i_category ,i_class, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_class = 0 then i_category end - order by total_sum desc) as rank_within_parent - from - results_rollup - order by - lochierarchy desc, - case when lochierarchy = 0 then i_category end, - rank_within_parent - limit 100; - --- end template query86a.tpl query 11 in stream 0 --- start template query1.tpl query 12 in stream 0 -with /* TPC-DS query1.tpl 0.12 */ customer_total_return as -(select sr_customer_sk as ctr_customer_sk -,sr_store_sk as ctr_store_sk -,sum(SR_RETURN_AMT_INC_TAX) as ctr_total_return -from store_returns -,date_dim -where sr_returned_date_sk = d_date_sk -and d_year =1999 -group by sr_customer_sk -,sr_store_sk) - select c_customer_id -from customer_total_return ctr1 -,store -,customer -where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 -from customer_total_return ctr2 -where ctr1.ctr_store_sk = ctr2.ctr_store_sk) -and s_store_sk = ctr1.ctr_store_sk -and s_state = 'VA' -and ctr1.ctr_customer_sk = c_customer_sk -order by c_customer_id -limit 100; - --- end template query1.tpl query 12 in stream 0 --- start template query91.tpl query 13 in stream 0 -select /* TPC-DS query91.tpl 0.13 */ - cc_call_center_id Call_Center, - cc_name Call_Center_Name, - cc_manager Manager, - sum(cr_net_loss) Returns_Loss -from - call_center, - catalog_returns, - date_dim, - customer, - customer_address, - customer_demographics, - household_demographics -where - cr_call_center_sk = cc_call_center_sk -and cr_returned_date_sk = d_date_sk -and cr_returning_customer_sk= c_customer_sk -and cd_demo_sk = c_current_cdemo_sk -and hd_demo_sk = c_current_hdemo_sk -and ca_address_sk = c_current_addr_sk -and d_year = 2002 -and d_moy = 11 -and ( (cd_marital_status = 'M' and cd_education_status = 'Unknown') - or(cd_marital_status = 'W' and cd_education_status = 'Advanced Degree')) -and hd_buy_potential like 'Unknown%' -and ca_gmt_offset = -6 -group by cc_call_center_id,cc_name,cc_manager,cd_marital_status,cd_education_status -order by sum(cr_net_loss) desc; - --- end template query91.tpl query 13 in stream 0 --- start template query21.tpl query 14 in stream 0 -select /* TPC-DS query21.tpl 0.14 */ * - from(select w_warehouse_name - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('2000-05-19' as date)) - then inv_quantity_on_hand - else 0 end) as inv_before - ,sum(case when (cast(d_date as date) >= cast ('2000-05-19' as date)) - then inv_quantity_on_hand - else 0 end) as inv_after - from inventory - ,warehouse - ,item - ,date_dim - where i_current_price between 0.99 and 1.49 - and i_item_sk = inv_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('2000-05-19' as date)) - and dateadd(day,30,cast ('2000-05-19' as date)) - group by w_warehouse_name, i_item_id) x - where (case when inv_before > 0 - then inv_after / inv_before - else null - end) between 2.0/3.0 and 3.0/2.0 - order by w_warehouse_name - ,i_item_id - limit 100; - --- end template query21.tpl query 14 in stream 0 --- start template query43.tpl query 15 in stream 0 -select /* TPC-DS query43.tpl 0.15 */ s_store_name, s_store_id, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from date_dim, store_sales, store - where d_date_sk = ss_sold_date_sk and - s_store_sk = ss_store_sk and - s_gmt_offset = -5 and - d_year = 2000 - group by s_store_name, s_store_id - order by s_store_name, s_store_id,sun_sales,mon_sales,tue_sales,wed_sales,thu_sales,fri_sales,sat_sales - limit 100; - --- end template query43.tpl query 15 in stream 0 --- start template query27a.tpl query 16 in stream 0 -with /* TPC-DS query27a.tpl 0.16 */ results as - (select i_item_id, - s_state, 0 as g_state, - ss_quantity agg1, - ss_list_price agg2, - ss_coupon_amt agg3, - ss_sales_price agg4 - from store_sales, customer_demographics, date_dim, store, item - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_store_sk = s_store_sk and - ss_cdemo_sk = cd_demo_sk and - cd_gender = 'F' and - cd_marital_status = 'U' and - cd_education_status = 'Primary' and - d_year = 2002 and - s_state in ('MN','MO', 'VT', 'CO', 'IL', 'SD') - ) - - select i_item_id, - s_state, g_state, agg1, agg2, agg3, agg4 - from ( - select i_item_id, s_state, 0 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4 from results - group by i_item_id, s_state - union all - select i_item_id, NULL AS s_state, 1 AS g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as s_state, 1 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - ) foo - order by i_item_id, s_state - limit 100; - --- end template query27a.tpl query 16 in stream 0 --- start template query94.tpl query 17 in stream 0 -select /* TPC-DS query94.tpl 0.17 */ - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2001-2-01' and - dateadd(day,60,cast('2001-2-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'AL' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and exists (select * - from web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) -and not exists(select * - from web_returns wr1 - where ws1.ws_order_number = wr1.wr_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query94.tpl query 17 in stream 0 --- start template query45.tpl query 18 in stream 0 -select /* TPC-DS query45.tpl 0.18 */ ca_zip, ca_state, sum(ws_sales_price) - from web_sales, customer, customer_address, date_dim, item - where ws_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ws_item_sk = i_item_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', '85392', '85460', '80348', '81792') - or - i_item_id in (select i_item_id - from item - where i_item_sk in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29) - ) - ) - and ws_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 2001 - group by ca_zip, ca_state - order by ca_zip, ca_state - limit 100; - --- end template query45.tpl query 18 in stream 0 --- start template query58.tpl query 19 in stream 0 -with /* TPC-DS query58.tpl 0.19 */ ss_items as - (select i_item_id item_id - ,sum(ss_ext_sales_price) ss_item_rev - from store_sales - ,item - ,date_dim - where ss_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '2000-02-01')) - and ss_sold_date_sk = d_date_sk - group by i_item_id), - cs_items as - (select i_item_id item_id - ,sum(cs_ext_sales_price) cs_item_rev - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '2000-02-01')) - and cs_sold_date_sk = d_date_sk - group by i_item_id), - ws_items as - (select i_item_id item_id - ,sum(ws_ext_sales_price) ws_item_rev - from web_sales - ,item - ,date_dim - where ws_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq =(select d_week_seq - from date_dim - where d_date = '2000-02-01')) - and ws_sold_date_sk = d_date_sk - group by i_item_id) - select ss_items.item_id - ,ss_item_rev - ,ss_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ss_dev - ,cs_item_rev - ,cs_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 cs_dev - ,ws_item_rev - ,ws_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ws_dev - ,(ss_item_rev+cs_item_rev+ws_item_rev)/3 average - from ss_items,cs_items,ws_items - where ss_items.item_id=cs_items.item_id - and ss_items.item_id=ws_items.item_id - and ss_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - and ss_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and cs_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and cs_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and ws_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and ws_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - order by item_id - ,ss_item_rev - limit 100; - --- end template query58.tpl query 19 in stream 0 --- start template query64.tpl query 20 in stream 0 -with /* TPC-DS query64.tpl 0.20 */ cs_ui as - (select cs_item_sk - ,sum(cs_ext_list_price) as sale,sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit) as refund - from catalog_sales - ,catalog_returns - where cs_item_sk = cr_item_sk - and cs_order_number = cr_order_number - group by cs_item_sk - having sum(cs_ext_list_price)>2*sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit)), -cross_sales as - (select i_product_name product_name - ,i_item_sk item_sk - ,s_store_name store_name - ,s_zip store_zip - ,ad1.ca_street_number b_street_number - ,ad1.ca_street_name b_street_name - ,ad1.ca_city b_city - ,ad1.ca_zip b_zip - ,ad2.ca_street_number c_street_number - ,ad2.ca_street_name c_street_name - ,ad2.ca_city c_city - ,ad2.ca_zip c_zip - ,d1.d_year as syear - ,d2.d_year as fsyear - ,d3.d_year s2year - ,count(*) cnt - ,sum(ss_wholesale_cost) s1 - ,sum(ss_list_price) s2 - ,sum(ss_coupon_amt) s3 - FROM store_sales - ,store_returns - ,cs_ui - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,customer - ,customer_demographics cd1 - ,customer_demographics cd2 - ,promotion - ,household_demographics hd1 - ,household_demographics hd2 - ,customer_address ad1 - ,customer_address ad2 - ,income_band ib1 - ,income_band ib2 - ,item - WHERE ss_store_sk = s_store_sk AND - ss_sold_date_sk = d1.d_date_sk AND - ss_customer_sk = c_customer_sk AND - ss_cdemo_sk= cd1.cd_demo_sk AND - ss_hdemo_sk = hd1.hd_demo_sk AND - ss_addr_sk = ad1.ca_address_sk and - ss_item_sk = i_item_sk and - ss_item_sk = sr_item_sk and - ss_ticket_number = sr_ticket_number and - ss_item_sk = cs_ui.cs_item_sk and - c_current_cdemo_sk = cd2.cd_demo_sk AND - c_current_hdemo_sk = hd2.hd_demo_sk AND - c_current_addr_sk = ad2.ca_address_sk and - c_first_sales_date_sk = d2.d_date_sk and - c_first_shipto_date_sk = d3.d_date_sk and - ss_promo_sk = p_promo_sk and - hd1.hd_income_band_sk = ib1.ib_income_band_sk and - hd2.hd_income_band_sk = ib2.ib_income_band_sk and - cd1.cd_marital_status <> cd2.cd_marital_status and - i_color in ('sky','smoke','honeydew','cyan','powder','medium') and - i_current_price between 38 and 38 + 10 and - i_current_price between 38 + 1 and 38 + 15 -group by i_product_name - ,i_item_sk - ,s_store_name - ,s_zip - ,ad1.ca_street_number - ,ad1.ca_street_name - ,ad1.ca_city - ,ad1.ca_zip - ,ad2.ca_street_number - ,ad2.ca_street_name - ,ad2.ca_city - ,ad2.ca_zip - ,d1.d_year - ,d2.d_year - ,d3.d_year -) -select cs1.product_name - ,cs1.store_name - ,cs1.store_zip - ,cs1.b_street_number - ,cs1.b_street_name - ,cs1.b_city - ,cs1.b_zip - ,cs1.c_street_number - ,cs1.c_street_name - ,cs1.c_city - ,cs1.c_zip - ,cs1.syear - ,cs1.cnt - ,cs1.s1 as s11 - ,cs1.s2 as s21 - ,cs1.s3 as s31 - ,cs2.s1 as s12 - ,cs2.s2 as s22 - ,cs2.s3 as s32 - ,cs2.syear - ,cs2.cnt -from cross_sales cs1,cross_sales cs2 -where cs1.item_sk=cs2.item_sk and - cs1.syear = 2001 and - cs2.syear = 2001 + 1 and - cs2.cnt <= cs1.cnt and - cs1.store_name = cs2.store_name and - cs1.store_zip = cs2.store_zip -order by cs1.product_name - ,cs1.store_name - ,cs2.cnt - ,cs1.s1 - ,cs2.s1; - --- end template query64.tpl query 20 in stream 0 --- start template query36a.tpl query 21 in stream 0 -with /* TPC-DS query36a.tpl 0.21 */ results as - (select - sum(ss_net_profit) as ss_net_profit, sum(ss_ext_sales_price) as ss_ext_sales_price, - sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin - ,i_category - ,i_class - ,0 as g_category, 0 as g_class - from - store_sales - ,date_dim d1 - ,item - ,store - where - d1.d_year = 2000 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and s_state in ('MO','GA','KS','NM', - 'MI','VT','AL','KS') - group by i_category,i_class) - , - results_rollup as - (select gross_margin ,i_category ,i_class,0 as t_category, 0 as t_class, 0 as lochierarchy from results - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - i_category, NULL AS i_class, 0 as t_category, 1 as t_class, 1 as lochierarchy from results group by i_category - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - NULL AS i_category ,NULL AS i_class, 1 as t_category, 1 as t_class, 2 as lochierarchy from results) - select - gross_margin ,i_category ,i_class, lochierarchy,rank() over ( - partition by lochierarchy, case when t_class = 0 then i_category end - order by gross_margin asc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then i_category end - ,rank_within_parent - limit 100; - --- end template query36a.tpl query 21 in stream 0 --- start template query33.tpl query 22 in stream 0 -with /* TPC-DS query33.tpl 0.22 */ ss as ( - select - i_manufact_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Electronics')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 6 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id), - cs as ( - select - i_manufact_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Electronics')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 6 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id), - ws as ( - select - i_manufact_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Electronics')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 6 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id) - select i_manufact_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_manufact_id - order by total_sales -limit 100; - --- end template query33.tpl query 22 in stream 0 --- start template query46.tpl query 23 in stream 0 -select /* TPC-DS query46.tpl 0.23 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and (household_demographics.hd_dep_count = 8 or - household_demographics.hd_vehicle_count= 1) - and date_dim.d_dow in (6,0) - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_city in ('Highland','Cedar Springs','Mill Creek','Forest Hills','Oakdale') - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,ca_city) dn,customer,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - limit 100; - --- end template query46.tpl query 23 in stream 0 --- start template query62.tpl query 24 in stream 0 -select /* TPC-DS query62.tpl 0.24 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 30) and - (ws_ship_date_sk - ws_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 60) and - (ws_ship_date_sk - ws_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 90) and - (ws_ship_date_sk - ws_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - web_sales - ,warehouse - ,ship_mode - ,web_site - ,date_dim -where - d_month_seq between 1196 and 1196 + 11 -and ws_ship_date_sk = d_date_sk -and ws_warehouse_sk = w_warehouse_sk -and ws_ship_mode_sk = sm_ship_mode_sk -and ws_web_site_sk = web_site_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -limit 100; - --- end template query62.tpl query 24 in stream 0 --- start template query16.tpl query 25 in stream 0 -select /* TPC-DS query16.tpl 0.25 */ - count(distinct cs_order_number) as "order count" - ,sum(cs_ext_ship_cost) as "total shipping cost" - ,sum(cs_net_profit) as "total net profit" -from - catalog_sales cs1 - ,date_dim - ,customer_address - ,call_center -where - d_date between '2000-2-01' and - dateadd(day, 60, cast('2000-2-01' as date)) -and cs1.cs_ship_date_sk = d_date_sk -and cs1.cs_ship_addr_sk = ca_address_sk -and ca_state = 'NC' -and cs1.cs_call_center_sk = cc_call_center_sk -and cc_county in ('Jefferson Davis Parish','Franklin Parish','Daviess County','San Miguel County', - 'Mobile County' -) -and exists (select * - from catalog_sales cs2 - where cs1.cs_order_number = cs2.cs_order_number - and cs1.cs_warehouse_sk <> cs2.cs_warehouse_sk) -and not exists(select * - from catalog_returns cr1 - where cs1.cs_order_number = cr1.cr_order_number) -order by count(distinct cs_order_number) -limit 100; - --- end template query16.tpl query 25 in stream 0 --- start template query10.tpl query 26 in stream 0 -select /* TPC-DS query10.tpl 0.26 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3, - cd_dep_count, - count(*) cnt4, - cd_dep_employed_count, - count(*) cnt5, - cd_dep_college_count, - count(*) cnt6 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_county in ('Chenango County','Josephine County','Lincoln County','Westchester County','Ripley County') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 1 and 1+3) and - (exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 1 ANd 1+3) or - exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 1 and 1+3)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count -limit 100; - --- end template query10.tpl query 26 in stream 0 --- start template query63.tpl query 27 in stream 0 -select /* TPC-DS query63.tpl 0.27 */ * -from (select i_manager_id - ,sum(ss_sales_price) sum_sales - ,avg(sum(ss_sales_price)) over (partition by i_manager_id) avg_monthly_sales - from item - ,store_sales - ,date_dim - ,store - where ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and d_month_seq in (1189,1189+1,1189+2,1189+3,1189+4,1189+5,1189+6,1189+7,1189+8,1189+9,1189+10,1189+11) - and (( i_category in ('Books','Children','Electronics') - and i_class in ('personal','portable','reference','self-help') - and i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) - or( i_category in ('Women','Music','Men') - and i_class in ('accessories','classical','fragrances','pants') - and i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manager_id, d_moy) tmp1 -where case when avg_monthly_sales > 0 then abs (sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 -order by i_manager_id - ,avg_monthly_sales - ,sum_sales -limit 100; - --- end template query63.tpl query 27 in stream 0 --- start template query69.tpl query 28 in stream 0 -select /* TPC-DS query69.tpl 0.28 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_state in ('AL','FL','NC') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 4 and 4+2) and - (not exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 4 and 4+2) and - not exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 4 and 4+2)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - limit 100; - --- end template query69.tpl query 28 in stream 0 --- start template query60.tpl query 29 in stream 0 -with /* TPC-DS query60.tpl 0.29 */ ss as ( - select - i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Shoes')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 8 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id), - cs as ( - select - i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Shoes')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 8 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id), - ws as ( - select - i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Shoes')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 8 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id) - select - i_item_id -,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by i_item_id - ,total_sales - limit 100; - --- end template query60.tpl query 29 in stream 0 --- start template query59.tpl query 30 in stream 0 -with /* TPC-DS query59.tpl 0.30 */ wss as - (select d_week_seq, - ss_store_sk, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - group by d_week_seq,ss_store_sk - ) - select s_store_name1,s_store_id1,d_week_seq1 - ,sun_sales1/sun_sales2,mon_sales1/mon_sales2 - ,tue_sales1/tue_sales2,wed_sales1/wed_sales2,thu_sales1/thu_sales2 - ,fri_sales1/fri_sales2,sat_sales1/sat_sales2 - from - (select s_store_name s_store_name1,wss.d_week_seq d_week_seq1 - ,s_store_id s_store_id1,sun_sales sun_sales1 - ,mon_sales mon_sales1,tue_sales tue_sales1 - ,wed_sales wed_sales1,thu_sales thu_sales1 - ,fri_sales fri_sales1,sat_sales sat_sales1 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1204 and 1204 + 11) y, - (select s_store_name s_store_name2,wss.d_week_seq d_week_seq2 - ,s_store_id s_store_id2,sun_sales sun_sales2 - ,mon_sales mon_sales2,tue_sales tue_sales2 - ,wed_sales wed_sales2,thu_sales thu_sales2 - ,fri_sales fri_sales2,sat_sales sat_sales2 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1204+ 12 and 1204 + 23) x - where s_store_id1=s_store_id2 - and d_week_seq1=d_week_seq2-52 - order by s_store_name1,s_store_id1,d_week_seq1 -limit 100; - --- end template query59.tpl query 30 in stream 0 --- start template query37.tpl query 31 in stream 0 -select /* TPC-DS query37.tpl 0.31 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, catalog_sales - where i_current_price between 38 and 38 + 30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('2002-05-14' as date) and dateadd(day,60,cast('2002-05-14' as date)) - and i_manufact_id in (805,765,688,790) - and inv_quantity_on_hand between 100 and 500 - and cs_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query37.tpl query 31 in stream 0 --- start template query98.tpl query 32 in stream 0 -select /* TPC-DS query98.tpl 0.32 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ss_ext_sales_price) as itemrevenue - ,sum(ss_ext_sales_price)*100/sum(sum(ss_ext_sales_price)) over - (partition by i_class) as revenueratio -from - store_sales - ,item - ,date_dim -where - ss_item_sk = i_item_sk - and i_category in ('Shoes', 'Books', 'Home') - and ss_sold_date_sk = d_date_sk - and d_date between cast('2001-02-24' as date) - and dateadd(day,30,cast('2001-02-24' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio; - --- end template query98.tpl query 32 in stream 0 --- start template query85.tpl query 33 in stream 0 -select /* TPC-DS query85.tpl 0.33 */ substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) - from web_sales, web_returns, web_page, customer_demographics cd1, - customer_demographics cd2, customer_address, date_dim, reason - where ws_web_page_sk = wp_web_page_sk - and ws_item_sk = wr_item_sk - and ws_order_number = wr_order_number - and ws_sold_date_sk = d_date_sk and d_year = 2002 - and cd1.cd_demo_sk = wr_refunded_cdemo_sk - and cd2.cd_demo_sk = wr_returning_cdemo_sk - and ca_address_sk = wr_refunded_addr_sk - and r_reason_sk = wr_reason_sk - and - ( - ( - cd1.cd_marital_status = 'D' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Unknown' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 100.00 and 150.00 - ) - or - ( - cd1.cd_marital_status = 'U' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Primary' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 50.00 and 100.00 - ) - or - ( - cd1.cd_marital_status = 'M' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = '2 yr Degree' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ca_country = 'United States' - and - ca_state in ('KS', 'WY', 'UT') - and ws_net_profit between 100 and 200 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('TX', 'CO', 'NC') - and ws_net_profit between 150 and 300 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('CA', 'ID', 'ND') - and ws_net_profit between 50 and 250 - ) - ) -group by r_reason_desc -order by substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) -limit 100; - --- end template query85.tpl query 33 in stream 0 --- start template query70a.tpl query 34 in stream 0 -with /* TPC-DS query70a.tpl 0.34 */ results as -( select - sum(ss_net_profit) as total_sum ,s_state ,s_county, 0 as gstate, 0 as g_county - from - store_sales - ,date_dim d1 - ,store - where - d1.d_month_seq between 1196 and 1196 + 11 - and d1.d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - and s_state in - ( select s_state - from (select s_state as s_state, - rank() over ( partition by s_state order by sum(ss_net_profit) desc) as ranking - from store_sales, store, date_dim - where d_month_seq between 1196 and 1196 + 11 - and d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - group by s_state - ) tmp1 - where ranking <= 5) - group by s_state,s_county) , - results_rollup as -(select total_sum ,s_state ,s_county, 0 as g_state, 0 as g_county, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum,s_state, NULL as s_county, 0 as g_state, 1 as g_county, 1 as lochierarchy from results group by s_state - union - select sum(total_sum) as total_sum ,NULL as s_state ,NULL as s_county, 1 as g_state, 1 as g_county, 2 as lochierarchy from results) - select total_sum ,s_state ,s_county, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_county = 0 then s_state end - order by total_sum desc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then s_state end - ,rank_within_parent - limit 100; - --- end template query70a.tpl query 34 in stream 0 --- start template query67a.tpl query 35 in stream 0 -with /* TPC-DS query67a.tpl 0.35 */ results as -( select i_category ,i_class ,i_brand ,i_product_name ,d_year ,d_qoy ,d_moy ,s_store_id - ,sum(coalesce(ss_sales_price*ss_quantity,0)) sumsales - from store_sales ,date_dim ,store ,item - where ss_sold_date_sk=d_date_sk - and ss_item_sk=i_item_sk - and ss_store_sk = s_store_sk - and d_month_seq between 1177 and 1177 + 11 - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy,s_store_id) - , - results_rollup as - (select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, s_store_id, sumsales - from results - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy - union all - select i_category, i_class, i_brand, i_product_name, d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year - union all - select i_category, i_class, i_brand, i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name - union all - select i_category, i_class, i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand - union all - select i_category, i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class - union all - select i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category - union all - select null i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results) - - select * -from (select i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rank() over (partition by i_category order by sumsales desc) rk - from results_rollup) dw2 -where rk <= 100 -order by i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rk -limit 100; - --- end template query67a.tpl query 35 in stream 0 --- start template query28.tpl query 36 in stream 0 -select /* TPC-DS query28.tpl 0.36 */ * -from (select avg(ss_list_price) B1_LP - ,count(ss_list_price) B1_CNT - ,count(distinct ss_list_price) B1_CNTD - from store_sales - where ss_quantity between 0 and 5 - and (ss_list_price between 69 and 69+10 - or ss_coupon_amt between 11959 and 11959+1000 - or ss_wholesale_cost between 56 and 56+20)) B1, - (select avg(ss_list_price) B2_LP - ,count(ss_list_price) B2_CNT - ,count(distinct ss_list_price) B2_CNTD - from store_sales - where ss_quantity between 6 and 10 - and (ss_list_price between 135 and 135+10 - or ss_coupon_amt between 17995 and 17995+1000 - or ss_wholesale_cost between 48 and 48+20)) B2, - (select avg(ss_list_price) B3_LP - ,count(ss_list_price) B3_CNT - ,count(distinct ss_list_price) B3_CNTD - from store_sales - where ss_quantity between 11 and 15 - and (ss_list_price between 88 and 88+10 - or ss_coupon_amt between 15887 and 15887+1000 - or ss_wholesale_cost between 22 and 22+20)) B3, - (select avg(ss_list_price) B4_LP - ,count(ss_list_price) B4_CNT - ,count(distinct ss_list_price) B4_CNTD - from store_sales - where ss_quantity between 16 and 20 - and (ss_list_price between 46 and 46+10 - or ss_coupon_amt between 12707 and 12707+1000 - or ss_wholesale_cost between 18 and 18+20)) B4, - (select avg(ss_list_price) B5_LP - ,count(ss_list_price) B5_CNT - ,count(distinct ss_list_price) B5_CNTD - from store_sales - where ss_quantity between 21 and 25 - and (ss_list_price between 54 and 54+10 - or ss_coupon_amt between 162 and 162+1000 - or ss_wholesale_cost between 20 and 20+20)) B5, - (select avg(ss_list_price) B6_LP - ,count(ss_list_price) B6_CNT - ,count(distinct ss_list_price) B6_CNTD - from store_sales - where ss_quantity between 26 and 30 - and (ss_list_price between 155 and 155+10 - or ss_coupon_amt between 16045 and 16045+1000 - or ss_wholesale_cost between 26 and 26+20)) B6 -limit 100; - --- end template query28.tpl query 36 in stream 0 --- start template query81.tpl query 37 in stream 0 -with /* TPC-DS query81.tpl 0.37 */ customer_total_return as - (select cr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(cr_return_amt_inc_tax) as ctr_total_return - from catalog_returns - ,date_dim - ,customer_address - where cr_returned_date_sk = d_date_sk - and d_year =2000 - and cr_returning_addr_sk = ca_address_sk - group by cr_returning_customer_sk - ,ca_state ) - select c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'NC' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - limit 100; - --- end template query81.tpl query 37 in stream 0 --- start template query97.tpl query 38 in stream 0 -with /* TPC-DS query97.tpl 0.38 */ ssci as ( -select ss_customer_sk customer_sk - ,ss_item_sk item_sk -from store_sales,date_dim -where ss_sold_date_sk = d_date_sk - and d_month_seq between 1199 and 1199 + 11 -group by ss_customer_sk - ,ss_item_sk), -csci as( - select cs_bill_customer_sk customer_sk - ,cs_item_sk item_sk -from catalog_sales,date_dim -where cs_sold_date_sk = d_date_sk - and d_month_seq between 1199 and 1199 + 11 -group by cs_bill_customer_sk - ,cs_item_sk) - select sum(case when ssci.customer_sk is not null and csci.customer_sk is null then 1 else 0 end) store_only - ,sum(case when ssci.customer_sk is null and csci.customer_sk is not null then 1 else 0 end) catalog_only - ,sum(case when ssci.customer_sk is not null and csci.customer_sk is not null then 1 else 0 end) store_and_catalog -from ssci full outer join csci on (ssci.customer_sk=csci.customer_sk - and ssci.item_sk = csci.item_sk) -limit 100; - --- end template query97.tpl query 38 in stream 0 --- start template query66.tpl query 39 in stream 0 -select /* TPC-DS query66.tpl 0.39 */ - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - ,sum(jan_sales) as jan_sales - ,sum(feb_sales) as feb_sales - ,sum(mar_sales) as mar_sales - ,sum(apr_sales) as apr_sales - ,sum(may_sales) as may_sales - ,sum(jun_sales) as jun_sales - ,sum(jul_sales) as jul_sales - ,sum(aug_sales) as aug_sales - ,sum(sep_sales) as sep_sales - ,sum(oct_sales) as oct_sales - ,sum(nov_sales) as nov_sales - ,sum(dec_sales) as dec_sales - ,sum(jan_sales/w_warehouse_sq_ft) as jan_sales_per_sq_foot - ,sum(feb_sales/w_warehouse_sq_ft) as feb_sales_per_sq_foot - ,sum(mar_sales/w_warehouse_sq_ft) as mar_sales_per_sq_foot - ,sum(apr_sales/w_warehouse_sq_ft) as apr_sales_per_sq_foot - ,sum(may_sales/w_warehouse_sq_ft) as may_sales_per_sq_foot - ,sum(jun_sales/w_warehouse_sq_ft) as jun_sales_per_sq_foot - ,sum(jul_sales/w_warehouse_sq_ft) as jul_sales_per_sq_foot - ,sum(aug_sales/w_warehouse_sq_ft) as aug_sales_per_sq_foot - ,sum(sep_sales/w_warehouse_sq_ft) as sep_sales_per_sq_foot - ,sum(oct_sales/w_warehouse_sq_ft) as oct_sales_per_sq_foot - ,sum(nov_sales/w_warehouse_sq_ft) as nov_sales_per_sq_foot - ,sum(dec_sales/w_warehouse_sq_ft) as dec_sales_per_sq_foot - ,sum(jan_net) as jan_net - ,sum(feb_net) as feb_net - ,sum(mar_net) as mar_net - ,sum(apr_net) as apr_net - ,sum(may_net) as may_net - ,sum(jun_net) as jun_net - ,sum(jul_net) as jul_net - ,sum(aug_net) as aug_net - ,sum(sep_net) as sep_net - ,sum(oct_net) as oct_net - ,sum(nov_net) as nov_net - ,sum(dec_net) as dec_net - from ( - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'MSC' || ',' || 'GREAT EASTERN' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then ws_ext_sales_price* ws_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then ws_ext_sales_price* ws_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then ws_ext_sales_price* ws_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then ws_ext_sales_price* ws_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then ws_ext_sales_price* ws_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then ws_ext_sales_price* ws_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then ws_ext_sales_price* ws_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then ws_ext_sales_price* ws_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then ws_ext_sales_price* ws_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then ws_ext_sales_price* ws_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then ws_ext_sales_price* ws_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then ws_ext_sales_price* ws_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as dec_net - from - web_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - ws_warehouse_sk = w_warehouse_sk - and ws_sold_date_sk = d_date_sk - and ws_sold_time_sk = t_time_sk - and ws_ship_mode_sk = sm_ship_mode_sk - and d_year = 1998 - and t_time between 38384 and 38384+28800 - and sm_carrier in ('MSC','GREAT EASTERN') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - union all - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'MSC' || ',' || 'GREAT EASTERN' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then cs_ext_list_price* cs_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then cs_ext_list_price* cs_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then cs_ext_list_price* cs_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then cs_ext_list_price* cs_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then cs_ext_list_price* cs_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then cs_ext_list_price* cs_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then cs_ext_list_price* cs_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then cs_ext_list_price* cs_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then cs_ext_list_price* cs_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then cs_ext_list_price* cs_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then cs_ext_list_price* cs_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then cs_ext_list_price* cs_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as dec_net - from - catalog_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and cs_sold_time_sk = t_time_sk - and cs_ship_mode_sk = sm_ship_mode_sk - and d_year = 1998 - and t_time between 38384 AND 38384+28800 - and sm_carrier in ('MSC','GREAT EASTERN') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - ) x - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - order by w_warehouse_name - limit 100; - --- end template query66.tpl query 39 in stream 0 --- start template query90.tpl query 40 in stream 0 -select /* TPC-DS query90.tpl 0.40 */ cast(amc as decimal(15,4))/cast(pmc as decimal(15,4)) am_pm_ratio - from ( select count(*) amc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 11 and 11+1 - and household_demographics.hd_dep_count = 0 - and web_page.wp_char_count between 5000 and 5200) at, - ( select count(*) pmc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 16 and 16+1 - and household_demographics.hd_dep_count = 0 - and web_page.wp_char_count between 5000 and 5200) pt - order by am_pm_ratio - limit 100; - --- end template query90.tpl query 40 in stream 0 --- start template query17.tpl query 41 in stream 0 -select /* TPC-DS query17.tpl 0.41 */ i_item_id - ,i_item_desc - ,s_state - ,count(ss_quantity) as store_sales_quantitycount - ,avg(ss_quantity) as store_sales_quantityave - ,stddev_samp(ss_quantity) as store_sales_quantitystdev - ,stddev_samp(ss_quantity)/avg(ss_quantity) as store_sales_quantitycov - ,count(sr_return_quantity) as store_returns_quantitycount - ,avg(sr_return_quantity) as store_returns_quantityave - ,stddev_samp(sr_return_quantity) as store_returns_quantitystdev - ,stddev_samp(sr_return_quantity)/avg(sr_return_quantity) as store_returns_quantitycov - ,count(cs_quantity) as catalog_sales_quantitycount ,avg(cs_quantity) as catalog_sales_quantityave - ,stddev_samp(cs_quantity) as catalog_sales_quantitystdev - ,stddev_samp(cs_quantity)/avg(cs_quantity) as catalog_sales_quantitycov - from store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where d1.d_quarter_name = '1999Q1' - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_quarter_name in ('1999Q1','1999Q2','1999Q3') - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_quarter_name in ('1999Q1','1999Q2','1999Q3') - group by i_item_id - ,i_item_desc - ,s_state - order by i_item_id - ,i_item_desc - ,s_state -limit 100; - --- end template query17.tpl query 41 in stream 0 --- start template query47.tpl query 42 in stream 0 -with /* TPC-DS query47.tpl 0.42 */ v1 as( - select i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, - s_store_name, s_company_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - s_store_name, s_company_name - order by d_year, d_moy) rn - from item, store_sales, date_dim, store - where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - ( - d_year = 1999 or - ( d_year = 1999-1 and d_moy =12) or - ( d_year = 1999+1 and d_moy =1) - ) - group by i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy), - v2 as( - select v1.s_company_name - ,v1.d_year, v1.d_moy - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1.s_store_name = v1_lag.s_store_name and - v1.s_store_name = v1_lead.s_store_name and - v1.s_company_name = v1_lag.s_company_name and - v1.s_company_name = v1_lead.s_company_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 1999 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, nsum - limit 100; - --- end template query47.tpl query 42 in stream 0 --- start template query95.tpl query 43 in stream 0 -with /* TPC-DS query95.tpl 0.43 */ ws_wh as -(select ws1.ws_order_number,ws1.ws_warehouse_sk wh1,ws2.ws_warehouse_sk wh2 - from web_sales ws1,web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) - select - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2001-2-01' and - dateadd(day,60,cast('2001-2-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'PA' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and ws1.ws_order_number in (select ws_order_number - from ws_wh) -and ws1.ws_order_number in (select wr_order_number - from web_returns,ws_wh - where wr_order_number = ws_wh.ws_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query95.tpl query 43 in stream 0 --- start template query92.tpl query 44 in stream 0 -select /* TPC-DS query92.tpl 0.44 */ - sum(ws_ext_discount_amt) as "Excess Discount Amount" -from - web_sales - ,item - ,date_dim -where -i_manufact_id = 438 -and i_item_sk = ws_item_sk -and d_date between '1999-03-21' and - dateadd(day,90,cast('1999-03-21' as date)) -and d_date_sk = ws_sold_date_sk -and ws_ext_discount_amt - > ( - SELECT - 1.3 * avg(ws_ext_discount_amt) - FROM - web_sales - ,date_dim - WHERE - ws_item_sk = i_item_sk - and d_date between '1999-03-21' and - dateadd(day,90,cast('1999-03-21' as date)) - and d_date_sk = ws_sold_date_sk - ) -order by sum(ws_ext_discount_amt) -limit 100; - --- end template query92.tpl query 44 in stream 0 --- start template query3.tpl query 45 in stream 0 -select /* TPC-DS query3.tpl 0.45 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_net_profit) sum_agg - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manufact_id = 901 - and dt.d_moy=12 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,sum_agg desc - ,brand_id - limit 100; - --- end template query3.tpl query 45 in stream 0 --- start template query51.tpl query 46 in stream 0 -WITH /* TPC-DS query51.tpl 0.46 */ web_v1 as ( -select - ws_item_sk item_sk, d_date, - sum(sum(ws_sales_price)) - over (partition by ws_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from web_sales - ,date_dim -where ws_sold_date_sk=d_date_sk - and d_month_seq between 1181 and 1181+11 - and ws_item_sk is not NULL -group by ws_item_sk, d_date), -store_v1 as ( -select - ss_item_sk item_sk, d_date, - sum(sum(ss_sales_price)) - over (partition by ss_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from store_sales - ,date_dim -where ss_sold_date_sk=d_date_sk - and d_month_seq between 1181 and 1181+11 - and ss_item_sk is not NULL -group by ss_item_sk, d_date) - select * -from (select item_sk - ,d_date - ,web_sales - ,store_sales - ,max(web_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) web_cumulative - ,max(store_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) store_cumulative - from (select case when web.item_sk is not null then web.item_sk else store.item_sk end item_sk - ,case when web.d_date is not null then web.d_date else store.d_date end d_date - ,web.cume_sales web_sales - ,store.cume_sales store_sales - from web_v1 web full outer join store_v1 store on (web.item_sk = store.item_sk - and web.d_date = store.d_date) - )x )y -where web_cumulative > store_cumulative -order by item_sk - ,d_date -limit 100; - --- end template query51.tpl query 46 in stream 0 --- start template query35a.tpl query 47 in stream 0 -select /* TPC-DS query35a.tpl 0.47 */ - ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - count(*) cnt1, - stddev_samp(cd_dep_count), - stddev_samp(cd_dep_count), - avg(cd_dep_count), - cd_dep_employed_count, - count(*) cnt2, - stddev_samp(cd_dep_employed_count), - stddev_samp(cd_dep_employed_count), - avg(cd_dep_employed_count), - cd_dep_college_count, - count(*) cnt3, - stddev_samp(cd_dep_college_count), - stddev_samp(cd_dep_college_count), - avg(cd_dep_college_count) - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2000 and - d_qoy < 4) and - exists (select * from - (select ws_bill_customer_sk customsk - from web_sales,date_dim - where - ws_sold_date_sk = d_date_sk and - d_year = 2000 and - d_qoy < 4 - union all - select cs_ship_customer_sk customsk - from catalog_sales,date_dim - where - cs_sold_date_sk = d_date_sk and - d_year = 2000 and - d_qoy < 4)x - where x.customsk = c.c_customer_sk) - group by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - limit 100; - --- end template query35a.tpl query 47 in stream 0 --- start template query49.tpl query 48 in stream 0 -select /* TPC-DS query49.tpl 0.48 */ channel, item, return_ratio, return_rank, currency_rank from - (select - 'web' as channel - ,web.item - ,web.return_ratio - ,web.return_rank - ,web.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select ws.ws_item_sk as item - ,(cast(sum(coalesce(wr.wr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(wr.wr_return_amt,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - web_sales ws left outer join web_returns wr - on (ws.ws_order_number = wr.wr_order_number and - ws.ws_item_sk = wr.wr_item_sk) - ,date_dim - where - wr.wr_return_amt > 10000 - and ws.ws_net_profit > 1 - and ws.ws_net_paid > 0 - and ws.ws_quantity > 0 - and ws_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 11 - group by ws.ws_item_sk - ) in_web - ) web - where - ( - web.return_rank <= 10 - or - web.currency_rank <= 10 - ) - union - select - 'catalog' as channel - ,catalog.item - ,catalog.return_ratio - ,catalog.return_rank - ,catalog.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select - cs.cs_item_sk as item - ,(cast(sum(coalesce(cr.cr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(cr.cr_return_amount,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - catalog_sales cs left outer join catalog_returns cr - on (cs.cs_order_number = cr.cr_order_number and - cs.cs_item_sk = cr.cr_item_sk) - ,date_dim - where - cr.cr_return_amount > 10000 - and cs.cs_net_profit > 1 - and cs.cs_net_paid > 0 - and cs.cs_quantity > 0 - and cs_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 11 - group by cs.cs_item_sk - ) in_cat - ) catalog - where - ( - catalog.return_rank <= 10 - or - catalog.currency_rank <=10 - ) - union - select - 'store' as channel - ,store.item - ,store.return_ratio - ,store.return_rank - ,store.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select sts.ss_item_sk as item - ,(cast(sum(coalesce(sr.sr_return_quantity,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(sr.sr_return_amt,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - store_sales sts left outer join store_returns sr - on (sts.ss_ticket_number = sr.sr_ticket_number and sts.ss_item_sk = sr.sr_item_sk) - ,date_dim - where - sr.sr_return_amt > 10000 - and sts.ss_net_profit > 1 - and sts.ss_net_paid > 0 - and sts.ss_quantity > 0 - and ss_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 11 - group by sts.ss_item_sk - ) in_store - ) store - where ( - store.return_rank <= 10 - or - store.currency_rank <= 10 - ) - ) - order by 1,4,5,2 - limit 100; - --- end template query49.tpl query 48 in stream 0 --- start template query9.tpl query 49 in stream 0 -select /* TPC-DS query9.tpl 0.49 */ case when (select count(*) - from store_sales - where ss_quantity between 1 and 20) > 4502458270 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 1 and 20) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 1 and 20) end bucket1 , - case when (select count(*) - from store_sales - where ss_quantity between 21 and 40) > 4756289490 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 21 and 40) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 21 and 40) end bucket2, - case when (select count(*) - from store_sales - where ss_quantity between 41 and 60) > 4101896285 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 41 and 60) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 41 and 60) end bucket3, - case when (select count(*) - from store_sales - where ss_quantity between 61 and 80) > 4583322734 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 61 and 80) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 61 and 80) end bucket4, - case when (select count(*) - from store_sales - where ss_quantity between 81 and 100) > 4208880504 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 81 and 100) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 81 and 100) end bucket5 -from reason -where r_reason_sk = 1 -; - --- end template query9.tpl query 49 in stream 0 --- start template query31.tpl query 50 in stream 0 -with /* TPC-DS query31.tpl 0.50 */ ss as - (select ca_county,d_qoy, d_year,sum(ss_ext_sales_price) as store_sales - from store_sales,date_dim,customer_address - where ss_sold_date_sk = d_date_sk - and ss_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year), - ws as - (select ca_county,d_qoy, d_year,sum(ws_ext_sales_price) as web_sales - from web_sales,date_dim,customer_address - where ws_sold_date_sk = d_date_sk - and ws_bill_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year) - select - ss1.ca_county - ,ss1.d_year - ,ws2.web_sales/ws1.web_sales web_q1_q2_increase - ,ss2.store_sales/ss1.store_sales store_q1_q2_increase - ,ws3.web_sales/ws2.web_sales web_q2_q3_increase - ,ss3.store_sales/ss2.store_sales store_q2_q3_increase - from - ss ss1 - ,ss ss2 - ,ss ss3 - ,ws ws1 - ,ws ws2 - ,ws ws3 - where - ss1.d_qoy = 1 - and ss1.d_year = 2001 - and ss1.ca_county = ss2.ca_county - and ss2.d_qoy = 2 - and ss2.d_year = 2001 - and ss2.ca_county = ss3.ca_county - and ss3.d_qoy = 3 - and ss3.d_year = 2001 - and ss1.ca_county = ws1.ca_county - and ws1.d_qoy = 1 - and ws1.d_year = 2001 - and ws1.ca_county = ws2.ca_county - and ws2.d_qoy = 2 - and ws2.d_year = 2001 - and ws1.ca_county = ws3.ca_county - and ws3.d_qoy = 3 - and ws3.d_year =2001 - and case when ws1.web_sales > 0 then ws2.web_sales/ws1.web_sales else null end - > case when ss1.store_sales > 0 then ss2.store_sales/ss1.store_sales else null end - and case when ws2.web_sales > 0 then ws3.web_sales/ws2.web_sales else null end - > case when ss2.store_sales > 0 then ss3.store_sales/ss2.store_sales else null end - order by store_q1_q2_increase; - --- end template query31.tpl query 50 in stream 0 --- start template query11.tpl query 51 in stream 0 -with /* TPC-DS query11.tpl 0.51 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ss_ext_list_price-ss_ext_discount_amt) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ws_ext_list_price-ws_ext_discount_amt) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_preferred_cust_flag - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 2001 - and t_s_secyear.dyear = 2001+1 - and t_w_firstyear.dyear = 2001 - and t_w_secyear.dyear = 2001+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else 0.0 end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else 0.0 end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_preferred_cust_flag -limit 100; - --- end template query11.tpl query 51 in stream 0 --- start template query93.tpl query 52 in stream 0 -select /* TPC-DS query93.tpl 0.52 */ ss_customer_sk - ,sum(act_sales) sumsales - from (select ss_item_sk - ,ss_ticket_number - ,ss_customer_sk - ,case when sr_return_quantity is not null then (ss_quantity-sr_return_quantity)*ss_sales_price - else (ss_quantity*ss_sales_price) end act_sales - from store_sales left outer join store_returns on (sr_item_sk = ss_item_sk - and sr_ticket_number = ss_ticket_number) - ,reason - where sr_reason_sk = r_reason_sk - and r_reason_desc = 'reason 44') t - group by ss_customer_sk - order by sumsales, ss_customer_sk -limit 100; - --- end template query93.tpl query 52 in stream 0 --- start template query29.tpl query 53 in stream 0 -select /* TPC-DS query29.tpl 0.53 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,sum(ss_quantity) as store_sales_quantity - ,sum(sr_return_quantity) as store_returns_quantity - ,sum(cs_quantity) as catalog_sales_quantity - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 2000 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 4 + 3 - and d2.d_year = 2000 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_year in (2000,2000+1,2000+2) - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query29.tpl query 53 in stream 0 --- start template query38.tpl query 54 in stream 0 -select /* TPC-DS query38.tpl 0.54 */ count(*) from ( - select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1212 and 1212 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1212 and 1212 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1212 and 1212 + 11 -) hot_cust -limit 100; - --- end template query38.tpl query 54 in stream 0 --- start template query22a.tpl query 55 in stream 0 -with /* TPC-DS query22a.tpl 0.55 */ results as -(select i_product_name - ,i_brand - ,i_class - ,i_category - ,avg(inv_quantity_on_hand) qoh - from inventory - ,date_dim - ,item --- ,warehouse - where inv_date_sk=d_date_sk - and inv_item_sk=i_item_sk --- and inv_warehouse_sk = w_warehouse_sk - and d_month_seq between 1181 and 1181 + 11 - group by i_product_name,i_brand,i_class,i_category), -results_rollup as -(select i_product_name, i_brand, i_class, i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class,i_category -union all -select i_product_name, i_brand, i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class -union all -select i_product_name, i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand -union all -select i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name -union all -select null i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results) - select i_product_name, i_brand, i_class, i_category,qoh - from results_rollup - order by qoh, i_product_name, i_brand, i_class, i_category -limit 100; - --- end template query22a.tpl query 55 in stream 0 --- start template query89.tpl query 56 in stream 0 -select /* TPC-DS query89.tpl 0.56 */ * -from( -select i_category, i_class, i_brand, - s_store_name, s_company_name, - d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, s_store_name, s_company_name) - avg_monthly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - d_year in (2001) and - ((i_category in ('Electronics','Children','Music') and - i_class in ('karoke','toddlers','pop') - ) - or (i_category in ('Men','Women','Books') and - i_class in ('accessories','fragrances','business') - )) -group by i_category, i_class, i_brand, - s_store_name, s_company_name, d_moy) tmp1 -where case when (avg_monthly_sales <> 0) then (abs(sum_sales - avg_monthly_sales) / avg_monthly_sales) else null end > 0.1 -order by sum_sales - avg_monthly_sales, s_store_name -limit 100; - --- end template query89.tpl query 56 in stream 0 --- start template query15.tpl query 57 in stream 0 -select /* TPC-DS query15.tpl 0.57 */ ca_zip - ,sum(cs_sales_price) - from catalog_sales - ,customer - ,customer_address - ,date_dim - where cs_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', - '85392', '85460', '80348', '81792') - or ca_state in ('CA','WA','GA') - or cs_sales_price > 500) - and cs_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 2001 - group by ca_zip - order by ca_zip - limit 100; - --- end template query15.tpl query 57 in stream 0 --- start template query6.tpl query 58 in stream 0 -select /* TPC-DS query6.tpl 0.58 */ a.ca_state state, count(*) cnt - from customer_address a - ,customer c - ,store_sales s - ,date_dim d - ,item i - where a.ca_address_sk = c.c_current_addr_sk - and c.c_customer_sk = s.ss_customer_sk - and s.ss_sold_date_sk = d.d_date_sk - and s.ss_item_sk = i.i_item_sk - and d.d_month_seq = - (select distinct (d_month_seq) - from date_dim - where d_year = 1998 - and d_moy = 2 ) - and i.i_current_price > 1.2 * - (select avg(j.i_current_price) - from item j - where j.i_category = i.i_category) - group by a.ca_state - having count(*) >= 10 - order by cnt, a.ca_state - limit 100; - --- end template query6.tpl query 58 in stream 0 --- start template query52.tpl query 59 in stream 0 -select /* TPC-DS query52.tpl 0.59 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_sales_price) ext_price - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=11 - and dt.d_year=2001 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,ext_price desc - ,brand_id -limit 100 ; - --- end template query52.tpl query 59 in stream 0 --- start template query50.tpl query 60 in stream 0 -select /* TPC-DS query50.tpl 0.60 */ - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 30) and - (sr_returned_date_sk - ss_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 60) and - (sr_returned_date_sk - ss_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 90) and - (sr_returned_date_sk - ss_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - store_sales - ,store_returns - ,store - ,date_dim d1 - ,date_dim d2 -where - d2.d_year = 2000 -and d2.d_moy = 10 -and ss_ticket_number = sr_ticket_number -and ss_item_sk = sr_item_sk -and ss_sold_date_sk = d1.d_date_sk -and sr_returned_date_sk = d2.d_date_sk -and ss_customer_sk = sr_customer_sk -and ss_store_sk = s_store_sk -group by - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -order by s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -limit 100; - --- end template query50.tpl query 60 in stream 0 --- start template query42.tpl query 61 in stream 0 -select /* TPC-DS query42.tpl 0.61 */ dt.d_year - ,item.i_category_id - ,item.i_category - ,sum(ss_ext_sales_price) - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=12 - and dt.d_year=2000 - group by dt.d_year - ,item.i_category_id - ,item.i_category - order by sum(ss_ext_sales_price) desc,dt.d_year - ,item.i_category_id - ,item.i_category -limit 100 ; - --- end template query42.tpl query 61 in stream 0 --- start template query41.tpl query 62 in stream 0 -select /* TPC-DS query41.tpl 0.62 */ distinct(i_product_name) - from item i1 - where i_manufact_id between 925 and 925+40 - and (select count(*) as item_cnt - from item - where (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'papaya' or i_color = 'khaki') and - (i_units = 'Unknown' or i_units = 'Tbl') and - (i_size = 'petite' or i_size = 'large') - ) or - (i_category = 'Women' and - (i_color = 'sandy' or i_color = 'chocolate') and - (i_units = 'Case' or i_units = 'Lb') and - (i_size = 'N/A' or i_size = 'medium') - ) or - (i_category = 'Men' and - (i_color = 'lemon' or i_color = 'brown') and - (i_units = 'Dozen' or i_units = 'Each') and - (i_size = 'small' or i_size = 'extra large') - ) or - (i_category = 'Men' and - (i_color = 'lawn' or i_color = 'firebrick') and - (i_units = 'Pound' or i_units = 'Gram') and - (i_size = 'petite' or i_size = 'large') - ))) or - (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'antique' or i_color = 'cornsilk') and - (i_units = 'Gross' or i_units = 'Cup') and - (i_size = 'petite' or i_size = 'large') - ) or - (i_category = 'Women' and - (i_color = 'light' or i_color = 'chiffon') and - (i_units = 'Box' or i_units = 'N/A') and - (i_size = 'N/A' or i_size = 'medium') - ) or - (i_category = 'Men' and - (i_color = 'peach' or i_color = 'pale') and - (i_units = 'Bunch' or i_units = 'Oz') and - (i_size = 'small' or i_size = 'extra large') - ) or - (i_category = 'Men' and - (i_color = 'orchid' or i_color = 'magenta') and - (i_units = 'Pallet' or i_units = 'Tsp') and - (i_size = 'petite' or i_size = 'large') - )))) > 0 - order by i_product_name - limit 100; - --- end template query41.tpl query 62 in stream 0 --- start template query8.tpl query 63 in stream 0 -select /* TPC-DS query8.tpl 0.63 */ s_store_name - ,sum(ss_net_profit) - from store_sales - ,date_dim - ,store, - (select ca_zip - from ( - SELECT substring(ca_zip,1,5) ca_zip - FROM customer_address - WHERE substring(ca_zip,1,5) IN ( - '72834','40181','36018','30255','51929','64527', - '67005','64729','76958','16705','25149', - '16796','56952','42684','43759','95708', - '88761','53411','59275','96955','10173', - '51092','20862','51250','19875','96392', - '96941','22454','48264','35393','65394', - '18466','35642','52631','60189','76893', - '81963','43120','31895','13434','28442', - '70411','39863','83795','46162','78063', - '35758','32750','37733','96210','36158', - '16860','30358','82921','56428','52841', - '94253','70498','24357','69808','31926', - '41180','12331','51661','54070','91949', - '16005','23813','18293','51198','83785', - '12931','59277','18604','29380','10933', - '65342','80974','27560','95822','50265', - '84217','14857','38703','73410','79800', - '57787','74713','72826','26159','98067', - '80169','93139','16066','25892','30280', - '42038','15816','38317','32333','86920', - '53251','87933','39318','21945','71414', - '13103','17914','83977','13015','31863', - '18969','28749','51188','23051','85919', - '77505','22269','54402','93593','48290', - '26387','38753','74518','95416','86950', - '44425','85097','27387','41035','25221', - '73030','61793','49403','30447','34911', - '17566','34170','61822','68274','54364', - '84352','48109','73457','63866','19513', - '49050','68909','11904','45281','20458', - '61445','95563','82947','34088','36845', - '30327','27663','25561','31582','82977', - '64448','46443','76698','64166','36240', - '29240','35312','44670','10892','34769', - '12824','14954','84985','13548','26103', - '75297','78487','74102','75387','55184', - '15664','85336','40967','77342','92848', - '40735','20118','33367','30776','34815', - '11157','49720','55346','43353','18746', - '97171','45709','92035','39048','67714', - '66086','24877','35300','84948','53938', - '43211','40377','17243','77311','85113', - '10835','36406','98567','36859','46795', - '32261','82020','30913','77514','69970', - '76298','82095','96313','71047','89989', - '12675','92061','85684','45670','20551', - '47069','62050','70678','42819','99362', - '20240','25440','24643','92788','21378', - '94409','68283','79740','73085','25196', - '68621','68685','62499','89559','35766', - '18221','64269','81744','26731','55498', - '19616','52531','40763','11947','29429', - '22909','22818','54767','14486','43367', - '92745','50802','29204','59888','19662', - '81401','44615','16010','66348','80989', - '37019','99736','80990','35029','36491', - '46843','12932','77172','12822','30107', - '24014','56364','56519','45005','39600', - '51056','15943','64627','35490','15182', - '51894','37764','31833','29755','78775', - '31238','40346','29736','33224','62123', - '34197','84458','44158','26186','78863', - '17493','16962','40816','57153','52334', - '27190','38942','32385','90866','91093', - '54782','74694','64069','39056','44353', - '56485','57962','71984','77722','16960', - '54642','26999','77254','28692','40494', - '22458','22344','69786','43603','30621', - '10856','88457','65038','21597','24290', - '51814','64838','70957','27324','76773', - '54478','61339','82942','35836','47385', - '91366','12089','61333','76284','84447', - '48918','59337','67348','15926','91882', - '49132','36529','54187','68522','10751', - '61586','10201','81861','43807','77164', - '76182','86762','51083','68475','60202', - '91345','25941','18199','27428','24456', - '86749','49468','40294','53010','64964', - '93566','55432','34313','29883','47568', - '39651','17061','72261','55632') - intersect - select ca_zip - from (SELECT substring(ca_zip,1,5) ca_zip,count(*) cnt - FROM customer_address, customer - WHERE ca_address_sk = c_current_addr_sk and - c_preferred_cust_flag='Y' - group by ca_zip - having count(*) > 10)A1)A2) V1 - where ss_store_sk = s_store_sk - and ss_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 2000 - and (substring(s_zip,1,2) = substring(V1.ca_zip,1,2)) - group by s_store_name - order by s_store_name - limit 100; - --- end template query8.tpl query 63 in stream 0 --- start template query12.tpl query 64 in stream 0 -select /* TPC-DS query12.tpl 0.64 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ws_ext_sales_price) as itemrevenue - ,sum(ws_ext_sales_price)*100/sum(sum(ws_ext_sales_price)) over - (partition by i_class) as revenueratio -from - web_sales - ,item - ,date_dim -where - ws_item_sk = i_item_sk - and i_category in ('Sports', 'Jewelry', 'Books') - and ws_sold_date_sk = d_date_sk - and d_date between cast('2002-03-10' as date) - and dateadd(day,30,cast('2002-03-10' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query12.tpl query 64 in stream 0 --- start template query20.tpl query 65 in stream 0 -select /* TPC-DS query20.tpl 0.65 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(cs_ext_sales_price) as itemrevenue - ,sum(cs_ext_sales_price)*100/sum(sum(cs_ext_sales_price)) over - (partition by i_class) as revenueratio - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and i_category in ('Men', 'Jewelry', 'Sports') - and cs_sold_date_sk = d_date_sk - and d_date between cast('2002-01-25' as date) - and dateadd(day,30,cast('2002-01-25' as date)) - group by i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - order by i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query20.tpl query 65 in stream 0 --- start template query88.tpl query 66 in stream 0 -select /* TPC-DS query88.tpl 0.66 */ * -from - (select count(*) h8_30_to_9 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s1, - (select count(*) h9_to_9_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s2, - (select count(*) h9_30_to_10 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s3, - (select count(*) h10_to_10_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s4, - (select count(*) h10_30_to_11 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s5, - (select count(*) h11_to_11_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s6, - (select count(*) h11_30_to_12 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s7, - (select count(*) h12_to_12_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 12 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s8 -; - --- end template query88.tpl query 66 in stream 0 --- start template query82.tpl query 67 in stream 0 -select /* TPC-DS query82.tpl 0.67 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, store_sales - where i_current_price between 55 and 55+30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('1998-03-27' as date) and dateadd(day,60,cast('1998-03-27' as date)) - and i_manufact_id in (769,119,345,926) - and inv_quantity_on_hand between 100 and 500 - and ss_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query82.tpl query 67 in stream 0 --- start template query23.tpl query 68 in stream 0 -with /* TPC-DS query23.tpl 0.68 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (2000,2000+1,2000+2,2000+3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (2000,2000+1,2000+2,2000+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * -from - max_store_sales)) - select sum(sales) - from (select cs_quantity*cs_list_price sales - from catalog_sales - ,date_dim - where d_year = 2000 - and d_moy = 7 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - union all - select ws_quantity*ws_list_price sales - from web_sales - ,date_dim - where d_year = 2000 - and d_moy = 7 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer)) - limit 100; -with /* TPC-DS query23.tpl 0.68 part2 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (2000,2000 + 1,2000 + 2,2000 + 3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (2000,2000+1,2000+2,2000+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * - from max_store_sales)) - select c_last_name,c_first_name,sales - from (select c_last_name,c_first_name,sum(cs_quantity*cs_list_price) sales - from catalog_sales - ,customer - ,date_dim - where d_year = 2000 - and d_moy = 7 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and cs_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name - union all - select c_last_name,c_first_name,sum(ws_quantity*ws_list_price) sales - from web_sales - ,customer - ,date_dim - where d_year = 2000 - and d_moy = 7 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and ws_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name) - order by c_last_name,c_first_name,sales - limit 100; - --- end template query23.tpl query 68 in stream 0 --- start template query14a.tpl query 69 in stream 0 -with /* TPC-DS query14a.tpl 0.69 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1999 AND 1999 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1999 AND 1999 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1999 AND 1999 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as - (select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2) x) -, - results AS -(select channel, i_brand_id, i_class_id, i_category_id, sum(sales) sum_sales, sum(number_sales) number_sales - from ( - select 'store' channel, i_brand_id,i_class_id - ,i_category_id,sum(ss_quantity*ss_list_price) sales - , count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1999+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales) - union all - select 'catalog' channel, i_brand_id,i_class_id,i_category_id, sum(cs_quantity*cs_list_price) sales, count(*) number_sales - from catalog_sales - ,item - ,date_dim - where cs_item_sk in (select ss_item_sk from cross_items) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1999+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(cs_quantity*cs_list_price) > (select average_sales from avg_sales) - union all - select 'web' channel, i_brand_id,i_class_id,i_category_id, sum(ws_quantity*ws_list_price) sales , count(*) number_sales - from web_sales - ,item - ,date_dim - where ws_item_sk in (select ss_item_sk from cross_items) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1999+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ws_quantity*ws_list_price) > (select average_sales from avg_sales) - ) y - group by channel, i_brand_id,i_class_id,i_category_id) - - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales -from ( - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales from results - union - select channel, i_brand_id, i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id, i_class_id - union - select channel, i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id - union - select channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel - union - select null as channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results) z -order by channel, i_brand_id, i_class_id, i_category_id - limit 100; -with /* TPC-DS query14a.tpl 0.69 part2 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1999 AND 1999 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1999 AND 1999 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1999 AND 1999 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as -(select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2) x) - select this_year.channel ty_channel - ,this_year.i_brand_id ty_brand - ,this_year.i_class_id ty_class - ,this_year.i_category_id ty_category - ,this_year.sales ty_sales - ,this_year.number_sales ty_number_sales - ,last_year.channel ly_channel - ,last_year.i_brand_id ly_brand - ,last_year.i_class_id ly_class - ,last_year.i_category_id ly_category - ,last_year.sales ly_sales - ,last_year.number_sales ly_number_sales -from - (select 'store' channel, i_brand_id,i_class_id,i_category_id - ,sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1999 + 1 - and d_moy = 12 - and d_dom = 18) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) this_year, - (select 'store' channel, i_brand_id,i_class_id - ,i_category_id, sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1999 - and d_moy = 12 - and d_dom = 18) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) last_year - where this_year.i_brand_id= last_year.i_brand_id - and this_year.i_class_id = last_year.i_class_id - and this_year.i_category_id = last_year.i_category_id - order by this_year.channel, this_year.i_brand_id, this_year.i_class_id, this_year.i_category_id - limit 100; - --- end template query14a.tpl query 69 in stream 0 --- start template query57.tpl query 70 in stream 0 -with /* TPC-DS query57.tpl 0.70 */ v1 as( - select i_category, i_brand, - cc_name, - d_year, d_moy, - sum(cs_sales_price) sum_sales, - avg(sum(cs_sales_price)) over - (partition by i_category, i_brand, - cc_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - cc_name - order by d_year, d_moy) rn - from item, catalog_sales, date_dim, call_center - where cs_item_sk = i_item_sk and - cs_sold_date_sk = d_date_sk and - cc_call_center_sk= cs_call_center_sk and - ( - d_year = 2000 or - ( d_year = 2000-1 and d_moy =12) or - ( d_year = 2000+1 and d_moy =1) - ) - group by i_category, i_brand, - cc_name , d_year, d_moy), - v2 as( - select v1.cc_name - ,v1.d_year, v1.d_moy - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1. cc_name = v1_lag. cc_name and - v1. cc_name = v1_lead. cc_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 2000 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, sum_sales - limit 100; - --- end template query57.tpl query 70 in stream 0 --- start template query65.tpl query 71 in stream 0 -select /* TPC-DS query65.tpl 0.71 */ - s_store_name, - i_item_desc, - sc.revenue, - i_current_price, - i_wholesale_cost, - i_brand - from store, item, - (select ss_store_sk, avg(revenue) as ave - from - (select ss_store_sk, ss_item_sk, - sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1223 and 1223+11 - group by ss_store_sk, ss_item_sk) sa - group by ss_store_sk) sb, - (select ss_store_sk, ss_item_sk, sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1223 and 1223+11 - group by ss_store_sk, ss_item_sk) sc - where sb.ss_store_sk = sc.ss_store_sk and - sc.revenue <= 0.1 * sb.ave and - s_store_sk = sc.ss_store_sk and - i_item_sk = sc.ss_item_sk - order by s_store_name, i_item_desc -limit 100; - --- end template query65.tpl query 71 in stream 0 --- start template query71.tpl query 72 in stream 0 -select /* TPC-DS query71.tpl 0.72 */ i_brand_id brand_id, i_brand brand,t_hour,t_minute, - sum(ext_price) ext_price - from item, (select ws_ext_sales_price as ext_price, - ws_sold_date_sk as sold_date_sk, - ws_item_sk as sold_item_sk, - ws_sold_time_sk as time_sk - from web_sales,date_dim - where d_date_sk = ws_sold_date_sk - and d_moy=11 - and d_year=2000 - union all - select cs_ext_sales_price as ext_price, - cs_sold_date_sk as sold_date_sk, - cs_item_sk as sold_item_sk, - cs_sold_time_sk as time_sk - from catalog_sales,date_dim - where d_date_sk = cs_sold_date_sk - and d_moy=11 - and d_year=2000 - union all - select ss_ext_sales_price as ext_price, - ss_sold_date_sk as sold_date_sk, - ss_item_sk as sold_item_sk, - ss_sold_time_sk as time_sk - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - and d_moy=11 - and d_year=2000 - ) tmp,time_dim - where - sold_item_sk = i_item_sk - and i_manager_id=1 - and time_sk = t_time_sk - and (t_meal_time = 'breakfast' or t_meal_time = 'dinner') - group by i_brand, i_brand_id,t_hour,t_minute - order by ext_price desc, i_brand_id - ; - --- end template query71.tpl query 72 in stream 0 --- start template query34.tpl query 73 in stream 0 -select /* TPC-DS query34.tpl 0.73 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (date_dim.d_dom between 1 and 3 or date_dim.d_dom between 25 and 28) - and (household_demographics.hd_buy_potential = '>10000' or - household_demographics.hd_buy_potential = '0-500') - and household_demographics.hd_vehicle_count > 0 - and (case when household_demographics.hd_vehicle_count > 0 - then household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count - else null - end) > 1.2 - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_county in ('Amherst County','Saginaw County','Harding County','Henry County', - 'Belknap County','Buncombe County','Carter County','District of Columbia') - group by ss_ticket_number,ss_customer_sk) dn,customer - where ss_customer_sk = c_customer_sk - and cnt between 15 and 20 - order by c_last_name,c_first_name,c_salutation,c_preferred_cust_flag desc, ss_ticket_number; - --- end template query34.tpl query 73 in stream 0 --- start template query48.tpl query 74 in stream 0 -select /* TPC-DS query48.tpl 0.74 */ sum (ss_quantity) - from store_sales, store, customer_demographics, customer_address, date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2001 - and - ( - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'W' - and - cd_education_status = '2 yr Degree' - and - ss_sales_price between 100.00 and 150.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'D' - and - cd_education_status = 'Advanced Degree' - and - ss_sales_price between 50.00 and 100.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'S' - and - cd_education_status = 'Primary' - and - ss_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('CA', 'CO', 'SD') - and ss_net_profit between 0 and 2000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('MS', 'NM', 'GA') - and ss_net_profit between 150 and 3000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('NE', 'SC', 'WY') - and ss_net_profit between 50 and 25000 - ) - ) -; - --- end template query48.tpl query 74 in stream 0 --- start template query30.tpl query 75 in stream 0 -with /* TPC-DS query30.tpl 0.75 */ customer_total_return as - (select wr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(wr_return_amt) as ctr_total_return - from web_returns - ,date_dim - ,customer_address - where wr_returned_date_sk = d_date_sk - and d_year =2000 - and wr_returning_addr_sk = ca_address_sk - group by wr_returning_customer_sk - ,ca_state) - select c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'KS' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return -limit 100; - --- end template query30.tpl query 75 in stream 0 --- start template query74.tpl query 76 in stream 0 -with /* TPC-DS query74.tpl 0.76 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,min(ss_net_paid) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1999,1999+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,min(ws_net_paid) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - and d_year in (1999,1999+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - ) - select - t_s_secyear.customer_id, t_s_secyear.customer_first_name, t_s_secyear.customer_last_name - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.year = 1999 - and t_s_secyear.year = 1999+1 - and t_w_firstyear.year = 1999 - and t_w_secyear.year = 1999+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - order by 3,1,2 -limit 100; - --- end template query74.tpl query 76 in stream 0 --- start template query87.tpl query 77 in stream 0 -select /* TPC-DS query87.tpl 0.77 */ count(*) -from ((select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1224 and 1224+11) - except - (select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1224 and 1224+11) - except - (select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1224 and 1224+11) -) cool_cust -; - --- end template query87.tpl query 77 in stream 0 --- start template query77a.tpl query 78 in stream 0 -with /* TPC-DS query77a.tpl 0.78 */ ss as - (select s_store_sk, - sum(ss_ext_sales_price) as sales, - sum(ss_net_profit) as profit - from store_sales, - date_dim, - store - where ss_sold_date_sk = d_date_sk - and d_date between cast('2000-08-19' as date) - and dateadd(day,30,cast('2000-08-19' as date)) - and ss_store_sk = s_store_sk - group by s_store_sk) - , - sr as - (select s_store_sk, - sum(sr_return_amt) as returns, - sum(sr_net_loss) as profit_loss - from store_returns, - date_dim, - store - where sr_returned_date_sk = d_date_sk - and d_date between cast('2000-08-19' as date) - and dateadd(day,30,cast('2000-08-19' as date)) - and sr_store_sk = s_store_sk - group by s_store_sk), - cs as - (select cs_call_center_sk, - sum(cs_ext_sales_price) as sales, - sum(cs_net_profit) as profit - from catalog_sales, - date_dim - where cs_sold_date_sk = d_date_sk - and d_date between cast('2000-08-19' as date) - and dateadd(day,30,cast('2000-08-19' as date)) - group by cs_call_center_sk - ), - cr as - (select cr_call_center_sk, - sum(cr_return_amount) as returns, - sum(cr_net_loss) as profit_loss - from catalog_returns, - date_dim - where cr_returned_date_sk = d_date_sk - and d_date between cast('2000-08-19' as date) - and dateadd(day,30,cast('2000-08-19' as date)) - group by cr_call_center_sk), - ws as - ( select wp_web_page_sk, - sum(ws_ext_sales_price) as sales, - sum(ws_net_profit) as profit - from web_sales, - date_dim, - web_page - where ws_sold_date_sk = d_date_sk - and d_date between cast('2000-08-19' as date) - and dateadd(day,30,cast('2000-08-19' as date)) - and ws_web_page_sk = wp_web_page_sk - group by wp_web_page_sk), - wr as - (select wp_web_page_sk, - sum(wr_return_amt) as returns, - sum(wr_net_loss) as profit_loss - from web_returns, - date_dim, - web_page - where wr_returned_date_sk = d_date_sk - and d_date between cast('2000-08-19' as date) - and dateadd(day,30,cast('2000-08-19' as date)) - and wr_web_page_sk = wp_web_page_sk - group by wp_web_page_sk) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , ss.s_store_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ss left join sr - on ss.s_store_sk = sr.s_store_sk - union all - select 'catalog channel' as channel - , cs_call_center_sk as id - , sales - , returns - , (profit - profit_loss) as profit - from cs - , cr - union all - select 'web channel' as channel - , ws.wp_web_page_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ws left join wr - on ws.wp_web_page_sk = wr.wp_web_page_sk - ) x - group by channel, id ) - - select * - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results -) foo -order by channel, id - limit 100; - --- end template query77a.tpl query 78 in stream 0 --- start template query73.tpl query 79 in stream 0 -select /* TPC-DS query73.tpl 0.79 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_buy_potential = '>10000' or - household_demographics.hd_buy_potential = 'Unknown') - and household_demographics.hd_vehicle_count > 0 - and case when household_demographics.hd_vehicle_count > 0 then - household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count else null end > 1 - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_county in ('Lake and Peninsula Borough','Brown County','Quitman County','Carter County') - group by ss_ticket_number,ss_customer_sk) dj,customer - where ss_customer_sk = c_customer_sk - and cnt between 1 and 5 - order by cnt desc, c_last_name asc; - --- end template query73.tpl query 79 in stream 0 --- start template query84.tpl query 80 in stream 0 -select /* TPC-DS query84.tpl 0.80 */ c_customer_id as customer_id - , coalesce(c_last_name,'') || ', ' || coalesce(c_first_name,'') as customername - from customer - ,customer_address - ,customer_demographics - ,household_demographics - ,income_band - ,store_returns - where ca_city = 'Mount Vernon' - and c_current_addr_sk = ca_address_sk - and ib_lower_bound >= 16672 - and ib_upper_bound <= 16672 + 50000 - and ib_income_band_sk = hd_income_band_sk - and cd_demo_sk = c_current_cdemo_sk - and hd_demo_sk = c_current_hdemo_sk - and sr_cdemo_sk = cd_demo_sk - order by c_customer_id - limit 100; - --- end template query84.tpl query 80 in stream 0 --- start template query54.tpl query 81 in stream 0 -with /* TPC-DS query54.tpl 0.81 */ my_customers as ( - select distinct c_customer_sk - , c_current_addr_sk - from - ( select cs_sold_date_sk sold_date_sk, - cs_bill_customer_sk customer_sk, - cs_item_sk item_sk - from catalog_sales - union all - select ws_sold_date_sk sold_date_sk, - ws_bill_customer_sk customer_sk, - ws_item_sk item_sk - from web_sales - ) cs_or_ws_sales, - item, - date_dim, - customer - where sold_date_sk = d_date_sk - and item_sk = i_item_sk - and i_category = 'Music' - and i_class = 'country' - and c_customer_sk = cs_or_ws_sales.customer_sk - and d_moy = 2 - and d_year = 1998 - ) - , my_revenue as ( - select c_customer_sk, - sum(ss_ext_sales_price) as revenue - from my_customers, - store_sales, - customer_address, - store, - date_dim - where c_current_addr_sk = ca_address_sk - and ca_county = s_county - and ca_state = s_state - and ss_sold_date_sk = d_date_sk - and c_customer_sk = ss_customer_sk - and d_month_seq between (select distinct d_month_seq+1 - from date_dim where d_year = 1998 and d_moy = 2) - and (select distinct d_month_seq+3 - from date_dim where d_year = 1998 and d_moy = 2) - group by c_customer_sk - ) - , segments as - (select cast((revenue/50) as bigint) as segment - from my_revenue - ) - select segment, count(*) as num_customers, segment*50 as segment_base - from segments - group by segment - order by segment, num_customers - limit 100; - --- end template query54.tpl query 81 in stream 0 --- start template query55.tpl query 82 in stream 0 -select /* TPC-DS query55.tpl 0.82 */ i_brand_id brand_id, i_brand brand, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=4 - and d_moy=12 - and d_year=1999 - group by i_brand, i_brand_id - order by ext_price desc, i_brand_id -limit 100 ; - --- end template query55.tpl query 82 in stream 0 --- start template query56.tpl query 83 in stream 0 -with /* TPC-DS query56.tpl 0.83 */ ss as ( - select i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where i_item_id in (select - i_item_id -from item -where i_color in ('blanched','magenta','hot')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 4 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - cs as ( - select i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('blanched','magenta','hot')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 4 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - ws as ( - select i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('blanched','magenta','hot')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 4 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id) - select i_item_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by total_sales, - i_item_id - limit 100; - --- end template query56.tpl query 83 in stream 0 --- start template query2.tpl query 84 in stream 0 -with /* TPC-DS query2.tpl 0.84 */ wscs as - (select sold_date_sk - ,sales_price - from (select ws_sold_date_sk sold_date_sk - ,ws_ext_sales_price sales_price - from web_sales - union all - select cs_sold_date_sk sold_date_sk - ,cs_ext_sales_price sales_price - from catalog_sales)), - wswscs as - (select d_week_seq, - sum(case when (d_day_name='Sunday') then sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then sales_price else null end) sat_sales - from wscs - ,date_dim - where d_date_sk = sold_date_sk - group by d_week_seq) - select d_week_seq1 - ,round(sun_sales1/sun_sales2,2) - ,round(mon_sales1/mon_sales2,2) - ,round(tue_sales1/tue_sales2,2) - ,round(wed_sales1/wed_sales2,2) - ,round(thu_sales1/thu_sales2,2) - ,round(fri_sales1/fri_sales2,2) - ,round(sat_sales1/sat_sales2,2) - from - (select wswscs.d_week_seq d_week_seq1 - ,sun_sales sun_sales1 - ,mon_sales mon_sales1 - ,tue_sales tue_sales1 - ,wed_sales wed_sales1 - ,thu_sales thu_sales1 - ,fri_sales fri_sales1 - ,sat_sales sat_sales1 - from wswscs,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 2001) y, - (select wswscs.d_week_seq d_week_seq2 - ,sun_sales sun_sales2 - ,mon_sales mon_sales2 - ,tue_sales tue_sales2 - ,wed_sales wed_sales2 - ,thu_sales thu_sales2 - ,fri_sales fri_sales2 - ,sat_sales sat_sales2 - from wswscs - ,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 2001+1) z - where d_week_seq1=d_week_seq2-53 - order by d_week_seq1; - --- end template query2.tpl query 84 in stream 0 --- start template query26.tpl query 85 in stream 0 -select /* TPC-DS query26.tpl 0.85 */ i_item_id, - avg(cs_quantity) agg1, - avg(cs_list_price) agg2, - avg(cs_coupon_amt) agg3, - avg(cs_sales_price) agg4 - from catalog_sales, customer_demographics, date_dim, item, promotion - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd_demo_sk and - cs_promo_sk = p_promo_sk and - cd_gender = 'F' and - cd_marital_status = 'U' and - cd_education_status = 'Unknown' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 1998 - group by i_item_id - order by i_item_id - limit 100; - --- end template query26.tpl query 85 in stream 0 --- start template query40.tpl query 86 in stream 0 -select /* TPC-DS query40.tpl 0.86 */ - w_state - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('2002-02-10' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_before - ,sum(case when (cast(d_date as date) >= cast ('2002-02-10' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_after - from - catalog_sales left outer join catalog_returns on - (cs_order_number = cr_order_number - and cs_item_sk = cr_item_sk) - ,warehouse - ,item - ,date_dim - where - i_current_price between 0.99 and 1.49 - and i_item_sk = cs_item_sk - and cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('2002-02-10' as date)) - and dateadd(day,30,cast ('2002-02-10' as date)) - group by - w_state,i_item_id - order by w_state,i_item_id -limit 100; - --- end template query40.tpl query 86 in stream 0 --- start template query72.tpl query 87 in stream 0 -select /* TPC-DS query72.tpl 0.87 */ i_item_desc - ,w_warehouse_name - ,d1.d_week_seq - ,sum(case when p_promo_sk is null then 1 else 0 end) no_promo - ,sum(case when p_promo_sk is not null then 1 else 0 end) promo - ,count(*) total_cnt -from catalog_sales -join inventory on (cs_item_sk = inv_item_sk) -join warehouse on (w_warehouse_sk=inv_warehouse_sk) -join item on (i_item_sk = cs_item_sk) -join customer_demographics on (cs_bill_cdemo_sk = cd_demo_sk) -join household_demographics on (cs_bill_hdemo_sk = hd_demo_sk) -join date_dim d1 on (cs_sold_date_sk = d1.d_date_sk) -join date_dim d2 on (inv_date_sk = d2.d_date_sk) -join date_dim d3 on (cs_ship_date_sk = d3.d_date_sk) -left outer join promotion on (cs_promo_sk=p_promo_sk) -left outer join catalog_returns on (cr_item_sk = cs_item_sk and cr_order_number = cs_order_number) -where d1.d_week_seq = d2.d_week_seq - and inv_quantity_on_hand < cs_quantity - and d3.d_date > d1.d_date + 5 - and hd_buy_potential = '501-1000' - and d1.d_year = 1998 - and cd_marital_status = 'U' -group by i_item_desc,w_warehouse_name,d1.d_week_seq -order by total_cnt desc, i_item_desc, w_warehouse_name, d_week_seq -limit 100; - --- end template query72.tpl query 87 in stream 0 --- start template query53.tpl query 88 in stream 0 -select /* TPC-DS query53.tpl 0.88 */ * from -(select i_manufact_id, -sum(ss_sales_price) sum_sales, -avg(sum(ss_sales_price)) over (partition by i_manufact_id) avg_quarterly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and -ss_sold_date_sk = d_date_sk and -ss_store_sk = s_store_sk and -d_month_seq in (1197,1197+1,1197+2,1197+3,1197+4,1197+5,1197+6,1197+7,1197+8,1197+9,1197+10,1197+11) and -((i_category in ('Books','Children','Electronics') and -i_class in ('personal','portable','reference','self-help') and -i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) -or(i_category in ('Women','Music','Men') and -i_class in ('accessories','classical','fragrances','pants') and -i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manufact_id, d_qoy ) tmp1 -where case when avg_quarterly_sales > 0 - then abs (sum_sales - avg_quarterly_sales)/ avg_quarterly_sales - else null end > 0.1 -order by avg_quarterly_sales, - sum_sales, - i_manufact_id -limit 100; - --- end template query53.tpl query 88 in stream 0 --- start template query79.tpl query 89 in stream 0 -select /* TPC-DS query79.tpl 0.89 */ - c_last_name,c_first_name,substring(s_city,1,30),ss_ticket_number,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,store.s_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (household_demographics.hd_dep_count = 9 or household_demographics.hd_vehicle_count > -1) - and date_dim.d_dow = 1 - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_number_employees between 200 and 295 - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,store.s_city) ms,customer - where ss_customer_sk = c_customer_sk - order by c_last_name,c_first_name,substring(s_city,1,30), profit -limit 100; - --- end template query79.tpl query 89 in stream 0 --- start template query18a.tpl query 90 in stream 0 -with /* TPC-DS query18a.tpl 0.90 */ results as - (select i_item_id, - ca_country, - ca_state, - ca_county, - cast(cs_quantity as decimal(12,2)) agg1, - cast(cs_list_price as decimal(12,2)) agg2, - cast(cs_coupon_amt as decimal(12,2)) agg3, - cast(cs_sales_price as decimal(12,2)) agg4, - cast(cs_net_profit as decimal(12,2)) agg5, - cast(c_birth_year as decimal(12,2)) agg6, - cast(cd1.cd_dep_count as decimal(12,2)) agg7 - from catalog_sales, customer_demographics cd1, customer_demographics cd2, customer, customer_address, date_dim, item - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd1.cd_demo_sk and - cs_bill_customer_sk = c_customer_sk and - cd1.cd_gender = 'M' and - cd1.cd_education_status = '2 yr Degree' and - c_current_cdemo_sk = cd2.cd_demo_sk and - c_current_addr_sk = ca_address_sk and - c_birth_month in (4,8,6,7,10,1) and - d_year = 1998 and - ca_state in ('OR','FL','WV','TN','NE','IL','MN') - ) - select i_item_id, ca_country, ca_state, ca_county, agg1, agg2, agg3, agg4, agg5, agg6, agg7 - from ( - select i_item_id, ca_country, ca_state, ca_county, avg(agg1) agg1, - avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state, ca_county - union all - select i_item_id, ca_country, ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state - union all - select i_item_id, ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country - union all - select i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - ) foo - order by ca_country, ca_state, ca_county, i_item_id - limit 100; - --- end template query18a.tpl query 90 in stream 0 --- start template query13.tpl query 91 in stream 0 -select /* TPC-DS query13.tpl 0.91 */ avg(ss_quantity) - ,avg(ss_ext_sales_price) - ,avg(ss_ext_wholesale_cost) - ,sum(ss_ext_wholesale_cost) - from store_sales - ,store - ,customer_demographics - ,household_demographics - ,customer_address - ,date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2001 - and((ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'D' - and cd_education_status = 'Unknown' - and ss_sales_price between 100.00 and 150.00 - and hd_dep_count = 3 - )or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'S' - and cd_education_status = 'College' - and ss_sales_price between 50.00 and 100.00 - and hd_dep_count = 1 - ) or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'U' - and cd_education_status = '2 yr Degree' - and ss_sales_price between 150.00 and 200.00 - and hd_dep_count = 1 - )) - and((ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('NC', 'CA', 'AR') - and ss_net_profit between 100 and 200 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('IA', 'OK', 'ND') - and ss_net_profit between 150 and 300 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('CO', 'IN', 'NY') - and ss_net_profit between 50 and 250 - )) -; - --- end template query13.tpl query 91 in stream 0 --- start template query24.tpl query 92 in stream 0 -with /* TPC-DS query24.tpl 0.92 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_net_profit) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip -and s_market_id=9 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'dodger' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; -with /* TPC-DS query24.tpl 0.92 part2 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_net_profit) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip - and s_market_id = 9 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'black' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; - --- end template query24.tpl query 92 in stream 0 --- start template query4.tpl query 93 in stream 0 -with /* TPC-DS query4.tpl 0.93 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(((ss_ext_list_price-ss_ext_wholesale_cost-ss_ext_discount_amt)+ss_ext_sales_price)/2) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((cs_ext_list_price-cs_ext_wholesale_cost-cs_ext_discount_amt)+cs_ext_sales_price)/2) ) year_total - ,'c' sale_type - from customer - ,catalog_sales - ,date_dim - where c_customer_sk = cs_bill_customer_sk - and cs_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year -union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((ws_ext_list_price-ws_ext_wholesale_cost-ws_ext_discount_amt)+ws_ext_sales_price)/2) ) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_birth_country - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_c_firstyear - ,year_total t_c_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_c_secyear.customer_id - and t_s_firstyear.customer_id = t_c_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_c_firstyear.sale_type = 'c' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_c_secyear.sale_type = 'c' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 2001 - and t_s_secyear.dyear = 2001+1 - and t_c_firstyear.dyear = 2001 - and t_c_secyear.dyear = 2001+1 - and t_w_firstyear.dyear = 2001 - and t_w_secyear.dyear = 2001+1 - and t_s_firstyear.year_total > 0 - and t_c_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_birth_country -limit 100; - --- end template query4.tpl query 93 in stream 0 --- start template query99.tpl query 94 in stream 0 -select /* TPC-DS query99.tpl 0.94 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 30) and - (cs_ship_date_sk - cs_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 60) and - (cs_ship_date_sk - cs_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 90) and - (cs_ship_date_sk - cs_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - catalog_sales - ,warehouse - ,ship_mode - ,call_center - ,date_dim -where - d_month_seq between 1203 and 1203 + 11 -and cs_ship_date_sk = d_date_sk -and cs_warehouse_sk = w_warehouse_sk -and cs_ship_mode_sk = sm_ship_mode_sk -and cs_call_center_sk = cc_call_center_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -limit 100; - --- end template query99.tpl query 94 in stream 0 --- start template query68.tpl query 95 in stream 0 -select /* TPC-DS query68.tpl 0.95 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,extended_price - ,extended_tax - ,list_price - from (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_ext_sales_price) extended_price - ,sum(ss_ext_list_price) list_price - ,sum(ss_ext_tax) extended_tax - from store_sales - ,date_dim - ,store - ,household_demographics - ,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_dep_count = 2 or - household_demographics.hd_vehicle_count= 3) - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_city in ('Mount Carmel','Fulton') - group by ss_ticket_number - ,ss_customer_sk - ,ss_addr_sk,ca_city) dn - ,customer - ,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,ss_ticket_number - limit 100; - --- end template query68.tpl query 95 in stream 0 --- start template query83.tpl query 96 in stream 0 -with /* TPC-DS query83.tpl 0.96 */ sr_items as - (select i_item_id item_id, - sum(sr_return_quantity) sr_item_qty - from store_returns, - item, - date_dim - where sr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2002-06-09','2002-10-06','2002-11-09'))) - and sr_returned_date_sk = d_date_sk - group by i_item_id), - cr_items as - (select i_item_id item_id, - sum(cr_return_quantity) cr_item_qty - from catalog_returns, - item, - date_dim - where cr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2002-06-09','2002-10-06','2002-11-09'))) - and cr_returned_date_sk = d_date_sk - group by i_item_id), - wr_items as - (select i_item_id item_id, - sum(wr_return_quantity) wr_item_qty - from web_returns, - item, - date_dim - where wr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2002-06-09','2002-10-06','2002-11-09'))) - and wr_returned_date_sk = d_date_sk - group by i_item_id) - select sr_items.item_id - ,sr_item_qty - ,sr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 sr_dev - ,cr_item_qty - ,cr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 cr_dev - ,wr_item_qty - ,wr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 wr_dev - ,(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 average - from sr_items - ,cr_items - ,wr_items - where sr_items.item_id=cr_items.item_id - and sr_items.item_id=wr_items.item_id - order by sr_items.item_id - ,sr_item_qty - limit 100; - --- end template query83.tpl query 96 in stream 0 --- start template query61.tpl query 97 in stream 0 -select /* TPC-DS query61.tpl 0.97 */ promotions,total,cast(promotions as decimal(16,4))/cast(total as decimal(16,4))*100 -from - (select sum(ss_ext_sales_price) promotions - from store_sales - ,store - ,promotion - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_promo_sk = p_promo_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -7 - and i_category = 'Home' - and (p_channel_dmail = 'Y' or p_channel_email = 'Y' or p_channel_tv = 'Y') - and s_gmt_offset = -7 - and d_year = 1999 - and d_moy = 12) promotional_sales, - (select sum(ss_ext_sales_price) total - from store_sales - ,store - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -7 - and i_category = 'Home' - and s_gmt_offset = -7 - and d_year = 1999 - and d_moy = 12) all_sales -order by promotions, total -limit 100; - --- end template query61.tpl query 97 in stream 0 --- start template query5a.tpl query 98 in stream 0 -with /* TPC-DS query5a.tpl 0.98 */ ssr as - (select s_store_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ss_store_sk as store_sk, - ss_sold_date_sk as date_sk, - ss_ext_sales_price as sales_price, - ss_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from store_sales - union all - select sr_store_sk as store_sk, - sr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - sr_return_amt as return_amt, - sr_net_loss as net_loss - from store_returns - ) salesreturns, - date_dim, - store - where date_sk = d_date_sk - and d_date between cast('2002-08-06' as date) - and dateadd(day,14,cast('2002-08-06' as date)) - and store_sk = s_store_sk - group by s_store_id) - , - csr as - (select cp_catalog_page_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select cs_catalog_page_sk as page_sk, - cs_sold_date_sk as date_sk, - cs_ext_sales_price as sales_price, - cs_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from catalog_sales - union all - select cr_catalog_page_sk as page_sk, - cr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - cr_return_amount as return_amt, - cr_net_loss as net_loss - from catalog_returns - ) salesreturns, - date_dim, - catalog_page - where date_sk = d_date_sk - and d_date between cast('2002-08-06' as date) - and dateadd(day,14,cast('2002-08-06' as date)) - and page_sk = cp_catalog_page_sk - group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ws_web_site_sk as wsr_web_site_sk, - ws_sold_date_sk as date_sk, - ws_ext_sales_price as sales_price, - ws_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from web_sales - union all - select ws_web_site_sk as wsr_web_site_sk, - wr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - wr_return_amt as return_amt, - wr_net_loss as net_loss - from web_returns left outer join web_sales on - ( wr_item_sk = ws_item_sk - and wr_order_number = ws_order_number) - ) salesreturns, - date_dim, - web_site - where date_sk = d_date_sk - and d_date between cast('2002-08-06' as date) - and dateadd(day,14,cast('2002-08-06' as date)) - and wsr_web_site_sk = web_site_sk - group by web_site_id) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || s_store_id as id - , sales - , returns - , (profit - profit_loss) as profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || cp_catalog_page_id as id - , sales - , returns - , (profit - profit_loss) as profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , (profit - profit_loss) as profit - from wsr - ) x - group by channel, id) - select channel, id, sales, returns, profit from ( - select channel, id, sales, returns, profit from results - union - select channel, null as id, sum(sales), sum(returns), sum(profit) from results group by channel - union - select null as channel, null as id, sum(sales), sum(returns), sum(profit) from results) foo -order by channel, id -limit 100; - --- end template query5a.tpl query 98 in stream 0 --- start template query76.tpl query 99 in stream 0 -select /* TPC-DS query76.tpl 0.99 */ channel, col_name, d_year, d_qoy, i_category, COUNT(*) sales_cnt, SUM(ext_sales_price) sales_amt FROM ( - SELECT 'store' as channel, 'ss_promo_sk' col_name, d_year, d_qoy, i_category, ss_ext_sales_price ext_sales_price - FROM store_sales, item, date_dim - WHERE ss_promo_sk IS NULL - AND ss_sold_date_sk=d_date_sk - AND ss_item_sk=i_item_sk - UNION ALL - SELECT 'web' as channel, 'ws_bill_addr_sk' col_name, d_year, d_qoy, i_category, ws_ext_sales_price ext_sales_price - FROM web_sales, item, date_dim - WHERE ws_bill_addr_sk IS NULL - AND ws_sold_date_sk=d_date_sk - AND ws_item_sk=i_item_sk - UNION ALL - SELECT 'catalog' as channel, 'cs_bill_hdemo_sk' col_name, d_year, d_qoy, i_category, cs_ext_sales_price ext_sales_price - FROM catalog_sales, item, date_dim - WHERE cs_bill_hdemo_sk IS NULL - AND cs_sold_date_sk=d_date_sk - AND cs_item_sk=i_item_sk) foo -GROUP BY channel, col_name, d_year, d_qoy, i_category -ORDER BY channel, col_name, d_year, d_qoy, i_category -limit 100; - --- end template query76.tpl query 99 in stream 0 diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/100TB/queries/query_1.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/100TB/queries/query_1.sql deleted file mode 100644 index 17f2dd3b..00000000 --- a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/100TB/queries/query_1.sql +++ /dev/null @@ -1,5027 +0,0 @@ --- start template query83.tpl query 1 in stream 1 -with /* TPC-DS query83.tpl 0.96 */ sr_items as - (select i_item_id item_id, - sum(sr_return_quantity) sr_item_qty - from store_returns, - item, - date_dim - where sr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2001-03-09','2001-08-17','2001-11-22'))) - and sr_returned_date_sk = d_date_sk - group by i_item_id), - cr_items as - (select i_item_id item_id, - sum(cr_return_quantity) cr_item_qty - from catalog_returns, - item, - date_dim - where cr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2001-03-09','2001-08-17','2001-11-22'))) - and cr_returned_date_sk = d_date_sk - group by i_item_id), - wr_items as - (select i_item_id item_id, - sum(wr_return_quantity) wr_item_qty - from web_returns, - item, - date_dim - where wr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2001-03-09','2001-08-17','2001-11-22'))) - and wr_returned_date_sk = d_date_sk - group by i_item_id) - select sr_items.item_id - ,sr_item_qty - ,sr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 sr_dev - ,cr_item_qty - ,cr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 cr_dev - ,wr_item_qty - ,wr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 wr_dev - ,(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 average - from sr_items - ,cr_items - ,wr_items - where sr_items.item_id=cr_items.item_id - and sr_items.item_id=wr_items.item_id - order by sr_items.item_id - ,sr_item_qty - limit 100; - --- end template query83.tpl query 1 in stream 1 --- start template query32.tpl query 2 in stream 1 -select /* TPC-DS query32.tpl 0.7 */ sum(cs_ext_discount_amt) as "excess discount amount" -from - catalog_sales - ,item - ,date_dim -where -i_manufact_id = 836 -and i_item_sk = cs_item_sk -and d_date between '1999-01-29' and - dateadd(day,90,cast('1999-01-29' as date)) -and d_date_sk = cs_sold_date_sk -and cs_ext_discount_amt - > ( - select - 1.3 * avg(cs_ext_discount_amt) - from - catalog_sales - ,date_dim - where - cs_item_sk = i_item_sk - and d_date between '1999-01-29' and - dateadd(day,90,cast('1999-01-29' as date)) - and d_date_sk = cs_sold_date_sk - ) -limit 100; - --- end template query32.tpl query 2 in stream 1 --- start template query30.tpl query 3 in stream 1 -with /* TPC-DS query30.tpl 0.75 */ customer_total_return as - (select wr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(wr_return_amt) as ctr_total_return - from web_returns - ,date_dim - ,customer_address - where wr_returned_date_sk = d_date_sk - and d_year =2002 - and wr_returning_addr_sk = ca_address_sk - group by wr_returning_customer_sk - ,ca_state) - select c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'MN' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return -limit 100; - --- end template query30.tpl query 3 in stream 1 --- start template query92.tpl query 4 in stream 1 -select /* TPC-DS query92.tpl 0.44 */ - sum(ws_ext_discount_amt) as "Excess Discount Amount" -from - web_sales - ,item - ,date_dim -where -i_manufact_id = 762 -and i_item_sk = ws_item_sk -and d_date between '2000-03-19' and - dateadd(day,90,cast('2000-03-19' as date)) -and d_date_sk = ws_sold_date_sk -and ws_ext_discount_amt - > ( - SELECT - 1.3 * avg(ws_ext_discount_amt) - FROM - web_sales - ,date_dim - WHERE - ws_item_sk = i_item_sk - and d_date between '2000-03-19' and - dateadd(day,90,cast('2000-03-19' as date)) - and d_date_sk = ws_sold_date_sk - ) -order by sum(ws_ext_discount_amt) -limit 100; - --- end template query92.tpl query 4 in stream 1 --- start template query66.tpl query 5 in stream 1 -select /* TPC-DS query66.tpl 0.39 */ - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - ,sum(jan_sales) as jan_sales - ,sum(feb_sales) as feb_sales - ,sum(mar_sales) as mar_sales - ,sum(apr_sales) as apr_sales - ,sum(may_sales) as may_sales - ,sum(jun_sales) as jun_sales - ,sum(jul_sales) as jul_sales - ,sum(aug_sales) as aug_sales - ,sum(sep_sales) as sep_sales - ,sum(oct_sales) as oct_sales - ,sum(nov_sales) as nov_sales - ,sum(dec_sales) as dec_sales - ,sum(jan_sales/w_warehouse_sq_ft) as jan_sales_per_sq_foot - ,sum(feb_sales/w_warehouse_sq_ft) as feb_sales_per_sq_foot - ,sum(mar_sales/w_warehouse_sq_ft) as mar_sales_per_sq_foot - ,sum(apr_sales/w_warehouse_sq_ft) as apr_sales_per_sq_foot - ,sum(may_sales/w_warehouse_sq_ft) as may_sales_per_sq_foot - ,sum(jun_sales/w_warehouse_sq_ft) as jun_sales_per_sq_foot - ,sum(jul_sales/w_warehouse_sq_ft) as jul_sales_per_sq_foot - ,sum(aug_sales/w_warehouse_sq_ft) as aug_sales_per_sq_foot - ,sum(sep_sales/w_warehouse_sq_ft) as sep_sales_per_sq_foot - ,sum(oct_sales/w_warehouse_sq_ft) as oct_sales_per_sq_foot - ,sum(nov_sales/w_warehouse_sq_ft) as nov_sales_per_sq_foot - ,sum(dec_sales/w_warehouse_sq_ft) as dec_sales_per_sq_foot - ,sum(jan_net) as jan_net - ,sum(feb_net) as feb_net - ,sum(mar_net) as mar_net - ,sum(apr_net) as apr_net - ,sum(may_net) as may_net - ,sum(jun_net) as jun_net - ,sum(jul_net) as jul_net - ,sum(aug_net) as aug_net - ,sum(sep_net) as sep_net - ,sum(oct_net) as oct_net - ,sum(nov_net) as nov_net - ,sum(dec_net) as dec_net - from ( - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'DHL' || ',' || 'UPS' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then ws_ext_sales_price* ws_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then ws_ext_sales_price* ws_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then ws_ext_sales_price* ws_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then ws_ext_sales_price* ws_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then ws_ext_sales_price* ws_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then ws_ext_sales_price* ws_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then ws_ext_sales_price* ws_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then ws_ext_sales_price* ws_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then ws_ext_sales_price* ws_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then ws_ext_sales_price* ws_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then ws_ext_sales_price* ws_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then ws_ext_sales_price* ws_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then ws_net_paid * ws_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then ws_net_paid * ws_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then ws_net_paid * ws_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then ws_net_paid * ws_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then ws_net_paid * ws_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then ws_net_paid * ws_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then ws_net_paid * ws_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then ws_net_paid * ws_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then ws_net_paid * ws_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then ws_net_paid * ws_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then ws_net_paid * ws_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then ws_net_paid * ws_quantity else 0 end) as dec_net - from - web_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - ws_warehouse_sk = w_warehouse_sk - and ws_sold_date_sk = d_date_sk - and ws_sold_time_sk = t_time_sk - and ws_ship_mode_sk = sm_ship_mode_sk - and d_year = 2000 - and t_time between 3295 and 3295+28800 - and sm_carrier in ('DHL','UPS') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - union all - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'DHL' || ',' || 'UPS' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then cs_sales_price* cs_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then cs_sales_price* cs_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then cs_sales_price* cs_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then cs_sales_price* cs_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then cs_sales_price* cs_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then cs_sales_price* cs_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then cs_sales_price* cs_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then cs_sales_price* cs_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then cs_sales_price* cs_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then cs_sales_price* cs_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then cs_sales_price* cs_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then cs_sales_price* cs_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as dec_net - from - catalog_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and cs_sold_time_sk = t_time_sk - and cs_ship_mode_sk = sm_ship_mode_sk - and d_year = 2000 - and t_time between 3295 AND 3295+28800 - and sm_carrier in ('DHL','UPS') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - ) x - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - order by w_warehouse_name - limit 100; - --- end template query66.tpl query 5 in stream 1 --- start template query84.tpl query 6 in stream 1 -select /* TPC-DS query84.tpl 0.80 */ c_customer_id as customer_id - , coalesce(c_last_name,'') || ', ' || coalesce(c_first_name,'') as customername - from customer - ,customer_address - ,customer_demographics - ,household_demographics - ,income_band - ,store_returns - where ca_city = 'Belmont' - and c_current_addr_sk = ca_address_sk - and ib_lower_bound >= 52249 - and ib_upper_bound <= 52249 + 50000 - and ib_income_band_sk = hd_income_band_sk - and cd_demo_sk = c_current_cdemo_sk - and hd_demo_sk = c_current_hdemo_sk - and sr_cdemo_sk = cd_demo_sk - order by c_customer_id - limit 100; - --- end template query84.tpl query 6 in stream 1 --- start template query98.tpl query 7 in stream 1 -select /* TPC-DS query98.tpl 0.32 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ss_ext_sales_price) as itemrevenue - ,sum(ss_ext_sales_price)*100/sum(sum(ss_ext_sales_price)) over - (partition by i_class) as revenueratio -from - store_sales - ,item - ,date_dim -where - ss_item_sk = i_item_sk - and i_category in ('Jewelry', 'Shoes', 'Books') - and ss_sold_date_sk = d_date_sk - and d_date between cast('2002-03-20' as date) - and dateadd(day,30,cast('2002-03-20' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio; - --- end template query98.tpl query 7 in stream 1 --- start template query58.tpl query 8 in stream 1 -with /* TPC-DS query58.tpl 0.19 */ ss_items as - (select i_item_id item_id - ,sum(ss_ext_sales_price) ss_item_rev - from store_sales - ,item - ,date_dim - where ss_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '1999-01-17')) - and ss_sold_date_sk = d_date_sk - group by i_item_id), - cs_items as - (select i_item_id item_id - ,sum(cs_ext_sales_price) cs_item_rev - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '1999-01-17')) - and cs_sold_date_sk = d_date_sk - group by i_item_id), - ws_items as - (select i_item_id item_id - ,sum(ws_ext_sales_price) ws_item_rev - from web_sales - ,item - ,date_dim - where ws_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq =(select d_week_seq - from date_dim - where d_date = '1999-01-17')) - and ws_sold_date_sk = d_date_sk - group by i_item_id) - select ss_items.item_id - ,ss_item_rev - ,ss_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ss_dev - ,cs_item_rev - ,cs_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 cs_dev - ,ws_item_rev - ,ws_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ws_dev - ,(ss_item_rev+cs_item_rev+ws_item_rev)/3 average - from ss_items,cs_items,ws_items - where ss_items.item_id=cs_items.item_id - and ss_items.item_id=ws_items.item_id - and ss_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - and ss_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and cs_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and cs_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and ws_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and ws_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - order by item_id - ,ss_item_rev - limit 100; - --- end template query58.tpl query 8 in stream 1 --- start template query16.tpl query 9 in stream 1 -select /* TPC-DS query16.tpl 0.25 */ - count(distinct cs_order_number) as "order count" - ,sum(cs_ext_ship_cost) as "total shipping cost" - ,sum(cs_net_profit) as "total net profit" -from - catalog_sales cs1 - ,date_dim - ,customer_address - ,call_center -where - d_date between '2001-4-01' and - dateadd(day, 60, cast('2001-4-01' as date)) -and cs1.cs_ship_date_sk = d_date_sk -and cs1.cs_ship_addr_sk = ca_address_sk -and ca_state = 'OK' -and cs1.cs_call_center_sk = cc_call_center_sk -and cc_county in ('Pennington County','Mobile County','Huron County','Fairfield County', - 'Gage County' -) -and exists (select * - from catalog_sales cs2 - where cs1.cs_order_number = cs2.cs_order_number - and cs1.cs_warehouse_sk <> cs2.cs_warehouse_sk) -and not exists(select * - from catalog_returns cr1 - where cs1.cs_order_number = cr1.cr_order_number) -order by count(distinct cs_order_number) -limit 100; - --- end template query16.tpl query 9 in stream 1 --- start template query77a.tpl query 10 in stream 1 -with /* TPC-DS query77a.tpl 0.78 */ ss as - (select s_store_sk, - sum(ss_ext_sales_price) as sales, - sum(ss_net_profit) as profit - from store_sales, - date_dim, - store - where ss_sold_date_sk = d_date_sk - and d_date between cast('1999-08-29' as date) - and dateadd(day,30,cast('1999-08-29' as date)) - and ss_store_sk = s_store_sk - group by s_store_sk) - , - sr as - (select s_store_sk, - sum(sr_return_amt) as returns, - sum(sr_net_loss) as profit_loss - from store_returns, - date_dim, - store - where sr_returned_date_sk = d_date_sk - and d_date between cast('1999-08-29' as date) - and dateadd(day,30,cast('1999-08-29' as date)) - and sr_store_sk = s_store_sk - group by s_store_sk), - cs as - (select cs_call_center_sk, - sum(cs_ext_sales_price) as sales, - sum(cs_net_profit) as profit - from catalog_sales, - date_dim - where cs_sold_date_sk = d_date_sk - and d_date between cast('1999-08-29' as date) - and dateadd(day,30,cast('1999-08-29' as date)) - group by cs_call_center_sk - ), - cr as - (select cr_call_center_sk, - sum(cr_return_amount) as returns, - sum(cr_net_loss) as profit_loss - from catalog_returns, - date_dim - where cr_returned_date_sk = d_date_sk - and d_date between cast('1999-08-29' as date) - and dateadd(day,30,cast('1999-08-29' as date)) - group by cr_call_center_sk), - ws as - ( select wp_web_page_sk, - sum(ws_ext_sales_price) as sales, - sum(ws_net_profit) as profit - from web_sales, - date_dim, - web_page - where ws_sold_date_sk = d_date_sk - and d_date between cast('1999-08-29' as date) - and dateadd(day,30,cast('1999-08-29' as date)) - and ws_web_page_sk = wp_web_page_sk - group by wp_web_page_sk), - wr as - (select wp_web_page_sk, - sum(wr_return_amt) as returns, - sum(wr_net_loss) as profit_loss - from web_returns, - date_dim, - web_page - where wr_returned_date_sk = d_date_sk - and d_date between cast('1999-08-29' as date) - and dateadd(day,30,cast('1999-08-29' as date)) - and wr_web_page_sk = wp_web_page_sk - group by wp_web_page_sk) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , ss.s_store_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ss left join sr - on ss.s_store_sk = sr.s_store_sk - union all - select 'catalog channel' as channel - , cs_call_center_sk as id - , sales - , returns - , (profit - profit_loss) as profit - from cs - , cr - union all - select 'web channel' as channel - , ws.wp_web_page_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ws left join wr - on ws.wp_web_page_sk = wr.wp_web_page_sk - ) x - group by channel, id ) - - select * - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results -) foo -order by channel, id - limit 100; - --- end template query77a.tpl query 10 in stream 1 --- start template query40.tpl query 11 in stream 1 -select /* TPC-DS query40.tpl 0.86 */ - w_state - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('2002-05-29' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_before - ,sum(case when (cast(d_date as date) >= cast ('2002-05-29' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_after - from - catalog_sales left outer join catalog_returns on - (cs_order_number = cr_order_number - and cs_item_sk = cr_item_sk) - ,warehouse - ,item - ,date_dim - where - i_current_price between 0.99 and 1.49 - and i_item_sk = cs_item_sk - and cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('2002-05-29' as date)) - and dateadd(day,30,cast ('2002-05-29' as date)) - group by - w_state,i_item_id - order by w_state,i_item_id -limit 100; - --- end template query40.tpl query 11 in stream 1 --- start template query96.tpl query 12 in stream 1 -select /* TPC-DS query96.tpl 0.1 */ count(*) -from store_sales - ,household_demographics - ,time_dim, store -where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 16 - and time_dim.t_minute >= 30 - and household_demographics.hd_dep_count = 0 - and store.s_store_name = 'ese' -order by count(*) -limit 100; - --- end template query96.tpl query 12 in stream 1 --- start template query13.tpl query 13 in stream 1 -select /* TPC-DS query13.tpl 0.91 */ avg(ss_quantity) - ,avg(ss_ext_sales_price) - ,avg(ss_ext_wholesale_cost) - ,sum(ss_ext_wholesale_cost) - from store_sales - ,store - ,customer_demographics - ,household_demographics - ,customer_address - ,date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2001 - and((ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'W' - and cd_education_status = '4 yr Degree' - and ss_sales_price between 100.00 and 150.00 - and hd_dep_count = 3 - )or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'M' - and cd_education_status = 'College' - and ss_sales_price between 50.00 and 100.00 - and hd_dep_count = 1 - ) or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'D' - and cd_education_status = 'Secondary' - and ss_sales_price between 150.00 and 200.00 - and hd_dep_count = 1 - )) - and((ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('GA', 'NY', 'NC') - and ss_net_profit between 100 and 200 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('KS', 'SD', 'VA') - and ss_net_profit between 150 and 300 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('TX', 'KY', 'CO') - and ss_net_profit between 50 and 250 - )) -; - --- end template query13.tpl query 13 in stream 1 --- start template query36a.tpl query 14 in stream 1 -with /* TPC-DS query36a.tpl 0.21 */ results as - (select - sum(ss_net_profit) as ss_net_profit, sum(ss_ext_sales_price) as ss_ext_sales_price, - sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin - ,i_category - ,i_class - ,0 as g_category, 0 as g_class - from - store_sales - ,date_dim d1 - ,item - ,store - where - d1.d_year = 2001 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and s_state in ('NM','MN','MI','MI', - 'WV','GA','SD','OK') - group by i_category,i_class) - , - results_rollup as - (select gross_margin ,i_category ,i_class,0 as t_category, 0 as t_class, 0 as lochierarchy from results - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - i_category, NULL AS i_class, 0 as t_category, 1 as t_class, 1 as lochierarchy from results group by i_category - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - NULL AS i_category ,NULL AS i_class, 1 as t_category, 1 as t_class, 2 as lochierarchy from results) - select - gross_margin ,i_category ,i_class, lochierarchy,rank() over ( - partition by lochierarchy, case when t_class = 0 then i_category end - order by gross_margin asc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then i_category end - ,rank_within_parent - limit 100; - --- end template query36a.tpl query 14 in stream 1 --- start template query95.tpl query 15 in stream 1 -with /* TPC-DS query95.tpl 0.43 */ ws_wh as -(select ws1.ws_order_number,ws1.ws_warehouse_sk wh1,ws2.ws_warehouse_sk wh2 - from web_sales ws1,web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) - select - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2001-4-01' and - dateadd(day,60,cast('2001-4-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'GA' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and ws1.ws_order_number in (select ws_order_number - from ws_wh) -and ws1.ws_order_number in (select wr_order_number - from web_returns,ws_wh - where wr_order_number = ws_wh.ws_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query95.tpl query 15 in stream 1 --- start template query63.tpl query 16 in stream 1 -select /* TPC-DS query63.tpl 0.27 */ * -from (select i_manager_id - ,sum(ss_sales_price) sum_sales - ,avg(sum(ss_sales_price)) over (partition by i_manager_id) avg_monthly_sales - from item - ,store_sales - ,date_dim - ,store - where ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and d_month_seq in (1193,1193+1,1193+2,1193+3,1193+4,1193+5,1193+6,1193+7,1193+8,1193+9,1193+10,1193+11) - and (( i_category in ('Books','Children','Electronics') - and i_class in ('personal','portable','reference','self-help') - and i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) - or( i_category in ('Women','Music','Men') - and i_class in ('accessories','classical','fragrances','pants') - and i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manager_id, d_moy) tmp1 -where case when avg_monthly_sales > 0 then abs (sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 -order by i_manager_id - ,avg_monthly_sales - ,sum_sales -limit 100; - --- end template query63.tpl query 16 in stream 1 --- start template query99.tpl query 17 in stream 1 -select /* TPC-DS query99.tpl 0.94 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 30) and - (cs_ship_date_sk - cs_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 60) and - (cs_ship_date_sk - cs_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 90) and - (cs_ship_date_sk - cs_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - catalog_sales - ,warehouse - ,ship_mode - ,call_center - ,date_dim -where - d_month_seq between 1215 and 1215 + 11 -and cs_ship_date_sk = d_date_sk -and cs_warehouse_sk = w_warehouse_sk -and cs_ship_mode_sk = sm_ship_mode_sk -and cs_call_center_sk = cc_call_center_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -limit 100; - --- end template query99.tpl query 17 in stream 1 --- start template query3.tpl query 18 in stream 1 -select /* TPC-DS query3.tpl 0.45 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_net_profit) sum_agg - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manufact_id = 399 - and dt.d_moy=12 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,sum_agg desc - ,brand_id - limit 100; - --- end template query3.tpl query 18 in stream 1 --- start template query6.tpl query 19 in stream 1 -select /* TPC-DS query6.tpl 0.58 */ a.ca_state state, count(*) cnt - from customer_address a - ,customer c - ,store_sales s - ,date_dim d - ,item i - where a.ca_address_sk = c.c_current_addr_sk - and c.c_customer_sk = s.ss_customer_sk - and s.ss_sold_date_sk = d.d_date_sk - and s.ss_item_sk = i.i_item_sk - and d.d_month_seq = - (select distinct (d_month_seq) - from date_dim - where d_year = 2001 - and d_moy = 7 ) - and i.i_current_price > 1.2 * - (select avg(j.i_current_price) - from item j - where j.i_category = i.i_category) - group by a.ca_state - having count(*) >= 10 - order by cnt, a.ca_state - limit 100; - --- end template query6.tpl query 19 in stream 1 --- start template query12.tpl query 20 in stream 1 -select /* TPC-DS query12.tpl 0.64 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ws_ext_sales_price) as itemrevenue - ,sum(ws_ext_sales_price)*100/sum(sum(ws_ext_sales_price)) over - (partition by i_class) as revenueratio -from - web_sales - ,item - ,date_dim -where - ws_item_sk = i_item_sk - and i_category in ('Children', 'Music', 'Sports') - and ws_sold_date_sk = d_date_sk - and d_date between cast('1999-03-11' as date) - and dateadd(day,30,cast('1999-03-11' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query12.tpl query 20 in stream 1 --- start template query28.tpl query 21 in stream 1 -select /* TPC-DS query28.tpl 0.36 */ * -from (select avg(ss_list_price) B1_LP - ,count(ss_list_price) B1_CNT - ,count(distinct ss_list_price) B1_CNTD - from store_sales - where ss_quantity between 0 and 5 - and (ss_list_price between 162 and 162+10 - or ss_coupon_amt between 17814 and 17814+1000 - or ss_wholesale_cost between 79 and 79+20)) B1, - (select avg(ss_list_price) B2_LP - ,count(ss_list_price) B2_CNT - ,count(distinct ss_list_price) B2_CNTD - from store_sales - where ss_quantity between 6 and 10 - and (ss_list_price between 186 and 186+10 - or ss_coupon_amt between 6282 and 6282+1000 - or ss_wholesale_cost between 69 and 69+20)) B2, - (select avg(ss_list_price) B3_LP - ,count(ss_list_price) B3_CNT - ,count(distinct ss_list_price) B3_CNTD - from store_sales - where ss_quantity between 11 and 15 - and (ss_list_price between 96 and 96+10 - or ss_coupon_amt between 12469 and 12469+1000 - or ss_wholesale_cost between 78 and 78+20)) B3, - (select avg(ss_list_price) B4_LP - ,count(ss_list_price) B4_CNT - ,count(distinct ss_list_price) B4_CNTD - from store_sales - where ss_quantity between 16 and 20 - and (ss_list_price between 81 and 81+10 - or ss_coupon_amt between 10851 and 10851+1000 - or ss_wholesale_cost between 24 and 24+20)) B4, - (select avg(ss_list_price) B5_LP - ,count(ss_list_price) B5_CNT - ,count(distinct ss_list_price) B5_CNTD - from store_sales - where ss_quantity between 21 and 25 - and (ss_list_price between 137 and 137+10 - or ss_coupon_amt between 17632 and 17632+1000 - or ss_wholesale_cost between 52 and 52+20)) B5, - (select avg(ss_list_price) B6_LP - ,count(ss_list_price) B6_CNT - ,count(distinct ss_list_price) B6_CNTD - from store_sales - where ss_quantity between 26 and 30 - and (ss_list_price between 125 and 125+10 - or ss_coupon_amt between 9896 and 9896+1000 - or ss_wholesale_cost between 63 and 63+20)) B6 -limit 100; - --- end template query28.tpl query 21 in stream 1 --- start template query85.tpl query 22 in stream 1 -select /* TPC-DS query85.tpl 0.33 */ substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) - from web_sales, web_returns, web_page, customer_demographics cd1, - customer_demographics cd2, customer_address, date_dim, reason - where ws_web_page_sk = wp_web_page_sk - and ws_item_sk = wr_item_sk - and ws_order_number = wr_order_number - and ws_sold_date_sk = d_date_sk and d_year = 2000 - and cd1.cd_demo_sk = wr_refunded_cdemo_sk - and cd2.cd_demo_sk = wr_returning_cdemo_sk - and ca_address_sk = wr_refunded_addr_sk - and r_reason_sk = wr_reason_sk - and - ( - ( - cd1.cd_marital_status = 'U' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Secondary' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 100.00 and 150.00 - ) - or - ( - cd1.cd_marital_status = 'S' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'College' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 50.00 and 100.00 - ) - or - ( - cd1.cd_marital_status = 'M' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = '4 yr Degree' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ca_country = 'United States' - and - ca_state in ('MT', 'ND', 'MO') - and ws_net_profit between 100 and 200 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('MI', 'WV', 'CO') - and ws_net_profit between 150 and 300 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('TX', 'ID', 'TN') - and ws_net_profit between 50 and 250 - ) - ) -group by r_reason_desc -order by substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) -limit 100; - --- end template query85.tpl query 22 in stream 1 --- start template query51.tpl query 23 in stream 1 -WITH /* TPC-DS query51.tpl 0.46 */ web_v1 as ( -select - ws_item_sk item_sk, d_date, - sum(sum(ws_sales_price)) - over (partition by ws_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from web_sales - ,date_dim -where ws_sold_date_sk=d_date_sk - and d_month_seq between 1193 and 1193+11 - and ws_item_sk is not NULL -group by ws_item_sk, d_date), -store_v1 as ( -select - ss_item_sk item_sk, d_date, - sum(sum(ss_sales_price)) - over (partition by ss_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from store_sales - ,date_dim -where ss_sold_date_sk=d_date_sk - and d_month_seq between 1193 and 1193+11 - and ss_item_sk is not NULL -group by ss_item_sk, d_date) - select * -from (select item_sk - ,d_date - ,web_sales - ,store_sales - ,max(web_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) web_cumulative - ,max(store_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) store_cumulative - from (select case when web.item_sk is not null then web.item_sk else store.item_sk end item_sk - ,case when web.d_date is not null then web.d_date else store.d_date end d_date - ,web.cume_sales web_sales - ,store.cume_sales store_sales - from web_v1 web full outer join store_v1 store on (web.item_sk = store.item_sk - and web.d_date = store.d_date) - )x )y -where web_cumulative > store_cumulative -order by item_sk - ,d_date -limit 100; - --- end template query51.tpl query 23 in stream 1 --- start template query41.tpl query 24 in stream 1 -select /* TPC-DS query41.tpl 0.62 */ distinct(i_product_name) - from item i1 - where i_manufact_id between 917 and 917+40 - and (select count(*) as item_cnt - from item - where (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'gainsboro' or i_color = 'seashell') and - (i_units = 'Gross' or i_units = 'Bundle') and - (i_size = 'petite' or i_size = 'N/A') - ) or - (i_category = 'Women' and - (i_color = 'almond' or i_color = 'sandy') and - (i_units = 'Case' or i_units = 'Box') and - (i_size = 'medium' or i_size = 'small') - ) or - (i_category = 'Men' and - (i_color = 'turquoise' or i_color = 'pink') and - (i_units = 'Ounce' or i_units = 'Gram') and - (i_size = 'economy' or i_size = 'large') - ) or - (i_category = 'Men' and - (i_color = 'indian' or i_color = 'blanched') and - (i_units = 'Unknown' or i_units = 'Bunch') and - (i_size = 'petite' or i_size = 'N/A') - ))) or - (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'drab' or i_color = 'lace') and - (i_units = 'Oz' or i_units = 'Ton') and - (i_size = 'petite' or i_size = 'N/A') - ) or - (i_category = 'Women' and - (i_color = 'cornsilk' or i_color = 'burlywood') and - (i_units = 'N/A' or i_units = 'Each') and - (i_size = 'medium' or i_size = 'small') - ) or - (i_category = 'Men' and - (i_color = 'red' or i_color = 'tomato') and - (i_units = 'Carton' or i_units = 'Cup') and - (i_size = 'economy' or i_size = 'large') - ) or - (i_category = 'Men' and - (i_color = 'ghost' or i_color = 'maroon') and - (i_units = 'Lb' or i_units = 'Tbl') and - (i_size = 'petite' or i_size = 'N/A') - )))) > 0 - order by i_product_name - limit 100; - --- end template query41.tpl query 24 in stream 1 --- start template query27a.tpl query 25 in stream 1 -with /* TPC-DS query27a.tpl 0.16 */ results as - (select i_item_id, - s_state, 0 as g_state, - ss_quantity agg1, - ss_list_price agg2, - ss_coupon_amt agg3, - ss_sales_price agg4 - from store_sales, customer_demographics, date_dim, store, item - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_store_sk = s_store_sk and - ss_cdemo_sk = cd_demo_sk and - cd_gender = 'F' and - cd_marital_status = 'U' and - cd_education_status = 'Unknown' and - d_year = 2002 and - s_state in ('KS','IA', 'WV', 'FL', 'WA', 'MI') - ) - - select i_item_id, - s_state, g_state, agg1, agg2, agg3, agg4 - from ( - select i_item_id, s_state, 0 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4 from results - group by i_item_id, s_state - union all - select i_item_id, NULL AS s_state, 1 AS g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as s_state, 1 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - ) foo - order by i_item_id, s_state - limit 100; - --- end template query27a.tpl query 25 in stream 1 --- start template query78.tpl query 26 in stream 1 -with /* TPC-DS query78.tpl 0.10 */ ws as - (select d_year AS ws_sold_year, ws_item_sk, - ws_bill_customer_sk ws_customer_sk, - sum(ws_quantity) ws_qty, - sum(ws_wholesale_cost) ws_wc, - sum(ws_sales_price) ws_sp - from web_sales - left join web_returns on wr_order_number=ws_order_number and ws_item_sk=wr_item_sk - join date_dim on ws_sold_date_sk = d_date_sk - where wr_order_number is null - group by d_year, ws_item_sk, ws_bill_customer_sk - ), -cs as - (select d_year AS cs_sold_year, cs_item_sk, - cs_bill_customer_sk cs_customer_sk, - sum(cs_quantity) cs_qty, - sum(cs_wholesale_cost) cs_wc, - sum(cs_sales_price) cs_sp - from catalog_sales - left join catalog_returns on cr_order_number=cs_order_number and cs_item_sk=cr_item_sk - join date_dim on cs_sold_date_sk = d_date_sk - where cr_order_number is null - group by d_year, cs_item_sk, cs_bill_customer_sk - ), -ss as - (select d_year AS ss_sold_year, ss_item_sk, - ss_customer_sk, - sum(ss_quantity) ss_qty, - sum(ss_wholesale_cost) ss_wc, - sum(ss_sales_price) ss_sp - from store_sales - left join store_returns on sr_ticket_number=ss_ticket_number and ss_item_sk=sr_item_sk - join date_dim on ss_sold_date_sk = d_date_sk - where sr_ticket_number is null - group by d_year, ss_item_sk, ss_customer_sk - ) - select -ss_item_sk, -round(ss_qty/(coalesce(ws_qty,0)+coalesce(cs_qty,0)),2) ratio, -ss_qty store_qty, ss_wc store_wholesale_cost, ss_sp store_sales_price, -coalesce(ws_qty,0)+coalesce(cs_qty,0) other_chan_qty, -coalesce(ws_wc,0)+coalesce(cs_wc,0) other_chan_wholesale_cost, -coalesce(ws_sp,0)+coalesce(cs_sp,0) other_chan_sales_price -from ss -left join ws on (ws_sold_year=ss_sold_year and ws_item_sk=ss_item_sk and ws_customer_sk=ss_customer_sk) -left join cs on (cs_sold_year=ss_sold_year and cs_item_sk=ss_item_sk and cs_customer_sk=ss_customer_sk) -where (coalesce(ws_qty,0)>0 or coalesce(cs_qty, 0)>0) and ss_sold_year=1998 -order by - ss_item_sk, - ss_qty desc, ss_wc desc, ss_sp desc, - other_chan_qty, - other_chan_wholesale_cost, - other_chan_sales_price, - ratio -limit 100; - --- end template query78.tpl query 26 in stream 1 --- start template query8.tpl query 27 in stream 1 -select /* TPC-DS query8.tpl 0.63 */ s_store_name - ,sum(ss_net_profit) - from store_sales - ,date_dim - ,store, - (select ca_zip - from ( - SELECT substring(ca_zip,1,5) ca_zip - FROM customer_address - WHERE substring(ca_zip,1,5) IN ( - '97140','48564','38301','52715','42337','39102', - '26442','61982','64833','69558','44101', - '74659','31584','25262','94426','40236', - '83399','55218','63674','15098','74347', - '55718','89754','89634','64501','76801', - '54874','48760','14668','73652','70214', - '72270','29530','99331','94961','69008', - '85967','51135','44153','53948','89877', - '88582','86217','32194','30678','32576', - '85137','24079','22658','94203','68225', - '99051','62260','37773','62118','82054', - '17574','65345','91798','36779','81765', - '84271','75570','26073','24371','31387', - '47494','19761','26051','81691','40457', - '96570','27959','31912','22134','93271', - '13804','63278','71966','85336','15547', - '15254','29249','92741','84360','36412', - '23329','20445','97689','96015','18743', - '24642','76023','18303','64792','73554', - '57480','42129','98440','45323','12993', - '63378','16091','55892','35259','38174', - '61831','67098','46906','42519','33972', - '23279','29577','81105','78206','86554', - '25365','59645','44888','56338','79335', - '78671','26325','91917','66507','75983', - '23903','13998','55627','15740','49800', - '30487','43144','98993','57124','50560', - '41854','17095','90176','31024','93281', - '49774','14541','23409','73214','12595', - '33136','73166','47111','99274','53155', - '95896','99910','28723','94211','56283', - '61262','62110','95109','53347','70606', - '13243','60172','34367','90093','72251', - '52287','81299','93605','66399','29848', - '41958','38721','86260','61575','87376', - '82270','94989','64332','41315','45778', - '96496','24512','78929','34656','78695', - '45199','85641','72022','72172','67489', - '76457','99406','40473','77330','16974', - '20795','19715','36514','67461','69145', - '38535','37040','69648','24640','93819', - '72291','65356','88774','58037','70643', - '82846','35299','36818','15464','86904', - '65884','73011','81934','76474','38312', - '93254','46875','85588','63847','88819', - '20230','91780','41852','11815','36465', - '60399','41924','57841','98448','75624', - '38828','64757','14806','12402','87224', - '59191','78645','74046','54617','44437', - '85657','19957','42300','91599','10411', - '71514','25069','49647','29268','18149', - '46826','87558','45504','13883','92260', - '28983','46633','85921','21436','46214', - '67669','64570','52732','61083','93473', - '42023','11572','13914','58732','45126', - '84785','42829','19165','41951','45865', - '86656','38416','82516','38929','74570', - '93750','29904','63345','19325','99815', - '23127','46130','96442','48604','46122', - '54000','94880','73296','96127','33776', - '61775','15477','66101','81457','40876', - '57746','87754','64644','21828','31479', - '84234','47728','91034','15820','80361', - '71199','42253','52804','65719','55925', - '11534','65593','30155','63142','90680', - '90429','37174','34532','57439','61867', - '24255','58847','17258','91785','77643', - '72567','33558','94200','49454','64625', - '90808','34760','75796','22900','20509', - '65504','28035','86626','31623','79192', - '72844','14901','35710','66918','99228', - '32229','74011','21371','70765','69068', - '26443','53586','49158','93021','65084', - '38969','17063','47957','50606','48658', - '88743','24366','42496','82682','70620', - '59214','30098','91368','48401','63410', - '25232','63748','66544','89236','46231', - '92984','44217','33601','72406','56189', - '63081','31083','35019','18213','76356', - '38772','97151','75514','91943') - intersect - select ca_zip - from (SELECT substring(ca_zip,1,5) ca_zip,count(*) cnt - FROM customer_address, customer - WHERE ca_address_sk = c_current_addr_sk and - c_preferred_cust_flag='Y' - group by ca_zip - having count(*) > 10)A1)A2) V1 - where ss_store_sk = s_store_sk - and ss_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 1999 - and (substring(s_zip,1,2) = substring(V1.ca_zip,1,2)) - group by s_store_name - order by s_store_name - limit 100; - --- end template query8.tpl query 27 in stream 1 --- start template query14a.tpl query 28 in stream 1 -with /* TPC-DS query14a.tpl 0.69 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1999 AND 1999 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1999 AND 1999 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1999 AND 1999 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as - (select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2) x) -, - results AS -(select channel, i_brand_id, i_class_id, i_category_id, sum(sales) sum_sales, sum(number_sales) number_sales - from ( - select 'store' channel, i_brand_id,i_class_id - ,i_category_id,sum(ss_quantity*ss_list_price) sales - , count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1999+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales) - union all - select 'catalog' channel, i_brand_id,i_class_id,i_category_id, sum(cs_quantity*cs_list_price) sales, count(*) number_sales - from catalog_sales - ,item - ,date_dim - where cs_item_sk in (select ss_item_sk from cross_items) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1999+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(cs_quantity*cs_list_price) > (select average_sales from avg_sales) - union all - select 'web' channel, i_brand_id,i_class_id,i_category_id, sum(ws_quantity*ws_list_price) sales , count(*) number_sales - from web_sales - ,item - ,date_dim - where ws_item_sk in (select ss_item_sk from cross_items) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1999+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ws_quantity*ws_list_price) > (select average_sales from avg_sales) - ) y - group by channel, i_brand_id,i_class_id,i_category_id) - - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales -from ( - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales from results - union - select channel, i_brand_id, i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id, i_class_id - union - select channel, i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id - union - select channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel - union - select null as channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results) z -order by channel, i_brand_id, i_class_id, i_category_id - limit 100; -with /* TPC-DS query14a.tpl 0.69 part2 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1999 AND 1999 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1999 AND 1999 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1999 AND 1999 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as -(select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2) x) - select this_year.channel ty_channel - ,this_year.i_brand_id ty_brand - ,this_year.i_class_id ty_class - ,this_year.i_category_id ty_category - ,this_year.sales ty_sales - ,this_year.number_sales ty_number_sales - ,last_year.channel ly_channel - ,last_year.i_brand_id ly_brand - ,last_year.i_class_id ly_class - ,last_year.i_category_id ly_category - ,last_year.sales ly_sales - ,last_year.number_sales ly_number_sales -from - (select 'store' channel, i_brand_id,i_class_id,i_category_id - ,sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1999 + 1 - and d_moy = 12 - and d_dom = 19) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) this_year, - (select 'store' channel, i_brand_id,i_class_id - ,i_category_id, sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1999 - and d_moy = 12 - and d_dom = 19) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) last_year - where this_year.i_brand_id= last_year.i_brand_id - and this_year.i_class_id = last_year.i_class_id - and this_year.i_category_id = last_year.i_category_id - order by this_year.channel, this_year.i_brand_id, this_year.i_class_id, this_year.i_category_id - limit 100; - --- end template query14a.tpl query 28 in stream 1 --- start template query50.tpl query 29 in stream 1 -select /* TPC-DS query50.tpl 0.60 */ - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 30) and - (sr_returned_date_sk - ss_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 60) and - (sr_returned_date_sk - ss_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 90) and - (sr_returned_date_sk - ss_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - store_sales - ,store_returns - ,store - ,date_dim d1 - ,date_dim d2 -where - d2.d_year = 2001 -and d2.d_moy = 10 -and ss_ticket_number = sr_ticket_number -and ss_item_sk = sr_item_sk -and ss_sold_date_sk = d1.d_date_sk -and sr_returned_date_sk = d2.d_date_sk -and ss_customer_sk = sr_customer_sk -and ss_store_sk = s_store_sk -group by - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -order by s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -limit 100; - --- end template query50.tpl query 29 in stream 1 --- start template query52.tpl query 30 in stream 1 -select /* TPC-DS query52.tpl 0.59 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_sales_price) ext_price - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=11 - and dt.d_year=2000 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,ext_price desc - ,brand_id -limit 100 ; - --- end template query52.tpl query 30 in stream 1 --- start template query81.tpl query 31 in stream 1 -with /* TPC-DS query81.tpl 0.37 */ customer_total_return as - (select cr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(cr_return_amt_inc_tax) as ctr_total_return - from catalog_returns - ,date_dim - ,customer_address - where cr_returned_date_sk = d_date_sk - and d_year =2001 - and cr_returning_addr_sk = ca_address_sk - group by cr_returning_customer_sk - ,ca_state ) - select c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'CO' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - limit 100; - --- end template query81.tpl query 31 in stream 1 --- start template query5a.tpl query 32 in stream 1 -with /* TPC-DS query5a.tpl 0.98 */ ssr as - (select s_store_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ss_store_sk as store_sk, - ss_sold_date_sk as date_sk, - ss_ext_sales_price as sales_price, - ss_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from store_sales - union all - select sr_store_sk as store_sk, - sr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - sr_return_amt as return_amt, - sr_net_loss as net_loss - from store_returns - ) salesreturns, - date_dim, - store - where date_sk = d_date_sk - and d_date between cast('2000-08-29' as date) - and dateadd(day,14,cast('2000-08-29' as date)) - and store_sk = s_store_sk - group by s_store_id) - , - csr as - (select cp_catalog_page_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select cs_catalog_page_sk as page_sk, - cs_sold_date_sk as date_sk, - cs_ext_sales_price as sales_price, - cs_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from catalog_sales - union all - select cr_catalog_page_sk as page_sk, - cr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - cr_return_amount as return_amt, - cr_net_loss as net_loss - from catalog_returns - ) salesreturns, - date_dim, - catalog_page - where date_sk = d_date_sk - and d_date between cast('2000-08-29' as date) - and dateadd(day,14,cast('2000-08-29' as date)) - and page_sk = cp_catalog_page_sk - group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ws_web_site_sk as wsr_web_site_sk, - ws_sold_date_sk as date_sk, - ws_ext_sales_price as sales_price, - ws_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from web_sales - union all - select ws_web_site_sk as wsr_web_site_sk, - wr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - wr_return_amt as return_amt, - wr_net_loss as net_loss - from web_returns left outer join web_sales on - ( wr_item_sk = ws_item_sk - and wr_order_number = ws_order_number) - ) salesreturns, - date_dim, - web_site - where date_sk = d_date_sk - and d_date between cast('2000-08-29' as date) - and dateadd(day,14,cast('2000-08-29' as date)) - and wsr_web_site_sk = web_site_sk - group by web_site_id) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || s_store_id as id - , sales - , returns - , (profit - profit_loss) as profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || cp_catalog_page_id as id - , sales - , returns - , (profit - profit_loss) as profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , (profit - profit_loss) as profit - from wsr - ) x - group by channel, id) - select channel, id, sales, returns, profit from ( - select channel, id, sales, returns, profit from results - union - select channel, null as id, sum(sales), sum(returns), sum(profit) from results group by channel - union - select null as channel, null as id, sum(sales), sum(returns), sum(profit) from results) foo -order by channel, id -limit 100; - --- end template query5a.tpl query 32 in stream 1 --- start template query26.tpl query 33 in stream 1 -select /* TPC-DS query26.tpl 0.85 */ i_item_id, - avg(cs_quantity) agg1, - avg(cs_list_price) agg2, - avg(cs_coupon_amt) agg3, - avg(cs_sales_price) agg4 - from catalog_sales, customer_demographics, date_dim, item, promotion - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd_demo_sk and - cs_promo_sk = p_promo_sk and - cd_gender = 'M' and - cd_marital_status = 'S' and - cd_education_status = 'Secondary' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 2002 - group by i_item_id - order by i_item_id - limit 100; - --- end template query26.tpl query 33 in stream 1 --- start template query57.tpl query 34 in stream 1 -with /* TPC-DS query57.tpl 0.70 */ v1 as( - select i_category, i_brand, - cc_name, - d_year, d_moy, - sum(cs_sales_price) sum_sales, - avg(sum(cs_sales_price)) over - (partition by i_category, i_brand, - cc_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - cc_name - order by d_year, d_moy) rn - from item, catalog_sales, date_dim, call_center - where cs_item_sk = i_item_sk and - cs_sold_date_sk = d_date_sk and - cc_call_center_sk= cs_call_center_sk and - ( - d_year = 2000 or - ( d_year = 2000-1 and d_moy =12) or - ( d_year = 2000+1 and d_moy =1) - ) - group by i_category, i_brand, - cc_name , d_year, d_moy), - v2 as( - select v1.cc_name - ,v1.d_year, v1.d_moy - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1. cc_name = v1_lag. cc_name and - v1. cc_name = v1_lead. cc_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 2000 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, psum - limit 100; - --- end template query57.tpl query 34 in stream 1 --- start template query82.tpl query 35 in stream 1 -select /* TPC-DS query82.tpl 0.67 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, store_sales - where i_current_price between 22 and 22+30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('2001-06-08' as date) and dateadd(day,60,cast('2001-06-08' as date)) - and i_manufact_id in (834,94,740,554) - and inv_quantity_on_hand between 100 and 500 - and ss_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query82.tpl query 35 in stream 1 --- start template query69.tpl query 36 in stream 1 -select /* TPC-DS query69.tpl 0.28 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_state in ('NY','NC','OH') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2004 and - d_moy between 1 and 1+2) and - (not exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2004 and - d_moy between 1 and 1+2) and - not exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2004 and - d_moy between 1 and 1+2)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - limit 100; - --- end template query69.tpl query 36 in stream 1 --- start template query54.tpl query 37 in stream 1 -with /* TPC-DS query54.tpl 0.81 */ my_customers as ( - select distinct c_customer_sk - , c_current_addr_sk - from - ( select cs_sold_date_sk sold_date_sk, - cs_bill_customer_sk customer_sk, - cs_item_sk item_sk - from catalog_sales - union all - select ws_sold_date_sk sold_date_sk, - ws_bill_customer_sk customer_sk, - ws_item_sk item_sk - from web_sales - ) cs_or_ws_sales, - item, - date_dim, - customer - where sold_date_sk = d_date_sk - and item_sk = i_item_sk - and i_category = 'Men' - and i_class = 'sports-apparel' - and c_customer_sk = cs_or_ws_sales.customer_sk - and d_moy = 4 - and d_year = 1998 - ) - , my_revenue as ( - select c_customer_sk, - sum(ss_ext_sales_price) as revenue - from my_customers, - store_sales, - customer_address, - store, - date_dim - where c_current_addr_sk = ca_address_sk - and ca_county = s_county - and ca_state = s_state - and ss_sold_date_sk = d_date_sk - and c_customer_sk = ss_customer_sk - and d_month_seq between (select distinct d_month_seq+1 - from date_dim where d_year = 1998 and d_moy = 4) - and (select distinct d_month_seq+3 - from date_dim where d_year = 1998 and d_moy = 4) - group by c_customer_sk - ) - , segments as - (select cast((revenue/50) as bigint) as segment - from my_revenue - ) - select segment, count(*) as num_customers, segment*50 as segment_base - from segments - group by segment - order by segment, num_customers - limit 100; - --- end template query54.tpl query 37 in stream 1 --- start template query61.tpl query 38 in stream 1 -select /* TPC-DS query61.tpl 0.97 */ promotions,total,cast(promotions as decimal(16,4))/cast(total as decimal(16,4))*100 -from - (select sum(ss_ext_sales_price) promotions - from store_sales - ,store - ,promotion - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_promo_sk = p_promo_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -7 - and i_category = 'Jewelry' - and (p_channel_dmail = 'Y' or p_channel_email = 'Y' or p_channel_tv = 'Y') - and s_gmt_offset = -7 - and d_year = 1999 - and d_moy = 11) promotional_sales, - (select sum(ss_ext_sales_price) total - from store_sales - ,store - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -7 - and i_category = 'Jewelry' - and s_gmt_offset = -7 - and d_year = 1999 - and d_moy = 11) all_sales -order by promotions, total -limit 100; - --- end template query61.tpl query 38 in stream 1 --- start template query88.tpl query 39 in stream 1 -select /* TPC-DS query88.tpl 0.66 */ * -from - (select count(*) h8_30_to_9 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s1, - (select count(*) h9_to_9_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s2, - (select count(*) h9_30_to_10 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s3, - (select count(*) h10_to_10_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s4, - (select count(*) h10_30_to_11 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s5, - (select count(*) h11_to_11_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s6, - (select count(*) h11_30_to_12 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s7, - (select count(*) h12_to_12_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 12 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s8 -; - --- end template query88.tpl query 39 in stream 1 --- start template query18a.tpl query 40 in stream 1 -with /* TPC-DS query18a.tpl 0.90 */ results as - (select i_item_id, - ca_country, - ca_state, - ca_county, - cast(cs_quantity as decimal(12,2)) agg1, - cast(cs_list_price as decimal(12,2)) agg2, - cast(cs_coupon_amt as decimal(12,2)) agg3, - cast(cs_sales_price as decimal(12,2)) agg4, - cast(cs_net_profit as decimal(12,2)) agg5, - cast(c_birth_year as decimal(12,2)) agg6, - cast(cd1.cd_dep_count as decimal(12,2)) agg7 - from catalog_sales, customer_demographics cd1, customer_demographics cd2, customer, customer_address, date_dim, item - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd1.cd_demo_sk and - cs_bill_customer_sk = c_customer_sk and - cd1.cd_gender = 'M' and - cd1.cd_education_status = 'Secondary' and - c_current_cdemo_sk = cd2.cd_demo_sk and - c_current_addr_sk = ca_address_sk and - c_birth_month in (12,7,2,1,8,3) and - d_year = 1998 and - ca_state in ('VA','WI','TN','MS','TX','NC','PA') - ) - select i_item_id, ca_country, ca_state, ca_county, agg1, agg2, agg3, agg4, agg5, agg6, agg7 - from ( - select i_item_id, ca_country, ca_state, ca_county, avg(agg1) agg1, - avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state, ca_county - union all - select i_item_id, ca_country, ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state - union all - select i_item_id, ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country - union all - select i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - ) foo - order by ca_country, ca_state, ca_county, i_item_id - limit 100; - --- end template query18a.tpl query 40 in stream 1 --- start template query94.tpl query 41 in stream 1 -select /* TPC-DS query94.tpl 0.17 */ - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2000-5-01' and - dateadd(day,60,cast('2000-5-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'OK' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and exists (select * - from web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) -and not exists(select * - from web_returns wr1 - where ws1.ws_order_number = wr1.wr_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query94.tpl query 41 in stream 1 --- start template query35a.tpl query 42 in stream 1 -select /* TPC-DS query35a.tpl 0.47 */ - ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - count(*) cnt1, - stddev_samp(cd_dep_count), - max(cd_dep_count), - sum(cd_dep_count), - cd_dep_employed_count, - count(*) cnt2, - stddev_samp(cd_dep_employed_count), - max(cd_dep_employed_count), - sum(cd_dep_employed_count), - cd_dep_college_count, - count(*) cnt3, - stddev_samp(cd_dep_college_count), - max(cd_dep_college_count), - sum(cd_dep_college_count) - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 1999 and - d_qoy < 4) and - exists (select * from - (select ws_bill_customer_sk customsk - from web_sales,date_dim - where - ws_sold_date_sk = d_date_sk and - d_year = 1999 and - d_qoy < 4 - union all - select cs_ship_customer_sk customsk - from catalog_sales,date_dim - where - cs_sold_date_sk = d_date_sk and - d_year = 1999 and - d_qoy < 4)x - where x.customsk = c.c_customer_sk) - group by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - limit 100; - --- end template query35a.tpl query 42 in stream 1 --- start template query68.tpl query 43 in stream 1 -select /* TPC-DS query68.tpl 0.95 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,extended_price - ,extended_tax - ,list_price - from (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_ext_sales_price) extended_price - ,sum(ss_ext_list_price) list_price - ,sum(ss_ext_tax) extended_tax - from store_sales - ,date_dim - ,store - ,household_demographics - ,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_dep_count = 7 or - household_demographics.hd_vehicle_count= -1) - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_city in ('Liberty','Buckeye') - group by ss_ticket_number - ,ss_customer_sk - ,ss_addr_sk,ca_city) dn - ,customer - ,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,ss_ticket_number - limit 100; - --- end template query68.tpl query 43 in stream 1 --- start template query24.tpl query 44 in stream 1 -with /* TPC-DS query24.tpl 0.92 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_sales_price) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip -and s_market_id=5 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'misty' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; -with /* TPC-DS query24.tpl 0.92 part2 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_sales_price) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip - and s_market_id = 5 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'yellow' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; - --- end template query24.tpl query 44 in stream 1 --- start template query75.tpl query 45 in stream 1 -WITH /* TPC-DS query75.tpl 0.3 */ all_sales AS ( - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,SUM(sales_cnt) AS sales_cnt - ,SUM(sales_amt) AS sales_amt - FROM (SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,cs_quantity - COALESCE(cr_return_quantity,0) AS sales_cnt - ,cs_ext_sales_price - COALESCE(cr_return_amount,0.0) AS sales_amt - FROM catalog_sales JOIN item ON i_item_sk=cs_item_sk - JOIN date_dim ON d_date_sk=cs_sold_date_sk - LEFT JOIN catalog_returns ON (cs_order_number=cr_order_number - AND cs_item_sk=cr_item_sk) - WHERE i_category='Women' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ss_quantity - COALESCE(sr_return_quantity,0) AS sales_cnt - ,ss_ext_sales_price - COALESCE(sr_return_amt,0.0) AS sales_amt - FROM store_sales JOIN item ON i_item_sk=ss_item_sk - JOIN date_dim ON d_date_sk=ss_sold_date_sk - LEFT JOIN store_returns ON (ss_ticket_number=sr_ticket_number - AND ss_item_sk=sr_item_sk) - WHERE i_category='Women' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ws_quantity - COALESCE(wr_return_quantity,0) AS sales_cnt - ,ws_ext_sales_price - COALESCE(wr_return_amt,0.0) AS sales_amt - FROM web_sales JOIN item ON i_item_sk=ws_item_sk - JOIN date_dim ON d_date_sk=ws_sold_date_sk - LEFT JOIN web_returns ON (ws_order_number=wr_order_number - AND ws_item_sk=wr_item_sk) - WHERE i_category='Women') sales_detail - GROUP BY d_year, i_brand_id, i_class_id, i_category_id, i_manufact_id) - SELECT prev_yr.d_year AS prev_year - ,curr_yr.d_year AS year - ,curr_yr.i_brand_id - ,curr_yr.i_class_id - ,curr_yr.i_category_id - ,curr_yr.i_manufact_id - ,prev_yr.sales_cnt AS prev_yr_cnt - ,curr_yr.sales_cnt AS curr_yr_cnt - ,curr_yr.sales_cnt-prev_yr.sales_cnt AS sales_cnt_diff - ,curr_yr.sales_amt-prev_yr.sales_amt AS sales_amt_diff - FROM all_sales curr_yr, all_sales prev_yr - WHERE curr_yr.i_brand_id=prev_yr.i_brand_id - AND curr_yr.i_class_id=prev_yr.i_class_id - AND curr_yr.i_category_id=prev_yr.i_category_id - AND curr_yr.i_manufact_id=prev_yr.i_manufact_id - AND curr_yr.d_year=1999 - AND prev_yr.d_year=1999-1 - AND CAST(curr_yr.sales_cnt AS DECIMAL(17,2))/CAST(prev_yr.sales_cnt AS DECIMAL(17,2))<0.9 - ORDER BY sales_cnt_diff,sales_amt_diff - limit 100; - --- end template query75.tpl query 45 in stream 1 --- start template query11.tpl query 46 in stream 1 -with /* TPC-DS query11.tpl 0.51 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ss_ext_list_price-ss_ext_discount_amt) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ws_ext_list_price-ws_ext_discount_amt) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_email_address - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 2001 - and t_s_secyear.dyear = 2001+1 - and t_w_firstyear.dyear = 2001 - and t_w_secyear.dyear = 2001+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else 0.0 end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else 0.0 end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_email_address -limit 100; - --- end template query11.tpl query 46 in stream 1 --- start template query67a.tpl query 47 in stream 1 -with /* TPC-DS query67a.tpl 0.35 */ results as -( select i_category ,i_class ,i_brand ,i_product_name ,d_year ,d_qoy ,d_moy ,s_store_id - ,sum(coalesce(ss_sales_price*ss_quantity,0)) sumsales - from store_sales ,date_dim ,store ,item - where ss_sold_date_sk=d_date_sk - and ss_item_sk=i_item_sk - and ss_store_sk = s_store_sk - and d_month_seq between 1188 and 1188 + 11 - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy,s_store_id) - , - results_rollup as - (select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, s_store_id, sumsales - from results - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy - union all - select i_category, i_class, i_brand, i_product_name, d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year - union all - select i_category, i_class, i_brand, i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name - union all - select i_category, i_class, i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand - union all - select i_category, i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class - union all - select i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category - union all - select null i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results) - - select * -from (select i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rank() over (partition by i_category order by sumsales desc) rk - from results_rollup) dw2 -where rk <= 100 -order by i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rk -limit 100; - --- end template query67a.tpl query 47 in stream 1 --- start template query9.tpl query 48 in stream 1 -select /* TPC-DS query9.tpl 0.49 */ case when (select count(*) - from store_sales - where ss_quantity between 1 and 20) > 2873076168 - then (select avg(ss_ext_list_price) - from store_sales - where ss_quantity between 1 and 20) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 1 and 20) end bucket1 , - case when (select count(*) - from store_sales - where ss_quantity between 21 and 40) > 3909301578 - then (select avg(ss_ext_list_price) - from store_sales - where ss_quantity between 21 and 40) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 21 and 40) end bucket2, - case when (select count(*) - from store_sales - where ss_quantity between 41 and 60) > 4296516047 - then (select avg(ss_ext_list_price) - from store_sales - where ss_quantity between 41 and 60) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 41 and 60) end bucket3, - case when (select count(*) - from store_sales - where ss_quantity between 61 and 80) > 3937448702 - then (select avg(ss_ext_list_price) - from store_sales - where ss_quantity between 61 and 80) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 61 and 80) end bucket4, - case when (select count(*) - from store_sales - where ss_quantity between 81 and 100) > 3534505721 - then (select avg(ss_ext_list_price) - from store_sales - where ss_quantity between 81 and 100) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 81 and 100) end bucket5 -from reason -where r_reason_sk = 1 -; - --- end template query9.tpl query 48 in stream 1 --- start template query25.tpl query 49 in stream 1 -select /* TPC-DS query25.tpl 0.9 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,stddev_samp(ss_net_profit) as store_sales_profit - ,stddev_samp(sr_net_loss) as store_returns_loss - ,stddev_samp(cs_net_profit) as catalog_sales_profit - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 2002 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 10 - and d2.d_year = 2002 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_moy between 4 and 10 - and d3.d_year = 2002 - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query25.tpl query 49 in stream 1 --- start template query37.tpl query 50 in stream 1 -select /* TPC-DS query37.tpl 0.31 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, catalog_sales - where i_current_price between 33 and 33 + 30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('2002-05-07' as date) and dateadd(day,60,cast('2002-05-07' as date)) - and i_manufact_id in (803,994,780,831) - and inv_quantity_on_hand between 100 and 500 - and cs_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query37.tpl query 50 in stream 1 --- start template query86a.tpl query 51 in stream 1 -with /* TPC-DS query86a.tpl 0.11 */ results as -( select sum(ws_net_paid) as total_sum, i_category, i_class, 0 as g_category, 0 as g_class - from - web_sales - ,date_dim d1 - ,item - where - d1.d_month_seq between 1196 and 1196+11 - and d1.d_date_sk = ws_sold_date_sk - and i_item_sk = ws_item_sk - group by i_category,i_class - ) , - - results_rollup as -( select total_sum ,i_category ,i_class, g_category, g_class, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum, i_category, NULL as i_class, 0 as g_category, 1 as g_class, 1 as lochierarchy from results group by i_category - union - select sum(total_sum) as total_sum, NULL as i_category, NULL as i_class, 1 as g_category, 1 as g_class, 2 as lochierarchy from results) - select - total_sum ,i_category ,i_class, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_class = 0 then i_category end - order by total_sum desc) as rank_within_parent - from - results_rollup - order by - lochierarchy desc, - case when lochierarchy = 0 then i_category end, - rank_within_parent - limit 100; - --- end template query86a.tpl query 51 in stream 1 --- start template query4.tpl query 52 in stream 1 -with /* TPC-DS query4.tpl 0.93 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(((ss_ext_list_price-ss_ext_wholesale_cost-ss_ext_discount_amt)+ss_ext_sales_price)/2) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((cs_ext_list_price-cs_ext_wholesale_cost-cs_ext_discount_amt)+cs_ext_sales_price)/2) ) year_total - ,'c' sale_type - from customer - ,catalog_sales - ,date_dim - where c_customer_sk = cs_bill_customer_sk - and cs_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year -union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((ws_ext_list_price-ws_ext_wholesale_cost-ws_ext_discount_amt)+ws_ext_sales_price)/2) ) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_preferred_cust_flag - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_c_firstyear - ,year_total t_c_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_c_secyear.customer_id - and t_s_firstyear.customer_id = t_c_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_c_firstyear.sale_type = 'c' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_c_secyear.sale_type = 'c' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 2001 - and t_s_secyear.dyear = 2001+1 - and t_c_firstyear.dyear = 2001 - and t_c_secyear.dyear = 2001+1 - and t_w_firstyear.dyear = 2001 - and t_w_secyear.dyear = 2001+1 - and t_s_firstyear.year_total > 0 - and t_c_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_preferred_cust_flag -limit 100; - --- end template query4.tpl query 52 in stream 1 --- start template query60.tpl query 53 in stream 1 -with /* TPC-DS query60.tpl 0.29 */ ss as ( - select - i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Music')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 10 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - cs as ( - select - i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Music')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 10 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - ws as ( - select - i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Music')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 10 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id) - select - i_item_id -,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by i_item_id - ,total_sales - limit 100; - --- end template query60.tpl query 53 in stream 1 --- start template query97.tpl query 54 in stream 1 -with /* TPC-DS query97.tpl 0.38 */ ssci as ( -select ss_customer_sk customer_sk - ,ss_item_sk item_sk -from store_sales,date_dim -where ss_sold_date_sk = d_date_sk - and d_month_seq between 1189 and 1189 + 11 -group by ss_customer_sk - ,ss_item_sk), -csci as( - select cs_bill_customer_sk customer_sk - ,cs_item_sk item_sk -from catalog_sales,date_dim -where cs_sold_date_sk = d_date_sk - and d_month_seq between 1189 and 1189 + 11 -group by cs_bill_customer_sk - ,cs_item_sk) - select sum(case when ssci.customer_sk is not null and csci.customer_sk is null then 1 else 0 end) store_only - ,sum(case when ssci.customer_sk is null and csci.customer_sk is not null then 1 else 0 end) catalog_only - ,sum(case when ssci.customer_sk is not null and csci.customer_sk is not null then 1 else 0 end) store_and_catalog -from ssci full outer join csci on (ssci.customer_sk=csci.customer_sk - and ssci.item_sk = csci.item_sk) -limit 100; - --- end template query97.tpl query 54 in stream 1 --- start template query33.tpl query 55 in stream 1 -with /* TPC-DS query33.tpl 0.22 */ ss as ( - select - i_manufact_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Jewelry')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 7 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -8 - group by i_manufact_id), - cs as ( - select - i_manufact_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Jewelry')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 7 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -8 - group by i_manufact_id), - ws as ( - select - i_manufact_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Jewelry')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 7 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -8 - group by i_manufact_id) - select i_manufact_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_manufact_id - order by total_sales -limit 100; - --- end template query33.tpl query 55 in stream 1 --- start template query79.tpl query 56 in stream 1 -select /* TPC-DS query79.tpl 0.89 */ - c_last_name,c_first_name,substring(s_city,1,30),ss_ticket_number,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,store.s_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (household_demographics.hd_dep_count = 9 or household_demographics.hd_vehicle_count > 0) - and date_dim.d_dow = 1 - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_number_employees between 200 and 295 - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,store.s_city) ms,customer - where ss_customer_sk = c_customer_sk - order by c_last_name,c_first_name,substring(s_city,1,30), profit -limit 100; - --- end template query79.tpl query 56 in stream 1 --- start template query43.tpl query 57 in stream 1 -select /* TPC-DS query43.tpl 0.15 */ s_store_name, s_store_id, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from date_dim, store_sales, store - where d_date_sk = ss_sold_date_sk and - s_store_sk = ss_store_sk and - s_gmt_offset = -7 and - d_year = 2002 - group by s_store_name, s_store_id - order by s_store_name, s_store_id,sun_sales,mon_sales,tue_sales,wed_sales,thu_sales,fri_sales,sat_sales - limit 100; - --- end template query43.tpl query 57 in stream 1 --- start template query80a.tpl query 58 in stream 1 -with /* TPC-DS query80a.tpl 0.6 */ ssr as - (select s_store_id as store_id, - sum(ss_ext_sales_price) as sales, - sum(coalesce(sr_return_amt, 0)) as returns, - sum(ss_net_profit - coalesce(sr_net_loss, 0)) as profit - from store_sales left outer join store_returns on - (ss_item_sk = sr_item_sk and ss_ticket_number = sr_ticket_number), - date_dim, - store, - item, - promotion - where ss_sold_date_sk = d_date_sk - and d_date between cast('2001-08-20' as date) - and dateadd(day,30,cast('2001-08-20' as date)) - and ss_store_sk = s_store_sk - and ss_item_sk = i_item_sk - and i_current_price > 50 - and ss_promo_sk = p_promo_sk - and p_channel_tv = 'N' - group by s_store_id) - , - csr as - (select cp_catalog_page_id as catalog_page_id, - sum(cs_ext_sales_price) as sales, - sum(coalesce(cr_return_amount, 0)) as returns, - sum(cs_net_profit - coalesce(cr_net_loss, 0)) as profit - from catalog_sales left outer join catalog_returns on - (cs_item_sk = cr_item_sk and cs_order_number = cr_order_number), - date_dim, - catalog_page, - item, - promotion - where cs_sold_date_sk = d_date_sk - and d_date between cast('2001-08-20' as date) - and dateadd(day,30,cast('2001-08-20' as date)) - and cs_catalog_page_sk = cp_catalog_page_sk - and cs_item_sk = i_item_sk - and i_current_price > 50 - and cs_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(ws_ext_sales_price) as sales, - sum(coalesce(wr_return_amt, 0)) as returns, - sum(ws_net_profit - coalesce(wr_net_loss, 0)) as profit - from web_sales left outer join web_returns on - (ws_item_sk = wr_item_sk and ws_order_number = wr_order_number), - date_dim, - web_site, - item, - promotion - where ws_sold_date_sk = d_date_sk - and d_date between cast('2001-08-20' as date) - and dateadd(day,30,cast('2001-08-20' as date)) - and ws_web_site_sk = web_site_sk - and ws_item_sk = i_item_sk - and i_current_price > 50 - and ws_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by web_site_id) -, -results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || store_id as id - , sales - , returns - , profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || catalog_page_id as id - , sales - , returns - , profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , profit - from wsr - ) x - group by channel, id) - - select channel - , id - , sales - , returns - , profit - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results - ) foo - order by channel, id - limit 100; - --- end template query80a.tpl query 58 in stream 1 --- start template query93.tpl query 59 in stream 1 -select /* TPC-DS query93.tpl 0.52 */ ss_customer_sk - ,sum(act_sales) sumsales - from (select ss_item_sk - ,ss_ticket_number - ,ss_customer_sk - ,case when sr_return_quantity is not null then (ss_quantity-sr_return_quantity)*ss_sales_price - else (ss_quantity*ss_sales_price) end act_sales - from store_sales left outer join store_returns on (sr_item_sk = ss_item_sk - and sr_ticket_number = ss_ticket_number) - ,reason - where sr_reason_sk = r_reason_sk - and r_reason_desc = 'reason 52') t - group by ss_customer_sk - order by sumsales, ss_customer_sk -limit 100; - --- end template query93.tpl query 59 in stream 1 --- start template query31.tpl query 60 in stream 1 -with /* TPC-DS query31.tpl 0.50 */ ss as - (select ca_county,d_qoy, d_year,sum(ss_ext_sales_price) as store_sales - from store_sales,date_dim,customer_address - where ss_sold_date_sk = d_date_sk - and ss_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year), - ws as - (select ca_county,d_qoy, d_year,sum(ws_ext_sales_price) as web_sales - from web_sales,date_dim,customer_address - where ws_sold_date_sk = d_date_sk - and ws_bill_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year) - select - ss1.ca_county - ,ss1.d_year - ,ws2.web_sales/ws1.web_sales web_q1_q2_increase - ,ss2.store_sales/ss1.store_sales store_q1_q2_increase - ,ws3.web_sales/ws2.web_sales web_q2_q3_increase - ,ss3.store_sales/ss2.store_sales store_q2_q3_increase - from - ss ss1 - ,ss ss2 - ,ss ss3 - ,ws ws1 - ,ws ws2 - ,ws ws3 - where - ss1.d_qoy = 1 - and ss1.d_year = 2001 - and ss1.ca_county = ss2.ca_county - and ss2.d_qoy = 2 - and ss2.d_year = 2001 - and ss2.ca_county = ss3.ca_county - and ss3.d_qoy = 3 - and ss3.d_year = 2001 - and ss1.ca_county = ws1.ca_county - and ws1.d_qoy = 1 - and ws1.d_year = 2001 - and ws1.ca_county = ws2.ca_county - and ws2.d_qoy = 2 - and ws2.d_year = 2001 - and ws1.ca_county = ws3.ca_county - and ws3.d_qoy = 3 - and ws3.d_year =2001 - and case when ws1.web_sales > 0 then ws2.web_sales/ws1.web_sales else null end - > case when ss1.store_sales > 0 then ss2.store_sales/ss1.store_sales else null end - and case when ws2.web_sales > 0 then ws3.web_sales/ws2.web_sales else null end - > case when ss2.store_sales > 0 then ss3.store_sales/ss2.store_sales else null end - order by store_q1_q2_increase; - --- end template query31.tpl query 60 in stream 1 --- start template query47.tpl query 61 in stream 1 -with /* TPC-DS query47.tpl 0.42 */ v1 as( - select i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, - s_store_name, s_company_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - s_store_name, s_company_name - order by d_year, d_moy) rn - from item, store_sales, date_dim, store - where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - ( - d_year = 2000 or - ( d_year = 2000-1 and d_moy =12) or - ( d_year = 2000+1 and d_moy =1) - ) - group by i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy), - v2 as( - select v1.s_store_name, v1.s_company_name - ,v1.d_year - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1.s_store_name = v1_lag.s_store_name and - v1.s_store_name = v1_lead.s_store_name and - v1.s_company_name = v1_lag.s_company_name and - v1.s_company_name = v1_lead.s_company_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 2000 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, avg_monthly_sales - limit 100; - --- end template query47.tpl query 61 in stream 1 --- start template query17.tpl query 62 in stream 1 -select /* TPC-DS query17.tpl 0.41 */ i_item_id - ,i_item_desc - ,s_state - ,count(ss_quantity) as store_sales_quantitycount - ,avg(ss_quantity) as store_sales_quantityave - ,stddev_samp(ss_quantity) as store_sales_quantitystdev - ,stddev_samp(ss_quantity)/avg(ss_quantity) as store_sales_quantitycov - ,count(sr_return_quantity) as store_returns_quantitycount - ,avg(sr_return_quantity) as store_returns_quantityave - ,stddev_samp(sr_return_quantity) as store_returns_quantitystdev - ,stddev_samp(sr_return_quantity)/avg(sr_return_quantity) as store_returns_quantitycov - ,count(cs_quantity) as catalog_sales_quantitycount ,avg(cs_quantity) as catalog_sales_quantityave - ,stddev_samp(cs_quantity) as catalog_sales_quantitystdev - ,stddev_samp(cs_quantity)/avg(cs_quantity) as catalog_sales_quantitycov - from store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where d1.d_quarter_name = '2000Q1' - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_quarter_name in ('2000Q1','2000Q2','2000Q3') - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_quarter_name in ('2000Q1','2000Q2','2000Q3') - group by i_item_id - ,i_item_desc - ,s_state - order by i_item_id - ,i_item_desc - ,s_state -limit 100; - --- end template query17.tpl query 62 in stream 1 --- start template query19.tpl query 63 in stream 1 -select /* TPC-DS query19.tpl 0.8 */ i_brand_id brand_id, i_brand brand, i_manufact_id, i_manufact, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item,customer,customer_address,store - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=6 - and d_moy=11 - and d_year=2001 - and ss_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and substring(ca_zip,1,5) <> substring(s_zip,1,5) - and ss_store_sk = s_store_sk - group by i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact - order by ext_price desc - ,i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact -limit 100 ; - --- end template query19.tpl query 63 in stream 1 --- start template query1.tpl query 64 in stream 1 -with /* TPC-DS query1.tpl 0.12 */ customer_total_return as -(select sr_customer_sk as ctr_customer_sk -,sr_store_sk as ctr_store_sk -,sum(SR_STORE_CREDIT) as ctr_total_return -from store_returns -,date_dim -where sr_returned_date_sk = d_date_sk -and d_year =2000 -group by sr_customer_sk -,sr_store_sk) - select c_customer_id -from customer_total_return ctr1 -,store -,customer -where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 -from customer_total_return ctr2 -where ctr1.ctr_store_sk = ctr2.ctr_store_sk) -and s_store_sk = ctr1.ctr_store_sk -and s_state = 'VA' -and ctr1.ctr_customer_sk = c_customer_sk -order by c_customer_id -limit 100; - --- end template query1.tpl query 64 in stream 1 --- start template query64.tpl query 65 in stream 1 -with /* TPC-DS query64.tpl 0.20 */ cs_ui as - (select cs_item_sk - ,sum(cs_ext_list_price) as sale,sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit) as refund - from catalog_sales - ,catalog_returns - where cs_item_sk = cr_item_sk - and cs_order_number = cr_order_number - group by cs_item_sk - having sum(cs_ext_list_price)>2*sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit)), -cross_sales as - (select i_product_name product_name - ,i_item_sk item_sk - ,s_store_name store_name - ,s_zip store_zip - ,ad1.ca_street_number b_street_number - ,ad1.ca_street_name b_street_name - ,ad1.ca_city b_city - ,ad1.ca_zip b_zip - ,ad2.ca_street_number c_street_number - ,ad2.ca_street_name c_street_name - ,ad2.ca_city c_city - ,ad2.ca_zip c_zip - ,d1.d_year as syear - ,d2.d_year as fsyear - ,d3.d_year s2year - ,count(*) cnt - ,sum(ss_wholesale_cost) s1 - ,sum(ss_list_price) s2 - ,sum(ss_coupon_amt) s3 - FROM store_sales - ,store_returns - ,cs_ui - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,customer - ,customer_demographics cd1 - ,customer_demographics cd2 - ,promotion - ,household_demographics hd1 - ,household_demographics hd2 - ,customer_address ad1 - ,customer_address ad2 - ,income_band ib1 - ,income_band ib2 - ,item - WHERE ss_store_sk = s_store_sk AND - ss_sold_date_sk = d1.d_date_sk AND - ss_customer_sk = c_customer_sk AND - ss_cdemo_sk= cd1.cd_demo_sk AND - ss_hdemo_sk = hd1.hd_demo_sk AND - ss_addr_sk = ad1.ca_address_sk and - ss_item_sk = i_item_sk and - ss_item_sk = sr_item_sk and - ss_ticket_number = sr_ticket_number and - ss_item_sk = cs_ui.cs_item_sk and - c_current_cdemo_sk = cd2.cd_demo_sk AND - c_current_hdemo_sk = hd2.hd_demo_sk AND - c_current_addr_sk = ad2.ca_address_sk and - c_first_sales_date_sk = d2.d_date_sk and - c_first_shipto_date_sk = d3.d_date_sk and - ss_promo_sk = p_promo_sk and - hd1.hd_income_band_sk = ib1.ib_income_band_sk and - hd2.hd_income_band_sk = ib2.ib_income_band_sk and - cd1.cd_marital_status <> cd2.cd_marital_status and - i_color in ('ghost','grey','antique','dim','violet','blush') and - i_current_price between 79 and 79 + 10 and - i_current_price between 79 + 1 and 79 + 15 -group by i_product_name - ,i_item_sk - ,s_store_name - ,s_zip - ,ad1.ca_street_number - ,ad1.ca_street_name - ,ad1.ca_city - ,ad1.ca_zip - ,ad2.ca_street_number - ,ad2.ca_street_name - ,ad2.ca_city - ,ad2.ca_zip - ,d1.d_year - ,d2.d_year - ,d3.d_year -) -select cs1.product_name - ,cs1.store_name - ,cs1.store_zip - ,cs1.b_street_number - ,cs1.b_street_name - ,cs1.b_city - ,cs1.b_zip - ,cs1.c_street_number - ,cs1.c_street_name - ,cs1.c_city - ,cs1.c_zip - ,cs1.syear - ,cs1.cnt - ,cs1.s1 as s11 - ,cs1.s2 as s21 - ,cs1.s3 as s31 - ,cs2.s1 as s12 - ,cs2.s2 as s22 - ,cs2.s3 as s32 - ,cs2.syear - ,cs2.cnt -from cross_sales cs1,cross_sales cs2 -where cs1.item_sk=cs2.item_sk and - cs1.syear = 2000 and - cs2.syear = 2000 + 1 and - cs2.cnt <= cs1.cnt and - cs1.store_name = cs2.store_name and - cs1.store_zip = cs2.store_zip -order by cs1.product_name - ,cs1.store_name - ,cs2.cnt - ,cs1.s1 - ,cs2.s1; - --- end template query64.tpl query 65 in stream 1 --- start template query53.tpl query 66 in stream 1 -select /* TPC-DS query53.tpl 0.88 */ * from -(select i_manufact_id, -sum(ss_sales_price) sum_sales, -avg(sum(ss_sales_price)) over (partition by i_manufact_id) avg_quarterly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and -ss_sold_date_sk = d_date_sk and -ss_store_sk = s_store_sk and -d_month_seq in (1219,1219+1,1219+2,1219+3,1219+4,1219+5,1219+6,1219+7,1219+8,1219+9,1219+10,1219+11) and -((i_category in ('Books','Children','Electronics') and -i_class in ('personal','portable','reference','self-help') and -i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) -or(i_category in ('Women','Music','Men') and -i_class in ('accessories','classical','fragrances','pants') and -i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manufact_id, d_qoy ) tmp1 -where case when avg_quarterly_sales > 0 - then abs (sum_sales - avg_quarterly_sales)/ avg_quarterly_sales - else null end > 0.1 -order by avg_quarterly_sales, - sum_sales, - i_manufact_id -limit 100; - --- end template query53.tpl query 66 in stream 1 --- start template query55.tpl query 67 in stream 1 -select /* TPC-DS query55.tpl 0.82 */ i_brand_id brand_id, i_brand brand, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=55 - and d_moy=11 - and d_year=2002 - group by i_brand, i_brand_id - order by ext_price desc, i_brand_id -limit 100 ; - --- end template query55.tpl query 67 in stream 1 --- start template query46.tpl query 68 in stream 1 -select /* TPC-DS query46.tpl 0.23 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and (household_demographics.hd_dep_count = 0 or - household_demographics.hd_vehicle_count= -1) - and date_dim.d_dow in (6,0) - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_city in ('Portland','Lowell','Harrison','Simpson','Dover') - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,ca_city) dn,customer,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - limit 100; - --- end template query46.tpl query 68 in stream 1 --- start template query21.tpl query 69 in stream 1 -select /* TPC-DS query21.tpl 0.14 */ * - from(select w_warehouse_name - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('2001-03-09' as date)) - then inv_quantity_on_hand - else 0 end) as inv_before - ,sum(case when (cast(d_date as date) >= cast ('2001-03-09' as date)) - then inv_quantity_on_hand - else 0 end) as inv_after - from inventory - ,warehouse - ,item - ,date_dim - where i_current_price between 0.99 and 1.49 - and i_item_sk = inv_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('2001-03-09' as date)) - and dateadd(day,30,cast ('2001-03-09' as date)) - group by w_warehouse_name, i_item_id) x - where (case when inv_before > 0 - then inv_after / inv_before - else null - end) between 2.0/3.0 and 3.0/2.0 - order by w_warehouse_name - ,i_item_id - limit 100; - --- end template query21.tpl query 69 in stream 1 --- start template query15.tpl query 70 in stream 1 -select /* TPC-DS query15.tpl 0.57 */ ca_zip - ,sum(cs_sales_price) - from catalog_sales - ,customer - ,customer_address - ,date_dim - where cs_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', - '85392', '85460', '80348', '81792') - or ca_state in ('CA','WA','GA') - or cs_sales_price > 500) - and cs_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 1998 - group by ca_zip - order by ca_zip - limit 100; - --- end template query15.tpl query 70 in stream 1 --- start template query20.tpl query 71 in stream 1 -select /* TPC-DS query20.tpl 0.65 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(cs_ext_sales_price) as itemrevenue - ,sum(cs_ext_sales_price)*100/sum(sum(cs_ext_sales_price)) over - (partition by i_class) as revenueratio - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and i_category in ('Jewelry', 'Books', 'Home') - and cs_sold_date_sk = d_date_sk - and d_date between cast('2002-01-12' as date) - and dateadd(day,30,cast('2002-01-12' as date)) - group by i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - order by i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query20.tpl query 71 in stream 1 --- start template query65.tpl query 72 in stream 1 -select /* TPC-DS query65.tpl 0.71 */ - s_store_name, - i_item_desc, - sc.revenue, - i_current_price, - i_wholesale_cost, - i_brand - from store, item, - (select ss_store_sk, avg(revenue) as ave - from - (select ss_store_sk, ss_item_sk, - sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1213 and 1213+11 - group by ss_store_sk, ss_item_sk) sa - group by ss_store_sk) sb, - (select ss_store_sk, ss_item_sk, sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1213 and 1213+11 - group by ss_store_sk, ss_item_sk) sc - where sb.ss_store_sk = sc.ss_store_sk and - sc.revenue <= 0.1 * sb.ave and - s_store_sk = sc.ss_store_sk and - i_item_sk = sc.ss_item_sk - order by s_store_name, i_item_desc -limit 100; - --- end template query65.tpl query 72 in stream 1 --- start template query70a.tpl query 73 in stream 1 -with /* TPC-DS query70a.tpl 0.34 */ results as -( select - sum(ss_net_profit) as total_sum ,s_state ,s_county, 0 as gstate, 0 as g_county - from - store_sales - ,date_dim d1 - ,store - where - d1.d_month_seq between 1185 and 1185 + 11 - and d1.d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - and s_state in - ( select s_state - from (select s_state as s_state, - rank() over ( partition by s_state order by sum(ss_net_profit) desc) as ranking - from store_sales, store, date_dim - where d_month_seq between 1185 and 1185 + 11 - and d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - group by s_state - ) tmp1 - where ranking <= 5) - group by s_state,s_county) , - results_rollup as -(select total_sum ,s_state ,s_county, 0 as g_state, 0 as g_county, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum,s_state, NULL as s_county, 0 as g_state, 1 as g_county, 1 as lochierarchy from results group by s_state - union - select sum(total_sum) as total_sum ,NULL as s_state ,NULL as s_county, 1 as g_state, 1 as g_county, 2 as lochierarchy from results) - select total_sum ,s_state ,s_county, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_county = 0 then s_state end - order by total_sum desc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then s_state end - ,rank_within_parent - limit 100; - --- end template query70a.tpl query 73 in stream 1 --- start template query49.tpl query 74 in stream 1 -select /* TPC-DS query49.tpl 0.48 */ channel, item, return_ratio, return_rank, currency_rank from - (select - 'web' as channel - ,web.item - ,web.return_ratio - ,web.return_rank - ,web.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select ws.ws_item_sk as item - ,(cast(sum(coalesce(wr.wr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(wr.wr_return_amt,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - web_sales ws left outer join web_returns wr - on (ws.ws_order_number = wr.wr_order_number and - ws.ws_item_sk = wr.wr_item_sk) - ,date_dim - where - wr.wr_return_amt > 10000 - and ws.ws_net_profit > 1 - and ws.ws_net_paid > 0 - and ws.ws_quantity > 0 - and ws_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 11 - group by ws.ws_item_sk - ) in_web - ) web - where - ( - web.return_rank <= 10 - or - web.currency_rank <= 10 - ) - union - select - 'catalog' as channel - ,catalog.item - ,catalog.return_ratio - ,catalog.return_rank - ,catalog.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select - cs.cs_item_sk as item - ,(cast(sum(coalesce(cr.cr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(cr.cr_return_amount,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - catalog_sales cs left outer join catalog_returns cr - on (cs.cs_order_number = cr.cr_order_number and - cs.cs_item_sk = cr.cr_item_sk) - ,date_dim - where - cr.cr_return_amount > 10000 - and cs.cs_net_profit > 1 - and cs.cs_net_paid > 0 - and cs.cs_quantity > 0 - and cs_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 11 - group by cs.cs_item_sk - ) in_cat - ) catalog - where - ( - catalog.return_rank <= 10 - or - catalog.currency_rank <=10 - ) - union - select - 'store' as channel - ,store.item - ,store.return_ratio - ,store.return_rank - ,store.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select sts.ss_item_sk as item - ,(cast(sum(coalesce(sr.sr_return_quantity,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(sr.sr_return_amt,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - store_sales sts left outer join store_returns sr - on (sts.ss_ticket_number = sr.sr_ticket_number and sts.ss_item_sk = sr.sr_item_sk) - ,date_dim - where - sr.sr_return_amt > 10000 - and sts.ss_net_profit > 1 - and sts.ss_net_paid > 0 - and sts.ss_quantity > 0 - and ss_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 11 - group by sts.ss_item_sk - ) in_store - ) store - where ( - store.return_rank <= 10 - or - store.currency_rank <= 10 - ) - ) - order by 1,4,5,2 - limit 100; - --- end template query49.tpl query 74 in stream 1 --- start template query59.tpl query 75 in stream 1 -with /* TPC-DS query59.tpl 0.30 */ wss as - (select d_week_seq, - ss_store_sk, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - group by d_week_seq,ss_store_sk - ) - select s_store_name1,s_store_id1,d_week_seq1 - ,sun_sales1/sun_sales2,mon_sales1/mon_sales2 - ,tue_sales1/tue_sales2,wed_sales1/wed_sales2,thu_sales1/thu_sales2 - ,fri_sales1/fri_sales2,sat_sales1/sat_sales2 - from - (select s_store_name s_store_name1,wss.d_week_seq d_week_seq1 - ,s_store_id s_store_id1,sun_sales sun_sales1 - ,mon_sales mon_sales1,tue_sales tue_sales1 - ,wed_sales wed_sales1,thu_sales thu_sales1 - ,fri_sales fri_sales1,sat_sales sat_sales1 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1203 and 1203 + 11) y, - (select s_store_name s_store_name2,wss.d_week_seq d_week_seq2 - ,s_store_id s_store_id2,sun_sales sun_sales2 - ,mon_sales mon_sales2,tue_sales tue_sales2 - ,wed_sales wed_sales2,thu_sales thu_sales2 - ,fri_sales fri_sales2,sat_sales sat_sales2 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1203+ 12 and 1203 + 23) x - where s_store_id1=s_store_id2 - and d_week_seq1=d_week_seq2-52 - order by s_store_name1,s_store_id1,d_week_seq1 -limit 100; - --- end template query59.tpl query 75 in stream 1 --- start template query48.tpl query 76 in stream 1 -select /* TPC-DS query48.tpl 0.74 */ sum (ss_quantity) - from store_sales, store, customer_demographics, customer_address, date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2002 - and - ( - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'M' - and - cd_education_status = 'Primary' - and - ss_sales_price between 100.00 and 150.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'U' - and - cd_education_status = '4 yr Degree' - and - ss_sales_price between 50.00 and 100.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'W' - and - cd_education_status = '2 yr Degree' - and - ss_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('LA', 'TN', 'MN') - and ss_net_profit between 0 and 2000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('WA', 'OH', 'CA') - and ss_net_profit between 150 and 3000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('KS', 'NE', 'TX') - and ss_net_profit between 50 and 25000 - ) - ) -; - --- end template query48.tpl query 76 in stream 1 --- start template query72.tpl query 77 in stream 1 -select /* TPC-DS query72.tpl 0.87 */ i_item_desc - ,w_warehouse_name - ,d1.d_week_seq - ,sum(case when p_promo_sk is null then 1 else 0 end) no_promo - ,sum(case when p_promo_sk is not null then 1 else 0 end) promo - ,count(*) total_cnt -from catalog_sales -join inventory on (cs_item_sk = inv_item_sk) -join warehouse on (w_warehouse_sk=inv_warehouse_sk) -join item on (i_item_sk = cs_item_sk) -join customer_demographics on (cs_bill_cdemo_sk = cd_demo_sk) -join household_demographics on (cs_bill_hdemo_sk = hd_demo_sk) -join date_dim d1 on (cs_sold_date_sk = d1.d_date_sk) -join date_dim d2 on (inv_date_sk = d2.d_date_sk) -join date_dim d3 on (cs_ship_date_sk = d3.d_date_sk) -left outer join promotion on (cs_promo_sk=p_promo_sk) -left outer join catalog_returns on (cr_item_sk = cs_item_sk and cr_order_number = cs_order_number) -where d1.d_week_seq = d2.d_week_seq - and inv_quantity_on_hand < cs_quantity - and d3.d_date > d1.d_date + 5 - and hd_buy_potential = '1001-5000' - and d1.d_year = 2002 - and cd_marital_status = 'S' -group by i_item_desc,w_warehouse_name,d1.d_week_seq -order by total_cnt desc, i_item_desc, w_warehouse_name, d_week_seq -limit 100; - --- end template query72.tpl query 77 in stream 1 --- start template query87.tpl query 78 in stream 1 -select /* TPC-DS query87.tpl 0.77 */ count(*) -from ((select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1177 and 1177+11) - except - (select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1177 and 1177+11) - except - (select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1177 and 1177+11) -) cool_cust -; - --- end template query87.tpl query 78 in stream 1 --- start template query34.tpl query 79 in stream 1 -select /* TPC-DS query34.tpl 0.73 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (date_dim.d_dom between 1 and 3 or date_dim.d_dom between 25 and 28) - and (household_demographics.hd_buy_potential = '>10000' or - household_demographics.hd_buy_potential = '5001-10000') - and household_demographics.hd_vehicle_count > 0 - and (case when household_demographics.hd_vehicle_count > 0 - then household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count - else null - end) > 1.2 - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_county in ('West Feliciana Parish','Crawford County','Haines Borough','Marshall County', - 'Montgomery County','Essex County','Orangeburg County','Gogebic County') - group by ss_ticket_number,ss_customer_sk) dn,customer - where ss_customer_sk = c_customer_sk - and cnt between 15 and 20 - order by c_last_name,c_first_name,c_salutation,c_preferred_cust_flag desc, ss_ticket_number; - --- end template query34.tpl query 79 in stream 1 --- start template query2.tpl query 80 in stream 1 -with /* TPC-DS query2.tpl 0.84 */ wscs as - (select sold_date_sk - ,sales_price - from (select ws_sold_date_sk sold_date_sk - ,ws_ext_sales_price sales_price - from web_sales - union all - select cs_sold_date_sk sold_date_sk - ,cs_ext_sales_price sales_price - from catalog_sales)), - wswscs as - (select d_week_seq, - sum(case when (d_day_name='Sunday') then sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then sales_price else null end) sat_sales - from wscs - ,date_dim - where d_date_sk = sold_date_sk - group by d_week_seq) - select d_week_seq1 - ,round(sun_sales1/sun_sales2,2) - ,round(mon_sales1/mon_sales2,2) - ,round(tue_sales1/tue_sales2,2) - ,round(wed_sales1/wed_sales2,2) - ,round(thu_sales1/thu_sales2,2) - ,round(fri_sales1/fri_sales2,2) - ,round(sat_sales1/sat_sales2,2) - from - (select wswscs.d_week_seq d_week_seq1 - ,sun_sales sun_sales1 - ,mon_sales mon_sales1 - ,tue_sales tue_sales1 - ,wed_sales wed_sales1 - ,thu_sales thu_sales1 - ,fri_sales fri_sales1 - ,sat_sales sat_sales1 - from wswscs,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 2001) y, - (select wswscs.d_week_seq d_week_seq2 - ,sun_sales sun_sales2 - ,mon_sales mon_sales2 - ,tue_sales tue_sales2 - ,wed_sales wed_sales2 - ,thu_sales thu_sales2 - ,fri_sales fri_sales2 - ,sat_sales sat_sales2 - from wswscs - ,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 2001+1) z - where d_week_seq1=d_week_seq2-53 - order by d_week_seq1; - --- end template query2.tpl query 80 in stream 1 --- start template query38.tpl query 81 in stream 1 -select /* TPC-DS query38.tpl 0.54 */ count(*) from ( - select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1201 and 1201 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1201 and 1201 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1201 and 1201 + 11 -) hot_cust -limit 100; - --- end template query38.tpl query 81 in stream 1 --- start template query22a.tpl query 82 in stream 1 -with /* TPC-DS query22a.tpl 0.55 */ results as -(select i_product_name - ,i_brand - ,i_class - ,i_category - ,avg(inv_quantity_on_hand) qoh - from inventory - ,date_dim - ,item --- ,warehouse - where inv_date_sk=d_date_sk - and inv_item_sk=i_item_sk --- and inv_warehouse_sk = w_warehouse_sk - and d_month_seq between 1200 and 1200 + 11 - group by i_product_name,i_brand,i_class,i_category), -results_rollup as -(select i_product_name, i_brand, i_class, i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class,i_category -union all -select i_product_name, i_brand, i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class -union all -select i_product_name, i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand -union all -select i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name -union all -select null i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results) - select i_product_name, i_brand, i_class, i_category,qoh - from results_rollup - order by qoh, i_product_name, i_brand, i_class, i_category -limit 100; - --- end template query22a.tpl query 82 in stream 1 --- start template query89.tpl query 83 in stream 1 -select /* TPC-DS query89.tpl 0.56 */ * -from( -select i_category, i_class, i_brand, - s_store_name, s_company_name, - d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, s_store_name, s_company_name) - avg_monthly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - d_year in (2001) and - ((i_category in ('Electronics','Children','Men') and - i_class in ('televisions','infants','accessories') - ) - or (i_category in ('Books','Music','Jewelry') and - i_class in ('computers','rock','semi-precious') - )) -group by i_category, i_class, i_brand, - s_store_name, s_company_name, d_moy) tmp1 -where case when (avg_monthly_sales <> 0) then (abs(sum_sales - avg_monthly_sales) / avg_monthly_sales) else null end > 0.1 -order by sum_sales - avg_monthly_sales, s_store_name -limit 100; - --- end template query89.tpl query 83 in stream 1 --- start template query7.tpl query 84 in stream 1 -select /* TPC-DS query7.tpl 0.2 */ i_item_id, - avg(ss_quantity) agg1, - avg(ss_list_price) agg2, - avg(ss_coupon_amt) agg3, - avg(ss_sales_price) agg4 - from store_sales, customer_demographics, date_dim, item, promotion - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_cdemo_sk = cd_demo_sk and - ss_promo_sk = p_promo_sk and - cd_gender = 'F' and - cd_marital_status = 'W' and - cd_education_status = 'Advanced Degree' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 2001 - group by i_item_id - order by i_item_id - limit 100; - --- end template query7.tpl query 84 in stream 1 --- start template query10.tpl query 85 in stream 1 -select /* TPC-DS query10.tpl 0.26 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3, - cd_dep_count, - count(*) cnt4, - cd_dep_employed_count, - count(*) cnt5, - cd_dep_college_count, - count(*) cnt6 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_county in ('Colbert County','Arapahoe County','Butler County','Tillman County','Franklin County') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 3 and 3+3) and - (exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 3 ANd 3+3) or - exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 3 and 3+3)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count -limit 100; - --- end template query10.tpl query 85 in stream 1 --- start template query90.tpl query 86 in stream 1 -select /* TPC-DS query90.tpl 0.40 */ cast(amc as decimal(15,4))/cast(pmc as decimal(15,4)) am_pm_ratio - from ( select count(*) amc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 6 and 6+1 - and household_demographics.hd_dep_count = 1 - and web_page.wp_char_count between 5000 and 5200) at, - ( select count(*) pmc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 15 and 15+1 - and household_demographics.hd_dep_count = 1 - and web_page.wp_char_count between 5000 and 5200) pt - order by am_pm_ratio - limit 100; - --- end template query90.tpl query 86 in stream 1 --- start template query71.tpl query 87 in stream 1 -select /* TPC-DS query71.tpl 0.72 */ i_brand_id brand_id, i_brand brand,t_hour,t_minute, - sum(ext_price) ext_price - from item, (select ws_ext_sales_price as ext_price, - ws_sold_date_sk as sold_date_sk, - ws_item_sk as sold_item_sk, - ws_sold_time_sk as time_sk - from web_sales,date_dim - where d_date_sk = ws_sold_date_sk - and d_moy=12 - and d_year=2002 - union all - select cs_ext_sales_price as ext_price, - cs_sold_date_sk as sold_date_sk, - cs_item_sk as sold_item_sk, - cs_sold_time_sk as time_sk - from catalog_sales,date_dim - where d_date_sk = cs_sold_date_sk - and d_moy=12 - and d_year=2002 - union all - select ss_ext_sales_price as ext_price, - ss_sold_date_sk as sold_date_sk, - ss_item_sk as sold_item_sk, - ss_sold_time_sk as time_sk - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - and d_moy=12 - and d_year=2002 - ) tmp,time_dim - where - sold_item_sk = i_item_sk - and i_manager_id=1 - and time_sk = t_time_sk - and (t_meal_time = 'breakfast' or t_meal_time = 'dinner') - group by i_brand, i_brand_id,t_hour,t_minute - order by ext_price desc, i_brand_id - ; - --- end template query71.tpl query 87 in stream 1 --- start template query29.tpl query 88 in stream 1 -select /* TPC-DS query29.tpl 0.53 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,min(ss_quantity) as store_sales_quantity - ,min(sr_return_quantity) as store_returns_quantity - ,min(cs_quantity) as catalog_sales_quantity - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 1999 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 4 + 3 - and d2.d_year = 1999 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_year in (1999,1999+1,1999+2) - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query29.tpl query 88 in stream 1 --- start template query73.tpl query 89 in stream 1 -select /* TPC-DS query73.tpl 0.79 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_buy_potential = '1001-5000' or - household_demographics.hd_buy_potential = '5001-10000') - and household_demographics.hd_vehicle_count > 0 - and case when household_demographics.hd_vehicle_count > 0 then - household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count else null end > 1 - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_county in ('Price County','Orange County','Jefferson County','Jackson County') - group by ss_ticket_number,ss_customer_sk) dj,customer - where ss_customer_sk = c_customer_sk - and cnt between 1 and 5 - order by cnt desc, c_last_name asc; - --- end template query73.tpl query 89 in stream 1 --- start template query45.tpl query 90 in stream 1 -select /* TPC-DS query45.tpl 0.18 */ ca_zip, ca_city, sum(ws_sales_price) - from web_sales, customer, customer_address, date_dim, item - where ws_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ws_item_sk = i_item_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', '85392', '85460', '80348', '81792') - or - i_item_id in (select i_item_id - from item - where i_item_sk in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29) - ) - ) - and ws_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 2000 - group by ca_zip, ca_city - order by ca_zip, ca_city - limit 100; - --- end template query45.tpl query 90 in stream 1 --- start template query91.tpl query 91 in stream 1 -select /* TPC-DS query91.tpl 0.13 */ - cc_call_center_id Call_Center, - cc_name Call_Center_Name, - cc_manager Manager, - sum(cr_net_loss) Returns_Loss -from - call_center, - catalog_returns, - date_dim, - customer, - customer_address, - customer_demographics, - household_demographics -where - cr_call_center_sk = cc_call_center_sk -and cr_returned_date_sk = d_date_sk -and cr_returning_customer_sk= c_customer_sk -and cd_demo_sk = c_current_cdemo_sk -and hd_demo_sk = c_current_hdemo_sk -and ca_address_sk = c_current_addr_sk -and d_year = 1998 -and d_moy = 12 -and ( (cd_marital_status = 'M' and cd_education_status = 'Unknown') - or(cd_marital_status = 'W' and cd_education_status = 'Advanced Degree')) -and hd_buy_potential like '0-500%' -and ca_gmt_offset = -7 -group by cc_call_center_id,cc_name,cc_manager,cd_marital_status,cd_education_status -order by sum(cr_net_loss) desc; - --- end template query91.tpl query 91 in stream 1 --- start template query62.tpl query 92 in stream 1 -select /* TPC-DS query62.tpl 0.24 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 30) and - (ws_ship_date_sk - ws_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 60) and - (ws_ship_date_sk - ws_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 90) and - (ws_ship_date_sk - ws_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - web_sales - ,warehouse - ,ship_mode - ,web_site - ,date_dim -where - d_month_seq between 1185 and 1185 + 11 -and ws_ship_date_sk = d_date_sk -and ws_warehouse_sk = w_warehouse_sk -and ws_ship_mode_sk = sm_ship_mode_sk -and ws_web_site_sk = web_site_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -limit 100; - --- end template query62.tpl query 92 in stream 1 --- start template query44.tpl query 93 in stream 1 -select /* TPC-DS query44.tpl 0.4 */ asceding.rnk, i1.i_product_name best_performing, i2.i_product_name worst_performing -from(select * - from (select item_sk,rank() over (order by rank_col asc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 342 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 342 - and ss_promo_sk is null - group by ss_store_sk))V1)V11 - where rnk < 11) asceding, - (select * - from (select item_sk,rank() over (order by rank_col desc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 342 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 342 - and ss_promo_sk is null - group by ss_store_sk))V2)V21 - where rnk < 11) descending, -item i1, -item i2 -where asceding.rnk = descending.rnk - and i1.i_item_sk=asceding.item_sk - and i2.i_item_sk=descending.item_sk -order by asceding.rnk -limit 100; - --- end template query44.tpl query 93 in stream 1 --- start template query76.tpl query 94 in stream 1 -select /* TPC-DS query76.tpl 0.99 */ channel, col_name, d_year, d_qoy, i_category, COUNT(*) sales_cnt, SUM(ext_sales_price) sales_amt FROM ( - SELECT 'store' as channel, 'ss_store_sk' col_name, d_year, d_qoy, i_category, ss_ext_sales_price ext_sales_price - FROM store_sales, item, date_dim - WHERE ss_store_sk IS NULL - AND ss_sold_date_sk=d_date_sk - AND ss_item_sk=i_item_sk - UNION ALL - SELECT 'web' as channel, 'ws_ship_addr_sk' col_name, d_year, d_qoy, i_category, ws_ext_sales_price ext_sales_price - FROM web_sales, item, date_dim - WHERE ws_ship_addr_sk IS NULL - AND ws_sold_date_sk=d_date_sk - AND ws_item_sk=i_item_sk - UNION ALL - SELECT 'catalog' as channel, 'cs_ship_cdemo_sk' col_name, d_year, d_qoy, i_category, cs_ext_sales_price ext_sales_price - FROM catalog_sales, item, date_dim - WHERE cs_ship_cdemo_sk IS NULL - AND cs_sold_date_sk=d_date_sk - AND cs_item_sk=i_item_sk) foo -GROUP BY channel, col_name, d_year, d_qoy, i_category -ORDER BY channel, col_name, d_year, d_qoy, i_category -limit 100; - --- end template query76.tpl query 94 in stream 1 --- start template query23.tpl query 95 in stream 1 -with /* TPC-DS query23.tpl 0.68 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (1998,1998+1,1998+2,1998+3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1998,1998+1,1998+2,1998+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * -from - max_store_sales)) - select sum(sales) - from (select cs_quantity*cs_list_price sales - from catalog_sales - ,date_dim - where d_year = 1998 - and d_moy = 6 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - union all - select ws_quantity*ws_list_price sales - from web_sales - ,date_dim - where d_year = 1998 - and d_moy = 6 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer)) - limit 100; -with /* TPC-DS query23.tpl 0.68 part2 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (1998,1998 + 1,1998 + 2,1998 + 3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1998,1998+1,1998+2,1998+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * - from max_store_sales)) - select c_last_name,c_first_name,sales - from (select c_last_name,c_first_name,sum(cs_quantity*cs_list_price) sales - from catalog_sales - ,customer - ,date_dim - where d_year = 1998 - and d_moy = 6 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and cs_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name - union all - select c_last_name,c_first_name,sum(ws_quantity*ws_list_price) sales - from web_sales - ,customer - ,date_dim - where d_year = 1998 - and d_moy = 6 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and ws_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name) - order by c_last_name,c_first_name,sales - limit 100; - --- end template query23.tpl query 95 in stream 1 --- start template query56.tpl query 96 in stream 1 -with /* TPC-DS query56.tpl 0.83 */ ss as ( - select i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where i_item_id in (select - i_item_id -from item -where i_color in ('indian','firebrick','plum')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 2 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id), - cs as ( - select i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('indian','firebrick','plum')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 2 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id), - ws as ( - select i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('indian','firebrick','plum')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 2 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id) - select i_item_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by total_sales, - i_item_id - limit 100; - --- end template query56.tpl query 96 in stream 1 --- start template query42.tpl query 97 in stream 1 -select /* TPC-DS query42.tpl 0.61 */ dt.d_year - ,item.i_category_id - ,item.i_category - ,sum(ss_ext_sales_price) - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=12 - and dt.d_year=1999 - group by dt.d_year - ,item.i_category_id - ,item.i_category - order by sum(ss_ext_sales_price) desc,dt.d_year - ,item.i_category_id - ,item.i_category -limit 100 ; - --- end template query42.tpl query 97 in stream 1 --- start template query39.tpl query 98 in stream 1 -with /* TPC-DS query39.tpl 0.5 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =1998 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=3 - and inv2.d_moy=3+1 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; -with /* TPC-DS query39.tpl 0.5 part2 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =1998 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=3 - and inv2.d_moy=3+1 - and inv1.cov > 1.5 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; - --- end template query39.tpl query 98 in stream 1 --- start template query74.tpl query 99 in stream 1 -with /* TPC-DS query74.tpl 0.76 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,max(ss_net_paid) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1998,1998+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,max(ws_net_paid) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - and d_year in (1998,1998+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - ) - select - t_s_secyear.customer_id, t_s_secyear.customer_first_name, t_s_secyear.customer_last_name - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.year = 1998 - and t_s_secyear.year = 1998+1 - and t_w_firstyear.year = 1998 - and t_w_secyear.year = 1998+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - order by 3,2,1 -limit 100; - --- end template query74.tpl query 99 in stream 1 diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/100TB/queries/query_10.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/100TB/queries/query_10.sql deleted file mode 100644 index 566c0c06..00000000 --- a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/100TB/queries/query_10.sql +++ /dev/null @@ -1,5027 +0,0 @@ --- start template query43.tpl query 1 in stream 10 -select /* TPC-DS query43.tpl 0.15 */ s_store_name, s_store_id, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from date_dim, store_sales, store - where d_date_sk = ss_sold_date_sk and - s_store_sk = ss_store_sk and - s_gmt_offset = -6 and - d_year = 2001 - group by s_store_name, s_store_id - order by s_store_name, s_store_id,sun_sales,mon_sales,tue_sales,wed_sales,thu_sales,fri_sales,sat_sales - limit 100; - --- end template query43.tpl query 1 in stream 10 --- start template query50.tpl query 2 in stream 10 -select /* TPC-DS query50.tpl 0.60 */ - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 30) and - (sr_returned_date_sk - ss_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 60) and - (sr_returned_date_sk - ss_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 90) and - (sr_returned_date_sk - ss_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - store_sales - ,store_returns - ,store - ,date_dim d1 - ,date_dim d2 -where - d2.d_year = 2001 -and d2.d_moy = 8 -and ss_ticket_number = sr_ticket_number -and ss_item_sk = sr_item_sk -and ss_sold_date_sk = d1.d_date_sk -and sr_returned_date_sk = d2.d_date_sk -and ss_customer_sk = sr_customer_sk -and ss_store_sk = s_store_sk -group by - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -order by s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -limit 100; - --- end template query50.tpl query 2 in stream 10 --- start template query41.tpl query 3 in stream 10 -select /* TPC-DS query41.tpl 0.62 */ distinct(i_product_name) - from item i1 - where i_manufact_id between 928 and 928+40 - and (select count(*) as item_cnt - from item - where (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'honeydew' or i_color = 'ivory') and - (i_units = 'Bundle' or i_units = 'Bunch') and - (i_size = 'N/A' or i_size = 'large') - ) or - (i_category = 'Women' and - (i_color = 'sienna' or i_color = 'turquoise') and - (i_units = 'Lb' or i_units = 'Dozen') and - (i_size = 'medium' or i_size = 'extra large') - ) or - (i_category = 'Men' and - (i_color = 'salmon' or i_color = 'lime') and - (i_units = 'Dram' or i_units = 'Each') and - (i_size = 'small' or i_size = 'petite') - ) or - (i_category = 'Men' and - (i_color = 'firebrick' or i_color = 'sky') and - (i_units = 'Tsp' or i_units = 'Ounce') and - (i_size = 'N/A' or i_size = 'large') - ))) or - (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'khaki' or i_color = 'violet') and - (i_units = 'Ton' or i_units = 'Box') and - (i_size = 'N/A' or i_size = 'large') - ) or - (i_category = 'Women' and - (i_color = 'peru' or i_color = 'thistle') and - (i_units = 'Case' or i_units = 'Pound') and - (i_size = 'medium' or i_size = 'extra large') - ) or - (i_category = 'Men' and - (i_color = 'antique' or i_color = 'grey') and - (i_units = 'Tbl' or i_units = 'Oz') and - (i_size = 'small' or i_size = 'petite') - ) or - (i_category = 'Men' and - (i_color = 'purple' or i_color = 'tomato') and - (i_units = 'Gram' or i_units = 'Cup') and - (i_size = 'N/A' or i_size = 'large') - )))) > 0 - order by i_product_name - limit 100; - --- end template query41.tpl query 3 in stream 10 --- start template query48.tpl query 4 in stream 10 -select /* TPC-DS query48.tpl 0.74 */ sum (ss_quantity) - from store_sales, store, customer_demographics, customer_address, date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2002 - and - ( - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'D' - and - cd_education_status = 'Advanced Degree' - and - ss_sales_price between 100.00 and 150.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'S' - and - cd_education_status = 'Secondary' - and - ss_sales_price between 50.00 and 100.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'U' - and - cd_education_status = 'Unknown' - and - ss_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('MO', 'MS', 'IA') - and ss_net_profit between 0 and 2000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('TN', 'TX', 'NY') - and ss_net_profit between 150 and 3000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('OK', 'AL', 'CO') - and ss_net_profit between 50 and 25000 - ) - ) -; - --- end template query48.tpl query 4 in stream 10 --- start template query54.tpl query 5 in stream 10 -with /* TPC-DS query54.tpl 0.81 */ my_customers as ( - select distinct c_customer_sk - , c_current_addr_sk - from - ( select cs_sold_date_sk sold_date_sk, - cs_bill_customer_sk customer_sk, - cs_item_sk item_sk - from catalog_sales - union all - select ws_sold_date_sk sold_date_sk, - ws_bill_customer_sk customer_sk, - ws_item_sk item_sk - from web_sales - ) cs_or_ws_sales, - item, - date_dim, - customer - where sold_date_sk = d_date_sk - and item_sk = i_item_sk - and i_category = 'Books' - and i_class = 'self-help' - and c_customer_sk = cs_or_ws_sales.customer_sk - and d_moy = 4 - and d_year = 2000 - ) - , my_revenue as ( - select c_customer_sk, - sum(ss_ext_sales_price) as revenue - from my_customers, - store_sales, - customer_address, - store, - date_dim - where c_current_addr_sk = ca_address_sk - and ca_county = s_county - and ca_state = s_state - and ss_sold_date_sk = d_date_sk - and c_customer_sk = ss_customer_sk - and d_month_seq between (select distinct d_month_seq+1 - from date_dim where d_year = 2000 and d_moy = 4) - and (select distinct d_month_seq+3 - from date_dim where d_year = 2000 and d_moy = 4) - group by c_customer_sk - ) - , segments as - (select cast((revenue/50) as bigint) as segment - from my_revenue - ) - select segment, count(*) as num_customers, segment*50 as segment_base - from segments - group by segment - order by segment, num_customers - limit 100; - --- end template query54.tpl query 5 in stream 10 --- start template query53.tpl query 6 in stream 10 -select /* TPC-DS query53.tpl 0.88 */ * from -(select i_manufact_id, -sum(ss_sales_price) sum_sales, -avg(sum(ss_sales_price)) over (partition by i_manufact_id) avg_quarterly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and -ss_sold_date_sk = d_date_sk and -ss_store_sk = s_store_sk and -d_month_seq in (1198,1198+1,1198+2,1198+3,1198+4,1198+5,1198+6,1198+7,1198+8,1198+9,1198+10,1198+11) and -((i_category in ('Books','Children','Electronics') and -i_class in ('personal','portable','reference','self-help') and -i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) -or(i_category in ('Women','Music','Men') and -i_class in ('accessories','classical','fragrances','pants') and -i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manufact_id, d_qoy ) tmp1 -where case when avg_quarterly_sales > 0 - then abs (sum_sales - avg_quarterly_sales)/ avg_quarterly_sales - else null end > 0.1 -order by avg_quarterly_sales, - sum_sales, - i_manufact_id -limit 100; - --- end template query53.tpl query 6 in stream 10 --- start template query31.tpl query 7 in stream 10 -with /* TPC-DS query31.tpl 0.50 */ ss as - (select ca_county,d_qoy, d_year,sum(ss_ext_sales_price) as store_sales - from store_sales,date_dim,customer_address - where ss_sold_date_sk = d_date_sk - and ss_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year), - ws as - (select ca_county,d_qoy, d_year,sum(ws_ext_sales_price) as web_sales - from web_sales,date_dim,customer_address - where ws_sold_date_sk = d_date_sk - and ws_bill_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year) - select - ss1.ca_county - ,ss1.d_year - ,ws2.web_sales/ws1.web_sales web_q1_q2_increase - ,ss2.store_sales/ss1.store_sales store_q1_q2_increase - ,ws3.web_sales/ws2.web_sales web_q2_q3_increase - ,ss3.store_sales/ss2.store_sales store_q2_q3_increase - from - ss ss1 - ,ss ss2 - ,ss ss3 - ,ws ws1 - ,ws ws2 - ,ws ws3 - where - ss1.d_qoy = 1 - and ss1.d_year = 2002 - and ss1.ca_county = ss2.ca_county - and ss2.d_qoy = 2 - and ss2.d_year = 2002 - and ss2.ca_county = ss3.ca_county - and ss3.d_qoy = 3 - and ss3.d_year = 2002 - and ss1.ca_county = ws1.ca_county - and ws1.d_qoy = 1 - and ws1.d_year = 2002 - and ws1.ca_county = ws2.ca_county - and ws2.d_qoy = 2 - and ws2.d_year = 2002 - and ws1.ca_county = ws3.ca_county - and ws3.d_qoy = 3 - and ws3.d_year =2002 - and case when ws1.web_sales > 0 then ws2.web_sales/ws1.web_sales else null end - > case when ss1.store_sales > 0 then ss2.store_sales/ss1.store_sales else null end - and case when ws2.web_sales > 0 then ws3.web_sales/ws2.web_sales else null end - > case when ss2.store_sales > 0 then ss3.store_sales/ss2.store_sales else null end - order by store_q2_q3_increase; - --- end template query31.tpl query 7 in stream 10 --- start template query39.tpl query 8 in stream 10 -with /* TPC-DS query39.tpl 0.5 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =2002 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=4 - and inv2.d_moy=4+1 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; -with /* TPC-DS query39.tpl 0.5 part2 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =2002 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=4 - and inv2.d_moy=4+1 - and inv1.cov > 1.5 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; - --- end template query39.tpl query 8 in stream 10 --- start template query2.tpl query 9 in stream 10 -with /* TPC-DS query2.tpl 0.84 */ wscs as - (select sold_date_sk - ,sales_price - from (select ws_sold_date_sk sold_date_sk - ,ws_ext_sales_price sales_price - from web_sales - union all - select cs_sold_date_sk sold_date_sk - ,cs_ext_sales_price sales_price - from catalog_sales)), - wswscs as - (select d_week_seq, - sum(case when (d_day_name='Sunday') then sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then sales_price else null end) sat_sales - from wscs - ,date_dim - where d_date_sk = sold_date_sk - group by d_week_seq) - select d_week_seq1 - ,round(sun_sales1/sun_sales2,2) - ,round(mon_sales1/mon_sales2,2) - ,round(tue_sales1/tue_sales2,2) - ,round(wed_sales1/wed_sales2,2) - ,round(thu_sales1/thu_sales2,2) - ,round(fri_sales1/fri_sales2,2) - ,round(sat_sales1/sat_sales2,2) - from - (select wswscs.d_week_seq d_week_seq1 - ,sun_sales sun_sales1 - ,mon_sales mon_sales1 - ,tue_sales tue_sales1 - ,wed_sales wed_sales1 - ,thu_sales thu_sales1 - ,fri_sales fri_sales1 - ,sat_sales sat_sales1 - from wswscs,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 1999) y, - (select wswscs.d_week_seq d_week_seq2 - ,sun_sales sun_sales2 - ,mon_sales mon_sales2 - ,tue_sales tue_sales2 - ,wed_sales wed_sales2 - ,thu_sales thu_sales2 - ,fri_sales fri_sales2 - ,sat_sales sat_sales2 - from wswscs - ,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 1999+1) z - where d_week_seq1=d_week_seq2-53 - order by d_week_seq1; - --- end template query2.tpl query 9 in stream 10 --- start template query96.tpl query 10 in stream 10 -select /* TPC-DS query96.tpl 0.1 */ count(*) -from store_sales - ,household_demographics - ,time_dim, store -where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 15 - and time_dim.t_minute >= 30 - and household_demographics.hd_dep_count = 9 - and store.s_store_name = 'ese' -order by count(*) -limit 100; - --- end template query96.tpl query 10 in stream 10 --- start template query93.tpl query 11 in stream 10 -select /* TPC-DS query93.tpl 0.52 */ ss_customer_sk - ,sum(act_sales) sumsales - from (select ss_item_sk - ,ss_ticket_number - ,ss_customer_sk - ,case when sr_return_quantity is not null then (ss_quantity-sr_return_quantity)*ss_sales_price - else (ss_quantity*ss_sales_price) end act_sales - from store_sales left outer join store_returns on (sr_item_sk = ss_item_sk - and sr_ticket_number = ss_ticket_number) - ,reason - where sr_reason_sk = r_reason_sk - and r_reason_desc = 'Not working any more') t - group by ss_customer_sk - order by sumsales, ss_customer_sk -limit 100; - --- end template query93.tpl query 11 in stream 10 --- start template query15.tpl query 12 in stream 10 -select /* TPC-DS query15.tpl 0.57 */ ca_zip - ,sum(cs_sales_price) - from catalog_sales - ,customer - ,customer_address - ,date_dim - where cs_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', - '85392', '85460', '80348', '81792') - or ca_state in ('CA','WA','GA') - or cs_sales_price > 500) - and cs_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 1998 - group by ca_zip - order by ca_zip - limit 100; - --- end template query15.tpl query 12 in stream 10 --- start template query91.tpl query 13 in stream 10 -select /* TPC-DS query91.tpl 0.13 */ - cc_call_center_id Call_Center, - cc_name Call_Center_Name, - cc_manager Manager, - sum(cr_net_loss) Returns_Loss -from - call_center, - catalog_returns, - date_dim, - customer, - customer_address, - customer_demographics, - household_demographics -where - cr_call_center_sk = cc_call_center_sk -and cr_returned_date_sk = d_date_sk -and cr_returning_customer_sk= c_customer_sk -and cd_demo_sk = c_current_cdemo_sk -and hd_demo_sk = c_current_hdemo_sk -and ca_address_sk = c_current_addr_sk -and d_year = 1999 -and d_moy = 12 -and ( (cd_marital_status = 'M' and cd_education_status = 'Unknown') - or(cd_marital_status = 'W' and cd_education_status = 'Advanced Degree')) -and hd_buy_potential like '5001-10000%' -and ca_gmt_offset = -6 -group by cc_call_center_id,cc_name,cc_manager,cd_marital_status,cd_education_status -order by sum(cr_net_loss) desc; - --- end template query91.tpl query 13 in stream 10 --- start template query21.tpl query 14 in stream 10 -select /* TPC-DS query21.tpl 0.14 */ * - from(select w_warehouse_name - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('2000-06-26' as date)) - then inv_quantity_on_hand - else 0 end) as inv_before - ,sum(case when (cast(d_date as date) >= cast ('2000-06-26' as date)) - then inv_quantity_on_hand - else 0 end) as inv_after - from inventory - ,warehouse - ,item - ,date_dim - where i_current_price between 0.99 and 1.49 - and i_item_sk = inv_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('2000-06-26' as date)) - and dateadd(day,30,cast ('2000-06-26' as date)) - group by w_warehouse_name, i_item_id) x - where (case when inv_before > 0 - then inv_after / inv_before - else null - end) between 2.0/3.0 and 3.0/2.0 - order by w_warehouse_name - ,i_item_id - limit 100; - --- end template query21.tpl query 14 in stream 10 --- start template query18a.tpl query 15 in stream 10 -with /* TPC-DS query18a.tpl 0.90 */ results as - (select i_item_id, - ca_country, - ca_state, - ca_county, - cast(cs_quantity as decimal(12,2)) agg1, - cast(cs_list_price as decimal(12,2)) agg2, - cast(cs_coupon_amt as decimal(12,2)) agg3, - cast(cs_sales_price as decimal(12,2)) agg4, - cast(cs_net_profit as decimal(12,2)) agg5, - cast(c_birth_year as decimal(12,2)) agg6, - cast(cd1.cd_dep_count as decimal(12,2)) agg7 - from catalog_sales, customer_demographics cd1, customer_demographics cd2, customer, customer_address, date_dim, item - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd1.cd_demo_sk and - cs_bill_customer_sk = c_customer_sk and - cd1.cd_gender = 'F' and - cd1.cd_education_status = '2 yr Degree' and - c_current_cdemo_sk = cd2.cd_demo_sk and - c_current_addr_sk = ca_address_sk and - c_birth_month in (6,3,1,11,7,4) and - d_year = 1998 and - ca_state in ('KY','TN','OK','NC','TX','VA','AL') - ) - select i_item_id, ca_country, ca_state, ca_county, agg1, agg2, agg3, agg4, agg5, agg6, agg7 - from ( - select i_item_id, ca_country, ca_state, ca_county, avg(agg1) agg1, - avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state, ca_county - union all - select i_item_id, ca_country, ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state - union all - select i_item_id, ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country - union all - select i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - ) foo - order by ca_country, ca_state, ca_county, i_item_id - limit 100; - --- end template query18a.tpl query 15 in stream 10 --- start template query32.tpl query 16 in stream 10 -select /* TPC-DS query32.tpl 0.7 */ sum(cs_ext_discount_amt) as "excess discount amount" -from - catalog_sales - ,item - ,date_dim -where -i_manufact_id = 825 -and i_item_sk = cs_item_sk -and d_date between '1999-03-25' and - dateadd(day,90,cast('1999-03-25' as date)) -and d_date_sk = cs_sold_date_sk -and cs_ext_discount_amt - > ( - select - 1.3 * avg(cs_ext_discount_amt) - from - catalog_sales - ,date_dim - where - cs_item_sk = i_item_sk - and d_date between '1999-03-25' and - dateadd(day,90,cast('1999-03-25' as date)) - and d_date_sk = cs_sold_date_sk - ) -limit 100; - --- end template query32.tpl query 16 in stream 10 --- start template query63.tpl query 17 in stream 10 -select /* TPC-DS query63.tpl 0.27 */ * -from (select i_manager_id - ,sum(ss_sales_price) sum_sales - ,avg(sum(ss_sales_price)) over (partition by i_manager_id) avg_monthly_sales - from item - ,store_sales - ,date_dim - ,store - where ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and d_month_seq in (1195,1195+1,1195+2,1195+3,1195+4,1195+5,1195+6,1195+7,1195+8,1195+9,1195+10,1195+11) - and (( i_category in ('Books','Children','Electronics') - and i_class in ('personal','portable','reference','self-help') - and i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) - or( i_category in ('Women','Music','Men') - and i_class in ('accessories','classical','fragrances','pants') - and i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manager_id, d_moy) tmp1 -where case when avg_monthly_sales > 0 then abs (sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 -order by i_manager_id - ,avg_monthly_sales - ,sum_sales -limit 100; - --- end template query63.tpl query 17 in stream 10 --- start template query24.tpl query 18 in stream 10 -with /* TPC-DS query24.tpl 0.92 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_net_paid) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip -and s_market_id=10 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'dark' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; -with /* TPC-DS query24.tpl 0.92 part2 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_net_paid) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip - and s_market_id = 10 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'magenta' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; - --- end template query24.tpl query 18 in stream 10 --- start template query66.tpl query 19 in stream 10 -select /* TPC-DS query66.tpl 0.39 */ - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - ,sum(jan_sales) as jan_sales - ,sum(feb_sales) as feb_sales - ,sum(mar_sales) as mar_sales - ,sum(apr_sales) as apr_sales - ,sum(may_sales) as may_sales - ,sum(jun_sales) as jun_sales - ,sum(jul_sales) as jul_sales - ,sum(aug_sales) as aug_sales - ,sum(sep_sales) as sep_sales - ,sum(oct_sales) as oct_sales - ,sum(nov_sales) as nov_sales - ,sum(dec_sales) as dec_sales - ,sum(jan_sales/w_warehouse_sq_ft) as jan_sales_per_sq_foot - ,sum(feb_sales/w_warehouse_sq_ft) as feb_sales_per_sq_foot - ,sum(mar_sales/w_warehouse_sq_ft) as mar_sales_per_sq_foot - ,sum(apr_sales/w_warehouse_sq_ft) as apr_sales_per_sq_foot - ,sum(may_sales/w_warehouse_sq_ft) as may_sales_per_sq_foot - ,sum(jun_sales/w_warehouse_sq_ft) as jun_sales_per_sq_foot - ,sum(jul_sales/w_warehouse_sq_ft) as jul_sales_per_sq_foot - ,sum(aug_sales/w_warehouse_sq_ft) as aug_sales_per_sq_foot - ,sum(sep_sales/w_warehouse_sq_ft) as sep_sales_per_sq_foot - ,sum(oct_sales/w_warehouse_sq_ft) as oct_sales_per_sq_foot - ,sum(nov_sales/w_warehouse_sq_ft) as nov_sales_per_sq_foot - ,sum(dec_sales/w_warehouse_sq_ft) as dec_sales_per_sq_foot - ,sum(jan_net) as jan_net - ,sum(feb_net) as feb_net - ,sum(mar_net) as mar_net - ,sum(apr_net) as apr_net - ,sum(may_net) as may_net - ,sum(jun_net) as jun_net - ,sum(jul_net) as jul_net - ,sum(aug_net) as aug_net - ,sum(sep_net) as sep_net - ,sum(oct_net) as oct_net - ,sum(nov_net) as nov_net - ,sum(dec_net) as dec_net - from ( - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'FEDEX' || ',' || 'ZOUROS' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then ws_sales_price* ws_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then ws_sales_price* ws_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then ws_sales_price* ws_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then ws_sales_price* ws_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then ws_sales_price* ws_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then ws_sales_price* ws_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then ws_sales_price* ws_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then ws_sales_price* ws_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then ws_sales_price* ws_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then ws_sales_price* ws_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then ws_sales_price* ws_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then ws_sales_price* ws_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then ws_net_profit * ws_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then ws_net_profit * ws_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then ws_net_profit * ws_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then ws_net_profit * ws_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then ws_net_profit * ws_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then ws_net_profit * ws_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then ws_net_profit * ws_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then ws_net_profit * ws_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then ws_net_profit * ws_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then ws_net_profit * ws_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then ws_net_profit * ws_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then ws_net_profit * ws_quantity else 0 end) as dec_net - from - web_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - ws_warehouse_sk = w_warehouse_sk - and ws_sold_date_sk = d_date_sk - and ws_sold_time_sk = t_time_sk - and ws_ship_mode_sk = sm_ship_mode_sk - and d_year = 2000 - and t_time between 56000 and 56000+28800 - and sm_carrier in ('FEDEX','ZOUROS') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - union all - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'FEDEX' || ',' || 'ZOUROS' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then cs_ext_sales_price* cs_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then cs_ext_sales_price* cs_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then cs_ext_sales_price* cs_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then cs_ext_sales_price* cs_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then cs_ext_sales_price* cs_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then cs_ext_sales_price* cs_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then cs_ext_sales_price* cs_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then cs_ext_sales_price* cs_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then cs_ext_sales_price* cs_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then cs_ext_sales_price* cs_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then cs_ext_sales_price* cs_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then cs_ext_sales_price* cs_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then cs_net_profit * cs_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then cs_net_profit * cs_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then cs_net_profit * cs_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then cs_net_profit * cs_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then cs_net_profit * cs_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then cs_net_profit * cs_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then cs_net_profit * cs_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then cs_net_profit * cs_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then cs_net_profit * cs_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then cs_net_profit * cs_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then cs_net_profit * cs_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then cs_net_profit * cs_quantity else 0 end) as dec_net - from - catalog_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and cs_sold_time_sk = t_time_sk - and cs_ship_mode_sk = sm_ship_mode_sk - and d_year = 2000 - and t_time between 56000 AND 56000+28800 - and sm_carrier in ('FEDEX','ZOUROS') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - ) x - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - order by w_warehouse_name - limit 100; - --- end template query66.tpl query 19 in stream 10 --- start template query70a.tpl query 20 in stream 10 -with /* TPC-DS query70a.tpl 0.34 */ results as -( select - sum(ss_net_profit) as total_sum ,s_state ,s_county, 0 as gstate, 0 as g_county - from - store_sales - ,date_dim d1 - ,store - where - d1.d_month_seq between 1176 and 1176 + 11 - and d1.d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - and s_state in - ( select s_state - from (select s_state as s_state, - rank() over ( partition by s_state order by sum(ss_net_profit) desc) as ranking - from store_sales, store, date_dim - where d_month_seq between 1176 and 1176 + 11 - and d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - group by s_state - ) tmp1 - where ranking <= 5) - group by s_state,s_county) , - results_rollup as -(select total_sum ,s_state ,s_county, 0 as g_state, 0 as g_county, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum,s_state, NULL as s_county, 0 as g_state, 1 as g_county, 1 as lochierarchy from results group by s_state - union - select sum(total_sum) as total_sum ,NULL as s_state ,NULL as s_county, 1 as g_state, 1 as g_county, 2 as lochierarchy from results) - select total_sum ,s_state ,s_county, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_county = 0 then s_state end - order by total_sum desc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then s_state end - ,rank_within_parent - limit 100; - --- end template query70a.tpl query 20 in stream 10 --- start template query36a.tpl query 21 in stream 10 -with /* TPC-DS query36a.tpl 0.21 */ results as - (select - sum(ss_net_profit) as ss_net_profit, sum(ss_ext_sales_price) as ss_ext_sales_price, - sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin - ,i_category - ,i_class - ,0 as g_category, 0 as g_class - from - store_sales - ,date_dim d1 - ,item - ,store - where - d1.d_year = 1998 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and s_state in ('TX','MN','TX','OH', - 'GA','WV','SD','SC') - group by i_category,i_class) - , - results_rollup as - (select gross_margin ,i_category ,i_class,0 as t_category, 0 as t_class, 0 as lochierarchy from results - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - i_category, NULL AS i_class, 0 as t_category, 1 as t_class, 1 as lochierarchy from results group by i_category - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - NULL AS i_category ,NULL AS i_class, 1 as t_category, 1 as t_class, 2 as lochierarchy from results) - select - gross_margin ,i_category ,i_class, lochierarchy,rank() over ( - partition by lochierarchy, case when t_class = 0 then i_category end - order by gross_margin asc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then i_category end - ,rank_within_parent - limit 100; - --- end template query36a.tpl query 21 in stream 10 --- start template query20.tpl query 22 in stream 10 -select /* TPC-DS query20.tpl 0.65 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(cs_ext_sales_price) as itemrevenue - ,sum(cs_ext_sales_price)*100/sum(sum(cs_ext_sales_price)) over - (partition by i_class) as revenueratio - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and i_category in ('Jewelry', 'Women', 'Music') - and cs_sold_date_sk = d_date_sk - and d_date between cast('2002-04-28' as date) - and dateadd(day,30,cast('2002-04-28' as date)) - group by i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - order by i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query20.tpl query 22 in stream 10 --- start template query30.tpl query 23 in stream 10 -with /* TPC-DS query30.tpl 0.75 */ customer_total_return as - (select wr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(wr_return_amt) as ctr_total_return - from web_returns - ,date_dim - ,customer_address - where wr_returned_date_sk = d_date_sk - and d_year =2000 - and wr_returning_addr_sk = ca_address_sk - group by wr_returning_customer_sk - ,ca_state) - select c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'GA' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return -limit 100; - --- end template query30.tpl query 23 in stream 10 --- start template query25.tpl query 24 in stream 10 -select /* TPC-DS query25.tpl 0.9 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,max(ss_net_profit) as store_sales_profit - ,max(sr_net_loss) as store_returns_loss - ,max(cs_net_profit) as catalog_sales_profit - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 2000 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 10 - and d2.d_year = 2000 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_moy between 4 and 10 - and d3.d_year = 2000 - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query25.tpl query 24 in stream 10 --- start template query7.tpl query 25 in stream 10 -select /* TPC-DS query7.tpl 0.2 */ i_item_id, - avg(ss_quantity) agg1, - avg(ss_list_price) agg2, - avg(ss_coupon_amt) agg3, - avg(ss_sales_price) agg4 - from store_sales, customer_demographics, date_dim, item, promotion - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_cdemo_sk = cd_demo_sk and - ss_promo_sk = p_promo_sk and - cd_gender = 'M' and - cd_marital_status = 'U' and - cd_education_status = 'Unknown' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 2002 - group by i_item_id - order by i_item_id - limit 100; - --- end template query7.tpl query 25 in stream 10 --- start template query1.tpl query 26 in stream 10 -with /* TPC-DS query1.tpl 0.12 */ customer_total_return as -(select sr_customer_sk as ctr_customer_sk -,sr_store_sk as ctr_store_sk -,sum(SR_RETURN_TAX) as ctr_total_return -from store_returns -,date_dim -where sr_returned_date_sk = d_date_sk -and d_year =1998 -group by sr_customer_sk -,sr_store_sk) - select c_customer_id -from customer_total_return ctr1 -,store -,customer -where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 -from customer_total_return ctr2 -where ctr1.ctr_store_sk = ctr2.ctr_store_sk) -and s_store_sk = ctr1.ctr_store_sk -and s_state = 'CO' -and ctr1.ctr_customer_sk = c_customer_sk -order by c_customer_id -limit 100; - --- end template query1.tpl query 26 in stream 10 --- start template query98.tpl query 27 in stream 10 -select /* TPC-DS query98.tpl 0.32 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ss_ext_sales_price) as itemrevenue - ,sum(ss_ext_sales_price)*100/sum(sum(ss_ext_sales_price)) over - (partition by i_class) as revenueratio -from - store_sales - ,item - ,date_dim -where - ss_item_sk = i_item_sk - and i_category in ('Children', 'Home', 'Shoes') - and ss_sold_date_sk = d_date_sk - and d_date between cast('1998-03-24' as date) - and dateadd(day,30,cast('1998-03-24' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio; - --- end template query98.tpl query 27 in stream 10 --- start template query69.tpl query 28 in stream 10 -select /* TPC-DS query69.tpl 0.28 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_state in ('AR','CA','OK') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 1999 and - d_moy between 3 and 3+2) and - (not exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 1999 and - d_moy between 3 and 3+2) and - not exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 1999 and - d_moy between 3 and 3+2)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - limit 100; - --- end template query69.tpl query 28 in stream 10 --- start template query47.tpl query 29 in stream 10 -with /* TPC-DS query47.tpl 0.42 */ v1 as( - select i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, - s_store_name, s_company_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - s_store_name, s_company_name - order by d_year, d_moy) rn - from item, store_sales, date_dim, store - where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - ( - d_year = 1999 or - ( d_year = 1999-1 and d_moy =12) or - ( d_year = 1999+1 and d_moy =1) - ) - group by i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy), - v2 as( - select v1.s_company_name - ,v1.d_year, v1.d_moy - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1.s_store_name = v1_lag.s_store_name and - v1.s_store_name = v1_lead.s_store_name and - v1.s_company_name = v1_lag.s_company_name and - v1.s_company_name = v1_lead.s_company_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 1999 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, avg_monthly_sales - limit 100; - --- end template query47.tpl query 29 in stream 10 --- start template query94.tpl query 30 in stream 10 -select /* TPC-DS query94.tpl 0.17 */ - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2000-5-01' and - dateadd(day,60,cast('2000-5-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'UT' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and exists (select * - from web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) -and not exists(select * - from web_returns wr1 - where ws1.ws_order_number = wr1.wr_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query94.tpl query 30 in stream 10 --- start template query82.tpl query 31 in stream 10 -select /* TPC-DS query82.tpl 0.67 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, store_sales - where i_current_price between 42 and 42+30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('1998-03-11' as date) and dateadd(day,60,cast('1998-03-11' as date)) - and i_manufact_id in (521,534,266,154) - and inv_quantity_on_hand between 100 and 500 - and ss_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query82.tpl query 31 in stream 10 --- start template query37.tpl query 32 in stream 10 -select /* TPC-DS query37.tpl 0.31 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, catalog_sales - where i_current_price between 44 and 44 + 30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('1998-05-28' as date) and dateadd(day,60,cast('1998-05-28' as date)) - and i_manufact_id in (717,898,923,894) - and inv_quantity_on_hand between 100 and 500 - and cs_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query37.tpl query 32 in stream 10 --- start template query64.tpl query 33 in stream 10 -with /* TPC-DS query64.tpl 0.20 */ cs_ui as - (select cs_item_sk - ,sum(cs_ext_list_price) as sale,sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit) as refund - from catalog_sales - ,catalog_returns - where cs_item_sk = cr_item_sk - and cs_order_number = cr_order_number - group by cs_item_sk - having sum(cs_ext_list_price)>2*sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit)), -cross_sales as - (select i_product_name product_name - ,i_item_sk item_sk - ,s_store_name store_name - ,s_zip store_zip - ,ad1.ca_street_number b_street_number - ,ad1.ca_street_name b_street_name - ,ad1.ca_city b_city - ,ad1.ca_zip b_zip - ,ad2.ca_street_number c_street_number - ,ad2.ca_street_name c_street_name - ,ad2.ca_city c_city - ,ad2.ca_zip c_zip - ,d1.d_year as syear - ,d2.d_year as fsyear - ,d3.d_year s2year - ,count(*) cnt - ,sum(ss_wholesale_cost) s1 - ,sum(ss_list_price) s2 - ,sum(ss_coupon_amt) s3 - FROM store_sales - ,store_returns - ,cs_ui - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,customer - ,customer_demographics cd1 - ,customer_demographics cd2 - ,promotion - ,household_demographics hd1 - ,household_demographics hd2 - ,customer_address ad1 - ,customer_address ad2 - ,income_band ib1 - ,income_band ib2 - ,item - WHERE ss_store_sk = s_store_sk AND - ss_sold_date_sk = d1.d_date_sk AND - ss_customer_sk = c_customer_sk AND - ss_cdemo_sk= cd1.cd_demo_sk AND - ss_hdemo_sk = hd1.hd_demo_sk AND - ss_addr_sk = ad1.ca_address_sk and - ss_item_sk = i_item_sk and - ss_item_sk = sr_item_sk and - ss_ticket_number = sr_ticket_number and - ss_item_sk = cs_ui.cs_item_sk and - c_current_cdemo_sk = cd2.cd_demo_sk AND - c_current_hdemo_sk = hd2.hd_demo_sk AND - c_current_addr_sk = ad2.ca_address_sk and - c_first_sales_date_sk = d2.d_date_sk and - c_first_shipto_date_sk = d3.d_date_sk and - ss_promo_sk = p_promo_sk and - hd1.hd_income_band_sk = ib1.ib_income_band_sk and - hd2.hd_income_band_sk = ib2.ib_income_band_sk and - cd1.cd_marital_status <> cd2.cd_marital_status and - i_color in ('blue','snow','almond','hot','blanched','turquoise') and - i_current_price between 40 and 40 + 10 and - i_current_price between 40 + 1 and 40 + 15 -group by i_product_name - ,i_item_sk - ,s_store_name - ,s_zip - ,ad1.ca_street_number - ,ad1.ca_street_name - ,ad1.ca_city - ,ad1.ca_zip - ,ad2.ca_street_number - ,ad2.ca_street_name - ,ad2.ca_city - ,ad2.ca_zip - ,d1.d_year - ,d2.d_year - ,d3.d_year -) -select cs1.product_name - ,cs1.store_name - ,cs1.store_zip - ,cs1.b_street_number - ,cs1.b_street_name - ,cs1.b_city - ,cs1.b_zip - ,cs1.c_street_number - ,cs1.c_street_name - ,cs1.c_city - ,cs1.c_zip - ,cs1.syear - ,cs1.cnt - ,cs1.s1 as s11 - ,cs1.s2 as s21 - ,cs1.s3 as s31 - ,cs2.s1 as s12 - ,cs2.s2 as s22 - ,cs2.s3 as s32 - ,cs2.syear - ,cs2.cnt -from cross_sales cs1,cross_sales cs2 -where cs1.item_sk=cs2.item_sk and - cs1.syear = 1999 and - cs2.syear = 1999 + 1 and - cs2.cnt <= cs1.cnt and - cs1.store_name = cs2.store_name and - cs1.store_zip = cs2.store_zip -order by cs1.product_name - ,cs1.store_name - ,cs2.cnt - ,cs1.s1 - ,cs2.s1; - --- end template query64.tpl query 33 in stream 10 --- start template query86a.tpl query 34 in stream 10 -with /* TPC-DS query86a.tpl 0.11 */ results as -( select sum(ws_net_paid) as total_sum, i_category, i_class, 0 as g_category, 0 as g_class - from - web_sales - ,date_dim d1 - ,item - where - d1.d_month_seq between 1217 and 1217+11 - and d1.d_date_sk = ws_sold_date_sk - and i_item_sk = ws_item_sk - group by i_category,i_class - ) , - - results_rollup as -( select total_sum ,i_category ,i_class, g_category, g_class, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum, i_category, NULL as i_class, 0 as g_category, 1 as g_class, 1 as lochierarchy from results group by i_category - union - select sum(total_sum) as total_sum, NULL as i_category, NULL as i_class, 1 as g_category, 1 as g_class, 2 as lochierarchy from results) - select - total_sum ,i_category ,i_class, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_class = 0 then i_category end - order by total_sum desc) as rank_within_parent - from - results_rollup - order by - lochierarchy desc, - case when lochierarchy = 0 then i_category end, - rank_within_parent - limit 100; - --- end template query86a.tpl query 34 in stream 10 --- start template query87.tpl query 35 in stream 10 -select /* TPC-DS query87.tpl 0.77 */ count(*) -from ((select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1203 and 1203+11) - except - (select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1203 and 1203+11) - except - (select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1203 and 1203+11) -) cool_cust -; - --- end template query87.tpl query 35 in stream 10 --- start template query28.tpl query 36 in stream 10 -select /* TPC-DS query28.tpl 0.36 */ * -from (select avg(ss_list_price) B1_LP - ,count(ss_list_price) B1_CNT - ,count(distinct ss_list_price) B1_CNTD - from store_sales - where ss_quantity between 0 and 5 - and (ss_list_price between 25 and 25+10 - or ss_coupon_amt between 8806 and 8806+1000 - or ss_wholesale_cost between 35 and 35+20)) B1, - (select avg(ss_list_price) B2_LP - ,count(ss_list_price) B2_CNT - ,count(distinct ss_list_price) B2_CNTD - from store_sales - where ss_quantity between 6 and 10 - and (ss_list_price between 175 and 175+10 - or ss_coupon_amt between 916 and 916+1000 - or ss_wholesale_cost between 29 and 29+20)) B2, - (select avg(ss_list_price) B3_LP - ,count(ss_list_price) B3_CNT - ,count(distinct ss_list_price) B3_CNTD - from store_sales - where ss_quantity between 11 and 15 - and (ss_list_price between 10 and 10+10 - or ss_coupon_amt between 7669 and 7669+1000 - or ss_wholesale_cost between 14 and 14+20)) B3, - (select avg(ss_list_price) B4_LP - ,count(ss_list_price) B4_CNT - ,count(distinct ss_list_price) B4_CNTD - from store_sales - where ss_quantity between 16 and 20 - and (ss_list_price between 144 and 144+10 - or ss_coupon_amt between 7682 and 7682+1000 - or ss_wholesale_cost between 64 and 64+20)) B4, - (select avg(ss_list_price) B5_LP - ,count(ss_list_price) B5_CNT - ,count(distinct ss_list_price) B5_CNTD - from store_sales - where ss_quantity between 21 and 25 - and (ss_list_price between 121 and 121+10 - or ss_coupon_amt between 3004 and 3004+1000 - or ss_wholesale_cost between 79 and 79+20)) B5, - (select avg(ss_list_price) B6_LP - ,count(ss_list_price) B6_CNT - ,count(distinct ss_list_price) B6_CNTD - from store_sales - where ss_quantity between 26 and 30 - and (ss_list_price between 58 and 58+10 - or ss_coupon_amt between 522 and 522+1000 - or ss_wholesale_cost between 28 and 28+20)) B6 -limit 100; - --- end template query28.tpl query 36 in stream 10 --- start template query55.tpl query 37 in stream 10 -select /* TPC-DS query55.tpl 0.82 */ i_brand_id brand_id, i_brand brand, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=93 - and d_moy=11 - and d_year=1998 - group by i_brand, i_brand_id - order by ext_price desc, i_brand_id -limit 100 ; - --- end template query55.tpl query 37 in stream 10 --- start template query85.tpl query 38 in stream 10 -select /* TPC-DS query85.tpl 0.33 */ substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) - from web_sales, web_returns, web_page, customer_demographics cd1, - customer_demographics cd2, customer_address, date_dim, reason - where ws_web_page_sk = wp_web_page_sk - and ws_item_sk = wr_item_sk - and ws_order_number = wr_order_number - and ws_sold_date_sk = d_date_sk and d_year = 2001 - and cd1.cd_demo_sk = wr_refunded_cdemo_sk - and cd2.cd_demo_sk = wr_returning_cdemo_sk - and ca_address_sk = wr_refunded_addr_sk - and r_reason_sk = wr_reason_sk - and - ( - ( - cd1.cd_marital_status = 'S' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Advanced Degree' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 100.00 and 150.00 - ) - or - ( - cd1.cd_marital_status = 'M' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = '2 yr Degree' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 50.00 and 100.00 - ) - or - ( - cd1.cd_marital_status = 'D' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Secondary' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ca_country = 'United States' - and - ca_state in ('WA', 'MN', 'OH') - and ws_net_profit between 100 and 200 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('PA', 'NC', 'SD') - and ws_net_profit between 150 and 300 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('KY', 'VA', 'WV') - and ws_net_profit between 50 and 250 - ) - ) -group by r_reason_desc -order by substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) -limit 100; - --- end template query85.tpl query 38 in stream 10 --- start template query38.tpl query 39 in stream 10 -select /* TPC-DS query38.tpl 0.54 */ count(*) from ( - select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1203 and 1203 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1203 and 1203 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1203 and 1203 + 11 -) hot_cust -limit 100; - --- end template query38.tpl query 39 in stream 10 --- start template query44.tpl query 40 in stream 10 -select /* TPC-DS query44.tpl 0.4 */ asceding.rnk, i1.i_product_name best_performing, i2.i_product_name worst_performing -from(select * - from (select item_sk,rank() over (order by rank_col asc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 777 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 777 - and ss_addr_sk is null - group by ss_store_sk))V1)V11 - where rnk < 11) asceding, - (select * - from (select item_sk,rank() over (order by rank_col desc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 777 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 777 - and ss_addr_sk is null - group by ss_store_sk))V2)V21 - where rnk < 11) descending, -item i1, -item i2 -where asceding.rnk = descending.rnk - and i1.i_item_sk=asceding.item_sk - and i2.i_item_sk=descending.item_sk -order by asceding.rnk -limit 100; - --- end template query44.tpl query 40 in stream 10 --- start template query27a.tpl query 41 in stream 10 -with /* TPC-DS query27a.tpl 0.16 */ results as - (select i_item_id, - s_state, 0 as g_state, - ss_quantity agg1, - ss_list_price agg2, - ss_coupon_amt agg3, - ss_sales_price agg4 - from store_sales, customer_demographics, date_dim, store, item - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_store_sk = s_store_sk and - ss_cdemo_sk = cd_demo_sk and - cd_gender = 'F' and - cd_marital_status = 'D' and - cd_education_status = '4 yr Degree' and - d_year = 1999 and - s_state in ('TX','GA', 'IL', 'OK', 'NE', 'MI') - ) - - select i_item_id, - s_state, g_state, agg1, agg2, agg3, agg4 - from ( - select i_item_id, s_state, 0 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4 from results - group by i_item_id, s_state - union all - select i_item_id, NULL AS s_state, 1 AS g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as s_state, 1 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - ) foo - order by i_item_id, s_state - limit 100; - --- end template query27a.tpl query 41 in stream 10 --- start template query78.tpl query 42 in stream 10 -with /* TPC-DS query78.tpl 0.10 */ ws as - (select d_year AS ws_sold_year, ws_item_sk, - ws_bill_customer_sk ws_customer_sk, - sum(ws_quantity) ws_qty, - sum(ws_wholesale_cost) ws_wc, - sum(ws_sales_price) ws_sp - from web_sales - left join web_returns on wr_order_number=ws_order_number and ws_item_sk=wr_item_sk - join date_dim on ws_sold_date_sk = d_date_sk - where wr_order_number is null - group by d_year, ws_item_sk, ws_bill_customer_sk - ), -cs as - (select d_year AS cs_sold_year, cs_item_sk, - cs_bill_customer_sk cs_customer_sk, - sum(cs_quantity) cs_qty, - sum(cs_wholesale_cost) cs_wc, - sum(cs_sales_price) cs_sp - from catalog_sales - left join catalog_returns on cr_order_number=cs_order_number and cs_item_sk=cr_item_sk - join date_dim on cs_sold_date_sk = d_date_sk - where cr_order_number is null - group by d_year, cs_item_sk, cs_bill_customer_sk - ), -ss as - (select d_year AS ss_sold_year, ss_item_sk, - ss_customer_sk, - sum(ss_quantity) ss_qty, - sum(ss_wholesale_cost) ss_wc, - sum(ss_sales_price) ss_sp - from store_sales - left join store_returns on sr_ticket_number=ss_ticket_number and ss_item_sk=sr_item_sk - join date_dim on ss_sold_date_sk = d_date_sk - where sr_ticket_number is null - group by d_year, ss_item_sk, ss_customer_sk - ) - select -ss_customer_sk, -round(ss_qty/(coalesce(ws_qty,0)+coalesce(cs_qty,0)),2) ratio, -ss_qty store_qty, ss_wc store_wholesale_cost, ss_sp store_sales_price, -coalesce(ws_qty,0)+coalesce(cs_qty,0) other_chan_qty, -coalesce(ws_wc,0)+coalesce(cs_wc,0) other_chan_wholesale_cost, -coalesce(ws_sp,0)+coalesce(cs_sp,0) other_chan_sales_price -from ss -left join ws on (ws_sold_year=ss_sold_year and ws_item_sk=ss_item_sk and ws_customer_sk=ss_customer_sk) -left join cs on (cs_sold_year=ss_sold_year and cs_item_sk=ss_item_sk and cs_customer_sk=ss_customer_sk) -where (coalesce(ws_qty,0)>0 or coalesce(cs_qty, 0)>0) and ss_sold_year=1999 -order by - ss_customer_sk, - ss_qty desc, ss_wc desc, ss_sp desc, - other_chan_qty, - other_chan_wholesale_cost, - other_chan_sales_price, - ratio -limit 100; - --- end template query78.tpl query 42 in stream 10 --- start template query45.tpl query 43 in stream 10 -select /* TPC-DS query45.tpl 0.18 */ ca_zip, ca_county, sum(ws_sales_price) - from web_sales, customer, customer_address, date_dim, item - where ws_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ws_item_sk = i_item_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', '85392', '85460', '80348', '81792') - or - i_item_id in (select i_item_id - from item - where i_item_sk in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29) - ) - ) - and ws_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 1999 - group by ca_zip, ca_county - order by ca_zip, ca_county - limit 100; - --- end template query45.tpl query 43 in stream 10 --- start template query49.tpl query 44 in stream 10 -select /* TPC-DS query49.tpl 0.48 */ channel, item, return_ratio, return_rank, currency_rank from - (select - 'web' as channel - ,web.item - ,web.return_ratio - ,web.return_rank - ,web.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select ws.ws_item_sk as item - ,(cast(sum(coalesce(wr.wr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(wr.wr_return_amt,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - web_sales ws left outer join web_returns wr - on (ws.ws_order_number = wr.wr_order_number and - ws.ws_item_sk = wr.wr_item_sk) - ,date_dim - where - wr.wr_return_amt > 10000 - and ws.ws_net_profit > 1 - and ws.ws_net_paid > 0 - and ws.ws_quantity > 0 - and ws_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 11 - group by ws.ws_item_sk - ) in_web - ) web - where - ( - web.return_rank <= 10 - or - web.currency_rank <= 10 - ) - union - select - 'catalog' as channel - ,catalog.item - ,catalog.return_ratio - ,catalog.return_rank - ,catalog.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select - cs.cs_item_sk as item - ,(cast(sum(coalesce(cr.cr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(cr.cr_return_amount,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - catalog_sales cs left outer join catalog_returns cr - on (cs.cs_order_number = cr.cr_order_number and - cs.cs_item_sk = cr.cr_item_sk) - ,date_dim - where - cr.cr_return_amount > 10000 - and cs.cs_net_profit > 1 - and cs.cs_net_paid > 0 - and cs.cs_quantity > 0 - and cs_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 11 - group by cs.cs_item_sk - ) in_cat - ) catalog - where - ( - catalog.return_rank <= 10 - or - catalog.currency_rank <=10 - ) - union - select - 'store' as channel - ,store.item - ,store.return_ratio - ,store.return_rank - ,store.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select sts.ss_item_sk as item - ,(cast(sum(coalesce(sr.sr_return_quantity,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(sr.sr_return_amt,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - store_sales sts left outer join store_returns sr - on (sts.ss_ticket_number = sr.sr_ticket_number and sts.ss_item_sk = sr.sr_item_sk) - ,date_dim - where - sr.sr_return_amt > 10000 - and sts.ss_net_profit > 1 - and sts.ss_net_paid > 0 - and sts.ss_quantity > 0 - and ss_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 11 - group by sts.ss_item_sk - ) in_store - ) store - where ( - store.return_rank <= 10 - or - store.currency_rank <= 10 - ) - ) - order by 1,4,5,2 - limit 100; - --- end template query49.tpl query 44 in stream 10 --- start template query62.tpl query 45 in stream 10 -select /* TPC-DS query62.tpl 0.24 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 30) and - (ws_ship_date_sk - ws_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 60) and - (ws_ship_date_sk - ws_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 90) and - (ws_ship_date_sk - ws_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - web_sales - ,warehouse - ,ship_mode - ,web_site - ,date_dim -where - d_month_seq between 1220 and 1220 + 11 -and ws_ship_date_sk = d_date_sk -and ws_warehouse_sk = w_warehouse_sk -and ws_ship_mode_sk = sm_ship_mode_sk -and ws_web_site_sk = web_site_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -limit 100; - --- end template query62.tpl query 45 in stream 10 --- start template query59.tpl query 46 in stream 10 -with /* TPC-DS query59.tpl 0.30 */ wss as - (select d_week_seq, - ss_store_sk, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - group by d_week_seq,ss_store_sk - ) - select s_store_name1,s_store_id1,d_week_seq1 - ,sun_sales1/sun_sales2,mon_sales1/mon_sales2 - ,tue_sales1/tue_sales2,wed_sales1/wed_sales2,thu_sales1/thu_sales2 - ,fri_sales1/fri_sales2,sat_sales1/sat_sales2 - from - (select s_store_name s_store_name1,wss.d_week_seq d_week_seq1 - ,s_store_id s_store_id1,sun_sales sun_sales1 - ,mon_sales mon_sales1,tue_sales tue_sales1 - ,wed_sales wed_sales1,thu_sales thu_sales1 - ,fri_sales fri_sales1,sat_sales sat_sales1 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1203 and 1203 + 11) y, - (select s_store_name s_store_name2,wss.d_week_seq d_week_seq2 - ,s_store_id s_store_id2,sun_sales sun_sales2 - ,mon_sales mon_sales2,tue_sales tue_sales2 - ,wed_sales wed_sales2,thu_sales thu_sales2 - ,fri_sales fri_sales2,sat_sales sat_sales2 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1203+ 12 and 1203 + 23) x - where s_store_id1=s_store_id2 - and d_week_seq1=d_week_seq2-52 - order by s_store_name1,s_store_id1,d_week_seq1 -limit 100; - --- end template query59.tpl query 46 in stream 10 --- start template query77a.tpl query 47 in stream 10 -with /* TPC-DS query77a.tpl 0.78 */ ss as - (select s_store_sk, - sum(ss_ext_sales_price) as sales, - sum(ss_net_profit) as profit - from store_sales, - date_dim, - store - where ss_sold_date_sk = d_date_sk - and d_date between cast('1998-08-13' as date) - and dateadd(day,30,cast('1998-08-13' as date)) - and ss_store_sk = s_store_sk - group by s_store_sk) - , - sr as - (select s_store_sk, - sum(sr_return_amt) as returns, - sum(sr_net_loss) as profit_loss - from store_returns, - date_dim, - store - where sr_returned_date_sk = d_date_sk - and d_date between cast('1998-08-13' as date) - and dateadd(day,30,cast('1998-08-13' as date)) - and sr_store_sk = s_store_sk - group by s_store_sk), - cs as - (select cs_call_center_sk, - sum(cs_ext_sales_price) as sales, - sum(cs_net_profit) as profit - from catalog_sales, - date_dim - where cs_sold_date_sk = d_date_sk - and d_date between cast('1998-08-13' as date) - and dateadd(day,30,cast('1998-08-13' as date)) - group by cs_call_center_sk - ), - cr as - (select cr_call_center_sk, - sum(cr_return_amount) as returns, - sum(cr_net_loss) as profit_loss - from catalog_returns, - date_dim - where cr_returned_date_sk = d_date_sk - and d_date between cast('1998-08-13' as date) - and dateadd(day,30,cast('1998-08-13' as date)) - group by cr_call_center_sk), - ws as - ( select wp_web_page_sk, - sum(ws_ext_sales_price) as sales, - sum(ws_net_profit) as profit - from web_sales, - date_dim, - web_page - where ws_sold_date_sk = d_date_sk - and d_date between cast('1998-08-13' as date) - and dateadd(day,30,cast('1998-08-13' as date)) - and ws_web_page_sk = wp_web_page_sk - group by wp_web_page_sk), - wr as - (select wp_web_page_sk, - sum(wr_return_amt) as returns, - sum(wr_net_loss) as profit_loss - from web_returns, - date_dim, - web_page - where wr_returned_date_sk = d_date_sk - and d_date between cast('1998-08-13' as date) - and dateadd(day,30,cast('1998-08-13' as date)) - and wr_web_page_sk = wp_web_page_sk - group by wp_web_page_sk) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , ss.s_store_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ss left join sr - on ss.s_store_sk = sr.s_store_sk - union all - select 'catalog channel' as channel - , cs_call_center_sk as id - , sales - , returns - , (profit - profit_loss) as profit - from cs - , cr - union all - select 'web channel' as channel - , ws.wp_web_page_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ws left join wr - on ws.wp_web_page_sk = wr.wp_web_page_sk - ) x - group by channel, id ) - - select * - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results -) foo -order by channel, id - limit 100; - --- end template query77a.tpl query 47 in stream 10 --- start template query80a.tpl query 48 in stream 10 -with /* TPC-DS query80a.tpl 0.6 */ ssr as - (select s_store_id as store_id, - sum(ss_ext_sales_price) as sales, - sum(coalesce(sr_return_amt, 0)) as returns, - sum(ss_net_profit - coalesce(sr_net_loss, 0)) as profit - from store_sales left outer join store_returns on - (ss_item_sk = sr_item_sk and ss_ticket_number = sr_ticket_number), - date_dim, - store, - item, - promotion - where ss_sold_date_sk = d_date_sk - and d_date between cast('2001-08-29' as date) - and dateadd(day,30,cast('2001-08-29' as date)) - and ss_store_sk = s_store_sk - and ss_item_sk = i_item_sk - and i_current_price > 50 - and ss_promo_sk = p_promo_sk - and p_channel_tv = 'N' - group by s_store_id) - , - csr as - (select cp_catalog_page_id as catalog_page_id, - sum(cs_ext_sales_price) as sales, - sum(coalesce(cr_return_amount, 0)) as returns, - sum(cs_net_profit - coalesce(cr_net_loss, 0)) as profit - from catalog_sales left outer join catalog_returns on - (cs_item_sk = cr_item_sk and cs_order_number = cr_order_number), - date_dim, - catalog_page, - item, - promotion - where cs_sold_date_sk = d_date_sk - and d_date between cast('2001-08-29' as date) - and dateadd(day,30,cast('2001-08-29' as date)) - and cs_catalog_page_sk = cp_catalog_page_sk - and cs_item_sk = i_item_sk - and i_current_price > 50 - and cs_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(ws_ext_sales_price) as sales, - sum(coalesce(wr_return_amt, 0)) as returns, - sum(ws_net_profit - coalesce(wr_net_loss, 0)) as profit - from web_sales left outer join web_returns on - (ws_item_sk = wr_item_sk and ws_order_number = wr_order_number), - date_dim, - web_site, - item, - promotion - where ws_sold_date_sk = d_date_sk - and d_date between cast('2001-08-29' as date) - and dateadd(day,30,cast('2001-08-29' as date)) - and ws_web_site_sk = web_site_sk - and ws_item_sk = i_item_sk - and i_current_price > 50 - and ws_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by web_site_id) -, -results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || store_id as id - , sales - , returns - , profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || catalog_page_id as id - , sales - , returns - , profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , profit - from wsr - ) x - group by channel, id) - - select channel - , id - , sales - , returns - , profit - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results - ) foo - order by channel, id - limit 100; - --- end template query80a.tpl query 48 in stream 10 --- start template query84.tpl query 49 in stream 10 -select /* TPC-DS query84.tpl 0.80 */ c_customer_id as customer_id - , coalesce(c_last_name,'') || ', ' || coalesce(c_first_name,'') as customername - from customer - ,customer_address - ,customer_demographics - ,household_demographics - ,income_band - ,store_returns - where ca_city = 'Fairview' - and c_current_addr_sk = ca_address_sk - and ib_lower_bound >= 5575 - and ib_upper_bound <= 5575 + 50000 - and ib_income_band_sk = hd_income_band_sk - and cd_demo_sk = c_current_cdemo_sk - and hd_demo_sk = c_current_hdemo_sk - and sr_cdemo_sk = cd_demo_sk - order by c_customer_id - limit 100; - --- end template query84.tpl query 49 in stream 10 --- start template query67a.tpl query 50 in stream 10 -with /* TPC-DS query67a.tpl 0.35 */ results as -( select i_category ,i_class ,i_brand ,i_product_name ,d_year ,d_qoy ,d_moy ,s_store_id - ,sum(coalesce(ss_sales_price*ss_quantity,0)) sumsales - from store_sales ,date_dim ,store ,item - where ss_sold_date_sk=d_date_sk - and ss_item_sk=i_item_sk - and ss_store_sk = s_store_sk - and d_month_seq between 1202 and 1202 + 11 - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy,s_store_id) - , - results_rollup as - (select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, s_store_id, sumsales - from results - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy - union all - select i_category, i_class, i_brand, i_product_name, d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year - union all - select i_category, i_class, i_brand, i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name - union all - select i_category, i_class, i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand - union all - select i_category, i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class - union all - select i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category - union all - select null i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results) - - select * -from (select i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rank() over (partition by i_category order by sumsales desc) rk - from results_rollup) dw2 -where rk <= 100 -order by i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rk -limit 100; - --- end template query67a.tpl query 50 in stream 10 --- start template query52.tpl query 51 in stream 10 -select /* TPC-DS query52.tpl 0.59 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_sales_price) ext_price - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=11 - and dt.d_year=2000 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,ext_price desc - ,brand_id -limit 100 ; - --- end template query52.tpl query 51 in stream 10 --- start template query76.tpl query 52 in stream 10 -select /* TPC-DS query76.tpl 0.99 */ channel, col_name, d_year, d_qoy, i_category, COUNT(*) sales_cnt, SUM(ext_sales_price) sales_amt FROM ( - SELECT 'store' as channel, 'ss_store_sk' col_name, d_year, d_qoy, i_category, ss_ext_sales_price ext_sales_price - FROM store_sales, item, date_dim - WHERE ss_store_sk IS NULL - AND ss_sold_date_sk=d_date_sk - AND ss_item_sk=i_item_sk - UNION ALL - SELECT 'web' as channel, 'ws_promo_sk' col_name, d_year, d_qoy, i_category, ws_ext_sales_price ext_sales_price - FROM web_sales, item, date_dim - WHERE ws_promo_sk IS NULL - AND ws_sold_date_sk=d_date_sk - AND ws_item_sk=i_item_sk - UNION ALL - SELECT 'catalog' as channel, 'cs_ship_hdemo_sk' col_name, d_year, d_qoy, i_category, cs_ext_sales_price ext_sales_price - FROM catalog_sales, item, date_dim - WHERE cs_ship_hdemo_sk IS NULL - AND cs_sold_date_sk=d_date_sk - AND cs_item_sk=i_item_sk) foo -GROUP BY channel, col_name, d_year, d_qoy, i_category -ORDER BY channel, col_name, d_year, d_qoy, i_category -limit 100; - --- end template query76.tpl query 52 in stream 10 --- start template query42.tpl query 53 in stream 10 -select /* TPC-DS query42.tpl 0.61 */ dt.d_year - ,item.i_category_id - ,item.i_category - ,sum(ss_ext_sales_price) - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=11 - and dt.d_year=2001 - group by dt.d_year - ,item.i_category_id - ,item.i_category - order by sum(ss_ext_sales_price) desc,dt.d_year - ,item.i_category_id - ,item.i_category -limit 100 ; - --- end template query42.tpl query 53 in stream 10 --- start template query33.tpl query 54 in stream 10 -with /* TPC-DS query33.tpl 0.22 */ ss as ( - select - i_manufact_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Home')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 7 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id), - cs as ( - select - i_manufact_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Home')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 7 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id), - ws as ( - select - i_manufact_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Home')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 7 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id) - select i_manufact_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_manufact_id - order by total_sales -limit 100; - --- end template query33.tpl query 54 in stream 10 --- start template query65.tpl query 55 in stream 10 -select /* TPC-DS query65.tpl 0.71 */ - s_store_name, - i_item_desc, - sc.revenue, - i_current_price, - i_wholesale_cost, - i_brand - from store, item, - (select ss_store_sk, avg(revenue) as ave - from - (select ss_store_sk, ss_item_sk, - sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1182 and 1182+11 - group by ss_store_sk, ss_item_sk) sa - group by ss_store_sk) sb, - (select ss_store_sk, ss_item_sk, sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1182 and 1182+11 - group by ss_store_sk, ss_item_sk) sc - where sb.ss_store_sk = sc.ss_store_sk and - sc.revenue <= 0.1 * sb.ave and - s_store_sk = sc.ss_store_sk and - i_item_sk = sc.ss_item_sk - order by s_store_name, i_item_desc -limit 100; - --- end template query65.tpl query 55 in stream 10 --- start template query23.tpl query 56 in stream 10 -with /* TPC-DS query23.tpl 0.68 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (2000,2000+1,2000+2,2000+3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (2000,2000+1,2000+2,2000+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * -from - max_store_sales)) - select sum(sales) - from (select cs_quantity*cs_list_price sales - from catalog_sales - ,date_dim - where d_year = 2000 - and d_moy = 4 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - union all - select ws_quantity*ws_list_price sales - from web_sales - ,date_dim - where d_year = 2000 - and d_moy = 4 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer)) - limit 100; -with /* TPC-DS query23.tpl 0.68 part2 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (2000,2000 + 1,2000 + 2,2000 + 3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (2000,2000+1,2000+2,2000+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * - from max_store_sales)) - select c_last_name,c_first_name,sales - from (select c_last_name,c_first_name,sum(cs_quantity*cs_list_price) sales - from catalog_sales - ,customer - ,date_dim - where d_year = 2000 - and d_moy = 4 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and cs_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name - union all - select c_last_name,c_first_name,sum(ws_quantity*ws_list_price) sales - from web_sales - ,customer - ,date_dim - where d_year = 2000 - and d_moy = 4 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and ws_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name) - order by c_last_name,c_first_name,sales - limit 100; - --- end template query23.tpl query 56 in stream 10 --- start template query90.tpl query 57 in stream 10 -select /* TPC-DS query90.tpl 0.40 */ cast(amc as decimal(15,4))/cast(pmc as decimal(15,4)) am_pm_ratio - from ( select count(*) amc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 10 and 10+1 - and household_demographics.hd_dep_count = 6 - and web_page.wp_char_count between 5000 and 5200) at, - ( select count(*) pmc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 13 and 13+1 - and household_demographics.hd_dep_count = 6 - and web_page.wp_char_count between 5000 and 5200) pt - order by am_pm_ratio - limit 100; - --- end template query90.tpl query 57 in stream 10 --- start template query88.tpl query 58 in stream 10 -select /* TPC-DS query88.tpl 0.66 */ * -from - (select count(*) h8_30_to_9 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s1, - (select count(*) h9_to_9_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s2, - (select count(*) h9_30_to_10 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s3, - (select count(*) h10_to_10_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s4, - (select count(*) h10_30_to_11 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s5, - (select count(*) h11_to_11_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s6, - (select count(*) h11_30_to_12 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s7, - (select count(*) h12_to_12_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 12 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s8 -; - --- end template query88.tpl query 58 in stream 10 --- start template query99.tpl query 59 in stream 10 -select /* TPC-DS query99.tpl 0.94 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 30) and - (cs_ship_date_sk - cs_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 60) and - (cs_ship_date_sk - cs_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 90) and - (cs_ship_date_sk - cs_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - catalog_sales - ,warehouse - ,ship_mode - ,call_center - ,date_dim -where - d_month_seq between 1201 and 1201 + 11 -and cs_ship_date_sk = d_date_sk -and cs_warehouse_sk = w_warehouse_sk -and cs_ship_mode_sk = sm_ship_mode_sk -and cs_call_center_sk = cc_call_center_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -limit 100; - --- end template query99.tpl query 59 in stream 10 --- start template query35a.tpl query 60 in stream 10 -select /* TPC-DS query35a.tpl 0.47 */ - ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - count(*) cnt1, - stddev_samp(cd_dep_count), - max(cd_dep_count), - max(cd_dep_count), - cd_dep_employed_count, - count(*) cnt2, - stddev_samp(cd_dep_employed_count), - max(cd_dep_employed_count), - max(cd_dep_employed_count), - cd_dep_college_count, - count(*) cnt3, - stddev_samp(cd_dep_college_count), - max(cd_dep_college_count), - max(cd_dep_college_count) - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2002 and - d_qoy < 4) and - exists (select * from - (select ws_bill_customer_sk customsk - from web_sales,date_dim - where - ws_sold_date_sk = d_date_sk and - d_year = 2002 and - d_qoy < 4 - union all - select cs_ship_customer_sk customsk - from catalog_sales,date_dim - where - cs_sold_date_sk = d_date_sk and - d_year = 2002 and - d_qoy < 4)x - where x.customsk = c.c_customer_sk) - group by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - limit 100; - --- end template query35a.tpl query 60 in stream 10 --- start template query10.tpl query 61 in stream 10 -select /* TPC-DS query10.tpl 0.26 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3, - cd_dep_count, - count(*) cnt4, - cd_dep_employed_count, - count(*) cnt5, - cd_dep_college_count, - count(*) cnt6 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_county in ('San Patricio County','Suffolk County','Charlottesville city','Appanoose County','Hancock County') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2001 and - d_moy between 3 and 3+3) and - (exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2001 and - d_moy between 3 ANd 3+3) or - exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2001 and - d_moy between 3 and 3+3)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count -limit 100; - --- end template query10.tpl query 61 in stream 10 --- start template query16.tpl query 62 in stream 10 -select /* TPC-DS query16.tpl 0.25 */ - count(distinct cs_order_number) as "order count" - ,sum(cs_ext_ship_cost) as "total shipping cost" - ,sum(cs_net_profit) as "total net profit" -from - catalog_sales cs1 - ,date_dim - ,customer_address - ,call_center -where - d_date between '2001-3-01' and - dateadd(day, 60, cast('2001-3-01' as date)) -and cs1.cs_ship_date_sk = d_date_sk -and cs1.cs_ship_addr_sk = ca_address_sk -and ca_state = 'AK' -and cs1.cs_call_center_sk = cc_call_center_sk -and cc_county in ('Richland County','Perry County','Daviess County','Walker County', - 'Marshall County' -) -and exists (select * - from catalog_sales cs2 - where cs1.cs_order_number = cs2.cs_order_number - and cs1.cs_warehouse_sk <> cs2.cs_warehouse_sk) -and not exists(select * - from catalog_returns cr1 - where cs1.cs_order_number = cr1.cr_order_number) -order by count(distinct cs_order_number) -limit 100; - --- end template query16.tpl query 62 in stream 10 --- start template query5a.tpl query 63 in stream 10 -with /* TPC-DS query5a.tpl 0.98 */ ssr as - (select s_store_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ss_store_sk as store_sk, - ss_sold_date_sk as date_sk, - ss_ext_sales_price as sales_price, - ss_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from store_sales - union all - select sr_store_sk as store_sk, - sr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - sr_return_amt as return_amt, - sr_net_loss as net_loss - from store_returns - ) salesreturns, - date_dim, - store - where date_sk = d_date_sk - and d_date between cast('1999-08-13' as date) - and dateadd(day,14,cast('1999-08-13' as date)) - and store_sk = s_store_sk - group by s_store_id) - , - csr as - (select cp_catalog_page_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select cs_catalog_page_sk as page_sk, - cs_sold_date_sk as date_sk, - cs_ext_sales_price as sales_price, - cs_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from catalog_sales - union all - select cr_catalog_page_sk as page_sk, - cr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - cr_return_amount as return_amt, - cr_net_loss as net_loss - from catalog_returns - ) salesreturns, - date_dim, - catalog_page - where date_sk = d_date_sk - and d_date between cast('1999-08-13' as date) - and dateadd(day,14,cast('1999-08-13' as date)) - and page_sk = cp_catalog_page_sk - group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ws_web_site_sk as wsr_web_site_sk, - ws_sold_date_sk as date_sk, - ws_ext_sales_price as sales_price, - ws_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from web_sales - union all - select ws_web_site_sk as wsr_web_site_sk, - wr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - wr_return_amt as return_amt, - wr_net_loss as net_loss - from web_returns left outer join web_sales on - ( wr_item_sk = ws_item_sk - and wr_order_number = ws_order_number) - ) salesreturns, - date_dim, - web_site - where date_sk = d_date_sk - and d_date between cast('1999-08-13' as date) - and dateadd(day,14,cast('1999-08-13' as date)) - and wsr_web_site_sk = web_site_sk - group by web_site_id) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || s_store_id as id - , sales - , returns - , (profit - profit_loss) as profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || cp_catalog_page_id as id - , sales - , returns - , (profit - profit_loss) as profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , (profit - profit_loss) as profit - from wsr - ) x - group by channel, id) - select channel, id, sales, returns, profit from ( - select channel, id, sales, returns, profit from results - union - select channel, null as id, sum(sales), sum(returns), sum(profit) from results group by channel - union - select null as channel, null as id, sum(sales), sum(returns), sum(profit) from results) foo -order by channel, id -limit 100; - --- end template query5a.tpl query 63 in stream 10 --- start template query57.tpl query 64 in stream 10 -with /* TPC-DS query57.tpl 0.70 */ v1 as( - select i_category, i_brand, - cc_name, - d_year, d_moy, - sum(cs_sales_price) sum_sales, - avg(sum(cs_sales_price)) over - (partition by i_category, i_brand, - cc_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - cc_name - order by d_year, d_moy) rn - from item, catalog_sales, date_dim, call_center - where cs_item_sk = i_item_sk and - cs_sold_date_sk = d_date_sk and - cc_call_center_sk= cs_call_center_sk and - ( - d_year = 1999 or - ( d_year = 1999-1 and d_moy =12) or - ( d_year = 1999+1 and d_moy =1) - ) - group by i_category, i_brand, - cc_name , d_year, d_moy), - v2 as( - select v1.i_category, v1.i_brand - ,v1.d_year - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1. cc_name = v1_lag. cc_name and - v1. cc_name = v1_lead. cc_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 1999 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, psum - limit 100; - --- end template query57.tpl query 64 in stream 10 --- start template query34.tpl query 65 in stream 10 -select /* TPC-DS query34.tpl 0.73 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (date_dim.d_dom between 1 and 3 or date_dim.d_dom between 25 and 28) - and (household_demographics.hd_buy_potential = '1001-5000' or - household_demographics.hd_buy_potential = 'Unknown') - and household_demographics.hd_vehicle_count > 0 - and (case when household_demographics.hd_vehicle_count > 0 - then household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count - else null - end) > 1.2 - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_county in ('Green Lake County','Terry County','Walker County','Porter County', - 'Musselshell County','Morgan County','Fergus County','Cook County') - group by ss_ticket_number,ss_customer_sk) dn,customer - where ss_customer_sk = c_customer_sk - and cnt between 15 and 20 - order by c_last_name,c_first_name,c_salutation,c_preferred_cust_flag desc, ss_ticket_number; - --- end template query34.tpl query 65 in stream 10 --- start template query97.tpl query 66 in stream 10 -with /* TPC-DS query97.tpl 0.38 */ ssci as ( -select ss_customer_sk customer_sk - ,ss_item_sk item_sk -from store_sales,date_dim -where ss_sold_date_sk = d_date_sk - and d_month_seq between 1202 and 1202 + 11 -group by ss_customer_sk - ,ss_item_sk), -csci as( - select cs_bill_customer_sk customer_sk - ,cs_item_sk item_sk -from catalog_sales,date_dim -where cs_sold_date_sk = d_date_sk - and d_month_seq between 1202 and 1202 + 11 -group by cs_bill_customer_sk - ,cs_item_sk) - select sum(case when ssci.customer_sk is not null and csci.customer_sk is null then 1 else 0 end) store_only - ,sum(case when ssci.customer_sk is null and csci.customer_sk is not null then 1 else 0 end) catalog_only - ,sum(case when ssci.customer_sk is not null and csci.customer_sk is not null then 1 else 0 end) store_and_catalog -from ssci full outer join csci on (ssci.customer_sk=csci.customer_sk - and ssci.item_sk = csci.item_sk) -limit 100; - --- end template query97.tpl query 66 in stream 10 --- start template query72.tpl query 67 in stream 10 -select /* TPC-DS query72.tpl 0.87 */ i_item_desc - ,w_warehouse_name - ,d1.d_week_seq - ,sum(case when p_promo_sk is null then 1 else 0 end) no_promo - ,sum(case when p_promo_sk is not null then 1 else 0 end) promo - ,count(*) total_cnt -from catalog_sales -join inventory on (cs_item_sk = inv_item_sk) -join warehouse on (w_warehouse_sk=inv_warehouse_sk) -join item on (i_item_sk = cs_item_sk) -join customer_demographics on (cs_bill_cdemo_sk = cd_demo_sk) -join household_demographics on (cs_bill_hdemo_sk = hd_demo_sk) -join date_dim d1 on (cs_sold_date_sk = d1.d_date_sk) -join date_dim d2 on (inv_date_sk = d2.d_date_sk) -join date_dim d3 on (cs_ship_date_sk = d3.d_date_sk) -left outer join promotion on (cs_promo_sk=p_promo_sk) -left outer join catalog_returns on (cr_item_sk = cs_item_sk and cr_order_number = cs_order_number) -where d1.d_week_seq = d2.d_week_seq - and inv_quantity_on_hand < cs_quantity - and d3.d_date > d1.d_date + 5 - and hd_buy_potential = '1001-5000' - and d1.d_year = 1998 - and cd_marital_status = 'M' -group by i_item_desc,w_warehouse_name,d1.d_week_seq -order by total_cnt desc, i_item_desc, w_warehouse_name, d_week_seq -limit 100; - --- end template query72.tpl query 67 in stream 10 --- start template query75.tpl query 68 in stream 10 -WITH /* TPC-DS query75.tpl 0.3 */ all_sales AS ( - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,SUM(sales_cnt) AS sales_cnt - ,SUM(sales_amt) AS sales_amt - FROM (SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,cs_quantity - COALESCE(cr_return_quantity,0) AS sales_cnt - ,cs_ext_sales_price - COALESCE(cr_return_amount,0.0) AS sales_amt - FROM catalog_sales JOIN item ON i_item_sk=cs_item_sk - JOIN date_dim ON d_date_sk=cs_sold_date_sk - LEFT JOIN catalog_returns ON (cs_order_number=cr_order_number - AND cs_item_sk=cr_item_sk) - WHERE i_category='Women' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ss_quantity - COALESCE(sr_return_quantity,0) AS sales_cnt - ,ss_ext_sales_price - COALESCE(sr_return_amt,0.0) AS sales_amt - FROM store_sales JOIN item ON i_item_sk=ss_item_sk - JOIN date_dim ON d_date_sk=ss_sold_date_sk - LEFT JOIN store_returns ON (ss_ticket_number=sr_ticket_number - AND ss_item_sk=sr_item_sk) - WHERE i_category='Women' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ws_quantity - COALESCE(wr_return_quantity,0) AS sales_cnt - ,ws_ext_sales_price - COALESCE(wr_return_amt,0.0) AS sales_amt - FROM web_sales JOIN item ON i_item_sk=ws_item_sk - JOIN date_dim ON d_date_sk=ws_sold_date_sk - LEFT JOIN web_returns ON (ws_order_number=wr_order_number - AND ws_item_sk=wr_item_sk) - WHERE i_category='Women') sales_detail - GROUP BY d_year, i_brand_id, i_class_id, i_category_id, i_manufact_id) - SELECT prev_yr.d_year AS prev_year - ,curr_yr.d_year AS year - ,curr_yr.i_brand_id - ,curr_yr.i_class_id - ,curr_yr.i_category_id - ,curr_yr.i_manufact_id - ,prev_yr.sales_cnt AS prev_yr_cnt - ,curr_yr.sales_cnt AS curr_yr_cnt - ,curr_yr.sales_cnt-prev_yr.sales_cnt AS sales_cnt_diff - ,curr_yr.sales_amt-prev_yr.sales_amt AS sales_amt_diff - FROM all_sales curr_yr, all_sales prev_yr - WHERE curr_yr.i_brand_id=prev_yr.i_brand_id - AND curr_yr.i_class_id=prev_yr.i_class_id - AND curr_yr.i_category_id=prev_yr.i_category_id - AND curr_yr.i_manufact_id=prev_yr.i_manufact_id - AND curr_yr.d_year=1999 - AND prev_yr.d_year=1999-1 - AND CAST(curr_yr.sales_cnt AS DECIMAL(17,2))/CAST(prev_yr.sales_cnt AS DECIMAL(17,2))<0.9 - ORDER BY sales_cnt_diff,sales_amt_diff - limit 100; - --- end template query75.tpl query 68 in stream 10 --- start template query14a.tpl query 69 in stream 10 -with /* TPC-DS query14a.tpl 0.69 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1998 AND 1998 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1998 AND 1998 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1998 AND 1998 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as - (select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2) x) -, - results AS -(select channel, i_brand_id, i_class_id, i_category_id, sum(sales) sum_sales, sum(number_sales) number_sales - from ( - select 'store' channel, i_brand_id,i_class_id - ,i_category_id,sum(ss_quantity*ss_list_price) sales - , count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1998+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales) - union all - select 'catalog' channel, i_brand_id,i_class_id,i_category_id, sum(cs_quantity*cs_list_price) sales, count(*) number_sales - from catalog_sales - ,item - ,date_dim - where cs_item_sk in (select ss_item_sk from cross_items) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1998+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(cs_quantity*cs_list_price) > (select average_sales from avg_sales) - union all - select 'web' channel, i_brand_id,i_class_id,i_category_id, sum(ws_quantity*ws_list_price) sales , count(*) number_sales - from web_sales - ,item - ,date_dim - where ws_item_sk in (select ss_item_sk from cross_items) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1998+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ws_quantity*ws_list_price) > (select average_sales from avg_sales) - ) y - group by channel, i_brand_id,i_class_id,i_category_id) - - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales -from ( - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales from results - union - select channel, i_brand_id, i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id, i_class_id - union - select channel, i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id - union - select channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel - union - select null as channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results) z -order by channel, i_brand_id, i_class_id, i_category_id - limit 100; -with /* TPC-DS query14a.tpl 0.69 part2 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1998 AND 1998 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1998 AND 1998 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1998 AND 1998 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as -(select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2) x) - select this_year.channel ty_channel - ,this_year.i_brand_id ty_brand - ,this_year.i_class_id ty_class - ,this_year.i_category_id ty_category - ,this_year.sales ty_sales - ,this_year.number_sales ty_number_sales - ,last_year.channel ly_channel - ,last_year.i_brand_id ly_brand - ,last_year.i_class_id ly_class - ,last_year.i_category_id ly_category - ,last_year.sales ly_sales - ,last_year.number_sales ly_number_sales -from - (select 'store' channel, i_brand_id,i_class_id,i_category_id - ,sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1998 + 1 - and d_moy = 12 - and d_dom = 10) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) this_year, - (select 'store' channel, i_brand_id,i_class_id - ,i_category_id, sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1998 - and d_moy = 12 - and d_dom = 10) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) last_year - where this_year.i_brand_id= last_year.i_brand_id - and this_year.i_class_id = last_year.i_class_id - and this_year.i_category_id = last_year.i_category_id - order by this_year.channel, this_year.i_brand_id, this_year.i_class_id, this_year.i_category_id - limit 100; - --- end template query14a.tpl query 69 in stream 10 --- start template query40.tpl query 70 in stream 10 -select /* TPC-DS query40.tpl 0.86 */ - w_state - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('1998-03-28' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_before - ,sum(case when (cast(d_date as date) >= cast ('1998-03-28' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_after - from - catalog_sales left outer join catalog_returns on - (cs_order_number = cr_order_number - and cs_item_sk = cr_item_sk) - ,warehouse - ,item - ,date_dim - where - i_current_price between 0.99 and 1.49 - and i_item_sk = cs_item_sk - and cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('1998-03-28' as date)) - and dateadd(day,30,cast ('1998-03-28' as date)) - group by - w_state,i_item_id - order by w_state,i_item_id -limit 100; - --- end template query40.tpl query 70 in stream 10 --- start template query73.tpl query 71 in stream 10 -select /* TPC-DS query73.tpl 0.79 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_buy_potential = '>10000' or - household_demographics.hd_buy_potential = '5001-10000') - and household_demographics.hd_vehicle_count > 0 - and case when household_demographics.hd_vehicle_count > 0 then - household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count else null end > 1 - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_county in ('Reagan County','LaMoure County','Pickens County','Daviess County') - group by ss_ticket_number,ss_customer_sk) dj,customer - where ss_customer_sk = c_customer_sk - and cnt between 1 and 5 - order by cnt desc, c_last_name asc; - --- end template query73.tpl query 71 in stream 10 --- start template query79.tpl query 72 in stream 10 -select /* TPC-DS query79.tpl 0.89 */ - c_last_name,c_first_name,substring(s_city,1,30),ss_ticket_number,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,store.s_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (household_demographics.hd_dep_count = 3 or household_demographics.hd_vehicle_count > -1) - and date_dim.d_dow = 1 - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_number_employees between 200 and 295 - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,store.s_city) ms,customer - where ss_customer_sk = c_customer_sk - order by c_last_name,c_first_name,substring(s_city,1,30), profit -limit 100; - --- end template query79.tpl query 72 in stream 10 --- start template query11.tpl query 73 in stream 10 -with /* TPC-DS query11.tpl 0.51 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ss_ext_list_price-ss_ext_discount_amt) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ws_ext_list_price-ws_ext_discount_amt) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_email_address - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 2001 - and t_s_secyear.dyear = 2001+1 - and t_w_firstyear.dyear = 2001 - and t_w_secyear.dyear = 2001+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else 0.0 end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else 0.0 end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_email_address -limit 100; - --- end template query11.tpl query 73 in stream 10 --- start template query6.tpl query 74 in stream 10 -select /* TPC-DS query6.tpl 0.58 */ a.ca_state state, count(*) cnt - from customer_address a - ,customer c - ,store_sales s - ,date_dim d - ,item i - where a.ca_address_sk = c.c_current_addr_sk - and c.c_customer_sk = s.ss_customer_sk - and s.ss_sold_date_sk = d.d_date_sk - and s.ss_item_sk = i.i_item_sk - and d.d_month_seq = - (select distinct (d_month_seq) - from date_dim - where d_year = 2001 - and d_moy = 6 ) - and i.i_current_price > 1.2 * - (select avg(j.i_current_price) - from item j - where j.i_category = i.i_category) - group by a.ca_state - having count(*) >= 10 - order by cnt, a.ca_state - limit 100; - --- end template query6.tpl query 74 in stream 10 --- start template query17.tpl query 75 in stream 10 -select /* TPC-DS query17.tpl 0.41 */ i_item_id - ,i_item_desc - ,s_state - ,count(ss_quantity) as store_sales_quantitycount - ,avg(ss_quantity) as store_sales_quantityave - ,stddev_samp(ss_quantity) as store_sales_quantitystdev - ,stddev_samp(ss_quantity)/avg(ss_quantity) as store_sales_quantitycov - ,count(sr_return_quantity) as store_returns_quantitycount - ,avg(sr_return_quantity) as store_returns_quantityave - ,stddev_samp(sr_return_quantity) as store_returns_quantitystdev - ,stddev_samp(sr_return_quantity)/avg(sr_return_quantity) as store_returns_quantitycov - ,count(cs_quantity) as catalog_sales_quantitycount ,avg(cs_quantity) as catalog_sales_quantityave - ,stddev_samp(cs_quantity) as catalog_sales_quantitystdev - ,stddev_samp(cs_quantity)/avg(cs_quantity) as catalog_sales_quantitycov - from store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where d1.d_quarter_name = '2001Q1' - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_quarter_name in ('2001Q1','2001Q2','2001Q3') - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_quarter_name in ('2001Q1','2001Q2','2001Q3') - group by i_item_id - ,i_item_desc - ,s_state - order by i_item_id - ,i_item_desc - ,s_state -limit 100; - --- end template query17.tpl query 75 in stream 10 --- start template query58.tpl query 76 in stream 10 -with /* TPC-DS query58.tpl 0.19 */ ss_items as - (select i_item_id item_id - ,sum(ss_ext_sales_price) ss_item_rev - from store_sales - ,item - ,date_dim - where ss_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '2002-05-06')) - and ss_sold_date_sk = d_date_sk - group by i_item_id), - cs_items as - (select i_item_id item_id - ,sum(cs_ext_sales_price) cs_item_rev - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '2002-05-06')) - and cs_sold_date_sk = d_date_sk - group by i_item_id), - ws_items as - (select i_item_id item_id - ,sum(ws_ext_sales_price) ws_item_rev - from web_sales - ,item - ,date_dim - where ws_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq =(select d_week_seq - from date_dim - where d_date = '2002-05-06')) - and ws_sold_date_sk = d_date_sk - group by i_item_id) - select ss_items.item_id - ,ss_item_rev - ,ss_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ss_dev - ,cs_item_rev - ,cs_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 cs_dev - ,ws_item_rev - ,ws_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ws_dev - ,(ss_item_rev+cs_item_rev+ws_item_rev)/3 average - from ss_items,cs_items,ws_items - where ss_items.item_id=cs_items.item_id - and ss_items.item_id=ws_items.item_id - and ss_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - and ss_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and cs_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and cs_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and ws_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and ws_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - order by item_id - ,ss_item_rev - limit 100; - --- end template query58.tpl query 76 in stream 10 --- start template query56.tpl query 77 in stream 10 -with /* TPC-DS query56.tpl 0.83 */ ss as ( - select i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where i_item_id in (select - i_item_id -from item -where i_color in ('brown','snow','mint')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 4 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id), - cs as ( - select i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('brown','snow','mint')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 4 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id), - ws as ( - select i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('brown','snow','mint')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 4 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id) - select i_item_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by total_sales, - i_item_id - limit 100; - --- end template query56.tpl query 77 in stream 10 --- start template query83.tpl query 78 in stream 10 -with /* TPC-DS query83.tpl 0.96 */ sr_items as - (select i_item_id item_id, - sum(sr_return_quantity) sr_item_qty - from store_returns, - item, - date_dim - where sr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('1999-02-16','1999-08-04','1999-11-22'))) - and sr_returned_date_sk = d_date_sk - group by i_item_id), - cr_items as - (select i_item_id item_id, - sum(cr_return_quantity) cr_item_qty - from catalog_returns, - item, - date_dim - where cr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('1999-02-16','1999-08-04','1999-11-22'))) - and cr_returned_date_sk = d_date_sk - group by i_item_id), - wr_items as - (select i_item_id item_id, - sum(wr_return_quantity) wr_item_qty - from web_returns, - item, - date_dim - where wr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('1999-02-16','1999-08-04','1999-11-22'))) - and wr_returned_date_sk = d_date_sk - group by i_item_id) - select sr_items.item_id - ,sr_item_qty - ,sr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 sr_dev - ,cr_item_qty - ,cr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 cr_dev - ,wr_item_qty - ,wr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 wr_dev - ,(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 average - from sr_items - ,cr_items - ,wr_items - where sr_items.item_id=cr_items.item_id - and sr_items.item_id=wr_items.item_id - order by sr_items.item_id - ,sr_item_qty - limit 100; - --- end template query83.tpl query 78 in stream 10 --- start template query51.tpl query 79 in stream 10 -WITH /* TPC-DS query51.tpl 0.46 */ web_v1 as ( -select - ws_item_sk item_sk, d_date, - sum(sum(ws_sales_price)) - over (partition by ws_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from web_sales - ,date_dim -where ws_sold_date_sk=d_date_sk - and d_month_seq between 1195 and 1195+11 - and ws_item_sk is not NULL -group by ws_item_sk, d_date), -store_v1 as ( -select - ss_item_sk item_sk, d_date, - sum(sum(ss_sales_price)) - over (partition by ss_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from store_sales - ,date_dim -where ss_sold_date_sk=d_date_sk - and d_month_seq between 1195 and 1195+11 - and ss_item_sk is not NULL -group by ss_item_sk, d_date) - select * -from (select item_sk - ,d_date - ,web_sales - ,store_sales - ,max(web_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) web_cumulative - ,max(store_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) store_cumulative - from (select case when web.item_sk is not null then web.item_sk else store.item_sk end item_sk - ,case when web.d_date is not null then web.d_date else store.d_date end d_date - ,web.cume_sales web_sales - ,store.cume_sales store_sales - from web_v1 web full outer join store_v1 store on (web.item_sk = store.item_sk - and web.d_date = store.d_date) - )x )y -where web_cumulative > store_cumulative -order by item_sk - ,d_date -limit 100; - --- end template query51.tpl query 79 in stream 10 --- start template query29.tpl query 80 in stream 10 -select /* TPC-DS query29.tpl 0.53 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,sum(ss_quantity) as store_sales_quantity - ,sum(sr_return_quantity) as store_returns_quantity - ,sum(cs_quantity) as catalog_sales_quantity - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 1999 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 4 + 3 - and d2.d_year = 1999 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_year in (1999,1999+1,1999+2) - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query29.tpl query 80 in stream 10 --- start template query22a.tpl query 81 in stream 10 -with /* TPC-DS query22a.tpl 0.55 */ results as -(select i_product_name - ,i_brand - ,i_class - ,i_category - ,avg(inv_quantity_on_hand) qoh - from inventory - ,date_dim - ,item --- ,warehouse - where inv_date_sk=d_date_sk - and inv_item_sk=i_item_sk --- and inv_warehouse_sk = w_warehouse_sk - and d_month_seq between 1201 and 1201 + 11 - group by i_product_name,i_brand,i_class,i_category), -results_rollup as -(select i_product_name, i_brand, i_class, i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class,i_category -union all -select i_product_name, i_brand, i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class -union all -select i_product_name, i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand -union all -select i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name -union all -select null i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results) - select i_product_name, i_brand, i_class, i_category,qoh - from results_rollup - order by qoh, i_product_name, i_brand, i_class, i_category -limit 100; - --- end template query22a.tpl query 81 in stream 10 --- start template query71.tpl query 82 in stream 10 -select /* TPC-DS query71.tpl 0.72 */ i_brand_id brand_id, i_brand brand,t_hour,t_minute, - sum(ext_price) ext_price - from item, (select ws_ext_sales_price as ext_price, - ws_sold_date_sk as sold_date_sk, - ws_item_sk as sold_item_sk, - ws_sold_time_sk as time_sk - from web_sales,date_dim - where d_date_sk = ws_sold_date_sk - and d_moy=12 - and d_year=2000 - union all - select cs_ext_sales_price as ext_price, - cs_sold_date_sk as sold_date_sk, - cs_item_sk as sold_item_sk, - cs_sold_time_sk as time_sk - from catalog_sales,date_dim - where d_date_sk = cs_sold_date_sk - and d_moy=12 - and d_year=2000 - union all - select ss_ext_sales_price as ext_price, - ss_sold_date_sk as sold_date_sk, - ss_item_sk as sold_item_sk, - ss_sold_time_sk as time_sk - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - and d_moy=12 - and d_year=2000 - ) tmp,time_dim - where - sold_item_sk = i_item_sk - and i_manager_id=1 - and time_sk = t_time_sk - and (t_meal_time = 'breakfast' or t_meal_time = 'dinner') - group by i_brand, i_brand_id,t_hour,t_minute - order by ext_price desc, i_brand_id - ; - --- end template query71.tpl query 82 in stream 10 --- start template query68.tpl query 83 in stream 10 -select /* TPC-DS query68.tpl 0.95 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,extended_price - ,extended_tax - ,list_price - from (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_ext_sales_price) extended_price - ,sum(ss_ext_list_price) list_price - ,sum(ss_ext_tax) extended_tax - from store_sales - ,date_dim - ,store - ,household_demographics - ,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_dep_count = 6 or - household_demographics.hd_vehicle_count= 4) - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_city in ('Helena','Midland') - group by ss_ticket_number - ,ss_customer_sk - ,ss_addr_sk,ca_city) dn - ,customer - ,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,ss_ticket_number - limit 100; - --- end template query68.tpl query 83 in stream 10 --- start template query60.tpl query 84 in stream 10 -with /* TPC-DS query60.tpl 0.29 */ ss as ( - select - i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Shoes')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 8 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id), - cs as ( - select - i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Shoes')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 8 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id), - ws as ( - select - i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Shoes')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 8 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id) - select - i_item_id -,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by i_item_id - ,total_sales - limit 100; - --- end template query60.tpl query 84 in stream 10 --- start template query12.tpl query 85 in stream 10 -select /* TPC-DS query12.tpl 0.64 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ws_ext_sales_price) as itemrevenue - ,sum(ws_ext_sales_price)*100/sum(sum(ws_ext_sales_price)) over - (partition by i_class) as revenueratio -from - web_sales - ,item - ,date_dim -where - ws_item_sk = i_item_sk - and i_category in ('Shoes', 'Books', 'Children') - and ws_sold_date_sk = d_date_sk - and d_date between cast('2002-04-23' as date) - and dateadd(day,30,cast('2002-04-23' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query12.tpl query 85 in stream 10 --- start template query4.tpl query 86 in stream 10 -with /* TPC-DS query4.tpl 0.93 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(((ss_ext_list_price-ss_ext_wholesale_cost-ss_ext_discount_amt)+ss_ext_sales_price)/2) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((cs_ext_list_price-cs_ext_wholesale_cost-cs_ext_discount_amt)+cs_ext_sales_price)/2) ) year_total - ,'c' sale_type - from customer - ,catalog_sales - ,date_dim - where c_customer_sk = cs_bill_customer_sk - and cs_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year -union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((ws_ext_list_price-ws_ext_wholesale_cost-ws_ext_discount_amt)+ws_ext_sales_price)/2) ) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_email_address - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_c_firstyear - ,year_total t_c_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_c_secyear.customer_id - and t_s_firstyear.customer_id = t_c_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_c_firstyear.sale_type = 'c' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_c_secyear.sale_type = 'c' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 2001 - and t_s_secyear.dyear = 2001+1 - and t_c_firstyear.dyear = 2001 - and t_c_secyear.dyear = 2001+1 - and t_w_firstyear.dyear = 2001 - and t_w_secyear.dyear = 2001+1 - and t_s_firstyear.year_total > 0 - and t_c_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_email_address -limit 100; - --- end template query4.tpl query 86 in stream 10 --- start template query89.tpl query 87 in stream 10 -select /* TPC-DS query89.tpl 0.56 */ * -from( -select i_category, i_class, i_brand, - s_store_name, s_company_name, - d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, s_store_name, s_company_name) - avg_monthly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - d_year in (1998) and - ((i_category in ('Women','Music','Electronics') and - i_class in ('dresses','country','dvd/vcr players') - ) - or (i_category in ('Men','Children','Books') and - i_class in ('shirts','toddlers','business') - )) -group by i_category, i_class, i_brand, - s_store_name, s_company_name, d_moy) tmp1 -where case when (avg_monthly_sales <> 0) then (abs(sum_sales - avg_monthly_sales) / avg_monthly_sales) else null end > 0.1 -order by sum_sales - avg_monthly_sales, s_store_name -limit 100; - --- end template query89.tpl query 87 in stream 10 --- start template query61.tpl query 88 in stream 10 -select /* TPC-DS query61.tpl 0.97 */ promotions,total,cast(promotions as decimal(16,4))/cast(total as decimal(16,4))*100 -from - (select sum(ss_ext_sales_price) promotions - from store_sales - ,store - ,promotion - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_promo_sk = p_promo_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -7 - and i_category = 'Sports' - and (p_channel_dmail = 'Y' or p_channel_email = 'Y' or p_channel_tv = 'Y') - and s_gmt_offset = -7 - and d_year = 2000 - and d_moy = 12) promotional_sales, - (select sum(ss_ext_sales_price) total - from store_sales - ,store - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -7 - and i_category = 'Sports' - and s_gmt_offset = -7 - and d_year = 2000 - and d_moy = 12) all_sales -order by promotions, total -limit 100; - --- end template query61.tpl query 88 in stream 10 --- start template query46.tpl query 89 in stream 10 -select /* TPC-DS query46.tpl 0.23 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and (household_demographics.hd_dep_count = 8 or - household_demographics.hd_vehicle_count= 0) - and date_dim.d_dow in (6,0) - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_city in ('Hilltop','Paradise','Stony Point','Evergreen','Fairmount') - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,ca_city) dn,customer,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - limit 100; - --- end template query46.tpl query 89 in stream 10 --- start template query92.tpl query 90 in stream 10 -select /* TPC-DS query92.tpl 0.44 */ - sum(ws_ext_discount_amt) as "Excess Discount Amount" -from - web_sales - ,item - ,date_dim -where -i_manufact_id = 911 -and i_item_sk = ws_item_sk -and d_date between '1999-01-08' and - dateadd(day,90,cast('1999-01-08' as date)) -and d_date_sk = ws_sold_date_sk -and ws_ext_discount_amt - > ( - SELECT - 1.3 * avg(ws_ext_discount_amt) - FROM - web_sales - ,date_dim - WHERE - ws_item_sk = i_item_sk - and d_date between '1999-01-08' and - dateadd(day,90,cast('1999-01-08' as date)) - and d_date_sk = ws_sold_date_sk - ) -order by sum(ws_ext_discount_amt) -limit 100; - --- end template query92.tpl query 90 in stream 10 --- start template query13.tpl query 91 in stream 10 -select /* TPC-DS query13.tpl 0.91 */ avg(ss_quantity) - ,avg(ss_ext_sales_price) - ,avg(ss_ext_wholesale_cost) - ,sum(ss_ext_wholesale_cost) - from store_sales - ,store - ,customer_demographics - ,household_demographics - ,customer_address - ,date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2001 - and((ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'D' - and cd_education_status = 'Unknown' - and ss_sales_price between 100.00 and 150.00 - and hd_dep_count = 3 - )or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'M' - and cd_education_status = 'Primary' - and ss_sales_price between 50.00 and 100.00 - and hd_dep_count = 1 - ) or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'W' - and cd_education_status = '2 yr Degree' - and ss_sales_price between 150.00 and 200.00 - and hd_dep_count = 1 - )) - and((ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('NC', 'IA', 'FL') - and ss_net_profit between 100 and 200 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('MN', 'KY', 'SC') - and ss_net_profit between 150 and 300 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('GA', 'AR', 'NH') - and ss_net_profit between 50 and 250 - )) -; - --- end template query13.tpl query 91 in stream 10 --- start template query9.tpl query 92 in stream 10 -select /* TPC-DS query9.tpl 0.49 */ case when (select count(*) - from store_sales - where ss_quantity between 1 and 20) > 1008104435 - then (select avg(ss_ext_list_price) - from store_sales - where ss_quantity between 1 and 20) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 1 and 20) end bucket1 , - case when (select count(*) - from store_sales - where ss_quantity between 21 and 40) > 616018151 - then (select avg(ss_ext_list_price) - from store_sales - where ss_quantity between 21 and 40) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 21 and 40) end bucket2, - case when (select count(*) - from store_sales - where ss_quantity between 41 and 60) > 2984570236 - then (select avg(ss_ext_list_price) - from store_sales - where ss_quantity between 41 and 60) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 41 and 60) end bucket3, - case when (select count(*) - from store_sales - where ss_quantity between 61 and 80) > 1407787133 - then (select avg(ss_ext_list_price) - from store_sales - where ss_quantity between 61 and 80) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 61 and 80) end bucket4, - case when (select count(*) - from store_sales - where ss_quantity between 81 and 100) > 768050028 - then (select avg(ss_ext_list_price) - from store_sales - where ss_quantity between 81 and 100) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 81 and 100) end bucket5 -from reason -where r_reason_sk = 1 -; - --- end template query9.tpl query 92 in stream 10 --- start template query74.tpl query 93 in stream 10 -with /* TPC-DS query74.tpl 0.76 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,sum(ss_net_paid) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1999,1999+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,sum(ws_net_paid) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - and d_year in (1999,1999+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - ) - select - t_s_secyear.customer_id, t_s_secyear.customer_first_name, t_s_secyear.customer_last_name - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.year = 1999 - and t_s_secyear.year = 1999+1 - and t_w_firstyear.year = 1999 - and t_w_secyear.year = 1999+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - order by 1,3,2 -limit 100; - --- end template query74.tpl query 93 in stream 10 --- start template query8.tpl query 94 in stream 10 -select /* TPC-DS query8.tpl 0.63 */ s_store_name - ,sum(ss_net_profit) - from store_sales - ,date_dim - ,store, - (select ca_zip - from ( - SELECT substring(ca_zip,1,5) ca_zip - FROM customer_address - WHERE substring(ca_zip,1,5) IN ( - '97987','16912','17287','34183','26603','98121', - '74530','93356','43297','48735','72241', - '56716','15993','63046','32099','82432', - '67279','32676','45754','44538','63619', - '63739','70145','85119','79727','91146', - '43603','67810','18876','71422','94804', - '69386','97072','81842','42490','43043', - '72204','91533','56212','19009','48323', - '18519','50353','75138','42911','10919', - '84960','56293','81765','86128','91010', - '26969','29396','10711','84113','41767', - '40604','64116','51029','68868','69796', - '98603','73458','74785','15862','37043', - '25427','27576','54941','20489','38996', - '46823','59104','29422','35248','85404', - '50977','28657','33237','12717','80950', - '54982','55725','58207','75809','63818', - '90808','41517','43905','50952','99759', - '61250','84760','18522','95109','18224', - '57530','40715','66089','30286','18058', - '12294','62960','83166','23572','82986', - '97951','27960','85750','80406','18498', - '10890','76814','67904','39129','62474', - '19068','87898','45086','55981','79210', - '60573','52003','29837','11288','18823', - '75750','21108','29321','35650','10493', - '11989','44643','17487','74988','86007', - '64084','98411','39329','26920','55567', - '80223','34408','30324','58563','84200', - '31814','33866','82061','53853','94782', - '57116','36515','11131','56759','56483', - '84358','98227','44292','14811','32551', - '85460','82393','63473','12746','76981', - '57679','94343','19062','30645','32330', - '41153','55587','13712','37999','42602', - '58926','23770','79339','14237','89834', - '56476','74387','61994','48998','32912', - '12570','18410','98334','46257','82077', - '63548','99349','12117','14139','74085', - '78062','87409','12962','34463','75454', - '79216','40872','38640','88668','79627', - '33824','78715','50044','64266','65731', - '27507','22028','12632','76730','85675', - '19870','67222','20387','14513','72909', - '62553','50995','16587','33942','86441', - '98995','27239','75786','52526','69097', - '20162','46346','86400','32325','36598', - '87645','11273','37908','71210','22844', - '45740','48780','33455','91807','83621', - '61094','45608','50639','60224','10807', - '35500','70319','87747','69724','50711', - '44254','91811','80124','18280','44617', - '43124','23595','53520','33862','55227', - '18942','61455','68732','15355','22399', - '53206','32839','52984','27452','14964', - '80412','84857','37726','86075','84063', - '55811','69428','63448','68348','55969', - '83052','95990','31006','42179','79876', - '91740','38376','53101','22160','51855', - '72872','89926','13746','66074','15319', - '82541','99338','75536','35649','45969', - '42233','67803','91339','50201','70979', - '31973','55817','79417','34445','32752', - '41966','18147','29146','12157','57471', - '27672','42219','60309','83786','42876', - '46892','83263','75361','33535','44296', - '51749','70731','39146','67612','83316', - '79603','57377','57663','86670','73947', - '26653','88290','70792','52845','35823', - '52021','62320','30612','62915','99160', - '10742','98219','62215','95681','52213', - '43592','98047','51207','32120','60331', - '92040','94328','69106','32001','67967', - '16014','92256','63218','45250','99490', - '18975','11240','53514','99536','89077', - '74228','86973','44201','43881','49688', - '92768','10903','70575','72652','57720', - '65250','73674','34722','36153','40983', - '57613','40103','29733','34690','29281', - '30798','34420','93978','28159') - intersect - select ca_zip - from (SELECT substring(ca_zip,1,5) ca_zip,count(*) cnt - FROM customer_address, customer - WHERE ca_address_sk = c_current_addr_sk and - c_preferred_cust_flag='Y' - group by ca_zip - having count(*) > 10)A1)A2) V1 - where ss_store_sk = s_store_sk - and ss_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 1999 - and (substring(s_zip,1,2) = substring(V1.ca_zip,1,2)) - group by s_store_name - order by s_store_name - limit 100; - --- end template query8.tpl query 94 in stream 10 --- start template query3.tpl query 95 in stream 10 -select /* TPC-DS query3.tpl 0.45 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_net_profit) sum_agg - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manufact_id = 615 - and dt.d_moy=11 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,sum_agg desc - ,brand_id - limit 100; - --- end template query3.tpl query 95 in stream 10 --- start template query95.tpl query 96 in stream 10 -with /* TPC-DS query95.tpl 0.43 */ ws_wh as -(select ws1.ws_order_number,ws1.ws_warehouse_sk wh1,ws2.ws_warehouse_sk wh2 - from web_sales ws1,web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) - select - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2000-4-01' and - dateadd(day,60,cast('2000-4-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'UT' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and ws1.ws_order_number in (select ws_order_number - from ws_wh) -and ws1.ws_order_number in (select wr_order_number - from web_returns,ws_wh - where wr_order_number = ws_wh.ws_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query95.tpl query 96 in stream 10 --- start template query26.tpl query 97 in stream 10 -select /* TPC-DS query26.tpl 0.85 */ i_item_id, - avg(cs_quantity) agg1, - avg(cs_list_price) agg2, - avg(cs_coupon_amt) agg3, - avg(cs_sales_price) agg4 - from catalog_sales, customer_demographics, date_dim, item, promotion - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd_demo_sk and - cs_promo_sk = p_promo_sk and - cd_gender = 'F' and - cd_marital_status = 'W' and - cd_education_status = 'Secondary' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 2001 - group by i_item_id - order by i_item_id - limit 100; - --- end template query26.tpl query 97 in stream 10 --- start template query81.tpl query 98 in stream 10 -with /* TPC-DS query81.tpl 0.37 */ customer_total_return as - (select cr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(cr_return_amt_inc_tax) as ctr_total_return - from catalog_returns - ,date_dim - ,customer_address - where cr_returned_date_sk = d_date_sk - and d_year =1998 - and cr_returning_addr_sk = ca_address_sk - group by cr_returning_customer_sk - ,ca_state ) - select c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'OK' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - limit 100; - --- end template query81.tpl query 98 in stream 10 --- start template query19.tpl query 99 in stream 10 -select /* TPC-DS query19.tpl 0.8 */ i_brand_id brand_id, i_brand brand, i_manufact_id, i_manufact, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item,customer,customer_address,store - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=15 - and d_moy=12 - and d_year=1998 - and ss_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and substring(ca_zip,1,5) <> substring(s_zip,1,5) - and ss_store_sk = s_store_sk - group by i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact - order by ext_price desc - ,i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact -limit 100 ; - --- end template query19.tpl query 99 in stream 10 diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/100TB/queries/query_2.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/100TB/queries/query_2.sql deleted file mode 100644 index eeee6094..00000000 --- a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/100TB/queries/query_2.sql +++ /dev/null @@ -1,5027 +0,0 @@ --- start template query56.tpl query 1 in stream 2 -with /* TPC-DS query56.tpl 0.83 */ ss as ( - select i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where i_item_id in (select - i_item_id -from item -where i_color in ('floral','bisque','burlywood')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 1 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id), - cs as ( - select i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('floral','bisque','burlywood')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 1 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id), - ws as ( - select i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('floral','bisque','burlywood')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 1 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id) - select i_item_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by total_sales, - i_item_id - limit 100; - --- end template query56.tpl query 1 in stream 2 --- start template query98.tpl query 2 in stream 2 -select /* TPC-DS query98.tpl 0.32 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ss_ext_sales_price) as itemrevenue - ,sum(ss_ext_sales_price)*100/sum(sum(ss_ext_sales_price)) over - (partition by i_class) as revenueratio -from - store_sales - ,item - ,date_dim -where - ss_item_sk = i_item_sk - and i_category in ('Children', 'Women', 'Home') - and ss_sold_date_sk = d_date_sk - and d_date between cast('2001-03-14' as date) - and dateadd(day,30,cast('2001-03-14' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio; - --- end template query98.tpl query 2 in stream 2 --- start template query59.tpl query 3 in stream 2 -with /* TPC-DS query59.tpl 0.30 */ wss as - (select d_week_seq, - ss_store_sk, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - group by d_week_seq,ss_store_sk - ) - select s_store_name1,s_store_id1,d_week_seq1 - ,sun_sales1/sun_sales2,mon_sales1/mon_sales2 - ,tue_sales1/tue_sales2,wed_sales1/wed_sales2,thu_sales1/thu_sales2 - ,fri_sales1/fri_sales2,sat_sales1/sat_sales2 - from - (select s_store_name s_store_name1,wss.d_week_seq d_week_seq1 - ,s_store_id s_store_id1,sun_sales sun_sales1 - ,mon_sales mon_sales1,tue_sales tue_sales1 - ,wed_sales wed_sales1,thu_sales thu_sales1 - ,fri_sales fri_sales1,sat_sales sat_sales1 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1179 and 1179 + 11) y, - (select s_store_name s_store_name2,wss.d_week_seq d_week_seq2 - ,s_store_id s_store_id2,sun_sales sun_sales2 - ,mon_sales mon_sales2,tue_sales tue_sales2 - ,wed_sales wed_sales2,thu_sales thu_sales2 - ,fri_sales fri_sales2,sat_sales sat_sales2 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1179+ 12 and 1179 + 23) x - where s_store_id1=s_store_id2 - and d_week_seq1=d_week_seq2-52 - order by s_store_name1,s_store_id1,d_week_seq1 -limit 100; - --- end template query59.tpl query 3 in stream 2 --- start template query24.tpl query 4 in stream 2 -with /* TPC-DS query24.tpl 0.92 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_net_paid) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip -and s_market_id=10 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'navy' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; -with /* TPC-DS query24.tpl 0.92 part2 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_net_paid) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip - and s_market_id = 10 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'honeydew' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; - --- end template query24.tpl query 4 in stream 2 --- start template query88.tpl query 5 in stream 2 -select /* TPC-DS query88.tpl 0.66 */ * -from - (select count(*) h8_30_to_9 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2)) - and store.s_store_name = 'ese') s1, - (select count(*) h9_to_9_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2)) - and store.s_store_name = 'ese') s2, - (select count(*) h9_30_to_10 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2)) - and store.s_store_name = 'ese') s3, - (select count(*) h10_to_10_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2)) - and store.s_store_name = 'ese') s4, - (select count(*) h10_30_to_11 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2)) - and store.s_store_name = 'ese') s5, - (select count(*) h11_to_11_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2)) - and store.s_store_name = 'ese') s6, - (select count(*) h11_30_to_12 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2)) - and store.s_store_name = 'ese') s7, - (select count(*) h12_to_12_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 12 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2)) - and store.s_store_name = 'ese') s8 -; - --- end template query88.tpl query 5 in stream 2 --- start template query2.tpl query 6 in stream 2 -with /* TPC-DS query2.tpl 0.84 */ wscs as - (select sold_date_sk - ,sales_price - from (select ws_sold_date_sk sold_date_sk - ,ws_ext_sales_price sales_price - from web_sales - union all - select cs_sold_date_sk sold_date_sk - ,cs_ext_sales_price sales_price - from catalog_sales)), - wswscs as - (select d_week_seq, - sum(case when (d_day_name='Sunday') then sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then sales_price else null end) sat_sales - from wscs - ,date_dim - where d_date_sk = sold_date_sk - group by d_week_seq) - select d_week_seq1 - ,round(sun_sales1/sun_sales2,2) - ,round(mon_sales1/mon_sales2,2) - ,round(tue_sales1/tue_sales2,2) - ,round(wed_sales1/wed_sales2,2) - ,round(thu_sales1/thu_sales2,2) - ,round(fri_sales1/fri_sales2,2) - ,round(sat_sales1/sat_sales2,2) - from - (select wswscs.d_week_seq d_week_seq1 - ,sun_sales sun_sales1 - ,mon_sales mon_sales1 - ,tue_sales tue_sales1 - ,wed_sales wed_sales1 - ,thu_sales thu_sales1 - ,fri_sales fri_sales1 - ,sat_sales sat_sales1 - from wswscs,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 1998) y, - (select wswscs.d_week_seq d_week_seq2 - ,sun_sales sun_sales2 - ,mon_sales mon_sales2 - ,tue_sales tue_sales2 - ,wed_sales wed_sales2 - ,thu_sales thu_sales2 - ,fri_sales fri_sales2 - ,sat_sales sat_sales2 - from wswscs - ,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 1998+1) z - where d_week_seq1=d_week_seq2-53 - order by d_week_seq1; - --- end template query2.tpl query 6 in stream 2 --- start template query5a.tpl query 7 in stream 2 -with /* TPC-DS query5a.tpl 0.98 */ ssr as - (select s_store_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ss_store_sk as store_sk, - ss_sold_date_sk as date_sk, - ss_ext_sales_price as sales_price, - ss_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from store_sales - union all - select sr_store_sk as store_sk, - sr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - sr_return_amt as return_amt, - sr_net_loss as net_loss - from store_returns - ) salesreturns, - date_dim, - store - where date_sk = d_date_sk - and d_date between cast('2001-08-29' as date) - and dateadd(day,14,cast('2001-08-29' as date)) - and store_sk = s_store_sk - group by s_store_id) - , - csr as - (select cp_catalog_page_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select cs_catalog_page_sk as page_sk, - cs_sold_date_sk as date_sk, - cs_ext_sales_price as sales_price, - cs_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from catalog_sales - union all - select cr_catalog_page_sk as page_sk, - cr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - cr_return_amount as return_amt, - cr_net_loss as net_loss - from catalog_returns - ) salesreturns, - date_dim, - catalog_page - where date_sk = d_date_sk - and d_date between cast('2001-08-29' as date) - and dateadd(day,14,cast('2001-08-29' as date)) - and page_sk = cp_catalog_page_sk - group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ws_web_site_sk as wsr_web_site_sk, - ws_sold_date_sk as date_sk, - ws_ext_sales_price as sales_price, - ws_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from web_sales - union all - select ws_web_site_sk as wsr_web_site_sk, - wr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - wr_return_amt as return_amt, - wr_net_loss as net_loss - from web_returns left outer join web_sales on - ( wr_item_sk = ws_item_sk - and wr_order_number = ws_order_number) - ) salesreturns, - date_dim, - web_site - where date_sk = d_date_sk - and d_date between cast('2001-08-29' as date) - and dateadd(day,14,cast('2001-08-29' as date)) - and wsr_web_site_sk = web_site_sk - group by web_site_id) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || s_store_id as id - , sales - , returns - , (profit - profit_loss) as profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || cp_catalog_page_id as id - , sales - , returns - , (profit - profit_loss) as profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , (profit - profit_loss) as profit - from wsr - ) x - group by channel, id) - select channel, id, sales, returns, profit from ( - select channel, id, sales, returns, profit from results - union - select channel, null as id, sum(sales), sum(returns), sum(profit) from results group by channel - union - select null as channel, null as id, sum(sales), sum(returns), sum(profit) from results) foo -order by channel, id -limit 100; - --- end template query5a.tpl query 7 in stream 2 --- start template query6.tpl query 8 in stream 2 -select /* TPC-DS query6.tpl 0.58 */ a.ca_state state, count(*) cnt - from customer_address a - ,customer c - ,store_sales s - ,date_dim d - ,item i - where a.ca_address_sk = c.c_current_addr_sk - and c.c_customer_sk = s.ss_customer_sk - and s.ss_sold_date_sk = d.d_date_sk - and s.ss_item_sk = i.i_item_sk - and d.d_month_seq = - (select distinct (d_month_seq) - from date_dim - where d_year = 2002 - and d_moy = 7 ) - and i.i_current_price > 1.2 * - (select avg(j.i_current_price) - from item j - where j.i_category = i.i_category) - group by a.ca_state - having count(*) >= 10 - order by cnt, a.ca_state - limit 100; - --- end template query6.tpl query 8 in stream 2 --- start template query27a.tpl query 9 in stream 2 -with /* TPC-DS query27a.tpl 0.16 */ results as - (select i_item_id, - s_state, 0 as g_state, - ss_quantity agg1, - ss_list_price agg2, - ss_coupon_amt agg3, - ss_sales_price agg4 - from store_sales, customer_demographics, date_dim, store, item - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_store_sk = s_store_sk and - ss_cdemo_sk = cd_demo_sk and - cd_gender = 'M' and - cd_marital_status = 'S' and - cd_education_status = 'College' and - d_year = 2002 and - s_state in ('NY','LA', 'IL', 'AL', 'IA', 'TN') - ) - - select i_item_id, - s_state, g_state, agg1, agg2, agg3, agg4 - from ( - select i_item_id, s_state, 0 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4 from results - group by i_item_id, s_state - union all - select i_item_id, NULL AS s_state, 1 AS g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as s_state, 1 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - ) foo - order by i_item_id, s_state - limit 100; - --- end template query27a.tpl query 9 in stream 2 --- start template query87.tpl query 10 in stream 2 -select /* TPC-DS query87.tpl 0.77 */ count(*) -from ((select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1211 and 1211+11) - except - (select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1211 and 1211+11) - except - (select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1211 and 1211+11) -) cool_cust -; - --- end template query87.tpl query 10 in stream 2 --- start template query90.tpl query 11 in stream 2 -select /* TPC-DS query90.tpl 0.40 */ cast(amc as decimal(15,4))/cast(pmc as decimal(15,4)) am_pm_ratio - from ( select count(*) amc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 9 and 9+1 - and household_demographics.hd_dep_count = 9 - and web_page.wp_char_count between 5000 and 5200) at, - ( select count(*) pmc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 15 and 15+1 - and household_demographics.hd_dep_count = 9 - and web_page.wp_char_count between 5000 and 5200) pt - order by am_pm_ratio - limit 100; - --- end template query90.tpl query 11 in stream 2 --- start template query83.tpl query 12 in stream 2 -with /* TPC-DS query83.tpl 0.96 */ sr_items as - (select i_item_id item_id, - sum(sr_return_quantity) sr_item_qty - from store_returns, - item, - date_dim - where sr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2000-05-23','2000-08-13','2000-11-12'))) - and sr_returned_date_sk = d_date_sk - group by i_item_id), - cr_items as - (select i_item_id item_id, - sum(cr_return_quantity) cr_item_qty - from catalog_returns, - item, - date_dim - where cr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2000-05-23','2000-08-13','2000-11-12'))) - and cr_returned_date_sk = d_date_sk - group by i_item_id), - wr_items as - (select i_item_id item_id, - sum(wr_return_quantity) wr_item_qty - from web_returns, - item, - date_dim - where wr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2000-05-23','2000-08-13','2000-11-12'))) - and wr_returned_date_sk = d_date_sk - group by i_item_id) - select sr_items.item_id - ,sr_item_qty - ,sr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 sr_dev - ,cr_item_qty - ,cr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 cr_dev - ,wr_item_qty - ,wr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 wr_dev - ,(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 average - from sr_items - ,cr_items - ,wr_items - where sr_items.item_id=cr_items.item_id - and sr_items.item_id=wr_items.item_id - order by sr_items.item_id - ,sr_item_qty - limit 100; - --- end template query83.tpl query 12 in stream 2 --- start template query91.tpl query 13 in stream 2 -select /* TPC-DS query91.tpl 0.13 */ - cc_call_center_id Call_Center, - cc_name Call_Center_Name, - cc_manager Manager, - sum(cr_net_loss) Returns_Loss -from - call_center, - catalog_returns, - date_dim, - customer, - customer_address, - customer_demographics, - household_demographics -where - cr_call_center_sk = cc_call_center_sk -and cr_returned_date_sk = d_date_sk -and cr_returning_customer_sk= c_customer_sk -and cd_demo_sk = c_current_cdemo_sk -and hd_demo_sk = c_current_hdemo_sk -and ca_address_sk = c_current_addr_sk -and d_year = 1998 -and d_moy = 12 -and ( (cd_marital_status = 'M' and cd_education_status = 'Unknown') - or(cd_marital_status = 'W' and cd_education_status = 'Advanced Degree')) -and hd_buy_potential like 'Unknown%' -and ca_gmt_offset = -6 -group by cc_call_center_id,cc_name,cc_manager,cd_marital_status,cd_education_status -order by sum(cr_net_loss) desc; - --- end template query91.tpl query 13 in stream 2 --- start template query28.tpl query 14 in stream 2 -select /* TPC-DS query28.tpl 0.36 */ * -from (select avg(ss_list_price) B1_LP - ,count(ss_list_price) B1_CNT - ,count(distinct ss_list_price) B1_CNTD - from store_sales - where ss_quantity between 0 and 5 - and (ss_list_price between 128 and 128+10 - or ss_coupon_amt between 7640 and 7640+1000 - or ss_wholesale_cost between 6 and 6+20)) B1, - (select avg(ss_list_price) B2_LP - ,count(ss_list_price) B2_CNT - ,count(distinct ss_list_price) B2_CNTD - from store_sales - where ss_quantity between 6 and 10 - and (ss_list_price between 23 and 23+10 - or ss_coupon_amt between 2581 and 2581+1000 - or ss_wholesale_cost between 46 and 46+20)) B2, - (select avg(ss_list_price) B3_LP - ,count(ss_list_price) B3_CNT - ,count(distinct ss_list_price) B3_CNTD - from store_sales - where ss_quantity between 11 and 15 - and (ss_list_price between 44 and 44+10 - or ss_coupon_amt between 4708 and 4708+1000 - or ss_wholesale_cost between 13 and 13+20)) B3, - (select avg(ss_list_price) B4_LP - ,count(ss_list_price) B4_CNT - ,count(distinct ss_list_price) B4_CNTD - from store_sales - where ss_quantity between 16 and 20 - and (ss_list_price between 125 and 125+10 - or ss_coupon_amt between 1082 and 1082+1000 - or ss_wholesale_cost between 78 and 78+20)) B4, - (select avg(ss_list_price) B5_LP - ,count(ss_list_price) B5_CNT - ,count(distinct ss_list_price) B5_CNTD - from store_sales - where ss_quantity between 21 and 25 - and (ss_list_price between 86 and 86+10 - or ss_coupon_amt between 9038 and 9038+1000 - or ss_wholesale_cost between 77 and 77+20)) B5, - (select avg(ss_list_price) B6_LP - ,count(ss_list_price) B6_CNT - ,count(distinct ss_list_price) B6_CNTD - from store_sales - where ss_quantity between 26 and 30 - and (ss_list_price between 63 and 63+10 - or ss_coupon_amt between 12196 and 12196+1000 - or ss_wholesale_cost between 9 and 9+20)) B6 -limit 100; - --- end template query28.tpl query 14 in stream 2 --- start template query68.tpl query 15 in stream 2 -select /* TPC-DS query68.tpl 0.95 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,extended_price - ,extended_tax - ,list_price - from (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_ext_sales_price) extended_price - ,sum(ss_ext_list_price) list_price - ,sum(ss_ext_tax) extended_tax - from store_sales - ,date_dim - ,store - ,household_demographics - ,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_dep_count = 7 or - household_demographics.hd_vehicle_count= -1) - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_city in ('Deerfield','Salem') - group by ss_ticket_number - ,ss_customer_sk - ,ss_addr_sk,ca_city) dn - ,customer - ,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,ss_ticket_number - limit 100; - --- end template query68.tpl query 15 in stream 2 --- start template query8.tpl query 16 in stream 2 -select /* TPC-DS query8.tpl 0.63 */ s_store_name - ,sum(ss_net_profit) - from store_sales - ,date_dim - ,store, - (select ca_zip - from ( - SELECT substring(ca_zip,1,5) ca_zip - FROM customer_address - WHERE substring(ca_zip,1,5) IN ( - '12223','54964','50292','68076','30727','91767', - '60011','47735','81604','16796','68870', - '28400','35223','81571','57643','10999', - '12118','38419','71913','71527','54984', - '79186','54877','56797','67299','40244', - '45957','41861','39638','11014','12575', - '72538','96967','61711','38638','92288', - '57459','47039','45107','43146','91806', - '64336','48849','85811','41949','61850', - '59449','63549','29932','57586','32575', - '41706','22110','75252','42964','87851', - '21546','41220','86957','31466','15243', - '62442','38406','63887','42144','82110', - '47573','82088','94372','39880','93501', - '31897','46873','91737','52836','28981', - '48170','44550','38564','72073','18667', - '89789','51394','59572','85536','45739', - '52013','98376','18234','24136','40328', - '49241','84901','28737','80273','81053', - '51384','91615','26842','36499','50600', - '80476','74013','54968','69176','31993', - '51623','93664','49002','83956','71315', - '22834','30098','21482','67467','79718', - '66737','13968','77558','91111','34636', - '42729','10215','13975','68817','98211', - '17112','30320','97341','42943','26937', - '85801','56671','13884','87345','87976', - '47522','87878','26703','96698','24236', - '52076','11316','91260','60545','83633', - '46934','29901','49172','34016','50359', - '77200','41133','83808','92115','66750', - '29798','85799','49145','89274','31298', - '51252','91031','60505','68275','14249', - '73078','46236','41941','34364','69980', - '23773','76683','60679','85462','77246', - '38172','62980','91243','78812','22859', - '69568','36885','76813','36847','43944', - '19623','45278','42178','44122','28389', - '52902','58145','79714','29431','72475', - '12112','82756','65747','65210','38447', - '12643','39988','89178','84351','60940', - '55971','47024','50241','34037','95856', - '20754','54725','15832','72887','23794', - '42310','43955','59061','89303','19500', - '43087','42746','18925','39208','18908', - '35629','37768','46208','66213','31340', - '21221','18798','77816','39345','29332', - '50303','67964','49850','97430','33473', - '13064','87889','18255','16536','61844', - '81624','87446','95158','66804','90360', - '64173','76012','19128','29313','26576', - '55522','39633','33999','22691','61875', - '96403','11645','63519','58323','92720', - '38501','88837','83785','89130','26840', - '35834','99214','16947','87844','33158', - '81016','95898','20446','52425','95086', - '86401','54358','26984','22090','67256', - '93932','58955','95736','98251','89271', - '31354','21783','92124','80071','41496', - '63428','87574','98043','56462','77026', - '50313','11774','83354','45503','61395', - '96774','38974','48884','92828','92281', - '29381','42415','14230','55538','19156', - '56677','56929','23560','79000','46371', - '23235','95467','99829','49314','85360', - '79963','76119','38804','50191','68311', - '36180','26838','76905','80246','25773', - '52100','94963','80572','81312','89143', - '68333','36248','50395','97746','75869', - '99853','27010','24807','46938','75163', - '63643','78439','82608','89000','79909', - '59909','24164','14211','75469','86023', - '84928','86549','40018','95571','52261', - '50654','34088','34881','91175','25075', - '89228','98906','13148','69890','24724', - '81785','30521','35726','50827','76526', - '52172','20434','14837','39080','25175', - '38911','78377','27203','66759','47150', - '27188','22496','26493','75003','74326', - '57932','24965','29334','51371') - intersect - select ca_zip - from (SELECT substring(ca_zip,1,5) ca_zip,count(*) cnt - FROM customer_address, customer - WHERE ca_address_sk = c_current_addr_sk and - c_preferred_cust_flag='Y' - group by ca_zip - having count(*) > 10)A1)A2) V1 - where ss_store_sk = s_store_sk - and ss_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 1998 - and (substring(s_zip,1,2) = substring(V1.ca_zip,1,2)) - group by s_store_name - order by s_store_name - limit 100; - --- end template query8.tpl query 16 in stream 2 --- start template query76.tpl query 17 in stream 2 -select /* TPC-DS query76.tpl 0.99 */ channel, col_name, d_year, d_qoy, i_category, COUNT(*) sales_cnt, SUM(ext_sales_price) sales_amt FROM ( - SELECT 'store' as channel, 'ss_hdemo_sk' col_name, d_year, d_qoy, i_category, ss_ext_sales_price ext_sales_price - FROM store_sales, item, date_dim - WHERE ss_hdemo_sk IS NULL - AND ss_sold_date_sk=d_date_sk - AND ss_item_sk=i_item_sk - UNION ALL - SELECT 'web' as channel, 'ws_web_page_sk' col_name, d_year, d_qoy, i_category, ws_ext_sales_price ext_sales_price - FROM web_sales, item, date_dim - WHERE ws_web_page_sk IS NULL - AND ws_sold_date_sk=d_date_sk - AND ws_item_sk=i_item_sk - UNION ALL - SELECT 'catalog' as channel, 'cs_warehouse_sk' col_name, d_year, d_qoy, i_category, cs_ext_sales_price ext_sales_price - FROM catalog_sales, item, date_dim - WHERE cs_warehouse_sk IS NULL - AND cs_sold_date_sk=d_date_sk - AND cs_item_sk=i_item_sk) foo -GROUP BY channel, col_name, d_year, d_qoy, i_category -ORDER BY channel, col_name, d_year, d_qoy, i_category -limit 100; - --- end template query76.tpl query 17 in stream 2 --- start template query75.tpl query 18 in stream 2 -WITH /* TPC-DS query75.tpl 0.3 */ all_sales AS ( - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,SUM(sales_cnt) AS sales_cnt - ,SUM(sales_amt) AS sales_amt - FROM (SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,cs_quantity - COALESCE(cr_return_quantity,0) AS sales_cnt - ,cs_ext_sales_price - COALESCE(cr_return_amount,0.0) AS sales_amt - FROM catalog_sales JOIN item ON i_item_sk=cs_item_sk - JOIN date_dim ON d_date_sk=cs_sold_date_sk - LEFT JOIN catalog_returns ON (cs_order_number=cr_order_number - AND cs_item_sk=cr_item_sk) - WHERE i_category='Home' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ss_quantity - COALESCE(sr_return_quantity,0) AS sales_cnt - ,ss_ext_sales_price - COALESCE(sr_return_amt,0.0) AS sales_amt - FROM store_sales JOIN item ON i_item_sk=ss_item_sk - JOIN date_dim ON d_date_sk=ss_sold_date_sk - LEFT JOIN store_returns ON (ss_ticket_number=sr_ticket_number - AND ss_item_sk=sr_item_sk) - WHERE i_category='Home' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ws_quantity - COALESCE(wr_return_quantity,0) AS sales_cnt - ,ws_ext_sales_price - COALESCE(wr_return_amt,0.0) AS sales_amt - FROM web_sales JOIN item ON i_item_sk=ws_item_sk - JOIN date_dim ON d_date_sk=ws_sold_date_sk - LEFT JOIN web_returns ON (ws_order_number=wr_order_number - AND ws_item_sk=wr_item_sk) - WHERE i_category='Home') sales_detail - GROUP BY d_year, i_brand_id, i_class_id, i_category_id, i_manufact_id) - SELECT prev_yr.d_year AS prev_year - ,curr_yr.d_year AS year - ,curr_yr.i_brand_id - ,curr_yr.i_class_id - ,curr_yr.i_category_id - ,curr_yr.i_manufact_id - ,prev_yr.sales_cnt AS prev_yr_cnt - ,curr_yr.sales_cnt AS curr_yr_cnt - ,curr_yr.sales_cnt-prev_yr.sales_cnt AS sales_cnt_diff - ,curr_yr.sales_amt-prev_yr.sales_amt AS sales_amt_diff - FROM all_sales curr_yr, all_sales prev_yr - WHERE curr_yr.i_brand_id=prev_yr.i_brand_id - AND curr_yr.i_class_id=prev_yr.i_class_id - AND curr_yr.i_category_id=prev_yr.i_category_id - AND curr_yr.i_manufact_id=prev_yr.i_manufact_id - AND curr_yr.d_year=2000 - AND prev_yr.d_year=2000-1 - AND CAST(curr_yr.sales_cnt AS DECIMAL(17,2))/CAST(prev_yr.sales_cnt AS DECIMAL(17,2))<0.9 - ORDER BY sales_cnt_diff,sales_amt_diff - limit 100; - --- end template query75.tpl query 18 in stream 2 --- start template query80a.tpl query 19 in stream 2 -with /* TPC-DS query80a.tpl 0.6 */ ssr as - (select s_store_id as store_id, - sum(ss_ext_sales_price) as sales, - sum(coalesce(sr_return_amt, 0)) as returns, - sum(ss_net_profit - coalesce(sr_net_loss, 0)) as profit - from store_sales left outer join store_returns on - (ss_item_sk = sr_item_sk and ss_ticket_number = sr_ticket_number), - date_dim, - store, - item, - promotion - where ss_sold_date_sk = d_date_sk - and d_date between cast('1999-08-11' as date) - and dateadd(day,30,cast('1999-08-11' as date)) - and ss_store_sk = s_store_sk - and ss_item_sk = i_item_sk - and i_current_price > 50 - and ss_promo_sk = p_promo_sk - and p_channel_tv = 'N' - group by s_store_id) - , - csr as - (select cp_catalog_page_id as catalog_page_id, - sum(cs_ext_sales_price) as sales, - sum(coalesce(cr_return_amount, 0)) as returns, - sum(cs_net_profit - coalesce(cr_net_loss, 0)) as profit - from catalog_sales left outer join catalog_returns on - (cs_item_sk = cr_item_sk and cs_order_number = cr_order_number), - date_dim, - catalog_page, - item, - promotion - where cs_sold_date_sk = d_date_sk - and d_date between cast('1999-08-11' as date) - and dateadd(day,30,cast('1999-08-11' as date)) - and cs_catalog_page_sk = cp_catalog_page_sk - and cs_item_sk = i_item_sk - and i_current_price > 50 - and cs_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(ws_ext_sales_price) as sales, - sum(coalesce(wr_return_amt, 0)) as returns, - sum(ws_net_profit - coalesce(wr_net_loss, 0)) as profit - from web_sales left outer join web_returns on - (ws_item_sk = wr_item_sk and ws_order_number = wr_order_number), - date_dim, - web_site, - item, - promotion - where ws_sold_date_sk = d_date_sk - and d_date between cast('1999-08-11' as date) - and dateadd(day,30,cast('1999-08-11' as date)) - and ws_web_site_sk = web_site_sk - and ws_item_sk = i_item_sk - and i_current_price > 50 - and ws_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by web_site_id) -, -results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || store_id as id - , sales - , returns - , profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || catalog_page_id as id - , sales - , returns - , profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , profit - from wsr - ) x - group by channel, id) - - select channel - , id - , sales - , returns - , profit - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results - ) foo - order by channel, id - limit 100; - --- end template query80a.tpl query 19 in stream 2 --- start template query1.tpl query 20 in stream 2 -with /* TPC-DS query1.tpl 0.12 */ customer_total_return as -(select sr_customer_sk as ctr_customer_sk -,sr_store_sk as ctr_store_sk -,sum(SR_RETURN_TAX) as ctr_total_return -from store_returns -,date_dim -where sr_returned_date_sk = d_date_sk -and d_year =2001 -group by sr_customer_sk -,sr_store_sk) - select c_customer_id -from customer_total_return ctr1 -,store -,customer -where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 -from customer_total_return ctr2 -where ctr1.ctr_store_sk = ctr2.ctr_store_sk) -and s_store_sk = ctr1.ctr_store_sk -and s_state = 'WA' -and ctr1.ctr_customer_sk = c_customer_sk -order by c_customer_id -limit 100; - --- end template query1.tpl query 20 in stream 2 --- start template query69.tpl query 21 in stream 2 -select /* TPC-DS query69.tpl 0.28 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_state in ('GA','MD','NC') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2004 and - d_moy between 1 and 1+2) and - (not exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2004 and - d_moy between 1 and 1+2) and - not exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2004 and - d_moy between 1 and 1+2)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - limit 100; - --- end template query69.tpl query 21 in stream 2 --- start template query26.tpl query 22 in stream 2 -select /* TPC-DS query26.tpl 0.85 */ i_item_id, - avg(cs_quantity) agg1, - avg(cs_list_price) agg2, - avg(cs_coupon_amt) agg3, - avg(cs_sales_price) agg4 - from catalog_sales, customer_demographics, date_dim, item, promotion - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd_demo_sk and - cs_promo_sk = p_promo_sk and - cd_gender = 'F' and - cd_marital_status = 'U' and - cd_education_status = 'College' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 1999 - group by i_item_id - order by i_item_id - limit 100; - --- end template query26.tpl query 22 in stream 2 --- start template query11.tpl query 23 in stream 2 -with /* TPC-DS query11.tpl 0.51 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ss_ext_list_price-ss_ext_discount_amt) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ws_ext_list_price-ws_ext_discount_amt) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_email_address - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 2000 - and t_s_secyear.dyear = 2000+1 - and t_w_firstyear.dyear = 2000 - and t_w_secyear.dyear = 2000+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else 0.0 end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else 0.0 end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_email_address -limit 100; - --- end template query11.tpl query 23 in stream 2 --- start template query17.tpl query 24 in stream 2 -select /* TPC-DS query17.tpl 0.41 */ i_item_id - ,i_item_desc - ,s_state - ,count(ss_quantity) as store_sales_quantitycount - ,avg(ss_quantity) as store_sales_quantityave - ,stddev_samp(ss_quantity) as store_sales_quantitystdev - ,stddev_samp(ss_quantity)/avg(ss_quantity) as store_sales_quantitycov - ,count(sr_return_quantity) as store_returns_quantitycount - ,avg(sr_return_quantity) as store_returns_quantityave - ,stddev_samp(sr_return_quantity) as store_returns_quantitystdev - ,stddev_samp(sr_return_quantity)/avg(sr_return_quantity) as store_returns_quantitycov - ,count(cs_quantity) as catalog_sales_quantitycount ,avg(cs_quantity) as catalog_sales_quantityave - ,stddev_samp(cs_quantity) as catalog_sales_quantitystdev - ,stddev_samp(cs_quantity)/avg(cs_quantity) as catalog_sales_quantitycov - from store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where d1.d_quarter_name = '1999Q1' - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_quarter_name in ('1999Q1','1999Q2','1999Q3') - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_quarter_name in ('1999Q1','1999Q2','1999Q3') - group by i_item_id - ,i_item_desc - ,s_state - order by i_item_id - ,i_item_desc - ,s_state -limit 100; - --- end template query17.tpl query 24 in stream 2 --- start template query63.tpl query 25 in stream 2 -select /* TPC-DS query63.tpl 0.27 */ * -from (select i_manager_id - ,sum(ss_sales_price) sum_sales - ,avg(sum(ss_sales_price)) over (partition by i_manager_id) avg_monthly_sales - from item - ,store_sales - ,date_dim - ,store - where ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and d_month_seq in (1208,1208+1,1208+2,1208+3,1208+4,1208+5,1208+6,1208+7,1208+8,1208+9,1208+10,1208+11) - and (( i_category in ('Books','Children','Electronics') - and i_class in ('personal','portable','reference','self-help') - and i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) - or( i_category in ('Women','Music','Men') - and i_class in ('accessories','classical','fragrances','pants') - and i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manager_id, d_moy) tmp1 -where case when avg_monthly_sales > 0 then abs (sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 -order by i_manager_id - ,avg_monthly_sales - ,sum_sales -limit 100; - --- end template query63.tpl query 25 in stream 2 --- start template query77a.tpl query 26 in stream 2 -with /* TPC-DS query77a.tpl 0.78 */ ss as - (select s_store_sk, - sum(ss_ext_sales_price) as sales, - sum(ss_net_profit) as profit - from store_sales, - date_dim, - store - where ss_sold_date_sk = d_date_sk - and d_date between cast('2001-08-08' as date) - and dateadd(day,30,cast('2001-08-08' as date)) - and ss_store_sk = s_store_sk - group by s_store_sk) - , - sr as - (select s_store_sk, - sum(sr_return_amt) as returns, - sum(sr_net_loss) as profit_loss - from store_returns, - date_dim, - store - where sr_returned_date_sk = d_date_sk - and d_date between cast('2001-08-08' as date) - and dateadd(day,30,cast('2001-08-08' as date)) - and sr_store_sk = s_store_sk - group by s_store_sk), - cs as - (select cs_call_center_sk, - sum(cs_ext_sales_price) as sales, - sum(cs_net_profit) as profit - from catalog_sales, - date_dim - where cs_sold_date_sk = d_date_sk - and d_date between cast('2001-08-08' as date) - and dateadd(day,30,cast('2001-08-08' as date)) - group by cs_call_center_sk - ), - cr as - (select cr_call_center_sk, - sum(cr_return_amount) as returns, - sum(cr_net_loss) as profit_loss - from catalog_returns, - date_dim - where cr_returned_date_sk = d_date_sk - and d_date between cast('2001-08-08' as date) - and dateadd(day,30,cast('2001-08-08' as date)) - group by cr_call_center_sk), - ws as - ( select wp_web_page_sk, - sum(ws_ext_sales_price) as sales, - sum(ws_net_profit) as profit - from web_sales, - date_dim, - web_page - where ws_sold_date_sk = d_date_sk - and d_date between cast('2001-08-08' as date) - and dateadd(day,30,cast('2001-08-08' as date)) - and ws_web_page_sk = wp_web_page_sk - group by wp_web_page_sk), - wr as - (select wp_web_page_sk, - sum(wr_return_amt) as returns, - sum(wr_net_loss) as profit_loss - from web_returns, - date_dim, - web_page - where wr_returned_date_sk = d_date_sk - and d_date between cast('2001-08-08' as date) - and dateadd(day,30,cast('2001-08-08' as date)) - and wr_web_page_sk = wp_web_page_sk - group by wp_web_page_sk) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , ss.s_store_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ss left join sr - on ss.s_store_sk = sr.s_store_sk - union all - select 'catalog channel' as channel - , cs_call_center_sk as id - , sales - , returns - , (profit - profit_loss) as profit - from cs - , cr - union all - select 'web channel' as channel - , ws.wp_web_page_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ws left join wr - on ws.wp_web_page_sk = wr.wp_web_page_sk - ) x - group by channel, id ) - - select * - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results -) foo -order by channel, id - limit 100; - --- end template query77a.tpl query 26 in stream 2 --- start template query19.tpl query 27 in stream 2 -select /* TPC-DS query19.tpl 0.8 */ i_brand_id brand_id, i_brand brand, i_manufact_id, i_manufact, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item,customer,customer_address,store - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=42 - and d_moy=12 - and d_year=1998 - and ss_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and substring(ca_zip,1,5) <> substring(s_zip,1,5) - and ss_store_sk = s_store_sk - group by i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact - order by ext_price desc - ,i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact -limit 100 ; - --- end template query19.tpl query 27 in stream 2 --- start template query21.tpl query 28 in stream 2 -select /* TPC-DS query21.tpl 0.14 */ * - from(select w_warehouse_name - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('2002-04-20' as date)) - then inv_quantity_on_hand - else 0 end) as inv_before - ,sum(case when (cast(d_date as date) >= cast ('2002-04-20' as date)) - then inv_quantity_on_hand - else 0 end) as inv_after - from inventory - ,warehouse - ,item - ,date_dim - where i_current_price between 0.99 and 1.49 - and i_item_sk = inv_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('2002-04-20' as date)) - and dateadd(day,30,cast ('2002-04-20' as date)) - group by w_warehouse_name, i_item_id) x - where (case when inv_before > 0 - then inv_after / inv_before - else null - end) between 2.0/3.0 and 3.0/2.0 - order by w_warehouse_name - ,i_item_id - limit 100; - --- end template query21.tpl query 28 in stream 2 --- start template query31.tpl query 29 in stream 2 -with /* TPC-DS query31.tpl 0.50 */ ss as - (select ca_county,d_qoy, d_year,sum(ss_ext_sales_price) as store_sales - from store_sales,date_dim,customer_address - where ss_sold_date_sk = d_date_sk - and ss_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year), - ws as - (select ca_county,d_qoy, d_year,sum(ws_ext_sales_price) as web_sales - from web_sales,date_dim,customer_address - where ws_sold_date_sk = d_date_sk - and ws_bill_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year) - select - ss1.ca_county - ,ss1.d_year - ,ws2.web_sales/ws1.web_sales web_q1_q2_increase - ,ss2.store_sales/ss1.store_sales store_q1_q2_increase - ,ws3.web_sales/ws2.web_sales web_q2_q3_increase - ,ss3.store_sales/ss2.store_sales store_q2_q3_increase - from - ss ss1 - ,ss ss2 - ,ss ss3 - ,ws ws1 - ,ws ws2 - ,ws ws3 - where - ss1.d_qoy = 1 - and ss1.d_year = 2000 - and ss1.ca_county = ss2.ca_county - and ss2.d_qoy = 2 - and ss2.d_year = 2000 - and ss2.ca_county = ss3.ca_county - and ss3.d_qoy = 3 - and ss3.d_year = 2000 - and ss1.ca_county = ws1.ca_county - and ws1.d_qoy = 1 - and ws1.d_year = 2000 - and ws1.ca_county = ws2.ca_county - and ws2.d_qoy = 2 - and ws2.d_year = 2000 - and ws1.ca_county = ws3.ca_county - and ws3.d_qoy = 3 - and ws3.d_year =2000 - and case when ws1.web_sales > 0 then ws2.web_sales/ws1.web_sales else null end - > case when ss1.store_sales > 0 then ss2.store_sales/ss1.store_sales else null end - and case when ws2.web_sales > 0 then ws3.web_sales/ws2.web_sales else null end - > case when ss2.store_sales > 0 then ss3.store_sales/ss2.store_sales else null end - order by web_q1_q2_increase; - --- end template query31.tpl query 29 in stream 2 --- start template query93.tpl query 30 in stream 2 -select /* TPC-DS query93.tpl 0.52 */ ss_customer_sk - ,sum(act_sales) sumsales - from (select ss_item_sk - ,ss_ticket_number - ,ss_customer_sk - ,case when sr_return_quantity is not null then (ss_quantity-sr_return_quantity)*ss_sales_price - else (ss_quantity*ss_sales_price) end act_sales - from store_sales left outer join store_returns on (sr_item_sk = ss_item_sk - and sr_ticket_number = ss_ticket_number) - ,reason - where sr_reason_sk = r_reason_sk - and r_reason_desc = 'reason 62') t - group by ss_customer_sk - order by sumsales, ss_customer_sk -limit 100; - --- end template query93.tpl query 30 in stream 2 --- start template query54.tpl query 31 in stream 2 -with /* TPC-DS query54.tpl 0.81 */ my_customers as ( - select distinct c_customer_sk - , c_current_addr_sk - from - ( select cs_sold_date_sk sold_date_sk, - cs_bill_customer_sk customer_sk, - cs_item_sk item_sk - from catalog_sales - union all - select ws_sold_date_sk sold_date_sk, - ws_bill_customer_sk customer_sk, - ws_item_sk item_sk - from web_sales - ) cs_or_ws_sales, - item, - date_dim, - customer - where sold_date_sk = d_date_sk - and item_sk = i_item_sk - and i_category = 'Children' - and i_class = 'school-uniforms' - and c_customer_sk = cs_or_ws_sales.customer_sk - and d_moy = 1 - and d_year = 2000 - ) - , my_revenue as ( - select c_customer_sk, - sum(ss_ext_sales_price) as revenue - from my_customers, - store_sales, - customer_address, - store, - date_dim - where c_current_addr_sk = ca_address_sk - and ca_county = s_county - and ca_state = s_state - and ss_sold_date_sk = d_date_sk - and c_customer_sk = ss_customer_sk - and d_month_seq between (select distinct d_month_seq+1 - from date_dim where d_year = 2000 and d_moy = 1) - and (select distinct d_month_seq+3 - from date_dim where d_year = 2000 and d_moy = 1) - group by c_customer_sk - ) - , segments as - (select cast((revenue/50) as bigint) as segment - from my_revenue - ) - select segment, count(*) as num_customers, segment*50 as segment_base - from segments - group by segment - order by segment, num_customers - limit 100; - --- end template query54.tpl query 31 in stream 2 --- start template query39.tpl query 32 in stream 2 -with /* TPC-DS query39.tpl 0.5 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =2000 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=2 - and inv2.d_moy=2+1 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; -with /* TPC-DS query39.tpl 0.5 part2 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =2000 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=2 - and inv2.d_moy=2+1 - and inv1.cov > 1.5 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; - --- end template query39.tpl query 32 in stream 2 --- start template query10.tpl query 33 in stream 2 -select /* TPC-DS query10.tpl 0.26 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3, - cd_dep_count, - count(*) cnt4, - cd_dep_employed_count, - count(*) cnt5, - cd_dep_college_count, - count(*) cnt6 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_county in ('Hockley County','Leavenworth County','DuPage County','Crenshaw County','Lake County') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 1 and 1+3) and - (exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 1 ANd 1+3) or - exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 1 and 1+3)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count -limit 100; - --- end template query10.tpl query 33 in stream 2 --- start template query15.tpl query 34 in stream 2 -select /* TPC-DS query15.tpl 0.57 */ ca_zip - ,sum(cs_sales_price) - from catalog_sales - ,customer - ,customer_address - ,date_dim - where cs_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', - '85392', '85460', '80348', '81792') - or ca_state in ('CA','WA','GA') - or cs_sales_price > 500) - and cs_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 2002 - group by ca_zip - order by ca_zip - limit 100; - --- end template query15.tpl query 34 in stream 2 --- start template query55.tpl query 35 in stream 2 -select /* TPC-DS query55.tpl 0.82 */ i_brand_id brand_id, i_brand brand, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=48 - and d_moy=12 - and d_year=2001 - group by i_brand, i_brand_id - order by ext_price desc, i_brand_id -limit 100 ; - --- end template query55.tpl query 35 in stream 2 --- start template query14a.tpl query 36 in stream 2 -with /* TPC-DS query14a.tpl 0.69 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1999 AND 1999 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1999 AND 1999 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1999 AND 1999 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as - (select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2) x) -, - results AS -(select channel, i_brand_id, i_class_id, i_category_id, sum(sales) sum_sales, sum(number_sales) number_sales - from ( - select 'store' channel, i_brand_id,i_class_id - ,i_category_id,sum(ss_quantity*ss_list_price) sales - , count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1999+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales) - union all - select 'catalog' channel, i_brand_id,i_class_id,i_category_id, sum(cs_quantity*cs_list_price) sales, count(*) number_sales - from catalog_sales - ,item - ,date_dim - where cs_item_sk in (select ss_item_sk from cross_items) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1999+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(cs_quantity*cs_list_price) > (select average_sales from avg_sales) - union all - select 'web' channel, i_brand_id,i_class_id,i_category_id, sum(ws_quantity*ws_list_price) sales , count(*) number_sales - from web_sales - ,item - ,date_dim - where ws_item_sk in (select ss_item_sk from cross_items) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1999+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ws_quantity*ws_list_price) > (select average_sales from avg_sales) - ) y - group by channel, i_brand_id,i_class_id,i_category_id) - - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales -from ( - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales from results - union - select channel, i_brand_id, i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id, i_class_id - union - select channel, i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id - union - select channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel - union - select null as channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results) z -order by channel, i_brand_id, i_class_id, i_category_id - limit 100; -with /* TPC-DS query14a.tpl 0.69 part2 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1999 AND 1999 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1999 AND 1999 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1999 AND 1999 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as -(select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2) x) - select this_year.channel ty_channel - ,this_year.i_brand_id ty_brand - ,this_year.i_class_id ty_class - ,this_year.i_category_id ty_category - ,this_year.sales ty_sales - ,this_year.number_sales ty_number_sales - ,last_year.channel ly_channel - ,last_year.i_brand_id ly_brand - ,last_year.i_class_id ly_class - ,last_year.i_category_id ly_category - ,last_year.sales ly_sales - ,last_year.number_sales ly_number_sales -from - (select 'store' channel, i_brand_id,i_class_id,i_category_id - ,sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1999 + 1 - and d_moy = 12 - and d_dom = 23) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) this_year, - (select 'store' channel, i_brand_id,i_class_id - ,i_category_id, sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1999 - and d_moy = 12 - and d_dom = 23) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) last_year - where this_year.i_brand_id= last_year.i_brand_id - and this_year.i_class_id = last_year.i_class_id - and this_year.i_category_id = last_year.i_category_id - order by this_year.channel, this_year.i_brand_id, this_year.i_class_id, this_year.i_category_id - limit 100; - --- end template query14a.tpl query 36 in stream 2 --- start template query38.tpl query 37 in stream 2 -select /* TPC-DS query38.tpl 0.54 */ count(*) from ( - select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1204 and 1204 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1204 and 1204 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1204 and 1204 + 11 -) hot_cust -limit 100; - --- end template query38.tpl query 37 in stream 2 --- start template query42.tpl query 38 in stream 2 -select /* TPC-DS query42.tpl 0.61 */ dt.d_year - ,item.i_category_id - ,item.i_category - ,sum(ss_ext_sales_price) - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=12 - and dt.d_year=2002 - group by dt.d_year - ,item.i_category_id - ,item.i_category - order by sum(ss_ext_sales_price) desc,dt.d_year - ,item.i_category_id - ,item.i_category -limit 100 ; - --- end template query42.tpl query 38 in stream 2 --- start template query53.tpl query 39 in stream 2 -select /* TPC-DS query53.tpl 0.88 */ * from -(select i_manufact_id, -sum(ss_sales_price) sum_sales, -avg(sum(ss_sales_price)) over (partition by i_manufact_id) avg_quarterly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and -ss_sold_date_sk = d_date_sk and -ss_store_sk = s_store_sk and -d_month_seq in (1188,1188+1,1188+2,1188+3,1188+4,1188+5,1188+6,1188+7,1188+8,1188+9,1188+10,1188+11) and -((i_category in ('Books','Children','Electronics') and -i_class in ('personal','portable','reference','self-help') and -i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) -or(i_category in ('Women','Music','Men') and -i_class in ('accessories','classical','fragrances','pants') and -i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manufact_id, d_qoy ) tmp1 -where case when avg_quarterly_sales > 0 - then abs (sum_sales - avg_quarterly_sales)/ avg_quarterly_sales - else null end > 0.1 -order by avg_quarterly_sales, - sum_sales, - i_manufact_id -limit 100; - --- end template query53.tpl query 39 in stream 2 --- start template query45.tpl query 40 in stream 2 -select /* TPC-DS query45.tpl 0.18 */ ca_zip, ca_city, sum(ws_sales_price) - from web_sales, customer, customer_address, date_dim, item - where ws_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ws_item_sk = i_item_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', '85392', '85460', '80348', '81792') - or - i_item_id in (select i_item_id - from item - where i_item_sk in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29) - ) - ) - and ws_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 2002 - group by ca_zip, ca_city - order by ca_zip, ca_city - limit 100; - --- end template query45.tpl query 40 in stream 2 --- start template query99.tpl query 41 in stream 2 -select /* TPC-DS query99.tpl 0.94 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 30) and - (cs_ship_date_sk - cs_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 60) and - (cs_ship_date_sk - cs_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 90) and - (cs_ship_date_sk - cs_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - catalog_sales - ,warehouse - ,ship_mode - ,call_center - ,date_dim -where - d_month_seq between 1197 and 1197 + 11 -and cs_ship_date_sk = d_date_sk -and cs_warehouse_sk = w_warehouse_sk -and cs_ship_mode_sk = sm_ship_mode_sk -and cs_call_center_sk = cc_call_center_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -limit 100; - --- end template query99.tpl query 41 in stream 2 --- start template query67a.tpl query 42 in stream 2 -with /* TPC-DS query67a.tpl 0.35 */ results as -( select i_category ,i_class ,i_brand ,i_product_name ,d_year ,d_qoy ,d_moy ,s_store_id - ,sum(coalesce(ss_sales_price*ss_quantity,0)) sumsales - from store_sales ,date_dim ,store ,item - where ss_sold_date_sk=d_date_sk - and ss_item_sk=i_item_sk - and ss_store_sk = s_store_sk - and d_month_seq between 1181 and 1181 + 11 - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy,s_store_id) - , - results_rollup as - (select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, s_store_id, sumsales - from results - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy - union all - select i_category, i_class, i_brand, i_product_name, d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year - union all - select i_category, i_class, i_brand, i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name - union all - select i_category, i_class, i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand - union all - select i_category, i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class - union all - select i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category - union all - select null i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results) - - select * -from (select i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rank() over (partition by i_category order by sumsales desc) rk - from results_rollup) dw2 -where rk <= 100 -order by i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rk -limit 100; - --- end template query67a.tpl query 42 in stream 2 --- start template query23.tpl query 43 in stream 2 -with /* TPC-DS query23.tpl 0.68 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (2000,2000+1,2000+2,2000+3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (2000,2000+1,2000+2,2000+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * -from - max_store_sales)) - select sum(sales) - from (select cs_quantity*cs_list_price sales - from catalog_sales - ,date_dim - where d_year = 2000 - and d_moy = 1 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - union all - select ws_quantity*ws_list_price sales - from web_sales - ,date_dim - where d_year = 2000 - and d_moy = 1 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer)) - limit 100; -with /* TPC-DS query23.tpl 0.68 part2 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (2000,2000 + 1,2000 + 2,2000 + 3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (2000,2000+1,2000+2,2000+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * - from max_store_sales)) - select c_last_name,c_first_name,sales - from (select c_last_name,c_first_name,sum(cs_quantity*cs_list_price) sales - from catalog_sales - ,customer - ,date_dim - where d_year = 2000 - and d_moy = 1 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and cs_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name - union all - select c_last_name,c_first_name,sum(ws_quantity*ws_list_price) sales - from web_sales - ,customer - ,date_dim - where d_year = 2000 - and d_moy = 1 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and ws_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name) - order by c_last_name,c_first_name,sales - limit 100; - --- end template query23.tpl query 43 in stream 2 --- start template query62.tpl query 44 in stream 2 -select /* TPC-DS query62.tpl 0.24 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 30) and - (ws_ship_date_sk - ws_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 60) and - (ws_ship_date_sk - ws_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 90) and - (ws_ship_date_sk - ws_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - web_sales - ,warehouse - ,ship_mode - ,web_site - ,date_dim -where - d_month_seq between 1186 and 1186 + 11 -and ws_ship_date_sk = d_date_sk -and ws_warehouse_sk = w_warehouse_sk -and ws_ship_mode_sk = sm_ship_mode_sk -and ws_web_site_sk = web_site_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -limit 100; - --- end template query62.tpl query 44 in stream 2 --- start template query30.tpl query 45 in stream 2 -with /* TPC-DS query30.tpl 0.75 */ customer_total_return as - (select wr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(wr_return_amt) as ctr_total_return - from web_returns - ,date_dim - ,customer_address - where wr_returned_date_sk = d_date_sk - and d_year =2002 - and wr_returning_addr_sk = ca_address_sk - group by wr_returning_customer_sk - ,ca_state) - select c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'NE' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return -limit 100; - --- end template query30.tpl query 45 in stream 2 --- start template query86a.tpl query 46 in stream 2 -with /* TPC-DS query86a.tpl 0.11 */ results as -( select sum(ws_net_paid) as total_sum, i_category, i_class, 0 as g_category, 0 as g_class - from - web_sales - ,date_dim d1 - ,item - where - d1.d_month_seq between 1213 and 1213+11 - and d1.d_date_sk = ws_sold_date_sk - and i_item_sk = ws_item_sk - group by i_category,i_class - ) , - - results_rollup as -( select total_sum ,i_category ,i_class, g_category, g_class, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum, i_category, NULL as i_class, 0 as g_category, 1 as g_class, 1 as lochierarchy from results group by i_category - union - select sum(total_sum) as total_sum, NULL as i_category, NULL as i_class, 1 as g_category, 1 as g_class, 2 as lochierarchy from results) - select - total_sum ,i_category ,i_class, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_class = 0 then i_category end - order by total_sum desc) as rank_within_parent - from - results_rollup - order by - lochierarchy desc, - case when lochierarchy = 0 then i_category end, - rank_within_parent - limit 100; - --- end template query86a.tpl query 46 in stream 2 --- start template query82.tpl query 47 in stream 2 -select /* TPC-DS query82.tpl 0.67 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, store_sales - where i_current_price between 35 and 35+30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('2002-01-30' as date) and dateadd(day,60,cast('2002-01-30' as date)) - and i_manufact_id in (26,556,746,533) - and inv_quantity_on_hand between 100 and 500 - and ss_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query82.tpl query 47 in stream 2 --- start template query25.tpl query 48 in stream 2 -select /* TPC-DS query25.tpl 0.9 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,avg(ss_net_profit) as store_sales_profit - ,avg(sr_net_loss) as store_returns_loss - ,avg(cs_net_profit) as catalog_sales_profit - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 2000 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 10 - and d2.d_year = 2000 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_moy between 4 and 10 - and d3.d_year = 2000 - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query25.tpl query 48 in stream 2 --- start template query16.tpl query 49 in stream 2 -select /* TPC-DS query16.tpl 0.25 */ - count(distinct cs_order_number) as "order count" - ,sum(cs_ext_ship_cost) as "total shipping cost" - ,sum(cs_net_profit) as "total net profit" -from - catalog_sales cs1 - ,date_dim - ,customer_address - ,call_center -where - d_date between '1999-5-01' and - dateadd(day, 60, cast('1999-5-01' as date)) -and cs1.cs_ship_date_sk = d_date_sk -and cs1.cs_ship_addr_sk = ca_address_sk -and ca_state = 'TX' -and cs1.cs_call_center_sk = cc_call_center_sk -and cc_county in ('Sumner County','Huron County','Gage County','Ziebach County', - 'Jefferson Davis Parish' -) -and exists (select * - from catalog_sales cs2 - where cs1.cs_order_number = cs2.cs_order_number - and cs1.cs_warehouse_sk <> cs2.cs_warehouse_sk) -and not exists(select * - from catalog_returns cr1 - where cs1.cs_order_number = cr1.cr_order_number) -order by count(distinct cs_order_number) -limit 100; - --- end template query16.tpl query 49 in stream 2 --- start template query81.tpl query 50 in stream 2 -with /* TPC-DS query81.tpl 0.37 */ customer_total_return as - (select cr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(cr_return_amt_inc_tax) as ctr_total_return - from catalog_returns - ,date_dim - ,customer_address - where cr_returned_date_sk = d_date_sk - and d_year =1999 - and cr_returning_addr_sk = ca_address_sk - group by cr_returning_customer_sk - ,ca_state ) - select c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'OK' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - limit 100; - --- end template query81.tpl query 50 in stream 2 --- start template query40.tpl query 51 in stream 2 -select /* TPC-DS query40.tpl 0.86 */ - w_state - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('2000-04-02' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_before - ,sum(case when (cast(d_date as date) >= cast ('2000-04-02' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_after - from - catalog_sales left outer join catalog_returns on - (cs_order_number = cr_order_number - and cs_item_sk = cr_item_sk) - ,warehouse - ,item - ,date_dim - where - i_current_price between 0.99 and 1.49 - and i_item_sk = cs_item_sk - and cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('2000-04-02' as date)) - and dateadd(day,30,cast ('2000-04-02' as date)) - group by - w_state,i_item_id - order by w_state,i_item_id -limit 100; - --- end template query40.tpl query 51 in stream 2 --- start template query44.tpl query 52 in stream 2 -select /* TPC-DS query44.tpl 0.4 */ asceding.rnk, i1.i_product_name best_performing, i2.i_product_name worst_performing -from(select * - from (select item_sk,rank() over (order by rank_col asc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 89 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 89 - and ss_hdemo_sk is null - group by ss_store_sk))V1)V11 - where rnk < 11) asceding, - (select * - from (select item_sk,rank() over (order by rank_col desc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 89 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 89 - and ss_hdemo_sk is null - group by ss_store_sk))V2)V21 - where rnk < 11) descending, -item i1, -item i2 -where asceding.rnk = descending.rnk - and i1.i_item_sk=asceding.item_sk - and i2.i_item_sk=descending.item_sk -order by asceding.rnk -limit 100; - --- end template query44.tpl query 52 in stream 2 --- start template query50.tpl query 53 in stream 2 -select /* TPC-DS query50.tpl 0.60 */ - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 30) and - (sr_returned_date_sk - ss_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 60) and - (sr_returned_date_sk - ss_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 90) and - (sr_returned_date_sk - ss_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - store_sales - ,store_returns - ,store - ,date_dim d1 - ,date_dim d2 -where - d2.d_year = 2001 -and d2.d_moy = 8 -and ss_ticket_number = sr_ticket_number -and ss_item_sk = sr_item_sk -and ss_sold_date_sk = d1.d_date_sk -and sr_returned_date_sk = d2.d_date_sk -and ss_customer_sk = sr_customer_sk -and ss_store_sk = s_store_sk -group by - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -order by s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -limit 100; - --- end template query50.tpl query 53 in stream 2 --- start template query61.tpl query 54 in stream 2 -select /* TPC-DS query61.tpl 0.97 */ promotions,total,cast(promotions as decimal(16,4))/cast(total as decimal(16,4))*100 -from - (select sum(ss_ext_sales_price) promotions - from store_sales - ,store - ,promotion - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_promo_sk = p_promo_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -6 - and i_category = 'Sports' - and (p_channel_dmail = 'Y' or p_channel_email = 'Y' or p_channel_tv = 'Y') - and s_gmt_offset = -6 - and d_year = 2002 - and d_moy = 12) promotional_sales, - (select sum(ss_ext_sales_price) total - from store_sales - ,store - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -6 - and i_category = 'Sports' - and s_gmt_offset = -6 - and d_year = 2002 - and d_moy = 12) all_sales -order by promotions, total -limit 100; - --- end template query61.tpl query 54 in stream 2 --- start template query85.tpl query 55 in stream 2 -select /* TPC-DS query85.tpl 0.33 */ substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) - from web_sales, web_returns, web_page, customer_demographics cd1, - customer_demographics cd2, customer_address, date_dim, reason - where ws_web_page_sk = wp_web_page_sk - and ws_item_sk = wr_item_sk - and ws_order_number = wr_order_number - and ws_sold_date_sk = d_date_sk and d_year = 2002 - and cd1.cd_demo_sk = wr_refunded_cdemo_sk - and cd2.cd_demo_sk = wr_returning_cdemo_sk - and ca_address_sk = wr_refunded_addr_sk - and r_reason_sk = wr_reason_sk - and - ( - ( - cd1.cd_marital_status = 'S' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'College' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 100.00 and 150.00 - ) - or - ( - cd1.cd_marital_status = 'M' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Secondary' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 50.00 and 100.00 - ) - or - ( - cd1.cd_marital_status = 'U' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = '4 yr Degree' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ca_country = 'United States' - and - ca_state in ('TX', 'AZ', 'WV') - and ws_net_profit between 100 and 200 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('KY', 'CO', 'IL') - and ws_net_profit between 150 and 300 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('NY', 'VA', 'NE') - and ws_net_profit between 50 and 250 - ) - ) -group by r_reason_desc -order by substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) -limit 100; - --- end template query85.tpl query 55 in stream 2 --- start template query73.tpl query 56 in stream 2 -select /* TPC-DS query73.tpl 0.79 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_buy_potential = '1001-5000' or - household_demographics.hd_buy_potential = '0-500') - and household_demographics.hd_vehicle_count > 0 - and case when household_demographics.hd_vehicle_count > 0 then - household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count else null end > 1 - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_county in ('Boone County','Sandusky County','Pinal County','Stafford County') - group by ss_ticket_number,ss_customer_sk) dj,customer - where ss_customer_sk = c_customer_sk - and cnt between 1 and 5 - order by cnt desc, c_last_name asc; - --- end template query73.tpl query 56 in stream 2 --- start template query95.tpl query 57 in stream 2 -with /* TPC-DS query95.tpl 0.43 */ ws_wh as -(select ws1.ws_order_number,ws1.ws_warehouse_sk wh1,ws2.ws_warehouse_sk wh2 - from web_sales ws1,web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) - select - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2000-4-01' and - dateadd(day,60,cast('2000-4-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'IN' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and ws1.ws_order_number in (select ws_order_number - from ws_wh) -and ws1.ws_order_number in (select wr_order_number - from web_returns,ws_wh - where wr_order_number = ws_wh.ws_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query95.tpl query 57 in stream 2 --- start template query84.tpl query 58 in stream 2 -select /* TPC-DS query84.tpl 0.80 */ c_customer_id as customer_id - , coalesce(c_last_name,'') || ', ' || coalesce(c_first_name,'') as customername - from customer - ,customer_address - ,customer_demographics - ,household_demographics - ,income_band - ,store_returns - where ca_city = 'Bethel' - and c_current_addr_sk = ca_address_sk - and ib_lower_bound >= 56061 - and ib_upper_bound <= 56061 + 50000 - and ib_income_band_sk = hd_income_band_sk - and cd_demo_sk = c_current_cdemo_sk - and hd_demo_sk = c_current_hdemo_sk - and sr_cdemo_sk = cd_demo_sk - order by c_customer_id - limit 100; - --- end template query84.tpl query 58 in stream 2 --- start template query4.tpl query 59 in stream 2 -with /* TPC-DS query4.tpl 0.93 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(((ss_ext_list_price-ss_ext_wholesale_cost-ss_ext_discount_amt)+ss_ext_sales_price)/2) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((cs_ext_list_price-cs_ext_wholesale_cost-cs_ext_discount_amt)+cs_ext_sales_price)/2) ) year_total - ,'c' sale_type - from customer - ,catalog_sales - ,date_dim - where c_customer_sk = cs_bill_customer_sk - and cs_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year -union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((ws_ext_list_price-ws_ext_wholesale_cost-ws_ext_discount_amt)+ws_ext_sales_price)/2) ) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_preferred_cust_flag - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_c_firstyear - ,year_total t_c_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_c_secyear.customer_id - and t_s_firstyear.customer_id = t_c_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_c_firstyear.sale_type = 'c' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_c_secyear.sale_type = 'c' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 2001 - and t_s_secyear.dyear = 2001+1 - and t_c_firstyear.dyear = 2001 - and t_c_secyear.dyear = 2001+1 - and t_w_firstyear.dyear = 2001 - and t_w_secyear.dyear = 2001+1 - and t_s_firstyear.year_total > 0 - and t_c_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_preferred_cust_flag -limit 100; - --- end template query4.tpl query 59 in stream 2 --- start template query37.tpl query 60 in stream 2 -select /* TPC-DS query37.tpl 0.31 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, catalog_sales - where i_current_price between 30 and 30 + 30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('1999-03-08' as date) and dateadd(day,60,cast('1999-03-08' as date)) - and i_manufact_id in (808,785,738,741) - and inv_quantity_on_hand between 100 and 500 - and cs_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query37.tpl query 60 in stream 2 --- start template query35a.tpl query 61 in stream 2 -select /* TPC-DS query35a.tpl 0.47 */ - ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - count(*) cnt1, - max(cd_dep_count), - avg(cd_dep_count), - avg(cd_dep_count), - cd_dep_employed_count, - count(*) cnt2, - max(cd_dep_employed_count), - avg(cd_dep_employed_count), - avg(cd_dep_employed_count), - cd_dep_college_count, - count(*) cnt3, - max(cd_dep_college_count), - avg(cd_dep_college_count), - avg(cd_dep_college_count) - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2002 and - d_qoy < 4) and - exists (select * from - (select ws_bill_customer_sk customsk - from web_sales,date_dim - where - ws_sold_date_sk = d_date_sk and - d_year = 2002 and - d_qoy < 4 - union all - select cs_ship_customer_sk customsk - from catalog_sales,date_dim - where - cs_sold_date_sk = d_date_sk and - d_year = 2002 and - d_qoy < 4)x - where x.customsk = c.c_customer_sk) - group by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - limit 100; - --- end template query35a.tpl query 61 in stream 2 --- start template query94.tpl query 62 in stream 2 -select /* TPC-DS query94.tpl 0.17 */ - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2000-5-01' and - dateadd(day,60,cast('2000-5-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'NC' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and exists (select * - from web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) -and not exists(select * - from web_returns wr1 - where ws1.ws_order_number = wr1.wr_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query94.tpl query 62 in stream 2 --- start template query58.tpl query 63 in stream 2 -with /* TPC-DS query58.tpl 0.19 */ ss_items as - (select i_item_id item_id - ,sum(ss_ext_sales_price) ss_item_rev - from store_sales - ,item - ,date_dim - where ss_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '2002-06-07')) - and ss_sold_date_sk = d_date_sk - group by i_item_id), - cs_items as - (select i_item_id item_id - ,sum(cs_ext_sales_price) cs_item_rev - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '2002-06-07')) - and cs_sold_date_sk = d_date_sk - group by i_item_id), - ws_items as - (select i_item_id item_id - ,sum(ws_ext_sales_price) ws_item_rev - from web_sales - ,item - ,date_dim - where ws_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq =(select d_week_seq - from date_dim - where d_date = '2002-06-07')) - and ws_sold_date_sk = d_date_sk - group by i_item_id) - select ss_items.item_id - ,ss_item_rev - ,ss_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ss_dev - ,cs_item_rev - ,cs_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 cs_dev - ,ws_item_rev - ,ws_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ws_dev - ,(ss_item_rev+cs_item_rev+ws_item_rev)/3 average - from ss_items,cs_items,ws_items - where ss_items.item_id=cs_items.item_id - and ss_items.item_id=ws_items.item_id - and ss_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - and ss_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and cs_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and cs_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and ws_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and ws_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - order by item_id - ,ss_item_rev - limit 100; - --- end template query58.tpl query 63 in stream 2 --- start template query96.tpl query 64 in stream 2 -select /* TPC-DS query96.tpl 0.1 */ count(*) -from store_sales - ,household_demographics - ,time_dim, store -where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 16 - and time_dim.t_minute >= 30 - and household_demographics.hd_dep_count = 9 - and store.s_store_name = 'ese' -order by count(*) -limit 100; - --- end template query96.tpl query 64 in stream 2 --- start template query12.tpl query 65 in stream 2 -select /* TPC-DS query12.tpl 0.64 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ws_ext_sales_price) as itemrevenue - ,sum(ws_ext_sales_price)*100/sum(sum(ws_ext_sales_price)) over - (partition by i_class) as revenueratio -from - web_sales - ,item - ,date_dim -where - ws_item_sk = i_item_sk - and i_category in ('Sports', 'Jewelry', 'Men') - and ws_sold_date_sk = d_date_sk - and d_date between cast('1998-05-04' as date) - and dateadd(day,30,cast('1998-05-04' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query12.tpl query 65 in stream 2 --- start template query29.tpl query 66 in stream 2 -select /* TPC-DS query29.tpl 0.53 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,max(ss_quantity) as store_sales_quantity - ,max(sr_return_quantity) as store_returns_quantity - ,max(cs_quantity) as catalog_sales_quantity - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 1998 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 4 + 3 - and d2.d_year = 1998 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_year in (1998,1998+1,1998+2) - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query29.tpl query 66 in stream 2 --- start template query22a.tpl query 67 in stream 2 -with /* TPC-DS query22a.tpl 0.55 */ results as -(select i_product_name - ,i_brand - ,i_class - ,i_category - ,avg(inv_quantity_on_hand) qoh - from inventory - ,date_dim - ,item --- ,warehouse - where inv_date_sk=d_date_sk - and inv_item_sk=i_item_sk --- and inv_warehouse_sk = w_warehouse_sk - and d_month_seq between 1216 and 1216 + 11 - group by i_product_name,i_brand,i_class,i_category), -results_rollup as -(select i_product_name, i_brand, i_class, i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class,i_category -union all -select i_product_name, i_brand, i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class -union all -select i_product_name, i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand -union all -select i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name -union all -select null i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results) - select i_product_name, i_brand, i_class, i_category,qoh - from results_rollup - order by qoh, i_product_name, i_brand, i_class, i_category -limit 100; - --- end template query22a.tpl query 67 in stream 2 --- start template query51.tpl query 68 in stream 2 -WITH /* TPC-DS query51.tpl 0.46 */ web_v1 as ( -select - ws_item_sk item_sk, d_date, - sum(sum(ws_sales_price)) - over (partition by ws_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from web_sales - ,date_dim -where ws_sold_date_sk=d_date_sk - and d_month_seq between 1216 and 1216+11 - and ws_item_sk is not NULL -group by ws_item_sk, d_date), -store_v1 as ( -select - ss_item_sk item_sk, d_date, - sum(sum(ss_sales_price)) - over (partition by ss_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from store_sales - ,date_dim -where ss_sold_date_sk=d_date_sk - and d_month_seq between 1216 and 1216+11 - and ss_item_sk is not NULL -group by ss_item_sk, d_date) - select * -from (select item_sk - ,d_date - ,web_sales - ,store_sales - ,max(web_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) web_cumulative - ,max(store_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) store_cumulative - from (select case when web.item_sk is not null then web.item_sk else store.item_sk end item_sk - ,case when web.d_date is not null then web.d_date else store.d_date end d_date - ,web.cume_sales web_sales - ,store.cume_sales store_sales - from web_v1 web full outer join store_v1 store on (web.item_sk = store.item_sk - and web.d_date = store.d_date) - )x )y -where web_cumulative > store_cumulative -order by item_sk - ,d_date -limit 100; - --- end template query51.tpl query 68 in stream 2 --- start template query36a.tpl query 69 in stream 2 -with /* TPC-DS query36a.tpl 0.21 */ results as - (select - sum(ss_net_profit) as ss_net_profit, sum(ss_ext_sales_price) as ss_ext_sales_price, - sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin - ,i_category - ,i_class - ,0 as g_category, 0 as g_class - from - store_sales - ,date_dim d1 - ,item - ,store - where - d1.d_year = 2001 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and s_state in ('CA','LA','MI','TX', - 'AL','NE','CO','KY') - group by i_category,i_class) - , - results_rollup as - (select gross_margin ,i_category ,i_class,0 as t_category, 0 as t_class, 0 as lochierarchy from results - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - i_category, NULL AS i_class, 0 as t_category, 1 as t_class, 1 as lochierarchy from results group by i_category - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - NULL AS i_category ,NULL AS i_class, 1 as t_category, 1 as t_class, 2 as lochierarchy from results) - select - gross_margin ,i_category ,i_class, lochierarchy,rank() over ( - partition by lochierarchy, case when t_class = 0 then i_category end - order by gross_margin asc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then i_category end - ,rank_within_parent - limit 100; - --- end template query36a.tpl query 69 in stream 2 --- start template query43.tpl query 70 in stream 2 -select /* TPC-DS query43.tpl 0.15 */ s_store_name, s_store_id, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from date_dim, store_sales, store - where d_date_sk = ss_sold_date_sk and - s_store_sk = ss_store_sk and - s_gmt_offset = -6 and - d_year = 1998 - group by s_store_name, s_store_id - order by s_store_name, s_store_id,sun_sales,mon_sales,tue_sales,wed_sales,thu_sales,fri_sales,sat_sales - limit 100; - --- end template query43.tpl query 70 in stream 2 --- start template query64.tpl query 71 in stream 2 -with /* TPC-DS query64.tpl 0.20 */ cs_ui as - (select cs_item_sk - ,sum(cs_ext_list_price) as sale,sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit) as refund - from catalog_sales - ,catalog_returns - where cs_item_sk = cr_item_sk - and cs_order_number = cr_order_number - group by cs_item_sk - having sum(cs_ext_list_price)>2*sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit)), -cross_sales as - (select i_product_name product_name - ,i_item_sk item_sk - ,s_store_name store_name - ,s_zip store_zip - ,ad1.ca_street_number b_street_number - ,ad1.ca_street_name b_street_name - ,ad1.ca_city b_city - ,ad1.ca_zip b_zip - ,ad2.ca_street_number c_street_number - ,ad2.ca_street_name c_street_name - ,ad2.ca_city c_city - ,ad2.ca_zip c_zip - ,d1.d_year as syear - ,d2.d_year as fsyear - ,d3.d_year s2year - ,count(*) cnt - ,sum(ss_wholesale_cost) s1 - ,sum(ss_list_price) s2 - ,sum(ss_coupon_amt) s3 - FROM store_sales - ,store_returns - ,cs_ui - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,customer - ,customer_demographics cd1 - ,customer_demographics cd2 - ,promotion - ,household_demographics hd1 - ,household_demographics hd2 - ,customer_address ad1 - ,customer_address ad2 - ,income_band ib1 - ,income_band ib2 - ,item - WHERE ss_store_sk = s_store_sk AND - ss_sold_date_sk = d1.d_date_sk AND - ss_customer_sk = c_customer_sk AND - ss_cdemo_sk= cd1.cd_demo_sk AND - ss_hdemo_sk = hd1.hd_demo_sk AND - ss_addr_sk = ad1.ca_address_sk and - ss_item_sk = i_item_sk and - ss_item_sk = sr_item_sk and - ss_ticket_number = sr_ticket_number and - ss_item_sk = cs_ui.cs_item_sk and - c_current_cdemo_sk = cd2.cd_demo_sk AND - c_current_hdemo_sk = hd2.hd_demo_sk AND - c_current_addr_sk = ad2.ca_address_sk and - c_first_sales_date_sk = d2.d_date_sk and - c_first_shipto_date_sk = d3.d_date_sk and - ss_promo_sk = p_promo_sk and - hd1.hd_income_band_sk = ib1.ib_income_band_sk and - hd2.hd_income_band_sk = ib2.ib_income_band_sk and - cd1.cd_marital_status <> cd2.cd_marital_status and - i_color in ('coral','drab','lime','puff','tan','blanched') and - i_current_price between 22 and 22 + 10 and - i_current_price between 22 + 1 and 22 + 15 -group by i_product_name - ,i_item_sk - ,s_store_name - ,s_zip - ,ad1.ca_street_number - ,ad1.ca_street_name - ,ad1.ca_city - ,ad1.ca_zip - ,ad2.ca_street_number - ,ad2.ca_street_name - ,ad2.ca_city - ,ad2.ca_zip - ,d1.d_year - ,d2.d_year - ,d3.d_year -) -select cs1.product_name - ,cs1.store_name - ,cs1.store_zip - ,cs1.b_street_number - ,cs1.b_street_name - ,cs1.b_city - ,cs1.b_zip - ,cs1.c_street_number - ,cs1.c_street_name - ,cs1.c_city - ,cs1.c_zip - ,cs1.syear - ,cs1.cnt - ,cs1.s1 as s11 - ,cs1.s2 as s21 - ,cs1.s3 as s31 - ,cs2.s1 as s12 - ,cs2.s2 as s22 - ,cs2.s3 as s32 - ,cs2.syear - ,cs2.cnt -from cross_sales cs1,cross_sales cs2 -where cs1.item_sk=cs2.item_sk and - cs1.syear = 1999 and - cs2.syear = 1999 + 1 and - cs2.cnt <= cs1.cnt and - cs1.store_name = cs2.store_name and - cs1.store_zip = cs2.store_zip -order by cs1.product_name - ,cs1.store_name - ,cs2.cnt - ,cs1.s1 - ,cs2.s1; - --- end template query64.tpl query 71 in stream 2 --- start template query20.tpl query 72 in stream 2 -select /* TPC-DS query20.tpl 0.65 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(cs_ext_sales_price) as itemrevenue - ,sum(cs_ext_sales_price)*100/sum(sum(cs_ext_sales_price)) over - (partition by i_class) as revenueratio - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and i_category in ('Jewelry', 'Women', 'Electronics') - and cs_sold_date_sk = d_date_sk - and d_date between cast('1998-03-22' as date) - and dateadd(day,30,cast('1998-03-22' as date)) - group by i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - order by i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query20.tpl query 72 in stream 2 --- start template query57.tpl query 73 in stream 2 -with /* TPC-DS query57.tpl 0.70 */ v1 as( - select i_category, i_brand, - cc_name, - d_year, d_moy, - sum(cs_sales_price) sum_sales, - avg(sum(cs_sales_price)) over - (partition by i_category, i_brand, - cc_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - cc_name - order by d_year, d_moy) rn - from item, catalog_sales, date_dim, call_center - where cs_item_sk = i_item_sk and - cs_sold_date_sk = d_date_sk and - cc_call_center_sk= cs_call_center_sk and - ( - d_year = 2000 or - ( d_year = 2000-1 and d_moy =12) or - ( d_year = 2000+1 and d_moy =1) - ) - group by i_category, i_brand, - cc_name , d_year, d_moy), - v2 as( - select v1.cc_name - ,v1.d_year, v1.d_moy - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1. cc_name = v1_lag. cc_name and - v1. cc_name = v1_lead. cc_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 2000 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, psum - limit 100; - --- end template query57.tpl query 73 in stream 2 --- start template query9.tpl query 74 in stream 2 -select /* TPC-DS query9.tpl 0.49 */ case when (select count(*) - from store_sales - where ss_quantity between 1 and 20) > 3361396897 - then (select avg(ss_ext_list_price) - from store_sales - where ss_quantity between 1 and 20) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 1 and 20) end bucket1 , - case when (select count(*) - from store_sales - where ss_quantity between 21 and 40) > 2897930060 - then (select avg(ss_ext_list_price) - from store_sales - where ss_quantity between 21 and 40) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 21 and 40) end bucket2, - case when (select count(*) - from store_sales - where ss_quantity between 41 and 60) > 3555470882 - then (select avg(ss_ext_list_price) - from store_sales - where ss_quantity between 41 and 60) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 41 and 60) end bucket3, - case when (select count(*) - from store_sales - where ss_quantity between 61 and 80) > 3933771439 - then (select avg(ss_ext_list_price) - from store_sales - where ss_quantity between 61 and 80) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 61 and 80) end bucket4, - case when (select count(*) - from store_sales - where ss_quantity between 81 and 100) > 3141165225 - then (select avg(ss_ext_list_price) - from store_sales - where ss_quantity between 81 and 100) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 81 and 100) end bucket5 -from reason -where r_reason_sk = 1 -; - --- end template query9.tpl query 74 in stream 2 --- start template query52.tpl query 75 in stream 2 -select /* TPC-DS query52.tpl 0.59 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_sales_price) ext_price - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=11 - and dt.d_year=1998 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,ext_price desc - ,brand_id -limit 100 ; - --- end template query52.tpl query 75 in stream 2 --- start template query49.tpl query 76 in stream 2 -select /* TPC-DS query49.tpl 0.48 */ channel, item, return_ratio, return_rank, currency_rank from - (select - 'web' as channel - ,web.item - ,web.return_ratio - ,web.return_rank - ,web.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select ws.ws_item_sk as item - ,(cast(sum(coalesce(wr.wr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(wr.wr_return_amt,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - web_sales ws left outer join web_returns wr - on (ws.ws_order_number = wr.wr_order_number and - ws.ws_item_sk = wr.wr_item_sk) - ,date_dim - where - wr.wr_return_amt > 10000 - and ws.ws_net_profit > 1 - and ws.ws_net_paid > 0 - and ws.ws_quantity > 0 - and ws_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 11 - group by ws.ws_item_sk - ) in_web - ) web - where - ( - web.return_rank <= 10 - or - web.currency_rank <= 10 - ) - union - select - 'catalog' as channel - ,catalog.item - ,catalog.return_ratio - ,catalog.return_rank - ,catalog.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select - cs.cs_item_sk as item - ,(cast(sum(coalesce(cr.cr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(cr.cr_return_amount,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - catalog_sales cs left outer join catalog_returns cr - on (cs.cs_order_number = cr.cr_order_number and - cs.cs_item_sk = cr.cr_item_sk) - ,date_dim - where - cr.cr_return_amount > 10000 - and cs.cs_net_profit > 1 - and cs.cs_net_paid > 0 - and cs.cs_quantity > 0 - and cs_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 11 - group by cs.cs_item_sk - ) in_cat - ) catalog - where - ( - catalog.return_rank <= 10 - or - catalog.currency_rank <=10 - ) - union - select - 'store' as channel - ,store.item - ,store.return_ratio - ,store.return_rank - ,store.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select sts.ss_item_sk as item - ,(cast(sum(coalesce(sr.sr_return_quantity,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(sr.sr_return_amt,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - store_sales sts left outer join store_returns sr - on (sts.ss_ticket_number = sr.sr_ticket_number and sts.ss_item_sk = sr.sr_item_sk) - ,date_dim - where - sr.sr_return_amt > 10000 - and sts.ss_net_profit > 1 - and sts.ss_net_paid > 0 - and sts.ss_quantity > 0 - and ss_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 11 - group by sts.ss_item_sk - ) in_store - ) store - where ( - store.return_rank <= 10 - or - store.currency_rank <= 10 - ) - ) - order by 1,4,5,2 - limit 100; - --- end template query49.tpl query 76 in stream 2 --- start template query71.tpl query 77 in stream 2 -select /* TPC-DS query71.tpl 0.72 */ i_brand_id brand_id, i_brand brand,t_hour,t_minute, - sum(ext_price) ext_price - from item, (select ws_ext_sales_price as ext_price, - ws_sold_date_sk as sold_date_sk, - ws_item_sk as sold_item_sk, - ws_sold_time_sk as time_sk - from web_sales,date_dim - where d_date_sk = ws_sold_date_sk - and d_moy=12 - and d_year=1999 - union all - select cs_ext_sales_price as ext_price, - cs_sold_date_sk as sold_date_sk, - cs_item_sk as sold_item_sk, - cs_sold_time_sk as time_sk - from catalog_sales,date_dim - where d_date_sk = cs_sold_date_sk - and d_moy=12 - and d_year=1999 - union all - select ss_ext_sales_price as ext_price, - ss_sold_date_sk as sold_date_sk, - ss_item_sk as sold_item_sk, - ss_sold_time_sk as time_sk - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - and d_moy=12 - and d_year=1999 - ) tmp,time_dim - where - sold_item_sk = i_item_sk - and i_manager_id=1 - and time_sk = t_time_sk - and (t_meal_time = 'breakfast' or t_meal_time = 'dinner') - group by i_brand, i_brand_id,t_hour,t_minute - order by ext_price desc, i_brand_id - ; - --- end template query71.tpl query 77 in stream 2 --- start template query72.tpl query 78 in stream 2 -select /* TPC-DS query72.tpl 0.87 */ i_item_desc - ,w_warehouse_name - ,d1.d_week_seq - ,sum(case when p_promo_sk is null then 1 else 0 end) no_promo - ,sum(case when p_promo_sk is not null then 1 else 0 end) promo - ,count(*) total_cnt -from catalog_sales -join inventory on (cs_item_sk = inv_item_sk) -join warehouse on (w_warehouse_sk=inv_warehouse_sk) -join item on (i_item_sk = cs_item_sk) -join customer_demographics on (cs_bill_cdemo_sk = cd_demo_sk) -join household_demographics on (cs_bill_hdemo_sk = hd_demo_sk) -join date_dim d1 on (cs_sold_date_sk = d1.d_date_sk) -join date_dim d2 on (inv_date_sk = d2.d_date_sk) -join date_dim d3 on (cs_ship_date_sk = d3.d_date_sk) -left outer join promotion on (cs_promo_sk=p_promo_sk) -left outer join catalog_returns on (cr_item_sk = cs_item_sk and cr_order_number = cs_order_number) -where d1.d_week_seq = d2.d_week_seq - and inv_quantity_on_hand < cs_quantity - and d3.d_date > d1.d_date + 5 - and hd_buy_potential = '501-1000' - and d1.d_year = 2002 - and cd_marital_status = 'U' -group by i_item_desc,w_warehouse_name,d1.d_week_seq -order by total_cnt desc, i_item_desc, w_warehouse_name, d_week_seq -limit 100; - --- end template query72.tpl query 78 in stream 2 --- start template query70a.tpl query 79 in stream 2 -with /* TPC-DS query70a.tpl 0.34 */ results as -( select - sum(ss_net_profit) as total_sum ,s_state ,s_county, 0 as gstate, 0 as g_county - from - store_sales - ,date_dim d1 - ,store - where - d1.d_month_seq between 1189 and 1189 + 11 - and d1.d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - and s_state in - ( select s_state - from (select s_state as s_state, - rank() over ( partition by s_state order by sum(ss_net_profit) desc) as ranking - from store_sales, store, date_dim - where d_month_seq between 1189 and 1189 + 11 - and d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - group by s_state - ) tmp1 - where ranking <= 5) - group by s_state,s_county) , - results_rollup as -(select total_sum ,s_state ,s_county, 0 as g_state, 0 as g_county, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum,s_state, NULL as s_county, 0 as g_state, 1 as g_county, 1 as lochierarchy from results group by s_state - union - select sum(total_sum) as total_sum ,NULL as s_state ,NULL as s_county, 1 as g_state, 1 as g_county, 2 as lochierarchy from results) - select total_sum ,s_state ,s_county, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_county = 0 then s_state end - order by total_sum desc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then s_state end - ,rank_within_parent - limit 100; - --- end template query70a.tpl query 79 in stream 2 --- start template query7.tpl query 80 in stream 2 -select /* TPC-DS query7.tpl 0.2 */ i_item_id, - avg(ss_quantity) agg1, - avg(ss_list_price) agg2, - avg(ss_coupon_amt) agg3, - avg(ss_sales_price) agg4 - from store_sales, customer_demographics, date_dim, item, promotion - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_cdemo_sk = cd_demo_sk and - ss_promo_sk = p_promo_sk and - cd_gender = 'M' and - cd_marital_status = 'W' and - cd_education_status = 'Unknown' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 2002 - group by i_item_id - order by i_item_id - limit 100; - --- end template query7.tpl query 80 in stream 2 --- start template query97.tpl query 81 in stream 2 -with /* TPC-DS query97.tpl 0.38 */ ssci as ( -select ss_customer_sk customer_sk - ,ss_item_sk item_sk -from store_sales,date_dim -where ss_sold_date_sk = d_date_sk - and d_month_seq between 1186 and 1186 + 11 -group by ss_customer_sk - ,ss_item_sk), -csci as( - select cs_bill_customer_sk customer_sk - ,cs_item_sk item_sk -from catalog_sales,date_dim -where cs_sold_date_sk = d_date_sk - and d_month_seq between 1186 and 1186 + 11 -group by cs_bill_customer_sk - ,cs_item_sk) - select sum(case when ssci.customer_sk is not null and csci.customer_sk is null then 1 else 0 end) store_only - ,sum(case when ssci.customer_sk is null and csci.customer_sk is not null then 1 else 0 end) catalog_only - ,sum(case when ssci.customer_sk is not null and csci.customer_sk is not null then 1 else 0 end) store_and_catalog -from ssci full outer join csci on (ssci.customer_sk=csci.customer_sk - and ssci.item_sk = csci.item_sk) -limit 100; - --- end template query97.tpl query 81 in stream 2 --- start template query33.tpl query 82 in stream 2 -with /* TPC-DS query33.tpl 0.22 */ ss as ( - select - i_manufact_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Home')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 6 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_manufact_id), - cs as ( - select - i_manufact_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Home')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 6 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_manufact_id), - ws as ( - select - i_manufact_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Home')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 6 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_manufact_id) - select i_manufact_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_manufact_id - order by total_sales -limit 100; - --- end template query33.tpl query 82 in stream 2 --- start template query79.tpl query 83 in stream 2 -select /* TPC-DS query79.tpl 0.89 */ - c_last_name,c_first_name,substring(s_city,1,30),ss_ticket_number,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,store.s_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (household_demographics.hd_dep_count = 8 or household_demographics.hd_vehicle_count > 4) - and date_dim.d_dow = 1 - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_number_employees between 200 and 295 - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,store.s_city) ms,customer - where ss_customer_sk = c_customer_sk - order by c_last_name,c_first_name,substring(s_city,1,30), profit -limit 100; - --- end template query79.tpl query 83 in stream 2 --- start template query32.tpl query 84 in stream 2 -select /* TPC-DS query32.tpl 0.7 */ sum(cs_ext_discount_amt) as "excess discount amount" -from - catalog_sales - ,item - ,date_dim -where -i_manufact_id = 166 -and i_item_sk = cs_item_sk -and d_date between '2002-03-12' and - dateadd(day,90,cast('2002-03-12' as date)) -and d_date_sk = cs_sold_date_sk -and cs_ext_discount_amt - > ( - select - 1.3 * avg(cs_ext_discount_amt) - from - catalog_sales - ,date_dim - where - cs_item_sk = i_item_sk - and d_date between '2002-03-12' and - dateadd(day,90,cast('2002-03-12' as date)) - and d_date_sk = cs_sold_date_sk - ) -limit 100; - --- end template query32.tpl query 84 in stream 2 --- start template query78.tpl query 85 in stream 2 -with /* TPC-DS query78.tpl 0.10 */ ws as - (select d_year AS ws_sold_year, ws_item_sk, - ws_bill_customer_sk ws_customer_sk, - sum(ws_quantity) ws_qty, - sum(ws_wholesale_cost) ws_wc, - sum(ws_sales_price) ws_sp - from web_sales - left join web_returns on wr_order_number=ws_order_number and ws_item_sk=wr_item_sk - join date_dim on ws_sold_date_sk = d_date_sk - where wr_order_number is null - group by d_year, ws_item_sk, ws_bill_customer_sk - ), -cs as - (select d_year AS cs_sold_year, cs_item_sk, - cs_bill_customer_sk cs_customer_sk, - sum(cs_quantity) cs_qty, - sum(cs_wholesale_cost) cs_wc, - sum(cs_sales_price) cs_sp - from catalog_sales - left join catalog_returns on cr_order_number=cs_order_number and cs_item_sk=cr_item_sk - join date_dim on cs_sold_date_sk = d_date_sk - where cr_order_number is null - group by d_year, cs_item_sk, cs_bill_customer_sk - ), -ss as - (select d_year AS ss_sold_year, ss_item_sk, - ss_customer_sk, - sum(ss_quantity) ss_qty, - sum(ss_wholesale_cost) ss_wc, - sum(ss_sales_price) ss_sp - from store_sales - left join store_returns on sr_ticket_number=ss_ticket_number and ss_item_sk=sr_item_sk - join date_dim on ss_sold_date_sk = d_date_sk - where sr_ticket_number is null - group by d_year, ss_item_sk, ss_customer_sk - ) - select -ss_item_sk, -round(ss_qty/(coalesce(ws_qty,0)+coalesce(cs_qty,0)),2) ratio, -ss_qty store_qty, ss_wc store_wholesale_cost, ss_sp store_sales_price, -coalesce(ws_qty,0)+coalesce(cs_qty,0) other_chan_qty, -coalesce(ws_wc,0)+coalesce(cs_wc,0) other_chan_wholesale_cost, -coalesce(ws_sp,0)+coalesce(cs_sp,0) other_chan_sales_price -from ss -left join ws on (ws_sold_year=ss_sold_year and ws_item_sk=ss_item_sk and ws_customer_sk=ss_customer_sk) -left join cs on (cs_sold_year=ss_sold_year and cs_item_sk=ss_item_sk and cs_customer_sk=ss_customer_sk) -where (coalesce(ws_qty,0)>0 or coalesce(cs_qty, 0)>0) and ss_sold_year=2001 -order by - ss_item_sk, - ss_qty desc, ss_wc desc, ss_sp desc, - other_chan_qty, - other_chan_wholesale_cost, - other_chan_sales_price, - ratio -limit 100; - --- end template query78.tpl query 85 in stream 2 --- start template query18a.tpl query 86 in stream 2 -with /* TPC-DS query18a.tpl 0.90 */ results as - (select i_item_id, - ca_country, - ca_state, - ca_county, - cast(cs_quantity as decimal(12,2)) agg1, - cast(cs_list_price as decimal(12,2)) agg2, - cast(cs_coupon_amt as decimal(12,2)) agg3, - cast(cs_sales_price as decimal(12,2)) agg4, - cast(cs_net_profit as decimal(12,2)) agg5, - cast(c_birth_year as decimal(12,2)) agg6, - cast(cd1.cd_dep_count as decimal(12,2)) agg7 - from catalog_sales, customer_demographics cd1, customer_demographics cd2, customer, customer_address, date_dim, item - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd1.cd_demo_sk and - cs_bill_customer_sk = c_customer_sk and - cd1.cd_gender = 'F' and - cd1.cd_education_status = 'Unknown' and - c_current_cdemo_sk = cd2.cd_demo_sk and - c_current_addr_sk = ca_address_sk and - c_birth_month in (1,4,12,11,5,10) and - d_year = 2000 and - ca_state in ('MS','GA','CO','NE','MO','NC','MD') - ) - select i_item_id, ca_country, ca_state, ca_county, agg1, agg2, agg3, agg4, agg5, agg6, agg7 - from ( - select i_item_id, ca_country, ca_state, ca_county, avg(agg1) agg1, - avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state, ca_county - union all - select i_item_id, ca_country, ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state - union all - select i_item_id, ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country - union all - select i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - ) foo - order by ca_country, ca_state, ca_county, i_item_id - limit 100; - --- end template query18a.tpl query 86 in stream 2 --- start template query65.tpl query 87 in stream 2 -select /* TPC-DS query65.tpl 0.71 */ - s_store_name, - i_item_desc, - sc.revenue, - i_current_price, - i_wholesale_cost, - i_brand - from store, item, - (select ss_store_sk, avg(revenue) as ave - from - (select ss_store_sk, ss_item_sk, - sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1197 and 1197+11 - group by ss_store_sk, ss_item_sk) sa - group by ss_store_sk) sb, - (select ss_store_sk, ss_item_sk, sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1197 and 1197+11 - group by ss_store_sk, ss_item_sk) sc - where sb.ss_store_sk = sc.ss_store_sk and - sc.revenue <= 0.1 * sb.ave and - s_store_sk = sc.ss_store_sk and - i_item_sk = sc.ss_item_sk - order by s_store_name, i_item_desc -limit 100; - --- end template query65.tpl query 87 in stream 2 --- start template query60.tpl query 88 in stream 2 -with /* TPC-DS query60.tpl 0.29 */ ss as ( - select - i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Men')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 9 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id), - cs as ( - select - i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Men')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 9 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id), - ws as ( - select - i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Men')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 9 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id) - select - i_item_id -,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by i_item_id - ,total_sales - limit 100; - --- end template query60.tpl query 88 in stream 2 --- start template query34.tpl query 89 in stream 2 -select /* TPC-DS query34.tpl 0.73 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (date_dim.d_dom between 1 and 3 or date_dim.d_dom between 25 and 28) - and (household_demographics.hd_buy_potential = '501-1000' or - household_demographics.hd_buy_potential = '0-500') - and household_demographics.hd_vehicle_count > 0 - and (case when household_demographics.hd_vehicle_count > 0 - then household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count - else null - end) > 1.2 - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_county in ('Boone County','Union County','Hancock County','Forsyth County', - 'Fentress County','Hartley County','Marshall County','Calhoun County') - group by ss_ticket_number,ss_customer_sk) dn,customer - where ss_customer_sk = c_customer_sk - and cnt between 15 and 20 - order by c_last_name,c_first_name,c_salutation,c_preferred_cust_flag desc, ss_ticket_number; - --- end template query34.tpl query 89 in stream 2 --- start template query3.tpl query 90 in stream 2 -select /* TPC-DS query3.tpl 0.45 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_sales_price) sum_agg - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manufact_id = 350 - and dt.d_moy=11 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,sum_agg desc - ,brand_id - limit 100; - --- end template query3.tpl query 90 in stream 2 --- start template query13.tpl query 91 in stream 2 -select /* TPC-DS query13.tpl 0.91 */ avg(ss_quantity) - ,avg(ss_ext_sales_price) - ,avg(ss_ext_wholesale_cost) - ,sum(ss_ext_wholesale_cost) - from store_sales - ,store - ,customer_demographics - ,household_demographics - ,customer_address - ,date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2001 - and((ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'D' - and cd_education_status = 'Unknown' - and ss_sales_price between 100.00 and 150.00 - and hd_dep_count = 3 - )or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'M' - and cd_education_status = 'Advanced Degree' - and ss_sales_price between 50.00 and 100.00 - and hd_dep_count = 1 - ) or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'W' - and cd_education_status = 'Secondary' - and ss_sales_price between 150.00 and 200.00 - and hd_dep_count = 1 - )) - and((ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('LA', 'MO', 'GA') - and ss_net_profit between 100 and 200 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('TX', 'ID', 'NY') - and ss_net_profit between 150 and 300 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('IA', 'CA', 'OK') - and ss_net_profit between 50 and 250 - )) -; - --- end template query13.tpl query 91 in stream 2 --- start template query41.tpl query 92 in stream 2 -select /* TPC-DS query41.tpl 0.62 */ distinct(i_product_name) - from item i1 - where i_manufact_id between 818 and 818+40 - and (select count(*) as item_cnt - from item - where (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'orchid' or i_color = 'gainsboro') and - (i_units = 'Tbl' or i_units = 'Unknown') and - (i_size = 'petite' or i_size = 'extra large') - ) or - (i_category = 'Women' and - (i_color = 'saddle' or i_color = 'lime') and - (i_units = 'Box' or i_units = 'Tsp') and - (i_size = 'small' or i_size = 'medium') - ) or - (i_category = 'Men' and - (i_color = 'salmon' or i_color = 'frosted') and - (i_units = 'Each' or i_units = 'Pound') and - (i_size = 'large' or i_size = 'economy') - ) or - (i_category = 'Men' and - (i_color = 'tomato' or i_color = 'lawn') and - (i_units = 'Gram' or i_units = 'Ton') and - (i_size = 'petite' or i_size = 'extra large') - ))) or - (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'olive' or i_color = 'purple') and - (i_units = 'Carton' or i_units = 'Dozen') and - (i_size = 'petite' or i_size = 'extra large') - ) or - (i_category = 'Women' and - (i_color = 'lavender' or i_color = 'orange') and - (i_units = 'Ounce' or i_units = 'Dram') and - (i_size = 'small' or i_size = 'medium') - ) or - (i_category = 'Men' and - (i_color = 'cyan' or i_color = 'tan') and - (i_units = 'Bundle' or i_units = 'Gross') and - (i_size = 'large' or i_size = 'economy') - ) or - (i_category = 'Men' and - (i_color = 'rosy' or i_color = 'misty') and - (i_units = 'Oz' or i_units = 'Cup') and - (i_size = 'petite' or i_size = 'extra large') - )))) > 0 - order by i_product_name - limit 100; - --- end template query41.tpl query 92 in stream 2 --- start template query92.tpl query 93 in stream 2 -select /* TPC-DS query92.tpl 0.44 */ - sum(ws_ext_discount_amt) as "Excess Discount Amount" -from - web_sales - ,item - ,date_dim -where -i_manufact_id = 907 -and i_item_sk = ws_item_sk -and d_date between '1998-03-16' and - dateadd(day,90,cast('1998-03-16' as date)) -and d_date_sk = ws_sold_date_sk -and ws_ext_discount_amt - > ( - SELECT - 1.3 * avg(ws_ext_discount_amt) - FROM - web_sales - ,date_dim - WHERE - ws_item_sk = i_item_sk - and d_date between '1998-03-16' and - dateadd(day,90,cast('1998-03-16' as date)) - and d_date_sk = ws_sold_date_sk - ) -order by sum(ws_ext_discount_amt) -limit 100; - --- end template query92.tpl query 93 in stream 2 --- start template query74.tpl query 94 in stream 2 -with /* TPC-DS query74.tpl 0.76 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,min(ss_net_paid) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1998,1998+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,min(ws_net_paid) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - and d_year in (1998,1998+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - ) - select - t_s_secyear.customer_id, t_s_secyear.customer_first_name, t_s_secyear.customer_last_name - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.year = 1998 - and t_s_secyear.year = 1998+1 - and t_w_firstyear.year = 1998 - and t_w_secyear.year = 1998+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - order by 3,2,1 -limit 100; - --- end template query74.tpl query 94 in stream 2 --- start template query46.tpl query 95 in stream 2 -select /* TPC-DS query46.tpl 0.23 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and (household_demographics.hd_dep_count = 8 or - household_demographics.hd_vehicle_count= -1) - and date_dim.d_dow in (6,0) - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_city in ('Buena Vista','Verona','Salem','Perryville','Oak Ridge') - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,ca_city) dn,customer,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - limit 100; - --- end template query46.tpl query 95 in stream 2 --- start template query89.tpl query 96 in stream 2 -select /* TPC-DS query89.tpl 0.56 */ * -from( -select i_category, i_class, i_brand, - s_store_name, s_company_name, - d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, s_store_name, s_company_name) - avg_monthly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - d_year in (2001) and - ((i_category in ('Books','Home','Children') and - i_class in ('history','paint','newborn') - ) - or (i_category in ('Music','Shoes','Electronics') and - i_class in ('pop','athletic','stereo') - )) -group by i_category, i_class, i_brand, - s_store_name, s_company_name, d_moy) tmp1 -where case when (avg_monthly_sales <> 0) then (abs(sum_sales - avg_monthly_sales) / avg_monthly_sales) else null end > 0.1 -order by sum_sales - avg_monthly_sales, s_store_name -limit 100; - --- end template query89.tpl query 96 in stream 2 --- start template query47.tpl query 97 in stream 2 -with /* TPC-DS query47.tpl 0.42 */ v1 as( - select i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, - s_store_name, s_company_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - s_store_name, s_company_name - order by d_year, d_moy) rn - from item, store_sales, date_dim, store - where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - ( - d_year = 2001 or - ( d_year = 2001-1 and d_moy =12) or - ( d_year = 2001+1 and d_moy =1) - ) - group by i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy), - v2 as( - select v1.i_category, v1.i_brand, v1.s_store_name, v1.s_company_name - ,v1.d_year - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1.s_store_name = v1_lag.s_store_name and - v1.s_store_name = v1_lead.s_store_name and - v1.s_company_name = v1_lag.s_company_name and - v1.s_company_name = v1_lead.s_company_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 2001 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, psum - limit 100; - --- end template query47.tpl query 97 in stream 2 --- start template query66.tpl query 98 in stream 2 -select /* TPC-DS query66.tpl 0.39 */ - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - ,sum(jan_sales) as jan_sales - ,sum(feb_sales) as feb_sales - ,sum(mar_sales) as mar_sales - ,sum(apr_sales) as apr_sales - ,sum(may_sales) as may_sales - ,sum(jun_sales) as jun_sales - ,sum(jul_sales) as jul_sales - ,sum(aug_sales) as aug_sales - ,sum(sep_sales) as sep_sales - ,sum(oct_sales) as oct_sales - ,sum(nov_sales) as nov_sales - ,sum(dec_sales) as dec_sales - ,sum(jan_sales/w_warehouse_sq_ft) as jan_sales_per_sq_foot - ,sum(feb_sales/w_warehouse_sq_ft) as feb_sales_per_sq_foot - ,sum(mar_sales/w_warehouse_sq_ft) as mar_sales_per_sq_foot - ,sum(apr_sales/w_warehouse_sq_ft) as apr_sales_per_sq_foot - ,sum(may_sales/w_warehouse_sq_ft) as may_sales_per_sq_foot - ,sum(jun_sales/w_warehouse_sq_ft) as jun_sales_per_sq_foot - ,sum(jul_sales/w_warehouse_sq_ft) as jul_sales_per_sq_foot - ,sum(aug_sales/w_warehouse_sq_ft) as aug_sales_per_sq_foot - ,sum(sep_sales/w_warehouse_sq_ft) as sep_sales_per_sq_foot - ,sum(oct_sales/w_warehouse_sq_ft) as oct_sales_per_sq_foot - ,sum(nov_sales/w_warehouse_sq_ft) as nov_sales_per_sq_foot - ,sum(dec_sales/w_warehouse_sq_ft) as dec_sales_per_sq_foot - ,sum(jan_net) as jan_net - ,sum(feb_net) as feb_net - ,sum(mar_net) as mar_net - ,sum(apr_net) as apr_net - ,sum(may_net) as may_net - ,sum(jun_net) as jun_net - ,sum(jul_net) as jul_net - ,sum(aug_net) as aug_net - ,sum(sep_net) as sep_net - ,sum(oct_net) as oct_net - ,sum(nov_net) as nov_net - ,sum(dec_net) as dec_net - from ( - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'BOXBUNDLES' || ',' || 'DIAMOND' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then ws_ext_sales_price* ws_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then ws_ext_sales_price* ws_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then ws_ext_sales_price* ws_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then ws_ext_sales_price* ws_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then ws_ext_sales_price* ws_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then ws_ext_sales_price* ws_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then ws_ext_sales_price* ws_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then ws_ext_sales_price* ws_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then ws_ext_sales_price* ws_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then ws_ext_sales_price* ws_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then ws_ext_sales_price* ws_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then ws_ext_sales_price* ws_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as dec_net - from - web_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - ws_warehouse_sk = w_warehouse_sk - and ws_sold_date_sk = d_date_sk - and ws_sold_time_sk = t_time_sk - and ws_ship_mode_sk = sm_ship_mode_sk - and d_year = 2002 - and t_time between 15670 and 15670+28800 - and sm_carrier in ('BOXBUNDLES','DIAMOND') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - union all - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'BOXBUNDLES' || ',' || 'DIAMOND' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then cs_ext_sales_price* cs_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then cs_ext_sales_price* cs_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then cs_ext_sales_price* cs_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then cs_ext_sales_price* cs_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then cs_ext_sales_price* cs_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then cs_ext_sales_price* cs_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then cs_ext_sales_price* cs_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then cs_ext_sales_price* cs_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then cs_ext_sales_price* cs_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then cs_ext_sales_price* cs_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then cs_ext_sales_price* cs_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then cs_ext_sales_price* cs_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as dec_net - from - catalog_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and cs_sold_time_sk = t_time_sk - and cs_ship_mode_sk = sm_ship_mode_sk - and d_year = 2002 - and t_time between 15670 AND 15670+28800 - and sm_carrier in ('BOXBUNDLES','DIAMOND') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - ) x - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - order by w_warehouse_name - limit 100; - --- end template query66.tpl query 98 in stream 2 --- start template query48.tpl query 99 in stream 2 -select /* TPC-DS query48.tpl 0.74 */ sum (ss_quantity) - from store_sales, store, customer_demographics, customer_address, date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 1998 - and - ( - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'S' - and - cd_education_status = 'College' - and - ss_sales_price between 100.00 and 150.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'W' - and - cd_education_status = '2 yr Degree' - and - ss_sales_price between 50.00 and 100.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'D' - and - cd_education_status = 'Secondary' - and - ss_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('AL', 'MO', 'SD') - and ss_net_profit between 0 and 2000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('VT', 'NE', 'MS') - and ss_net_profit between 150 and 3000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('TX', 'NC', 'LA') - and ss_net_profit between 50 and 25000 - ) - ) -; - --- end template query48.tpl query 99 in stream 2 diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/100TB/queries/query_3.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/100TB/queries/query_3.sql deleted file mode 100644 index 91e632ce..00000000 --- a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/100TB/queries/query_3.sql +++ /dev/null @@ -1,5027 +0,0 @@ --- start template query89.tpl query 1 in stream 3 -select /* TPC-DS query89.tpl 0.56 */ * -from( -select i_category, i_class, i_brand, - s_store_name, s_company_name, - d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, s_store_name, s_company_name) - avg_monthly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - d_year in (1998) and - ((i_category in ('Electronics','Women','Books') and - i_class in ('dvd/vcr players','fragrances','cooking') - ) - or (i_category in ('Sports','Children','Jewelry') and - i_class in ('optics','toddlers','bracelets') - )) -group by i_category, i_class, i_brand, - s_store_name, s_company_name, d_moy) tmp1 -where case when (avg_monthly_sales <> 0) then (abs(sum_sales - avg_monthly_sales) / avg_monthly_sales) else null end > 0.1 -order by sum_sales - avg_monthly_sales, s_store_name -limit 100; - --- end template query89.tpl query 1 in stream 3 --- start template query5a.tpl query 2 in stream 3 -with /* TPC-DS query5a.tpl 0.98 */ ssr as - (select s_store_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ss_store_sk as store_sk, - ss_sold_date_sk as date_sk, - ss_ext_sales_price as sales_price, - ss_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from store_sales - union all - select sr_store_sk as store_sk, - sr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - sr_return_amt as return_amt, - sr_net_loss as net_loss - from store_returns - ) salesreturns, - date_dim, - store - where date_sk = d_date_sk - and d_date between cast('1999-08-17' as date) - and dateadd(day,14,cast('1999-08-17' as date)) - and store_sk = s_store_sk - group by s_store_id) - , - csr as - (select cp_catalog_page_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select cs_catalog_page_sk as page_sk, - cs_sold_date_sk as date_sk, - cs_ext_sales_price as sales_price, - cs_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from catalog_sales - union all - select cr_catalog_page_sk as page_sk, - cr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - cr_return_amount as return_amt, - cr_net_loss as net_loss - from catalog_returns - ) salesreturns, - date_dim, - catalog_page - where date_sk = d_date_sk - and d_date between cast('1999-08-17' as date) - and dateadd(day,14,cast('1999-08-17' as date)) - and page_sk = cp_catalog_page_sk - group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ws_web_site_sk as wsr_web_site_sk, - ws_sold_date_sk as date_sk, - ws_ext_sales_price as sales_price, - ws_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from web_sales - union all - select ws_web_site_sk as wsr_web_site_sk, - wr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - wr_return_amt as return_amt, - wr_net_loss as net_loss - from web_returns left outer join web_sales on - ( wr_item_sk = ws_item_sk - and wr_order_number = ws_order_number) - ) salesreturns, - date_dim, - web_site - where date_sk = d_date_sk - and d_date between cast('1999-08-17' as date) - and dateadd(day,14,cast('1999-08-17' as date)) - and wsr_web_site_sk = web_site_sk - group by web_site_id) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || s_store_id as id - , sales - , returns - , (profit - profit_loss) as profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || cp_catalog_page_id as id - , sales - , returns - , (profit - profit_loss) as profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , (profit - profit_loss) as profit - from wsr - ) x - group by channel, id) - select channel, id, sales, returns, profit from ( - select channel, id, sales, returns, profit from results - union - select channel, null as id, sum(sales), sum(returns), sum(profit) from results group by channel - union - select null as channel, null as id, sum(sales), sum(returns), sum(profit) from results) foo -order by channel, id -limit 100; - --- end template query5a.tpl query 2 in stream 3 --- start template query52.tpl query 3 in stream 3 -select /* TPC-DS query52.tpl 0.59 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_sales_price) ext_price - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=11 - and dt.d_year=1999 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,ext_price desc - ,brand_id -limit 100 ; - --- end template query52.tpl query 3 in stream 3 --- start template query62.tpl query 4 in stream 3 -select /* TPC-DS query62.tpl 0.24 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 30) and - (ws_ship_date_sk - ws_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 60) and - (ws_ship_date_sk - ws_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 90) and - (ws_ship_date_sk - ws_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - web_sales - ,warehouse - ,ship_mode - ,web_site - ,date_dim -where - d_month_seq between 1198 and 1198 + 11 -and ws_ship_date_sk = d_date_sk -and ws_warehouse_sk = w_warehouse_sk -and ws_ship_mode_sk = sm_ship_mode_sk -and ws_web_site_sk = web_site_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -limit 100; - --- end template query62.tpl query 4 in stream 3 --- start template query53.tpl query 5 in stream 3 -select /* TPC-DS query53.tpl 0.88 */ * from -(select i_manufact_id, -sum(ss_sales_price) sum_sales, -avg(sum(ss_sales_price)) over (partition by i_manufact_id) avg_quarterly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and -ss_sold_date_sk = d_date_sk and -ss_store_sk = s_store_sk and -d_month_seq in (1224,1224+1,1224+2,1224+3,1224+4,1224+5,1224+6,1224+7,1224+8,1224+9,1224+10,1224+11) and -((i_category in ('Books','Children','Electronics') and -i_class in ('personal','portable','reference','self-help') and -i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) -or(i_category in ('Women','Music','Men') and -i_class in ('accessories','classical','fragrances','pants') and -i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manufact_id, d_qoy ) tmp1 -where case when avg_quarterly_sales > 0 - then abs (sum_sales - avg_quarterly_sales)/ avg_quarterly_sales - else null end > 0.1 -order by avg_quarterly_sales, - sum_sales, - i_manufact_id -limit 100; - --- end template query53.tpl query 5 in stream 3 --- start template query7.tpl query 6 in stream 3 -select /* TPC-DS query7.tpl 0.2 */ i_item_id, - avg(ss_quantity) agg1, - avg(ss_list_price) agg2, - avg(ss_coupon_amt) agg3, - avg(ss_sales_price) agg4 - from store_sales, customer_demographics, date_dim, item, promotion - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_cdemo_sk = cd_demo_sk and - ss_promo_sk = p_promo_sk and - cd_gender = 'F' and - cd_marital_status = 'U' and - cd_education_status = 'Primary' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 2001 - group by i_item_id - order by i_item_id - limit 100; - --- end template query7.tpl query 6 in stream 3 --- start template query39.tpl query 7 in stream 3 -with /* TPC-DS query39.tpl 0.5 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =1999 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=4 - and inv2.d_moy=4+1 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; -with /* TPC-DS query39.tpl 0.5 part2 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =1999 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=4 - and inv2.d_moy=4+1 - and inv1.cov > 1.5 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; - --- end template query39.tpl query 7 in stream 3 --- start template query80a.tpl query 8 in stream 3 -with /* TPC-DS query80a.tpl 0.6 */ ssr as - (select s_store_id as store_id, - sum(ss_ext_sales_price) as sales, - sum(coalesce(sr_return_amt, 0)) as returns, - sum(ss_net_profit - coalesce(sr_net_loss, 0)) as profit - from store_sales left outer join store_returns on - (ss_item_sk = sr_item_sk and ss_ticket_number = sr_ticket_number), - date_dim, - store, - item, - promotion - where ss_sold_date_sk = d_date_sk - and d_date between cast('2000-08-21' as date) - and dateadd(day,30,cast('2000-08-21' as date)) - and ss_store_sk = s_store_sk - and ss_item_sk = i_item_sk - and i_current_price > 50 - and ss_promo_sk = p_promo_sk - and p_channel_tv = 'N' - group by s_store_id) - , - csr as - (select cp_catalog_page_id as catalog_page_id, - sum(cs_ext_sales_price) as sales, - sum(coalesce(cr_return_amount, 0)) as returns, - sum(cs_net_profit - coalesce(cr_net_loss, 0)) as profit - from catalog_sales left outer join catalog_returns on - (cs_item_sk = cr_item_sk and cs_order_number = cr_order_number), - date_dim, - catalog_page, - item, - promotion - where cs_sold_date_sk = d_date_sk - and d_date between cast('2000-08-21' as date) - and dateadd(day,30,cast('2000-08-21' as date)) - and cs_catalog_page_sk = cp_catalog_page_sk - and cs_item_sk = i_item_sk - and i_current_price > 50 - and cs_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(ws_ext_sales_price) as sales, - sum(coalesce(wr_return_amt, 0)) as returns, - sum(ws_net_profit - coalesce(wr_net_loss, 0)) as profit - from web_sales left outer join web_returns on - (ws_item_sk = wr_item_sk and ws_order_number = wr_order_number), - date_dim, - web_site, - item, - promotion - where ws_sold_date_sk = d_date_sk - and d_date between cast('2000-08-21' as date) - and dateadd(day,30,cast('2000-08-21' as date)) - and ws_web_site_sk = web_site_sk - and ws_item_sk = i_item_sk - and i_current_price > 50 - and ws_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by web_site_id) -, -results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || store_id as id - , sales - , returns - , profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || catalog_page_id as id - , sales - , returns - , profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , profit - from wsr - ) x - group by channel, id) - - select channel - , id - , sales - , returns - , profit - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results - ) foo - order by channel, id - limit 100; - --- end template query80a.tpl query 8 in stream 3 --- start template query63.tpl query 9 in stream 3 -select /* TPC-DS query63.tpl 0.27 */ * -from (select i_manager_id - ,sum(ss_sales_price) sum_sales - ,avg(sum(ss_sales_price)) over (partition by i_manager_id) avg_monthly_sales - from item - ,store_sales - ,date_dim - ,store - where ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and d_month_seq in (1187,1187+1,1187+2,1187+3,1187+4,1187+5,1187+6,1187+7,1187+8,1187+9,1187+10,1187+11) - and (( i_category in ('Books','Children','Electronics') - and i_class in ('personal','portable','reference','self-help') - and i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) - or( i_category in ('Women','Music','Men') - and i_class in ('accessories','classical','fragrances','pants') - and i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manager_id, d_moy) tmp1 -where case when avg_monthly_sales > 0 then abs (sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 -order by i_manager_id - ,avg_monthly_sales - ,sum_sales -limit 100; - --- end template query63.tpl query 9 in stream 3 --- start template query72.tpl query 10 in stream 3 -select /* TPC-DS query72.tpl 0.87 */ i_item_desc - ,w_warehouse_name - ,d1.d_week_seq - ,sum(case when p_promo_sk is null then 1 else 0 end) no_promo - ,sum(case when p_promo_sk is not null then 1 else 0 end) promo - ,count(*) total_cnt -from catalog_sales -join inventory on (cs_item_sk = inv_item_sk) -join warehouse on (w_warehouse_sk=inv_warehouse_sk) -join item on (i_item_sk = cs_item_sk) -join customer_demographics on (cs_bill_cdemo_sk = cd_demo_sk) -join household_demographics on (cs_bill_hdemo_sk = hd_demo_sk) -join date_dim d1 on (cs_sold_date_sk = d1.d_date_sk) -join date_dim d2 on (inv_date_sk = d2.d_date_sk) -join date_dim d3 on (cs_ship_date_sk = d3.d_date_sk) -left outer join promotion on (cs_promo_sk=p_promo_sk) -left outer join catalog_returns on (cr_item_sk = cs_item_sk and cr_order_number = cs_order_number) -where d1.d_week_seq = d2.d_week_seq - and inv_quantity_on_hand < cs_quantity - and d3.d_date > d1.d_date + 5 - and hd_buy_potential = '>10000' - and d1.d_year = 1998 - and cd_marital_status = 'M' -group by i_item_desc,w_warehouse_name,d1.d_week_seq -order by total_cnt desc, i_item_desc, w_warehouse_name, d_week_seq -limit 100; - --- end template query72.tpl query 10 in stream 3 --- start template query18a.tpl query 11 in stream 3 -with /* TPC-DS query18a.tpl 0.90 */ results as - (select i_item_id, - ca_country, - ca_state, - ca_county, - cast(cs_quantity as decimal(12,2)) agg1, - cast(cs_list_price as decimal(12,2)) agg2, - cast(cs_coupon_amt as decimal(12,2)) agg3, - cast(cs_sales_price as decimal(12,2)) agg4, - cast(cs_net_profit as decimal(12,2)) agg5, - cast(c_birth_year as decimal(12,2)) agg6, - cast(cd1.cd_dep_count as decimal(12,2)) agg7 - from catalog_sales, customer_demographics cd1, customer_demographics cd2, customer, customer_address, date_dim, item - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd1.cd_demo_sk and - cs_bill_customer_sk = c_customer_sk and - cd1.cd_gender = 'M' and - cd1.cd_education_status = 'Primary' and - c_current_cdemo_sk = cd2.cd_demo_sk and - c_current_addr_sk = ca_address_sk and - c_birth_month in (12,5,11,7,1,3) and - d_year = 1998 and - ca_state in ('AL','FL','MD','NY','NC','TX','SC') - ) - select i_item_id, ca_country, ca_state, ca_county, agg1, agg2, agg3, agg4, agg5, agg6, agg7 - from ( - select i_item_id, ca_country, ca_state, ca_county, avg(agg1) agg1, - avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state, ca_county - union all - select i_item_id, ca_country, ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state - union all - select i_item_id, ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country - union all - select i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - ) foo - order by ca_country, ca_state, ca_county, i_item_id - limit 100; - --- end template query18a.tpl query 11 in stream 3 --- start template query56.tpl query 12 in stream 3 -with /* TPC-DS query56.tpl 0.83 */ ss as ( - select i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where i_item_id in (select - i_item_id -from item -where i_color in ('lime','maroon','brown')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 5 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id), - cs as ( - select i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('lime','maroon','brown')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 5 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id), - ws as ( - select i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('lime','maroon','brown')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 5 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id) - select i_item_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by total_sales, - i_item_id - limit 100; - --- end template query56.tpl query 12 in stream 3 --- start template query13.tpl query 13 in stream 3 -select /* TPC-DS query13.tpl 0.91 */ avg(ss_quantity) - ,avg(ss_ext_sales_price) - ,avg(ss_ext_wholesale_cost) - ,sum(ss_ext_wholesale_cost) - from store_sales - ,store - ,customer_demographics - ,household_demographics - ,customer_address - ,date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2001 - and((ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'D' - and cd_education_status = '4 yr Degree' - and ss_sales_price between 100.00 and 150.00 - and hd_dep_count = 3 - )or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'W' - and cd_education_status = 'Primary' - and ss_sales_price between 50.00 and 100.00 - and hd_dep_count = 1 - ) or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'S' - and cd_education_status = 'College' - and ss_sales_price between 150.00 and 200.00 - and hd_dep_count = 1 - )) - and((ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('VA', 'CA', 'OH') - and ss_net_profit between 100 and 200 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('MO', 'HI', 'IN') - and ss_net_profit between 150 and 300 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('WV', 'GA', 'IL') - and ss_net_profit between 50 and 250 - )) -; - --- end template query13.tpl query 13 in stream 3 --- start template query69.tpl query 14 in stream 3 -select /* TPC-DS query69.tpl 0.28 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_state in ('OH','IN','NY') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2003 and - d_moy between 2 and 2+2) and - (not exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2003 and - d_moy between 2 and 2+2) and - not exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2003 and - d_moy between 2 and 2+2)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - limit 100; - --- end template query69.tpl query 14 in stream 3 --- start template query23.tpl query 15 in stream 3 -with /* TPC-DS query23.tpl 0.68 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (1999,1999+1,1999+2,1999+3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1999,1999+1,1999+2,1999+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * -from - max_store_sales)) - select sum(sales) - from (select cs_quantity*cs_list_price sales - from catalog_sales - ,date_dim - where d_year = 1999 - and d_moy = 5 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - union all - select ws_quantity*ws_list_price sales - from web_sales - ,date_dim - where d_year = 1999 - and d_moy = 5 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer)) - limit 100; -with /* TPC-DS query23.tpl 0.68 part2 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (1999,1999 + 1,1999 + 2,1999 + 3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1999,1999+1,1999+2,1999+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * - from max_store_sales)) - select c_last_name,c_first_name,sales - from (select c_last_name,c_first_name,sum(cs_quantity*cs_list_price) sales - from catalog_sales - ,customer - ,date_dim - where d_year = 1999 - and d_moy = 5 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and cs_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name - union all - select c_last_name,c_first_name,sum(ws_quantity*ws_list_price) sales - from web_sales - ,customer - ,date_dim - where d_year = 1999 - and d_moy = 5 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and ws_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name) - order by c_last_name,c_first_name,sales - limit 100; - --- end template query23.tpl query 15 in stream 3 --- start template query19.tpl query 16 in stream 3 -select /* TPC-DS query19.tpl 0.8 */ i_brand_id brand_id, i_brand brand, i_manufact_id, i_manufact, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item,customer,customer_address,store - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=56 - and d_moy=11 - and d_year=2002 - and ss_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and substring(ca_zip,1,5) <> substring(s_zip,1,5) - and ss_store_sk = s_store_sk - group by i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact - order by ext_price desc - ,i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact -limit 100 ; - --- end template query19.tpl query 16 in stream 3 --- start template query74.tpl query 17 in stream 3 -with /* TPC-DS query74.tpl 0.76 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,stddev_samp(ss_net_paid) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (2001,2001+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,stddev_samp(ws_net_paid) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - and d_year in (2001,2001+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - ) - select - t_s_secyear.customer_id, t_s_secyear.customer_first_name, t_s_secyear.customer_last_name - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.year = 2001 - and t_s_secyear.year = 2001+1 - and t_w_firstyear.year = 2001 - and t_w_secyear.year = 2001+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - order by 2,1,3 -limit 100; - --- end template query74.tpl query 17 in stream 3 --- start template query30.tpl query 18 in stream 3 -with /* TPC-DS query30.tpl 0.75 */ customer_total_return as - (select wr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(wr_return_amt) as ctr_total_return - from web_returns - ,date_dim - ,customer_address - where wr_returned_date_sk = d_date_sk - and d_year =2002 - and wr_returning_addr_sk = ca_address_sk - group by wr_returning_customer_sk - ,ca_state) - select c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'KS' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return -limit 100; - --- end template query30.tpl query 18 in stream 3 --- start template query84.tpl query 19 in stream 3 -select /* TPC-DS query84.tpl 0.80 */ c_customer_id as customer_id - , coalesce(c_last_name,'') || ', ' || coalesce(c_first_name,'') as customername - from customer - ,customer_address - ,customer_demographics - ,household_demographics - ,income_band - ,store_returns - where ca_city = 'Lakeside' - and c_current_addr_sk = ca_address_sk - and ib_lower_bound >= 51766 - and ib_upper_bound <= 51766 + 50000 - and ib_income_band_sk = hd_income_band_sk - and cd_demo_sk = c_current_cdemo_sk - and hd_demo_sk = c_current_hdemo_sk - and sr_cdemo_sk = cd_demo_sk - order by c_customer_id - limit 100; - --- end template query84.tpl query 19 in stream 3 --- start template query96.tpl query 20 in stream 3 -select /* TPC-DS query96.tpl 0.1 */ count(*) -from store_sales - ,household_demographics - ,time_dim, store -where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 16 - and time_dim.t_minute >= 30 - and household_demographics.hd_dep_count = 4 - and store.s_store_name = 'ese' -order by count(*) -limit 100; - --- end template query96.tpl query 20 in stream 3 --- start template query14a.tpl query 21 in stream 3 -with /* TPC-DS query14a.tpl 0.69 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1999 AND 1999 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1999 AND 1999 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1999 AND 1999 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as - (select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2) x) -, - results AS -(select channel, i_brand_id, i_class_id, i_category_id, sum(sales) sum_sales, sum(number_sales) number_sales - from ( - select 'store' channel, i_brand_id,i_class_id - ,i_category_id,sum(ss_quantity*ss_list_price) sales - , count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1999+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales) - union all - select 'catalog' channel, i_brand_id,i_class_id,i_category_id, sum(cs_quantity*cs_list_price) sales, count(*) number_sales - from catalog_sales - ,item - ,date_dim - where cs_item_sk in (select ss_item_sk from cross_items) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1999+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(cs_quantity*cs_list_price) > (select average_sales from avg_sales) - union all - select 'web' channel, i_brand_id,i_class_id,i_category_id, sum(ws_quantity*ws_list_price) sales , count(*) number_sales - from web_sales - ,item - ,date_dim - where ws_item_sk in (select ss_item_sk from cross_items) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1999+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ws_quantity*ws_list_price) > (select average_sales from avg_sales) - ) y - group by channel, i_brand_id,i_class_id,i_category_id) - - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales -from ( - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales from results - union - select channel, i_brand_id, i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id, i_class_id - union - select channel, i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id - union - select channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel - union - select null as channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results) z -order by channel, i_brand_id, i_class_id, i_category_id - limit 100; -with /* TPC-DS query14a.tpl 0.69 part2 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1999 AND 1999 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1999 AND 1999 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1999 AND 1999 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as -(select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2) x) - select this_year.channel ty_channel - ,this_year.i_brand_id ty_brand - ,this_year.i_class_id ty_class - ,this_year.i_category_id ty_category - ,this_year.sales ty_sales - ,this_year.number_sales ty_number_sales - ,last_year.channel ly_channel - ,last_year.i_brand_id ly_brand - ,last_year.i_class_id ly_class - ,last_year.i_category_id ly_category - ,last_year.sales ly_sales - ,last_year.number_sales ly_number_sales -from - (select 'store' channel, i_brand_id,i_class_id,i_category_id - ,sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1999 + 1 - and d_moy = 12 - and d_dom = 3) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) this_year, - (select 'store' channel, i_brand_id,i_class_id - ,i_category_id, sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1999 - and d_moy = 12 - and d_dom = 3) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) last_year - where this_year.i_brand_id= last_year.i_brand_id - and this_year.i_class_id = last_year.i_class_id - and this_year.i_category_id = last_year.i_category_id - order by this_year.channel, this_year.i_brand_id, this_year.i_class_id, this_year.i_category_id - limit 100; - --- end template query14a.tpl query 21 in stream 3 --- start template query10.tpl query 22 in stream 3 -select /* TPC-DS query10.tpl 0.26 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3, - cd_dep_count, - count(*) cnt4, - cd_dep_employed_count, - count(*) cnt5, - cd_dep_college_count, - count(*) cnt6 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_county in ('Arkansas County','Hoke County','Yukon-Koyukuk Census Area','Calhoun County','Polk County') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2001 and - d_moy between 4 and 4+3) and - (exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2001 and - d_moy between 4 ANd 4+3) or - exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2001 and - d_moy between 4 and 4+3)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count -limit 100; - --- end template query10.tpl query 22 in stream 3 --- start template query86a.tpl query 23 in stream 3 -with /* TPC-DS query86a.tpl 0.11 */ results as -( select sum(ws_net_paid) as total_sum, i_category, i_class, 0 as g_category, 0 as g_class - from - web_sales - ,date_dim d1 - ,item - where - d1.d_month_seq between 1200 and 1200+11 - and d1.d_date_sk = ws_sold_date_sk - and i_item_sk = ws_item_sk - group by i_category,i_class - ) , - - results_rollup as -( select total_sum ,i_category ,i_class, g_category, g_class, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum, i_category, NULL as i_class, 0 as g_category, 1 as g_class, 1 as lochierarchy from results group by i_category - union - select sum(total_sum) as total_sum, NULL as i_category, NULL as i_class, 1 as g_category, 1 as g_class, 2 as lochierarchy from results) - select - total_sum ,i_category ,i_class, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_class = 0 then i_category end - order by total_sum desc) as rank_within_parent - from - results_rollup - order by - lochierarchy desc, - case when lochierarchy = 0 then i_category end, - rank_within_parent - limit 100; - --- end template query86a.tpl query 23 in stream 3 --- start template query94.tpl query 24 in stream 3 -select /* TPC-DS query94.tpl 0.17 */ - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2001-4-01' and - dateadd(day,60,cast('2001-4-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'MS' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and exists (select * - from web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) -and not exists(select * - from web_returns wr1 - where ws1.ws_order_number = wr1.wr_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query94.tpl query 24 in stream 3 --- start template query8.tpl query 25 in stream 3 -select /* TPC-DS query8.tpl 0.63 */ s_store_name - ,sum(ss_net_profit) - from store_sales - ,date_dim - ,store, - (select ca_zip - from ( - SELECT substring(ca_zip,1,5) ca_zip - FROM customer_address - WHERE substring(ca_zip,1,5) IN ( - '92013','91817','53384','65812','65236','86023', - '57828','57354','53562','82731','68074', - '33333','80601','17651','20999','94254', - '45914','24400','90587','97249','13134', - '54403','55639','27737','72858','86747', - '77050','37894','21930','11944','61883', - '19085','90759','92349','10119','42018', - '87931','16059','33532','66418','52147', - '44928','66048','35166','50786','65485', - '82692','27800','59985','53814','21829', - '25523','13532','97683','35060','21114', - '96328','86780','12082','75818','66994', - '88164','28853','58545','32736','36655', - '77379','92213','21563','25009','53191', - '62369','67020','98697','60954','63914', - '74587','43545','94184','48831','20508', - '24061','30490','80894','86536','26942', - '40067','12834','24357','45058','18351', - '11305','82559','81951','32654','73084', - '33987','77871','76506','94711','18928', - '46000','82618','66986','39443','38041', - '28021','38229','22326','29374','23160', - '34845','35062','91720','45173','82978', - '32033','97965','26092','35448','45662', - '48874','89009','39208','78648','33916', - '77457','30736','68657','65973','16070', - '32256','11929','66883','91475','87352', - '72881','56200','56684','78043','27954', - '87495','84198','69651','72288','20437', - '47516','16920','97701','23086','31657', - '79675','70543','66903','28099','61726', - '18896','34923','82078','59960','20451', - '54664','66649','54932','76682','65439', - '37089','10313','11039','12399','61829', - '64909','77823','46978','53309','74619', - '31871','56008','82527','82629','72579', - '87316','99443','69057','54677','37400', - '97943','71036','34641','17677','47757', - '77681','18847','79464','24886','16958', - '79315','92862','73917','45547','83990', - '85483','29794','60281','30082','33799', - '57843','22642','31840','99424','55859', - '57866','45256','78793','34362','70596', - '97685','99896','79088','55214','57701', - '10385','13588','14987','28066','41832', - '13677','47991','96184','21941','24319', - '64761','98556','22063','52992','55509', - '49987','90745','65917','19272','19305', - '20885','25408','94731','50484','25346', - '88126','32055','72371','54113','25829', - '27938','92340','85025','47563','71786', - '19269','44281','12796','28024','31723', - '91390','34308','32201','67133','38664', - '16839','29694','99259','39815','97308', - '97260','55016','11043','87174','72432', - '92061','54702','56985','50541','26903', - '97780','15476','42999','71847','41438', - '10510','70612','82263','45617','20693', - '18499','82949','22050','35667','28820', - '71455','78574','16712','53394','46895', - '16261','91591','23338','65020','51460', - '38318','54757','69440','82149','46193', - '85033','53385','19145','97193','95989', - '96783','24260','11681','69353','69517', - '66683','76152','90734','66468','34490', - '88537','83216','32723','62646','95310', - '85275','43780','59534','72139','29443', - '22590','22775','64014','90230','81445', - '35248','71209','39013','85989','24813', - '27110','74719','40744','98440','24250', - '67213','62167','21688','97389','77414', - '95032','12723','49164','22874','96874', - '30216','70794','23885','73842','32260', - '17139','46220','94055','36673','73369', - '37295','62255','32772','70725','68400', - '72243','11134','94102','18183','75114', - '11701','45109','92359','56672','66955', - '37147','84901','27551','70025','63911', - '62221','69242','59414','10344','64284', - '11800','30903','78214','44385') - intersect - select ca_zip - from (SELECT substring(ca_zip,1,5) ca_zip,count(*) cnt - FROM customer_address, customer - WHERE ca_address_sk = c_current_addr_sk and - c_preferred_cust_flag='Y' - group by ca_zip - having count(*) > 10)A1)A2) V1 - where ss_store_sk = s_store_sk - and ss_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 2001 - and (substring(s_zip,1,2) = substring(V1.ca_zip,1,2)) - group by s_store_name - order by s_store_name - limit 100; - --- end template query8.tpl query 25 in stream 3 --- start template query87.tpl query 26 in stream 3 -select /* TPC-DS query87.tpl 0.77 */ count(*) -from ((select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1202 and 1202+11) - except - (select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1202 and 1202+11) - except - (select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1202 and 1202+11) -) cool_cust -; - --- end template query87.tpl query 26 in stream 3 --- start template query58.tpl query 27 in stream 3 -with /* TPC-DS query58.tpl 0.19 */ ss_items as - (select i_item_id item_id - ,sum(ss_ext_sales_price) ss_item_rev - from store_sales - ,item - ,date_dim - where ss_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '2000-07-04')) - and ss_sold_date_sk = d_date_sk - group by i_item_id), - cs_items as - (select i_item_id item_id - ,sum(cs_ext_sales_price) cs_item_rev - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '2000-07-04')) - and cs_sold_date_sk = d_date_sk - group by i_item_id), - ws_items as - (select i_item_id item_id - ,sum(ws_ext_sales_price) ws_item_rev - from web_sales - ,item - ,date_dim - where ws_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq =(select d_week_seq - from date_dim - where d_date = '2000-07-04')) - and ws_sold_date_sk = d_date_sk - group by i_item_id) - select ss_items.item_id - ,ss_item_rev - ,ss_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ss_dev - ,cs_item_rev - ,cs_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 cs_dev - ,ws_item_rev - ,ws_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ws_dev - ,(ss_item_rev+cs_item_rev+ws_item_rev)/3 average - from ss_items,cs_items,ws_items - where ss_items.item_id=cs_items.item_id - and ss_items.item_id=ws_items.item_id - and ss_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - and ss_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and cs_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and cs_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and ws_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and ws_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - order by item_id - ,ss_item_rev - limit 100; - --- end template query58.tpl query 27 in stream 3 --- start template query36a.tpl query 28 in stream 3 -with /* TPC-DS query36a.tpl 0.21 */ results as - (select - sum(ss_net_profit) as ss_net_profit, sum(ss_ext_sales_price) as ss_ext_sales_price, - sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin - ,i_category - ,i_class - ,0 as g_category, 0 as g_class - from - store_sales - ,date_dim d1 - ,item - ,store - where - d1.d_year = 1998 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and s_state in ('FL','MI','KS','KY', - 'IA','KS','NC','NE') - group by i_category,i_class) - , - results_rollup as - (select gross_margin ,i_category ,i_class,0 as t_category, 0 as t_class, 0 as lochierarchy from results - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - i_category, NULL AS i_class, 0 as t_category, 1 as t_class, 1 as lochierarchy from results group by i_category - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - NULL AS i_category ,NULL AS i_class, 1 as t_category, 1 as t_class, 2 as lochierarchy from results) - select - gross_margin ,i_category ,i_class, lochierarchy,rank() over ( - partition by lochierarchy, case when t_class = 0 then i_category end - order by gross_margin asc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then i_category end - ,rank_within_parent - limit 100; - --- end template query36a.tpl query 28 in stream 3 --- start template query37.tpl query 29 in stream 3 -select /* TPC-DS query37.tpl 0.31 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, catalog_sales - where i_current_price between 25 and 25 + 30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('2000-02-11' as date) and dateadd(day,60,cast('2000-02-11' as date)) - and i_manufact_id in (706,779,945,958) - and inv_quantity_on_hand between 100 and 500 - and cs_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query37.tpl query 29 in stream 3 --- start template query4.tpl query 30 in stream 3 -with /* TPC-DS query4.tpl 0.93 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(((ss_ext_list_price-ss_ext_wholesale_cost-ss_ext_discount_amt)+ss_ext_sales_price)/2) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((cs_ext_list_price-cs_ext_wholesale_cost-cs_ext_discount_amt)+cs_ext_sales_price)/2) ) year_total - ,'c' sale_type - from customer - ,catalog_sales - ,date_dim - where c_customer_sk = cs_bill_customer_sk - and cs_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year -union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((ws_ext_list_price-ws_ext_wholesale_cost-ws_ext_discount_amt)+ws_ext_sales_price)/2) ) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_login - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_c_firstyear - ,year_total t_c_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_c_secyear.customer_id - and t_s_firstyear.customer_id = t_c_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_c_firstyear.sale_type = 'c' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_c_secyear.sale_type = 'c' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 2001 - and t_s_secyear.dyear = 2001+1 - and t_c_firstyear.dyear = 2001 - and t_c_secyear.dyear = 2001+1 - and t_w_firstyear.dyear = 2001 - and t_w_secyear.dyear = 2001+1 - and t_s_firstyear.year_total > 0 - and t_c_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_login -limit 100; - --- end template query4.tpl query 30 in stream 3 --- start template query38.tpl query 31 in stream 3 -select /* TPC-DS query38.tpl 0.54 */ count(*) from ( - select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1223 and 1223 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1223 and 1223 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1223 and 1223 + 11 -) hot_cust -limit 100; - --- end template query38.tpl query 31 in stream 3 --- start template query66.tpl query 32 in stream 3 -select /* TPC-DS query66.tpl 0.39 */ - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - ,sum(jan_sales) as jan_sales - ,sum(feb_sales) as feb_sales - ,sum(mar_sales) as mar_sales - ,sum(apr_sales) as apr_sales - ,sum(may_sales) as may_sales - ,sum(jun_sales) as jun_sales - ,sum(jul_sales) as jul_sales - ,sum(aug_sales) as aug_sales - ,sum(sep_sales) as sep_sales - ,sum(oct_sales) as oct_sales - ,sum(nov_sales) as nov_sales - ,sum(dec_sales) as dec_sales - ,sum(jan_sales/w_warehouse_sq_ft) as jan_sales_per_sq_foot - ,sum(feb_sales/w_warehouse_sq_ft) as feb_sales_per_sq_foot - ,sum(mar_sales/w_warehouse_sq_ft) as mar_sales_per_sq_foot - ,sum(apr_sales/w_warehouse_sq_ft) as apr_sales_per_sq_foot - ,sum(may_sales/w_warehouse_sq_ft) as may_sales_per_sq_foot - ,sum(jun_sales/w_warehouse_sq_ft) as jun_sales_per_sq_foot - ,sum(jul_sales/w_warehouse_sq_ft) as jul_sales_per_sq_foot - ,sum(aug_sales/w_warehouse_sq_ft) as aug_sales_per_sq_foot - ,sum(sep_sales/w_warehouse_sq_ft) as sep_sales_per_sq_foot - ,sum(oct_sales/w_warehouse_sq_ft) as oct_sales_per_sq_foot - ,sum(nov_sales/w_warehouse_sq_ft) as nov_sales_per_sq_foot - ,sum(dec_sales/w_warehouse_sq_ft) as dec_sales_per_sq_foot - ,sum(jan_net) as jan_net - ,sum(feb_net) as feb_net - ,sum(mar_net) as mar_net - ,sum(apr_net) as apr_net - ,sum(may_net) as may_net - ,sum(jun_net) as jun_net - ,sum(jul_net) as jul_net - ,sum(aug_net) as aug_net - ,sum(sep_net) as sep_net - ,sum(oct_net) as oct_net - ,sum(nov_net) as nov_net - ,sum(dec_net) as dec_net - from ( - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'GERMA' || ',' || 'BOXBUNDLES' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then ws_sales_price* ws_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then ws_sales_price* ws_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then ws_sales_price* ws_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then ws_sales_price* ws_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then ws_sales_price* ws_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then ws_sales_price* ws_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then ws_sales_price* ws_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then ws_sales_price* ws_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then ws_sales_price* ws_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then ws_sales_price* ws_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then ws_sales_price* ws_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then ws_sales_price* ws_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then ws_net_profit * ws_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then ws_net_profit * ws_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then ws_net_profit * ws_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then ws_net_profit * ws_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then ws_net_profit * ws_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then ws_net_profit * ws_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then ws_net_profit * ws_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then ws_net_profit * ws_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then ws_net_profit * ws_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then ws_net_profit * ws_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then ws_net_profit * ws_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then ws_net_profit * ws_quantity else 0 end) as dec_net - from - web_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - ws_warehouse_sk = w_warehouse_sk - and ws_sold_date_sk = d_date_sk - and ws_sold_time_sk = t_time_sk - and ws_ship_mode_sk = sm_ship_mode_sk - and d_year = 1998 - and t_time between 56071 and 56071+28800 - and sm_carrier in ('GERMA','BOXBUNDLES') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - union all - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'GERMA' || ',' || 'BOXBUNDLES' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then cs_ext_sales_price* cs_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then cs_ext_sales_price* cs_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then cs_ext_sales_price* cs_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then cs_ext_sales_price* cs_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then cs_ext_sales_price* cs_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then cs_ext_sales_price* cs_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then cs_ext_sales_price* cs_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then cs_ext_sales_price* cs_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then cs_ext_sales_price* cs_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then cs_ext_sales_price* cs_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then cs_ext_sales_price* cs_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then cs_ext_sales_price* cs_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as dec_net - from - catalog_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and cs_sold_time_sk = t_time_sk - and cs_ship_mode_sk = sm_ship_mode_sk - and d_year = 1998 - and t_time between 56071 AND 56071+28800 - and sm_carrier in ('GERMA','BOXBUNDLES') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - ) x - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - order by w_warehouse_name - limit 100; - --- end template query66.tpl query 32 in stream 3 --- start template query78.tpl query 33 in stream 3 -with /* TPC-DS query78.tpl 0.10 */ ws as - (select d_year AS ws_sold_year, ws_item_sk, - ws_bill_customer_sk ws_customer_sk, - sum(ws_quantity) ws_qty, - sum(ws_wholesale_cost) ws_wc, - sum(ws_sales_price) ws_sp - from web_sales - left join web_returns on wr_order_number=ws_order_number and ws_item_sk=wr_item_sk - join date_dim on ws_sold_date_sk = d_date_sk - where wr_order_number is null - group by d_year, ws_item_sk, ws_bill_customer_sk - ), -cs as - (select d_year AS cs_sold_year, cs_item_sk, - cs_bill_customer_sk cs_customer_sk, - sum(cs_quantity) cs_qty, - sum(cs_wholesale_cost) cs_wc, - sum(cs_sales_price) cs_sp - from catalog_sales - left join catalog_returns on cr_order_number=cs_order_number and cs_item_sk=cr_item_sk - join date_dim on cs_sold_date_sk = d_date_sk - where cr_order_number is null - group by d_year, cs_item_sk, cs_bill_customer_sk - ), -ss as - (select d_year AS ss_sold_year, ss_item_sk, - ss_customer_sk, - sum(ss_quantity) ss_qty, - sum(ss_wholesale_cost) ss_wc, - sum(ss_sales_price) ss_sp - from store_sales - left join store_returns on sr_ticket_number=ss_ticket_number and ss_item_sk=sr_item_sk - join date_dim on ss_sold_date_sk = d_date_sk - where sr_ticket_number is null - group by d_year, ss_item_sk, ss_customer_sk - ) - select -ss_sold_year, -round(ss_qty/(coalesce(ws_qty,0)+coalesce(cs_qty,0)),2) ratio, -ss_qty store_qty, ss_wc store_wholesale_cost, ss_sp store_sales_price, -coalesce(ws_qty,0)+coalesce(cs_qty,0) other_chan_qty, -coalesce(ws_wc,0)+coalesce(cs_wc,0) other_chan_wholesale_cost, -coalesce(ws_sp,0)+coalesce(cs_sp,0) other_chan_sales_price -from ss -left join ws on (ws_sold_year=ss_sold_year and ws_item_sk=ss_item_sk and ws_customer_sk=ss_customer_sk) -left join cs on (cs_sold_year=ss_sold_year and cs_item_sk=ss_item_sk and cs_customer_sk=ss_customer_sk) -where (coalesce(ws_qty,0)>0 or coalesce(cs_qty, 0)>0) and ss_sold_year=2000 -order by - ss_sold_year, - ss_qty desc, ss_wc desc, ss_sp desc, - other_chan_qty, - other_chan_wholesale_cost, - other_chan_sales_price, - ratio -limit 100; - --- end template query78.tpl query 33 in stream 3 --- start template query43.tpl query 34 in stream 3 -select /* TPC-DS query43.tpl 0.15 */ s_store_name, s_store_id, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from date_dim, store_sales, store - where d_date_sk = ss_sold_date_sk and - s_store_sk = ss_store_sk and - s_gmt_offset = -7 and - d_year = 1998 - group by s_store_name, s_store_id - order by s_store_name, s_store_id,sun_sales,mon_sales,tue_sales,wed_sales,thu_sales,fri_sales,sat_sales - limit 100; - --- end template query43.tpl query 34 in stream 3 --- start template query22a.tpl query 35 in stream 3 -with /* TPC-DS query22a.tpl 0.55 */ results as -(select i_product_name - ,i_brand - ,i_class - ,i_category - ,avg(inv_quantity_on_hand) qoh - from inventory - ,date_dim - ,item --- ,warehouse - where inv_date_sk=d_date_sk - and inv_item_sk=i_item_sk --- and inv_warehouse_sk = w_warehouse_sk - and d_month_seq between 1218 and 1218 + 11 - group by i_product_name,i_brand,i_class,i_category), -results_rollup as -(select i_product_name, i_brand, i_class, i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class,i_category -union all -select i_product_name, i_brand, i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class -union all -select i_product_name, i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand -union all -select i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name -union all -select null i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results) - select i_product_name, i_brand, i_class, i_category,qoh - from results_rollup - order by qoh, i_product_name, i_brand, i_class, i_category -limit 100; - --- end template query22a.tpl query 35 in stream 3 --- start template query21.tpl query 36 in stream 3 -select /* TPC-DS query21.tpl 0.14 */ * - from(select w_warehouse_name - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('2002-05-17' as date)) - then inv_quantity_on_hand - else 0 end) as inv_before - ,sum(case when (cast(d_date as date) >= cast ('2002-05-17' as date)) - then inv_quantity_on_hand - else 0 end) as inv_after - from inventory - ,warehouse - ,item - ,date_dim - where i_current_price between 0.99 and 1.49 - and i_item_sk = inv_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('2002-05-17' as date)) - and dateadd(day,30,cast ('2002-05-17' as date)) - group by w_warehouse_name, i_item_id) x - where (case when inv_before > 0 - then inv_after / inv_before - else null - end) between 2.0/3.0 and 3.0/2.0 - order by w_warehouse_name - ,i_item_id - limit 100; - --- end template query21.tpl query 36 in stream 3 --- start template query97.tpl query 37 in stream 3 -with /* TPC-DS query97.tpl 0.38 */ ssci as ( -select ss_customer_sk customer_sk - ,ss_item_sk item_sk -from store_sales,date_dim -where ss_sold_date_sk = d_date_sk - and d_month_seq between 1184 and 1184 + 11 -group by ss_customer_sk - ,ss_item_sk), -csci as( - select cs_bill_customer_sk customer_sk - ,cs_item_sk item_sk -from catalog_sales,date_dim -where cs_sold_date_sk = d_date_sk - and d_month_seq between 1184 and 1184 + 11 -group by cs_bill_customer_sk - ,cs_item_sk) - select sum(case when ssci.customer_sk is not null and csci.customer_sk is null then 1 else 0 end) store_only - ,sum(case when ssci.customer_sk is null and csci.customer_sk is not null then 1 else 0 end) catalog_only - ,sum(case when ssci.customer_sk is not null and csci.customer_sk is not null then 1 else 0 end) store_and_catalog -from ssci full outer join csci on (ssci.customer_sk=csci.customer_sk - and ssci.item_sk = csci.item_sk) -limit 100; - --- end template query97.tpl query 37 in stream 3 --- start template query47.tpl query 38 in stream 3 -with /* TPC-DS query47.tpl 0.42 */ v1 as( - select i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, - s_store_name, s_company_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - s_store_name, s_company_name - order by d_year, d_moy) rn - from item, store_sales, date_dim, store - where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - ( - d_year = 2000 or - ( d_year = 2000-1 and d_moy =12) or - ( d_year = 2000+1 and d_moy =1) - ) - group by i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy), - v2 as( - select v1.s_store_name - ,v1.d_year - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1.s_store_name = v1_lag.s_store_name and - v1.s_store_name = v1_lead.s_store_name and - v1.s_company_name = v1_lag.s_company_name and - v1.s_company_name = v1_lead.s_company_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 2000 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, avg_monthly_sales - limit 100; - --- end template query47.tpl query 38 in stream 3 --- start template query29.tpl query 39 in stream 3 -select /* TPC-DS query29.tpl 0.53 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,stddev_samp(ss_quantity) as store_sales_quantity - ,stddev_samp(sr_return_quantity) as store_returns_quantity - ,stddev_samp(cs_quantity) as catalog_sales_quantity - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 2000 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 4 + 3 - and d2.d_year = 2000 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_year in (2000,2000+1,2000+2) - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query29.tpl query 39 in stream 3 --- start template query3.tpl query 40 in stream 3 -select /* TPC-DS query3.tpl 0.45 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_discount_amt) sum_agg - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manufact_id = 958 - and dt.d_moy=12 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,sum_agg desc - ,brand_id - limit 100; - --- end template query3.tpl query 40 in stream 3 --- start template query76.tpl query 41 in stream 3 -select /* TPC-DS query76.tpl 0.99 */ channel, col_name, d_year, d_qoy, i_category, COUNT(*) sales_cnt, SUM(ext_sales_price) sales_amt FROM ( - SELECT 'store' as channel, 'ss_promo_sk' col_name, d_year, d_qoy, i_category, ss_ext_sales_price ext_sales_price - FROM store_sales, item, date_dim - WHERE ss_promo_sk IS NULL - AND ss_sold_date_sk=d_date_sk - AND ss_item_sk=i_item_sk - UNION ALL - SELECT 'web' as channel, 'ws_ship_hdemo_sk' col_name, d_year, d_qoy, i_category, ws_ext_sales_price ext_sales_price - FROM web_sales, item, date_dim - WHERE ws_ship_hdemo_sk IS NULL - AND ws_sold_date_sk=d_date_sk - AND ws_item_sk=i_item_sk - UNION ALL - SELECT 'catalog' as channel, 'cs_ship_mode_sk' col_name, d_year, d_qoy, i_category, cs_ext_sales_price ext_sales_price - FROM catalog_sales, item, date_dim - WHERE cs_ship_mode_sk IS NULL - AND cs_sold_date_sk=d_date_sk - AND cs_item_sk=i_item_sk) foo -GROUP BY channel, col_name, d_year, d_qoy, i_category -ORDER BY channel, col_name, d_year, d_qoy, i_category -limit 100; - --- end template query76.tpl query 41 in stream 3 --- start template query82.tpl query 42 in stream 3 -select /* TPC-DS query82.tpl 0.67 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, store_sales - where i_current_price between 85 and 85+30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('1999-03-10' as date) and dateadd(day,60,cast('1999-03-10' as date)) - and i_manufact_id in (232,600,760,907) - and inv_quantity_on_hand between 100 and 500 - and ss_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query82.tpl query 42 in stream 3 --- start template query46.tpl query 43 in stream 3 -select /* TPC-DS query46.tpl 0.23 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and (household_demographics.hd_dep_count = 7 or - household_demographics.hd_vehicle_count= 1) - and date_dim.d_dow in (6,0) - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_city in ('Williams','High Point','Perryville','Bunker Hill','Hopewell') - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,ca_city) dn,customer,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - limit 100; - --- end template query46.tpl query 43 in stream 3 --- start template query41.tpl query 44 in stream 3 -select /* TPC-DS query41.tpl 0.62 */ distinct(i_product_name) - from item i1 - where i_manufact_id between 671 and 671+40 - and (select count(*) as item_cnt - from item - where (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'steel' or i_color = 'lavender') and - (i_units = 'Box' or i_units = 'Ton') and - (i_size = 'extra large' or i_size = 'economy') - ) or - (i_category = 'Women' and - (i_color = 'moccasin' or i_color = 'pale') and - (i_units = 'Pallet' or i_units = 'Each') and - (i_size = 'medium' or i_size = 'small') - ) or - (i_category = 'Men' and - (i_color = 'lemon' or i_color = 'dodger') and - (i_units = 'Ounce' or i_units = 'Bundle') and - (i_size = 'large' or i_size = 'petite') - ) or - (i_category = 'Men' and - (i_color = 'blush' or i_color = 'green') and - (i_units = 'Oz' or i_units = 'N/A') and - (i_size = 'extra large' or i_size = 'economy') - ))) or - (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'forest' or i_color = 'mint') and - (i_units = 'Tsp' or i_units = 'Case') and - (i_size = 'extra large' or i_size = 'economy') - ) or - (i_category = 'Women' and - (i_color = 'peru' or i_color = 'light') and - (i_units = 'Carton' or i_units = 'Dram') and - (i_size = 'medium' or i_size = 'small') - ) or - (i_category = 'Men' and - (i_color = 'honeydew' or i_color = 'olive') and - (i_units = 'Gross' or i_units = 'Cup') and - (i_size = 'large' or i_size = 'petite') - ) or - (i_category = 'Men' and - (i_color = 'chocolate' or i_color = 'grey') and - (i_units = 'Dozen' or i_units = 'Bunch') and - (i_size = 'extra large' or i_size = 'economy') - )))) > 0 - order by i_product_name - limit 100; - --- end template query41.tpl query 44 in stream 3 --- start template query59.tpl query 45 in stream 3 -with /* TPC-DS query59.tpl 0.30 */ wss as - (select d_week_seq, - ss_store_sk, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - group by d_week_seq,ss_store_sk - ) - select s_store_name1,s_store_id1,d_week_seq1 - ,sun_sales1/sun_sales2,mon_sales1/mon_sales2 - ,tue_sales1/tue_sales2,wed_sales1/wed_sales2,thu_sales1/thu_sales2 - ,fri_sales1/fri_sales2,sat_sales1/sat_sales2 - from - (select s_store_name s_store_name1,wss.d_week_seq d_week_seq1 - ,s_store_id s_store_id1,sun_sales sun_sales1 - ,mon_sales mon_sales1,tue_sales tue_sales1 - ,wed_sales wed_sales1,thu_sales thu_sales1 - ,fri_sales fri_sales1,sat_sales sat_sales1 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1211 and 1211 + 11) y, - (select s_store_name s_store_name2,wss.d_week_seq d_week_seq2 - ,s_store_id s_store_id2,sun_sales sun_sales2 - ,mon_sales mon_sales2,tue_sales tue_sales2 - ,wed_sales wed_sales2,thu_sales thu_sales2 - ,fri_sales fri_sales2,sat_sales sat_sales2 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1211+ 12 and 1211 + 23) x - where s_store_id1=s_store_id2 - and d_week_seq1=d_week_seq2-52 - order by s_store_name1,s_store_id1,d_week_seq1 -limit 100; - --- end template query59.tpl query 45 in stream 3 --- start template query40.tpl query 46 in stream 3 -select /* TPC-DS query40.tpl 0.86 */ - w_state - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('2000-06-13' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_before - ,sum(case when (cast(d_date as date) >= cast ('2000-06-13' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_after - from - catalog_sales left outer join catalog_returns on - (cs_order_number = cr_order_number - and cs_item_sk = cr_item_sk) - ,warehouse - ,item - ,date_dim - where - i_current_price between 0.99 and 1.49 - and i_item_sk = cs_item_sk - and cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('2000-06-13' as date)) - and dateadd(day,30,cast ('2000-06-13' as date)) - group by - w_state,i_item_id - order by w_state,i_item_id -limit 100; - --- end template query40.tpl query 46 in stream 3 --- start template query55.tpl query 47 in stream 3 -select /* TPC-DS query55.tpl 0.82 */ i_brand_id brand_id, i_brand brand, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=83 - and d_moy=12 - and d_year=2002 - group by i_brand, i_brand_id - order by ext_price desc, i_brand_id -limit 100 ; - --- end template query55.tpl query 47 in stream 3 --- start template query16.tpl query 48 in stream 3 -select /* TPC-DS query16.tpl 0.25 */ - count(distinct cs_order_number) as "order count" - ,sum(cs_ext_ship_cost) as "total shipping cost" - ,sum(cs_net_profit) as "total net profit" -from - catalog_sales cs1 - ,date_dim - ,customer_address - ,call_center -where - d_date between '2002-2-01' and - dateadd(day, 60, cast('2002-2-01' as date)) -and cs1.cs_ship_date_sk = d_date_sk -and cs1.cs_ship_addr_sk = ca_address_sk -and ca_state = 'PA' -and cs1.cs_call_center_sk = cc_call_center_sk -and cc_county in ('Huron County','Oglethorpe County','Pennington County','Walker County', - 'Mobile County' -) -and exists (select * - from catalog_sales cs2 - where cs1.cs_order_number = cs2.cs_order_number - and cs1.cs_warehouse_sk <> cs2.cs_warehouse_sk) -and not exists(select * - from catalog_returns cr1 - where cs1.cs_order_number = cr1.cr_order_number) -order by count(distinct cs_order_number) -limit 100; - --- end template query16.tpl query 48 in stream 3 --- start template query27a.tpl query 49 in stream 3 -with /* TPC-DS query27a.tpl 0.16 */ results as - (select i_item_id, - s_state, 0 as g_state, - ss_quantity agg1, - ss_list_price agg2, - ss_coupon_amt agg3, - ss_sales_price agg4 - from store_sales, customer_demographics, date_dim, store, item - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_store_sk = s_store_sk and - ss_cdemo_sk = cd_demo_sk and - cd_gender = 'M' and - cd_marital_status = 'M' and - cd_education_status = '4 yr Degree' and - d_year = 1998 and - s_state in ('SD','MI', 'WV', 'NM', 'IL', 'KS') - ) - - select i_item_id, - s_state, g_state, agg1, agg2, agg3, agg4 - from ( - select i_item_id, s_state, 0 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4 from results - group by i_item_id, s_state - union all - select i_item_id, NULL AS s_state, 1 AS g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as s_state, 1 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - ) foo - order by i_item_id, s_state - limit 100; - --- end template query27a.tpl query 49 in stream 3 --- start template query54.tpl query 50 in stream 3 -with /* TPC-DS query54.tpl 0.81 */ my_customers as ( - select distinct c_customer_sk - , c_current_addr_sk - from - ( select cs_sold_date_sk sold_date_sk, - cs_bill_customer_sk customer_sk, - cs_item_sk item_sk - from catalog_sales - union all - select ws_sold_date_sk sold_date_sk, - ws_bill_customer_sk customer_sk, - ws_item_sk item_sk - from web_sales - ) cs_or_ws_sales, - item, - date_dim, - customer - where sold_date_sk = d_date_sk - and item_sk = i_item_sk - and i_category = 'Sports' - and i_class = 'athletic shoes' - and c_customer_sk = cs_or_ws_sales.customer_sk - and d_moy = 5 - and d_year = 2002 - ) - , my_revenue as ( - select c_customer_sk, - sum(ss_ext_sales_price) as revenue - from my_customers, - store_sales, - customer_address, - store, - date_dim - where c_current_addr_sk = ca_address_sk - and ca_county = s_county - and ca_state = s_state - and ss_sold_date_sk = d_date_sk - and c_customer_sk = ss_customer_sk - and d_month_seq between (select distinct d_month_seq+1 - from date_dim where d_year = 2002 and d_moy = 5) - and (select distinct d_month_seq+3 - from date_dim where d_year = 2002 and d_moy = 5) - group by c_customer_sk - ) - , segments as - (select cast((revenue/50) as bigint) as segment - from my_revenue - ) - select segment, count(*) as num_customers, segment*50 as segment_base - from segments - group by segment - order by segment, num_customers - limit 100; - --- end template query54.tpl query 50 in stream 3 --- start template query90.tpl query 51 in stream 3 -select /* TPC-DS query90.tpl 0.40 */ cast(amc as decimal(15,4))/cast(pmc as decimal(15,4)) am_pm_ratio - from ( select count(*) amc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 7 and 7+1 - and household_demographics.hd_dep_count = 5 - and web_page.wp_char_count between 5000 and 5200) at, - ( select count(*) pmc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 16 and 16+1 - and household_demographics.hd_dep_count = 5 - and web_page.wp_char_count between 5000 and 5200) pt - order by am_pm_ratio - limit 100; - --- end template query90.tpl query 51 in stream 3 --- start template query92.tpl query 52 in stream 3 -select /* TPC-DS query92.tpl 0.44 */ - sum(ws_ext_discount_amt) as "Excess Discount Amount" -from - web_sales - ,item - ,date_dim -where -i_manufact_id = 411 -and i_item_sk = ws_item_sk -and d_date between '2000-02-01' and - dateadd(day,90,cast('2000-02-01' as date)) -and d_date_sk = ws_sold_date_sk -and ws_ext_discount_amt - > ( - SELECT - 1.3 * avg(ws_ext_discount_amt) - FROM - web_sales - ,date_dim - WHERE - ws_item_sk = i_item_sk - and d_date between '2000-02-01' and - dateadd(day,90,cast('2000-02-01' as date)) - and d_date_sk = ws_sold_date_sk - ) -order by sum(ws_ext_discount_amt) -limit 100; - --- end template query92.tpl query 52 in stream 3 --- start template query31.tpl query 53 in stream 3 -with /* TPC-DS query31.tpl 0.50 */ ss as - (select ca_county,d_qoy, d_year,sum(ss_ext_sales_price) as store_sales - from store_sales,date_dim,customer_address - where ss_sold_date_sk = d_date_sk - and ss_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year), - ws as - (select ca_county,d_qoy, d_year,sum(ws_ext_sales_price) as web_sales - from web_sales,date_dim,customer_address - where ws_sold_date_sk = d_date_sk - and ws_bill_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year) - select - ss1.ca_county - ,ss1.d_year - ,ws2.web_sales/ws1.web_sales web_q1_q2_increase - ,ss2.store_sales/ss1.store_sales store_q1_q2_increase - ,ws3.web_sales/ws2.web_sales web_q2_q3_increase - ,ss3.store_sales/ss2.store_sales store_q2_q3_increase - from - ss ss1 - ,ss ss2 - ,ss ss3 - ,ws ws1 - ,ws ws2 - ,ws ws3 - where - ss1.d_qoy = 1 - and ss1.d_year = 1999 - and ss1.ca_county = ss2.ca_county - and ss2.d_qoy = 2 - and ss2.d_year = 1999 - and ss2.ca_county = ss3.ca_county - and ss3.d_qoy = 3 - and ss3.d_year = 1999 - and ss1.ca_county = ws1.ca_county - and ws1.d_qoy = 1 - and ws1.d_year = 1999 - and ws1.ca_county = ws2.ca_county - and ws2.d_qoy = 2 - and ws2.d_year = 1999 - and ws1.ca_county = ws3.ca_county - and ws3.d_qoy = 3 - and ws3.d_year =1999 - and case when ws1.web_sales > 0 then ws2.web_sales/ws1.web_sales else null end - > case when ss1.store_sales > 0 then ss2.store_sales/ss1.store_sales else null end - and case when ws2.web_sales > 0 then ws3.web_sales/ws2.web_sales else null end - > case when ss2.store_sales > 0 then ss3.store_sales/ss2.store_sales else null end - order by ss1.ca_county; - --- end template query31.tpl query 53 in stream 3 --- start template query42.tpl query 54 in stream 3 -select /* TPC-DS query42.tpl 0.61 */ dt.d_year - ,item.i_category_id - ,item.i_category - ,sum(ss_ext_sales_price) - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=12 - and dt.d_year=2000 - group by dt.d_year - ,item.i_category_id - ,item.i_category - order by sum(ss_ext_sales_price) desc,dt.d_year - ,item.i_category_id - ,item.i_category -limit 100 ; - --- end template query42.tpl query 54 in stream 3 --- start template query26.tpl query 55 in stream 3 -select /* TPC-DS query26.tpl 0.85 */ i_item_id, - avg(cs_quantity) agg1, - avg(cs_list_price) agg2, - avg(cs_coupon_amt) agg3, - avg(cs_sales_price) agg4 - from catalog_sales, customer_demographics, date_dim, item, promotion - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd_demo_sk and - cs_promo_sk = p_promo_sk and - cd_gender = 'M' and - cd_marital_status = 'M' and - cd_education_status = 'College' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 1999 - group by i_item_id - order by i_item_id - limit 100; - --- end template query26.tpl query 55 in stream 3 --- start template query34.tpl query 56 in stream 3 -select /* TPC-DS query34.tpl 0.73 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (date_dim.d_dom between 1 and 3 or date_dim.d_dom between 25 and 28) - and (household_demographics.hd_buy_potential = '1001-5000' or - household_demographics.hd_buy_potential = 'Unknown') - and household_demographics.hd_vehicle_count > 0 - and (case when household_demographics.hd_vehicle_count > 0 - then household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count - else null - end) > 1.2 - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_county in ('Ford County','Barrow County','Franklin County','West Feliciana Parish', - 'Wasco County','Musselshell County','Roane County','Levy County') - group by ss_ticket_number,ss_customer_sk) dn,customer - where ss_customer_sk = c_customer_sk - and cnt between 15 and 20 - order by c_last_name,c_first_name,c_salutation,c_preferred_cust_flag desc, ss_ticket_number; - --- end template query34.tpl query 56 in stream 3 --- start template query68.tpl query 57 in stream 3 -select /* TPC-DS query68.tpl 0.95 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,extended_price - ,extended_tax - ,list_price - from (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_ext_sales_price) extended_price - ,sum(ss_ext_list_price) list_price - ,sum(ss_ext_tax) extended_tax - from store_sales - ,date_dim - ,store - ,household_demographics - ,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_dep_count = 4 or - household_demographics.hd_vehicle_count= 2) - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_city in ('Harrison','Five Corners') - group by ss_ticket_number - ,ss_customer_sk - ,ss_addr_sk,ca_city) dn - ,customer - ,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,ss_ticket_number - limit 100; - --- end template query68.tpl query 57 in stream 3 --- start template query2.tpl query 58 in stream 3 -with /* TPC-DS query2.tpl 0.84 */ wscs as - (select sold_date_sk - ,sales_price - from (select ws_sold_date_sk sold_date_sk - ,ws_ext_sales_price sales_price - from web_sales - union all - select cs_sold_date_sk sold_date_sk - ,cs_ext_sales_price sales_price - from catalog_sales)), - wswscs as - (select d_week_seq, - sum(case when (d_day_name='Sunday') then sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then sales_price else null end) sat_sales - from wscs - ,date_dim - where d_date_sk = sold_date_sk - group by d_week_seq) - select d_week_seq1 - ,round(sun_sales1/sun_sales2,2) - ,round(mon_sales1/mon_sales2,2) - ,round(tue_sales1/tue_sales2,2) - ,round(wed_sales1/wed_sales2,2) - ,round(thu_sales1/thu_sales2,2) - ,round(fri_sales1/fri_sales2,2) - ,round(sat_sales1/sat_sales2,2) - from - (select wswscs.d_week_seq d_week_seq1 - ,sun_sales sun_sales1 - ,mon_sales mon_sales1 - ,tue_sales tue_sales1 - ,wed_sales wed_sales1 - ,thu_sales thu_sales1 - ,fri_sales fri_sales1 - ,sat_sales sat_sales1 - from wswscs,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 1999) y, - (select wswscs.d_week_seq d_week_seq2 - ,sun_sales sun_sales2 - ,mon_sales mon_sales2 - ,tue_sales tue_sales2 - ,wed_sales wed_sales2 - ,thu_sales thu_sales2 - ,fri_sales fri_sales2 - ,sat_sales sat_sales2 - from wswscs - ,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 1999+1) z - where d_week_seq1=d_week_seq2-53 - order by d_week_seq1; - --- end template query2.tpl query 58 in stream 3 --- start template query44.tpl query 59 in stream 3 -select /* TPC-DS query44.tpl 0.4 */ asceding.rnk, i1.i_product_name best_performing, i2.i_product_name worst_performing -from(select * - from (select item_sk,rank() over (order by rank_col asc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 502 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 502 - and ss_addr_sk is null - group by ss_store_sk))V1)V11 - where rnk < 11) asceding, - (select * - from (select item_sk,rank() over (order by rank_col desc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 502 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 502 - and ss_addr_sk is null - group by ss_store_sk))V2)V21 - where rnk < 11) descending, -item i1, -item i2 -where asceding.rnk = descending.rnk - and i1.i_item_sk=asceding.item_sk - and i2.i_item_sk=descending.item_sk -order by asceding.rnk -limit 100; - --- end template query44.tpl query 59 in stream 3 --- start template query81.tpl query 60 in stream 3 -with /* TPC-DS query81.tpl 0.37 */ customer_total_return as - (select cr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(cr_return_amt_inc_tax) as ctr_total_return - from catalog_returns - ,date_dim - ,customer_address - where cr_returned_date_sk = d_date_sk - and d_year =2000 - and cr_returning_addr_sk = ca_address_sk - group by cr_returning_customer_sk - ,ca_state ) - select c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'KY' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - limit 100; - --- end template query81.tpl query 60 in stream 3 --- start template query67a.tpl query 61 in stream 3 -with /* TPC-DS query67a.tpl 0.35 */ results as -( select i_category ,i_class ,i_brand ,i_product_name ,d_year ,d_qoy ,d_moy ,s_store_id - ,sum(coalesce(ss_sales_price*ss_quantity,0)) sumsales - from store_sales ,date_dim ,store ,item - where ss_sold_date_sk=d_date_sk - and ss_item_sk=i_item_sk - and ss_store_sk = s_store_sk - and d_month_seq between 1203 and 1203 + 11 - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy,s_store_id) - , - results_rollup as - (select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, s_store_id, sumsales - from results - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy - union all - select i_category, i_class, i_brand, i_product_name, d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year - union all - select i_category, i_class, i_brand, i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name - union all - select i_category, i_class, i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand - union all - select i_category, i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class - union all - select i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category - union all - select null i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results) - - select * -from (select i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rank() over (partition by i_category order by sumsales desc) rk - from results_rollup) dw2 -where rk <= 100 -order by i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rk -limit 100; - --- end template query67a.tpl query 61 in stream 3 --- start template query99.tpl query 62 in stream 3 -select /* TPC-DS query99.tpl 0.94 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 30) and - (cs_ship_date_sk - cs_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 60) and - (cs_ship_date_sk - cs_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 90) and - (cs_ship_date_sk - cs_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - catalog_sales - ,warehouse - ,ship_mode - ,call_center - ,date_dim -where - d_month_seq between 1208 and 1208 + 11 -and cs_ship_date_sk = d_date_sk -and cs_warehouse_sk = w_warehouse_sk -and cs_ship_mode_sk = sm_ship_mode_sk -and cs_call_center_sk = cc_call_center_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -limit 100; - --- end template query99.tpl query 62 in stream 3 --- start template query6.tpl query 63 in stream 3 -select /* TPC-DS query6.tpl 0.58 */ a.ca_state state, count(*) cnt - from customer_address a - ,customer c - ,store_sales s - ,date_dim d - ,item i - where a.ca_address_sk = c.c_current_addr_sk - and c.c_customer_sk = s.ss_customer_sk - and s.ss_sold_date_sk = d.d_date_sk - and s.ss_item_sk = i.i_item_sk - and d.d_month_seq = - (select distinct (d_month_seq) - from date_dim - where d_year = 2002 - and d_moy = 5 ) - and i.i_current_price > 1.2 * - (select avg(j.i_current_price) - from item j - where j.i_category = i.i_category) - group by a.ca_state - having count(*) >= 10 - order by cnt, a.ca_state - limit 100; - --- end template query6.tpl query 63 in stream 3 --- start template query83.tpl query 64 in stream 3 -with /* TPC-DS query83.tpl 0.96 */ sr_items as - (select i_item_id item_id, - sum(sr_return_quantity) sr_item_qty - from store_returns, - item, - date_dim - where sr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2000-06-13','2000-09-18','2000-11-23'))) - and sr_returned_date_sk = d_date_sk - group by i_item_id), - cr_items as - (select i_item_id item_id, - sum(cr_return_quantity) cr_item_qty - from catalog_returns, - item, - date_dim - where cr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2000-06-13','2000-09-18','2000-11-23'))) - and cr_returned_date_sk = d_date_sk - group by i_item_id), - wr_items as - (select i_item_id item_id, - sum(wr_return_quantity) wr_item_qty - from web_returns, - item, - date_dim - where wr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2000-06-13','2000-09-18','2000-11-23'))) - and wr_returned_date_sk = d_date_sk - group by i_item_id) - select sr_items.item_id - ,sr_item_qty - ,sr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 sr_dev - ,cr_item_qty - ,cr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 cr_dev - ,wr_item_qty - ,wr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 wr_dev - ,(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 average - from sr_items - ,cr_items - ,wr_items - where sr_items.item_id=cr_items.item_id - and sr_items.item_id=wr_items.item_id - order by sr_items.item_id - ,sr_item_qty - limit 100; - --- end template query83.tpl query 64 in stream 3 --- start template query1.tpl query 65 in stream 3 -with /* TPC-DS query1.tpl 0.12 */ customer_total_return as -(select sr_customer_sk as ctr_customer_sk -,sr_store_sk as ctr_store_sk -,sum(SR_FEE) as ctr_total_return -from store_returns -,date_dim -where sr_returned_date_sk = d_date_sk -and d_year =2002 -group by sr_customer_sk -,sr_store_sk) - select c_customer_id -from customer_total_return ctr1 -,store -,customer -where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 -from customer_total_return ctr2 -where ctr1.ctr_store_sk = ctr2.ctr_store_sk) -and s_store_sk = ctr1.ctr_store_sk -and s_state = 'MA' -and ctr1.ctr_customer_sk = c_customer_sk -order by c_customer_id -limit 100; - --- end template query1.tpl query 65 in stream 3 --- start template query60.tpl query 66 in stream 3 -with /* TPC-DS query60.tpl 0.29 */ ss as ( - select - i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Shoes')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 8 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - cs as ( - select - i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Shoes')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 8 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - ws as ( - select - i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Shoes')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 8 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id) - select - i_item_id -,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by i_item_id - ,total_sales - limit 100; - --- end template query60.tpl query 66 in stream 3 --- start template query33.tpl query 67 in stream 3 -with /* TPC-DS query33.tpl 0.22 */ ss as ( - select - i_manufact_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Sports')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 4 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id), - cs as ( - select - i_manufact_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Sports')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 4 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id), - ws as ( - select - i_manufact_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Sports')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 4 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id) - select i_manufact_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_manufact_id - order by total_sales -limit 100; - --- end template query33.tpl query 67 in stream 3 --- start template query11.tpl query 68 in stream 3 -with /* TPC-DS query11.tpl 0.51 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ss_ext_list_price-ss_ext_discount_amt) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ws_ext_list_price-ws_ext_discount_amt) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_email_address - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 1999 - and t_s_secyear.dyear = 1999+1 - and t_w_firstyear.dyear = 1999 - and t_w_secyear.dyear = 1999+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else 0.0 end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else 0.0 end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_email_address -limit 100; - --- end template query11.tpl query 68 in stream 3 --- start template query28.tpl query 69 in stream 3 -select /* TPC-DS query28.tpl 0.36 */ * -from (select avg(ss_list_price) B1_LP - ,count(ss_list_price) B1_CNT - ,count(distinct ss_list_price) B1_CNTD - from store_sales - where ss_quantity between 0 and 5 - and (ss_list_price between 107 and 107+10 - or ss_coupon_amt between 13668 and 13668+1000 - or ss_wholesale_cost between 76 and 76+20)) B1, - (select avg(ss_list_price) B2_LP - ,count(ss_list_price) B2_CNT - ,count(distinct ss_list_price) B2_CNTD - from store_sales - where ss_quantity between 6 and 10 - and (ss_list_price between 126 and 126+10 - or ss_coupon_amt between 16920 and 16920+1000 - or ss_wholesale_cost between 30 and 30+20)) B2, - (select avg(ss_list_price) B3_LP - ,count(ss_list_price) B3_CNT - ,count(distinct ss_list_price) B3_CNTD - from store_sales - where ss_quantity between 11 and 15 - and (ss_list_price between 130 and 130+10 - or ss_coupon_amt between 1357 and 1357+1000 - or ss_wholesale_cost between 80 and 80+20)) B3, - (select avg(ss_list_price) B4_LP - ,count(ss_list_price) B4_CNT - ,count(distinct ss_list_price) B4_CNTD - from store_sales - where ss_quantity between 16 and 20 - and (ss_list_price between 133 and 133+10 - or ss_coupon_amt between 12289 and 12289+1000 - or ss_wholesale_cost between 71 and 71+20)) B4, - (select avg(ss_list_price) B5_LP - ,count(ss_list_price) B5_CNT - ,count(distinct ss_list_price) B5_CNTD - from store_sales - where ss_quantity between 21 and 25 - and (ss_list_price between 116 and 116+10 - or ss_coupon_amt between 5943 and 5943+1000 - or ss_wholesale_cost between 63 and 63+20)) B5, - (select avg(ss_list_price) B6_LP - ,count(ss_list_price) B6_CNT - ,count(distinct ss_list_price) B6_CNTD - from store_sales - where ss_quantity between 26 and 30 - and (ss_list_price between 112 and 112+10 - or ss_coupon_amt between 7386 and 7386+1000 - or ss_wholesale_cost between 72 and 72+20)) B6 -limit 100; - --- end template query28.tpl query 69 in stream 3 --- start template query95.tpl query 70 in stream 3 -with /* TPC-DS query95.tpl 0.43 */ ws_wh as -(select ws1.ws_order_number,ws1.ws_warehouse_sk wh1,ws2.ws_warehouse_sk wh2 - from web_sales ws1,web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) - select - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2000-2-01' and - dateadd(day,60,cast('2000-2-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'NE' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and ws1.ws_order_number in (select ws_order_number - from ws_wh) -and ws1.ws_order_number in (select wr_order_number - from web_returns,ws_wh - where wr_order_number = ws_wh.ws_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query95.tpl query 70 in stream 3 --- start template query12.tpl query 71 in stream 3 -select /* TPC-DS query12.tpl 0.64 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ws_ext_sales_price) as itemrevenue - ,sum(ws_ext_sales_price)*100/sum(sum(ws_ext_sales_price)) over - (partition by i_class) as revenueratio -from - web_sales - ,item - ,date_dim -where - ws_item_sk = i_item_sk - and i_category in ('Electronics', 'Jewelry', 'Children') - and ws_sold_date_sk = d_date_sk - and d_date between cast('1998-06-17' as date) - and dateadd(day,30,cast('1998-06-17' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query12.tpl query 71 in stream 3 --- start template query64.tpl query 72 in stream 3 -with /* TPC-DS query64.tpl 0.20 */ cs_ui as - (select cs_item_sk - ,sum(cs_ext_list_price) as sale,sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit) as refund - from catalog_sales - ,catalog_returns - where cs_item_sk = cr_item_sk - and cs_order_number = cr_order_number - group by cs_item_sk - having sum(cs_ext_list_price)>2*sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit)), -cross_sales as - (select i_product_name product_name - ,i_item_sk item_sk - ,s_store_name store_name - ,s_zip store_zip - ,ad1.ca_street_number b_street_number - ,ad1.ca_street_name b_street_name - ,ad1.ca_city b_city - ,ad1.ca_zip b_zip - ,ad2.ca_street_number c_street_number - ,ad2.ca_street_name c_street_name - ,ad2.ca_city c_city - ,ad2.ca_zip c_zip - ,d1.d_year as syear - ,d2.d_year as fsyear - ,d3.d_year s2year - ,count(*) cnt - ,sum(ss_wholesale_cost) s1 - ,sum(ss_list_price) s2 - ,sum(ss_coupon_amt) s3 - FROM store_sales - ,store_returns - ,cs_ui - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,customer - ,customer_demographics cd1 - ,customer_demographics cd2 - ,promotion - ,household_demographics hd1 - ,household_demographics hd2 - ,customer_address ad1 - ,customer_address ad2 - ,income_band ib1 - ,income_band ib2 - ,item - WHERE ss_store_sk = s_store_sk AND - ss_sold_date_sk = d1.d_date_sk AND - ss_customer_sk = c_customer_sk AND - ss_cdemo_sk= cd1.cd_demo_sk AND - ss_hdemo_sk = hd1.hd_demo_sk AND - ss_addr_sk = ad1.ca_address_sk and - ss_item_sk = i_item_sk and - ss_item_sk = sr_item_sk and - ss_ticket_number = sr_ticket_number and - ss_item_sk = cs_ui.cs_item_sk and - c_current_cdemo_sk = cd2.cd_demo_sk AND - c_current_hdemo_sk = hd2.hd_demo_sk AND - c_current_addr_sk = ad2.ca_address_sk and - c_first_sales_date_sk = d2.d_date_sk and - c_first_shipto_date_sk = d3.d_date_sk and - ss_promo_sk = p_promo_sk and - hd1.hd_income_band_sk = ib1.ib_income_band_sk and - hd2.hd_income_band_sk = ib2.ib_income_band_sk and - cd1.cd_marital_status <> cd2.cd_marital_status and - i_color in ('deep','snow','yellow','gainsboro','blanched','black') and - i_current_price between 6 and 6 + 10 and - i_current_price between 6 + 1 and 6 + 15 -group by i_product_name - ,i_item_sk - ,s_store_name - ,s_zip - ,ad1.ca_street_number - ,ad1.ca_street_name - ,ad1.ca_city - ,ad1.ca_zip - ,ad2.ca_street_number - ,ad2.ca_street_name - ,ad2.ca_city - ,ad2.ca_zip - ,d1.d_year - ,d2.d_year - ,d3.d_year -) -select cs1.product_name - ,cs1.store_name - ,cs1.store_zip - ,cs1.b_street_number - ,cs1.b_street_name - ,cs1.b_city - ,cs1.b_zip - ,cs1.c_street_number - ,cs1.c_street_name - ,cs1.c_city - ,cs1.c_zip - ,cs1.syear - ,cs1.cnt - ,cs1.s1 as s11 - ,cs1.s2 as s21 - ,cs1.s3 as s31 - ,cs2.s1 as s12 - ,cs2.s2 as s22 - ,cs2.s3 as s32 - ,cs2.syear - ,cs2.cnt -from cross_sales cs1,cross_sales cs2 -where cs1.item_sk=cs2.item_sk and - cs1.syear = 1999 and - cs2.syear = 1999 + 1 and - cs2.cnt <= cs1.cnt and - cs1.store_name = cs2.store_name and - cs1.store_zip = cs2.store_zip -order by cs1.product_name - ,cs1.store_name - ,cs2.cnt - ,cs1.s1 - ,cs2.s1; - --- end template query64.tpl query 72 in stream 3 --- start template query15.tpl query 73 in stream 3 -select /* TPC-DS query15.tpl 0.57 */ ca_zip - ,sum(cs_sales_price) - from catalog_sales - ,customer - ,customer_address - ,date_dim - where cs_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', - '85392', '85460', '80348', '81792') - or ca_state in ('CA','WA','GA') - or cs_sales_price > 500) - and cs_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 1999 - group by ca_zip - order by ca_zip - limit 100; - --- end template query15.tpl query 73 in stream 3 --- start template query25.tpl query 74 in stream 3 -select /* TPC-DS query25.tpl 0.9 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,avg(ss_net_profit) as store_sales_profit - ,avg(sr_net_loss) as store_returns_loss - ,avg(cs_net_profit) as catalog_sales_profit - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 2001 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 10 - and d2.d_year = 2001 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_moy between 4 and 10 - and d3.d_year = 2001 - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query25.tpl query 74 in stream 3 --- start template query93.tpl query 75 in stream 3 -select /* TPC-DS query93.tpl 0.52 */ ss_customer_sk - ,sum(act_sales) sumsales - from (select ss_item_sk - ,ss_ticket_number - ,ss_customer_sk - ,case when sr_return_quantity is not null then (ss_quantity-sr_return_quantity)*ss_sales_price - else (ss_quantity*ss_sales_price) end act_sales - from store_sales left outer join store_returns on (sr_item_sk = ss_item_sk - and sr_ticket_number = ss_ticket_number) - ,reason - where sr_reason_sk = r_reason_sk - and r_reason_desc = 'reason 75') t - group by ss_customer_sk - order by sumsales, ss_customer_sk -limit 100; - --- end template query93.tpl query 75 in stream 3 --- start template query9.tpl query 76 in stream 3 -select /* TPC-DS query9.tpl 0.49 */ case when (select count(*) - from store_sales - where ss_quantity between 1 and 20) > 2318207835 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 1 and 20) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 1 and 20) end bucket1 , - case when (select count(*) - from store_sales - where ss_quantity between 21 and 40) > 2821119084 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 21 and 40) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 21 and 40) end bucket2, - case when (select count(*) - from store_sales - where ss_quantity between 41 and 60) > 3305402934 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 41 and 60) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 41 and 60) end bucket3, - case when (select count(*) - from store_sales - where ss_quantity between 61 and 80) > 3465197024 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 61 and 80) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 61 and 80) end bucket4, - case when (select count(*) - from store_sales - where ss_quantity between 81 and 100) > 3816333958 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 81 and 100) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 81 and 100) end bucket5 -from reason -where r_reason_sk = 1 -; - --- end template query9.tpl query 76 in stream 3 --- start template query65.tpl query 77 in stream 3 -select /* TPC-DS query65.tpl 0.71 */ - s_store_name, - i_item_desc, - sc.revenue, - i_current_price, - i_wholesale_cost, - i_brand - from store, item, - (select ss_store_sk, avg(revenue) as ave - from - (select ss_store_sk, ss_item_sk, - sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1209 and 1209+11 - group by ss_store_sk, ss_item_sk) sa - group by ss_store_sk) sb, - (select ss_store_sk, ss_item_sk, sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1209 and 1209+11 - group by ss_store_sk, ss_item_sk) sc - where sb.ss_store_sk = sc.ss_store_sk and - sc.revenue <= 0.1 * sb.ave and - s_store_sk = sc.ss_store_sk and - i_item_sk = sc.ss_item_sk - order by s_store_name, i_item_desc -limit 100; - --- end template query65.tpl query 77 in stream 3 --- start template query71.tpl query 78 in stream 3 -select /* TPC-DS query71.tpl 0.72 */ i_brand_id brand_id, i_brand brand,t_hour,t_minute, - sum(ext_price) ext_price - from item, (select ws_ext_sales_price as ext_price, - ws_sold_date_sk as sold_date_sk, - ws_item_sk as sold_item_sk, - ws_sold_time_sk as time_sk - from web_sales,date_dim - where d_date_sk = ws_sold_date_sk - and d_moy=11 - and d_year=1999 - union all - select cs_ext_sales_price as ext_price, - cs_sold_date_sk as sold_date_sk, - cs_item_sk as sold_item_sk, - cs_sold_time_sk as time_sk - from catalog_sales,date_dim - where d_date_sk = cs_sold_date_sk - and d_moy=11 - and d_year=1999 - union all - select ss_ext_sales_price as ext_price, - ss_sold_date_sk as sold_date_sk, - ss_item_sk as sold_item_sk, - ss_sold_time_sk as time_sk - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - and d_moy=11 - and d_year=1999 - ) tmp,time_dim - where - sold_item_sk = i_item_sk - and i_manager_id=1 - and time_sk = t_time_sk - and (t_meal_time = 'breakfast' or t_meal_time = 'dinner') - group by i_brand, i_brand_id,t_hour,t_minute - order by ext_price desc, i_brand_id - ; - --- end template query71.tpl query 78 in stream 3 --- start template query57.tpl query 79 in stream 3 -with /* TPC-DS query57.tpl 0.70 */ v1 as( - select i_category, i_brand, - cc_name, - d_year, d_moy, - sum(cs_sales_price) sum_sales, - avg(sum(cs_sales_price)) over - (partition by i_category, i_brand, - cc_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - cc_name - order by d_year, d_moy) rn - from item, catalog_sales, date_dim, call_center - where cs_item_sk = i_item_sk and - cs_sold_date_sk = d_date_sk and - cc_call_center_sk= cs_call_center_sk and - ( - d_year = 1999 or - ( d_year = 1999-1 and d_moy =12) or - ( d_year = 1999+1 and d_moy =1) - ) - group by i_category, i_brand, - cc_name , d_year, d_moy), - v2 as( - select v1.cc_name - ,v1.d_year, v1.d_moy - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1. cc_name = v1_lag. cc_name and - v1. cc_name = v1_lead. cc_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 1999 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, psum - limit 100; - --- end template query57.tpl query 79 in stream 3 --- start template query32.tpl query 80 in stream 3 -select /* TPC-DS query32.tpl 0.7 */ sum(cs_ext_discount_amt) as "excess discount amount" -from - catalog_sales - ,item - ,date_dim -where -i_manufact_id = 300 -and i_item_sk = cs_item_sk -and d_date between '1999-01-05' and - dateadd(day,90,cast('1999-01-05' as date)) -and d_date_sk = cs_sold_date_sk -and cs_ext_discount_amt - > ( - select - 1.3 * avg(cs_ext_discount_amt) - from - catalog_sales - ,date_dim - where - cs_item_sk = i_item_sk - and d_date between '1999-01-05' and - dateadd(day,90,cast('1999-01-05' as date)) - and d_date_sk = cs_sold_date_sk - ) -limit 100; - --- end template query32.tpl query 80 in stream 3 --- start template query61.tpl query 81 in stream 3 -select /* TPC-DS query61.tpl 0.97 */ promotions,total,cast(promotions as decimal(16,4))/cast(total as decimal(16,4))*100 -from - (select sum(ss_ext_sales_price) promotions - from store_sales - ,store - ,promotion - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_promo_sk = p_promo_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -7 - and i_category = 'Books' - and (p_channel_dmail = 'Y' or p_channel_email = 'Y' or p_channel_tv = 'Y') - and s_gmt_offset = -7 - and d_year = 1998 - and d_moy = 12) promotional_sales, - (select sum(ss_ext_sales_price) total - from store_sales - ,store - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -7 - and i_category = 'Books' - and s_gmt_offset = -7 - and d_year = 1998 - and d_moy = 12) all_sales -order by promotions, total -limit 100; - --- end template query61.tpl query 81 in stream 3 --- start template query85.tpl query 82 in stream 3 -select /* TPC-DS query85.tpl 0.33 */ substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) - from web_sales, web_returns, web_page, customer_demographics cd1, - customer_demographics cd2, customer_address, date_dim, reason - where ws_web_page_sk = wp_web_page_sk - and ws_item_sk = wr_item_sk - and ws_order_number = wr_order_number - and ws_sold_date_sk = d_date_sk and d_year = 2000 - and cd1.cd_demo_sk = wr_refunded_cdemo_sk - and cd2.cd_demo_sk = wr_returning_cdemo_sk - and ca_address_sk = wr_refunded_addr_sk - and r_reason_sk = wr_reason_sk - and - ( - ( - cd1.cd_marital_status = 'D' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = '2 yr Degree' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 100.00 and 150.00 - ) - or - ( - cd1.cd_marital_status = 'U' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = '4 yr Degree' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 50.00 and 100.00 - ) - or - ( - cd1.cd_marital_status = 'W' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Advanced Degree' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ca_country = 'United States' - and - ca_state in ('PA', 'TX', 'SC') - and ws_net_profit between 100 and 200 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('IA', 'VA', 'FL') - and ws_net_profit between 150 and 300 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('MN', 'SD', 'AK') - and ws_net_profit between 50 and 250 - ) - ) -group by r_reason_desc -order by substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) -limit 100; - --- end template query85.tpl query 82 in stream 3 --- start template query73.tpl query 83 in stream 3 -select /* TPC-DS query73.tpl 0.79 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_buy_potential = '>10000' or - household_demographics.hd_buy_potential = '5001-10000') - and household_demographics.hd_vehicle_count > 0 - and case when household_demographics.hd_vehicle_count > 0 then - household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count else null end > 1 - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_county in ('Murray County','Fulton County','Kootenai County','Forsyth County') - group by ss_ticket_number,ss_customer_sk) dj,customer - where ss_customer_sk = c_customer_sk - and cnt between 1 and 5 - order by cnt desc, c_last_name asc; - --- end template query73.tpl query 83 in stream 3 --- start template query98.tpl query 84 in stream 3 -select /* TPC-DS query98.tpl 0.32 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ss_ext_sales_price) as itemrevenue - ,sum(ss_ext_sales_price)*100/sum(sum(ss_ext_sales_price)) over - (partition by i_class) as revenueratio -from - store_sales - ,item - ,date_dim -where - ss_item_sk = i_item_sk - and i_category in ('Home', 'Shoes', 'Jewelry') - and ss_sold_date_sk = d_date_sk - and d_date between cast('2002-04-07' as date) - and dateadd(day,30,cast('2002-04-07' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio; - --- end template query98.tpl query 84 in stream 3 --- start template query77a.tpl query 85 in stream 3 -with /* TPC-DS query77a.tpl 0.78 */ ss as - (select s_store_sk, - sum(ss_ext_sales_price) as sales, - sum(ss_net_profit) as profit - from store_sales, - date_dim, - store - where ss_sold_date_sk = d_date_sk - and d_date between cast('2000-08-03' as date) - and dateadd(day,30,cast('2000-08-03' as date)) - and ss_store_sk = s_store_sk - group by s_store_sk) - , - sr as - (select s_store_sk, - sum(sr_return_amt) as returns, - sum(sr_net_loss) as profit_loss - from store_returns, - date_dim, - store - where sr_returned_date_sk = d_date_sk - and d_date between cast('2000-08-03' as date) - and dateadd(day,30,cast('2000-08-03' as date)) - and sr_store_sk = s_store_sk - group by s_store_sk), - cs as - (select cs_call_center_sk, - sum(cs_ext_sales_price) as sales, - sum(cs_net_profit) as profit - from catalog_sales, - date_dim - where cs_sold_date_sk = d_date_sk - and d_date between cast('2000-08-03' as date) - and dateadd(day,30,cast('2000-08-03' as date)) - group by cs_call_center_sk - ), - cr as - (select cr_call_center_sk, - sum(cr_return_amount) as returns, - sum(cr_net_loss) as profit_loss - from catalog_returns, - date_dim - where cr_returned_date_sk = d_date_sk - and d_date between cast('2000-08-03' as date) - and dateadd(day,30,cast('2000-08-03' as date)) - group by cr_call_center_sk), - ws as - ( select wp_web_page_sk, - sum(ws_ext_sales_price) as sales, - sum(ws_net_profit) as profit - from web_sales, - date_dim, - web_page - where ws_sold_date_sk = d_date_sk - and d_date between cast('2000-08-03' as date) - and dateadd(day,30,cast('2000-08-03' as date)) - and ws_web_page_sk = wp_web_page_sk - group by wp_web_page_sk), - wr as - (select wp_web_page_sk, - sum(wr_return_amt) as returns, - sum(wr_net_loss) as profit_loss - from web_returns, - date_dim, - web_page - where wr_returned_date_sk = d_date_sk - and d_date between cast('2000-08-03' as date) - and dateadd(day,30,cast('2000-08-03' as date)) - and wr_web_page_sk = wp_web_page_sk - group by wp_web_page_sk) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , ss.s_store_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ss left join sr - on ss.s_store_sk = sr.s_store_sk - union all - select 'catalog channel' as channel - , cs_call_center_sk as id - , sales - , returns - , (profit - profit_loss) as profit - from cs - , cr - union all - select 'web channel' as channel - , ws.wp_web_page_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ws left join wr - on ws.wp_web_page_sk = wr.wp_web_page_sk - ) x - group by channel, id ) - - select * - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results -) foo -order by channel, id - limit 100; - --- end template query77a.tpl query 85 in stream 3 --- start template query45.tpl query 86 in stream 3 -select /* TPC-DS query45.tpl 0.18 */ ca_zip, ca_state, sum(ws_sales_price) - from web_sales, customer, customer_address, date_dim, item - where ws_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ws_item_sk = i_item_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', '85392', '85460', '80348', '81792') - or - i_item_id in (select i_item_id - from item - where i_item_sk in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29) - ) - ) - and ws_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 2001 - group by ca_zip, ca_state - order by ca_zip, ca_state - limit 100; - --- end template query45.tpl query 86 in stream 3 --- start template query20.tpl query 87 in stream 3 -select /* TPC-DS query20.tpl 0.65 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(cs_ext_sales_price) as itemrevenue - ,sum(cs_ext_sales_price)*100/sum(sum(cs_ext_sales_price)) over - (partition by i_class) as revenueratio - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and i_category in ('Electronics', 'Men', 'Women') - and cs_sold_date_sk = d_date_sk - and d_date between cast('2001-04-12' as date) - and dateadd(day,30,cast('2001-04-12' as date)) - group by i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - order by i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query20.tpl query 87 in stream 3 --- start template query50.tpl query 88 in stream 3 -select /* TPC-DS query50.tpl 0.60 */ - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 30) and - (sr_returned_date_sk - ss_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 60) and - (sr_returned_date_sk - ss_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 90) and - (sr_returned_date_sk - ss_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - store_sales - ,store_returns - ,store - ,date_dim d1 - ,date_dim d2 -where - d2.d_year = 2000 -and d2.d_moy = 8 -and ss_ticket_number = sr_ticket_number -and ss_item_sk = sr_item_sk -and ss_sold_date_sk = d1.d_date_sk -and sr_returned_date_sk = d2.d_date_sk -and ss_customer_sk = sr_customer_sk -and ss_store_sk = s_store_sk -group by - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -order by s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -limit 100; - --- end template query50.tpl query 88 in stream 3 --- start template query70a.tpl query 89 in stream 3 -with /* TPC-DS query70a.tpl 0.34 */ results as -( select - sum(ss_net_profit) as total_sum ,s_state ,s_county, 0 as gstate, 0 as g_county - from - store_sales - ,date_dim d1 - ,store - where - d1.d_month_seq between 1178 and 1178 + 11 - and d1.d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - and s_state in - ( select s_state - from (select s_state as s_state, - rank() over ( partition by s_state order by sum(ss_net_profit) desc) as ranking - from store_sales, store, date_dim - where d_month_seq between 1178 and 1178 + 11 - and d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - group by s_state - ) tmp1 - where ranking <= 5) - group by s_state,s_county) , - results_rollup as -(select total_sum ,s_state ,s_county, 0 as g_state, 0 as g_county, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum,s_state, NULL as s_county, 0 as g_state, 1 as g_county, 1 as lochierarchy from results group by s_state - union - select sum(total_sum) as total_sum ,NULL as s_state ,NULL as s_county, 1 as g_state, 1 as g_county, 2 as lochierarchy from results) - select total_sum ,s_state ,s_county, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_county = 0 then s_state end - order by total_sum desc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then s_state end - ,rank_within_parent - limit 100; - --- end template query70a.tpl query 89 in stream 3 --- start template query75.tpl query 90 in stream 3 -WITH /* TPC-DS query75.tpl 0.3 */ all_sales AS ( - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,SUM(sales_cnt) AS sales_cnt - ,SUM(sales_amt) AS sales_amt - FROM (SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,cs_quantity - COALESCE(cr_return_quantity,0) AS sales_cnt - ,cs_ext_sales_price - COALESCE(cr_return_amount,0.0) AS sales_amt - FROM catalog_sales JOIN item ON i_item_sk=cs_item_sk - JOIN date_dim ON d_date_sk=cs_sold_date_sk - LEFT JOIN catalog_returns ON (cs_order_number=cr_order_number - AND cs_item_sk=cr_item_sk) - WHERE i_category='Books' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ss_quantity - COALESCE(sr_return_quantity,0) AS sales_cnt - ,ss_ext_sales_price - COALESCE(sr_return_amt,0.0) AS sales_amt - FROM store_sales JOIN item ON i_item_sk=ss_item_sk - JOIN date_dim ON d_date_sk=ss_sold_date_sk - LEFT JOIN store_returns ON (ss_ticket_number=sr_ticket_number - AND ss_item_sk=sr_item_sk) - WHERE i_category='Books' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ws_quantity - COALESCE(wr_return_quantity,0) AS sales_cnt - ,ws_ext_sales_price - COALESCE(wr_return_amt,0.0) AS sales_amt - FROM web_sales JOIN item ON i_item_sk=ws_item_sk - JOIN date_dim ON d_date_sk=ws_sold_date_sk - LEFT JOIN web_returns ON (ws_order_number=wr_order_number - AND ws_item_sk=wr_item_sk) - WHERE i_category='Books') sales_detail - GROUP BY d_year, i_brand_id, i_class_id, i_category_id, i_manufact_id) - SELECT prev_yr.d_year AS prev_year - ,curr_yr.d_year AS year - ,curr_yr.i_brand_id - ,curr_yr.i_class_id - ,curr_yr.i_category_id - ,curr_yr.i_manufact_id - ,prev_yr.sales_cnt AS prev_yr_cnt - ,curr_yr.sales_cnt AS curr_yr_cnt - ,curr_yr.sales_cnt-prev_yr.sales_cnt AS sales_cnt_diff - ,curr_yr.sales_amt-prev_yr.sales_amt AS sales_amt_diff - FROM all_sales curr_yr, all_sales prev_yr - WHERE curr_yr.i_brand_id=prev_yr.i_brand_id - AND curr_yr.i_class_id=prev_yr.i_class_id - AND curr_yr.i_category_id=prev_yr.i_category_id - AND curr_yr.i_manufact_id=prev_yr.i_manufact_id - AND curr_yr.d_year=2001 - AND prev_yr.d_year=2001-1 - AND CAST(curr_yr.sales_cnt AS DECIMAL(17,2))/CAST(prev_yr.sales_cnt AS DECIMAL(17,2))<0.9 - ORDER BY sales_cnt_diff,sales_amt_diff - limit 100; - --- end template query75.tpl query 90 in stream 3 --- start template query91.tpl query 91 in stream 3 -select /* TPC-DS query91.tpl 0.13 */ - cc_call_center_id Call_Center, - cc_name Call_Center_Name, - cc_manager Manager, - sum(cr_net_loss) Returns_Loss -from - call_center, - catalog_returns, - date_dim, - customer, - customer_address, - customer_demographics, - household_demographics -where - cr_call_center_sk = cc_call_center_sk -and cr_returned_date_sk = d_date_sk -and cr_returning_customer_sk= c_customer_sk -and cd_demo_sk = c_current_cdemo_sk -and hd_demo_sk = c_current_hdemo_sk -and ca_address_sk = c_current_addr_sk -and d_year = 2002 -and d_moy = 12 -and ( (cd_marital_status = 'M' and cd_education_status = 'Unknown') - or(cd_marital_status = 'W' and cd_education_status = 'Advanced Degree')) -and hd_buy_potential like 'Unknown%' -and ca_gmt_offset = -7 -group by cc_call_center_id,cc_name,cc_manager,cd_marital_status,cd_education_status -order by sum(cr_net_loss) desc; - --- end template query91.tpl query 91 in stream 3 --- start template query17.tpl query 92 in stream 3 -select /* TPC-DS query17.tpl 0.41 */ i_item_id - ,i_item_desc - ,s_state - ,count(ss_quantity) as store_sales_quantitycount - ,avg(ss_quantity) as store_sales_quantityave - ,stddev_samp(ss_quantity) as store_sales_quantitystdev - ,stddev_samp(ss_quantity)/avg(ss_quantity) as store_sales_quantitycov - ,count(sr_return_quantity) as store_returns_quantitycount - ,avg(sr_return_quantity) as store_returns_quantityave - ,stddev_samp(sr_return_quantity) as store_returns_quantitystdev - ,stddev_samp(sr_return_quantity)/avg(sr_return_quantity) as store_returns_quantitycov - ,count(cs_quantity) as catalog_sales_quantitycount ,avg(cs_quantity) as catalog_sales_quantityave - ,stddev_samp(cs_quantity) as catalog_sales_quantitystdev - ,stddev_samp(cs_quantity)/avg(cs_quantity) as catalog_sales_quantitycov - from store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where d1.d_quarter_name = '2000Q1' - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_quarter_name in ('2000Q1','2000Q2','2000Q3') - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_quarter_name in ('2000Q1','2000Q2','2000Q3') - group by i_item_id - ,i_item_desc - ,s_state - order by i_item_id - ,i_item_desc - ,s_state -limit 100; - --- end template query17.tpl query 92 in stream 3 --- start template query24.tpl query 93 in stream 3 -with /* TPC-DS query24.tpl 0.92 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_net_profit) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip -and s_market_id=10 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'saddle' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; -with /* TPC-DS query24.tpl 0.92 part2 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_net_profit) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip - and s_market_id = 10 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'linen' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; - --- end template query24.tpl query 93 in stream 3 --- start template query48.tpl query 94 in stream 3 -select /* TPC-DS query48.tpl 0.74 */ sum (ss_quantity) - from store_sales, store, customer_demographics, customer_address, date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 1998 - and - ( - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'D' - and - cd_education_status = '4 yr Degree' - and - ss_sales_price between 100.00 and 150.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'W' - and - cd_education_status = 'Advanced Degree' - and - ss_sales_price between 50.00 and 100.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'S' - and - cd_education_status = '2 yr Degree' - and - ss_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('VA', 'TX', 'AL') - and ss_net_profit between 0 and 2000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('PA', 'MO', 'MI') - and ss_net_profit between 150 and 3000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('WV', 'AR', 'NC') - and ss_net_profit between 50 and 25000 - ) - ) -; - --- end template query48.tpl query 94 in stream 3 --- start template query51.tpl query 95 in stream 3 -WITH /* TPC-DS query51.tpl 0.46 */ web_v1 as ( -select - ws_item_sk item_sk, d_date, - sum(sum(ws_sales_price)) - over (partition by ws_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from web_sales - ,date_dim -where ws_sold_date_sk=d_date_sk - and d_month_seq between 1202 and 1202+11 - and ws_item_sk is not NULL -group by ws_item_sk, d_date), -store_v1 as ( -select - ss_item_sk item_sk, d_date, - sum(sum(ss_sales_price)) - over (partition by ss_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from store_sales - ,date_dim -where ss_sold_date_sk=d_date_sk - and d_month_seq between 1202 and 1202+11 - and ss_item_sk is not NULL -group by ss_item_sk, d_date) - select * -from (select item_sk - ,d_date - ,web_sales - ,store_sales - ,max(web_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) web_cumulative - ,max(store_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) store_cumulative - from (select case when web.item_sk is not null then web.item_sk else store.item_sk end item_sk - ,case when web.d_date is not null then web.d_date else store.d_date end d_date - ,web.cume_sales web_sales - ,store.cume_sales store_sales - from web_v1 web full outer join store_v1 store on (web.item_sk = store.item_sk - and web.d_date = store.d_date) - )x )y -where web_cumulative > store_cumulative -order by item_sk - ,d_date -limit 100; - --- end template query51.tpl query 95 in stream 3 --- start template query79.tpl query 96 in stream 3 -select /* TPC-DS query79.tpl 0.89 */ - c_last_name,c_first_name,substring(s_city,1,30),ss_ticket_number,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,store.s_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (household_demographics.hd_dep_count = 1 or household_demographics.hd_vehicle_count > 1) - and date_dim.d_dow = 1 - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_number_employees between 200 and 295 - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,store.s_city) ms,customer - where ss_customer_sk = c_customer_sk - order by c_last_name,c_first_name,substring(s_city,1,30), profit -limit 100; - --- end template query79.tpl query 96 in stream 3 --- start template query35a.tpl query 97 in stream 3 -select /* TPC-DS query35a.tpl 0.47 */ - ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - count(*) cnt1, - max(cd_dep_count), - min(cd_dep_count), - avg(cd_dep_count), - cd_dep_employed_count, - count(*) cnt2, - max(cd_dep_employed_count), - min(cd_dep_employed_count), - avg(cd_dep_employed_count), - cd_dep_college_count, - count(*) cnt3, - max(cd_dep_college_count), - min(cd_dep_college_count), - avg(cd_dep_college_count) - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2000 and - d_qoy < 4) and - exists (select * from - (select ws_bill_customer_sk customsk - from web_sales,date_dim - where - ws_sold_date_sk = d_date_sk and - d_year = 2000 and - d_qoy < 4 - union all - select cs_ship_customer_sk customsk - from catalog_sales,date_dim - where - cs_sold_date_sk = d_date_sk and - d_year = 2000 and - d_qoy < 4)x - where x.customsk = c.c_customer_sk) - group by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - limit 100; - --- end template query35a.tpl query 97 in stream 3 --- start template query88.tpl query 98 in stream 3 -select /* TPC-DS query88.tpl 0.66 */ * -from - (select count(*) h8_30_to_9 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2)) - and store.s_store_name = 'ese') s1, - (select count(*) h9_to_9_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2)) - and store.s_store_name = 'ese') s2, - (select count(*) h9_30_to_10 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2)) - and store.s_store_name = 'ese') s3, - (select count(*) h10_to_10_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2)) - and store.s_store_name = 'ese') s4, - (select count(*) h10_30_to_11 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2)) - and store.s_store_name = 'ese') s5, - (select count(*) h11_to_11_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2)) - and store.s_store_name = 'ese') s6, - (select count(*) h11_30_to_12 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2)) - and store.s_store_name = 'ese') s7, - (select count(*) h12_to_12_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 12 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2)) - and store.s_store_name = 'ese') s8 -; - --- end template query88.tpl query 98 in stream 3 --- start template query49.tpl query 99 in stream 3 -select /* TPC-DS query49.tpl 0.48 */ channel, item, return_ratio, return_rank, currency_rank from - (select - 'web' as channel - ,web.item - ,web.return_ratio - ,web.return_rank - ,web.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select ws.ws_item_sk as item - ,(cast(sum(coalesce(wr.wr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(wr.wr_return_amt,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - web_sales ws left outer join web_returns wr - on (ws.ws_order_number = wr.wr_order_number and - ws.ws_item_sk = wr.wr_item_sk) - ,date_dim - where - wr.wr_return_amt > 10000 - and ws.ws_net_profit > 1 - and ws.ws_net_paid > 0 - and ws.ws_quantity > 0 - and ws_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 12 - group by ws.ws_item_sk - ) in_web - ) web - where - ( - web.return_rank <= 10 - or - web.currency_rank <= 10 - ) - union - select - 'catalog' as channel - ,catalog.item - ,catalog.return_ratio - ,catalog.return_rank - ,catalog.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select - cs.cs_item_sk as item - ,(cast(sum(coalesce(cr.cr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(cr.cr_return_amount,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - catalog_sales cs left outer join catalog_returns cr - on (cs.cs_order_number = cr.cr_order_number and - cs.cs_item_sk = cr.cr_item_sk) - ,date_dim - where - cr.cr_return_amount > 10000 - and cs.cs_net_profit > 1 - and cs.cs_net_paid > 0 - and cs.cs_quantity > 0 - and cs_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 12 - group by cs.cs_item_sk - ) in_cat - ) catalog - where - ( - catalog.return_rank <= 10 - or - catalog.currency_rank <=10 - ) - union - select - 'store' as channel - ,store.item - ,store.return_ratio - ,store.return_rank - ,store.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select sts.ss_item_sk as item - ,(cast(sum(coalesce(sr.sr_return_quantity,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(sr.sr_return_amt,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - store_sales sts left outer join store_returns sr - on (sts.ss_ticket_number = sr.sr_ticket_number and sts.ss_item_sk = sr.sr_item_sk) - ,date_dim - where - sr.sr_return_amt > 10000 - and sts.ss_net_profit > 1 - and sts.ss_net_paid > 0 - and sts.ss_quantity > 0 - and ss_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 12 - group by sts.ss_item_sk - ) in_store - ) store - where ( - store.return_rank <= 10 - or - store.currency_rank <= 10 - ) - ) - order by 1,4,5,2 - limit 100; - --- end template query49.tpl query 99 in stream 3 diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/100TB/queries/query_4.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/100TB/queries/query_4.sql deleted file mode 100644 index 117e7824..00000000 --- a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/100TB/queries/query_4.sql +++ /dev/null @@ -1,5027 +0,0 @@ --- start template query79.tpl query 1 in stream 4 -select /* TPC-DS query79.tpl 0.89 */ - c_last_name,c_first_name,substring(s_city,1,30),ss_ticket_number,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,store.s_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (household_demographics.hd_dep_count = 0 or household_demographics.hd_vehicle_count > 3) - and date_dim.d_dow = 1 - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_number_employees between 200 and 295 - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,store.s_city) ms,customer - where ss_customer_sk = c_customer_sk - order by c_last_name,c_first_name,substring(s_city,1,30), profit -limit 100; - --- end template query79.tpl query 1 in stream 4 --- start template query39.tpl query 2 in stream 4 -with /* TPC-DS query39.tpl 0.5 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =2002 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=4 - and inv2.d_moy=4+1 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; -with /* TPC-DS query39.tpl 0.5 part2 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =2002 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=4 - and inv2.d_moy=4+1 - and inv1.cov > 1.5 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; - --- end template query39.tpl query 2 in stream 4 --- start template query93.tpl query 3 in stream 4 -select /* TPC-DS query93.tpl 0.52 */ ss_customer_sk - ,sum(act_sales) sumsales - from (select ss_item_sk - ,ss_ticket_number - ,ss_customer_sk - ,case when sr_return_quantity is not null then (ss_quantity-sr_return_quantity)*ss_sales_price - else (ss_quantity*ss_sales_price) end act_sales - from store_sales left outer join store_returns on (sr_item_sk = ss_item_sk - and sr_ticket_number = ss_ticket_number) - ,reason - where sr_reason_sk = r_reason_sk - and r_reason_desc = 'reason 69') t - group by ss_customer_sk - order by sumsales, ss_customer_sk -limit 100; - --- end template query93.tpl query 3 in stream 4 --- start template query41.tpl query 4 in stream 4 -select /* TPC-DS query41.tpl 0.62 */ distinct(i_product_name) - from item i1 - where i_manufact_id between 772 and 772+40 - and (select count(*) as item_cnt - from item - where (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'goldenrod' or i_color = 'spring') and - (i_units = 'Cup' or i_units = 'Carton') and - (i_size = 'extra large' or i_size = 'N/A') - ) or - (i_category = 'Women' and - (i_color = 'sienna' or i_color = 'navajo') and - (i_units = 'Oz' or i_units = 'Box') and - (i_size = 'medium' or i_size = 'economy') - ) or - (i_category = 'Men' and - (i_color = 'sky' or i_color = 'dodger') and - (i_units = 'Bunch' or i_units = 'Ton') and - (i_size = 'large' or i_size = 'petite') - ) or - (i_category = 'Men' and - (i_color = 'turquoise' or i_color = 'beige') and - (i_units = 'Tbl' or i_units = 'Bundle') and - (i_size = 'extra large' or i_size = 'N/A') - ))) or - (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'deep' or i_color = 'white') and - (i_units = 'Pallet' or i_units = 'Gross') and - (i_size = 'extra large' or i_size = 'N/A') - ) or - (i_category = 'Women' and - (i_color = 'tomato' or i_color = 'magenta') and - (i_units = 'Ounce' or i_units = 'Each') and - (i_size = 'medium' or i_size = 'economy') - ) or - (i_category = 'Men' and - (i_color = 'salmon' or i_color = 'olive') and - (i_units = 'Dozen' or i_units = 'Dram') and - (i_size = 'large' or i_size = 'petite') - ) or - (i_category = 'Men' and - (i_color = 'thistle' or i_color = 'forest') and - (i_units = 'N/A' or i_units = 'Pound') and - (i_size = 'extra large' or i_size = 'N/A') - )))) > 0 - order by i_product_name - limit 100; - --- end template query41.tpl query 4 in stream 4 --- start template query29.tpl query 5 in stream 4 -select /* TPC-DS query29.tpl 0.53 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,sum(ss_quantity) as store_sales_quantity - ,sum(sr_return_quantity) as store_returns_quantity - ,sum(cs_quantity) as catalog_sales_quantity - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 2000 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 4 + 3 - and d2.d_year = 2000 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_year in (2000,2000+1,2000+2) - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query29.tpl query 5 in stream 4 --- start template query32.tpl query 6 in stream 4 -select /* TPC-DS query32.tpl 0.7 */ sum(cs_ext_discount_amt) as "excess discount amount" -from - catalog_sales - ,item - ,date_dim -where -i_manufact_id = 97 -and i_item_sk = cs_item_sk -and d_date between '2000-03-11' and - dateadd(day,90,cast('2000-03-11' as date)) -and d_date_sk = cs_sold_date_sk -and cs_ext_discount_amt - > ( - select - 1.3 * avg(cs_ext_discount_amt) - from - catalog_sales - ,date_dim - where - cs_item_sk = i_item_sk - and d_date between '2000-03-11' and - dateadd(day,90,cast('2000-03-11' as date)) - and d_date_sk = cs_sold_date_sk - ) -limit 100; - --- end template query32.tpl query 6 in stream 4 --- start template query66.tpl query 7 in stream 4 -select /* TPC-DS query66.tpl 0.39 */ - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - ,sum(jan_sales) as jan_sales - ,sum(feb_sales) as feb_sales - ,sum(mar_sales) as mar_sales - ,sum(apr_sales) as apr_sales - ,sum(may_sales) as may_sales - ,sum(jun_sales) as jun_sales - ,sum(jul_sales) as jul_sales - ,sum(aug_sales) as aug_sales - ,sum(sep_sales) as sep_sales - ,sum(oct_sales) as oct_sales - ,sum(nov_sales) as nov_sales - ,sum(dec_sales) as dec_sales - ,sum(jan_sales/w_warehouse_sq_ft) as jan_sales_per_sq_foot - ,sum(feb_sales/w_warehouse_sq_ft) as feb_sales_per_sq_foot - ,sum(mar_sales/w_warehouse_sq_ft) as mar_sales_per_sq_foot - ,sum(apr_sales/w_warehouse_sq_ft) as apr_sales_per_sq_foot - ,sum(may_sales/w_warehouse_sq_ft) as may_sales_per_sq_foot - ,sum(jun_sales/w_warehouse_sq_ft) as jun_sales_per_sq_foot - ,sum(jul_sales/w_warehouse_sq_ft) as jul_sales_per_sq_foot - ,sum(aug_sales/w_warehouse_sq_ft) as aug_sales_per_sq_foot - ,sum(sep_sales/w_warehouse_sq_ft) as sep_sales_per_sq_foot - ,sum(oct_sales/w_warehouse_sq_ft) as oct_sales_per_sq_foot - ,sum(nov_sales/w_warehouse_sq_ft) as nov_sales_per_sq_foot - ,sum(dec_sales/w_warehouse_sq_ft) as dec_sales_per_sq_foot - ,sum(jan_net) as jan_net - ,sum(feb_net) as feb_net - ,sum(mar_net) as mar_net - ,sum(apr_net) as apr_net - ,sum(may_net) as may_net - ,sum(jun_net) as jun_net - ,sum(jul_net) as jul_net - ,sum(aug_net) as aug_net - ,sum(sep_net) as sep_net - ,sum(oct_net) as oct_net - ,sum(nov_net) as nov_net - ,sum(dec_net) as dec_net - from ( - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'HARMSTORF' || ',' || 'GERMA' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then ws_ext_list_price* ws_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then ws_ext_list_price* ws_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then ws_ext_list_price* ws_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then ws_ext_list_price* ws_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then ws_ext_list_price* ws_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then ws_ext_list_price* ws_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then ws_ext_list_price* ws_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then ws_ext_list_price* ws_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then ws_ext_list_price* ws_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then ws_ext_list_price* ws_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then ws_ext_list_price* ws_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then ws_ext_list_price* ws_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then ws_net_profit * ws_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then ws_net_profit * ws_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then ws_net_profit * ws_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then ws_net_profit * ws_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then ws_net_profit * ws_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then ws_net_profit * ws_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then ws_net_profit * ws_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then ws_net_profit * ws_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then ws_net_profit * ws_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then ws_net_profit * ws_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then ws_net_profit * ws_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then ws_net_profit * ws_quantity else 0 end) as dec_net - from - web_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - ws_warehouse_sk = w_warehouse_sk - and ws_sold_date_sk = d_date_sk - and ws_sold_time_sk = t_time_sk - and ws_ship_mode_sk = sm_ship_mode_sk - and d_year = 1999 - and t_time between 9421 and 9421+28800 - and sm_carrier in ('HARMSTORF','GERMA') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - union all - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'HARMSTORF' || ',' || 'GERMA' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then cs_sales_price* cs_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then cs_sales_price* cs_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then cs_sales_price* cs_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then cs_sales_price* cs_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then cs_sales_price* cs_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then cs_sales_price* cs_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then cs_sales_price* cs_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then cs_sales_price* cs_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then cs_sales_price* cs_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then cs_sales_price* cs_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then cs_sales_price* cs_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then cs_sales_price* cs_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as dec_net - from - catalog_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and cs_sold_time_sk = t_time_sk - and cs_ship_mode_sk = sm_ship_mode_sk - and d_year = 1999 - and t_time between 9421 AND 9421+28800 - and sm_carrier in ('HARMSTORF','GERMA') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - ) x - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - order by w_warehouse_name - limit 100; - --- end template query66.tpl query 7 in stream 4 --- start template query84.tpl query 8 in stream 4 -select /* TPC-DS query84.tpl 0.80 */ c_customer_id as customer_id - , coalesce(c_last_name,'') || ', ' || coalesce(c_first_name,'') as customername - from customer - ,customer_address - ,customer_demographics - ,household_demographics - ,income_band - ,store_returns - where ca_city = 'Fairview' - and c_current_addr_sk = ca_address_sk - and ib_lower_bound >= 28765 - and ib_upper_bound <= 28765 + 50000 - and ib_income_band_sk = hd_income_band_sk - and cd_demo_sk = c_current_cdemo_sk - and hd_demo_sk = c_current_hdemo_sk - and sr_cdemo_sk = cd_demo_sk - order by c_customer_id - limit 100; - --- end template query84.tpl query 8 in stream 4 --- start template query8.tpl query 9 in stream 4 -select /* TPC-DS query8.tpl 0.63 */ s_store_name - ,sum(ss_net_profit) - from store_sales - ,date_dim - ,store, - (select ca_zip - from ( - SELECT substring(ca_zip,1,5) ca_zip - FROM customer_address - WHERE substring(ca_zip,1,5) IN ( - '15682','60805','12837','31155','39469','60774', - '27664','91267','40881','88939','94217', - '89242','14280','41186','97650','83908', - '43863','90150','36432','82576','51230', - '81846','74727','70209','98632','66499', - '39851','34831','79788','48078','27126', - '14296','65759','16589','20867','48837', - '56057','35438','98304','19016','24336', - '72663','78175','17532','48141','85231', - '71201','56313','43834','77365','29787', - '80593','54826','78110','68221','63352', - '40769','51768','20593','69328','34262', - '46767','70591','97731','44108','13015', - '66010','88256','40709','27579','54002', - '34010','45312','68022','63805','19239', - '70240','83226','58463','99394','18422', - '92576','68034','61860','80766','73580', - '91688','67300','14606','89859','58811', - '37767','43080','21246','28758','79214', - '29512','56277','32619','49359','39549', - '40659','90026','94026','51392','96610', - '40132','76717','31233','18675','98183', - '16720','93259','90422','71832','13346', - '23985','26550','67029','94154','51630', - '62644','99705','57457','27284','19759', - '59906','25127','75125','88060','27881', - '34030','79718','67228','26402','33723', - '28862','66717','18708','50038','35860', - '25138','57133','73032','38123','93348', - '50996','45685','20217','63385','71386', - '53618','78228','45956','77219','60258', - '47714','67306','33101','87114','41558', - '71424','57055','75937','73841','19836', - '68089','58045','93716','35452','80400', - '33843','47988','42171','10615','98802', - '40324','40502','23923','60701','46299', - '58136','46984','93149','81281','18012', - '73081','26656','51190','65956','66713', - '71719','92539','31154','73518','90589', - '60470','79112','67457','39284','29597', - '81559','88661','32871','60658','34626', - '11802','34009','88370','45158','37634', - '58840','88966','28999','12329','84229', - '41329','68106','46324','47778','88886', - '89135','28685','90555','14597','21130', - '63209','38139','12639','63621','51758', - '22963','20574','31968','60004','17671', - '51859','30595','14488','18314','87571', - '92186','29315','63933','80389','21878', - '39113','18489','67391','76963','69418', - '54625','77105','39270','73992','60219', - '78409','40011','43434','90744','11866', - '33733','65852','64873','28103','39492', - '83805','23839','65449','96114','17819', - '55143','60907','57143','25531','65966', - '77864','74722','25641','99366','51202', - '46071','73315','69202','24709','56648', - '21571','17004','82747','59945','44755', - '93622','51651','32339','65673','31487', - '16255','26087','58971','40857','39164', - '13269','63750','26997','43851','29403', - '81299','63676','46708','57686','14466', - '65468','48999','43078','97604','18649', - '52852','73963','37618','19406','69392', - '91372','40873','86108','73866','95595', - '15759','41782','34567','83088','21209', - '30081','30613','70602','96601','22536', - '59240','98372','17359','63783','10171', - '11169','84992','75768','42811','32867', - '70705','22064','69095','52427','48687', - '32703','37722','56015','72237','81522', - '72192','50238','34563','58480','71248', - '85214','76089','92682','72729','84192', - '85934','62690','42378','68847','98271', - '39210','45024','87281','71791','55350', - '82871','26395','62833','98885','85409', - '75056','50430','52062','60017','57147', - '20976','49700','75704','64804','93282', - '79510','31348','88228','99005','59002', - '22472','13219','19305','19375') - intersect - select ca_zip - from (SELECT substring(ca_zip,1,5) ca_zip,count(*) cnt - FROM customer_address, customer - WHERE ca_address_sk = c_current_addr_sk and - c_preferred_cust_flag='Y' - group by ca_zip - having count(*) > 10)A1)A2) V1 - where ss_store_sk = s_store_sk - and ss_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 2000 - and (substring(s_zip,1,2) = substring(V1.ca_zip,1,2)) - group by s_store_name - order by s_store_name - limit 100; - --- end template query8.tpl query 9 in stream 4 --- start template query71.tpl query 10 in stream 4 -select /* TPC-DS query71.tpl 0.72 */ i_brand_id brand_id, i_brand brand,t_hour,t_minute, - sum(ext_price) ext_price - from item, (select ws_ext_sales_price as ext_price, - ws_sold_date_sk as sold_date_sk, - ws_item_sk as sold_item_sk, - ws_sold_time_sk as time_sk - from web_sales,date_dim - where d_date_sk = ws_sold_date_sk - and d_moy=12 - and d_year=1998 - union all - select cs_ext_sales_price as ext_price, - cs_sold_date_sk as sold_date_sk, - cs_item_sk as sold_item_sk, - cs_sold_time_sk as time_sk - from catalog_sales,date_dim - where d_date_sk = cs_sold_date_sk - and d_moy=12 - and d_year=1998 - union all - select ss_ext_sales_price as ext_price, - ss_sold_date_sk as sold_date_sk, - ss_item_sk as sold_item_sk, - ss_sold_time_sk as time_sk - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - and d_moy=12 - and d_year=1998 - ) tmp,time_dim - where - sold_item_sk = i_item_sk - and i_manager_id=1 - and time_sk = t_time_sk - and (t_meal_time = 'breakfast' or t_meal_time = 'dinner') - group by i_brand, i_brand_id,t_hour,t_minute - order by ext_price desc, i_brand_id - ; - --- end template query71.tpl query 10 in stream 4 --- start template query45.tpl query 11 in stream 4 -select /* TPC-DS query45.tpl 0.18 */ ca_zip, ca_state, sum(ws_sales_price) - from web_sales, customer, customer_address, date_dim, item - where ws_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ws_item_sk = i_item_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', '85392', '85460', '80348', '81792') - or - i_item_id in (select i_item_id - from item - where i_item_sk in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29) - ) - ) - and ws_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 1998 - group by ca_zip, ca_state - order by ca_zip, ca_state - limit 100; - --- end template query45.tpl query 11 in stream 4 --- start template query89.tpl query 12 in stream 4 -select /* TPC-DS query89.tpl 0.56 */ * -from( -select i_category, i_class, i_brand, - s_store_name, s_company_name, - d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, s_store_name, s_company_name) - avg_monthly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - d_year in (2002) and - ((i_category in ('Sports','Electronics','Books') and - i_class in ('optics','stereo','entertainments') - ) - or (i_category in ('Jewelry','Children','Men') and - i_class in ('diamonds','infants','sports-apparel') - )) -group by i_category, i_class, i_brand, - s_store_name, s_company_name, d_moy) tmp1 -where case when (avg_monthly_sales <> 0) then (abs(sum_sales - avg_monthly_sales) / avg_monthly_sales) else null end > 0.1 -order by sum_sales - avg_monthly_sales, s_store_name -limit 100; - --- end template query89.tpl query 12 in stream 4 --- start template query91.tpl query 13 in stream 4 -select /* TPC-DS query91.tpl 0.13 */ - cc_call_center_id Call_Center, - cc_name Call_Center_Name, - cc_manager Manager, - sum(cr_net_loss) Returns_Loss -from - call_center, - catalog_returns, - date_dim, - customer, - customer_address, - customer_demographics, - household_demographics -where - cr_call_center_sk = cc_call_center_sk -and cr_returned_date_sk = d_date_sk -and cr_returning_customer_sk= c_customer_sk -and cd_demo_sk = c_current_cdemo_sk -and hd_demo_sk = c_current_hdemo_sk -and ca_address_sk = c_current_addr_sk -and d_year = 2000 -and d_moy = 11 -and ( (cd_marital_status = 'M' and cd_education_status = 'Unknown') - or(cd_marital_status = 'W' and cd_education_status = 'Advanced Degree')) -and hd_buy_potential like '0-500%' -and ca_gmt_offset = -7 -group by cc_call_center_id,cc_name,cc_manager,cd_marital_status,cd_education_status -order by sum(cr_net_loss) desc; - --- end template query91.tpl query 13 in stream 4 --- start template query14a.tpl query 14 in stream 4 -with /* TPC-DS query14a.tpl 0.69 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1999 AND 1999 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1999 AND 1999 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1999 AND 1999 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as - (select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2) x) -, - results AS -(select channel, i_brand_id, i_class_id, i_category_id, sum(sales) sum_sales, sum(number_sales) number_sales - from ( - select 'store' channel, i_brand_id,i_class_id - ,i_category_id,sum(ss_quantity*ss_list_price) sales - , count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1999+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales) - union all - select 'catalog' channel, i_brand_id,i_class_id,i_category_id, sum(cs_quantity*cs_list_price) sales, count(*) number_sales - from catalog_sales - ,item - ,date_dim - where cs_item_sk in (select ss_item_sk from cross_items) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1999+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(cs_quantity*cs_list_price) > (select average_sales from avg_sales) - union all - select 'web' channel, i_brand_id,i_class_id,i_category_id, sum(ws_quantity*ws_list_price) sales , count(*) number_sales - from web_sales - ,item - ,date_dim - where ws_item_sk in (select ss_item_sk from cross_items) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1999+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ws_quantity*ws_list_price) > (select average_sales from avg_sales) - ) y - group by channel, i_brand_id,i_class_id,i_category_id) - - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales -from ( - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales from results - union - select channel, i_brand_id, i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id, i_class_id - union - select channel, i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id - union - select channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel - union - select null as channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results) z -order by channel, i_brand_id, i_class_id, i_category_id - limit 100; -with /* TPC-DS query14a.tpl 0.69 part2 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1999 AND 1999 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1999 AND 1999 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1999 AND 1999 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as -(select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2) x) - select this_year.channel ty_channel - ,this_year.i_brand_id ty_brand - ,this_year.i_class_id ty_class - ,this_year.i_category_id ty_category - ,this_year.sales ty_sales - ,this_year.number_sales ty_number_sales - ,last_year.channel ly_channel - ,last_year.i_brand_id ly_brand - ,last_year.i_class_id ly_class - ,last_year.i_category_id ly_category - ,last_year.sales ly_sales - ,last_year.number_sales ly_number_sales -from - (select 'store' channel, i_brand_id,i_class_id,i_category_id - ,sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1999 + 1 - and d_moy = 12 - and d_dom = 5) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) this_year, - (select 'store' channel, i_brand_id,i_class_id - ,i_category_id, sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1999 - and d_moy = 12 - and d_dom = 5) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) last_year - where this_year.i_brand_id= last_year.i_brand_id - and this_year.i_class_id = last_year.i_class_id - and this_year.i_category_id = last_year.i_category_id - order by this_year.channel, this_year.i_brand_id, this_year.i_class_id, this_year.i_category_id - limit 100; - --- end template query14a.tpl query 14 in stream 4 --- start template query46.tpl query 15 in stream 4 -select /* TPC-DS query46.tpl 0.23 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and (household_demographics.hd_dep_count = 1 or - household_demographics.hd_vehicle_count= 0) - and date_dim.d_dow in (6,0) - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_city in ('Foster','Sardis','Elgin','Cooper','Bethany') - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,ca_city) dn,customer,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - limit 100; - --- end template query46.tpl query 15 in stream 4 --- start template query58.tpl query 16 in stream 4 -with /* TPC-DS query58.tpl 0.19 */ ss_items as - (select i_item_id item_id - ,sum(ss_ext_sales_price) ss_item_rev - from store_sales - ,item - ,date_dim - where ss_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '1999-02-27')) - and ss_sold_date_sk = d_date_sk - group by i_item_id), - cs_items as - (select i_item_id item_id - ,sum(cs_ext_sales_price) cs_item_rev - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '1999-02-27')) - and cs_sold_date_sk = d_date_sk - group by i_item_id), - ws_items as - (select i_item_id item_id - ,sum(ws_ext_sales_price) ws_item_rev - from web_sales - ,item - ,date_dim - where ws_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq =(select d_week_seq - from date_dim - where d_date = '1999-02-27')) - and ws_sold_date_sk = d_date_sk - group by i_item_id) - select ss_items.item_id - ,ss_item_rev - ,ss_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ss_dev - ,cs_item_rev - ,cs_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 cs_dev - ,ws_item_rev - ,ws_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ws_dev - ,(ss_item_rev+cs_item_rev+ws_item_rev)/3 average - from ss_items,cs_items,ws_items - where ss_items.item_id=cs_items.item_id - and ss_items.item_id=ws_items.item_id - and ss_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - and ss_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and cs_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and cs_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and ws_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and ws_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - order by item_id - ,ss_item_rev - limit 100; - --- end template query58.tpl query 16 in stream 4 --- start template query48.tpl query 17 in stream 4 -select /* TPC-DS query48.tpl 0.74 */ sum (ss_quantity) - from store_sales, store, customer_demographics, customer_address, date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2002 - and - ( - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'U' - and - cd_education_status = '4 yr Degree' - and - ss_sales_price between 100.00 and 150.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'W' - and - cd_education_status = 'Unknown' - and - ss_sales_price between 50.00 and 100.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'M' - and - cd_education_status = 'Secondary' - and - ss_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('NY', 'TX', 'TN') - and ss_net_profit between 0 and 2000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('GA', 'IN', 'IA') - and ss_net_profit between 150 and 3000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('OH', 'MN', 'KY') - and ss_net_profit between 50 and 25000 - ) - ) -; - --- end template query48.tpl query 17 in stream 4 --- start template query59.tpl query 18 in stream 4 -with /* TPC-DS query59.tpl 0.30 */ wss as - (select d_week_seq, - ss_store_sk, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - group by d_week_seq,ss_store_sk - ) - select s_store_name1,s_store_id1,d_week_seq1 - ,sun_sales1/sun_sales2,mon_sales1/mon_sales2 - ,tue_sales1/tue_sales2,wed_sales1/wed_sales2,thu_sales1/thu_sales2 - ,fri_sales1/fri_sales2,sat_sales1/sat_sales2 - from - (select s_store_name s_store_name1,wss.d_week_seq d_week_seq1 - ,s_store_id s_store_id1,sun_sales sun_sales1 - ,mon_sales mon_sales1,tue_sales tue_sales1 - ,wed_sales wed_sales1,thu_sales thu_sales1 - ,fri_sales fri_sales1,sat_sales sat_sales1 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1212 and 1212 + 11) y, - (select s_store_name s_store_name2,wss.d_week_seq d_week_seq2 - ,s_store_id s_store_id2,sun_sales sun_sales2 - ,mon_sales mon_sales2,tue_sales tue_sales2 - ,wed_sales wed_sales2,thu_sales thu_sales2 - ,fri_sales fri_sales2,sat_sales sat_sales2 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1212+ 12 and 1212 + 23) x - where s_store_id1=s_store_id2 - and d_week_seq1=d_week_seq2-52 - order by s_store_name1,s_store_id1,d_week_seq1 -limit 100; - --- end template query59.tpl query 18 in stream 4 --- start template query2.tpl query 19 in stream 4 -with /* TPC-DS query2.tpl 0.84 */ wscs as - (select sold_date_sk - ,sales_price - from (select ws_sold_date_sk sold_date_sk - ,ws_ext_sales_price sales_price - from web_sales - union all - select cs_sold_date_sk sold_date_sk - ,cs_ext_sales_price sales_price - from catalog_sales)), - wswscs as - (select d_week_seq, - sum(case when (d_day_name='Sunday') then sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then sales_price else null end) sat_sales - from wscs - ,date_dim - where d_date_sk = sold_date_sk - group by d_week_seq) - select d_week_seq1 - ,round(sun_sales1/sun_sales2,2) - ,round(mon_sales1/mon_sales2,2) - ,round(tue_sales1/tue_sales2,2) - ,round(wed_sales1/wed_sales2,2) - ,round(thu_sales1/thu_sales2,2) - ,round(fri_sales1/fri_sales2,2) - ,round(sat_sales1/sat_sales2,2) - from - (select wswscs.d_week_seq d_week_seq1 - ,sun_sales sun_sales1 - ,mon_sales mon_sales1 - ,tue_sales tue_sales1 - ,wed_sales wed_sales1 - ,thu_sales thu_sales1 - ,fri_sales fri_sales1 - ,sat_sales sat_sales1 - from wswscs,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 2000) y, - (select wswscs.d_week_seq d_week_seq2 - ,sun_sales sun_sales2 - ,mon_sales mon_sales2 - ,tue_sales tue_sales2 - ,wed_sales wed_sales2 - ,thu_sales thu_sales2 - ,fri_sales fri_sales2 - ,sat_sales sat_sales2 - from wswscs - ,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 2000+1) z - where d_week_seq1=d_week_seq2-53 - order by d_week_seq1; - --- end template query2.tpl query 19 in stream 4 --- start template query83.tpl query 20 in stream 4 -with /* TPC-DS query83.tpl 0.96 */ sr_items as - (select i_item_id item_id, - sum(sr_return_quantity) sr_item_qty - from store_returns, - item, - date_dim - where sr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('1999-02-23','1999-09-27','1999-11-18'))) - and sr_returned_date_sk = d_date_sk - group by i_item_id), - cr_items as - (select i_item_id item_id, - sum(cr_return_quantity) cr_item_qty - from catalog_returns, - item, - date_dim - where cr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('1999-02-23','1999-09-27','1999-11-18'))) - and cr_returned_date_sk = d_date_sk - group by i_item_id), - wr_items as - (select i_item_id item_id, - sum(wr_return_quantity) wr_item_qty - from web_returns, - item, - date_dim - where wr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('1999-02-23','1999-09-27','1999-11-18'))) - and wr_returned_date_sk = d_date_sk - group by i_item_id) - select sr_items.item_id - ,sr_item_qty - ,sr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 sr_dev - ,cr_item_qty - ,cr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 cr_dev - ,wr_item_qty - ,wr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 wr_dev - ,(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 average - from sr_items - ,cr_items - ,wr_items - where sr_items.item_id=cr_items.item_id - and sr_items.item_id=wr_items.item_id - order by sr_items.item_id - ,sr_item_qty - limit 100; - --- end template query83.tpl query 20 in stream 4 --- start template query21.tpl query 21 in stream 4 -select /* TPC-DS query21.tpl 0.14 */ * - from(select w_warehouse_name - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('2002-04-13' as date)) - then inv_quantity_on_hand - else 0 end) as inv_before - ,sum(case when (cast(d_date as date) >= cast ('2002-04-13' as date)) - then inv_quantity_on_hand - else 0 end) as inv_after - from inventory - ,warehouse - ,item - ,date_dim - where i_current_price between 0.99 and 1.49 - and i_item_sk = inv_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('2002-04-13' as date)) - and dateadd(day,30,cast ('2002-04-13' as date)) - group by w_warehouse_name, i_item_id) x - where (case when inv_before > 0 - then inv_after / inv_before - else null - end) between 2.0/3.0 and 3.0/2.0 - order by w_warehouse_name - ,i_item_id - limit 100; - --- end template query21.tpl query 21 in stream 4 --- start template query78.tpl query 22 in stream 4 -with /* TPC-DS query78.tpl 0.10 */ ws as - (select d_year AS ws_sold_year, ws_item_sk, - ws_bill_customer_sk ws_customer_sk, - sum(ws_quantity) ws_qty, - sum(ws_wholesale_cost) ws_wc, - sum(ws_sales_price) ws_sp - from web_sales - left join web_returns on wr_order_number=ws_order_number and ws_item_sk=wr_item_sk - join date_dim on ws_sold_date_sk = d_date_sk - where wr_order_number is null - group by d_year, ws_item_sk, ws_bill_customer_sk - ), -cs as - (select d_year AS cs_sold_year, cs_item_sk, - cs_bill_customer_sk cs_customer_sk, - sum(cs_quantity) cs_qty, - sum(cs_wholesale_cost) cs_wc, - sum(cs_sales_price) cs_sp - from catalog_sales - left join catalog_returns on cr_order_number=cs_order_number and cs_item_sk=cr_item_sk - join date_dim on cs_sold_date_sk = d_date_sk - where cr_order_number is null - group by d_year, cs_item_sk, cs_bill_customer_sk - ), -ss as - (select d_year AS ss_sold_year, ss_item_sk, - ss_customer_sk, - sum(ss_quantity) ss_qty, - sum(ss_wholesale_cost) ss_wc, - sum(ss_sales_price) ss_sp - from store_sales - left join store_returns on sr_ticket_number=ss_ticket_number and ss_item_sk=sr_item_sk - join date_dim on ss_sold_date_sk = d_date_sk - where sr_ticket_number is null - group by d_year, ss_item_sk, ss_customer_sk - ) - select -ss_item_sk, -round(ss_qty/(coalesce(ws_qty,0)+coalesce(cs_qty,0)),2) ratio, -ss_qty store_qty, ss_wc store_wholesale_cost, ss_sp store_sales_price, -coalesce(ws_qty,0)+coalesce(cs_qty,0) other_chan_qty, -coalesce(ws_wc,0)+coalesce(cs_wc,0) other_chan_wholesale_cost, -coalesce(ws_sp,0)+coalesce(cs_sp,0) other_chan_sales_price -from ss -left join ws on (ws_sold_year=ss_sold_year and ws_item_sk=ss_item_sk and ws_customer_sk=ss_customer_sk) -left join cs on (cs_sold_year=ss_sold_year and cs_item_sk=ss_item_sk and cs_customer_sk=ss_customer_sk) -where (coalesce(ws_qty,0)>0 or coalesce(cs_qty, 0)>0) and ss_sold_year=2001 -order by - ss_item_sk, - ss_qty desc, ss_wc desc, ss_sp desc, - other_chan_qty, - other_chan_wholesale_cost, - other_chan_sales_price, - ratio -limit 100; - --- end template query78.tpl query 22 in stream 4 --- start template query40.tpl query 23 in stream 4 -select /* TPC-DS query40.tpl 0.86 */ - w_state - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('1998-03-03' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_before - ,sum(case when (cast(d_date as date) >= cast ('1998-03-03' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_after - from - catalog_sales left outer join catalog_returns on - (cs_order_number = cr_order_number - and cs_item_sk = cr_item_sk) - ,warehouse - ,item - ,date_dim - where - i_current_price between 0.99 and 1.49 - and i_item_sk = cs_item_sk - and cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('1998-03-03' as date)) - and dateadd(day,30,cast ('1998-03-03' as date)) - group by - w_state,i_item_id - order by w_state,i_item_id -limit 100; - --- end template query40.tpl query 23 in stream 4 --- start template query99.tpl query 24 in stream 4 -select /* TPC-DS query99.tpl 0.94 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 30) and - (cs_ship_date_sk - cs_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 60) and - (cs_ship_date_sk - cs_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 90) and - (cs_ship_date_sk - cs_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - catalog_sales - ,warehouse - ,ship_mode - ,call_center - ,date_dim -where - d_month_seq between 1198 and 1198 + 11 -and cs_ship_date_sk = d_date_sk -and cs_warehouse_sk = w_warehouse_sk -and cs_ship_mode_sk = sm_ship_mode_sk -and cs_call_center_sk = cc_call_center_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -limit 100; - --- end template query99.tpl query 24 in stream 4 --- start template query19.tpl query 25 in stream 4 -select /* TPC-DS query19.tpl 0.8 */ i_brand_id brand_id, i_brand brand, i_manufact_id, i_manufact, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item,customer,customer_address,store - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=17 - and d_moy=11 - and d_year=1998 - and ss_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and substring(ca_zip,1,5) <> substring(s_zip,1,5) - and ss_store_sk = s_store_sk - group by i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact - order by ext_price desc - ,i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact -limit 100 ; - --- end template query19.tpl query 25 in stream 4 --- start template query72.tpl query 26 in stream 4 -select /* TPC-DS query72.tpl 0.87 */ i_item_desc - ,w_warehouse_name - ,d1.d_week_seq - ,sum(case when p_promo_sk is null then 1 else 0 end) no_promo - ,sum(case when p_promo_sk is not null then 1 else 0 end) promo - ,count(*) total_cnt -from catalog_sales -join inventory on (cs_item_sk = inv_item_sk) -join warehouse on (w_warehouse_sk=inv_warehouse_sk) -join item on (i_item_sk = cs_item_sk) -join customer_demographics on (cs_bill_cdemo_sk = cd_demo_sk) -join household_demographics on (cs_bill_hdemo_sk = hd_demo_sk) -join date_dim d1 on (cs_sold_date_sk = d1.d_date_sk) -join date_dim d2 on (inv_date_sk = d2.d_date_sk) -join date_dim d3 on (cs_ship_date_sk = d3.d_date_sk) -left outer join promotion on (cs_promo_sk=p_promo_sk) -left outer join catalog_returns on (cr_item_sk = cs_item_sk and cr_order_number = cs_order_number) -where d1.d_week_seq = d2.d_week_seq - and inv_quantity_on_hand < cs_quantity - and d3.d_date > d1.d_date + 5 - and hd_buy_potential = '1001-5000' - and d1.d_year = 1998 - and cd_marital_status = 'W' -group by i_item_desc,w_warehouse_name,d1.d_week_seq -order by total_cnt desc, i_item_desc, w_warehouse_name, d_week_seq -limit 100; - --- end template query72.tpl query 26 in stream 4 --- start template query6.tpl query 27 in stream 4 -select /* TPC-DS query6.tpl 0.58 */ a.ca_state state, count(*) cnt - from customer_address a - ,customer c - ,store_sales s - ,date_dim d - ,item i - where a.ca_address_sk = c.c_current_addr_sk - and c.c_customer_sk = s.ss_customer_sk - and s.ss_sold_date_sk = d.d_date_sk - and s.ss_item_sk = i.i_item_sk - and d.d_month_seq = - (select distinct (d_month_seq) - from date_dim - where d_year = 2000 - and d_moy = 7 ) - and i.i_current_price > 1.2 * - (select avg(j.i_current_price) - from item j - where j.i_category = i.i_category) - group by a.ca_state - having count(*) >= 10 - order by cnt, a.ca_state - limit 100; - --- end template query6.tpl query 27 in stream 4 --- start template query28.tpl query 28 in stream 4 -select /* TPC-DS query28.tpl 0.36 */ * -from (select avg(ss_list_price) B1_LP - ,count(ss_list_price) B1_CNT - ,count(distinct ss_list_price) B1_CNTD - from store_sales - where ss_quantity between 0 and 5 - and (ss_list_price between 49 and 49+10 - or ss_coupon_amt between 5524 and 5524+1000 - or ss_wholesale_cost between 72 and 72+20)) B1, - (select avg(ss_list_price) B2_LP - ,count(ss_list_price) B2_CNT - ,count(distinct ss_list_price) B2_CNTD - from store_sales - where ss_quantity between 6 and 10 - and (ss_list_price between 27 and 27+10 - or ss_coupon_amt between 9769 and 9769+1000 - or ss_wholesale_cost between 54 and 54+20)) B2, - (select avg(ss_list_price) B3_LP - ,count(ss_list_price) B3_CNT - ,count(distinct ss_list_price) B3_CNTD - from store_sales - where ss_quantity between 11 and 15 - and (ss_list_price between 188 and 188+10 - or ss_coupon_amt between 5039 and 5039+1000 - or ss_wholesale_cost between 29 and 29+20)) B3, - (select avg(ss_list_price) B4_LP - ,count(ss_list_price) B4_CNT - ,count(distinct ss_list_price) B4_CNTD - from store_sales - where ss_quantity between 16 and 20 - and (ss_list_price between 113 and 113+10 - or ss_coupon_amt between 17318 and 17318+1000 - or ss_wholesale_cost between 27 and 27+20)) B4, - (select avg(ss_list_price) B5_LP - ,count(ss_list_price) B5_CNT - ,count(distinct ss_list_price) B5_CNTD - from store_sales - where ss_quantity between 21 and 25 - and (ss_list_price between 36 and 36+10 - or ss_coupon_amt between 8560 and 8560+1000 - or ss_wholesale_cost between 5 and 5+20)) B5, - (select avg(ss_list_price) B6_LP - ,count(ss_list_price) B6_CNT - ,count(distinct ss_list_price) B6_CNTD - from store_sales - where ss_quantity between 26 and 30 - and (ss_list_price between 146 and 146+10 - or ss_coupon_amt between 13198 and 13198+1000 - or ss_wholesale_cost between 59 and 59+20)) B6 -limit 100; - --- end template query28.tpl query 28 in stream 4 --- start template query81.tpl query 29 in stream 4 -with /* TPC-DS query81.tpl 0.37 */ customer_total_return as - (select cr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(cr_return_amt_inc_tax) as ctr_total_return - from catalog_returns - ,date_dim - ,customer_address - where cr_returned_date_sk = d_date_sk - and d_year =2000 - and cr_returning_addr_sk = ca_address_sk - group by cr_returning_customer_sk - ,ca_state ) - select c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'NM' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - limit 100; - --- end template query81.tpl query 29 in stream 4 --- start template query44.tpl query 30 in stream 4 -select /* TPC-DS query44.tpl 0.4 */ asceding.rnk, i1.i_product_name best_performing, i2.i_product_name worst_performing -from(select * - from (select item_sk,rank() over (order by rank_col asc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 602 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 602 - and ss_promo_sk is null - group by ss_store_sk))V1)V11 - where rnk < 11) asceding, - (select * - from (select item_sk,rank() over (order by rank_col desc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 602 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 602 - and ss_promo_sk is null - group by ss_store_sk))V2)V21 - where rnk < 11) descending, -item i1, -item i2 -where asceding.rnk = descending.rnk - and i1.i_item_sk=asceding.item_sk - and i2.i_item_sk=descending.item_sk -order by asceding.rnk -limit 100; - --- end template query44.tpl query 30 in stream 4 --- start template query97.tpl query 31 in stream 4 -with /* TPC-DS query97.tpl 0.38 */ ssci as ( -select ss_customer_sk customer_sk - ,ss_item_sk item_sk -from store_sales,date_dim -where ss_sold_date_sk = d_date_sk - and d_month_seq between 1196 and 1196 + 11 -group by ss_customer_sk - ,ss_item_sk), -csci as( - select cs_bill_customer_sk customer_sk - ,cs_item_sk item_sk -from catalog_sales,date_dim -where cs_sold_date_sk = d_date_sk - and d_month_seq between 1196 and 1196 + 11 -group by cs_bill_customer_sk - ,cs_item_sk) - select sum(case when ssci.customer_sk is not null and csci.customer_sk is null then 1 else 0 end) store_only - ,sum(case when ssci.customer_sk is null and csci.customer_sk is not null then 1 else 0 end) catalog_only - ,sum(case when ssci.customer_sk is not null and csci.customer_sk is not null then 1 else 0 end) store_and_catalog -from ssci full outer join csci on (ssci.customer_sk=csci.customer_sk - and ssci.item_sk = csci.item_sk) -limit 100; - --- end template query97.tpl query 31 in stream 4 --- start template query88.tpl query 32 in stream 4 -select /* TPC-DS query88.tpl 0.66 */ * -from - (select count(*) h8_30_to_9 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2)) - and store.s_store_name = 'ese') s1, - (select count(*) h9_to_9_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2)) - and store.s_store_name = 'ese') s2, - (select count(*) h9_30_to_10 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2)) - and store.s_store_name = 'ese') s3, - (select count(*) h10_to_10_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2)) - and store.s_store_name = 'ese') s4, - (select count(*) h10_30_to_11 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2)) - and store.s_store_name = 'ese') s5, - (select count(*) h11_to_11_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2)) - and store.s_store_name = 'ese') s6, - (select count(*) h11_30_to_12 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2)) - and store.s_store_name = 'ese') s7, - (select count(*) h12_to_12_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 12 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2)) - and store.s_store_name = 'ese') s8 -; - --- end template query88.tpl query 32 in stream 4 --- start template query77a.tpl query 33 in stream 4 -with /* TPC-DS query77a.tpl 0.78 */ ss as - (select s_store_sk, - sum(ss_ext_sales_price) as sales, - sum(ss_net_profit) as profit - from store_sales, - date_dim, - store - where ss_sold_date_sk = d_date_sk - and d_date between cast('2002-08-13' as date) - and dateadd(day,30,cast('2002-08-13' as date)) - and ss_store_sk = s_store_sk - group by s_store_sk) - , - sr as - (select s_store_sk, - sum(sr_return_amt) as returns, - sum(sr_net_loss) as profit_loss - from store_returns, - date_dim, - store - where sr_returned_date_sk = d_date_sk - and d_date between cast('2002-08-13' as date) - and dateadd(day,30,cast('2002-08-13' as date)) - and sr_store_sk = s_store_sk - group by s_store_sk), - cs as - (select cs_call_center_sk, - sum(cs_ext_sales_price) as sales, - sum(cs_net_profit) as profit - from catalog_sales, - date_dim - where cs_sold_date_sk = d_date_sk - and d_date between cast('2002-08-13' as date) - and dateadd(day,30,cast('2002-08-13' as date)) - group by cs_call_center_sk - ), - cr as - (select cr_call_center_sk, - sum(cr_return_amount) as returns, - sum(cr_net_loss) as profit_loss - from catalog_returns, - date_dim - where cr_returned_date_sk = d_date_sk - and d_date between cast('2002-08-13' as date) - and dateadd(day,30,cast('2002-08-13' as date)) - group by cr_call_center_sk), - ws as - ( select wp_web_page_sk, - sum(ws_ext_sales_price) as sales, - sum(ws_net_profit) as profit - from web_sales, - date_dim, - web_page - where ws_sold_date_sk = d_date_sk - and d_date between cast('2002-08-13' as date) - and dateadd(day,30,cast('2002-08-13' as date)) - and ws_web_page_sk = wp_web_page_sk - group by wp_web_page_sk), - wr as - (select wp_web_page_sk, - sum(wr_return_amt) as returns, - sum(wr_net_loss) as profit_loss - from web_returns, - date_dim, - web_page - where wr_returned_date_sk = d_date_sk - and d_date between cast('2002-08-13' as date) - and dateadd(day,30,cast('2002-08-13' as date)) - and wr_web_page_sk = wp_web_page_sk - group by wp_web_page_sk) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , ss.s_store_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ss left join sr - on ss.s_store_sk = sr.s_store_sk - union all - select 'catalog channel' as channel - , cs_call_center_sk as id - , sales - , returns - , (profit - profit_loss) as profit - from cs - , cr - union all - select 'web channel' as channel - , ws.wp_web_page_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ws left join wr - on ws.wp_web_page_sk = wr.wp_web_page_sk - ) x - group by channel, id ) - - select * - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results -) foo -order by channel, id - limit 100; - --- end template query77a.tpl query 33 in stream 4 --- start template query95.tpl query 34 in stream 4 -with /* TPC-DS query95.tpl 0.43 */ ws_wh as -(select ws1.ws_order_number,ws1.ws_warehouse_sk wh1,ws2.ws_warehouse_sk wh2 - from web_sales ws1,web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) - select - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '1999-5-01' and - dateadd(day,60,cast('1999-5-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'NM' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and ws1.ws_order_number in (select ws_order_number - from ws_wh) -and ws1.ws_order_number in (select wr_order_number - from web_returns,ws_wh - where wr_order_number = ws_wh.ws_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query95.tpl query 34 in stream 4 --- start template query33.tpl query 35 in stream 4 -with /* TPC-DS query33.tpl 0.22 */ ss as ( - select - i_manufact_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Electronics')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 1 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_manufact_id), - cs as ( - select - i_manufact_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Electronics')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 1 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_manufact_id), - ws as ( - select - i_manufact_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Electronics')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 1 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_manufact_id) - select i_manufact_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_manufact_id - order by total_sales -limit 100; - --- end template query33.tpl query 35 in stream 4 --- start template query36a.tpl query 36 in stream 4 -with /* TPC-DS query36a.tpl 0.21 */ results as - (select - sum(ss_net_profit) as ss_net_profit, sum(ss_ext_sales_price) as ss_ext_sales_price, - sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin - ,i_category - ,i_class - ,0 as g_category, 0 as g_class - from - store_sales - ,date_dim d1 - ,item - ,store - where - d1.d_year = 1998 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and s_state in ('CO','CA','IN','MI', - 'SD','OK','AL','TN') - group by i_category,i_class) - , - results_rollup as - (select gross_margin ,i_category ,i_class,0 as t_category, 0 as t_class, 0 as lochierarchy from results - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - i_category, NULL AS i_class, 0 as t_category, 1 as t_class, 1 as lochierarchy from results group by i_category - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - NULL AS i_category ,NULL AS i_class, 1 as t_category, 1 as t_class, 2 as lochierarchy from results) - select - gross_margin ,i_category ,i_class, lochierarchy,rank() over ( - partition by lochierarchy, case when t_class = 0 then i_category end - order by gross_margin asc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then i_category end - ,rank_within_parent - limit 100; - --- end template query36a.tpl query 36 in stream 4 --- start template query61.tpl query 37 in stream 4 -select /* TPC-DS query61.tpl 0.97 */ promotions,total,cast(promotions as decimal(16,4))/cast(total as decimal(16,4))*100 -from - (select sum(ss_ext_sales_price) promotions - from store_sales - ,store - ,promotion - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_promo_sk = p_promo_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -7 - and i_category = 'Electronics' - and (p_channel_dmail = 'Y' or p_channel_email = 'Y' or p_channel_tv = 'Y') - and s_gmt_offset = -7 - and d_year = 1998 - and d_moy = 12) promotional_sales, - (select sum(ss_ext_sales_price) total - from store_sales - ,store - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -7 - and i_category = 'Electronics' - and s_gmt_offset = -7 - and d_year = 1998 - and d_moy = 12) all_sales -order by promotions, total -limit 100; - --- end template query61.tpl query 37 in stream 4 --- start template query35a.tpl query 38 in stream 4 -select /* TPC-DS query35a.tpl 0.47 */ - ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - count(*) cnt1, - max(cd_dep_count), - max(cd_dep_count), - stddev_samp(cd_dep_count), - cd_dep_employed_count, - count(*) cnt2, - max(cd_dep_employed_count), - max(cd_dep_employed_count), - stddev_samp(cd_dep_employed_count), - cd_dep_college_count, - count(*) cnt3, - max(cd_dep_college_count), - max(cd_dep_college_count), - stddev_samp(cd_dep_college_count) - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2001 and - d_qoy < 4) and - exists (select * from - (select ws_bill_customer_sk customsk - from web_sales,date_dim - where - ws_sold_date_sk = d_date_sk and - d_year = 2001 and - d_qoy < 4 - union all - select cs_ship_customer_sk customsk - from catalog_sales,date_dim - where - cs_sold_date_sk = d_date_sk and - d_year = 2001 and - d_qoy < 4)x - where x.customsk = c.c_customer_sk) - group by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - limit 100; - --- end template query35a.tpl query 38 in stream 4 --- start template query60.tpl query 39 in stream 4 -with /* TPC-DS query60.tpl 0.29 */ ss as ( - select - i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Shoes')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 10 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -8 - group by i_item_id), - cs as ( - select - i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Shoes')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 10 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -8 - group by i_item_id), - ws as ( - select - i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Shoes')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 10 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -8 - group by i_item_id) - select - i_item_id -,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by i_item_id - ,total_sales - limit 100; - --- end template query60.tpl query 39 in stream 4 --- start template query75.tpl query 40 in stream 4 -WITH /* TPC-DS query75.tpl 0.3 */ all_sales AS ( - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,SUM(sales_cnt) AS sales_cnt - ,SUM(sales_amt) AS sales_amt - FROM (SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,cs_quantity - COALESCE(cr_return_quantity,0) AS sales_cnt - ,cs_ext_sales_price - COALESCE(cr_return_amount,0.0) AS sales_amt - FROM catalog_sales JOIN item ON i_item_sk=cs_item_sk - JOIN date_dim ON d_date_sk=cs_sold_date_sk - LEFT JOIN catalog_returns ON (cs_order_number=cr_order_number - AND cs_item_sk=cr_item_sk) - WHERE i_category='Music' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ss_quantity - COALESCE(sr_return_quantity,0) AS sales_cnt - ,ss_ext_sales_price - COALESCE(sr_return_amt,0.0) AS sales_amt - FROM store_sales JOIN item ON i_item_sk=ss_item_sk - JOIN date_dim ON d_date_sk=ss_sold_date_sk - LEFT JOIN store_returns ON (ss_ticket_number=sr_ticket_number - AND ss_item_sk=sr_item_sk) - WHERE i_category='Music' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ws_quantity - COALESCE(wr_return_quantity,0) AS sales_cnt - ,ws_ext_sales_price - COALESCE(wr_return_amt,0.0) AS sales_amt - FROM web_sales JOIN item ON i_item_sk=ws_item_sk - JOIN date_dim ON d_date_sk=ws_sold_date_sk - LEFT JOIN web_returns ON (ws_order_number=wr_order_number - AND ws_item_sk=wr_item_sk) - WHERE i_category='Music') sales_detail - GROUP BY d_year, i_brand_id, i_class_id, i_category_id, i_manufact_id) - SELECT prev_yr.d_year AS prev_year - ,curr_yr.d_year AS year - ,curr_yr.i_brand_id - ,curr_yr.i_class_id - ,curr_yr.i_category_id - ,curr_yr.i_manufact_id - ,prev_yr.sales_cnt AS prev_yr_cnt - ,curr_yr.sales_cnt AS curr_yr_cnt - ,curr_yr.sales_cnt-prev_yr.sales_cnt AS sales_cnt_diff - ,curr_yr.sales_amt-prev_yr.sales_amt AS sales_amt_diff - FROM all_sales curr_yr, all_sales prev_yr - WHERE curr_yr.i_brand_id=prev_yr.i_brand_id - AND curr_yr.i_class_id=prev_yr.i_class_id - AND curr_yr.i_category_id=prev_yr.i_category_id - AND curr_yr.i_manufact_id=prev_yr.i_manufact_id - AND curr_yr.d_year=2000 - AND prev_yr.d_year=2000-1 - AND CAST(curr_yr.sales_cnt AS DECIMAL(17,2))/CAST(prev_yr.sales_cnt AS DECIMAL(17,2))<0.9 - ORDER BY sales_cnt_diff,sales_amt_diff - limit 100; - --- end template query75.tpl query 40 in stream 4 --- start template query74.tpl query 41 in stream 4 -with /* TPC-DS query74.tpl 0.76 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,max(ss_net_paid) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1999,1999+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,max(ws_net_paid) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - and d_year in (1999,1999+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - ) - select - t_s_secyear.customer_id, t_s_secyear.customer_first_name, t_s_secyear.customer_last_name - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.year = 1999 - and t_s_secyear.year = 1999+1 - and t_w_firstyear.year = 1999 - and t_w_secyear.year = 1999+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - order by 1,3,2 -limit 100; - --- end template query74.tpl query 41 in stream 4 --- start template query55.tpl query 42 in stream 4 -select /* TPC-DS query55.tpl 0.82 */ i_brand_id brand_id, i_brand brand, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=86 - and d_moy=12 - and d_year=2002 - group by i_brand, i_brand_id - order by ext_price desc, i_brand_id -limit 100 ; - --- end template query55.tpl query 42 in stream 4 --- start template query51.tpl query 43 in stream 4 -WITH /* TPC-DS query51.tpl 0.46 */ web_v1 as ( -select - ws_item_sk item_sk, d_date, - sum(sum(ws_sales_price)) - over (partition by ws_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from web_sales - ,date_dim -where ws_sold_date_sk=d_date_sk - and d_month_seq between 1180 and 1180+11 - and ws_item_sk is not NULL -group by ws_item_sk, d_date), -store_v1 as ( -select - ss_item_sk item_sk, d_date, - sum(sum(ss_sales_price)) - over (partition by ss_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from store_sales - ,date_dim -where ss_sold_date_sk=d_date_sk - and d_month_seq between 1180 and 1180+11 - and ss_item_sk is not NULL -group by ss_item_sk, d_date) - select * -from (select item_sk - ,d_date - ,web_sales - ,store_sales - ,max(web_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) web_cumulative - ,max(store_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) store_cumulative - from (select case when web.item_sk is not null then web.item_sk else store.item_sk end item_sk - ,case when web.d_date is not null then web.d_date else store.d_date end d_date - ,web.cume_sales web_sales - ,store.cume_sales store_sales - from web_v1 web full outer join store_v1 store on (web.item_sk = store.item_sk - and web.d_date = store.d_date) - )x )y -where web_cumulative > store_cumulative -order by item_sk - ,d_date -limit 100; - --- end template query51.tpl query 43 in stream 4 --- start template query17.tpl query 44 in stream 4 -select /* TPC-DS query17.tpl 0.41 */ i_item_id - ,i_item_desc - ,s_state - ,count(ss_quantity) as store_sales_quantitycount - ,avg(ss_quantity) as store_sales_quantityave - ,stddev_samp(ss_quantity) as store_sales_quantitystdev - ,stddev_samp(ss_quantity)/avg(ss_quantity) as store_sales_quantitycov - ,count(sr_return_quantity) as store_returns_quantitycount - ,avg(sr_return_quantity) as store_returns_quantityave - ,stddev_samp(sr_return_quantity) as store_returns_quantitystdev - ,stddev_samp(sr_return_quantity)/avg(sr_return_quantity) as store_returns_quantitycov - ,count(cs_quantity) as catalog_sales_quantitycount ,avg(cs_quantity) as catalog_sales_quantityave - ,stddev_samp(cs_quantity) as catalog_sales_quantitystdev - ,stddev_samp(cs_quantity)/avg(cs_quantity) as catalog_sales_quantitycov - from store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where d1.d_quarter_name = '2001Q1' - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_quarter_name in ('2001Q1','2001Q2','2001Q3') - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_quarter_name in ('2001Q1','2001Q2','2001Q3') - group by i_item_id - ,i_item_desc - ,s_state - order by i_item_id - ,i_item_desc - ,s_state -limit 100; - --- end template query17.tpl query 44 in stream 4 --- start template query52.tpl query 45 in stream 4 -select /* TPC-DS query52.tpl 0.59 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_sales_price) ext_price - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=11 - and dt.d_year=2002 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,ext_price desc - ,brand_id -limit 100 ; - --- end template query52.tpl query 45 in stream 4 --- start template query90.tpl query 46 in stream 4 -select /* TPC-DS query90.tpl 0.40 */ cast(amc as decimal(15,4))/cast(pmc as decimal(15,4)) am_pm_ratio - from ( select count(*) amc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 7 and 7+1 - and household_demographics.hd_dep_count = 8 - and web_page.wp_char_count between 5000 and 5200) at, - ( select count(*) pmc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 13 and 13+1 - and household_demographics.hd_dep_count = 8 - and web_page.wp_char_count between 5000 and 5200) pt - order by am_pm_ratio - limit 100; - --- end template query90.tpl query 46 in stream 4 --- start template query22a.tpl query 47 in stream 4 -with /* TPC-DS query22a.tpl 0.55 */ results as -(select i_product_name - ,i_brand - ,i_class - ,i_category - ,avg(inv_quantity_on_hand) qoh - from inventory - ,date_dim - ,item --- ,warehouse - where inv_date_sk=d_date_sk - and inv_item_sk=i_item_sk --- and inv_warehouse_sk = w_warehouse_sk - and d_month_seq between 1180 and 1180 + 11 - group by i_product_name,i_brand,i_class,i_category), -results_rollup as -(select i_product_name, i_brand, i_class, i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class,i_category -union all -select i_product_name, i_brand, i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class -union all -select i_product_name, i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand -union all -select i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name -union all -select null i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results) - select i_product_name, i_brand, i_class, i_category,qoh - from results_rollup - order by qoh, i_product_name, i_brand, i_class, i_category -limit 100; - --- end template query22a.tpl query 47 in stream 4 --- start template query27a.tpl query 48 in stream 4 -with /* TPC-DS query27a.tpl 0.16 */ results as - (select i_item_id, - s_state, 0 as g_state, - ss_quantity agg1, - ss_list_price agg2, - ss_coupon_amt agg3, - ss_sales_price agg4 - from store_sales, customer_demographics, date_dim, store, item - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_store_sk = s_store_sk and - ss_cdemo_sk = cd_demo_sk and - cd_gender = 'M' and - cd_marital_status = 'W' and - cd_education_status = 'College' and - d_year = 2001 and - s_state in ('WA','MI', 'GA', 'NE', 'NC', 'LA') - ) - - select i_item_id, - s_state, g_state, agg1, agg2, agg3, agg4 - from ( - select i_item_id, s_state, 0 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4 from results - group by i_item_id, s_state - union all - select i_item_id, NULL AS s_state, 1 AS g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as s_state, 1 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - ) foo - order by i_item_id, s_state - limit 100; - --- end template query27a.tpl query 48 in stream 4 --- start template query63.tpl query 49 in stream 4 -select /* TPC-DS query63.tpl 0.27 */ * -from (select i_manager_id - ,sum(ss_sales_price) sum_sales - ,avg(sum(ss_sales_price)) over (partition by i_manager_id) avg_monthly_sales - from item - ,store_sales - ,date_dim - ,store - where ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and d_month_seq in (1216,1216+1,1216+2,1216+3,1216+4,1216+5,1216+6,1216+7,1216+8,1216+9,1216+10,1216+11) - and (( i_category in ('Books','Children','Electronics') - and i_class in ('personal','portable','reference','self-help') - and i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) - or( i_category in ('Women','Music','Men') - and i_class in ('accessories','classical','fragrances','pants') - and i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manager_id, d_moy) tmp1 -where case when avg_monthly_sales > 0 then abs (sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 -order by i_manager_id - ,avg_monthly_sales - ,sum_sales -limit 100; - --- end template query63.tpl query 49 in stream 4 --- start template query38.tpl query 50 in stream 4 -select /* TPC-DS query38.tpl 0.54 */ count(*) from ( - select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1182 and 1182 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1182 and 1182 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1182 and 1182 + 11 -) hot_cust -limit 100; - --- end template query38.tpl query 50 in stream 4 --- start template query18a.tpl query 51 in stream 4 -with /* TPC-DS query18a.tpl 0.90 */ results as - (select i_item_id, - ca_country, - ca_state, - ca_county, - cast(cs_quantity as decimal(12,2)) agg1, - cast(cs_list_price as decimal(12,2)) agg2, - cast(cs_coupon_amt as decimal(12,2)) agg3, - cast(cs_sales_price as decimal(12,2)) agg4, - cast(cs_net_profit as decimal(12,2)) agg5, - cast(c_birth_year as decimal(12,2)) agg6, - cast(cd1.cd_dep_count as decimal(12,2)) agg7 - from catalog_sales, customer_demographics cd1, customer_demographics cd2, customer, customer_address, date_dim, item - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd1.cd_demo_sk and - cs_bill_customer_sk = c_customer_sk and - cd1.cd_gender = 'M' and - cd1.cd_education_status = 'Unknown' and - c_current_cdemo_sk = cd2.cd_demo_sk and - c_current_addr_sk = ca_address_sk and - c_birth_month in (8,11,1,4,9,3) and - d_year = 2002 and - ca_state in ('NE','KY','GA','KS','WA','SD','MS') - ) - select i_item_id, ca_country, ca_state, ca_county, agg1, agg2, agg3, agg4, agg5, agg6, agg7 - from ( - select i_item_id, ca_country, ca_state, ca_county, avg(agg1) agg1, - avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state, ca_county - union all - select i_item_id, ca_country, ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state - union all - select i_item_id, ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country - union all - select i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - ) foo - order by ca_country, ca_state, ca_county, i_item_id - limit 100; - --- end template query18a.tpl query 51 in stream 4 --- start template query24.tpl query 52 in stream 4 -with /* TPC-DS query24.tpl 0.92 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_net_profit) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip -and s_market_id=10 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'maroon' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; -with /* TPC-DS query24.tpl 0.92 part2 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_net_profit) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip - and s_market_id = 10 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'coral' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; - --- end template query24.tpl query 52 in stream 4 --- start template query37.tpl query 53 in stream 4 -select /* TPC-DS query37.tpl 0.31 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, catalog_sales - where i_current_price between 24 and 24 + 30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('1998-05-23' as date) and dateadd(day,60,cast('1998-05-23' as date)) - and i_manufact_id in (906,968,919,720) - and inv_quantity_on_hand between 100 and 500 - and cs_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query37.tpl query 53 in stream 4 --- start template query47.tpl query 54 in stream 4 -with /* TPC-DS query47.tpl 0.42 */ v1 as( - select i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, - s_store_name, s_company_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - s_store_name, s_company_name - order by d_year, d_moy) rn - from item, store_sales, date_dim, store - where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - ( - d_year = 1999 or - ( d_year = 1999-1 and d_moy =12) or - ( d_year = 1999+1 and d_moy =1) - ) - group by i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy), - v2 as( - select v1.s_store_name, v1.s_company_name - ,v1.d_year, v1.d_moy - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1.s_store_name = v1_lag.s_store_name and - v1.s_store_name = v1_lead.s_store_name and - v1.s_company_name = v1_lag.s_company_name and - v1.s_company_name = v1_lead.s_company_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 1999 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, sum_sales - limit 100; - --- end template query47.tpl query 54 in stream 4 --- start template query10.tpl query 55 in stream 4 -select /* TPC-DS query10.tpl 0.26 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3, - cd_dep_count, - count(*) cnt4, - cd_dep_employed_count, - count(*) cnt5, - cd_dep_college_count, - count(*) cnt6 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_county in ('Cheyenne County','Prairie County','Washington County','Madison County','Menard County') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2001 and - d_moy between 1 and 1+3) and - (exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2001 and - d_moy between 1 ANd 1+3) or - exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2001 and - d_moy between 1 and 1+3)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count -limit 100; - --- end template query10.tpl query 55 in stream 4 --- start template query70a.tpl query 56 in stream 4 -with /* TPC-DS query70a.tpl 0.34 */ results as -( select - sum(ss_net_profit) as total_sum ,s_state ,s_county, 0 as gstate, 0 as g_county - from - store_sales - ,date_dim d1 - ,store - where - d1.d_month_seq between 1203 and 1203 + 11 - and d1.d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - and s_state in - ( select s_state - from (select s_state as s_state, - rank() over ( partition by s_state order by sum(ss_net_profit) desc) as ranking - from store_sales, store, date_dim - where d_month_seq between 1203 and 1203 + 11 - and d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - group by s_state - ) tmp1 - where ranking <= 5) - group by s_state,s_county) , - results_rollup as -(select total_sum ,s_state ,s_county, 0 as g_state, 0 as g_county, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum,s_state, NULL as s_county, 0 as g_state, 1 as g_county, 1 as lochierarchy from results group by s_state - union - select sum(total_sum) as total_sum ,NULL as s_state ,NULL as s_county, 1 as g_state, 1 as g_county, 2 as lochierarchy from results) - select total_sum ,s_state ,s_county, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_county = 0 then s_state end - order by total_sum desc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then s_state end - ,rank_within_parent - limit 100; - --- end template query70a.tpl query 56 in stream 4 --- start template query23.tpl query 57 in stream 4 -with /* TPC-DS query23.tpl 0.68 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (2000,2000+1,2000+2,2000+3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (2000,2000+1,2000+2,2000+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * -from - max_store_sales)) - select sum(sales) - from (select cs_quantity*cs_list_price sales - from catalog_sales - ,date_dim - where d_year = 2000 - and d_moy = 7 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - union all - select ws_quantity*ws_list_price sales - from web_sales - ,date_dim - where d_year = 2000 - and d_moy = 7 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer)) - limit 100; -with /* TPC-DS query23.tpl 0.68 part2 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (2000,2000 + 1,2000 + 2,2000 + 3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (2000,2000+1,2000+2,2000+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * - from max_store_sales)) - select c_last_name,c_first_name,sales - from (select c_last_name,c_first_name,sum(cs_quantity*cs_list_price) sales - from catalog_sales - ,customer - ,date_dim - where d_year = 2000 - and d_moy = 7 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and cs_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name - union all - select c_last_name,c_first_name,sum(ws_quantity*ws_list_price) sales - from web_sales - ,customer - ,date_dim - where d_year = 2000 - and d_moy = 7 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and ws_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name) - order by c_last_name,c_first_name,sales - limit 100; - --- end template query23.tpl query 57 in stream 4 --- start template query7.tpl query 58 in stream 4 -select /* TPC-DS query7.tpl 0.2 */ i_item_id, - avg(ss_quantity) agg1, - avg(ss_list_price) agg2, - avg(ss_coupon_amt) agg3, - avg(ss_sales_price) agg4 - from store_sales, customer_demographics, date_dim, item, promotion - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_cdemo_sk = cd_demo_sk and - ss_promo_sk = p_promo_sk and - cd_gender = 'F' and - cd_marital_status = 'D' and - cd_education_status = 'College' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 2000 - group by i_item_id - order by i_item_id - limit 100; - --- end template query7.tpl query 58 in stream 4 --- start template query92.tpl query 59 in stream 4 -select /* TPC-DS query92.tpl 0.44 */ - sum(ws_ext_discount_amt) as "Excess Discount Amount" -from - web_sales - ,item - ,date_dim -where -i_manufact_id = 989 -and i_item_sk = ws_item_sk -and d_date between '1999-01-19' and - dateadd(day,90,cast('1999-01-19' as date)) -and d_date_sk = ws_sold_date_sk -and ws_ext_discount_amt - > ( - SELECT - 1.3 * avg(ws_ext_discount_amt) - FROM - web_sales - ,date_dim - WHERE - ws_item_sk = i_item_sk - and d_date between '1999-01-19' and - dateadd(day,90,cast('1999-01-19' as date)) - and d_date_sk = ws_sold_date_sk - ) -order by sum(ws_ext_discount_amt) -limit 100; - --- end template query92.tpl query 59 in stream 4 --- start template query54.tpl query 60 in stream 4 -with /* TPC-DS query54.tpl 0.81 */ my_customers as ( - select distinct c_customer_sk - , c_current_addr_sk - from - ( select cs_sold_date_sk sold_date_sk, - cs_bill_customer_sk customer_sk, - cs_item_sk item_sk - from catalog_sales - union all - select ws_sold_date_sk sold_date_sk, - ws_bill_customer_sk customer_sk, - ws_item_sk item_sk - from web_sales - ) cs_or_ws_sales, - item, - date_dim, - customer - where sold_date_sk = d_date_sk - and item_sk = i_item_sk - and i_category = 'Electronics' - and i_class = 'memory' - and c_customer_sk = cs_or_ws_sales.customer_sk - and d_moy = 1 - and d_year = 1999 - ) - , my_revenue as ( - select c_customer_sk, - sum(ss_ext_sales_price) as revenue - from my_customers, - store_sales, - customer_address, - store, - date_dim - where c_current_addr_sk = ca_address_sk - and ca_county = s_county - and ca_state = s_state - and ss_sold_date_sk = d_date_sk - and c_customer_sk = ss_customer_sk - and d_month_seq between (select distinct d_month_seq+1 - from date_dim where d_year = 1999 and d_moy = 1) - and (select distinct d_month_seq+3 - from date_dim where d_year = 1999 and d_moy = 1) - group by c_customer_sk - ) - , segments as - (select cast((revenue/50) as bigint) as segment - from my_revenue - ) - select segment, count(*) as num_customers, segment*50 as segment_base - from segments - group by segment - order by segment, num_customers - limit 100; - --- end template query54.tpl query 60 in stream 4 --- start template query82.tpl query 61 in stream 4 -select /* TPC-DS query82.tpl 0.67 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, store_sales - where i_current_price between 4 and 4+30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('2002-01-06' as date) and dateadd(day,60,cast('2002-01-06' as date)) - and i_manufact_id in (832,507,875,874) - and inv_quantity_on_hand between 100 and 500 - and ss_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query82.tpl query 61 in stream 4 --- start template query76.tpl query 62 in stream 4 -select /* TPC-DS query76.tpl 0.99 */ channel, col_name, d_year, d_qoy, i_category, COUNT(*) sales_cnt, SUM(ext_sales_price) sales_amt FROM ( - SELECT 'store' as channel, 'ss_cdemo_sk' col_name, d_year, d_qoy, i_category, ss_ext_sales_price ext_sales_price - FROM store_sales, item, date_dim - WHERE ss_cdemo_sk IS NULL - AND ss_sold_date_sk=d_date_sk - AND ss_item_sk=i_item_sk - UNION ALL - SELECT 'web' as channel, 'ws_bill_customer_sk' col_name, d_year, d_qoy, i_category, ws_ext_sales_price ext_sales_price - FROM web_sales, item, date_dim - WHERE ws_bill_customer_sk IS NULL - AND ws_sold_date_sk=d_date_sk - AND ws_item_sk=i_item_sk - UNION ALL - SELECT 'catalog' as channel, 'cs_ship_customer_sk' col_name, d_year, d_qoy, i_category, cs_ext_sales_price ext_sales_price - FROM catalog_sales, item, date_dim - WHERE cs_ship_customer_sk IS NULL - AND cs_sold_date_sk=d_date_sk - AND cs_item_sk=i_item_sk) foo -GROUP BY channel, col_name, d_year, d_qoy, i_category -ORDER BY channel, col_name, d_year, d_qoy, i_category -limit 100; - --- end template query76.tpl query 62 in stream 4 --- start template query80a.tpl query 63 in stream 4 -with /* TPC-DS query80a.tpl 0.6 */ ssr as - (select s_store_id as store_id, - sum(ss_ext_sales_price) as sales, - sum(coalesce(sr_return_amt, 0)) as returns, - sum(ss_net_profit - coalesce(sr_net_loss, 0)) as profit - from store_sales left outer join store_returns on - (ss_item_sk = sr_item_sk and ss_ticket_number = sr_ticket_number), - date_dim, - store, - item, - promotion - where ss_sold_date_sk = d_date_sk - and d_date between cast('2001-08-17' as date) - and dateadd(day,30,cast('2001-08-17' as date)) - and ss_store_sk = s_store_sk - and ss_item_sk = i_item_sk - and i_current_price > 50 - and ss_promo_sk = p_promo_sk - and p_channel_tv = 'N' - group by s_store_id) - , - csr as - (select cp_catalog_page_id as catalog_page_id, - sum(cs_ext_sales_price) as sales, - sum(coalesce(cr_return_amount, 0)) as returns, - sum(cs_net_profit - coalesce(cr_net_loss, 0)) as profit - from catalog_sales left outer join catalog_returns on - (cs_item_sk = cr_item_sk and cs_order_number = cr_order_number), - date_dim, - catalog_page, - item, - promotion - where cs_sold_date_sk = d_date_sk - and d_date between cast('2001-08-17' as date) - and dateadd(day,30,cast('2001-08-17' as date)) - and cs_catalog_page_sk = cp_catalog_page_sk - and cs_item_sk = i_item_sk - and i_current_price > 50 - and cs_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(ws_ext_sales_price) as sales, - sum(coalesce(wr_return_amt, 0)) as returns, - sum(ws_net_profit - coalesce(wr_net_loss, 0)) as profit - from web_sales left outer join web_returns on - (ws_item_sk = wr_item_sk and ws_order_number = wr_order_number), - date_dim, - web_site, - item, - promotion - where ws_sold_date_sk = d_date_sk - and d_date between cast('2001-08-17' as date) - and dateadd(day,30,cast('2001-08-17' as date)) - and ws_web_site_sk = web_site_sk - and ws_item_sk = i_item_sk - and i_current_price > 50 - and ws_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by web_site_id) -, -results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || store_id as id - , sales - , returns - , profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || catalog_page_id as id - , sales - , returns - , profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , profit - from wsr - ) x - group by channel, id) - - select channel - , id - , sales - , returns - , profit - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results - ) foo - order by channel, id - limit 100; - --- end template query80a.tpl query 63 in stream 4 --- start template query56.tpl query 64 in stream 4 -with /* TPC-DS query56.tpl 0.83 */ ss as ( - select i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where i_item_id in (select - i_item_id -from item -where i_color in ('lemon','hot','floral')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 6 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - cs as ( - select i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('lemon','hot','floral')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 6 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - ws as ( - select i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('lemon','hot','floral')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 6 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id) - select i_item_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by total_sales, - i_item_id - limit 100; - --- end template query56.tpl query 64 in stream 4 --- start template query96.tpl query 65 in stream 4 -select /* TPC-DS query96.tpl 0.1 */ count(*) -from store_sales - ,household_demographics - ,time_dim, store -where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 20 - and time_dim.t_minute >= 30 - and household_demographics.hd_dep_count = 6 - and store.s_store_name = 'ese' -order by count(*) -limit 100; - --- end template query96.tpl query 65 in stream 4 --- start template query50.tpl query 66 in stream 4 -select /* TPC-DS query50.tpl 0.60 */ - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 30) and - (sr_returned_date_sk - ss_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 60) and - (sr_returned_date_sk - ss_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 90) and - (sr_returned_date_sk - ss_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - store_sales - ,store_returns - ,store - ,date_dim d1 - ,date_dim d2 -where - d2.d_year = 2001 -and d2.d_moy = 9 -and ss_ticket_number = sr_ticket_number -and ss_item_sk = sr_item_sk -and ss_sold_date_sk = d1.d_date_sk -and sr_returned_date_sk = d2.d_date_sk -and ss_customer_sk = sr_customer_sk -and ss_store_sk = s_store_sk -group by - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -order by s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -limit 100; - --- end template query50.tpl query 66 in stream 4 --- start template query85.tpl query 67 in stream 4 -select /* TPC-DS query85.tpl 0.33 */ substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) - from web_sales, web_returns, web_page, customer_demographics cd1, - customer_demographics cd2, customer_address, date_dim, reason - where ws_web_page_sk = wp_web_page_sk - and ws_item_sk = wr_item_sk - and ws_order_number = wr_order_number - and ws_sold_date_sk = d_date_sk and d_year = 2001 - and cd1.cd_demo_sk = wr_refunded_cdemo_sk - and cd2.cd_demo_sk = wr_returning_cdemo_sk - and ca_address_sk = wr_refunded_addr_sk - and r_reason_sk = wr_reason_sk - and - ( - ( - cd1.cd_marital_status = 'D' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Primary' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 100.00 and 150.00 - ) - or - ( - cd1.cd_marital_status = 'S' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = '2 yr Degree' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 50.00 and 100.00 - ) - or - ( - cd1.cd_marital_status = 'U' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Unknown' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ca_country = 'United States' - and - ca_state in ('GA', 'OH', 'NC') - and ws_net_profit between 100 and 200 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('CT', 'MI', 'AR') - and ws_net_profit between 150 and 300 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('IA', 'NE', 'WA') - and ws_net_profit between 50 and 250 - ) - ) -group by r_reason_desc -order by substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) -limit 100; - --- end template query85.tpl query 67 in stream 4 --- start template query86a.tpl query 68 in stream 4 -with /* TPC-DS query86a.tpl 0.11 */ results as -( select sum(ws_net_paid) as total_sum, i_category, i_class, 0 as g_category, 0 as g_class - from - web_sales - ,date_dim d1 - ,item - where - d1.d_month_seq between 1216 and 1216+11 - and d1.d_date_sk = ws_sold_date_sk - and i_item_sk = ws_item_sk - group by i_category,i_class - ) , - - results_rollup as -( select total_sum ,i_category ,i_class, g_category, g_class, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum, i_category, NULL as i_class, 0 as g_category, 1 as g_class, 1 as lochierarchy from results group by i_category - union - select sum(total_sum) as total_sum, NULL as i_category, NULL as i_class, 1 as g_category, 1 as g_class, 2 as lochierarchy from results) - select - total_sum ,i_category ,i_class, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_class = 0 then i_category end - order by total_sum desc) as rank_within_parent - from - results_rollup - order by - lochierarchy desc, - case when lochierarchy = 0 then i_category end, - rank_within_parent - limit 100; - --- end template query86a.tpl query 68 in stream 4 --- start template query69.tpl query 69 in stream 4 -select /* TPC-DS query69.tpl 0.28 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_state in ('NC','ID','KS') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2003 and - d_moy between 2 and 2+2) and - (not exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2003 and - d_moy between 2 and 2+2) and - not exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2003 and - d_moy between 2 and 2+2)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - limit 100; - --- end template query69.tpl query 69 in stream 4 --- start template query68.tpl query 70 in stream 4 -select /* TPC-DS query68.tpl 0.95 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,extended_price - ,extended_tax - ,list_price - from (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_ext_sales_price) extended_price - ,sum(ss_ext_list_price) list_price - ,sum(ss_ext_tax) extended_tax - from store_sales - ,date_dim - ,store - ,household_demographics - ,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_dep_count = 7 or - household_demographics.hd_vehicle_count= 4) - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_city in ('Buena Vista','Diamond') - group by ss_ticket_number - ,ss_customer_sk - ,ss_addr_sk,ca_city) dn - ,customer - ,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,ss_ticket_number - limit 100; - --- end template query68.tpl query 70 in stream 4 --- start template query1.tpl query 71 in stream 4 -with /* TPC-DS query1.tpl 0.12 */ customer_total_return as -(select sr_customer_sk as ctr_customer_sk -,sr_store_sk as ctr_store_sk -,sum(SR_RETURN_AMT_INC_TAX) as ctr_total_return -from store_returns -,date_dim -where sr_returned_date_sk = d_date_sk -and d_year =1998 -group by sr_customer_sk -,sr_store_sk) - select c_customer_id -from customer_total_return ctr1 -,store -,customer -where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 -from customer_total_return ctr2 -where ctr1.ctr_store_sk = ctr2.ctr_store_sk) -and s_store_sk = ctr1.ctr_store_sk -and s_state = 'WI' -and ctr1.ctr_customer_sk = c_customer_sk -order by c_customer_id -limit 100; - --- end template query1.tpl query 71 in stream 4 --- start template query12.tpl query 72 in stream 4 -select /* TPC-DS query12.tpl 0.64 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ws_ext_sales_price) as itemrevenue - ,sum(ws_ext_sales_price)*100/sum(sum(ws_ext_sales_price)) over - (partition by i_class) as revenueratio -from - web_sales - ,item - ,date_dim -where - ws_item_sk = i_item_sk - and i_category in ('Men', 'Shoes', 'Home') - and ws_sold_date_sk = d_date_sk - and d_date between cast('2000-05-26' as date) - and dateadd(day,30,cast('2000-05-26' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query12.tpl query 72 in stream 4 --- start template query43.tpl query 73 in stream 4 -select /* TPC-DS query43.tpl 0.15 */ s_store_name, s_store_id, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from date_dim, store_sales, store - where d_date_sk = ss_sold_date_sk and - s_store_sk = ss_store_sk and - s_gmt_offset = -6 and - d_year = 1999 - group by s_store_name, s_store_id - order by s_store_name, s_store_id,sun_sales,mon_sales,tue_sales,wed_sales,thu_sales,fri_sales,sat_sales - limit 100; - --- end template query43.tpl query 73 in stream 4 --- start template query16.tpl query 74 in stream 4 -select /* TPC-DS query16.tpl 0.25 */ - count(distinct cs_order_number) as "order count" - ,sum(cs_ext_ship_cost) as "total shipping cost" - ,sum(cs_net_profit) as "total net profit" -from - catalog_sales cs1 - ,date_dim - ,customer_address - ,call_center -where - d_date between '2000-4-01' and - dateadd(day, 60, cast('2000-4-01' as date)) -and cs1.cs_ship_date_sk = d_date_sk -and cs1.cs_ship_addr_sk = ca_address_sk -and ca_state = 'OH' -and cs1.cs_call_center_sk = cc_call_center_sk -and cc_county in ('Franklin Parish','Mobile County','Sierra County','Luce County', - 'Williamson County' -) -and exists (select * - from catalog_sales cs2 - where cs1.cs_order_number = cs2.cs_order_number - and cs1.cs_warehouse_sk <> cs2.cs_warehouse_sk) -and not exists(select * - from catalog_returns cr1 - where cs1.cs_order_number = cr1.cr_order_number) -order by count(distinct cs_order_number) -limit 100; - --- end template query16.tpl query 74 in stream 4 --- start template query4.tpl query 75 in stream 4 -with /* TPC-DS query4.tpl 0.93 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(((ss_ext_list_price-ss_ext_wholesale_cost-ss_ext_discount_amt)+ss_ext_sales_price)/2) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((cs_ext_list_price-cs_ext_wholesale_cost-cs_ext_discount_amt)+cs_ext_sales_price)/2) ) year_total - ,'c' sale_type - from customer - ,catalog_sales - ,date_dim - where c_customer_sk = cs_bill_customer_sk - and cs_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year -union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((ws_ext_list_price-ws_ext_wholesale_cost-ws_ext_discount_amt)+ws_ext_sales_price)/2) ) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_preferred_cust_flag - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_c_firstyear - ,year_total t_c_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_c_secyear.customer_id - and t_s_firstyear.customer_id = t_c_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_c_firstyear.sale_type = 'c' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_c_secyear.sale_type = 'c' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 2000 - and t_s_secyear.dyear = 2000+1 - and t_c_firstyear.dyear = 2000 - and t_c_secyear.dyear = 2000+1 - and t_w_firstyear.dyear = 2000 - and t_w_secyear.dyear = 2000+1 - and t_s_firstyear.year_total > 0 - and t_c_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_preferred_cust_flag -limit 100; - --- end template query4.tpl query 75 in stream 4 --- start template query25.tpl query 76 in stream 4 -select /* TPC-DS query25.tpl 0.9 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,avg(ss_net_profit) as store_sales_profit - ,avg(sr_net_loss) as store_returns_loss - ,avg(cs_net_profit) as catalog_sales_profit - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 1998 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 10 - and d2.d_year = 1998 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_moy between 4 and 10 - and d3.d_year = 1998 - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query25.tpl query 76 in stream 4 --- start template query20.tpl query 77 in stream 4 -select /* TPC-DS query20.tpl 0.65 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(cs_ext_sales_price) as itemrevenue - ,sum(cs_ext_sales_price)*100/sum(sum(cs_ext_sales_price)) over - (partition by i_class) as revenueratio - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and i_category in ('Sports', 'Books', 'Shoes') - and cs_sold_date_sk = d_date_sk - and d_date between cast('1998-04-28' as date) - and dateadd(day,30,cast('1998-04-28' as date)) - group by i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - order by i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query20.tpl query 77 in stream 4 --- start template query65.tpl query 78 in stream 4 -select /* TPC-DS query65.tpl 0.71 */ - s_store_name, - i_item_desc, - sc.revenue, - i_current_price, - i_wholesale_cost, - i_brand - from store, item, - (select ss_store_sk, avg(revenue) as ave - from - (select ss_store_sk, ss_item_sk, - sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1204 and 1204+11 - group by ss_store_sk, ss_item_sk) sa - group by ss_store_sk) sb, - (select ss_store_sk, ss_item_sk, sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1204 and 1204+11 - group by ss_store_sk, ss_item_sk) sc - where sb.ss_store_sk = sc.ss_store_sk and - sc.revenue <= 0.1 * sb.ave and - s_store_sk = sc.ss_store_sk and - i_item_sk = sc.ss_item_sk - order by s_store_name, i_item_desc -limit 100; - --- end template query65.tpl query 78 in stream 4 --- start template query15.tpl query 79 in stream 4 -select /* TPC-DS query15.tpl 0.57 */ ca_zip - ,sum(cs_sales_price) - from catalog_sales - ,customer - ,customer_address - ,date_dim - where cs_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', - '85392', '85460', '80348', '81792') - or ca_state in ('CA','WA','GA') - or cs_sales_price > 500) - and cs_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 2000 - group by ca_zip - order by ca_zip - limit 100; - --- end template query15.tpl query 79 in stream 4 --- start template query98.tpl query 80 in stream 4 -select /* TPC-DS query98.tpl 0.32 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ss_ext_sales_price) as itemrevenue - ,sum(ss_ext_sales_price)*100/sum(sum(ss_ext_sales_price)) over - (partition by i_class) as revenueratio -from - store_sales - ,item - ,date_dim -where - ss_item_sk = i_item_sk - and i_category in ('Children', 'Men', 'Shoes') - and ss_sold_date_sk = d_date_sk - and d_date between cast('2000-05-27' as date) - and dateadd(day,30,cast('2000-05-27' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio; - --- end template query98.tpl query 80 in stream 4 --- start template query42.tpl query 81 in stream 4 -select /* TPC-DS query42.tpl 0.61 */ dt.d_year - ,item.i_category_id - ,item.i_category - ,sum(ss_ext_sales_price) - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=11 - and dt.d_year=2001 - group by dt.d_year - ,item.i_category_id - ,item.i_category - order by sum(ss_ext_sales_price) desc,dt.d_year - ,item.i_category_id - ,item.i_category -limit 100 ; - --- end template query42.tpl query 81 in stream 4 --- start template query26.tpl query 82 in stream 4 -select /* TPC-DS query26.tpl 0.85 */ i_item_id, - avg(cs_quantity) agg1, - avg(cs_list_price) agg2, - avg(cs_coupon_amt) agg3, - avg(cs_sales_price) agg4 - from catalog_sales, customer_demographics, date_dim, item, promotion - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd_demo_sk and - cs_promo_sk = p_promo_sk and - cd_gender = 'M' and - cd_marital_status = 'D' and - cd_education_status = 'Advanced Degree' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 2000 - group by i_item_id - order by i_item_id - limit 100; - --- end template query26.tpl query 82 in stream 4 --- start template query34.tpl query 83 in stream 4 -select /* TPC-DS query34.tpl 0.73 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (date_dim.d_dom between 1 and 3 or date_dim.d_dom between 25 and 28) - and (household_demographics.hd_buy_potential = '1001-5000' or - household_demographics.hd_buy_potential = '5001-10000') - and household_demographics.hd_vehicle_count > 0 - and (case when household_demographics.hd_vehicle_count > 0 - then household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count - else null - end) > 1.2 - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_county in ('Morgan County','Salem County','West Feliciana Parish','Knox County', - 'Barrow County','Jasper County','Anderson County','Fulton County') - group by ss_ticket_number,ss_customer_sk) dn,customer - where ss_customer_sk = c_customer_sk - and cnt between 15 and 20 - order by c_last_name,c_first_name,c_salutation,c_preferred_cust_flag desc, ss_ticket_number; - --- end template query34.tpl query 83 in stream 4 --- start template query5a.tpl query 84 in stream 4 -with /* TPC-DS query5a.tpl 0.98 */ ssr as - (select s_store_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ss_store_sk as store_sk, - ss_sold_date_sk as date_sk, - ss_ext_sales_price as sales_price, - ss_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from store_sales - union all - select sr_store_sk as store_sk, - sr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - sr_return_amt as return_amt, - sr_net_loss as net_loss - from store_returns - ) salesreturns, - date_dim, - store - where date_sk = d_date_sk - and d_date between cast('1998-08-12' as date) - and dateadd(day,14,cast('1998-08-12' as date)) - and store_sk = s_store_sk - group by s_store_id) - , - csr as - (select cp_catalog_page_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select cs_catalog_page_sk as page_sk, - cs_sold_date_sk as date_sk, - cs_ext_sales_price as sales_price, - cs_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from catalog_sales - union all - select cr_catalog_page_sk as page_sk, - cr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - cr_return_amount as return_amt, - cr_net_loss as net_loss - from catalog_returns - ) salesreturns, - date_dim, - catalog_page - where date_sk = d_date_sk - and d_date between cast('1998-08-12' as date) - and dateadd(day,14,cast('1998-08-12' as date)) - and page_sk = cp_catalog_page_sk - group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ws_web_site_sk as wsr_web_site_sk, - ws_sold_date_sk as date_sk, - ws_ext_sales_price as sales_price, - ws_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from web_sales - union all - select ws_web_site_sk as wsr_web_site_sk, - wr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - wr_return_amt as return_amt, - wr_net_loss as net_loss - from web_returns left outer join web_sales on - ( wr_item_sk = ws_item_sk - and wr_order_number = ws_order_number) - ) salesreturns, - date_dim, - web_site - where date_sk = d_date_sk - and d_date between cast('1998-08-12' as date) - and dateadd(day,14,cast('1998-08-12' as date)) - and wsr_web_site_sk = web_site_sk - group by web_site_id) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || s_store_id as id - , sales - , returns - , (profit - profit_loss) as profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || cp_catalog_page_id as id - , sales - , returns - , (profit - profit_loss) as profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , (profit - profit_loss) as profit - from wsr - ) x - group by channel, id) - select channel, id, sales, returns, profit from ( - select channel, id, sales, returns, profit from results - union - select channel, null as id, sum(sales), sum(returns), sum(profit) from results group by channel - union - select null as channel, null as id, sum(sales), sum(returns), sum(profit) from results) foo -order by channel, id -limit 100; - --- end template query5a.tpl query 84 in stream 4 --- start template query87.tpl query 85 in stream 4 -select /* TPC-DS query87.tpl 0.77 */ count(*) -from ((select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1189 and 1189+11) - except - (select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1189 and 1189+11) - except - (select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1189 and 1189+11) -) cool_cust -; - --- end template query87.tpl query 85 in stream 4 --- start template query3.tpl query 86 in stream 4 -select /* TPC-DS query3.tpl 0.45 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_sales_price) sum_agg - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manufact_id = 753 - and dt.d_moy=12 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,sum_agg desc - ,brand_id - limit 100; - --- end template query3.tpl query 86 in stream 4 --- start template query64.tpl query 87 in stream 4 -with /* TPC-DS query64.tpl 0.20 */ cs_ui as - (select cs_item_sk - ,sum(cs_ext_list_price) as sale,sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit) as refund - from catalog_sales - ,catalog_returns - where cs_item_sk = cr_item_sk - and cs_order_number = cr_order_number - group by cs_item_sk - having sum(cs_ext_list_price)>2*sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit)), -cross_sales as - (select i_product_name product_name - ,i_item_sk item_sk - ,s_store_name store_name - ,s_zip store_zip - ,ad1.ca_street_number b_street_number - ,ad1.ca_street_name b_street_name - ,ad1.ca_city b_city - ,ad1.ca_zip b_zip - ,ad2.ca_street_number c_street_number - ,ad2.ca_street_name c_street_name - ,ad2.ca_city c_city - ,ad2.ca_zip c_zip - ,d1.d_year as syear - ,d2.d_year as fsyear - ,d3.d_year s2year - ,count(*) cnt - ,sum(ss_wholesale_cost) s1 - ,sum(ss_list_price) s2 - ,sum(ss_coupon_amt) s3 - FROM store_sales - ,store_returns - ,cs_ui - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,customer - ,customer_demographics cd1 - ,customer_demographics cd2 - ,promotion - ,household_demographics hd1 - ,household_demographics hd2 - ,customer_address ad1 - ,customer_address ad2 - ,income_band ib1 - ,income_band ib2 - ,item - WHERE ss_store_sk = s_store_sk AND - ss_sold_date_sk = d1.d_date_sk AND - ss_customer_sk = c_customer_sk AND - ss_cdemo_sk= cd1.cd_demo_sk AND - ss_hdemo_sk = hd1.hd_demo_sk AND - ss_addr_sk = ad1.ca_address_sk and - ss_item_sk = i_item_sk and - ss_item_sk = sr_item_sk and - ss_ticket_number = sr_ticket_number and - ss_item_sk = cs_ui.cs_item_sk and - c_current_cdemo_sk = cd2.cd_demo_sk AND - c_current_hdemo_sk = hd2.hd_demo_sk AND - c_current_addr_sk = ad2.ca_address_sk and - c_first_sales_date_sk = d2.d_date_sk and - c_first_shipto_date_sk = d3.d_date_sk and - ss_promo_sk = p_promo_sk and - hd1.hd_income_band_sk = ib1.ib_income_band_sk and - hd2.hd_income_band_sk = ib2.ib_income_band_sk and - cd1.cd_marital_status <> cd2.cd_marital_status and - i_color in ('saddle','orange','peru','frosted','hot','gainsboro') and - i_current_price between 47 and 47 + 10 and - i_current_price between 47 + 1 and 47 + 15 -group by i_product_name - ,i_item_sk - ,s_store_name - ,s_zip - ,ad1.ca_street_number - ,ad1.ca_street_name - ,ad1.ca_city - ,ad1.ca_zip - ,ad2.ca_street_number - ,ad2.ca_street_name - ,ad2.ca_city - ,ad2.ca_zip - ,d1.d_year - ,d2.d_year - ,d3.d_year -) -select cs1.product_name - ,cs1.store_name - ,cs1.store_zip - ,cs1.b_street_number - ,cs1.b_street_name - ,cs1.b_city - ,cs1.b_zip - ,cs1.c_street_number - ,cs1.c_street_name - ,cs1.c_city - ,cs1.c_zip - ,cs1.syear - ,cs1.cnt - ,cs1.s1 as s11 - ,cs1.s2 as s21 - ,cs1.s3 as s31 - ,cs2.s1 as s12 - ,cs2.s2 as s22 - ,cs2.s3 as s32 - ,cs2.syear - ,cs2.cnt -from cross_sales cs1,cross_sales cs2 -where cs1.item_sk=cs2.item_sk and - cs1.syear = 1999 and - cs2.syear = 1999 + 1 and - cs2.cnt <= cs1.cnt and - cs1.store_name = cs2.store_name and - cs1.store_zip = cs2.store_zip -order by cs1.product_name - ,cs1.store_name - ,cs2.cnt - ,cs1.s1 - ,cs2.s1; - --- end template query64.tpl query 87 in stream 4 --- start template query31.tpl query 88 in stream 4 -with /* TPC-DS query31.tpl 0.50 */ ss as - (select ca_county,d_qoy, d_year,sum(ss_ext_sales_price) as store_sales - from store_sales,date_dim,customer_address - where ss_sold_date_sk = d_date_sk - and ss_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year), - ws as - (select ca_county,d_qoy, d_year,sum(ws_ext_sales_price) as web_sales - from web_sales,date_dim,customer_address - where ws_sold_date_sk = d_date_sk - and ws_bill_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year) - select - ss1.ca_county - ,ss1.d_year - ,ws2.web_sales/ws1.web_sales web_q1_q2_increase - ,ss2.store_sales/ss1.store_sales store_q1_q2_increase - ,ws3.web_sales/ws2.web_sales web_q2_q3_increase - ,ss3.store_sales/ss2.store_sales store_q2_q3_increase - from - ss ss1 - ,ss ss2 - ,ss ss3 - ,ws ws1 - ,ws ws2 - ,ws ws3 - where - ss1.d_qoy = 1 - and ss1.d_year = 1998 - and ss1.ca_county = ss2.ca_county - and ss2.d_qoy = 2 - and ss2.d_year = 1998 - and ss2.ca_county = ss3.ca_county - and ss3.d_qoy = 3 - and ss3.d_year = 1998 - and ss1.ca_county = ws1.ca_county - and ws1.d_qoy = 1 - and ws1.d_year = 1998 - and ws1.ca_county = ws2.ca_county - and ws2.d_qoy = 2 - and ws2.d_year = 1998 - and ws1.ca_county = ws3.ca_county - and ws3.d_qoy = 3 - and ws3.d_year =1998 - and case when ws1.web_sales > 0 then ws2.web_sales/ws1.web_sales else null end - > case when ss1.store_sales > 0 then ss2.store_sales/ss1.store_sales else null end - and case when ws2.web_sales > 0 then ws3.web_sales/ws2.web_sales else null end - > case when ss2.store_sales > 0 then ss3.store_sales/ss2.store_sales else null end - order by store_q2_q3_increase; - --- end template query31.tpl query 88 in stream 4 --- start template query57.tpl query 89 in stream 4 -with /* TPC-DS query57.tpl 0.70 */ v1 as( - select i_category, i_brand, - cc_name, - d_year, d_moy, - sum(cs_sales_price) sum_sales, - avg(sum(cs_sales_price)) over - (partition by i_category, i_brand, - cc_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - cc_name - order by d_year, d_moy) rn - from item, catalog_sales, date_dim, call_center - where cs_item_sk = i_item_sk and - cs_sold_date_sk = d_date_sk and - cc_call_center_sk= cs_call_center_sk and - ( - d_year = 2000 or - ( d_year = 2000-1 and d_moy =12) or - ( d_year = 2000+1 and d_moy =1) - ) - group by i_category, i_brand, - cc_name , d_year, d_moy), - v2 as( - select v1.i_brand - ,v1.d_year, v1.d_moy - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1. cc_name = v1_lag. cc_name and - v1. cc_name = v1_lead. cc_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 2000 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, nsum - limit 100; - --- end template query57.tpl query 89 in stream 4 --- start template query30.tpl query 90 in stream 4 -with /* TPC-DS query30.tpl 0.75 */ customer_total_return as - (select wr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(wr_return_amt) as ctr_total_return - from web_returns - ,date_dim - ,customer_address - where wr_returned_date_sk = d_date_sk - and d_year =2000 - and wr_returning_addr_sk = ca_address_sk - group by wr_returning_customer_sk - ,ca_state) - select c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'NC' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return -limit 100; - --- end template query30.tpl query 90 in stream 4 --- start template query13.tpl query 91 in stream 4 -select /* TPC-DS query13.tpl 0.91 */ avg(ss_quantity) - ,avg(ss_ext_sales_price) - ,avg(ss_ext_wholesale_cost) - ,sum(ss_ext_wholesale_cost) - from store_sales - ,store - ,customer_demographics - ,household_demographics - ,customer_address - ,date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2001 - and((ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'D' - and cd_education_status = 'Unknown' - and ss_sales_price between 100.00 and 150.00 - and hd_dep_count = 3 - )or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'S' - and cd_education_status = 'Primary' - and ss_sales_price between 50.00 and 100.00 - and hd_dep_count = 1 - ) or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'W' - and cd_education_status = '4 yr Degree' - and ss_sales_price between 150.00 and 200.00 - and hd_dep_count = 1 - )) - and((ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('TX', 'TN', 'NY') - and ss_net_profit between 100 and 200 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('NC', 'MA', 'AL') - and ss_net_profit between 150 and 300 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('AR', 'WV', 'MS') - and ss_net_profit between 50 and 250 - )) -; - --- end template query13.tpl query 91 in stream 4 --- start template query94.tpl query 92 in stream 4 -select /* TPC-DS query94.tpl 0.17 */ - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '1999-3-01' and - dateadd(day,60,cast('1999-3-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'HI' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and exists (select * - from web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) -and not exists(select * - from web_returns wr1 - where ws1.ws_order_number = wr1.wr_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query94.tpl query 92 in stream 4 --- start template query62.tpl query 93 in stream 4 -select /* TPC-DS query62.tpl 0.24 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 30) and - (ws_ship_date_sk - ws_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 60) and - (ws_ship_date_sk - ws_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 90) and - (ws_ship_date_sk - ws_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - web_sales - ,warehouse - ,ship_mode - ,web_site - ,date_dim -where - d_month_seq between 1182 and 1182 + 11 -and ws_ship_date_sk = d_date_sk -and ws_warehouse_sk = w_warehouse_sk -and ws_ship_mode_sk = sm_ship_mode_sk -and ws_web_site_sk = web_site_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -limit 100; - --- end template query62.tpl query 93 in stream 4 --- start template query49.tpl query 94 in stream 4 -select /* TPC-DS query49.tpl 0.48 */ channel, item, return_ratio, return_rank, currency_rank from - (select - 'web' as channel - ,web.item - ,web.return_ratio - ,web.return_rank - ,web.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select ws.ws_item_sk as item - ,(cast(sum(coalesce(wr.wr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(wr.wr_return_amt,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - web_sales ws left outer join web_returns wr - on (ws.ws_order_number = wr.wr_order_number and - ws.ws_item_sk = wr.wr_item_sk) - ,date_dim - where - wr.wr_return_amt > 10000 - and ws.ws_net_profit > 1 - and ws.ws_net_paid > 0 - and ws.ws_quantity > 0 - and ws_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 12 - group by ws.ws_item_sk - ) in_web - ) web - where - ( - web.return_rank <= 10 - or - web.currency_rank <= 10 - ) - union - select - 'catalog' as channel - ,catalog.item - ,catalog.return_ratio - ,catalog.return_rank - ,catalog.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select - cs.cs_item_sk as item - ,(cast(sum(coalesce(cr.cr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(cr.cr_return_amount,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - catalog_sales cs left outer join catalog_returns cr - on (cs.cs_order_number = cr.cr_order_number and - cs.cs_item_sk = cr.cr_item_sk) - ,date_dim - where - cr.cr_return_amount > 10000 - and cs.cs_net_profit > 1 - and cs.cs_net_paid > 0 - and cs.cs_quantity > 0 - and cs_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 12 - group by cs.cs_item_sk - ) in_cat - ) catalog - where - ( - catalog.return_rank <= 10 - or - catalog.currency_rank <=10 - ) - union - select - 'store' as channel - ,store.item - ,store.return_ratio - ,store.return_rank - ,store.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select sts.ss_item_sk as item - ,(cast(sum(coalesce(sr.sr_return_quantity,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(sr.sr_return_amt,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - store_sales sts left outer join store_returns sr - on (sts.ss_ticket_number = sr.sr_ticket_number and sts.ss_item_sk = sr.sr_item_sk) - ,date_dim - where - sr.sr_return_amt > 10000 - and sts.ss_net_profit > 1 - and sts.ss_net_paid > 0 - and sts.ss_quantity > 0 - and ss_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 12 - group by sts.ss_item_sk - ) in_store - ) store - where ( - store.return_rank <= 10 - or - store.currency_rank <= 10 - ) - ) - order by 1,4,5,2 - limit 100; - --- end template query49.tpl query 94 in stream 4 --- start template query11.tpl query 95 in stream 4 -with /* TPC-DS query11.tpl 0.51 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ss_ext_list_price-ss_ext_discount_amt) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ws_ext_list_price-ws_ext_discount_amt) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_preferred_cust_flag - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 1999 - and t_s_secyear.dyear = 1999+1 - and t_w_firstyear.dyear = 1999 - and t_w_secyear.dyear = 1999+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else 0.0 end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else 0.0 end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_preferred_cust_flag -limit 100; - --- end template query11.tpl query 95 in stream 4 --- start template query73.tpl query 96 in stream 4 -select /* TPC-DS query73.tpl 0.79 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_buy_potential = '>10000' or - household_demographics.hd_buy_potential = 'Unknown') - and household_demographics.hd_vehicle_count > 0 - and case when household_demographics.hd_vehicle_count > 0 then - household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count else null end > 1 - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_county in ('LaMoure County','Sibley County','Lincoln County','Franklin County') - group by ss_ticket_number,ss_customer_sk) dj,customer - where ss_customer_sk = c_customer_sk - and cnt between 1 and 5 - order by cnt desc, c_last_name asc; - --- end template query73.tpl query 96 in stream 4 --- start template query67a.tpl query 97 in stream 4 -with /* TPC-DS query67a.tpl 0.35 */ results as -( select i_category ,i_class ,i_brand ,i_product_name ,d_year ,d_qoy ,d_moy ,s_store_id - ,sum(coalesce(ss_sales_price*ss_quantity,0)) sumsales - from store_sales ,date_dim ,store ,item - where ss_sold_date_sk=d_date_sk - and ss_item_sk=i_item_sk - and ss_store_sk = s_store_sk - and d_month_seq between 1202 and 1202 + 11 - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy,s_store_id) - , - results_rollup as - (select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, s_store_id, sumsales - from results - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy - union all - select i_category, i_class, i_brand, i_product_name, d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year - union all - select i_category, i_class, i_brand, i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name - union all - select i_category, i_class, i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand - union all - select i_category, i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class - union all - select i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category - union all - select null i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results) - - select * -from (select i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rank() over (partition by i_category order by sumsales desc) rk - from results_rollup) dw2 -where rk <= 100 -order by i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rk -limit 100; - --- end template query67a.tpl query 97 in stream 4 --- start template query53.tpl query 98 in stream 4 -select /* TPC-DS query53.tpl 0.88 */ * from -(select i_manufact_id, -sum(ss_sales_price) sum_sales, -avg(sum(ss_sales_price)) over (partition by i_manufact_id) avg_quarterly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and -ss_sold_date_sk = d_date_sk and -ss_store_sk = s_store_sk and -d_month_seq in (1205,1205+1,1205+2,1205+3,1205+4,1205+5,1205+6,1205+7,1205+8,1205+9,1205+10,1205+11) and -((i_category in ('Books','Children','Electronics') and -i_class in ('personal','portable','reference','self-help') and -i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) -or(i_category in ('Women','Music','Men') and -i_class in ('accessories','classical','fragrances','pants') and -i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manufact_id, d_qoy ) tmp1 -where case when avg_quarterly_sales > 0 - then abs (sum_sales - avg_quarterly_sales)/ avg_quarterly_sales - else null end > 0.1 -order by avg_quarterly_sales, - sum_sales, - i_manufact_id -limit 100; - --- end template query53.tpl query 98 in stream 4 --- start template query9.tpl query 99 in stream 4 -select /* TPC-DS query9.tpl 0.49 */ case when (select count(*) - from store_sales - where ss_quantity between 1 and 20) > 4232705270 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 1 and 20) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 1 and 20) end bucket1 , - case when (select count(*) - from store_sales - where ss_quantity between 21 and 40) > 1069102487 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 21 and 40) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 21 and 40) end bucket2, - case when (select count(*) - from store_sales - where ss_quantity between 41 and 60) > 1319136311 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 41 and 60) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 41 and 60) end bucket3, - case when (select count(*) - from store_sales - where ss_quantity between 61 and 80) > 3049961548 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 61 and 80) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 61 and 80) end bucket4, - case when (select count(*) - from store_sales - where ss_quantity between 81 and 100) > 3228477222 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 81 and 100) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 81 and 100) end bucket5 -from reason -where r_reason_sk = 1 -; - --- end template query9.tpl query 99 in stream 4 diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/100TB/queries/query_5.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/100TB/queries/query_5.sql deleted file mode 100644 index 4e87af34..00000000 --- a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/100TB/queries/query_5.sql +++ /dev/null @@ -1,5027 +0,0 @@ --- start template query73.tpl query 1 in stream 5 -select /* TPC-DS query73.tpl 0.79 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_buy_potential = '>10000' or - household_demographics.hd_buy_potential = '0-500') - and household_demographics.hd_vehicle_count > 0 - and case when household_demographics.hd_vehicle_count > 0 then - household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count else null end > 1 - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_county in ('Nez Perce County','Klamath County','LaMoure County','Wadena County') - group by ss_ticket_number,ss_customer_sk) dj,customer - where ss_customer_sk = c_customer_sk - and cnt between 1 and 5 - order by cnt desc, c_last_name asc; - --- end template query73.tpl query 1 in stream 5 --- start template query66.tpl query 2 in stream 5 -select /* TPC-DS query66.tpl 0.39 */ - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - ,sum(jan_sales) as jan_sales - ,sum(feb_sales) as feb_sales - ,sum(mar_sales) as mar_sales - ,sum(apr_sales) as apr_sales - ,sum(may_sales) as may_sales - ,sum(jun_sales) as jun_sales - ,sum(jul_sales) as jul_sales - ,sum(aug_sales) as aug_sales - ,sum(sep_sales) as sep_sales - ,sum(oct_sales) as oct_sales - ,sum(nov_sales) as nov_sales - ,sum(dec_sales) as dec_sales - ,sum(jan_sales/w_warehouse_sq_ft) as jan_sales_per_sq_foot - ,sum(feb_sales/w_warehouse_sq_ft) as feb_sales_per_sq_foot - ,sum(mar_sales/w_warehouse_sq_ft) as mar_sales_per_sq_foot - ,sum(apr_sales/w_warehouse_sq_ft) as apr_sales_per_sq_foot - ,sum(may_sales/w_warehouse_sq_ft) as may_sales_per_sq_foot - ,sum(jun_sales/w_warehouse_sq_ft) as jun_sales_per_sq_foot - ,sum(jul_sales/w_warehouse_sq_ft) as jul_sales_per_sq_foot - ,sum(aug_sales/w_warehouse_sq_ft) as aug_sales_per_sq_foot - ,sum(sep_sales/w_warehouse_sq_ft) as sep_sales_per_sq_foot - ,sum(oct_sales/w_warehouse_sq_ft) as oct_sales_per_sq_foot - ,sum(nov_sales/w_warehouse_sq_ft) as nov_sales_per_sq_foot - ,sum(dec_sales/w_warehouse_sq_ft) as dec_sales_per_sq_foot - ,sum(jan_net) as jan_net - ,sum(feb_net) as feb_net - ,sum(mar_net) as mar_net - ,sum(apr_net) as apr_net - ,sum(may_net) as may_net - ,sum(jun_net) as jun_net - ,sum(jul_net) as jul_net - ,sum(aug_net) as aug_net - ,sum(sep_net) as sep_net - ,sum(oct_net) as oct_net - ,sum(nov_net) as nov_net - ,sum(dec_net) as dec_net - from ( - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'DIAMOND' || ',' || 'PRIVATECARRIER' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then ws_sales_price* ws_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then ws_sales_price* ws_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then ws_sales_price* ws_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then ws_sales_price* ws_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then ws_sales_price* ws_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then ws_sales_price* ws_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then ws_sales_price* ws_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then ws_sales_price* ws_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then ws_sales_price* ws_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then ws_sales_price* ws_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then ws_sales_price* ws_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then ws_sales_price* ws_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as dec_net - from - web_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - ws_warehouse_sk = w_warehouse_sk - and ws_sold_date_sk = d_date_sk - and ws_sold_time_sk = t_time_sk - and ws_ship_mode_sk = sm_ship_mode_sk - and d_year = 1998 - and t_time between 28658 and 28658+28800 - and sm_carrier in ('DIAMOND','PRIVATECARRIER') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - union all - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'DIAMOND' || ',' || 'PRIVATECARRIER' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then cs_ext_sales_price* cs_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then cs_ext_sales_price* cs_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then cs_ext_sales_price* cs_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then cs_ext_sales_price* cs_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then cs_ext_sales_price* cs_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then cs_ext_sales_price* cs_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then cs_ext_sales_price* cs_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then cs_ext_sales_price* cs_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then cs_ext_sales_price* cs_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then cs_ext_sales_price* cs_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then cs_ext_sales_price* cs_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then cs_ext_sales_price* cs_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then cs_net_profit * cs_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then cs_net_profit * cs_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then cs_net_profit * cs_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then cs_net_profit * cs_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then cs_net_profit * cs_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then cs_net_profit * cs_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then cs_net_profit * cs_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then cs_net_profit * cs_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then cs_net_profit * cs_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then cs_net_profit * cs_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then cs_net_profit * cs_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then cs_net_profit * cs_quantity else 0 end) as dec_net - from - catalog_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and cs_sold_time_sk = t_time_sk - and cs_ship_mode_sk = sm_ship_mode_sk - and d_year = 1998 - and t_time between 28658 AND 28658+28800 - and sm_carrier in ('DIAMOND','PRIVATECARRIER') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - ) x - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - order by w_warehouse_name - limit 100; - --- end template query66.tpl query 2 in stream 5 --- start template query4.tpl query 3 in stream 5 -with /* TPC-DS query4.tpl 0.93 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(((ss_ext_list_price-ss_ext_wholesale_cost-ss_ext_discount_amt)+ss_ext_sales_price)/2) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((cs_ext_list_price-cs_ext_wholesale_cost-cs_ext_discount_amt)+cs_ext_sales_price)/2) ) year_total - ,'c' sale_type - from customer - ,catalog_sales - ,date_dim - where c_customer_sk = cs_bill_customer_sk - and cs_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year -union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((ws_ext_list_price-ws_ext_wholesale_cost-ws_ext_discount_amt)+ws_ext_sales_price)/2) ) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_email_address - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_c_firstyear - ,year_total t_c_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_c_secyear.customer_id - and t_s_firstyear.customer_id = t_c_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_c_firstyear.sale_type = 'c' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_c_secyear.sale_type = 'c' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 2000 - and t_s_secyear.dyear = 2000+1 - and t_c_firstyear.dyear = 2000 - and t_c_secyear.dyear = 2000+1 - and t_w_firstyear.dyear = 2000 - and t_w_secyear.dyear = 2000+1 - and t_s_firstyear.year_total > 0 - and t_c_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_email_address -limit 100; - --- end template query4.tpl query 3 in stream 5 --- start template query17.tpl query 4 in stream 5 -select /* TPC-DS query17.tpl 0.41 */ i_item_id - ,i_item_desc - ,s_state - ,count(ss_quantity) as store_sales_quantitycount - ,avg(ss_quantity) as store_sales_quantityave - ,stddev_samp(ss_quantity) as store_sales_quantitystdev - ,stddev_samp(ss_quantity)/avg(ss_quantity) as store_sales_quantitycov - ,count(sr_return_quantity) as store_returns_quantitycount - ,avg(sr_return_quantity) as store_returns_quantityave - ,stddev_samp(sr_return_quantity) as store_returns_quantitystdev - ,stddev_samp(sr_return_quantity)/avg(sr_return_quantity) as store_returns_quantitycov - ,count(cs_quantity) as catalog_sales_quantitycount ,avg(cs_quantity) as catalog_sales_quantityave - ,stddev_samp(cs_quantity) as catalog_sales_quantitystdev - ,stddev_samp(cs_quantity)/avg(cs_quantity) as catalog_sales_quantitycov - from store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where d1.d_quarter_name = '2001Q1' - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_quarter_name in ('2001Q1','2001Q2','2001Q3') - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_quarter_name in ('2001Q1','2001Q2','2001Q3') - group by i_item_id - ,i_item_desc - ,s_state - order by i_item_id - ,i_item_desc - ,s_state -limit 100; - --- end template query17.tpl query 4 in stream 5 --- start template query60.tpl query 5 in stream 5 -with /* TPC-DS query60.tpl 0.29 */ ss as ( - select - i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Men')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 8 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - cs as ( - select - i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Men')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 8 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - ws as ( - select - i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Men')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 8 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id) - select - i_item_id -,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by i_item_id - ,total_sales - limit 100; - --- end template query60.tpl query 5 in stream 5 --- start template query98.tpl query 6 in stream 5 -select /* TPC-DS query98.tpl 0.32 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ss_ext_sales_price) as itemrevenue - ,sum(ss_ext_sales_price)*100/sum(sum(ss_ext_sales_price)) over - (partition by i_class) as revenueratio -from - store_sales - ,item - ,date_dim -where - ss_item_sk = i_item_sk - and i_category in ('Shoes', 'Men', 'Music') - and ss_sold_date_sk = d_date_sk - and d_date between cast('2001-01-05' as date) - and dateadd(day,30,cast('2001-01-05' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio; - --- end template query98.tpl query 6 in stream 5 --- start template query88.tpl query 7 in stream 5 -select /* TPC-DS query88.tpl 0.66 */ * -from - (select count(*) h8_30_to_9 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s1, - (select count(*) h9_to_9_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s2, - (select count(*) h9_30_to_10 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s3, - (select count(*) h10_to_10_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s4, - (select count(*) h10_30_to_11 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s5, - (select count(*) h11_to_11_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s6, - (select count(*) h11_30_to_12 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s7, - (select count(*) h12_to_12_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 12 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s8 -; - --- end template query88.tpl query 7 in stream 5 --- start template query2.tpl query 8 in stream 5 -with /* TPC-DS query2.tpl 0.84 */ wscs as - (select sold_date_sk - ,sales_price - from (select ws_sold_date_sk sold_date_sk - ,ws_ext_sales_price sales_price - from web_sales - union all - select cs_sold_date_sk sold_date_sk - ,cs_ext_sales_price sales_price - from catalog_sales)), - wswscs as - (select d_week_seq, - sum(case when (d_day_name='Sunday') then sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then sales_price else null end) sat_sales - from wscs - ,date_dim - where d_date_sk = sold_date_sk - group by d_week_seq) - select d_week_seq1 - ,round(sun_sales1/sun_sales2,2) - ,round(mon_sales1/mon_sales2,2) - ,round(tue_sales1/tue_sales2,2) - ,round(wed_sales1/wed_sales2,2) - ,round(thu_sales1/thu_sales2,2) - ,round(fri_sales1/fri_sales2,2) - ,round(sat_sales1/sat_sales2,2) - from - (select wswscs.d_week_seq d_week_seq1 - ,sun_sales sun_sales1 - ,mon_sales mon_sales1 - ,tue_sales tue_sales1 - ,wed_sales wed_sales1 - ,thu_sales thu_sales1 - ,fri_sales fri_sales1 - ,sat_sales sat_sales1 - from wswscs,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 2001) y, - (select wswscs.d_week_seq d_week_seq2 - ,sun_sales sun_sales2 - ,mon_sales mon_sales2 - ,tue_sales tue_sales2 - ,wed_sales wed_sales2 - ,thu_sales thu_sales2 - ,fri_sales fri_sales2 - ,sat_sales sat_sales2 - from wswscs - ,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 2001+1) z - where d_week_seq1=d_week_seq2-53 - order by d_week_seq1; - --- end template query2.tpl query 8 in stream 5 --- start template query19.tpl query 9 in stream 5 -select /* TPC-DS query19.tpl 0.8 */ i_brand_id brand_id, i_brand brand, i_manufact_id, i_manufact, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item,customer,customer_address,store - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=15 - and d_moy=12 - and d_year=1998 - and ss_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and substring(ca_zip,1,5) <> substring(s_zip,1,5) - and ss_store_sk = s_store_sk - group by i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact - order by ext_price desc - ,i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact -limit 100 ; - --- end template query19.tpl query 9 in stream 5 --- start template query65.tpl query 10 in stream 5 -select /* TPC-DS query65.tpl 0.71 */ - s_store_name, - i_item_desc, - sc.revenue, - i_current_price, - i_wholesale_cost, - i_brand - from store, item, - (select ss_store_sk, avg(revenue) as ave - from - (select ss_store_sk, ss_item_sk, - sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1221 and 1221+11 - group by ss_store_sk, ss_item_sk) sa - group by ss_store_sk) sb, - (select ss_store_sk, ss_item_sk, sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1221 and 1221+11 - group by ss_store_sk, ss_item_sk) sc - where sb.ss_store_sk = sc.ss_store_sk and - sc.revenue <= 0.1 * sb.ave and - s_store_sk = sc.ss_store_sk and - i_item_sk = sc.ss_item_sk - order by s_store_name, i_item_desc -limit 100; - --- end template query65.tpl query 10 in stream 5 --- start template query3.tpl query 11 in stream 5 -select /* TPC-DS query3.tpl 0.45 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_discount_amt) sum_agg - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manufact_id = 512 - and dt.d_moy=11 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,sum_agg desc - ,brand_id - limit 100; - --- end template query3.tpl query 11 in stream 5 --- start template query79.tpl query 12 in stream 5 -select /* TPC-DS query79.tpl 0.89 */ - c_last_name,c_first_name,substring(s_city,1,30),ss_ticket_number,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,store.s_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (household_demographics.hd_dep_count = 6 or household_demographics.hd_vehicle_count > 4) - and date_dim.d_dow = 1 - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_number_employees between 200 and 295 - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,store.s_city) ms,customer - where ss_customer_sk = c_customer_sk - order by c_last_name,c_first_name,substring(s_city,1,30), profit -limit 100; - --- end template query79.tpl query 12 in stream 5 --- start template query13.tpl query 13 in stream 5 -select /* TPC-DS query13.tpl 0.91 */ avg(ss_quantity) - ,avg(ss_ext_sales_price) - ,avg(ss_ext_wholesale_cost) - ,sum(ss_ext_wholesale_cost) - from store_sales - ,store - ,customer_demographics - ,household_demographics - ,customer_address - ,date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2001 - and((ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'W' - and cd_education_status = '4 yr Degree' - and ss_sales_price between 100.00 and 150.00 - and hd_dep_count = 3 - )or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'D' - and cd_education_status = 'College' - and ss_sales_price between 50.00 and 100.00 - and hd_dep_count = 1 - ) or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'U' - and cd_education_status = '2 yr Degree' - and ss_sales_price between 150.00 and 200.00 - and hd_dep_count = 1 - )) - and((ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('GA', 'CO', 'MT') - and ss_net_profit between 100 and 200 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('ND', 'MI', 'CA') - and ss_net_profit between 150 and 300 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('NE', 'NJ', 'SD') - and ss_net_profit between 50 and 250 - )) -; - --- end template query13.tpl query 13 in stream 5 --- start template query21.tpl query 14 in stream 5 -select /* TPC-DS query21.tpl 0.14 */ * - from(select w_warehouse_name - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('1999-05-12' as date)) - then inv_quantity_on_hand - else 0 end) as inv_before - ,sum(case when (cast(d_date as date) >= cast ('1999-05-12' as date)) - then inv_quantity_on_hand - else 0 end) as inv_after - from inventory - ,warehouse - ,item - ,date_dim - where i_current_price between 0.99 and 1.49 - and i_item_sk = inv_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('1999-05-12' as date)) - and dateadd(day,30,cast ('1999-05-12' as date)) - group by w_warehouse_name, i_item_id) x - where (case when inv_before > 0 - then inv_after / inv_before - else null - end) between 2.0/3.0 and 3.0/2.0 - order by w_warehouse_name - ,i_item_id - limit 100; - --- end template query21.tpl query 14 in stream 5 --- start template query51.tpl query 15 in stream 5 -WITH /* TPC-DS query51.tpl 0.46 */ web_v1 as ( -select - ws_item_sk item_sk, d_date, - sum(sum(ws_sales_price)) - over (partition by ws_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from web_sales - ,date_dim -where ws_sold_date_sk=d_date_sk - and d_month_seq between 1176 and 1176+11 - and ws_item_sk is not NULL -group by ws_item_sk, d_date), -store_v1 as ( -select - ss_item_sk item_sk, d_date, - sum(sum(ss_sales_price)) - over (partition by ss_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from store_sales - ,date_dim -where ss_sold_date_sk=d_date_sk - and d_month_seq between 1176 and 1176+11 - and ss_item_sk is not NULL -group by ss_item_sk, d_date) - select * -from (select item_sk - ,d_date - ,web_sales - ,store_sales - ,max(web_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) web_cumulative - ,max(store_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) store_cumulative - from (select case when web.item_sk is not null then web.item_sk else store.item_sk end item_sk - ,case when web.d_date is not null then web.d_date else store.d_date end d_date - ,web.cume_sales web_sales - ,store.cume_sales store_sales - from web_v1 web full outer join store_v1 store on (web.item_sk = store.item_sk - and web.d_date = store.d_date) - )x )y -where web_cumulative > store_cumulative -order by item_sk - ,d_date -limit 100; - --- end template query51.tpl query 15 in stream 5 --- start template query6.tpl query 16 in stream 5 -select /* TPC-DS query6.tpl 0.58 */ a.ca_state state, count(*) cnt - from customer_address a - ,customer c - ,store_sales s - ,date_dim d - ,item i - where a.ca_address_sk = c.c_current_addr_sk - and c.c_customer_sk = s.ss_customer_sk - and s.ss_sold_date_sk = d.d_date_sk - and s.ss_item_sk = i.i_item_sk - and d.d_month_seq = - (select distinct (d_month_seq) - from date_dim - where d_year = 2002 - and d_moy = 7 ) - and i.i_current_price > 1.2 * - (select avg(j.i_current_price) - from item j - where j.i_category = i.i_category) - group by a.ca_state - having count(*) >= 10 - order by cnt, a.ca_state - limit 100; - --- end template query6.tpl query 16 in stream 5 --- start template query49.tpl query 17 in stream 5 -select /* TPC-DS query49.tpl 0.48 */ channel, item, return_ratio, return_rank, currency_rank from - (select - 'web' as channel - ,web.item - ,web.return_ratio - ,web.return_rank - ,web.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select ws.ws_item_sk as item - ,(cast(sum(coalesce(wr.wr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(wr.wr_return_amt,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - web_sales ws left outer join web_returns wr - on (ws.ws_order_number = wr.wr_order_number and - ws.ws_item_sk = wr.wr_item_sk) - ,date_dim - where - wr.wr_return_amt > 10000 - and ws.ws_net_profit > 1 - and ws.ws_net_paid > 0 - and ws.ws_quantity > 0 - and ws_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 11 - group by ws.ws_item_sk - ) in_web - ) web - where - ( - web.return_rank <= 10 - or - web.currency_rank <= 10 - ) - union - select - 'catalog' as channel - ,catalog.item - ,catalog.return_ratio - ,catalog.return_rank - ,catalog.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select - cs.cs_item_sk as item - ,(cast(sum(coalesce(cr.cr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(cr.cr_return_amount,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - catalog_sales cs left outer join catalog_returns cr - on (cs.cs_order_number = cr.cr_order_number and - cs.cs_item_sk = cr.cr_item_sk) - ,date_dim - where - cr.cr_return_amount > 10000 - and cs.cs_net_profit > 1 - and cs.cs_net_paid > 0 - and cs.cs_quantity > 0 - and cs_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 11 - group by cs.cs_item_sk - ) in_cat - ) catalog - where - ( - catalog.return_rank <= 10 - or - catalog.currency_rank <=10 - ) - union - select - 'store' as channel - ,store.item - ,store.return_ratio - ,store.return_rank - ,store.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select sts.ss_item_sk as item - ,(cast(sum(coalesce(sr.sr_return_quantity,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(sr.sr_return_amt,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - store_sales sts left outer join store_returns sr - on (sts.ss_ticket_number = sr.sr_ticket_number and sts.ss_item_sk = sr.sr_item_sk) - ,date_dim - where - sr.sr_return_amt > 10000 - and sts.ss_net_profit > 1 - and sts.ss_net_paid > 0 - and sts.ss_quantity > 0 - and ss_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 11 - group by sts.ss_item_sk - ) in_store - ) store - where ( - store.return_rank <= 10 - or - store.currency_rank <= 10 - ) - ) - order by 1,4,5,2 - limit 100; - --- end template query49.tpl query 17 in stream 5 --- start template query52.tpl query 18 in stream 5 -select /* TPC-DS query52.tpl 0.59 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_sales_price) ext_price - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=11 - and dt.d_year=1999 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,ext_price desc - ,brand_id -limit 100 ; - --- end template query52.tpl query 18 in stream 5 --- start template query7.tpl query 19 in stream 5 -select /* TPC-DS query7.tpl 0.2 */ i_item_id, - avg(ss_quantity) agg1, - avg(ss_list_price) agg2, - avg(ss_coupon_amt) agg3, - avg(ss_sales_price) agg4 - from store_sales, customer_demographics, date_dim, item, promotion - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_cdemo_sk = cd_demo_sk and - ss_promo_sk = p_promo_sk and - cd_gender = 'M' and - cd_marital_status = 'W' and - cd_education_status = 'Secondary' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 1998 - group by i_item_id - order by i_item_id - limit 100; - --- end template query7.tpl query 19 in stream 5 --- start template query56.tpl query 20 in stream 5 -with /* TPC-DS query56.tpl 0.83 */ ss as ( - select i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where i_item_id in (select - i_item_id -from item -where i_color in ('midnight','lavender','indian')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 1 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - cs as ( - select i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('midnight','lavender','indian')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 1 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - ws as ( - select i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('midnight','lavender','indian')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 1 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id) - select i_item_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by total_sales, - i_item_id - limit 100; - --- end template query56.tpl query 20 in stream 5 --- start template query36a.tpl query 21 in stream 5 -with /* TPC-DS query36a.tpl 0.21 */ results as - (select - sum(ss_net_profit) as ss_net_profit, sum(ss_ext_sales_price) as ss_ext_sales_price, - sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin - ,i_category - ,i_class - ,0 as g_category, 0 as g_class - from - store_sales - ,date_dim d1 - ,item - ,store - where - d1.d_year = 2002 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and s_state in ('MN','FL','OK','NC', - 'TX','NM','SC','GA') - group by i_category,i_class) - , - results_rollup as - (select gross_margin ,i_category ,i_class,0 as t_category, 0 as t_class, 0 as lochierarchy from results - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - i_category, NULL AS i_class, 0 as t_category, 1 as t_class, 1 as lochierarchy from results group by i_category - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - NULL AS i_category ,NULL AS i_class, 1 as t_category, 1 as t_class, 2 as lochierarchy from results) - select - gross_margin ,i_category ,i_class, lochierarchy,rank() over ( - partition by lochierarchy, case when t_class = 0 then i_category end - order by gross_margin asc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then i_category end - ,rank_within_parent - limit 100; - --- end template query36a.tpl query 21 in stream 5 --- start template query77a.tpl query 22 in stream 5 -with /* TPC-DS query77a.tpl 0.78 */ ss as - (select s_store_sk, - sum(ss_ext_sales_price) as sales, - sum(ss_net_profit) as profit - from store_sales, - date_dim, - store - where ss_sold_date_sk = d_date_sk - and d_date between cast('1999-08-27' as date) - and dateadd(day,30,cast('1999-08-27' as date)) - and ss_store_sk = s_store_sk - group by s_store_sk) - , - sr as - (select s_store_sk, - sum(sr_return_amt) as returns, - sum(sr_net_loss) as profit_loss - from store_returns, - date_dim, - store - where sr_returned_date_sk = d_date_sk - and d_date between cast('1999-08-27' as date) - and dateadd(day,30,cast('1999-08-27' as date)) - and sr_store_sk = s_store_sk - group by s_store_sk), - cs as - (select cs_call_center_sk, - sum(cs_ext_sales_price) as sales, - sum(cs_net_profit) as profit - from catalog_sales, - date_dim - where cs_sold_date_sk = d_date_sk - and d_date between cast('1999-08-27' as date) - and dateadd(day,30,cast('1999-08-27' as date)) - group by cs_call_center_sk - ), - cr as - (select cr_call_center_sk, - sum(cr_return_amount) as returns, - sum(cr_net_loss) as profit_loss - from catalog_returns, - date_dim - where cr_returned_date_sk = d_date_sk - and d_date between cast('1999-08-27' as date) - and dateadd(day,30,cast('1999-08-27' as date)) - group by cr_call_center_sk), - ws as - ( select wp_web_page_sk, - sum(ws_ext_sales_price) as sales, - sum(ws_net_profit) as profit - from web_sales, - date_dim, - web_page - where ws_sold_date_sk = d_date_sk - and d_date between cast('1999-08-27' as date) - and dateadd(day,30,cast('1999-08-27' as date)) - and ws_web_page_sk = wp_web_page_sk - group by wp_web_page_sk), - wr as - (select wp_web_page_sk, - sum(wr_return_amt) as returns, - sum(wr_net_loss) as profit_loss - from web_returns, - date_dim, - web_page - where wr_returned_date_sk = d_date_sk - and d_date between cast('1999-08-27' as date) - and dateadd(day,30,cast('1999-08-27' as date)) - and wr_web_page_sk = wp_web_page_sk - group by wp_web_page_sk) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , ss.s_store_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ss left join sr - on ss.s_store_sk = sr.s_store_sk - union all - select 'catalog channel' as channel - , cs_call_center_sk as id - , sales - , returns - , (profit - profit_loss) as profit - from cs - , cr - union all - select 'web channel' as channel - , ws.wp_web_page_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ws left join wr - on ws.wp_web_page_sk = wr.wp_web_page_sk - ) x - group by channel, id ) - - select * - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results -) foo -order by channel, id - limit 100; - --- end template query77a.tpl query 22 in stream 5 --- start template query90.tpl query 23 in stream 5 -select /* TPC-DS query90.tpl 0.40 */ cast(amc as decimal(15,4))/cast(pmc as decimal(15,4)) am_pm_ratio - from ( select count(*) amc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 6 and 6+1 - and household_demographics.hd_dep_count = 0 - and web_page.wp_char_count between 5000 and 5200) at, - ( select count(*) pmc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 20 and 20+1 - and household_demographics.hd_dep_count = 0 - and web_page.wp_char_count between 5000 and 5200) pt - order by am_pm_ratio - limit 100; - --- end template query90.tpl query 23 in stream 5 --- start template query76.tpl query 24 in stream 5 -select /* TPC-DS query76.tpl 0.99 */ channel, col_name, d_year, d_qoy, i_category, COUNT(*) sales_cnt, SUM(ext_sales_price) sales_amt FROM ( - SELECT 'store' as channel, 'ss_cdemo_sk' col_name, d_year, d_qoy, i_category, ss_ext_sales_price ext_sales_price - FROM store_sales, item, date_dim - WHERE ss_cdemo_sk IS NULL - AND ss_sold_date_sk=d_date_sk - AND ss_item_sk=i_item_sk - UNION ALL - SELECT 'web' as channel, 'ws_ship_customer_sk' col_name, d_year, d_qoy, i_category, ws_ext_sales_price ext_sales_price - FROM web_sales, item, date_dim - WHERE ws_ship_customer_sk IS NULL - AND ws_sold_date_sk=d_date_sk - AND ws_item_sk=i_item_sk - UNION ALL - SELECT 'catalog' as channel, 'cs_ship_customer_sk' col_name, d_year, d_qoy, i_category, cs_ext_sales_price ext_sales_price - FROM catalog_sales, item, date_dim - WHERE cs_ship_customer_sk IS NULL - AND cs_sold_date_sk=d_date_sk - AND cs_item_sk=i_item_sk) foo -GROUP BY channel, col_name, d_year, d_qoy, i_category -ORDER BY channel, col_name, d_year, d_qoy, i_category -limit 100; - --- end template query76.tpl query 24 in stream 5 --- start template query58.tpl query 25 in stream 5 -with /* TPC-DS query58.tpl 0.19 */ ss_items as - (select i_item_id item_id - ,sum(ss_ext_sales_price) ss_item_rev - from store_sales - ,item - ,date_dim - where ss_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '1999-07-01')) - and ss_sold_date_sk = d_date_sk - group by i_item_id), - cs_items as - (select i_item_id item_id - ,sum(cs_ext_sales_price) cs_item_rev - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '1999-07-01')) - and cs_sold_date_sk = d_date_sk - group by i_item_id), - ws_items as - (select i_item_id item_id - ,sum(ws_ext_sales_price) ws_item_rev - from web_sales - ,item - ,date_dim - where ws_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq =(select d_week_seq - from date_dim - where d_date = '1999-07-01')) - and ws_sold_date_sk = d_date_sk - group by i_item_id) - select ss_items.item_id - ,ss_item_rev - ,ss_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ss_dev - ,cs_item_rev - ,cs_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 cs_dev - ,ws_item_rev - ,ws_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ws_dev - ,(ss_item_rev+cs_item_rev+ws_item_rev)/3 average - from ss_items,cs_items,ws_items - where ss_items.item_id=cs_items.item_id - and ss_items.item_id=ws_items.item_id - and ss_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - and ss_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and cs_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and cs_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and ws_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and ws_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - order by item_id - ,ss_item_rev - limit 100; - --- end template query58.tpl query 25 in stream 5 --- start template query71.tpl query 26 in stream 5 -select /* TPC-DS query71.tpl 0.72 */ i_brand_id brand_id, i_brand brand,t_hour,t_minute, - sum(ext_price) ext_price - from item, (select ws_ext_sales_price as ext_price, - ws_sold_date_sk as sold_date_sk, - ws_item_sk as sold_item_sk, - ws_sold_time_sk as time_sk - from web_sales,date_dim - where d_date_sk = ws_sold_date_sk - and d_moy=11 - and d_year=2000 - union all - select cs_ext_sales_price as ext_price, - cs_sold_date_sk as sold_date_sk, - cs_item_sk as sold_item_sk, - cs_sold_time_sk as time_sk - from catalog_sales,date_dim - where d_date_sk = cs_sold_date_sk - and d_moy=11 - and d_year=2000 - union all - select ss_ext_sales_price as ext_price, - ss_sold_date_sk as sold_date_sk, - ss_item_sk as sold_item_sk, - ss_sold_time_sk as time_sk - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - and d_moy=11 - and d_year=2000 - ) tmp,time_dim - where - sold_item_sk = i_item_sk - and i_manager_id=1 - and time_sk = t_time_sk - and (t_meal_time = 'breakfast' or t_meal_time = 'dinner') - group by i_brand, i_brand_id,t_hour,t_minute - order by ext_price desc, i_brand_id - ; - --- end template query71.tpl query 26 in stream 5 --- start template query80a.tpl query 27 in stream 5 -with /* TPC-DS query80a.tpl 0.6 */ ssr as - (select s_store_id as store_id, - sum(ss_ext_sales_price) as sales, - sum(coalesce(sr_return_amt, 0)) as returns, - sum(ss_net_profit - coalesce(sr_net_loss, 0)) as profit - from store_sales left outer join store_returns on - (ss_item_sk = sr_item_sk and ss_ticket_number = sr_ticket_number), - date_dim, - store, - item, - promotion - where ss_sold_date_sk = d_date_sk - and d_date between cast('1999-08-03' as date) - and dateadd(day,30,cast('1999-08-03' as date)) - and ss_store_sk = s_store_sk - and ss_item_sk = i_item_sk - and i_current_price > 50 - and ss_promo_sk = p_promo_sk - and p_channel_tv = 'N' - group by s_store_id) - , - csr as - (select cp_catalog_page_id as catalog_page_id, - sum(cs_ext_sales_price) as sales, - sum(coalesce(cr_return_amount, 0)) as returns, - sum(cs_net_profit - coalesce(cr_net_loss, 0)) as profit - from catalog_sales left outer join catalog_returns on - (cs_item_sk = cr_item_sk and cs_order_number = cr_order_number), - date_dim, - catalog_page, - item, - promotion - where cs_sold_date_sk = d_date_sk - and d_date between cast('1999-08-03' as date) - and dateadd(day,30,cast('1999-08-03' as date)) - and cs_catalog_page_sk = cp_catalog_page_sk - and cs_item_sk = i_item_sk - and i_current_price > 50 - and cs_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(ws_ext_sales_price) as sales, - sum(coalesce(wr_return_amt, 0)) as returns, - sum(ws_net_profit - coalesce(wr_net_loss, 0)) as profit - from web_sales left outer join web_returns on - (ws_item_sk = wr_item_sk and ws_order_number = wr_order_number), - date_dim, - web_site, - item, - promotion - where ws_sold_date_sk = d_date_sk - and d_date between cast('1999-08-03' as date) - and dateadd(day,30,cast('1999-08-03' as date)) - and ws_web_site_sk = web_site_sk - and ws_item_sk = i_item_sk - and i_current_price > 50 - and ws_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by web_site_id) -, -results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || store_id as id - , sales - , returns - , profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || catalog_page_id as id - , sales - , returns - , profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , profit - from wsr - ) x - group by channel, id) - - select channel - , id - , sales - , returns - , profit - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results - ) foo - order by channel, id - limit 100; - --- end template query80a.tpl query 27 in stream 5 --- start template query69.tpl query 28 in stream 5 -select /* TPC-DS query69.tpl 0.28 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_state in ('NM','IN','KS') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 2 and 2+2) and - (not exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 2 and 2+2) and - not exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 2 and 2+2)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - limit 100; - --- end template query69.tpl query 28 in stream 5 --- start template query54.tpl query 29 in stream 5 -with /* TPC-DS query54.tpl 0.81 */ my_customers as ( - select distinct c_customer_sk - , c_current_addr_sk - from - ( select cs_sold_date_sk sold_date_sk, - cs_bill_customer_sk customer_sk, - cs_item_sk item_sk - from catalog_sales - union all - select ws_sold_date_sk sold_date_sk, - ws_bill_customer_sk customer_sk, - ws_item_sk item_sk - from web_sales - ) cs_or_ws_sales, - item, - date_dim, - customer - where sold_date_sk = d_date_sk - and item_sk = i_item_sk - and i_category = 'Jewelry' - and i_class = 'costume' - and c_customer_sk = cs_or_ws_sales.customer_sk - and d_moy = 4 - and d_year = 2000 - ) - , my_revenue as ( - select c_customer_sk, - sum(ss_ext_sales_price) as revenue - from my_customers, - store_sales, - customer_address, - store, - date_dim - where c_current_addr_sk = ca_address_sk - and ca_county = s_county - and ca_state = s_state - and ss_sold_date_sk = d_date_sk - and c_customer_sk = ss_customer_sk - and d_month_seq between (select distinct d_month_seq+1 - from date_dim where d_year = 2000 and d_moy = 4) - and (select distinct d_month_seq+3 - from date_dim where d_year = 2000 and d_moy = 4) - group by c_customer_sk - ) - , segments as - (select cast((revenue/50) as bigint) as segment - from my_revenue - ) - select segment, count(*) as num_customers, segment*50 as segment_base - from segments - group by segment - order by segment, num_customers - limit 100; - --- end template query54.tpl query 29 in stream 5 --- start template query92.tpl query 30 in stream 5 -select /* TPC-DS query92.tpl 0.44 */ - sum(ws_ext_discount_amt) as "Excess Discount Amount" -from - web_sales - ,item - ,date_dim -where -i_manufact_id = 795 -and i_item_sk = ws_item_sk -and d_date between '1999-01-10' and - dateadd(day,90,cast('1999-01-10' as date)) -and d_date_sk = ws_sold_date_sk -and ws_ext_discount_amt - > ( - SELECT - 1.3 * avg(ws_ext_discount_amt) - FROM - web_sales - ,date_dim - WHERE - ws_item_sk = i_item_sk - and d_date between '1999-01-10' and - dateadd(day,90,cast('1999-01-10' as date)) - and d_date_sk = ws_sold_date_sk - ) -order by sum(ws_ext_discount_amt) -limit 100; - --- end template query92.tpl query 30 in stream 5 --- start template query61.tpl query 31 in stream 5 -select /* TPC-DS query61.tpl 0.97 */ promotions,total,cast(promotions as decimal(16,4))/cast(total as decimal(16,4))*100 -from - (select sum(ss_ext_sales_price) promotions - from store_sales - ,store - ,promotion - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_promo_sk = p_promo_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -6 - and i_category = 'Electronics' - and (p_channel_dmail = 'Y' or p_channel_email = 'Y' or p_channel_tv = 'Y') - and s_gmt_offset = -6 - and d_year = 1999 - and d_moy = 11) promotional_sales, - (select sum(ss_ext_sales_price) total - from store_sales - ,store - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -6 - and i_category = 'Electronics' - and s_gmt_offset = -6 - and d_year = 1999 - and d_moy = 11) all_sales -order by promotions, total -limit 100; - --- end template query61.tpl query 31 in stream 5 --- start template query53.tpl query 32 in stream 5 -select /* TPC-DS query53.tpl 0.88 */ * from -(select i_manufact_id, -sum(ss_sales_price) sum_sales, -avg(sum(ss_sales_price)) over (partition by i_manufact_id) avg_quarterly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and -ss_sold_date_sk = d_date_sk and -ss_store_sk = s_store_sk and -d_month_seq in (1176,1176+1,1176+2,1176+3,1176+4,1176+5,1176+6,1176+7,1176+8,1176+9,1176+10,1176+11) and -((i_category in ('Books','Children','Electronics') and -i_class in ('personal','portable','reference','self-help') and -i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) -or(i_category in ('Women','Music','Men') and -i_class in ('accessories','classical','fragrances','pants') and -i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manufact_id, d_qoy ) tmp1 -where case when avg_quarterly_sales > 0 - then abs (sum_sales - avg_quarterly_sales)/ avg_quarterly_sales - else null end > 0.1 -order by avg_quarterly_sales, - sum_sales, - i_manufact_id -limit 100; - --- end template query53.tpl query 32 in stream 5 --- start template query87.tpl query 33 in stream 5 -select /* TPC-DS query87.tpl 0.77 */ count(*) -from ((select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1179 and 1179+11) - except - (select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1179 and 1179+11) - except - (select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1179 and 1179+11) -) cool_cust -; - --- end template query87.tpl query 33 in stream 5 --- start template query68.tpl query 34 in stream 5 -select /* TPC-DS query68.tpl 0.95 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,extended_price - ,extended_tax - ,list_price - from (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_ext_sales_price) extended_price - ,sum(ss_ext_list_price) list_price - ,sum(ss_ext_tax) extended_tax - from store_sales - ,date_dim - ,store - ,household_demographics - ,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_dep_count = 5 or - household_demographics.hd_vehicle_count= 3) - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_city in ('Greenwood','Franklin') - group by ss_ticket_number - ,ss_customer_sk - ,ss_addr_sk,ca_city) dn - ,customer - ,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,ss_ticket_number - limit 100; - --- end template query68.tpl query 34 in stream 5 --- start template query85.tpl query 35 in stream 5 -select /* TPC-DS query85.tpl 0.33 */ substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) - from web_sales, web_returns, web_page, customer_demographics cd1, - customer_demographics cd2, customer_address, date_dim, reason - where ws_web_page_sk = wp_web_page_sk - and ws_item_sk = wr_item_sk - and ws_order_number = wr_order_number - and ws_sold_date_sk = d_date_sk and d_year = 2000 - and cd1.cd_demo_sk = wr_refunded_cdemo_sk - and cd2.cd_demo_sk = wr_returning_cdemo_sk - and ca_address_sk = wr_refunded_addr_sk - and r_reason_sk = wr_reason_sk - and - ( - ( - cd1.cd_marital_status = 'W' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Unknown' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 100.00 and 150.00 - ) - or - ( - cd1.cd_marital_status = 'U' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Primary' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 50.00 and 100.00 - ) - or - ( - cd1.cd_marital_status = 'S' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = '2 yr Degree' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ca_country = 'United States' - and - ca_state in ('KS', 'OH', 'VA') - and ws_net_profit between 100 and 200 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('FL', 'TX', 'NJ') - and ws_net_profit between 150 and 300 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('IL', 'PA', 'NC') - and ws_net_profit between 50 and 250 - ) - ) -group by r_reason_desc -order by substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) -limit 100; - --- end template query85.tpl query 35 in stream 5 --- start template query28.tpl query 36 in stream 5 -select /* TPC-DS query28.tpl 0.36 */ * -from (select avg(ss_list_price) B1_LP - ,count(ss_list_price) B1_CNT - ,count(distinct ss_list_price) B1_CNTD - from store_sales - where ss_quantity between 0 and 5 - and (ss_list_price between 18 and 18+10 - or ss_coupon_amt between 3819 and 3819+1000 - or ss_wholesale_cost between 49 and 49+20)) B1, - (select avg(ss_list_price) B2_LP - ,count(ss_list_price) B2_CNT - ,count(distinct ss_list_price) B2_CNTD - from store_sales - where ss_quantity between 6 and 10 - and (ss_list_price between 6 and 6+10 - or ss_coupon_amt between 16750 and 16750+1000 - or ss_wholesale_cost between 75 and 75+20)) B2, - (select avg(ss_list_price) B3_LP - ,count(ss_list_price) B3_CNT - ,count(distinct ss_list_price) B3_CNTD - from store_sales - where ss_quantity between 11 and 15 - and (ss_list_price between 150 and 150+10 - or ss_coupon_amt between 15607 and 15607+1000 - or ss_wholesale_cost between 69 and 69+20)) B3, - (select avg(ss_list_price) B4_LP - ,count(ss_list_price) B4_CNT - ,count(distinct ss_list_price) B4_CNTD - from store_sales - where ss_quantity between 16 and 20 - and (ss_list_price between 12 and 12+10 - or ss_coupon_amt between 2928 and 2928+1000 - or ss_wholesale_cost between 48 and 48+20)) B4, - (select avg(ss_list_price) B5_LP - ,count(ss_list_price) B5_CNT - ,count(distinct ss_list_price) B5_CNTD - from store_sales - where ss_quantity between 21 and 25 - and (ss_list_price between 30 and 30+10 - or ss_coupon_amt between 10215 and 10215+1000 - or ss_wholesale_cost between 11 and 11+20)) B5, - (select avg(ss_list_price) B6_LP - ,count(ss_list_price) B6_CNT - ,count(distinct ss_list_price) B6_CNTD - from store_sales - where ss_quantity between 26 and 30 - and (ss_list_price between 117 and 117+10 - or ss_coupon_amt between 1523 and 1523+1000 - or ss_wholesale_cost between 61 and 61+20)) B6 -limit 100; - --- end template query28.tpl query 36 in stream 5 --- start template query42.tpl query 37 in stream 5 -select /* TPC-DS query42.tpl 0.61 */ dt.d_year - ,item.i_category_id - ,item.i_category - ,sum(ss_ext_sales_price) - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=12 - and dt.d_year=2001 - group by dt.d_year - ,item.i_category_id - ,item.i_category - order by sum(ss_ext_sales_price) desc,dt.d_year - ,item.i_category_id - ,item.i_category -limit 100 ; - --- end template query42.tpl query 37 in stream 5 --- start template query67a.tpl query 38 in stream 5 -with /* TPC-DS query67a.tpl 0.35 */ results as -( select i_category ,i_class ,i_brand ,i_product_name ,d_year ,d_qoy ,d_moy ,s_store_id - ,sum(coalesce(ss_sales_price*ss_quantity,0)) sumsales - from store_sales ,date_dim ,store ,item - where ss_sold_date_sk=d_date_sk - and ss_item_sk=i_item_sk - and ss_store_sk = s_store_sk - and d_month_seq between 1195 and 1195 + 11 - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy,s_store_id) - , - results_rollup as - (select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, s_store_id, sumsales - from results - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy - union all - select i_category, i_class, i_brand, i_product_name, d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year - union all - select i_category, i_class, i_brand, i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name - union all - select i_category, i_class, i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand - union all - select i_category, i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class - union all - select i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category - union all - select null i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results) - - select * -from (select i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rank() over (partition by i_category order by sumsales desc) rk - from results_rollup) dw2 -where rk <= 100 -order by i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rk -limit 100; - --- end template query67a.tpl query 38 in stream 5 --- start template query50.tpl query 39 in stream 5 -select /* TPC-DS query50.tpl 0.60 */ - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 30) and - (sr_returned_date_sk - ss_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 60) and - (sr_returned_date_sk - ss_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 90) and - (sr_returned_date_sk - ss_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - store_sales - ,store_returns - ,store - ,date_dim d1 - ,date_dim d2 -where - d2.d_year = 1998 -and d2.d_moy = 10 -and ss_ticket_number = sr_ticket_number -and ss_item_sk = sr_item_sk -and ss_sold_date_sk = d1.d_date_sk -and sr_returned_date_sk = d2.d_date_sk -and ss_customer_sk = sr_customer_sk -and ss_store_sk = s_store_sk -group by - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -order by s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -limit 100; - --- end template query50.tpl query 39 in stream 5 --- start template query30.tpl query 40 in stream 5 -with /* TPC-DS query30.tpl 0.75 */ customer_total_return as - (select wr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(wr_return_amt) as ctr_total_return - from web_returns - ,date_dim - ,customer_address - where wr_returned_date_sk = d_date_sk - and d_year =1999 - and wr_returning_addr_sk = ca_address_sk - group by wr_returning_customer_sk - ,ca_state) - select c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'TX' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return -limit 100; - --- end template query30.tpl query 40 in stream 5 --- start template query48.tpl query 41 in stream 5 -select /* TPC-DS query48.tpl 0.74 */ sum (ss_quantity) - from store_sales, store, customer_demographics, customer_address, date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 1999 - and - ( - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'U' - and - cd_education_status = 'College' - and - ss_sales_price between 100.00 and 150.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'D' - and - cd_education_status = 'Advanced Degree' - and - ss_sales_price between 50.00 and 100.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'S' - and - cd_education_status = '4 yr Degree' - and - ss_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('NE', 'AK', 'NJ') - and ss_net_profit between 0 and 2000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('CO', 'GA', 'OK') - and ss_net_profit between 150 and 3000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('IL', 'ND', 'IA') - and ss_net_profit between 50 and 25000 - ) - ) -; - --- end template query48.tpl query 41 in stream 5 --- start template query22a.tpl query 42 in stream 5 -with /* TPC-DS query22a.tpl 0.55 */ results as -(select i_product_name - ,i_brand - ,i_class - ,i_category - ,avg(inv_quantity_on_hand) qoh - from inventory - ,date_dim - ,item --- ,warehouse - where inv_date_sk=d_date_sk - and inv_item_sk=i_item_sk --- and inv_warehouse_sk = w_warehouse_sk - and d_month_seq between 1179 and 1179 + 11 - group by i_product_name,i_brand,i_class,i_category), -results_rollup as -(select i_product_name, i_brand, i_class, i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class,i_category -union all -select i_product_name, i_brand, i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class -union all -select i_product_name, i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand -union all -select i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name -union all -select null i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results) - select i_product_name, i_brand, i_class, i_category,qoh - from results_rollup - order by qoh, i_product_name, i_brand, i_class, i_category -limit 100; - --- end template query22a.tpl query 42 in stream 5 --- start template query11.tpl query 43 in stream 5 -with /* TPC-DS query11.tpl 0.51 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ss_ext_list_price-ss_ext_discount_amt) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ws_ext_list_price-ws_ext_discount_amt) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_preferred_cust_flag - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 1999 - and t_s_secyear.dyear = 1999+1 - and t_w_firstyear.dyear = 1999 - and t_w_secyear.dyear = 1999+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else 0.0 end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else 0.0 end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_preferred_cust_flag -limit 100; - --- end template query11.tpl query 43 in stream 5 --- start template query94.tpl query 44 in stream 5 -select /* TPC-DS query94.tpl 0.17 */ - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '1999-5-01' and - dateadd(day,60,cast('1999-5-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'IN' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and exists (select * - from web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) -and not exists(select * - from web_returns wr1 - where ws1.ws_order_number = wr1.wr_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query94.tpl query 44 in stream 5 --- start template query93.tpl query 45 in stream 5 -select /* TPC-DS query93.tpl 0.52 */ ss_customer_sk - ,sum(act_sales) sumsales - from (select ss_item_sk - ,ss_ticket_number - ,ss_customer_sk - ,case when sr_return_quantity is not null then (ss_quantity-sr_return_quantity)*ss_sales_price - else (ss_quantity*ss_sales_price) end act_sales - from store_sales left outer join store_returns on (sr_item_sk = ss_item_sk - and sr_ticket_number = ss_ticket_number) - ,reason - where sr_reason_sk = r_reason_sk - and r_reason_desc = 'Parts missing') t - group by ss_customer_sk - order by sumsales, ss_customer_sk -limit 100; - --- end template query93.tpl query 45 in stream 5 --- start template query18a.tpl query 46 in stream 5 -with /* TPC-DS query18a.tpl 0.90 */ results as - (select i_item_id, - ca_country, - ca_state, - ca_county, - cast(cs_quantity as decimal(12,2)) agg1, - cast(cs_list_price as decimal(12,2)) agg2, - cast(cs_coupon_amt as decimal(12,2)) agg3, - cast(cs_sales_price as decimal(12,2)) agg4, - cast(cs_net_profit as decimal(12,2)) agg5, - cast(c_birth_year as decimal(12,2)) agg6, - cast(cd1.cd_dep_count as decimal(12,2)) agg7 - from catalog_sales, customer_demographics cd1, customer_demographics cd2, customer, customer_address, date_dim, item - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd1.cd_demo_sk and - cs_bill_customer_sk = c_customer_sk and - cd1.cd_gender = 'M' and - cd1.cd_education_status = 'College' and - c_current_cdemo_sk = cd2.cd_demo_sk and - c_current_addr_sk = ca_address_sk and - c_birth_month in (2,1,8,9,6,5) and - d_year = 2002 and - ca_state in ('KS','OK','GA','VA','MD','NJ','CO') - ) - select i_item_id, ca_country, ca_state, ca_county, agg1, agg2, agg3, agg4, agg5, agg6, agg7 - from ( - select i_item_id, ca_country, ca_state, ca_county, avg(agg1) agg1, - avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state, ca_county - union all - select i_item_id, ca_country, ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state - union all - select i_item_id, ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country - union all - select i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - ) foo - order by ca_country, ca_state, ca_county, i_item_id - limit 100; - --- end template query18a.tpl query 46 in stream 5 --- start template query33.tpl query 47 in stream 5 -with /* TPC-DS query33.tpl 0.22 */ ss as ( - select - i_manufact_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Sports')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 2 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id), - cs as ( - select - i_manufact_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Sports')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 2 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id), - ws as ( - select - i_manufact_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Sports')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 2 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id) - select i_manufact_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_manufact_id - order by total_sales -limit 100; - --- end template query33.tpl query 47 in stream 5 --- start template query63.tpl query 48 in stream 5 -select /* TPC-DS query63.tpl 0.27 */ * -from (select i_manager_id - ,sum(ss_sales_price) sum_sales - ,avg(sum(ss_sales_price)) over (partition by i_manager_id) avg_monthly_sales - from item - ,store_sales - ,date_dim - ,store - where ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and d_month_seq in (1197,1197+1,1197+2,1197+3,1197+4,1197+5,1197+6,1197+7,1197+8,1197+9,1197+10,1197+11) - and (( i_category in ('Books','Children','Electronics') - and i_class in ('personal','portable','reference','self-help') - and i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) - or( i_category in ('Women','Music','Men') - and i_class in ('accessories','classical','fragrances','pants') - and i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manager_id, d_moy) tmp1 -where case when avg_monthly_sales > 0 then abs (sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 -order by i_manager_id - ,avg_monthly_sales - ,sum_sales -limit 100; - --- end template query63.tpl query 48 in stream 5 --- start template query8.tpl query 49 in stream 5 -select /* TPC-DS query8.tpl 0.63 */ s_store_name - ,sum(ss_net_profit) - from store_sales - ,date_dim - ,store, - (select ca_zip - from ( - SELECT substring(ca_zip,1,5) ca_zip - FROM customer_address - WHERE substring(ca_zip,1,5) IN ( - '63203','71331','13312','38578','83236','32747', - '79123','23805','59197','24764','88427', - '34463','50701','50236','54271','37502', - '18649','60488','26105','48311','66652', - '83326','52950','56375','94925','84697', - '49439','32955','32073','48476','40093', - '28543','29433','67239','90758','72459', - '38784','78236','77430','72249','31027', - '45394','29964','46370','26521','67511', - '98350','64754','83555','27051','42167', - '47359','11989','39530','18627','50001', - '13376','71749','83732','19724','81804', - '16991','32065','49229','76822','17601', - '64958','14745','70329','71592','24780', - '87435','27323','64184','22493','46067', - '80570','87017','62206','23492','52133', - '51317','91449','86897','48960','24251', - '63923','44774','96818','32089','79669', - '73532','10951','25784','82987','49359', - '63144','73498','48514','91102','72867', - '52816','28542','78879','15660','74252', - '56571','44712','34925','30319','22610', - '55085','52242','11269','63728','34592', - '66963','26064','20843','30903','84922', - '61585','84698','54621','90916','72675', - '66124','53368','76963','48704','78222', - '77349','16430','45716','66698','65332', - '82820','66244','76466','49968','77036', - '50376','82490','15638','26587','60885', - '89660','12567','92812','69592','30384', - '90828','66004','12267','64007','51193', - '23668','30887','74302','40270','57636', - '45816','53839','30268','76842','93894', - '57988','89881','33163','25687','26817', - '32256','95118','97475','47078','19312', - '30484','88714','80960','69490','66815', - '43314','43556','94851','40404','99567', - '81134','70498','68450','44684','39613', - '33213','94025','63669','64877','65774', - '79665','86181','53683','21184','73748', - '27391','46631','82504','24132','95334', - '87954','45581','24652','28992','63075', - '95454','38640','22403','66454','43633', - '62532','28187','37719','23640','39408', - '47328','90394','17595','15599','86119', - '56562','35527','89996','54637','58047', - '48646','96039','78682','51813','18107', - '73682','96206','88554','40536','10180', - '81138','12822','30766','94033','98305', - '78857','19113','13598','82642','68967', - '49489','33005','65081','32079','64781', - '71181','93407','77241','27934','34440', - '14902','22238','24095','69103','27279', - '75078','52208','90621','78276','60345', - '66401','19438','16363','56239','57931', - '45933','25026','70117','16284','88901', - '94289','65013','15563','98049','58545', - '79372','67399','83731','95813','48095', - '44913','13604','37352','14599','34830', - '40824','31536','64443','73331','74811', - '69337','26318','86679','79528','64592', - '75465','25638','15921','70512','84021', - '18466','51524','53236','25562','48116', - '32449','90041','18826','10015','60575', - '53508','82124','82399','19468','50998', - '29083','53265','45244','28716','22208', - '92873','93202','20115','11103','57462', - '55439','89450','75248','33109','12104', - '48383','43936','49557','34777','62482', - '84615','52341','83784','91309','80453', - '40512','81228','22192','31230','48498', - '23638','26382','24618','58811','13196', - '46337','97157','70709','82866','11286', - '87145','57263','12243','44325','52863', - '58968','53447','66504','81290','24832', - '50393','19659','91355','46492','21434', - '37947','18732','66208','56940','16817', - '23717','28237','66023','18805','94679', - '64290','34046','32301','10283','41562', - '11808','86956','41030','73628') - intersect - select ca_zip - from (SELECT substring(ca_zip,1,5) ca_zip,count(*) cnt - FROM customer_address, customer - WHERE ca_address_sk = c_current_addr_sk and - c_preferred_cust_flag='Y' - group by ca_zip - having count(*) > 10)A1)A2) V1 - where ss_store_sk = s_store_sk - and ss_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 2001 - and (substring(s_zip,1,2) = substring(V1.ca_zip,1,2)) - group by s_store_name - order by s_store_name - limit 100; - --- end template query8.tpl query 49 in stream 5 --- start template query97.tpl query 50 in stream 5 -with /* TPC-DS query97.tpl 0.38 */ ssci as ( -select ss_customer_sk customer_sk - ,ss_item_sk item_sk -from store_sales,date_dim -where ss_sold_date_sk = d_date_sk - and d_month_seq between 1221 and 1221 + 11 -group by ss_customer_sk - ,ss_item_sk), -csci as( - select cs_bill_customer_sk customer_sk - ,cs_item_sk item_sk -from catalog_sales,date_dim -where cs_sold_date_sk = d_date_sk - and d_month_seq between 1221 and 1221 + 11 -group by cs_bill_customer_sk - ,cs_item_sk) - select sum(case when ssci.customer_sk is not null and csci.customer_sk is null then 1 else 0 end) store_only - ,sum(case when ssci.customer_sk is null and csci.customer_sk is not null then 1 else 0 end) catalog_only - ,sum(case when ssci.customer_sk is not null and csci.customer_sk is not null then 1 else 0 end) store_and_catalog -from ssci full outer join csci on (ssci.customer_sk=csci.customer_sk - and ssci.item_sk = csci.item_sk) -limit 100; - --- end template query97.tpl query 50 in stream 5 --- start template query45.tpl query 51 in stream 5 -select /* TPC-DS query45.tpl 0.18 */ ca_zip, ca_state, sum(ws_sales_price) - from web_sales, customer, customer_address, date_dim, item - where ws_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ws_item_sk = i_item_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', '85392', '85460', '80348', '81792') - or - i_item_id in (select i_item_id - from item - where i_item_sk in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29) - ) - ) - and ws_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 1999 - group by ca_zip, ca_state - order by ca_zip, ca_state - limit 100; - --- end template query45.tpl query 51 in stream 5 --- start template query62.tpl query 52 in stream 5 -select /* TPC-DS query62.tpl 0.24 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 30) and - (ws_ship_date_sk - ws_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 60) and - (ws_ship_date_sk - ws_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 90) and - (ws_ship_date_sk - ws_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - web_sales - ,warehouse - ,ship_mode - ,web_site - ,date_dim -where - d_month_seq between 1215 and 1215 + 11 -and ws_ship_date_sk = d_date_sk -and ws_warehouse_sk = w_warehouse_sk -and ws_ship_mode_sk = sm_ship_mode_sk -and ws_web_site_sk = web_site_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -limit 100; - --- end template query62.tpl query 52 in stream 5 --- start template query81.tpl query 53 in stream 5 -with /* TPC-DS query81.tpl 0.37 */ customer_total_return as - (select cr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(cr_return_amt_inc_tax) as ctr_total_return - from catalog_returns - ,date_dim - ,customer_address - where cr_returned_date_sk = d_date_sk - and d_year =2002 - and cr_returning_addr_sk = ca_address_sk - group by cr_returning_customer_sk - ,ca_state ) - select c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'MI' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - limit 100; - --- end template query81.tpl query 53 in stream 5 --- start template query35a.tpl query 54 in stream 5 -select /* TPC-DS query35a.tpl 0.47 */ - ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - count(*) cnt1, - max(cd_dep_count), - avg(cd_dep_count), - max(cd_dep_count), - cd_dep_employed_count, - count(*) cnt2, - max(cd_dep_employed_count), - avg(cd_dep_employed_count), - max(cd_dep_employed_count), - cd_dep_college_count, - count(*) cnt3, - max(cd_dep_college_count), - avg(cd_dep_college_count), - max(cd_dep_college_count) - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2002 and - d_qoy < 4) and - exists (select * from - (select ws_bill_customer_sk customsk - from web_sales,date_dim - where - ws_sold_date_sk = d_date_sk and - d_year = 2002 and - d_qoy < 4 - union all - select cs_ship_customer_sk customsk - from catalog_sales,date_dim - where - cs_sold_date_sk = d_date_sk and - d_year = 2002 and - d_qoy < 4)x - where x.customsk = c.c_customer_sk) - group by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - limit 100; - --- end template query35a.tpl query 54 in stream 5 --- start template query78.tpl query 55 in stream 5 -with /* TPC-DS query78.tpl 0.10 */ ws as - (select d_year AS ws_sold_year, ws_item_sk, - ws_bill_customer_sk ws_customer_sk, - sum(ws_quantity) ws_qty, - sum(ws_wholesale_cost) ws_wc, - sum(ws_sales_price) ws_sp - from web_sales - left join web_returns on wr_order_number=ws_order_number and ws_item_sk=wr_item_sk - join date_dim on ws_sold_date_sk = d_date_sk - where wr_order_number is null - group by d_year, ws_item_sk, ws_bill_customer_sk - ), -cs as - (select d_year AS cs_sold_year, cs_item_sk, - cs_bill_customer_sk cs_customer_sk, - sum(cs_quantity) cs_qty, - sum(cs_wholesale_cost) cs_wc, - sum(cs_sales_price) cs_sp - from catalog_sales - left join catalog_returns on cr_order_number=cs_order_number and cs_item_sk=cr_item_sk - join date_dim on cs_sold_date_sk = d_date_sk - where cr_order_number is null - group by d_year, cs_item_sk, cs_bill_customer_sk - ), -ss as - (select d_year AS ss_sold_year, ss_item_sk, - ss_customer_sk, - sum(ss_quantity) ss_qty, - sum(ss_wholesale_cost) ss_wc, - sum(ss_sales_price) ss_sp - from store_sales - left join store_returns on sr_ticket_number=ss_ticket_number and ss_item_sk=sr_item_sk - join date_dim on ss_sold_date_sk = d_date_sk - where sr_ticket_number is null - group by d_year, ss_item_sk, ss_customer_sk - ) - select -ss_sold_year, -round(ss_qty/(coalesce(ws_qty,0)+coalesce(cs_qty,0)),2) ratio, -ss_qty store_qty, ss_wc store_wholesale_cost, ss_sp store_sales_price, -coalesce(ws_qty,0)+coalesce(cs_qty,0) other_chan_qty, -coalesce(ws_wc,0)+coalesce(cs_wc,0) other_chan_wholesale_cost, -coalesce(ws_sp,0)+coalesce(cs_sp,0) other_chan_sales_price -from ss -left join ws on (ws_sold_year=ss_sold_year and ws_item_sk=ss_item_sk and ws_customer_sk=ss_customer_sk) -left join cs on (cs_sold_year=ss_sold_year and cs_item_sk=ss_item_sk and cs_customer_sk=ss_customer_sk) -where (coalesce(ws_qty,0)>0 or coalesce(cs_qty, 0)>0) and ss_sold_year=1998 -order by - ss_sold_year, - ss_qty desc, ss_wc desc, ss_sp desc, - other_chan_qty, - other_chan_wholesale_cost, - other_chan_sales_price, - ratio -limit 100; - --- end template query78.tpl query 55 in stream 5 --- start template query57.tpl query 56 in stream 5 -with /* TPC-DS query57.tpl 0.70 */ v1 as( - select i_category, i_brand, - cc_name, - d_year, d_moy, - sum(cs_sales_price) sum_sales, - avg(sum(cs_sales_price)) over - (partition by i_category, i_brand, - cc_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - cc_name - order by d_year, d_moy) rn - from item, catalog_sales, date_dim, call_center - where cs_item_sk = i_item_sk and - cs_sold_date_sk = d_date_sk and - cc_call_center_sk= cs_call_center_sk and - ( - d_year = 2001 or - ( d_year = 2001-1 and d_moy =12) or - ( d_year = 2001+1 and d_moy =1) - ) - group by i_category, i_brand, - cc_name , d_year, d_moy), - v2 as( - select v1.i_category, v1.i_brand, v1.cc_name - ,v1.d_year, v1.d_moy - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1. cc_name = v1_lag. cc_name and - v1. cc_name = v1_lead. cc_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 2001 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, nsum - limit 100; - --- end template query57.tpl query 56 in stream 5 --- start template query46.tpl query 57 in stream 5 -select /* TPC-DS query46.tpl 0.23 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and (household_demographics.hd_dep_count = 9 or - household_demographics.hd_vehicle_count= 3) - and date_dim.d_dow in (6,0) - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_city in ('Adamsville','Westville','Harrisville','Riverdale','Troy') - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,ca_city) dn,customer,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - limit 100; - --- end template query46.tpl query 57 in stream 5 --- start template query32.tpl query 58 in stream 5 -select /* TPC-DS query32.tpl 0.7 */ sum(cs_ext_discount_amt) as "excess discount amount" -from - catalog_sales - ,item - ,date_dim -where -i_manufact_id = 736 -and i_item_sk = cs_item_sk -and d_date between '2001-02-21' and - dateadd(day,90,cast('2001-02-21' as date)) -and d_date_sk = cs_sold_date_sk -and cs_ext_discount_amt - > ( - select - 1.3 * avg(cs_ext_discount_amt) - from - catalog_sales - ,date_dim - where - cs_item_sk = i_item_sk - and d_date between '2001-02-21' and - dateadd(day,90,cast('2001-02-21' as date)) - and d_date_sk = cs_sold_date_sk - ) -limit 100; - --- end template query32.tpl query 58 in stream 5 --- start template query24.tpl query 59 in stream 5 -with /* TPC-DS query24.tpl 0.92 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_net_paid) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip -and s_market_id=8 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'snow' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; -with /* TPC-DS query24.tpl 0.92 part2 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_net_paid) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip - and s_market_id = 8 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'azure' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; - --- end template query24.tpl query 59 in stream 5 --- start template query38.tpl query 60 in stream 5 -select /* TPC-DS query38.tpl 0.54 */ count(*) from ( - select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1220 and 1220 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1220 and 1220 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1220 and 1220 + 11 -) hot_cust -limit 100; - --- end template query38.tpl query 60 in stream 5 --- start template query55.tpl query 61 in stream 5 -select /* TPC-DS query55.tpl 0.82 */ i_brand_id brand_id, i_brand brand, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=59 - and d_moy=11 - and d_year=2000 - group by i_brand, i_brand_id - order by ext_price desc, i_brand_id -limit 100 ; - --- end template query55.tpl query 61 in stream 5 --- start template query74.tpl query 62 in stream 5 -with /* TPC-DS query74.tpl 0.76 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,avg(ss_net_paid) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (2000,2000+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,avg(ws_net_paid) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - and d_year in (2000,2000+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - ) - select - t_s_secyear.customer_id, t_s_secyear.customer_first_name, t_s_secyear.customer_last_name - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.year = 2000 - and t_s_secyear.year = 2000+1 - and t_w_firstyear.year = 2000 - and t_w_secyear.year = 2000+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - order by 1,3,2 -limit 100; - --- end template query74.tpl query 62 in stream 5 --- start template query84.tpl query 63 in stream 5 -select /* TPC-DS query84.tpl 0.80 */ c_customer_id as customer_id - , coalesce(c_last_name,'') || ', ' || coalesce(c_first_name,'') as customername - from customer - ,customer_address - ,customer_demographics - ,household_demographics - ,income_band - ,store_returns - where ca_city = 'Clinton' - and c_current_addr_sk = ca_address_sk - and ib_lower_bound >= 42986 - and ib_upper_bound <= 42986 + 50000 - and ib_income_band_sk = hd_income_band_sk - and cd_demo_sk = c_current_cdemo_sk - and hd_demo_sk = c_current_hdemo_sk - and sr_cdemo_sk = cd_demo_sk - order by c_customer_id - limit 100; - --- end template query84.tpl query 63 in stream 5 --- start template query89.tpl query 64 in stream 5 -select /* TPC-DS query89.tpl 0.56 */ * -from( -select i_category, i_class, i_brand, - s_store_name, s_company_name, - d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, s_store_name, s_company_name) - avg_monthly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - d_year in (2001) and - ((i_category in ('Shoes','Home','Books') and - i_class in ('womens','tables','business') - ) - or (i_category in ('Children','Sports','Men') and - i_class in ('infants','golf','pants') - )) -group by i_category, i_class, i_brand, - s_store_name, s_company_name, d_moy) tmp1 -where case when (avg_monthly_sales <> 0) then (abs(sum_sales - avg_monthly_sales) / avg_monthly_sales) else null end > 0.1 -order by sum_sales - avg_monthly_sales, s_store_name -limit 100; - --- end template query89.tpl query 64 in stream 5 --- start template query83.tpl query 65 in stream 5 -with /* TPC-DS query83.tpl 0.96 */ sr_items as - (select i_item_id item_id, - sum(sr_return_quantity) sr_item_qty - from store_returns, - item, - date_dim - where sr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2002-06-05','2002-10-19','2002-11-08'))) - and sr_returned_date_sk = d_date_sk - group by i_item_id), - cr_items as - (select i_item_id item_id, - sum(cr_return_quantity) cr_item_qty - from catalog_returns, - item, - date_dim - where cr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2002-06-05','2002-10-19','2002-11-08'))) - and cr_returned_date_sk = d_date_sk - group by i_item_id), - wr_items as - (select i_item_id item_id, - sum(wr_return_quantity) wr_item_qty - from web_returns, - item, - date_dim - where wr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2002-06-05','2002-10-19','2002-11-08'))) - and wr_returned_date_sk = d_date_sk - group by i_item_id) - select sr_items.item_id - ,sr_item_qty - ,sr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 sr_dev - ,cr_item_qty - ,cr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 cr_dev - ,wr_item_qty - ,wr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 wr_dev - ,(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 average - from sr_items - ,cr_items - ,wr_items - where sr_items.item_id=cr_items.item_id - and sr_items.item_id=wr_items.item_id - order by sr_items.item_id - ,sr_item_qty - limit 100; - --- end template query83.tpl query 65 in stream 5 --- start template query31.tpl query 66 in stream 5 -with /* TPC-DS query31.tpl 0.50 */ ss as - (select ca_county,d_qoy, d_year,sum(ss_ext_sales_price) as store_sales - from store_sales,date_dim,customer_address - where ss_sold_date_sk = d_date_sk - and ss_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year), - ws as - (select ca_county,d_qoy, d_year,sum(ws_ext_sales_price) as web_sales - from web_sales,date_dim,customer_address - where ws_sold_date_sk = d_date_sk - and ws_bill_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year) - select - ss1.ca_county - ,ss1.d_year - ,ws2.web_sales/ws1.web_sales web_q1_q2_increase - ,ss2.store_sales/ss1.store_sales store_q1_q2_increase - ,ws3.web_sales/ws2.web_sales web_q2_q3_increase - ,ss3.store_sales/ss2.store_sales store_q2_q3_increase - from - ss ss1 - ,ss ss2 - ,ss ss3 - ,ws ws1 - ,ws ws2 - ,ws ws3 - where - ss1.d_qoy = 1 - and ss1.d_year = 1999 - and ss1.ca_county = ss2.ca_county - and ss2.d_qoy = 2 - and ss2.d_year = 1999 - and ss2.ca_county = ss3.ca_county - and ss3.d_qoy = 3 - and ss3.d_year = 1999 - and ss1.ca_county = ws1.ca_county - and ws1.d_qoy = 1 - and ws1.d_year = 1999 - and ws1.ca_county = ws2.ca_county - and ws2.d_qoy = 2 - and ws2.d_year = 1999 - and ws1.ca_county = ws3.ca_county - and ws3.d_qoy = 3 - and ws3.d_year =1999 - and case when ws1.web_sales > 0 then ws2.web_sales/ws1.web_sales else null end - > case when ss1.store_sales > 0 then ss2.store_sales/ss1.store_sales else null end - and case when ws2.web_sales > 0 then ws3.web_sales/ws2.web_sales else null end - > case when ss2.store_sales > 0 then ss3.store_sales/ss2.store_sales else null end - order by web_q2_q3_increase; - --- end template query31.tpl query 66 in stream 5 --- start template query26.tpl query 67 in stream 5 -select /* TPC-DS query26.tpl 0.85 */ i_item_id, - avg(cs_quantity) agg1, - avg(cs_list_price) agg2, - avg(cs_coupon_amt) agg3, - avg(cs_sales_price) agg4 - from catalog_sales, customer_demographics, date_dim, item, promotion - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd_demo_sk and - cs_promo_sk = p_promo_sk and - cd_gender = 'M' and - cd_marital_status = 'M' and - cd_education_status = 'Primary' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 1998 - group by i_item_id - order by i_item_id - limit 100; - --- end template query26.tpl query 67 in stream 5 --- start template query40.tpl query 68 in stream 5 -select /* TPC-DS query40.tpl 0.86 */ - w_state - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('2002-04-11' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_before - ,sum(case when (cast(d_date as date) >= cast ('2002-04-11' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_after - from - catalog_sales left outer join catalog_returns on - (cs_order_number = cr_order_number - and cs_item_sk = cr_item_sk) - ,warehouse - ,item - ,date_dim - where - i_current_price between 0.99 and 1.49 - and i_item_sk = cs_item_sk - and cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('2002-04-11' as date)) - and dateadd(day,30,cast ('2002-04-11' as date)) - group by - w_state,i_item_id - order by w_state,i_item_id -limit 100; - --- end template query40.tpl query 68 in stream 5 --- start template query14a.tpl query 69 in stream 5 -with /* TPC-DS query14a.tpl 0.69 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1998 AND 1998 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1998 AND 1998 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1998 AND 1998 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as - (select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2) x) -, - results AS -(select channel, i_brand_id, i_class_id, i_category_id, sum(sales) sum_sales, sum(number_sales) number_sales - from ( - select 'store' channel, i_brand_id,i_class_id - ,i_category_id,sum(ss_quantity*ss_list_price) sales - , count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1998+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales) - union all - select 'catalog' channel, i_brand_id,i_class_id,i_category_id, sum(cs_quantity*cs_list_price) sales, count(*) number_sales - from catalog_sales - ,item - ,date_dim - where cs_item_sk in (select ss_item_sk from cross_items) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1998+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(cs_quantity*cs_list_price) > (select average_sales from avg_sales) - union all - select 'web' channel, i_brand_id,i_class_id,i_category_id, sum(ws_quantity*ws_list_price) sales , count(*) number_sales - from web_sales - ,item - ,date_dim - where ws_item_sk in (select ss_item_sk from cross_items) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1998+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ws_quantity*ws_list_price) > (select average_sales from avg_sales) - ) y - group by channel, i_brand_id,i_class_id,i_category_id) - - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales -from ( - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales from results - union - select channel, i_brand_id, i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id, i_class_id - union - select channel, i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id - union - select channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel - union - select null as channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results) z -order by channel, i_brand_id, i_class_id, i_category_id - limit 100; -with /* TPC-DS query14a.tpl 0.69 part2 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1998 AND 1998 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1998 AND 1998 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1998 AND 1998 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as -(select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2) x) - select this_year.channel ty_channel - ,this_year.i_brand_id ty_brand - ,this_year.i_class_id ty_class - ,this_year.i_category_id ty_category - ,this_year.sales ty_sales - ,this_year.number_sales ty_number_sales - ,last_year.channel ly_channel - ,last_year.i_brand_id ly_brand - ,last_year.i_class_id ly_class - ,last_year.i_category_id ly_category - ,last_year.sales ly_sales - ,last_year.number_sales ly_number_sales -from - (select 'store' channel, i_brand_id,i_class_id,i_category_id - ,sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1998 + 1 - and d_moy = 12 - and d_dom = 1) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) this_year, - (select 'store' channel, i_brand_id,i_class_id - ,i_category_id, sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1998 - and d_moy = 12 - and d_dom = 1) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) last_year - where this_year.i_brand_id= last_year.i_brand_id - and this_year.i_class_id = last_year.i_class_id - and this_year.i_category_id = last_year.i_category_id - order by this_year.channel, this_year.i_brand_id, this_year.i_class_id, this_year.i_category_id - limit 100; - --- end template query14a.tpl query 69 in stream 5 --- start template query23.tpl query 70 in stream 5 -with /* TPC-DS query23.tpl 0.68 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (1999,1999+1,1999+2,1999+3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1999,1999+1,1999+2,1999+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * -from - max_store_sales)) - select sum(sales) - from (select cs_quantity*cs_list_price sales - from catalog_sales - ,date_dim - where d_year = 1999 - and d_moy = 3 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - union all - select ws_quantity*ws_list_price sales - from web_sales - ,date_dim - where d_year = 1999 - and d_moy = 3 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer)) - limit 100; -with /* TPC-DS query23.tpl 0.68 part2 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (1999,1999 + 1,1999 + 2,1999 + 3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1999,1999+1,1999+2,1999+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * - from max_store_sales)) - select c_last_name,c_first_name,sales - from (select c_last_name,c_first_name,sum(cs_quantity*cs_list_price) sales - from catalog_sales - ,customer - ,date_dim - where d_year = 1999 - and d_moy = 3 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and cs_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name - union all - select c_last_name,c_first_name,sum(ws_quantity*ws_list_price) sales - from web_sales - ,customer - ,date_dim - where d_year = 1999 - and d_moy = 3 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and ws_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name) - order by c_last_name,c_first_name,sales - limit 100; - --- end template query23.tpl query 70 in stream 5 --- start template query96.tpl query 71 in stream 5 -select /* TPC-DS query96.tpl 0.1 */ count(*) -from store_sales - ,household_demographics - ,time_dim, store -where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and household_demographics.hd_dep_count = 8 - and store.s_store_name = 'ese' -order by count(*) -limit 100; - --- end template query96.tpl query 71 in stream 5 --- start template query1.tpl query 72 in stream 5 -with /* TPC-DS query1.tpl 0.12 */ customer_total_return as -(select sr_customer_sk as ctr_customer_sk -,sr_store_sk as ctr_store_sk -,sum(SR_FEE) as ctr_total_return -from store_returns -,date_dim -where sr_returned_date_sk = d_date_sk -and d_year =2000 -group by sr_customer_sk -,sr_store_sk) - select c_customer_id -from customer_total_return ctr1 -,store -,customer -where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 -from customer_total_return ctr2 -where ctr1.ctr_store_sk = ctr2.ctr_store_sk) -and s_store_sk = ctr1.ctr_store_sk -and s_state = 'MN' -and ctr1.ctr_customer_sk = c_customer_sk -order by c_customer_id -limit 100; - --- end template query1.tpl query 72 in stream 5 --- start template query95.tpl query 73 in stream 5 -with /* TPC-DS query95.tpl 0.43 */ ws_wh as -(select ws1.ws_order_number,ws1.ws_warehouse_sk wh1,ws2.ws_warehouse_sk wh2 - from web_sales ws1,web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) - select - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2002-2-01' and - dateadd(day,60,cast('2002-2-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'TX' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and ws1.ws_order_number in (select ws_order_number - from ws_wh) -and ws1.ws_order_number in (select wr_order_number - from web_returns,ws_wh - where wr_order_number = ws_wh.ws_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query95.tpl query 73 in stream 5 --- start template query27a.tpl query 74 in stream 5 -with /* TPC-DS query27a.tpl 0.16 */ results as - (select i_item_id, - s_state, 0 as g_state, - ss_quantity agg1, - ss_list_price agg2, - ss_coupon_amt agg3, - ss_sales_price agg4 - from store_sales, customer_demographics, date_dim, store, item - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_store_sk = s_store_sk and - ss_cdemo_sk = cd_demo_sk and - cd_gender = 'M' and - cd_marital_status = 'U' and - cd_education_status = 'Advanced Degree' and - d_year = 2001 and - s_state in ('AL','VT', 'MN', 'GA', 'NM', 'CA') - ) - - select i_item_id, - s_state, g_state, agg1, agg2, agg3, agg4 - from ( - select i_item_id, s_state, 0 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4 from results - group by i_item_id, s_state - union all - select i_item_id, NULL AS s_state, 1 AS g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as s_state, 1 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - ) foo - order by i_item_id, s_state - limit 100; - --- end template query27a.tpl query 74 in stream 5 --- start template query44.tpl query 75 in stream 5 -select /* TPC-DS query44.tpl 0.4 */ asceding.rnk, i1.i_product_name best_performing, i2.i_product_name worst_performing -from(select * - from (select item_sk,rank() over (order by rank_col asc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 421 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 421 - and ss_hdemo_sk is null - group by ss_store_sk))V1)V11 - where rnk < 11) asceding, - (select * - from (select item_sk,rank() over (order by rank_col desc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 421 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 421 - and ss_hdemo_sk is null - group by ss_store_sk))V2)V21 - where rnk < 11) descending, -item i1, -item i2 -where asceding.rnk = descending.rnk - and i1.i_item_sk=asceding.item_sk - and i2.i_item_sk=descending.item_sk -order by asceding.rnk -limit 100; - --- end template query44.tpl query 75 in stream 5 --- start template query16.tpl query 76 in stream 5 -select /* TPC-DS query16.tpl 0.25 */ - count(distinct cs_order_number) as "order count" - ,sum(cs_ext_ship_cost) as "total shipping cost" - ,sum(cs_net_profit) as "total net profit" -from - catalog_sales cs1 - ,date_dim - ,customer_address - ,call_center -where - d_date between '1999-2-01' and - dateadd(day, 60, cast('1999-2-01' as date)) -and cs1.cs_ship_date_sk = d_date_sk -and cs1.cs_ship_addr_sk = ca_address_sk -and ca_state = 'KS' -and cs1.cs_call_center_sk = cc_call_center_sk -and cc_county in ('Gage County','Sierra County','Jackson County','Williamson County', - 'Franklin Parish' -) -and exists (select * - from catalog_sales cs2 - where cs1.cs_order_number = cs2.cs_order_number - and cs1.cs_warehouse_sk <> cs2.cs_warehouse_sk) -and not exists(select * - from catalog_returns cr1 - where cs1.cs_order_number = cr1.cr_order_number) -order by count(distinct cs_order_number) -limit 100; - --- end template query16.tpl query 76 in stream 5 --- start template query64.tpl query 77 in stream 5 -with /* TPC-DS query64.tpl 0.20 */ cs_ui as - (select cs_item_sk - ,sum(cs_ext_list_price) as sale,sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit) as refund - from catalog_sales - ,catalog_returns - where cs_item_sk = cr_item_sk - and cs_order_number = cr_order_number - group by cs_item_sk - having sum(cs_ext_list_price)>2*sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit)), -cross_sales as - (select i_product_name product_name - ,i_item_sk item_sk - ,s_store_name store_name - ,s_zip store_zip - ,ad1.ca_street_number b_street_number - ,ad1.ca_street_name b_street_name - ,ad1.ca_city b_city - ,ad1.ca_zip b_zip - ,ad2.ca_street_number c_street_number - ,ad2.ca_street_name c_street_name - ,ad2.ca_city c_city - ,ad2.ca_zip c_zip - ,d1.d_year as syear - ,d2.d_year as fsyear - ,d3.d_year s2year - ,count(*) cnt - ,sum(ss_wholesale_cost) s1 - ,sum(ss_list_price) s2 - ,sum(ss_coupon_amt) s3 - FROM store_sales - ,store_returns - ,cs_ui - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,customer - ,customer_demographics cd1 - ,customer_demographics cd2 - ,promotion - ,household_demographics hd1 - ,household_demographics hd2 - ,customer_address ad1 - ,customer_address ad2 - ,income_band ib1 - ,income_band ib2 - ,item - WHERE ss_store_sk = s_store_sk AND - ss_sold_date_sk = d1.d_date_sk AND - ss_customer_sk = c_customer_sk AND - ss_cdemo_sk= cd1.cd_demo_sk AND - ss_hdemo_sk = hd1.hd_demo_sk AND - ss_addr_sk = ad1.ca_address_sk and - ss_item_sk = i_item_sk and - ss_item_sk = sr_item_sk and - ss_ticket_number = sr_ticket_number and - ss_item_sk = cs_ui.cs_item_sk and - c_current_cdemo_sk = cd2.cd_demo_sk AND - c_current_hdemo_sk = hd2.hd_demo_sk AND - c_current_addr_sk = ad2.ca_address_sk and - c_first_sales_date_sk = d2.d_date_sk and - c_first_shipto_date_sk = d3.d_date_sk and - ss_promo_sk = p_promo_sk and - hd1.hd_income_band_sk = ib1.ib_income_band_sk and - hd2.hd_income_band_sk = ib2.ib_income_band_sk and - cd1.cd_marital_status <> cd2.cd_marital_status and - i_color in ('azure','peru','ghost','seashell','tan','cornflower') and - i_current_price between 9 and 9 + 10 and - i_current_price between 9 + 1 and 9 + 15 -group by i_product_name - ,i_item_sk - ,s_store_name - ,s_zip - ,ad1.ca_street_number - ,ad1.ca_street_name - ,ad1.ca_city - ,ad1.ca_zip - ,ad2.ca_street_number - ,ad2.ca_street_name - ,ad2.ca_city - ,ad2.ca_zip - ,d1.d_year - ,d2.d_year - ,d3.d_year -) -select cs1.product_name - ,cs1.store_name - ,cs1.store_zip - ,cs1.b_street_number - ,cs1.b_street_name - ,cs1.b_city - ,cs1.b_zip - ,cs1.c_street_number - ,cs1.c_street_name - ,cs1.c_city - ,cs1.c_zip - ,cs1.syear - ,cs1.cnt - ,cs1.s1 as s11 - ,cs1.s2 as s21 - ,cs1.s3 as s31 - ,cs2.s1 as s12 - ,cs2.s2 as s22 - ,cs2.s3 as s32 - ,cs2.syear - ,cs2.cnt -from cross_sales cs1,cross_sales cs2 -where cs1.item_sk=cs2.item_sk and - cs1.syear = 2001 and - cs2.syear = 2001 + 1 and - cs2.cnt <= cs1.cnt and - cs1.store_name = cs2.store_name and - cs1.store_zip = cs2.store_zip -order by cs1.product_name - ,cs1.store_name - ,cs2.cnt - ,cs1.s1 - ,cs2.s1; - --- end template query64.tpl query 77 in stream 5 --- start template query20.tpl query 78 in stream 5 -select /* TPC-DS query20.tpl 0.65 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(cs_ext_sales_price) as itemrevenue - ,sum(cs_ext_sales_price)*100/sum(sum(cs_ext_sales_price)) over - (partition by i_class) as revenueratio - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and i_category in ('Jewelry', 'Music', 'Home') - and cs_sold_date_sk = d_date_sk - and d_date between cast('2002-01-14' as date) - and dateadd(day,30,cast('2002-01-14' as date)) - group by i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - order by i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query20.tpl query 78 in stream 5 --- start template query43.tpl query 79 in stream 5 -select /* TPC-DS query43.tpl 0.15 */ s_store_name, s_store_id, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from date_dim, store_sales, store - where d_date_sk = ss_sold_date_sk and - s_store_sk = ss_store_sk and - s_gmt_offset = -6 and - d_year = 2000 - group by s_store_name, s_store_id - order by s_store_name, s_store_id,sun_sales,mon_sales,tue_sales,wed_sales,thu_sales,fri_sales,sat_sales - limit 100; - --- end template query43.tpl query 79 in stream 5 --- start template query5a.tpl query 80 in stream 5 -with /* TPC-DS query5a.tpl 0.98 */ ssr as - (select s_store_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ss_store_sk as store_sk, - ss_sold_date_sk as date_sk, - ss_ext_sales_price as sales_price, - ss_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from store_sales - union all - select sr_store_sk as store_sk, - sr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - sr_return_amt as return_amt, - sr_net_loss as net_loss - from store_returns - ) salesreturns, - date_dim, - store - where date_sk = d_date_sk - and d_date between cast('2002-08-17' as date) - and dateadd(day,14,cast('2002-08-17' as date)) - and store_sk = s_store_sk - group by s_store_id) - , - csr as - (select cp_catalog_page_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select cs_catalog_page_sk as page_sk, - cs_sold_date_sk as date_sk, - cs_ext_sales_price as sales_price, - cs_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from catalog_sales - union all - select cr_catalog_page_sk as page_sk, - cr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - cr_return_amount as return_amt, - cr_net_loss as net_loss - from catalog_returns - ) salesreturns, - date_dim, - catalog_page - where date_sk = d_date_sk - and d_date between cast('2002-08-17' as date) - and dateadd(day,14,cast('2002-08-17' as date)) - and page_sk = cp_catalog_page_sk - group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ws_web_site_sk as wsr_web_site_sk, - ws_sold_date_sk as date_sk, - ws_ext_sales_price as sales_price, - ws_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from web_sales - union all - select ws_web_site_sk as wsr_web_site_sk, - wr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - wr_return_amt as return_amt, - wr_net_loss as net_loss - from web_returns left outer join web_sales on - ( wr_item_sk = ws_item_sk - and wr_order_number = ws_order_number) - ) salesreturns, - date_dim, - web_site - where date_sk = d_date_sk - and d_date between cast('2002-08-17' as date) - and dateadd(day,14,cast('2002-08-17' as date)) - and wsr_web_site_sk = web_site_sk - group by web_site_id) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || s_store_id as id - , sales - , returns - , (profit - profit_loss) as profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || cp_catalog_page_id as id - , sales - , returns - , (profit - profit_loss) as profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , (profit - profit_loss) as profit - from wsr - ) x - group by channel, id) - select channel, id, sales, returns, profit from ( - select channel, id, sales, returns, profit from results - union - select channel, null as id, sum(sales), sum(returns), sum(profit) from results group by channel - union - select null as channel, null as id, sum(sales), sum(returns), sum(profit) from results) foo -order by channel, id -limit 100; - --- end template query5a.tpl query 80 in stream 5 --- start template query47.tpl query 81 in stream 5 -with /* TPC-DS query47.tpl 0.42 */ v1 as( - select i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, - s_store_name, s_company_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - s_store_name, s_company_name - order by d_year, d_moy) rn - from item, store_sales, date_dim, store - where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - ( - d_year = 2000 or - ( d_year = 2000-1 and d_moy =12) or - ( d_year = 2000+1 and d_moy =1) - ) - group by i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy), - v2 as( - select v1.i_category, v1.i_brand - ,v1.d_year, v1.d_moy - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1.s_store_name = v1_lag.s_store_name and - v1.s_store_name = v1_lead.s_store_name and - v1.s_company_name = v1_lag.s_company_name and - v1.s_company_name = v1_lead.s_company_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 2000 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, sum_sales - limit 100; - --- end template query47.tpl query 81 in stream 5 --- start template query10.tpl query 82 in stream 5 -select /* TPC-DS query10.tpl 0.26 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3, - cd_dep_count, - count(*) cnt4, - cd_dep_employed_count, - count(*) cnt5, - cd_dep_college_count, - count(*) cnt6 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_county in ('Kittson County','Sweetwater County','Wilson County','Catoosa County','Manatee County') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2001 and - d_moy between 4 and 4+3) and - (exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2001 and - d_moy between 4 ANd 4+3) or - exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2001 and - d_moy between 4 and 4+3)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count -limit 100; - --- end template query10.tpl query 82 in stream 5 --- start template query70a.tpl query 83 in stream 5 -with /* TPC-DS query70a.tpl 0.34 */ results as -( select - sum(ss_net_profit) as total_sum ,s_state ,s_county, 0 as gstate, 0 as g_county - from - store_sales - ,date_dim d1 - ,store - where - d1.d_month_seq between 1197 and 1197 + 11 - and d1.d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - and s_state in - ( select s_state - from (select s_state as s_state, - rank() over ( partition by s_state order by sum(ss_net_profit) desc) as ranking - from store_sales, store, date_dim - where d_month_seq between 1197 and 1197 + 11 - and d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - group by s_state - ) tmp1 - where ranking <= 5) - group by s_state,s_county) , - results_rollup as -(select total_sum ,s_state ,s_county, 0 as g_state, 0 as g_county, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum,s_state, NULL as s_county, 0 as g_state, 1 as g_county, 1 as lochierarchy from results group by s_state - union - select sum(total_sum) as total_sum ,NULL as s_state ,NULL as s_county, 1 as g_state, 1 as g_county, 2 as lochierarchy from results) - select total_sum ,s_state ,s_county, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_county = 0 then s_state end - order by total_sum desc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then s_state end - ,rank_within_parent - limit 100; - --- end template query70a.tpl query 83 in stream 5 --- start template query39.tpl query 84 in stream 5 -with /* TPC-DS query39.tpl 0.5 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =2000 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=3 - and inv2.d_moy=3+1 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; -with /* TPC-DS query39.tpl 0.5 part2 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =2000 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=3 - and inv2.d_moy=3+1 - and inv1.cov > 1.5 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; - --- end template query39.tpl query 84 in stream 5 --- start template query72.tpl query 85 in stream 5 -select /* TPC-DS query72.tpl 0.87 */ i_item_desc - ,w_warehouse_name - ,d1.d_week_seq - ,sum(case when p_promo_sk is null then 1 else 0 end) no_promo - ,sum(case when p_promo_sk is not null then 1 else 0 end) promo - ,count(*) total_cnt -from catalog_sales -join inventory on (cs_item_sk = inv_item_sk) -join warehouse on (w_warehouse_sk=inv_warehouse_sk) -join item on (i_item_sk = cs_item_sk) -join customer_demographics on (cs_bill_cdemo_sk = cd_demo_sk) -join household_demographics on (cs_bill_hdemo_sk = hd_demo_sk) -join date_dim d1 on (cs_sold_date_sk = d1.d_date_sk) -join date_dim d2 on (inv_date_sk = d2.d_date_sk) -join date_dim d3 on (cs_ship_date_sk = d3.d_date_sk) -left outer join promotion on (cs_promo_sk=p_promo_sk) -left outer join catalog_returns on (cr_item_sk = cs_item_sk and cr_order_number = cs_order_number) -where d1.d_week_seq = d2.d_week_seq - and inv_quantity_on_hand < cs_quantity - and d3.d_date > d1.d_date + 5 - and hd_buy_potential = '501-1000' - and d1.d_year = 2002 - and cd_marital_status = 'S' -group by i_item_desc,w_warehouse_name,d1.d_week_seq -order by total_cnt desc, i_item_desc, w_warehouse_name, d_week_seq -limit 100; - --- end template query72.tpl query 85 in stream 5 --- start template query75.tpl query 86 in stream 5 -WITH /* TPC-DS query75.tpl 0.3 */ all_sales AS ( - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,SUM(sales_cnt) AS sales_cnt - ,SUM(sales_amt) AS sales_amt - FROM (SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,cs_quantity - COALESCE(cr_return_quantity,0) AS sales_cnt - ,cs_ext_sales_price - COALESCE(cr_return_amount,0.0) AS sales_amt - FROM catalog_sales JOIN item ON i_item_sk=cs_item_sk - JOIN date_dim ON d_date_sk=cs_sold_date_sk - LEFT JOIN catalog_returns ON (cs_order_number=cr_order_number - AND cs_item_sk=cr_item_sk) - WHERE i_category='Electronics' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ss_quantity - COALESCE(sr_return_quantity,0) AS sales_cnt - ,ss_ext_sales_price - COALESCE(sr_return_amt,0.0) AS sales_amt - FROM store_sales JOIN item ON i_item_sk=ss_item_sk - JOIN date_dim ON d_date_sk=ss_sold_date_sk - LEFT JOIN store_returns ON (ss_ticket_number=sr_ticket_number - AND ss_item_sk=sr_item_sk) - WHERE i_category='Electronics' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ws_quantity - COALESCE(wr_return_quantity,0) AS sales_cnt - ,ws_ext_sales_price - COALESCE(wr_return_amt,0.0) AS sales_amt - FROM web_sales JOIN item ON i_item_sk=ws_item_sk - JOIN date_dim ON d_date_sk=ws_sold_date_sk - LEFT JOIN web_returns ON (ws_order_number=wr_order_number - AND ws_item_sk=wr_item_sk) - WHERE i_category='Electronics') sales_detail - GROUP BY d_year, i_brand_id, i_class_id, i_category_id, i_manufact_id) - SELECT prev_yr.d_year AS prev_year - ,curr_yr.d_year AS year - ,curr_yr.i_brand_id - ,curr_yr.i_class_id - ,curr_yr.i_category_id - ,curr_yr.i_manufact_id - ,prev_yr.sales_cnt AS prev_yr_cnt - ,curr_yr.sales_cnt AS curr_yr_cnt - ,curr_yr.sales_cnt-prev_yr.sales_cnt AS sales_cnt_diff - ,curr_yr.sales_amt-prev_yr.sales_amt AS sales_amt_diff - FROM all_sales curr_yr, all_sales prev_yr - WHERE curr_yr.i_brand_id=prev_yr.i_brand_id - AND curr_yr.i_class_id=prev_yr.i_class_id - AND curr_yr.i_category_id=prev_yr.i_category_id - AND curr_yr.i_manufact_id=prev_yr.i_manufact_id - AND curr_yr.d_year=2001 - AND prev_yr.d_year=2001-1 - AND CAST(curr_yr.sales_cnt AS DECIMAL(17,2))/CAST(prev_yr.sales_cnt AS DECIMAL(17,2))<0.9 - ORDER BY sales_cnt_diff,sales_amt_diff - limit 100; - --- end template query75.tpl query 86 in stream 5 --- start template query12.tpl query 87 in stream 5 -select /* TPC-DS query12.tpl 0.64 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ws_ext_sales_price) as itemrevenue - ,sum(ws_ext_sales_price)*100/sum(sum(ws_ext_sales_price)) over - (partition by i_class) as revenueratio -from - web_sales - ,item - ,date_dim -where - ws_item_sk = i_item_sk - and i_category in ('Home', 'Women', 'Electronics') - and ws_sold_date_sk = d_date_sk - and d_date between cast('2000-01-18' as date) - and dateadd(day,30,cast('2000-01-18' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query12.tpl query 87 in stream 5 --- start template query37.tpl query 88 in stream 5 -select /* TPC-DS query37.tpl 0.31 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, catalog_sales - where i_current_price between 43 and 43 + 30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('2002-06-05' as date) and dateadd(day,60,cast('2002-06-05' as date)) - and i_manufact_id in (873,858,886,713) - and inv_quantity_on_hand between 100 and 500 - and cs_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query37.tpl query 88 in stream 5 --- start template query15.tpl query 89 in stream 5 -select /* TPC-DS query15.tpl 0.57 */ ca_zip - ,sum(cs_sales_price) - from catalog_sales - ,customer - ,customer_address - ,date_dim - where cs_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', - '85392', '85460', '80348', '81792') - or ca_state in ('CA','WA','GA') - or cs_sales_price > 500) - and cs_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 1998 - group by ca_zip - order by ca_zip - limit 100; - --- end template query15.tpl query 89 in stream 5 --- start template query59.tpl query 90 in stream 5 -with /* TPC-DS query59.tpl 0.30 */ wss as - (select d_week_seq, - ss_store_sk, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - group by d_week_seq,ss_store_sk - ) - select s_store_name1,s_store_id1,d_week_seq1 - ,sun_sales1/sun_sales2,mon_sales1/mon_sales2 - ,tue_sales1/tue_sales2,wed_sales1/wed_sales2,thu_sales1/thu_sales2 - ,fri_sales1/fri_sales2,sat_sales1/sat_sales2 - from - (select s_store_name s_store_name1,wss.d_week_seq d_week_seq1 - ,s_store_id s_store_id1,sun_sales sun_sales1 - ,mon_sales mon_sales1,tue_sales tue_sales1 - ,wed_sales wed_sales1,thu_sales thu_sales1 - ,fri_sales fri_sales1,sat_sales sat_sales1 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1180 and 1180 + 11) y, - (select s_store_name s_store_name2,wss.d_week_seq d_week_seq2 - ,s_store_id s_store_id2,sun_sales sun_sales2 - ,mon_sales mon_sales2,tue_sales tue_sales2 - ,wed_sales wed_sales2,thu_sales thu_sales2 - ,fri_sales fri_sales2,sat_sales sat_sales2 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1180+ 12 and 1180 + 23) x - where s_store_id1=s_store_id2 - and d_week_seq1=d_week_seq2-52 - order by s_store_name1,s_store_id1,d_week_seq1 -limit 100; - --- end template query59.tpl query 90 in stream 5 --- start template query91.tpl query 91 in stream 5 -select /* TPC-DS query91.tpl 0.13 */ - cc_call_center_id Call_Center, - cc_name Call_Center_Name, - cc_manager Manager, - sum(cr_net_loss) Returns_Loss -from - call_center, - catalog_returns, - date_dim, - customer, - customer_address, - customer_demographics, - household_demographics -where - cr_call_center_sk = cc_call_center_sk -and cr_returned_date_sk = d_date_sk -and cr_returning_customer_sk= c_customer_sk -and cd_demo_sk = c_current_cdemo_sk -and hd_demo_sk = c_current_hdemo_sk -and ca_address_sk = c_current_addr_sk -and d_year = 2000 -and d_moy = 12 -and ( (cd_marital_status = 'M' and cd_education_status = 'Unknown') - or(cd_marital_status = 'W' and cd_education_status = 'Advanced Degree')) -and hd_buy_potential like '>10000%' -and ca_gmt_offset = -7 -group by cc_call_center_id,cc_name,cc_manager,cd_marital_status,cd_education_status -order by sum(cr_net_loss) desc; - --- end template query91.tpl query 91 in stream 5 --- start template query99.tpl query 92 in stream 5 -select /* TPC-DS query99.tpl 0.94 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 30) and - (cs_ship_date_sk - cs_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 60) and - (cs_ship_date_sk - cs_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 90) and - (cs_ship_date_sk - cs_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - catalog_sales - ,warehouse - ,ship_mode - ,call_center - ,date_dim -where - d_month_seq between 1183 and 1183 + 11 -and cs_ship_date_sk = d_date_sk -and cs_warehouse_sk = w_warehouse_sk -and cs_ship_mode_sk = sm_ship_mode_sk -and cs_call_center_sk = cc_call_center_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -limit 100; - --- end template query99.tpl query 92 in stream 5 --- start template query41.tpl query 93 in stream 5 -select /* TPC-DS query41.tpl 0.62 */ distinct(i_product_name) - from item i1 - where i_manufact_id between 823 and 823+40 - and (select count(*) as item_cnt - from item - where (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'mint' or i_color = 'puff') and - (i_units = 'Pound' or i_units = 'Unknown') and - (i_size = 'economy' or i_size = 'N/A') - ) or - (i_category = 'Women' and - (i_color = 'azure' or i_color = 'beige') and - (i_units = 'Dozen' or i_units = 'Dram') and - (i_size = 'medium' or i_size = 'large') - ) or - (i_category = 'Men' and - (i_color = 'dark' or i_color = 'royal') and - (i_units = 'Oz' or i_units = 'Carton') and - (i_size = 'small' or i_size = 'extra large') - ) or - (i_category = 'Men' and - (i_color = 'misty' or i_color = 'blue') and - (i_units = 'Pallet' or i_units = 'Case') and - (i_size = 'economy' or i_size = 'N/A') - ))) or - (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'khaki' or i_color = 'seashell') and - (i_units = 'Cup' or i_units = 'Gross') and - (i_size = 'economy' or i_size = 'N/A') - ) or - (i_category = 'Women' and - (i_color = 'brown' or i_color = 'medium') and - (i_units = 'Bundle' or i_units = 'Gram') and - (i_size = 'medium' or i_size = 'large') - ) or - (i_category = 'Men' and - (i_color = 'floral' or i_color = 'deep') and - (i_units = 'Bunch' or i_units = 'N/A') and - (i_size = 'small' or i_size = 'extra large') - ) or - (i_category = 'Men' and - (i_color = 'moccasin' or i_color = 'wheat') and - (i_units = 'Tbl' or i_units = 'Each') and - (i_size = 'economy' or i_size = 'N/A') - )))) > 0 - order by i_product_name - limit 100; - --- end template query41.tpl query 93 in stream 5 --- start template query9.tpl query 94 in stream 5 -select /* TPC-DS query9.tpl 0.49 */ case when (select count(*) - from store_sales - where ss_quantity between 1 and 20) > 313148609 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 1 and 20) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 1 and 20) end bucket1 , - case when (select count(*) - from store_sales - where ss_quantity between 21 and 40) > 1349752283 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 21 and 40) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 21 and 40) end bucket2, - case when (select count(*) - from store_sales - where ss_quantity between 41 and 60) > 2141410297 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 41 and 60) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 41 and 60) end bucket3, - case when (select count(*) - from store_sales - where ss_quantity between 61 and 80) > 1409901474 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 61 and 80) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 61 and 80) end bucket4, - case when (select count(*) - from store_sales - where ss_quantity between 81 and 100) > 1211599653 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 81 and 100) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 81 and 100) end bucket5 -from reason -where r_reason_sk = 1 -; - --- end template query9.tpl query 94 in stream 5 --- start template query86a.tpl query 95 in stream 5 -with /* TPC-DS query86a.tpl 0.11 */ results as -( select sum(ws_net_paid) as total_sum, i_category, i_class, 0 as g_category, 0 as g_class - from - web_sales - ,date_dim d1 - ,item - where - d1.d_month_seq between 1199 and 1199+11 - and d1.d_date_sk = ws_sold_date_sk - and i_item_sk = ws_item_sk - group by i_category,i_class - ) , - - results_rollup as -( select total_sum ,i_category ,i_class, g_category, g_class, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum, i_category, NULL as i_class, 0 as g_category, 1 as g_class, 1 as lochierarchy from results group by i_category - union - select sum(total_sum) as total_sum, NULL as i_category, NULL as i_class, 1 as g_category, 1 as g_class, 2 as lochierarchy from results) - select - total_sum ,i_category ,i_class, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_class = 0 then i_category end - order by total_sum desc) as rank_within_parent - from - results_rollup - order by - lochierarchy desc, - case when lochierarchy = 0 then i_category end, - rank_within_parent - limit 100; - --- end template query86a.tpl query 95 in stream 5 --- start template query34.tpl query 96 in stream 5 -select /* TPC-DS query34.tpl 0.73 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (date_dim.d_dom between 1 and 3 or date_dim.d_dom between 25 and 28) - and (household_demographics.hd_buy_potential = '>10000' or - household_demographics.hd_buy_potential = '5001-10000') - and household_demographics.hd_vehicle_count > 0 - and (case when household_demographics.hd_vehicle_count > 0 - then household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count - else null - end) > 1.2 - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_county in ('Maries County','Perry County','Lunenburg County','Kootenai County', - 'McHenry County','Crawford County','Scott County','Stanislaus County') - group by ss_ticket_number,ss_customer_sk) dn,customer - where ss_customer_sk = c_customer_sk - and cnt between 15 and 20 - order by c_last_name,c_first_name,c_salutation,c_preferred_cust_flag desc, ss_ticket_number; - --- end template query34.tpl query 96 in stream 5 --- start template query82.tpl query 97 in stream 5 -select /* TPC-DS query82.tpl 0.67 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, store_sales - where i_current_price between 33 and 33+30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('1998-05-10' as date) and dateadd(day,60,cast('1998-05-10' as date)) - and i_manufact_id in (916,430,245,294) - and inv_quantity_on_hand between 100 and 500 - and ss_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query82.tpl query 97 in stream 5 --- start template query29.tpl query 98 in stream 5 -select /* TPC-DS query29.tpl 0.53 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,avg(ss_quantity) as store_sales_quantity - ,avg(sr_return_quantity) as store_returns_quantity - ,avg(cs_quantity) as catalog_sales_quantity - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 1998 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 4 + 3 - and d2.d_year = 1998 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_year in (1998,1998+1,1998+2) - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query29.tpl query 98 in stream 5 --- start template query25.tpl query 99 in stream 5 -select /* TPC-DS query25.tpl 0.9 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,max(ss_net_profit) as store_sales_profit - ,max(sr_net_loss) as store_returns_loss - ,max(cs_net_profit) as catalog_sales_profit - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 2001 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 10 - and d2.d_year = 2001 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_moy between 4 and 10 - and d3.d_year = 2001 - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query25.tpl query 99 in stream 5 diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/100TB/queries/query_6.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/100TB/queries/query_6.sql deleted file mode 100644 index b049b7fb..00000000 --- a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/100TB/queries/query_6.sql +++ /dev/null @@ -1,5027 +0,0 @@ --- start template query34.tpl query 1 in stream 6 -select /* TPC-DS query34.tpl 0.73 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (date_dim.d_dom between 1 and 3 or date_dim.d_dom between 25 and 28) - and (household_demographics.hd_buy_potential = '>10000' or - household_demographics.hd_buy_potential = '5001-10000') - and household_demographics.hd_vehicle_count > 0 - and (case when household_demographics.hd_vehicle_count > 0 - then household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count - else null - end) > 1.2 - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_county in ('Clinton County','Brown County','Arthur County','Walker County', - 'Elmore County','Washington County','Sierra County','Piute County') - group by ss_ticket_number,ss_customer_sk) dn,customer - where ss_customer_sk = c_customer_sk - and cnt between 15 and 20 - order by c_last_name,c_first_name,c_salutation,c_preferred_cust_flag desc, ss_ticket_number; - --- end template query34.tpl query 1 in stream 6 --- start template query88.tpl query 2 in stream 6 -select /* TPC-DS query88.tpl 0.66 */ * -from - (select count(*) h8_30_to_9 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2)) - and store.s_store_name = 'ese') s1, - (select count(*) h9_to_9_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2)) - and store.s_store_name = 'ese') s2, - (select count(*) h9_30_to_10 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2)) - and store.s_store_name = 'ese') s3, - (select count(*) h10_to_10_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2)) - and store.s_store_name = 'ese') s4, - (select count(*) h10_30_to_11 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2)) - and store.s_store_name = 'ese') s5, - (select count(*) h11_to_11_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2)) - and store.s_store_name = 'ese') s6, - (select count(*) h11_30_to_12 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2)) - and store.s_store_name = 'ese') s7, - (select count(*) h12_to_12_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 12 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2)) - and store.s_store_name = 'ese') s8 -; - --- end template query88.tpl query 2 in stream 6 --- start template query44.tpl query 3 in stream 6 -select /* TPC-DS query44.tpl 0.4 */ asceding.rnk, i1.i_product_name best_performing, i2.i_product_name worst_performing -from(select * - from (select item_sk,rank() over (order by rank_col asc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 558 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 558 - and ss_addr_sk is null - group by ss_store_sk))V1)V11 - where rnk < 11) asceding, - (select * - from (select item_sk,rank() over (order by rank_col desc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 558 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 558 - and ss_addr_sk is null - group by ss_store_sk))V2)V21 - where rnk < 11) descending, -item i1, -item i2 -where asceding.rnk = descending.rnk - and i1.i_item_sk=asceding.item_sk - and i2.i_item_sk=descending.item_sk -order by asceding.rnk -limit 100; - --- end template query44.tpl query 3 in stream 6 --- start template query94.tpl query 4 in stream 6 -select /* TPC-DS query94.tpl 0.17 */ - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '1999-2-01' and - dateadd(day,60,cast('1999-2-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'KY' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and exists (select * - from web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) -and not exists(select * - from web_returns wr1 - where ws1.ws_order_number = wr1.wr_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query94.tpl query 4 in stream 6 --- start template query50.tpl query 5 in stream 6 -select /* TPC-DS query50.tpl 0.60 */ - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 30) and - (sr_returned_date_sk - ss_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 60) and - (sr_returned_date_sk - ss_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 90) and - (sr_returned_date_sk - ss_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - store_sales - ,store_returns - ,store - ,date_dim d1 - ,date_dim d2 -where - d2.d_year = 2002 -and d2.d_moy = 8 -and ss_ticket_number = sr_ticket_number -and ss_item_sk = sr_item_sk -and ss_sold_date_sk = d1.d_date_sk -and sr_returned_date_sk = d2.d_date_sk -and ss_customer_sk = sr_customer_sk -and ss_store_sk = s_store_sk -group by - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -order by s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -limit 100; - --- end template query50.tpl query 5 in stream 6 --- start template query5a.tpl query 6 in stream 6 -with /* TPC-DS query5a.tpl 0.98 */ ssr as - (select s_store_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ss_store_sk as store_sk, - ss_sold_date_sk as date_sk, - ss_ext_sales_price as sales_price, - ss_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from store_sales - union all - select sr_store_sk as store_sk, - sr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - sr_return_amt as return_amt, - sr_net_loss as net_loss - from store_returns - ) salesreturns, - date_dim, - store - where date_sk = d_date_sk - and d_date between cast('2002-08-08' as date) - and dateadd(day,14,cast('2002-08-08' as date)) - and store_sk = s_store_sk - group by s_store_id) - , - csr as - (select cp_catalog_page_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select cs_catalog_page_sk as page_sk, - cs_sold_date_sk as date_sk, - cs_ext_sales_price as sales_price, - cs_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from catalog_sales - union all - select cr_catalog_page_sk as page_sk, - cr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - cr_return_amount as return_amt, - cr_net_loss as net_loss - from catalog_returns - ) salesreturns, - date_dim, - catalog_page - where date_sk = d_date_sk - and d_date between cast('2002-08-08' as date) - and dateadd(day,14,cast('2002-08-08' as date)) - and page_sk = cp_catalog_page_sk - group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ws_web_site_sk as wsr_web_site_sk, - ws_sold_date_sk as date_sk, - ws_ext_sales_price as sales_price, - ws_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from web_sales - union all - select ws_web_site_sk as wsr_web_site_sk, - wr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - wr_return_amt as return_amt, - wr_net_loss as net_loss - from web_returns left outer join web_sales on - ( wr_item_sk = ws_item_sk - and wr_order_number = ws_order_number) - ) salesreturns, - date_dim, - web_site - where date_sk = d_date_sk - and d_date between cast('2002-08-08' as date) - and dateadd(day,14,cast('2002-08-08' as date)) - and wsr_web_site_sk = web_site_sk - group by web_site_id) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || s_store_id as id - , sales - , returns - , (profit - profit_loss) as profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || cp_catalog_page_id as id - , sales - , returns - , (profit - profit_loss) as profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , (profit - profit_loss) as profit - from wsr - ) x - group by channel, id) - select channel, id, sales, returns, profit from ( - select channel, id, sales, returns, profit from results - union - select channel, null as id, sum(sales), sum(returns), sum(profit) from results group by channel - union - select null as channel, null as id, sum(sales), sum(returns), sum(profit) from results) foo -order by channel, id -limit 100; - --- end template query5a.tpl query 6 in stream 6 --- start template query53.tpl query 7 in stream 6 -select /* TPC-DS query53.tpl 0.88 */ * from -(select i_manufact_id, -sum(ss_sales_price) sum_sales, -avg(sum(ss_sales_price)) over (partition by i_manufact_id) avg_quarterly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and -ss_sold_date_sk = d_date_sk and -ss_store_sk = s_store_sk and -d_month_seq in (1211,1211+1,1211+2,1211+3,1211+4,1211+5,1211+6,1211+7,1211+8,1211+9,1211+10,1211+11) and -((i_category in ('Books','Children','Electronics') and -i_class in ('personal','portable','reference','self-help') and -i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) -or(i_category in ('Women','Music','Men') and -i_class in ('accessories','classical','fragrances','pants') and -i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manufact_id, d_qoy ) tmp1 -where case when avg_quarterly_sales > 0 - then abs (sum_sales - avg_quarterly_sales)/ avg_quarterly_sales - else null end > 0.1 -order by avg_quarterly_sales, - sum_sales, - i_manufact_id -limit 100; - --- end template query53.tpl query 7 in stream 6 --- start template query7.tpl query 8 in stream 6 -select /* TPC-DS query7.tpl 0.2 */ i_item_id, - avg(ss_quantity) agg1, - avg(ss_list_price) agg2, - avg(ss_coupon_amt) agg3, - avg(ss_sales_price) agg4 - from store_sales, customer_demographics, date_dim, item, promotion - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_cdemo_sk = cd_demo_sk and - ss_promo_sk = p_promo_sk and - cd_gender = 'F' and - cd_marital_status = 'S' and - cd_education_status = 'Advanced Degree' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 2000 - group by i_item_id - order by i_item_id - limit 100; - --- end template query7.tpl query 8 in stream 6 --- start template query58.tpl query 9 in stream 6 -with /* TPC-DS query58.tpl 0.19 */ ss_items as - (select i_item_id item_id - ,sum(ss_ext_sales_price) ss_item_rev - from store_sales - ,item - ,date_dim - where ss_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '2002-05-24')) - and ss_sold_date_sk = d_date_sk - group by i_item_id), - cs_items as - (select i_item_id item_id - ,sum(cs_ext_sales_price) cs_item_rev - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '2002-05-24')) - and cs_sold_date_sk = d_date_sk - group by i_item_id), - ws_items as - (select i_item_id item_id - ,sum(ws_ext_sales_price) ws_item_rev - from web_sales - ,item - ,date_dim - where ws_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq =(select d_week_seq - from date_dim - where d_date = '2002-05-24')) - and ws_sold_date_sk = d_date_sk - group by i_item_id) - select ss_items.item_id - ,ss_item_rev - ,ss_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ss_dev - ,cs_item_rev - ,cs_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 cs_dev - ,ws_item_rev - ,ws_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ws_dev - ,(ss_item_rev+cs_item_rev+ws_item_rev)/3 average - from ss_items,cs_items,ws_items - where ss_items.item_id=cs_items.item_id - and ss_items.item_id=ws_items.item_id - and ss_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - and ss_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and cs_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and cs_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and ws_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and ws_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - order by item_id - ,ss_item_rev - limit 100; - --- end template query58.tpl query 9 in stream 6 --- start template query20.tpl query 10 in stream 6 -select /* TPC-DS query20.tpl 0.65 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(cs_ext_sales_price) as itemrevenue - ,sum(cs_ext_sales_price)*100/sum(sum(cs_ext_sales_price)) over - (partition by i_class) as revenueratio - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and i_category in ('Shoes', 'Home', 'Men') - and cs_sold_date_sk = d_date_sk - and d_date between cast('2002-04-03' as date) - and dateadd(day,30,cast('2002-04-03' as date)) - group by i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - order by i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query20.tpl query 10 in stream 6 --- start template query75.tpl query 11 in stream 6 -WITH /* TPC-DS query75.tpl 0.3 */ all_sales AS ( - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,SUM(sales_cnt) AS sales_cnt - ,SUM(sales_amt) AS sales_amt - FROM (SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,cs_quantity - COALESCE(cr_return_quantity,0) AS sales_cnt - ,cs_ext_sales_price - COALESCE(cr_return_amount,0.0) AS sales_amt - FROM catalog_sales JOIN item ON i_item_sk=cs_item_sk - JOIN date_dim ON d_date_sk=cs_sold_date_sk - LEFT JOIN catalog_returns ON (cs_order_number=cr_order_number - AND cs_item_sk=cr_item_sk) - WHERE i_category='Sports' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ss_quantity - COALESCE(sr_return_quantity,0) AS sales_cnt - ,ss_ext_sales_price - COALESCE(sr_return_amt,0.0) AS sales_amt - FROM store_sales JOIN item ON i_item_sk=ss_item_sk - JOIN date_dim ON d_date_sk=ss_sold_date_sk - LEFT JOIN store_returns ON (ss_ticket_number=sr_ticket_number - AND ss_item_sk=sr_item_sk) - WHERE i_category='Sports' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ws_quantity - COALESCE(wr_return_quantity,0) AS sales_cnt - ,ws_ext_sales_price - COALESCE(wr_return_amt,0.0) AS sales_amt - FROM web_sales JOIN item ON i_item_sk=ws_item_sk - JOIN date_dim ON d_date_sk=ws_sold_date_sk - LEFT JOIN web_returns ON (ws_order_number=wr_order_number - AND ws_item_sk=wr_item_sk) - WHERE i_category='Sports') sales_detail - GROUP BY d_year, i_brand_id, i_class_id, i_category_id, i_manufact_id) - SELECT prev_yr.d_year AS prev_year - ,curr_yr.d_year AS year - ,curr_yr.i_brand_id - ,curr_yr.i_class_id - ,curr_yr.i_category_id - ,curr_yr.i_manufact_id - ,prev_yr.sales_cnt AS prev_yr_cnt - ,curr_yr.sales_cnt AS curr_yr_cnt - ,curr_yr.sales_cnt-prev_yr.sales_cnt AS sales_cnt_diff - ,curr_yr.sales_amt-prev_yr.sales_amt AS sales_amt_diff - FROM all_sales curr_yr, all_sales prev_yr - WHERE curr_yr.i_brand_id=prev_yr.i_brand_id - AND curr_yr.i_class_id=prev_yr.i_class_id - AND curr_yr.i_category_id=prev_yr.i_category_id - AND curr_yr.i_manufact_id=prev_yr.i_manufact_id - AND curr_yr.d_year=1999 - AND prev_yr.d_year=1999-1 - AND CAST(curr_yr.sales_cnt AS DECIMAL(17,2))/CAST(prev_yr.sales_cnt AS DECIMAL(17,2))<0.9 - ORDER BY sales_cnt_diff,sales_amt_diff - limit 100; - --- end template query75.tpl query 11 in stream 6 --- start template query73.tpl query 12 in stream 6 -select /* TPC-DS query73.tpl 0.79 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_buy_potential = '501-1000' or - household_demographics.hd_buy_potential = '0-500') - and household_demographics.hd_vehicle_count > 0 - and case when household_demographics.hd_vehicle_count > 0 then - household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count else null end > 1 - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_county in ('Montgomery County','Karnes County','Price County','Orangeburg County') - group by ss_ticket_number,ss_customer_sk) dj,customer - where ss_customer_sk = c_customer_sk - and cnt between 1 and 5 - order by cnt desc, c_last_name asc; - --- end template query73.tpl query 12 in stream 6 --- start template query91.tpl query 13 in stream 6 -select /* TPC-DS query91.tpl 0.13 */ - cc_call_center_id Call_Center, - cc_name Call_Center_Name, - cc_manager Manager, - sum(cr_net_loss) Returns_Loss -from - call_center, - catalog_returns, - date_dim, - customer, - customer_address, - customer_demographics, - household_demographics -where - cr_call_center_sk = cc_call_center_sk -and cr_returned_date_sk = d_date_sk -and cr_returning_customer_sk= c_customer_sk -and cd_demo_sk = c_current_cdemo_sk -and hd_demo_sk = c_current_hdemo_sk -and ca_address_sk = c_current_addr_sk -and d_year = 2002 -and d_moy = 12 -and ( (cd_marital_status = 'M' and cd_education_status = 'Unknown') - or(cd_marital_status = 'W' and cd_education_status = 'Advanced Degree')) -and hd_buy_potential like '1001-5000%' -and ca_gmt_offset = -6 -group by cc_call_center_id,cc_name,cc_manager,cd_marital_status,cd_education_status -order by sum(cr_net_loss) desc; - --- end template query91.tpl query 13 in stream 6 --- start template query36a.tpl query 14 in stream 6 -with /* TPC-DS query36a.tpl 0.21 */ results as - (select - sum(ss_net_profit) as ss_net_profit, sum(ss_ext_sales_price) as ss_ext_sales_price, - sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin - ,i_category - ,i_class - ,0 as g_category, 0 as g_class - from - store_sales - ,date_dim d1 - ,item - ,store - where - d1.d_year = 1998 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and s_state in ('KS','OK','SC','TN', - 'NJ','NM','CO','IN') - group by i_category,i_class) - , - results_rollup as - (select gross_margin ,i_category ,i_class,0 as t_category, 0 as t_class, 0 as lochierarchy from results - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - i_category, NULL AS i_class, 0 as t_category, 1 as t_class, 1 as lochierarchy from results group by i_category - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - NULL AS i_category ,NULL AS i_class, 1 as t_category, 1 as t_class, 2 as lochierarchy from results) - select - gross_margin ,i_category ,i_class, lochierarchy,rank() over ( - partition by lochierarchy, case when t_class = 0 then i_category end - order by gross_margin asc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then i_category end - ,rank_within_parent - limit 100; - --- end template query36a.tpl query 14 in stream 6 --- start template query11.tpl query 15 in stream 6 -with /* TPC-DS query11.tpl 0.51 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ss_ext_list_price-ss_ext_discount_amt) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ws_ext_list_price-ws_ext_discount_amt) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_preferred_cust_flag - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 2000 - and t_s_secyear.dyear = 2000+1 - and t_w_firstyear.dyear = 2000 - and t_w_secyear.dyear = 2000+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else 0.0 end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else 0.0 end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_preferred_cust_flag -limit 100; - --- end template query11.tpl query 15 in stream 6 --- start template query80a.tpl query 16 in stream 6 -with /* TPC-DS query80a.tpl 0.6 */ ssr as - (select s_store_id as store_id, - sum(ss_ext_sales_price) as sales, - sum(coalesce(sr_return_amt, 0)) as returns, - sum(ss_net_profit - coalesce(sr_net_loss, 0)) as profit - from store_sales left outer join store_returns on - (ss_item_sk = sr_item_sk and ss_ticket_number = sr_ticket_number), - date_dim, - store, - item, - promotion - where ss_sold_date_sk = d_date_sk - and d_date between cast('1999-08-21' as date) - and dateadd(day,30,cast('1999-08-21' as date)) - and ss_store_sk = s_store_sk - and ss_item_sk = i_item_sk - and i_current_price > 50 - and ss_promo_sk = p_promo_sk - and p_channel_tv = 'N' - group by s_store_id) - , - csr as - (select cp_catalog_page_id as catalog_page_id, - sum(cs_ext_sales_price) as sales, - sum(coalesce(cr_return_amount, 0)) as returns, - sum(cs_net_profit - coalesce(cr_net_loss, 0)) as profit - from catalog_sales left outer join catalog_returns on - (cs_item_sk = cr_item_sk and cs_order_number = cr_order_number), - date_dim, - catalog_page, - item, - promotion - where cs_sold_date_sk = d_date_sk - and d_date between cast('1999-08-21' as date) - and dateadd(day,30,cast('1999-08-21' as date)) - and cs_catalog_page_sk = cp_catalog_page_sk - and cs_item_sk = i_item_sk - and i_current_price > 50 - and cs_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(ws_ext_sales_price) as sales, - sum(coalesce(wr_return_amt, 0)) as returns, - sum(ws_net_profit - coalesce(wr_net_loss, 0)) as profit - from web_sales left outer join web_returns on - (ws_item_sk = wr_item_sk and ws_order_number = wr_order_number), - date_dim, - web_site, - item, - promotion - where ws_sold_date_sk = d_date_sk - and d_date between cast('1999-08-21' as date) - and dateadd(day,30,cast('1999-08-21' as date)) - and ws_web_site_sk = web_site_sk - and ws_item_sk = i_item_sk - and i_current_price > 50 - and ws_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by web_site_id) -, -results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || store_id as id - , sales - , returns - , profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || catalog_page_id as id - , sales - , returns - , profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , profit - from wsr - ) x - group by channel, id) - - select channel - , id - , sales - , returns - , profit - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results - ) foo - order by channel, id - limit 100; - --- end template query80a.tpl query 16 in stream 6 --- start template query9.tpl query 17 in stream 6 -select /* TPC-DS query9.tpl 0.49 */ case when (select count(*) - from store_sales - where ss_quantity between 1 and 20) > 2407671397 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 1 and 20) - else (select avg(ss_net_profit) - from store_sales - where ss_quantity between 1 and 20) end bucket1 , - case when (select count(*) - from store_sales - where ss_quantity between 21 and 40) > 4528491357 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 21 and 40) - else (select avg(ss_net_profit) - from store_sales - where ss_quantity between 21 and 40) end bucket2, - case when (select count(*) - from store_sales - where ss_quantity between 41 and 60) > 4651586833 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 41 and 60) - else (select avg(ss_net_profit) - from store_sales - where ss_quantity between 41 and 60) end bucket3, - case when (select count(*) - from store_sales - where ss_quantity between 61 and 80) > 1272088001 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 61 and 80) - else (select avg(ss_net_profit) - from store_sales - where ss_quantity between 61 and 80) end bucket4, - case when (select count(*) - from store_sales - where ss_quantity between 81 and 100) > 1509011181 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 81 and 100) - else (select avg(ss_net_profit) - from store_sales - where ss_quantity between 81 and 100) end bucket5 -from reason -where r_reason_sk = 1 -; - --- end template query9.tpl query 17 in stream 6 --- start template query93.tpl query 18 in stream 6 -select /* TPC-DS query93.tpl 0.52 */ ss_customer_sk - ,sum(act_sales) sumsales - from (select ss_item_sk - ,ss_ticket_number - ,ss_customer_sk - ,case when sr_return_quantity is not null then (ss_quantity-sr_return_quantity)*ss_sales_price - else (ss_quantity*ss_sales_price) end act_sales - from store_sales left outer join store_returns on (sr_item_sk = ss_item_sk - and sr_ticket_number = ss_ticket_number) - ,reason - where sr_reason_sk = r_reason_sk - and r_reason_desc = 'Lost my job') t - group by ss_customer_sk - order by sumsales, ss_customer_sk -limit 100; - --- end template query93.tpl query 18 in stream 6 --- start template query32.tpl query 19 in stream 6 -select /* TPC-DS query32.tpl 0.7 */ sum(cs_ext_discount_amt) as "excess discount amount" -from - catalog_sales - ,item - ,date_dim -where -i_manufact_id = 54 -and i_item_sk = cs_item_sk -and d_date between '2000-02-15' and - dateadd(day,90,cast('2000-02-15' as date)) -and d_date_sk = cs_sold_date_sk -and cs_ext_discount_amt - > ( - select - 1.3 * avg(cs_ext_discount_amt) - from - catalog_sales - ,date_dim - where - cs_item_sk = i_item_sk - and d_date between '2000-02-15' and - dateadd(day,90,cast('2000-02-15' as date)) - and d_date_sk = cs_sold_date_sk - ) -limit 100; - --- end template query32.tpl query 19 in stream 6 --- start template query89.tpl query 20 in stream 6 -select /* TPC-DS query89.tpl 0.56 */ * -from( -select i_category, i_class, i_brand, - s_store_name, s_company_name, - d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, s_store_name, s_company_name) - avg_monthly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - d_year in (1999) and - ((i_category in ('Men','Books','Women') and - i_class in ('shirts','home repair','fragrances') - ) - or (i_category in ('Music','Jewelry','Electronics') and - i_class in ('classical','diamonds','scanners') - )) -group by i_category, i_class, i_brand, - s_store_name, s_company_name, d_moy) tmp1 -where case when (avg_monthly_sales <> 0) then (abs(sum_sales - avg_monthly_sales) / avg_monthly_sales) else null end > 0.1 -order by sum_sales - avg_monthly_sales, s_store_name -limit 100; - --- end template query89.tpl query 20 in stream 6 --- start template query28.tpl query 21 in stream 6 -select /* TPC-DS query28.tpl 0.36 */ * -from (select avg(ss_list_price) B1_LP - ,count(ss_list_price) B1_CNT - ,count(distinct ss_list_price) B1_CNTD - from store_sales - where ss_quantity between 0 and 5 - and (ss_list_price between 46 and 46+10 - or ss_coupon_amt between 875 and 875+1000 - or ss_wholesale_cost between 16 and 16+20)) B1, - (select avg(ss_list_price) B2_LP - ,count(ss_list_price) B2_CNT - ,count(distinct ss_list_price) B2_CNTD - from store_sales - where ss_quantity between 6 and 10 - and (ss_list_price between 168 and 168+10 - or ss_coupon_amt between 1830 and 1830+1000 - or ss_wholesale_cost between 14 and 14+20)) B2, - (select avg(ss_list_price) B3_LP - ,count(ss_list_price) B3_CNT - ,count(distinct ss_list_price) B3_CNTD - from store_sales - where ss_quantity between 11 and 15 - and (ss_list_price between 141 and 141+10 - or ss_coupon_amt between 12733 and 12733+1000 - or ss_wholesale_cost between 0 and 0+20)) B3, - (select avg(ss_list_price) B4_LP - ,count(ss_list_price) B4_CNT - ,count(distinct ss_list_price) B4_CNTD - from store_sales - where ss_quantity between 16 and 20 - and (ss_list_price between 176 and 176+10 - or ss_coupon_amt between 339 and 339+1000 - or ss_wholesale_cost between 45 and 45+20)) B4, - (select avg(ss_list_price) B5_LP - ,count(ss_list_price) B5_CNT - ,count(distinct ss_list_price) B5_CNTD - from store_sales - where ss_quantity between 21 and 25 - and (ss_list_price between 127 and 127+10 - or ss_coupon_amt between 7123 and 7123+1000 - or ss_wholesale_cost between 42 and 42+20)) B5, - (select avg(ss_list_price) B6_LP - ,count(ss_list_price) B6_CNT - ,count(distinct ss_list_price) B6_CNTD - from store_sales - where ss_quantity between 26 and 30 - and (ss_list_price between 190 and 190+10 - or ss_coupon_amt between 11706 and 11706+1000 - or ss_wholesale_cost between 1 and 1+20)) B6 -limit 100; - --- end template query28.tpl query 21 in stream 6 --- start template query87.tpl query 22 in stream 6 -select /* TPC-DS query87.tpl 0.77 */ count(*) -from ((select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1205 and 1205+11) - except - (select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1205 and 1205+11) - except - (select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1205 and 1205+11) -) cool_cust -; - --- end template query87.tpl query 22 in stream 6 --- start template query18a.tpl query 23 in stream 6 -with /* TPC-DS query18a.tpl 0.90 */ results as - (select i_item_id, - ca_country, - ca_state, - ca_county, - cast(cs_quantity as decimal(12,2)) agg1, - cast(cs_list_price as decimal(12,2)) agg2, - cast(cs_coupon_amt as decimal(12,2)) agg3, - cast(cs_sales_price as decimal(12,2)) agg4, - cast(cs_net_profit as decimal(12,2)) agg5, - cast(c_birth_year as decimal(12,2)) agg6, - cast(cd1.cd_dep_count as decimal(12,2)) agg7 - from catalog_sales, customer_demographics cd1, customer_demographics cd2, customer, customer_address, date_dim, item - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd1.cd_demo_sk and - cs_bill_customer_sk = c_customer_sk and - cd1.cd_gender = 'F' and - cd1.cd_education_status = 'Advanced Degree' and - c_current_cdemo_sk = cd2.cd_demo_sk and - c_current_addr_sk = ca_address_sk and - c_birth_month in (3,9,6,11,1,5) and - d_year = 2002 and - ca_state in ('IN','IA','NE','MO','TX','OK','GA') - ) - select i_item_id, ca_country, ca_state, ca_county, agg1, agg2, agg3, agg4, agg5, agg6, agg7 - from ( - select i_item_id, ca_country, ca_state, ca_county, avg(agg1) agg1, - avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state, ca_county - union all - select i_item_id, ca_country, ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state - union all - select i_item_id, ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country - union all - select i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - ) foo - order by ca_country, ca_state, ca_county, i_item_id - limit 100; - --- end template query18a.tpl query 23 in stream 6 --- start template query74.tpl query 24 in stream 6 -with /* TPC-DS query74.tpl 0.76 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,max(ss_net_paid) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (2000,2000+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,max(ws_net_paid) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - and d_year in (2000,2000+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - ) - select - t_s_secyear.customer_id, t_s_secyear.customer_first_name, t_s_secyear.customer_last_name - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.year = 2000 - and t_s_secyear.year = 2000+1 - and t_w_firstyear.year = 2000 - and t_w_secyear.year = 2000+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - order by 1,3,2 -limit 100; - --- end template query74.tpl query 24 in stream 6 --- start template query6.tpl query 25 in stream 6 -select /* TPC-DS query6.tpl 0.58 */ a.ca_state state, count(*) cnt - from customer_address a - ,customer c - ,store_sales s - ,date_dim d - ,item i - where a.ca_address_sk = c.c_current_addr_sk - and c.c_customer_sk = s.ss_customer_sk - and s.ss_sold_date_sk = d.d_date_sk - and s.ss_item_sk = i.i_item_sk - and d.d_month_seq = - (select distinct (d_month_seq) - from date_dim - where d_year = 1999 - and d_moy = 6 ) - and i.i_current_price > 1.2 * - (select avg(j.i_current_price) - from item j - where j.i_category = i.i_category) - group by a.ca_state - having count(*) >= 10 - order by cnt, a.ca_state - limit 100; - --- end template query6.tpl query 25 in stream 6 --- start template query65.tpl query 26 in stream 6 -select /* TPC-DS query65.tpl 0.71 */ - s_store_name, - i_item_desc, - sc.revenue, - i_current_price, - i_wholesale_cost, - i_brand - from store, item, - (select ss_store_sk, avg(revenue) as ave - from - (select ss_store_sk, ss_item_sk, - sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1179 and 1179+11 - group by ss_store_sk, ss_item_sk) sa - group by ss_store_sk) sb, - (select ss_store_sk, ss_item_sk, sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1179 and 1179+11 - group by ss_store_sk, ss_item_sk) sc - where sb.ss_store_sk = sc.ss_store_sk and - sc.revenue <= 0.1 * sb.ave and - s_store_sk = sc.ss_store_sk and - i_item_sk = sc.ss_item_sk - order by s_store_name, i_item_desc -limit 100; - --- end template query65.tpl query 26 in stream 6 --- start template query84.tpl query 27 in stream 6 -select /* TPC-DS query84.tpl 0.80 */ c_customer_id as customer_id - , coalesce(c_last_name,'') || ', ' || coalesce(c_first_name,'') as customername - from customer - ,customer_address - ,customer_demographics - ,household_demographics - ,income_band - ,store_returns - where ca_city = 'Union' - and c_current_addr_sk = ca_address_sk - and ib_lower_bound >= 38655 - and ib_upper_bound <= 38655 + 50000 - and ib_income_band_sk = hd_income_band_sk - and cd_demo_sk = c_current_cdemo_sk - and hd_demo_sk = c_current_hdemo_sk - and sr_cdemo_sk = cd_demo_sk - order by c_customer_id - limit 100; - --- end template query84.tpl query 27 in stream 6 --- start template query14a.tpl query 28 in stream 6 -with /* TPC-DS query14a.tpl 0.69 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1999 AND 1999 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1999 AND 1999 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1999 AND 1999 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as - (select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2) x) -, - results AS -(select channel, i_brand_id, i_class_id, i_category_id, sum(sales) sum_sales, sum(number_sales) number_sales - from ( - select 'store' channel, i_brand_id,i_class_id - ,i_category_id,sum(ss_quantity*ss_list_price) sales - , count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1999+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales) - union all - select 'catalog' channel, i_brand_id,i_class_id,i_category_id, sum(cs_quantity*cs_list_price) sales, count(*) number_sales - from catalog_sales - ,item - ,date_dim - where cs_item_sk in (select ss_item_sk from cross_items) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1999+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(cs_quantity*cs_list_price) > (select average_sales from avg_sales) - union all - select 'web' channel, i_brand_id,i_class_id,i_category_id, sum(ws_quantity*ws_list_price) sales , count(*) number_sales - from web_sales - ,item - ,date_dim - where ws_item_sk in (select ss_item_sk from cross_items) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1999+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ws_quantity*ws_list_price) > (select average_sales from avg_sales) - ) y - group by channel, i_brand_id,i_class_id,i_category_id) - - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales -from ( - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales from results - union - select channel, i_brand_id, i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id, i_class_id - union - select channel, i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id - union - select channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel - union - select null as channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results) z -order by channel, i_brand_id, i_class_id, i_category_id - limit 100; -with /* TPC-DS query14a.tpl 0.69 part2 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1999 AND 1999 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1999 AND 1999 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1999 AND 1999 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as -(select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2) x) - select this_year.channel ty_channel - ,this_year.i_brand_id ty_brand - ,this_year.i_class_id ty_class - ,this_year.i_category_id ty_category - ,this_year.sales ty_sales - ,this_year.number_sales ty_number_sales - ,last_year.channel ly_channel - ,last_year.i_brand_id ly_brand - ,last_year.i_class_id ly_class - ,last_year.i_category_id ly_category - ,last_year.sales ly_sales - ,last_year.number_sales ly_number_sales -from - (select 'store' channel, i_brand_id,i_class_id,i_category_id - ,sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1999 + 1 - and d_moy = 12 - and d_dom = 13) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) this_year, - (select 'store' channel, i_brand_id,i_class_id - ,i_category_id, sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1999 - and d_moy = 12 - and d_dom = 13) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) last_year - where this_year.i_brand_id= last_year.i_brand_id - and this_year.i_class_id = last_year.i_class_id - and this_year.i_category_id = last_year.i_category_id - order by this_year.channel, this_year.i_brand_id, this_year.i_class_id, this_year.i_category_id - limit 100; - --- end template query14a.tpl query 28 in stream 6 --- start template query38.tpl query 29 in stream 6 -select /* TPC-DS query38.tpl 0.54 */ count(*) from ( - select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1180 and 1180 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1180 and 1180 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1180 and 1180 + 11 -) hot_cust -limit 100; - --- end template query38.tpl query 29 in stream 6 --- start template query24.tpl query 30 in stream 6 -with /* TPC-DS query24.tpl 0.92 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_sales_price) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip -and s_market_id=9 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'lace' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; -with /* TPC-DS query24.tpl 0.92 part2 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_sales_price) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip - and s_market_id = 9 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'black' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; - --- end template query24.tpl query 30 in stream 6 --- start template query42.tpl query 31 in stream 6 -select /* TPC-DS query42.tpl 0.61 */ dt.d_year - ,item.i_category_id - ,item.i_category - ,sum(ss_ext_sales_price) - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=11 - and dt.d_year=2001 - group by dt.d_year - ,item.i_category_id - ,item.i_category - order by sum(ss_ext_sales_price) desc,dt.d_year - ,item.i_category_id - ,item.i_category -limit 100 ; - --- end template query42.tpl query 31 in stream 6 --- start template query29.tpl query 32 in stream 6 -select /* TPC-DS query29.tpl 0.53 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,min(ss_quantity) as store_sales_quantity - ,min(sr_return_quantity) as store_returns_quantity - ,min(cs_quantity) as catalog_sales_quantity - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 1998 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 4 + 3 - and d2.d_year = 1998 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_year in (1998,1998+1,1998+2) - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query29.tpl query 32 in stream 6 --- start template query72.tpl query 33 in stream 6 -select /* TPC-DS query72.tpl 0.87 */ i_item_desc - ,w_warehouse_name - ,d1.d_week_seq - ,sum(case when p_promo_sk is null then 1 else 0 end) no_promo - ,sum(case when p_promo_sk is not null then 1 else 0 end) promo - ,count(*) total_cnt -from catalog_sales -join inventory on (cs_item_sk = inv_item_sk) -join warehouse on (w_warehouse_sk=inv_warehouse_sk) -join item on (i_item_sk = cs_item_sk) -join customer_demographics on (cs_bill_cdemo_sk = cd_demo_sk) -join household_demographics on (cs_bill_hdemo_sk = hd_demo_sk) -join date_dim d1 on (cs_sold_date_sk = d1.d_date_sk) -join date_dim d2 on (inv_date_sk = d2.d_date_sk) -join date_dim d3 on (cs_ship_date_sk = d3.d_date_sk) -left outer join promotion on (cs_promo_sk=p_promo_sk) -left outer join catalog_returns on (cr_item_sk = cs_item_sk and cr_order_number = cs_order_number) -where d1.d_week_seq = d2.d_week_seq - and inv_quantity_on_hand < cs_quantity - and d3.d_date > d1.d_date + 5 - and hd_buy_potential = '501-1000' - and d1.d_year = 2001 - and cd_marital_status = 'U' -group by i_item_desc,w_warehouse_name,d1.d_week_seq -order by total_cnt desc, i_item_desc, w_warehouse_name, d_week_seq -limit 100; - --- end template query72.tpl query 33 in stream 6 --- start template query23.tpl query 34 in stream 6 -with /* TPC-DS query23.tpl 0.68 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (2000,2000+1,2000+2,2000+3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (2000,2000+1,2000+2,2000+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * -from - max_store_sales)) - select sum(sales) - from (select cs_quantity*cs_list_price sales - from catalog_sales - ,date_dim - where d_year = 2000 - and d_moy = 3 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - union all - select ws_quantity*ws_list_price sales - from web_sales - ,date_dim - where d_year = 2000 - and d_moy = 3 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer)) - limit 100; -with /* TPC-DS query23.tpl 0.68 part2 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (2000,2000 + 1,2000 + 2,2000 + 3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (2000,2000+1,2000+2,2000+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * - from max_store_sales)) - select c_last_name,c_first_name,sales - from (select c_last_name,c_first_name,sum(cs_quantity*cs_list_price) sales - from catalog_sales - ,customer - ,date_dim - where d_year = 2000 - and d_moy = 3 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and cs_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name - union all - select c_last_name,c_first_name,sum(ws_quantity*ws_list_price) sales - from web_sales - ,customer - ,date_dim - where d_year = 2000 - and d_moy = 3 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and ws_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name) - order by c_last_name,c_first_name,sales - limit 100; - --- end template query23.tpl query 34 in stream 6 --- start template query26.tpl query 35 in stream 6 -select /* TPC-DS query26.tpl 0.85 */ i_item_id, - avg(cs_quantity) agg1, - avg(cs_list_price) agg2, - avg(cs_coupon_amt) agg3, - avg(cs_sales_price) agg4 - from catalog_sales, customer_demographics, date_dim, item, promotion - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd_demo_sk and - cs_promo_sk = p_promo_sk and - cd_gender = 'F' and - cd_marital_status = 'W' and - cd_education_status = 'College' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 2002 - group by i_item_id - order by i_item_id - limit 100; - --- end template query26.tpl query 35 in stream 6 --- start template query69.tpl query 36 in stream 6 -select /* TPC-DS query69.tpl 0.28 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_state in ('SC','NY','ME') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2004 and - d_moy between 1 and 1+2) and - (not exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2004 and - d_moy between 1 and 1+2) and - not exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2004 and - d_moy between 1 and 1+2)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - limit 100; - --- end template query69.tpl query 36 in stream 6 --- start template query47.tpl query 37 in stream 6 -with /* TPC-DS query47.tpl 0.42 */ v1 as( - select i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, - s_store_name, s_company_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - s_store_name, s_company_name - order by d_year, d_moy) rn - from item, store_sales, date_dim, store - where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - ( - d_year = 2000 or - ( d_year = 2000-1 and d_moy =12) or - ( d_year = 2000+1 and d_moy =1) - ) - group by i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy), - v2 as( - select v1.s_store_name - ,v1.d_year - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1.s_store_name = v1_lag.s_store_name and - v1.s_store_name = v1_lead.s_store_name and - v1.s_company_name = v1_lag.s_company_name and - v1.s_company_name = v1_lead.s_company_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 2000 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, psum - limit 100; - --- end template query47.tpl query 37 in stream 6 --- start template query82.tpl query 38 in stream 6 -select /* TPC-DS query82.tpl 0.67 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, store_sales - where i_current_price between 22 and 22+30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('1998-02-12' as date) and dateadd(day,60,cast('1998-02-12' as date)) - and i_manufact_id in (285,218,610,126) - and inv_quantity_on_hand between 100 and 500 - and ss_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query82.tpl query 38 in stream 6 --- start template query31.tpl query 39 in stream 6 -with /* TPC-DS query31.tpl 0.50 */ ss as - (select ca_county,d_qoy, d_year,sum(ss_ext_sales_price) as store_sales - from store_sales,date_dim,customer_address - where ss_sold_date_sk = d_date_sk - and ss_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year), - ws as - (select ca_county,d_qoy, d_year,sum(ws_ext_sales_price) as web_sales - from web_sales,date_dim,customer_address - where ws_sold_date_sk = d_date_sk - and ws_bill_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year) - select - ss1.ca_county - ,ss1.d_year - ,ws2.web_sales/ws1.web_sales web_q1_q2_increase - ,ss2.store_sales/ss1.store_sales store_q1_q2_increase - ,ws3.web_sales/ws2.web_sales web_q2_q3_increase - ,ss3.store_sales/ss2.store_sales store_q2_q3_increase - from - ss ss1 - ,ss ss2 - ,ss ss3 - ,ws ws1 - ,ws ws2 - ,ws ws3 - where - ss1.d_qoy = 1 - and ss1.d_year = 2000 - and ss1.ca_county = ss2.ca_county - and ss2.d_qoy = 2 - and ss2.d_year = 2000 - and ss2.ca_county = ss3.ca_county - and ss3.d_qoy = 3 - and ss3.d_year = 2000 - and ss1.ca_county = ws1.ca_county - and ws1.d_qoy = 1 - and ws1.d_year = 2000 - and ws1.ca_county = ws2.ca_county - and ws2.d_qoy = 2 - and ws2.d_year = 2000 - and ws1.ca_county = ws3.ca_county - and ws3.d_qoy = 3 - and ws3.d_year =2000 - and case when ws1.web_sales > 0 then ws2.web_sales/ws1.web_sales else null end - > case when ss1.store_sales > 0 then ss2.store_sales/ss1.store_sales else null end - and case when ws2.web_sales > 0 then ws3.web_sales/ws2.web_sales else null end - > case when ss2.store_sales > 0 then ss3.store_sales/ss2.store_sales else null end - order by ss1.d_year; - --- end template query31.tpl query 39 in stream 6 --- start template query59.tpl query 40 in stream 6 -with /* TPC-DS query59.tpl 0.30 */ wss as - (select d_week_seq, - ss_store_sk, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - group by d_week_seq,ss_store_sk - ) - select s_store_name1,s_store_id1,d_week_seq1 - ,sun_sales1/sun_sales2,mon_sales1/mon_sales2 - ,tue_sales1/tue_sales2,wed_sales1/wed_sales2,thu_sales1/thu_sales2 - ,fri_sales1/fri_sales2,sat_sales1/sat_sales2 - from - (select s_store_name s_store_name1,wss.d_week_seq d_week_seq1 - ,s_store_id s_store_id1,sun_sales sun_sales1 - ,mon_sales mon_sales1,tue_sales tue_sales1 - ,wed_sales wed_sales1,thu_sales thu_sales1 - ,fri_sales fri_sales1,sat_sales sat_sales1 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1185 and 1185 + 11) y, - (select s_store_name s_store_name2,wss.d_week_seq d_week_seq2 - ,s_store_id s_store_id2,sun_sales sun_sales2 - ,mon_sales mon_sales2,tue_sales tue_sales2 - ,wed_sales wed_sales2,thu_sales thu_sales2 - ,fri_sales fri_sales2,sat_sales sat_sales2 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1185+ 12 and 1185 + 23) x - where s_store_id1=s_store_id2 - and d_week_seq1=d_week_seq2-52 - order by s_store_name1,s_store_id1,d_week_seq1 -limit 100; - --- end template query59.tpl query 40 in stream 6 --- start template query49.tpl query 41 in stream 6 -select /* TPC-DS query49.tpl 0.48 */ channel, item, return_ratio, return_rank, currency_rank from - (select - 'web' as channel - ,web.item - ,web.return_ratio - ,web.return_rank - ,web.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select ws.ws_item_sk as item - ,(cast(sum(coalesce(wr.wr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(wr.wr_return_amt,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - web_sales ws left outer join web_returns wr - on (ws.ws_order_number = wr.wr_order_number and - ws.ws_item_sk = wr.wr_item_sk) - ,date_dim - where - wr.wr_return_amt > 10000 - and ws.ws_net_profit > 1 - and ws.ws_net_paid > 0 - and ws.ws_quantity > 0 - and ws_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 11 - group by ws.ws_item_sk - ) in_web - ) web - where - ( - web.return_rank <= 10 - or - web.currency_rank <= 10 - ) - union - select - 'catalog' as channel - ,catalog.item - ,catalog.return_ratio - ,catalog.return_rank - ,catalog.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select - cs.cs_item_sk as item - ,(cast(sum(coalesce(cr.cr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(cr.cr_return_amount,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - catalog_sales cs left outer join catalog_returns cr - on (cs.cs_order_number = cr.cr_order_number and - cs.cs_item_sk = cr.cr_item_sk) - ,date_dim - where - cr.cr_return_amount > 10000 - and cs.cs_net_profit > 1 - and cs.cs_net_paid > 0 - and cs.cs_quantity > 0 - and cs_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 11 - group by cs.cs_item_sk - ) in_cat - ) catalog - where - ( - catalog.return_rank <= 10 - or - catalog.currency_rank <=10 - ) - union - select - 'store' as channel - ,store.item - ,store.return_ratio - ,store.return_rank - ,store.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select sts.ss_item_sk as item - ,(cast(sum(coalesce(sr.sr_return_quantity,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(sr.sr_return_amt,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - store_sales sts left outer join store_returns sr - on (sts.ss_ticket_number = sr.sr_ticket_number and sts.ss_item_sk = sr.sr_item_sk) - ,date_dim - where - sr.sr_return_amt > 10000 - and sts.ss_net_profit > 1 - and sts.ss_net_paid > 0 - and sts.ss_quantity > 0 - and ss_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 11 - group by sts.ss_item_sk - ) in_store - ) store - where ( - store.return_rank <= 10 - or - store.currency_rank <= 10 - ) - ) - order by 1,4,5,2 - limit 100; - --- end template query49.tpl query 41 in stream 6 --- start template query33.tpl query 42 in stream 6 -with /* TPC-DS query33.tpl 0.22 */ ss as ( - select - i_manufact_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Sports')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 5 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -7 - group by i_manufact_id), - cs as ( - select - i_manufact_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Sports')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 5 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -7 - group by i_manufact_id), - ws as ( - select - i_manufact_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Sports')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 5 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -7 - group by i_manufact_id) - select i_manufact_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_manufact_id - order by total_sales -limit 100; - --- end template query33.tpl query 42 in stream 6 --- start template query86a.tpl query 43 in stream 6 -with /* TPC-DS query86a.tpl 0.11 */ results as -( select sum(ws_net_paid) as total_sum, i_category, i_class, 0 as g_category, 0 as g_class - from - web_sales - ,date_dim d1 - ,item - where - d1.d_month_seq between 1213 and 1213+11 - and d1.d_date_sk = ws_sold_date_sk - and i_item_sk = ws_item_sk - group by i_category,i_class - ) , - - results_rollup as -( select total_sum ,i_category ,i_class, g_category, g_class, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum, i_category, NULL as i_class, 0 as g_category, 1 as g_class, 1 as lochierarchy from results group by i_category - union - select sum(total_sum) as total_sum, NULL as i_category, NULL as i_class, 1 as g_category, 1 as g_class, 2 as lochierarchy from results) - select - total_sum ,i_category ,i_class, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_class = 0 then i_category end - order by total_sum desc) as rank_within_parent - from - results_rollup - order by - lochierarchy desc, - case when lochierarchy = 0 then i_category end, - rank_within_parent - limit 100; - --- end template query86a.tpl query 43 in stream 6 --- start template query99.tpl query 44 in stream 6 -select /* TPC-DS query99.tpl 0.94 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 30) and - (cs_ship_date_sk - cs_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 60) and - (cs_ship_date_sk - cs_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 90) and - (cs_ship_date_sk - cs_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - catalog_sales - ,warehouse - ,ship_mode - ,call_center - ,date_dim -where - d_month_seq between 1189 and 1189 + 11 -and cs_ship_date_sk = d_date_sk -and cs_warehouse_sk = w_warehouse_sk -and cs_ship_mode_sk = sm_ship_mode_sk -and cs_call_center_sk = cc_call_center_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -limit 100; - --- end template query99.tpl query 44 in stream 6 --- start template query4.tpl query 45 in stream 6 -with /* TPC-DS query4.tpl 0.93 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(((ss_ext_list_price-ss_ext_wholesale_cost-ss_ext_discount_amt)+ss_ext_sales_price)/2) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((cs_ext_list_price-cs_ext_wholesale_cost-cs_ext_discount_amt)+cs_ext_sales_price)/2) ) year_total - ,'c' sale_type - from customer - ,catalog_sales - ,date_dim - where c_customer_sk = cs_bill_customer_sk - and cs_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year -union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((ws_ext_list_price-ws_ext_wholesale_cost-ws_ext_discount_amt)+ws_ext_sales_price)/2) ) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_login - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_c_firstyear - ,year_total t_c_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_c_secyear.customer_id - and t_s_firstyear.customer_id = t_c_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_c_firstyear.sale_type = 'c' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_c_secyear.sale_type = 'c' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 2000 - and t_s_secyear.dyear = 2000+1 - and t_c_firstyear.dyear = 2000 - and t_c_secyear.dyear = 2000+1 - and t_w_firstyear.dyear = 2000 - and t_w_secyear.dyear = 2000+1 - and t_s_firstyear.year_total > 0 - and t_c_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_login -limit 100; - --- end template query4.tpl query 45 in stream 6 --- start template query45.tpl query 46 in stream 6 -select /* TPC-DS query45.tpl 0.18 */ ca_zip, ca_city, sum(ws_sales_price) - from web_sales, customer, customer_address, date_dim, item - where ws_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ws_item_sk = i_item_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', '85392', '85460', '80348', '81792') - or - i_item_id in (select i_item_id - from item - where i_item_sk in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29) - ) - ) - and ws_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 1999 - group by ca_zip, ca_city - order by ca_zip, ca_city - limit 100; - --- end template query45.tpl query 46 in stream 6 --- start template query85.tpl query 47 in stream 6 -select /* TPC-DS query85.tpl 0.33 */ substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) - from web_sales, web_returns, web_page, customer_demographics cd1, - customer_demographics cd2, customer_address, date_dim, reason - where ws_web_page_sk = wp_web_page_sk - and ws_item_sk = wr_item_sk - and ws_order_number = wr_order_number - and ws_sold_date_sk = d_date_sk and d_year = 2001 - and cd1.cd_demo_sk = wr_refunded_cdemo_sk - and cd2.cd_demo_sk = wr_returning_cdemo_sk - and ca_address_sk = wr_refunded_addr_sk - and r_reason_sk = wr_reason_sk - and - ( - ( - cd1.cd_marital_status = 'S' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Advanced Degree' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 100.00 and 150.00 - ) - or - ( - cd1.cd_marital_status = 'D' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = '4 yr Degree' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 50.00 and 100.00 - ) - or - ( - cd1.cd_marital_status = 'M' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Secondary' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ca_country = 'United States' - and - ca_state in ('AL', 'NE', 'SD') - and ws_net_profit between 100 and 200 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('MS', 'FL', 'MO') - and ws_net_profit between 150 and 300 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('TX', 'ID', 'VA') - and ws_net_profit between 50 and 250 - ) - ) -group by r_reason_desc -order by substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) -limit 100; - --- end template query85.tpl query 47 in stream 6 --- start template query8.tpl query 48 in stream 6 -select /* TPC-DS query8.tpl 0.63 */ s_store_name - ,sum(ss_net_profit) - from store_sales - ,date_dim - ,store, - (select ca_zip - from ( - SELECT substring(ca_zip,1,5) ca_zip - FROM customer_address - WHERE substring(ca_zip,1,5) IN ( - '85714','11942','35853','37452','70262','61929', - '19817','62147','65058','21009','57620', - '81490','96277','89221','53007','25633', - '11729','37371','71299','22288','43576', - '82435','55156','49116','38969','59725', - '24600','98274','76815','29837','78780', - '14611','77386','91582','10801','77499', - '19117','39584','21443','66846','46302', - '89855','58654','38386','86955','13156', - '33525','34747','93990','64530','68690', - '19654','28827','50372','91855','11298', - '98877','32211','83298','47183','60447', - '58378','22393','56464','59769','52041', - '26061','78952','13105','95515','52962', - '26430','30480','14942','60892','59083', - '46937','29919','14724','16825','80087', - '43113','52513','61856','11334','20531', - '23034','38759','46672','44699','30126', - '79535','84351','28242','72365','87755', - '79767','80229','22240','81630','29767', - '85305','16659','28762','91865','95344', - '45016','30981','11609','99047','95549', - '55501','90987','37828','50453','84575', - '46908','90950','41135','84573','14086', - '16558','78613','54422','69902','68968', - '20799','65656','86101','90529','20124', - '72651','59342','87599','36430','69677', - '93702','99835','84328','76688','98740', - '66752','10855','29820','42140','64041', - '16393','31370','73263','12122','37044', - '44315','56752','22124','45185','14910', - '70014','62961','29880','41938','62534', - '14135','40763','76674','43692','94361', - '44264','14370','29031','31417','33143', - '54245','47576','77182','36577','40088', - '33253','92062','25482','22358','43817', - '49632','16728','66208','48603','12424', - '92505','61952','76503','10503','88548', - '30870','32651','30071','70921','28434', - '15994','64671','42217','27238','79728', - '50730','92947','58093','84010','67631', - '51443','11585','56761','10399','36625', - '86569','49871','70053','85606','58692', - '87047','43429','56260','89471','66376', - '69450','81503','52143','10239','76302', - '25340','68388','53594','43599','40057', - '34305','34513','16803','62584','42999', - '77368','29803','83672','86997','88896', - '11714','52129','42942','55881','93633', - '99760','55044','32557','80860','54355', - '32951','80025','49174','69364','60979', - '76383','95958','71774','17972','47671', - '99069','34836','91458','23232','34268', - '46709','18125','58648','98572','29627', - '21876','11937','52480','90618','22800', - '74778','43235','69405','22228','10835', - '22259','81729','87946','95818','73230', - '94433','70977','87679','89655','34085', - '12345','39686','28297','95614','92503', - '37992','48421','23311','36001','67844', - '56088','68314','93900','49773','59816', - '20264','88702','84236','32634','69203', - '24119','90916','83043','89467','10401', - '42453','16219','77206','67732','89538', - '40935','28394','60680','49248','47503', - '87960','17357','44408','32698','18955', - '75851','43669','32288','49302','39499', - '90255','61137','83654','10036','55716', - '14388','11810','87977','57284','28661', - '13718','95740','89351','77769','27169', - '76993','67029','73888','47780','27845', - '54952','77806','92462','40954','88211', - '61448','32506','29325','58148','58947', - '43500','45708','69801','77902','41286', - '34022','24973','35937','53343','68007', - '84748','74820','57675','71437','60839', - '27448','33225','80574','55117','23109', - '26814','27562','80019','45647','45428', - '32459','73279','10976','87805','34766', - '55013','11820','63775','33542') - intersect - select ca_zip - from (SELECT substring(ca_zip,1,5) ca_zip,count(*) cnt - FROM customer_address, customer - WHERE ca_address_sk = c_current_addr_sk and - c_preferred_cust_flag='Y' - group by ca_zip - having count(*) > 10)A1)A2) V1 - where ss_store_sk = s_store_sk - and ss_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 1999 - and (substring(s_zip,1,2) = substring(V1.ca_zip,1,2)) - group by s_store_name - order by s_store_name - limit 100; - --- end template query8.tpl query 48 in stream 6 --- start template query19.tpl query 49 in stream 6 -select /* TPC-DS query19.tpl 0.8 */ i_brand_id brand_id, i_brand brand, i_manufact_id, i_manufact, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item,customer,customer_address,store - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=21 - and d_moy=11 - and d_year=1998 - and ss_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and substring(ca_zip,1,5) <> substring(s_zip,1,5) - and ss_store_sk = s_store_sk - group by i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact - order by ext_price desc - ,i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact -limit 100 ; - --- end template query19.tpl query 49 in stream 6 --- start template query61.tpl query 50 in stream 6 -select /* TPC-DS query61.tpl 0.97 */ promotions,total,cast(promotions as decimal(16,4))/cast(total as decimal(16,4))*100 -from - (select sum(ss_ext_sales_price) promotions - from store_sales - ,store - ,promotion - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_promo_sk = p_promo_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -7 - and i_category = 'Jewelry' - and (p_channel_dmail = 'Y' or p_channel_email = 'Y' or p_channel_tv = 'Y') - and s_gmt_offset = -7 - and d_year = 2002 - and d_moy = 11) promotional_sales, - (select sum(ss_ext_sales_price) total - from store_sales - ,store - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -7 - and i_category = 'Jewelry' - and s_gmt_offset = -7 - and d_year = 2002 - and d_moy = 11) all_sales -order by promotions, total -limit 100; - --- end template query61.tpl query 50 in stream 6 --- start template query3.tpl query 51 in stream 6 -select /* TPC-DS query3.tpl 0.45 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_discount_amt) sum_agg - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manufact_id = 345 - and dt.d_moy=12 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,sum_agg desc - ,brand_id - limit 100; - --- end template query3.tpl query 51 in stream 6 --- start template query41.tpl query 52 in stream 6 -select /* TPC-DS query41.tpl 0.62 */ distinct(i_product_name) - from item i1 - where i_manufact_id between 825 and 825+40 - and (select count(*) as item_cnt - from item - where (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'almond' or i_color = 'linen') and - (i_units = 'Bundle' or i_units = 'Cup') and - (i_size = 'economy' or i_size = 'N/A') - ) or - (i_category = 'Women' and - (i_color = 'chocolate' or i_color = 'peru') and - (i_units = 'Carton' or i_units = 'Oz') and - (i_size = 'extra large' or i_size = 'petite') - ) or - (i_category = 'Men' and - (i_color = 'forest' or i_color = 'orange') and - (i_units = 'Case' or i_units = 'Ounce') and - (i_size = 'large' or i_size = 'small') - ) or - (i_category = 'Men' and - (i_color = 'deep' or i_color = 'hot') and - (i_units = 'Gross' or i_units = 'Ton') and - (i_size = 'economy' or i_size = 'N/A') - ))) or - (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'chiffon' or i_color = 'floral') and - (i_units = 'Unknown' or i_units = 'Tbl') and - (i_size = 'economy' or i_size = 'N/A') - ) or - (i_category = 'Women' and - (i_color = 'beige' or i_color = 'ivory') and - (i_units = 'Tsp' or i_units = 'Pallet') and - (i_size = 'extra large' or i_size = 'petite') - ) or - (i_category = 'Men' and - (i_color = 'blanched' or i_color = 'burnished') and - (i_units = 'Bunch' or i_units = 'Pound') and - (i_size = 'large' or i_size = 'small') - ) or - (i_category = 'Men' and - (i_color = 'peach' or i_color = 'honeydew') and - (i_units = 'Gram' or i_units = 'Box') and - (i_size = 'economy' or i_size = 'N/A') - )))) > 0 - order by i_product_name - limit 100; - --- end template query41.tpl query 52 in stream 6 --- start template query54.tpl query 53 in stream 6 -with /* TPC-DS query54.tpl 0.81 */ my_customers as ( - select distinct c_customer_sk - , c_current_addr_sk - from - ( select cs_sold_date_sk sold_date_sk, - cs_bill_customer_sk customer_sk, - cs_item_sk item_sk - from catalog_sales - union all - select ws_sold_date_sk sold_date_sk, - ws_bill_customer_sk customer_sk, - ws_item_sk item_sk - from web_sales - ) cs_or_ws_sales, - item, - date_dim, - customer - where sold_date_sk = d_date_sk - and item_sk = i_item_sk - and i_category = 'Women' - and i_class = 'dresses' - and c_customer_sk = cs_or_ws_sales.customer_sk - and d_moy = 1 - and d_year = 2001 - ) - , my_revenue as ( - select c_customer_sk, - sum(ss_ext_sales_price) as revenue - from my_customers, - store_sales, - customer_address, - store, - date_dim - where c_current_addr_sk = ca_address_sk - and ca_county = s_county - and ca_state = s_state - and ss_sold_date_sk = d_date_sk - and c_customer_sk = ss_customer_sk - and d_month_seq between (select distinct d_month_seq+1 - from date_dim where d_year = 2001 and d_moy = 1) - and (select distinct d_month_seq+3 - from date_dim where d_year = 2001 and d_moy = 1) - group by c_customer_sk - ) - , segments as - (select cast((revenue/50) as bigint) as segment - from my_revenue - ) - select segment, count(*) as num_customers, segment*50 as segment_base - from segments - group by segment - order by segment, num_customers - limit 100; - --- end template query54.tpl query 53 in stream 6 --- start template query67a.tpl query 54 in stream 6 -with /* TPC-DS query67a.tpl 0.35 */ results as -( select i_category ,i_class ,i_brand ,i_product_name ,d_year ,d_qoy ,d_moy ,s_store_id - ,sum(coalesce(ss_sales_price*ss_quantity,0)) sumsales - from store_sales ,date_dim ,store ,item - where ss_sold_date_sk=d_date_sk - and ss_item_sk=i_item_sk - and ss_store_sk = s_store_sk - and d_month_seq between 1203 and 1203 + 11 - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy,s_store_id) - , - results_rollup as - (select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, s_store_id, sumsales - from results - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy - union all - select i_category, i_class, i_brand, i_product_name, d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year - union all - select i_category, i_class, i_brand, i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name - union all - select i_category, i_class, i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand - union all - select i_category, i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class - union all - select i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category - union all - select null i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results) - - select * -from (select i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rank() over (partition by i_category order by sumsales desc) rk - from results_rollup) dw2 -where rk <= 100 -order by i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rk -limit 100; - --- end template query67a.tpl query 54 in stream 6 --- start template query77a.tpl query 55 in stream 6 -with /* TPC-DS query77a.tpl 0.78 */ ss as - (select s_store_sk, - sum(ss_ext_sales_price) as sales, - sum(ss_net_profit) as profit - from store_sales, - date_dim, - store - where ss_sold_date_sk = d_date_sk - and d_date between cast('2000-08-04' as date) - and dateadd(day,30,cast('2000-08-04' as date)) - and ss_store_sk = s_store_sk - group by s_store_sk) - , - sr as - (select s_store_sk, - sum(sr_return_amt) as returns, - sum(sr_net_loss) as profit_loss - from store_returns, - date_dim, - store - where sr_returned_date_sk = d_date_sk - and d_date between cast('2000-08-04' as date) - and dateadd(day,30,cast('2000-08-04' as date)) - and sr_store_sk = s_store_sk - group by s_store_sk), - cs as - (select cs_call_center_sk, - sum(cs_ext_sales_price) as sales, - sum(cs_net_profit) as profit - from catalog_sales, - date_dim - where cs_sold_date_sk = d_date_sk - and d_date between cast('2000-08-04' as date) - and dateadd(day,30,cast('2000-08-04' as date)) - group by cs_call_center_sk - ), - cr as - (select cr_call_center_sk, - sum(cr_return_amount) as returns, - sum(cr_net_loss) as profit_loss - from catalog_returns, - date_dim - where cr_returned_date_sk = d_date_sk - and d_date between cast('2000-08-04' as date) - and dateadd(day,30,cast('2000-08-04' as date)) - group by cr_call_center_sk), - ws as - ( select wp_web_page_sk, - sum(ws_ext_sales_price) as sales, - sum(ws_net_profit) as profit - from web_sales, - date_dim, - web_page - where ws_sold_date_sk = d_date_sk - and d_date between cast('2000-08-04' as date) - and dateadd(day,30,cast('2000-08-04' as date)) - and ws_web_page_sk = wp_web_page_sk - group by wp_web_page_sk), - wr as - (select wp_web_page_sk, - sum(wr_return_amt) as returns, - sum(wr_net_loss) as profit_loss - from web_returns, - date_dim, - web_page - where wr_returned_date_sk = d_date_sk - and d_date between cast('2000-08-04' as date) - and dateadd(day,30,cast('2000-08-04' as date)) - and wr_web_page_sk = wp_web_page_sk - group by wp_web_page_sk) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , ss.s_store_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ss left join sr - on ss.s_store_sk = sr.s_store_sk - union all - select 'catalog channel' as channel - , cs_call_center_sk as id - , sales - , returns - , (profit - profit_loss) as profit - from cs - , cr - union all - select 'web channel' as channel - , ws.wp_web_page_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ws left join wr - on ws.wp_web_page_sk = wr.wp_web_page_sk - ) x - group by channel, id ) - - select * - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results -) foo -order by channel, id - limit 100; - --- end template query77a.tpl query 55 in stream 6 --- start template query15.tpl query 56 in stream 6 -select /* TPC-DS query15.tpl 0.57 */ ca_zip - ,sum(cs_sales_price) - from catalog_sales - ,customer - ,customer_address - ,date_dim - where cs_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', - '85392', '85460', '80348', '81792') - or ca_state in ('CA','WA','GA') - or cs_sales_price > 500) - and cs_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 2000 - group by ca_zip - order by ca_zip - limit 100; - --- end template query15.tpl query 56 in stream 6 --- start template query51.tpl query 57 in stream 6 -WITH /* TPC-DS query51.tpl 0.46 */ web_v1 as ( -select - ws_item_sk item_sk, d_date, - sum(sum(ws_sales_price)) - over (partition by ws_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from web_sales - ,date_dim -where ws_sold_date_sk=d_date_sk - and d_month_seq between 1188 and 1188+11 - and ws_item_sk is not NULL -group by ws_item_sk, d_date), -store_v1 as ( -select - ss_item_sk item_sk, d_date, - sum(sum(ss_sales_price)) - over (partition by ss_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from store_sales - ,date_dim -where ss_sold_date_sk=d_date_sk - and d_month_seq between 1188 and 1188+11 - and ss_item_sk is not NULL -group by ss_item_sk, d_date) - select * -from (select item_sk - ,d_date - ,web_sales - ,store_sales - ,max(web_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) web_cumulative - ,max(store_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) store_cumulative - from (select case when web.item_sk is not null then web.item_sk else store.item_sk end item_sk - ,case when web.d_date is not null then web.d_date else store.d_date end d_date - ,web.cume_sales web_sales - ,store.cume_sales store_sales - from web_v1 web full outer join store_v1 store on (web.item_sk = store.item_sk - and web.d_date = store.d_date) - )x )y -where web_cumulative > store_cumulative -order by item_sk - ,d_date -limit 100; - --- end template query51.tpl query 57 in stream 6 --- start template query98.tpl query 58 in stream 6 -select /* TPC-DS query98.tpl 0.32 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ss_ext_sales_price) as itemrevenue - ,sum(ss_ext_sales_price)*100/sum(sum(ss_ext_sales_price)) over - (partition by i_class) as revenueratio -from - store_sales - ,item - ,date_dim -where - ss_item_sk = i_item_sk - and i_category in ('Jewelry', 'Children', 'Sports') - and ss_sold_date_sk = d_date_sk - and d_date between cast('1998-05-15' as date) - and dateadd(day,30,cast('1998-05-15' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio; - --- end template query98.tpl query 58 in stream 6 --- start template query62.tpl query 59 in stream 6 -select /* TPC-DS query62.tpl 0.24 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 30) and - (ws_ship_date_sk - ws_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 60) and - (ws_ship_date_sk - ws_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 90) and - (ws_ship_date_sk - ws_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - web_sales - ,warehouse - ,ship_mode - ,web_site - ,date_dim -where - d_month_seq between 1202 and 1202 + 11 -and ws_ship_date_sk = d_date_sk -and ws_warehouse_sk = w_warehouse_sk -and ws_ship_mode_sk = sm_ship_mode_sk -and ws_web_site_sk = web_site_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -limit 100; - --- end template query62.tpl query 59 in stream 6 --- start template query97.tpl query 60 in stream 6 -with /* TPC-DS query97.tpl 0.38 */ ssci as ( -select ss_customer_sk customer_sk - ,ss_item_sk item_sk -from store_sales,date_dim -where ss_sold_date_sk = d_date_sk - and d_month_seq between 1208 and 1208 + 11 -group by ss_customer_sk - ,ss_item_sk), -csci as( - select cs_bill_customer_sk customer_sk - ,cs_item_sk item_sk -from catalog_sales,date_dim -where cs_sold_date_sk = d_date_sk - and d_month_seq between 1208 and 1208 + 11 -group by cs_bill_customer_sk - ,cs_item_sk) - select sum(case when ssci.customer_sk is not null and csci.customer_sk is null then 1 else 0 end) store_only - ,sum(case when ssci.customer_sk is null and csci.customer_sk is not null then 1 else 0 end) catalog_only - ,sum(case when ssci.customer_sk is not null and csci.customer_sk is not null then 1 else 0 end) store_and_catalog -from ssci full outer join csci on (ssci.customer_sk=csci.customer_sk - and ssci.item_sk = csci.item_sk) -limit 100; - --- end template query97.tpl query 60 in stream 6 --- start template query22a.tpl query 61 in stream 6 -with /* TPC-DS query22a.tpl 0.55 */ results as -(select i_product_name - ,i_brand - ,i_class - ,i_category - ,avg(inv_quantity_on_hand) qoh - from inventory - ,date_dim - ,item --- ,warehouse - where inv_date_sk=d_date_sk - and inv_item_sk=i_item_sk --- and inv_warehouse_sk = w_warehouse_sk - and d_month_seq between 1212 and 1212 + 11 - group by i_product_name,i_brand,i_class,i_category), -results_rollup as -(select i_product_name, i_brand, i_class, i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class,i_category -union all -select i_product_name, i_brand, i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class -union all -select i_product_name, i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand -union all -select i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name -union all -select null i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results) - select i_product_name, i_brand, i_class, i_category,qoh - from results_rollup - order by qoh, i_product_name, i_brand, i_class, i_category -limit 100; - --- end template query22a.tpl query 61 in stream 6 --- start template query48.tpl query 62 in stream 6 -select /* TPC-DS query48.tpl 0.74 */ sum (ss_quantity) - from store_sales, store, customer_demographics, customer_address, date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 1999 - and - ( - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'S' - and - cd_education_status = 'Primary' - and - ss_sales_price between 100.00 and 150.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'U' - and - cd_education_status = '2 yr Degree' - and - ss_sales_price between 50.00 and 100.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'W' - and - cd_education_status = '4 yr Degree' - and - ss_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('ND', 'SD', 'OH') - and ss_net_profit between 0 and 2000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('GA', 'AL', 'MN') - and ss_net_profit between 150 and 3000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('MT', 'LA', 'WV') - and ss_net_profit between 50 and 25000 - ) - ) -; - --- end template query48.tpl query 62 in stream 6 --- start template query2.tpl query 63 in stream 6 -with /* TPC-DS query2.tpl 0.84 */ wscs as - (select sold_date_sk - ,sales_price - from (select ws_sold_date_sk sold_date_sk - ,ws_ext_sales_price sales_price - from web_sales - union all - select cs_sold_date_sk sold_date_sk - ,cs_ext_sales_price sales_price - from catalog_sales)), - wswscs as - (select d_week_seq, - sum(case when (d_day_name='Sunday') then sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then sales_price else null end) sat_sales - from wscs - ,date_dim - where d_date_sk = sold_date_sk - group by d_week_seq) - select d_week_seq1 - ,round(sun_sales1/sun_sales2,2) - ,round(mon_sales1/mon_sales2,2) - ,round(tue_sales1/tue_sales2,2) - ,round(wed_sales1/wed_sales2,2) - ,round(thu_sales1/thu_sales2,2) - ,round(fri_sales1/fri_sales2,2) - ,round(sat_sales1/sat_sales2,2) - from - (select wswscs.d_week_seq d_week_seq1 - ,sun_sales sun_sales1 - ,mon_sales mon_sales1 - ,tue_sales tue_sales1 - ,wed_sales wed_sales1 - ,thu_sales thu_sales1 - ,fri_sales fri_sales1 - ,sat_sales sat_sales1 - from wswscs,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 1999) y, - (select wswscs.d_week_seq d_week_seq2 - ,sun_sales sun_sales2 - ,mon_sales mon_sales2 - ,tue_sales tue_sales2 - ,wed_sales wed_sales2 - ,thu_sales thu_sales2 - ,fri_sales fri_sales2 - ,sat_sales sat_sales2 - from wswscs - ,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 1999+1) z - where d_week_seq1=d_week_seq2-53 - order by d_week_seq1; - --- end template query2.tpl query 63 in stream 6 --- start template query79.tpl query 64 in stream 6 -select /* TPC-DS query79.tpl 0.89 */ - c_last_name,c_first_name,substring(s_city,1,30),ss_ticket_number,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,store.s_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (household_demographics.hd_dep_count = 7 or household_demographics.hd_vehicle_count > 2) - and date_dim.d_dow = 1 - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_number_employees between 200 and 295 - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,store.s_city) ms,customer - where ss_customer_sk = c_customer_sk - order by c_last_name,c_first_name,substring(s_city,1,30), profit -limit 100; - --- end template query79.tpl query 64 in stream 6 --- start template query56.tpl query 65 in stream 6 -with /* TPC-DS query56.tpl 0.83 */ ss as ( - select i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where i_item_id in (select - i_item_id -from item -where i_color in ('thistle','cornsilk','cornflower')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 5 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -8 - group by i_item_id), - cs as ( - select i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('thistle','cornsilk','cornflower')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 5 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -8 - group by i_item_id), - ws as ( - select i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('thistle','cornsilk','cornflower')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 5 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -8 - group by i_item_id) - select i_item_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by total_sales, - i_item_id - limit 100; - --- end template query56.tpl query 65 in stream 6 --- start template query37.tpl query 66 in stream 6 -select /* TPC-DS query37.tpl 0.31 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, catalog_sales - where i_current_price between 14 and 14 + 30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('2002-07-16' as date) and dateadd(day,60,cast('2002-07-16' as date)) - and i_manufact_id in (797,849,795,923) - and inv_quantity_on_hand between 100 and 500 - and cs_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query37.tpl query 66 in stream 6 --- start template query10.tpl query 67 in stream 6 -select /* TPC-DS query10.tpl 0.26 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3, - cd_dep_count, - count(*) cnt4, - cd_dep_employed_count, - count(*) cnt5, - cd_dep_college_count, - count(*) cnt6 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_county in ('Tioga County','Perry County','Polk County','Angelina County','Grant County') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 1 and 1+3) and - (exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 1 ANd 1+3) or - exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 1 and 1+3)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count -limit 100; - --- end template query10.tpl query 67 in stream 6 --- start template query90.tpl query 68 in stream 6 -select /* TPC-DS query90.tpl 0.40 */ cast(amc as decimal(15,4))/cast(pmc as decimal(15,4)) am_pm_ratio - from ( select count(*) amc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 8 and 8+1 - and household_demographics.hd_dep_count = 5 - and web_page.wp_char_count between 5000 and 5200) at, - ( select count(*) pmc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 14 and 14+1 - and household_demographics.hd_dep_count = 5 - and web_page.wp_char_count between 5000 and 5200) pt - order by am_pm_ratio - limit 100; - --- end template query90.tpl query 68 in stream 6 --- start template query21.tpl query 69 in stream 6 -select /* TPC-DS query21.tpl 0.14 */ * - from(select w_warehouse_name - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('1999-02-08' as date)) - then inv_quantity_on_hand - else 0 end) as inv_before - ,sum(case when (cast(d_date as date) >= cast ('1999-02-08' as date)) - then inv_quantity_on_hand - else 0 end) as inv_after - from inventory - ,warehouse - ,item - ,date_dim - where i_current_price between 0.99 and 1.49 - and i_item_sk = inv_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('1999-02-08' as date)) - and dateadd(day,30,cast ('1999-02-08' as date)) - group by w_warehouse_name, i_item_id) x - where (case when inv_before > 0 - then inv_after / inv_before - else null - end) between 2.0/3.0 and 3.0/2.0 - order by w_warehouse_name - ,i_item_id - limit 100; - --- end template query21.tpl query 69 in stream 6 --- start template query46.tpl query 70 in stream 6 -select /* TPC-DS query46.tpl 0.23 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and (household_demographics.hd_dep_count = 9 or - household_demographics.hd_vehicle_count= 2) - and date_dim.d_dow in (6,0) - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_city in ('Slabtown','New Salem','Montrose','Upton','Verona') - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,ca_city) dn,customer,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - limit 100; - --- end template query46.tpl query 70 in stream 6 --- start template query83.tpl query 71 in stream 6 -with /* TPC-DS query83.tpl 0.96 */ sr_items as - (select i_item_id item_id, - sum(sr_return_quantity) sr_item_qty - from store_returns, - item, - date_dim - where sr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2002-04-18','2002-10-16','2002-11-03'))) - and sr_returned_date_sk = d_date_sk - group by i_item_id), - cr_items as - (select i_item_id item_id, - sum(cr_return_quantity) cr_item_qty - from catalog_returns, - item, - date_dim - where cr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2002-04-18','2002-10-16','2002-11-03'))) - and cr_returned_date_sk = d_date_sk - group by i_item_id), - wr_items as - (select i_item_id item_id, - sum(wr_return_quantity) wr_item_qty - from web_returns, - item, - date_dim - where wr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2002-04-18','2002-10-16','2002-11-03'))) - and wr_returned_date_sk = d_date_sk - group by i_item_id) - select sr_items.item_id - ,sr_item_qty - ,sr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 sr_dev - ,cr_item_qty - ,cr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 cr_dev - ,wr_item_qty - ,wr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 wr_dev - ,(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 average - from sr_items - ,cr_items - ,wr_items - where sr_items.item_id=cr_items.item_id - and sr_items.item_id=wr_items.item_id - order by sr_items.item_id - ,sr_item_qty - limit 100; - --- end template query83.tpl query 71 in stream 6 --- start template query96.tpl query 72 in stream 6 -select /* TPC-DS query96.tpl 0.1 */ count(*) -from store_sales - ,household_demographics - ,time_dim, store -where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 20 - and time_dim.t_minute >= 30 - and household_demographics.hd_dep_count = 2 - and store.s_store_name = 'ese' -order by count(*) -limit 100; - --- end template query96.tpl query 72 in stream 6 --- start template query68.tpl query 73 in stream 6 -select /* TPC-DS query68.tpl 0.95 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,extended_price - ,extended_tax - ,list_price - from (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_ext_sales_price) extended_price - ,sum(ss_ext_list_price) list_price - ,sum(ss_ext_tax) extended_tax - from store_sales - ,date_dim - ,store - ,household_demographics - ,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_dep_count = 9 or - household_demographics.hd_vehicle_count= 1) - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_city in ('Ebenezer','Bradford') - group by ss_ticket_number - ,ss_customer_sk - ,ss_addr_sk,ca_city) dn - ,customer - ,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,ss_ticket_number - limit 100; - --- end template query68.tpl query 73 in stream 6 --- start template query63.tpl query 74 in stream 6 -select /* TPC-DS query63.tpl 0.27 */ * -from (select i_manager_id - ,sum(ss_sales_price) sum_sales - ,avg(sum(ss_sales_price)) over (partition by i_manager_id) avg_monthly_sales - from item - ,store_sales - ,date_dim - ,store - where ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and d_month_seq in (1218,1218+1,1218+2,1218+3,1218+4,1218+5,1218+6,1218+7,1218+8,1218+9,1218+10,1218+11) - and (( i_category in ('Books','Children','Electronics') - and i_class in ('personal','portable','reference','self-help') - and i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) - or( i_category in ('Women','Music','Men') - and i_class in ('accessories','classical','fragrances','pants') - and i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manager_id, d_moy) tmp1 -where case when avg_monthly_sales > 0 then abs (sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 -order by i_manager_id - ,avg_monthly_sales - ,sum_sales -limit 100; - --- end template query63.tpl query 74 in stream 6 --- start template query92.tpl query 75 in stream 6 -select /* TPC-DS query92.tpl 0.44 */ - sum(ws_ext_discount_amt) as "Excess Discount Amount" -from - web_sales - ,item - ,date_dim -where -i_manufact_id = 365 -and i_item_sk = ws_item_sk -and d_date between '2000-01-30' and - dateadd(day,90,cast('2000-01-30' as date)) -and d_date_sk = ws_sold_date_sk -and ws_ext_discount_amt - > ( - SELECT - 1.3 * avg(ws_ext_discount_amt) - FROM - web_sales - ,date_dim - WHERE - ws_item_sk = i_item_sk - and d_date between '2000-01-30' and - dateadd(day,90,cast('2000-01-30' as date)) - and d_date_sk = ws_sold_date_sk - ) -order by sum(ws_ext_discount_amt) -limit 100; - --- end template query92.tpl query 75 in stream 6 --- start template query27a.tpl query 76 in stream 6 -with /* TPC-DS query27a.tpl 0.16 */ results as - (select i_item_id, - s_state, 0 as g_state, - ss_quantity agg1, - ss_list_price agg2, - ss_coupon_amt agg3, - ss_sales_price agg4 - from store_sales, customer_demographics, date_dim, store, item - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_store_sk = s_store_sk and - ss_cdemo_sk = cd_demo_sk and - cd_gender = 'M' and - cd_marital_status = 'W' and - cd_education_status = 'College' and - d_year = 2002 and - s_state in ('KY','MN', 'IL', 'WA', 'TN', 'GA') - ) - - select i_item_id, - s_state, g_state, agg1, agg2, agg3, agg4 - from ( - select i_item_id, s_state, 0 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4 from results - group by i_item_id, s_state - union all - select i_item_id, NULL AS s_state, 1 AS g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as s_state, 1 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - ) foo - order by i_item_id, s_state - limit 100; - --- end template query27a.tpl query 76 in stream 6 --- start template query12.tpl query 77 in stream 6 -select /* TPC-DS query12.tpl 0.64 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ws_ext_sales_price) as itemrevenue - ,sum(ws_ext_sales_price)*100/sum(sum(ws_ext_sales_price)) over - (partition by i_class) as revenueratio -from - web_sales - ,item - ,date_dim -where - ws_item_sk = i_item_sk - and i_category in ('Jewelry', 'Electronics', 'Men') - and ws_sold_date_sk = d_date_sk - and d_date between cast('1999-06-30' as date) - and dateadd(day,30,cast('1999-06-30' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query12.tpl query 77 in stream 6 --- start template query64.tpl query 78 in stream 6 -with /* TPC-DS query64.tpl 0.20 */ cs_ui as - (select cs_item_sk - ,sum(cs_ext_list_price) as sale,sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit) as refund - from catalog_sales - ,catalog_returns - where cs_item_sk = cr_item_sk - and cs_order_number = cr_order_number - group by cs_item_sk - having sum(cs_ext_list_price)>2*sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit)), -cross_sales as - (select i_product_name product_name - ,i_item_sk item_sk - ,s_store_name store_name - ,s_zip store_zip - ,ad1.ca_street_number b_street_number - ,ad1.ca_street_name b_street_name - ,ad1.ca_city b_city - ,ad1.ca_zip b_zip - ,ad2.ca_street_number c_street_number - ,ad2.ca_street_name c_street_name - ,ad2.ca_city c_city - ,ad2.ca_zip c_zip - ,d1.d_year as syear - ,d2.d_year as fsyear - ,d3.d_year s2year - ,count(*) cnt - ,sum(ss_wholesale_cost) s1 - ,sum(ss_list_price) s2 - ,sum(ss_coupon_amt) s3 - FROM store_sales - ,store_returns - ,cs_ui - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,customer - ,customer_demographics cd1 - ,customer_demographics cd2 - ,promotion - ,household_demographics hd1 - ,household_demographics hd2 - ,customer_address ad1 - ,customer_address ad2 - ,income_band ib1 - ,income_band ib2 - ,item - WHERE ss_store_sk = s_store_sk AND - ss_sold_date_sk = d1.d_date_sk AND - ss_customer_sk = c_customer_sk AND - ss_cdemo_sk= cd1.cd_demo_sk AND - ss_hdemo_sk = hd1.hd_demo_sk AND - ss_addr_sk = ad1.ca_address_sk and - ss_item_sk = i_item_sk and - ss_item_sk = sr_item_sk and - ss_ticket_number = sr_ticket_number and - ss_item_sk = cs_ui.cs_item_sk and - c_current_cdemo_sk = cd2.cd_demo_sk AND - c_current_hdemo_sk = hd2.hd_demo_sk AND - c_current_addr_sk = ad2.ca_address_sk and - c_first_sales_date_sk = d2.d_date_sk and - c_first_shipto_date_sk = d3.d_date_sk and - ss_promo_sk = p_promo_sk and - hd1.hd_income_band_sk = ib1.ib_income_band_sk and - hd2.hd_income_band_sk = ib2.ib_income_band_sk and - cd1.cd_marital_status <> cd2.cd_marital_status and - i_color in ('cornsilk','puff','saddle','honeydew','lawn','beige') and - i_current_price between 19 and 19 + 10 and - i_current_price between 19 + 1 and 19 + 15 -group by i_product_name - ,i_item_sk - ,s_store_name - ,s_zip - ,ad1.ca_street_number - ,ad1.ca_street_name - ,ad1.ca_city - ,ad1.ca_zip - ,ad2.ca_street_number - ,ad2.ca_street_name - ,ad2.ca_city - ,ad2.ca_zip - ,d1.d_year - ,d2.d_year - ,d3.d_year -) -select cs1.product_name - ,cs1.store_name - ,cs1.store_zip - ,cs1.b_street_number - ,cs1.b_street_name - ,cs1.b_city - ,cs1.b_zip - ,cs1.c_street_number - ,cs1.c_street_name - ,cs1.c_city - ,cs1.c_zip - ,cs1.syear - ,cs1.cnt - ,cs1.s1 as s11 - ,cs1.s2 as s21 - ,cs1.s3 as s31 - ,cs2.s1 as s12 - ,cs2.s2 as s22 - ,cs2.s3 as s32 - ,cs2.syear - ,cs2.cnt -from cross_sales cs1,cross_sales cs2 -where cs1.item_sk=cs2.item_sk and - cs1.syear = 2000 and - cs2.syear = 2000 + 1 and - cs2.cnt <= cs1.cnt and - cs1.store_name = cs2.store_name and - cs1.store_zip = cs2.store_zip -order by cs1.product_name - ,cs1.store_name - ,cs2.cnt - ,cs1.s1 - ,cs2.s1; - --- end template query64.tpl query 78 in stream 6 --- start template query95.tpl query 79 in stream 6 -with /* TPC-DS query95.tpl 0.43 */ ws_wh as -(select ws1.ws_order_number,ws1.ws_warehouse_sk wh1,ws2.ws_warehouse_sk wh2 - from web_sales ws1,web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) - select - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '1999-2-01' and - dateadd(day,60,cast('1999-2-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'LA' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and ws1.ws_order_number in (select ws_order_number - from ws_wh) -and ws1.ws_order_number in (select wr_order_number - from web_returns,ws_wh - where wr_order_number = ws_wh.ws_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query95.tpl query 79 in stream 6 --- start template query39.tpl query 80 in stream 6 -with /* TPC-DS query39.tpl 0.5 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =1998 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=3 - and inv2.d_moy=3+1 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; -with /* TPC-DS query39.tpl 0.5 part2 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =1998 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=3 - and inv2.d_moy=3+1 - and inv1.cov > 1.5 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; - --- end template query39.tpl query 80 in stream 6 --- start template query35a.tpl query 81 in stream 6 -select /* TPC-DS query35a.tpl 0.47 */ - ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - count(*) cnt1, - min(cd_dep_count), - max(cd_dep_count), - min(cd_dep_count), - cd_dep_employed_count, - count(*) cnt2, - min(cd_dep_employed_count), - max(cd_dep_employed_count), - min(cd_dep_employed_count), - cd_dep_college_count, - count(*) cnt3, - min(cd_dep_college_count), - max(cd_dep_college_count), - min(cd_dep_college_count) - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2002 and - d_qoy < 4) and - exists (select * from - (select ws_bill_customer_sk customsk - from web_sales,date_dim - where - ws_sold_date_sk = d_date_sk and - d_year = 2002 and - d_qoy < 4 - union all - select cs_ship_customer_sk customsk - from catalog_sales,date_dim - where - cs_sold_date_sk = d_date_sk and - d_year = 2002 and - d_qoy < 4)x - where x.customsk = c.c_customer_sk) - group by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - limit 100; - --- end template query35a.tpl query 81 in stream 6 --- start template query78.tpl query 82 in stream 6 -with /* TPC-DS query78.tpl 0.10 */ ws as - (select d_year AS ws_sold_year, ws_item_sk, - ws_bill_customer_sk ws_customer_sk, - sum(ws_quantity) ws_qty, - sum(ws_wholesale_cost) ws_wc, - sum(ws_sales_price) ws_sp - from web_sales - left join web_returns on wr_order_number=ws_order_number and ws_item_sk=wr_item_sk - join date_dim on ws_sold_date_sk = d_date_sk - where wr_order_number is null - group by d_year, ws_item_sk, ws_bill_customer_sk - ), -cs as - (select d_year AS cs_sold_year, cs_item_sk, - cs_bill_customer_sk cs_customer_sk, - sum(cs_quantity) cs_qty, - sum(cs_wholesale_cost) cs_wc, - sum(cs_sales_price) cs_sp - from catalog_sales - left join catalog_returns on cr_order_number=cs_order_number and cs_item_sk=cr_item_sk - join date_dim on cs_sold_date_sk = d_date_sk - where cr_order_number is null - group by d_year, cs_item_sk, cs_bill_customer_sk - ), -ss as - (select d_year AS ss_sold_year, ss_item_sk, - ss_customer_sk, - sum(ss_quantity) ss_qty, - sum(ss_wholesale_cost) ss_wc, - sum(ss_sales_price) ss_sp - from store_sales - left join store_returns on sr_ticket_number=ss_ticket_number and ss_item_sk=sr_item_sk - join date_dim on ss_sold_date_sk = d_date_sk - where sr_ticket_number is null - group by d_year, ss_item_sk, ss_customer_sk - ) - select -ss_sold_year, -round(ss_qty/(coalesce(ws_qty,0)+coalesce(cs_qty,0)),2) ratio, -ss_qty store_qty, ss_wc store_wholesale_cost, ss_sp store_sales_price, -coalesce(ws_qty,0)+coalesce(cs_qty,0) other_chan_qty, -coalesce(ws_wc,0)+coalesce(cs_wc,0) other_chan_wholesale_cost, -coalesce(ws_sp,0)+coalesce(cs_sp,0) other_chan_sales_price -from ss -left join ws on (ws_sold_year=ss_sold_year and ws_item_sk=ss_item_sk and ws_customer_sk=ss_customer_sk) -left join cs on (cs_sold_year=ss_sold_year and cs_item_sk=ss_item_sk and cs_customer_sk=ss_customer_sk) -where (coalesce(ws_qty,0)>0 or coalesce(cs_qty, 0)>0) and ss_sold_year=2002 -order by - ss_sold_year, - ss_qty desc, ss_wc desc, ss_sp desc, - other_chan_qty, - other_chan_wholesale_cost, - other_chan_sales_price, - ratio -limit 100; - --- end template query78.tpl query 82 in stream 6 --- start template query57.tpl query 83 in stream 6 -with /* TPC-DS query57.tpl 0.70 */ v1 as( - select i_category, i_brand, - cc_name, - d_year, d_moy, - sum(cs_sales_price) sum_sales, - avg(sum(cs_sales_price)) over - (partition by i_category, i_brand, - cc_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - cc_name - order by d_year, d_moy) rn - from item, catalog_sales, date_dim, call_center - where cs_item_sk = i_item_sk and - cs_sold_date_sk = d_date_sk and - cc_call_center_sk= cs_call_center_sk and - ( - d_year = 2001 or - ( d_year = 2001-1 and d_moy =12) or - ( d_year = 2001+1 and d_moy =1) - ) - group by i_category, i_brand, - cc_name , d_year, d_moy), - v2 as( - select v1.i_brand - ,v1.d_year - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1. cc_name = v1_lag. cc_name and - v1. cc_name = v1_lead. cc_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 2001 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, sum_sales - limit 100; - --- end template query57.tpl query 83 in stream 6 --- start template query66.tpl query 84 in stream 6 -select /* TPC-DS query66.tpl 0.39 */ - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - ,sum(jan_sales) as jan_sales - ,sum(feb_sales) as feb_sales - ,sum(mar_sales) as mar_sales - ,sum(apr_sales) as apr_sales - ,sum(may_sales) as may_sales - ,sum(jun_sales) as jun_sales - ,sum(jul_sales) as jul_sales - ,sum(aug_sales) as aug_sales - ,sum(sep_sales) as sep_sales - ,sum(oct_sales) as oct_sales - ,sum(nov_sales) as nov_sales - ,sum(dec_sales) as dec_sales - ,sum(jan_sales/w_warehouse_sq_ft) as jan_sales_per_sq_foot - ,sum(feb_sales/w_warehouse_sq_ft) as feb_sales_per_sq_foot - ,sum(mar_sales/w_warehouse_sq_ft) as mar_sales_per_sq_foot - ,sum(apr_sales/w_warehouse_sq_ft) as apr_sales_per_sq_foot - ,sum(may_sales/w_warehouse_sq_ft) as may_sales_per_sq_foot - ,sum(jun_sales/w_warehouse_sq_ft) as jun_sales_per_sq_foot - ,sum(jul_sales/w_warehouse_sq_ft) as jul_sales_per_sq_foot - ,sum(aug_sales/w_warehouse_sq_ft) as aug_sales_per_sq_foot - ,sum(sep_sales/w_warehouse_sq_ft) as sep_sales_per_sq_foot - ,sum(oct_sales/w_warehouse_sq_ft) as oct_sales_per_sq_foot - ,sum(nov_sales/w_warehouse_sq_ft) as nov_sales_per_sq_foot - ,sum(dec_sales/w_warehouse_sq_ft) as dec_sales_per_sq_foot - ,sum(jan_net) as jan_net - ,sum(feb_net) as feb_net - ,sum(mar_net) as mar_net - ,sum(apr_net) as apr_net - ,sum(may_net) as may_net - ,sum(jun_net) as jun_net - ,sum(jul_net) as jul_net - ,sum(aug_net) as aug_net - ,sum(sep_net) as sep_net - ,sum(oct_net) as oct_net - ,sum(nov_net) as nov_net - ,sum(dec_net) as dec_net - from ( - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'AIRBORNE' || ',' || 'BOXBUNDLES' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then ws_ext_list_price* ws_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then ws_ext_list_price* ws_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then ws_ext_list_price* ws_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then ws_ext_list_price* ws_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then ws_ext_list_price* ws_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then ws_ext_list_price* ws_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then ws_ext_list_price* ws_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then ws_ext_list_price* ws_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then ws_ext_list_price* ws_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then ws_ext_list_price* ws_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then ws_ext_list_price* ws_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then ws_ext_list_price* ws_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as dec_net - from - web_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - ws_warehouse_sk = w_warehouse_sk - and ws_sold_date_sk = d_date_sk - and ws_sold_time_sk = t_time_sk - and ws_ship_mode_sk = sm_ship_mode_sk - and d_year = 1999 - and t_time between 38564 and 38564+28800 - and sm_carrier in ('AIRBORNE','BOXBUNDLES') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - union all - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'AIRBORNE' || ',' || 'BOXBUNDLES' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then cs_ext_list_price* cs_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then cs_ext_list_price* cs_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then cs_ext_list_price* cs_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then cs_ext_list_price* cs_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then cs_ext_list_price* cs_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then cs_ext_list_price* cs_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then cs_ext_list_price* cs_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then cs_ext_list_price* cs_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then cs_ext_list_price* cs_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then cs_ext_list_price* cs_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then cs_ext_list_price* cs_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then cs_ext_list_price* cs_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then cs_net_paid * cs_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then cs_net_paid * cs_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then cs_net_paid * cs_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then cs_net_paid * cs_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then cs_net_paid * cs_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then cs_net_paid * cs_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then cs_net_paid * cs_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then cs_net_paid * cs_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then cs_net_paid * cs_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then cs_net_paid * cs_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then cs_net_paid * cs_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then cs_net_paid * cs_quantity else 0 end) as dec_net - from - catalog_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and cs_sold_time_sk = t_time_sk - and cs_ship_mode_sk = sm_ship_mode_sk - and d_year = 1999 - and t_time between 38564 AND 38564+28800 - and sm_carrier in ('AIRBORNE','BOXBUNDLES') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - ) x - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - order by w_warehouse_name - limit 100; - --- end template query66.tpl query 84 in stream 6 --- start template query71.tpl query 85 in stream 6 -select /* TPC-DS query71.tpl 0.72 */ i_brand_id brand_id, i_brand brand,t_hour,t_minute, - sum(ext_price) ext_price - from item, (select ws_ext_sales_price as ext_price, - ws_sold_date_sk as sold_date_sk, - ws_item_sk as sold_item_sk, - ws_sold_time_sk as time_sk - from web_sales,date_dim - where d_date_sk = ws_sold_date_sk - and d_moy=12 - and d_year=2002 - union all - select cs_ext_sales_price as ext_price, - cs_sold_date_sk as sold_date_sk, - cs_item_sk as sold_item_sk, - cs_sold_time_sk as time_sk - from catalog_sales,date_dim - where d_date_sk = cs_sold_date_sk - and d_moy=12 - and d_year=2002 - union all - select ss_ext_sales_price as ext_price, - ss_sold_date_sk as sold_date_sk, - ss_item_sk as sold_item_sk, - ss_sold_time_sk as time_sk - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - and d_moy=12 - and d_year=2002 - ) tmp,time_dim - where - sold_item_sk = i_item_sk - and i_manager_id=1 - and time_sk = t_time_sk - and (t_meal_time = 'breakfast' or t_meal_time = 'dinner') - group by i_brand, i_brand_id,t_hour,t_minute - order by ext_price desc, i_brand_id - ; - --- end template query71.tpl query 85 in stream 6 --- start template query30.tpl query 86 in stream 6 -with /* TPC-DS query30.tpl 0.75 */ customer_total_return as - (select wr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(wr_return_amt) as ctr_total_return - from web_returns - ,date_dim - ,customer_address - where wr_returned_date_sk = d_date_sk - and d_year =2002 - and wr_returning_addr_sk = ca_address_sk - group by wr_returning_customer_sk - ,ca_state) - select c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'TX' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return -limit 100; - --- end template query30.tpl query 86 in stream 6 --- start template query1.tpl query 87 in stream 6 -with /* TPC-DS query1.tpl 0.12 */ customer_total_return as -(select sr_customer_sk as ctr_customer_sk -,sr_store_sk as ctr_store_sk -,sum(SR_RETURN_AMT) as ctr_total_return -from store_returns -,date_dim -where sr_returned_date_sk = d_date_sk -and d_year =2002 -group by sr_customer_sk -,sr_store_sk) - select c_customer_id -from customer_total_return ctr1 -,store -,customer -where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 -from customer_total_return ctr2 -where ctr1.ctr_store_sk = ctr2.ctr_store_sk) -and s_store_sk = ctr1.ctr_store_sk -and s_state = 'TX' -and ctr1.ctr_customer_sk = c_customer_sk -order by c_customer_id -limit 100; - --- end template query1.tpl query 87 in stream 6 --- start template query81.tpl query 88 in stream 6 -with /* TPC-DS query81.tpl 0.37 */ customer_total_return as - (select cr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(cr_return_amt_inc_tax) as ctr_total_return - from catalog_returns - ,date_dim - ,customer_address - where cr_returned_date_sk = d_date_sk - and d_year =1998 - and cr_returning_addr_sk = ca_address_sk - group by cr_returning_customer_sk - ,ca_state ) - select c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'MS' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - limit 100; - --- end template query81.tpl query 88 in stream 6 --- start template query43.tpl query 89 in stream 6 -select /* TPC-DS query43.tpl 0.15 */ s_store_name, s_store_id, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from date_dim, store_sales, store - where d_date_sk = ss_sold_date_sk and - s_store_sk = ss_store_sk and - s_gmt_offset = -6 and - d_year = 1999 - group by s_store_name, s_store_id - order by s_store_name, s_store_id,sun_sales,mon_sales,tue_sales,wed_sales,thu_sales,fri_sales,sat_sales - limit 100; - --- end template query43.tpl query 89 in stream 6 --- start template query52.tpl query 90 in stream 6 -select /* TPC-DS query52.tpl 0.59 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_sales_price) ext_price - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=11 - and dt.d_year=2001 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,ext_price desc - ,brand_id -limit 100 ; - --- end template query52.tpl query 90 in stream 6 --- start template query13.tpl query 91 in stream 6 -select /* TPC-DS query13.tpl 0.91 */ avg(ss_quantity) - ,avg(ss_ext_sales_price) - ,avg(ss_ext_wholesale_cost) - ,sum(ss_ext_wholesale_cost) - from store_sales - ,store - ,customer_demographics - ,household_demographics - ,customer_address - ,date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2001 - and((ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'U' - and cd_education_status = 'Secondary' - and ss_sales_price between 100.00 and 150.00 - and hd_dep_count = 3 - )or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'S' - and cd_education_status = 'Unknown' - and ss_sales_price between 50.00 and 100.00 - and hd_dep_count = 1 - ) or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'D' - and cd_education_status = 'Primary' - and ss_sales_price between 150.00 and 200.00 - and hd_dep_count = 1 - )) - and((ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('SD', 'NV', 'IN') - and ss_net_profit between 100 and 200 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('TN', 'TX', 'WI') - and ss_net_profit between 150 and 300 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('OH', 'GA', 'FL') - and ss_net_profit between 50 and 250 - )) -; - --- end template query13.tpl query 91 in stream 6 --- start template query76.tpl query 92 in stream 6 -select /* TPC-DS query76.tpl 0.99 */ channel, col_name, d_year, d_qoy, i_category, COUNT(*) sales_cnt, SUM(ext_sales_price) sales_amt FROM ( - SELECT 'store' as channel, 'ss_store_sk' col_name, d_year, d_qoy, i_category, ss_ext_sales_price ext_sales_price - FROM store_sales, item, date_dim - WHERE ss_store_sk IS NULL - AND ss_sold_date_sk=d_date_sk - AND ss_item_sk=i_item_sk - UNION ALL - SELECT 'web' as channel, 'ws_ship_cdemo_sk' col_name, d_year, d_qoy, i_category, ws_ext_sales_price ext_sales_price - FROM web_sales, item, date_dim - WHERE ws_ship_cdemo_sk IS NULL - AND ws_sold_date_sk=d_date_sk - AND ws_item_sk=i_item_sk - UNION ALL - SELECT 'catalog' as channel, 'cs_warehouse_sk' col_name, d_year, d_qoy, i_category, cs_ext_sales_price ext_sales_price - FROM catalog_sales, item, date_dim - WHERE cs_warehouse_sk IS NULL - AND cs_sold_date_sk=d_date_sk - AND cs_item_sk=i_item_sk) foo -GROUP BY channel, col_name, d_year, d_qoy, i_category -ORDER BY channel, col_name, d_year, d_qoy, i_category -limit 100; - --- end template query76.tpl query 92 in stream 6 --- start template query17.tpl query 93 in stream 6 -select /* TPC-DS query17.tpl 0.41 */ i_item_id - ,i_item_desc - ,s_state - ,count(ss_quantity) as store_sales_quantitycount - ,avg(ss_quantity) as store_sales_quantityave - ,stddev_samp(ss_quantity) as store_sales_quantitystdev - ,stddev_samp(ss_quantity)/avg(ss_quantity) as store_sales_quantitycov - ,count(sr_return_quantity) as store_returns_quantitycount - ,avg(sr_return_quantity) as store_returns_quantityave - ,stddev_samp(sr_return_quantity) as store_returns_quantitystdev - ,stddev_samp(sr_return_quantity)/avg(sr_return_quantity) as store_returns_quantitycov - ,count(cs_quantity) as catalog_sales_quantitycount ,avg(cs_quantity) as catalog_sales_quantityave - ,stddev_samp(cs_quantity) as catalog_sales_quantitystdev - ,stddev_samp(cs_quantity)/avg(cs_quantity) as catalog_sales_quantitycov - from store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where d1.d_quarter_name = '2001Q1' - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_quarter_name in ('2001Q1','2001Q2','2001Q3') - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_quarter_name in ('2001Q1','2001Q2','2001Q3') - group by i_item_id - ,i_item_desc - ,s_state - order by i_item_id - ,i_item_desc - ,s_state -limit 100; - --- end template query17.tpl query 93 in stream 6 --- start template query25.tpl query 94 in stream 6 -select /* TPC-DS query25.tpl 0.9 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,stddev_samp(ss_net_profit) as store_sales_profit - ,stddev_samp(sr_net_loss) as store_returns_loss - ,stddev_samp(cs_net_profit) as catalog_sales_profit - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 2002 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 10 - and d2.d_year = 2002 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_moy between 4 and 10 - and d3.d_year = 2002 - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query25.tpl query 94 in stream 6 --- start template query40.tpl query 95 in stream 6 -select /* TPC-DS query40.tpl 0.86 */ - w_state - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('2002-03-14' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_before - ,sum(case when (cast(d_date as date) >= cast ('2002-03-14' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_after - from - catalog_sales left outer join catalog_returns on - (cs_order_number = cr_order_number - and cs_item_sk = cr_item_sk) - ,warehouse - ,item - ,date_dim - where - i_current_price between 0.99 and 1.49 - and i_item_sk = cs_item_sk - and cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('2002-03-14' as date)) - and dateadd(day,30,cast ('2002-03-14' as date)) - group by - w_state,i_item_id - order by w_state,i_item_id -limit 100; - --- end template query40.tpl query 95 in stream 6 --- start template query70a.tpl query 96 in stream 6 -with /* TPC-DS query70a.tpl 0.34 */ results as -( select - sum(ss_net_profit) as total_sum ,s_state ,s_county, 0 as gstate, 0 as g_county - from - store_sales - ,date_dim d1 - ,store - where - d1.d_month_seq between 1217 and 1217 + 11 - and d1.d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - and s_state in - ( select s_state - from (select s_state as s_state, - rank() over ( partition by s_state order by sum(ss_net_profit) desc) as ranking - from store_sales, store, date_dim - where d_month_seq between 1217 and 1217 + 11 - and d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - group by s_state - ) tmp1 - where ranking <= 5) - group by s_state,s_county) , - results_rollup as -(select total_sum ,s_state ,s_county, 0 as g_state, 0 as g_county, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum,s_state, NULL as s_county, 0 as g_state, 1 as g_county, 1 as lochierarchy from results group by s_state - union - select sum(total_sum) as total_sum ,NULL as s_state ,NULL as s_county, 1 as g_state, 1 as g_county, 2 as lochierarchy from results) - select total_sum ,s_state ,s_county, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_county = 0 then s_state end - order by total_sum desc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then s_state end - ,rank_within_parent - limit 100; - --- end template query70a.tpl query 96 in stream 6 --- start template query55.tpl query 97 in stream 6 -select /* TPC-DS query55.tpl 0.82 */ i_brand_id brand_id, i_brand brand, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=88 - and d_moy=11 - and d_year=1998 - group by i_brand, i_brand_id - order by ext_price desc, i_brand_id -limit 100 ; - --- end template query55.tpl query 97 in stream 6 --- start template query60.tpl query 98 in stream 6 -with /* TPC-DS query60.tpl 0.29 */ ss as ( - select - i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Children')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 10 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - cs as ( - select - i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Children')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 10 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - ws as ( - select - i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Children')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 10 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id) - select - i_item_id -,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by i_item_id - ,total_sales - limit 100; - --- end template query60.tpl query 98 in stream 6 --- start template query16.tpl query 99 in stream 6 -select /* TPC-DS query16.tpl 0.25 */ - count(distinct cs_order_number) as "order count" - ,sum(cs_ext_ship_cost) as "total shipping cost" - ,sum(cs_net_profit) as "total net profit" -from - catalog_sales cs1 - ,date_dim - ,customer_address - ,call_center -where - d_date between '2002-4-01' and - dateadd(day, 60, cast('2002-4-01' as date)) -and cs1.cs_ship_date_sk = d_date_sk -and cs1.cs_ship_addr_sk = ca_address_sk -and ca_state = 'NC' -and cs1.cs_call_center_sk = cc_call_center_sk -and cc_county in ('San Miguel County','Jefferson Davis Parish','Gogebic County','Wadena County', - 'Barrow County' -) -and exists (select * - from catalog_sales cs2 - where cs1.cs_order_number = cs2.cs_order_number - and cs1.cs_warehouse_sk <> cs2.cs_warehouse_sk) -and not exists(select * - from catalog_returns cr1 - where cs1.cs_order_number = cr1.cr_order_number) -order by count(distinct cs_order_number) -limit 100; - --- end template query16.tpl query 99 in stream 6 diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/100TB/queries/query_7.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/100TB/queries/query_7.sql deleted file mode 100644 index d236b563..00000000 --- a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/100TB/queries/query_7.sql +++ /dev/null @@ -1,5027 +0,0 @@ --- start template query70a.tpl query 1 in stream 7 -with /* TPC-DS query70a.tpl 0.34 */ results as -( select - sum(ss_net_profit) as total_sum ,s_state ,s_county, 0 as gstate, 0 as g_county - from - store_sales - ,date_dim d1 - ,store - where - d1.d_month_seq between 1209 and 1209 + 11 - and d1.d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - and s_state in - ( select s_state - from (select s_state as s_state, - rank() over ( partition by s_state order by sum(ss_net_profit) desc) as ranking - from store_sales, store, date_dim - where d_month_seq between 1209 and 1209 + 11 - and d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - group by s_state - ) tmp1 - where ranking <= 5) - group by s_state,s_county) , - results_rollup as -(select total_sum ,s_state ,s_county, 0 as g_state, 0 as g_county, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum,s_state, NULL as s_county, 0 as g_state, 1 as g_county, 1 as lochierarchy from results group by s_state - union - select sum(total_sum) as total_sum ,NULL as s_state ,NULL as s_county, 1 as g_state, 1 as g_county, 2 as lochierarchy from results) - select total_sum ,s_state ,s_county, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_county = 0 then s_state end - order by total_sum desc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then s_state end - ,rank_within_parent - limit 100; - --- end template query70a.tpl query 1 in stream 7 --- start template query53.tpl query 2 in stream 7 -select /* TPC-DS query53.tpl 0.88 */ * from -(select i_manufact_id, -sum(ss_sales_price) sum_sales, -avg(sum(ss_sales_price)) over (partition by i_manufact_id) avg_quarterly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and -ss_sold_date_sk = d_date_sk and -ss_store_sk = s_store_sk and -d_month_seq in (1193,1193+1,1193+2,1193+3,1193+4,1193+5,1193+6,1193+7,1193+8,1193+9,1193+10,1193+11) and -((i_category in ('Books','Children','Electronics') and -i_class in ('personal','portable','reference','self-help') and -i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) -or(i_category in ('Women','Music','Men') and -i_class in ('accessories','classical','fragrances','pants') and -i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manufact_id, d_qoy ) tmp1 -where case when avg_quarterly_sales > 0 - then abs (sum_sales - avg_quarterly_sales)/ avg_quarterly_sales - else null end > 0.1 -order by avg_quarterly_sales, - sum_sales, - i_manufact_id -limit 100; - --- end template query53.tpl query 2 in stream 7 --- start template query92.tpl query 3 in stream 7 -select /* TPC-DS query92.tpl 0.44 */ - sum(ws_ext_discount_amt) as "Excess Discount Amount" -from - web_sales - ,item - ,date_dim -where -i_manufact_id = 470 -and i_item_sk = ws_item_sk -and d_date between '1998-01-06' and - dateadd(day,90,cast('1998-01-06' as date)) -and d_date_sk = ws_sold_date_sk -and ws_ext_discount_amt - > ( - SELECT - 1.3 * avg(ws_ext_discount_amt) - FROM - web_sales - ,date_dim - WHERE - ws_item_sk = i_item_sk - and d_date between '1998-01-06' and - dateadd(day,90,cast('1998-01-06' as date)) - and d_date_sk = ws_sold_date_sk - ) -order by sum(ws_ext_discount_amt) -limit 100; - --- end template query92.tpl query 3 in stream 7 --- start template query99.tpl query 4 in stream 7 -select /* TPC-DS query99.tpl 0.94 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 30) and - (cs_ship_date_sk - cs_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 60) and - (cs_ship_date_sk - cs_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 90) and - (cs_ship_date_sk - cs_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - catalog_sales - ,warehouse - ,ship_mode - ,call_center - ,date_dim -where - d_month_seq between 1203 and 1203 + 11 -and cs_ship_date_sk = d_date_sk -and cs_warehouse_sk = w_warehouse_sk -and cs_ship_mode_sk = sm_ship_mode_sk -and cs_call_center_sk = cc_call_center_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -limit 100; - --- end template query99.tpl query 4 in stream 7 --- start template query31.tpl query 5 in stream 7 -with /* TPC-DS query31.tpl 0.50 */ ss as - (select ca_county,d_qoy, d_year,sum(ss_ext_sales_price) as store_sales - from store_sales,date_dim,customer_address - where ss_sold_date_sk = d_date_sk - and ss_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year), - ws as - (select ca_county,d_qoy, d_year,sum(ws_ext_sales_price) as web_sales - from web_sales,date_dim,customer_address - where ws_sold_date_sk = d_date_sk - and ws_bill_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year) - select - ss1.ca_county - ,ss1.d_year - ,ws2.web_sales/ws1.web_sales web_q1_q2_increase - ,ss2.store_sales/ss1.store_sales store_q1_q2_increase - ,ws3.web_sales/ws2.web_sales web_q2_q3_increase - ,ss3.store_sales/ss2.store_sales store_q2_q3_increase - from - ss ss1 - ,ss ss2 - ,ss ss3 - ,ws ws1 - ,ws ws2 - ,ws ws3 - where - ss1.d_qoy = 1 - and ss1.d_year = 2002 - and ss1.ca_county = ss2.ca_county - and ss2.d_qoy = 2 - and ss2.d_year = 2002 - and ss2.ca_county = ss3.ca_county - and ss3.d_qoy = 3 - and ss3.d_year = 2002 - and ss1.ca_county = ws1.ca_county - and ws1.d_qoy = 1 - and ws1.d_year = 2002 - and ws1.ca_county = ws2.ca_county - and ws2.d_qoy = 2 - and ws2.d_year = 2002 - and ws1.ca_county = ws3.ca_county - and ws3.d_qoy = 3 - and ws3.d_year =2002 - and case when ws1.web_sales > 0 then ws2.web_sales/ws1.web_sales else null end - > case when ss1.store_sales > 0 then ss2.store_sales/ss1.store_sales else null end - and case when ws2.web_sales > 0 then ws3.web_sales/ws2.web_sales else null end - > case when ss2.store_sales > 0 then ss3.store_sales/ss2.store_sales else null end - order by web_q1_q2_increase; - --- end template query31.tpl query 5 in stream 7 --- start template query39.tpl query 6 in stream 7 -with /* TPC-DS query39.tpl 0.5 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =2001 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=1 - and inv2.d_moy=1+1 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; -with /* TPC-DS query39.tpl 0.5 part2 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =2001 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=1 - and inv2.d_moy=1+1 - and inv1.cov > 1.5 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; - --- end template query39.tpl query 6 in stream 7 --- start template query29.tpl query 7 in stream 7 -select /* TPC-DS query29.tpl 0.53 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,min(ss_quantity) as store_sales_quantity - ,min(sr_return_quantity) as store_returns_quantity - ,min(cs_quantity) as catalog_sales_quantity - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 1999 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 4 + 3 - and d2.d_year = 1999 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_year in (1999,1999+1,1999+2) - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query29.tpl query 7 in stream 7 --- start template query32.tpl query 8 in stream 7 -select /* TPC-DS query32.tpl 0.7 */ sum(cs_ext_discount_amt) as "excess discount amount" -from - catalog_sales - ,item - ,date_dim -where -i_manufact_id = 435 -and i_item_sk = cs_item_sk -and d_date between '2001-01-28' and - dateadd(day,90,cast('2001-01-28' as date)) -and d_date_sk = cs_sold_date_sk -and cs_ext_discount_amt - > ( - select - 1.3 * avg(cs_ext_discount_amt) - from - catalog_sales - ,date_dim - where - cs_item_sk = i_item_sk - and d_date between '2001-01-28' and - dateadd(day,90,cast('2001-01-28' as date)) - and d_date_sk = cs_sold_date_sk - ) -limit 100; - --- end template query32.tpl query 8 in stream 7 --- start template query6.tpl query 9 in stream 7 -select /* TPC-DS query6.tpl 0.58 */ a.ca_state state, count(*) cnt - from customer_address a - ,customer c - ,store_sales s - ,date_dim d - ,item i - where a.ca_address_sk = c.c_current_addr_sk - and c.c_customer_sk = s.ss_customer_sk - and s.ss_sold_date_sk = d.d_date_sk - and s.ss_item_sk = i.i_item_sk - and d.d_month_seq = - (select distinct (d_month_seq) - from date_dim - where d_year = 1999 - and d_moy = 4 ) - and i.i_current_price > 1.2 * - (select avg(j.i_current_price) - from item j - where j.i_category = i.i_category) - group by a.ca_state - having count(*) >= 10 - order by cnt, a.ca_state - limit 100; - --- end template query6.tpl query 9 in stream 7 --- start template query64.tpl query 10 in stream 7 -with /* TPC-DS query64.tpl 0.20 */ cs_ui as - (select cs_item_sk - ,sum(cs_ext_list_price) as sale,sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit) as refund - from catalog_sales - ,catalog_returns - where cs_item_sk = cr_item_sk - and cs_order_number = cr_order_number - group by cs_item_sk - having sum(cs_ext_list_price)>2*sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit)), -cross_sales as - (select i_product_name product_name - ,i_item_sk item_sk - ,s_store_name store_name - ,s_zip store_zip - ,ad1.ca_street_number b_street_number - ,ad1.ca_street_name b_street_name - ,ad1.ca_city b_city - ,ad1.ca_zip b_zip - ,ad2.ca_street_number c_street_number - ,ad2.ca_street_name c_street_name - ,ad2.ca_city c_city - ,ad2.ca_zip c_zip - ,d1.d_year as syear - ,d2.d_year as fsyear - ,d3.d_year s2year - ,count(*) cnt - ,sum(ss_wholesale_cost) s1 - ,sum(ss_list_price) s2 - ,sum(ss_coupon_amt) s3 - FROM store_sales - ,store_returns - ,cs_ui - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,customer - ,customer_demographics cd1 - ,customer_demographics cd2 - ,promotion - ,household_demographics hd1 - ,household_demographics hd2 - ,customer_address ad1 - ,customer_address ad2 - ,income_band ib1 - ,income_band ib2 - ,item - WHERE ss_store_sk = s_store_sk AND - ss_sold_date_sk = d1.d_date_sk AND - ss_customer_sk = c_customer_sk AND - ss_cdemo_sk= cd1.cd_demo_sk AND - ss_hdemo_sk = hd1.hd_demo_sk AND - ss_addr_sk = ad1.ca_address_sk and - ss_item_sk = i_item_sk and - ss_item_sk = sr_item_sk and - ss_ticket_number = sr_ticket_number and - ss_item_sk = cs_ui.cs_item_sk and - c_current_cdemo_sk = cd2.cd_demo_sk AND - c_current_hdemo_sk = hd2.hd_demo_sk AND - c_current_addr_sk = ad2.ca_address_sk and - c_first_sales_date_sk = d2.d_date_sk and - c_first_shipto_date_sk = d3.d_date_sk and - ss_promo_sk = p_promo_sk and - hd1.hd_income_band_sk = ib1.ib_income_band_sk and - hd2.hd_income_band_sk = ib2.ib_income_band_sk and - cd1.cd_marital_status <> cd2.cd_marital_status and - i_color in ('blue','tan','mint','hot','beige','wheat') and - i_current_price between 75 and 75 + 10 and - i_current_price between 75 + 1 and 75 + 15 -group by i_product_name - ,i_item_sk - ,s_store_name - ,s_zip - ,ad1.ca_street_number - ,ad1.ca_street_name - ,ad1.ca_city - ,ad1.ca_zip - ,ad2.ca_street_number - ,ad2.ca_street_name - ,ad2.ca_city - ,ad2.ca_zip - ,d1.d_year - ,d2.d_year - ,d3.d_year -) -select cs1.product_name - ,cs1.store_name - ,cs1.store_zip - ,cs1.b_street_number - ,cs1.b_street_name - ,cs1.b_city - ,cs1.b_zip - ,cs1.c_street_number - ,cs1.c_street_name - ,cs1.c_city - ,cs1.c_zip - ,cs1.syear - ,cs1.cnt - ,cs1.s1 as s11 - ,cs1.s2 as s21 - ,cs1.s3 as s31 - ,cs2.s1 as s12 - ,cs2.s2 as s22 - ,cs2.s3 as s32 - ,cs2.syear - ,cs2.cnt -from cross_sales cs1,cross_sales cs2 -where cs1.item_sk=cs2.item_sk and - cs1.syear = 1999 and - cs2.syear = 1999 + 1 and - cs2.cnt <= cs1.cnt and - cs1.store_name = cs2.store_name and - cs1.store_zip = cs2.store_zip -order by cs1.product_name - ,cs1.store_name - ,cs2.cnt - ,cs1.s1 - ,cs2.s1; - --- end template query64.tpl query 10 in stream 7 --- start template query30.tpl query 11 in stream 7 -with /* TPC-DS query30.tpl 0.75 */ customer_total_return as - (select wr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(wr_return_amt) as ctr_total_return - from web_returns - ,date_dim - ,customer_address - where wr_returned_date_sk = d_date_sk - and d_year =2000 - and wr_returning_addr_sk = ca_address_sk - group by wr_returning_customer_sk - ,ca_state) - select c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'KS' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return -limit 100; - --- end template query30.tpl query 11 in stream 7 --- start template query34.tpl query 12 in stream 7 -select /* TPC-DS query34.tpl 0.73 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (date_dim.d_dom between 1 and 3 or date_dim.d_dom between 25 and 28) - and (household_demographics.hd_buy_potential = '>10000' or - household_demographics.hd_buy_potential = 'Unknown') - and household_demographics.hd_vehicle_count > 0 - and (case when household_demographics.hd_vehicle_count > 0 - then household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count - else null - end) > 1.2 - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_county in ('Sierra County','Greene County','Klamath County','Wood County', - 'Price County','Washington County','Franklin County','Lake and Peninsula Borough') - group by ss_ticket_number,ss_customer_sk) dn,customer - where ss_customer_sk = c_customer_sk - and cnt between 15 and 20 - order by c_last_name,c_first_name,c_salutation,c_preferred_cust_flag desc, ss_ticket_number; - --- end template query34.tpl query 12 in stream 7 --- start template query13.tpl query 13 in stream 7 -select /* TPC-DS query13.tpl 0.91 */ avg(ss_quantity) - ,avg(ss_ext_sales_price) - ,avg(ss_ext_wholesale_cost) - ,sum(ss_ext_wholesale_cost) - from store_sales - ,store - ,customer_demographics - ,household_demographics - ,customer_address - ,date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2001 - and((ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'W' - and cd_education_status = '2 yr Degree' - and ss_sales_price between 100.00 and 150.00 - and hd_dep_count = 3 - )or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'U' - and cd_education_status = 'College' - and ss_sales_price between 50.00 and 100.00 - and hd_dep_count = 1 - ) or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'D' - and cd_education_status = 'Unknown' - and ss_sales_price between 150.00 and 200.00 - and hd_dep_count = 1 - )) - and((ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('IN', 'VA', 'TX') - and ss_net_profit between 100 and 200 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('OR', 'OH', 'MO') - and ss_net_profit between 150 and 300 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('SC', 'ID', 'CA') - and ss_net_profit between 50 and 250 - )) -; - --- end template query13.tpl query 13 in stream 7 --- start template query28.tpl query 14 in stream 7 -select /* TPC-DS query28.tpl 0.36 */ * -from (select avg(ss_list_price) B1_LP - ,count(ss_list_price) B1_CNT - ,count(distinct ss_list_price) B1_CNTD - from store_sales - where ss_quantity between 0 and 5 - and (ss_list_price between 166 and 166+10 - or ss_coupon_amt between 15526 and 15526+1000 - or ss_wholesale_cost between 49 and 49+20)) B1, - (select avg(ss_list_price) B2_LP - ,count(ss_list_price) B2_CNT - ,count(distinct ss_list_price) B2_CNTD - from store_sales - where ss_quantity between 6 and 10 - and (ss_list_price between 0 and 0+10 - or ss_coupon_amt between 8772 and 8772+1000 - or ss_wholesale_cost between 52 and 52+20)) B2, - (select avg(ss_list_price) B3_LP - ,count(ss_list_price) B3_CNT - ,count(distinct ss_list_price) B3_CNTD - from store_sales - where ss_quantity between 11 and 15 - and (ss_list_price between 95 and 95+10 - or ss_coupon_amt between 733 and 733+1000 - or ss_wholesale_cost between 16 and 16+20)) B3, - (select avg(ss_list_price) B4_LP - ,count(ss_list_price) B4_CNT - ,count(distinct ss_list_price) B4_CNTD - from store_sales - where ss_quantity between 16 and 20 - and (ss_list_price between 113 and 113+10 - or ss_coupon_amt between 15700 and 15700+1000 - or ss_wholesale_cost between 21 and 21+20)) B4, - (select avg(ss_list_price) B5_LP - ,count(ss_list_price) B5_CNT - ,count(distinct ss_list_price) B5_CNTD - from store_sales - where ss_quantity between 21 and 25 - and (ss_list_price between 104 and 104+10 - or ss_coupon_amt between 12302 and 12302+1000 - or ss_wholesale_cost between 60 and 60+20)) B5, - (select avg(ss_list_price) B6_LP - ,count(ss_list_price) B6_CNT - ,count(distinct ss_list_price) B6_CNTD - from store_sales - where ss_quantity between 26 and 30 - and (ss_list_price between 98 and 98+10 - or ss_coupon_amt between 4712 and 4712+1000 - or ss_wholesale_cost between 63 and 63+20)) B6 -limit 100; - --- end template query28.tpl query 14 in stream 7 --- start template query86a.tpl query 15 in stream 7 -with /* TPC-DS query86a.tpl 0.11 */ results as -( select sum(ws_net_paid) as total_sum, i_category, i_class, 0 as g_category, 0 as g_class - from - web_sales - ,date_dim d1 - ,item - where - d1.d_month_seq between 1179 and 1179+11 - and d1.d_date_sk = ws_sold_date_sk - and i_item_sk = ws_item_sk - group by i_category,i_class - ) , - - results_rollup as -( select total_sum ,i_category ,i_class, g_category, g_class, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum, i_category, NULL as i_class, 0 as g_category, 1 as g_class, 1 as lochierarchy from results group by i_category - union - select sum(total_sum) as total_sum, NULL as i_category, NULL as i_class, 1 as g_category, 1 as g_class, 2 as lochierarchy from results) - select - total_sum ,i_category ,i_class, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_class = 0 then i_category end - order by total_sum desc) as rank_within_parent - from - results_rollup - order by - lochierarchy desc, - case when lochierarchy = 0 then i_category end, - rank_within_parent - limit 100; - --- end template query86a.tpl query 15 in stream 7 --- start template query84.tpl query 16 in stream 7 -select /* TPC-DS query84.tpl 0.80 */ c_customer_id as customer_id - , coalesce(c_last_name,'') || ', ' || coalesce(c_first_name,'') as customername - from customer - ,customer_address - ,customer_demographics - ,household_demographics - ,income_band - ,store_returns - where ca_city = 'Springdale' - and c_current_addr_sk = ca_address_sk - and ib_lower_bound >= 26710 - and ib_upper_bound <= 26710 + 50000 - and ib_income_band_sk = hd_income_band_sk - and cd_demo_sk = c_current_cdemo_sk - and hd_demo_sk = c_current_hdemo_sk - and sr_cdemo_sk = cd_demo_sk - order by c_customer_id - limit 100; - --- end template query84.tpl query 16 in stream 7 --- start template query25.tpl query 17 in stream 7 -select /* TPC-DS query25.tpl 0.9 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,max(ss_net_profit) as store_sales_profit - ,max(sr_net_loss) as store_returns_loss - ,max(cs_net_profit) as catalog_sales_profit - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 2001 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 10 - and d2.d_year = 2001 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_moy between 4 and 10 - and d3.d_year = 2001 - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query25.tpl query 17 in stream 7 --- start template query4.tpl query 18 in stream 7 -with /* TPC-DS query4.tpl 0.93 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(((ss_ext_list_price-ss_ext_wholesale_cost-ss_ext_discount_amt)+ss_ext_sales_price)/2) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((cs_ext_list_price-cs_ext_wholesale_cost-cs_ext_discount_amt)+cs_ext_sales_price)/2) ) year_total - ,'c' sale_type - from customer - ,catalog_sales - ,date_dim - where c_customer_sk = cs_bill_customer_sk - and cs_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year -union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((ws_ext_list_price-ws_ext_wholesale_cost-ws_ext_discount_amt)+ws_ext_sales_price)/2) ) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_birth_country - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_c_firstyear - ,year_total t_c_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_c_secyear.customer_id - and t_s_firstyear.customer_id = t_c_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_c_firstyear.sale_type = 'c' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_c_secyear.sale_type = 'c' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 2000 - and t_s_secyear.dyear = 2000+1 - and t_c_firstyear.dyear = 2000 - and t_c_secyear.dyear = 2000+1 - and t_w_firstyear.dyear = 2000 - and t_w_secyear.dyear = 2000+1 - and t_s_firstyear.year_total > 0 - and t_c_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_birth_country -limit 100; - --- end template query4.tpl query 18 in stream 7 --- start template query98.tpl query 19 in stream 7 -select /* TPC-DS query98.tpl 0.32 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ss_ext_sales_price) as itemrevenue - ,sum(ss_ext_sales_price)*100/sum(sum(ss_ext_sales_price)) over - (partition by i_class) as revenueratio -from - store_sales - ,item - ,date_dim -where - ss_item_sk = i_item_sk - and i_category in ('Music', 'Shoes', 'Books') - and ss_sold_date_sk = d_date_sk - and d_date between cast('2000-04-27' as date) - and dateadd(day,30,cast('2000-04-27' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio; - --- end template query98.tpl query 19 in stream 7 --- start template query79.tpl query 20 in stream 7 -select /* TPC-DS query79.tpl 0.89 */ - c_last_name,c_first_name,substring(s_city,1,30),ss_ticket_number,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,store.s_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (household_demographics.hd_dep_count = 6 or household_demographics.hd_vehicle_count > 2) - and date_dim.d_dow = 1 - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_number_employees between 200 and 295 - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,store.s_city) ms,customer - where ss_customer_sk = c_customer_sk - order by c_last_name,c_first_name,substring(s_city,1,30), profit -limit 100; - --- end template query79.tpl query 20 in stream 7 --- start template query69.tpl query 21 in stream 7 -select /* TPC-DS query69.tpl 0.28 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_state in ('OK','OH','SD') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 3 and 3+2) and - (not exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 3 and 3+2) and - not exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 3 and 3+2)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - limit 100; - --- end template query69.tpl query 21 in stream 7 --- start template query72.tpl query 22 in stream 7 -select /* TPC-DS query72.tpl 0.87 */ i_item_desc - ,w_warehouse_name - ,d1.d_week_seq - ,sum(case when p_promo_sk is null then 1 else 0 end) no_promo - ,sum(case when p_promo_sk is not null then 1 else 0 end) promo - ,count(*) total_cnt -from catalog_sales -join inventory on (cs_item_sk = inv_item_sk) -join warehouse on (w_warehouse_sk=inv_warehouse_sk) -join item on (i_item_sk = cs_item_sk) -join customer_demographics on (cs_bill_cdemo_sk = cd_demo_sk) -join household_demographics on (cs_bill_hdemo_sk = hd_demo_sk) -join date_dim d1 on (cs_sold_date_sk = d1.d_date_sk) -join date_dim d2 on (inv_date_sk = d2.d_date_sk) -join date_dim d3 on (cs_ship_date_sk = d3.d_date_sk) -left outer join promotion on (cs_promo_sk=p_promo_sk) -left outer join catalog_returns on (cr_item_sk = cs_item_sk and cr_order_number = cs_order_number) -where d1.d_week_seq = d2.d_week_seq - and inv_quantity_on_hand < cs_quantity - and d3.d_date > d1.d_date + 5 - and hd_buy_potential = '1001-5000' - and d1.d_year = 1998 - and cd_marital_status = 'W' -group by i_item_desc,w_warehouse_name,d1.d_week_seq -order by total_cnt desc, i_item_desc, w_warehouse_name, d_week_seq -limit 100; - --- end template query72.tpl query 22 in stream 7 --- start template query45.tpl query 23 in stream 7 -select /* TPC-DS query45.tpl 0.18 */ ca_zip, ca_county, sum(ws_sales_price) - from web_sales, customer, customer_address, date_dim, item - where ws_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ws_item_sk = i_item_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', '85392', '85460', '80348', '81792') - or - i_item_id in (select i_item_id - from item - where i_item_sk in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29) - ) - ) - and ws_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 2002 - group by ca_zip, ca_county - order by ca_zip, ca_county - limit 100; - --- end template query45.tpl query 23 in stream 7 --- start template query48.tpl query 24 in stream 7 -select /* TPC-DS query48.tpl 0.74 */ sum (ss_quantity) - from store_sales, store, customer_demographics, customer_address, date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2000 - and - ( - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'U' - and - cd_education_status = 'Secondary' - and - ss_sales_price between 100.00 and 150.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'W' - and - cd_education_status = 'Advanced Degree' - and - ss_sales_price between 50.00 and 100.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'D' - and - cd_education_status = 'Primary' - and - ss_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('IN', 'KY', 'AL') - and ss_net_profit between 0 and 2000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('TX', 'NC', 'CA') - and ss_net_profit between 150 and 3000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('NM', 'VA', 'FL') - and ss_net_profit between 50 and 25000 - ) - ) -; - --- end template query48.tpl query 24 in stream 7 --- start template query80a.tpl query 25 in stream 7 -with /* TPC-DS query80a.tpl 0.6 */ ssr as - (select s_store_id as store_id, - sum(ss_ext_sales_price) as sales, - sum(coalesce(sr_return_amt, 0)) as returns, - sum(ss_net_profit - coalesce(sr_net_loss, 0)) as profit - from store_sales left outer join store_returns on - (ss_item_sk = sr_item_sk and ss_ticket_number = sr_ticket_number), - date_dim, - store, - item, - promotion - where ss_sold_date_sk = d_date_sk - and d_date between cast('2002-08-05' as date) - and dateadd(day,30,cast('2002-08-05' as date)) - and ss_store_sk = s_store_sk - and ss_item_sk = i_item_sk - and i_current_price > 50 - and ss_promo_sk = p_promo_sk - and p_channel_tv = 'N' - group by s_store_id) - , - csr as - (select cp_catalog_page_id as catalog_page_id, - sum(cs_ext_sales_price) as sales, - sum(coalesce(cr_return_amount, 0)) as returns, - sum(cs_net_profit - coalesce(cr_net_loss, 0)) as profit - from catalog_sales left outer join catalog_returns on - (cs_item_sk = cr_item_sk and cs_order_number = cr_order_number), - date_dim, - catalog_page, - item, - promotion - where cs_sold_date_sk = d_date_sk - and d_date between cast('2002-08-05' as date) - and dateadd(day,30,cast('2002-08-05' as date)) - and cs_catalog_page_sk = cp_catalog_page_sk - and cs_item_sk = i_item_sk - and i_current_price > 50 - and cs_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(ws_ext_sales_price) as sales, - sum(coalesce(wr_return_amt, 0)) as returns, - sum(ws_net_profit - coalesce(wr_net_loss, 0)) as profit - from web_sales left outer join web_returns on - (ws_item_sk = wr_item_sk and ws_order_number = wr_order_number), - date_dim, - web_site, - item, - promotion - where ws_sold_date_sk = d_date_sk - and d_date between cast('2002-08-05' as date) - and dateadd(day,30,cast('2002-08-05' as date)) - and ws_web_site_sk = web_site_sk - and ws_item_sk = i_item_sk - and i_current_price > 50 - and ws_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by web_site_id) -, -results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || store_id as id - , sales - , returns - , profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || catalog_page_id as id - , sales - , returns - , profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , profit - from wsr - ) x - group by channel, id) - - select channel - , id - , sales - , returns - , profit - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results - ) foo - order by channel, id - limit 100; - --- end template query80a.tpl query 25 in stream 7 --- start template query20.tpl query 26 in stream 7 -select /* TPC-DS query20.tpl 0.65 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(cs_ext_sales_price) as itemrevenue - ,sum(cs_ext_sales_price)*100/sum(sum(cs_ext_sales_price)) over - (partition by i_class) as revenueratio - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and i_category in ('Home', 'Shoes', 'Electronics') - and cs_sold_date_sk = d_date_sk - and d_date between cast('1998-06-06' as date) - and dateadd(day,30,cast('1998-06-06' as date)) - group by i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - order by i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query20.tpl query 26 in stream 7 --- start template query2.tpl query 27 in stream 7 -with /* TPC-DS query2.tpl 0.84 */ wscs as - (select sold_date_sk - ,sales_price - from (select ws_sold_date_sk sold_date_sk - ,ws_ext_sales_price sales_price - from web_sales - union all - select cs_sold_date_sk sold_date_sk - ,cs_ext_sales_price sales_price - from catalog_sales)), - wswscs as - (select d_week_seq, - sum(case when (d_day_name='Sunday') then sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then sales_price else null end) sat_sales - from wscs - ,date_dim - where d_date_sk = sold_date_sk - group by d_week_seq) - select d_week_seq1 - ,round(sun_sales1/sun_sales2,2) - ,round(mon_sales1/mon_sales2,2) - ,round(tue_sales1/tue_sales2,2) - ,round(wed_sales1/wed_sales2,2) - ,round(thu_sales1/thu_sales2,2) - ,round(fri_sales1/fri_sales2,2) - ,round(sat_sales1/sat_sales2,2) - from - (select wswscs.d_week_seq d_week_seq1 - ,sun_sales sun_sales1 - ,mon_sales mon_sales1 - ,tue_sales tue_sales1 - ,wed_sales wed_sales1 - ,thu_sales thu_sales1 - ,fri_sales fri_sales1 - ,sat_sales sat_sales1 - from wswscs,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 1998) y, - (select wswscs.d_week_seq d_week_seq2 - ,sun_sales sun_sales2 - ,mon_sales mon_sales2 - ,tue_sales tue_sales2 - ,wed_sales wed_sales2 - ,thu_sales thu_sales2 - ,fri_sales fri_sales2 - ,sat_sales sat_sales2 - from wswscs - ,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 1998+1) z - where d_week_seq1=d_week_seq2-53 - order by d_week_seq1; - --- end template query2.tpl query 27 in stream 7 --- start template query21.tpl query 28 in stream 7 -select /* TPC-DS query21.tpl 0.14 */ * - from(select w_warehouse_name - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('2001-02-08' as date)) - then inv_quantity_on_hand - else 0 end) as inv_before - ,sum(case when (cast(d_date as date) >= cast ('2001-02-08' as date)) - then inv_quantity_on_hand - else 0 end) as inv_after - from inventory - ,warehouse - ,item - ,date_dim - where i_current_price between 0.99 and 1.49 - and i_item_sk = inv_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('2001-02-08' as date)) - and dateadd(day,30,cast ('2001-02-08' as date)) - group by w_warehouse_name, i_item_id) x - where (case when inv_before > 0 - then inv_after / inv_before - else null - end) between 2.0/3.0 and 3.0/2.0 - order by w_warehouse_name - ,i_item_id - limit 100; - --- end template query21.tpl query 28 in stream 7 --- start template query97.tpl query 29 in stream 7 -with /* TPC-DS query97.tpl 0.38 */ ssci as ( -select ss_customer_sk customer_sk - ,ss_item_sk item_sk -from store_sales,date_dim -where ss_sold_date_sk = d_date_sk - and d_month_seq between 1219 and 1219 + 11 -group by ss_customer_sk - ,ss_item_sk), -csci as( - select cs_bill_customer_sk customer_sk - ,cs_item_sk item_sk -from catalog_sales,date_dim -where cs_sold_date_sk = d_date_sk - and d_month_seq between 1219 and 1219 + 11 -group by cs_bill_customer_sk - ,cs_item_sk) - select sum(case when ssci.customer_sk is not null and csci.customer_sk is null then 1 else 0 end) store_only - ,sum(case when ssci.customer_sk is null and csci.customer_sk is not null then 1 else 0 end) catalog_only - ,sum(case when ssci.customer_sk is not null and csci.customer_sk is not null then 1 else 0 end) store_and_catalog -from ssci full outer join csci on (ssci.customer_sk=csci.customer_sk - and ssci.item_sk = csci.item_sk) -limit 100; - --- end template query97.tpl query 29 in stream 7 --- start template query62.tpl query 30 in stream 7 -select /* TPC-DS query62.tpl 0.24 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 30) and - (ws_ship_date_sk - ws_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 60) and - (ws_ship_date_sk - ws_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 90) and - (ws_ship_date_sk - ws_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - web_sales - ,warehouse - ,ship_mode - ,web_site - ,date_dim -where - d_month_seq between 1224 and 1224 + 11 -and ws_ship_date_sk = d_date_sk -and ws_warehouse_sk = w_warehouse_sk -and ws_ship_mode_sk = sm_ship_mode_sk -and ws_web_site_sk = web_site_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -limit 100; - --- end template query62.tpl query 30 in stream 7 --- start template query47.tpl query 31 in stream 7 -with /* TPC-DS query47.tpl 0.42 */ v1 as( - select i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, - s_store_name, s_company_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - s_store_name, s_company_name - order by d_year, d_moy) rn - from item, store_sales, date_dim, store - where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - ( - d_year = 2000 or - ( d_year = 2000-1 and d_moy =12) or - ( d_year = 2000+1 and d_moy =1) - ) - group by i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy), - v2 as( - select v1.s_company_name - ,v1.d_year - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1.s_store_name = v1_lag.s_store_name and - v1.s_store_name = v1_lead.s_store_name and - v1.s_company_name = v1_lag.s_company_name and - v1.s_company_name = v1_lead.s_company_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 2000 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, avg_monthly_sales - limit 100; - --- end template query47.tpl query 31 in stream 7 --- start template query60.tpl query 32 in stream 7 -with /* TPC-DS query60.tpl 0.29 */ ss as ( - select - i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Shoes')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 10 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id), - cs as ( - select - i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Shoes')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 10 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id), - ws as ( - select - i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Shoes')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 10 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id) - select - i_item_id -,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by i_item_id - ,total_sales - limit 100; - --- end template query60.tpl query 32 in stream 7 --- start template query71.tpl query 33 in stream 7 -select /* TPC-DS query71.tpl 0.72 */ i_brand_id brand_id, i_brand brand,t_hour,t_minute, - sum(ext_price) ext_price - from item, (select ws_ext_sales_price as ext_price, - ws_sold_date_sk as sold_date_sk, - ws_item_sk as sold_item_sk, - ws_sold_time_sk as time_sk - from web_sales,date_dim - where d_date_sk = ws_sold_date_sk - and d_moy=12 - and d_year=2001 - union all - select cs_ext_sales_price as ext_price, - cs_sold_date_sk as sold_date_sk, - cs_item_sk as sold_item_sk, - cs_sold_time_sk as time_sk - from catalog_sales,date_dim - where d_date_sk = cs_sold_date_sk - and d_moy=12 - and d_year=2001 - union all - select ss_ext_sales_price as ext_price, - ss_sold_date_sk as sold_date_sk, - ss_item_sk as sold_item_sk, - ss_sold_time_sk as time_sk - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - and d_moy=12 - and d_year=2001 - ) tmp,time_dim - where - sold_item_sk = i_item_sk - and i_manager_id=1 - and time_sk = t_time_sk - and (t_meal_time = 'breakfast' or t_meal_time = 'dinner') - group by i_brand, i_brand_id,t_hour,t_minute - order by ext_price desc, i_brand_id - ; - --- end template query71.tpl query 33 in stream 7 --- start template query46.tpl query 34 in stream 7 -select /* TPC-DS query46.tpl 0.23 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and (household_demographics.hd_dep_count = 6 or - household_demographics.hd_vehicle_count= -1) - and date_dim.d_dow in (6,0) - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_city in ('Fairfax','Greenville','Midland','Lake City','Preston') - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,ca_city) dn,customer,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - limit 100; - --- end template query46.tpl query 34 in stream 7 --- start template query10.tpl query 35 in stream 7 -select /* TPC-DS query10.tpl 0.26 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3, - cd_dep_count, - count(*) cnt4, - cd_dep_employed_count, - count(*) cnt5, - cd_dep_college_count, - count(*) cnt6 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_county in ('Sutter County','Graham County','Pueblo County','Mora County','Calaveras County') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 4 and 4+3) and - (exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 4 ANd 4+3) or - exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 4 and 4+3)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count -limit 100; - --- end template query10.tpl query 35 in stream 7 --- start template query14a.tpl query 36 in stream 7 -with /* TPC-DS query14a.tpl 0.69 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1999 AND 1999 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1999 AND 1999 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1999 AND 1999 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as - (select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2) x) -, - results AS -(select channel, i_brand_id, i_class_id, i_category_id, sum(sales) sum_sales, sum(number_sales) number_sales - from ( - select 'store' channel, i_brand_id,i_class_id - ,i_category_id,sum(ss_quantity*ss_list_price) sales - , count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1999+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales) - union all - select 'catalog' channel, i_brand_id,i_class_id,i_category_id, sum(cs_quantity*cs_list_price) sales, count(*) number_sales - from catalog_sales - ,item - ,date_dim - where cs_item_sk in (select ss_item_sk from cross_items) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1999+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(cs_quantity*cs_list_price) > (select average_sales from avg_sales) - union all - select 'web' channel, i_brand_id,i_class_id,i_category_id, sum(ws_quantity*ws_list_price) sales , count(*) number_sales - from web_sales - ,item - ,date_dim - where ws_item_sk in (select ss_item_sk from cross_items) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1999+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ws_quantity*ws_list_price) > (select average_sales from avg_sales) - ) y - group by channel, i_brand_id,i_class_id,i_category_id) - - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales -from ( - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales from results - union - select channel, i_brand_id, i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id, i_class_id - union - select channel, i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id - union - select channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel - union - select null as channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results) z -order by channel, i_brand_id, i_class_id, i_category_id - limit 100; -with /* TPC-DS query14a.tpl 0.69 part2 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1999 AND 1999 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1999 AND 1999 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1999 AND 1999 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as -(select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2) x) - select this_year.channel ty_channel - ,this_year.i_brand_id ty_brand - ,this_year.i_class_id ty_class - ,this_year.i_category_id ty_category - ,this_year.sales ty_sales - ,this_year.number_sales ty_number_sales - ,last_year.channel ly_channel - ,last_year.i_brand_id ly_brand - ,last_year.i_class_id ly_class - ,last_year.i_category_id ly_category - ,last_year.sales ly_sales - ,last_year.number_sales ly_number_sales -from - (select 'store' channel, i_brand_id,i_class_id,i_category_id - ,sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1999 + 1 - and d_moy = 12 - and d_dom = 27) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) this_year, - (select 'store' channel, i_brand_id,i_class_id - ,i_category_id, sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1999 - and d_moy = 12 - and d_dom = 27) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) last_year - where this_year.i_brand_id= last_year.i_brand_id - and this_year.i_class_id = last_year.i_class_id - and this_year.i_category_id = last_year.i_category_id - order by this_year.channel, this_year.i_brand_id, this_year.i_class_id, this_year.i_category_id - limit 100; - --- end template query14a.tpl query 36 in stream 7 --- start template query35a.tpl query 37 in stream 7 -select /* TPC-DS query35a.tpl 0.47 */ - ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - count(*) cnt1, - avg(cd_dep_count), - stddev_samp(cd_dep_count), - stddev_samp(cd_dep_count), - cd_dep_employed_count, - count(*) cnt2, - avg(cd_dep_employed_count), - stddev_samp(cd_dep_employed_count), - stddev_samp(cd_dep_employed_count), - cd_dep_college_count, - count(*) cnt3, - avg(cd_dep_college_count), - stddev_samp(cd_dep_college_count), - stddev_samp(cd_dep_college_count) - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2000 and - d_qoy < 4) and - exists (select * from - (select ws_bill_customer_sk customsk - from web_sales,date_dim - where - ws_sold_date_sk = d_date_sk and - d_year = 2000 and - d_qoy < 4 - union all - select cs_ship_customer_sk customsk - from catalog_sales,date_dim - where - cs_sold_date_sk = d_date_sk and - d_year = 2000 and - d_qoy < 4)x - where x.customsk = c.c_customer_sk) - group by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - limit 100; - --- end template query35a.tpl query 37 in stream 7 --- start template query55.tpl query 38 in stream 7 -select /* TPC-DS query55.tpl 0.82 */ i_brand_id brand_id, i_brand brand, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=45 - and d_moy=12 - and d_year=1999 - group by i_brand, i_brand_id - order by ext_price desc, i_brand_id -limit 100 ; - --- end template query55.tpl query 38 in stream 7 --- start template query37.tpl query 39 in stream 7 -select /* TPC-DS query37.tpl 0.31 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, catalog_sales - where i_current_price between 59 and 59 + 30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('1998-07-03' as date) and dateadd(day,60,cast('1998-07-03' as date)) - and i_manufact_id in (860,791,836,867) - and inv_quantity_on_hand between 100 and 500 - and cs_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query37.tpl query 39 in stream 7 --- start template query52.tpl query 40 in stream 7 -select /* TPC-DS query52.tpl 0.59 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_sales_price) ext_price - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=11 - and dt.d_year=2002 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,ext_price desc - ,brand_id -limit 100 ; - --- end template query52.tpl query 40 in stream 7 --- start template query9.tpl query 41 in stream 7 -select /* TPC-DS query9.tpl 0.49 */ case when (select count(*) - from store_sales - where ss_quantity between 1 and 20) > 630329129 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 1 and 20) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 1 and 20) end bucket1 , - case when (select count(*) - from store_sales - where ss_quantity between 21 and 40) > 1045765723 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 21 and 40) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 21 and 40) end bucket2, - case when (select count(*) - from store_sales - where ss_quantity between 41 and 60) > 4420161001 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 41 and 60) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 41 and 60) end bucket3, - case when (select count(*) - from store_sales - where ss_quantity between 61 and 80) > 1206589815 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 61 and 80) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 61 and 80) end bucket4, - case when (select count(*) - from store_sales - where ss_quantity between 81 and 100) > 2018658541 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 81 and 100) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 81 and 100) end bucket5 -from reason -where r_reason_sk = 1 -; - --- end template query9.tpl query 41 in stream 7 --- start template query85.tpl query 42 in stream 7 -select /* TPC-DS query85.tpl 0.33 */ substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) - from web_sales, web_returns, web_page, customer_demographics cd1, - customer_demographics cd2, customer_address, date_dim, reason - where ws_web_page_sk = wp_web_page_sk - and ws_item_sk = wr_item_sk - and ws_order_number = wr_order_number - and ws_sold_date_sk = d_date_sk and d_year = 2002 - and cd1.cd_demo_sk = wr_refunded_cdemo_sk - and cd2.cd_demo_sk = wr_returning_cdemo_sk - and ca_address_sk = wr_refunded_addr_sk - and r_reason_sk = wr_reason_sk - and - ( - ( - cd1.cd_marital_status = 'M' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Advanced Degree' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 100.00 and 150.00 - ) - or - ( - cd1.cd_marital_status = 'S' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'College' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 50.00 and 100.00 - ) - or - ( - cd1.cd_marital_status = 'U' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Primary' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ca_country = 'United States' - and - ca_state in ('TX', 'AL', 'MI') - and ws_net_profit between 100 and 200 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('NE', 'SC', 'KY') - and ws_net_profit between 150 and 300 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('ID', 'OK', 'IN') - and ws_net_profit between 50 and 250 - ) - ) -group by r_reason_desc -order by substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) -limit 100; - --- end template query85.tpl query 42 in stream 7 --- start template query40.tpl query 43 in stream 7 -select /* TPC-DS query40.tpl 0.86 */ - w_state - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('2001-05-09' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_before - ,sum(case when (cast(d_date as date) >= cast ('2001-05-09' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_after - from - catalog_sales left outer join catalog_returns on - (cs_order_number = cr_order_number - and cs_item_sk = cr_item_sk) - ,warehouse - ,item - ,date_dim - where - i_current_price between 0.99 and 1.49 - and i_item_sk = cs_item_sk - and cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('2001-05-09' as date)) - and dateadd(day,30,cast ('2001-05-09' as date)) - group by - w_state,i_item_id - order by w_state,i_item_id -limit 100; - --- end template query40.tpl query 43 in stream 7 --- start template query76.tpl query 44 in stream 7 -select /* TPC-DS query76.tpl 0.99 */ channel, col_name, d_year, d_qoy, i_category, COUNT(*) sales_cnt, SUM(ext_sales_price) sales_amt FROM ( - SELECT 'store' as channel, 'ss_promo_sk' col_name, d_year, d_qoy, i_category, ss_ext_sales_price ext_sales_price - FROM store_sales, item, date_dim - WHERE ss_promo_sk IS NULL - AND ss_sold_date_sk=d_date_sk - AND ss_item_sk=i_item_sk - UNION ALL - SELECT 'web' as channel, 'ws_web_site_sk' col_name, d_year, d_qoy, i_category, ws_ext_sales_price ext_sales_price - FROM web_sales, item, date_dim - WHERE ws_web_site_sk IS NULL - AND ws_sold_date_sk=d_date_sk - AND ws_item_sk=i_item_sk - UNION ALL - SELECT 'catalog' as channel, 'cs_ship_addr_sk' col_name, d_year, d_qoy, i_category, cs_ext_sales_price ext_sales_price - FROM catalog_sales, item, date_dim - WHERE cs_ship_addr_sk IS NULL - AND cs_sold_date_sk=d_date_sk - AND cs_item_sk=i_item_sk) foo -GROUP BY channel, col_name, d_year, d_qoy, i_category -ORDER BY channel, col_name, d_year, d_qoy, i_category -limit 100; - --- end template query76.tpl query 44 in stream 7 --- start template query44.tpl query 45 in stream 7 -select /* TPC-DS query44.tpl 0.4 */ asceding.rnk, i1.i_product_name best_performing, i2.i_product_name worst_performing -from(select * - from (select item_sk,rank() over (order by rank_col asc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 654 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 654 - and ss_customer_sk is null - group by ss_store_sk))V1)V11 - where rnk < 11) asceding, - (select * - from (select item_sk,rank() over (order by rank_col desc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 654 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 654 - and ss_customer_sk is null - group by ss_store_sk))V2)V21 - where rnk < 11) descending, -item i1, -item i2 -where asceding.rnk = descending.rnk - and i1.i_item_sk=asceding.item_sk - and i2.i_item_sk=descending.item_sk -order by asceding.rnk -limit 100; - --- end template query44.tpl query 45 in stream 7 --- start template query3.tpl query 46 in stream 7 -select /* TPC-DS query3.tpl 0.45 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_discount_amt) sum_agg - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manufact_id = 212 - and dt.d_moy=12 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,sum_agg desc - ,brand_id - limit 100; - --- end template query3.tpl query 46 in stream 7 --- start template query26.tpl query 47 in stream 7 -select /* TPC-DS query26.tpl 0.85 */ i_item_id, - avg(cs_quantity) agg1, - avg(cs_list_price) agg2, - avg(cs_coupon_amt) agg3, - avg(cs_sales_price) agg4 - from catalog_sales, customer_demographics, date_dim, item, promotion - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd_demo_sk and - cs_promo_sk = p_promo_sk and - cd_gender = 'M' and - cd_marital_status = 'U' and - cd_education_status = 'Unknown' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 2000 - group by i_item_id - order by i_item_id - limit 100; - --- end template query26.tpl query 47 in stream 7 --- start template query19.tpl query 48 in stream 7 -select /* TPC-DS query19.tpl 0.8 */ i_brand_id brand_id, i_brand brand, i_manufact_id, i_manufact, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item,customer,customer_address,store - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=23 - and d_moy=12 - and d_year=1999 - and ss_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and substring(ca_zip,1,5) <> substring(s_zip,1,5) - and ss_store_sk = s_store_sk - group by i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact - order by ext_price desc - ,i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact -limit 100 ; - --- end template query19.tpl query 48 in stream 7 --- start template query58.tpl query 49 in stream 7 -with /* TPC-DS query58.tpl 0.19 */ ss_items as - (select i_item_id item_id - ,sum(ss_ext_sales_price) ss_item_rev - from store_sales - ,item - ,date_dim - where ss_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '2002-07-10')) - and ss_sold_date_sk = d_date_sk - group by i_item_id), - cs_items as - (select i_item_id item_id - ,sum(cs_ext_sales_price) cs_item_rev - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '2002-07-10')) - and cs_sold_date_sk = d_date_sk - group by i_item_id), - ws_items as - (select i_item_id item_id - ,sum(ws_ext_sales_price) ws_item_rev - from web_sales - ,item - ,date_dim - where ws_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq =(select d_week_seq - from date_dim - where d_date = '2002-07-10')) - and ws_sold_date_sk = d_date_sk - group by i_item_id) - select ss_items.item_id - ,ss_item_rev - ,ss_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ss_dev - ,cs_item_rev - ,cs_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 cs_dev - ,ws_item_rev - ,ws_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ws_dev - ,(ss_item_rev+cs_item_rev+ws_item_rev)/3 average - from ss_items,cs_items,ws_items - where ss_items.item_id=cs_items.item_id - and ss_items.item_id=ws_items.item_id - and ss_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - and ss_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and cs_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and cs_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and ws_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and ws_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - order by item_id - ,ss_item_rev - limit 100; - --- end template query58.tpl query 49 in stream 7 --- start template query42.tpl query 50 in stream 7 -select /* TPC-DS query42.tpl 0.61 */ dt.d_year - ,item.i_category_id - ,item.i_category - ,sum(ss_ext_sales_price) - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=12 - and dt.d_year=1998 - group by dt.d_year - ,item.i_category_id - ,item.i_category - order by sum(ss_ext_sales_price) desc,dt.d_year - ,item.i_category_id - ,item.i_category -limit 100 ; - --- end template query42.tpl query 50 in stream 7 --- start template query75.tpl query 51 in stream 7 -WITH /* TPC-DS query75.tpl 0.3 */ all_sales AS ( - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,SUM(sales_cnt) AS sales_cnt - ,SUM(sales_amt) AS sales_amt - FROM (SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,cs_quantity - COALESCE(cr_return_quantity,0) AS sales_cnt - ,cs_ext_sales_price - COALESCE(cr_return_amount,0.0) AS sales_amt - FROM catalog_sales JOIN item ON i_item_sk=cs_item_sk - JOIN date_dim ON d_date_sk=cs_sold_date_sk - LEFT JOIN catalog_returns ON (cs_order_number=cr_order_number - AND cs_item_sk=cr_item_sk) - WHERE i_category='Electronics' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ss_quantity - COALESCE(sr_return_quantity,0) AS sales_cnt - ,ss_ext_sales_price - COALESCE(sr_return_amt,0.0) AS sales_amt - FROM store_sales JOIN item ON i_item_sk=ss_item_sk - JOIN date_dim ON d_date_sk=ss_sold_date_sk - LEFT JOIN store_returns ON (ss_ticket_number=sr_ticket_number - AND ss_item_sk=sr_item_sk) - WHERE i_category='Electronics' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ws_quantity - COALESCE(wr_return_quantity,0) AS sales_cnt - ,ws_ext_sales_price - COALESCE(wr_return_amt,0.0) AS sales_amt - FROM web_sales JOIN item ON i_item_sk=ws_item_sk - JOIN date_dim ON d_date_sk=ws_sold_date_sk - LEFT JOIN web_returns ON (ws_order_number=wr_order_number - AND ws_item_sk=wr_item_sk) - WHERE i_category='Electronics') sales_detail - GROUP BY d_year, i_brand_id, i_class_id, i_category_id, i_manufact_id) - SELECT prev_yr.d_year AS prev_year - ,curr_yr.d_year AS year - ,curr_yr.i_brand_id - ,curr_yr.i_class_id - ,curr_yr.i_category_id - ,curr_yr.i_manufact_id - ,prev_yr.sales_cnt AS prev_yr_cnt - ,curr_yr.sales_cnt AS curr_yr_cnt - ,curr_yr.sales_cnt-prev_yr.sales_cnt AS sales_cnt_diff - ,curr_yr.sales_amt-prev_yr.sales_amt AS sales_amt_diff - FROM all_sales curr_yr, all_sales prev_yr - WHERE curr_yr.i_brand_id=prev_yr.i_brand_id - AND curr_yr.i_class_id=prev_yr.i_class_id - AND curr_yr.i_category_id=prev_yr.i_category_id - AND curr_yr.i_manufact_id=prev_yr.i_manufact_id - AND curr_yr.d_year=2002 - AND prev_yr.d_year=2002-1 - AND CAST(curr_yr.sales_cnt AS DECIMAL(17,2))/CAST(prev_yr.sales_cnt AS DECIMAL(17,2))<0.9 - ORDER BY sales_cnt_diff,sales_amt_diff - limit 100; - --- end template query75.tpl query 51 in stream 7 --- start template query17.tpl query 52 in stream 7 -select /* TPC-DS query17.tpl 0.41 */ i_item_id - ,i_item_desc - ,s_state - ,count(ss_quantity) as store_sales_quantitycount - ,avg(ss_quantity) as store_sales_quantityave - ,stddev_samp(ss_quantity) as store_sales_quantitystdev - ,stddev_samp(ss_quantity)/avg(ss_quantity) as store_sales_quantitycov - ,count(sr_return_quantity) as store_returns_quantitycount - ,avg(sr_return_quantity) as store_returns_quantityave - ,stddev_samp(sr_return_quantity) as store_returns_quantitystdev - ,stddev_samp(sr_return_quantity)/avg(sr_return_quantity) as store_returns_quantitycov - ,count(cs_quantity) as catalog_sales_quantitycount ,avg(cs_quantity) as catalog_sales_quantityave - ,stddev_samp(cs_quantity) as catalog_sales_quantitystdev - ,stddev_samp(cs_quantity)/avg(cs_quantity) as catalog_sales_quantitycov - from store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where d1.d_quarter_name = '1998Q1' - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_quarter_name in ('1998Q1','1998Q2','1998Q3') - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_quarter_name in ('1998Q1','1998Q2','1998Q3') - group by i_item_id - ,i_item_desc - ,s_state - order by i_item_id - ,i_item_desc - ,s_state -limit 100; - --- end template query17.tpl query 52 in stream 7 --- start template query38.tpl query 53 in stream 7 -select /* TPC-DS query38.tpl 0.54 */ count(*) from ( - select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1200 and 1200 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1200 and 1200 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1200 and 1200 + 11 -) hot_cust -limit 100; - --- end template query38.tpl query 53 in stream 7 --- start template query82.tpl query 54 in stream 7 -select /* TPC-DS query82.tpl 0.67 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, store_sales - where i_current_price between 20 and 20+30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('2000-06-17' as date) and dateadd(day,60,cast('2000-06-17' as date)) - and i_manufact_id in (88,175,734,833) - and inv_quantity_on_hand between 100 and 500 - and ss_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query82.tpl query 54 in stream 7 --- start template query87.tpl query 55 in stream 7 -select /* TPC-DS query87.tpl 0.77 */ count(*) -from ((select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1203 and 1203+11) - except - (select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1203 and 1203+11) - except - (select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1203 and 1203+11) -) cool_cust -; - --- end template query87.tpl query 55 in stream 7 --- start template query43.tpl query 56 in stream 7 -select /* TPC-DS query43.tpl 0.15 */ s_store_name, s_store_id, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from date_dim, store_sales, store - where d_date_sk = ss_sold_date_sk and - s_store_sk = ss_store_sk and - s_gmt_offset = -5 and - d_year = 2002 - group by s_store_name, s_store_id - order by s_store_name, s_store_id,sun_sales,mon_sales,tue_sales,wed_sales,thu_sales,fri_sales,sat_sales - limit 100; - --- end template query43.tpl query 56 in stream 7 --- start template query11.tpl query 57 in stream 7 -with /* TPC-DS query11.tpl 0.51 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ss_ext_list_price-ss_ext_discount_amt) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ws_ext_list_price-ws_ext_discount_amt) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_login - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 1998 - and t_s_secyear.dyear = 1998+1 - and t_w_firstyear.dyear = 1998 - and t_w_secyear.dyear = 1998+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else 0.0 end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else 0.0 end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_login -limit 100; - --- end template query11.tpl query 57 in stream 7 --- start template query5a.tpl query 58 in stream 7 -with /* TPC-DS query5a.tpl 0.98 */ ssr as - (select s_store_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ss_store_sk as store_sk, - ss_sold_date_sk as date_sk, - ss_ext_sales_price as sales_price, - ss_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from store_sales - union all - select sr_store_sk as store_sk, - sr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - sr_return_amt as return_amt, - sr_net_loss as net_loss - from store_returns - ) salesreturns, - date_dim, - store - where date_sk = d_date_sk - and d_date between cast('2001-08-12' as date) - and dateadd(day,14,cast('2001-08-12' as date)) - and store_sk = s_store_sk - group by s_store_id) - , - csr as - (select cp_catalog_page_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select cs_catalog_page_sk as page_sk, - cs_sold_date_sk as date_sk, - cs_ext_sales_price as sales_price, - cs_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from catalog_sales - union all - select cr_catalog_page_sk as page_sk, - cr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - cr_return_amount as return_amt, - cr_net_loss as net_loss - from catalog_returns - ) salesreturns, - date_dim, - catalog_page - where date_sk = d_date_sk - and d_date between cast('2001-08-12' as date) - and dateadd(day,14,cast('2001-08-12' as date)) - and page_sk = cp_catalog_page_sk - group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ws_web_site_sk as wsr_web_site_sk, - ws_sold_date_sk as date_sk, - ws_ext_sales_price as sales_price, - ws_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from web_sales - union all - select ws_web_site_sk as wsr_web_site_sk, - wr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - wr_return_amt as return_amt, - wr_net_loss as net_loss - from web_returns left outer join web_sales on - ( wr_item_sk = ws_item_sk - and wr_order_number = ws_order_number) - ) salesreturns, - date_dim, - web_site - where date_sk = d_date_sk - and d_date between cast('2001-08-12' as date) - and dateadd(day,14,cast('2001-08-12' as date)) - and wsr_web_site_sk = web_site_sk - group by web_site_id) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || s_store_id as id - , sales - , returns - , (profit - profit_loss) as profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || cp_catalog_page_id as id - , sales - , returns - , (profit - profit_loss) as profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , (profit - profit_loss) as profit - from wsr - ) x - group by channel, id) - select channel, id, sales, returns, profit from ( - select channel, id, sales, returns, profit from results - union - select channel, null as id, sum(sales), sum(returns), sum(profit) from results group by channel - union - select null as channel, null as id, sum(sales), sum(returns), sum(profit) from results) foo -order by channel, id -limit 100; - --- end template query5a.tpl query 58 in stream 7 --- start template query41.tpl query 59 in stream 7 -select /* TPC-DS query41.tpl 0.62 */ distinct(i_product_name) - from item i1 - where i_manufact_id between 934 and 934+40 - and (select count(*) as item_cnt - from item - where (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'rose' or i_color = 'plum') and - (i_units = 'Bunch' or i_units = 'Pallet') and - (i_size = 'medium' or i_size = 'economy') - ) or - (i_category = 'Women' and - (i_color = 'spring' or i_color = 'burnished') and - (i_units = 'N/A' or i_units = 'Tbl') and - (i_size = 'large' or i_size = 'small') - ) or - (i_category = 'Men' and - (i_color = 'steel' or i_color = 'blanched') and - (i_units = 'Box' or i_units = 'Ounce') and - (i_size = 'N/A' or i_size = 'extra large') - ) or - (i_category = 'Men' and - (i_color = 'peach' or i_color = 'ivory') and - (i_units = 'Gram' or i_units = 'Each') and - (i_size = 'medium' or i_size = 'economy') - ))) or - (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'chartreuse' or i_color = 'saddle') and - (i_units = 'Pound' or i_units = 'Oz') and - (i_size = 'medium' or i_size = 'economy') - ) or - (i_category = 'Women' and - (i_color = 'purple' or i_color = 'metallic') and - (i_units = 'Gross' or i_units = 'Case') and - (i_size = 'large' or i_size = 'small') - ) or - (i_category = 'Men' and - (i_color = 'floral' or i_color = 'mint') and - (i_units = 'Carton' or i_units = 'Ton') and - (i_size = 'N/A' or i_size = 'extra large') - ) or - (i_category = 'Men' and - (i_color = 'maroon' or i_color = 'wheat') and - (i_units = 'Tsp' or i_units = 'Unknown') and - (i_size = 'medium' or i_size = 'economy') - )))) > 0 - order by i_product_name - limit 100; - --- end template query41.tpl query 59 in stream 7 --- start template query61.tpl query 60 in stream 7 -select /* TPC-DS query61.tpl 0.97 */ promotions,total,cast(promotions as decimal(16,4))/cast(total as decimal(16,4))*100 -from - (select sum(ss_ext_sales_price) promotions - from store_sales - ,store - ,promotion - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_promo_sk = p_promo_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -6 - and i_category = 'Home' - and (p_channel_dmail = 'Y' or p_channel_email = 'Y' or p_channel_tv = 'Y') - and s_gmt_offset = -6 - and d_year = 1998 - and d_moy = 12) promotional_sales, - (select sum(ss_ext_sales_price) total - from store_sales - ,store - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -6 - and i_category = 'Home' - and s_gmt_offset = -6 - and d_year = 1998 - and d_moy = 12) all_sales -order by promotions, total -limit 100; - --- end template query61.tpl query 60 in stream 7 --- start template query33.tpl query 61 in stream 7 -with /* TPC-DS query33.tpl 0.22 */ ss as ( - select - i_manufact_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Books')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 7 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -7 - group by i_manufact_id), - cs as ( - select - i_manufact_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Books')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 7 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -7 - group by i_manufact_id), - ws as ( - select - i_manufact_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Books')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 7 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -7 - group by i_manufact_id) - select i_manufact_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_manufact_id - order by total_sales -limit 100; - --- end template query33.tpl query 61 in stream 7 --- start template query49.tpl query 62 in stream 7 -select /* TPC-DS query49.tpl 0.48 */ channel, item, return_ratio, return_rank, currency_rank from - (select - 'web' as channel - ,web.item - ,web.return_ratio - ,web.return_rank - ,web.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select ws.ws_item_sk as item - ,(cast(sum(coalesce(wr.wr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(wr.wr_return_amt,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - web_sales ws left outer join web_returns wr - on (ws.ws_order_number = wr.wr_order_number and - ws.ws_item_sk = wr.wr_item_sk) - ,date_dim - where - wr.wr_return_amt > 10000 - and ws.ws_net_profit > 1 - and ws.ws_net_paid > 0 - and ws.ws_quantity > 0 - and ws_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 11 - group by ws.ws_item_sk - ) in_web - ) web - where - ( - web.return_rank <= 10 - or - web.currency_rank <= 10 - ) - union - select - 'catalog' as channel - ,catalog.item - ,catalog.return_ratio - ,catalog.return_rank - ,catalog.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select - cs.cs_item_sk as item - ,(cast(sum(coalesce(cr.cr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(cr.cr_return_amount,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - catalog_sales cs left outer join catalog_returns cr - on (cs.cs_order_number = cr.cr_order_number and - cs.cs_item_sk = cr.cr_item_sk) - ,date_dim - where - cr.cr_return_amount > 10000 - and cs.cs_net_profit > 1 - and cs.cs_net_paid > 0 - and cs.cs_quantity > 0 - and cs_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 11 - group by cs.cs_item_sk - ) in_cat - ) catalog - where - ( - catalog.return_rank <= 10 - or - catalog.currency_rank <=10 - ) - union - select - 'store' as channel - ,store.item - ,store.return_ratio - ,store.return_rank - ,store.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select sts.ss_item_sk as item - ,(cast(sum(coalesce(sr.sr_return_quantity,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(sr.sr_return_amt,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - store_sales sts left outer join store_returns sr - on (sts.ss_ticket_number = sr.sr_ticket_number and sts.ss_item_sk = sr.sr_item_sk) - ,date_dim - where - sr.sr_return_amt > 10000 - and sts.ss_net_profit > 1 - and sts.ss_net_paid > 0 - and sts.ss_quantity > 0 - and ss_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 11 - group by sts.ss_item_sk - ) in_store - ) store - where ( - store.return_rank <= 10 - or - store.currency_rank <= 10 - ) - ) - order by 1,4,5,2 - limit 100; - --- end template query49.tpl query 62 in stream 7 --- start template query7.tpl query 63 in stream 7 -select /* TPC-DS query7.tpl 0.2 */ i_item_id, - avg(ss_quantity) agg1, - avg(ss_list_price) agg2, - avg(ss_coupon_amt) agg3, - avg(ss_sales_price) agg4 - from store_sales, customer_demographics, date_dim, item, promotion - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_cdemo_sk = cd_demo_sk and - ss_promo_sk = p_promo_sk and - cd_gender = 'M' and - cd_marital_status = 'U' and - cd_education_status = 'Primary' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 1998 - group by i_item_id - order by i_item_id - limit 100; - --- end template query7.tpl query 63 in stream 7 --- start template query73.tpl query 64 in stream 7 -select /* TPC-DS query73.tpl 0.79 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_buy_potential = '>10000' or - household_demographics.hd_buy_potential = 'Unknown') - and household_demographics.hd_vehicle_count > 0 - and case when household_demographics.hd_vehicle_count > 0 then - household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count else null end > 1 - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_county in ('Daviess County','Red River Parish','Price County','Tippecanoe County') - group by ss_ticket_number,ss_customer_sk) dj,customer - where ss_customer_sk = c_customer_sk - and cnt between 1 and 5 - order by cnt desc, c_last_name asc; - --- end template query73.tpl query 64 in stream 7 --- start template query89.tpl query 65 in stream 7 -select /* TPC-DS query89.tpl 0.56 */ * -from( -select i_category, i_class, i_brand, - s_store_name, s_company_name, - d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, s_store_name, s_company_name) - avg_monthly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - d_year in (1999) and - ((i_category in ('Jewelry','Women','Books') and - i_class in ('diamonds','maternity','entertainments') - ) - or (i_category in ('Children','Electronics','Music') and - i_class in ('newborn','cameras','pop') - )) -group by i_category, i_class, i_brand, - s_store_name, s_company_name, d_moy) tmp1 -where case when (avg_monthly_sales <> 0) then (abs(sum_sales - avg_monthly_sales) / avg_monthly_sales) else null end > 0.1 -order by sum_sales - avg_monthly_sales, s_store_name -limit 100; - --- end template query89.tpl query 65 in stream 7 --- start template query81.tpl query 66 in stream 7 -with /* TPC-DS query81.tpl 0.37 */ customer_total_return as - (select cr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(cr_return_amt_inc_tax) as ctr_total_return - from catalog_returns - ,date_dim - ,customer_address - where cr_returned_date_sk = d_date_sk - and d_year =2002 - and cr_returning_addr_sk = ca_address_sk - group by cr_returning_customer_sk - ,ca_state ) - select c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'OK' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - limit 100; - --- end template query81.tpl query 66 in stream 7 --- start template query78.tpl query 67 in stream 7 -with /* TPC-DS query78.tpl 0.10 */ ws as - (select d_year AS ws_sold_year, ws_item_sk, - ws_bill_customer_sk ws_customer_sk, - sum(ws_quantity) ws_qty, - sum(ws_wholesale_cost) ws_wc, - sum(ws_sales_price) ws_sp - from web_sales - left join web_returns on wr_order_number=ws_order_number and ws_item_sk=wr_item_sk - join date_dim on ws_sold_date_sk = d_date_sk - where wr_order_number is null - group by d_year, ws_item_sk, ws_bill_customer_sk - ), -cs as - (select d_year AS cs_sold_year, cs_item_sk, - cs_bill_customer_sk cs_customer_sk, - sum(cs_quantity) cs_qty, - sum(cs_wholesale_cost) cs_wc, - sum(cs_sales_price) cs_sp - from catalog_sales - left join catalog_returns on cr_order_number=cs_order_number and cs_item_sk=cr_item_sk - join date_dim on cs_sold_date_sk = d_date_sk - where cr_order_number is null - group by d_year, cs_item_sk, cs_bill_customer_sk - ), -ss as - (select d_year AS ss_sold_year, ss_item_sk, - ss_customer_sk, - sum(ss_quantity) ss_qty, - sum(ss_wholesale_cost) ss_wc, - sum(ss_sales_price) ss_sp - from store_sales - left join store_returns on sr_ticket_number=ss_ticket_number and ss_item_sk=sr_item_sk - join date_dim on ss_sold_date_sk = d_date_sk - where sr_ticket_number is null - group by d_year, ss_item_sk, ss_customer_sk - ) - select -ss_sold_year, ss_item_sk, ss_customer_sk, -round(ss_qty/(coalesce(ws_qty,0)+coalesce(cs_qty,0)),2) ratio, -ss_qty store_qty, ss_wc store_wholesale_cost, ss_sp store_sales_price, -coalesce(ws_qty,0)+coalesce(cs_qty,0) other_chan_qty, -coalesce(ws_wc,0)+coalesce(cs_wc,0) other_chan_wholesale_cost, -coalesce(ws_sp,0)+coalesce(cs_sp,0) other_chan_sales_price -from ss -left join ws on (ws_sold_year=ss_sold_year and ws_item_sk=ss_item_sk and ws_customer_sk=ss_customer_sk) -left join cs on (cs_sold_year=ss_sold_year and cs_item_sk=ss_item_sk and cs_customer_sk=ss_customer_sk) -where (coalesce(ws_qty,0)>0 or coalesce(cs_qty, 0)>0) and ss_sold_year=2002 -order by - ss_sold_year, ss_item_sk, ss_customer_sk, - ss_qty desc, ss_wc desc, ss_sp desc, - other_chan_qty, - other_chan_wholesale_cost, - other_chan_sales_price, - ratio -limit 100; - --- end template query78.tpl query 67 in stream 7 --- start template query18a.tpl query 68 in stream 7 -with /* TPC-DS query18a.tpl 0.90 */ results as - (select i_item_id, - ca_country, - ca_state, - ca_county, - cast(cs_quantity as decimal(12,2)) agg1, - cast(cs_list_price as decimal(12,2)) agg2, - cast(cs_coupon_amt as decimal(12,2)) agg3, - cast(cs_sales_price as decimal(12,2)) agg4, - cast(cs_net_profit as decimal(12,2)) agg5, - cast(c_birth_year as decimal(12,2)) agg6, - cast(cd1.cd_dep_count as decimal(12,2)) agg7 - from catalog_sales, customer_demographics cd1, customer_demographics cd2, customer, customer_address, date_dim, item - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd1.cd_demo_sk and - cs_bill_customer_sk = c_customer_sk and - cd1.cd_gender = 'M' and - cd1.cd_education_status = 'Primary' and - c_current_cdemo_sk = cd2.cd_demo_sk and - c_current_addr_sk = ca_address_sk and - c_birth_month in (9,6,11,1,7,4) and - d_year = 2002 and - ca_state in ('LA','IN','CO','NY','NC','KS','TX') - ) - select i_item_id, ca_country, ca_state, ca_county, agg1, agg2, agg3, agg4, agg5, agg6, agg7 - from ( - select i_item_id, ca_country, ca_state, ca_county, avg(agg1) agg1, - avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state, ca_county - union all - select i_item_id, ca_country, ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state - union all - select i_item_id, ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country - union all - select i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - ) foo - order by ca_country, ca_state, ca_county, i_item_id - limit 100; - --- end template query18a.tpl query 68 in stream 7 --- start template query36a.tpl query 69 in stream 7 -with /* TPC-DS query36a.tpl 0.21 */ results as - (select - sum(ss_net_profit) as ss_net_profit, sum(ss_ext_sales_price) as ss_ext_sales_price, - sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin - ,i_category - ,i_class - ,0 as g_category, 0 as g_class - from - store_sales - ,date_dim d1 - ,item - ,store - where - d1.d_year = 2002 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and s_state in ('NM','OK','GA','TX', - 'TN','MI','WA','NY') - group by i_category,i_class) - , - results_rollup as - (select gross_margin ,i_category ,i_class,0 as t_category, 0 as t_class, 0 as lochierarchy from results - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - i_category, NULL AS i_class, 0 as t_category, 1 as t_class, 1 as lochierarchy from results group by i_category - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - NULL AS i_category ,NULL AS i_class, 1 as t_category, 1 as t_class, 2 as lochierarchy from results) - select - gross_margin ,i_category ,i_class, lochierarchy,rank() over ( - partition by lochierarchy, case when t_class = 0 then i_category end - order by gross_margin asc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then i_category end - ,rank_within_parent - limit 100; - --- end template query36a.tpl query 69 in stream 7 --- start template query51.tpl query 70 in stream 7 -WITH /* TPC-DS query51.tpl 0.46 */ web_v1 as ( -select - ws_item_sk item_sk, d_date, - sum(sum(ws_sales_price)) - over (partition by ws_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from web_sales - ,date_dim -where ws_sold_date_sk=d_date_sk - and d_month_seq between 1191 and 1191+11 - and ws_item_sk is not NULL -group by ws_item_sk, d_date), -store_v1 as ( -select - ss_item_sk item_sk, d_date, - sum(sum(ss_sales_price)) - over (partition by ss_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from store_sales - ,date_dim -where ss_sold_date_sk=d_date_sk - and d_month_seq between 1191 and 1191+11 - and ss_item_sk is not NULL -group by ss_item_sk, d_date) - select * -from (select item_sk - ,d_date - ,web_sales - ,store_sales - ,max(web_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) web_cumulative - ,max(store_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) store_cumulative - from (select case when web.item_sk is not null then web.item_sk else store.item_sk end item_sk - ,case when web.d_date is not null then web.d_date else store.d_date end d_date - ,web.cume_sales web_sales - ,store.cume_sales store_sales - from web_v1 web full outer join store_v1 store on (web.item_sk = store.item_sk - and web.d_date = store.d_date) - )x )y -where web_cumulative > store_cumulative -order by item_sk - ,d_date -limit 100; - --- end template query51.tpl query 70 in stream 7 --- start template query56.tpl query 71 in stream 7 -with /* TPC-DS query56.tpl 0.83 */ ss as ( - select i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where i_item_id in (select - i_item_id -from item -where i_color in ('olive','sky','blue')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 4 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id), - cs as ( - select i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('olive','sky','blue')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 4 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id), - ws as ( - select i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('olive','sky','blue')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 4 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id) - select i_item_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by total_sales, - i_item_id - limit 100; - --- end template query56.tpl query 71 in stream 7 --- start template query83.tpl query 72 in stream 7 -with /* TPC-DS query83.tpl 0.96 */ sr_items as - (select i_item_id item_id, - sum(sr_return_quantity) sr_item_qty - from store_returns, - item, - date_dim - where sr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('1999-05-06','1999-10-10','1999-11-22'))) - and sr_returned_date_sk = d_date_sk - group by i_item_id), - cr_items as - (select i_item_id item_id, - sum(cr_return_quantity) cr_item_qty - from catalog_returns, - item, - date_dim - where cr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('1999-05-06','1999-10-10','1999-11-22'))) - and cr_returned_date_sk = d_date_sk - group by i_item_id), - wr_items as - (select i_item_id item_id, - sum(wr_return_quantity) wr_item_qty - from web_returns, - item, - date_dim - where wr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('1999-05-06','1999-10-10','1999-11-22'))) - and wr_returned_date_sk = d_date_sk - group by i_item_id) - select sr_items.item_id - ,sr_item_qty - ,sr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 sr_dev - ,cr_item_qty - ,cr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 cr_dev - ,wr_item_qty - ,wr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 wr_dev - ,(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 average - from sr_items - ,cr_items - ,wr_items - where sr_items.item_id=cr_items.item_id - and sr_items.item_id=wr_items.item_id - order by sr_items.item_id - ,sr_item_qty - limit 100; - --- end template query83.tpl query 72 in stream 7 --- start template query23.tpl query 73 in stream 7 -with /* TPC-DS query23.tpl 0.68 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (1998,1998+1,1998+2,1998+3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1998,1998+1,1998+2,1998+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * -from - max_store_sales)) - select sum(sales) - from (select cs_quantity*cs_list_price sales - from catalog_sales - ,date_dim - where d_year = 1998 - and d_moy = 4 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - union all - select ws_quantity*ws_list_price sales - from web_sales - ,date_dim - where d_year = 1998 - and d_moy = 4 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer)) - limit 100; -with /* TPC-DS query23.tpl 0.68 part2 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (1998,1998 + 1,1998 + 2,1998 + 3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1998,1998+1,1998+2,1998+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * - from max_store_sales)) - select c_last_name,c_first_name,sales - from (select c_last_name,c_first_name,sum(cs_quantity*cs_list_price) sales - from catalog_sales - ,customer - ,date_dim - where d_year = 1998 - and d_moy = 4 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and cs_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name - union all - select c_last_name,c_first_name,sum(ws_quantity*ws_list_price) sales - from web_sales - ,customer - ,date_dim - where d_year = 1998 - and d_moy = 4 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and ws_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name) - order by c_last_name,c_first_name,sales - limit 100; - --- end template query23.tpl query 73 in stream 7 --- start template query8.tpl query 74 in stream 7 -select /* TPC-DS query8.tpl 0.63 */ s_store_name - ,sum(ss_net_profit) - from store_sales - ,date_dim - ,store, - (select ca_zip - from ( - SELECT substring(ca_zip,1,5) ca_zip - FROM customer_address - WHERE substring(ca_zip,1,5) IN ( - '96588','98333','71257','31326','54347','60745', - '76653','31592','12038','51794','91968', - '53625','61785','70637','73080','82313', - '14488','23926','78042','19521','46514', - '56258','70050','50410','75304','22461', - '16657','92019','69084','52262','30415', - '40287','14960','70374','17169','78439', - '41029','42548','23310','44696','52998', - '30016','76105','61878','20548','88473', - '14900','52157','59950','93708','56672', - '24677','17270','78139','12205','77386', - '45536','76463','89505','22743','78872', - '58239','15571','54667','70231','29119', - '93994','14947','86284','44424','44141', - '75171','86029','93703','32527','91345', - '82363','69499','20239','39972','33977', - '11026','19150','36831','46984','65501', - '85240','81231','40111','21204','50009', - '16650','71697','97728','57108','16787', - '50893','26801','55226','11620','75664', - '60605','60389','34700','88233','29469', - '43006','68053','68453','89702','70185', - '84028','89659','37913','73777','15484', - '32194','46317','78268','38798','86263', - '91895','23420','86723','58011','70500', - '92453','41526','29160','50054','80621', - '52596','57462','24102','96485','37767', - '47465','29074','23919','50785','37541', - '77595','54708','33081','35513','28896', - '69543','15406','21826','98143','17451', - '80692','91280','15679','56049','48261', - '45600','48788','65389','92486','11549', - '78101','61238','47516','38699','81648', - '22428','36623','73280','51818','29800', - '58141','18332','17496','29834','57918', - '73560','12699','72436','55326','69456', - '74902','52241','65150','11402','38247', - '45472','78137','65490','80784','61677', - '36306','23983','75423','82875','57768', - '36442','16107','47087','35005','30958', - '16037','42897','72046','67345','75635', - '41281','85550','44640','69001','60070', - '99748','47469','78827','10609','45845', - '52299','92102','86827','23788','14557', - '40975','55862','21512','12855','28323', - '65975','78747','51486','66841','43688', - '67475','52229','46924','19352','33696', - '57190','63147','16701','27251','10244', - '77797','78312','79472','18791','75120', - '59992','37349','46602','28505','27890', - '58350','56827','22749','25080','25375', - '17918','96104','48249','35937','19368', - '13729','79077','64869','14066','16289', - '17494','26815','87839','49365','31110', - '61373','55948','91302','87694','82964', - '27128','97308','17436','43741','96751', - '20925','19915','66746','68310','53848', - '12715','57127','19965','88718','24754', - '91235','11223','21057','45018','62651', - '40205','36559','59980','80182','26277', - '84462','68496','49073','74684','69736', - '82850','56416','45964','73609','40674', - '12459','17926','65070','10688','56849', - '68982','25392','16507','86070','91628', - '55108','39040','66183','81571','82527', - '53024','59663','75795','57009','84849', - '43619','90720','63949','48189','61828', - '51994','58004','97734','90040','23136', - '94891','19397','91784','79020','75107', - '61022','56609','99295','90363','37390', - '69300','16492','93182','83244','30023', - '75514','44474','64537','96668','38684', - '87051','32646','22602','71629','87953', - '26391','74931','11847','98425','31552', - '38975','75683','27376','68354','25734', - '86404','42849','43822','44959','50778', - '52277','65783','73544','83080','79617', - '74782','58339','93690','30210','33553', - '26652','68695','88198','62800','45100', - '20681','72446','38865','17884') - intersect - select ca_zip - from (SELECT substring(ca_zip,1,5) ca_zip,count(*) cnt - FROM customer_address, customer - WHERE ca_address_sk = c_current_addr_sk and - c_preferred_cust_flag='Y' - group by ca_zip - having count(*) > 10)A1)A2) V1 - where ss_store_sk = s_store_sk - and ss_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 2000 - and (substring(s_zip,1,2) = substring(V1.ca_zip,1,2)) - group by s_store_name - order by s_store_name - limit 100; - --- end template query8.tpl query 74 in stream 7 --- start template query24.tpl query 75 in stream 7 -with /* TPC-DS query24.tpl 0.92 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_net_profit) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip -and s_market_id=8 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'khaki' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; -with /* TPC-DS query24.tpl 0.92 part2 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_net_profit) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip - and s_market_id = 8 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'firebrick' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; - --- end template query24.tpl query 75 in stream 7 --- start template query63.tpl query 76 in stream 7 -select /* TPC-DS query63.tpl 0.27 */ * -from (select i_manager_id - ,sum(ss_sales_price) sum_sales - ,avg(sum(ss_sales_price)) over (partition by i_manager_id) avg_monthly_sales - from item - ,store_sales - ,date_dim - ,store - where ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and d_month_seq in (1202,1202+1,1202+2,1202+3,1202+4,1202+5,1202+6,1202+7,1202+8,1202+9,1202+10,1202+11) - and (( i_category in ('Books','Children','Electronics') - and i_class in ('personal','portable','reference','self-help') - and i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) - or( i_category in ('Women','Music','Men') - and i_class in ('accessories','classical','fragrances','pants') - and i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manager_id, d_moy) tmp1 -where case when avg_monthly_sales > 0 then abs (sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 -order by i_manager_id - ,avg_monthly_sales - ,sum_sales -limit 100; - --- end template query63.tpl query 76 in stream 7 --- start template query1.tpl query 77 in stream 7 -with /* TPC-DS query1.tpl 0.12 */ customer_total_return as -(select sr_customer_sk as ctr_customer_sk -,sr_store_sk as ctr_store_sk -,sum(SR_STORE_CREDIT) as ctr_total_return -from store_returns -,date_dim -where sr_returned_date_sk = d_date_sk -and d_year =1998 -group by sr_customer_sk -,sr_store_sk) - select c_customer_id -from customer_total_return ctr1 -,store -,customer -where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 -from customer_total_return ctr2 -where ctr1.ctr_store_sk = ctr2.ctr_store_sk) -and s_store_sk = ctr1.ctr_store_sk -and s_state = 'IL' -and ctr1.ctr_customer_sk = c_customer_sk -order by c_customer_id -limit 100; - --- end template query1.tpl query 77 in stream 7 --- start template query12.tpl query 78 in stream 7 -select /* TPC-DS query12.tpl 0.64 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ws_ext_sales_price) as itemrevenue - ,sum(ws_ext_sales_price)*100/sum(sum(ws_ext_sales_price)) over - (partition by i_class) as revenueratio -from - web_sales - ,item - ,date_dim -where - ws_item_sk = i_item_sk - and i_category in ('Sports', 'Home', 'Books') - and ws_sold_date_sk = d_date_sk - and d_date between cast('1998-03-23' as date) - and dateadd(day,30,cast('1998-03-23' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query12.tpl query 78 in stream 7 --- start template query68.tpl query 79 in stream 7 -select /* TPC-DS query68.tpl 0.95 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,extended_price - ,extended_tax - ,list_price - from (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_ext_sales_price) extended_price - ,sum(ss_ext_list_price) list_price - ,sum(ss_ext_tax) extended_tax - from store_sales - ,date_dim - ,store - ,household_demographics - ,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_dep_count = 1 or - household_demographics.hd_vehicle_count= -1) - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_city in ('McDonald','Sunnyside') - group by ss_ticket_number - ,ss_customer_sk - ,ss_addr_sk,ca_city) dn - ,customer - ,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,ss_ticket_number - limit 100; - --- end template query68.tpl query 79 in stream 7 --- start template query66.tpl query 80 in stream 7 -select /* TPC-DS query66.tpl 0.39 */ - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - ,sum(jan_sales) as jan_sales - ,sum(feb_sales) as feb_sales - ,sum(mar_sales) as mar_sales - ,sum(apr_sales) as apr_sales - ,sum(may_sales) as may_sales - ,sum(jun_sales) as jun_sales - ,sum(jul_sales) as jul_sales - ,sum(aug_sales) as aug_sales - ,sum(sep_sales) as sep_sales - ,sum(oct_sales) as oct_sales - ,sum(nov_sales) as nov_sales - ,sum(dec_sales) as dec_sales - ,sum(jan_sales/w_warehouse_sq_ft) as jan_sales_per_sq_foot - ,sum(feb_sales/w_warehouse_sq_ft) as feb_sales_per_sq_foot - ,sum(mar_sales/w_warehouse_sq_ft) as mar_sales_per_sq_foot - ,sum(apr_sales/w_warehouse_sq_ft) as apr_sales_per_sq_foot - ,sum(may_sales/w_warehouse_sq_ft) as may_sales_per_sq_foot - ,sum(jun_sales/w_warehouse_sq_ft) as jun_sales_per_sq_foot - ,sum(jul_sales/w_warehouse_sq_ft) as jul_sales_per_sq_foot - ,sum(aug_sales/w_warehouse_sq_ft) as aug_sales_per_sq_foot - ,sum(sep_sales/w_warehouse_sq_ft) as sep_sales_per_sq_foot - ,sum(oct_sales/w_warehouse_sq_ft) as oct_sales_per_sq_foot - ,sum(nov_sales/w_warehouse_sq_ft) as nov_sales_per_sq_foot - ,sum(dec_sales/w_warehouse_sq_ft) as dec_sales_per_sq_foot - ,sum(jan_net) as jan_net - ,sum(feb_net) as feb_net - ,sum(mar_net) as mar_net - ,sum(apr_net) as apr_net - ,sum(may_net) as may_net - ,sum(jun_net) as jun_net - ,sum(jul_net) as jul_net - ,sum(aug_net) as aug_net - ,sum(sep_net) as sep_net - ,sum(oct_net) as oct_net - ,sum(nov_net) as nov_net - ,sum(dec_net) as dec_net - from ( - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'RUPEKSA' || ',' || 'ZOUROS' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then ws_ext_sales_price* ws_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then ws_ext_sales_price* ws_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then ws_ext_sales_price* ws_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then ws_ext_sales_price* ws_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then ws_ext_sales_price* ws_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then ws_ext_sales_price* ws_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then ws_ext_sales_price* ws_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then ws_ext_sales_price* ws_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then ws_ext_sales_price* ws_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then ws_ext_sales_price* ws_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then ws_ext_sales_price* ws_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then ws_ext_sales_price* ws_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as dec_net - from - web_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - ws_warehouse_sk = w_warehouse_sk - and ws_sold_date_sk = d_date_sk - and ws_sold_time_sk = t_time_sk - and ws_ship_mode_sk = sm_ship_mode_sk - and d_year = 2002 - and t_time between 48586 and 48586+28800 - and sm_carrier in ('RUPEKSA','ZOUROS') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - union all - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'RUPEKSA' || ',' || 'ZOUROS' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then cs_ext_list_price* cs_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then cs_ext_list_price* cs_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then cs_ext_list_price* cs_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then cs_ext_list_price* cs_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then cs_ext_list_price* cs_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then cs_ext_list_price* cs_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then cs_ext_list_price* cs_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then cs_ext_list_price* cs_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then cs_ext_list_price* cs_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then cs_ext_list_price* cs_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then cs_ext_list_price* cs_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then cs_ext_list_price* cs_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as dec_net - from - catalog_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and cs_sold_time_sk = t_time_sk - and cs_ship_mode_sk = sm_ship_mode_sk - and d_year = 2002 - and t_time between 48586 AND 48586+28800 - and sm_carrier in ('RUPEKSA','ZOUROS') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - ) x - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - order by w_warehouse_name - limit 100; - --- end template query66.tpl query 80 in stream 7 --- start template query67a.tpl query 81 in stream 7 -with /* TPC-DS query67a.tpl 0.35 */ results as -( select i_category ,i_class ,i_brand ,i_product_name ,d_year ,d_qoy ,d_moy ,s_store_id - ,sum(coalesce(ss_sales_price*ss_quantity,0)) sumsales - from store_sales ,date_dim ,store ,item - where ss_sold_date_sk=d_date_sk - and ss_item_sk=i_item_sk - and ss_store_sk = s_store_sk - and d_month_seq between 1192 and 1192 + 11 - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy,s_store_id) - , - results_rollup as - (select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, s_store_id, sumsales - from results - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy - union all - select i_category, i_class, i_brand, i_product_name, d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year - union all - select i_category, i_class, i_brand, i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name - union all - select i_category, i_class, i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand - union all - select i_category, i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class - union all - select i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category - union all - select null i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results) - - select * -from (select i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rank() over (partition by i_category order by sumsales desc) rk - from results_rollup) dw2 -where rk <= 100 -order by i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rk -limit 100; - --- end template query67a.tpl query 81 in stream 7 --- start template query77a.tpl query 82 in stream 7 -with /* TPC-DS query77a.tpl 0.78 */ ss as - (select s_store_sk, - sum(ss_ext_sales_price) as sales, - sum(ss_net_profit) as profit - from store_sales, - date_dim, - store - where ss_sold_date_sk = d_date_sk - and d_date between cast('1999-08-13' as date) - and dateadd(day,30,cast('1999-08-13' as date)) - and ss_store_sk = s_store_sk - group by s_store_sk) - , - sr as - (select s_store_sk, - sum(sr_return_amt) as returns, - sum(sr_net_loss) as profit_loss - from store_returns, - date_dim, - store - where sr_returned_date_sk = d_date_sk - and d_date between cast('1999-08-13' as date) - and dateadd(day,30,cast('1999-08-13' as date)) - and sr_store_sk = s_store_sk - group by s_store_sk), - cs as - (select cs_call_center_sk, - sum(cs_ext_sales_price) as sales, - sum(cs_net_profit) as profit - from catalog_sales, - date_dim - where cs_sold_date_sk = d_date_sk - and d_date between cast('1999-08-13' as date) - and dateadd(day,30,cast('1999-08-13' as date)) - group by cs_call_center_sk - ), - cr as - (select cr_call_center_sk, - sum(cr_return_amount) as returns, - sum(cr_net_loss) as profit_loss - from catalog_returns, - date_dim - where cr_returned_date_sk = d_date_sk - and d_date between cast('1999-08-13' as date) - and dateadd(day,30,cast('1999-08-13' as date)) - group by cr_call_center_sk), - ws as - ( select wp_web_page_sk, - sum(ws_ext_sales_price) as sales, - sum(ws_net_profit) as profit - from web_sales, - date_dim, - web_page - where ws_sold_date_sk = d_date_sk - and d_date between cast('1999-08-13' as date) - and dateadd(day,30,cast('1999-08-13' as date)) - and ws_web_page_sk = wp_web_page_sk - group by wp_web_page_sk), - wr as - (select wp_web_page_sk, - sum(wr_return_amt) as returns, - sum(wr_net_loss) as profit_loss - from web_returns, - date_dim, - web_page - where wr_returned_date_sk = d_date_sk - and d_date between cast('1999-08-13' as date) - and dateadd(day,30,cast('1999-08-13' as date)) - and wr_web_page_sk = wp_web_page_sk - group by wp_web_page_sk) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , ss.s_store_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ss left join sr - on ss.s_store_sk = sr.s_store_sk - union all - select 'catalog channel' as channel - , cs_call_center_sk as id - , sales - , returns - , (profit - profit_loss) as profit - from cs - , cr - union all - select 'web channel' as channel - , ws.wp_web_page_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ws left join wr - on ws.wp_web_page_sk = wr.wp_web_page_sk - ) x - group by channel, id ) - - select * - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results -) foo -order by channel, id - limit 100; - --- end template query77a.tpl query 82 in stream 7 --- start template query15.tpl query 83 in stream 7 -select /* TPC-DS query15.tpl 0.57 */ ca_zip - ,sum(cs_sales_price) - from catalog_sales - ,customer - ,customer_address - ,date_dim - where cs_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', - '85392', '85460', '80348', '81792') - or ca_state in ('CA','WA','GA') - or cs_sales_price > 500) - and cs_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 1998 - group by ca_zip - order by ca_zip - limit 100; - --- end template query15.tpl query 83 in stream 7 --- start template query88.tpl query 84 in stream 7 -select /* TPC-DS query88.tpl 0.66 */ * -from - (select count(*) h8_30_to_9 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s1, - (select count(*) h9_to_9_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s2, - (select count(*) h9_30_to_10 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s3, - (select count(*) h10_to_10_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s4, - (select count(*) h10_30_to_11 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s5, - (select count(*) h11_to_11_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s6, - (select count(*) h11_30_to_12 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s7, - (select count(*) h12_to_12_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 12 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s8 -; - --- end template query88.tpl query 84 in stream 7 --- start template query65.tpl query 85 in stream 7 -select /* TPC-DS query65.tpl 0.71 */ - s_store_name, - i_item_desc, - sc.revenue, - i_current_price, - i_wholesale_cost, - i_brand - from store, item, - (select ss_store_sk, avg(revenue) as ave - from - (select ss_store_sk, ss_item_sk, - sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1194 and 1194+11 - group by ss_store_sk, ss_item_sk) sa - group by ss_store_sk) sb, - (select ss_store_sk, ss_item_sk, sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1194 and 1194+11 - group by ss_store_sk, ss_item_sk) sc - where sb.ss_store_sk = sc.ss_store_sk and - sc.revenue <= 0.1 * sb.ave and - s_store_sk = sc.ss_store_sk and - i_item_sk = sc.ss_item_sk - order by s_store_name, i_item_desc -limit 100; - --- end template query65.tpl query 85 in stream 7 --- start template query59.tpl query 86 in stream 7 -with /* TPC-DS query59.tpl 0.30 */ wss as - (select d_week_seq, - ss_store_sk, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - group by d_week_seq,ss_store_sk - ) - select s_store_name1,s_store_id1,d_week_seq1 - ,sun_sales1/sun_sales2,mon_sales1/mon_sales2 - ,tue_sales1/tue_sales2,wed_sales1/wed_sales2,thu_sales1/thu_sales2 - ,fri_sales1/fri_sales2,sat_sales1/sat_sales2 - from - (select s_store_name s_store_name1,wss.d_week_seq d_week_seq1 - ,s_store_id s_store_id1,sun_sales sun_sales1 - ,mon_sales mon_sales1,tue_sales tue_sales1 - ,wed_sales wed_sales1,thu_sales thu_sales1 - ,fri_sales fri_sales1,sat_sales sat_sales1 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1195 and 1195 + 11) y, - (select s_store_name s_store_name2,wss.d_week_seq d_week_seq2 - ,s_store_id s_store_id2,sun_sales sun_sales2 - ,mon_sales mon_sales2,tue_sales tue_sales2 - ,wed_sales wed_sales2,thu_sales thu_sales2 - ,fri_sales fri_sales2,sat_sales sat_sales2 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1195+ 12 and 1195 + 23) x - where s_store_id1=s_store_id2 - and d_week_seq1=d_week_seq2-52 - order by s_store_name1,s_store_id1,d_week_seq1 -limit 100; - --- end template query59.tpl query 86 in stream 7 --- start template query96.tpl query 87 in stream 7 -select /* TPC-DS query96.tpl 0.1 */ count(*) -from store_sales - ,household_demographics - ,time_dim, store -where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 15 - and time_dim.t_minute >= 30 - and household_demographics.hd_dep_count = 1 - and store.s_store_name = 'ese' -order by count(*) -limit 100; - --- end template query96.tpl query 87 in stream 7 --- start template query54.tpl query 88 in stream 7 -with /* TPC-DS query54.tpl 0.81 */ my_customers as ( - select distinct c_customer_sk - , c_current_addr_sk - from - ( select cs_sold_date_sk sold_date_sk, - cs_bill_customer_sk customer_sk, - cs_item_sk item_sk - from catalog_sales - union all - select ws_sold_date_sk sold_date_sk, - ws_bill_customer_sk customer_sk, - ws_item_sk item_sk - from web_sales - ) cs_or_ws_sales, - item, - date_dim, - customer - where sold_date_sk = d_date_sk - and item_sk = i_item_sk - and i_category = 'Home' - and i_class = 'flatware' - and c_customer_sk = cs_or_ws_sales.customer_sk - and d_moy = 7 - and d_year = 2001 - ) - , my_revenue as ( - select c_customer_sk, - sum(ss_ext_sales_price) as revenue - from my_customers, - store_sales, - customer_address, - store, - date_dim - where c_current_addr_sk = ca_address_sk - and ca_county = s_county - and ca_state = s_state - and ss_sold_date_sk = d_date_sk - and c_customer_sk = ss_customer_sk - and d_month_seq between (select distinct d_month_seq+1 - from date_dim where d_year = 2001 and d_moy = 7) - and (select distinct d_month_seq+3 - from date_dim where d_year = 2001 and d_moy = 7) - group by c_customer_sk - ) - , segments as - (select cast((revenue/50) as bigint) as segment - from my_revenue - ) - select segment, count(*) as num_customers, segment*50 as segment_base - from segments - group by segment - order by segment, num_customers - limit 100; - --- end template query54.tpl query 88 in stream 7 --- start template query95.tpl query 89 in stream 7 -with /* TPC-DS query95.tpl 0.43 */ ws_wh as -(select ws1.ws_order_number,ws1.ws_warehouse_sk wh1,ws2.ws_warehouse_sk wh2 - from web_sales ws1,web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) - select - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '1999-3-01' and - dateadd(day,60,cast('1999-3-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'MD' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and ws1.ws_order_number in (select ws_order_number - from ws_wh) -and ws1.ws_order_number in (select wr_order_number - from web_returns,ws_wh - where wr_order_number = ws_wh.ws_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query95.tpl query 89 in stream 7 --- start template query93.tpl query 90 in stream 7 -select /* TPC-DS query93.tpl 0.52 */ ss_customer_sk - ,sum(act_sales) sumsales - from (select ss_item_sk - ,ss_ticket_number - ,ss_customer_sk - ,case when sr_return_quantity is not null then (ss_quantity-sr_return_quantity)*ss_sales_price - else (ss_quantity*ss_sales_price) end act_sales - from store_sales left outer join store_returns on (sr_item_sk = ss_item_sk - and sr_ticket_number = ss_ticket_number) - ,reason - where sr_reason_sk = r_reason_sk - and r_reason_desc = 'reason 42') t - group by ss_customer_sk - order by sumsales, ss_customer_sk -limit 100; - --- end template query93.tpl query 90 in stream 7 --- start template query91.tpl query 91 in stream 7 -select /* TPC-DS query91.tpl 0.13 */ - cc_call_center_id Call_Center, - cc_name Call_Center_Name, - cc_manager Manager, - sum(cr_net_loss) Returns_Loss -from - call_center, - catalog_returns, - date_dim, - customer, - customer_address, - customer_demographics, - household_demographics -where - cr_call_center_sk = cc_call_center_sk -and cr_returned_date_sk = d_date_sk -and cr_returning_customer_sk= c_customer_sk -and cd_demo_sk = c_current_cdemo_sk -and hd_demo_sk = c_current_hdemo_sk -and ca_address_sk = c_current_addr_sk -and d_year = 2001 -and d_moy = 12 -and ( (cd_marital_status = 'M' and cd_education_status = 'Unknown') - or(cd_marital_status = 'W' and cd_education_status = 'Advanced Degree')) -and hd_buy_potential like '501-1000%' -and ca_gmt_offset = -6 -group by cc_call_center_id,cc_name,cc_manager,cd_marital_status,cd_education_status -order by sum(cr_net_loss) desc; - --- end template query91.tpl query 91 in stream 7 --- start template query74.tpl query 92 in stream 7 -with /* TPC-DS query74.tpl 0.76 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,stddev_samp(ss_net_paid) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (2001,2001+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,stddev_samp(ws_net_paid) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - and d_year in (2001,2001+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - ) - select - t_s_secyear.customer_id, t_s_secyear.customer_first_name, t_s_secyear.customer_last_name - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.year = 2001 - and t_s_secyear.year = 2001+1 - and t_w_firstyear.year = 2001 - and t_w_secyear.year = 2001+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - order by 2,1,3 -limit 100; - --- end template query74.tpl query 92 in stream 7 --- start template query94.tpl query 93 in stream 7 -select /* TPC-DS query94.tpl 0.17 */ - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2000-4-01' and - dateadd(day,60,cast('2000-4-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'TN' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and exists (select * - from web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) -and not exists(select * - from web_returns wr1 - where ws1.ws_order_number = wr1.wr_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query94.tpl query 93 in stream 7 --- start template query16.tpl query 94 in stream 7 -select /* TPC-DS query16.tpl 0.25 */ - count(distinct cs_order_number) as "order count" - ,sum(cs_ext_ship_cost) as "total shipping cost" - ,sum(cs_net_profit) as "total net profit" -from - catalog_sales cs1 - ,date_dim - ,customer_address - ,call_center -where - d_date between '2001-3-01' and - dateadd(day, 60, cast('2001-3-01' as date)) -and cs1.cs_ship_date_sk = d_date_sk -and cs1.cs_ship_addr_sk = ca_address_sk -and ca_state = 'SC' -and cs1.cs_call_center_sk = cc_call_center_sk -and cc_county in ('Walker County','Bronx County','Jackson County','Mesa County', - 'Daviess County' -) -and exists (select * - from catalog_sales cs2 - where cs1.cs_order_number = cs2.cs_order_number - and cs1.cs_warehouse_sk <> cs2.cs_warehouse_sk) -and not exists(select * - from catalog_returns cr1 - where cs1.cs_order_number = cr1.cr_order_number) -order by count(distinct cs_order_number) -limit 100; - --- end template query16.tpl query 94 in stream 7 --- start template query90.tpl query 95 in stream 7 -select /* TPC-DS query90.tpl 0.40 */ cast(amc as decimal(15,4))/cast(pmc as decimal(15,4)) am_pm_ratio - from ( select count(*) amc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 10 and 10+1 - and household_demographics.hd_dep_count = 2 - and web_page.wp_char_count between 5000 and 5200) at, - ( select count(*) pmc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 15 and 15+1 - and household_demographics.hd_dep_count = 2 - and web_page.wp_char_count between 5000 and 5200) pt - order by am_pm_ratio - limit 100; - --- end template query90.tpl query 95 in stream 7 --- start template query57.tpl query 96 in stream 7 -with /* TPC-DS query57.tpl 0.70 */ v1 as( - select i_category, i_brand, - cc_name, - d_year, d_moy, - sum(cs_sales_price) sum_sales, - avg(sum(cs_sales_price)) over - (partition by i_category, i_brand, - cc_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - cc_name - order by d_year, d_moy) rn - from item, catalog_sales, date_dim, call_center - where cs_item_sk = i_item_sk and - cs_sold_date_sk = d_date_sk and - cc_call_center_sk= cs_call_center_sk and - ( - d_year = 1999 or - ( d_year = 1999-1 and d_moy =12) or - ( d_year = 1999+1 and d_moy =1) - ) - group by i_category, i_brand, - cc_name , d_year, d_moy), - v2 as( - select v1.i_brand - ,v1.d_year, v1.d_moy - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1. cc_name = v1_lag. cc_name and - v1. cc_name = v1_lead. cc_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 1999 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, avg_monthly_sales - limit 100; - --- end template query57.tpl query 96 in stream 7 --- start template query22a.tpl query 97 in stream 7 -with /* TPC-DS query22a.tpl 0.55 */ results as -(select i_product_name - ,i_brand - ,i_class - ,i_category - ,avg(inv_quantity_on_hand) qoh - from inventory - ,date_dim - ,item --- ,warehouse - where inv_date_sk=d_date_sk - and inv_item_sk=i_item_sk --- and inv_warehouse_sk = w_warehouse_sk - and d_month_seq between 1187 and 1187 + 11 - group by i_product_name,i_brand,i_class,i_category), -results_rollup as -(select i_product_name, i_brand, i_class, i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class,i_category -union all -select i_product_name, i_brand, i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class -union all -select i_product_name, i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand -union all -select i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name -union all -select null i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results) - select i_product_name, i_brand, i_class, i_category,qoh - from results_rollup - order by qoh, i_product_name, i_brand, i_class, i_category -limit 100; - --- end template query22a.tpl query 97 in stream 7 --- start template query50.tpl query 98 in stream 7 -select /* TPC-DS query50.tpl 0.60 */ - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 30) and - (sr_returned_date_sk - ss_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 60) and - (sr_returned_date_sk - ss_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 90) and - (sr_returned_date_sk - ss_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - store_sales - ,store_returns - ,store - ,date_dim d1 - ,date_dim d2 -where - d2.d_year = 2000 -and d2.d_moy = 10 -and ss_ticket_number = sr_ticket_number -and ss_item_sk = sr_item_sk -and ss_sold_date_sk = d1.d_date_sk -and sr_returned_date_sk = d2.d_date_sk -and ss_customer_sk = sr_customer_sk -and ss_store_sk = s_store_sk -group by - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -order by s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -limit 100; - --- end template query50.tpl query 98 in stream 7 --- start template query27a.tpl query 99 in stream 7 -with /* TPC-DS query27a.tpl 0.16 */ results as - (select i_item_id, - s_state, 0 as g_state, - ss_quantity agg1, - ss_list_price agg2, - ss_coupon_amt agg3, - ss_sales_price agg4 - from store_sales, customer_demographics, date_dim, store, item - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_store_sk = s_store_sk and - ss_cdemo_sk = cd_demo_sk and - cd_gender = 'F' and - cd_marital_status = 'D' and - cd_education_status = '2 yr Degree' and - d_year = 2001 and - s_state in ('NC','GA', 'LA', 'CO', 'GA', 'MO') - ) - - select i_item_id, - s_state, g_state, agg1, agg2, agg3, agg4 - from ( - select i_item_id, s_state, 0 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4 from results - group by i_item_id, s_state - union all - select i_item_id, NULL AS s_state, 1 AS g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as s_state, 1 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - ) foo - order by i_item_id, s_state - limit 100; - --- end template query27a.tpl query 99 in stream 7 diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/100TB/queries/query_8.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/100TB/queries/query_8.sql deleted file mode 100644 index 0568b219..00000000 --- a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/100TB/queries/query_8.sql +++ /dev/null @@ -1,5027 +0,0 @@ --- start template query57.tpl query 1 in stream 8 -with /* TPC-DS query57.tpl 0.70 */ v1 as( - select i_category, i_brand, - cc_name, - d_year, d_moy, - sum(cs_sales_price) sum_sales, - avg(sum(cs_sales_price)) over - (partition by i_category, i_brand, - cc_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - cc_name - order by d_year, d_moy) rn - from item, catalog_sales, date_dim, call_center - where cs_item_sk = i_item_sk and - cs_sold_date_sk = d_date_sk and - cc_call_center_sk= cs_call_center_sk and - ( - d_year = 2001 or - ( d_year = 2001-1 and d_moy =12) or - ( d_year = 2001+1 and d_moy =1) - ) - group by i_category, i_brand, - cc_name , d_year, d_moy), - v2 as( - select v1.i_category, v1.i_brand, v1.cc_name - ,v1.d_year - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1. cc_name = v1_lag. cc_name and - v1. cc_name = v1_lead. cc_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 2001 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, avg_monthly_sales - limit 100; - --- end template query57.tpl query 1 in stream 8 --- start template query29.tpl query 2 in stream 8 -select /* TPC-DS query29.tpl 0.53 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,avg(ss_quantity) as store_sales_quantity - ,avg(sr_return_quantity) as store_returns_quantity - ,avg(cs_quantity) as catalog_sales_quantity - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 1998 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 4 + 3 - and d2.d_year = 1998 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_year in (1998,1998+1,1998+2) - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query29.tpl query 2 in stream 8 --- start template query24.tpl query 3 in stream 8 -with /* TPC-DS query24.tpl 0.92 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_net_paid) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip -and s_market_id=5 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'green' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; -with /* TPC-DS query24.tpl 0.92 part2 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_net_paid) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip - and s_market_id = 5 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'lace' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; - --- end template query24.tpl query 3 in stream 8 --- start template query76.tpl query 4 in stream 8 -select /* TPC-DS query76.tpl 0.99 */ channel, col_name, d_year, d_qoy, i_category, COUNT(*) sales_cnt, SUM(ext_sales_price) sales_amt FROM ( - SELECT 'store' as channel, 'ss_cdemo_sk' col_name, d_year, d_qoy, i_category, ss_ext_sales_price ext_sales_price - FROM store_sales, item, date_dim - WHERE ss_cdemo_sk IS NULL - AND ss_sold_date_sk=d_date_sk - AND ss_item_sk=i_item_sk - UNION ALL - SELECT 'web' as channel, 'ws_ship_mode_sk' col_name, d_year, d_qoy, i_category, ws_ext_sales_price ext_sales_price - FROM web_sales, item, date_dim - WHERE ws_ship_mode_sk IS NULL - AND ws_sold_date_sk=d_date_sk - AND ws_item_sk=i_item_sk - UNION ALL - SELECT 'catalog' as channel, 'cs_ship_mode_sk' col_name, d_year, d_qoy, i_category, cs_ext_sales_price ext_sales_price - FROM catalog_sales, item, date_dim - WHERE cs_ship_mode_sk IS NULL - AND cs_sold_date_sk=d_date_sk - AND cs_item_sk=i_item_sk) foo -GROUP BY channel, col_name, d_year, d_qoy, i_category -ORDER BY channel, col_name, d_year, d_qoy, i_category -limit 100; - --- end template query76.tpl query 4 in stream 8 --- start template query37.tpl query 5 in stream 8 -select /* TPC-DS query37.tpl 0.31 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, catalog_sales - where i_current_price between 65 and 65 + 30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('2002-04-30' as date) and dateadd(day,60,cast('2002-04-30' as date)) - and i_manufact_id in (780,702,758,827) - and inv_quantity_on_hand between 100 and 500 - and cs_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query37.tpl query 5 in stream 8 --- start template query66.tpl query 6 in stream 8 -select /* TPC-DS query66.tpl 0.39 */ - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - ,sum(jan_sales) as jan_sales - ,sum(feb_sales) as feb_sales - ,sum(mar_sales) as mar_sales - ,sum(apr_sales) as apr_sales - ,sum(may_sales) as may_sales - ,sum(jun_sales) as jun_sales - ,sum(jul_sales) as jul_sales - ,sum(aug_sales) as aug_sales - ,sum(sep_sales) as sep_sales - ,sum(oct_sales) as oct_sales - ,sum(nov_sales) as nov_sales - ,sum(dec_sales) as dec_sales - ,sum(jan_sales/w_warehouse_sq_ft) as jan_sales_per_sq_foot - ,sum(feb_sales/w_warehouse_sq_ft) as feb_sales_per_sq_foot - ,sum(mar_sales/w_warehouse_sq_ft) as mar_sales_per_sq_foot - ,sum(apr_sales/w_warehouse_sq_ft) as apr_sales_per_sq_foot - ,sum(may_sales/w_warehouse_sq_ft) as may_sales_per_sq_foot - ,sum(jun_sales/w_warehouse_sq_ft) as jun_sales_per_sq_foot - ,sum(jul_sales/w_warehouse_sq_ft) as jul_sales_per_sq_foot - ,sum(aug_sales/w_warehouse_sq_ft) as aug_sales_per_sq_foot - ,sum(sep_sales/w_warehouse_sq_ft) as sep_sales_per_sq_foot - ,sum(oct_sales/w_warehouse_sq_ft) as oct_sales_per_sq_foot - ,sum(nov_sales/w_warehouse_sq_ft) as nov_sales_per_sq_foot - ,sum(dec_sales/w_warehouse_sq_ft) as dec_sales_per_sq_foot - ,sum(jan_net) as jan_net - ,sum(feb_net) as feb_net - ,sum(mar_net) as mar_net - ,sum(apr_net) as apr_net - ,sum(may_net) as may_net - ,sum(jun_net) as jun_net - ,sum(jul_net) as jul_net - ,sum(aug_net) as aug_net - ,sum(sep_net) as sep_net - ,sum(oct_net) as oct_net - ,sum(nov_net) as nov_net - ,sum(dec_net) as dec_net - from ( - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'AIRBORNE' || ',' || 'DHL' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then ws_ext_list_price* ws_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then ws_ext_list_price* ws_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then ws_ext_list_price* ws_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then ws_ext_list_price* ws_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then ws_ext_list_price* ws_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then ws_ext_list_price* ws_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then ws_ext_list_price* ws_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then ws_ext_list_price* ws_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then ws_ext_list_price* ws_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then ws_ext_list_price* ws_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then ws_ext_list_price* ws_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then ws_ext_list_price* ws_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then ws_net_profit * ws_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then ws_net_profit * ws_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then ws_net_profit * ws_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then ws_net_profit * ws_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then ws_net_profit * ws_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then ws_net_profit * ws_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then ws_net_profit * ws_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then ws_net_profit * ws_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then ws_net_profit * ws_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then ws_net_profit * ws_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then ws_net_profit * ws_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then ws_net_profit * ws_quantity else 0 end) as dec_net - from - web_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - ws_warehouse_sk = w_warehouse_sk - and ws_sold_date_sk = d_date_sk - and ws_sold_time_sk = t_time_sk - and ws_ship_mode_sk = sm_ship_mode_sk - and d_year = 1998 - and t_time between 12974 and 12974+28800 - and sm_carrier in ('AIRBORNE','DHL') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - union all - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'AIRBORNE' || ',' || 'DHL' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then cs_ext_list_price* cs_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then cs_ext_list_price* cs_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then cs_ext_list_price* cs_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then cs_ext_list_price* cs_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then cs_ext_list_price* cs_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then cs_ext_list_price* cs_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then cs_ext_list_price* cs_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then cs_ext_list_price* cs_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then cs_ext_list_price* cs_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then cs_ext_list_price* cs_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then cs_ext_list_price* cs_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then cs_ext_list_price* cs_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as dec_net - from - catalog_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and cs_sold_time_sk = t_time_sk - and cs_ship_mode_sk = sm_ship_mode_sk - and d_year = 1998 - and t_time between 12974 AND 12974+28800 - and sm_carrier in ('AIRBORNE','DHL') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - ) x - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - order by w_warehouse_name - limit 100; - --- end template query66.tpl query 6 in stream 8 --- start template query60.tpl query 7 in stream 8 -with /* TPC-DS query60.tpl 0.29 */ ss as ( - select - i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Music')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 10 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id), - cs as ( - select - i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Music')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 10 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id), - ws as ( - select - i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Music')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 10 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id) - select - i_item_id -,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by i_item_id - ,total_sales - limit 100; - --- end template query60.tpl query 7 in stream 8 --- start template query98.tpl query 8 in stream 8 -select /* TPC-DS query98.tpl 0.32 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ss_ext_sales_price) as itemrevenue - ,sum(ss_ext_sales_price)*100/sum(sum(ss_ext_sales_price)) over - (partition by i_class) as revenueratio -from - store_sales - ,item - ,date_dim -where - ss_item_sk = i_item_sk - and i_category in ('Jewelry', 'Books', 'Home') - and ss_sold_date_sk = d_date_sk - and d_date between cast('1999-03-22' as date) - and dateadd(day,30,cast('1999-03-22' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio; - --- end template query98.tpl query 8 in stream 8 --- start template query80a.tpl query 9 in stream 8 -with /* TPC-DS query80a.tpl 0.6 */ ssr as - (select s_store_id as store_id, - sum(ss_ext_sales_price) as sales, - sum(coalesce(sr_return_amt, 0)) as returns, - sum(ss_net_profit - coalesce(sr_net_loss, 0)) as profit - from store_sales left outer join store_returns on - (ss_item_sk = sr_item_sk and ss_ticket_number = sr_ticket_number), - date_dim, - store, - item, - promotion - where ss_sold_date_sk = d_date_sk - and d_date between cast('2000-08-22' as date) - and dateadd(day,30,cast('2000-08-22' as date)) - and ss_store_sk = s_store_sk - and ss_item_sk = i_item_sk - and i_current_price > 50 - and ss_promo_sk = p_promo_sk - and p_channel_tv = 'N' - group by s_store_id) - , - csr as - (select cp_catalog_page_id as catalog_page_id, - sum(cs_ext_sales_price) as sales, - sum(coalesce(cr_return_amount, 0)) as returns, - sum(cs_net_profit - coalesce(cr_net_loss, 0)) as profit - from catalog_sales left outer join catalog_returns on - (cs_item_sk = cr_item_sk and cs_order_number = cr_order_number), - date_dim, - catalog_page, - item, - promotion - where cs_sold_date_sk = d_date_sk - and d_date between cast('2000-08-22' as date) - and dateadd(day,30,cast('2000-08-22' as date)) - and cs_catalog_page_sk = cp_catalog_page_sk - and cs_item_sk = i_item_sk - and i_current_price > 50 - and cs_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(ws_ext_sales_price) as sales, - sum(coalesce(wr_return_amt, 0)) as returns, - sum(ws_net_profit - coalesce(wr_net_loss, 0)) as profit - from web_sales left outer join web_returns on - (ws_item_sk = wr_item_sk and ws_order_number = wr_order_number), - date_dim, - web_site, - item, - promotion - where ws_sold_date_sk = d_date_sk - and d_date between cast('2000-08-22' as date) - and dateadd(day,30,cast('2000-08-22' as date)) - and ws_web_site_sk = web_site_sk - and ws_item_sk = i_item_sk - and i_current_price > 50 - and ws_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by web_site_id) -, -results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || store_id as id - , sales - , returns - , profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || catalog_page_id as id - , sales - , returns - , profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , profit - from wsr - ) x - group by channel, id) - - select channel - , id - , sales - , returns - , profit - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results - ) foo - order by channel, id - limit 100; - --- end template query80a.tpl query 9 in stream 8 --- start template query12.tpl query 10 in stream 8 -select /* TPC-DS query12.tpl 0.64 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ws_ext_sales_price) as itemrevenue - ,sum(ws_ext_sales_price)*100/sum(sum(ws_ext_sales_price)) over - (partition by i_class) as revenueratio -from - web_sales - ,item - ,date_dim -where - ws_item_sk = i_item_sk - and i_category in ('Women', 'Jewelry', 'Books') - and ws_sold_date_sk = d_date_sk - and d_date between cast('1998-04-02' as date) - and dateadd(day,30,cast('1998-04-02' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query12.tpl query 10 in stream 8 --- start template query59.tpl query 11 in stream 8 -with /* TPC-DS query59.tpl 0.30 */ wss as - (select d_week_seq, - ss_store_sk, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - group by d_week_seq,ss_store_sk - ) - select s_store_name1,s_store_id1,d_week_seq1 - ,sun_sales1/sun_sales2,mon_sales1/mon_sales2 - ,tue_sales1/tue_sales2,wed_sales1/wed_sales2,thu_sales1/thu_sales2 - ,fri_sales1/fri_sales2,sat_sales1/sat_sales2 - from - (select s_store_name s_store_name1,wss.d_week_seq d_week_seq1 - ,s_store_id s_store_id1,sun_sales sun_sales1 - ,mon_sales mon_sales1,tue_sales tue_sales1 - ,wed_sales wed_sales1,thu_sales thu_sales1 - ,fri_sales fri_sales1,sat_sales sat_sales1 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1202 and 1202 + 11) y, - (select s_store_name s_store_name2,wss.d_week_seq d_week_seq2 - ,s_store_id s_store_id2,sun_sales sun_sales2 - ,mon_sales mon_sales2,tue_sales tue_sales2 - ,wed_sales wed_sales2,thu_sales thu_sales2 - ,fri_sales fri_sales2,sat_sales sat_sales2 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1202+ 12 and 1202 + 23) x - where s_store_id1=s_store_id2 - and d_week_seq1=d_week_seq2-52 - order by s_store_name1,s_store_id1,d_week_seq1 -limit 100; - --- end template query59.tpl query 11 in stream 8 --- start template query70a.tpl query 12 in stream 8 -with /* TPC-DS query70a.tpl 0.34 */ results as -( select - sum(ss_net_profit) as total_sum ,s_state ,s_county, 0 as gstate, 0 as g_county - from - store_sales - ,date_dim d1 - ,store - where - d1.d_month_seq between 1193 and 1193 + 11 - and d1.d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - and s_state in - ( select s_state - from (select s_state as s_state, - rank() over ( partition by s_state order by sum(ss_net_profit) desc) as ranking - from store_sales, store, date_dim - where d_month_seq between 1193 and 1193 + 11 - and d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - group by s_state - ) tmp1 - where ranking <= 5) - group by s_state,s_county) , - results_rollup as -(select total_sum ,s_state ,s_county, 0 as g_state, 0 as g_county, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum,s_state, NULL as s_county, 0 as g_state, 1 as g_county, 1 as lochierarchy from results group by s_state - union - select sum(total_sum) as total_sum ,NULL as s_state ,NULL as s_county, 1 as g_state, 1 as g_county, 2 as lochierarchy from results) - select total_sum ,s_state ,s_county, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_county = 0 then s_state end - order by total_sum desc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then s_state end - ,rank_within_parent - limit 100; - --- end template query70a.tpl query 12 in stream 8 --- start template query91.tpl query 13 in stream 8 -select /* TPC-DS query91.tpl 0.13 */ - cc_call_center_id Call_Center, - cc_name Call_Center_Name, - cc_manager Manager, - sum(cr_net_loss) Returns_Loss -from - call_center, - catalog_returns, - date_dim, - customer, - customer_address, - customer_demographics, - household_demographics -where - cr_call_center_sk = cc_call_center_sk -and cr_returned_date_sk = d_date_sk -and cr_returning_customer_sk= c_customer_sk -and cd_demo_sk = c_current_cdemo_sk -and hd_demo_sk = c_current_hdemo_sk -and ca_address_sk = c_current_addr_sk -and d_year = 2000 -and d_moy = 11 -and ( (cd_marital_status = 'M' and cd_education_status = 'Unknown') - or(cd_marital_status = 'W' and cd_education_status = 'Advanced Degree')) -and hd_buy_potential like '501-1000%' -and ca_gmt_offset = -6 -group by cc_call_center_id,cc_name,cc_manager,cd_marital_status,cd_education_status -order by sum(cr_net_loss) desc; - --- end template query91.tpl query 13 in stream 8 --- start template query69.tpl query 14 in stream 8 -select /* TPC-DS query69.tpl 0.28 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_state in ('TX','GA','WV') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2003 and - d_moy between 1 and 1+2) and - (not exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2003 and - d_moy between 1 and 1+2) and - not exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2003 and - d_moy between 1 and 1+2)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - limit 100; - --- end template query69.tpl query 14 in stream 8 --- start template query40.tpl query 15 in stream 8 -select /* TPC-DS query40.tpl 0.86 */ - w_state - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('2001-05-19' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_before - ,sum(case when (cast(d_date as date) >= cast ('2001-05-19' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_after - from - catalog_sales left outer join catalog_returns on - (cs_order_number = cr_order_number - and cs_item_sk = cr_item_sk) - ,warehouse - ,item - ,date_dim - where - i_current_price between 0.99 and 1.49 - and i_item_sk = cs_item_sk - and cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('2001-05-19' as date)) - and dateadd(day,30,cast ('2001-05-19' as date)) - group by - w_state,i_item_id - order by w_state,i_item_id -limit 100; - --- end template query40.tpl query 15 in stream 8 --- start template query2.tpl query 16 in stream 8 -with /* TPC-DS query2.tpl 0.84 */ wscs as - (select sold_date_sk - ,sales_price - from (select ws_sold_date_sk sold_date_sk - ,ws_ext_sales_price sales_price - from web_sales - union all - select cs_sold_date_sk sold_date_sk - ,cs_ext_sales_price sales_price - from catalog_sales)), - wswscs as - (select d_week_seq, - sum(case when (d_day_name='Sunday') then sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then sales_price else null end) sat_sales - from wscs - ,date_dim - where d_date_sk = sold_date_sk - group by d_week_seq) - select d_week_seq1 - ,round(sun_sales1/sun_sales2,2) - ,round(mon_sales1/mon_sales2,2) - ,round(tue_sales1/tue_sales2,2) - ,round(wed_sales1/wed_sales2,2) - ,round(thu_sales1/thu_sales2,2) - ,round(fri_sales1/fri_sales2,2) - ,round(sat_sales1/sat_sales2,2) - from - (select wswscs.d_week_seq d_week_seq1 - ,sun_sales sun_sales1 - ,mon_sales mon_sales1 - ,tue_sales tue_sales1 - ,wed_sales wed_sales1 - ,thu_sales thu_sales1 - ,fri_sales fri_sales1 - ,sat_sales sat_sales1 - from wswscs,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 2001) y, - (select wswscs.d_week_seq d_week_seq2 - ,sun_sales sun_sales2 - ,mon_sales mon_sales2 - ,tue_sales tue_sales2 - ,wed_sales wed_sales2 - ,thu_sales thu_sales2 - ,fri_sales fri_sales2 - ,sat_sales sat_sales2 - from wswscs - ,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 2001+1) z - where d_week_seq1=d_week_seq2-53 - order by d_week_seq1; - --- end template query2.tpl query 16 in stream 8 --- start template query16.tpl query 17 in stream 8 -select /* TPC-DS query16.tpl 0.25 */ - count(distinct cs_order_number) as "order count" - ,sum(cs_ext_ship_cost) as "total shipping cost" - ,sum(cs_net_profit) as "total net profit" -from - catalog_sales cs1 - ,date_dim - ,customer_address - ,call_center -where - d_date between '2000-2-01' and - dateadd(day, 60, cast('2000-2-01' as date)) -and cs1.cs_ship_date_sk = d_date_sk -and cs1.cs_ship_addr_sk = ca_address_sk -and ca_state = 'CO' -and cs1.cs_call_center_sk = cc_call_center_sk -and cc_county in ('Kittitas County','Perry County','Franklin Parish','Sierra County', - 'Bronx County' -) -and exists (select * - from catalog_sales cs2 - where cs1.cs_order_number = cs2.cs_order_number - and cs1.cs_warehouse_sk <> cs2.cs_warehouse_sk) -and not exists(select * - from catalog_returns cr1 - where cs1.cs_order_number = cr1.cr_order_number) -order by count(distinct cs_order_number) -limit 100; - --- end template query16.tpl query 17 in stream 8 --- start template query44.tpl query 18 in stream 8 -select /* TPC-DS query44.tpl 0.4 */ asceding.rnk, i1.i_product_name best_performing, i2.i_product_name worst_performing -from(select * - from (select item_sk,rank() over (order by rank_col asc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 717 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 717 - and ss_addr_sk is null - group by ss_store_sk))V1)V11 - where rnk < 11) asceding, - (select * - from (select item_sk,rank() over (order by rank_col desc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 717 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 717 - and ss_addr_sk is null - group by ss_store_sk))V2)V21 - where rnk < 11) descending, -item i1, -item i2 -where asceding.rnk = descending.rnk - and i1.i_item_sk=asceding.item_sk - and i2.i_item_sk=descending.item_sk -order by asceding.rnk -limit 100; - --- end template query44.tpl query 18 in stream 8 --- start template query5a.tpl query 19 in stream 8 -with /* TPC-DS query5a.tpl 0.98 */ ssr as - (select s_store_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ss_store_sk as store_sk, - ss_sold_date_sk as date_sk, - ss_ext_sales_price as sales_price, - ss_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from store_sales - union all - select sr_store_sk as store_sk, - sr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - sr_return_amt as return_amt, - sr_net_loss as net_loss - from store_returns - ) salesreturns, - date_dim, - store - where date_sk = d_date_sk - and d_date between cast('2000-08-25' as date) - and dateadd(day,14,cast('2000-08-25' as date)) - and store_sk = s_store_sk - group by s_store_id) - , - csr as - (select cp_catalog_page_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select cs_catalog_page_sk as page_sk, - cs_sold_date_sk as date_sk, - cs_ext_sales_price as sales_price, - cs_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from catalog_sales - union all - select cr_catalog_page_sk as page_sk, - cr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - cr_return_amount as return_amt, - cr_net_loss as net_loss - from catalog_returns - ) salesreturns, - date_dim, - catalog_page - where date_sk = d_date_sk - and d_date between cast('2000-08-25' as date) - and dateadd(day,14,cast('2000-08-25' as date)) - and page_sk = cp_catalog_page_sk - group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ws_web_site_sk as wsr_web_site_sk, - ws_sold_date_sk as date_sk, - ws_ext_sales_price as sales_price, - ws_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from web_sales - union all - select ws_web_site_sk as wsr_web_site_sk, - wr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - wr_return_amt as return_amt, - wr_net_loss as net_loss - from web_returns left outer join web_sales on - ( wr_item_sk = ws_item_sk - and wr_order_number = ws_order_number) - ) salesreturns, - date_dim, - web_site - where date_sk = d_date_sk - and d_date between cast('2000-08-25' as date) - and dateadd(day,14,cast('2000-08-25' as date)) - and wsr_web_site_sk = web_site_sk - group by web_site_id) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || s_store_id as id - , sales - , returns - , (profit - profit_loss) as profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || cp_catalog_page_id as id - , sales - , returns - , (profit - profit_loss) as profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , (profit - profit_loss) as profit - from wsr - ) x - group by channel, id) - select channel, id, sales, returns, profit from ( - select channel, id, sales, returns, profit from results - union - select channel, null as id, sum(sales), sum(returns), sum(profit) from results group by channel - union - select null as channel, null as id, sum(sales), sum(returns), sum(profit) from results) foo -order by channel, id -limit 100; - --- end template query5a.tpl query 19 in stream 8 --- start template query73.tpl query 20 in stream 8 -select /* TPC-DS query73.tpl 0.79 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_buy_potential = '501-1000' or - household_demographics.hd_buy_potential = '5001-10000') - and household_demographics.hd_vehicle_count > 0 - and case when household_demographics.hd_vehicle_count > 0 then - household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count else null end > 1 - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_county in ('Ziebach County','Lake County','Huron County','Baltimore County') - group by ss_ticket_number,ss_customer_sk) dj,customer - where ss_customer_sk = c_customer_sk - and cnt between 1 and 5 - order by cnt desc, c_last_name asc; - --- end template query73.tpl query 20 in stream 8 --- start template query14a.tpl query 21 in stream 8 -with /* TPC-DS query14a.tpl 0.69 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1999 AND 1999 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1999 AND 1999 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1999 AND 1999 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as - (select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2) x) -, - results AS -(select channel, i_brand_id, i_class_id, i_category_id, sum(sales) sum_sales, sum(number_sales) number_sales - from ( - select 'store' channel, i_brand_id,i_class_id - ,i_category_id,sum(ss_quantity*ss_list_price) sales - , count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1999+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales) - union all - select 'catalog' channel, i_brand_id,i_class_id,i_category_id, sum(cs_quantity*cs_list_price) sales, count(*) number_sales - from catalog_sales - ,item - ,date_dim - where cs_item_sk in (select ss_item_sk from cross_items) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1999+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(cs_quantity*cs_list_price) > (select average_sales from avg_sales) - union all - select 'web' channel, i_brand_id,i_class_id,i_category_id, sum(ws_quantity*ws_list_price) sales , count(*) number_sales - from web_sales - ,item - ,date_dim - where ws_item_sk in (select ss_item_sk from cross_items) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1999+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ws_quantity*ws_list_price) > (select average_sales from avg_sales) - ) y - group by channel, i_brand_id,i_class_id,i_category_id) - - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales -from ( - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales from results - union - select channel, i_brand_id, i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id, i_class_id - union - select channel, i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id - union - select channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel - union - select null as channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results) z -order by channel, i_brand_id, i_class_id, i_category_id - limit 100; -with /* TPC-DS query14a.tpl 0.69 part2 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1999 AND 1999 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1999 AND 1999 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1999 AND 1999 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as -(select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2) x) - select this_year.channel ty_channel - ,this_year.i_brand_id ty_brand - ,this_year.i_class_id ty_class - ,this_year.i_category_id ty_category - ,this_year.sales ty_sales - ,this_year.number_sales ty_number_sales - ,last_year.channel ly_channel - ,last_year.i_brand_id ly_brand - ,last_year.i_class_id ly_class - ,last_year.i_category_id ly_category - ,last_year.sales ly_sales - ,last_year.number_sales ly_number_sales -from - (select 'store' channel, i_brand_id,i_class_id,i_category_id - ,sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1999 + 1 - and d_moy = 12 - and d_dom = 6) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) this_year, - (select 'store' channel, i_brand_id,i_class_id - ,i_category_id, sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1999 - and d_moy = 12 - and d_dom = 6) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) last_year - where this_year.i_brand_id= last_year.i_brand_id - and this_year.i_class_id = last_year.i_class_id - and this_year.i_category_id = last_year.i_category_id - order by this_year.channel, this_year.i_brand_id, this_year.i_class_id, this_year.i_category_id - limit 100; - --- end template query14a.tpl query 21 in stream 8 --- start template query71.tpl query 22 in stream 8 -select /* TPC-DS query71.tpl 0.72 */ i_brand_id brand_id, i_brand brand,t_hour,t_minute, - sum(ext_price) ext_price - from item, (select ws_ext_sales_price as ext_price, - ws_sold_date_sk as sold_date_sk, - ws_item_sk as sold_item_sk, - ws_sold_time_sk as time_sk - from web_sales,date_dim - where d_date_sk = ws_sold_date_sk - and d_moy=11 - and d_year=2002 - union all - select cs_ext_sales_price as ext_price, - cs_sold_date_sk as sold_date_sk, - cs_item_sk as sold_item_sk, - cs_sold_time_sk as time_sk - from catalog_sales,date_dim - where d_date_sk = cs_sold_date_sk - and d_moy=11 - and d_year=2002 - union all - select ss_ext_sales_price as ext_price, - ss_sold_date_sk as sold_date_sk, - ss_item_sk as sold_item_sk, - ss_sold_time_sk as time_sk - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - and d_moy=11 - and d_year=2002 - ) tmp,time_dim - where - sold_item_sk = i_item_sk - and i_manager_id=1 - and time_sk = t_time_sk - and (t_meal_time = 'breakfast' or t_meal_time = 'dinner') - group by i_brand, i_brand_id,t_hour,t_minute - order by ext_price desc, i_brand_id - ; - --- end template query71.tpl query 22 in stream 8 --- start template query3.tpl query 23 in stream 8 -select /* TPC-DS query3.tpl 0.45 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_sales_price) sum_agg - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manufact_id = 681 - and dt.d_moy=12 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,sum_agg desc - ,brand_id - limit 100; - --- end template query3.tpl query 23 in stream 8 --- start template query49.tpl query 24 in stream 8 -select /* TPC-DS query49.tpl 0.48 */ channel, item, return_ratio, return_rank, currency_rank from - (select - 'web' as channel - ,web.item - ,web.return_ratio - ,web.return_rank - ,web.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select ws.ws_item_sk as item - ,(cast(sum(coalesce(wr.wr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(wr.wr_return_amt,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - web_sales ws left outer join web_returns wr - on (ws.ws_order_number = wr.wr_order_number and - ws.ws_item_sk = wr.wr_item_sk) - ,date_dim - where - wr.wr_return_amt > 10000 - and ws.ws_net_profit > 1 - and ws.ws_net_paid > 0 - and ws.ws_quantity > 0 - and ws_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 12 - group by ws.ws_item_sk - ) in_web - ) web - where - ( - web.return_rank <= 10 - or - web.currency_rank <= 10 - ) - union - select - 'catalog' as channel - ,catalog.item - ,catalog.return_ratio - ,catalog.return_rank - ,catalog.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select - cs.cs_item_sk as item - ,(cast(sum(coalesce(cr.cr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(cr.cr_return_amount,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - catalog_sales cs left outer join catalog_returns cr - on (cs.cs_order_number = cr.cr_order_number and - cs.cs_item_sk = cr.cr_item_sk) - ,date_dim - where - cr.cr_return_amount > 10000 - and cs.cs_net_profit > 1 - and cs.cs_net_paid > 0 - and cs.cs_quantity > 0 - and cs_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 12 - group by cs.cs_item_sk - ) in_cat - ) catalog - where - ( - catalog.return_rank <= 10 - or - catalog.currency_rank <=10 - ) - union - select - 'store' as channel - ,store.item - ,store.return_ratio - ,store.return_rank - ,store.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select sts.ss_item_sk as item - ,(cast(sum(coalesce(sr.sr_return_quantity,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(sr.sr_return_amt,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - store_sales sts left outer join store_returns sr - on (sts.ss_ticket_number = sr.sr_ticket_number and sts.ss_item_sk = sr.sr_item_sk) - ,date_dim - where - sr.sr_return_amt > 10000 - and sts.ss_net_profit > 1 - and sts.ss_net_paid > 0 - and sts.ss_quantity > 0 - and ss_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 12 - group by sts.ss_item_sk - ) in_store - ) store - where ( - store.return_rank <= 10 - or - store.currency_rank <= 10 - ) - ) - order by 1,4,5,2 - limit 100; - --- end template query49.tpl query 24 in stream 8 --- start template query84.tpl query 25 in stream 8 -select /* TPC-DS query84.tpl 0.80 */ c_customer_id as customer_id - , coalesce(c_last_name,'') || ', ' || coalesce(c_first_name,'') as customername - from customer - ,customer_address - ,customer_demographics - ,household_demographics - ,income_band - ,store_returns - where ca_city = 'Stringtown' - and c_current_addr_sk = ca_address_sk - and ib_lower_bound >= 56947 - and ib_upper_bound <= 56947 + 50000 - and ib_income_band_sk = hd_income_band_sk - and cd_demo_sk = c_current_cdemo_sk - and hd_demo_sk = c_current_hdemo_sk - and sr_cdemo_sk = cd_demo_sk - order by c_customer_id - limit 100; - --- end template query84.tpl query 25 in stream 8 --- start template query64.tpl query 26 in stream 8 -with /* TPC-DS query64.tpl 0.20 */ cs_ui as - (select cs_item_sk - ,sum(cs_ext_list_price) as sale,sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit) as refund - from catalog_sales - ,catalog_returns - where cs_item_sk = cr_item_sk - and cs_order_number = cr_order_number - group by cs_item_sk - having sum(cs_ext_list_price)>2*sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit)), -cross_sales as - (select i_product_name product_name - ,i_item_sk item_sk - ,s_store_name store_name - ,s_zip store_zip - ,ad1.ca_street_number b_street_number - ,ad1.ca_street_name b_street_name - ,ad1.ca_city b_city - ,ad1.ca_zip b_zip - ,ad2.ca_street_number c_street_number - ,ad2.ca_street_name c_street_name - ,ad2.ca_city c_city - ,ad2.ca_zip c_zip - ,d1.d_year as syear - ,d2.d_year as fsyear - ,d3.d_year s2year - ,count(*) cnt - ,sum(ss_wholesale_cost) s1 - ,sum(ss_list_price) s2 - ,sum(ss_coupon_amt) s3 - FROM store_sales - ,store_returns - ,cs_ui - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,customer - ,customer_demographics cd1 - ,customer_demographics cd2 - ,promotion - ,household_demographics hd1 - ,household_demographics hd2 - ,customer_address ad1 - ,customer_address ad2 - ,income_band ib1 - ,income_band ib2 - ,item - WHERE ss_store_sk = s_store_sk AND - ss_sold_date_sk = d1.d_date_sk AND - ss_customer_sk = c_customer_sk AND - ss_cdemo_sk= cd1.cd_demo_sk AND - ss_hdemo_sk = hd1.hd_demo_sk AND - ss_addr_sk = ad1.ca_address_sk and - ss_item_sk = i_item_sk and - ss_item_sk = sr_item_sk and - ss_ticket_number = sr_ticket_number and - ss_item_sk = cs_ui.cs_item_sk and - c_current_cdemo_sk = cd2.cd_demo_sk AND - c_current_hdemo_sk = hd2.hd_demo_sk AND - c_current_addr_sk = ad2.ca_address_sk and - c_first_sales_date_sk = d2.d_date_sk and - c_first_shipto_date_sk = d3.d_date_sk and - ss_promo_sk = p_promo_sk and - hd1.hd_income_band_sk = ib1.ib_income_band_sk and - hd2.hd_income_band_sk = ib2.ib_income_band_sk and - cd1.cd_marital_status <> cd2.cd_marital_status and - i_color in ('brown','thistle','metallic','light','cream','violet') and - i_current_price between 33 and 33 + 10 and - i_current_price between 33 + 1 and 33 + 15 -group by i_product_name - ,i_item_sk - ,s_store_name - ,s_zip - ,ad1.ca_street_number - ,ad1.ca_street_name - ,ad1.ca_city - ,ad1.ca_zip - ,ad2.ca_street_number - ,ad2.ca_street_name - ,ad2.ca_city - ,ad2.ca_zip - ,d1.d_year - ,d2.d_year - ,d3.d_year -) -select cs1.product_name - ,cs1.store_name - ,cs1.store_zip - ,cs1.b_street_number - ,cs1.b_street_name - ,cs1.b_city - ,cs1.b_zip - ,cs1.c_street_number - ,cs1.c_street_name - ,cs1.c_city - ,cs1.c_zip - ,cs1.syear - ,cs1.cnt - ,cs1.s1 as s11 - ,cs1.s2 as s21 - ,cs1.s3 as s31 - ,cs2.s1 as s12 - ,cs2.s2 as s22 - ,cs2.s3 as s32 - ,cs2.syear - ,cs2.cnt -from cross_sales cs1,cross_sales cs2 -where cs1.item_sk=cs2.item_sk and - cs1.syear = 1999 and - cs2.syear = 1999 + 1 and - cs2.cnt <= cs1.cnt and - cs1.store_name = cs2.store_name and - cs1.store_zip = cs2.store_zip -order by cs1.product_name - ,cs1.store_name - ,cs2.cnt - ,cs1.s1 - ,cs2.s1; - --- end template query64.tpl query 26 in stream 8 --- start template query7.tpl query 27 in stream 8 -select /* TPC-DS query7.tpl 0.2 */ i_item_id, - avg(ss_quantity) agg1, - avg(ss_list_price) agg2, - avg(ss_coupon_amt) agg3, - avg(ss_sales_price) agg4 - from store_sales, customer_demographics, date_dim, item, promotion - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_cdemo_sk = cd_demo_sk and - ss_promo_sk = p_promo_sk and - cd_gender = 'M' and - cd_marital_status = 'U' and - cd_education_status = 'Unknown' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 2001 - group by i_item_id - order by i_item_id - limit 100; - --- end template query7.tpl query 27 in stream 8 --- start template query36a.tpl query 28 in stream 8 -with /* TPC-DS query36a.tpl 0.21 */ results as - (select - sum(ss_net_profit) as ss_net_profit, sum(ss_ext_sales_price) as ss_ext_sales_price, - sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin - ,i_category - ,i_class - ,0 as g_category, 0 as g_class - from - store_sales - ,date_dim d1 - ,item - ,store - where - d1.d_year = 1999 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and s_state in ('OK','NM','IL','IA', - 'TX','PA','MI','GA') - group by i_category,i_class) - , - results_rollup as - (select gross_margin ,i_category ,i_class,0 as t_category, 0 as t_class, 0 as lochierarchy from results - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - i_category, NULL AS i_class, 0 as t_category, 1 as t_class, 1 as lochierarchy from results group by i_category - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - NULL AS i_category ,NULL AS i_class, 1 as t_category, 1 as t_class, 2 as lochierarchy from results) - select - gross_margin ,i_category ,i_class, lochierarchy,rank() over ( - partition by lochierarchy, case when t_class = 0 then i_category end - order by gross_margin asc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then i_category end - ,rank_within_parent - limit 100; - --- end template query36a.tpl query 28 in stream 8 --- start template query61.tpl query 29 in stream 8 -select /* TPC-DS query61.tpl 0.97 */ promotions,total,cast(promotions as decimal(16,4))/cast(total as decimal(16,4))*100 -from - (select sum(ss_ext_sales_price) promotions - from store_sales - ,store - ,promotion - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_promo_sk = p_promo_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -6 - and i_category = 'Home' - and (p_channel_dmail = 'Y' or p_channel_email = 'Y' or p_channel_tv = 'Y') - and s_gmt_offset = -6 - and d_year = 2002 - and d_moy = 11) promotional_sales, - (select sum(ss_ext_sales_price) total - from store_sales - ,store - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -6 - and i_category = 'Home' - and s_gmt_offset = -6 - and d_year = 2002 - and d_moy = 11) all_sales -order by promotions, total -limit 100; - --- end template query61.tpl query 29 in stream 8 --- start template query41.tpl query 30 in stream 8 -select /* TPC-DS query41.tpl 0.62 */ distinct(i_product_name) - from item i1 - where i_manufact_id between 727 and 727+40 - and (select count(*) as item_cnt - from item - where (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'spring' or i_color = 'moccasin') and - (i_units = 'Tbl' or i_units = 'Cup') and - (i_size = 'large' or i_size = 'medium') - ) or - (i_category = 'Women' and - (i_color = 'peach' or i_color = 'rose') and - (i_units = 'Dram' or i_units = 'Bundle') and - (i_size = 'extra large' or i_size = 'petite') - ) or - (i_category = 'Men' and - (i_color = 'medium' or i_color = 'cream') and - (i_units = 'Carton' or i_units = 'Gram') and - (i_size = 'small' or i_size = 'N/A') - ) or - (i_category = 'Men' and - (i_color = 'coral' or i_color = 'dark') and - (i_units = 'Pound' or i_units = 'Dozen') and - (i_size = 'large' or i_size = 'medium') - ))) or - (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'salmon' or i_color = 'turquoise') and - (i_units = 'Ton' or i_units = 'Oz') and - (i_size = 'large' or i_size = 'medium') - ) or - (i_category = 'Women' and - (i_color = 'metallic' or i_color = 'misty') and - (i_units = 'Pallet' or i_units = 'N/A') and - (i_size = 'extra large' or i_size = 'petite') - ) or - (i_category = 'Men' and - (i_color = 'beige' or i_color = 'sky') and - (i_units = 'Tsp' or i_units = 'Each') and - (i_size = 'small' or i_size = 'N/A') - ) or - (i_category = 'Men' and - (i_color = 'powder' or i_color = 'light') and - (i_units = 'Unknown' or i_units = 'Ounce') and - (i_size = 'large' or i_size = 'medium') - )))) > 0 - order by i_product_name - limit 100; - --- end template query41.tpl query 30 in stream 8 --- start template query35a.tpl query 31 in stream 8 -select /* TPC-DS query35a.tpl 0.47 */ - ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - count(*) cnt1, - max(cd_dep_count), - sum(cd_dep_count), - avg(cd_dep_count), - cd_dep_employed_count, - count(*) cnt2, - max(cd_dep_employed_count), - sum(cd_dep_employed_count), - avg(cd_dep_employed_count), - cd_dep_college_count, - count(*) cnt3, - max(cd_dep_college_count), - sum(cd_dep_college_count), - avg(cd_dep_college_count) - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 1999 and - d_qoy < 4) and - exists (select * from - (select ws_bill_customer_sk customsk - from web_sales,date_dim - where - ws_sold_date_sk = d_date_sk and - d_year = 1999 and - d_qoy < 4 - union all - select cs_ship_customer_sk customsk - from catalog_sales,date_dim - where - cs_sold_date_sk = d_date_sk and - d_year = 1999 and - d_qoy < 4)x - where x.customsk = c.c_customer_sk) - group by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - limit 100; - --- end template query35a.tpl query 31 in stream 8 --- start template query50.tpl query 32 in stream 8 -select /* TPC-DS query50.tpl 0.60 */ - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 30) and - (sr_returned_date_sk - ss_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 60) and - (sr_returned_date_sk - ss_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 90) and - (sr_returned_date_sk - ss_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - store_sales - ,store_returns - ,store - ,date_dim d1 - ,date_dim d2 -where - d2.d_year = 2000 -and d2.d_moy = 9 -and ss_ticket_number = sr_ticket_number -and ss_item_sk = sr_item_sk -and ss_sold_date_sk = d1.d_date_sk -and sr_returned_date_sk = d2.d_date_sk -and ss_customer_sk = sr_customer_sk -and ss_store_sk = s_store_sk -group by - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -order by s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -limit 100; - --- end template query50.tpl query 32 in stream 8 --- start template query65.tpl query 33 in stream 8 -select /* TPC-DS query65.tpl 0.71 */ - s_store_name, - i_item_desc, - sc.revenue, - i_current_price, - i_wholesale_cost, - i_brand - from store, item, - (select ss_store_sk, avg(revenue) as ave - from - (select ss_store_sk, ss_item_sk, - sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1193 and 1193+11 - group by ss_store_sk, ss_item_sk) sa - group by ss_store_sk) sb, - (select ss_store_sk, ss_item_sk, sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1193 and 1193+11 - group by ss_store_sk, ss_item_sk) sc - where sb.ss_store_sk = sc.ss_store_sk and - sc.revenue <= 0.1 * sb.ave and - s_store_sk = sc.ss_store_sk and - i_item_sk = sc.ss_item_sk - order by s_store_name, i_item_desc -limit 100; - --- end template query65.tpl query 33 in stream 8 --- start template query51.tpl query 34 in stream 8 -WITH /* TPC-DS query51.tpl 0.46 */ web_v1 as ( -select - ws_item_sk item_sk, d_date, - sum(sum(ws_sales_price)) - over (partition by ws_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from web_sales - ,date_dim -where ws_sold_date_sk=d_date_sk - and d_month_seq between 1204 and 1204+11 - and ws_item_sk is not NULL -group by ws_item_sk, d_date), -store_v1 as ( -select - ss_item_sk item_sk, d_date, - sum(sum(ss_sales_price)) - over (partition by ss_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from store_sales - ,date_dim -where ss_sold_date_sk=d_date_sk - and d_month_seq between 1204 and 1204+11 - and ss_item_sk is not NULL -group by ss_item_sk, d_date) - select * -from (select item_sk - ,d_date - ,web_sales - ,store_sales - ,max(web_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) web_cumulative - ,max(store_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) store_cumulative - from (select case when web.item_sk is not null then web.item_sk else store.item_sk end item_sk - ,case when web.d_date is not null then web.d_date else store.d_date end d_date - ,web.cume_sales web_sales - ,store.cume_sales store_sales - from web_v1 web full outer join store_v1 store on (web.item_sk = store.item_sk - and web.d_date = store.d_date) - )x )y -where web_cumulative > store_cumulative -order by item_sk - ,d_date -limit 100; - --- end template query51.tpl query 34 in stream 8 --- start template query78.tpl query 35 in stream 8 -with /* TPC-DS query78.tpl 0.10 */ ws as - (select d_year AS ws_sold_year, ws_item_sk, - ws_bill_customer_sk ws_customer_sk, - sum(ws_quantity) ws_qty, - sum(ws_wholesale_cost) ws_wc, - sum(ws_sales_price) ws_sp - from web_sales - left join web_returns on wr_order_number=ws_order_number and ws_item_sk=wr_item_sk - join date_dim on ws_sold_date_sk = d_date_sk - where wr_order_number is null - group by d_year, ws_item_sk, ws_bill_customer_sk - ), -cs as - (select d_year AS cs_sold_year, cs_item_sk, - cs_bill_customer_sk cs_customer_sk, - sum(cs_quantity) cs_qty, - sum(cs_wholesale_cost) cs_wc, - sum(cs_sales_price) cs_sp - from catalog_sales - left join catalog_returns on cr_order_number=cs_order_number and cs_item_sk=cr_item_sk - join date_dim on cs_sold_date_sk = d_date_sk - where cr_order_number is null - group by d_year, cs_item_sk, cs_bill_customer_sk - ), -ss as - (select d_year AS ss_sold_year, ss_item_sk, - ss_customer_sk, - sum(ss_quantity) ss_qty, - sum(ss_wholesale_cost) ss_wc, - sum(ss_sales_price) ss_sp - from store_sales - left join store_returns on sr_ticket_number=ss_ticket_number and ss_item_sk=sr_item_sk - join date_dim on ss_sold_date_sk = d_date_sk - where sr_ticket_number is null - group by d_year, ss_item_sk, ss_customer_sk - ) - select -ss_customer_sk, -round(ss_qty/(coalesce(ws_qty,0)+coalesce(cs_qty,0)),2) ratio, -ss_qty store_qty, ss_wc store_wholesale_cost, ss_sp store_sales_price, -coalesce(ws_qty,0)+coalesce(cs_qty,0) other_chan_qty, -coalesce(ws_wc,0)+coalesce(cs_wc,0) other_chan_wholesale_cost, -coalesce(ws_sp,0)+coalesce(cs_sp,0) other_chan_sales_price -from ss -left join ws on (ws_sold_year=ss_sold_year and ws_item_sk=ss_item_sk and ws_customer_sk=ss_customer_sk) -left join cs on (cs_sold_year=ss_sold_year and cs_item_sk=ss_item_sk and cs_customer_sk=ss_customer_sk) -where (coalesce(ws_qty,0)>0 or coalesce(cs_qty, 0)>0) and ss_sold_year=2002 -order by - ss_customer_sk, - ss_qty desc, ss_wc desc, ss_sp desc, - other_chan_qty, - other_chan_wholesale_cost, - other_chan_sales_price, - ratio -limit 100; - --- end template query78.tpl query 35 in stream 8 --- start template query21.tpl query 36 in stream 8 -select /* TPC-DS query21.tpl 0.14 */ * - from(select w_warehouse_name - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('2000-03-23' as date)) - then inv_quantity_on_hand - else 0 end) as inv_before - ,sum(case when (cast(d_date as date) >= cast ('2000-03-23' as date)) - then inv_quantity_on_hand - else 0 end) as inv_after - from inventory - ,warehouse - ,item - ,date_dim - where i_current_price between 0.99 and 1.49 - and i_item_sk = inv_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('2000-03-23' as date)) - and dateadd(day,30,cast ('2000-03-23' as date)) - group by w_warehouse_name, i_item_id) x - where (case when inv_before > 0 - then inv_after / inv_before - else null - end) between 2.0/3.0 and 3.0/2.0 - order by w_warehouse_name - ,i_item_id - limit 100; - --- end template query21.tpl query 36 in stream 8 --- start template query67a.tpl query 37 in stream 8 -with /* TPC-DS query67a.tpl 0.35 */ results as -( select i_category ,i_class ,i_brand ,i_product_name ,d_year ,d_qoy ,d_moy ,s_store_id - ,sum(coalesce(ss_sales_price*ss_quantity,0)) sumsales - from store_sales ,date_dim ,store ,item - where ss_sold_date_sk=d_date_sk - and ss_item_sk=i_item_sk - and ss_store_sk = s_store_sk - and d_month_seq between 1207 and 1207 + 11 - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy,s_store_id) - , - results_rollup as - (select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, s_store_id, sumsales - from results - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy - union all - select i_category, i_class, i_brand, i_product_name, d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year - union all - select i_category, i_class, i_brand, i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name - union all - select i_category, i_class, i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand - union all - select i_category, i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class - union all - select i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category - union all - select null i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results) - - select * -from (select i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rank() over (partition by i_category order by sumsales desc) rk - from results_rollup) dw2 -where rk <= 100 -order by i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rk -limit 100; - --- end template query67a.tpl query 37 in stream 8 --- start template query22a.tpl query 38 in stream 8 -with /* TPC-DS query22a.tpl 0.55 */ results as -(select i_product_name - ,i_brand - ,i_class - ,i_category - ,avg(inv_quantity_on_hand) qoh - from inventory - ,date_dim - ,item --- ,warehouse - where inv_date_sk=d_date_sk - and inv_item_sk=i_item_sk --- and inv_warehouse_sk = w_warehouse_sk - and d_month_seq between 1183 and 1183 + 11 - group by i_product_name,i_brand,i_class,i_category), -results_rollup as -(select i_product_name, i_brand, i_class, i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class,i_category -union all -select i_product_name, i_brand, i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class -union all -select i_product_name, i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand -union all -select i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name -union all -select null i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results) - select i_product_name, i_brand, i_class, i_category,qoh - from results_rollup - order by qoh, i_product_name, i_brand, i_class, i_category -limit 100; - --- end template query22a.tpl query 38 in stream 8 --- start template query81.tpl query 39 in stream 8 -with /* TPC-DS query81.tpl 0.37 */ customer_total_return as - (select cr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(cr_return_amt_inc_tax) as ctr_total_return - from catalog_returns - ,date_dim - ,customer_address - where cr_returned_date_sk = d_date_sk - and d_year =1999 - and cr_returning_addr_sk = ca_address_sk - group by cr_returning_customer_sk - ,ca_state ) - select c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'MD' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - limit 100; - --- end template query81.tpl query 39 in stream 8 --- start template query93.tpl query 40 in stream 8 -select /* TPC-DS query93.tpl 0.52 */ ss_customer_sk - ,sum(act_sales) sumsales - from (select ss_item_sk - ,ss_ticket_number - ,ss_customer_sk - ,case when sr_return_quantity is not null then (ss_quantity-sr_return_quantity)*ss_sales_price - else (ss_quantity*ss_sales_price) end act_sales - from store_sales left outer join store_returns on (sr_item_sk = ss_item_sk - and sr_ticket_number = ss_ticket_number) - ,reason - where sr_reason_sk = r_reason_sk - and r_reason_desc = 'reason 44') t - group by ss_customer_sk - order by sumsales, ss_customer_sk -limit 100; - --- end template query93.tpl query 40 in stream 8 --- start template query25.tpl query 41 in stream 8 -select /* TPC-DS query25.tpl 0.9 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,sum(ss_net_profit) as store_sales_profit - ,sum(sr_net_loss) as store_returns_loss - ,sum(cs_net_profit) as catalog_sales_profit - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 2001 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 10 - and d2.d_year = 2001 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_moy between 4 and 10 - and d3.d_year = 2001 - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query25.tpl query 41 in stream 8 --- start template query26.tpl query 42 in stream 8 -select /* TPC-DS query26.tpl 0.85 */ i_item_id, - avg(cs_quantity) agg1, - avg(cs_list_price) agg2, - avg(cs_coupon_amt) agg3, - avg(cs_sales_price) agg4 - from catalog_sales, customer_demographics, date_dim, item, promotion - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd_demo_sk and - cs_promo_sk = p_promo_sk and - cd_gender = 'F' and - cd_marital_status = 'U' and - cd_education_status = '2 yr Degree' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 1999 - group by i_item_id - order by i_item_id - limit 100; - --- end template query26.tpl query 42 in stream 8 --- start template query90.tpl query 43 in stream 8 -select /* TPC-DS query90.tpl 0.40 */ cast(amc as decimal(15,4))/cast(pmc as decimal(15,4)) am_pm_ratio - from ( select count(*) amc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 6 and 6+1 - and household_demographics.hd_dep_count = 1 - and web_page.wp_char_count between 5000 and 5200) at, - ( select count(*) pmc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 14 and 14+1 - and household_demographics.hd_dep_count = 1 - and web_page.wp_char_count between 5000 and 5200) pt - order by am_pm_ratio - limit 100; - --- end template query90.tpl query 43 in stream 8 --- start template query74.tpl query 44 in stream 8 -with /* TPC-DS query74.tpl 0.76 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,sum(ss_net_paid) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (2001,2001+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,sum(ws_net_paid) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - and d_year in (2001,2001+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - ) - select - t_s_secyear.customer_id, t_s_secyear.customer_first_name, t_s_secyear.customer_last_name - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.year = 2001 - and t_s_secyear.year = 2001+1 - and t_w_firstyear.year = 2001 - and t_w_secyear.year = 2001+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - order by 2,3,1 -limit 100; - --- end template query74.tpl query 44 in stream 8 --- start template query92.tpl query 45 in stream 8 -select /* TPC-DS query92.tpl 0.44 */ - sum(ws_ext_discount_amt) as "Excess Discount Amount" -from - web_sales - ,item - ,date_dim -where -i_manufact_id = 793 -and i_item_sk = ws_item_sk -and d_date between '1999-03-16' and - dateadd(day,90,cast('1999-03-16' as date)) -and d_date_sk = ws_sold_date_sk -and ws_ext_discount_amt - > ( - SELECT - 1.3 * avg(ws_ext_discount_amt) - FROM - web_sales - ,date_dim - WHERE - ws_item_sk = i_item_sk - and d_date between '1999-03-16' and - dateadd(day,90,cast('1999-03-16' as date)) - and d_date_sk = ws_sold_date_sk - ) -order by sum(ws_ext_discount_amt) -limit 100; - --- end template query92.tpl query 45 in stream 8 --- start template query75.tpl query 46 in stream 8 -WITH /* TPC-DS query75.tpl 0.3 */ all_sales AS ( - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,SUM(sales_cnt) AS sales_cnt - ,SUM(sales_amt) AS sales_amt - FROM (SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,cs_quantity - COALESCE(cr_return_quantity,0) AS sales_cnt - ,cs_ext_sales_price - COALESCE(cr_return_amount,0.0) AS sales_amt - FROM catalog_sales JOIN item ON i_item_sk=cs_item_sk - JOIN date_dim ON d_date_sk=cs_sold_date_sk - LEFT JOIN catalog_returns ON (cs_order_number=cr_order_number - AND cs_item_sk=cr_item_sk) - WHERE i_category='Children' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ss_quantity - COALESCE(sr_return_quantity,0) AS sales_cnt - ,ss_ext_sales_price - COALESCE(sr_return_amt,0.0) AS sales_amt - FROM store_sales JOIN item ON i_item_sk=ss_item_sk - JOIN date_dim ON d_date_sk=ss_sold_date_sk - LEFT JOIN store_returns ON (ss_ticket_number=sr_ticket_number - AND ss_item_sk=sr_item_sk) - WHERE i_category='Children' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ws_quantity - COALESCE(wr_return_quantity,0) AS sales_cnt - ,ws_ext_sales_price - COALESCE(wr_return_amt,0.0) AS sales_amt - FROM web_sales JOIN item ON i_item_sk=ws_item_sk - JOIN date_dim ON d_date_sk=ws_sold_date_sk - LEFT JOIN web_returns ON (ws_order_number=wr_order_number - AND ws_item_sk=wr_item_sk) - WHERE i_category='Children') sales_detail - GROUP BY d_year, i_brand_id, i_class_id, i_category_id, i_manufact_id) - SELECT prev_yr.d_year AS prev_year - ,curr_yr.d_year AS year - ,curr_yr.i_brand_id - ,curr_yr.i_class_id - ,curr_yr.i_category_id - ,curr_yr.i_manufact_id - ,prev_yr.sales_cnt AS prev_yr_cnt - ,curr_yr.sales_cnt AS curr_yr_cnt - ,curr_yr.sales_cnt-prev_yr.sales_cnt AS sales_cnt_diff - ,curr_yr.sales_amt-prev_yr.sales_amt AS sales_amt_diff - FROM all_sales curr_yr, all_sales prev_yr - WHERE curr_yr.i_brand_id=prev_yr.i_brand_id - AND curr_yr.i_class_id=prev_yr.i_class_id - AND curr_yr.i_category_id=prev_yr.i_category_id - AND curr_yr.i_manufact_id=prev_yr.i_manufact_id - AND curr_yr.d_year=2002 - AND prev_yr.d_year=2002-1 - AND CAST(curr_yr.sales_cnt AS DECIMAL(17,2))/CAST(prev_yr.sales_cnt AS DECIMAL(17,2))<0.9 - ORDER BY sales_cnt_diff,sales_amt_diff - limit 100; - --- end template query75.tpl query 46 in stream 8 --- start template query10.tpl query 47 in stream 8 -select /* TPC-DS query10.tpl 0.26 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3, - cd_dep_count, - count(*) cnt4, - cd_dep_employed_count, - count(*) cnt5, - cd_dep_college_count, - count(*) cnt6 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_county in ('Elk County','Chatham County','Middlesex County','Waldo County','Fulton County') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 4 and 4+3) and - (exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 4 ANd 4+3) or - exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 4 and 4+3)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count -limit 100; - --- end template query10.tpl query 47 in stream 8 --- start template query58.tpl query 48 in stream 8 -with /* TPC-DS query58.tpl 0.19 */ ss_items as - (select i_item_id item_id - ,sum(ss_ext_sales_price) ss_item_rev - from store_sales - ,item - ,date_dim - where ss_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '2001-03-15')) - and ss_sold_date_sk = d_date_sk - group by i_item_id), - cs_items as - (select i_item_id item_id - ,sum(cs_ext_sales_price) cs_item_rev - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '2001-03-15')) - and cs_sold_date_sk = d_date_sk - group by i_item_id), - ws_items as - (select i_item_id item_id - ,sum(ws_ext_sales_price) ws_item_rev - from web_sales - ,item - ,date_dim - where ws_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq =(select d_week_seq - from date_dim - where d_date = '2001-03-15')) - and ws_sold_date_sk = d_date_sk - group by i_item_id) - select ss_items.item_id - ,ss_item_rev - ,ss_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ss_dev - ,cs_item_rev - ,cs_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 cs_dev - ,ws_item_rev - ,ws_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ws_dev - ,(ss_item_rev+cs_item_rev+ws_item_rev)/3 average - from ss_items,cs_items,ws_items - where ss_items.item_id=cs_items.item_id - and ss_items.item_id=ws_items.item_id - and ss_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - and ss_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and cs_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and cs_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and ws_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and ws_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - order by item_id - ,ss_item_rev - limit 100; - --- end template query58.tpl query 48 in stream 8 --- start template query6.tpl query 49 in stream 8 -select /* TPC-DS query6.tpl 0.58 */ a.ca_state state, count(*) cnt - from customer_address a - ,customer c - ,store_sales s - ,date_dim d - ,item i - where a.ca_address_sk = c.c_current_addr_sk - and c.c_customer_sk = s.ss_customer_sk - and s.ss_sold_date_sk = d.d_date_sk - and s.ss_item_sk = i.i_item_sk - and d.d_month_seq = - (select distinct (d_month_seq) - from date_dim - where d_year = 1999 - and d_moy = 2 ) - and i.i_current_price > 1.2 * - (select avg(j.i_current_price) - from item j - where j.i_category = i.i_category) - group by a.ca_state - having count(*) >= 10 - order by cnt, a.ca_state - limit 100; - --- end template query6.tpl query 49 in stream 8 --- start template query47.tpl query 50 in stream 8 -with /* TPC-DS query47.tpl 0.42 */ v1 as( - select i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, - s_store_name, s_company_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - s_store_name, s_company_name - order by d_year, d_moy) rn - from item, store_sales, date_dim, store - where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - ( - d_year = 1999 or - ( d_year = 1999-1 and d_moy =12) or - ( d_year = 1999+1 and d_moy =1) - ) - group by i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy), - v2 as( - select v1.s_store_name, v1.s_company_name - ,v1.d_year, v1.d_moy - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1.s_store_name = v1_lag.s_store_name and - v1.s_store_name = v1_lead.s_store_name and - v1.s_company_name = v1_lag.s_company_name and - v1.s_company_name = v1_lead.s_company_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 1999 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, avg_monthly_sales - limit 100; - --- end template query47.tpl query 50 in stream 8 --- start template query30.tpl query 51 in stream 8 -with /* TPC-DS query30.tpl 0.75 */ customer_total_return as - (select wr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(wr_return_amt) as ctr_total_return - from web_returns - ,date_dim - ,customer_address - where wr_returned_date_sk = d_date_sk - and d_year =2001 - and wr_returning_addr_sk = ca_address_sk - group by wr_returning_customer_sk - ,ca_state) - select c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'LA' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return -limit 100; - --- end template query30.tpl query 51 in stream 8 --- start template query94.tpl query 52 in stream 8 -select /* TPC-DS query94.tpl 0.17 */ - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '1999-2-01' and - dateadd(day,60,cast('1999-2-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'TX' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and exists (select * - from web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) -and not exists(select * - from web_returns wr1 - where ws1.ws_order_number = wr1.wr_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query94.tpl query 52 in stream 8 --- start template query97.tpl query 53 in stream 8 -with /* TPC-DS query97.tpl 0.38 */ ssci as ( -select ss_customer_sk customer_sk - ,ss_item_sk item_sk -from store_sales,date_dim -where ss_sold_date_sk = d_date_sk - and d_month_seq between 1202 and 1202 + 11 -group by ss_customer_sk - ,ss_item_sk), -csci as( - select cs_bill_customer_sk customer_sk - ,cs_item_sk item_sk -from catalog_sales,date_dim -where cs_sold_date_sk = d_date_sk - and d_month_seq between 1202 and 1202 + 11 -group by cs_bill_customer_sk - ,cs_item_sk) - select sum(case when ssci.customer_sk is not null and csci.customer_sk is null then 1 else 0 end) store_only - ,sum(case when ssci.customer_sk is null and csci.customer_sk is not null then 1 else 0 end) catalog_only - ,sum(case when ssci.customer_sk is not null and csci.customer_sk is not null then 1 else 0 end) store_and_catalog -from ssci full outer join csci on (ssci.customer_sk=csci.customer_sk - and ssci.item_sk = csci.item_sk) -limit 100; - --- end template query97.tpl query 53 in stream 8 --- start template query55.tpl query 54 in stream 8 -select /* TPC-DS query55.tpl 0.82 */ i_brand_id brand_id, i_brand brand, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=66 - and d_moy=12 - and d_year=1999 - group by i_brand, i_brand_id - order by ext_price desc, i_brand_id -limit 100 ; - --- end template query55.tpl query 54 in stream 8 --- start template query72.tpl query 55 in stream 8 -select /* TPC-DS query72.tpl 0.87 */ i_item_desc - ,w_warehouse_name - ,d1.d_week_seq - ,sum(case when p_promo_sk is null then 1 else 0 end) no_promo - ,sum(case when p_promo_sk is not null then 1 else 0 end) promo - ,count(*) total_cnt -from catalog_sales -join inventory on (cs_item_sk = inv_item_sk) -join warehouse on (w_warehouse_sk=inv_warehouse_sk) -join item on (i_item_sk = cs_item_sk) -join customer_demographics on (cs_bill_cdemo_sk = cd_demo_sk) -join household_demographics on (cs_bill_hdemo_sk = hd_demo_sk) -join date_dim d1 on (cs_sold_date_sk = d1.d_date_sk) -join date_dim d2 on (inv_date_sk = d2.d_date_sk) -join date_dim d3 on (cs_ship_date_sk = d3.d_date_sk) -left outer join promotion on (cs_promo_sk=p_promo_sk) -left outer join catalog_returns on (cr_item_sk = cs_item_sk and cr_order_number = cs_order_number) -where d1.d_week_seq = d2.d_week_seq - and inv_quantity_on_hand < cs_quantity - and d3.d_date > d1.d_date + 5 - and hd_buy_potential = '1001-5000' - and d1.d_year = 2001 - and cd_marital_status = 'W' -group by i_item_desc,w_warehouse_name,d1.d_week_seq -order by total_cnt desc, i_item_desc, w_warehouse_name, d_week_seq -limit 100; - --- end template query72.tpl query 55 in stream 8 --- start template query95.tpl query 56 in stream 8 -with /* TPC-DS query95.tpl 0.43 */ ws_wh as -(select ws1.ws_order_number,ws1.ws_warehouse_sk wh1,ws2.ws_warehouse_sk wh2 - from web_sales ws1,web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) - select - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2001-5-01' and - dateadd(day,60,cast('2001-5-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'OH' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and ws1.ws_order_number in (select ws_order_number - from ws_wh) -and ws1.ws_order_number in (select wr_order_number - from web_returns,ws_wh - where wr_order_number = ws_wh.ws_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query95.tpl query 56 in stream 8 --- start template query86a.tpl query 57 in stream 8 -with /* TPC-DS query86a.tpl 0.11 */ results as -( select sum(ws_net_paid) as total_sum, i_category, i_class, 0 as g_category, 0 as g_class - from - web_sales - ,date_dim d1 - ,item - where - d1.d_month_seq between 1180 and 1180+11 - and d1.d_date_sk = ws_sold_date_sk - and i_item_sk = ws_item_sk - group by i_category,i_class - ) , - - results_rollup as -( select total_sum ,i_category ,i_class, g_category, g_class, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum, i_category, NULL as i_class, 0 as g_category, 1 as g_class, 1 as lochierarchy from results group by i_category - union - select sum(total_sum) as total_sum, NULL as i_category, NULL as i_class, 1 as g_category, 1 as g_class, 2 as lochierarchy from results) - select - total_sum ,i_category ,i_class, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_class = 0 then i_category end - order by total_sum desc) as rank_within_parent - from - results_rollup - order by - lochierarchy desc, - case when lochierarchy = 0 then i_category end, - rank_within_parent - limit 100; - --- end template query86a.tpl query 57 in stream 8 --- start template query39.tpl query 58 in stream 8 -with /* TPC-DS query39.tpl 0.5 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =2002 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=4 - and inv2.d_moy=4+1 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; -with /* TPC-DS query39.tpl 0.5 part2 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =2002 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=4 - and inv2.d_moy=4+1 - and inv1.cov > 1.5 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; - --- end template query39.tpl query 58 in stream 8 --- start template query17.tpl query 59 in stream 8 -select /* TPC-DS query17.tpl 0.41 */ i_item_id - ,i_item_desc - ,s_state - ,count(ss_quantity) as store_sales_quantitycount - ,avg(ss_quantity) as store_sales_quantityave - ,stddev_samp(ss_quantity) as store_sales_quantitystdev - ,stddev_samp(ss_quantity)/avg(ss_quantity) as store_sales_quantitycov - ,count(sr_return_quantity) as store_returns_quantitycount - ,avg(sr_return_quantity) as store_returns_quantityave - ,stddev_samp(sr_return_quantity) as store_returns_quantitystdev - ,stddev_samp(sr_return_quantity)/avg(sr_return_quantity) as store_returns_quantitycov - ,count(cs_quantity) as catalog_sales_quantitycount ,avg(cs_quantity) as catalog_sales_quantityave - ,stddev_samp(cs_quantity) as catalog_sales_quantitystdev - ,stddev_samp(cs_quantity)/avg(cs_quantity) as catalog_sales_quantitycov - from store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where d1.d_quarter_name = '1999Q1' - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_quarter_name in ('1999Q1','1999Q2','1999Q3') - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_quarter_name in ('1999Q1','1999Q2','1999Q3') - group by i_item_id - ,i_item_desc - ,s_state - order by i_item_id - ,i_item_desc - ,s_state -limit 100; - --- end template query17.tpl query 59 in stream 8 --- start template query42.tpl query 60 in stream 8 -select /* TPC-DS query42.tpl 0.61 */ dt.d_year - ,item.i_category_id - ,item.i_category - ,sum(ss_ext_sales_price) - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=12 - and dt.d_year=2002 - group by dt.d_year - ,item.i_category_id - ,item.i_category - order by sum(ss_ext_sales_price) desc,dt.d_year - ,item.i_category_id - ,item.i_category -limit 100 ; - --- end template query42.tpl query 60 in stream 8 --- start template query85.tpl query 61 in stream 8 -select /* TPC-DS query85.tpl 0.33 */ substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) - from web_sales, web_returns, web_page, customer_demographics cd1, - customer_demographics cd2, customer_address, date_dim, reason - where ws_web_page_sk = wp_web_page_sk - and ws_item_sk = wr_item_sk - and ws_order_number = wr_order_number - and ws_sold_date_sk = d_date_sk and d_year = 2000 - and cd1.cd_demo_sk = wr_refunded_cdemo_sk - and cd2.cd_demo_sk = wr_returning_cdemo_sk - and ca_address_sk = wr_refunded_addr_sk - and r_reason_sk = wr_reason_sk - and - ( - ( - cd1.cd_marital_status = 'M' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Secondary' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 100.00 and 150.00 - ) - or - ( - cd1.cd_marital_status = 'S' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = '4 yr Degree' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 50.00 and 100.00 - ) - or - ( - cd1.cd_marital_status = 'U' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Unknown' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ca_country = 'United States' - and - ca_state in ('AL', 'OH', 'MO') - and ws_net_profit between 100 and 200 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('VA', 'FL', 'IA') - and ws_net_profit between 150 and 300 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('WA', 'PA', 'WI') - and ws_net_profit between 50 and 250 - ) - ) -group by r_reason_desc -order by substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) -limit 100; - --- end template query85.tpl query 61 in stream 8 --- start template query9.tpl query 62 in stream 8 -select /* TPC-DS query9.tpl 0.49 */ case when (select count(*) - from store_sales - where ss_quantity between 1 and 20) > 2143141710 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 1 and 20) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 1 and 20) end bucket1 , - case when (select count(*) - from store_sales - where ss_quantity between 21 and 40) > 2081061254 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 21 and 40) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 21 and 40) end bucket2, - case when (select count(*) - from store_sales - where ss_quantity between 41 and 60) > 1249493601 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 41 and 60) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 41 and 60) end bucket3, - case when (select count(*) - from store_sales - where ss_quantity between 61 and 80) > 1415848901 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 61 and 80) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 61 and 80) end bucket4, - case when (select count(*) - from store_sales - where ss_quantity between 81 and 100) > 2244990348 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 81 and 100) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 81 and 100) end bucket5 -from reason -where r_reason_sk = 1 -; - --- end template query9.tpl query 62 in stream 8 --- start template query32.tpl query 63 in stream 8 -select /* TPC-DS query32.tpl 0.7 */ sum(cs_ext_discount_amt) as "excess discount amount" -from - catalog_sales - ,item - ,date_dim -where -i_manufact_id = 818 -and i_item_sk = cs_item_sk -and d_date between '1998-02-17' and - dateadd(day,90,cast('1998-02-17' as date)) -and d_date_sk = cs_sold_date_sk -and cs_ext_discount_amt - > ( - select - 1.3 * avg(cs_ext_discount_amt) - from - catalog_sales - ,date_dim - where - cs_item_sk = i_item_sk - and d_date between '1998-02-17' and - dateadd(day,90,cast('1998-02-17' as date)) - and d_date_sk = cs_sold_date_sk - ) -limit 100; - --- end template query32.tpl query 63 in stream 8 --- start template query34.tpl query 64 in stream 8 -select /* TPC-DS query34.tpl 0.73 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (date_dim.d_dom between 1 and 3 or date_dim.d_dom between 25 and 28) - and (household_demographics.hd_buy_potential = '1001-5000' or - household_demographics.hd_buy_potential = '0-500') - and household_demographics.hd_vehicle_count > 0 - and (case when household_demographics.hd_vehicle_count > 0 - then household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count - else null - end) > 1.2 - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_county in ('Houston County','Wilkinson County','Montgomery County','Pacific County', - 'Monroe County','Jackson County','Quay County','Marshall County') - group by ss_ticket_number,ss_customer_sk) dn,customer - where ss_customer_sk = c_customer_sk - and cnt between 15 and 20 - order by c_last_name,c_first_name,c_salutation,c_preferred_cust_flag desc, ss_ticket_number; - --- end template query34.tpl query 64 in stream 8 --- start template query79.tpl query 65 in stream 8 -select /* TPC-DS query79.tpl 0.89 */ - c_last_name,c_first_name,substring(s_city,1,30),ss_ticket_number,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,store.s_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (household_demographics.hd_dep_count = 9 or household_demographics.hd_vehicle_count > 4) - and date_dim.d_dow = 1 - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_number_employees between 200 and 295 - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,store.s_city) ms,customer - where ss_customer_sk = c_customer_sk - order by c_last_name,c_first_name,substring(s_city,1,30), profit -limit 100; - --- end template query79.tpl query 65 in stream 8 --- start template query54.tpl query 66 in stream 8 -with /* TPC-DS query54.tpl 0.81 */ my_customers as ( - select distinct c_customer_sk - , c_current_addr_sk - from - ( select cs_sold_date_sk sold_date_sk, - cs_bill_customer_sk customer_sk, - cs_item_sk item_sk - from catalog_sales - union all - select ws_sold_date_sk sold_date_sk, - ws_bill_customer_sk customer_sk, - ws_item_sk item_sk - from web_sales - ) cs_or_ws_sales, - item, - date_dim, - customer - where sold_date_sk = d_date_sk - and item_sk = i_item_sk - and i_category = 'Jewelry' - and i_class = 'estate' - and c_customer_sk = cs_or_ws_sales.customer_sk - and d_moy = 4 - and d_year = 1998 - ) - , my_revenue as ( - select c_customer_sk, - sum(ss_ext_sales_price) as revenue - from my_customers, - store_sales, - customer_address, - store, - date_dim - where c_current_addr_sk = ca_address_sk - and ca_county = s_county - and ca_state = s_state - and ss_sold_date_sk = d_date_sk - and c_customer_sk = ss_customer_sk - and d_month_seq between (select distinct d_month_seq+1 - from date_dim where d_year = 1998 and d_moy = 4) - and (select distinct d_month_seq+3 - from date_dim where d_year = 1998 and d_moy = 4) - group by c_customer_sk - ) - , segments as - (select cast((revenue/50) as bigint) as segment - from my_revenue - ) - select segment, count(*) as num_customers, segment*50 as segment_base - from segments - group by segment - order by segment, num_customers - limit 100; - --- end template query54.tpl query 66 in stream 8 --- start template query77a.tpl query 67 in stream 8 -with /* TPC-DS query77a.tpl 0.78 */ ss as - (select s_store_sk, - sum(ss_ext_sales_price) as sales, - sum(ss_net_profit) as profit - from store_sales, - date_dim, - store - where ss_sold_date_sk = d_date_sk - and d_date between cast('2002-08-27' as date) - and dateadd(day,30,cast('2002-08-27' as date)) - and ss_store_sk = s_store_sk - group by s_store_sk) - , - sr as - (select s_store_sk, - sum(sr_return_amt) as returns, - sum(sr_net_loss) as profit_loss - from store_returns, - date_dim, - store - where sr_returned_date_sk = d_date_sk - and d_date between cast('2002-08-27' as date) - and dateadd(day,30,cast('2002-08-27' as date)) - and sr_store_sk = s_store_sk - group by s_store_sk), - cs as - (select cs_call_center_sk, - sum(cs_ext_sales_price) as sales, - sum(cs_net_profit) as profit - from catalog_sales, - date_dim - where cs_sold_date_sk = d_date_sk - and d_date between cast('2002-08-27' as date) - and dateadd(day,30,cast('2002-08-27' as date)) - group by cs_call_center_sk - ), - cr as - (select cr_call_center_sk, - sum(cr_return_amount) as returns, - sum(cr_net_loss) as profit_loss - from catalog_returns, - date_dim - where cr_returned_date_sk = d_date_sk - and d_date between cast('2002-08-27' as date) - and dateadd(day,30,cast('2002-08-27' as date)) - group by cr_call_center_sk), - ws as - ( select wp_web_page_sk, - sum(ws_ext_sales_price) as sales, - sum(ws_net_profit) as profit - from web_sales, - date_dim, - web_page - where ws_sold_date_sk = d_date_sk - and d_date between cast('2002-08-27' as date) - and dateadd(day,30,cast('2002-08-27' as date)) - and ws_web_page_sk = wp_web_page_sk - group by wp_web_page_sk), - wr as - (select wp_web_page_sk, - sum(wr_return_amt) as returns, - sum(wr_net_loss) as profit_loss - from web_returns, - date_dim, - web_page - where wr_returned_date_sk = d_date_sk - and d_date between cast('2002-08-27' as date) - and dateadd(day,30,cast('2002-08-27' as date)) - and wr_web_page_sk = wp_web_page_sk - group by wp_web_page_sk) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , ss.s_store_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ss left join sr - on ss.s_store_sk = sr.s_store_sk - union all - select 'catalog channel' as channel - , cs_call_center_sk as id - , sales - , returns - , (profit - profit_loss) as profit - from cs - , cr - union all - select 'web channel' as channel - , ws.wp_web_page_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ws left join wr - on ws.wp_web_page_sk = wr.wp_web_page_sk - ) x - group by channel, id ) - - select * - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results -) foo -order by channel, id - limit 100; - --- end template query77a.tpl query 67 in stream 8 --- start template query45.tpl query 68 in stream 8 -select /* TPC-DS query45.tpl 0.18 */ ca_zip, ca_state, sum(ws_sales_price) - from web_sales, customer, customer_address, date_dim, item - where ws_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ws_item_sk = i_item_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', '85392', '85460', '80348', '81792') - or - i_item_id in (select i_item_id - from item - where i_item_sk in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29) - ) - ) - and ws_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 2001 - group by ca_zip, ca_state - order by ca_zip, ca_state - limit 100; - --- end template query45.tpl query 68 in stream 8 --- start template query28.tpl query 69 in stream 8 -select /* TPC-DS query28.tpl 0.36 */ * -from (select avg(ss_list_price) B1_LP - ,count(ss_list_price) B1_CNT - ,count(distinct ss_list_price) B1_CNTD - from store_sales - where ss_quantity between 0 and 5 - and (ss_list_price between 24 and 24+10 - or ss_coupon_amt between 6948 and 6948+1000 - or ss_wholesale_cost between 77 and 77+20)) B1, - (select avg(ss_list_price) B2_LP - ,count(ss_list_price) B2_CNT - ,count(distinct ss_list_price) B2_CNTD - from store_sales - where ss_quantity between 6 and 10 - and (ss_list_price between 120 and 120+10 - or ss_coupon_amt between 13516 and 13516+1000 - or ss_wholesale_cost between 19 and 19+20)) B2, - (select avg(ss_list_price) B3_LP - ,count(ss_list_price) B3_CNT - ,count(distinct ss_list_price) B3_CNTD - from store_sales - where ss_quantity between 11 and 15 - and (ss_list_price between 37 and 37+10 - or ss_coupon_amt between 4899 and 4899+1000 - or ss_wholesale_cost between 47 and 47+20)) B3, - (select avg(ss_list_price) B4_LP - ,count(ss_list_price) B4_CNT - ,count(distinct ss_list_price) B4_CNTD - from store_sales - where ss_quantity between 16 and 20 - and (ss_list_price between 25 and 25+10 - or ss_coupon_amt between 593 and 593+1000 - or ss_wholesale_cost between 29 and 29+20)) B4, - (select avg(ss_list_price) B5_LP - ,count(ss_list_price) B5_CNT - ,count(distinct ss_list_price) B5_CNTD - from store_sales - where ss_quantity between 21 and 25 - and (ss_list_price between 62 and 62+10 - or ss_coupon_amt between 17850 and 17850+1000 - or ss_wholesale_cost between 56 and 56+20)) B5, - (select avg(ss_list_price) B6_LP - ,count(ss_list_price) B6_CNT - ,count(distinct ss_list_price) B6_CNTD - from store_sales - where ss_quantity between 26 and 30 - and (ss_list_price between 109 and 109+10 - or ss_coupon_amt between 1979 and 1979+1000 - or ss_wholesale_cost between 0 and 0+20)) B6 -limit 100; - --- end template query28.tpl query 69 in stream 8 --- start template query11.tpl query 70 in stream 8 -with /* TPC-DS query11.tpl 0.51 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ss_ext_list_price-ss_ext_discount_amt) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ws_ext_list_price-ws_ext_discount_amt) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_email_address - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 1998 - and t_s_secyear.dyear = 1998+1 - and t_w_firstyear.dyear = 1998 - and t_w_secyear.dyear = 1998+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else 0.0 end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else 0.0 end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_email_address -limit 100; - --- end template query11.tpl query 70 in stream 8 --- start template query89.tpl query 71 in stream 8 -select /* TPC-DS query89.tpl 0.56 */ * -from( -select i_category, i_class, i_brand, - s_store_name, s_company_name, - d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, s_store_name, s_company_name) - avg_monthly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - d_year in (1998) and - ((i_category in ('Books','Electronics','Home') and - i_class in ('reference','automotive','bedding') - ) - or (i_category in ('Music','Women','Men') and - i_class in ('country','maternity','pants') - )) -group by i_category, i_class, i_brand, - s_store_name, s_company_name, d_moy) tmp1 -where case when (avg_monthly_sales <> 0) then (abs(sum_sales - avg_monthly_sales) / avg_monthly_sales) else null end > 0.1 -order by sum_sales - avg_monthly_sales, s_store_name -limit 100; - --- end template query89.tpl query 71 in stream 8 --- start template query56.tpl query 72 in stream 8 -with /* TPC-DS query56.tpl 0.83 */ ss as ( - select i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where i_item_id in (select - i_item_id -from item -where i_color in ('floral','sienna','azure')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 7 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -7 - group by i_item_id), - cs as ( - select i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('floral','sienna','azure')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 7 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -7 - group by i_item_id), - ws as ( - select i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('floral','sienna','azure')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 7 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -7 - group by i_item_id) - select i_item_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by total_sales, - i_item_id - limit 100; - --- end template query56.tpl query 72 in stream 8 --- start template query46.tpl query 73 in stream 8 -select /* TPC-DS query46.tpl 0.23 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and (household_demographics.hd_dep_count = 3 or - household_demographics.hd_vehicle_count= 4) - and date_dim.d_dow in (6,0) - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_city in ('Buffalo','Smyrna','Simpson','Three Forks','Diamond') - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,ca_city) dn,customer,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - limit 100; - --- end template query46.tpl query 73 in stream 8 --- start template query19.tpl query 74 in stream 8 -select /* TPC-DS query19.tpl 0.8 */ i_brand_id brand_id, i_brand brand, i_manufact_id, i_manufact, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item,customer,customer_address,store - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=89 - and d_moy=12 - and d_year=2000 - and ss_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and substring(ca_zip,1,5) <> substring(s_zip,1,5) - and ss_store_sk = s_store_sk - group by i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact - order by ext_price desc - ,i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact -limit 100 ; - --- end template query19.tpl query 74 in stream 8 --- start template query62.tpl query 75 in stream 8 -select /* TPC-DS query62.tpl 0.24 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 30) and - (ws_ship_date_sk - ws_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 60) and - (ws_ship_date_sk - ws_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 90) and - (ws_ship_date_sk - ws_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - web_sales - ,warehouse - ,ship_mode - ,web_site - ,date_dim -where - d_month_seq between 1209 and 1209 + 11 -and ws_ship_date_sk = d_date_sk -and ws_warehouse_sk = w_warehouse_sk -and ws_ship_mode_sk = sm_ship_mode_sk -and ws_web_site_sk = web_site_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -limit 100; - --- end template query62.tpl query 75 in stream 8 --- start template query8.tpl query 76 in stream 8 -select /* TPC-DS query8.tpl 0.63 */ s_store_name - ,sum(ss_net_profit) - from store_sales - ,date_dim - ,store, - (select ca_zip - from ( - SELECT substring(ca_zip,1,5) ca_zip - FROM customer_address - WHERE substring(ca_zip,1,5) IN ( - '10384','19472','40133','20556','13959','81439', - '53057','63016','75034','58025','86060', - '82290','85524','81781','67029','36420', - '49586','18363','37453','13000','89918', - '42357','16191','76566','45498','98462', - '59728','49009','39399','46761','62246', - '46593','97207','92026','74927','59146', - '80922','78544','65909','74579','55886', - '95991','87264','64747','93083','81186', - '97731','94962','84261','89903','33767', - '58929','68325','60211','87874','37486', - '37803','34925','14226','74378','79092', - '61267','25115','18302','52500','60913', - '46831','45961','76317','41750','76220', - '65475','28576','53414','96052','54661', - '23820','68934','63646','19590','49232', - '90390','52750','36739','21489','56291', - '16272','96163','68398','93420','83175', - '98895','68345','79967','24361','75758', - '80399','19470','17768','47108','67537', - '66281','99515','64908','25288','74194', - '69252','40930','92658','14886','99938', - '20416','56958','66859','31812','88363', - '38561','56999','62661','30843','84081', - '53017','24407','49944','87368','36431', - '31068','91844','80114','75662','21191', - '12350','23736','66399','17891','47036', - '72601','56807','85187','20512','82620', - '77951','92167','79078','73353','15303', - '66760','11770','12949','12886','96699', - '80462','52710','38371','80191','95958', - '58522','10415','27981','99865','84806', - '47035','24225','70102','99500','76577', - '80730','73877','82318','39505','75683', - '82454','44908','60712','14424','80705', - '98939','31976','12779','71541','86693', - '35042','66686','50680','32559','88726', - '65578','59179','25573','85163','55029', - '56926','10129','48193','34731','54453', - '15718','80751','25962','54407','53382', - '77024','79419','96266','45808','15709', - '24832','82659','66216','50027','70959', - '16163','77438','94247','79201','80941', - '53369','36729','26487','22466','87868', - '69362','37995','30540','47408','47786', - '57363','25703','68608','63140','94145', - '98992','54306','55103','62315','52869', - '69987','25524','75468','68682','87377', - '52752','48392','18254','61614','29301', - '29236','76423','97294','71074','55655', - '58129','64606','12196','74331','76971', - '68454','84365','42637','68946','69862', - '30281','28852','30757','66536','96320', - '42355','41590','60125','13742','10762', - '85194','50292','21620','84429','87169', - '87952','10615','22791','99054','47857', - '44187','88048','92785','52730','39979', - '37527','72483','83780','74379','98622', - '31561','30625','52528','15006','21846', - '54537','20273','64611','34188','88477', - '86364','62732','16079','57048','80359', - '58099','38110','47980','60405','70836', - '47909','34836','57234','80721','23091', - '68427','84390','59234','62694','33097', - '24899','23588','59293','20897','82307', - '97672','68192','72957','26191','30288', - '59608','18259','64679','23746','38351', - '66579','33160','43037','80578','29862', - '15241','18296','23389','70827','85351', - '89071','74685','64318','16821','57912', - '82972','35228','37841','96662','89332', - '61853','30868','72368','14287','43871', - '29141','41899','48997','58297','99092', - '25576','13033','24055','18870','44688', - '50044','88589','22689','67643','48726', - '26557','60419','42002','88074','74567', - '69120','97756','68979','74131','84506', - '94576','49089','26224','83310','83193', - '62796','34904','57719','50330','59341', - '57965','21743','23068','38980') - intersect - select ca_zip - from (SELECT substring(ca_zip,1,5) ca_zip,count(*) cnt - FROM customer_address, customer - WHERE ca_address_sk = c_current_addr_sk and - c_preferred_cust_flag='Y' - group by ca_zip - having count(*) > 10)A1)A2) V1 - where ss_store_sk = s_store_sk - and ss_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 2001 - and (substring(s_zip,1,2) = substring(V1.ca_zip,1,2)) - group by s_store_name - order by s_store_name - limit 100; - --- end template query8.tpl query 76 in stream 8 --- start template query96.tpl query 77 in stream 8 -select /* TPC-DS query96.tpl 0.1 */ count(*) -from store_sales - ,household_demographics - ,time_dim, store -where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and household_demographics.hd_dep_count = 0 - and store.s_store_name = 'ese' -order by count(*) -limit 100; - --- end template query96.tpl query 77 in stream 8 --- start template query1.tpl query 78 in stream 8 -with /* TPC-DS query1.tpl 0.12 */ customer_total_return as -(select sr_customer_sk as ctr_customer_sk -,sr_store_sk as ctr_store_sk -,sum(SR_RETURN_AMT) as ctr_total_return -from store_returns -,date_dim -where sr_returned_date_sk = d_date_sk -and d_year =2000 -group by sr_customer_sk -,sr_store_sk) - select c_customer_id -from customer_total_return ctr1 -,store -,customer -where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 -from customer_total_return ctr2 -where ctr1.ctr_store_sk = ctr2.ctr_store_sk) -and s_store_sk = ctr1.ctr_store_sk -and s_state = 'GA' -and ctr1.ctr_customer_sk = c_customer_sk -order by c_customer_id -limit 100; - --- end template query1.tpl query 78 in stream 8 --- start template query23.tpl query 79 in stream 8 -with /* TPC-DS query23.tpl 0.68 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (2000,2000+1,2000+2,2000+3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (2000,2000+1,2000+2,2000+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * -from - max_store_sales)) - select sum(sales) - from (select cs_quantity*cs_list_price sales - from catalog_sales - ,date_dim - where d_year = 2000 - and d_moy = 7 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - union all - select ws_quantity*ws_list_price sales - from web_sales - ,date_dim - where d_year = 2000 - and d_moy = 7 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer)) - limit 100; -with /* TPC-DS query23.tpl 0.68 part2 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (2000,2000 + 1,2000 + 2,2000 + 3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (2000,2000+1,2000+2,2000+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * - from max_store_sales)) - select c_last_name,c_first_name,sales - from (select c_last_name,c_first_name,sum(cs_quantity*cs_list_price) sales - from catalog_sales - ,customer - ,date_dim - where d_year = 2000 - and d_moy = 7 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and cs_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name - union all - select c_last_name,c_first_name,sum(ws_quantity*ws_list_price) sales - from web_sales - ,customer - ,date_dim - where d_year = 2000 - and d_moy = 7 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and ws_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name) - order by c_last_name,c_first_name,sales - limit 100; - --- end template query23.tpl query 79 in stream 8 --- start template query88.tpl query 80 in stream 8 -select /* TPC-DS query88.tpl 0.66 */ * -from - (select count(*) h8_30_to_9 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s1, - (select count(*) h9_to_9_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s2, - (select count(*) h9_30_to_10 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s3, - (select count(*) h10_to_10_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s4, - (select count(*) h10_30_to_11 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s5, - (select count(*) h11_to_11_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s6, - (select count(*) h11_30_to_12 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s7, - (select count(*) h12_to_12_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 12 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s8 -; - --- end template query88.tpl query 80 in stream 8 --- start template query82.tpl query 81 in stream 8 -select /* TPC-DS query82.tpl 0.67 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, store_sales - where i_current_price between 45 and 45+30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('2002-07-03' as date) and dateadd(day,60,cast('2002-07-03' as date)) - and i_manufact_id in (765,226,314,870) - and inv_quantity_on_hand between 100 and 500 - and ss_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query82.tpl query 81 in stream 8 --- start template query87.tpl query 82 in stream 8 -select /* TPC-DS query87.tpl 0.77 */ count(*) -from ((select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1212 and 1212+11) - except - (select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1212 and 1212+11) - except - (select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1212 and 1212+11) -) cool_cust -; - --- end template query87.tpl query 82 in stream 8 --- start template query43.tpl query 83 in stream 8 -select /* TPC-DS query43.tpl 0.15 */ s_store_name, s_store_id, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from date_dim, store_sales, store - where d_date_sk = ss_sold_date_sk and - s_store_sk = ss_store_sk and - s_gmt_offset = -5 and - d_year = 2000 - group by s_store_name, s_store_id - order by s_store_name, s_store_id,sun_sales,mon_sales,tue_sales,wed_sales,thu_sales,fri_sales,sat_sales - limit 100; - --- end template query43.tpl query 83 in stream 8 --- start template query53.tpl query 84 in stream 8 -select /* TPC-DS query53.tpl 0.88 */ * from -(select i_manufact_id, -sum(ss_sales_price) sum_sales, -avg(sum(ss_sales_price)) over (partition by i_manufact_id) avg_quarterly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and -ss_sold_date_sk = d_date_sk and -ss_store_sk = s_store_sk and -d_month_seq in (1223,1223+1,1223+2,1223+3,1223+4,1223+5,1223+6,1223+7,1223+8,1223+9,1223+10,1223+11) and -((i_category in ('Books','Children','Electronics') and -i_class in ('personal','portable','reference','self-help') and -i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) -or(i_category in ('Women','Music','Men') and -i_class in ('accessories','classical','fragrances','pants') and -i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manufact_id, d_qoy ) tmp1 -where case when avg_quarterly_sales > 0 - then abs (sum_sales - avg_quarterly_sales)/ avg_quarterly_sales - else null end > 0.1 -order by avg_quarterly_sales, - sum_sales, - i_manufact_id -limit 100; - --- end template query53.tpl query 84 in stream 8 --- start template query20.tpl query 85 in stream 8 -select /* TPC-DS query20.tpl 0.65 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(cs_ext_sales_price) as itemrevenue - ,sum(cs_ext_sales_price)*100/sum(sum(cs_ext_sales_price)) over - (partition by i_class) as revenueratio - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and i_category in ('Men', 'Home', 'Shoes') - and cs_sold_date_sk = d_date_sk - and d_date between cast('2002-05-24' as date) - and dateadd(day,30,cast('2002-05-24' as date)) - group by i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - order by i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query20.tpl query 85 in stream 8 --- start template query52.tpl query 86 in stream 8 -select /* TPC-DS query52.tpl 0.59 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_sales_price) ext_price - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=12 - and dt.d_year=1998 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,ext_price desc - ,brand_id -limit 100 ; - --- end template query52.tpl query 86 in stream 8 --- start template query83.tpl query 87 in stream 8 -with /* TPC-DS query83.tpl 0.96 */ sr_items as - (select i_item_id item_id, - sum(sr_return_quantity) sr_item_qty - from store_returns, - item, - date_dim - where sr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2001-03-29','2001-09-13','2001-11-17'))) - and sr_returned_date_sk = d_date_sk - group by i_item_id), - cr_items as - (select i_item_id item_id, - sum(cr_return_quantity) cr_item_qty - from catalog_returns, - item, - date_dim - where cr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2001-03-29','2001-09-13','2001-11-17'))) - and cr_returned_date_sk = d_date_sk - group by i_item_id), - wr_items as - (select i_item_id item_id, - sum(wr_return_quantity) wr_item_qty - from web_returns, - item, - date_dim - where wr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2001-03-29','2001-09-13','2001-11-17'))) - and wr_returned_date_sk = d_date_sk - group by i_item_id) - select sr_items.item_id - ,sr_item_qty - ,sr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 sr_dev - ,cr_item_qty - ,cr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 cr_dev - ,wr_item_qty - ,wr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 wr_dev - ,(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 average - from sr_items - ,cr_items - ,wr_items - where sr_items.item_id=cr_items.item_id - and sr_items.item_id=wr_items.item_id - order by sr_items.item_id - ,sr_item_qty - limit 100; - --- end template query83.tpl query 87 in stream 8 --- start template query38.tpl query 88 in stream 8 -select /* TPC-DS query38.tpl 0.54 */ count(*) from ( - select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1205 and 1205 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1205 and 1205 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1205 and 1205 + 11 -) hot_cust -limit 100; - --- end template query38.tpl query 88 in stream 8 --- start template query68.tpl query 89 in stream 8 -select /* TPC-DS query68.tpl 0.95 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,extended_price - ,extended_tax - ,list_price - from (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_ext_sales_price) extended_price - ,sum(ss_ext_list_price) list_price - ,sum(ss_ext_tax) extended_tax - from store_sales - ,date_dim - ,store - ,household_demographics - ,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_dep_count = 3 or - household_demographics.hd_vehicle_count= 4) - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_city in ('Johnson','Lakeside') - group by ss_ticket_number - ,ss_customer_sk - ,ss_addr_sk,ca_city) dn - ,customer - ,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,ss_ticket_number - limit 100; - --- end template query68.tpl query 89 in stream 8 --- start template query4.tpl query 90 in stream 8 -with /* TPC-DS query4.tpl 0.93 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(((ss_ext_list_price-ss_ext_wholesale_cost-ss_ext_discount_amt)+ss_ext_sales_price)/2) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((cs_ext_list_price-cs_ext_wholesale_cost-cs_ext_discount_amt)+cs_ext_sales_price)/2) ) year_total - ,'c' sale_type - from customer - ,catalog_sales - ,date_dim - where c_customer_sk = cs_bill_customer_sk - and cs_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year -union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((ws_ext_list_price-ws_ext_wholesale_cost-ws_ext_discount_amt)+ws_ext_sales_price)/2) ) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_preferred_cust_flag - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_c_firstyear - ,year_total t_c_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_c_secyear.customer_id - and t_s_firstyear.customer_id = t_c_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_c_firstyear.sale_type = 'c' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_c_secyear.sale_type = 'c' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 2001 - and t_s_secyear.dyear = 2001+1 - and t_c_firstyear.dyear = 2001 - and t_c_secyear.dyear = 2001+1 - and t_w_firstyear.dyear = 2001 - and t_w_secyear.dyear = 2001+1 - and t_s_firstyear.year_total > 0 - and t_c_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_preferred_cust_flag -limit 100; - --- end template query4.tpl query 90 in stream 8 --- start template query13.tpl query 91 in stream 8 -select /* TPC-DS query13.tpl 0.91 */ avg(ss_quantity) - ,avg(ss_ext_sales_price) - ,avg(ss_ext_wholesale_cost) - ,sum(ss_ext_wholesale_cost) - from store_sales - ,store - ,customer_demographics - ,household_demographics - ,customer_address - ,date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2001 - and((ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'S' - and cd_education_status = '4 yr Degree' - and ss_sales_price between 100.00 and 150.00 - and hd_dep_count = 3 - )or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'D' - and cd_education_status = 'Advanced Degree' - and ss_sales_price between 50.00 and 100.00 - and hd_dep_count = 1 - ) or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'W' - and cd_education_status = 'Primary' - and ss_sales_price between 150.00 and 200.00 - and hd_dep_count = 1 - )) - and((ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('AL', 'MO', 'TN') - and ss_net_profit between 100 and 200 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('MT', 'SC', 'PA') - and ss_net_profit between 150 and 300 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('WI', 'VA', 'MN') - and ss_net_profit between 50 and 250 - )) -; - --- end template query13.tpl query 91 in stream 8 --- start template query48.tpl query 92 in stream 8 -select /* TPC-DS query48.tpl 0.74 */ sum (ss_quantity) - from store_sales, store, customer_demographics, customer_address, date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 1999 - and - ( - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'U' - and - cd_education_status = 'Primary' - and - ss_sales_price between 100.00 and 150.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'M' - and - cd_education_status = 'Unknown' - and - ss_sales_price between 50.00 and 100.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'D' - and - cd_education_status = 'Secondary' - and - ss_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('TX', 'IN', 'IA') - and ss_net_profit between 0 and 2000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('GA', 'WI', 'SD') - and ss_net_profit between 150 and 3000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('AL', 'KS', 'UT') - and ss_net_profit between 50 and 25000 - ) - ) -; - --- end template query48.tpl query 92 in stream 8 --- start template query99.tpl query 93 in stream 8 -select /* TPC-DS query99.tpl 0.94 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 30) and - (cs_ship_date_sk - cs_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 60) and - (cs_ship_date_sk - cs_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 90) and - (cs_ship_date_sk - cs_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - catalog_sales - ,warehouse - ,ship_mode - ,call_center - ,date_dim -where - d_month_seq between 1181 and 1181 + 11 -and cs_ship_date_sk = d_date_sk -and cs_warehouse_sk = w_warehouse_sk -and cs_ship_mode_sk = sm_ship_mode_sk -and cs_call_center_sk = cc_call_center_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -limit 100; - --- end template query99.tpl query 93 in stream 8 --- start template query27a.tpl query 94 in stream 8 -with /* TPC-DS query27a.tpl 0.16 */ results as - (select i_item_id, - s_state, 0 as g_state, - ss_quantity agg1, - ss_list_price agg2, - ss_coupon_amt agg3, - ss_sales_price agg4 - from store_sales, customer_demographics, date_dim, store, item - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_store_sk = s_store_sk and - ss_cdemo_sk = cd_demo_sk and - cd_gender = 'F' and - cd_marital_status = 'D' and - cd_education_status = 'Secondary' and - d_year = 1999 and - s_state in ('TX','MN', 'TX', 'LA', 'NE', 'CA') - ) - - select i_item_id, - s_state, g_state, agg1, agg2, agg3, agg4 - from ( - select i_item_id, s_state, 0 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4 from results - group by i_item_id, s_state - union all - select i_item_id, NULL AS s_state, 1 AS g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as s_state, 1 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - ) foo - order by i_item_id, s_state - limit 100; - --- end template query27a.tpl query 94 in stream 8 --- start template query18a.tpl query 95 in stream 8 -with /* TPC-DS query18a.tpl 0.90 */ results as - (select i_item_id, - ca_country, - ca_state, - ca_county, - cast(cs_quantity as decimal(12,2)) agg1, - cast(cs_list_price as decimal(12,2)) agg2, - cast(cs_coupon_amt as decimal(12,2)) agg3, - cast(cs_sales_price as decimal(12,2)) agg4, - cast(cs_net_profit as decimal(12,2)) agg5, - cast(c_birth_year as decimal(12,2)) agg6, - cast(cd1.cd_dep_count as decimal(12,2)) agg7 - from catalog_sales, customer_demographics cd1, customer_demographics cd2, customer, customer_address, date_dim, item - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd1.cd_demo_sk and - cs_bill_customer_sk = c_customer_sk and - cd1.cd_gender = 'F' and - cd1.cd_education_status = 'Primary' and - c_current_cdemo_sk = cd2.cd_demo_sk and - c_current_addr_sk = ca_address_sk and - c_birth_month in (10,5,4,3,11,12) and - d_year = 2002 and - ca_state in ('MO','SD','MS','OR','NC','OH','IL') - ) - select i_item_id, ca_country, ca_state, ca_county, agg1, agg2, agg3, agg4, agg5, agg6, agg7 - from ( - select i_item_id, ca_country, ca_state, ca_county, avg(agg1) agg1, - avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state, ca_county - union all - select i_item_id, ca_country, ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state - union all - select i_item_id, ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country - union all - select i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - ) foo - order by ca_country, ca_state, ca_county, i_item_id - limit 100; - --- end template query18a.tpl query 95 in stream 8 --- start template query15.tpl query 96 in stream 8 -select /* TPC-DS query15.tpl 0.57 */ ca_zip - ,sum(cs_sales_price) - from catalog_sales - ,customer - ,customer_address - ,date_dim - where cs_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', - '85392', '85460', '80348', '81792') - or ca_state in ('CA','WA','GA') - or cs_sales_price > 500) - and cs_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 1998 - group by ca_zip - order by ca_zip - limit 100; - --- end template query15.tpl query 96 in stream 8 --- start template query33.tpl query 97 in stream 8 -with /* TPC-DS query33.tpl 0.22 */ ss as ( - select - i_manufact_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Books')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 1 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -7 - group by i_manufact_id), - cs as ( - select - i_manufact_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Books')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 1 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -7 - group by i_manufact_id), - ws as ( - select - i_manufact_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Books')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 1 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -7 - group by i_manufact_id) - select i_manufact_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_manufact_id - order by total_sales -limit 100; - --- end template query33.tpl query 97 in stream 8 --- start template query31.tpl query 98 in stream 8 -with /* TPC-DS query31.tpl 0.50 */ ss as - (select ca_county,d_qoy, d_year,sum(ss_ext_sales_price) as store_sales - from store_sales,date_dim,customer_address - where ss_sold_date_sk = d_date_sk - and ss_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year), - ws as - (select ca_county,d_qoy, d_year,sum(ws_ext_sales_price) as web_sales - from web_sales,date_dim,customer_address - where ws_sold_date_sk = d_date_sk - and ws_bill_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year) - select - ss1.ca_county - ,ss1.d_year - ,ws2.web_sales/ws1.web_sales web_q1_q2_increase - ,ss2.store_sales/ss1.store_sales store_q1_q2_increase - ,ws3.web_sales/ws2.web_sales web_q2_q3_increase - ,ss3.store_sales/ss2.store_sales store_q2_q3_increase - from - ss ss1 - ,ss ss2 - ,ss ss3 - ,ws ws1 - ,ws ws2 - ,ws ws3 - where - ss1.d_qoy = 1 - and ss1.d_year = 2000 - and ss1.ca_county = ss2.ca_county - and ss2.d_qoy = 2 - and ss2.d_year = 2000 - and ss2.ca_county = ss3.ca_county - and ss3.d_qoy = 3 - and ss3.d_year = 2000 - and ss1.ca_county = ws1.ca_county - and ws1.d_qoy = 1 - and ws1.d_year = 2000 - and ws1.ca_county = ws2.ca_county - and ws2.d_qoy = 2 - and ws2.d_year = 2000 - and ws1.ca_county = ws3.ca_county - and ws3.d_qoy = 3 - and ws3.d_year =2000 - and case when ws1.web_sales > 0 then ws2.web_sales/ws1.web_sales else null end - > case when ss1.store_sales > 0 then ss2.store_sales/ss1.store_sales else null end - and case when ws2.web_sales > 0 then ws3.web_sales/ws2.web_sales else null end - > case when ss2.store_sales > 0 then ss3.store_sales/ss2.store_sales else null end - order by web_q2_q3_increase; - --- end template query31.tpl query 98 in stream 8 --- start template query63.tpl query 99 in stream 8 -select /* TPC-DS query63.tpl 0.27 */ * -from (select i_manager_id - ,sum(ss_sales_price) sum_sales - ,avg(sum(ss_sales_price)) over (partition by i_manager_id) avg_monthly_sales - from item - ,store_sales - ,date_dim - ,store - where ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and d_month_seq in (1203,1203+1,1203+2,1203+3,1203+4,1203+5,1203+6,1203+7,1203+8,1203+9,1203+10,1203+11) - and (( i_category in ('Books','Children','Electronics') - and i_class in ('personal','portable','reference','self-help') - and i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) - or( i_category in ('Women','Music','Men') - and i_class in ('accessories','classical','fragrances','pants') - and i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manager_id, d_moy) tmp1 -where case when avg_monthly_sales > 0 then abs (sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 -order by i_manager_id - ,avg_monthly_sales - ,sum_sales -limit 100; - --- end template query63.tpl query 99 in stream 8 diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/100TB/queries/query_9.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/100TB/queries/query_9.sql deleted file mode 100644 index c0af03ff..00000000 --- a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/100TB/queries/query_9.sql +++ /dev/null @@ -1,5027 +0,0 @@ --- start template query15.tpl query 1 in stream 9 -select /* TPC-DS query15.tpl 0.57 */ ca_zip - ,sum(cs_sales_price) - from catalog_sales - ,customer - ,customer_address - ,date_dim - where cs_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', - '85392', '85460', '80348', '81792') - or ca_state in ('CA','WA','GA') - or cs_sales_price > 500) - and cs_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 2000 - group by ca_zip - order by ca_zip - limit 100; - --- end template query15.tpl query 1 in stream 9 --- start template query60.tpl query 2 in stream 9 -with /* TPC-DS query60.tpl 0.29 */ ss as ( - select - i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Men')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 10 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id), - cs as ( - select - i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Men')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 10 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id), - ws as ( - select - i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Men')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 10 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id) - select - i_item_id -,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by i_item_id - ,total_sales - limit 100; - --- end template query60.tpl query 2 in stream 9 --- start template query62.tpl query 3 in stream 9 -select /* TPC-DS query62.tpl 0.24 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 30) and - (ws_ship_date_sk - ws_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 60) and - (ws_ship_date_sk - ws_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 90) and - (ws_ship_date_sk - ws_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - web_sales - ,warehouse - ,ship_mode - ,web_site - ,date_dim -where - d_month_seq between 1217 and 1217 + 11 -and ws_ship_date_sk = d_date_sk -and ws_warehouse_sk = w_warehouse_sk -and ws_ship_mode_sk = sm_ship_mode_sk -and ws_web_site_sk = web_site_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -limit 100; - --- end template query62.tpl query 3 in stream 9 --- start template query74.tpl query 4 in stream 9 -with /* TPC-DS query74.tpl 0.76 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,avg(ss_net_paid) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (2000,2000+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,avg(ws_net_paid) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - and d_year in (2000,2000+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - ) - select - t_s_secyear.customer_id, t_s_secyear.customer_first_name, t_s_secyear.customer_last_name - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.year = 2000 - and t_s_secyear.year = 2000+1 - and t_w_firstyear.year = 2000 - and t_w_secyear.year = 2000+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - order by 2,3,1 -limit 100; - --- end template query74.tpl query 4 in stream 9 --- start template query81.tpl query 5 in stream 9 -with /* TPC-DS query81.tpl 0.37 */ customer_total_return as - (select cr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(cr_return_amt_inc_tax) as ctr_total_return - from catalog_returns - ,date_dim - ,customer_address - where cr_returned_date_sk = d_date_sk - and d_year =2002 - and cr_returning_addr_sk = ca_address_sk - group by cr_returning_customer_sk - ,ca_state ) - select c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'TX' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - limit 100; - --- end template query81.tpl query 5 in stream 9 --- start template query88.tpl query 6 in stream 9 -select /* TPC-DS query88.tpl 0.66 */ * -from - (select count(*) h8_30_to_9 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s1, - (select count(*) h9_to_9_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s2, - (select count(*) h9_30_to_10 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s3, - (select count(*) h10_to_10_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s4, - (select count(*) h10_30_to_11 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s5, - (select count(*) h11_to_11_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s6, - (select count(*) h11_30_to_12 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s7, - (select count(*) h12_to_12_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 12 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s8 -; - --- end template query88.tpl query 6 in stream 9 --- start template query50.tpl query 7 in stream 9 -select /* TPC-DS query50.tpl 0.60 */ - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 30) and - (sr_returned_date_sk - ss_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 60) and - (sr_returned_date_sk - ss_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 90) and - (sr_returned_date_sk - ss_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - store_sales - ,store_returns - ,store - ,date_dim d1 - ,date_dim d2 -where - d2.d_year = 2000 -and d2.d_moy = 9 -and ss_ticket_number = sr_ticket_number -and ss_item_sk = sr_item_sk -and ss_sold_date_sk = d1.d_date_sk -and sr_returned_date_sk = d2.d_date_sk -and ss_customer_sk = sr_customer_sk -and ss_store_sk = s_store_sk -group by - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -order by s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -limit 100; - --- end template query50.tpl query 7 in stream 9 --- start template query5a.tpl query 8 in stream 9 -with /* TPC-DS query5a.tpl 0.98 */ ssr as - (select s_store_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ss_store_sk as store_sk, - ss_sold_date_sk as date_sk, - ss_ext_sales_price as sales_price, - ss_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from store_sales - union all - select sr_store_sk as store_sk, - sr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - sr_return_amt as return_amt, - sr_net_loss as net_loss - from store_returns - ) salesreturns, - date_dim, - store - where date_sk = d_date_sk - and d_date between cast('2001-08-26' as date) - and dateadd(day,14,cast('2001-08-26' as date)) - and store_sk = s_store_sk - group by s_store_id) - , - csr as - (select cp_catalog_page_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select cs_catalog_page_sk as page_sk, - cs_sold_date_sk as date_sk, - cs_ext_sales_price as sales_price, - cs_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from catalog_sales - union all - select cr_catalog_page_sk as page_sk, - cr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - cr_return_amount as return_amt, - cr_net_loss as net_loss - from catalog_returns - ) salesreturns, - date_dim, - catalog_page - where date_sk = d_date_sk - and d_date between cast('2001-08-26' as date) - and dateadd(day,14,cast('2001-08-26' as date)) - and page_sk = cp_catalog_page_sk - group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ws_web_site_sk as wsr_web_site_sk, - ws_sold_date_sk as date_sk, - ws_ext_sales_price as sales_price, - ws_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from web_sales - union all - select ws_web_site_sk as wsr_web_site_sk, - wr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - wr_return_amt as return_amt, - wr_net_loss as net_loss - from web_returns left outer join web_sales on - ( wr_item_sk = ws_item_sk - and wr_order_number = ws_order_number) - ) salesreturns, - date_dim, - web_site - where date_sk = d_date_sk - and d_date between cast('2001-08-26' as date) - and dateadd(day,14,cast('2001-08-26' as date)) - and wsr_web_site_sk = web_site_sk - group by web_site_id) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || s_store_id as id - , sales - , returns - , (profit - profit_loss) as profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || cp_catalog_page_id as id - , sales - , returns - , (profit - profit_loss) as profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , (profit - profit_loss) as profit - from wsr - ) x - group by channel, id) - select channel, id, sales, returns, profit from ( - select channel, id, sales, returns, profit from results - union - select channel, null as id, sum(sales), sum(returns), sum(profit) from results group by channel - union - select null as channel, null as id, sum(sales), sum(returns), sum(profit) from results) foo -order by channel, id -limit 100; - --- end template query5a.tpl query 8 in stream 9 --- start template query84.tpl query 9 in stream 9 -select /* TPC-DS query84.tpl 0.80 */ c_customer_id as customer_id - , coalesce(c_last_name,'') || ', ' || coalesce(c_first_name,'') as customername - from customer - ,customer_address - ,customer_demographics - ,household_demographics - ,income_band - ,store_returns - where ca_city = 'Liberty' - and c_current_addr_sk = ca_address_sk - and ib_lower_bound >= 15765 - and ib_upper_bound <= 15765 + 50000 - and ib_income_band_sk = hd_income_band_sk - and cd_demo_sk = c_current_cdemo_sk - and hd_demo_sk = c_current_hdemo_sk - and sr_cdemo_sk = cd_demo_sk - order by c_customer_id - limit 100; - --- end template query84.tpl query 9 in stream 9 --- start template query1.tpl query 10 in stream 9 -with /* TPC-DS query1.tpl 0.12 */ customer_total_return as -(select sr_customer_sk as ctr_customer_sk -,sr_store_sk as ctr_store_sk -,sum(SR_RETURN_AMT_INC_TAX) as ctr_total_return -from store_returns -,date_dim -where sr_returned_date_sk = d_date_sk -and d_year =2001 -group by sr_customer_sk -,sr_store_sk) - select c_customer_id -from customer_total_return ctr1 -,store -,customer -where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 -from customer_total_return ctr2 -where ctr1.ctr_store_sk = ctr2.ctr_store_sk) -and s_store_sk = ctr1.ctr_store_sk -and s_state = 'ME' -and ctr1.ctr_customer_sk = c_customer_sk -order by c_customer_id -limit 100; - --- end template query1.tpl query 10 in stream 9 --- start template query52.tpl query 11 in stream 9 -select /* TPC-DS query52.tpl 0.59 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_sales_price) ext_price - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=12 - and dt.d_year=2000 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,ext_price desc - ,brand_id -limit 100 ; - --- end template query52.tpl query 11 in stream 9 --- start template query57.tpl query 12 in stream 9 -with /* TPC-DS query57.tpl 0.70 */ v1 as( - select i_category, i_brand, - cc_name, - d_year, d_moy, - sum(cs_sales_price) sum_sales, - avg(sum(cs_sales_price)) over - (partition by i_category, i_brand, - cc_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - cc_name - order by d_year, d_moy) rn - from item, catalog_sales, date_dim, call_center - where cs_item_sk = i_item_sk and - cs_sold_date_sk = d_date_sk and - cc_call_center_sk= cs_call_center_sk and - ( - d_year = 1999 or - ( d_year = 1999-1 and d_moy =12) or - ( d_year = 1999+1 and d_moy =1) - ) - group by i_category, i_brand, - cc_name , d_year, d_moy), - v2 as( - select v1.i_brand - ,v1.d_year - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1. cc_name = v1_lag. cc_name and - v1. cc_name = v1_lead. cc_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 1999 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, sum_sales - limit 100; - --- end template query57.tpl query 12 in stream 9 --- start template query13.tpl query 13 in stream 9 -select /* TPC-DS query13.tpl 0.91 */ avg(ss_quantity) - ,avg(ss_ext_sales_price) - ,avg(ss_ext_wholesale_cost) - ,sum(ss_ext_wholesale_cost) - from store_sales - ,store - ,customer_demographics - ,household_demographics - ,customer_address - ,date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2001 - and((ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'D' - and cd_education_status = 'Unknown' - and ss_sales_price between 100.00 and 150.00 - and hd_dep_count = 3 - )or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'U' - and cd_education_status = 'Secondary' - and ss_sales_price between 50.00 and 100.00 - and hd_dep_count = 1 - ) or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'M' - and cd_education_status = 'Advanced Degree' - and ss_sales_price between 150.00 and 200.00 - and hd_dep_count = 1 - )) - and((ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('WV', 'MD', 'IA') - and ss_net_profit between 100 and 200 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('NH', 'IN', 'AZ') - and ss_net_profit between 150 and 300 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('TX', 'GA', 'MN') - and ss_net_profit between 50 and 250 - )) -; - --- end template query13.tpl query 13 in stream 9 --- start template query14a.tpl query 14 in stream 9 -with /* TPC-DS query14a.tpl 0.69 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1999 AND 1999 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1999 AND 1999 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1999 AND 1999 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as - (select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2) x) -, - results AS -(select channel, i_brand_id, i_class_id, i_category_id, sum(sales) sum_sales, sum(number_sales) number_sales - from ( - select 'store' channel, i_brand_id,i_class_id - ,i_category_id,sum(ss_quantity*ss_list_price) sales - , count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1999+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales) - union all - select 'catalog' channel, i_brand_id,i_class_id,i_category_id, sum(cs_quantity*cs_list_price) sales, count(*) number_sales - from catalog_sales - ,item - ,date_dim - where cs_item_sk in (select ss_item_sk from cross_items) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1999+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(cs_quantity*cs_list_price) > (select average_sales from avg_sales) - union all - select 'web' channel, i_brand_id,i_class_id,i_category_id, sum(ws_quantity*ws_list_price) sales , count(*) number_sales - from web_sales - ,item - ,date_dim - where ws_item_sk in (select ss_item_sk from cross_items) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1999+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ws_quantity*ws_list_price) > (select average_sales from avg_sales) - ) y - group by channel, i_brand_id,i_class_id,i_category_id) - - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales -from ( - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales from results - union - select channel, i_brand_id, i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id, i_class_id - union - select channel, i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id - union - select channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel - union - select null as channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results) z -order by channel, i_brand_id, i_class_id, i_category_id - limit 100; -with /* TPC-DS query14a.tpl 0.69 part2 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1999 AND 1999 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1999 AND 1999 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1999 AND 1999 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as -(select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2) x) - select this_year.channel ty_channel - ,this_year.i_brand_id ty_brand - ,this_year.i_class_id ty_class - ,this_year.i_category_id ty_category - ,this_year.sales ty_sales - ,this_year.number_sales ty_number_sales - ,last_year.channel ly_channel - ,last_year.i_brand_id ly_brand - ,last_year.i_class_id ly_class - ,last_year.i_category_id ly_category - ,last_year.sales ly_sales - ,last_year.number_sales ly_number_sales -from - (select 'store' channel, i_brand_id,i_class_id,i_category_id - ,sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1999 + 1 - and d_moy = 12 - and d_dom = 8) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) this_year, - (select 'store' channel, i_brand_id,i_class_id - ,i_category_id, sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1999 - and d_moy = 12 - and d_dom = 8) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) last_year - where this_year.i_brand_id= last_year.i_brand_id - and this_year.i_class_id = last_year.i_class_id - and this_year.i_category_id = last_year.i_category_id - order by this_year.channel, this_year.i_brand_id, this_year.i_class_id, this_year.i_category_id - limit 100; - --- end template query14a.tpl query 14 in stream 9 --- start template query90.tpl query 15 in stream 9 -select /* TPC-DS query90.tpl 0.40 */ cast(amc as decimal(15,4))/cast(pmc as decimal(15,4)) am_pm_ratio - from ( select count(*) amc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 9 and 9+1 - and household_demographics.hd_dep_count = 7 - and web_page.wp_char_count between 5000 and 5200) at, - ( select count(*) pmc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 16 and 16+1 - and household_demographics.hd_dep_count = 7 - and web_page.wp_char_count between 5000 and 5200) pt - order by am_pm_ratio - limit 100; - --- end template query90.tpl query 15 in stream 9 --- start template query7.tpl query 16 in stream 9 -select /* TPC-DS query7.tpl 0.2 */ i_item_id, - avg(ss_quantity) agg1, - avg(ss_list_price) agg2, - avg(ss_coupon_amt) agg3, - avg(ss_sales_price) agg4 - from store_sales, customer_demographics, date_dim, item, promotion - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_cdemo_sk = cd_demo_sk and - ss_promo_sk = p_promo_sk and - cd_gender = 'M' and - cd_marital_status = 'M' and - cd_education_status = 'Secondary' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 1999 - group by i_item_id - order by i_item_id - limit 100; - --- end template query7.tpl query 16 in stream 9 --- start template query27a.tpl query 17 in stream 9 -with /* TPC-DS query27a.tpl 0.16 */ results as - (select i_item_id, - s_state, 0 as g_state, - ss_quantity agg1, - ss_list_price agg2, - ss_coupon_amt agg3, - ss_sales_price agg4 - from store_sales, customer_demographics, date_dim, store, item - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_store_sk = s_store_sk and - ss_cdemo_sk = cd_demo_sk and - cd_gender = 'M' and - cd_marital_status = 'W' and - cd_education_status = '4 yr Degree' and - d_year = 2001 and - s_state in ('TN','MN', 'WV', 'IA', 'TX', 'TX') - ) - - select i_item_id, - s_state, g_state, agg1, agg2, agg3, agg4 - from ( - select i_item_id, s_state, 0 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4 from results - group by i_item_id, s_state - union all - select i_item_id, NULL AS s_state, 1 AS g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as s_state, 1 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - ) foo - order by i_item_id, s_state - limit 100; - --- end template query27a.tpl query 17 in stream 9 --- start template query92.tpl query 18 in stream 9 -select /* TPC-DS query92.tpl 0.44 */ - sum(ws_ext_discount_amt) as "Excess Discount Amount" -from - web_sales - ,item - ,date_dim -where -i_manufact_id = 514 -and i_item_sk = ws_item_sk -and d_date between '2001-02-06' and - dateadd(day,90,cast('2001-02-06' as date)) -and d_date_sk = ws_sold_date_sk -and ws_ext_discount_amt - > ( - SELECT - 1.3 * avg(ws_ext_discount_amt) - FROM - web_sales - ,date_dim - WHERE - ws_item_sk = i_item_sk - and d_date between '2001-02-06' and - dateadd(day,90,cast('2001-02-06' as date)) - and d_date_sk = ws_sold_date_sk - ) -order by sum(ws_ext_discount_amt) -limit 100; - --- end template query92.tpl query 18 in stream 9 --- start template query39.tpl query 19 in stream 9 -with /* TPC-DS query39.tpl 0.5 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =1998 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=1 - and inv2.d_moy=1+1 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; -with /* TPC-DS query39.tpl 0.5 part2 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =1998 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=1 - and inv2.d_moy=1+1 - and inv1.cov > 1.5 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; - --- end template query39.tpl query 19 in stream 9 --- start template query34.tpl query 20 in stream 9 -select /* TPC-DS query34.tpl 0.73 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (date_dim.d_dom between 1 and 3 or date_dim.d_dom between 25 and 28) - and (household_demographics.hd_buy_potential = '1001-5000' or - household_demographics.hd_buy_potential = '5001-10000') - and household_demographics.hd_vehicle_count > 0 - and (case when household_demographics.hd_vehicle_count > 0 - then household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count - else null - end) > 1.2 - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_county in ('Knox County','Suffolk County','Red River Parish','Carter County', - 'Murray County','Oglethorpe County','Coal County','Lincoln County') - group by ss_ticket_number,ss_customer_sk) dn,customer - where ss_customer_sk = c_customer_sk - and cnt between 15 and 20 - order by c_last_name,c_first_name,c_salutation,c_preferred_cust_flag desc, ss_ticket_number; - --- end template query34.tpl query 20 in stream 9 --- start template query21.tpl query 21 in stream 9 -select /* TPC-DS query21.tpl 0.14 */ * - from(select w_warehouse_name - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('2001-05-28' as date)) - then inv_quantity_on_hand - else 0 end) as inv_before - ,sum(case when (cast(d_date as date) >= cast ('2001-05-28' as date)) - then inv_quantity_on_hand - else 0 end) as inv_after - from inventory - ,warehouse - ,item - ,date_dim - where i_current_price between 0.99 and 1.49 - and i_item_sk = inv_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('2001-05-28' as date)) - and dateadd(day,30,cast ('2001-05-28' as date)) - group by w_warehouse_name, i_item_id) x - where (case when inv_before > 0 - then inv_after / inv_before - else null - end) between 2.0/3.0 and 3.0/2.0 - order by w_warehouse_name - ,i_item_id - limit 100; - --- end template query21.tpl query 21 in stream 9 --- start template query65.tpl query 22 in stream 9 -select /* TPC-DS query65.tpl 0.71 */ - s_store_name, - i_item_desc, - sc.revenue, - i_current_price, - i_wholesale_cost, - i_brand - from store, item, - (select ss_store_sk, avg(revenue) as ave - from - (select ss_store_sk, ss_item_sk, - sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1207 and 1207+11 - group by ss_store_sk, ss_item_sk) sa - group by ss_store_sk) sb, - (select ss_store_sk, ss_item_sk, sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1207 and 1207+11 - group by ss_store_sk, ss_item_sk) sc - where sb.ss_store_sk = sc.ss_store_sk and - sc.revenue <= 0.1 * sb.ave and - s_store_sk = sc.ss_store_sk and - i_item_sk = sc.ss_item_sk - order by s_store_name, i_item_desc -limit 100; - --- end template query65.tpl query 22 in stream 9 --- start template query75.tpl query 23 in stream 9 -WITH /* TPC-DS query75.tpl 0.3 */ all_sales AS ( - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,SUM(sales_cnt) AS sales_cnt - ,SUM(sales_amt) AS sales_amt - FROM (SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,cs_quantity - COALESCE(cr_return_quantity,0) AS sales_cnt - ,cs_ext_sales_price - COALESCE(cr_return_amount,0.0) AS sales_amt - FROM catalog_sales JOIN item ON i_item_sk=cs_item_sk - JOIN date_dim ON d_date_sk=cs_sold_date_sk - LEFT JOIN catalog_returns ON (cs_order_number=cr_order_number - AND cs_item_sk=cr_item_sk) - WHERE i_category='Sports' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ss_quantity - COALESCE(sr_return_quantity,0) AS sales_cnt - ,ss_ext_sales_price - COALESCE(sr_return_amt,0.0) AS sales_amt - FROM store_sales JOIN item ON i_item_sk=ss_item_sk - JOIN date_dim ON d_date_sk=ss_sold_date_sk - LEFT JOIN store_returns ON (ss_ticket_number=sr_ticket_number - AND ss_item_sk=sr_item_sk) - WHERE i_category='Sports' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ws_quantity - COALESCE(wr_return_quantity,0) AS sales_cnt - ,ws_ext_sales_price - COALESCE(wr_return_amt,0.0) AS sales_amt - FROM web_sales JOIN item ON i_item_sk=ws_item_sk - JOIN date_dim ON d_date_sk=ws_sold_date_sk - LEFT JOIN web_returns ON (ws_order_number=wr_order_number - AND ws_item_sk=wr_item_sk) - WHERE i_category='Sports') sales_detail - GROUP BY d_year, i_brand_id, i_class_id, i_category_id, i_manufact_id) - SELECT prev_yr.d_year AS prev_year - ,curr_yr.d_year AS year - ,curr_yr.i_brand_id - ,curr_yr.i_class_id - ,curr_yr.i_category_id - ,curr_yr.i_manufact_id - ,prev_yr.sales_cnt AS prev_yr_cnt - ,curr_yr.sales_cnt AS curr_yr_cnt - ,curr_yr.sales_cnt-prev_yr.sales_cnt AS sales_cnt_diff - ,curr_yr.sales_amt-prev_yr.sales_amt AS sales_amt_diff - FROM all_sales curr_yr, all_sales prev_yr - WHERE curr_yr.i_brand_id=prev_yr.i_brand_id - AND curr_yr.i_class_id=prev_yr.i_class_id - AND curr_yr.i_category_id=prev_yr.i_category_id - AND curr_yr.i_manufact_id=prev_yr.i_manufact_id - AND curr_yr.d_year=2001 - AND prev_yr.d_year=2001-1 - AND CAST(curr_yr.sales_cnt AS DECIMAL(17,2))/CAST(prev_yr.sales_cnt AS DECIMAL(17,2))<0.9 - ORDER BY sales_cnt_diff,sales_amt_diff - limit 100; - --- end template query75.tpl query 23 in stream 9 --- start template query9.tpl query 24 in stream 9 -select /* TPC-DS query9.tpl 0.49 */ case when (select count(*) - from store_sales - where ss_quantity between 1 and 20) > 411084957 - then (select avg(ss_ext_list_price) - from store_sales - where ss_quantity between 1 and 20) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 1 and 20) end bucket1 , - case when (select count(*) - from store_sales - where ss_quantity between 21 and 40) > 3033686132 - then (select avg(ss_ext_list_price) - from store_sales - where ss_quantity between 21 and 40) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 21 and 40) end bucket2, - case when (select count(*) - from store_sales - where ss_quantity between 41 and 60) > 1107973670 - then (select avg(ss_ext_list_price) - from store_sales - where ss_quantity between 41 and 60) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 41 and 60) end bucket3, - case when (select count(*) - from store_sales - where ss_quantity between 61 and 80) > 4050818901 - then (select avg(ss_ext_list_price) - from store_sales - where ss_quantity between 61 and 80) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 61 and 80) end bucket4, - case when (select count(*) - from store_sales - where ss_quantity between 81 and 100) > 596507312 - then (select avg(ss_ext_list_price) - from store_sales - where ss_quantity between 81 and 100) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 81 and 100) end bucket5 -from reason -where r_reason_sk = 1 -; - --- end template query9.tpl query 24 in stream 9 --- start template query2.tpl query 25 in stream 9 -with /* TPC-DS query2.tpl 0.84 */ wscs as - (select sold_date_sk - ,sales_price - from (select ws_sold_date_sk sold_date_sk - ,ws_ext_sales_price sales_price - from web_sales - union all - select cs_sold_date_sk sold_date_sk - ,cs_ext_sales_price sales_price - from catalog_sales)), - wswscs as - (select d_week_seq, - sum(case when (d_day_name='Sunday') then sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then sales_price else null end) sat_sales - from wscs - ,date_dim - where d_date_sk = sold_date_sk - group by d_week_seq) - select d_week_seq1 - ,round(sun_sales1/sun_sales2,2) - ,round(mon_sales1/mon_sales2,2) - ,round(tue_sales1/tue_sales2,2) - ,round(wed_sales1/wed_sales2,2) - ,round(thu_sales1/thu_sales2,2) - ,round(fri_sales1/fri_sales2,2) - ,round(sat_sales1/sat_sales2,2) - from - (select wswscs.d_week_seq d_week_seq1 - ,sun_sales sun_sales1 - ,mon_sales mon_sales1 - ,tue_sales tue_sales1 - ,wed_sales wed_sales1 - ,thu_sales thu_sales1 - ,fri_sales fri_sales1 - ,sat_sales sat_sales1 - from wswscs,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 1999) y, - (select wswscs.d_week_seq d_week_seq2 - ,sun_sales sun_sales2 - ,mon_sales mon_sales2 - ,tue_sales tue_sales2 - ,wed_sales wed_sales2 - ,thu_sales thu_sales2 - ,fri_sales fri_sales2 - ,sat_sales sat_sales2 - from wswscs - ,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 1999+1) z - where d_week_seq1=d_week_seq2-53 - order by d_week_seq1; - --- end template query2.tpl query 25 in stream 9 --- start template query12.tpl query 26 in stream 9 -select /* TPC-DS query12.tpl 0.64 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ws_ext_sales_price) as itemrevenue - ,sum(ws_ext_sales_price)*100/sum(sum(ws_ext_sales_price)) over - (partition by i_class) as revenueratio -from - web_sales - ,item - ,date_dim -where - ws_item_sk = i_item_sk - and i_category in ('Shoes', 'Children', 'Home') - and ws_sold_date_sk = d_date_sk - and d_date between cast('2000-04-06' as date) - and dateadd(day,30,cast('2000-04-06' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query12.tpl query 26 in stream 9 --- start template query32.tpl query 27 in stream 9 -select /* TPC-DS query32.tpl 0.7 */ sum(cs_ext_discount_amt) as "excess discount amount" -from - catalog_sales - ,item - ,date_dim -where -i_manufact_id = 177 -and i_item_sk = cs_item_sk -and d_date between '2000-01-10' and - dateadd(day,90,cast('2000-01-10' as date)) -and d_date_sk = cs_sold_date_sk -and cs_ext_discount_amt - > ( - select - 1.3 * avg(cs_ext_discount_amt) - from - catalog_sales - ,date_dim - where - cs_item_sk = i_item_sk - and d_date between '2000-01-10' and - dateadd(day,90,cast('2000-01-10' as date)) - and d_date_sk = cs_sold_date_sk - ) -limit 100; - --- end template query32.tpl query 27 in stream 9 --- start template query28.tpl query 28 in stream 9 -select /* TPC-DS query28.tpl 0.36 */ * -from (select avg(ss_list_price) B1_LP - ,count(ss_list_price) B1_CNT - ,count(distinct ss_list_price) B1_CNTD - from store_sales - where ss_quantity between 0 and 5 - and (ss_list_price between 182 and 182+10 - or ss_coupon_amt between 818 and 818+1000 - or ss_wholesale_cost between 27 and 27+20)) B1, - (select avg(ss_list_price) B2_LP - ,count(ss_list_price) B2_CNT - ,count(distinct ss_list_price) B2_CNTD - from store_sales - where ss_quantity between 6 and 10 - and (ss_list_price between 12 and 12+10 - or ss_coupon_amt between 5892 and 5892+1000 - or ss_wholesale_cost between 51 and 51+20)) B2, - (select avg(ss_list_price) B3_LP - ,count(ss_list_price) B3_CNT - ,count(distinct ss_list_price) B3_CNTD - from store_sales - where ss_quantity between 11 and 15 - and (ss_list_price between 155 and 155+10 - or ss_coupon_amt between 3825 and 3825+1000 - or ss_wholesale_cost between 36 and 36+20)) B3, - (select avg(ss_list_price) B4_LP - ,count(ss_list_price) B4_CNT - ,count(distinct ss_list_price) B4_CNTD - from store_sales - where ss_quantity between 16 and 20 - and (ss_list_price between 1 and 1+10 - or ss_coupon_amt between 15569 and 15569+1000 - or ss_wholesale_cost between 30 and 30+20)) B4, - (select avg(ss_list_price) B5_LP - ,count(ss_list_price) B5_CNT - ,count(distinct ss_list_price) B5_CNTD - from store_sales - where ss_quantity between 21 and 25 - and (ss_list_price between 83 and 83+10 - or ss_coupon_amt between 5733 and 5733+1000 - or ss_wholesale_cost between 35 and 35+20)) B5, - (select avg(ss_list_price) B6_LP - ,count(ss_list_price) B6_CNT - ,count(distinct ss_list_price) B6_CNTD - from store_sales - where ss_quantity between 26 and 30 - and (ss_list_price between 66 and 66+10 - or ss_coupon_amt between 1834 and 1834+1000 - or ss_wholesale_cost between 19 and 19+20)) B6 -limit 100; - --- end template query28.tpl query 28 in stream 9 --- start template query42.tpl query 29 in stream 9 -select /* TPC-DS query42.tpl 0.61 */ dt.d_year - ,item.i_category_id - ,item.i_category - ,sum(ss_ext_sales_price) - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=12 - and dt.d_year=1998 - group by dt.d_year - ,item.i_category_id - ,item.i_category - order by sum(ss_ext_sales_price) desc,dt.d_year - ,item.i_category_id - ,item.i_category -limit 100 ; - --- end template query42.tpl query 29 in stream 9 --- start template query17.tpl query 30 in stream 9 -select /* TPC-DS query17.tpl 0.41 */ i_item_id - ,i_item_desc - ,s_state - ,count(ss_quantity) as store_sales_quantitycount - ,avg(ss_quantity) as store_sales_quantityave - ,stddev_samp(ss_quantity) as store_sales_quantitystdev - ,stddev_samp(ss_quantity)/avg(ss_quantity) as store_sales_quantitycov - ,count(sr_return_quantity) as store_returns_quantitycount - ,avg(sr_return_quantity) as store_returns_quantityave - ,stddev_samp(sr_return_quantity) as store_returns_quantitystdev - ,stddev_samp(sr_return_quantity)/avg(sr_return_quantity) as store_returns_quantitycov - ,count(cs_quantity) as catalog_sales_quantitycount ,avg(cs_quantity) as catalog_sales_quantityave - ,stddev_samp(cs_quantity) as catalog_sales_quantitystdev - ,stddev_samp(cs_quantity)/avg(cs_quantity) as catalog_sales_quantitycov - from store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where d1.d_quarter_name = '1998Q1' - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_quarter_name in ('1998Q1','1998Q2','1998Q3') - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_quarter_name in ('1998Q1','1998Q2','1998Q3') - group by i_item_id - ,i_item_desc - ,s_state - order by i_item_id - ,i_item_desc - ,s_state -limit 100; - --- end template query17.tpl query 30 in stream 9 --- start template query67a.tpl query 31 in stream 9 -with /* TPC-DS query67a.tpl 0.35 */ results as -( select i_category ,i_class ,i_brand ,i_product_name ,d_year ,d_qoy ,d_moy ,s_store_id - ,sum(coalesce(ss_sales_price*ss_quantity,0)) sumsales - from store_sales ,date_dim ,store ,item - where ss_sold_date_sk=d_date_sk - and ss_item_sk=i_item_sk - and ss_store_sk = s_store_sk - and d_month_seq between 1177 and 1177 + 11 - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy,s_store_id) - , - results_rollup as - (select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, s_store_id, sumsales - from results - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy - union all - select i_category, i_class, i_brand, i_product_name, d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year - union all - select i_category, i_class, i_brand, i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name - union all - select i_category, i_class, i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand - union all - select i_category, i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class - union all - select i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category - union all - select null i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results) - - select * -from (select i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rank() over (partition by i_category order by sumsales desc) rk - from results_rollup) dw2 -where rk <= 100 -order by i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rk -limit 100; - --- end template query67a.tpl query 31 in stream 9 --- start template query31.tpl query 32 in stream 9 -with /* TPC-DS query31.tpl 0.50 */ ss as - (select ca_county,d_qoy, d_year,sum(ss_ext_sales_price) as store_sales - from store_sales,date_dim,customer_address - where ss_sold_date_sk = d_date_sk - and ss_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year), - ws as - (select ca_county,d_qoy, d_year,sum(ws_ext_sales_price) as web_sales - from web_sales,date_dim,customer_address - where ws_sold_date_sk = d_date_sk - and ws_bill_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year) - select - ss1.ca_county - ,ss1.d_year - ,ws2.web_sales/ws1.web_sales web_q1_q2_increase - ,ss2.store_sales/ss1.store_sales store_q1_q2_increase - ,ws3.web_sales/ws2.web_sales web_q2_q3_increase - ,ss3.store_sales/ss2.store_sales store_q2_q3_increase - from - ss ss1 - ,ss ss2 - ,ss ss3 - ,ws ws1 - ,ws ws2 - ,ws ws3 - where - ss1.d_qoy = 1 - and ss1.d_year = 2000 - and ss1.ca_county = ss2.ca_county - and ss2.d_qoy = 2 - and ss2.d_year = 2000 - and ss2.ca_county = ss3.ca_county - and ss3.d_qoy = 3 - and ss3.d_year = 2000 - and ss1.ca_county = ws1.ca_county - and ws1.d_qoy = 1 - and ws1.d_year = 2000 - and ws1.ca_county = ws2.ca_county - and ws2.d_qoy = 2 - and ws2.d_year = 2000 - and ws1.ca_county = ws3.ca_county - and ws3.d_qoy = 3 - and ws3.d_year =2000 - and case when ws1.web_sales > 0 then ws2.web_sales/ws1.web_sales else null end - > case when ss1.store_sales > 0 then ss2.store_sales/ss1.store_sales else null end - and case when ws2.web_sales > 0 then ws3.web_sales/ws2.web_sales else null end - > case when ss2.store_sales > 0 then ss3.store_sales/ss2.store_sales else null end - order by store_q1_q2_increase; - --- end template query31.tpl query 32 in stream 9 --- start template query20.tpl query 33 in stream 9 -select /* TPC-DS query20.tpl 0.65 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(cs_ext_sales_price) as itemrevenue - ,sum(cs_ext_sales_price)*100/sum(sum(cs_ext_sales_price)) over - (partition by i_class) as revenueratio - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and i_category in ('Electronics', 'Music', 'Jewelry') - and cs_sold_date_sk = d_date_sk - and d_date between cast('2002-04-16' as date) - and dateadd(day,30,cast('2002-04-16' as date)) - group by i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - order by i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query20.tpl query 33 in stream 9 --- start template query11.tpl query 34 in stream 9 -with /* TPC-DS query11.tpl 0.51 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ss_ext_list_price-ss_ext_discount_amt) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ws_ext_list_price-ws_ext_discount_amt) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_login - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 1999 - and t_s_secyear.dyear = 1999+1 - and t_w_firstyear.dyear = 1999 - and t_w_secyear.dyear = 1999+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else 0.0 end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else 0.0 end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_login -limit 100; - --- end template query11.tpl query 34 in stream 9 --- start template query77a.tpl query 35 in stream 9 -with /* TPC-DS query77a.tpl 0.78 */ ss as - (select s_store_sk, - sum(ss_ext_sales_price) as sales, - sum(ss_net_profit) as profit - from store_sales, - date_dim, - store - where ss_sold_date_sk = d_date_sk - and d_date between cast('2001-08-10' as date) - and dateadd(day,30,cast('2001-08-10' as date)) - and ss_store_sk = s_store_sk - group by s_store_sk) - , - sr as - (select s_store_sk, - sum(sr_return_amt) as returns, - sum(sr_net_loss) as profit_loss - from store_returns, - date_dim, - store - where sr_returned_date_sk = d_date_sk - and d_date between cast('2001-08-10' as date) - and dateadd(day,30,cast('2001-08-10' as date)) - and sr_store_sk = s_store_sk - group by s_store_sk), - cs as - (select cs_call_center_sk, - sum(cs_ext_sales_price) as sales, - sum(cs_net_profit) as profit - from catalog_sales, - date_dim - where cs_sold_date_sk = d_date_sk - and d_date between cast('2001-08-10' as date) - and dateadd(day,30,cast('2001-08-10' as date)) - group by cs_call_center_sk - ), - cr as - (select cr_call_center_sk, - sum(cr_return_amount) as returns, - sum(cr_net_loss) as profit_loss - from catalog_returns, - date_dim - where cr_returned_date_sk = d_date_sk - and d_date between cast('2001-08-10' as date) - and dateadd(day,30,cast('2001-08-10' as date)) - group by cr_call_center_sk), - ws as - ( select wp_web_page_sk, - sum(ws_ext_sales_price) as sales, - sum(ws_net_profit) as profit - from web_sales, - date_dim, - web_page - where ws_sold_date_sk = d_date_sk - and d_date between cast('2001-08-10' as date) - and dateadd(day,30,cast('2001-08-10' as date)) - and ws_web_page_sk = wp_web_page_sk - group by wp_web_page_sk), - wr as - (select wp_web_page_sk, - sum(wr_return_amt) as returns, - sum(wr_net_loss) as profit_loss - from web_returns, - date_dim, - web_page - where wr_returned_date_sk = d_date_sk - and d_date between cast('2001-08-10' as date) - and dateadd(day,30,cast('2001-08-10' as date)) - and wr_web_page_sk = wp_web_page_sk - group by wp_web_page_sk) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , ss.s_store_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ss left join sr - on ss.s_store_sk = sr.s_store_sk - union all - select 'catalog channel' as channel - , cs_call_center_sk as id - , sales - , returns - , (profit - profit_loss) as profit - from cs - , cr - union all - select 'web channel' as channel - , ws.wp_web_page_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ws left join wr - on ws.wp_web_page_sk = wr.wp_web_page_sk - ) x - group by channel, id ) - - select * - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results -) foo -order by channel, id - limit 100; - --- end template query77a.tpl query 35 in stream 9 --- start template query36a.tpl query 36 in stream 9 -with /* TPC-DS query36a.tpl 0.21 */ results as - (select - sum(ss_net_profit) as ss_net_profit, sum(ss_ext_sales_price) as ss_ext_sales_price, - sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin - ,i_category - ,i_class - ,0 as g_category, 0 as g_class - from - store_sales - ,date_dim d1 - ,item - ,store - where - d1.d_year = 1998 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and s_state in ('WA','MI','PA','IA', - 'KS','GA','NC','OH') - group by i_category,i_class) - , - results_rollup as - (select gross_margin ,i_category ,i_class,0 as t_category, 0 as t_class, 0 as lochierarchy from results - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - i_category, NULL AS i_class, 0 as t_category, 1 as t_class, 1 as lochierarchy from results group by i_category - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - NULL AS i_category ,NULL AS i_class, 1 as t_category, 1 as t_class, 2 as lochierarchy from results) - select - gross_margin ,i_category ,i_class, lochierarchy,rank() over ( - partition by lochierarchy, case when t_class = 0 then i_category end - order by gross_margin asc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then i_category end - ,rank_within_parent - limit 100; - --- end template query36a.tpl query 36 in stream 9 --- start template query82.tpl query 37 in stream 9 -select /* TPC-DS query82.tpl 0.67 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, store_sales - where i_current_price between 12 and 12+30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('2001-06-07' as date) and dateadd(day,60,cast('2001-06-07' as date)) - and i_manufact_id in (410,239,78,315) - and inv_quantity_on_hand between 100 and 500 - and ss_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query82.tpl query 37 in stream 9 --- start template query33.tpl query 38 in stream 9 -with /* TPC-DS query33.tpl 0.22 */ ss as ( - select - i_manufact_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Home')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 1 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_manufact_id), - cs as ( - select - i_manufact_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Home')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 1 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_manufact_id), - ws as ( - select - i_manufact_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Home')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 1 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_manufact_id) - select i_manufact_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_manufact_id - order by total_sales -limit 100; - --- end template query33.tpl query 38 in stream 9 --- start template query54.tpl query 39 in stream 9 -with /* TPC-DS query54.tpl 0.81 */ my_customers as ( - select distinct c_customer_sk - , c_current_addr_sk - from - ( select cs_sold_date_sk sold_date_sk, - cs_bill_customer_sk customer_sk, - cs_item_sk item_sk - from catalog_sales - union all - select ws_sold_date_sk sold_date_sk, - ws_bill_customer_sk customer_sk, - ws_item_sk item_sk - from web_sales - ) cs_or_ws_sales, - item, - date_dim, - customer - where sold_date_sk = d_date_sk - and item_sk = i_item_sk - and i_category = 'Books' - and i_class = 'cooking' - and c_customer_sk = cs_or_ws_sales.customer_sk - and d_moy = 1 - and d_year = 2002 - ) - , my_revenue as ( - select c_customer_sk, - sum(ss_ext_sales_price) as revenue - from my_customers, - store_sales, - customer_address, - store, - date_dim - where c_current_addr_sk = ca_address_sk - and ca_county = s_county - and ca_state = s_state - and ss_sold_date_sk = d_date_sk - and c_customer_sk = ss_customer_sk - and d_month_seq between (select distinct d_month_seq+1 - from date_dim where d_year = 2002 and d_moy = 1) - and (select distinct d_month_seq+3 - from date_dim where d_year = 2002 and d_moy = 1) - group by c_customer_sk - ) - , segments as - (select cast((revenue/50) as bigint) as segment - from my_revenue - ) - select segment, count(*) as num_customers, segment*50 as segment_base - from segments - group by segment - order by segment, num_customers - limit 100; - --- end template query54.tpl query 39 in stream 9 --- start template query4.tpl query 40 in stream 9 -with /* TPC-DS query4.tpl 0.93 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(((ss_ext_list_price-ss_ext_wholesale_cost-ss_ext_discount_amt)+ss_ext_sales_price)/2) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((cs_ext_list_price-cs_ext_wholesale_cost-cs_ext_discount_amt)+cs_ext_sales_price)/2) ) year_total - ,'c' sale_type - from customer - ,catalog_sales - ,date_dim - where c_customer_sk = cs_bill_customer_sk - and cs_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year -union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((ws_ext_list_price-ws_ext_wholesale_cost-ws_ext_discount_amt)+ws_ext_sales_price)/2) ) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_birth_country - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_c_firstyear - ,year_total t_c_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_c_secyear.customer_id - and t_s_firstyear.customer_id = t_c_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_c_firstyear.sale_type = 'c' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_c_secyear.sale_type = 'c' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 2000 - and t_s_secyear.dyear = 2000+1 - and t_c_firstyear.dyear = 2000 - and t_c_secyear.dyear = 2000+1 - and t_w_firstyear.dyear = 2000 - and t_w_secyear.dyear = 2000+1 - and t_s_firstyear.year_total > 0 - and t_c_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_birth_country -limit 100; - --- end template query4.tpl query 40 in stream 9 --- start template query16.tpl query 41 in stream 9 -select /* TPC-DS query16.tpl 0.25 */ - count(distinct cs_order_number) as "order count" - ,sum(cs_ext_ship_cost) as "total shipping cost" - ,sum(cs_net_profit) as "total net profit" -from - catalog_sales cs1 - ,date_dim - ,customer_address - ,call_center -where - d_date between '1999-4-01' and - dateadd(day, 60, cast('1999-4-01' as date)) -and cs1.cs_ship_date_sk = d_date_sk -and cs1.cs_ship_addr_sk = ca_address_sk -and ca_state = 'NE' -and cs1.cs_call_center_sk = cc_call_center_sk -and cc_county in ('Fairfield County','Sumner County','San Miguel County','Jefferson Davis Parish', - 'Raleigh County' -) -and exists (select * - from catalog_sales cs2 - where cs1.cs_order_number = cs2.cs_order_number - and cs1.cs_warehouse_sk <> cs2.cs_warehouse_sk) -and not exists(select * - from catalog_returns cr1 - where cs1.cs_order_number = cr1.cr_order_number) -order by count(distinct cs_order_number) -limit 100; - --- end template query16.tpl query 41 in stream 9 --- start template query10.tpl query 42 in stream 9 -select /* TPC-DS query10.tpl 0.26 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3, - cd_dep_count, - count(*) cnt4, - cd_dep_employed_count, - count(*) cnt5, - cd_dep_college_count, - count(*) cnt6 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_county in ('Ashtabula County','Traverse County','Centre County','Tuolumne County','Le Flore County') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 1 and 1+3) and - (exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 1 ANd 1+3) or - exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 1 and 1+3)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count -limit 100; - --- end template query10.tpl query 42 in stream 9 --- start template query18a.tpl query 43 in stream 9 -with /* TPC-DS query18a.tpl 0.90 */ results as - (select i_item_id, - ca_country, - ca_state, - ca_county, - cast(cs_quantity as decimal(12,2)) agg1, - cast(cs_list_price as decimal(12,2)) agg2, - cast(cs_coupon_amt as decimal(12,2)) agg3, - cast(cs_sales_price as decimal(12,2)) agg4, - cast(cs_net_profit as decimal(12,2)) agg5, - cast(c_birth_year as decimal(12,2)) agg6, - cast(cd1.cd_dep_count as decimal(12,2)) agg7 - from catalog_sales, customer_demographics cd1, customer_demographics cd2, customer, customer_address, date_dim, item - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd1.cd_demo_sk and - cs_bill_customer_sk = c_customer_sk and - cd1.cd_gender = 'F' and - cd1.cd_education_status = 'Primary' and - c_current_cdemo_sk = cd2.cd_demo_sk and - c_current_addr_sk = ca_address_sk and - c_birth_month in (4,3,1,7,6,10) and - d_year = 1998 and - ca_state in ('AK','AR','TX','FL','NE','CO','WI') - ) - select i_item_id, ca_country, ca_state, ca_county, agg1, agg2, agg3, agg4, agg5, agg6, agg7 - from ( - select i_item_id, ca_country, ca_state, ca_county, avg(agg1) agg1, - avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state, ca_county - union all - select i_item_id, ca_country, ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state - union all - select i_item_id, ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country - union all - select i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - ) foo - order by ca_country, ca_state, ca_county, i_item_id - limit 100; - --- end template query18a.tpl query 43 in stream 9 --- start template query48.tpl query 44 in stream 9 -select /* TPC-DS query48.tpl 0.74 */ sum (ss_quantity) - from store_sales, store, customer_demographics, customer_address, date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2001 - and - ( - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'D' - and - cd_education_status = 'Unknown' - and - ss_sales_price between 100.00 and 150.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'U' - and - cd_education_status = '4 yr Degree' - and - ss_sales_price between 50.00 and 100.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'S' - and - cd_education_status = 'College' - and - ss_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('AL', 'KY', 'PA') - and ss_net_profit between 0 and 2000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('OK', 'RI', 'FL') - and ss_net_profit between 150 and 3000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('ME', 'MT', 'LA') - and ss_net_profit between 50 and 25000 - ) - ) -; - --- end template query48.tpl query 44 in stream 9 --- start template query24.tpl query 45 in stream 9 -with /* TPC-DS query24.tpl 0.92 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_ext_sales_price) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip -and s_market_id=8 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'powder' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; -with /* TPC-DS query24.tpl 0.92 part2 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_ext_sales_price) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip - and s_market_id = 8 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'almond' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; - --- end template query24.tpl query 45 in stream 9 --- start template query30.tpl query 46 in stream 9 -with /* TPC-DS query30.tpl 0.75 */ customer_total_return as - (select wr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(wr_return_amt) as ctr_total_return - from web_returns - ,date_dim - ,customer_address - where wr_returned_date_sk = d_date_sk - and d_year =1999 - and wr_returning_addr_sk = ca_address_sk - group by wr_returning_customer_sk - ,ca_state) - select c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'GA' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return -limit 100; - --- end template query30.tpl query 46 in stream 9 --- start template query78.tpl query 47 in stream 9 -with /* TPC-DS query78.tpl 0.10 */ ws as - (select d_year AS ws_sold_year, ws_item_sk, - ws_bill_customer_sk ws_customer_sk, - sum(ws_quantity) ws_qty, - sum(ws_wholesale_cost) ws_wc, - sum(ws_sales_price) ws_sp - from web_sales - left join web_returns on wr_order_number=ws_order_number and ws_item_sk=wr_item_sk - join date_dim on ws_sold_date_sk = d_date_sk - where wr_order_number is null - group by d_year, ws_item_sk, ws_bill_customer_sk - ), -cs as - (select d_year AS cs_sold_year, cs_item_sk, - cs_bill_customer_sk cs_customer_sk, - sum(cs_quantity) cs_qty, - sum(cs_wholesale_cost) cs_wc, - sum(cs_sales_price) cs_sp - from catalog_sales - left join catalog_returns on cr_order_number=cs_order_number and cs_item_sk=cr_item_sk - join date_dim on cs_sold_date_sk = d_date_sk - where cr_order_number is null - group by d_year, cs_item_sk, cs_bill_customer_sk - ), -ss as - (select d_year AS ss_sold_year, ss_item_sk, - ss_customer_sk, - sum(ss_quantity) ss_qty, - sum(ss_wholesale_cost) ss_wc, - sum(ss_sales_price) ss_sp - from store_sales - left join store_returns on sr_ticket_number=ss_ticket_number and ss_item_sk=sr_item_sk - join date_dim on ss_sold_date_sk = d_date_sk - where sr_ticket_number is null - group by d_year, ss_item_sk, ss_customer_sk - ) - select -ss_sold_year, ss_item_sk, ss_customer_sk, -round(ss_qty/(coalesce(ws_qty,0)+coalesce(cs_qty,0)),2) ratio, -ss_qty store_qty, ss_wc store_wholesale_cost, ss_sp store_sales_price, -coalesce(ws_qty,0)+coalesce(cs_qty,0) other_chan_qty, -coalesce(ws_wc,0)+coalesce(cs_wc,0) other_chan_wholesale_cost, -coalesce(ws_sp,0)+coalesce(cs_sp,0) other_chan_sales_price -from ss -left join ws on (ws_sold_year=ss_sold_year and ws_item_sk=ss_item_sk and ws_customer_sk=ss_customer_sk) -left join cs on (cs_sold_year=ss_sold_year and cs_item_sk=ss_item_sk and cs_customer_sk=ss_customer_sk) -where (coalesce(ws_qty,0)>0 or coalesce(cs_qty, 0)>0) and ss_sold_year=2000 -order by - ss_sold_year, ss_item_sk, ss_customer_sk, - ss_qty desc, ss_wc desc, ss_sp desc, - other_chan_qty, - other_chan_wholesale_cost, - other_chan_sales_price, - ratio -limit 100; - --- end template query78.tpl query 47 in stream 9 --- start template query6.tpl query 48 in stream 9 -select /* TPC-DS query6.tpl 0.58 */ a.ca_state state, count(*) cnt - from customer_address a - ,customer c - ,store_sales s - ,date_dim d - ,item i - where a.ca_address_sk = c.c_current_addr_sk - and c.c_customer_sk = s.ss_customer_sk - and s.ss_sold_date_sk = d.d_date_sk - and s.ss_item_sk = i.i_item_sk - and d.d_month_seq = - (select distinct (d_month_seq) - from date_dim - where d_year = 2002 - and d_moy = 4 ) - and i.i_current_price > 1.2 * - (select avg(j.i_current_price) - from item j - where j.i_category = i.i_category) - group by a.ca_state - having count(*) >= 10 - order by cnt, a.ca_state - limit 100; - --- end template query6.tpl query 48 in stream 9 --- start template query80a.tpl query 49 in stream 9 -with /* TPC-DS query80a.tpl 0.6 */ ssr as - (select s_store_id as store_id, - sum(ss_ext_sales_price) as sales, - sum(coalesce(sr_return_amt, 0)) as returns, - sum(ss_net_profit - coalesce(sr_net_loss, 0)) as profit - from store_sales left outer join store_returns on - (ss_item_sk = sr_item_sk and ss_ticket_number = sr_ticket_number), - date_dim, - store, - item, - promotion - where ss_sold_date_sk = d_date_sk - and d_date between cast('2000-08-20' as date) - and dateadd(day,30,cast('2000-08-20' as date)) - and ss_store_sk = s_store_sk - and ss_item_sk = i_item_sk - and i_current_price > 50 - and ss_promo_sk = p_promo_sk - and p_channel_tv = 'N' - group by s_store_id) - , - csr as - (select cp_catalog_page_id as catalog_page_id, - sum(cs_ext_sales_price) as sales, - sum(coalesce(cr_return_amount, 0)) as returns, - sum(cs_net_profit - coalesce(cr_net_loss, 0)) as profit - from catalog_sales left outer join catalog_returns on - (cs_item_sk = cr_item_sk and cs_order_number = cr_order_number), - date_dim, - catalog_page, - item, - promotion - where cs_sold_date_sk = d_date_sk - and d_date between cast('2000-08-20' as date) - and dateadd(day,30,cast('2000-08-20' as date)) - and cs_catalog_page_sk = cp_catalog_page_sk - and cs_item_sk = i_item_sk - and i_current_price > 50 - and cs_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(ws_ext_sales_price) as sales, - sum(coalesce(wr_return_amt, 0)) as returns, - sum(ws_net_profit - coalesce(wr_net_loss, 0)) as profit - from web_sales left outer join web_returns on - (ws_item_sk = wr_item_sk and ws_order_number = wr_order_number), - date_dim, - web_site, - item, - promotion - where ws_sold_date_sk = d_date_sk - and d_date between cast('2000-08-20' as date) - and dateadd(day,30,cast('2000-08-20' as date)) - and ws_web_site_sk = web_site_sk - and ws_item_sk = i_item_sk - and i_current_price > 50 - and ws_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by web_site_id) -, -results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || store_id as id - , sales - , returns - , profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || catalog_page_id as id - , sales - , returns - , profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , profit - from wsr - ) x - group by channel, id) - - select channel - , id - , sales - , returns - , profit - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results - ) foo - order by channel, id - limit 100; - --- end template query80a.tpl query 49 in stream 9 --- start template query35a.tpl query 50 in stream 9 -select /* TPC-DS query35a.tpl 0.47 */ - ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - count(*) cnt1, - max(cd_dep_count), - min(cd_dep_count), - stddev_samp(cd_dep_count), - cd_dep_employed_count, - count(*) cnt2, - max(cd_dep_employed_count), - min(cd_dep_employed_count), - stddev_samp(cd_dep_employed_count), - cd_dep_college_count, - count(*) cnt3, - max(cd_dep_college_count), - min(cd_dep_college_count), - stddev_samp(cd_dep_college_count) - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2002 and - d_qoy < 4) and - exists (select * from - (select ws_bill_customer_sk customsk - from web_sales,date_dim - where - ws_sold_date_sk = d_date_sk and - d_year = 2002 and - d_qoy < 4 - union all - select cs_ship_customer_sk customsk - from catalog_sales,date_dim - where - cs_sold_date_sk = d_date_sk and - d_year = 2002 and - d_qoy < 4)x - where x.customsk = c.c_customer_sk) - group by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - limit 100; - --- end template query35a.tpl query 50 in stream 9 --- start template query59.tpl query 51 in stream 9 -with /* TPC-DS query59.tpl 0.30 */ wss as - (select d_week_seq, - ss_store_sk, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - group by d_week_seq,ss_store_sk - ) - select s_store_name1,s_store_id1,d_week_seq1 - ,sun_sales1/sun_sales2,mon_sales1/mon_sales2 - ,tue_sales1/tue_sales2,wed_sales1/wed_sales2,thu_sales1/thu_sales2 - ,fri_sales1/fri_sales2,sat_sales1/sat_sales2 - from - (select s_store_name s_store_name1,wss.d_week_seq d_week_seq1 - ,s_store_id s_store_id1,sun_sales sun_sales1 - ,mon_sales mon_sales1,tue_sales tue_sales1 - ,wed_sales wed_sales1,thu_sales thu_sales1 - ,fri_sales fri_sales1,sat_sales sat_sales1 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1178 and 1178 + 11) y, - (select s_store_name s_store_name2,wss.d_week_seq d_week_seq2 - ,s_store_id s_store_id2,sun_sales sun_sales2 - ,mon_sales mon_sales2,tue_sales tue_sales2 - ,wed_sales wed_sales2,thu_sales thu_sales2 - ,fri_sales fri_sales2,sat_sales sat_sales2 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1178+ 12 and 1178 + 23) x - where s_store_id1=s_store_id2 - and d_week_seq1=d_week_seq2-52 - order by s_store_name1,s_store_id1,d_week_seq1 -limit 100; - --- end template query59.tpl query 51 in stream 9 --- start template query99.tpl query 52 in stream 9 -select /* TPC-DS query99.tpl 0.94 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 30) and - (cs_ship_date_sk - cs_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 60) and - (cs_ship_date_sk - cs_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 90) and - (cs_ship_date_sk - cs_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - catalog_sales - ,warehouse - ,ship_mode - ,call_center - ,date_dim -where - d_month_seq between 1180 and 1180 + 11 -and cs_ship_date_sk = d_date_sk -and cs_warehouse_sk = w_warehouse_sk -and cs_ship_mode_sk = sm_ship_mode_sk -and cs_call_center_sk = cc_call_center_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -limit 100; - --- end template query99.tpl query 52 in stream 9 --- start template query61.tpl query 53 in stream 9 -select /* TPC-DS query61.tpl 0.97 */ promotions,total,cast(promotions as decimal(16,4))/cast(total as decimal(16,4))*100 -from - (select sum(ss_ext_sales_price) promotions - from store_sales - ,store - ,promotion - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_promo_sk = p_promo_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -6 - and i_category = 'Home' - and (p_channel_dmail = 'Y' or p_channel_email = 'Y' or p_channel_tv = 'Y') - and s_gmt_offset = -6 - and d_year = 1999 - and d_moy = 12) promotional_sales, - (select sum(ss_ext_sales_price) total - from store_sales - ,store - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -6 - and i_category = 'Home' - and s_gmt_offset = -6 - and d_year = 1999 - and d_moy = 12) all_sales -order by promotions, total -limit 100; - --- end template query61.tpl query 53 in stream 9 --- start template query22a.tpl query 54 in stream 9 -with /* TPC-DS query22a.tpl 0.55 */ results as -(select i_product_name - ,i_brand - ,i_class - ,i_category - ,avg(inv_quantity_on_hand) qoh - from inventory - ,date_dim - ,item --- ,warehouse - where inv_date_sk=d_date_sk - and inv_item_sk=i_item_sk --- and inv_warehouse_sk = w_warehouse_sk - and d_month_seq between 1195 and 1195 + 11 - group by i_product_name,i_brand,i_class,i_category), -results_rollup as -(select i_product_name, i_brand, i_class, i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class,i_category -union all -select i_product_name, i_brand, i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class -union all -select i_product_name, i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand -union all -select i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name -union all -select null i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results) - select i_product_name, i_brand, i_class, i_category,qoh - from results_rollup - order by qoh, i_product_name, i_brand, i_class, i_category -limit 100; - --- end template query22a.tpl query 54 in stream 9 --- start template query71.tpl query 55 in stream 9 -select /* TPC-DS query71.tpl 0.72 */ i_brand_id brand_id, i_brand brand,t_hour,t_minute, - sum(ext_price) ext_price - from item, (select ws_ext_sales_price as ext_price, - ws_sold_date_sk as sold_date_sk, - ws_item_sk as sold_item_sk, - ws_sold_time_sk as time_sk - from web_sales,date_dim - where d_date_sk = ws_sold_date_sk - and d_moy=11 - and d_year=1999 - union all - select cs_ext_sales_price as ext_price, - cs_sold_date_sk as sold_date_sk, - cs_item_sk as sold_item_sk, - cs_sold_time_sk as time_sk - from catalog_sales,date_dim - where d_date_sk = cs_sold_date_sk - and d_moy=11 - and d_year=1999 - union all - select ss_ext_sales_price as ext_price, - ss_sold_date_sk as sold_date_sk, - ss_item_sk as sold_item_sk, - ss_sold_time_sk as time_sk - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - and d_moy=11 - and d_year=1999 - ) tmp,time_dim - where - sold_item_sk = i_item_sk - and i_manager_id=1 - and time_sk = t_time_sk - and (t_meal_time = 'breakfast' or t_meal_time = 'dinner') - group by i_brand, i_brand_id,t_hour,t_minute - order by ext_price desc, i_brand_id - ; - --- end template query71.tpl query 55 in stream 9 --- start template query68.tpl query 56 in stream 9 -select /* TPC-DS query68.tpl 0.95 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,extended_price - ,extended_tax - ,list_price - from (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_ext_sales_price) extended_price - ,sum(ss_ext_list_price) list_price - ,sum(ss_ext_tax) extended_tax - from store_sales - ,date_dim - ,store - ,household_demographics - ,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_dep_count = 6 or - household_demographics.hd_vehicle_count= 4) - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_city in ('Waterville','White City') - group by ss_ticket_number - ,ss_customer_sk - ,ss_addr_sk,ca_city) dn - ,customer - ,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,ss_ticket_number - limit 100; - --- end template query68.tpl query 56 in stream 9 --- start template query40.tpl query 57 in stream 9 -select /* TPC-DS query40.tpl 0.86 */ - w_state - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('1999-02-07' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_before - ,sum(case when (cast(d_date as date) >= cast ('1999-02-07' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_after - from - catalog_sales left outer join catalog_returns on - (cs_order_number = cr_order_number - and cs_item_sk = cr_item_sk) - ,warehouse - ,item - ,date_dim - where - i_current_price between 0.99 and 1.49 - and i_item_sk = cs_item_sk - and cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('1999-02-07' as date)) - and dateadd(day,30,cast ('1999-02-07' as date)) - group by - w_state,i_item_id - order by w_state,i_item_id -limit 100; - --- end template query40.tpl query 57 in stream 9 --- start template query66.tpl query 58 in stream 9 -select /* TPC-DS query66.tpl 0.39 */ - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - ,sum(jan_sales) as jan_sales - ,sum(feb_sales) as feb_sales - ,sum(mar_sales) as mar_sales - ,sum(apr_sales) as apr_sales - ,sum(may_sales) as may_sales - ,sum(jun_sales) as jun_sales - ,sum(jul_sales) as jul_sales - ,sum(aug_sales) as aug_sales - ,sum(sep_sales) as sep_sales - ,sum(oct_sales) as oct_sales - ,sum(nov_sales) as nov_sales - ,sum(dec_sales) as dec_sales - ,sum(jan_sales/w_warehouse_sq_ft) as jan_sales_per_sq_foot - ,sum(feb_sales/w_warehouse_sq_ft) as feb_sales_per_sq_foot - ,sum(mar_sales/w_warehouse_sq_ft) as mar_sales_per_sq_foot - ,sum(apr_sales/w_warehouse_sq_ft) as apr_sales_per_sq_foot - ,sum(may_sales/w_warehouse_sq_ft) as may_sales_per_sq_foot - ,sum(jun_sales/w_warehouse_sq_ft) as jun_sales_per_sq_foot - ,sum(jul_sales/w_warehouse_sq_ft) as jul_sales_per_sq_foot - ,sum(aug_sales/w_warehouse_sq_ft) as aug_sales_per_sq_foot - ,sum(sep_sales/w_warehouse_sq_ft) as sep_sales_per_sq_foot - ,sum(oct_sales/w_warehouse_sq_ft) as oct_sales_per_sq_foot - ,sum(nov_sales/w_warehouse_sq_ft) as nov_sales_per_sq_foot - ,sum(dec_sales/w_warehouse_sq_ft) as dec_sales_per_sq_foot - ,sum(jan_net) as jan_net - ,sum(feb_net) as feb_net - ,sum(mar_net) as mar_net - ,sum(apr_net) as apr_net - ,sum(may_net) as may_net - ,sum(jun_net) as jun_net - ,sum(jul_net) as jul_net - ,sum(aug_net) as aug_net - ,sum(sep_net) as sep_net - ,sum(oct_net) as oct_net - ,sum(nov_net) as nov_net - ,sum(dec_net) as dec_net - from ( - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'USPS' || ',' || 'ZHOU' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then ws_ext_list_price* ws_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then ws_ext_list_price* ws_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then ws_ext_list_price* ws_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then ws_ext_list_price* ws_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then ws_ext_list_price* ws_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then ws_ext_list_price* ws_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then ws_ext_list_price* ws_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then ws_ext_list_price* ws_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then ws_ext_list_price* ws_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then ws_ext_list_price* ws_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then ws_ext_list_price* ws_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then ws_ext_list_price* ws_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as dec_net - from - web_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - ws_warehouse_sk = w_warehouse_sk - and ws_sold_date_sk = d_date_sk - and ws_sold_time_sk = t_time_sk - and ws_ship_mode_sk = sm_ship_mode_sk - and d_year = 2000 - and t_time between 41568 and 41568+28800 - and sm_carrier in ('USPS','ZHOU') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - union all - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'USPS' || ',' || 'ZHOU' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then cs_sales_price* cs_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then cs_sales_price* cs_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then cs_sales_price* cs_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then cs_sales_price* cs_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then cs_sales_price* cs_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then cs_sales_price* cs_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then cs_sales_price* cs_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then cs_sales_price* cs_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then cs_sales_price* cs_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then cs_sales_price* cs_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then cs_sales_price* cs_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then cs_sales_price* cs_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as dec_net - from - catalog_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and cs_sold_time_sk = t_time_sk - and cs_ship_mode_sk = sm_ship_mode_sk - and d_year = 2000 - and t_time between 41568 AND 41568+28800 - and sm_carrier in ('USPS','ZHOU') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - ) x - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - order by w_warehouse_name - limit 100; - --- end template query66.tpl query 58 in stream 9 --- start template query94.tpl query 59 in stream 9 -select /* TPC-DS query94.tpl 0.17 */ - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2001-2-01' and - dateadd(day,60,cast('2001-2-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'TX' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and exists (select * - from web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) -and not exists(select * - from web_returns wr1 - where ws1.ws_order_number = wr1.wr_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query94.tpl query 59 in stream 9 --- start template query47.tpl query 60 in stream 9 -with /* TPC-DS query47.tpl 0.42 */ v1 as( - select i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, - s_store_name, s_company_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - s_store_name, s_company_name - order by d_year, d_moy) rn - from item, store_sales, date_dim, store - where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - ( - d_year = 2000 or - ( d_year = 2000-1 and d_moy =12) or - ( d_year = 2000+1 and d_moy =1) - ) - group by i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy), - v2 as( - select v1.s_store_name, v1.s_company_name - ,v1.d_year, v1.d_moy - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1.s_store_name = v1_lag.s_store_name and - v1.s_store_name = v1_lead.s_store_name and - v1.s_company_name = v1_lag.s_company_name and - v1.s_company_name = v1_lead.s_company_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 2000 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, avg_monthly_sales - limit 100; - --- end template query47.tpl query 60 in stream 9 --- start template query26.tpl query 61 in stream 9 -select /* TPC-DS query26.tpl 0.85 */ i_item_id, - avg(cs_quantity) agg1, - avg(cs_list_price) agg2, - avg(cs_coupon_amt) agg3, - avg(cs_sales_price) agg4 - from catalog_sales, customer_demographics, date_dim, item, promotion - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd_demo_sk and - cs_promo_sk = p_promo_sk and - cd_gender = 'F' and - cd_marital_status = 'S' and - cd_education_status = 'Primary' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 1998 - group by i_item_id - order by i_item_id - limit 100; - --- end template query26.tpl query 61 in stream 9 --- start template query25.tpl query 62 in stream 9 -select /* TPC-DS query25.tpl 0.9 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,max(ss_net_profit) as store_sales_profit - ,max(sr_net_loss) as store_returns_loss - ,max(cs_net_profit) as catalog_sales_profit - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 1998 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 10 - and d2.d_year = 1998 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_moy between 4 and 10 - and d3.d_year = 1998 - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query25.tpl query 62 in stream 9 --- start template query98.tpl query 63 in stream 9 -select /* TPC-DS query98.tpl 0.32 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ss_ext_sales_price) as itemrevenue - ,sum(ss_ext_sales_price)*100/sum(sum(ss_ext_sales_price)) over - (partition by i_class) as revenueratio -from - store_sales - ,item - ,date_dim -where - ss_item_sk = i_item_sk - and i_category in ('Home', 'Children', 'Women') - and ss_sold_date_sk = d_date_sk - and d_date between cast('1999-06-10' as date) - and dateadd(day,30,cast('1999-06-10' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio; - --- end template query98.tpl query 63 in stream 9 --- start template query70a.tpl query 64 in stream 9 -with /* TPC-DS query70a.tpl 0.34 */ results as -( select - sum(ss_net_profit) as total_sum ,s_state ,s_county, 0 as gstate, 0 as g_county - from - store_sales - ,date_dim d1 - ,store - where - d1.d_month_seq between 1191 and 1191 + 11 - and d1.d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - and s_state in - ( select s_state - from (select s_state as s_state, - rank() over ( partition by s_state order by sum(ss_net_profit) desc) as ranking - from store_sales, store, date_dim - where d_month_seq between 1191 and 1191 + 11 - and d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - group by s_state - ) tmp1 - where ranking <= 5) - group by s_state,s_county) , - results_rollup as -(select total_sum ,s_state ,s_county, 0 as g_state, 0 as g_county, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum,s_state, NULL as s_county, 0 as g_state, 1 as g_county, 1 as lochierarchy from results group by s_state - union - select sum(total_sum) as total_sum ,NULL as s_state ,NULL as s_county, 1 as g_state, 1 as g_county, 2 as lochierarchy from results) - select total_sum ,s_state ,s_county, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_county = 0 then s_state end - order by total_sum desc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then s_state end - ,rank_within_parent - limit 100; - --- end template query70a.tpl query 64 in stream 9 --- start template query73.tpl query 65 in stream 9 -select /* TPC-DS query73.tpl 0.79 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_buy_potential = '>10000' or - household_demographics.hd_buy_potential = '0-500') - and household_demographics.hd_vehicle_count > 0 - and case when household_demographics.hd_vehicle_count > 0 then - household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count else null end > 1 - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_county in ('Conecuh County','Dade County','Clayton County','Gogebic County') - group by ss_ticket_number,ss_customer_sk) dj,customer - where ss_customer_sk = c_customer_sk - and cnt between 1 and 5 - order by cnt desc, c_last_name asc; - --- end template query73.tpl query 65 in stream 9 --- start template query38.tpl query 66 in stream 9 -select /* TPC-DS query38.tpl 0.54 */ count(*) from ( - select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1213 and 1213 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1213 and 1213 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1213 and 1213 + 11 -) hot_cust -limit 100; - --- end template query38.tpl query 66 in stream 9 --- start template query87.tpl query 67 in stream 9 -select /* TPC-DS query87.tpl 0.77 */ count(*) -from ((select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1206 and 1206+11) - except - (select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1206 and 1206+11) - except - (select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1206 and 1206+11) -) cool_cust -; - --- end template query87.tpl query 67 in stream 9 --- start template query3.tpl query 68 in stream 9 -select /* TPC-DS query3.tpl 0.45 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_sales_price) sum_agg - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manufact_id = 803 - and dt.d_moy=11 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,sum_agg desc - ,brand_id - limit 100; - --- end template query3.tpl query 68 in stream 9 --- start template query69.tpl query 69 in stream 9 -select /* TPC-DS query69.tpl 0.28 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_state in ('MN','NM','NC') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2004 and - d_moy between 2 and 2+2) and - (not exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2004 and - d_moy between 2 and 2+2) and - not exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2004 and - d_moy between 2 and 2+2)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - limit 100; - --- end template query69.tpl query 69 in stream 9 --- start template query86a.tpl query 70 in stream 9 -with /* TPC-DS query86a.tpl 0.11 */ results as -( select sum(ws_net_paid) as total_sum, i_category, i_class, 0 as g_category, 0 as g_class - from - web_sales - ,date_dim d1 - ,item - where - d1.d_month_seq between 1184 and 1184+11 - and d1.d_date_sk = ws_sold_date_sk - and i_item_sk = ws_item_sk - group by i_category,i_class - ) , - - results_rollup as -( select total_sum ,i_category ,i_class, g_category, g_class, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum, i_category, NULL as i_class, 0 as g_category, 1 as g_class, 1 as lochierarchy from results group by i_category - union - select sum(total_sum) as total_sum, NULL as i_category, NULL as i_class, 1 as g_category, 1 as g_class, 2 as lochierarchy from results) - select - total_sum ,i_category ,i_class, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_class = 0 then i_category end - order by total_sum desc) as rank_within_parent - from - results_rollup - order by - lochierarchy desc, - case when lochierarchy = 0 then i_category end, - rank_within_parent - limit 100; - --- end template query86a.tpl query 70 in stream 9 --- start template query79.tpl query 71 in stream 9 -select /* TPC-DS query79.tpl 0.89 */ - c_last_name,c_first_name,substring(s_city,1,30),ss_ticket_number,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,store.s_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (household_demographics.hd_dep_count = 3 or household_demographics.hd_vehicle_count > -1) - and date_dim.d_dow = 1 - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_number_employees between 200 and 295 - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,store.s_city) ms,customer - where ss_customer_sk = c_customer_sk - order by c_last_name,c_first_name,substring(s_city,1,30), profit -limit 100; - --- end template query79.tpl query 71 in stream 9 --- start template query89.tpl query 72 in stream 9 -select /* TPC-DS query89.tpl 0.56 */ * -from( -select i_category, i_class, i_brand, - s_store_name, s_company_name, - d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, s_store_name, s_company_name) - avg_monthly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - d_year in (1999) and - ((i_category in ('Women','Shoes','Sports') and - i_class in ('dresses','kids','hockey') - ) - or (i_category in ('Children','Electronics','Music') and - i_class in ('school-uniforms','dvd/vcr players','country') - )) -group by i_category, i_class, i_brand, - s_store_name, s_company_name, d_moy) tmp1 -where case when (avg_monthly_sales <> 0) then (abs(sum_sales - avg_monthly_sales) / avg_monthly_sales) else null end > 0.1 -order by sum_sales - avg_monthly_sales, s_store_name -limit 100; - --- end template query89.tpl query 72 in stream 9 --- start template query51.tpl query 73 in stream 9 -WITH /* TPC-DS query51.tpl 0.46 */ web_v1 as ( -select - ws_item_sk item_sk, d_date, - sum(sum(ws_sales_price)) - over (partition by ws_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from web_sales - ,date_dim -where ws_sold_date_sk=d_date_sk - and d_month_seq between 1224 and 1224+11 - and ws_item_sk is not NULL -group by ws_item_sk, d_date), -store_v1 as ( -select - ss_item_sk item_sk, d_date, - sum(sum(ss_sales_price)) - over (partition by ss_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from store_sales - ,date_dim -where ss_sold_date_sk=d_date_sk - and d_month_seq between 1224 and 1224+11 - and ss_item_sk is not NULL -group by ss_item_sk, d_date) - select * -from (select item_sk - ,d_date - ,web_sales - ,store_sales - ,max(web_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) web_cumulative - ,max(store_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) store_cumulative - from (select case when web.item_sk is not null then web.item_sk else store.item_sk end item_sk - ,case when web.d_date is not null then web.d_date else store.d_date end d_date - ,web.cume_sales web_sales - ,store.cume_sales store_sales - from web_v1 web full outer join store_v1 store on (web.item_sk = store.item_sk - and web.d_date = store.d_date) - )x )y -where web_cumulative > store_cumulative -order by item_sk - ,d_date -limit 100; - --- end template query51.tpl query 73 in stream 9 --- start template query58.tpl query 74 in stream 9 -with /* TPC-DS query58.tpl 0.19 */ ss_items as - (select i_item_id item_id - ,sum(ss_ext_sales_price) ss_item_rev - from store_sales - ,item - ,date_dim - where ss_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '1998-05-27')) - and ss_sold_date_sk = d_date_sk - group by i_item_id), - cs_items as - (select i_item_id item_id - ,sum(cs_ext_sales_price) cs_item_rev - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '1998-05-27')) - and cs_sold_date_sk = d_date_sk - group by i_item_id), - ws_items as - (select i_item_id item_id - ,sum(ws_ext_sales_price) ws_item_rev - from web_sales - ,item - ,date_dim - where ws_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq =(select d_week_seq - from date_dim - where d_date = '1998-05-27')) - and ws_sold_date_sk = d_date_sk - group by i_item_id) - select ss_items.item_id - ,ss_item_rev - ,ss_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ss_dev - ,cs_item_rev - ,cs_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 cs_dev - ,ws_item_rev - ,ws_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ws_dev - ,(ss_item_rev+cs_item_rev+ws_item_rev)/3 average - from ss_items,cs_items,ws_items - where ss_items.item_id=cs_items.item_id - and ss_items.item_id=ws_items.item_id - and ss_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - and ss_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and cs_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and cs_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and ws_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and ws_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - order by item_id - ,ss_item_rev - limit 100; - --- end template query58.tpl query 74 in stream 9 --- start template query41.tpl query 75 in stream 9 -select /* TPC-DS query41.tpl 0.62 */ distinct(i_product_name) - from item i1 - where i_manufact_id between 806 and 806+40 - and (select count(*) as item_cnt - from item - where (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'tan' or i_color = 'spring') and - (i_units = 'Pound' or i_units = 'Tbl') and - (i_size = 'small' or i_size = 'petite') - ) or - (i_category = 'Women' and - (i_color = 'cornflower' or i_color = 'sienna') and - (i_units = 'Case' or i_units = 'Gram') and - (i_size = 'extra large' or i_size = 'N/A') - ) or - (i_category = 'Men' and - (i_color = 'rosy' or i_color = 'powder') and - (i_units = 'Gross' or i_units = 'Ton') and - (i_size = 'economy' or i_size = 'medium') - ) or - (i_category = 'Men' and - (i_color = 'papaya' or i_color = 'orchid') and - (i_units = 'Carton' or i_units = 'Pallet') and - (i_size = 'small' or i_size = 'petite') - ))) or - (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'azure' or i_color = 'chocolate') and - (i_units = 'Each' or i_units = 'Unknown') and - (i_size = 'small' or i_size = 'petite') - ) or - (i_category = 'Women' and - (i_color = 'light' or i_color = 'frosted') and - (i_units = 'Box' or i_units = 'Oz') and - (i_size = 'extra large' or i_size = 'N/A') - ) or - (i_category = 'Men' and - (i_color = 'firebrick' or i_color = 'grey') and - (i_units = 'Bunch' or i_units = 'Tsp') and - (i_size = 'economy' or i_size = 'medium') - ) or - (i_category = 'Men' and - (i_color = 'honeydew' or i_color = 'cornsilk') and - (i_units = 'Dozen' or i_units = 'Dram') and - (i_size = 'small' or i_size = 'petite') - )))) > 0 - order by i_product_name - limit 100; - --- end template query41.tpl query 75 in stream 9 --- start template query19.tpl query 76 in stream 9 -select /* TPC-DS query19.tpl 0.8 */ i_brand_id brand_id, i_brand brand, i_manufact_id, i_manufact, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item,customer,customer_address,store - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=53 - and d_moy=12 - and d_year=1998 - and ss_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and substring(ca_zip,1,5) <> substring(s_zip,1,5) - and ss_store_sk = s_store_sk - group by i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact - order by ext_price desc - ,i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact -limit 100 ; - --- end template query19.tpl query 76 in stream 9 --- start template query83.tpl query 77 in stream 9 -with /* TPC-DS query83.tpl 0.96 */ sr_items as - (select i_item_id item_id, - sum(sr_return_quantity) sr_item_qty - from store_returns, - item, - date_dim - where sr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2001-01-16','2001-09-01','2001-11-05'))) - and sr_returned_date_sk = d_date_sk - group by i_item_id), - cr_items as - (select i_item_id item_id, - sum(cr_return_quantity) cr_item_qty - from catalog_returns, - item, - date_dim - where cr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2001-01-16','2001-09-01','2001-11-05'))) - and cr_returned_date_sk = d_date_sk - group by i_item_id), - wr_items as - (select i_item_id item_id, - sum(wr_return_quantity) wr_item_qty - from web_returns, - item, - date_dim - where wr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2001-01-16','2001-09-01','2001-11-05'))) - and wr_returned_date_sk = d_date_sk - group by i_item_id) - select sr_items.item_id - ,sr_item_qty - ,sr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 sr_dev - ,cr_item_qty - ,cr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 cr_dev - ,wr_item_qty - ,wr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 wr_dev - ,(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 average - from sr_items - ,cr_items - ,wr_items - where sr_items.item_id=cr_items.item_id - and sr_items.item_id=wr_items.item_id - order by sr_items.item_id - ,sr_item_qty - limit 100; - --- end template query83.tpl query 77 in stream 9 --- start template query96.tpl query 78 in stream 9 -select /* TPC-DS query96.tpl 0.1 */ count(*) -from store_sales - ,household_demographics - ,time_dim, store -where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 15 - and time_dim.t_minute >= 30 - and household_demographics.hd_dep_count = 7 - and store.s_store_name = 'ese' -order by count(*) -limit 100; - --- end template query96.tpl query 78 in stream 9 --- start template query46.tpl query 79 in stream 9 -select /* TPC-DS query46.tpl 0.23 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and (household_demographics.hd_dep_count = 5 or - household_demographics.hd_vehicle_count= 4) - and date_dim.d_dow in (6,0) - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_city in ('Russell','Lexington','Cairo','Cloverdale','Sherwood Forest') - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,ca_city) dn,customer,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - limit 100; - --- end template query46.tpl query 79 in stream 9 --- start template query53.tpl query 80 in stream 9 -select /* TPC-DS query53.tpl 0.88 */ * from -(select i_manufact_id, -sum(ss_sales_price) sum_sales, -avg(sum(ss_sales_price)) over (partition by i_manufact_id) avg_quarterly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and -ss_sold_date_sk = d_date_sk and -ss_store_sk = s_store_sk and -d_month_seq in (1185,1185+1,1185+2,1185+3,1185+4,1185+5,1185+6,1185+7,1185+8,1185+9,1185+10,1185+11) and -((i_category in ('Books','Children','Electronics') and -i_class in ('personal','portable','reference','self-help') and -i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) -or(i_category in ('Women','Music','Men') and -i_class in ('accessories','classical','fragrances','pants') and -i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manufact_id, d_qoy ) tmp1 -where case when avg_quarterly_sales > 0 - then abs (sum_sales - avg_quarterly_sales)/ avg_quarterly_sales - else null end > 0.1 -order by avg_quarterly_sales, - sum_sales, - i_manufact_id -limit 100; - --- end template query53.tpl query 80 in stream 9 --- start template query55.tpl query 81 in stream 9 -select /* TPC-DS query55.tpl 0.82 */ i_brand_id brand_id, i_brand brand, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=91 - and d_moy=11 - and d_year=1999 - group by i_brand, i_brand_id - order by ext_price desc, i_brand_id -limit 100 ; - --- end template query55.tpl query 81 in stream 9 --- start template query72.tpl query 82 in stream 9 -select /* TPC-DS query72.tpl 0.87 */ i_item_desc - ,w_warehouse_name - ,d1.d_week_seq - ,sum(case when p_promo_sk is null then 1 else 0 end) no_promo - ,sum(case when p_promo_sk is not null then 1 else 0 end) promo - ,count(*) total_cnt -from catalog_sales -join inventory on (cs_item_sk = inv_item_sk) -join warehouse on (w_warehouse_sk=inv_warehouse_sk) -join item on (i_item_sk = cs_item_sk) -join customer_demographics on (cs_bill_cdemo_sk = cd_demo_sk) -join household_demographics on (cs_bill_hdemo_sk = hd_demo_sk) -join date_dim d1 on (cs_sold_date_sk = d1.d_date_sk) -join date_dim d2 on (inv_date_sk = d2.d_date_sk) -join date_dim d3 on (cs_ship_date_sk = d3.d_date_sk) -left outer join promotion on (cs_promo_sk=p_promo_sk) -left outer join catalog_returns on (cr_item_sk = cs_item_sk and cr_order_number = cs_order_number) -where d1.d_week_seq = d2.d_week_seq - and inv_quantity_on_hand < cs_quantity - and d3.d_date > d1.d_date + 5 - and hd_buy_potential = '1001-5000' - and d1.d_year = 2000 - and cd_marital_status = 'W' -group by i_item_desc,w_warehouse_name,d1.d_week_seq -order by total_cnt desc, i_item_desc, w_warehouse_name, d_week_seq -limit 100; - --- end template query72.tpl query 82 in stream 9 --- start template query95.tpl query 83 in stream 9 -with /* TPC-DS query95.tpl 0.43 */ ws_wh as -(select ws1.ws_order_number,ws1.ws_warehouse_sk wh1,ws2.ws_warehouse_sk wh2 - from web_sales ws1,web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) - select - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2000-3-01' and - dateadd(day,60,cast('2000-3-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'KS' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and ws1.ws_order_number in (select ws_order_number - from ws_wh) -and ws1.ws_order_number in (select wr_order_number - from web_returns,ws_wh - where wr_order_number = ws_wh.ws_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query95.tpl query 83 in stream 9 --- start template query29.tpl query 84 in stream 9 -select /* TPC-DS query29.tpl 0.53 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,stddev_samp(ss_quantity) as store_sales_quantity - ,stddev_samp(sr_return_quantity) as store_returns_quantity - ,stddev_samp(cs_quantity) as catalog_sales_quantity - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 1999 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 4 + 3 - and d2.d_year = 1999 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_year in (1999,1999+1,1999+2) - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query29.tpl query 84 in stream 9 --- start template query64.tpl query 85 in stream 9 -with /* TPC-DS query64.tpl 0.20 */ cs_ui as - (select cs_item_sk - ,sum(cs_ext_list_price) as sale,sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit) as refund - from catalog_sales - ,catalog_returns - where cs_item_sk = cr_item_sk - and cs_order_number = cr_order_number - group by cs_item_sk - having sum(cs_ext_list_price)>2*sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit)), -cross_sales as - (select i_product_name product_name - ,i_item_sk item_sk - ,s_store_name store_name - ,s_zip store_zip - ,ad1.ca_street_number b_street_number - ,ad1.ca_street_name b_street_name - ,ad1.ca_city b_city - ,ad1.ca_zip b_zip - ,ad2.ca_street_number c_street_number - ,ad2.ca_street_name c_street_name - ,ad2.ca_city c_city - ,ad2.ca_zip c_zip - ,d1.d_year as syear - ,d2.d_year as fsyear - ,d3.d_year s2year - ,count(*) cnt - ,sum(ss_wholesale_cost) s1 - ,sum(ss_list_price) s2 - ,sum(ss_coupon_amt) s3 - FROM store_sales - ,store_returns - ,cs_ui - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,customer - ,customer_demographics cd1 - ,customer_demographics cd2 - ,promotion - ,household_demographics hd1 - ,household_demographics hd2 - ,customer_address ad1 - ,customer_address ad2 - ,income_band ib1 - ,income_band ib2 - ,item - WHERE ss_store_sk = s_store_sk AND - ss_sold_date_sk = d1.d_date_sk AND - ss_customer_sk = c_customer_sk AND - ss_cdemo_sk= cd1.cd_demo_sk AND - ss_hdemo_sk = hd1.hd_demo_sk AND - ss_addr_sk = ad1.ca_address_sk and - ss_item_sk = i_item_sk and - ss_item_sk = sr_item_sk and - ss_ticket_number = sr_ticket_number and - ss_item_sk = cs_ui.cs_item_sk and - c_current_cdemo_sk = cd2.cd_demo_sk AND - c_current_hdemo_sk = hd2.hd_demo_sk AND - c_current_addr_sk = ad2.ca_address_sk and - c_first_sales_date_sk = d2.d_date_sk and - c_first_shipto_date_sk = d3.d_date_sk and - ss_promo_sk = p_promo_sk and - hd1.hd_income_band_sk = ib1.ib_income_band_sk and - hd2.hd_income_band_sk = ib2.ib_income_band_sk and - cd1.cd_marital_status <> cd2.cd_marital_status and - i_color in ('maroon','dodger','lime','pink','yellow','tomato') and - i_current_price between 52 and 52 + 10 and - i_current_price between 52 + 1 and 52 + 15 -group by i_product_name - ,i_item_sk - ,s_store_name - ,s_zip - ,ad1.ca_street_number - ,ad1.ca_street_name - ,ad1.ca_city - ,ad1.ca_zip - ,ad2.ca_street_number - ,ad2.ca_street_name - ,ad2.ca_city - ,ad2.ca_zip - ,d1.d_year - ,d2.d_year - ,d3.d_year -) -select cs1.product_name - ,cs1.store_name - ,cs1.store_zip - ,cs1.b_street_number - ,cs1.b_street_name - ,cs1.b_city - ,cs1.b_zip - ,cs1.c_street_number - ,cs1.c_street_name - ,cs1.c_city - ,cs1.c_zip - ,cs1.syear - ,cs1.cnt - ,cs1.s1 as s11 - ,cs1.s2 as s21 - ,cs1.s3 as s31 - ,cs2.s1 as s12 - ,cs2.s2 as s22 - ,cs2.s3 as s32 - ,cs2.syear - ,cs2.cnt -from cross_sales cs1,cross_sales cs2 -where cs1.item_sk=cs2.item_sk and - cs1.syear = 2000 and - cs2.syear = 2000 + 1 and - cs2.cnt <= cs1.cnt and - cs1.store_name = cs2.store_name and - cs1.store_zip = cs2.store_zip -order by cs1.product_name - ,cs1.store_name - ,cs2.cnt - ,cs1.s1 - ,cs2.s1; - --- end template query64.tpl query 85 in stream 9 --- start template query93.tpl query 86 in stream 9 -select /* TPC-DS query93.tpl 0.52 */ ss_customer_sk - ,sum(act_sales) sumsales - from (select ss_item_sk - ,ss_ticket_number - ,ss_customer_sk - ,case when sr_return_quantity is not null then (ss_quantity-sr_return_quantity)*ss_sales_price - else (ss_quantity*ss_sales_price) end act_sales - from store_sales left outer join store_returns on (sr_item_sk = ss_item_sk - and sr_ticket_number = ss_ticket_number) - ,reason - where sr_reason_sk = r_reason_sk - and r_reason_desc = 'reason 40') t - group by ss_customer_sk - order by sumsales, ss_customer_sk -limit 100; - --- end template query93.tpl query 86 in stream 9 --- start template query56.tpl query 87 in stream 9 -with /* TPC-DS query56.tpl 0.83 */ ss as ( - select i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where i_item_id in (select - i_item_id -from item -where i_color in ('bisque','chiffon','lawn')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 3 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - cs as ( - select i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('bisque','chiffon','lawn')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 3 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - ws as ( - select i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('bisque','chiffon','lawn')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 3 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id) - select i_item_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by total_sales, - i_item_id - limit 100; - --- end template query56.tpl query 87 in stream 9 --- start template query97.tpl query 88 in stream 9 -with /* TPC-DS query97.tpl 0.38 */ ssci as ( -select ss_customer_sk customer_sk - ,ss_item_sk item_sk -from store_sales,date_dim -where ss_sold_date_sk = d_date_sk - and d_month_seq between 1212 and 1212 + 11 -group by ss_customer_sk - ,ss_item_sk), -csci as( - select cs_bill_customer_sk customer_sk - ,cs_item_sk item_sk -from catalog_sales,date_dim -where cs_sold_date_sk = d_date_sk - and d_month_seq between 1212 and 1212 + 11 -group by cs_bill_customer_sk - ,cs_item_sk) - select sum(case when ssci.customer_sk is not null and csci.customer_sk is null then 1 else 0 end) store_only - ,sum(case when ssci.customer_sk is null and csci.customer_sk is not null then 1 else 0 end) catalog_only - ,sum(case when ssci.customer_sk is not null and csci.customer_sk is not null then 1 else 0 end) store_and_catalog -from ssci full outer join csci on (ssci.customer_sk=csci.customer_sk - and ssci.item_sk = csci.item_sk) -limit 100; - --- end template query97.tpl query 88 in stream 9 --- start template query23.tpl query 89 in stream 9 -with /* TPC-DS query23.tpl 0.68 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (1999,1999+1,1999+2,1999+3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1999,1999+1,1999+2,1999+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * -from - max_store_sales)) - select sum(sales) - from (select cs_quantity*cs_list_price sales - from catalog_sales - ,date_dim - where d_year = 1999 - and d_moy = 6 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - union all - select ws_quantity*ws_list_price sales - from web_sales - ,date_dim - where d_year = 1999 - and d_moy = 6 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer)) - limit 100; -with /* TPC-DS query23.tpl 0.68 part2 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (1999,1999 + 1,1999 + 2,1999 + 3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1999,1999+1,1999+2,1999+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * - from max_store_sales)) - select c_last_name,c_first_name,sales - from (select c_last_name,c_first_name,sum(cs_quantity*cs_list_price) sales - from catalog_sales - ,customer - ,date_dim - where d_year = 1999 - and d_moy = 6 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and cs_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name - union all - select c_last_name,c_first_name,sum(ws_quantity*ws_list_price) sales - from web_sales - ,customer - ,date_dim - where d_year = 1999 - and d_moy = 6 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and ws_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name) - order by c_last_name,c_first_name,sales - limit 100; - --- end template query23.tpl query 89 in stream 9 --- start template query44.tpl query 90 in stream 9 -select /* TPC-DS query44.tpl 0.4 */ asceding.rnk, i1.i_product_name best_performing, i2.i_product_name worst_performing -from(select * - from (select item_sk,rank() over (order by rank_col asc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 110 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 110 - and ss_addr_sk is null - group by ss_store_sk))V1)V11 - where rnk < 11) asceding, - (select * - from (select item_sk,rank() over (order by rank_col desc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 110 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 110 - and ss_addr_sk is null - group by ss_store_sk))V2)V21 - where rnk < 11) descending, -item i1, -item i2 -where asceding.rnk = descending.rnk - and i1.i_item_sk=asceding.item_sk - and i2.i_item_sk=descending.item_sk -order by asceding.rnk -limit 100; - --- end template query44.tpl query 90 in stream 9 --- start template query91.tpl query 91 in stream 9 -select /* TPC-DS query91.tpl 0.13 */ - cc_call_center_id Call_Center, - cc_name Call_Center_Name, - cc_manager Manager, - sum(cr_net_loss) Returns_Loss -from - call_center, - catalog_returns, - date_dim, - customer, - customer_address, - customer_demographics, - household_demographics -where - cr_call_center_sk = cc_call_center_sk -and cr_returned_date_sk = d_date_sk -and cr_returning_customer_sk= c_customer_sk -and cd_demo_sk = c_current_cdemo_sk -and hd_demo_sk = c_current_hdemo_sk -and ca_address_sk = c_current_addr_sk -and d_year = 2001 -and d_moy = 12 -and ( (cd_marital_status = 'M' and cd_education_status = 'Unknown') - or(cd_marital_status = 'W' and cd_education_status = 'Advanced Degree')) -and hd_buy_potential like '0-500%' -and ca_gmt_offset = -7 -group by cc_call_center_id,cc_name,cc_manager,cd_marital_status,cd_education_status -order by sum(cr_net_loss) desc; - --- end template query91.tpl query 91 in stream 9 --- start template query49.tpl query 92 in stream 9 -select /* TPC-DS query49.tpl 0.48 */ channel, item, return_ratio, return_rank, currency_rank from - (select - 'web' as channel - ,web.item - ,web.return_ratio - ,web.return_rank - ,web.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select ws.ws_item_sk as item - ,(cast(sum(coalesce(wr.wr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(wr.wr_return_amt,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - web_sales ws left outer join web_returns wr - on (ws.ws_order_number = wr.wr_order_number and - ws.ws_item_sk = wr.wr_item_sk) - ,date_dim - where - wr.wr_return_amt > 10000 - and ws.ws_net_profit > 1 - and ws.ws_net_paid > 0 - and ws.ws_quantity > 0 - and ws_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 11 - group by ws.ws_item_sk - ) in_web - ) web - where - ( - web.return_rank <= 10 - or - web.currency_rank <= 10 - ) - union - select - 'catalog' as channel - ,catalog.item - ,catalog.return_ratio - ,catalog.return_rank - ,catalog.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select - cs.cs_item_sk as item - ,(cast(sum(coalesce(cr.cr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(cr.cr_return_amount,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - catalog_sales cs left outer join catalog_returns cr - on (cs.cs_order_number = cr.cr_order_number and - cs.cs_item_sk = cr.cr_item_sk) - ,date_dim - where - cr.cr_return_amount > 10000 - and cs.cs_net_profit > 1 - and cs.cs_net_paid > 0 - and cs.cs_quantity > 0 - and cs_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 11 - group by cs.cs_item_sk - ) in_cat - ) catalog - where - ( - catalog.return_rank <= 10 - or - catalog.currency_rank <=10 - ) - union - select - 'store' as channel - ,store.item - ,store.return_ratio - ,store.return_rank - ,store.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select sts.ss_item_sk as item - ,(cast(sum(coalesce(sr.sr_return_quantity,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(sr.sr_return_amt,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - store_sales sts left outer join store_returns sr - on (sts.ss_ticket_number = sr.sr_ticket_number and sts.ss_item_sk = sr.sr_item_sk) - ,date_dim - where - sr.sr_return_amt > 10000 - and sts.ss_net_profit > 1 - and sts.ss_net_paid > 0 - and sts.ss_quantity > 0 - and ss_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 11 - group by sts.ss_item_sk - ) in_store - ) store - where ( - store.return_rank <= 10 - or - store.currency_rank <= 10 - ) - ) - order by 1,4,5,2 - limit 100; - --- end template query49.tpl query 92 in stream 9 --- start template query76.tpl query 93 in stream 9 -select /* TPC-DS query76.tpl 0.99 */ channel, col_name, d_year, d_qoy, i_category, COUNT(*) sales_cnt, SUM(ext_sales_price) sales_amt FROM ( - SELECT 'store' as channel, 'ss_promo_sk' col_name, d_year, d_qoy, i_category, ss_ext_sales_price ext_sales_price - FROM store_sales, item, date_dim - WHERE ss_promo_sk IS NULL - AND ss_sold_date_sk=d_date_sk - AND ss_item_sk=i_item_sk - UNION ALL - SELECT 'web' as channel, 'ws_bill_customer_sk' col_name, d_year, d_qoy, i_category, ws_ext_sales_price ext_sales_price - FROM web_sales, item, date_dim - WHERE ws_bill_customer_sk IS NULL - AND ws_sold_date_sk=d_date_sk - AND ws_item_sk=i_item_sk - UNION ALL - SELECT 'catalog' as channel, 'cs_ship_hdemo_sk' col_name, d_year, d_qoy, i_category, cs_ext_sales_price ext_sales_price - FROM catalog_sales, item, date_dim - WHERE cs_ship_hdemo_sk IS NULL - AND cs_sold_date_sk=d_date_sk - AND cs_item_sk=i_item_sk) foo -GROUP BY channel, col_name, d_year, d_qoy, i_category -ORDER BY channel, col_name, d_year, d_qoy, i_category -limit 100; - --- end template query76.tpl query 93 in stream 9 --- start template query63.tpl query 94 in stream 9 -select /* TPC-DS query63.tpl 0.27 */ * -from (select i_manager_id - ,sum(ss_sales_price) sum_sales - ,avg(sum(ss_sales_price)) over (partition by i_manager_id) avg_monthly_sales - from item - ,store_sales - ,date_dim - ,store - where ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and d_month_seq in (1177,1177+1,1177+2,1177+3,1177+4,1177+5,1177+6,1177+7,1177+8,1177+9,1177+10,1177+11) - and (( i_category in ('Books','Children','Electronics') - and i_class in ('personal','portable','reference','self-help') - and i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) - or( i_category in ('Women','Music','Men') - and i_class in ('accessories','classical','fragrances','pants') - and i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manager_id, d_moy) tmp1 -where case when avg_monthly_sales > 0 then abs (sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 -order by i_manager_id - ,avg_monthly_sales - ,sum_sales -limit 100; - --- end template query63.tpl query 94 in stream 9 --- start template query45.tpl query 95 in stream 9 -select /* TPC-DS query45.tpl 0.18 */ ca_zip, ca_state, sum(ws_sales_price) - from web_sales, customer, customer_address, date_dim, item - where ws_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ws_item_sk = i_item_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', '85392', '85460', '80348', '81792') - or - i_item_id in (select i_item_id - from item - where i_item_sk in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29) - ) - ) - and ws_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 1999 - group by ca_zip, ca_state - order by ca_zip, ca_state - limit 100; - --- end template query45.tpl query 95 in stream 9 --- start template query43.tpl query 96 in stream 9 -select /* TPC-DS query43.tpl 0.15 */ s_store_name, s_store_id, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from date_dim, store_sales, store - where d_date_sk = ss_sold_date_sk and - s_store_sk = ss_store_sk and - s_gmt_offset = -6 and - d_year = 2001 - group by s_store_name, s_store_id - order by s_store_name, s_store_id,sun_sales,mon_sales,tue_sales,wed_sales,thu_sales,fri_sales,sat_sales - limit 100; - --- end template query43.tpl query 96 in stream 9 --- start template query85.tpl query 97 in stream 9 -select /* TPC-DS query85.tpl 0.33 */ substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) - from web_sales, web_returns, web_page, customer_demographics cd1, - customer_demographics cd2, customer_address, date_dim, reason - where ws_web_page_sk = wp_web_page_sk - and ws_item_sk = wr_item_sk - and ws_order_number = wr_order_number - and ws_sold_date_sk = d_date_sk and d_year = 2002 - and cd1.cd_demo_sk = wr_refunded_cdemo_sk - and cd2.cd_demo_sk = wr_returning_cdemo_sk - and ca_address_sk = wr_refunded_addr_sk - and r_reason_sk = wr_reason_sk - and - ( - ( - cd1.cd_marital_status = 'U' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'College' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 100.00 and 150.00 - ) - or - ( - cd1.cd_marital_status = 'S' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Primary' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 50.00 and 100.00 - ) - or - ( - cd1.cd_marital_status = 'W' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Secondary' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ca_country = 'United States' - and - ca_state in ('ID', 'VA', 'MO') - and ws_net_profit between 100 and 200 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('WV', 'MN', 'TX') - and ws_net_profit between 150 and 300 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('OK', 'IN', 'OH') - and ws_net_profit between 50 and 250 - ) - ) -group by r_reason_desc -order by substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) -limit 100; - --- end template query85.tpl query 97 in stream 9 --- start template query37.tpl query 98 in stream 9 -select /* TPC-DS query37.tpl 0.31 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, catalog_sales - where i_current_price between 37 and 37 + 30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('2001-02-16' as date) and dateadd(day,60,cast('2001-02-16' as date)) - and i_manufact_id in (765,927,842,847) - and inv_quantity_on_hand between 100 and 500 - and cs_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query37.tpl query 98 in stream 9 --- start template query8.tpl query 99 in stream 9 -select /* TPC-DS query8.tpl 0.63 */ s_store_name - ,sum(ss_net_profit) - from store_sales - ,date_dim - ,store, - (select ca_zip - from ( - SELECT substring(ca_zip,1,5) ca_zip - FROM customer_address - WHERE substring(ca_zip,1,5) IN ( - '78878','34500','84987','86569','94793','71605', - '98827','47283','92580','59573','95652', - '74329','56608','68435','52193','80952', - '22590','99459','80804','34648','21116', - '18394','14071','24194','26623','43965', - '68354','43032','23555','51854','81343', - '85148','70469','73760','42263','98896', - '58293','52264','68251','55329','13708', - '88639','33685','30738','97852','30580', - '45743','84110','61323','99723','69721', - '11638','69680','70162','55607','62112', - '28484','73848','11939','90222','20087', - '39337','48876','50958','64382','97029', - '86679','79851','15616','17120','12847', - '17573','46992','94634','29388','76845', - '94967','12023','36243','43066','90255', - '87383','88044','85187','64972','64323', - '48862','67442','56526','79416','30653', - '56855','98476','96855','62770','93096', - '92559','74114','68104','99145','61657', - '27304','54386','79848','17572','63132', - '53060','10150','16232','72524','92284', - '71803','39084','72403','71917','67887', - '78145','51155','10834','60454','85959', - '46406','67623','35740','39209','90047', - '74915','45552','20062','99660','54890', - '45443','97957','85545','89373','61937', - '41154','82565','35745','38789','19891', - '19316','38746','35299','26554','36977', - '45114','81126','63142','52111','64932', - '79810','79990','40061','75619','53383', - '27903','38274','58014','80942','36297', - '50806','40087','98539','62288','92780', - '31904','16154','72579','88956','18701', - '86805','25140','16883','94163','95507', - '53049','42061','15172','30493','79434', - '11668','95695','15870','14641','79364', - '47282','83796','78636','84397','21259', - '31140','47052','41165','62015','51344', - '79087','78450','64043','47432','15981', - '16715','20427','11805','94262','76679', - '99634','53620','58165','51510','15989', - '82995','19723','66947','25346','46919', - '65269','19856','77307','90914','35903', - '85680','80550','58068','41423','62491', - '15557','32780','39935','57069','69923', - '13734','63506','98390','43891','89783', - '69545','87905','21992','64631','77226', - '70916','85104','87322','63625','61649', - '81390','60336','13523','80745','26957', - '10068','67758','46333','15603','94542', - '10469','13065','51610','19296','76402', - '73182','11224','23965','80689','73234', - '26361','69305','36929','41766','48527', - '55158','13126','53603','40047','65059', - '73130','96306','57117','82001','68245', - '87872','56428','70938','64192','81106', - '39703','41820','45726','84596','98726', - '80423','34576','60631','90669','57396', - '52203','84880','32049','13405','68610', - '99127','34163','11398','74548','29543', - '13762','77093','51167','93176','99360', - '86270','20708','95930','91977','26388', - '75311','64114','35979','61017','74481', - '21979','58125','20637','31187','11057', - '25786','78279','27894','90304','76161', - '32603','81831','33703','49798','26334', - '54893','80601','35442','29336','33125', - '85899','27052','36099','69833','59870', - '25128','61288','64162','15380','46033', - '76234','43027','86410','51883','64033', - '25251','41370','96220','94008','24159', - '68760','36866','68252','96432','72809', - '23739','91783','91584','79352','14693', - '19970','18660','30279','47471','81537', - '57648','81562','82205','25660','42253', - '51096','96266','84967','17525','81285', - '78491','49943','86014','49287','51390', - '53171','76632','98930','21105','95034', - '69459','13545','14864','62172') - intersect - select ca_zip - from (SELECT substring(ca_zip,1,5) ca_zip,count(*) cnt - FROM customer_address, customer - WHERE ca_address_sk = c_current_addr_sk and - c_preferred_cust_flag='Y' - group by ca_zip - having count(*) > 10)A1)A2) V1 - where ss_store_sk = s_store_sk - and ss_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 1998 - and (substring(s_zip,1,2) = substring(V1.ca_zip,1,2)) - group by s_store_name - order by s_store_name - limit 100; - --- end template query8.tpl query 99 in stream 9 diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/30TB/ddl.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/30TB/ddl.sql deleted file mode 100644 index d9a3da4d..00000000 --- a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/30TB/ddl.sql +++ /dev/null @@ -1,620 +0,0 @@ -create table dbgen_version -( - dv_version varchar(32), - dv_create_date date , - dv_create_time timestamp, - dv_cmdline_args varchar(200) -); - -create table customer_address -( - ca_address_sk int4 not null , - ca_address_id char(16) not null , - ca_street_number char(10) , - ca_street_name varchar(60) , - ca_street_type char(15) , - ca_suite_number char(10) , - ca_city varchar(60) , - ca_county varchar(30) , - ca_state char(2) , - ca_zip char(10) , - ca_country varchar(20) , - ca_gmt_offset numeric(5,2) , - ca_location_type char(20) - ,primary key (ca_address_sk) -) distkey(ca_address_sk); - -create table customer_demographics -( - cd_demo_sk int4 not null , - cd_gender char(1) , - cd_marital_status char(1) , - cd_education_status char(20) , - cd_purchase_estimate int4 , - cd_credit_rating char(10) , - cd_dep_count int4 , - cd_dep_employed_count int4 , - cd_dep_college_count int4 - ,primary key (cd_demo_sk) -)distkey (cd_demo_sk); - -create table date_dim -( - d_date_sk integer not null, - d_date_id char(16) not null, - d_date date, - d_month_seq integer , - d_week_seq integer , - d_quarter_seq integer , - d_year integer , - d_dow integer , - d_moy integer , - d_dom integer , - d_qoy integer , - d_fy_year integer , - d_fy_quarter_seq integer , - d_fy_week_seq integer , - d_day_name char(9) , - d_quarter_name char(6) , - d_holiday char(1) , - d_weekend char(1) , - d_following_holiday char(1) , - d_first_dom integer , - d_last_dom integer , - d_same_day_ly integer , - d_same_day_lq integer , - d_current_day char(1) , - d_current_week char(1) , - d_current_month char(1) , - d_current_quarter char(1) , - d_current_year char(1) , - primary key (d_date_sk) -) diststyle all; - -create table warehouse -( - w_warehouse_sk integer not null, - w_warehouse_id char(16) not null, - w_warehouse_name varchar(20) , - w_warehouse_sq_ft integer , - w_street_number char(10) , - w_street_name varchar(60) , - w_street_type char(15) , - w_suite_number char(10) , - w_city varchar(60) , - w_county varchar(30) , - w_state char(2) , - w_zip char(10) , - w_country varchar(20) , - w_gmt_offset decimal(5,2) , - primary key (w_warehouse_sk) -) diststyle all; - -create table ship_mode -( - sm_ship_mode_sk integer not null, - sm_ship_mode_id char(16) not null, - sm_type char(30) , - sm_code char(10) , - sm_carrier char(20) , - sm_contract char(20) , - primary key (sm_ship_mode_sk) -) diststyle all; - -create table time_dim -( - t_time_sk integer not null, - t_time_id char(16) not null, - t_time integer , - t_hour integer , - t_minute integer , - t_second integer , - t_am_pm char(2) , - t_shift char(20) , - t_sub_shift char(20) , - t_meal_time char(20) , - primary key (t_time_sk) -) diststyle all; - -create table reason -( - r_reason_sk integer not null, - r_reason_id char(16) not null, - r_reason_desc char(100) , - primary key (r_reason_sk) -) diststyle all ; - -create table income_band -( - ib_income_band_sk integer not null, - ib_lower_bound integer , - ib_upper_bound integer , - primary key (ib_income_band_sk) -) diststyle all; - -create table item -( -i_item_sk int4 not null, - i_item_id char(16) not null , - i_rec_start_date date, - i_rec_end_date date, - i_item_desc varchar(200) , - i_current_price numeric(7,2), - i_wholesale_cost numeric(7,2), - i_brand_id int4, - i_brand char(50) , - i_class_id int4, - i_class char(50) , - i_category_id int4, - i_category char(50) , - i_manufact_id int4, - i_manufact char(50) , - i_size char(20) , - i_formulation char(20) , - i_color char(20) , - i_units char(10), - i_container char(10), - i_manager_id int4, - i_product_name char(50) - ,primary key (i_item_sk) -) distkey(i_item_sk) sortkey(i_category); - -create table store -( - s_store_sk integer not null, - s_store_id char(16) not null, - s_rec_start_date date, - s_rec_end_date date, - s_closed_date_sk integer , - s_store_name varchar(50) , - s_number_employees integer , - s_floor_space integer , - s_hours char(20) , - s_manager varchar(40) , - s_market_id integer , - s_geography_class varchar(100) , - s_market_desc varchar(100) , - s_market_manager varchar(40) , - s_division_id integer , - s_division_name varchar(50) , - s_company_id integer , - s_company_name varchar(50) , - s_street_number varchar(10) , - s_street_name varchar(60) , - s_street_type char(15) , - s_suite_number char(10) , - s_city varchar(60) , - s_county varchar(30) , - s_state char(2) , - s_zip char(10) , - s_country varchar(20) , - s_gmt_offset decimal(5,2) , - s_tax_precentage decimal(5,2) , - primary key (s_store_sk) -) diststyle all; - -create table call_center -( - cc_call_center_sk integer not null, - cc_call_center_id char(16) not null, - cc_rec_start_date date, - cc_rec_end_date date, - cc_closed_date_sk integer , - cc_open_date_sk integer , - cc_name varchar(50) , - cc_class varchar(50) , - cc_employees integer , - cc_sq_ft integer , - cc_hours char(20) , - cc_manager varchar(40) , - cc_mkt_id integer , - cc_mkt_class char(50) , - cc_mkt_desc varchar(100) , - cc_market_manager varchar(40) , - cc_division integer , - cc_division_name varchar(50) , - cc_company integer , - cc_company_name char(50) , - cc_street_number char(10) , - cc_street_name varchar(60) , - cc_street_type char(15) , - cc_suite_number char(10) , - cc_city varchar(60) , - cc_county varchar(30) , - cc_state char(2) , - cc_zip char(10) , - cc_country varchar(20) , - cc_gmt_offset decimal(5,2) , - cc_tax_percentage decimal(5,2) , - primary key (cc_call_center_sk) -) diststyle all; - -create table customer -( - c_customer_sk int4 not null , - c_customer_id char(16) not null , - c_current_cdemo_sk int4 , - c_current_hdemo_sk int4 , - c_current_addr_sk int4 , - c_first_shipto_date_sk int4 , - c_first_sales_date_sk int4 , - c_salutation char(10) , - c_first_name char(20) , - c_last_name char(30) , - c_preferred_cust_flag char(1) , - c_birth_day int4 , - c_birth_month int4 , - c_birth_year int4 , - c_birth_country varchar(20) , - c_login char(13) , - c_email_address char(50) , - c_last_review_date_sk int4 , - primary key (c_customer_sk) -) distkey(c_customer_sk); - -create table web_site -( - web_site_sk integer not null, - web_site_id char(16) not null, - web_rec_start_date date, - web_rec_end_date date, - web_name varchar(50) , - web_open_date_sk integer , - web_close_date_sk integer , - web_class varchar(50) , - web_manager varchar(40) , - web_mkt_id integer , - web_mkt_class varchar(50) , - web_mkt_desc varchar(100) , - web_market_manager varchar(40) , - web_company_id integer , - web_company_name char(50) , - web_street_number char(10) , - web_street_name varchar(60) , - web_street_type char(15) , - web_suite_number char(10) , - web_city varchar(60) , - web_county varchar(30) , - web_state char(2) , - web_zip char(10) , - web_country varchar(20) , - web_gmt_offset decimal(5,2) , - web_tax_percentage decimal(5,2) , - primary key (web_site_sk) -) diststyle all; - -create table store_returns -( -sr_returned_date_sk int4 , - sr_return_time_sk int4 , - sr_item_sk int4 not null , - sr_customer_sk int4 , - sr_cdemo_sk int4 , - sr_hdemo_sk int4 , - sr_addr_sk int4 , - sr_store_sk int4 , - sr_reason_sk int4 , - sr_ticket_number int8 not null, - sr_return_quantity int4 , - sr_return_amt numeric(7,2) , - sr_return_tax numeric(7,2) , - sr_return_amt_inc_tax numeric(7,2) , - sr_fee numeric(7,2) , - sr_return_ship_cost numeric(7,2) , - sr_refunded_cash numeric(7,2) , - sr_reversed_charge numeric(7,2) , - sr_store_credit numeric(7,2) , - sr_net_loss numeric(7,2) - ,primary key (sr_item_sk, sr_ticket_number) -) distkey(sr_item_sk) sortkey(sr_returned_date_sk); - -create table household_demographics -( - hd_demo_sk integer not null, - hd_income_band_sk integer , - hd_buy_potential char(15) , - hd_dep_count integer , - hd_vehicle_count integer , - primary key (hd_demo_sk) -) diststyle all; - -create table web_page -( - wp_web_page_sk integer not null, - wp_web_page_id char(16) not null, - wp_rec_start_date date, - wp_rec_end_date date, - wp_creation_date_sk integer , - wp_access_date_sk integer , - wp_autogen_flag char(1) , - wp_customer_sk integer , - wp_url varchar(100) , - wp_type char(50) , - wp_char_count integer , - wp_link_count integer , - wp_image_count integer , - wp_max_ad_count integer , - primary key (wp_web_page_sk) -) diststyle all; - -create table promotion -( - p_promo_sk integer not null, - p_promo_id char(16) not null, - p_start_date_sk integer , - p_end_date_sk integer , - p_item_sk integer , - p_cost decimal(15,2) , - p_response_target integer , - p_promo_name char(50) , - p_channel_dmail char(1) , - p_channel_email char(1) , - p_channel_catalog char(1) , - p_channel_tv char(1) , - p_channel_radio char(1) , - p_channel_press char(1) , - p_channel_event char(1) , - p_channel_demo char(1) , - p_channel_details varchar(100) , - p_purpose char(15) , - p_discount_active char(1) , - primary key (p_promo_sk) -) diststyle all; - -create table catalog_page -( - cp_catalog_page_sk integer not null, - cp_catalog_page_id char(16) not null, - cp_start_date_sk integer , - cp_end_date_sk integer , - cp_department varchar(50) , - cp_catalog_number integer , - cp_catalog_page_number integer , - cp_description varchar(100) , - cp_type varchar(100) , - primary key (cp_catalog_page_sk) -) diststyle all; - -create table inventory -( - inv_date_sk int4 not null , - inv_item_sk int4 not null , - inv_warehouse_sk int4 not null , - inv_quantity_on_hand int4 - ,primary key (inv_date_sk, inv_item_sk, inv_warehouse_sk) -) distkey(inv_item_sk) sortkey(inv_date_sk); - -create table catalog_returns -( - cr_returned_date_sk int4 , - cr_returned_time_sk int4 , - cr_item_sk int4 not null , - cr_refunded_customer_sk int4 , - cr_refunded_cdemo_sk int4 , - cr_refunded_hdemo_sk int4 , - cr_refunded_addr_sk int4 , - cr_returning_customer_sk int4 , - cr_returning_cdemo_sk int4 , - cr_returning_hdemo_sk int4 , - cr_returning_addr_sk int4 , - cr_call_center_sk int4 , - cr_catalog_page_sk int4 , - cr_ship_mode_sk int4 , - cr_warehouse_sk int4 , - cr_reason_sk int4 , - cr_order_number int8 not null, - cr_return_quantity int4 , - cr_return_amount numeric(7,2) , - cr_return_tax numeric(7,2) , - cr_return_amt_inc_tax numeric(7,2) , - cr_fee numeric(7,2) , - cr_return_ship_cost numeric(7,2) , - cr_refunded_cash numeric(7,2) , - cr_reversed_charge numeric(7,2) , - cr_store_credit numeric(7,2) , - cr_net_loss numeric(7,2) - ,primary key (cr_item_sk, cr_order_number) -) distkey(cr_item_sk) sortkey(cr_returned_date_sk); - -create table web_returns -( -wr_returned_date_sk int4 , - wr_returned_time_sk int4 , - wr_item_sk int4 not null , - wr_refunded_customer_sk int4 , - wr_refunded_cdemo_sk int4 , - wr_refunded_hdemo_sk int4 , - wr_refunded_addr_sk int4 , - wr_returning_customer_sk int4 , - wr_returning_cdemo_sk int4 , - wr_returning_hdemo_sk int4 , - wr_returning_addr_sk int4 , - wr_web_page_sk int4 , - wr_reason_sk int4 , - wr_order_number int8 not null, - wr_return_quantity int4 , - wr_return_amt numeric(7,2) , - wr_return_tax numeric(7,2) , - wr_return_amt_inc_tax numeric(7,2) , - wr_fee numeric(7,2) , - wr_return_ship_cost numeric(7,2) , - wr_refunded_cash numeric(7,2) , - wr_reversed_charge numeric(7,2) , - wr_account_credit numeric(7,2) , - wr_net_loss numeric(7,2) - ,primary key (wr_item_sk, wr_order_number) -) distkey(wr_order_number) sortkey(wr_returned_date_sk); - -create table web_sales -( - ws_sold_date_sk int4 , - ws_sold_time_sk int4 , - ws_ship_date_sk int4 , - ws_item_sk int4 not null , - ws_bill_customer_sk int4 , - ws_bill_cdemo_sk int4 , - ws_bill_hdemo_sk int4 , - ws_bill_addr_sk int4 , - ws_ship_customer_sk int4 , - ws_ship_cdemo_sk int4 , - ws_ship_hdemo_sk int4 , - ws_ship_addr_sk int4 , - ws_web_page_sk int4 , - ws_web_site_sk int4 , - ws_ship_mode_sk int4 , - ws_warehouse_sk int4 , - ws_promo_sk int4 , - ws_order_number int8 not null, - ws_quantity int4 , - ws_wholesale_cost numeric(7,2) , - ws_list_price numeric(7,2) , - ws_sales_price numeric(7,2) , - ws_ext_discount_amt numeric(7,2) , - ws_ext_sales_price numeric(7,2) , - ws_ext_wholesale_cost numeric(7,2) , - ws_ext_list_price numeric(7,2) , - ws_ext_tax numeric(7,2) , - ws_coupon_amt numeric(7,2) , - ws_ext_ship_cost numeric(7,2) , - ws_net_paid numeric(7,2) , - ws_net_paid_inc_tax numeric(7,2) , - ws_net_paid_inc_ship numeric(7,2) , - ws_net_paid_inc_ship_tax numeric(7,2) , - ws_net_profit numeric(7,2) - ,primary key (ws_item_sk, ws_order_number) -) distkey(ws_order_number) sortkey(ws_sold_date_sk); - -create table catalog_sales -( - cs_sold_date_sk int4 , - cs_sold_time_sk int4 , - cs_ship_date_sk int4 , - cs_bill_customer_sk int4 , - cs_bill_cdemo_sk int4 , - cs_bill_hdemo_sk int4 , - cs_bill_addr_sk int4 , - cs_ship_customer_sk int4 , - cs_ship_cdemo_sk int4 , - cs_ship_hdemo_sk int4 , - cs_ship_addr_sk int4 , - cs_call_center_sk int4 , - cs_catalog_page_sk int4 , - cs_ship_mode_sk int4 , - cs_warehouse_sk int4 , - cs_item_sk int4 not null , - cs_promo_sk int4 , - cs_order_number int8 not null , - cs_quantity int4 , - cs_wholesale_cost numeric(7,2) , - cs_list_price numeric(7,2) , - cs_sales_price numeric(7,2) , - cs_ext_discount_amt numeric(7,2) , - cs_ext_sales_price numeric(7,2) , - cs_ext_wholesale_cost numeric(7,2) , - cs_ext_list_price numeric(7,2) , - cs_ext_tax numeric(7,2) , - cs_coupon_amt numeric(7,2) , - cs_ext_ship_cost numeric(7,2) , - cs_net_paid numeric(7,2) , - cs_net_paid_inc_tax numeric(7,2) , - cs_net_paid_inc_ship numeric(7,2) , - cs_net_paid_inc_ship_tax numeric(7,2) , - cs_net_profit numeric(7,2) - ,primary key (cs_item_sk, cs_order_number) -) distkey(cs_item_sk) sortkey(cs_sold_date_sk); - -create table store_sales -( -ss_sold_date_sk int4 , - ss_sold_time_sk int4 , - ss_item_sk int4 not null , - ss_customer_sk int4 , - ss_cdemo_sk int4 , - ss_hdemo_sk int4 , - ss_addr_sk int4 , - ss_store_sk int4 , - ss_promo_sk int4 , - ss_ticket_number int8 not null, - ss_quantity int4 , - ss_wholesale_cost numeric(7,2) , - ss_list_price numeric(7,2) , - ss_sales_price numeric(7,2) , - ss_ext_discount_amt numeric(7,2) , - ss_ext_sales_price numeric(7,2) , - ss_ext_wholesale_cost numeric(7,2) , - ss_ext_list_price numeric(7,2) , - ss_ext_tax numeric(7,2) , - ss_coupon_amt numeric(7,2) , - ss_net_paid numeric(7,2) , - ss_net_paid_inc_tax numeric(7,2) , - ss_net_profit numeric(7,2) - ,primary key (ss_item_sk, ss_ticket_number) -) distkey(ss_item_sk) sortkey(ss_sold_date_sk); - -/* - Text files needed to load test data under s3://redshift-downloads/TPC-DS/2.13/30TB are publicly available. - - To load the sample data, you must provide authentication for your cluster to access Amazon S3 on your behalf. - - You can provide authentication by referencing an IAM role that you have created. You can set an IAM_Role as the default for your cluster or you can directly provide the ARN of an IAM_Role. - For more information https://docs.aws.amazon.com/redshift/latest/mgmt/authorizing-redshift-service.html - - The COPY commands include a placeholder for IAM_Role, in this code IAM_Role clause is set to use the default IAM_Role. If your cluster does not have a IAM_Role set as default then please follow the instructions provided here: - - https://docs.aws.amazon.com/redshift/latest/mgmt/default-iam-role.html - - For more information check samples in https://docs.aws.amazon.com/redshift/latest/gsg/rs-gsg-create-sample-db.html - - **Note** another option to provide IAM_Role is to provide IAM_Role ARN in IAM_Role clause. For example - copy call_center from 's3://redshift-downloads/TPC-DS/2.13/30TB/call_center/' IAM_Role 'Replace text inside the quotes with Redshift cluster IAM_Role ARN' gzip delimiter '|' EMPTYASNULL region 'us-east-1'; -*/ - -copy call_center from 's3://redshift-downloads/TPC-DS/2.13/30TB/call_center/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1'; -copy catalog_page from 's3://redshift-downloads/TPC-DS/2.13/30TB/catalog_page/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1'; -copy catalog_returns from 's3://redshift-downloads/TPC-DS/2.13/30TB/catalog_returns/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1'; -copy catalog_sales from 's3://redshift-downloads/TPC-DS/2.13/30TB/catalog_sales/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1'; -copy customer_address from 's3://redshift-downloads/TPC-DS/2.13/30TB/customer_address/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1'; -copy customer_demographics from 's3://redshift-downloads/TPC-DS/2.13/30TB/customer_demographics/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1'; -copy customer from 's3://redshift-downloads/TPC-DS/2.13/30TB/customer/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1'; -copy date_dim from 's3://redshift-downloads/TPC-DS/2.13/30TB/date_dim/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1'; -copy household_demographics from 's3://redshift-downloads/TPC-DS/2.13/30TB/household_demographics/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1'; -copy income_band from 's3://redshift-downloads/TPC-DS/2.13/30TB/income_band/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1'; -copy inventory from 's3://redshift-downloads/TPC-DS/2.13/30TB/inventory/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1'; -copy item from 's3://redshift-downloads/TPC-DS/2.13/30TB/item/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1'; -copy promotion from 's3://redshift-downloads/TPC-DS/2.13/30TB/promotion/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1'; -copy reason from 's3://redshift-downloads/TPC-DS/2.13/30TB/reason/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1'; -copy ship_mode from 's3://redshift-downloads/TPC-DS/2.13/30TB/ship_mode/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1'; -copy store from 's3://redshift-downloads/TPC-DS/2.13/30TB/store/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1'; -copy store_returns from 's3://redshift-downloads/TPC-DS/2.13/30TB/store_returns/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1'; -copy store_sales from 's3://redshift-downloads/TPC-DS/2.13/30TB/store_sales/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1'; -copy time_dim from 's3://redshift-downloads/TPC-DS/2.13/30TB/time_dim/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1'; -copy warehouse from 's3://redshift-downloads/TPC-DS/2.13/30TB/warehouse/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1'; -copy web_page from 's3://redshift-downloads/TPC-DS/2.13/30TB/web_page/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1'; -copy web_returns from 's3://redshift-downloads/TPC-DS/2.13/30TB/web_returns/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1'; -copy web_sales from 's3://redshift-downloads/TPC-DS/2.13/30TB/web_sales/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1'; -copy web_site from 's3://redshift-downloads/TPC-DS/2.13/30TB/web_site/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1'; - -select count(*) from call_center; -- 60 -select count(*) from catalog_page; -- 46000 -select count(*) from catalog_returns; -- 4322178294 -select count(*) from catalog_sales; -- 43219134288 -select count(*) from customer; -- 80000000 -select count(*) from customer_address; -- 40000000 -select count(*) from customer_demographics; -- 1920800 -select count(*) from date_dim; -- 73049 -select count(*) from household_demographics; -- 7200 -select count(*) from income_band; -- 20 -select count(*) from inventory; -- 1627857000 -select count(*) from item; -- 462000 -select count(*) from promotion; -- 2300 -select count(*) from reason; -- 72 -select count(*) from ship_mode; -- 20 -select count(*) from store; -- 1704 -select count(*) from store_returns; -- 8632366679 -select count(*) from store_sales; -- 86414817969 -select count(*) from time_dim; -- 86400 -select count(*) from warehouse; -- 27 -select count(*) from web_page; -- 4602 -select count(*) from web_returns; -- 2160007345 -select count(*) from web_sales; -- 21600036511 -select count(*) from web_site; -- 84 diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/30TB/queries/query_0.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/30TB/queries/query_0.sql deleted file mode 100644 index 7a68e585..00000000 --- a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/30TB/queries/query_0.sql +++ /dev/null @@ -1,5027 +0,0 @@ --- start template query96.tpl query 1 in stream 0 -select /* TPC-DS query96.tpl 0.1 */ count(*) -from store_sales - ,household_demographics - ,time_dim, store -where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and household_demographics.hd_dep_count = 5 - and store.s_store_name = 'ese' -order by count(*) -limit 100; - --- end template query96.tpl query 1 in stream 0 --- start template query7.tpl query 2 in stream 0 -select /* TPC-DS query7.tpl 0.2 */ i_item_id, - avg(ss_quantity) agg1, - avg(ss_list_price) agg2, - avg(ss_coupon_amt) agg3, - avg(ss_sales_price) agg4 - from store_sales, customer_demographics, date_dim, item, promotion - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_cdemo_sk = cd_demo_sk and - ss_promo_sk = p_promo_sk and - cd_gender = 'M' and - cd_marital_status = 'M' and - cd_education_status = '4 yr Degree' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 2001 - group by i_item_id - order by i_item_id - limit 100; - --- end template query7.tpl query 2 in stream 0 --- start template query75.tpl query 3 in stream 0 -WITH /* TPC-DS query75.tpl 0.3 */ all_sales AS ( - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,SUM(sales_cnt) AS sales_cnt - ,SUM(sales_amt) AS sales_amt - FROM (SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,cs_quantity - COALESCE(cr_return_quantity,0) AS sales_cnt - ,cs_ext_sales_price - COALESCE(cr_return_amount,0.0) AS sales_amt - FROM catalog_sales JOIN item ON i_item_sk=cs_item_sk - JOIN date_dim ON d_date_sk=cs_sold_date_sk - LEFT JOIN catalog_returns ON (cs_order_number=cr_order_number - AND cs_item_sk=cr_item_sk) - WHERE i_category='Shoes' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ss_quantity - COALESCE(sr_return_quantity,0) AS sales_cnt - ,ss_ext_sales_price - COALESCE(sr_return_amt,0.0) AS sales_amt - FROM store_sales JOIN item ON i_item_sk=ss_item_sk - JOIN date_dim ON d_date_sk=ss_sold_date_sk - LEFT JOIN store_returns ON (ss_ticket_number=sr_ticket_number - AND ss_item_sk=sr_item_sk) - WHERE i_category='Shoes' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ws_quantity - COALESCE(wr_return_quantity,0) AS sales_cnt - ,ws_ext_sales_price - COALESCE(wr_return_amt,0.0) AS sales_amt - FROM web_sales JOIN item ON i_item_sk=ws_item_sk - JOIN date_dim ON d_date_sk=ws_sold_date_sk - LEFT JOIN web_returns ON (ws_order_number=wr_order_number - AND ws_item_sk=wr_item_sk) - WHERE i_category='Shoes') sales_detail - GROUP BY d_year, i_brand_id, i_class_id, i_category_id, i_manufact_id) - SELECT prev_yr.d_year AS prev_year - ,curr_yr.d_year AS year - ,curr_yr.i_brand_id - ,curr_yr.i_class_id - ,curr_yr.i_category_id - ,curr_yr.i_manufact_id - ,prev_yr.sales_cnt AS prev_yr_cnt - ,curr_yr.sales_cnt AS curr_yr_cnt - ,curr_yr.sales_cnt-prev_yr.sales_cnt AS sales_cnt_diff - ,curr_yr.sales_amt-prev_yr.sales_amt AS sales_amt_diff - FROM all_sales curr_yr, all_sales prev_yr - WHERE curr_yr.i_brand_id=prev_yr.i_brand_id - AND curr_yr.i_class_id=prev_yr.i_class_id - AND curr_yr.i_category_id=prev_yr.i_category_id - AND curr_yr.i_manufact_id=prev_yr.i_manufact_id - AND curr_yr.d_year=2000 - AND prev_yr.d_year=2000-1 - AND CAST(curr_yr.sales_cnt AS DECIMAL(17,2))/CAST(prev_yr.sales_cnt AS DECIMAL(17,2))<0.9 - ORDER BY sales_cnt_diff,sales_amt_diff - limit 100; - --- end template query75.tpl query 3 in stream 0 --- start template query44.tpl query 4 in stream 0 -select /* TPC-DS query44.tpl 0.4 */ asceding.rnk, i1.i_product_name best_performing, i2.i_product_name worst_performing -from(select * - from (select item_sk,rank() over (order by rank_col asc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 126 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 126 - and ss_hdemo_sk is null - group by ss_store_sk))V1)V11 - where rnk < 11) asceding, - (select * - from (select item_sk,rank() over (order by rank_col desc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 126 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 126 - and ss_hdemo_sk is null - group by ss_store_sk))V2)V21 - where rnk < 11) descending, -item i1, -item i2 -where asceding.rnk = descending.rnk - and i1.i_item_sk=asceding.item_sk - and i2.i_item_sk=descending.item_sk -order by asceding.rnk -limit 100; - --- end template query44.tpl query 4 in stream 0 --- start template query39.tpl query 5 in stream 0 -with /* TPC-DS query39.tpl 0.5 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =2001 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=1 - and inv2.d_moy=1+1 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; -with /* TPC-DS query39.tpl 0.5 part2 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =2001 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=1 - and inv2.d_moy=1+1 - and inv1.cov > 1.5 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; - --- end template query39.tpl query 5 in stream 0 --- start template query80a.tpl query 6 in stream 0 -with /* TPC-DS query80a.tpl 0.6 */ ssr as - (select s_store_id as store_id, - sum(ss_ext_sales_price) as sales, - sum(coalesce(sr_return_amt, 0)) as returns, - sum(ss_net_profit - coalesce(sr_net_loss, 0)) as profit - from store_sales left outer join store_returns on - (ss_item_sk = sr_item_sk and ss_ticket_number = sr_ticket_number), - date_dim, - store, - item, - promotion - where ss_sold_date_sk = d_date_sk - and d_date between cast('2002-08-04' as date) - and dateadd(day,30,cast('2002-08-04' as date)) - and ss_store_sk = s_store_sk - and ss_item_sk = i_item_sk - and i_current_price > 50 - and ss_promo_sk = p_promo_sk - and p_channel_tv = 'N' - group by s_store_id) - , - csr as - (select cp_catalog_page_id as catalog_page_id, - sum(cs_ext_sales_price) as sales, - sum(coalesce(cr_return_amount, 0)) as returns, - sum(cs_net_profit - coalesce(cr_net_loss, 0)) as profit - from catalog_sales left outer join catalog_returns on - (cs_item_sk = cr_item_sk and cs_order_number = cr_order_number), - date_dim, - catalog_page, - item, - promotion - where cs_sold_date_sk = d_date_sk - and d_date between cast('2002-08-04' as date) - and dateadd(day,30,cast('2002-08-04' as date)) - and cs_catalog_page_sk = cp_catalog_page_sk - and cs_item_sk = i_item_sk - and i_current_price > 50 - and cs_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(ws_ext_sales_price) as sales, - sum(coalesce(wr_return_amt, 0)) as returns, - sum(ws_net_profit - coalesce(wr_net_loss, 0)) as profit - from web_sales left outer join web_returns on - (ws_item_sk = wr_item_sk and ws_order_number = wr_order_number), - date_dim, - web_site, - item, - promotion - where ws_sold_date_sk = d_date_sk - and d_date between cast('2002-08-04' as date) - and dateadd(day,30,cast('2002-08-04' as date)) - and ws_web_site_sk = web_site_sk - and ws_item_sk = i_item_sk - and i_current_price > 50 - and ws_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by web_site_id) -, -results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || store_id as id - , sales - , returns - , profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || catalog_page_id as id - , sales - , returns - , profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , profit - from wsr - ) x - group by channel, id) - - select channel - , id - , sales - , returns - , profit - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results - ) foo - order by channel, id - limit 100; - --- end template query80a.tpl query 6 in stream 0 --- start template query32.tpl query 7 in stream 0 -select /* TPC-DS query32.tpl 0.7 */ sum(cs_ext_discount_amt) as "excess discount amount" -from - catalog_sales - ,item - ,date_dim -where -i_manufact_id = 283 -and i_item_sk = cs_item_sk -and d_date between '1999-02-22' and - dateadd(day,90,cast('1999-02-22' as date)) -and d_date_sk = cs_sold_date_sk -and cs_ext_discount_amt - > ( - select - 1.3 * avg(cs_ext_discount_amt) - from - catalog_sales - ,date_dim - where - cs_item_sk = i_item_sk - and d_date between '1999-02-22' and - dateadd(day,90,cast('1999-02-22' as date)) - and d_date_sk = cs_sold_date_sk - ) -limit 100; - --- end template query32.tpl query 7 in stream 0 --- start template query19.tpl query 8 in stream 0 -select /* TPC-DS query19.tpl 0.8 */ i_brand_id brand_id, i_brand brand, i_manufact_id, i_manufact, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item,customer,customer_address,store - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=8 - and d_moy=11 - and d_year=1999 - and ss_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and substring(ca_zip,1,5) <> substring(s_zip,1,5) - and ss_store_sk = s_store_sk - group by i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact - order by ext_price desc - ,i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact -limit 100 ; - --- end template query19.tpl query 8 in stream 0 --- start template query25.tpl query 9 in stream 0 -select /* TPC-DS query25.tpl 0.9 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,min(ss_net_profit) as store_sales_profit - ,min(sr_net_loss) as store_returns_loss - ,min(cs_net_profit) as catalog_sales_profit - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 2002 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 10 - and d2.d_year = 2002 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_moy between 4 and 10 - and d3.d_year = 2002 - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query25.tpl query 9 in stream 0 --- start template query78.tpl query 10 in stream 0 -with /* TPC-DS query78.tpl 0.10 */ ws as - (select d_year AS ws_sold_year, ws_item_sk, - ws_bill_customer_sk ws_customer_sk, - sum(ws_quantity) ws_qty, - sum(ws_wholesale_cost) ws_wc, - sum(ws_sales_price) ws_sp - from web_sales - left join web_returns on wr_order_number=ws_order_number and ws_item_sk=wr_item_sk - join date_dim on ws_sold_date_sk = d_date_sk - where wr_order_number is null - group by d_year, ws_item_sk, ws_bill_customer_sk - ), -cs as - (select d_year AS cs_sold_year, cs_item_sk, - cs_bill_customer_sk cs_customer_sk, - sum(cs_quantity) cs_qty, - sum(cs_wholesale_cost) cs_wc, - sum(cs_sales_price) cs_sp - from catalog_sales - left join catalog_returns on cr_order_number=cs_order_number and cs_item_sk=cr_item_sk - join date_dim on cs_sold_date_sk = d_date_sk - where cr_order_number is null - group by d_year, cs_item_sk, cs_bill_customer_sk - ), -ss as - (select d_year AS ss_sold_year, ss_item_sk, - ss_customer_sk, - sum(ss_quantity) ss_qty, - sum(ss_wholesale_cost) ss_wc, - sum(ss_sales_price) ss_sp - from store_sales - left join store_returns on sr_ticket_number=ss_ticket_number and ss_item_sk=sr_item_sk - join date_dim on ss_sold_date_sk = d_date_sk - where sr_ticket_number is null - group by d_year, ss_item_sk, ss_customer_sk - ) - select -ss_customer_sk, -round(ss_qty/(coalesce(ws_qty,0)+coalesce(cs_qty,0)),2) ratio, -ss_qty store_qty, ss_wc store_wholesale_cost, ss_sp store_sales_price, -coalesce(ws_qty,0)+coalesce(cs_qty,0) other_chan_qty, -coalesce(ws_wc,0)+coalesce(cs_wc,0) other_chan_wholesale_cost, -coalesce(ws_sp,0)+coalesce(cs_sp,0) other_chan_sales_price -from ss -left join ws on (ws_sold_year=ss_sold_year and ws_item_sk=ss_item_sk and ws_customer_sk=ss_customer_sk) -left join cs on (cs_sold_year=ss_sold_year and cs_item_sk=ss_item_sk and cs_customer_sk=ss_customer_sk) -where (coalesce(ws_qty,0)>0 or coalesce(cs_qty, 0)>0) and ss_sold_year=2001 -order by - ss_customer_sk, - ss_qty desc, ss_wc desc, ss_sp desc, - other_chan_qty, - other_chan_wholesale_cost, - other_chan_sales_price, - ratio -limit 100; - --- end template query78.tpl query 10 in stream 0 --- start template query86a.tpl query 11 in stream 0 -with /* TPC-DS query86a.tpl 0.11 */ results as -( select sum(ws_net_paid) as total_sum, i_category, i_class, 0 as g_category, 0 as g_class - from - web_sales - ,date_dim d1 - ,item - where - d1.d_month_seq between 1205 and 1205+11 - and d1.d_date_sk = ws_sold_date_sk - and i_item_sk = ws_item_sk - group by i_category,i_class - ) , - - results_rollup as -( select total_sum ,i_category ,i_class, g_category, g_class, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum, i_category, NULL as i_class, 0 as g_category, 1 as g_class, 1 as lochierarchy from results group by i_category - union - select sum(total_sum) as total_sum, NULL as i_category, NULL as i_class, 1 as g_category, 1 as g_class, 2 as lochierarchy from results) - select - total_sum ,i_category ,i_class, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_class = 0 then i_category end - order by total_sum desc) as rank_within_parent - from - results_rollup - order by - lochierarchy desc, - case when lochierarchy = 0 then i_category end, - rank_within_parent - limit 100; - --- end template query86a.tpl query 11 in stream 0 --- start template query1.tpl query 12 in stream 0 -with /* TPC-DS query1.tpl 0.12 */ customer_total_return as -(select sr_customer_sk as ctr_customer_sk -,sr_store_sk as ctr_store_sk -,sum(SR_RETURN_AMT_INC_TAX) as ctr_total_return -from store_returns -,date_dim -where sr_returned_date_sk = d_date_sk -and d_year =1999 -group by sr_customer_sk -,sr_store_sk) - select c_customer_id -from customer_total_return ctr1 -,store -,customer -where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 -from customer_total_return ctr2 -where ctr1.ctr_store_sk = ctr2.ctr_store_sk) -and s_store_sk = ctr1.ctr_store_sk -and s_state = 'NM' -and ctr1.ctr_customer_sk = c_customer_sk -order by c_customer_id -limit 100; - --- end template query1.tpl query 12 in stream 0 --- start template query91.tpl query 13 in stream 0 -select /* TPC-DS query91.tpl 0.13 */ - cc_call_center_id Call_Center, - cc_name Call_Center_Name, - cc_manager Manager, - sum(cr_net_loss) Returns_Loss -from - call_center, - catalog_returns, - date_dim, - customer, - customer_address, - customer_demographics, - household_demographics -where - cr_call_center_sk = cc_call_center_sk -and cr_returned_date_sk = d_date_sk -and cr_returning_customer_sk= c_customer_sk -and cd_demo_sk = c_current_cdemo_sk -and hd_demo_sk = c_current_hdemo_sk -and ca_address_sk = c_current_addr_sk -and d_year = 2002 -and d_moy = 11 -and ( (cd_marital_status = 'M' and cd_education_status = 'Unknown') - or(cd_marital_status = 'W' and cd_education_status = 'Advanced Degree')) -and hd_buy_potential like 'Unknown%' -and ca_gmt_offset = -6 -group by cc_call_center_id,cc_name,cc_manager,cd_marital_status,cd_education_status -order by sum(cr_net_loss) desc; - --- end template query91.tpl query 13 in stream 0 --- start template query21.tpl query 14 in stream 0 -select /* TPC-DS query21.tpl 0.14 */ * - from(select w_warehouse_name - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('2000-05-19' as date)) - then inv_quantity_on_hand - else 0 end) as inv_before - ,sum(case when (cast(d_date as date) >= cast ('2000-05-19' as date)) - then inv_quantity_on_hand - else 0 end) as inv_after - from inventory - ,warehouse - ,item - ,date_dim - where i_current_price between 0.99 and 1.49 - and i_item_sk = inv_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('2000-05-19' as date)) - and dateadd(day,30,cast ('2000-05-19' as date)) - group by w_warehouse_name, i_item_id) x - where (case when inv_before > 0 - then inv_after / inv_before - else null - end) between 2.0/3.0 and 3.0/2.0 - order by w_warehouse_name - ,i_item_id - limit 100; - --- end template query21.tpl query 14 in stream 0 --- start template query43.tpl query 15 in stream 0 -select /* TPC-DS query43.tpl 0.15 */ s_store_name, s_store_id, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from date_dim, store_sales, store - where d_date_sk = ss_sold_date_sk and - s_store_sk = ss_store_sk and - s_gmt_offset = -6 and - d_year = 2000 - group by s_store_name, s_store_id - order by s_store_name, s_store_id,sun_sales,mon_sales,tue_sales,wed_sales,thu_sales,fri_sales,sat_sales - limit 100; - --- end template query43.tpl query 15 in stream 0 --- start template query27a.tpl query 16 in stream 0 -with /* TPC-DS query27a.tpl 0.16 */ results as - (select i_item_id, - s_state, 0 as g_state, - ss_quantity agg1, - ss_list_price agg2, - ss_coupon_amt agg3, - ss_sales_price agg4 - from store_sales, customer_demographics, date_dim, store, item - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_store_sk = s_store_sk and - ss_cdemo_sk = cd_demo_sk and - cd_gender = 'F' and - cd_marital_status = 'D' and - cd_education_status = 'College' and - d_year = 2000 and - s_state in ('NY','AL', 'NM', 'IN', 'GA', 'MN') - ) - - select i_item_id, - s_state, g_state, agg1, agg2, agg3, agg4 - from ( - select i_item_id, s_state, 0 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4 from results - group by i_item_id, s_state - union all - select i_item_id, NULL AS s_state, 1 AS g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as s_state, 1 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - ) foo - order by i_item_id, s_state - limit 100; - --- end template query27a.tpl query 16 in stream 0 --- start template query94.tpl query 17 in stream 0 -select /* TPC-DS query94.tpl 0.17 */ - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2002-4-01' and - dateadd(day,60,cast('2002-4-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'GA' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and exists (select * - from web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) -and not exists(select * - from web_returns wr1 - where ws1.ws_order_number = wr1.wr_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query94.tpl query 17 in stream 0 --- start template query45.tpl query 18 in stream 0 -select /* TPC-DS query45.tpl 0.18 */ ca_zip, ca_county, sum(ws_sales_price) - from web_sales, customer, customer_address, date_dim, item - where ws_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ws_item_sk = i_item_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', '85392', '85460', '80348', '81792') - or - i_item_id in (select i_item_id - from item - where i_item_sk in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29) - ) - ) - and ws_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 2002 - group by ca_zip, ca_county - order by ca_zip, ca_county - limit 100; - --- end template query45.tpl query 18 in stream 0 --- start template query58.tpl query 19 in stream 0 -with /* TPC-DS query58.tpl 0.19 */ ss_items as - (select i_item_id item_id - ,sum(ss_ext_sales_price) ss_item_rev - from store_sales - ,item - ,date_dim - where ss_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '1999-06-09')) - and ss_sold_date_sk = d_date_sk - group by i_item_id), - cs_items as - (select i_item_id item_id - ,sum(cs_ext_sales_price) cs_item_rev - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '1999-06-09')) - and cs_sold_date_sk = d_date_sk - group by i_item_id), - ws_items as - (select i_item_id item_id - ,sum(ws_ext_sales_price) ws_item_rev - from web_sales - ,item - ,date_dim - where ws_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq =(select d_week_seq - from date_dim - where d_date = '1999-06-09')) - and ws_sold_date_sk = d_date_sk - group by i_item_id) - select ss_items.item_id - ,ss_item_rev - ,ss_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ss_dev - ,cs_item_rev - ,cs_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 cs_dev - ,ws_item_rev - ,ws_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ws_dev - ,(ss_item_rev+cs_item_rev+ws_item_rev)/3 average - from ss_items,cs_items,ws_items - where ss_items.item_id=cs_items.item_id - and ss_items.item_id=ws_items.item_id - and ss_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - and ss_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and cs_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and cs_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and ws_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and ws_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - order by item_id - ,ss_item_rev - limit 100; - --- end template query58.tpl query 19 in stream 0 --- start template query64.tpl query 20 in stream 0 -with /* TPC-DS query64.tpl 0.20 */ cs_ui as - (select cs_item_sk - ,sum(cs_ext_list_price) as sale,sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit) as refund - from catalog_sales - ,catalog_returns - where cs_item_sk = cr_item_sk - and cs_order_number = cr_order_number - group by cs_item_sk - having sum(cs_ext_list_price)>2*sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit)), -cross_sales as - (select i_product_name product_name - ,i_item_sk item_sk - ,s_store_name store_name - ,s_zip store_zip - ,ad1.ca_street_number b_street_number - ,ad1.ca_street_name b_street_name - ,ad1.ca_city b_city - ,ad1.ca_zip b_zip - ,ad2.ca_street_number c_street_number - ,ad2.ca_street_name c_street_name - ,ad2.ca_city c_city - ,ad2.ca_zip c_zip - ,d1.d_year as syear - ,d2.d_year as fsyear - ,d3.d_year s2year - ,count(*) cnt - ,sum(ss_wholesale_cost) s1 - ,sum(ss_list_price) s2 - ,sum(ss_coupon_amt) s3 - FROM store_sales - ,store_returns - ,cs_ui - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,customer - ,customer_demographics cd1 - ,customer_demographics cd2 - ,promotion - ,household_demographics hd1 - ,household_demographics hd2 - ,customer_address ad1 - ,customer_address ad2 - ,income_band ib1 - ,income_band ib2 - ,item - WHERE ss_store_sk = s_store_sk AND - ss_sold_date_sk = d1.d_date_sk AND - ss_customer_sk = c_customer_sk AND - ss_cdemo_sk= cd1.cd_demo_sk AND - ss_hdemo_sk = hd1.hd_demo_sk AND - ss_addr_sk = ad1.ca_address_sk and - ss_item_sk = i_item_sk and - ss_item_sk = sr_item_sk and - ss_ticket_number = sr_ticket_number and - ss_item_sk = cs_ui.cs_item_sk and - c_current_cdemo_sk = cd2.cd_demo_sk AND - c_current_hdemo_sk = hd2.hd_demo_sk AND - c_current_addr_sk = ad2.ca_address_sk and - c_first_sales_date_sk = d2.d_date_sk and - c_first_shipto_date_sk = d3.d_date_sk and - ss_promo_sk = p_promo_sk and - hd1.hd_income_band_sk = ib1.ib_income_band_sk and - hd2.hd_income_band_sk = ib2.ib_income_band_sk and - cd1.cd_marital_status <> cd2.cd_marital_status and - i_color in ('azure','thistle','salmon','tomato','burnished','sky') and - i_current_price between 7 and 7 + 10 and - i_current_price between 7 + 1 and 7 + 15 -group by i_product_name - ,i_item_sk - ,s_store_name - ,s_zip - ,ad1.ca_street_number - ,ad1.ca_street_name - ,ad1.ca_city - ,ad1.ca_zip - ,ad2.ca_street_number - ,ad2.ca_street_name - ,ad2.ca_city - ,ad2.ca_zip - ,d1.d_year - ,d2.d_year - ,d3.d_year -) -select cs1.product_name - ,cs1.store_name - ,cs1.store_zip - ,cs1.b_street_number - ,cs1.b_street_name - ,cs1.b_city - ,cs1.b_zip - ,cs1.c_street_number - ,cs1.c_street_name - ,cs1.c_city - ,cs1.c_zip - ,cs1.syear - ,cs1.cnt - ,cs1.s1 as s11 - ,cs1.s2 as s21 - ,cs1.s3 as s31 - ,cs2.s1 as s12 - ,cs2.s2 as s22 - ,cs2.s3 as s32 - ,cs2.syear - ,cs2.cnt -from cross_sales cs1,cross_sales cs2 -where cs1.item_sk=cs2.item_sk and - cs1.syear = 2001 and - cs2.syear = 2001 + 1 and - cs2.cnt <= cs1.cnt and - cs1.store_name = cs2.store_name and - cs1.store_zip = cs2.store_zip -order by cs1.product_name - ,cs1.store_name - ,cs2.cnt - ,cs1.s1 - ,cs2.s1; - --- end template query64.tpl query 20 in stream 0 --- start template query36a.tpl query 21 in stream 0 -with /* TPC-DS query36a.tpl 0.21 */ results as - (select - sum(ss_net_profit) as ss_net_profit, sum(ss_ext_sales_price) as ss_ext_sales_price, - sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin - ,i_category - ,i_class - ,0 as g_category, 0 as g_class - from - store_sales - ,date_dim d1 - ,item - ,store - where - d1.d_year = 2000 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and s_state in ('NE','GA','TN','SD', - 'KY','IN','IN','LA') - group by i_category,i_class) - , - results_rollup as - (select gross_margin ,i_category ,i_class,0 as t_category, 0 as t_class, 0 as lochierarchy from results - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - i_category, NULL AS i_class, 0 as t_category, 1 as t_class, 1 as lochierarchy from results group by i_category - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - NULL AS i_category ,NULL AS i_class, 1 as t_category, 1 as t_class, 2 as lochierarchy from results) - select - gross_margin ,i_category ,i_class, lochierarchy,rank() over ( - partition by lochierarchy, case when t_class = 0 then i_category end - order by gross_margin asc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then i_category end - ,rank_within_parent - limit 100; - --- end template query36a.tpl query 21 in stream 0 --- start template query33.tpl query 22 in stream 0 -with /* TPC-DS query33.tpl 0.22 */ ss as ( - select - i_manufact_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Sports')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 3 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id), - cs as ( - select - i_manufact_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Sports')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 3 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id), - ws as ( - select - i_manufact_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Sports')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 3 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id) - select i_manufact_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_manufact_id - order by total_sales -limit 100; - --- end template query33.tpl query 22 in stream 0 --- start template query46.tpl query 23 in stream 0 -select /* TPC-DS query46.tpl 0.23 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and (household_demographics.hd_dep_count = 2 or - household_demographics.hd_vehicle_count= 3) - and date_dim.d_dow in (6,0) - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_city in ('Alpine','Friendship','Elmwood','Deerfield','Bellevue') - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,ca_city) dn,customer,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - limit 100; - --- end template query46.tpl query 23 in stream 0 --- start template query62.tpl query 24 in stream 0 -select /* TPC-DS query62.tpl 0.24 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 30) and - (ws_ship_date_sk - ws_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 60) and - (ws_ship_date_sk - ws_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 90) and - (ws_ship_date_sk - ws_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - web_sales - ,warehouse - ,ship_mode - ,web_site - ,date_dim -where - d_month_seq between 1180 and 1180 + 11 -and ws_ship_date_sk = d_date_sk -and ws_warehouse_sk = w_warehouse_sk -and ws_ship_mode_sk = sm_ship_mode_sk -and ws_web_site_sk = web_site_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -limit 100; - --- end template query62.tpl query 24 in stream 0 --- start template query16.tpl query 25 in stream 0 -select /* TPC-DS query16.tpl 0.25 */ - count(distinct cs_order_number) as "order count" - ,sum(cs_ext_ship_cost) as "total shipping cost" - ,sum(cs_net_profit) as "total net profit" -from - catalog_sales cs1 - ,date_dim - ,customer_address - ,call_center -where - d_date between '1999-3-01' and - dateadd(day, 60, cast('1999-3-01' as date)) -and cs1.cs_ship_date_sk = d_date_sk -and cs1.cs_ship_addr_sk = ca_address_sk -and ca_state = 'AL' -and cs1.cs_call_center_sk = cc_call_center_sk -and cc_county in ('Luce County','Bronx County','Levy County','Franklin Parish', - 'Sierra County' -) -and exists (select * - from catalog_sales cs2 - where cs1.cs_order_number = cs2.cs_order_number - and cs1.cs_warehouse_sk <> cs2.cs_warehouse_sk) -and not exists(select * - from catalog_returns cr1 - where cs1.cs_order_number = cr1.cr_order_number) -order by count(distinct cs_order_number) -limit 100; - --- end template query16.tpl query 25 in stream 0 --- start template query10.tpl query 26 in stream 0 -select /* TPC-DS query10.tpl 0.26 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3, - cd_dep_count, - count(*) cnt4, - cd_dep_employed_count, - count(*) cnt5, - cd_dep_college_count, - count(*) cnt6 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_county in ('Martin County','Mahnomen County','Todd County','Jefferson County','Hancock County') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 1999 and - d_moy between 2 and 2+3) and - (exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 1999 and - d_moy between 2 ANd 2+3) or - exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 1999 and - d_moy between 2 and 2+3)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count -limit 100; - --- end template query10.tpl query 26 in stream 0 --- start template query63.tpl query 27 in stream 0 -select /* TPC-DS query63.tpl 0.27 */ * -from (select i_manager_id - ,sum(ss_sales_price) sum_sales - ,avg(sum(ss_sales_price)) over (partition by i_manager_id) avg_monthly_sales - from item - ,store_sales - ,date_dim - ,store - where ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and d_month_seq in (1206,1206+1,1206+2,1206+3,1206+4,1206+5,1206+6,1206+7,1206+8,1206+9,1206+10,1206+11) - and (( i_category in ('Books','Children','Electronics') - and i_class in ('personal','portable','reference','self-help') - and i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) - or( i_category in ('Women','Music','Men') - and i_class in ('accessories','classical','fragrances','pants') - and i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manager_id, d_moy) tmp1 -where case when avg_monthly_sales > 0 then abs (sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 -order by i_manager_id - ,avg_monthly_sales - ,sum_sales -limit 100; - --- end template query63.tpl query 27 in stream 0 --- start template query69.tpl query 28 in stream 0 -select /* TPC-DS query69.tpl 0.28 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_state in ('SC','WV','TN') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 1999 and - d_moy between 3 and 3+2) and - (not exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 1999 and - d_moy between 3 and 3+2) and - not exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 1999 and - d_moy between 3 and 3+2)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - limit 100; - --- end template query69.tpl query 28 in stream 0 --- start template query60.tpl query 29 in stream 0 -with /* TPC-DS query60.tpl 0.29 */ ss as ( - select - i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Men')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 10 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - cs as ( - select - i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Men')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 10 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - ws as ( - select - i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Men')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 10 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id) - select - i_item_id -,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by i_item_id - ,total_sales - limit 100; - --- end template query60.tpl query 29 in stream 0 --- start template query59.tpl query 30 in stream 0 -with /* TPC-DS query59.tpl 0.30 */ wss as - (select d_week_seq, - ss_store_sk, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - group by d_week_seq,ss_store_sk - ) - select s_store_name1,s_store_id1,d_week_seq1 - ,sun_sales1/sun_sales2,mon_sales1/mon_sales2 - ,tue_sales1/tue_sales2,wed_sales1/wed_sales2,thu_sales1/thu_sales2 - ,fri_sales1/fri_sales2,sat_sales1/sat_sales2 - from - (select s_store_name s_store_name1,wss.d_week_seq d_week_seq1 - ,s_store_id s_store_id1,sun_sales sun_sales1 - ,mon_sales mon_sales1,tue_sales tue_sales1 - ,wed_sales wed_sales1,thu_sales thu_sales1 - ,fri_sales fri_sales1,sat_sales sat_sales1 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1181 and 1181 + 11) y, - (select s_store_name s_store_name2,wss.d_week_seq d_week_seq2 - ,s_store_id s_store_id2,sun_sales sun_sales2 - ,mon_sales mon_sales2,tue_sales tue_sales2 - ,wed_sales wed_sales2,thu_sales thu_sales2 - ,fri_sales fri_sales2,sat_sales sat_sales2 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1181+ 12 and 1181 + 23) x - where s_store_id1=s_store_id2 - and d_week_seq1=d_week_seq2-52 - order by s_store_name1,s_store_id1,d_week_seq1 -limit 100; - --- end template query59.tpl query 30 in stream 0 --- start template query37.tpl query 31 in stream 0 -select /* TPC-DS query37.tpl 0.31 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, catalog_sales - where i_current_price between 29 and 29 + 30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('1999-03-27' as date) and dateadd(day,60,cast('1999-03-27' as date)) - and i_manufact_id in (846,800,681,713) - and inv_quantity_on_hand between 100 and 500 - and cs_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query37.tpl query 31 in stream 0 --- start template query98.tpl query 32 in stream 0 -select /* TPC-DS query98.tpl 0.32 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ss_ext_sales_price) as itemrevenue - ,sum(ss_ext_sales_price)*100/sum(sum(ss_ext_sales_price)) over - (partition by i_class) as revenueratio -from - store_sales - ,item - ,date_dim -where - ss_item_sk = i_item_sk - and i_category in ('Music', 'Women', 'Electronics') - and ss_sold_date_sk = d_date_sk - and d_date between cast('1998-01-03' as date) - and dateadd(day,30,cast('1998-01-03' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio; - --- end template query98.tpl query 32 in stream 0 --- start template query85.tpl query 33 in stream 0 -select /* TPC-DS query85.tpl 0.33 */ substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) - from web_sales, web_returns, web_page, customer_demographics cd1, - customer_demographics cd2, customer_address, date_dim, reason - where ws_web_page_sk = wp_web_page_sk - and ws_item_sk = wr_item_sk - and ws_order_number = wr_order_number - and ws_sold_date_sk = d_date_sk and d_year = 1999 - and cd1.cd_demo_sk = wr_refunded_cdemo_sk - and cd2.cd_demo_sk = wr_returning_cdemo_sk - and ca_address_sk = wr_refunded_addr_sk - and r_reason_sk = wr_reason_sk - and - ( - ( - cd1.cd_marital_status = 'D' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = '4 yr Degree' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 100.00 and 150.00 - ) - or - ( - cd1.cd_marital_status = 'W' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Unknown' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 50.00 and 100.00 - ) - or - ( - cd1.cd_marital_status = 'U' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Primary' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ca_country = 'United States' - and - ca_state in ('VA', 'ID', 'MS') - and ws_net_profit between 100 and 200 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('NE', 'PA', 'TX') - and ws_net_profit between 150 and 300 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('MN', 'MD', 'LA') - and ws_net_profit between 50 and 250 - ) - ) -group by r_reason_desc -order by substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) -limit 100; - --- end template query85.tpl query 33 in stream 0 --- start template query70a.tpl query 34 in stream 0 -with /* TPC-DS query70a.tpl 0.34 */ results as -( select - sum(ss_net_profit) as total_sum ,s_state ,s_county, 0 as gstate, 0 as g_county - from - store_sales - ,date_dim d1 - ,store - where - d1.d_month_seq between 1198 and 1198 + 11 - and d1.d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - and s_state in - ( select s_state - from (select s_state as s_state, - rank() over ( partition by s_state order by sum(ss_net_profit) desc) as ranking - from store_sales, store, date_dim - where d_month_seq between 1198 and 1198 + 11 - and d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - group by s_state - ) tmp1 - where ranking <= 5) - group by s_state,s_county) , - results_rollup as -(select total_sum ,s_state ,s_county, 0 as g_state, 0 as g_county, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum,s_state, NULL as s_county, 0 as g_state, 1 as g_county, 1 as lochierarchy from results group by s_state - union - select sum(total_sum) as total_sum ,NULL as s_state ,NULL as s_county, 1 as g_state, 1 as g_county, 2 as lochierarchy from results) - select total_sum ,s_state ,s_county, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_county = 0 then s_state end - order by total_sum desc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then s_state end - ,rank_within_parent - limit 100; - --- end template query70a.tpl query 34 in stream 0 --- start template query67a.tpl query 35 in stream 0 -with /* TPC-DS query67a.tpl 0.35 */ results as -( select i_category ,i_class ,i_brand ,i_product_name ,d_year ,d_qoy ,d_moy ,s_store_id - ,sum(coalesce(ss_sales_price*ss_quantity,0)) sumsales - from store_sales ,date_dim ,store ,item - where ss_sold_date_sk=d_date_sk - and ss_item_sk=i_item_sk - and ss_store_sk = s_store_sk - and d_month_seq between 1205 and 1205 + 11 - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy,s_store_id) - , - results_rollup as - (select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, s_store_id, sumsales - from results - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy - union all - select i_category, i_class, i_brand, i_product_name, d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year - union all - select i_category, i_class, i_brand, i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name - union all - select i_category, i_class, i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand - union all - select i_category, i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class - union all - select i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category - union all - select null i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results) - - select * -from (select i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rank() over (partition by i_category order by sumsales desc) rk - from results_rollup) dw2 -where rk <= 100 -order by i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rk -limit 100; - --- end template query67a.tpl query 35 in stream 0 --- start template query28.tpl query 36 in stream 0 -select /* TPC-DS query28.tpl 0.36 */ * -from (select avg(ss_list_price) B1_LP - ,count(ss_list_price) B1_CNT - ,count(distinct ss_list_price) B1_CNTD - from store_sales - where ss_quantity between 0 and 5 - and (ss_list_price between 61 and 61+10 - or ss_coupon_amt between 12194 and 12194+1000 - or ss_wholesale_cost between 43 and 43+20)) B1, - (select avg(ss_list_price) B2_LP - ,count(ss_list_price) B2_CNT - ,count(distinct ss_list_price) B2_CNTD - from store_sales - where ss_quantity between 6 and 10 - and (ss_list_price between 183 and 183+10 - or ss_coupon_amt between 9455 and 9455+1000 - or ss_wholesale_cost between 5 and 5+20)) B2, - (select avg(ss_list_price) B3_LP - ,count(ss_list_price) B3_CNT - ,count(distinct ss_list_price) B3_CNTD - from store_sales - where ss_quantity between 11 and 15 - and (ss_list_price between 6 and 6+10 - or ss_coupon_amt between 3633 and 3633+1000 - or ss_wholesale_cost between 80 and 80+20)) B3, - (select avg(ss_list_price) B4_LP - ,count(ss_list_price) B4_CNT - ,count(distinct ss_list_price) B4_CNTD - from store_sales - where ss_quantity between 16 and 20 - and (ss_list_price between 60 and 60+10 - or ss_coupon_amt between 12942 and 12942+1000 - or ss_wholesale_cost between 58 and 58+20)) B4, - (select avg(ss_list_price) B5_LP - ,count(ss_list_price) B5_CNT - ,count(distinct ss_list_price) B5_CNTD - from store_sales - where ss_quantity between 21 and 25 - and (ss_list_price between 88 and 88+10 - or ss_coupon_amt between 5678 and 5678+1000 - or ss_wholesale_cost between 23 and 23+20)) B5, - (select avg(ss_list_price) B6_LP - ,count(ss_list_price) B6_CNT - ,count(distinct ss_list_price) B6_CNTD - from store_sales - where ss_quantity between 26 and 30 - and (ss_list_price between 46 and 46+10 - or ss_coupon_amt between 13113 and 13113+1000 - or ss_wholesale_cost between 22 and 22+20)) B6 -limit 100; - --- end template query28.tpl query 36 in stream 0 --- start template query81.tpl query 37 in stream 0 -with /* TPC-DS query81.tpl 0.37 */ customer_total_return as - (select cr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(cr_return_amt_inc_tax) as ctr_total_return - from catalog_returns - ,date_dim - ,customer_address - where cr_returned_date_sk = d_date_sk - and d_year =2000 - and cr_returning_addr_sk = ca_address_sk - group by cr_returning_customer_sk - ,ca_state ) - select c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'ID' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - limit 100; - --- end template query81.tpl query 37 in stream 0 --- start template query97.tpl query 38 in stream 0 -with /* TPC-DS query97.tpl 0.38 */ ssci as ( -select ss_customer_sk customer_sk - ,ss_item_sk item_sk -from store_sales,date_dim -where ss_sold_date_sk = d_date_sk - and d_month_seq between 1203 and 1203 + 11 -group by ss_customer_sk - ,ss_item_sk), -csci as( - select cs_bill_customer_sk customer_sk - ,cs_item_sk item_sk -from catalog_sales,date_dim -where cs_sold_date_sk = d_date_sk - and d_month_seq between 1203 and 1203 + 11 -group by cs_bill_customer_sk - ,cs_item_sk) - select sum(case when ssci.customer_sk is not null and csci.customer_sk is null then 1 else 0 end) store_only - ,sum(case when ssci.customer_sk is null and csci.customer_sk is not null then 1 else 0 end) catalog_only - ,sum(case when ssci.customer_sk is not null and csci.customer_sk is not null then 1 else 0 end) store_and_catalog -from ssci full outer join csci on (ssci.customer_sk=csci.customer_sk - and ssci.item_sk = csci.item_sk) -limit 100; - --- end template query97.tpl query 38 in stream 0 --- start template query66.tpl query 39 in stream 0 -select /* TPC-DS query66.tpl 0.39 */ - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - ,sum(jan_sales) as jan_sales - ,sum(feb_sales) as feb_sales - ,sum(mar_sales) as mar_sales - ,sum(apr_sales) as apr_sales - ,sum(may_sales) as may_sales - ,sum(jun_sales) as jun_sales - ,sum(jul_sales) as jul_sales - ,sum(aug_sales) as aug_sales - ,sum(sep_sales) as sep_sales - ,sum(oct_sales) as oct_sales - ,sum(nov_sales) as nov_sales - ,sum(dec_sales) as dec_sales - ,sum(jan_sales/w_warehouse_sq_ft) as jan_sales_per_sq_foot - ,sum(feb_sales/w_warehouse_sq_ft) as feb_sales_per_sq_foot - ,sum(mar_sales/w_warehouse_sq_ft) as mar_sales_per_sq_foot - ,sum(apr_sales/w_warehouse_sq_ft) as apr_sales_per_sq_foot - ,sum(may_sales/w_warehouse_sq_ft) as may_sales_per_sq_foot - ,sum(jun_sales/w_warehouse_sq_ft) as jun_sales_per_sq_foot - ,sum(jul_sales/w_warehouse_sq_ft) as jul_sales_per_sq_foot - ,sum(aug_sales/w_warehouse_sq_ft) as aug_sales_per_sq_foot - ,sum(sep_sales/w_warehouse_sq_ft) as sep_sales_per_sq_foot - ,sum(oct_sales/w_warehouse_sq_ft) as oct_sales_per_sq_foot - ,sum(nov_sales/w_warehouse_sq_ft) as nov_sales_per_sq_foot - ,sum(dec_sales/w_warehouse_sq_ft) as dec_sales_per_sq_foot - ,sum(jan_net) as jan_net - ,sum(feb_net) as feb_net - ,sum(mar_net) as mar_net - ,sum(apr_net) as apr_net - ,sum(may_net) as may_net - ,sum(jun_net) as jun_net - ,sum(jul_net) as jul_net - ,sum(aug_net) as aug_net - ,sum(sep_net) as sep_net - ,sum(oct_net) as oct_net - ,sum(nov_net) as nov_net - ,sum(dec_net) as dec_net - from ( - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'ORIENTAL' || ',' || 'MSC' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then ws_sales_price* ws_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then ws_sales_price* ws_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then ws_sales_price* ws_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then ws_sales_price* ws_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then ws_sales_price* ws_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then ws_sales_price* ws_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then ws_sales_price* ws_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then ws_sales_price* ws_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then ws_sales_price* ws_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then ws_sales_price* ws_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then ws_sales_price* ws_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then ws_sales_price* ws_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then ws_net_profit * ws_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then ws_net_profit * ws_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then ws_net_profit * ws_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then ws_net_profit * ws_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then ws_net_profit * ws_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then ws_net_profit * ws_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then ws_net_profit * ws_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then ws_net_profit * ws_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then ws_net_profit * ws_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then ws_net_profit * ws_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then ws_net_profit * ws_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then ws_net_profit * ws_quantity else 0 end) as dec_net - from - web_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - ws_warehouse_sk = w_warehouse_sk - and ws_sold_date_sk = d_date_sk - and ws_sold_time_sk = t_time_sk - and ws_ship_mode_sk = sm_ship_mode_sk - and d_year = 1998 - and t_time between 22844 and 22844+28800 - and sm_carrier in ('ORIENTAL','MSC') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - union all - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'ORIENTAL' || ',' || 'MSC' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then cs_ext_list_price* cs_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then cs_ext_list_price* cs_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then cs_ext_list_price* cs_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then cs_ext_list_price* cs_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then cs_ext_list_price* cs_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then cs_ext_list_price* cs_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then cs_ext_list_price* cs_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then cs_ext_list_price* cs_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then cs_ext_list_price* cs_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then cs_ext_list_price* cs_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then cs_ext_list_price* cs_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then cs_ext_list_price* cs_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as dec_net - from - catalog_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and cs_sold_time_sk = t_time_sk - and cs_ship_mode_sk = sm_ship_mode_sk - and d_year = 1998 - and t_time between 22844 AND 22844+28800 - and sm_carrier in ('ORIENTAL','MSC') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - ) x - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - order by w_warehouse_name - limit 100; - --- end template query66.tpl query 39 in stream 0 --- start template query90.tpl query 40 in stream 0 -select /* TPC-DS query90.tpl 0.40 */ cast(amc as decimal(15,4))/cast(pmc as decimal(15,4)) am_pm_ratio - from ( select count(*) amc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 7 and 7+1 - and household_demographics.hd_dep_count = 1 - and web_page.wp_char_count between 5000 and 5200) at, - ( select count(*) pmc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 17 and 17+1 - and household_demographics.hd_dep_count = 1 - and web_page.wp_char_count between 5000 and 5200) pt - order by am_pm_ratio - limit 100; - --- end template query90.tpl query 40 in stream 0 --- start template query17.tpl query 41 in stream 0 -select /* TPC-DS query17.tpl 0.41 */ i_item_id - ,i_item_desc - ,s_state - ,count(ss_quantity) as store_sales_quantitycount - ,avg(ss_quantity) as store_sales_quantityave - ,stddev_samp(ss_quantity) as store_sales_quantitystdev - ,stddev_samp(ss_quantity)/avg(ss_quantity) as store_sales_quantitycov - ,count(sr_return_quantity) as store_returns_quantitycount - ,avg(sr_return_quantity) as store_returns_quantityave - ,stddev_samp(sr_return_quantity) as store_returns_quantitystdev - ,stddev_samp(sr_return_quantity)/avg(sr_return_quantity) as store_returns_quantitycov - ,count(cs_quantity) as catalog_sales_quantitycount ,avg(cs_quantity) as catalog_sales_quantityave - ,stddev_samp(cs_quantity) as catalog_sales_quantitystdev - ,stddev_samp(cs_quantity)/avg(cs_quantity) as catalog_sales_quantitycov - from store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where d1.d_quarter_name = '2002Q1' - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_quarter_name in ('2002Q1','2002Q2','2002Q3') - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_quarter_name in ('2002Q1','2002Q2','2002Q3') - group by i_item_id - ,i_item_desc - ,s_state - order by i_item_id - ,i_item_desc - ,s_state -limit 100; - --- end template query17.tpl query 41 in stream 0 --- start template query47.tpl query 42 in stream 0 -with /* TPC-DS query47.tpl 0.42 */ v1 as( - select i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, - s_store_name, s_company_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - s_store_name, s_company_name - order by d_year, d_moy) rn - from item, store_sales, date_dim, store - where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - ( - d_year = 1999 or - ( d_year = 1999-1 and d_moy =12) or - ( d_year = 1999+1 and d_moy =1) - ) - group by i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy), - v2 as( - select v1.s_store_name, v1.s_company_name - ,v1.d_year - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1.s_store_name = v1_lag.s_store_name and - v1.s_store_name = v1_lead.s_store_name and - v1.s_company_name = v1_lag.s_company_name and - v1.s_company_name = v1_lead.s_company_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 1999 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, nsum - limit 100; - --- end template query47.tpl query 42 in stream 0 --- start template query95.tpl query 43 in stream 0 -with /* TPC-DS query95.tpl 0.43 */ ws_wh as -(select ws1.ws_order_number,ws1.ws_warehouse_sk wh1,ws2.ws_warehouse_sk wh2 - from web_sales ws1,web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) - select - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2000-3-01' and - dateadd(day,60,cast('2000-3-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'ND' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and ws1.ws_order_number in (select ws_order_number - from ws_wh) -and ws1.ws_order_number in (select wr_order_number - from web_returns,ws_wh - where wr_order_number = ws_wh.ws_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query95.tpl query 43 in stream 0 --- start template query92.tpl query 44 in stream 0 -select /* TPC-DS query92.tpl 0.44 */ - sum(ws_ext_discount_amt) as "Excess Discount Amount" -from - web_sales - ,item - ,date_dim -where -i_manufact_id = 459 -and i_item_sk = ws_item_sk -and d_date between '2002-01-25' and - dateadd(day,90,cast('2002-01-25' as date)) -and d_date_sk = ws_sold_date_sk -and ws_ext_discount_amt - > ( - SELECT - 1.3 * avg(ws_ext_discount_amt) - FROM - web_sales - ,date_dim - WHERE - ws_item_sk = i_item_sk - and d_date between '2002-01-25' and - dateadd(day,90,cast('2002-01-25' as date)) - and d_date_sk = ws_sold_date_sk - ) -order by sum(ws_ext_discount_amt) -limit 100; - --- end template query92.tpl query 44 in stream 0 --- start template query3.tpl query 45 in stream 0 -select /* TPC-DS query3.tpl 0.45 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_sales_price) sum_agg - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manufact_id = 868 - and dt.d_moy=12 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,sum_agg desc - ,brand_id - limit 100; - --- end template query3.tpl query 45 in stream 0 --- start template query51.tpl query 46 in stream 0 -WITH /* TPC-DS query51.tpl 0.46 */ web_v1 as ( -select - ws_item_sk item_sk, d_date, - sum(sum(ws_sales_price)) - over (partition by ws_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from web_sales - ,date_dim -where ws_sold_date_sk=d_date_sk - and d_month_seq between 1215 and 1215+11 - and ws_item_sk is not NULL -group by ws_item_sk, d_date), -store_v1 as ( -select - ss_item_sk item_sk, d_date, - sum(sum(ss_sales_price)) - over (partition by ss_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from store_sales - ,date_dim -where ss_sold_date_sk=d_date_sk - and d_month_seq between 1215 and 1215+11 - and ss_item_sk is not NULL -group by ss_item_sk, d_date) - select * -from (select item_sk - ,d_date - ,web_sales - ,store_sales - ,max(web_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) web_cumulative - ,max(store_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) store_cumulative - from (select case when web.item_sk is not null then web.item_sk else store.item_sk end item_sk - ,case when web.d_date is not null then web.d_date else store.d_date end d_date - ,web.cume_sales web_sales - ,store.cume_sales store_sales - from web_v1 web full outer join store_v1 store on (web.item_sk = store.item_sk - and web.d_date = store.d_date) - )x )y -where web_cumulative > store_cumulative -order by item_sk - ,d_date -limit 100; - --- end template query51.tpl query 46 in stream 0 --- start template query35a.tpl query 47 in stream 0 -select /* TPC-DS query35a.tpl 0.47 */ - ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - count(*) cnt1, - stddev_samp(cd_dep_count), - sum(cd_dep_count), - avg(cd_dep_count), - cd_dep_employed_count, - count(*) cnt2, - stddev_samp(cd_dep_employed_count), - sum(cd_dep_employed_count), - avg(cd_dep_employed_count), - cd_dep_college_count, - count(*) cnt3, - stddev_samp(cd_dep_college_count), - sum(cd_dep_college_count), - avg(cd_dep_college_count) - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2000 and - d_qoy < 4) and - exists (select * from - (select ws_bill_customer_sk customsk - from web_sales,date_dim - where - ws_sold_date_sk = d_date_sk and - d_year = 2000 and - d_qoy < 4 - union all - select cs_ship_customer_sk customsk - from catalog_sales,date_dim - where - cs_sold_date_sk = d_date_sk and - d_year = 2000 and - d_qoy < 4)x - where x.customsk = c.c_customer_sk) - group by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - limit 100; - --- end template query35a.tpl query 47 in stream 0 --- start template query49.tpl query 48 in stream 0 -select /* TPC-DS query49.tpl 0.48 */ channel, item, return_ratio, return_rank, currency_rank from - (select - 'web' as channel - ,web.item - ,web.return_ratio - ,web.return_rank - ,web.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select ws.ws_item_sk as item - ,(cast(sum(coalesce(wr.wr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(wr.wr_return_amt,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - web_sales ws left outer join web_returns wr - on (ws.ws_order_number = wr.wr_order_number and - ws.ws_item_sk = wr.wr_item_sk) - ,date_dim - where - wr.wr_return_amt > 10000 - and ws.ws_net_profit > 1 - and ws.ws_net_paid > 0 - and ws.ws_quantity > 0 - and ws_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 12 - group by ws.ws_item_sk - ) in_web - ) web - where - ( - web.return_rank <= 10 - or - web.currency_rank <= 10 - ) - union - select - 'catalog' as channel - ,catalog.item - ,catalog.return_ratio - ,catalog.return_rank - ,catalog.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select - cs.cs_item_sk as item - ,(cast(sum(coalesce(cr.cr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(cr.cr_return_amount,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - catalog_sales cs left outer join catalog_returns cr - on (cs.cs_order_number = cr.cr_order_number and - cs.cs_item_sk = cr.cr_item_sk) - ,date_dim - where - cr.cr_return_amount > 10000 - and cs.cs_net_profit > 1 - and cs.cs_net_paid > 0 - and cs.cs_quantity > 0 - and cs_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 12 - group by cs.cs_item_sk - ) in_cat - ) catalog - where - ( - catalog.return_rank <= 10 - or - catalog.currency_rank <=10 - ) - union - select - 'store' as channel - ,store.item - ,store.return_ratio - ,store.return_rank - ,store.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select sts.ss_item_sk as item - ,(cast(sum(coalesce(sr.sr_return_quantity,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(sr.sr_return_amt,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - store_sales sts left outer join store_returns sr - on (sts.ss_ticket_number = sr.sr_ticket_number and sts.ss_item_sk = sr.sr_item_sk) - ,date_dim - where - sr.sr_return_amt > 10000 - and sts.ss_net_profit > 1 - and sts.ss_net_paid > 0 - and sts.ss_quantity > 0 - and ss_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 12 - group by sts.ss_item_sk - ) in_store - ) store - where ( - store.return_rank <= 10 - or - store.currency_rank <= 10 - ) - ) - order by 1,4,5,2 - limit 100; - --- end template query49.tpl query 48 in stream 0 --- start template query9.tpl query 49 in stream 0 -select /* TPC-DS query9.tpl 0.49 */ case when (select count(*) - from store_sales - where ss_quantity between 1 and 20) > 872987528 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 1 and 20) - else (select avg(ss_net_profit) - from store_sales - where ss_quantity between 1 and 20) end bucket1 , - case when (select count(*) - from store_sales - where ss_quantity between 21 and 40) > 127492262 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 21 and 40) - else (select avg(ss_net_profit) - from store_sales - where ss_quantity between 21 and 40) end bucket2, - case when (select count(*) - from store_sales - where ss_quantity between 41 and 60) > 529601320 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 41 and 60) - else (select avg(ss_net_profit) - from store_sales - where ss_quantity between 41 and 60) end bucket3, - case when (select count(*) - from store_sales - where ss_quantity between 61 and 80) > 205197627 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 61 and 80) - else (select avg(ss_net_profit) - from store_sales - where ss_quantity between 61 and 80) end bucket4, - case when (select count(*) - from store_sales - where ss_quantity between 81 and 100) > 498636300 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 81 and 100) - else (select avg(ss_net_profit) - from store_sales - where ss_quantity between 81 and 100) end bucket5 -from reason -where r_reason_sk = 1 -; - --- end template query9.tpl query 49 in stream 0 --- start template query31.tpl query 50 in stream 0 -with /* TPC-DS query31.tpl 0.50 */ ss as - (select ca_county,d_qoy, d_year,sum(ss_ext_sales_price) as store_sales - from store_sales,date_dim,customer_address - where ss_sold_date_sk = d_date_sk - and ss_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year), - ws as - (select ca_county,d_qoy, d_year,sum(ws_ext_sales_price) as web_sales - from web_sales,date_dim,customer_address - where ws_sold_date_sk = d_date_sk - and ws_bill_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year) - select - ss1.ca_county - ,ss1.d_year - ,ws2.web_sales/ws1.web_sales web_q1_q2_increase - ,ss2.store_sales/ss1.store_sales store_q1_q2_increase - ,ws3.web_sales/ws2.web_sales web_q2_q3_increase - ,ss3.store_sales/ss2.store_sales store_q2_q3_increase - from - ss ss1 - ,ss ss2 - ,ss ss3 - ,ws ws1 - ,ws ws2 - ,ws ws3 - where - ss1.d_qoy = 1 - and ss1.d_year = 1998 - and ss1.ca_county = ss2.ca_county - and ss2.d_qoy = 2 - and ss2.d_year = 1998 - and ss2.ca_county = ss3.ca_county - and ss3.d_qoy = 3 - and ss3.d_year = 1998 - and ss1.ca_county = ws1.ca_county - and ws1.d_qoy = 1 - and ws1.d_year = 1998 - and ws1.ca_county = ws2.ca_county - and ws2.d_qoy = 2 - and ws2.d_year = 1998 - and ws1.ca_county = ws3.ca_county - and ws3.d_qoy = 3 - and ws3.d_year =1998 - and case when ws1.web_sales > 0 then ws2.web_sales/ws1.web_sales else null end - > case when ss1.store_sales > 0 then ss2.store_sales/ss1.store_sales else null end - and case when ws2.web_sales > 0 then ws3.web_sales/ws2.web_sales else null end - > case when ss2.store_sales > 0 then ss3.store_sales/ss2.store_sales else null end - order by store_q2_q3_increase; - --- end template query31.tpl query 50 in stream 0 --- start template query11.tpl query 51 in stream 0 -with /* TPC-DS query11.tpl 0.51 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ss_ext_list_price-ss_ext_discount_amt) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ws_ext_list_price-ws_ext_discount_amt) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_preferred_cust_flag - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 2001 - and t_s_secyear.dyear = 2001+1 - and t_w_firstyear.dyear = 2001 - and t_w_secyear.dyear = 2001+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else 0.0 end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else 0.0 end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_preferred_cust_flag -limit 100; - --- end template query11.tpl query 51 in stream 0 --- start template query93.tpl query 52 in stream 0 -select /* TPC-DS query93.tpl 0.52 */ ss_customer_sk - ,sum(act_sales) sumsales - from (select ss_item_sk - ,ss_ticket_number - ,ss_customer_sk - ,case when sr_return_quantity is not null then (ss_quantity-sr_return_quantity)*ss_sales_price - else (ss_quantity*ss_sales_price) end act_sales - from store_sales left outer join store_returns on (sr_item_sk = ss_item_sk - and sr_ticket_number = ss_ticket_number) - ,reason - where sr_reason_sk = r_reason_sk - and r_reason_desc = 'reason 73') t - group by ss_customer_sk - order by sumsales, ss_customer_sk -limit 100; - --- end template query93.tpl query 52 in stream 0 --- start template query29.tpl query 53 in stream 0 -select /* TPC-DS query29.tpl 0.53 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,stddev_samp(ss_quantity) as store_sales_quantity - ,stddev_samp(sr_return_quantity) as store_returns_quantity - ,stddev_samp(cs_quantity) as catalog_sales_quantity - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 1998 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 4 + 3 - and d2.d_year = 1998 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_year in (1998,1998+1,1998+2) - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query29.tpl query 53 in stream 0 --- start template query38.tpl query 54 in stream 0 -select /* TPC-DS query38.tpl 0.54 */ count(*) from ( - select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1207 and 1207 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1207 and 1207 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1207 and 1207 + 11 -) hot_cust -limit 100; - --- end template query38.tpl query 54 in stream 0 --- start template query22a.tpl query 55 in stream 0 -with /* TPC-DS query22a.tpl 0.55 */ results as -(select i_product_name - ,i_brand - ,i_class - ,i_category - ,avg(inv_quantity_on_hand) qoh - from inventory - ,date_dim - ,item --- ,warehouse - where inv_date_sk=d_date_sk - and inv_item_sk=i_item_sk --- and inv_warehouse_sk = w_warehouse_sk - and d_month_seq between 1213 and 1213 + 11 - group by i_product_name,i_brand,i_class,i_category), -results_rollup as -(select i_product_name, i_brand, i_class, i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class,i_category -union all -select i_product_name, i_brand, i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class -union all -select i_product_name, i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand -union all -select i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name -union all -select null i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results) - select i_product_name, i_brand, i_class, i_category,qoh - from results_rollup - order by qoh, i_product_name, i_brand, i_class, i_category -limit 100; - --- end template query22a.tpl query 55 in stream 0 --- start template query89.tpl query 56 in stream 0 -select /* TPC-DS query89.tpl 0.56 */ * -from( -select i_category, i_class, i_brand, - s_store_name, s_company_name, - d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, s_store_name, s_company_name) - avg_monthly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - d_year in (1998) and - ((i_category in ('Home','Men','Children') and - i_class in ('curtains/drapes','accessories','newborn') - ) - or (i_category in ('Jewelry','Electronics','Sports') and - i_class in ('gold','memory','fishing') - )) -group by i_category, i_class, i_brand, - s_store_name, s_company_name, d_moy) tmp1 -where case when (avg_monthly_sales <> 0) then (abs(sum_sales - avg_monthly_sales) / avg_monthly_sales) else null end > 0.1 -order by sum_sales - avg_monthly_sales, s_store_name -limit 100; - --- end template query89.tpl query 56 in stream 0 --- start template query15.tpl query 57 in stream 0 -select /* TPC-DS query15.tpl 0.57 */ ca_zip - ,sum(cs_sales_price) - from catalog_sales - ,customer - ,customer_address - ,date_dim - where cs_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', - '85392', '85460', '80348', '81792') - or ca_state in ('CA','WA','GA') - or cs_sales_price > 500) - and cs_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 2001 - group by ca_zip - order by ca_zip - limit 100; - --- end template query15.tpl query 57 in stream 0 --- start template query6.tpl query 58 in stream 0 -select /* TPC-DS query6.tpl 0.58 */ a.ca_state state, count(*) cnt - from customer_address a - ,customer c - ,store_sales s - ,date_dim d - ,item i - where a.ca_address_sk = c.c_current_addr_sk - and c.c_customer_sk = s.ss_customer_sk - and s.ss_sold_date_sk = d.d_date_sk - and s.ss_item_sk = i.i_item_sk - and d.d_month_seq = - (select distinct (d_month_seq) - from date_dim - where d_year = 2001 - and d_moy = 1 ) - and i.i_current_price > 1.2 * - (select avg(j.i_current_price) - from item j - where j.i_category = i.i_category) - group by a.ca_state - having count(*) >= 10 - order by cnt, a.ca_state - limit 100; - --- end template query6.tpl query 58 in stream 0 --- start template query52.tpl query 59 in stream 0 -select /* TPC-DS query52.tpl 0.59 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_sales_price) ext_price - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=12 - and dt.d_year=2000 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,ext_price desc - ,brand_id -limit 100 ; - --- end template query52.tpl query 59 in stream 0 --- start template query50.tpl query 60 in stream 0 -select /* TPC-DS query50.tpl 0.60 */ - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 30) and - (sr_returned_date_sk - ss_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 60) and - (sr_returned_date_sk - ss_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 90) and - (sr_returned_date_sk - ss_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - store_sales - ,store_returns - ,store - ,date_dim d1 - ,date_dim d2 -where - d2.d_year = 2000 -and d2.d_moy = 8 -and ss_ticket_number = sr_ticket_number -and ss_item_sk = sr_item_sk -and ss_sold_date_sk = d1.d_date_sk -and sr_returned_date_sk = d2.d_date_sk -and ss_customer_sk = sr_customer_sk -and ss_store_sk = s_store_sk -group by - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -order by s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -limit 100; - --- end template query50.tpl query 60 in stream 0 --- start template query42.tpl query 61 in stream 0 -select /* TPC-DS query42.tpl 0.61 */ dt.d_year - ,item.i_category_id - ,item.i_category - ,sum(ss_ext_sales_price) - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=12 - and dt.d_year=1998 - group by dt.d_year - ,item.i_category_id - ,item.i_category - order by sum(ss_ext_sales_price) desc,dt.d_year - ,item.i_category_id - ,item.i_category -limit 100 ; - --- end template query42.tpl query 61 in stream 0 --- start template query41.tpl query 62 in stream 0 -select /* TPC-DS query41.tpl 0.62 */ distinct(i_product_name) - from item i1 - where i_manufact_id between 800 and 800+40 - and (select count(*) as item_cnt - from item - where (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'indian' or i_color = 'grey') and - (i_units = 'Oz' or i_units = 'Gross') and - (i_size = 'small' or i_size = 'petite') - ) or - (i_category = 'Women' and - (i_color = 'dim' or i_color = 'coral') and - (i_units = 'Ounce' or i_units = 'Lb') and - (i_size = 'large' or i_size = 'N/A') - ) or - (i_category = 'Men' and - (i_color = 'lawn' or i_color = 'antique') and - (i_units = 'Tsp' or i_units = 'Dram') and - (i_size = 'extra large' or i_size = 'economy') - ) or - (i_category = 'Men' and - (i_color = 'slate' or i_color = 'firebrick') and - (i_units = 'Tbl' or i_units = 'Each') and - (i_size = 'small' or i_size = 'petite') - ))) or - (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'chartreuse' or i_color = 'blue') and - (i_units = 'Unknown' or i_units = 'Box') and - (i_size = 'small' or i_size = 'petite') - ) or - (i_category = 'Women' and - (i_color = 'pale' or i_color = 'dark') and - (i_units = 'Cup' or i_units = 'Gram') and - (i_size = 'large' or i_size = 'N/A') - ) or - (i_category = 'Men' and - (i_color = 'hot' or i_color = 'light') and - (i_units = 'Bundle' or i_units = 'Ton') and - (i_size = 'extra large' or i_size = 'economy') - ) or - (i_category = 'Men' and - (i_color = 'peach' or i_color = 'rose') and - (i_units = 'Carton' or i_units = 'Pound') and - (i_size = 'small' or i_size = 'petite') - )))) > 0 - order by i_product_name - limit 100; - --- end template query41.tpl query 62 in stream 0 --- start template query8.tpl query 63 in stream 0 -select /* TPC-DS query8.tpl 0.63 */ s_store_name - ,sum(ss_net_profit) - from store_sales - ,date_dim - ,store, - (select ca_zip - from ( - SELECT substring(ca_zip,1,5) ca_zip - FROM customer_address - WHERE substring(ca_zip,1,5) IN ( - '60484','56969','50746','49459','72167','29928', - '73482','67939','29413','26150','95194', - '68311','93274','39871','13776','58085', - '18385','97134','71055','53136','56230', - '51659','39538','23936','71277','17772', - '25751','56128','16620','77787','27557', - '46035','75605','82716','10118','36054', - '62843','37335','63384','22953','33893', - '42047','76507','96871','27871','35467', - '26904','22775','27431','78481','46977', - '17524','35376','79954','19542','67294', - '23589','41453','23121','24134','22359', - '63073','44205','24293','83937','90420', - '15996','11801','57406','17623','50408', - '63219','49093','45814','42740','38855', - '96631','52756','21729','30133','84275', - '21151','39091','71449','78441','94212', - '49149','60925','58634','86490','83675', - '19582','44041','85697','78631','47454', - '23354','91846','42932','15225','39404', - '53670','30080','76550','74969','73545', - '48726','77665','12713','70987','27286', - '55483','94293','81003','57953','73302', - '80781','70657','64452','44582','40017', - '43478','71044','37616','22063','12323', - '24522','16337','96802','89058','66455', - '64952','51674','16358','19208','83249', - '96392','19279','97231','95678','91078', - '67703','98941','13961','13393','64704', - '18845','41289','43317','21913','16573', - '68268','81813','33990','79832','65206', - '72722','34242','16951','40102','28947', - '49091','40421','27930','57984','68112', - '98878','86957','23005','63424','81535', - '87437','64534','74615','18556','59551', - '51800','42782','99771','55291','21007', - '24899','92782','59683','65767','10622', - '96147','17789','43097','56372','26944', - '44373','13579','41336','63682','35734', - '85679','34194','33403','13728','13096', - '34986','47638','38862','94661','25935', - '19664','22069','17040','30119','59044', - '43636','15765','59327','91501','85006', - '87753','71827','39806','84287','28264', - '91864','24193','65305','26151','48582', - '92588','89115','13744','11983','29050', - '44217','72025','32170','90745','18069', - '16288','25524','98918','20055','20839', - '64848','18118','91813','16108','20594', - '44390','19565','80934','17873','64470', - '46501','38181','97755','16675','14517', - '25905','43551','28598','17888','76840', - '32265','42676','47601','16289','11987', - '28124','68316','21626','23695','87245', - '56600','87676','51597','61834','90711', - '63467','79205','90457','56392','34058', - '34505','13207','93566','26058','29295', - '12135','77801','18714','41118','37447', - '99671','21355','13769','62342','24639', - '27935','27343','18104','65197','37675', - '88224','31479','36207','61897','51270', - '98821','54267','49989','10754','29402', - '36718','34749','56587','51410','29505', - '11234','67543','52619','11904','53693', - '25190','45575','93954','94183','37846', - '46015','88133','66861','77953','23498', - '59482','81201','38673','46872','10444', - '44223','14708','43205','99878','71365', - '80335','16149','20614','91142','32190', - '94722','17667','16888','32454','11085', - '26569','21843','76238','13535','48351', - '70881','33336','85895','53232','80057', - '48038','63886','77142','11416','78408', - '28115','57061','63956','74843','55905', - '16405','27957','43535','36230','52220', - '62159','68452','50521','27827','18322', - '85934','72118','21757','36657','12546', - '62266','54370','10709','57779','55323', - '85299','74184','64395','51080','18148', - '97013','42119','84453','78586') - intersect - select ca_zip - from (SELECT substring(ca_zip,1,5) ca_zip,count(*) cnt - FROM customer_address, customer - WHERE ca_address_sk = c_current_addr_sk and - c_preferred_cust_flag='Y' - group by ca_zip - having count(*) > 10)A1)A2) V1 - where ss_store_sk = s_store_sk - and ss_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 2000 - and (substring(s_zip,1,2) = substring(V1.ca_zip,1,2)) - group by s_store_name - order by s_store_name - limit 100; - --- end template query8.tpl query 63 in stream 0 --- start template query12.tpl query 64 in stream 0 -select /* TPC-DS query12.tpl 0.64 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ws_ext_sales_price) as itemrevenue - ,sum(ws_ext_sales_price)*100/sum(sum(ws_ext_sales_price)) over - (partition by i_class) as revenueratio -from - web_sales - ,item - ,date_dim -where - ws_item_sk = i_item_sk - and i_category in ('Home', 'Electronics', 'Sports') - and ws_sold_date_sk = d_date_sk - and d_date between cast('2001-01-09' as date) - and dateadd(day,30,cast('2001-01-09' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query12.tpl query 64 in stream 0 --- start template query20.tpl query 65 in stream 0 -select /* TPC-DS query20.tpl 0.65 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(cs_ext_sales_price) as itemrevenue - ,sum(cs_ext_sales_price)*100/sum(sum(cs_ext_sales_price)) over - (partition by i_class) as revenueratio - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and i_category in ('Women', 'Home', 'Music') - and cs_sold_date_sk = d_date_sk - and d_date between cast('2001-05-08' as date) - and dateadd(day,30,cast('2001-05-08' as date)) - group by i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - order by i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query20.tpl query 65 in stream 0 --- start template query88.tpl query 66 in stream 0 -select /* TPC-DS query88.tpl 0.66 */ * -from - (select count(*) h8_30_to_9 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2)) - and store.s_store_name = 'ese') s1, - (select count(*) h9_to_9_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2)) - and store.s_store_name = 'ese') s2, - (select count(*) h9_30_to_10 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2)) - and store.s_store_name = 'ese') s3, - (select count(*) h10_to_10_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2)) - and store.s_store_name = 'ese') s4, - (select count(*) h10_30_to_11 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2)) - and store.s_store_name = 'ese') s5, - (select count(*) h11_to_11_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2)) - and store.s_store_name = 'ese') s6, - (select count(*) h11_30_to_12 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2)) - and store.s_store_name = 'ese') s7, - (select count(*) h12_to_12_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 12 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2)) - and store.s_store_name = 'ese') s8 -; - --- end template query88.tpl query 66 in stream 0 --- start template query82.tpl query 67 in stream 0 -select /* TPC-DS query82.tpl 0.67 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, store_sales - where i_current_price between 21 and 21+30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('2001-05-27' as date) and dateadd(day,60,cast('2001-05-27' as date)) - and i_manufact_id in (887,669,319,811) - and inv_quantity_on_hand between 100 and 500 - and ss_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query82.tpl query 67 in stream 0 --- start template query23.tpl query 68 in stream 0 -with /* TPC-DS query23.tpl 0.68 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (1998,1998+1,1998+2,1998+3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1998,1998+1,1998+2,1998+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * -from - max_store_sales)) - select sum(sales) - from (select cs_quantity*cs_list_price sales - from catalog_sales - ,date_dim - where d_year = 1998 - and d_moy = 5 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - union all - select ws_quantity*ws_list_price sales - from web_sales - ,date_dim - where d_year = 1998 - and d_moy = 5 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer)) - limit 100; -with /* TPC-DS query23.tpl 0.68 part2 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (1998,1998 + 1,1998 + 2,1998 + 3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1998,1998+1,1998+2,1998+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * - from max_store_sales)) - select c_last_name,c_first_name,sales - from (select c_last_name,c_first_name,sum(cs_quantity*cs_list_price) sales - from catalog_sales - ,customer - ,date_dim - where d_year = 1998 - and d_moy = 5 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and cs_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name - union all - select c_last_name,c_first_name,sum(ws_quantity*ws_list_price) sales - from web_sales - ,customer - ,date_dim - where d_year = 1998 - and d_moy = 5 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and ws_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name) - order by c_last_name,c_first_name,sales - limit 100; - --- end template query23.tpl query 68 in stream 0 --- start template query14a.tpl query 69 in stream 0 -with /* TPC-DS query14a.tpl 0.69 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 2000 AND 2000 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 2000 AND 2000 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 2000 AND 2000 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as - (select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2) x) -, - results AS -(select channel, i_brand_id, i_class_id, i_category_id, sum(sales) sum_sales, sum(number_sales) number_sales - from ( - select 'store' channel, i_brand_id,i_class_id - ,i_category_id,sum(ss_quantity*ss_list_price) sales - , count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2000+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales) - union all - select 'catalog' channel, i_brand_id,i_class_id,i_category_id, sum(cs_quantity*cs_list_price) sales, count(*) number_sales - from catalog_sales - ,item - ,date_dim - where cs_item_sk in (select ss_item_sk from cross_items) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2000+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(cs_quantity*cs_list_price) > (select average_sales from avg_sales) - union all - select 'web' channel, i_brand_id,i_class_id,i_category_id, sum(ws_quantity*ws_list_price) sales , count(*) number_sales - from web_sales - ,item - ,date_dim - where ws_item_sk in (select ss_item_sk from cross_items) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2000+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ws_quantity*ws_list_price) > (select average_sales from avg_sales) - ) y - group by channel, i_brand_id,i_class_id,i_category_id) - - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales -from ( - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales from results - union - select channel, i_brand_id, i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id, i_class_id - union - select channel, i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id - union - select channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel - union - select null as channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results) z -order by channel, i_brand_id, i_class_id, i_category_id - limit 100; -with /* TPC-DS query14a.tpl 0.69 part2 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 2000 AND 2000 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 2000 AND 2000 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 2000 AND 2000 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as -(select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2) x) - select this_year.channel ty_channel - ,this_year.i_brand_id ty_brand - ,this_year.i_class_id ty_class - ,this_year.i_category_id ty_category - ,this_year.sales ty_sales - ,this_year.number_sales ty_number_sales - ,last_year.channel ly_channel - ,last_year.i_brand_id ly_brand - ,last_year.i_class_id ly_class - ,last_year.i_category_id ly_category - ,last_year.sales ly_sales - ,last_year.number_sales ly_number_sales -from - (select 'store' channel, i_brand_id,i_class_id,i_category_id - ,sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 2000 + 1 - and d_moy = 12 - and d_dom = 10) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) this_year, - (select 'store' channel, i_brand_id,i_class_id - ,i_category_id, sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 2000 - and d_moy = 12 - and d_dom = 10) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) last_year - where this_year.i_brand_id= last_year.i_brand_id - and this_year.i_class_id = last_year.i_class_id - and this_year.i_category_id = last_year.i_category_id - order by this_year.channel, this_year.i_brand_id, this_year.i_class_id, this_year.i_category_id - limit 100; - --- end template query14a.tpl query 69 in stream 0 --- start template query57.tpl query 70 in stream 0 -with /* TPC-DS query57.tpl 0.70 */ v1 as( - select i_category, i_brand, - cc_name, - d_year, d_moy, - sum(cs_sales_price) sum_sales, - avg(sum(cs_sales_price)) over - (partition by i_category, i_brand, - cc_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - cc_name - order by d_year, d_moy) rn - from item, catalog_sales, date_dim, call_center - where cs_item_sk = i_item_sk and - cs_sold_date_sk = d_date_sk and - cc_call_center_sk= cs_call_center_sk and - ( - d_year = 2001 or - ( d_year = 2001-1 and d_moy =12) or - ( d_year = 2001+1 and d_moy =1) - ) - group by i_category, i_brand, - cc_name , d_year, d_moy), - v2 as( - select v1.i_category, v1.i_brand - ,v1.d_year, v1.d_moy - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1. cc_name = v1_lag. cc_name and - v1. cc_name = v1_lead. cc_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 2001 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, sum_sales - limit 100; - --- end template query57.tpl query 70 in stream 0 --- start template query65.tpl query 71 in stream 0 -select /* TPC-DS query65.tpl 0.71 */ - s_store_name, - i_item_desc, - sc.revenue, - i_current_price, - i_wholesale_cost, - i_brand - from store, item, - (select ss_store_sk, avg(revenue) as ave - from - (select ss_store_sk, ss_item_sk, - sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1207 and 1207+11 - group by ss_store_sk, ss_item_sk) sa - group by ss_store_sk) sb, - (select ss_store_sk, ss_item_sk, sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1207 and 1207+11 - group by ss_store_sk, ss_item_sk) sc - where sb.ss_store_sk = sc.ss_store_sk and - sc.revenue <= 0.1 * sb.ave and - s_store_sk = sc.ss_store_sk and - i_item_sk = sc.ss_item_sk - order by s_store_name, i_item_desc -limit 100; - --- end template query65.tpl query 71 in stream 0 --- start template query71.tpl query 72 in stream 0 -select /* TPC-DS query71.tpl 0.72 */ i_brand_id brand_id, i_brand brand,t_hour,t_minute, - sum(ext_price) ext_price - from item, (select ws_ext_sales_price as ext_price, - ws_sold_date_sk as sold_date_sk, - ws_item_sk as sold_item_sk, - ws_sold_time_sk as time_sk - from web_sales,date_dim - where d_date_sk = ws_sold_date_sk - and d_moy=11 - and d_year=1999 - union all - select cs_ext_sales_price as ext_price, - cs_sold_date_sk as sold_date_sk, - cs_item_sk as sold_item_sk, - cs_sold_time_sk as time_sk - from catalog_sales,date_dim - where d_date_sk = cs_sold_date_sk - and d_moy=11 - and d_year=1999 - union all - select ss_ext_sales_price as ext_price, - ss_sold_date_sk as sold_date_sk, - ss_item_sk as sold_item_sk, - ss_sold_time_sk as time_sk - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - and d_moy=11 - and d_year=1999 - ) tmp,time_dim - where - sold_item_sk = i_item_sk - and i_manager_id=1 - and time_sk = t_time_sk - and (t_meal_time = 'breakfast' or t_meal_time = 'dinner') - group by i_brand, i_brand_id,t_hour,t_minute - order by ext_price desc, i_brand_id - ; - --- end template query71.tpl query 72 in stream 0 --- start template query34.tpl query 73 in stream 0 -select /* TPC-DS query34.tpl 0.73 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (date_dim.d_dom between 1 and 3 or date_dim.d_dom between 25 and 28) - and (household_demographics.hd_buy_potential = '1001-5000' or - household_demographics.hd_buy_potential = '5001-10000') - and household_demographics.hd_vehicle_count > 0 - and (case when household_demographics.hd_vehicle_count > 0 - then household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count - else null - end) > 1.2 - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_county in ('Dutchess County','Carter County','Brazos County','Mesa County', - 'Arthur County','Val Verde County','Richland County','Marshall County') - group by ss_ticket_number,ss_customer_sk) dn,customer - where ss_customer_sk = c_customer_sk - and cnt between 15 and 20 - order by c_last_name,c_first_name,c_salutation,c_preferred_cust_flag desc, ss_ticket_number; - --- end template query34.tpl query 73 in stream 0 --- start template query48.tpl query 74 in stream 0 -select /* TPC-DS query48.tpl 0.74 */ sum (ss_quantity) - from store_sales, store, customer_demographics, customer_address, date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 1999 - and - ( - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'S' - and - cd_education_status = 'Secondary' - and - ss_sales_price between 100.00 and 150.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'M' - and - cd_education_status = '2 yr Degree' - and - ss_sales_price between 50.00 and 100.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'W' - and - cd_education_status = 'College' - and - ss_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('MI', 'WI', 'MN') - and ss_net_profit between 0 and 2000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('IA', 'NV', 'WV') - and ss_net_profit between 150 and 3000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('ME', 'NC', 'OH') - and ss_net_profit between 50 and 25000 - ) - ) -; - --- end template query48.tpl query 74 in stream 0 --- start template query30.tpl query 75 in stream 0 -with /* TPC-DS query30.tpl 0.75 */ customer_total_return as - (select wr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(wr_return_amt) as ctr_total_return - from web_returns - ,date_dim - ,customer_address - where wr_returned_date_sk = d_date_sk - and d_year =2000 - and wr_returning_addr_sk = ca_address_sk - group by wr_returning_customer_sk - ,ca_state) - select c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'KY' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return -limit 100; - --- end template query30.tpl query 75 in stream 0 --- start template query74.tpl query 76 in stream 0 -with /* TPC-DS query74.tpl 0.76 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,stddev_samp(ss_net_paid) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1999,1999+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,stddev_samp(ws_net_paid) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - and d_year in (1999,1999+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - ) - select - t_s_secyear.customer_id, t_s_secyear.customer_first_name, t_s_secyear.customer_last_name - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.year = 1999 - and t_s_secyear.year = 1999+1 - and t_w_firstyear.year = 1999 - and t_w_secyear.year = 1999+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - order by 3,2,1 -limit 100; - --- end template query74.tpl query 76 in stream 0 --- start template query87.tpl query 77 in stream 0 -select /* TPC-DS query87.tpl 0.77 */ count(*) -from ((select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1200 and 1200+11) - except - (select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1200 and 1200+11) - except - (select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1200 and 1200+11) -) cool_cust -; - --- end template query87.tpl query 77 in stream 0 --- start template query77a.tpl query 78 in stream 0 -with /* TPC-DS query77a.tpl 0.78 */ ss as - (select s_store_sk, - sum(ss_ext_sales_price) as sales, - sum(ss_net_profit) as profit - from store_sales, - date_dim, - store - where ss_sold_date_sk = d_date_sk - and d_date between cast('2002-08-23' as date) - and dateadd(day,30,cast('2002-08-23' as date)) - and ss_store_sk = s_store_sk - group by s_store_sk) - , - sr as - (select s_store_sk, - sum(sr_return_amt) as returns, - sum(sr_net_loss) as profit_loss - from store_returns, - date_dim, - store - where sr_returned_date_sk = d_date_sk - and d_date between cast('2002-08-23' as date) - and dateadd(day,30,cast('2002-08-23' as date)) - and sr_store_sk = s_store_sk - group by s_store_sk), - cs as - (select cs_call_center_sk, - sum(cs_ext_sales_price) as sales, - sum(cs_net_profit) as profit - from catalog_sales, - date_dim - where cs_sold_date_sk = d_date_sk - and d_date between cast('2002-08-23' as date) - and dateadd(day,30,cast('2002-08-23' as date)) - group by cs_call_center_sk - ), - cr as - (select cr_call_center_sk, - sum(cr_return_amount) as returns, - sum(cr_net_loss) as profit_loss - from catalog_returns, - date_dim - where cr_returned_date_sk = d_date_sk - and d_date between cast('2002-08-23' as date) - and dateadd(day,30,cast('2002-08-23' as date)) - group by cr_call_center_sk), - ws as - ( select wp_web_page_sk, - sum(ws_ext_sales_price) as sales, - sum(ws_net_profit) as profit - from web_sales, - date_dim, - web_page - where ws_sold_date_sk = d_date_sk - and d_date between cast('2002-08-23' as date) - and dateadd(day,30,cast('2002-08-23' as date)) - and ws_web_page_sk = wp_web_page_sk - group by wp_web_page_sk), - wr as - (select wp_web_page_sk, - sum(wr_return_amt) as returns, - sum(wr_net_loss) as profit_loss - from web_returns, - date_dim, - web_page - where wr_returned_date_sk = d_date_sk - and d_date between cast('2002-08-23' as date) - and dateadd(day,30,cast('2002-08-23' as date)) - and wr_web_page_sk = wp_web_page_sk - group by wp_web_page_sk) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , ss.s_store_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ss left join sr - on ss.s_store_sk = sr.s_store_sk - union all - select 'catalog channel' as channel - , cs_call_center_sk as id - , sales - , returns - , (profit - profit_loss) as profit - from cs - , cr - union all - select 'web channel' as channel - , ws.wp_web_page_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ws left join wr - on ws.wp_web_page_sk = wr.wp_web_page_sk - ) x - group by channel, id ) - - select * - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results -) foo -order by channel, id - limit 100; - --- end template query77a.tpl query 78 in stream 0 --- start template query73.tpl query 79 in stream 0 -select /* TPC-DS query73.tpl 0.79 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_buy_potential = '501-1000' or - household_demographics.hd_buy_potential = '0-500') - and household_demographics.hd_vehicle_count > 0 - and case when household_demographics.hd_vehicle_count > 0 then - household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count else null end > 1 - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_county in ('Van Buren County','Morgan County','Marshall County','McHenry County') - group by ss_ticket_number,ss_customer_sk) dj,customer - where ss_customer_sk = c_customer_sk - and cnt between 1 and 5 - order by cnt desc, c_last_name asc; - --- end template query73.tpl query 79 in stream 0 --- start template query84.tpl query 80 in stream 0 -select /* TPC-DS query84.tpl 0.80 */ c_customer_id as customer_id - , coalesce(c_last_name,'') || ', ' || coalesce(c_first_name,'') as customername - from customer - ,customer_address - ,customer_demographics - ,household_demographics - ,income_band - ,store_returns - where ca_city = 'Deerfield' - and c_current_addr_sk = ca_address_sk - and ib_lower_bound >= 27408 - and ib_upper_bound <= 27408 + 50000 - and ib_income_band_sk = hd_income_band_sk - and cd_demo_sk = c_current_cdemo_sk - and hd_demo_sk = c_current_hdemo_sk - and sr_cdemo_sk = cd_demo_sk - order by c_customer_id - limit 100; - --- end template query84.tpl query 80 in stream 0 --- start template query54.tpl query 81 in stream 0 -with /* TPC-DS query54.tpl 0.81 */ my_customers as ( - select distinct c_customer_sk - , c_current_addr_sk - from - ( select cs_sold_date_sk sold_date_sk, - cs_bill_customer_sk customer_sk, - cs_item_sk item_sk - from catalog_sales - union all - select ws_sold_date_sk sold_date_sk, - ws_bill_customer_sk customer_sk, - ws_item_sk item_sk - from web_sales - ) cs_or_ws_sales, - item, - date_dim, - customer - where sold_date_sk = d_date_sk - and item_sk = i_item_sk - and i_category = 'Sports' - and i_class = 'football' - and c_customer_sk = cs_or_ws_sales.customer_sk - and d_moy = 3 - and d_year = 1999 - ) - , my_revenue as ( - select c_customer_sk, - sum(ss_ext_sales_price) as revenue - from my_customers, - store_sales, - customer_address, - store, - date_dim - where c_current_addr_sk = ca_address_sk - and ca_county = s_county - and ca_state = s_state - and ss_sold_date_sk = d_date_sk - and c_customer_sk = ss_customer_sk - and d_month_seq between (select distinct d_month_seq+1 - from date_dim where d_year = 1999 and d_moy = 3) - and (select distinct d_month_seq+3 - from date_dim where d_year = 1999 and d_moy = 3) - group by c_customer_sk - ) - , segments as - (select cast((revenue/50) as bigint) as segment - from my_revenue - ) - select segment, count(*) as num_customers, segment*50 as segment_base - from segments - group by segment - order by segment, num_customers - limit 100; - --- end template query54.tpl query 81 in stream 0 --- start template query55.tpl query 82 in stream 0 -select /* TPC-DS query55.tpl 0.82 */ i_brand_id brand_id, i_brand brand, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=70 - and d_moy=12 - and d_year=1999 - group by i_brand, i_brand_id - order by ext_price desc, i_brand_id -limit 100 ; - --- end template query55.tpl query 82 in stream 0 --- start template query56.tpl query 83 in stream 0 -with /* TPC-DS query56.tpl 0.83 */ ss as ( - select i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where i_item_id in (select - i_item_id -from item -where i_color in ('firebrick','burnished','lavender')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 6 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - cs as ( - select i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('firebrick','burnished','lavender')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 6 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - ws as ( - select i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('firebrick','burnished','lavender')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 6 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id) - select i_item_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by total_sales, - i_item_id - limit 100; - --- end template query56.tpl query 83 in stream 0 --- start template query2.tpl query 84 in stream 0 -with /* TPC-DS query2.tpl 0.84 */ wscs as - (select sold_date_sk - ,sales_price - from (select ws_sold_date_sk sold_date_sk - ,ws_ext_sales_price sales_price - from web_sales - union all - select cs_sold_date_sk sold_date_sk - ,cs_ext_sales_price sales_price - from catalog_sales)), - wswscs as - (select d_week_seq, - sum(case when (d_day_name='Sunday') then sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then sales_price else null end) sat_sales - from wscs - ,date_dim - where d_date_sk = sold_date_sk - group by d_week_seq) - select d_week_seq1 - ,round(sun_sales1/sun_sales2,2) - ,round(mon_sales1/mon_sales2,2) - ,round(tue_sales1/tue_sales2,2) - ,round(wed_sales1/wed_sales2,2) - ,round(thu_sales1/thu_sales2,2) - ,round(fri_sales1/fri_sales2,2) - ,round(sat_sales1/sat_sales2,2) - from - (select wswscs.d_week_seq d_week_seq1 - ,sun_sales sun_sales1 - ,mon_sales mon_sales1 - ,tue_sales tue_sales1 - ,wed_sales wed_sales1 - ,thu_sales thu_sales1 - ,fri_sales fri_sales1 - ,sat_sales sat_sales1 - from wswscs,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 2001) y, - (select wswscs.d_week_seq d_week_seq2 - ,sun_sales sun_sales2 - ,mon_sales mon_sales2 - ,tue_sales tue_sales2 - ,wed_sales wed_sales2 - ,thu_sales thu_sales2 - ,fri_sales fri_sales2 - ,sat_sales sat_sales2 - from wswscs - ,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 2001+1) z - where d_week_seq1=d_week_seq2-53 - order by d_week_seq1; - --- end template query2.tpl query 84 in stream 0 --- start template query26.tpl query 85 in stream 0 -select /* TPC-DS query26.tpl 0.85 */ i_item_id, - avg(cs_quantity) agg1, - avg(cs_list_price) agg2, - avg(cs_coupon_amt) agg3, - avg(cs_sales_price) agg4 - from catalog_sales, customer_demographics, date_dim, item, promotion - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd_demo_sk and - cs_promo_sk = p_promo_sk and - cd_gender = 'F' and - cd_marital_status = 'M' and - cd_education_status = 'College' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 2002 - group by i_item_id - order by i_item_id - limit 100; - --- end template query26.tpl query 85 in stream 0 --- start template query40.tpl query 86 in stream 0 -select /* TPC-DS query40.tpl 0.86 */ - w_state - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('1998-02-21' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_before - ,sum(case when (cast(d_date as date) >= cast ('1998-02-21' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_after - from - catalog_sales left outer join catalog_returns on - (cs_order_number = cr_order_number - and cs_item_sk = cr_item_sk) - ,warehouse - ,item - ,date_dim - where - i_current_price between 0.99 and 1.49 - and i_item_sk = cs_item_sk - and cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('1998-02-21' as date)) - and dateadd(day,30,cast ('1998-02-21' as date)) - group by - w_state,i_item_id - order by w_state,i_item_id -limit 100; - --- end template query40.tpl query 86 in stream 0 --- start template query72.tpl query 87 in stream 0 -select /* TPC-DS query72.tpl 0.87 */ i_item_desc - ,w_warehouse_name - ,d1.d_week_seq - ,sum(case when p_promo_sk is null then 1 else 0 end) no_promo - ,sum(case when p_promo_sk is not null then 1 else 0 end) promo - ,count(*) total_cnt -from catalog_sales -join inventory on (cs_item_sk = inv_item_sk) -join warehouse on (w_warehouse_sk=inv_warehouse_sk) -join item on (i_item_sk = cs_item_sk) -join customer_demographics on (cs_bill_cdemo_sk = cd_demo_sk) -join household_demographics on (cs_bill_hdemo_sk = hd_demo_sk) -join date_dim d1 on (cs_sold_date_sk = d1.d_date_sk) -join date_dim d2 on (inv_date_sk = d2.d_date_sk) -join date_dim d3 on (cs_ship_date_sk = d3.d_date_sk) -left outer join promotion on (cs_promo_sk=p_promo_sk) -left outer join catalog_returns on (cr_item_sk = cs_item_sk and cr_order_number = cs_order_number) -where d1.d_week_seq = d2.d_week_seq - and inv_quantity_on_hand < cs_quantity - and d3.d_date > d1.d_date + 5 - and hd_buy_potential = '1001-5000' - and d1.d_year = 2000 - and cd_marital_status = 'M' -group by i_item_desc,w_warehouse_name,d1.d_week_seq -order by total_cnt desc, i_item_desc, w_warehouse_name, d_week_seq -limit 100; - --- end template query72.tpl query 87 in stream 0 --- start template query53.tpl query 88 in stream 0 -select /* TPC-DS query53.tpl 0.88 */ * from -(select i_manufact_id, -sum(ss_sales_price) sum_sales, -avg(sum(ss_sales_price)) over (partition by i_manufact_id) avg_quarterly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and -ss_sold_date_sk = d_date_sk and -ss_store_sk = s_store_sk and -d_month_seq in (1201,1201+1,1201+2,1201+3,1201+4,1201+5,1201+6,1201+7,1201+8,1201+9,1201+10,1201+11) and -((i_category in ('Books','Children','Electronics') and -i_class in ('personal','portable','reference','self-help') and -i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) -or(i_category in ('Women','Music','Men') and -i_class in ('accessories','classical','fragrances','pants') and -i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manufact_id, d_qoy ) tmp1 -where case when avg_quarterly_sales > 0 - then abs (sum_sales - avg_quarterly_sales)/ avg_quarterly_sales - else null end > 0.1 -order by avg_quarterly_sales, - sum_sales, - i_manufact_id -limit 100; - --- end template query53.tpl query 88 in stream 0 --- start template query79.tpl query 89 in stream 0 -select /* TPC-DS query79.tpl 0.89 */ - c_last_name,c_first_name,substring(s_city,1,30),ss_ticket_number,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,store.s_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (household_demographics.hd_dep_count = 2 or household_demographics.hd_vehicle_count > -1) - and date_dim.d_dow = 1 - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_number_employees between 200 and 295 - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,store.s_city) ms,customer - where ss_customer_sk = c_customer_sk - order by c_last_name,c_first_name,substring(s_city,1,30), profit -limit 100; - --- end template query79.tpl query 89 in stream 0 --- start template query18a.tpl query 90 in stream 0 -with /* TPC-DS query18a.tpl 0.90 */ results as - (select i_item_id, - ca_country, - ca_state, - ca_county, - cast(cs_quantity as decimal(12,2)) agg1, - cast(cs_list_price as decimal(12,2)) agg2, - cast(cs_coupon_amt as decimal(12,2)) agg3, - cast(cs_sales_price as decimal(12,2)) agg4, - cast(cs_net_profit as decimal(12,2)) agg5, - cast(c_birth_year as decimal(12,2)) agg6, - cast(cd1.cd_dep_count as decimal(12,2)) agg7 - from catalog_sales, customer_demographics cd1, customer_demographics cd2, customer, customer_address, date_dim, item - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd1.cd_demo_sk and - cs_bill_customer_sk = c_customer_sk and - cd1.cd_gender = 'F' and - cd1.cd_education_status = 'College' and - c_current_cdemo_sk = cd2.cd_demo_sk and - c_current_addr_sk = ca_address_sk and - c_birth_month in (7,2,10,9,12,5) and - d_year = 2002 and - ca_state in ('KY','NC','IA','NY','NV','IL','NE') - ) - select i_item_id, ca_country, ca_state, ca_county, agg1, agg2, agg3, agg4, agg5, agg6, agg7 - from ( - select i_item_id, ca_country, ca_state, ca_county, avg(agg1) agg1, - avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state, ca_county - union all - select i_item_id, ca_country, ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state - union all - select i_item_id, ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country - union all - select i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - ) foo - order by ca_country, ca_state, ca_county, i_item_id - limit 100; - --- end template query18a.tpl query 90 in stream 0 --- start template query13.tpl query 91 in stream 0 -select /* TPC-DS query13.tpl 0.91 */ avg(ss_quantity) - ,avg(ss_ext_sales_price) - ,avg(ss_ext_wholesale_cost) - ,sum(ss_ext_wholesale_cost) - from store_sales - ,store - ,customer_demographics - ,household_demographics - ,customer_address - ,date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2001 - and((ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'D' - and cd_education_status = 'College' - and ss_sales_price between 100.00 and 150.00 - and hd_dep_count = 3 - )or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'S' - and cd_education_status = 'Primary' - and ss_sales_price between 50.00 and 100.00 - and hd_dep_count = 1 - ) or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'U' - and cd_education_status = 'Secondary' - and ss_sales_price between 150.00 and 200.00 - and hd_dep_count = 1 - )) - and((ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('KS', 'MI', 'MT') - and ss_net_profit between 100 and 200 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('MS', 'TX', 'AR') - and ss_net_profit between 150 and 300 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('IN', 'IA', 'OH') - and ss_net_profit between 50 and 250 - )) -; - --- end template query13.tpl query 91 in stream 0 --- start template query24.tpl query 92 in stream 0 -with /* TPC-DS query24.tpl 0.92 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_net_paid_inc_tax) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip -and s_market_id=6 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'yellow' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; -with /* TPC-DS query24.tpl 0.92 part2 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_net_paid_inc_tax) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip - and s_market_id = 6 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'maroon' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; - --- end template query24.tpl query 92 in stream 0 --- start template query4.tpl query 93 in stream 0 -with /* TPC-DS query4.tpl 0.93 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(((ss_ext_list_price-ss_ext_wholesale_cost-ss_ext_discount_amt)+ss_ext_sales_price)/2) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((cs_ext_list_price-cs_ext_wholesale_cost-cs_ext_discount_amt)+cs_ext_sales_price)/2) ) year_total - ,'c' sale_type - from customer - ,catalog_sales - ,date_dim - where c_customer_sk = cs_bill_customer_sk - and cs_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year -union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((ws_ext_list_price-ws_ext_wholesale_cost-ws_ext_discount_amt)+ws_ext_sales_price)/2) ) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_birth_country - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_c_firstyear - ,year_total t_c_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_c_secyear.customer_id - and t_s_firstyear.customer_id = t_c_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_c_firstyear.sale_type = 'c' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_c_secyear.sale_type = 'c' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 1999 - and t_s_secyear.dyear = 1999+1 - and t_c_firstyear.dyear = 1999 - and t_c_secyear.dyear = 1999+1 - and t_w_firstyear.dyear = 1999 - and t_w_secyear.dyear = 1999+1 - and t_s_firstyear.year_total > 0 - and t_c_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_birth_country -limit 100; - --- end template query4.tpl query 93 in stream 0 --- start template query99.tpl query 94 in stream 0 -select /* TPC-DS query99.tpl 0.94 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 30) and - (cs_ship_date_sk - cs_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 60) and - (cs_ship_date_sk - cs_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 90) and - (cs_ship_date_sk - cs_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - catalog_sales - ,warehouse - ,ship_mode - ,call_center - ,date_dim -where - d_month_seq between 1220 and 1220 + 11 -and cs_ship_date_sk = d_date_sk -and cs_warehouse_sk = w_warehouse_sk -and cs_ship_mode_sk = sm_ship_mode_sk -and cs_call_center_sk = cc_call_center_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -limit 100; - --- end template query99.tpl query 94 in stream 0 --- start template query68.tpl query 95 in stream 0 -select /* TPC-DS query68.tpl 0.95 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,extended_price - ,extended_tax - ,list_price - from (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_ext_sales_price) extended_price - ,sum(ss_ext_list_price) list_price - ,sum(ss_ext_tax) extended_tax - from store_sales - ,date_dim - ,store - ,household_demographics - ,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_dep_count = 1 or - household_demographics.hd_vehicle_count= 1) - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_city in ('Madison','Mechanicsville') - group by ss_ticket_number - ,ss_customer_sk - ,ss_addr_sk,ca_city) dn - ,customer - ,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,ss_ticket_number - limit 100; - --- end template query68.tpl query 95 in stream 0 --- start template query83.tpl query 96 in stream 0 -with /* TPC-DS query83.tpl 0.96 */ sr_items as - (select i_item_id item_id, - sum(sr_return_quantity) sr_item_qty - from store_returns, - item, - date_dim - where sr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2000-06-24','2000-08-02','2000-11-06'))) - and sr_returned_date_sk = d_date_sk - group by i_item_id), - cr_items as - (select i_item_id item_id, - sum(cr_return_quantity) cr_item_qty - from catalog_returns, - item, - date_dim - where cr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2000-06-24','2000-08-02','2000-11-06'))) - and cr_returned_date_sk = d_date_sk - group by i_item_id), - wr_items as - (select i_item_id item_id, - sum(wr_return_quantity) wr_item_qty - from web_returns, - item, - date_dim - where wr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2000-06-24','2000-08-02','2000-11-06'))) - and wr_returned_date_sk = d_date_sk - group by i_item_id) - select sr_items.item_id - ,sr_item_qty - ,sr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 sr_dev - ,cr_item_qty - ,cr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 cr_dev - ,wr_item_qty - ,wr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 wr_dev - ,(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 average - from sr_items - ,cr_items - ,wr_items - where sr_items.item_id=cr_items.item_id - and sr_items.item_id=wr_items.item_id - order by sr_items.item_id - ,sr_item_qty - limit 100; - --- end template query83.tpl query 96 in stream 0 --- start template query61.tpl query 97 in stream 0 -select /* TPC-DS query61.tpl 0.97 */ promotions,total,cast(promotions as decimal(15,4))/cast(total as decimal(15,4))*100 -from - (select sum(ss_ext_sales_price) promotions - from store_sales - ,store - ,promotion - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_promo_sk = p_promo_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -7 - and i_category = 'Home' - and (p_channel_dmail = 'Y' or p_channel_email = 'Y' or p_channel_tv = 'Y') - and s_gmt_offset = -7 - and d_year = 2001 - and d_moy = 11) promotional_sales, - (select sum(ss_ext_sales_price) total - from store_sales - ,store - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -7 - and i_category = 'Home' - and s_gmt_offset = -7 - and d_year = 2001 - and d_moy = 11) all_sales -order by promotions, total -limit 100; - --- end template query61.tpl query 97 in stream 0 --- start template query5a.tpl query 98 in stream 0 -with /* TPC-DS query5a.tpl 0.98 */ ssr as - (select s_store_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ss_store_sk as store_sk, - ss_sold_date_sk as date_sk, - ss_ext_sales_price as sales_price, - ss_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from store_sales - union all - select sr_store_sk as store_sk, - sr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - sr_return_amt as return_amt, - sr_net_loss as net_loss - from store_returns - ) salesreturns, - date_dim, - store - where date_sk = d_date_sk - and d_date between cast('2002-08-02' as date) - and dateadd(day,14,cast('2002-08-02' as date)) - and store_sk = s_store_sk - group by s_store_id) - , - csr as - (select cp_catalog_page_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select cs_catalog_page_sk as page_sk, - cs_sold_date_sk as date_sk, - cs_ext_sales_price as sales_price, - cs_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from catalog_sales - union all - select cr_catalog_page_sk as page_sk, - cr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - cr_return_amount as return_amt, - cr_net_loss as net_loss - from catalog_returns - ) salesreturns, - date_dim, - catalog_page - where date_sk = d_date_sk - and d_date between cast('2002-08-02' as date) - and dateadd(day,14,cast('2002-08-02' as date)) - and page_sk = cp_catalog_page_sk - group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ws_web_site_sk as wsr_web_site_sk, - ws_sold_date_sk as date_sk, - ws_ext_sales_price as sales_price, - ws_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from web_sales - union all - select ws_web_site_sk as wsr_web_site_sk, - wr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - wr_return_amt as return_amt, - wr_net_loss as net_loss - from web_returns left outer join web_sales on - ( wr_item_sk = ws_item_sk - and wr_order_number = ws_order_number) - ) salesreturns, - date_dim, - web_site - where date_sk = d_date_sk - and d_date between cast('2002-08-02' as date) - and dateadd(day,14,cast('2002-08-02' as date)) - and wsr_web_site_sk = web_site_sk - group by web_site_id) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || s_store_id as id - , sales - , returns - , (profit - profit_loss) as profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || cp_catalog_page_id as id - , sales - , returns - , (profit - profit_loss) as profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , (profit - profit_loss) as profit - from wsr - ) x - group by channel, id) - select channel, id, sales, returns, profit from ( - select channel, id, sales, returns, profit from results - union - select channel, null as id, sum(sales), sum(returns), sum(profit) from results group by channel - union - select null as channel, null as id, sum(sales), sum(returns), sum(profit) from results) foo -order by channel, id -limit 100; - --- end template query5a.tpl query 98 in stream 0 --- start template query76.tpl query 99 in stream 0 -select /* TPC-DS query76.tpl 0.99 */ channel, col_name, d_year, d_qoy, i_category, COUNT(*) sales_cnt, SUM(ext_sales_price) sales_amt FROM ( - SELECT 'store' as channel, 'ss_hdemo_sk' col_name, d_year, d_qoy, i_category, ss_ext_sales_price ext_sales_price - FROM store_sales, item, date_dim - WHERE ss_hdemo_sk IS NULL - AND ss_sold_date_sk=d_date_sk - AND ss_item_sk=i_item_sk - UNION ALL - SELECT 'web' as channel, 'ws_bill_addr_sk' col_name, d_year, d_qoy, i_category, ws_ext_sales_price ext_sales_price - FROM web_sales, item, date_dim - WHERE ws_bill_addr_sk IS NULL - AND ws_sold_date_sk=d_date_sk - AND ws_item_sk=i_item_sk - UNION ALL - SELECT 'catalog' as channel, 'cs_bill_hdemo_sk' col_name, d_year, d_qoy, i_category, cs_ext_sales_price ext_sales_price - FROM catalog_sales, item, date_dim - WHERE cs_bill_hdemo_sk IS NULL - AND cs_sold_date_sk=d_date_sk - AND cs_item_sk=i_item_sk) foo -GROUP BY channel, col_name, d_year, d_qoy, i_category -ORDER BY channel, col_name, d_year, d_qoy, i_category -limit 100; - --- end template query76.tpl query 99 in stream 0 diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/30TB/queries/query_1.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/30TB/queries/query_1.sql deleted file mode 100644 index e64e1aa6..00000000 --- a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/30TB/queries/query_1.sql +++ /dev/null @@ -1,5027 +0,0 @@ --- start template query83.tpl query 1 in stream 1 -with /* TPC-DS query83.tpl 0.96 */ sr_items as - (select i_item_id item_id, - sum(sr_return_quantity) sr_item_qty - from store_returns, - item, - date_dim - where sr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2000-06-14','2000-08-18','2000-11-22'))) - and sr_returned_date_sk = d_date_sk - group by i_item_id), - cr_items as - (select i_item_id item_id, - sum(cr_return_quantity) cr_item_qty - from catalog_returns, - item, - date_dim - where cr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2000-06-14','2000-08-18','2000-11-22'))) - and cr_returned_date_sk = d_date_sk - group by i_item_id), - wr_items as - (select i_item_id item_id, - sum(wr_return_quantity) wr_item_qty - from web_returns, - item, - date_dim - where wr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2000-06-14','2000-08-18','2000-11-22'))) - and wr_returned_date_sk = d_date_sk - group by i_item_id) - select sr_items.item_id - ,sr_item_qty - ,sr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 sr_dev - ,cr_item_qty - ,cr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 cr_dev - ,wr_item_qty - ,wr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 wr_dev - ,(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 average - from sr_items - ,cr_items - ,wr_items - where sr_items.item_id=cr_items.item_id - and sr_items.item_id=wr_items.item_id - order by sr_items.item_id - ,sr_item_qty - limit 100; - --- end template query83.tpl query 1 in stream 1 --- start template query32.tpl query 2 in stream 1 -select /* TPC-DS query32.tpl 0.7 */ sum(cs_ext_discount_amt) as "excess discount amount" -from - catalog_sales - ,item - ,date_dim -where -i_manufact_id = 315 -and i_item_sk = cs_item_sk -and d_date between '2000-03-07' and - dateadd(day,90,cast('2000-03-07' as date)) -and d_date_sk = cs_sold_date_sk -and cs_ext_discount_amt - > ( - select - 1.3 * avg(cs_ext_discount_amt) - from - catalog_sales - ,date_dim - where - cs_item_sk = i_item_sk - and d_date between '2000-03-07' and - dateadd(day,90,cast('2000-03-07' as date)) - and d_date_sk = cs_sold_date_sk - ) -limit 100; - --- end template query32.tpl query 2 in stream 1 --- start template query30.tpl query 3 in stream 1 -with /* TPC-DS query30.tpl 0.75 */ customer_total_return as - (select wr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(wr_return_amt) as ctr_total_return - from web_returns - ,date_dim - ,customer_address - where wr_returned_date_sk = d_date_sk - and d_year =2001 - and wr_returning_addr_sk = ca_address_sk - group by wr_returning_customer_sk - ,ca_state) - select c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'ND' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return -limit 100; - --- end template query30.tpl query 3 in stream 1 --- start template query92.tpl query 4 in stream 1 -select /* TPC-DS query92.tpl 0.44 */ - sum(ws_ext_discount_amt) as "Excess Discount Amount" -from - web_sales - ,item - ,date_dim -where -i_manufact_id = 402 -and i_item_sk = ws_item_sk -and d_date between '2001-03-04' and - dateadd(day,90,cast('2001-03-04' as date)) -and d_date_sk = ws_sold_date_sk -and ws_ext_discount_amt - > ( - SELECT - 1.3 * avg(ws_ext_discount_amt) - FROM - web_sales - ,date_dim - WHERE - ws_item_sk = i_item_sk - and d_date between '2001-03-04' and - dateadd(day,90,cast('2001-03-04' as date)) - and d_date_sk = ws_sold_date_sk - ) -order by sum(ws_ext_discount_amt) -limit 100; - --- end template query92.tpl query 4 in stream 1 --- start template query66.tpl query 5 in stream 1 -select /* TPC-DS query66.tpl 0.39 */ - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - ,sum(jan_sales) as jan_sales - ,sum(feb_sales) as feb_sales - ,sum(mar_sales) as mar_sales - ,sum(apr_sales) as apr_sales - ,sum(may_sales) as may_sales - ,sum(jun_sales) as jun_sales - ,sum(jul_sales) as jul_sales - ,sum(aug_sales) as aug_sales - ,sum(sep_sales) as sep_sales - ,sum(oct_sales) as oct_sales - ,sum(nov_sales) as nov_sales - ,sum(dec_sales) as dec_sales - ,sum(jan_sales/w_warehouse_sq_ft) as jan_sales_per_sq_foot - ,sum(feb_sales/w_warehouse_sq_ft) as feb_sales_per_sq_foot - ,sum(mar_sales/w_warehouse_sq_ft) as mar_sales_per_sq_foot - ,sum(apr_sales/w_warehouse_sq_ft) as apr_sales_per_sq_foot - ,sum(may_sales/w_warehouse_sq_ft) as may_sales_per_sq_foot - ,sum(jun_sales/w_warehouse_sq_ft) as jun_sales_per_sq_foot - ,sum(jul_sales/w_warehouse_sq_ft) as jul_sales_per_sq_foot - ,sum(aug_sales/w_warehouse_sq_ft) as aug_sales_per_sq_foot - ,sum(sep_sales/w_warehouse_sq_ft) as sep_sales_per_sq_foot - ,sum(oct_sales/w_warehouse_sq_ft) as oct_sales_per_sq_foot - ,sum(nov_sales/w_warehouse_sq_ft) as nov_sales_per_sq_foot - ,sum(dec_sales/w_warehouse_sq_ft) as dec_sales_per_sq_foot - ,sum(jan_net) as jan_net - ,sum(feb_net) as feb_net - ,sum(mar_net) as mar_net - ,sum(apr_net) as apr_net - ,sum(may_net) as may_net - ,sum(jun_net) as jun_net - ,sum(jul_net) as jul_net - ,sum(aug_net) as aug_net - ,sum(sep_net) as sep_net - ,sum(oct_net) as oct_net - ,sum(nov_net) as nov_net - ,sum(dec_net) as dec_net - from ( - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'ALLIANCE' || ',' || 'AIRBORNE' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then ws_ext_sales_price* ws_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then ws_ext_sales_price* ws_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then ws_ext_sales_price* ws_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then ws_ext_sales_price* ws_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then ws_ext_sales_price* ws_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then ws_ext_sales_price* ws_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then ws_ext_sales_price* ws_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then ws_ext_sales_price* ws_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then ws_ext_sales_price* ws_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then ws_ext_sales_price* ws_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then ws_ext_sales_price* ws_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then ws_ext_sales_price* ws_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then ws_net_paid * ws_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then ws_net_paid * ws_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then ws_net_paid * ws_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then ws_net_paid * ws_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then ws_net_paid * ws_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then ws_net_paid * ws_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then ws_net_paid * ws_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then ws_net_paid * ws_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then ws_net_paid * ws_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then ws_net_paid * ws_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then ws_net_paid * ws_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then ws_net_paid * ws_quantity else 0 end) as dec_net - from - web_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - ws_warehouse_sk = w_warehouse_sk - and ws_sold_date_sk = d_date_sk - and ws_sold_time_sk = t_time_sk - and ws_ship_mode_sk = sm_ship_mode_sk - and d_year = 1999 - and t_time between 30414 and 30414+28800 - and sm_carrier in ('ALLIANCE','AIRBORNE') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - union all - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'ALLIANCE' || ',' || 'AIRBORNE' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then cs_ext_sales_price* cs_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then cs_ext_sales_price* cs_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then cs_ext_sales_price* cs_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then cs_ext_sales_price* cs_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then cs_ext_sales_price* cs_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then cs_ext_sales_price* cs_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then cs_ext_sales_price* cs_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then cs_ext_sales_price* cs_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then cs_ext_sales_price* cs_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then cs_ext_sales_price* cs_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then cs_ext_sales_price* cs_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then cs_ext_sales_price* cs_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then cs_net_paid * cs_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then cs_net_paid * cs_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then cs_net_paid * cs_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then cs_net_paid * cs_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then cs_net_paid * cs_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then cs_net_paid * cs_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then cs_net_paid * cs_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then cs_net_paid * cs_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then cs_net_paid * cs_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then cs_net_paid * cs_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then cs_net_paid * cs_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then cs_net_paid * cs_quantity else 0 end) as dec_net - from - catalog_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and cs_sold_time_sk = t_time_sk - and cs_ship_mode_sk = sm_ship_mode_sk - and d_year = 1999 - and t_time between 30414 AND 30414+28800 - and sm_carrier in ('ALLIANCE','AIRBORNE') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - ) x - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - order by w_warehouse_name - limit 100; - --- end template query66.tpl query 5 in stream 1 --- start template query84.tpl query 6 in stream 1 -select /* TPC-DS query84.tpl 0.80 */ c_customer_id as customer_id - , coalesce(c_last_name,'') || ', ' || coalesce(c_first_name,'') as customername - from customer - ,customer_address - ,customer_demographics - ,household_demographics - ,income_band - ,store_returns - where ca_city = 'Belmont' - and c_current_addr_sk = ca_address_sk - and ib_lower_bound >= 39473 - and ib_upper_bound <= 39473 + 50000 - and ib_income_band_sk = hd_income_band_sk - and cd_demo_sk = c_current_cdemo_sk - and hd_demo_sk = c_current_hdemo_sk - and sr_cdemo_sk = cd_demo_sk - order by c_customer_id - limit 100; - --- end template query84.tpl query 6 in stream 1 --- start template query98.tpl query 7 in stream 1 -select /* TPC-DS query98.tpl 0.32 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ss_ext_sales_price) as itemrevenue - ,sum(ss_ext_sales_price)*100/sum(sum(ss_ext_sales_price)) over - (partition by i_class) as revenueratio -from - store_sales - ,item - ,date_dim -where - ss_item_sk = i_item_sk - and i_category in ('Music', 'Electronics', 'Sports') - and ss_sold_date_sk = d_date_sk - and d_date between cast('2002-01-12' as date) - and dateadd(day,30,cast('2002-01-12' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio; - --- end template query98.tpl query 7 in stream 1 --- start template query58.tpl query 8 in stream 1 -with /* TPC-DS query58.tpl 0.19 */ ss_items as - (select i_item_id item_id - ,sum(ss_ext_sales_price) ss_item_rev - from store_sales - ,item - ,date_dim - where ss_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '1998-05-16')) - and ss_sold_date_sk = d_date_sk - group by i_item_id), - cs_items as - (select i_item_id item_id - ,sum(cs_ext_sales_price) cs_item_rev - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '1998-05-16')) - and cs_sold_date_sk = d_date_sk - group by i_item_id), - ws_items as - (select i_item_id item_id - ,sum(ws_ext_sales_price) ws_item_rev - from web_sales - ,item - ,date_dim - where ws_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq =(select d_week_seq - from date_dim - where d_date = '1998-05-16')) - and ws_sold_date_sk = d_date_sk - group by i_item_id) - select ss_items.item_id - ,ss_item_rev - ,ss_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ss_dev - ,cs_item_rev - ,cs_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 cs_dev - ,ws_item_rev - ,ws_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ws_dev - ,(ss_item_rev+cs_item_rev+ws_item_rev)/3 average - from ss_items,cs_items,ws_items - where ss_items.item_id=cs_items.item_id - and ss_items.item_id=ws_items.item_id - and ss_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - and ss_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and cs_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and cs_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and ws_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and ws_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - order by item_id - ,ss_item_rev - limit 100; - --- end template query58.tpl query 8 in stream 1 --- start template query16.tpl query 9 in stream 1 -select /* TPC-DS query16.tpl 0.25 */ - count(distinct cs_order_number) as "order count" - ,sum(cs_ext_ship_cost) as "total shipping cost" - ,sum(cs_net_profit) as "total net profit" -from - catalog_sales cs1 - ,date_dim - ,customer_address - ,call_center -where - d_date between '2000-4-01' and - dateadd(day, 60, cast('2000-4-01' as date)) -and cs1.cs_ship_date_sk = d_date_sk -and cs1.cs_ship_addr_sk = ca_address_sk -and ca_state = 'MI' -and cs1.cs_call_center_sk = cc_call_center_sk -and cc_county in ('Huron County','Luce County','Perry County','Marshall County', - 'Walker County' -) -and exists (select * - from catalog_sales cs2 - where cs1.cs_order_number = cs2.cs_order_number - and cs1.cs_warehouse_sk <> cs2.cs_warehouse_sk) -and not exists(select * - from catalog_returns cr1 - where cs1.cs_order_number = cr1.cr_order_number) -order by count(distinct cs_order_number) -limit 100; - --- end template query16.tpl query 9 in stream 1 --- start template query77a.tpl query 10 in stream 1 -with /* TPC-DS query77a.tpl 0.78 */ ss as - (select s_store_sk, - sum(ss_ext_sales_price) as sales, - sum(ss_net_profit) as profit - from store_sales, - date_dim, - store - where ss_sold_date_sk = d_date_sk - and d_date between cast('1998-08-03' as date) - and dateadd(day,30,cast('1998-08-03' as date)) - and ss_store_sk = s_store_sk - group by s_store_sk) - , - sr as - (select s_store_sk, - sum(sr_return_amt) as returns, - sum(sr_net_loss) as profit_loss - from store_returns, - date_dim, - store - where sr_returned_date_sk = d_date_sk - and d_date between cast('1998-08-03' as date) - and dateadd(day,30,cast('1998-08-03' as date)) - and sr_store_sk = s_store_sk - group by s_store_sk), - cs as - (select cs_call_center_sk, - sum(cs_ext_sales_price) as sales, - sum(cs_net_profit) as profit - from catalog_sales, - date_dim - where cs_sold_date_sk = d_date_sk - and d_date between cast('1998-08-03' as date) - and dateadd(day,30,cast('1998-08-03' as date)) - group by cs_call_center_sk - ), - cr as - (select cr_call_center_sk, - sum(cr_return_amount) as returns, - sum(cr_net_loss) as profit_loss - from catalog_returns, - date_dim - where cr_returned_date_sk = d_date_sk - and d_date between cast('1998-08-03' as date) - and dateadd(day,30,cast('1998-08-03' as date)) - group by cr_call_center_sk), - ws as - ( select wp_web_page_sk, - sum(ws_ext_sales_price) as sales, - sum(ws_net_profit) as profit - from web_sales, - date_dim, - web_page - where ws_sold_date_sk = d_date_sk - and d_date between cast('1998-08-03' as date) - and dateadd(day,30,cast('1998-08-03' as date)) - and ws_web_page_sk = wp_web_page_sk - group by wp_web_page_sk), - wr as - (select wp_web_page_sk, - sum(wr_return_amt) as returns, - sum(wr_net_loss) as profit_loss - from web_returns, - date_dim, - web_page - where wr_returned_date_sk = d_date_sk - and d_date between cast('1998-08-03' as date) - and dateadd(day,30,cast('1998-08-03' as date)) - and wr_web_page_sk = wp_web_page_sk - group by wp_web_page_sk) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , ss.s_store_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ss left join sr - on ss.s_store_sk = sr.s_store_sk - union all - select 'catalog channel' as channel - , cs_call_center_sk as id - , sales - , returns - , (profit - profit_loss) as profit - from cs - , cr - union all - select 'web channel' as channel - , ws.wp_web_page_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ws left join wr - on ws.wp_web_page_sk = wr.wp_web_page_sk - ) x - group by channel, id ) - - select * - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results -) foo -order by channel, id - limit 100; - --- end template query77a.tpl query 10 in stream 1 --- start template query40.tpl query 11 in stream 1 -select /* TPC-DS query40.tpl 0.86 */ - w_state - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('2002-06-25' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_before - ,sum(case when (cast(d_date as date) >= cast ('2002-06-25' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_after - from - catalog_sales left outer join catalog_returns on - (cs_order_number = cr_order_number - and cs_item_sk = cr_item_sk) - ,warehouse - ,item - ,date_dim - where - i_current_price between 0.99 and 1.49 - and i_item_sk = cs_item_sk - and cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('2002-06-25' as date)) - and dateadd(day,30,cast ('2002-06-25' as date)) - group by - w_state,i_item_id - order by w_state,i_item_id -limit 100; - --- end template query40.tpl query 11 in stream 1 --- start template query96.tpl query 12 in stream 1 -select /* TPC-DS query96.tpl 0.1 */ count(*) -from store_sales - ,household_demographics - ,time_dim, store -where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and household_demographics.hd_dep_count = 3 - and store.s_store_name = 'ese' -order by count(*) -limit 100; - --- end template query96.tpl query 12 in stream 1 --- start template query13.tpl query 13 in stream 1 -select /* TPC-DS query13.tpl 0.91 */ avg(ss_quantity) - ,avg(ss_ext_sales_price) - ,avg(ss_ext_wholesale_cost) - ,sum(ss_ext_wholesale_cost) - from store_sales - ,store - ,customer_demographics - ,household_demographics - ,customer_address - ,date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2001 - and((ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'S' - and cd_education_status = 'College' - and ss_sales_price between 100.00 and 150.00 - and hd_dep_count = 3 - )or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'U' - and cd_education_status = 'Unknown' - and ss_sales_price between 50.00 and 100.00 - and hd_dep_count = 1 - ) or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'M' - and cd_education_status = 'Advanced Degree' - and ss_sales_price between 150.00 and 200.00 - and hd_dep_count = 1 - )) - and((ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('KS', 'GA', 'WI') - and ss_net_profit between 100 and 200 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('NC', 'MO', 'CA') - and ss_net_profit between 150 and 300 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('VA', 'TN', 'FL') - and ss_net_profit between 50 and 250 - )) -; - --- end template query13.tpl query 13 in stream 1 --- start template query36a.tpl query 14 in stream 1 -with /* TPC-DS query36a.tpl 0.21 */ results as - (select - sum(ss_net_profit) as ss_net_profit, sum(ss_ext_sales_price) as ss_ext_sales_price, - sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin - ,i_category - ,i_class - ,0 as g_category, 0 as g_class - from - store_sales - ,date_dim d1 - ,item - ,store - where - d1.d_year = 1998 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and s_state in ('IN','GA','TX','LA', - 'NY','VT','SC','AL') - group by i_category,i_class) - , - results_rollup as - (select gross_margin ,i_category ,i_class,0 as t_category, 0 as t_class, 0 as lochierarchy from results - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - i_category, NULL AS i_class, 0 as t_category, 1 as t_class, 1 as lochierarchy from results group by i_category - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - NULL AS i_category ,NULL AS i_class, 1 as t_category, 1 as t_class, 2 as lochierarchy from results) - select - gross_margin ,i_category ,i_class, lochierarchy,rank() over ( - partition by lochierarchy, case when t_class = 0 then i_category end - order by gross_margin asc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then i_category end - ,rank_within_parent - limit 100; - --- end template query36a.tpl query 14 in stream 1 --- start template query95.tpl query 15 in stream 1 -with /* TPC-DS query95.tpl 0.43 */ ws_wh as -(select ws1.ws_order_number,ws1.ws_warehouse_sk wh1,ws2.ws_warehouse_sk wh2 - from web_sales ws1,web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) - select - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2001-3-01' and - dateadd(day,60,cast('2001-3-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'UT' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and ws1.ws_order_number in (select ws_order_number - from ws_wh) -and ws1.ws_order_number in (select wr_order_number - from web_returns,ws_wh - where wr_order_number = ws_wh.ws_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query95.tpl query 15 in stream 1 --- start template query63.tpl query 16 in stream 1 -select /* TPC-DS query63.tpl 0.27 */ * -from (select i_manager_id - ,sum(ss_sales_price) sum_sales - ,avg(sum(ss_sales_price)) over (partition by i_manager_id) avg_monthly_sales - from item - ,store_sales - ,date_dim - ,store - where ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and d_month_seq in (1197,1197+1,1197+2,1197+3,1197+4,1197+5,1197+6,1197+7,1197+8,1197+9,1197+10,1197+11) - and (( i_category in ('Books','Children','Electronics') - and i_class in ('personal','portable','reference','self-help') - and i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) - or( i_category in ('Women','Music','Men') - and i_class in ('accessories','classical','fragrances','pants') - and i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manager_id, d_moy) tmp1 -where case when avg_monthly_sales > 0 then abs (sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 -order by i_manager_id - ,avg_monthly_sales - ,sum_sales -limit 100; - --- end template query63.tpl query 16 in stream 1 --- start template query99.tpl query 17 in stream 1 -select /* TPC-DS query99.tpl 0.94 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 30) and - (cs_ship_date_sk - cs_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 60) and - (cs_ship_date_sk - cs_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 90) and - (cs_ship_date_sk - cs_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - catalog_sales - ,warehouse - ,ship_mode - ,call_center - ,date_dim -where - d_month_seq between 1188 and 1188 + 11 -and cs_ship_date_sk = d_date_sk -and cs_warehouse_sk = w_warehouse_sk -and cs_ship_mode_sk = sm_ship_mode_sk -and cs_call_center_sk = cc_call_center_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -limit 100; - --- end template query99.tpl query 17 in stream 1 --- start template query3.tpl query 18 in stream 1 -select /* TPC-DS query3.tpl 0.45 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_sales_price) sum_agg - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manufact_id = 837 - and dt.d_moy=12 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,sum_agg desc - ,brand_id - limit 100; - --- end template query3.tpl query 18 in stream 1 --- start template query6.tpl query 19 in stream 1 -select /* TPC-DS query6.tpl 0.58 */ a.ca_state state, count(*) cnt - from customer_address a - ,customer c - ,store_sales s - ,date_dim d - ,item i - where a.ca_address_sk = c.c_current_addr_sk - and c.c_customer_sk = s.ss_customer_sk - and s.ss_sold_date_sk = d.d_date_sk - and s.ss_item_sk = i.i_item_sk - and d.d_month_seq = - (select distinct (d_month_seq) - from date_dim - where d_year = 2001 - and d_moy = 5 ) - and i.i_current_price > 1.2 * - (select avg(j.i_current_price) - from item j - where j.i_category = i.i_category) - group by a.ca_state - having count(*) >= 10 - order by cnt, a.ca_state - limit 100; - --- end template query6.tpl query 19 in stream 1 --- start template query12.tpl query 20 in stream 1 -select /* TPC-DS query12.tpl 0.64 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ws_ext_sales_price) as itemrevenue - ,sum(ws_ext_sales_price)*100/sum(sum(ws_ext_sales_price)) over - (partition by i_class) as revenueratio -from - web_sales - ,item - ,date_dim -where - ws_item_sk = i_item_sk - and i_category in ('Music', 'Men', 'Shoes') - and ws_sold_date_sk = d_date_sk - and d_date between cast('2000-02-14' as date) - and dateadd(day,30,cast('2000-02-14' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query12.tpl query 20 in stream 1 --- start template query28.tpl query 21 in stream 1 -select /* TPC-DS query28.tpl 0.36 */ * -from (select avg(ss_list_price) B1_LP - ,count(ss_list_price) B1_CNT - ,count(distinct ss_list_price) B1_CNTD - from store_sales - where ss_quantity between 0 and 5 - and (ss_list_price between 81 and 81+10 - or ss_coupon_amt between 670 and 670+1000 - or ss_wholesale_cost between 11 and 11+20)) B1, - (select avg(ss_list_price) B2_LP - ,count(ss_list_price) B2_CNT - ,count(distinct ss_list_price) B2_CNTD - from store_sales - where ss_quantity between 6 and 10 - and (ss_list_price between 79 and 79+10 - or ss_coupon_amt between 15284 and 15284+1000 - or ss_wholesale_cost between 67 and 67+20)) B2, - (select avg(ss_list_price) B3_LP - ,count(ss_list_price) B3_CNT - ,count(distinct ss_list_price) B3_CNTD - from store_sales - where ss_quantity between 11 and 15 - and (ss_list_price between 187 and 187+10 - or ss_coupon_amt between 3659 and 3659+1000 - or ss_wholesale_cost between 1 and 1+20)) B3, - (select avg(ss_list_price) B4_LP - ,count(ss_list_price) B4_CNT - ,count(distinct ss_list_price) B4_CNTD - from store_sales - where ss_quantity between 16 and 20 - and (ss_list_price between 0 and 0+10 - or ss_coupon_amt between 7352 and 7352+1000 - or ss_wholesale_cost between 76 and 76+20)) B4, - (select avg(ss_list_price) B5_LP - ,count(ss_list_price) B5_CNT - ,count(distinct ss_list_price) B5_CNTD - from store_sales - where ss_quantity between 21 and 25 - and (ss_list_price between 111 and 111+10 - or ss_coupon_amt between 7785 and 7785+1000 - or ss_wholesale_cost between 23 and 23+20)) B5, - (select avg(ss_list_price) B6_LP - ,count(ss_list_price) B6_CNT - ,count(distinct ss_list_price) B6_CNTD - from store_sales - where ss_quantity between 26 and 30 - and (ss_list_price between 66 and 66+10 - or ss_coupon_amt between 14191 and 14191+1000 - or ss_wholesale_cost between 37 and 37+20)) B6 -limit 100; - --- end template query28.tpl query 21 in stream 1 --- start template query85.tpl query 22 in stream 1 -select /* TPC-DS query85.tpl 0.33 */ substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) - from web_sales, web_returns, web_page, customer_demographics cd1, - customer_demographics cd2, customer_address, date_dim, reason - where ws_web_page_sk = wp_web_page_sk - and ws_item_sk = wr_item_sk - and ws_order_number = wr_order_number - and ws_sold_date_sk = d_date_sk and d_year = 2000 - and cd1.cd_demo_sk = wr_refunded_cdemo_sk - and cd2.cd_demo_sk = wr_returning_cdemo_sk - and ca_address_sk = wr_refunded_addr_sk - and r_reason_sk = wr_reason_sk - and - ( - ( - cd1.cd_marital_status = 'S' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Advanced Degree' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 100.00 and 150.00 - ) - or - ( - cd1.cd_marital_status = 'M' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Secondary' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 50.00 and 100.00 - ) - or - ( - cd1.cd_marital_status = 'D' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = '2 yr Degree' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ca_country = 'United States' - and - ca_state in ('AL', 'SC', 'KS') - and ws_net_profit between 100 and 200 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('GA', 'PA', 'MS') - and ws_net_profit between 150 and 300 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('NC', 'ND', 'AR') - and ws_net_profit between 50 and 250 - ) - ) -group by r_reason_desc -order by substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) -limit 100; - --- end template query85.tpl query 22 in stream 1 --- start template query51.tpl query 23 in stream 1 -WITH /* TPC-DS query51.tpl 0.46 */ web_v1 as ( -select - ws_item_sk item_sk, d_date, - sum(sum(ws_sales_price)) - over (partition by ws_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from web_sales - ,date_dim -where ws_sold_date_sk=d_date_sk - and d_month_seq between 1209 and 1209+11 - and ws_item_sk is not NULL -group by ws_item_sk, d_date), -store_v1 as ( -select - ss_item_sk item_sk, d_date, - sum(sum(ss_sales_price)) - over (partition by ss_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from store_sales - ,date_dim -where ss_sold_date_sk=d_date_sk - and d_month_seq between 1209 and 1209+11 - and ss_item_sk is not NULL -group by ss_item_sk, d_date) - select * -from (select item_sk - ,d_date - ,web_sales - ,store_sales - ,max(web_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) web_cumulative - ,max(store_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) store_cumulative - from (select case when web.item_sk is not null then web.item_sk else store.item_sk end item_sk - ,case when web.d_date is not null then web.d_date else store.d_date end d_date - ,web.cume_sales web_sales - ,store.cume_sales store_sales - from web_v1 web full outer join store_v1 store on (web.item_sk = store.item_sk - and web.d_date = store.d_date) - )x )y -where web_cumulative > store_cumulative -order by item_sk - ,d_date -limit 100; - --- end template query51.tpl query 23 in stream 1 --- start template query41.tpl query 24 in stream 1 -select /* TPC-DS query41.tpl 0.62 */ distinct(i_product_name) - from item i1 - where i_manufact_id between 678 and 678+40 - and (select count(*) as item_cnt - from item - where (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'cornflower' or i_color = 'wheat') and - (i_units = 'Cup' or i_units = 'Ounce') and - (i_size = 'extra large' or i_size = 'large') - ) or - (i_category = 'Women' and - (i_color = 'indian' or i_color = 'puff') and - (i_units = 'Tsp' or i_units = 'Gross') and - (i_size = 'economy' or i_size = 'N/A') - ) or - (i_category = 'Men' and - (i_color = 'grey' or i_color = 'slate') and - (i_units = 'Bunch' or i_units = 'Gram') and - (i_size = 'petite' or i_size = 'small') - ) or - (i_category = 'Men' and - (i_color = 'sienna' or i_color = 'rose') and - (i_units = 'N/A' or i_units = 'Lb') and - (i_size = 'extra large' or i_size = 'large') - ))) or - (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'white' or i_color = 'gainsboro') and - (i_units = 'Dram' or i_units = 'Ton') and - (i_size = 'extra large' or i_size = 'large') - ) or - (i_category = 'Women' and - (i_color = 'blanched' or i_color = 'cyan') and - (i_units = 'Tbl' or i_units = 'Dozen') and - (i_size = 'economy' or i_size = 'N/A') - ) or - (i_category = 'Men' and - (i_color = 'purple' or i_color = 'magenta') and - (i_units = 'Bundle' or i_units = 'Each') and - (i_size = 'petite' or i_size = 'small') - ) or - (i_category = 'Men' and - (i_color = 'pink' or i_color = 'burnished') and - (i_units = 'Case' or i_units = 'Oz') and - (i_size = 'extra large' or i_size = 'large') - )))) > 0 - order by i_product_name - limit 100; - --- end template query41.tpl query 24 in stream 1 --- start template query27a.tpl query 25 in stream 1 -with /* TPC-DS query27a.tpl 0.16 */ results as - (select i_item_id, - s_state, 0 as g_state, - ss_quantity agg1, - ss_list_price agg2, - ss_coupon_amt agg3, - ss_sales_price agg4 - from store_sales, customer_demographics, date_dim, store, item - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_store_sk = s_store_sk and - ss_cdemo_sk = cd_demo_sk and - cd_gender = 'M' and - cd_marital_status = 'W' and - cd_education_status = 'College' and - d_year = 2001 and - s_state in ('SC','MI', 'SD', 'VT', 'GA', 'NM') - ) - - select i_item_id, - s_state, g_state, agg1, agg2, agg3, agg4 - from ( - select i_item_id, s_state, 0 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4 from results - group by i_item_id, s_state - union all - select i_item_id, NULL AS s_state, 1 AS g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as s_state, 1 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - ) foo - order by i_item_id, s_state - limit 100; - --- end template query27a.tpl query 25 in stream 1 --- start template query78.tpl query 26 in stream 1 -with /* TPC-DS query78.tpl 0.10 */ ws as - (select d_year AS ws_sold_year, ws_item_sk, - ws_bill_customer_sk ws_customer_sk, - sum(ws_quantity) ws_qty, - sum(ws_wholesale_cost) ws_wc, - sum(ws_sales_price) ws_sp - from web_sales - left join web_returns on wr_order_number=ws_order_number and ws_item_sk=wr_item_sk - join date_dim on ws_sold_date_sk = d_date_sk - where wr_order_number is null - group by d_year, ws_item_sk, ws_bill_customer_sk - ), -cs as - (select d_year AS cs_sold_year, cs_item_sk, - cs_bill_customer_sk cs_customer_sk, - sum(cs_quantity) cs_qty, - sum(cs_wholesale_cost) cs_wc, - sum(cs_sales_price) cs_sp - from catalog_sales - left join catalog_returns on cr_order_number=cs_order_number and cs_item_sk=cr_item_sk - join date_dim on cs_sold_date_sk = d_date_sk - where cr_order_number is null - group by d_year, cs_item_sk, cs_bill_customer_sk - ), -ss as - (select d_year AS ss_sold_year, ss_item_sk, - ss_customer_sk, - sum(ss_quantity) ss_qty, - sum(ss_wholesale_cost) ss_wc, - sum(ss_sales_price) ss_sp - from store_sales - left join store_returns on sr_ticket_number=ss_ticket_number and ss_item_sk=sr_item_sk - join date_dim on ss_sold_date_sk = d_date_sk - where sr_ticket_number is null - group by d_year, ss_item_sk, ss_customer_sk - ) - select -ss_sold_year, -round(ss_qty/(coalesce(ws_qty,0)+coalesce(cs_qty,0)),2) ratio, -ss_qty store_qty, ss_wc store_wholesale_cost, ss_sp store_sales_price, -coalesce(ws_qty,0)+coalesce(cs_qty,0) other_chan_qty, -coalesce(ws_wc,0)+coalesce(cs_wc,0) other_chan_wholesale_cost, -coalesce(ws_sp,0)+coalesce(cs_sp,0) other_chan_sales_price -from ss -left join ws on (ws_sold_year=ss_sold_year and ws_item_sk=ss_item_sk and ws_customer_sk=ss_customer_sk) -left join cs on (cs_sold_year=ss_sold_year and cs_item_sk=ss_item_sk and cs_customer_sk=ss_customer_sk) -where (coalesce(ws_qty,0)>0 or coalesce(cs_qty, 0)>0) and ss_sold_year=1999 -order by - ss_sold_year, - ss_qty desc, ss_wc desc, ss_sp desc, - other_chan_qty, - other_chan_wholesale_cost, - other_chan_sales_price, - ratio -limit 100; - --- end template query78.tpl query 26 in stream 1 --- start template query8.tpl query 27 in stream 1 -select /* TPC-DS query8.tpl 0.63 */ s_store_name - ,sum(ss_net_profit) - from store_sales - ,date_dim - ,store, - (select ca_zip - from ( - SELECT substring(ca_zip,1,5) ca_zip - FROM customer_address - WHERE substring(ca_zip,1,5) IN ( - '36260','26350','63250','37869','81721','53693', - '26855','37563','41987','72521','40599', - '79280','75213','44524','49144','87434', - '35195','45457','52033','48450','88552', - '55336','67199','62853','17395','38138', - '69288','81191','78270','96463','72978', - '70293','93555','71626','73128','54730', - '39359','47355','78636','64637','13317', - '50382','53069','80694','31138','79408', - '18459','76396','44322','56563','82131', - '32908','87077','49679','97650','57265', - '30782','90387','55900','60051','90802', - '77463','68886','17538','92897','40862', - '86929','91240','30597','47965','12383', - '32270','45576','57089','37665','55839', - '29973','35478','11427','22613','35961', - '81595','91171','18744','75959','14392', - '52650','17822','83320','66444','46885', - '51205','30131','71984','14567','84062', - '14765','34081','63083','95375','64792', - '33408','85925','35467','63037','33352', - '90226','47937','79097','82728','84250', - '72194','37745','56816','81526','29361', - '74904','85175','35804','21744','66471', - '63889','42007','58997','37774','43102', - '74871','50878','18807','85671','31835', - '63423','57189','69564','26220','85885', - '75885','58202','38983','21303','32994', - '76237','10034','63910','75713','50012', - '91882','55034','77419','49841','98502', - '76050','13473','33409','40431','49098', - '28432','38740','12057','67125','35543', - '32721','20187','99079','89823','15364', - '77594','17614','83552','85528','16679', - '88133','86455','64413','23874','74415', - '75894','84336','87205','99812','78538', - '87127','16490','29752','94119','80957', - '97219','86656','77053','18354','98128', - '56099','93134','35185','90279','15300', - '26678','19019','20478','81531','16306', - '79368','24590','80362','42831','38429', - '92105','17711','64607','98367','39286', - '91094','80109','94702','56491','28503', - '96430','44963','99196','32476','89208', - '64089','57006','44747','22186','29767', - '25092','90225','93176','66665','74304', - '37846','76436','57805','26824','98876', - '22017','99430','72221','54332','65684', - '83055','68113','65440','26720','39249', - '54885','96814','14344','49539','94483', - '46751','70867','99883','11646','74181', - '88302','49113','75437','81275','68880', - '61664','34107','38324','58163','38627', - '17783','49394','16108','71395','25697', - '33039','12697','73515','12510','57318', - '33203','59471','73168','70469','20120', - '82377','77560','88845','56537','15750', - '28247','64308','52892','51284','18162', - '26356','42683','41367','32689','23776', - '22021','66489','42204','36129','40226', - '34746','64463','84836','80444','39514', - '98188','47491','63121','48729','84622', - '46648','19352','97714','35035','72950', - '96659','82703','91323','58782','30829', - '38608','90166','97300','37612','25086', - '94029','91539','18900','25856','50954', - '46834','40659','86681','80650','29820', - '16624','30525','24125','54177','54144', - '75812','61072','51545','22780','65746', - '59491','77841','91839','47556','87035', - '85121','88765','30280','67057','69838', - '78160','97270','96730','12811','40034', - '66782','19625','10988','28486','63111', - '30724','96614','77311','45506','81994', - '29376','93358','89331','20994','73170', - '77372','76348','42445','81488','49844', - '62331','32141','85814','72104','26116', - '40595','20435','31200','49372','14488', - '19334','27914','32097','12904','96945', - '10661','34912','48195','32904') - intersect - select ca_zip - from (SELECT substring(ca_zip,1,5) ca_zip,count(*) cnt - FROM customer_address, customer - WHERE ca_address_sk = c_current_addr_sk and - c_preferred_cust_flag='Y' - group by ca_zip - having count(*) > 10)A1)A2) V1 - where ss_store_sk = s_store_sk - and ss_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 2000 - and (substring(s_zip,1,2) = substring(V1.ca_zip,1,2)) - group by s_store_name - order by s_store_name - limit 100; - --- end template query8.tpl query 27 in stream 1 --- start template query14a.tpl query 28 in stream 1 -with /* TPC-DS query14a.tpl 0.69 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1999 AND 1999 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1999 AND 1999 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1999 AND 1999 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as - (select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2) x) -, - results AS -(select channel, i_brand_id, i_class_id, i_category_id, sum(sales) sum_sales, sum(number_sales) number_sales - from ( - select 'store' channel, i_brand_id,i_class_id - ,i_category_id,sum(ss_quantity*ss_list_price) sales - , count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1999+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales) - union all - select 'catalog' channel, i_brand_id,i_class_id,i_category_id, sum(cs_quantity*cs_list_price) sales, count(*) number_sales - from catalog_sales - ,item - ,date_dim - where cs_item_sk in (select ss_item_sk from cross_items) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1999+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(cs_quantity*cs_list_price) > (select average_sales from avg_sales) - union all - select 'web' channel, i_brand_id,i_class_id,i_category_id, sum(ws_quantity*ws_list_price) sales , count(*) number_sales - from web_sales - ,item - ,date_dim - where ws_item_sk in (select ss_item_sk from cross_items) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1999+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ws_quantity*ws_list_price) > (select average_sales from avg_sales) - ) y - group by channel, i_brand_id,i_class_id,i_category_id) - - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales -from ( - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales from results - union - select channel, i_brand_id, i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id, i_class_id - union - select channel, i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id - union - select channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel - union - select null as channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results) z -order by channel, i_brand_id, i_class_id, i_category_id - limit 100; -with /* TPC-DS query14a.tpl 0.69 part2 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1999 AND 1999 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1999 AND 1999 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1999 AND 1999 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as -(select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2) x) - select this_year.channel ty_channel - ,this_year.i_brand_id ty_brand - ,this_year.i_class_id ty_class - ,this_year.i_category_id ty_category - ,this_year.sales ty_sales - ,this_year.number_sales ty_number_sales - ,last_year.channel ly_channel - ,last_year.i_brand_id ly_brand - ,last_year.i_class_id ly_class - ,last_year.i_category_id ly_category - ,last_year.sales ly_sales - ,last_year.number_sales ly_number_sales -from - (select 'store' channel, i_brand_id,i_class_id,i_category_id - ,sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1999 + 1 - and d_moy = 12 - and d_dom = 8) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) this_year, - (select 'store' channel, i_brand_id,i_class_id - ,i_category_id, sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1999 - and d_moy = 12 - and d_dom = 8) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) last_year - where this_year.i_brand_id= last_year.i_brand_id - and this_year.i_class_id = last_year.i_class_id - and this_year.i_category_id = last_year.i_category_id - order by this_year.channel, this_year.i_brand_id, this_year.i_class_id, this_year.i_category_id - limit 100; - --- end template query14a.tpl query 28 in stream 1 --- start template query50.tpl query 29 in stream 1 -select /* TPC-DS query50.tpl 0.60 */ - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 30) and - (sr_returned_date_sk - ss_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 60) and - (sr_returned_date_sk - ss_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 90) and - (sr_returned_date_sk - ss_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - store_sales - ,store_returns - ,store - ,date_dim d1 - ,date_dim d2 -where - d2.d_year = 1998 -and d2.d_moy = 8 -and ss_ticket_number = sr_ticket_number -and ss_item_sk = sr_item_sk -and ss_sold_date_sk = d1.d_date_sk -and sr_returned_date_sk = d2.d_date_sk -and ss_customer_sk = sr_customer_sk -and ss_store_sk = s_store_sk -group by - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -order by s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -limit 100; - --- end template query50.tpl query 29 in stream 1 --- start template query52.tpl query 30 in stream 1 -select /* TPC-DS query52.tpl 0.59 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_sales_price) ext_price - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=12 - and dt.d_year=2002 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,ext_price desc - ,brand_id -limit 100 ; - --- end template query52.tpl query 30 in stream 1 --- start template query81.tpl query 31 in stream 1 -with /* TPC-DS query81.tpl 0.37 */ customer_total_return as - (select cr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(cr_return_amt_inc_tax) as ctr_total_return - from catalog_returns - ,date_dim - ,customer_address - where cr_returned_date_sk = d_date_sk - and d_year =2002 - and cr_returning_addr_sk = ca_address_sk - group by cr_returning_customer_sk - ,ca_state ) - select c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'NC' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - limit 100; - --- end template query81.tpl query 31 in stream 1 --- start template query5a.tpl query 32 in stream 1 -with /* TPC-DS query5a.tpl 0.98 */ ssr as - (select s_store_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ss_store_sk as store_sk, - ss_sold_date_sk as date_sk, - ss_ext_sales_price as sales_price, - ss_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from store_sales - union all - select sr_store_sk as store_sk, - sr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - sr_return_amt as return_amt, - sr_net_loss as net_loss - from store_returns - ) salesreturns, - date_dim, - store - where date_sk = d_date_sk - and d_date between cast('2001-08-16' as date) - and dateadd(day,14,cast('2001-08-16' as date)) - and store_sk = s_store_sk - group by s_store_id) - , - csr as - (select cp_catalog_page_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select cs_catalog_page_sk as page_sk, - cs_sold_date_sk as date_sk, - cs_ext_sales_price as sales_price, - cs_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from catalog_sales - union all - select cr_catalog_page_sk as page_sk, - cr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - cr_return_amount as return_amt, - cr_net_loss as net_loss - from catalog_returns - ) salesreturns, - date_dim, - catalog_page - where date_sk = d_date_sk - and d_date between cast('2001-08-16' as date) - and dateadd(day,14,cast('2001-08-16' as date)) - and page_sk = cp_catalog_page_sk - group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ws_web_site_sk as wsr_web_site_sk, - ws_sold_date_sk as date_sk, - ws_ext_sales_price as sales_price, - ws_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from web_sales - union all - select ws_web_site_sk as wsr_web_site_sk, - wr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - wr_return_amt as return_amt, - wr_net_loss as net_loss - from web_returns left outer join web_sales on - ( wr_item_sk = ws_item_sk - and wr_order_number = ws_order_number) - ) salesreturns, - date_dim, - web_site - where date_sk = d_date_sk - and d_date between cast('2001-08-16' as date) - and dateadd(day,14,cast('2001-08-16' as date)) - and wsr_web_site_sk = web_site_sk - group by web_site_id) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || s_store_id as id - , sales - , returns - , (profit - profit_loss) as profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || cp_catalog_page_id as id - , sales - , returns - , (profit - profit_loss) as profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , (profit - profit_loss) as profit - from wsr - ) x - group by channel, id) - select channel, id, sales, returns, profit from ( - select channel, id, sales, returns, profit from results - union - select channel, null as id, sum(sales), sum(returns), sum(profit) from results group by channel - union - select null as channel, null as id, sum(sales), sum(returns), sum(profit) from results) foo -order by channel, id -limit 100; - --- end template query5a.tpl query 32 in stream 1 --- start template query26.tpl query 33 in stream 1 -select /* TPC-DS query26.tpl 0.85 */ i_item_id, - avg(cs_quantity) agg1, - avg(cs_list_price) agg2, - avg(cs_coupon_amt) agg3, - avg(cs_sales_price) agg4 - from catalog_sales, customer_demographics, date_dim, item, promotion - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd_demo_sk and - cs_promo_sk = p_promo_sk and - cd_gender = 'M' and - cd_marital_status = 'M' and - cd_education_status = '4 yr Degree' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 1999 - group by i_item_id - order by i_item_id - limit 100; - --- end template query26.tpl query 33 in stream 1 --- start template query57.tpl query 34 in stream 1 -with /* TPC-DS query57.tpl 0.70 */ v1 as( - select i_category, i_brand, - cc_name, - d_year, d_moy, - sum(cs_sales_price) sum_sales, - avg(sum(cs_sales_price)) over - (partition by i_category, i_brand, - cc_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - cc_name - order by d_year, d_moy) rn - from item, catalog_sales, date_dim, call_center - where cs_item_sk = i_item_sk and - cs_sold_date_sk = d_date_sk and - cc_call_center_sk= cs_call_center_sk and - ( - d_year = 2000 or - ( d_year = 2000-1 and d_moy =12) or - ( d_year = 2000+1 and d_moy =1) - ) - group by i_category, i_brand, - cc_name , d_year, d_moy), - v2 as( - select v1.i_category - ,v1.d_year, v1.d_moy - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1. cc_name = v1_lag. cc_name and - v1. cc_name = v1_lead. cc_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 2000 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, avg_monthly_sales - limit 100; - --- end template query57.tpl query 34 in stream 1 --- start template query82.tpl query 35 in stream 1 -select /* TPC-DS query82.tpl 0.67 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, store_sales - where i_current_price between 15 and 15+30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('1998-07-23' as date) and dateadd(day,60,cast('1998-07-23' as date)) - and i_manufact_id in (586,100,245,782) - and inv_quantity_on_hand between 100 and 500 - and ss_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query82.tpl query 35 in stream 1 --- start template query69.tpl query 36 in stream 1 -select /* TPC-DS query69.tpl 0.28 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_state in ('CT','IN','OK') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 2 and 2+2) and - (not exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 2 and 2+2) and - not exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 2 and 2+2)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - limit 100; - --- end template query69.tpl query 36 in stream 1 --- start template query54.tpl query 37 in stream 1 -with /* TPC-DS query54.tpl 0.81 */ my_customers as ( - select distinct c_customer_sk - , c_current_addr_sk - from - ( select cs_sold_date_sk sold_date_sk, - cs_bill_customer_sk customer_sk, - cs_item_sk item_sk - from catalog_sales - union all - select ws_sold_date_sk sold_date_sk, - ws_bill_customer_sk customer_sk, - ws_item_sk item_sk - from web_sales - ) cs_or_ws_sales, - item, - date_dim, - customer - where sold_date_sk = d_date_sk - and item_sk = i_item_sk - and i_category = 'Books' - and i_class = 'parenting' - and c_customer_sk = cs_or_ws_sales.customer_sk - and d_moy = 1 - and d_year = 2001 - ) - , my_revenue as ( - select c_customer_sk, - sum(ss_ext_sales_price) as revenue - from my_customers, - store_sales, - customer_address, - store, - date_dim - where c_current_addr_sk = ca_address_sk - and ca_county = s_county - and ca_state = s_state - and ss_sold_date_sk = d_date_sk - and c_customer_sk = ss_customer_sk - and d_month_seq between (select distinct d_month_seq+1 - from date_dim where d_year = 2001 and d_moy = 1) - and (select distinct d_month_seq+3 - from date_dim where d_year = 2001 and d_moy = 1) - group by c_customer_sk - ) - , segments as - (select cast((revenue/50) as bigint) as segment - from my_revenue - ) - select segment, count(*) as num_customers, segment*50 as segment_base - from segments - group by segment - order by segment, num_customers - limit 100; - --- end template query54.tpl query 37 in stream 1 --- start template query61.tpl query 38 in stream 1 -select /* TPC-DS query61.tpl 0.97 */ promotions,total,cast(promotions as decimal(15,4))/cast(total as decimal(15,4))*100 -from - (select sum(ss_ext_sales_price) promotions - from store_sales - ,store - ,promotion - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_promo_sk = p_promo_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -7 - and i_category = 'Jewelry' - and (p_channel_dmail = 'Y' or p_channel_email = 'Y' or p_channel_tv = 'Y') - and s_gmt_offset = -7 - and d_year = 1999 - and d_moy = 12) promotional_sales, - (select sum(ss_ext_sales_price) total - from store_sales - ,store - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -7 - and i_category = 'Jewelry' - and s_gmt_offset = -7 - and d_year = 1999 - and d_moy = 12) all_sales -order by promotions, total -limit 100; - --- end template query61.tpl query 38 in stream 1 --- start template query88.tpl query 39 in stream 1 -select /* TPC-DS query88.tpl 0.66 */ * -from - (select count(*) h8_30_to_9 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2)) - and store.s_store_name = 'ese') s1, - (select count(*) h9_to_9_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2)) - and store.s_store_name = 'ese') s2, - (select count(*) h9_30_to_10 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2)) - and store.s_store_name = 'ese') s3, - (select count(*) h10_to_10_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2)) - and store.s_store_name = 'ese') s4, - (select count(*) h10_30_to_11 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2)) - and store.s_store_name = 'ese') s5, - (select count(*) h11_to_11_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2)) - and store.s_store_name = 'ese') s6, - (select count(*) h11_30_to_12 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2)) - and store.s_store_name = 'ese') s7, - (select count(*) h12_to_12_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 12 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2)) - and store.s_store_name = 'ese') s8 -; - --- end template query88.tpl query 39 in stream 1 --- start template query18a.tpl query 40 in stream 1 -with /* TPC-DS query18a.tpl 0.90 */ results as - (select i_item_id, - ca_country, - ca_state, - ca_county, - cast(cs_quantity as decimal(12,2)) agg1, - cast(cs_list_price as decimal(12,2)) agg2, - cast(cs_coupon_amt as decimal(12,2)) agg3, - cast(cs_sales_price as decimal(12,2)) agg4, - cast(cs_net_profit as decimal(12,2)) agg5, - cast(c_birth_year as decimal(12,2)) agg6, - cast(cd1.cd_dep_count as decimal(12,2)) agg7 - from catalog_sales, customer_demographics cd1, customer_demographics cd2, customer, customer_address, date_dim, item - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd1.cd_demo_sk and - cs_bill_customer_sk = c_customer_sk and - cd1.cd_gender = 'F' and - cd1.cd_education_status = 'College' and - c_current_cdemo_sk = cd2.cd_demo_sk and - c_current_addr_sk = ca_address_sk and - c_birth_month in (12,11,4,2,3,7) and - d_year = 2002 and - ca_state in ('SC','AR','TX','IA','MN','CO','NC') - ) - select i_item_id, ca_country, ca_state, ca_county, agg1, agg2, agg3, agg4, agg5, agg6, agg7 - from ( - select i_item_id, ca_country, ca_state, ca_county, avg(agg1) agg1, - avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state, ca_county - union all - select i_item_id, ca_country, ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state - union all - select i_item_id, ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country - union all - select i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - ) foo - order by ca_country, ca_state, ca_county, i_item_id - limit 100; - --- end template query18a.tpl query 40 in stream 1 --- start template query94.tpl query 41 in stream 1 -select /* TPC-DS query94.tpl 0.17 */ - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2002-3-01' and - dateadd(day,60,cast('2002-3-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'IN' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and exists (select * - from web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) -and not exists(select * - from web_returns wr1 - where ws1.ws_order_number = wr1.wr_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query94.tpl query 41 in stream 1 --- start template query35a.tpl query 42 in stream 1 -select /* TPC-DS query35a.tpl 0.47 */ - ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - count(*) cnt1, - avg(cd_dep_count), - min(cd_dep_count), - min(cd_dep_count), - cd_dep_employed_count, - count(*) cnt2, - avg(cd_dep_employed_count), - min(cd_dep_employed_count), - min(cd_dep_employed_count), - cd_dep_college_count, - count(*) cnt3, - avg(cd_dep_college_count), - min(cd_dep_college_count), - min(cd_dep_college_count) - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2000 and - d_qoy < 4) and - exists (select * from - (select ws_bill_customer_sk customsk - from web_sales,date_dim - where - ws_sold_date_sk = d_date_sk and - d_year = 2000 and - d_qoy < 4 - union all - select cs_ship_customer_sk customsk - from catalog_sales,date_dim - where - cs_sold_date_sk = d_date_sk and - d_year = 2000 and - d_qoy < 4)x - where x.customsk = c.c_customer_sk) - group by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - limit 100; - --- end template query35a.tpl query 42 in stream 1 --- start template query68.tpl query 43 in stream 1 -select /* TPC-DS query68.tpl 0.95 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,extended_price - ,extended_tax - ,list_price - from (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_ext_sales_price) extended_price - ,sum(ss_ext_list_price) list_price - ,sum(ss_ext_tax) extended_tax - from store_sales - ,date_dim - ,store - ,household_demographics - ,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_dep_count = 3 or - household_demographics.hd_vehicle_count= 3) - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_city in ('Westwood','Burlington') - group by ss_ticket_number - ,ss_customer_sk - ,ss_addr_sk,ca_city) dn - ,customer - ,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,ss_ticket_number - limit 100; - --- end template query68.tpl query 43 in stream 1 --- start template query24.tpl query 44 in stream 1 -with /* TPC-DS query24.tpl 0.92 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_net_paid_inc_tax) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip -and s_market_id=7 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'cornsilk' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; -with /* TPC-DS query24.tpl 0.92 part2 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_net_paid_inc_tax) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip - and s_market_id = 7 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'deep' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; - --- end template query24.tpl query 44 in stream 1 --- start template query75.tpl query 45 in stream 1 -WITH /* TPC-DS query75.tpl 0.3 */ all_sales AS ( - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,SUM(sales_cnt) AS sales_cnt - ,SUM(sales_amt) AS sales_amt - FROM (SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,cs_quantity - COALESCE(cr_return_quantity,0) AS sales_cnt - ,cs_ext_sales_price - COALESCE(cr_return_amount,0.0) AS sales_amt - FROM catalog_sales JOIN item ON i_item_sk=cs_item_sk - JOIN date_dim ON d_date_sk=cs_sold_date_sk - LEFT JOIN catalog_returns ON (cs_order_number=cr_order_number - AND cs_item_sk=cr_item_sk) - WHERE i_category='Children' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ss_quantity - COALESCE(sr_return_quantity,0) AS sales_cnt - ,ss_ext_sales_price - COALESCE(sr_return_amt,0.0) AS sales_amt - FROM store_sales JOIN item ON i_item_sk=ss_item_sk - JOIN date_dim ON d_date_sk=ss_sold_date_sk - LEFT JOIN store_returns ON (ss_ticket_number=sr_ticket_number - AND ss_item_sk=sr_item_sk) - WHERE i_category='Children' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ws_quantity - COALESCE(wr_return_quantity,0) AS sales_cnt - ,ws_ext_sales_price - COALESCE(wr_return_amt,0.0) AS sales_amt - FROM web_sales JOIN item ON i_item_sk=ws_item_sk - JOIN date_dim ON d_date_sk=ws_sold_date_sk - LEFT JOIN web_returns ON (ws_order_number=wr_order_number - AND ws_item_sk=wr_item_sk) - WHERE i_category='Children') sales_detail - GROUP BY d_year, i_brand_id, i_class_id, i_category_id, i_manufact_id) - SELECT prev_yr.d_year AS prev_year - ,curr_yr.d_year AS year - ,curr_yr.i_brand_id - ,curr_yr.i_class_id - ,curr_yr.i_category_id - ,curr_yr.i_manufact_id - ,prev_yr.sales_cnt AS prev_yr_cnt - ,curr_yr.sales_cnt AS curr_yr_cnt - ,curr_yr.sales_cnt-prev_yr.sales_cnt AS sales_cnt_diff - ,curr_yr.sales_amt-prev_yr.sales_amt AS sales_amt_diff - FROM all_sales curr_yr, all_sales prev_yr - WHERE curr_yr.i_brand_id=prev_yr.i_brand_id - AND curr_yr.i_class_id=prev_yr.i_class_id - AND curr_yr.i_category_id=prev_yr.i_category_id - AND curr_yr.i_manufact_id=prev_yr.i_manufact_id - AND curr_yr.d_year=2001 - AND prev_yr.d_year=2001-1 - AND CAST(curr_yr.sales_cnt AS DECIMAL(17,2))/CAST(prev_yr.sales_cnt AS DECIMAL(17,2))<0.9 - ORDER BY sales_cnt_diff,sales_amt_diff - limit 100; - --- end template query75.tpl query 45 in stream 1 --- start template query11.tpl query 46 in stream 1 -with /* TPC-DS query11.tpl 0.51 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ss_ext_list_price-ss_ext_discount_amt) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ws_ext_list_price-ws_ext_discount_amt) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_login - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 2001 - and t_s_secyear.dyear = 2001+1 - and t_w_firstyear.dyear = 2001 - and t_w_secyear.dyear = 2001+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else 0.0 end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else 0.0 end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_login -limit 100; - --- end template query11.tpl query 46 in stream 1 --- start template query67a.tpl query 47 in stream 1 -with /* TPC-DS query67a.tpl 0.35 */ results as -( select i_category ,i_class ,i_brand ,i_product_name ,d_year ,d_qoy ,d_moy ,s_store_id - ,sum(coalesce(ss_sales_price*ss_quantity,0)) sumsales - from store_sales ,date_dim ,store ,item - where ss_sold_date_sk=d_date_sk - and ss_item_sk=i_item_sk - and ss_store_sk = s_store_sk - and d_month_seq between 1213 and 1213 + 11 - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy,s_store_id) - , - results_rollup as - (select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, s_store_id, sumsales - from results - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy - union all - select i_category, i_class, i_brand, i_product_name, d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year - union all - select i_category, i_class, i_brand, i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name - union all - select i_category, i_class, i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand - union all - select i_category, i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class - union all - select i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category - union all - select null i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results) - - select * -from (select i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rank() over (partition by i_category order by sumsales desc) rk - from results_rollup) dw2 -where rk <= 100 -order by i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rk -limit 100; - --- end template query67a.tpl query 47 in stream 1 --- start template query9.tpl query 48 in stream 1 -select /* TPC-DS query9.tpl 0.49 */ case when (select count(*) - from store_sales - where ss_quantity between 1 and 20) > 332581425 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 1 and 20) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 1 and 20) end bucket1 , - case when (select count(*) - from store_sales - where ss_quantity between 21 and 40) > 1258895815 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 21 and 40) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 21 and 40) end bucket2, - case when (select count(*) - from store_sales - where ss_quantity between 41 and 60) > 52260434 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 41 and 60) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 41 and 60) end bucket3, - case when (select count(*) - from store_sales - where ss_quantity between 61 and 80) > 1398238135 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 61 and 80) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 61 and 80) end bucket4, - case when (select count(*) - from store_sales - where ss_quantity between 81 and 100) > 562312060 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 81 and 100) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 81 and 100) end bucket5 -from reason -where r_reason_sk = 1 -; - --- end template query9.tpl query 48 in stream 1 --- start template query25.tpl query 49 in stream 1 -select /* TPC-DS query25.tpl 0.9 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,avg(ss_net_profit) as store_sales_profit - ,avg(sr_net_loss) as store_returns_loss - ,avg(cs_net_profit) as catalog_sales_profit - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 2001 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 10 - and d2.d_year = 2001 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_moy between 4 and 10 - and d3.d_year = 2001 - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query25.tpl query 49 in stream 1 --- start template query37.tpl query 50 in stream 1 -select /* TPC-DS query37.tpl 0.31 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, catalog_sales - where i_current_price between 55 and 55 + 30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('2002-04-21' as date) and dateadd(day,60,cast('2002-04-21' as date)) - and i_manufact_id in (712,714,956,807) - and inv_quantity_on_hand between 100 and 500 - and cs_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query37.tpl query 50 in stream 1 --- start template query86a.tpl query 51 in stream 1 -with /* TPC-DS query86a.tpl 0.11 */ results as -( select sum(ws_net_paid) as total_sum, i_category, i_class, 0 as g_category, 0 as g_class - from - web_sales - ,date_dim d1 - ,item - where - d1.d_month_seq between 1186 and 1186+11 - and d1.d_date_sk = ws_sold_date_sk - and i_item_sk = ws_item_sk - group by i_category,i_class - ) , - - results_rollup as -( select total_sum ,i_category ,i_class, g_category, g_class, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum, i_category, NULL as i_class, 0 as g_category, 1 as g_class, 1 as lochierarchy from results group by i_category - union - select sum(total_sum) as total_sum, NULL as i_category, NULL as i_class, 1 as g_category, 1 as g_class, 2 as lochierarchy from results) - select - total_sum ,i_category ,i_class, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_class = 0 then i_category end - order by total_sum desc) as rank_within_parent - from - results_rollup - order by - lochierarchy desc, - case when lochierarchy = 0 then i_category end, - rank_within_parent - limit 100; - --- end template query86a.tpl query 51 in stream 1 --- start template query4.tpl query 52 in stream 1 -with /* TPC-DS query4.tpl 0.93 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(((ss_ext_list_price-ss_ext_wholesale_cost-ss_ext_discount_amt)+ss_ext_sales_price)/2) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((cs_ext_list_price-cs_ext_wholesale_cost-cs_ext_discount_amt)+cs_ext_sales_price)/2) ) year_total - ,'c' sale_type - from customer - ,catalog_sales - ,date_dim - where c_customer_sk = cs_bill_customer_sk - and cs_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year -union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((ws_ext_list_price-ws_ext_wholesale_cost-ws_ext_discount_amt)+ws_ext_sales_price)/2) ) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_birth_country - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_c_firstyear - ,year_total t_c_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_c_secyear.customer_id - and t_s_firstyear.customer_id = t_c_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_c_firstyear.sale_type = 'c' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_c_secyear.sale_type = 'c' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 2001 - and t_s_secyear.dyear = 2001+1 - and t_c_firstyear.dyear = 2001 - and t_c_secyear.dyear = 2001+1 - and t_w_firstyear.dyear = 2001 - and t_w_secyear.dyear = 2001+1 - and t_s_firstyear.year_total > 0 - and t_c_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_birth_country -limit 100; - --- end template query4.tpl query 52 in stream 1 --- start template query60.tpl query 53 in stream 1 -with /* TPC-DS query60.tpl 0.29 */ ss as ( - select - i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Jewelry')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 9 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id), - cs as ( - select - i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Jewelry')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 9 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id), - ws as ( - select - i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Jewelry')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 9 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id) - select - i_item_id -,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by i_item_id - ,total_sales - limit 100; - --- end template query60.tpl query 53 in stream 1 --- start template query97.tpl query 54 in stream 1 -with /* TPC-DS query97.tpl 0.38 */ ssci as ( -select ss_customer_sk customer_sk - ,ss_item_sk item_sk -from store_sales,date_dim -where ss_sold_date_sk = d_date_sk - and d_month_seq between 1212 and 1212 + 11 -group by ss_customer_sk - ,ss_item_sk), -csci as( - select cs_bill_customer_sk customer_sk - ,cs_item_sk item_sk -from catalog_sales,date_dim -where cs_sold_date_sk = d_date_sk - and d_month_seq between 1212 and 1212 + 11 -group by cs_bill_customer_sk - ,cs_item_sk) - select sum(case when ssci.customer_sk is not null and csci.customer_sk is null then 1 else 0 end) store_only - ,sum(case when ssci.customer_sk is null and csci.customer_sk is not null then 1 else 0 end) catalog_only - ,sum(case when ssci.customer_sk is not null and csci.customer_sk is not null then 1 else 0 end) store_and_catalog -from ssci full outer join csci on (ssci.customer_sk=csci.customer_sk - and ssci.item_sk = csci.item_sk) -limit 100; - --- end template query97.tpl query 54 in stream 1 --- start template query33.tpl query 55 in stream 1 -with /* TPC-DS query33.tpl 0.22 */ ss as ( - select - i_manufact_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Home')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 3 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_manufact_id), - cs as ( - select - i_manufact_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Home')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 3 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_manufact_id), - ws as ( - select - i_manufact_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Home')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 3 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_manufact_id) - select i_manufact_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_manufact_id - order by total_sales -limit 100; - --- end template query33.tpl query 55 in stream 1 --- start template query79.tpl query 56 in stream 1 -select /* TPC-DS query79.tpl 0.89 */ - c_last_name,c_first_name,substring(s_city,1,30),ss_ticket_number,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,store.s_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (household_demographics.hd_dep_count = 9 or household_demographics.hd_vehicle_count > 2) - and date_dim.d_dow = 1 - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_number_employees between 200 and 295 - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,store.s_city) ms,customer - where ss_customer_sk = c_customer_sk - order by c_last_name,c_first_name,substring(s_city,1,30), profit -limit 100; - --- end template query79.tpl query 56 in stream 1 --- start template query43.tpl query 57 in stream 1 -select /* TPC-DS query43.tpl 0.15 */ s_store_name, s_store_id, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from date_dim, store_sales, store - where d_date_sk = ss_sold_date_sk and - s_store_sk = ss_store_sk and - s_gmt_offset = -9 and - d_year = 2001 - group by s_store_name, s_store_id - order by s_store_name, s_store_id,sun_sales,mon_sales,tue_sales,wed_sales,thu_sales,fri_sales,sat_sales - limit 100; - --- end template query43.tpl query 57 in stream 1 --- start template query80a.tpl query 58 in stream 1 -with /* TPC-DS query80a.tpl 0.6 */ ssr as - (select s_store_id as store_id, - sum(ss_ext_sales_price) as sales, - sum(coalesce(sr_return_amt, 0)) as returns, - sum(ss_net_profit - coalesce(sr_net_loss, 0)) as profit - from store_sales left outer join store_returns on - (ss_item_sk = sr_item_sk and ss_ticket_number = sr_ticket_number), - date_dim, - store, - item, - promotion - where ss_sold_date_sk = d_date_sk - and d_date between cast('1999-08-12' as date) - and dateadd(day,30,cast('1999-08-12' as date)) - and ss_store_sk = s_store_sk - and ss_item_sk = i_item_sk - and i_current_price > 50 - and ss_promo_sk = p_promo_sk - and p_channel_tv = 'N' - group by s_store_id) - , - csr as - (select cp_catalog_page_id as catalog_page_id, - sum(cs_ext_sales_price) as sales, - sum(coalesce(cr_return_amount, 0)) as returns, - sum(cs_net_profit - coalesce(cr_net_loss, 0)) as profit - from catalog_sales left outer join catalog_returns on - (cs_item_sk = cr_item_sk and cs_order_number = cr_order_number), - date_dim, - catalog_page, - item, - promotion - where cs_sold_date_sk = d_date_sk - and d_date between cast('1999-08-12' as date) - and dateadd(day,30,cast('1999-08-12' as date)) - and cs_catalog_page_sk = cp_catalog_page_sk - and cs_item_sk = i_item_sk - and i_current_price > 50 - and cs_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(ws_ext_sales_price) as sales, - sum(coalesce(wr_return_amt, 0)) as returns, - sum(ws_net_profit - coalesce(wr_net_loss, 0)) as profit - from web_sales left outer join web_returns on - (ws_item_sk = wr_item_sk and ws_order_number = wr_order_number), - date_dim, - web_site, - item, - promotion - where ws_sold_date_sk = d_date_sk - and d_date between cast('1999-08-12' as date) - and dateadd(day,30,cast('1999-08-12' as date)) - and ws_web_site_sk = web_site_sk - and ws_item_sk = i_item_sk - and i_current_price > 50 - and ws_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by web_site_id) -, -results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || store_id as id - , sales - , returns - , profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || catalog_page_id as id - , sales - , returns - , profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , profit - from wsr - ) x - group by channel, id) - - select channel - , id - , sales - , returns - , profit - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results - ) foo - order by channel, id - limit 100; - --- end template query80a.tpl query 58 in stream 1 --- start template query93.tpl query 59 in stream 1 -select /* TPC-DS query93.tpl 0.52 */ ss_customer_sk - ,sum(act_sales) sumsales - from (select ss_item_sk - ,ss_ticket_number - ,ss_customer_sk - ,case when sr_return_quantity is not null then (ss_quantity-sr_return_quantity)*ss_sales_price - else (ss_quantity*ss_sales_price) end act_sales - from store_sales left outer join store_returns on (sr_item_sk = ss_item_sk - and sr_ticket_number = ss_ticket_number) - ,reason - where sr_reason_sk = r_reason_sk - and r_reason_desc = 'reason 35') t - group by ss_customer_sk - order by sumsales, ss_customer_sk -limit 100; - --- end template query93.tpl query 59 in stream 1 --- start template query31.tpl query 60 in stream 1 -with /* TPC-DS query31.tpl 0.50 */ ss as - (select ca_county,d_qoy, d_year,sum(ss_ext_sales_price) as store_sales - from store_sales,date_dim,customer_address - where ss_sold_date_sk = d_date_sk - and ss_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year), - ws as - (select ca_county,d_qoy, d_year,sum(ws_ext_sales_price) as web_sales - from web_sales,date_dim,customer_address - where ws_sold_date_sk = d_date_sk - and ws_bill_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year) - select - ss1.ca_county - ,ss1.d_year - ,ws2.web_sales/ws1.web_sales web_q1_q2_increase - ,ss2.store_sales/ss1.store_sales store_q1_q2_increase - ,ws3.web_sales/ws2.web_sales web_q2_q3_increase - ,ss3.store_sales/ss2.store_sales store_q2_q3_increase - from - ss ss1 - ,ss ss2 - ,ss ss3 - ,ws ws1 - ,ws ws2 - ,ws ws3 - where - ss1.d_qoy = 1 - and ss1.d_year = 2001 - and ss1.ca_county = ss2.ca_county - and ss2.d_qoy = 2 - and ss2.d_year = 2001 - and ss2.ca_county = ss3.ca_county - and ss3.d_qoy = 3 - and ss3.d_year = 2001 - and ss1.ca_county = ws1.ca_county - and ws1.d_qoy = 1 - and ws1.d_year = 2001 - and ws1.ca_county = ws2.ca_county - and ws2.d_qoy = 2 - and ws2.d_year = 2001 - and ws1.ca_county = ws3.ca_county - and ws3.d_qoy = 3 - and ws3.d_year =2001 - and case when ws1.web_sales > 0 then ws2.web_sales/ws1.web_sales else null end - > case when ss1.store_sales > 0 then ss2.store_sales/ss1.store_sales else null end - and case when ws2.web_sales > 0 then ws3.web_sales/ws2.web_sales else null end - > case when ss2.store_sales > 0 then ss3.store_sales/ss2.store_sales else null end - order by store_q2_q3_increase; - --- end template query31.tpl query 60 in stream 1 --- start template query47.tpl query 61 in stream 1 -with /* TPC-DS query47.tpl 0.42 */ v1 as( - select i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, - s_store_name, s_company_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - s_store_name, s_company_name - order by d_year, d_moy) rn - from item, store_sales, date_dim, store - where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - ( - d_year = 2000 or - ( d_year = 2000-1 and d_moy =12) or - ( d_year = 2000+1 and d_moy =1) - ) - group by i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy), - v2 as( - select v1.i_category, v1.i_brand, v1.s_store_name, v1.s_company_name - ,v1.d_year, v1.d_moy - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1.s_store_name = v1_lag.s_store_name and - v1.s_store_name = v1_lead.s_store_name and - v1.s_company_name = v1_lag.s_company_name and - v1.s_company_name = v1_lead.s_company_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 2000 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, sum_sales - limit 100; - --- end template query47.tpl query 61 in stream 1 --- start template query17.tpl query 62 in stream 1 -select /* TPC-DS query17.tpl 0.41 */ i_item_id - ,i_item_desc - ,s_state - ,count(ss_quantity) as store_sales_quantitycount - ,avg(ss_quantity) as store_sales_quantityave - ,stddev_samp(ss_quantity) as store_sales_quantitystdev - ,stddev_samp(ss_quantity)/avg(ss_quantity) as store_sales_quantitycov - ,count(sr_return_quantity) as store_returns_quantitycount - ,avg(sr_return_quantity) as store_returns_quantityave - ,stddev_samp(sr_return_quantity) as store_returns_quantitystdev - ,stddev_samp(sr_return_quantity)/avg(sr_return_quantity) as store_returns_quantitycov - ,count(cs_quantity) as catalog_sales_quantitycount ,avg(cs_quantity) as catalog_sales_quantityave - ,stddev_samp(cs_quantity) as catalog_sales_quantitystdev - ,stddev_samp(cs_quantity)/avg(cs_quantity) as catalog_sales_quantitycov - from store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where d1.d_quarter_name = '1998Q1' - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_quarter_name in ('1998Q1','1998Q2','1998Q3') - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_quarter_name in ('1998Q1','1998Q2','1998Q3') - group by i_item_id - ,i_item_desc - ,s_state - order by i_item_id - ,i_item_desc - ,s_state -limit 100; - --- end template query17.tpl query 62 in stream 1 --- start template query19.tpl query 63 in stream 1 -select /* TPC-DS query19.tpl 0.8 */ i_brand_id brand_id, i_brand brand, i_manufact_id, i_manufact, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item,customer,customer_address,store - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=35 - and d_moy=11 - and d_year=1998 - and ss_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and substring(ca_zip,1,5) <> substring(s_zip,1,5) - and ss_store_sk = s_store_sk - group by i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact - order by ext_price desc - ,i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact -limit 100 ; - --- end template query19.tpl query 63 in stream 1 --- start template query1.tpl query 64 in stream 1 -with /* TPC-DS query1.tpl 0.12 */ customer_total_return as -(select sr_customer_sk as ctr_customer_sk -,sr_store_sk as ctr_store_sk -,sum(SR_RETURN_TAX) as ctr_total_return -from store_returns -,date_dim -where sr_returned_date_sk = d_date_sk -and d_year =2002 -group by sr_customer_sk -,sr_store_sk) - select c_customer_id -from customer_total_return ctr1 -,store -,customer -where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 -from customer_total_return ctr2 -where ctr1.ctr_store_sk = ctr2.ctr_store_sk) -and s_store_sk = ctr1.ctr_store_sk -and s_state = 'TX' -and ctr1.ctr_customer_sk = c_customer_sk -order by c_customer_id -limit 100; - --- end template query1.tpl query 64 in stream 1 --- start template query64.tpl query 65 in stream 1 -with /* TPC-DS query64.tpl 0.20 */ cs_ui as - (select cs_item_sk - ,sum(cs_ext_list_price) as sale,sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit) as refund - from catalog_sales - ,catalog_returns - where cs_item_sk = cr_item_sk - and cs_order_number = cr_order_number - group by cs_item_sk - having sum(cs_ext_list_price)>2*sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit)), -cross_sales as - (select i_product_name product_name - ,i_item_sk item_sk - ,s_store_name store_name - ,s_zip store_zip - ,ad1.ca_street_number b_street_number - ,ad1.ca_street_name b_street_name - ,ad1.ca_city b_city - ,ad1.ca_zip b_zip - ,ad2.ca_street_number c_street_number - ,ad2.ca_street_name c_street_name - ,ad2.ca_city c_city - ,ad2.ca_zip c_zip - ,d1.d_year as syear - ,d2.d_year as fsyear - ,d3.d_year s2year - ,count(*) cnt - ,sum(ss_wholesale_cost) s1 - ,sum(ss_list_price) s2 - ,sum(ss_coupon_amt) s3 - FROM store_sales - ,store_returns - ,cs_ui - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,customer - ,customer_demographics cd1 - ,customer_demographics cd2 - ,promotion - ,household_demographics hd1 - ,household_demographics hd2 - ,customer_address ad1 - ,customer_address ad2 - ,income_band ib1 - ,income_band ib2 - ,item - WHERE ss_store_sk = s_store_sk AND - ss_sold_date_sk = d1.d_date_sk AND - ss_customer_sk = c_customer_sk AND - ss_cdemo_sk= cd1.cd_demo_sk AND - ss_hdemo_sk = hd1.hd_demo_sk AND - ss_addr_sk = ad1.ca_address_sk and - ss_item_sk = i_item_sk and - ss_item_sk = sr_item_sk and - ss_ticket_number = sr_ticket_number and - ss_item_sk = cs_ui.cs_item_sk and - c_current_cdemo_sk = cd2.cd_demo_sk AND - c_current_hdemo_sk = hd2.hd_demo_sk AND - c_current_addr_sk = ad2.ca_address_sk and - c_first_sales_date_sk = d2.d_date_sk and - c_first_shipto_date_sk = d3.d_date_sk and - ss_promo_sk = p_promo_sk and - hd1.hd_income_band_sk = ib1.ib_income_band_sk and - hd2.hd_income_band_sk = ib2.ib_income_band_sk and - cd1.cd_marital_status <> cd2.cd_marital_status and - i_color in ('purple','lawn','chocolate','burnished','spring','mint') and - i_current_price between 40 and 40 + 10 and - i_current_price between 40 + 1 and 40 + 15 -group by i_product_name - ,i_item_sk - ,s_store_name - ,s_zip - ,ad1.ca_street_number - ,ad1.ca_street_name - ,ad1.ca_city - ,ad1.ca_zip - ,ad2.ca_street_number - ,ad2.ca_street_name - ,ad2.ca_city - ,ad2.ca_zip - ,d1.d_year - ,d2.d_year - ,d3.d_year -) -select cs1.product_name - ,cs1.store_name - ,cs1.store_zip - ,cs1.b_street_number - ,cs1.b_street_name - ,cs1.b_city - ,cs1.b_zip - ,cs1.c_street_number - ,cs1.c_street_name - ,cs1.c_city - ,cs1.c_zip - ,cs1.syear - ,cs1.cnt - ,cs1.s1 as s11 - ,cs1.s2 as s21 - ,cs1.s3 as s31 - ,cs2.s1 as s12 - ,cs2.s2 as s22 - ,cs2.s3 as s32 - ,cs2.syear - ,cs2.cnt -from cross_sales cs1,cross_sales cs2 -where cs1.item_sk=cs2.item_sk and - cs1.syear = 1999 and - cs2.syear = 1999 + 1 and - cs2.cnt <= cs1.cnt and - cs1.store_name = cs2.store_name and - cs1.store_zip = cs2.store_zip -order by cs1.product_name - ,cs1.store_name - ,cs2.cnt - ,cs1.s1 - ,cs2.s1; - --- end template query64.tpl query 65 in stream 1 --- start template query53.tpl query 66 in stream 1 -select /* TPC-DS query53.tpl 0.88 */ * from -(select i_manufact_id, -sum(ss_sales_price) sum_sales, -avg(sum(ss_sales_price)) over (partition by i_manufact_id) avg_quarterly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and -ss_sold_date_sk = d_date_sk and -ss_store_sk = s_store_sk and -d_month_seq in (1217,1217+1,1217+2,1217+3,1217+4,1217+5,1217+6,1217+7,1217+8,1217+9,1217+10,1217+11) and -((i_category in ('Books','Children','Electronics') and -i_class in ('personal','portable','reference','self-help') and -i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) -or(i_category in ('Women','Music','Men') and -i_class in ('accessories','classical','fragrances','pants') and -i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manufact_id, d_qoy ) tmp1 -where case when avg_quarterly_sales > 0 - then abs (sum_sales - avg_quarterly_sales)/ avg_quarterly_sales - else null end > 0.1 -order by avg_quarterly_sales, - sum_sales, - i_manufact_id -limit 100; - --- end template query53.tpl query 66 in stream 1 --- start template query55.tpl query 67 in stream 1 -select /* TPC-DS query55.tpl 0.82 */ i_brand_id brand_id, i_brand brand, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=36 - and d_moy=11 - and d_year=2002 - group by i_brand, i_brand_id - order by ext_price desc, i_brand_id -limit 100 ; - --- end template query55.tpl query 67 in stream 1 --- start template query46.tpl query 68 in stream 1 -select /* TPC-DS query46.tpl 0.23 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and (household_demographics.hd_dep_count = 8 or - household_demographics.hd_vehicle_count= -1) - and date_dim.d_dow in (6,0) - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_city in ('Sharon','Beulah','Buena Vista','Woodland','Woodlawn') - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,ca_city) dn,customer,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - limit 100; - --- end template query46.tpl query 68 in stream 1 --- start template query21.tpl query 69 in stream 1 -select /* TPC-DS query21.tpl 0.14 */ * - from(select w_warehouse_name - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('2000-03-03' as date)) - then inv_quantity_on_hand - else 0 end) as inv_before - ,sum(case when (cast(d_date as date) >= cast ('2000-03-03' as date)) - then inv_quantity_on_hand - else 0 end) as inv_after - from inventory - ,warehouse - ,item - ,date_dim - where i_current_price between 0.99 and 1.49 - and i_item_sk = inv_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('2000-03-03' as date)) - and dateadd(day,30,cast ('2000-03-03' as date)) - group by w_warehouse_name, i_item_id) x - where (case when inv_before > 0 - then inv_after / inv_before - else null - end) between 2.0/3.0 and 3.0/2.0 - order by w_warehouse_name - ,i_item_id - limit 100; - --- end template query21.tpl query 69 in stream 1 --- start template query15.tpl query 70 in stream 1 -select /* TPC-DS query15.tpl 0.57 */ ca_zip - ,sum(cs_sales_price) - from catalog_sales - ,customer - ,customer_address - ,date_dim - where cs_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', - '85392', '85460', '80348', '81792') - or ca_state in ('CA','WA','GA') - or cs_sales_price > 500) - and cs_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 1998 - group by ca_zip - order by ca_zip - limit 100; - --- end template query15.tpl query 70 in stream 1 --- start template query20.tpl query 71 in stream 1 -select /* TPC-DS query20.tpl 0.65 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(cs_ext_sales_price) as itemrevenue - ,sum(cs_ext_sales_price)*100/sum(sum(cs_ext_sales_price)) over - (partition by i_class) as revenueratio - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and i_category in ('Sports', 'Home', 'Jewelry') - and cs_sold_date_sk = d_date_sk - and d_date between cast('1999-03-14' as date) - and dateadd(day,30,cast('1999-03-14' as date)) - group by i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - order by i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query20.tpl query 71 in stream 1 --- start template query65.tpl query 72 in stream 1 -select /* TPC-DS query65.tpl 0.71 */ - s_store_name, - i_item_desc, - sc.revenue, - i_current_price, - i_wholesale_cost, - i_brand - from store, item, - (select ss_store_sk, avg(revenue) as ave - from - (select ss_store_sk, ss_item_sk, - sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1224 and 1224+11 - group by ss_store_sk, ss_item_sk) sa - group by ss_store_sk) sb, - (select ss_store_sk, ss_item_sk, sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1224 and 1224+11 - group by ss_store_sk, ss_item_sk) sc - where sb.ss_store_sk = sc.ss_store_sk and - sc.revenue <= 0.1 * sb.ave and - s_store_sk = sc.ss_store_sk and - i_item_sk = sc.ss_item_sk - order by s_store_name, i_item_desc -limit 100; - --- end template query65.tpl query 72 in stream 1 --- start template query70a.tpl query 73 in stream 1 -with /* TPC-DS query70a.tpl 0.34 */ results as -( select - sum(ss_net_profit) as total_sum ,s_state ,s_county, 0 as gstate, 0 as g_county - from - store_sales - ,date_dim d1 - ,store - where - d1.d_month_seq between 1183 and 1183 + 11 - and d1.d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - and s_state in - ( select s_state - from (select s_state as s_state, - rank() over ( partition by s_state order by sum(ss_net_profit) desc) as ranking - from store_sales, store, date_dim - where d_month_seq between 1183 and 1183 + 11 - and d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - group by s_state - ) tmp1 - where ranking <= 5) - group by s_state,s_county) , - results_rollup as -(select total_sum ,s_state ,s_county, 0 as g_state, 0 as g_county, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum,s_state, NULL as s_county, 0 as g_state, 1 as g_county, 1 as lochierarchy from results group by s_state - union - select sum(total_sum) as total_sum ,NULL as s_state ,NULL as s_county, 1 as g_state, 1 as g_county, 2 as lochierarchy from results) - select total_sum ,s_state ,s_county, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_county = 0 then s_state end - order by total_sum desc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then s_state end - ,rank_within_parent - limit 100; - --- end template query70a.tpl query 73 in stream 1 --- start template query49.tpl query 74 in stream 1 -select /* TPC-DS query49.tpl 0.48 */ channel, item, return_ratio, return_rank, currency_rank from - (select - 'web' as channel - ,web.item - ,web.return_ratio - ,web.return_rank - ,web.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select ws.ws_item_sk as item - ,(cast(sum(coalesce(wr.wr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(wr.wr_return_amt,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - web_sales ws left outer join web_returns wr - on (ws.ws_order_number = wr.wr_order_number and - ws.ws_item_sk = wr.wr_item_sk) - ,date_dim - where - wr.wr_return_amt > 10000 - and ws.ws_net_profit > 1 - and ws.ws_net_paid > 0 - and ws.ws_quantity > 0 - and ws_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 11 - group by ws.ws_item_sk - ) in_web - ) web - where - ( - web.return_rank <= 10 - or - web.currency_rank <= 10 - ) - union - select - 'catalog' as channel - ,catalog.item - ,catalog.return_ratio - ,catalog.return_rank - ,catalog.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select - cs.cs_item_sk as item - ,(cast(sum(coalesce(cr.cr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(cr.cr_return_amount,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - catalog_sales cs left outer join catalog_returns cr - on (cs.cs_order_number = cr.cr_order_number and - cs.cs_item_sk = cr.cr_item_sk) - ,date_dim - where - cr.cr_return_amount > 10000 - and cs.cs_net_profit > 1 - and cs.cs_net_paid > 0 - and cs.cs_quantity > 0 - and cs_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 11 - group by cs.cs_item_sk - ) in_cat - ) catalog - where - ( - catalog.return_rank <= 10 - or - catalog.currency_rank <=10 - ) - union - select - 'store' as channel - ,store.item - ,store.return_ratio - ,store.return_rank - ,store.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select sts.ss_item_sk as item - ,(cast(sum(coalesce(sr.sr_return_quantity,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(sr.sr_return_amt,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - store_sales sts left outer join store_returns sr - on (sts.ss_ticket_number = sr.sr_ticket_number and sts.ss_item_sk = sr.sr_item_sk) - ,date_dim - where - sr.sr_return_amt > 10000 - and sts.ss_net_profit > 1 - and sts.ss_net_paid > 0 - and sts.ss_quantity > 0 - and ss_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 11 - group by sts.ss_item_sk - ) in_store - ) store - where ( - store.return_rank <= 10 - or - store.currency_rank <= 10 - ) - ) - order by 1,4,5,2 - limit 100; - --- end template query49.tpl query 74 in stream 1 --- start template query59.tpl query 75 in stream 1 -with /* TPC-DS query59.tpl 0.30 */ wss as - (select d_week_seq, - ss_store_sk, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - group by d_week_seq,ss_store_sk - ) - select s_store_name1,s_store_id1,d_week_seq1 - ,sun_sales1/sun_sales2,mon_sales1/mon_sales2 - ,tue_sales1/tue_sales2,wed_sales1/wed_sales2,thu_sales1/thu_sales2 - ,fri_sales1/fri_sales2,sat_sales1/sat_sales2 - from - (select s_store_name s_store_name1,wss.d_week_seq d_week_seq1 - ,s_store_id s_store_id1,sun_sales sun_sales1 - ,mon_sales mon_sales1,tue_sales tue_sales1 - ,wed_sales wed_sales1,thu_sales thu_sales1 - ,fri_sales fri_sales1,sat_sales sat_sales1 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1186 and 1186 + 11) y, - (select s_store_name s_store_name2,wss.d_week_seq d_week_seq2 - ,s_store_id s_store_id2,sun_sales sun_sales2 - ,mon_sales mon_sales2,tue_sales tue_sales2 - ,wed_sales wed_sales2,thu_sales thu_sales2 - ,fri_sales fri_sales2,sat_sales sat_sales2 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1186+ 12 and 1186 + 23) x - where s_store_id1=s_store_id2 - and d_week_seq1=d_week_seq2-52 - order by s_store_name1,s_store_id1,d_week_seq1 -limit 100; - --- end template query59.tpl query 75 in stream 1 --- start template query48.tpl query 76 in stream 1 -select /* TPC-DS query48.tpl 0.74 */ sum (ss_quantity) - from store_sales, store, customer_demographics, customer_address, date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 1999 - and - ( - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'W' - and - cd_education_status = 'Advanced Degree' - and - ss_sales_price between 100.00 and 150.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'M' - and - cd_education_status = '2 yr Degree' - and - ss_sales_price between 50.00 and 100.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'S' - and - cd_education_status = '4 yr Degree' - and - ss_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('AR', 'SD', 'GA') - and ss_net_profit between 0 and 2000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('KY', 'TX', 'TN') - and ss_net_profit between 150 and 3000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('IN', 'WY', 'NV') - and ss_net_profit between 50 and 25000 - ) - ) -; - --- end template query48.tpl query 76 in stream 1 --- start template query72.tpl query 77 in stream 1 -select /* TPC-DS query72.tpl 0.87 */ i_item_desc - ,w_warehouse_name - ,d1.d_week_seq - ,sum(case when p_promo_sk is null then 1 else 0 end) no_promo - ,sum(case when p_promo_sk is not null then 1 else 0 end) promo - ,count(*) total_cnt -from catalog_sales -join inventory on (cs_item_sk = inv_item_sk) -join warehouse on (w_warehouse_sk=inv_warehouse_sk) -join item on (i_item_sk = cs_item_sk) -join customer_demographics on (cs_bill_cdemo_sk = cd_demo_sk) -join household_demographics on (cs_bill_hdemo_sk = hd_demo_sk) -join date_dim d1 on (cs_sold_date_sk = d1.d_date_sk) -join date_dim d2 on (inv_date_sk = d2.d_date_sk) -join date_dim d3 on (cs_ship_date_sk = d3.d_date_sk) -left outer join promotion on (cs_promo_sk=p_promo_sk) -left outer join catalog_returns on (cr_item_sk = cs_item_sk and cr_order_number = cs_order_number) -where d1.d_week_seq = d2.d_week_seq - and inv_quantity_on_hand < cs_quantity - and d3.d_date > d1.d_date + 5 - and hd_buy_potential = '501-1000' - and d1.d_year = 2002 - and cd_marital_status = 'W' -group by i_item_desc,w_warehouse_name,d1.d_week_seq -order by total_cnt desc, i_item_desc, w_warehouse_name, d_week_seq -limit 100; - --- end template query72.tpl query 77 in stream 1 --- start template query87.tpl query 78 in stream 1 -select /* TPC-DS query87.tpl 0.77 */ count(*) -from ((select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1176 and 1176+11) - except - (select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1176 and 1176+11) - except - (select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1176 and 1176+11) -) cool_cust -; - --- end template query87.tpl query 78 in stream 1 --- start template query34.tpl query 79 in stream 1 -select /* TPC-DS query34.tpl 0.73 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (date_dim.d_dom between 1 and 3 or date_dim.d_dom between 25 and 28) - and (household_demographics.hd_buy_potential = '501-1000' or - household_demographics.hd_buy_potential = 'Unknown') - and household_demographics.hd_vehicle_count > 0 - and (case when household_demographics.hd_vehicle_count > 0 - then household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count - else null - end) > 1.2 - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_county in ('Ashley County','Itawamba County','Appomattox County','Dade County', - 'Grant County','Franklin Parish','Jefferson County','Montgomery County') - group by ss_ticket_number,ss_customer_sk) dn,customer - where ss_customer_sk = c_customer_sk - and cnt between 15 and 20 - order by c_last_name,c_first_name,c_salutation,c_preferred_cust_flag desc, ss_ticket_number; - --- end template query34.tpl query 79 in stream 1 --- start template query2.tpl query 80 in stream 1 -with /* TPC-DS query2.tpl 0.84 */ wscs as - (select sold_date_sk - ,sales_price - from (select ws_sold_date_sk sold_date_sk - ,ws_ext_sales_price sales_price - from web_sales - union all - select cs_sold_date_sk sold_date_sk - ,cs_ext_sales_price sales_price - from catalog_sales)), - wswscs as - (select d_week_seq, - sum(case when (d_day_name='Sunday') then sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then sales_price else null end) sat_sales - from wscs - ,date_dim - where d_date_sk = sold_date_sk - group by d_week_seq) - select d_week_seq1 - ,round(sun_sales1/sun_sales2,2) - ,round(mon_sales1/mon_sales2,2) - ,round(tue_sales1/tue_sales2,2) - ,round(wed_sales1/wed_sales2,2) - ,round(thu_sales1/thu_sales2,2) - ,round(fri_sales1/fri_sales2,2) - ,round(sat_sales1/sat_sales2,2) - from - (select wswscs.d_week_seq d_week_seq1 - ,sun_sales sun_sales1 - ,mon_sales mon_sales1 - ,tue_sales tue_sales1 - ,wed_sales wed_sales1 - ,thu_sales thu_sales1 - ,fri_sales fri_sales1 - ,sat_sales sat_sales1 - from wswscs,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 2001) y, - (select wswscs.d_week_seq d_week_seq2 - ,sun_sales sun_sales2 - ,mon_sales mon_sales2 - ,tue_sales tue_sales2 - ,wed_sales wed_sales2 - ,thu_sales thu_sales2 - ,fri_sales fri_sales2 - ,sat_sales sat_sales2 - from wswscs - ,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 2001+1) z - where d_week_seq1=d_week_seq2-53 - order by d_week_seq1; - --- end template query2.tpl query 80 in stream 1 --- start template query38.tpl query 81 in stream 1 -select /* TPC-DS query38.tpl 0.54 */ count(*) from ( - select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1186 and 1186 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1186 and 1186 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1186 and 1186 + 11 -) hot_cust -limit 100; - --- end template query38.tpl query 81 in stream 1 --- start template query22a.tpl query 82 in stream 1 -with /* TPC-DS query22a.tpl 0.55 */ results as -(select i_product_name - ,i_brand - ,i_class - ,i_category - ,avg(inv_quantity_on_hand) qoh - from inventory - ,date_dim - ,item --- ,warehouse - where inv_date_sk=d_date_sk - and inv_item_sk=i_item_sk --- and inv_warehouse_sk = w_warehouse_sk - and d_month_seq between 1194 and 1194 + 11 - group by i_product_name,i_brand,i_class,i_category), -results_rollup as -(select i_product_name, i_brand, i_class, i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class,i_category -union all -select i_product_name, i_brand, i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class -union all -select i_product_name, i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand -union all -select i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name -union all -select null i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results) - select i_product_name, i_brand, i_class, i_category,qoh - from results_rollup - order by qoh, i_product_name, i_brand, i_class, i_category -limit 100; - --- end template query22a.tpl query 82 in stream 1 --- start template query89.tpl query 83 in stream 1 -select /* TPC-DS query89.tpl 0.56 */ * -from( -select i_category, i_class, i_brand, - s_store_name, s_company_name, - d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, s_store_name, s_company_name) - avg_monthly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - d_year in (2001) and - ((i_category in ('Electronics','Sports','Home') and - i_class in ('stereo','optics','wallpaper') - ) - or (i_category in ('Music','Children','Books') and - i_class in ('pop','newborn','science') - )) -group by i_category, i_class, i_brand, - s_store_name, s_company_name, d_moy) tmp1 -where case when (avg_monthly_sales <> 0) then (abs(sum_sales - avg_monthly_sales) / avg_monthly_sales) else null end > 0.1 -order by sum_sales - avg_monthly_sales, s_store_name -limit 100; - --- end template query89.tpl query 83 in stream 1 --- start template query7.tpl query 84 in stream 1 -select /* TPC-DS query7.tpl 0.2 */ i_item_id, - avg(ss_quantity) agg1, - avg(ss_list_price) agg2, - avg(ss_coupon_amt) agg3, - avg(ss_sales_price) agg4 - from store_sales, customer_demographics, date_dim, item, promotion - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_cdemo_sk = cd_demo_sk and - ss_promo_sk = p_promo_sk and - cd_gender = 'M' and - cd_marital_status = 'D' and - cd_education_status = 'Advanced Degree' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 1998 - group by i_item_id - order by i_item_id - limit 100; - --- end template query7.tpl query 84 in stream 1 --- start template query10.tpl query 85 in stream 1 -select /* TPC-DS query10.tpl 0.26 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3, - cd_dep_count, - count(*) cnt4, - cd_dep_employed_count, - count(*) cnt5, - cd_dep_college_count, - count(*) cnt6 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_county in ('Wilkinson County','Bonneville County','Dimmit County','Angelina County','Emery County') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2001 and - d_moy between 1 and 1+3) and - (exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2001 and - d_moy between 1 ANd 1+3) or - exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2001 and - d_moy between 1 and 1+3)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count -limit 100; - --- end template query10.tpl query 85 in stream 1 --- start template query90.tpl query 86 in stream 1 -select /* TPC-DS query90.tpl 0.40 */ cast(amc as decimal(15,4))/cast(pmc as decimal(15,4)) am_pm_ratio - from ( select count(*) amc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 11 and 11+1 - and household_demographics.hd_dep_count = 3 - and web_page.wp_char_count between 5000 and 5200) at, - ( select count(*) pmc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 15 and 15+1 - and household_demographics.hd_dep_count = 3 - and web_page.wp_char_count between 5000 and 5200) pt - order by am_pm_ratio - limit 100; - --- end template query90.tpl query 86 in stream 1 --- start template query71.tpl query 87 in stream 1 -select /* TPC-DS query71.tpl 0.72 */ i_brand_id brand_id, i_brand brand,t_hour,t_minute, - sum(ext_price) ext_price - from item, (select ws_ext_sales_price as ext_price, - ws_sold_date_sk as sold_date_sk, - ws_item_sk as sold_item_sk, - ws_sold_time_sk as time_sk - from web_sales,date_dim - where d_date_sk = ws_sold_date_sk - and d_moy=12 - and d_year=1998 - union all - select cs_ext_sales_price as ext_price, - cs_sold_date_sk as sold_date_sk, - cs_item_sk as sold_item_sk, - cs_sold_time_sk as time_sk - from catalog_sales,date_dim - where d_date_sk = cs_sold_date_sk - and d_moy=12 - and d_year=1998 - union all - select ss_ext_sales_price as ext_price, - ss_sold_date_sk as sold_date_sk, - ss_item_sk as sold_item_sk, - ss_sold_time_sk as time_sk - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - and d_moy=12 - and d_year=1998 - ) tmp,time_dim - where - sold_item_sk = i_item_sk - and i_manager_id=1 - and time_sk = t_time_sk - and (t_meal_time = 'breakfast' or t_meal_time = 'dinner') - group by i_brand, i_brand_id,t_hour,t_minute - order by ext_price desc, i_brand_id - ; - --- end template query71.tpl query 87 in stream 1 --- start template query29.tpl query 88 in stream 1 -select /* TPC-DS query29.tpl 0.53 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,max(ss_quantity) as store_sales_quantity - ,max(sr_return_quantity) as store_returns_quantity - ,max(cs_quantity) as catalog_sales_quantity - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 1999 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 4 + 3 - and d2.d_year = 1999 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_year in (1999,1999+1,1999+2) - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query29.tpl query 88 in stream 1 --- start template query73.tpl query 89 in stream 1 -select /* TPC-DS query73.tpl 0.79 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_buy_potential = '>10000' or - household_demographics.hd_buy_potential = '5001-10000') - and household_demographics.hd_vehicle_count > 0 - and case when household_demographics.hd_vehicle_count > 0 then - household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count else null end > 1 - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_county in ('Dutchess County','Galax city','Tolland County','Appanoose County') - group by ss_ticket_number,ss_customer_sk) dj,customer - where ss_customer_sk = c_customer_sk - and cnt between 1 and 5 - order by cnt desc, c_last_name asc; - --- end template query73.tpl query 89 in stream 1 --- start template query45.tpl query 90 in stream 1 -select /* TPC-DS query45.tpl 0.18 */ ca_zip, ca_state, sum(ws_sales_price) - from web_sales, customer, customer_address, date_dim, item - where ws_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ws_item_sk = i_item_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', '85392', '85460', '80348', '81792') - or - i_item_id in (select i_item_id - from item - where i_item_sk in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29) - ) - ) - and ws_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 2000 - group by ca_zip, ca_state - order by ca_zip, ca_state - limit 100; - --- end template query45.tpl query 90 in stream 1 --- start template query91.tpl query 91 in stream 1 -select /* TPC-DS query91.tpl 0.13 */ - cc_call_center_id Call_Center, - cc_name Call_Center_Name, - cc_manager Manager, - sum(cr_net_loss) Returns_Loss -from - call_center, - catalog_returns, - date_dim, - customer, - customer_address, - customer_demographics, - household_demographics -where - cr_call_center_sk = cc_call_center_sk -and cr_returned_date_sk = d_date_sk -and cr_returning_customer_sk= c_customer_sk -and cd_demo_sk = c_current_cdemo_sk -and hd_demo_sk = c_current_hdemo_sk -and ca_address_sk = c_current_addr_sk -and d_year = 2000 -and d_moy = 12 -and ( (cd_marital_status = 'M' and cd_education_status = 'Unknown') - or(cd_marital_status = 'W' and cd_education_status = 'Advanced Degree')) -and hd_buy_potential like 'Unknown%' -and ca_gmt_offset = -6 -group by cc_call_center_id,cc_name,cc_manager,cd_marital_status,cd_education_status -order by sum(cr_net_loss) desc; - --- end template query91.tpl query 91 in stream 1 --- start template query62.tpl query 92 in stream 1 -select /* TPC-DS query62.tpl 0.24 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 30) and - (ws_ship_date_sk - ws_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 60) and - (ws_ship_date_sk - ws_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 90) and - (ws_ship_date_sk - ws_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - web_sales - ,warehouse - ,ship_mode - ,web_site - ,date_dim -where - d_month_seq between 1214 and 1214 + 11 -and ws_ship_date_sk = d_date_sk -and ws_warehouse_sk = w_warehouse_sk -and ws_ship_mode_sk = sm_ship_mode_sk -and ws_web_site_sk = web_site_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -limit 100; - --- end template query62.tpl query 92 in stream 1 --- start template query44.tpl query 93 in stream 1 -select /* TPC-DS query44.tpl 0.4 */ asceding.rnk, i1.i_product_name best_performing, i2.i_product_name worst_performing -from(select * - from (select item_sk,rank() over (order by rank_col asc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 98 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 98 - and ss_hdemo_sk is null - group by ss_store_sk))V1)V11 - where rnk < 11) asceding, - (select * - from (select item_sk,rank() over (order by rank_col desc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 98 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 98 - and ss_hdemo_sk is null - group by ss_store_sk))V2)V21 - where rnk < 11) descending, -item i1, -item i2 -where asceding.rnk = descending.rnk - and i1.i_item_sk=asceding.item_sk - and i2.i_item_sk=descending.item_sk -order by asceding.rnk -limit 100; - --- end template query44.tpl query 93 in stream 1 --- start template query76.tpl query 94 in stream 1 -select /* TPC-DS query76.tpl 0.99 */ channel, col_name, d_year, d_qoy, i_category, COUNT(*) sales_cnt, SUM(ext_sales_price) sales_amt FROM ( - SELECT 'store' as channel, 'ss_addr_sk' col_name, d_year, d_qoy, i_category, ss_ext_sales_price ext_sales_price - FROM store_sales, item, date_dim - WHERE ss_addr_sk IS NULL - AND ss_sold_date_sk=d_date_sk - AND ss_item_sk=i_item_sk - UNION ALL - SELECT 'web' as channel, 'ws_web_site_sk' col_name, d_year, d_qoy, i_category, ws_ext_sales_price ext_sales_price - FROM web_sales, item, date_dim - WHERE ws_web_site_sk IS NULL - AND ws_sold_date_sk=d_date_sk - AND ws_item_sk=i_item_sk - UNION ALL - SELECT 'catalog' as channel, 'cs_ship_cdemo_sk' col_name, d_year, d_qoy, i_category, cs_ext_sales_price ext_sales_price - FROM catalog_sales, item, date_dim - WHERE cs_ship_cdemo_sk IS NULL - AND cs_sold_date_sk=d_date_sk - AND cs_item_sk=i_item_sk) foo -GROUP BY channel, col_name, d_year, d_qoy, i_category -ORDER BY channel, col_name, d_year, d_qoy, i_category -limit 100; - --- end template query76.tpl query 94 in stream 1 --- start template query23.tpl query 95 in stream 1 -with /* TPC-DS query23.tpl 0.68 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (1999,1999+1,1999+2,1999+3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1999,1999+1,1999+2,1999+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * -from - max_store_sales)) - select sum(sales) - from (select cs_quantity*cs_list_price sales - from catalog_sales - ,date_dim - where d_year = 1999 - and d_moy = 2 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - union all - select ws_quantity*ws_list_price sales - from web_sales - ,date_dim - where d_year = 1999 - and d_moy = 2 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer)) - limit 100; -with /* TPC-DS query23.tpl 0.68 part2 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (1999,1999 + 1,1999 + 2,1999 + 3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1999,1999+1,1999+2,1999+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * - from max_store_sales)) - select c_last_name,c_first_name,sales - from (select c_last_name,c_first_name,sum(cs_quantity*cs_list_price) sales - from catalog_sales - ,customer - ,date_dim - where d_year = 1999 - and d_moy = 2 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and cs_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name - union all - select c_last_name,c_first_name,sum(ws_quantity*ws_list_price) sales - from web_sales - ,customer - ,date_dim - where d_year = 1999 - and d_moy = 2 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and ws_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name) - order by c_last_name,c_first_name,sales - limit 100; - --- end template query23.tpl query 95 in stream 1 --- start template query56.tpl query 96 in stream 1 -with /* TPC-DS query56.tpl 0.83 */ ss as ( - select i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where i_item_id in (select - i_item_id -from item -where i_color in ('honeydew','grey','sienna')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 5 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id), - cs as ( - select i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('honeydew','grey','sienna')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 5 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id), - ws as ( - select i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('honeydew','grey','sienna')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 5 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id) - select i_item_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by total_sales, - i_item_id - limit 100; - --- end template query56.tpl query 96 in stream 1 --- start template query42.tpl query 97 in stream 1 -select /* TPC-DS query42.tpl 0.61 */ dt.d_year - ,item.i_category_id - ,item.i_category - ,sum(ss_ext_sales_price) - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=12 - and dt.d_year=1998 - group by dt.d_year - ,item.i_category_id - ,item.i_category - order by sum(ss_ext_sales_price) desc,dt.d_year - ,item.i_category_id - ,item.i_category -limit 100 ; - --- end template query42.tpl query 97 in stream 1 --- start template query39.tpl query 98 in stream 1 -with /* TPC-DS query39.tpl 0.5 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =2001 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=3 - and inv2.d_moy=3+1 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; -with /* TPC-DS query39.tpl 0.5 part2 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =2001 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=3 - and inv2.d_moy=3+1 - and inv1.cov > 1.5 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; - --- end template query39.tpl query 98 in stream 1 --- start template query74.tpl query 99 in stream 1 -with /* TPC-DS query74.tpl 0.76 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,sum(ss_net_paid) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1998,1998+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,sum(ws_net_paid) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - and d_year in (1998,1998+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - ) - select - t_s_secyear.customer_id, t_s_secyear.customer_first_name, t_s_secyear.customer_last_name - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.year = 1998 - and t_s_secyear.year = 1998+1 - and t_w_firstyear.year = 1998 - and t_w_secyear.year = 1998+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - order by 2,1,3 -limit 100; - --- end template query74.tpl query 99 in stream 1 diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/30TB/queries/query_10.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/30TB/queries/query_10.sql deleted file mode 100644 index 4b9400d5..00000000 --- a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/30TB/queries/query_10.sql +++ /dev/null @@ -1,5027 +0,0 @@ --- start template query43.tpl query 1 in stream 10 -select /* TPC-DS query43.tpl 0.15 */ s_store_name, s_store_id, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from date_dim, store_sales, store - where d_date_sk = ss_sold_date_sk and - s_store_sk = ss_store_sk and - s_gmt_offset = -5 and - d_year = 1999 - group by s_store_name, s_store_id - order by s_store_name, s_store_id,sun_sales,mon_sales,tue_sales,wed_sales,thu_sales,fri_sales,sat_sales - limit 100; - --- end template query43.tpl query 1 in stream 10 --- start template query50.tpl query 2 in stream 10 -select /* TPC-DS query50.tpl 0.60 */ - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 30) and - (sr_returned_date_sk - ss_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 60) and - (sr_returned_date_sk - ss_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 90) and - (sr_returned_date_sk - ss_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - store_sales - ,store_returns - ,store - ,date_dim d1 - ,date_dim d2 -where - d2.d_year = 2002 -and d2.d_moy = 9 -and ss_ticket_number = sr_ticket_number -and ss_item_sk = sr_item_sk -and ss_sold_date_sk = d1.d_date_sk -and sr_returned_date_sk = d2.d_date_sk -and ss_customer_sk = sr_customer_sk -and ss_store_sk = s_store_sk -group by - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -order by s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -limit 100; - --- end template query50.tpl query 2 in stream 10 --- start template query41.tpl query 3 in stream 10 -select /* TPC-DS query41.tpl 0.62 */ distinct(i_product_name) - from item i1 - where i_manufact_id between 964 and 964+40 - and (select count(*) as item_cnt - from item - where (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'rosy' or i_color = 'cyan') and - (i_units = 'Gross' or i_units = 'Cup') and - (i_size = 'medium' or i_size = 'economy') - ) or - (i_category = 'Women' and - (i_color = 'lace' or i_color = 'tomato') and - (i_units = 'Gram' or i_units = 'Tsp') and - (i_size = 'large' or i_size = 'small') - ) or - (i_category = 'Men' and - (i_color = 'spring' or i_color = 'lavender') and - (i_units = 'Ounce' or i_units = 'Unknown') and - (i_size = 'extra large' or i_size = 'petite') - ) or - (i_category = 'Men' and - (i_color = 'burnished' or i_color = 'gainsboro') and - (i_units = 'Tbl' or i_units = 'Dram') and - (i_size = 'medium' or i_size = 'economy') - ))) or - (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'cornsilk' or i_color = 'lawn') and - (i_units = 'Lb' or i_units = 'Each') and - (i_size = 'medium' or i_size = 'economy') - ) or - (i_category = 'Women' and - (i_color = 'medium' or i_color = 'green') and - (i_units = 'Pound' or i_units = 'Ton') and - (i_size = 'large' or i_size = 'small') - ) or - (i_category = 'Men' and - (i_color = 'almond' or i_color = 'smoke') and - (i_units = 'Pallet' or i_units = 'Case') and - (i_size = 'extra large' or i_size = 'petite') - ) or - (i_category = 'Men' and - (i_color = 'azure' or i_color = 'navy') and - (i_units = 'N/A' or i_units = 'Bundle') and - (i_size = 'medium' or i_size = 'economy') - )))) > 0 - order by i_product_name - limit 100; - --- end template query41.tpl query 3 in stream 10 --- start template query48.tpl query 4 in stream 10 -select /* TPC-DS query48.tpl 0.74 */ sum (ss_quantity) - from store_sales, store, customer_demographics, customer_address, date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2000 - and - ( - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'D' - and - cd_education_status = '4 yr Degree' - and - ss_sales_price between 100.00 and 150.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'U' - and - cd_education_status = 'Advanced Degree' - and - ss_sales_price between 50.00 and 100.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'M' - and - cd_education_status = 'Unknown' - and - ss_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('IN', 'TX', 'CA') - and ss_net_profit between 0 and 2000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('IL', 'OH', 'SC') - and ss_net_profit between 150 and 3000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('CO', 'KY', 'NY') - and ss_net_profit between 50 and 25000 - ) - ) -; - --- end template query48.tpl query 4 in stream 10 --- start template query54.tpl query 5 in stream 10 -with /* TPC-DS query54.tpl 0.81 */ my_customers as ( - select distinct c_customer_sk - , c_current_addr_sk - from - ( select cs_sold_date_sk sold_date_sk, - cs_bill_customer_sk customer_sk, - cs_item_sk item_sk - from catalog_sales - union all - select ws_sold_date_sk sold_date_sk, - ws_bill_customer_sk customer_sk, - ws_item_sk item_sk - from web_sales - ) cs_or_ws_sales, - item, - date_dim, - customer - where sold_date_sk = d_date_sk - and item_sk = i_item_sk - and i_category = 'Children' - and i_class = 'toddlers' - and c_customer_sk = cs_or_ws_sales.customer_sk - and d_moy = 5 - and d_year = 2000 - ) - , my_revenue as ( - select c_customer_sk, - sum(ss_ext_sales_price) as revenue - from my_customers, - store_sales, - customer_address, - store, - date_dim - where c_current_addr_sk = ca_address_sk - and ca_county = s_county - and ca_state = s_state - and ss_sold_date_sk = d_date_sk - and c_customer_sk = ss_customer_sk - and d_month_seq between (select distinct d_month_seq+1 - from date_dim where d_year = 2000 and d_moy = 5) - and (select distinct d_month_seq+3 - from date_dim where d_year = 2000 and d_moy = 5) - group by c_customer_sk - ) - , segments as - (select cast((revenue/50) as bigint) as segment - from my_revenue - ) - select segment, count(*) as num_customers, segment*50 as segment_base - from segments - group by segment - order by segment, num_customers - limit 100; - --- end template query54.tpl query 5 in stream 10 --- start template query53.tpl query 6 in stream 10 -select /* TPC-DS query53.tpl 0.88 */ * from -(select i_manufact_id, -sum(ss_sales_price) sum_sales, -avg(sum(ss_sales_price)) over (partition by i_manufact_id) avg_quarterly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and -ss_sold_date_sk = d_date_sk and -ss_store_sk = s_store_sk and -d_month_seq in (1184,1184+1,1184+2,1184+3,1184+4,1184+5,1184+6,1184+7,1184+8,1184+9,1184+10,1184+11) and -((i_category in ('Books','Children','Electronics') and -i_class in ('personal','portable','reference','self-help') and -i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) -or(i_category in ('Women','Music','Men') and -i_class in ('accessories','classical','fragrances','pants') and -i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manufact_id, d_qoy ) tmp1 -where case when avg_quarterly_sales > 0 - then abs (sum_sales - avg_quarterly_sales)/ avg_quarterly_sales - else null end > 0.1 -order by avg_quarterly_sales, - sum_sales, - i_manufact_id -limit 100; - --- end template query53.tpl query 6 in stream 10 --- start template query31.tpl query 7 in stream 10 -with /* TPC-DS query31.tpl 0.50 */ ss as - (select ca_county,d_qoy, d_year,sum(ss_ext_sales_price) as store_sales - from store_sales,date_dim,customer_address - where ss_sold_date_sk = d_date_sk - and ss_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year), - ws as - (select ca_county,d_qoy, d_year,sum(ws_ext_sales_price) as web_sales - from web_sales,date_dim,customer_address - where ws_sold_date_sk = d_date_sk - and ws_bill_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year) - select - ss1.ca_county - ,ss1.d_year - ,ws2.web_sales/ws1.web_sales web_q1_q2_increase - ,ss2.store_sales/ss1.store_sales store_q1_q2_increase - ,ws3.web_sales/ws2.web_sales web_q2_q3_increase - ,ss3.store_sales/ss2.store_sales store_q2_q3_increase - from - ss ss1 - ,ss ss2 - ,ss ss3 - ,ws ws1 - ,ws ws2 - ,ws ws3 - where - ss1.d_qoy = 1 - and ss1.d_year = 2000 - and ss1.ca_county = ss2.ca_county - and ss2.d_qoy = 2 - and ss2.d_year = 2000 - and ss2.ca_county = ss3.ca_county - and ss3.d_qoy = 3 - and ss3.d_year = 2000 - and ss1.ca_county = ws1.ca_county - and ws1.d_qoy = 1 - and ws1.d_year = 2000 - and ws1.ca_county = ws2.ca_county - and ws2.d_qoy = 2 - and ws2.d_year = 2000 - and ws1.ca_county = ws3.ca_county - and ws3.d_qoy = 3 - and ws3.d_year =2000 - and case when ws1.web_sales > 0 then ws2.web_sales/ws1.web_sales else null end - > case when ss1.store_sales > 0 then ss2.store_sales/ss1.store_sales else null end - and case when ws2.web_sales > 0 then ws3.web_sales/ws2.web_sales else null end - > case when ss2.store_sales > 0 then ss3.store_sales/ss2.store_sales else null end - order by web_q1_q2_increase; - --- end template query31.tpl query 7 in stream 10 --- start template query39.tpl query 8 in stream 10 -with /* TPC-DS query39.tpl 0.5 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =2001 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=4 - and inv2.d_moy=4+1 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; -with /* TPC-DS query39.tpl 0.5 part2 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =2001 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=4 - and inv2.d_moy=4+1 - and inv1.cov > 1.5 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; - --- end template query39.tpl query 8 in stream 10 --- start template query2.tpl query 9 in stream 10 -with /* TPC-DS query2.tpl 0.84 */ wscs as - (select sold_date_sk - ,sales_price - from (select ws_sold_date_sk sold_date_sk - ,ws_ext_sales_price sales_price - from web_sales - union all - select cs_sold_date_sk sold_date_sk - ,cs_ext_sales_price sales_price - from catalog_sales)), - wswscs as - (select d_week_seq, - sum(case when (d_day_name='Sunday') then sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then sales_price else null end) sat_sales - from wscs - ,date_dim - where d_date_sk = sold_date_sk - group by d_week_seq) - select d_week_seq1 - ,round(sun_sales1/sun_sales2,2) - ,round(mon_sales1/mon_sales2,2) - ,round(tue_sales1/tue_sales2,2) - ,round(wed_sales1/wed_sales2,2) - ,round(thu_sales1/thu_sales2,2) - ,round(fri_sales1/fri_sales2,2) - ,round(sat_sales1/sat_sales2,2) - from - (select wswscs.d_week_seq d_week_seq1 - ,sun_sales sun_sales1 - ,mon_sales mon_sales1 - ,tue_sales tue_sales1 - ,wed_sales wed_sales1 - ,thu_sales thu_sales1 - ,fri_sales fri_sales1 - ,sat_sales sat_sales1 - from wswscs,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 2001) y, - (select wswscs.d_week_seq d_week_seq2 - ,sun_sales sun_sales2 - ,mon_sales mon_sales2 - ,tue_sales tue_sales2 - ,wed_sales wed_sales2 - ,thu_sales thu_sales2 - ,fri_sales fri_sales2 - ,sat_sales sat_sales2 - from wswscs - ,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 2001+1) z - where d_week_seq1=d_week_seq2-53 - order by d_week_seq1; - --- end template query2.tpl query 9 in stream 10 --- start template query96.tpl query 10 in stream 10 -select /* TPC-DS query96.tpl 0.1 */ count(*) -from store_sales - ,household_demographics - ,time_dim, store -where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and household_demographics.hd_dep_count = 8 - and store.s_store_name = 'ese' -order by count(*) -limit 100; - --- end template query96.tpl query 10 in stream 10 --- start template query93.tpl query 11 in stream 10 -select /* TPC-DS query93.tpl 0.52 */ ss_customer_sk - ,sum(act_sales) sumsales - from (select ss_item_sk - ,ss_ticket_number - ,ss_customer_sk - ,case when sr_return_quantity is not null then (ss_quantity-sr_return_quantity)*ss_sales_price - else (ss_quantity*ss_sales_price) end act_sales - from store_sales left outer join store_returns on (sr_item_sk = ss_item_sk - and sr_ticket_number = ss_ticket_number) - ,reason - where sr_reason_sk = r_reason_sk - and r_reason_desc = 'reason 48') t - group by ss_customer_sk - order by sumsales, ss_customer_sk -limit 100; - --- end template query93.tpl query 11 in stream 10 --- start template query15.tpl query 12 in stream 10 -select /* TPC-DS query15.tpl 0.57 */ ca_zip - ,sum(cs_sales_price) - from catalog_sales - ,customer - ,customer_address - ,date_dim - where cs_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', - '85392', '85460', '80348', '81792') - or ca_state in ('CA','WA','GA') - or cs_sales_price > 500) - and cs_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 2001 - group by ca_zip - order by ca_zip - limit 100; - --- end template query15.tpl query 12 in stream 10 --- start template query91.tpl query 13 in stream 10 -select /* TPC-DS query91.tpl 0.13 */ - cc_call_center_id Call_Center, - cc_name Call_Center_Name, - cc_manager Manager, - sum(cr_net_loss) Returns_Loss -from - call_center, - catalog_returns, - date_dim, - customer, - customer_address, - customer_demographics, - household_demographics -where - cr_call_center_sk = cc_call_center_sk -and cr_returned_date_sk = d_date_sk -and cr_returning_customer_sk= c_customer_sk -and cd_demo_sk = c_current_cdemo_sk -and hd_demo_sk = c_current_hdemo_sk -and ca_address_sk = c_current_addr_sk -and d_year = 2001 -and d_moy = 12 -and ( (cd_marital_status = 'M' and cd_education_status = 'Unknown') - or(cd_marital_status = 'W' and cd_education_status = 'Advanced Degree')) -and hd_buy_potential like '501-1000%' -and ca_gmt_offset = -6 -group by cc_call_center_id,cc_name,cc_manager,cd_marital_status,cd_education_status -order by sum(cr_net_loss) desc; - --- end template query91.tpl query 13 in stream 10 --- start template query21.tpl query 14 in stream 10 -select /* TPC-DS query21.tpl 0.14 */ * - from(select w_warehouse_name - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('1998-06-27' as date)) - then inv_quantity_on_hand - else 0 end) as inv_before - ,sum(case when (cast(d_date as date) >= cast ('1998-06-27' as date)) - then inv_quantity_on_hand - else 0 end) as inv_after - from inventory - ,warehouse - ,item - ,date_dim - where i_current_price between 0.99 and 1.49 - and i_item_sk = inv_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('1998-06-27' as date)) - and dateadd(day,30,cast ('1998-06-27' as date)) - group by w_warehouse_name, i_item_id) x - where (case when inv_before > 0 - then inv_after / inv_before - else null - end) between 2.0/3.0 and 3.0/2.0 - order by w_warehouse_name - ,i_item_id - limit 100; - --- end template query21.tpl query 14 in stream 10 --- start template query18a.tpl query 15 in stream 10 -with /* TPC-DS query18a.tpl 0.90 */ results as - (select i_item_id, - ca_country, - ca_state, - ca_county, - cast(cs_quantity as decimal(12,2)) agg1, - cast(cs_list_price as decimal(12,2)) agg2, - cast(cs_coupon_amt as decimal(12,2)) agg3, - cast(cs_sales_price as decimal(12,2)) agg4, - cast(cs_net_profit as decimal(12,2)) agg5, - cast(c_birth_year as decimal(12,2)) agg6, - cast(cd1.cd_dep_count as decimal(12,2)) agg7 - from catalog_sales, customer_demographics cd1, customer_demographics cd2, customer, customer_address, date_dim, item - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd1.cd_demo_sk and - cs_bill_customer_sk = c_customer_sk and - cd1.cd_gender = 'F' and - cd1.cd_education_status = 'Primary' and - c_current_cdemo_sk = cd2.cd_demo_sk and - c_current_addr_sk = ca_address_sk and - c_birth_month in (5,10,6,2,9,8) and - d_year = 2000 and - ca_state in ('MO','IA','VA','ND','WA','OH','NE') - ) - select i_item_id, ca_country, ca_state, ca_county, agg1, agg2, agg3, agg4, agg5, agg6, agg7 - from ( - select i_item_id, ca_country, ca_state, ca_county, avg(agg1) agg1, - avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state, ca_county - union all - select i_item_id, ca_country, ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state - union all - select i_item_id, ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country - union all - select i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - ) foo - order by ca_country, ca_state, ca_county, i_item_id - limit 100; - --- end template query18a.tpl query 15 in stream 10 --- start template query32.tpl query 16 in stream 10 -select /* TPC-DS query32.tpl 0.7 */ sum(cs_ext_discount_amt) as "excess discount amount" -from - catalog_sales - ,item - ,date_dim -where -i_manufact_id = 640 -and i_item_sk = cs_item_sk -and d_date between '2002-02-21' and - dateadd(day,90,cast('2002-02-21' as date)) -and d_date_sk = cs_sold_date_sk -and cs_ext_discount_amt - > ( - select - 1.3 * avg(cs_ext_discount_amt) - from - catalog_sales - ,date_dim - where - cs_item_sk = i_item_sk - and d_date between '2002-02-21' and - dateadd(day,90,cast('2002-02-21' as date)) - and d_date_sk = cs_sold_date_sk - ) -limit 100; - --- end template query32.tpl query 16 in stream 10 --- start template query63.tpl query 17 in stream 10 -select /* TPC-DS query63.tpl 0.27 */ * -from (select i_manager_id - ,sum(ss_sales_price) sum_sales - ,avg(sum(ss_sales_price)) over (partition by i_manager_id) avg_monthly_sales - from item - ,store_sales - ,date_dim - ,store - where ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and d_month_seq in (1177,1177+1,1177+2,1177+3,1177+4,1177+5,1177+6,1177+7,1177+8,1177+9,1177+10,1177+11) - and (( i_category in ('Books','Children','Electronics') - and i_class in ('personal','portable','reference','self-help') - and i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) - or( i_category in ('Women','Music','Men') - and i_class in ('accessories','classical','fragrances','pants') - and i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manager_id, d_moy) tmp1 -where case when avg_monthly_sales > 0 then abs (sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 -order by i_manager_id - ,avg_monthly_sales - ,sum_sales -limit 100; - --- end template query63.tpl query 17 in stream 10 --- start template query24.tpl query 18 in stream 10 -with /* TPC-DS query24.tpl 0.92 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_sales_price) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip -and s_market_id=5 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'lavender' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; -with /* TPC-DS query24.tpl 0.92 part2 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_sales_price) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip - and s_market_id = 5 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'lace' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; - --- end template query24.tpl query 18 in stream 10 --- start template query66.tpl query 19 in stream 10 -select /* TPC-DS query66.tpl 0.39 */ - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - ,sum(jan_sales) as jan_sales - ,sum(feb_sales) as feb_sales - ,sum(mar_sales) as mar_sales - ,sum(apr_sales) as apr_sales - ,sum(may_sales) as may_sales - ,sum(jun_sales) as jun_sales - ,sum(jul_sales) as jul_sales - ,sum(aug_sales) as aug_sales - ,sum(sep_sales) as sep_sales - ,sum(oct_sales) as oct_sales - ,sum(nov_sales) as nov_sales - ,sum(dec_sales) as dec_sales - ,sum(jan_sales/w_warehouse_sq_ft) as jan_sales_per_sq_foot - ,sum(feb_sales/w_warehouse_sq_ft) as feb_sales_per_sq_foot - ,sum(mar_sales/w_warehouse_sq_ft) as mar_sales_per_sq_foot - ,sum(apr_sales/w_warehouse_sq_ft) as apr_sales_per_sq_foot - ,sum(may_sales/w_warehouse_sq_ft) as may_sales_per_sq_foot - ,sum(jun_sales/w_warehouse_sq_ft) as jun_sales_per_sq_foot - ,sum(jul_sales/w_warehouse_sq_ft) as jul_sales_per_sq_foot - ,sum(aug_sales/w_warehouse_sq_ft) as aug_sales_per_sq_foot - ,sum(sep_sales/w_warehouse_sq_ft) as sep_sales_per_sq_foot - ,sum(oct_sales/w_warehouse_sq_ft) as oct_sales_per_sq_foot - ,sum(nov_sales/w_warehouse_sq_ft) as nov_sales_per_sq_foot - ,sum(dec_sales/w_warehouse_sq_ft) as dec_sales_per_sq_foot - ,sum(jan_net) as jan_net - ,sum(feb_net) as feb_net - ,sum(mar_net) as mar_net - ,sum(apr_net) as apr_net - ,sum(may_net) as may_net - ,sum(jun_net) as jun_net - ,sum(jul_net) as jul_net - ,sum(aug_net) as aug_net - ,sum(sep_net) as sep_net - ,sum(oct_net) as oct_net - ,sum(nov_net) as nov_net - ,sum(dec_net) as dec_net - from ( - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'UPS' || ',' || 'PRIVATECARRIER' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then ws_sales_price* ws_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then ws_sales_price* ws_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then ws_sales_price* ws_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then ws_sales_price* ws_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then ws_sales_price* ws_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then ws_sales_price* ws_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then ws_sales_price* ws_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then ws_sales_price* ws_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then ws_sales_price* ws_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then ws_sales_price* ws_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then ws_sales_price* ws_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then ws_sales_price* ws_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then ws_net_profit * ws_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then ws_net_profit * ws_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then ws_net_profit * ws_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then ws_net_profit * ws_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then ws_net_profit * ws_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then ws_net_profit * ws_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then ws_net_profit * ws_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then ws_net_profit * ws_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then ws_net_profit * ws_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then ws_net_profit * ws_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then ws_net_profit * ws_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then ws_net_profit * ws_quantity else 0 end) as dec_net - from - web_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - ws_warehouse_sk = w_warehouse_sk - and ws_sold_date_sk = d_date_sk - and ws_sold_time_sk = t_time_sk - and ws_ship_mode_sk = sm_ship_mode_sk - and d_year = 1999 - and t_time between 46439 and 46439+28800 - and sm_carrier in ('UPS','PRIVATECARRIER') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - union all - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'UPS' || ',' || 'PRIVATECARRIER' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then cs_ext_sales_price* cs_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then cs_ext_sales_price* cs_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then cs_ext_sales_price* cs_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then cs_ext_sales_price* cs_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then cs_ext_sales_price* cs_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then cs_ext_sales_price* cs_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then cs_ext_sales_price* cs_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then cs_ext_sales_price* cs_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then cs_ext_sales_price* cs_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then cs_ext_sales_price* cs_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then cs_ext_sales_price* cs_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then cs_ext_sales_price* cs_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as dec_net - from - catalog_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and cs_sold_time_sk = t_time_sk - and cs_ship_mode_sk = sm_ship_mode_sk - and d_year = 1999 - and t_time between 46439 AND 46439+28800 - and sm_carrier in ('UPS','PRIVATECARRIER') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - ) x - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - order by w_warehouse_name - limit 100; - --- end template query66.tpl query 19 in stream 10 --- start template query70a.tpl query 20 in stream 10 -with /* TPC-DS query70a.tpl 0.34 */ results as -( select - sum(ss_net_profit) as total_sum ,s_state ,s_county, 0 as gstate, 0 as g_county - from - store_sales - ,date_dim d1 - ,store - where - d1.d_month_seq between 1210 and 1210 + 11 - and d1.d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - and s_state in - ( select s_state - from (select s_state as s_state, - rank() over ( partition by s_state order by sum(ss_net_profit) desc) as ranking - from store_sales, store, date_dim - where d_month_seq between 1210 and 1210 + 11 - and d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - group by s_state - ) tmp1 - where ranking <= 5) - group by s_state,s_county) , - results_rollup as -(select total_sum ,s_state ,s_county, 0 as g_state, 0 as g_county, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum,s_state, NULL as s_county, 0 as g_state, 1 as g_county, 1 as lochierarchy from results group by s_state - union - select sum(total_sum) as total_sum ,NULL as s_state ,NULL as s_county, 1 as g_state, 1 as g_county, 2 as lochierarchy from results) - select total_sum ,s_state ,s_county, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_county = 0 then s_state end - order by total_sum desc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then s_state end - ,rank_within_parent - limit 100; - --- end template query70a.tpl query 20 in stream 10 --- start template query36a.tpl query 21 in stream 10 -with /* TPC-DS query36a.tpl 0.21 */ results as - (select - sum(ss_net_profit) as ss_net_profit, sum(ss_ext_sales_price) as ss_ext_sales_price, - sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin - ,i_category - ,i_class - ,0 as g_category, 0 as g_class - from - store_sales - ,date_dim d1 - ,item - ,store - where - d1.d_year = 2002 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and s_state in ('CO','VT','TN','IL', - 'IN','LA','WV','MN') - group by i_category,i_class) - , - results_rollup as - (select gross_margin ,i_category ,i_class,0 as t_category, 0 as t_class, 0 as lochierarchy from results - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - i_category, NULL AS i_class, 0 as t_category, 1 as t_class, 1 as lochierarchy from results group by i_category - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - NULL AS i_category ,NULL AS i_class, 1 as t_category, 1 as t_class, 2 as lochierarchy from results) - select - gross_margin ,i_category ,i_class, lochierarchy,rank() over ( - partition by lochierarchy, case when t_class = 0 then i_category end - order by gross_margin asc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then i_category end - ,rank_within_parent - limit 100; - --- end template query36a.tpl query 21 in stream 10 --- start template query20.tpl query 22 in stream 10 -select /* TPC-DS query20.tpl 0.65 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(cs_ext_sales_price) as itemrevenue - ,sum(cs_ext_sales_price)*100/sum(sum(cs_ext_sales_price)) over - (partition by i_class) as revenueratio - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and i_category in ('Electronics', 'Music', 'Women') - and cs_sold_date_sk = d_date_sk - and d_date between cast('2001-05-20' as date) - and dateadd(day,30,cast('2001-05-20' as date)) - group by i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - order by i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query20.tpl query 22 in stream 10 --- start template query30.tpl query 23 in stream 10 -with /* TPC-DS query30.tpl 0.75 */ customer_total_return as - (select wr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(wr_return_amt) as ctr_total_return - from web_returns - ,date_dim - ,customer_address - where wr_returned_date_sk = d_date_sk - and d_year =2001 - and wr_returning_addr_sk = ca_address_sk - group by wr_returning_customer_sk - ,ca_state) - select c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'AR' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return -limit 100; - --- end template query30.tpl query 23 in stream 10 --- start template query25.tpl query 24 in stream 10 -select /* TPC-DS query25.tpl 0.9 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,stddev_samp(ss_net_profit) as store_sales_profit - ,stddev_samp(sr_net_loss) as store_returns_loss - ,stddev_samp(cs_net_profit) as catalog_sales_profit - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 1999 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 10 - and d2.d_year = 1999 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_moy between 4 and 10 - and d3.d_year = 1999 - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query25.tpl query 24 in stream 10 --- start template query7.tpl query 25 in stream 10 -select /* TPC-DS query7.tpl 0.2 */ i_item_id, - avg(ss_quantity) agg1, - avg(ss_list_price) agg2, - avg(ss_coupon_amt) agg3, - avg(ss_sales_price) agg4 - from store_sales, customer_demographics, date_dim, item, promotion - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_cdemo_sk = cd_demo_sk and - ss_promo_sk = p_promo_sk and - cd_gender = 'M' and - cd_marital_status = 'U' and - cd_education_status = 'Advanced Degree' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 1998 - group by i_item_id - order by i_item_id - limit 100; - --- end template query7.tpl query 25 in stream 10 --- start template query1.tpl query 26 in stream 10 -with /* TPC-DS query1.tpl 0.12 */ customer_total_return as -(select sr_customer_sk as ctr_customer_sk -,sr_store_sk as ctr_store_sk -,sum(SR_REVERSED_CHARGE) as ctr_total_return -from store_returns -,date_dim -where sr_returned_date_sk = d_date_sk -and d_year =1998 -group by sr_customer_sk -,sr_store_sk) - select c_customer_id -from customer_total_return ctr1 -,store -,customer -where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 -from customer_total_return ctr2 -where ctr1.ctr_store_sk = ctr2.ctr_store_sk) -and s_store_sk = ctr1.ctr_store_sk -and s_state = 'IN' -and ctr1.ctr_customer_sk = c_customer_sk -order by c_customer_id -limit 100; - --- end template query1.tpl query 26 in stream 10 --- start template query98.tpl query 27 in stream 10 -select /* TPC-DS query98.tpl 0.32 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ss_ext_sales_price) as itemrevenue - ,sum(ss_ext_sales_price)*100/sum(sum(ss_ext_sales_price)) over - (partition by i_class) as revenueratio -from - store_sales - ,item - ,date_dim -where - ss_item_sk = i_item_sk - and i_category in ('Shoes', 'Jewelry', 'Home') - and ss_sold_date_sk = d_date_sk - and d_date between cast('2001-02-17' as date) - and dateadd(day,30,cast('2001-02-17' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio; - --- end template query98.tpl query 27 in stream 10 --- start template query69.tpl query 28 in stream 10 -select /* TPC-DS query69.tpl 0.28 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_state in ('NY','MN','IL') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2004 and - d_moy between 4 and 4+2) and - (not exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2004 and - d_moy between 4 and 4+2) and - not exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2004 and - d_moy between 4 and 4+2)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - limit 100; - --- end template query69.tpl query 28 in stream 10 --- start template query47.tpl query 29 in stream 10 -with /* TPC-DS query47.tpl 0.42 */ v1 as( - select i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, - s_store_name, s_company_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - s_store_name, s_company_name - order by d_year, d_moy) rn - from item, store_sales, date_dim, store - where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - ( - d_year = 1999 or - ( d_year = 1999-1 and d_moy =12) or - ( d_year = 1999+1 and d_moy =1) - ) - group by i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy), - v2 as( - select v1.i_category, v1.i_brand, v1.s_store_name, v1.s_company_name - ,v1.d_year, v1.d_moy - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1.s_store_name = v1_lag.s_store_name and - v1.s_store_name = v1_lead.s_store_name and - v1.s_company_name = v1_lag.s_company_name and - v1.s_company_name = v1_lead.s_company_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 1999 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, sum_sales - limit 100; - --- end template query47.tpl query 29 in stream 10 --- start template query94.tpl query 30 in stream 10 -select /* TPC-DS query94.tpl 0.17 */ - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2002-5-01' and - dateadd(day,60,cast('2002-5-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'WA' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and exists (select * - from web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) -and not exists(select * - from web_returns wr1 - where ws1.ws_order_number = wr1.wr_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query94.tpl query 30 in stream 10 --- start template query82.tpl query 31 in stream 10 -select /* TPC-DS query82.tpl 0.67 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, store_sales - where i_current_price between 45 and 45+30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('2002-01-11' as date) and dateadd(day,60,cast('2002-01-11' as date)) - and i_manufact_id in (247,372,342,97) - and inv_quantity_on_hand between 100 and 500 - and ss_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query82.tpl query 31 in stream 10 --- start template query37.tpl query 32 in stream 10 -select /* TPC-DS query37.tpl 0.31 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, catalog_sales - where i_current_price between 33 and 33 + 30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('2000-07-21' as date) and dateadd(day,60,cast('2000-07-21' as date)) - and i_manufact_id in (693,747,966,828) - and inv_quantity_on_hand between 100 and 500 - and cs_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query37.tpl query 32 in stream 10 --- start template query64.tpl query 33 in stream 10 -with /* TPC-DS query64.tpl 0.20 */ cs_ui as - (select cs_item_sk - ,sum(cs_ext_list_price) as sale,sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit) as refund - from catalog_sales - ,catalog_returns - where cs_item_sk = cr_item_sk - and cs_order_number = cr_order_number - group by cs_item_sk - having sum(cs_ext_list_price)>2*sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit)), -cross_sales as - (select i_product_name product_name - ,i_item_sk item_sk - ,s_store_name store_name - ,s_zip store_zip - ,ad1.ca_street_number b_street_number - ,ad1.ca_street_name b_street_name - ,ad1.ca_city b_city - ,ad1.ca_zip b_zip - ,ad2.ca_street_number c_street_number - ,ad2.ca_street_name c_street_name - ,ad2.ca_city c_city - ,ad2.ca_zip c_zip - ,d1.d_year as syear - ,d2.d_year as fsyear - ,d3.d_year s2year - ,count(*) cnt - ,sum(ss_wholesale_cost) s1 - ,sum(ss_list_price) s2 - ,sum(ss_coupon_amt) s3 - FROM store_sales - ,store_returns - ,cs_ui - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,customer - ,customer_demographics cd1 - ,customer_demographics cd2 - ,promotion - ,household_demographics hd1 - ,household_demographics hd2 - ,customer_address ad1 - ,customer_address ad2 - ,income_band ib1 - ,income_band ib2 - ,item - WHERE ss_store_sk = s_store_sk AND - ss_sold_date_sk = d1.d_date_sk AND - ss_customer_sk = c_customer_sk AND - ss_cdemo_sk= cd1.cd_demo_sk AND - ss_hdemo_sk = hd1.hd_demo_sk AND - ss_addr_sk = ad1.ca_address_sk and - ss_item_sk = i_item_sk and - ss_item_sk = sr_item_sk and - ss_ticket_number = sr_ticket_number and - ss_item_sk = cs_ui.cs_item_sk and - c_current_cdemo_sk = cd2.cd_demo_sk AND - c_current_hdemo_sk = hd2.hd_demo_sk AND - c_current_addr_sk = ad2.ca_address_sk and - c_first_sales_date_sk = d2.d_date_sk and - c_first_shipto_date_sk = d3.d_date_sk and - ss_promo_sk = p_promo_sk and - hd1.hd_income_band_sk = ib1.ib_income_band_sk and - hd2.hd_income_band_sk = ib2.ib_income_band_sk and - cd1.cd_marital_status <> cd2.cd_marital_status and - i_color in ('royal','wheat','dodger','rosy','linen','blanched') and - i_current_price between 25 and 25 + 10 and - i_current_price between 25 + 1 and 25 + 15 -group by i_product_name - ,i_item_sk - ,s_store_name - ,s_zip - ,ad1.ca_street_number - ,ad1.ca_street_name - ,ad1.ca_city - ,ad1.ca_zip - ,ad2.ca_street_number - ,ad2.ca_street_name - ,ad2.ca_city - ,ad2.ca_zip - ,d1.d_year - ,d2.d_year - ,d3.d_year -) -select cs1.product_name - ,cs1.store_name - ,cs1.store_zip - ,cs1.b_street_number - ,cs1.b_street_name - ,cs1.b_city - ,cs1.b_zip - ,cs1.c_street_number - ,cs1.c_street_name - ,cs1.c_city - ,cs1.c_zip - ,cs1.syear - ,cs1.cnt - ,cs1.s1 as s11 - ,cs1.s2 as s21 - ,cs1.s3 as s31 - ,cs2.s1 as s12 - ,cs2.s2 as s22 - ,cs2.s3 as s32 - ,cs2.syear - ,cs2.cnt -from cross_sales cs1,cross_sales cs2 -where cs1.item_sk=cs2.item_sk and - cs1.syear = 2000 and - cs2.syear = 2000 + 1 and - cs2.cnt <= cs1.cnt and - cs1.store_name = cs2.store_name and - cs1.store_zip = cs2.store_zip -order by cs1.product_name - ,cs1.store_name - ,cs2.cnt - ,cs1.s1 - ,cs2.s1; - --- end template query64.tpl query 33 in stream 10 --- start template query86a.tpl query 34 in stream 10 -with /* TPC-DS query86a.tpl 0.11 */ results as -( select sum(ws_net_paid) as total_sum, i_category, i_class, 0 as g_category, 0 as g_class - from - web_sales - ,date_dim d1 - ,item - where - d1.d_month_seq between 1223 and 1223+11 - and d1.d_date_sk = ws_sold_date_sk - and i_item_sk = ws_item_sk - group by i_category,i_class - ) , - - results_rollup as -( select total_sum ,i_category ,i_class, g_category, g_class, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum, i_category, NULL as i_class, 0 as g_category, 1 as g_class, 1 as lochierarchy from results group by i_category - union - select sum(total_sum) as total_sum, NULL as i_category, NULL as i_class, 1 as g_category, 1 as g_class, 2 as lochierarchy from results) - select - total_sum ,i_category ,i_class, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_class = 0 then i_category end - order by total_sum desc) as rank_within_parent - from - results_rollup - order by - lochierarchy desc, - case when lochierarchy = 0 then i_category end, - rank_within_parent - limit 100; - --- end template query86a.tpl query 34 in stream 10 --- start template query87.tpl query 35 in stream 10 -select /* TPC-DS query87.tpl 0.77 */ count(*) -from ((select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1178 and 1178+11) - except - (select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1178 and 1178+11) - except - (select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1178 and 1178+11) -) cool_cust -; - --- end template query87.tpl query 35 in stream 10 --- start template query28.tpl query 36 in stream 10 -select /* TPC-DS query28.tpl 0.36 */ * -from (select avg(ss_list_price) B1_LP - ,count(ss_list_price) B1_CNT - ,count(distinct ss_list_price) B1_CNTD - from store_sales - where ss_quantity between 0 and 5 - and (ss_list_price between 51 and 51+10 - or ss_coupon_amt between 17479 and 17479+1000 - or ss_wholesale_cost between 38 and 38+20)) B1, - (select avg(ss_list_price) B2_LP - ,count(ss_list_price) B2_CNT - ,count(distinct ss_list_price) B2_CNTD - from store_sales - where ss_quantity between 6 and 10 - and (ss_list_price between 89 and 89+10 - or ss_coupon_amt between 2269 and 2269+1000 - or ss_wholesale_cost between 67 and 67+20)) B2, - (select avg(ss_list_price) B3_LP - ,count(ss_list_price) B3_CNT - ,count(distinct ss_list_price) B3_CNTD - from store_sales - where ss_quantity between 11 and 15 - and (ss_list_price between 117 and 117+10 - or ss_coupon_amt between 9156 and 9156+1000 - or ss_wholesale_cost between 58 and 58+20)) B3, - (select avg(ss_list_price) B4_LP - ,count(ss_list_price) B4_CNT - ,count(distinct ss_list_price) B4_CNTD - from store_sales - where ss_quantity between 16 and 20 - and (ss_list_price between 161 and 161+10 - or ss_coupon_amt between 15135 and 15135+1000 - or ss_wholesale_cost between 46 and 46+20)) B4, - (select avg(ss_list_price) B5_LP - ,count(ss_list_price) B5_CNT - ,count(distinct ss_list_price) B5_CNTD - from store_sales - where ss_quantity between 21 and 25 - and (ss_list_price between 29 and 29+10 - or ss_coupon_amt between 2295 and 2295+1000 - or ss_wholesale_cost between 33 and 33+20)) B5, - (select avg(ss_list_price) B6_LP - ,count(ss_list_price) B6_CNT - ,count(distinct ss_list_price) B6_CNTD - from store_sales - where ss_quantity between 26 and 30 - and (ss_list_price between 114 and 114+10 - or ss_coupon_amt between 13004 and 13004+1000 - or ss_wholesale_cost between 49 and 49+20)) B6 -limit 100; - --- end template query28.tpl query 36 in stream 10 --- start template query55.tpl query 37 in stream 10 -select /* TPC-DS query55.tpl 0.82 */ i_brand_id brand_id, i_brand brand, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=88 - and d_moy=11 - and d_year=1999 - group by i_brand, i_brand_id - order by ext_price desc, i_brand_id -limit 100 ; - --- end template query55.tpl query 37 in stream 10 --- start template query85.tpl query 38 in stream 10 -select /* TPC-DS query85.tpl 0.33 */ substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) - from web_sales, web_returns, web_page, customer_demographics cd1, - customer_demographics cd2, customer_address, date_dim, reason - where ws_web_page_sk = wp_web_page_sk - and ws_item_sk = wr_item_sk - and ws_order_number = wr_order_number - and ws_sold_date_sk = d_date_sk and d_year = 2002 - and cd1.cd_demo_sk = wr_refunded_cdemo_sk - and cd2.cd_demo_sk = wr_returning_cdemo_sk - and ca_address_sk = wr_refunded_addr_sk - and r_reason_sk = wr_reason_sk - and - ( - ( - cd1.cd_marital_status = 'S' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = '2 yr Degree' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 100.00 and 150.00 - ) - or - ( - cd1.cd_marital_status = 'M' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Unknown' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 50.00 and 100.00 - ) - or - ( - cd1.cd_marital_status = 'D' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Primary' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ca_country = 'United States' - and - ca_state in ('WI', 'VA', 'LA') - and ws_net_profit between 100 and 200 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('PA', 'KS', 'WA') - and ws_net_profit between 150 and 300 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('TX', 'MS', 'OH') - and ws_net_profit between 50 and 250 - ) - ) -group by r_reason_desc -order by substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) -limit 100; - --- end template query85.tpl query 38 in stream 10 --- start template query38.tpl query 39 in stream 10 -select /* TPC-DS query38.tpl 0.54 */ count(*) from ( - select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1196 and 1196 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1196 and 1196 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1196 and 1196 + 11 -) hot_cust -limit 100; - --- end template query38.tpl query 39 in stream 10 --- start template query44.tpl query 40 in stream 10 -select /* TPC-DS query44.tpl 0.4 */ asceding.rnk, i1.i_product_name best_performing, i2.i_product_name worst_performing -from(select * - from (select item_sk,rank() over (order by rank_col asc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 630 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 630 - and ss_cdemo_sk is null - group by ss_store_sk))V1)V11 - where rnk < 11) asceding, - (select * - from (select item_sk,rank() over (order by rank_col desc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 630 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 630 - and ss_cdemo_sk is null - group by ss_store_sk))V2)V21 - where rnk < 11) descending, -item i1, -item i2 -where asceding.rnk = descending.rnk - and i1.i_item_sk=asceding.item_sk - and i2.i_item_sk=descending.item_sk -order by asceding.rnk -limit 100; - --- end template query44.tpl query 40 in stream 10 --- start template query27a.tpl query 41 in stream 10 -with /* TPC-DS query27a.tpl 0.16 */ results as - (select i_item_id, - s_state, 0 as g_state, - ss_quantity agg1, - ss_list_price agg2, - ss_coupon_amt agg3, - ss_sales_price agg4 - from store_sales, customer_demographics, date_dim, store, item - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_store_sk = s_store_sk and - ss_cdemo_sk = cd_demo_sk and - cd_gender = 'F' and - cd_marital_status = 'M' and - cd_education_status = 'Advanced Degree' and - d_year = 2000 and - s_state in ('TN','TX', 'CA', 'TN', 'WA', 'MI') - ) - - select i_item_id, - s_state, g_state, agg1, agg2, agg3, agg4 - from ( - select i_item_id, s_state, 0 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4 from results - group by i_item_id, s_state - union all - select i_item_id, NULL AS s_state, 1 AS g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as s_state, 1 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - ) foo - order by i_item_id, s_state - limit 100; - --- end template query27a.tpl query 41 in stream 10 --- start template query78.tpl query 42 in stream 10 -with /* TPC-DS query78.tpl 0.10 */ ws as - (select d_year AS ws_sold_year, ws_item_sk, - ws_bill_customer_sk ws_customer_sk, - sum(ws_quantity) ws_qty, - sum(ws_wholesale_cost) ws_wc, - sum(ws_sales_price) ws_sp - from web_sales - left join web_returns on wr_order_number=ws_order_number and ws_item_sk=wr_item_sk - join date_dim on ws_sold_date_sk = d_date_sk - where wr_order_number is null - group by d_year, ws_item_sk, ws_bill_customer_sk - ), -cs as - (select d_year AS cs_sold_year, cs_item_sk, - cs_bill_customer_sk cs_customer_sk, - sum(cs_quantity) cs_qty, - sum(cs_wholesale_cost) cs_wc, - sum(cs_sales_price) cs_sp - from catalog_sales - left join catalog_returns on cr_order_number=cs_order_number and cs_item_sk=cr_item_sk - join date_dim on cs_sold_date_sk = d_date_sk - where cr_order_number is null - group by d_year, cs_item_sk, cs_bill_customer_sk - ), -ss as - (select d_year AS ss_sold_year, ss_item_sk, - ss_customer_sk, - sum(ss_quantity) ss_qty, - sum(ss_wholesale_cost) ss_wc, - sum(ss_sales_price) ss_sp - from store_sales - left join store_returns on sr_ticket_number=ss_ticket_number and ss_item_sk=sr_item_sk - join date_dim on ss_sold_date_sk = d_date_sk - where sr_ticket_number is null - group by d_year, ss_item_sk, ss_customer_sk - ) - select -ss_item_sk, -round(ss_qty/(coalesce(ws_qty,0)+coalesce(cs_qty,0)),2) ratio, -ss_qty store_qty, ss_wc store_wholesale_cost, ss_sp store_sales_price, -coalesce(ws_qty,0)+coalesce(cs_qty,0) other_chan_qty, -coalesce(ws_wc,0)+coalesce(cs_wc,0) other_chan_wholesale_cost, -coalesce(ws_sp,0)+coalesce(cs_sp,0) other_chan_sales_price -from ss -left join ws on (ws_sold_year=ss_sold_year and ws_item_sk=ss_item_sk and ws_customer_sk=ss_customer_sk) -left join cs on (cs_sold_year=ss_sold_year and cs_item_sk=ss_item_sk and cs_customer_sk=ss_customer_sk) -where (coalesce(ws_qty,0)>0 or coalesce(cs_qty, 0)>0) and ss_sold_year=2001 -order by - ss_item_sk, - ss_qty desc, ss_wc desc, ss_sp desc, - other_chan_qty, - other_chan_wholesale_cost, - other_chan_sales_price, - ratio -limit 100; - --- end template query78.tpl query 42 in stream 10 --- start template query45.tpl query 43 in stream 10 -select /* TPC-DS query45.tpl 0.18 */ ca_zip, ca_county, sum(ws_sales_price) - from web_sales, customer, customer_address, date_dim, item - where ws_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ws_item_sk = i_item_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', '85392', '85460', '80348', '81792') - or - i_item_id in (select i_item_id - from item - where i_item_sk in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29) - ) - ) - and ws_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 2002 - group by ca_zip, ca_county - order by ca_zip, ca_county - limit 100; - --- end template query45.tpl query 43 in stream 10 --- start template query49.tpl query 44 in stream 10 -select /* TPC-DS query49.tpl 0.48 */ channel, item, return_ratio, return_rank, currency_rank from - (select - 'web' as channel - ,web.item - ,web.return_ratio - ,web.return_rank - ,web.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select ws.ws_item_sk as item - ,(cast(sum(coalesce(wr.wr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(wr.wr_return_amt,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - web_sales ws left outer join web_returns wr - on (ws.ws_order_number = wr.wr_order_number and - ws.ws_item_sk = wr.wr_item_sk) - ,date_dim - where - wr.wr_return_amt > 10000 - and ws.ws_net_profit > 1 - and ws.ws_net_paid > 0 - and ws.ws_quantity > 0 - and ws_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 12 - group by ws.ws_item_sk - ) in_web - ) web - where - ( - web.return_rank <= 10 - or - web.currency_rank <= 10 - ) - union - select - 'catalog' as channel - ,catalog.item - ,catalog.return_ratio - ,catalog.return_rank - ,catalog.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select - cs.cs_item_sk as item - ,(cast(sum(coalesce(cr.cr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(cr.cr_return_amount,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - catalog_sales cs left outer join catalog_returns cr - on (cs.cs_order_number = cr.cr_order_number and - cs.cs_item_sk = cr.cr_item_sk) - ,date_dim - where - cr.cr_return_amount > 10000 - and cs.cs_net_profit > 1 - and cs.cs_net_paid > 0 - and cs.cs_quantity > 0 - and cs_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 12 - group by cs.cs_item_sk - ) in_cat - ) catalog - where - ( - catalog.return_rank <= 10 - or - catalog.currency_rank <=10 - ) - union - select - 'store' as channel - ,store.item - ,store.return_ratio - ,store.return_rank - ,store.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select sts.ss_item_sk as item - ,(cast(sum(coalesce(sr.sr_return_quantity,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(sr.sr_return_amt,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - store_sales sts left outer join store_returns sr - on (sts.ss_ticket_number = sr.sr_ticket_number and sts.ss_item_sk = sr.sr_item_sk) - ,date_dim - where - sr.sr_return_amt > 10000 - and sts.ss_net_profit > 1 - and sts.ss_net_paid > 0 - and sts.ss_quantity > 0 - and ss_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 12 - group by sts.ss_item_sk - ) in_store - ) store - where ( - store.return_rank <= 10 - or - store.currency_rank <= 10 - ) - ) - order by 1,4,5,2 - limit 100; - --- end template query49.tpl query 44 in stream 10 --- start template query62.tpl query 45 in stream 10 -select /* TPC-DS query62.tpl 0.24 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 30) and - (ws_ship_date_sk - ws_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 60) and - (ws_ship_date_sk - ws_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 90) and - (ws_ship_date_sk - ws_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - web_sales - ,warehouse - ,ship_mode - ,web_site - ,date_dim -where - d_month_seq between 1220 and 1220 + 11 -and ws_ship_date_sk = d_date_sk -and ws_warehouse_sk = w_warehouse_sk -and ws_ship_mode_sk = sm_ship_mode_sk -and ws_web_site_sk = web_site_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -limit 100; - --- end template query62.tpl query 45 in stream 10 --- start template query59.tpl query 46 in stream 10 -with /* TPC-DS query59.tpl 0.30 */ wss as - (select d_week_seq, - ss_store_sk, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - group by d_week_seq,ss_store_sk - ) - select s_store_name1,s_store_id1,d_week_seq1 - ,sun_sales1/sun_sales2,mon_sales1/mon_sales2 - ,tue_sales1/tue_sales2,wed_sales1/wed_sales2,thu_sales1/thu_sales2 - ,fri_sales1/fri_sales2,sat_sales1/sat_sales2 - from - (select s_store_name s_store_name1,wss.d_week_seq d_week_seq1 - ,s_store_id s_store_id1,sun_sales sun_sales1 - ,mon_sales mon_sales1,tue_sales tue_sales1 - ,wed_sales wed_sales1,thu_sales thu_sales1 - ,fri_sales fri_sales1,sat_sales sat_sales1 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1207 and 1207 + 11) y, - (select s_store_name s_store_name2,wss.d_week_seq d_week_seq2 - ,s_store_id s_store_id2,sun_sales sun_sales2 - ,mon_sales mon_sales2,tue_sales tue_sales2 - ,wed_sales wed_sales2,thu_sales thu_sales2 - ,fri_sales fri_sales2,sat_sales sat_sales2 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1207+ 12 and 1207 + 23) x - where s_store_id1=s_store_id2 - and d_week_seq1=d_week_seq2-52 - order by s_store_name1,s_store_id1,d_week_seq1 -limit 100; - --- end template query59.tpl query 46 in stream 10 --- start template query77a.tpl query 47 in stream 10 -with /* TPC-DS query77a.tpl 0.78 */ ss as - (select s_store_sk, - sum(ss_ext_sales_price) as sales, - sum(ss_net_profit) as profit - from store_sales, - date_dim, - store - where ss_sold_date_sk = d_date_sk - and d_date between cast('2000-08-05' as date) - and dateadd(day,30,cast('2000-08-05' as date)) - and ss_store_sk = s_store_sk - group by s_store_sk) - , - sr as - (select s_store_sk, - sum(sr_return_amt) as returns, - sum(sr_net_loss) as profit_loss - from store_returns, - date_dim, - store - where sr_returned_date_sk = d_date_sk - and d_date between cast('2000-08-05' as date) - and dateadd(day,30,cast('2000-08-05' as date)) - and sr_store_sk = s_store_sk - group by s_store_sk), - cs as - (select cs_call_center_sk, - sum(cs_ext_sales_price) as sales, - sum(cs_net_profit) as profit - from catalog_sales, - date_dim - where cs_sold_date_sk = d_date_sk - and d_date between cast('2000-08-05' as date) - and dateadd(day,30,cast('2000-08-05' as date)) - group by cs_call_center_sk - ), - cr as - (select cr_call_center_sk, - sum(cr_return_amount) as returns, - sum(cr_net_loss) as profit_loss - from catalog_returns, - date_dim - where cr_returned_date_sk = d_date_sk - and d_date between cast('2000-08-05' as date) - and dateadd(day,30,cast('2000-08-05' as date)) - group by cr_call_center_sk), - ws as - ( select wp_web_page_sk, - sum(ws_ext_sales_price) as sales, - sum(ws_net_profit) as profit - from web_sales, - date_dim, - web_page - where ws_sold_date_sk = d_date_sk - and d_date between cast('2000-08-05' as date) - and dateadd(day,30,cast('2000-08-05' as date)) - and ws_web_page_sk = wp_web_page_sk - group by wp_web_page_sk), - wr as - (select wp_web_page_sk, - sum(wr_return_amt) as returns, - sum(wr_net_loss) as profit_loss - from web_returns, - date_dim, - web_page - where wr_returned_date_sk = d_date_sk - and d_date between cast('2000-08-05' as date) - and dateadd(day,30,cast('2000-08-05' as date)) - and wr_web_page_sk = wp_web_page_sk - group by wp_web_page_sk) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , ss.s_store_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ss left join sr - on ss.s_store_sk = sr.s_store_sk - union all - select 'catalog channel' as channel - , cs_call_center_sk as id - , sales - , returns - , (profit - profit_loss) as profit - from cs - , cr - union all - select 'web channel' as channel - , ws.wp_web_page_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ws left join wr - on ws.wp_web_page_sk = wr.wp_web_page_sk - ) x - group by channel, id ) - - select * - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results -) foo -order by channel, id - limit 100; - --- end template query77a.tpl query 47 in stream 10 --- start template query80a.tpl query 48 in stream 10 -with /* TPC-DS query80a.tpl 0.6 */ ssr as - (select s_store_id as store_id, - sum(ss_ext_sales_price) as sales, - sum(coalesce(sr_return_amt, 0)) as returns, - sum(ss_net_profit - coalesce(sr_net_loss, 0)) as profit - from store_sales left outer join store_returns on - (ss_item_sk = sr_item_sk and ss_ticket_number = sr_ticket_number), - date_dim, - store, - item, - promotion - where ss_sold_date_sk = d_date_sk - and d_date between cast('2000-08-29' as date) - and dateadd(day,30,cast('2000-08-29' as date)) - and ss_store_sk = s_store_sk - and ss_item_sk = i_item_sk - and i_current_price > 50 - and ss_promo_sk = p_promo_sk - and p_channel_tv = 'N' - group by s_store_id) - , - csr as - (select cp_catalog_page_id as catalog_page_id, - sum(cs_ext_sales_price) as sales, - sum(coalesce(cr_return_amount, 0)) as returns, - sum(cs_net_profit - coalesce(cr_net_loss, 0)) as profit - from catalog_sales left outer join catalog_returns on - (cs_item_sk = cr_item_sk and cs_order_number = cr_order_number), - date_dim, - catalog_page, - item, - promotion - where cs_sold_date_sk = d_date_sk - and d_date between cast('2000-08-29' as date) - and dateadd(day,30,cast('2000-08-29' as date)) - and cs_catalog_page_sk = cp_catalog_page_sk - and cs_item_sk = i_item_sk - and i_current_price > 50 - and cs_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(ws_ext_sales_price) as sales, - sum(coalesce(wr_return_amt, 0)) as returns, - sum(ws_net_profit - coalesce(wr_net_loss, 0)) as profit - from web_sales left outer join web_returns on - (ws_item_sk = wr_item_sk and ws_order_number = wr_order_number), - date_dim, - web_site, - item, - promotion - where ws_sold_date_sk = d_date_sk - and d_date between cast('2000-08-29' as date) - and dateadd(day,30,cast('2000-08-29' as date)) - and ws_web_site_sk = web_site_sk - and ws_item_sk = i_item_sk - and i_current_price > 50 - and ws_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by web_site_id) -, -results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || store_id as id - , sales - , returns - , profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || catalog_page_id as id - , sales - , returns - , profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , profit - from wsr - ) x - group by channel, id) - - select channel - , id - , sales - , returns - , profit - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results - ) foo - order by channel, id - limit 100; - --- end template query80a.tpl query 48 in stream 10 --- start template query84.tpl query 49 in stream 10 -select /* TPC-DS query84.tpl 0.80 */ c_customer_id as customer_id - , coalesce(c_last_name,'') || ', ' || coalesce(c_first_name,'') as customername - from customer - ,customer_address - ,customer_demographics - ,household_demographics - ,income_band - ,store_returns - where ca_city = 'Shiloh' - and c_current_addr_sk = ca_address_sk - and ib_lower_bound >= 4967 - and ib_upper_bound <= 4967 + 50000 - and ib_income_band_sk = hd_income_band_sk - and cd_demo_sk = c_current_cdemo_sk - and hd_demo_sk = c_current_hdemo_sk - and sr_cdemo_sk = cd_demo_sk - order by c_customer_id - limit 100; - --- end template query84.tpl query 49 in stream 10 --- start template query67a.tpl query 50 in stream 10 -with /* TPC-DS query67a.tpl 0.35 */ results as -( select i_category ,i_class ,i_brand ,i_product_name ,d_year ,d_qoy ,d_moy ,s_store_id - ,sum(coalesce(ss_sales_price*ss_quantity,0)) sumsales - from store_sales ,date_dim ,store ,item - where ss_sold_date_sk=d_date_sk - and ss_item_sk=i_item_sk - and ss_store_sk = s_store_sk - and d_month_seq between 1206 and 1206 + 11 - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy,s_store_id) - , - results_rollup as - (select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, s_store_id, sumsales - from results - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy - union all - select i_category, i_class, i_brand, i_product_name, d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year - union all - select i_category, i_class, i_brand, i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name - union all - select i_category, i_class, i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand - union all - select i_category, i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class - union all - select i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category - union all - select null i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results) - - select * -from (select i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rank() over (partition by i_category order by sumsales desc) rk - from results_rollup) dw2 -where rk <= 100 -order by i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rk -limit 100; - --- end template query67a.tpl query 50 in stream 10 --- start template query52.tpl query 51 in stream 10 -select /* TPC-DS query52.tpl 0.59 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_sales_price) ext_price - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=11 - and dt.d_year=2000 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,ext_price desc - ,brand_id -limit 100 ; - --- end template query52.tpl query 51 in stream 10 --- start template query76.tpl query 52 in stream 10 -select /* TPC-DS query76.tpl 0.99 */ channel, col_name, d_year, d_qoy, i_category, COUNT(*) sales_cnt, SUM(ext_sales_price) sales_amt FROM ( - SELECT 'store' as channel, 'ss_cdemo_sk' col_name, d_year, d_qoy, i_category, ss_ext_sales_price ext_sales_price - FROM store_sales, item, date_dim - WHERE ss_cdemo_sk IS NULL - AND ss_sold_date_sk=d_date_sk - AND ss_item_sk=i_item_sk - UNION ALL - SELECT 'web' as channel, 'ws_ship_customer_sk' col_name, d_year, d_qoy, i_category, ws_ext_sales_price ext_sales_price - FROM web_sales, item, date_dim - WHERE ws_ship_customer_sk IS NULL - AND ws_sold_date_sk=d_date_sk - AND ws_item_sk=i_item_sk - UNION ALL - SELECT 'catalog' as channel, 'cs_warehouse_sk' col_name, d_year, d_qoy, i_category, cs_ext_sales_price ext_sales_price - FROM catalog_sales, item, date_dim - WHERE cs_warehouse_sk IS NULL - AND cs_sold_date_sk=d_date_sk - AND cs_item_sk=i_item_sk) foo -GROUP BY channel, col_name, d_year, d_qoy, i_category -ORDER BY channel, col_name, d_year, d_qoy, i_category -limit 100; - --- end template query76.tpl query 52 in stream 10 --- start template query42.tpl query 53 in stream 10 -select /* TPC-DS query42.tpl 0.61 */ dt.d_year - ,item.i_category_id - ,item.i_category - ,sum(ss_ext_sales_price) - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=12 - and dt.d_year=1998 - group by dt.d_year - ,item.i_category_id - ,item.i_category - order by sum(ss_ext_sales_price) desc,dt.d_year - ,item.i_category_id - ,item.i_category -limit 100 ; - --- end template query42.tpl query 53 in stream 10 --- start template query33.tpl query 54 in stream 10 -with /* TPC-DS query33.tpl 0.22 */ ss as ( - select - i_manufact_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Jewelry')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 2 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_manufact_id), - cs as ( - select - i_manufact_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Jewelry')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 2 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_manufact_id), - ws as ( - select - i_manufact_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Jewelry')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 2 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_manufact_id) - select i_manufact_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_manufact_id - order by total_sales -limit 100; - --- end template query33.tpl query 54 in stream 10 --- start template query65.tpl query 55 in stream 10 -select /* TPC-DS query65.tpl 0.71 */ - s_store_name, - i_item_desc, - sc.revenue, - i_current_price, - i_wholesale_cost, - i_brand - from store, item, - (select ss_store_sk, avg(revenue) as ave - from - (select ss_store_sk, ss_item_sk, - sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1211 and 1211+11 - group by ss_store_sk, ss_item_sk) sa - group by ss_store_sk) sb, - (select ss_store_sk, ss_item_sk, sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1211 and 1211+11 - group by ss_store_sk, ss_item_sk) sc - where sb.ss_store_sk = sc.ss_store_sk and - sc.revenue <= 0.1 * sb.ave and - s_store_sk = sc.ss_store_sk and - i_item_sk = sc.ss_item_sk - order by s_store_name, i_item_desc -limit 100; - --- end template query65.tpl query 55 in stream 10 --- start template query23.tpl query 56 in stream 10 -with /* TPC-DS query23.tpl 0.68 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (2000,2000+1,2000+2,2000+3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (2000,2000+1,2000+2,2000+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * -from - max_store_sales)) - select sum(sales) - from (select cs_quantity*cs_list_price sales - from catalog_sales - ,date_dim - where d_year = 2000 - and d_moy = 7 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - union all - select ws_quantity*ws_list_price sales - from web_sales - ,date_dim - where d_year = 2000 - and d_moy = 7 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer)) - limit 100; -with /* TPC-DS query23.tpl 0.68 part2 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (2000,2000 + 1,2000 + 2,2000 + 3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (2000,2000+1,2000+2,2000+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * - from max_store_sales)) - select c_last_name,c_first_name,sales - from (select c_last_name,c_first_name,sum(cs_quantity*cs_list_price) sales - from catalog_sales - ,customer - ,date_dim - where d_year = 2000 - and d_moy = 7 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and cs_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name - union all - select c_last_name,c_first_name,sum(ws_quantity*ws_list_price) sales - from web_sales - ,customer - ,date_dim - where d_year = 2000 - and d_moy = 7 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and ws_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name) - order by c_last_name,c_first_name,sales - limit 100; - --- end template query23.tpl query 56 in stream 10 --- start template query90.tpl query 57 in stream 10 -select /* TPC-DS query90.tpl 0.40 */ cast(amc as decimal(15,4))/cast(pmc as decimal(15,4)) am_pm_ratio - from ( select count(*) amc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 6 and 6+1 - and household_demographics.hd_dep_count = 2 - and web_page.wp_char_count between 5000 and 5200) at, - ( select count(*) pmc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 16 and 16+1 - and household_demographics.hd_dep_count = 2 - and web_page.wp_char_count between 5000 and 5200) pt - order by am_pm_ratio - limit 100; - --- end template query90.tpl query 57 in stream 10 --- start template query88.tpl query 58 in stream 10 -select /* TPC-DS query88.tpl 0.66 */ * -from - (select count(*) h8_30_to_9 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s1, - (select count(*) h9_to_9_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s2, - (select count(*) h9_30_to_10 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s3, - (select count(*) h10_to_10_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s4, - (select count(*) h10_30_to_11 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s5, - (select count(*) h11_to_11_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s6, - (select count(*) h11_30_to_12 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s7, - (select count(*) h12_to_12_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 12 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s8 -; - --- end template query88.tpl query 58 in stream 10 --- start template query99.tpl query 59 in stream 10 -select /* TPC-DS query99.tpl 0.94 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 30) and - (cs_ship_date_sk - cs_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 60) and - (cs_ship_date_sk - cs_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 90) and - (cs_ship_date_sk - cs_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - catalog_sales - ,warehouse - ,ship_mode - ,call_center - ,date_dim -where - d_month_seq between 1204 and 1204 + 11 -and cs_ship_date_sk = d_date_sk -and cs_warehouse_sk = w_warehouse_sk -and cs_ship_mode_sk = sm_ship_mode_sk -and cs_call_center_sk = cc_call_center_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -limit 100; - --- end template query99.tpl query 59 in stream 10 --- start template query35a.tpl query 60 in stream 10 -select /* TPC-DS query35a.tpl 0.47 */ - ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - count(*) cnt1, - max(cd_dep_count), - sum(cd_dep_count), - stddev_samp(cd_dep_count), - cd_dep_employed_count, - count(*) cnt2, - max(cd_dep_employed_count), - sum(cd_dep_employed_count), - stddev_samp(cd_dep_employed_count), - cd_dep_college_count, - count(*) cnt3, - max(cd_dep_college_count), - sum(cd_dep_college_count), - stddev_samp(cd_dep_college_count) - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2001 and - d_qoy < 4) and - exists (select * from - (select ws_bill_customer_sk customsk - from web_sales,date_dim - where - ws_sold_date_sk = d_date_sk and - d_year = 2001 and - d_qoy < 4 - union all - select cs_ship_customer_sk customsk - from catalog_sales,date_dim - where - cs_sold_date_sk = d_date_sk and - d_year = 2001 and - d_qoy < 4)x - where x.customsk = c.c_customer_sk) - group by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - limit 100; - --- end template query35a.tpl query 60 in stream 10 --- start template query10.tpl query 61 in stream 10 -select /* TPC-DS query10.tpl 0.26 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3, - cd_dep_count, - count(*) cnt4, - cd_dep_employed_count, - count(*) cnt5, - cd_dep_college_count, - count(*) cnt6 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_county in ('Eaton County','DeKalb County','Berkeley County','Miller County','Spokane County') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 4 and 4+3) and - (exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 4 ANd 4+3) or - exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 4 and 4+3)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count -limit 100; - --- end template query10.tpl query 61 in stream 10 --- start template query16.tpl query 62 in stream 10 -select /* TPC-DS query16.tpl 0.25 */ - count(distinct cs_order_number) as "order count" - ,sum(cs_ext_ship_cost) as "total shipping cost" - ,sum(cs_net_profit) as "total net profit" -from - catalog_sales cs1 - ,date_dim - ,customer_address - ,call_center -where - d_date between '1999-4-01' and - dateadd(day, 60, cast('1999-4-01' as date)) -and cs1.cs_ship_date_sk = d_date_sk -and cs1.cs_ship_addr_sk = ca_address_sk -and ca_state = 'LA' -and cs1.cs_call_center_sk = cc_call_center_sk -and cc_county in ('Ziebach County','Raleigh County','Fairfield County','Perry County', - 'Wadena County' -) -and exists (select * - from catalog_sales cs2 - where cs1.cs_order_number = cs2.cs_order_number - and cs1.cs_warehouse_sk <> cs2.cs_warehouse_sk) -and not exists(select * - from catalog_returns cr1 - where cs1.cs_order_number = cr1.cr_order_number) -order by count(distinct cs_order_number) -limit 100; - --- end template query16.tpl query 62 in stream 10 --- start template query5a.tpl query 63 in stream 10 -with /* TPC-DS query5a.tpl 0.98 */ ssr as - (select s_store_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ss_store_sk as store_sk, - ss_sold_date_sk as date_sk, - ss_ext_sales_price as sales_price, - ss_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from store_sales - union all - select sr_store_sk as store_sk, - sr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - sr_return_amt as return_amt, - sr_net_loss as net_loss - from store_returns - ) salesreturns, - date_dim, - store - where date_sk = d_date_sk - and d_date between cast('2002-08-29' as date) - and dateadd(day,14,cast('2002-08-29' as date)) - and store_sk = s_store_sk - group by s_store_id) - , - csr as - (select cp_catalog_page_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select cs_catalog_page_sk as page_sk, - cs_sold_date_sk as date_sk, - cs_ext_sales_price as sales_price, - cs_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from catalog_sales - union all - select cr_catalog_page_sk as page_sk, - cr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - cr_return_amount as return_amt, - cr_net_loss as net_loss - from catalog_returns - ) salesreturns, - date_dim, - catalog_page - where date_sk = d_date_sk - and d_date between cast('2002-08-29' as date) - and dateadd(day,14,cast('2002-08-29' as date)) - and page_sk = cp_catalog_page_sk - group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ws_web_site_sk as wsr_web_site_sk, - ws_sold_date_sk as date_sk, - ws_ext_sales_price as sales_price, - ws_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from web_sales - union all - select ws_web_site_sk as wsr_web_site_sk, - wr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - wr_return_amt as return_amt, - wr_net_loss as net_loss - from web_returns left outer join web_sales on - ( wr_item_sk = ws_item_sk - and wr_order_number = ws_order_number) - ) salesreturns, - date_dim, - web_site - where date_sk = d_date_sk - and d_date between cast('2002-08-29' as date) - and dateadd(day,14,cast('2002-08-29' as date)) - and wsr_web_site_sk = web_site_sk - group by web_site_id) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || s_store_id as id - , sales - , returns - , (profit - profit_loss) as profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || cp_catalog_page_id as id - , sales - , returns - , (profit - profit_loss) as profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , (profit - profit_loss) as profit - from wsr - ) x - group by channel, id) - select channel, id, sales, returns, profit from ( - select channel, id, sales, returns, profit from results - union - select channel, null as id, sum(sales), sum(returns), sum(profit) from results group by channel - union - select null as channel, null as id, sum(sales), sum(returns), sum(profit) from results) foo -order by channel, id -limit 100; - --- end template query5a.tpl query 63 in stream 10 --- start template query57.tpl query 64 in stream 10 -with /* TPC-DS query57.tpl 0.70 */ v1 as( - select i_category, i_brand, - cc_name, - d_year, d_moy, - sum(cs_sales_price) sum_sales, - avg(sum(cs_sales_price)) over - (partition by i_category, i_brand, - cc_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - cc_name - order by d_year, d_moy) rn - from item, catalog_sales, date_dim, call_center - where cs_item_sk = i_item_sk and - cs_sold_date_sk = d_date_sk and - cc_call_center_sk= cs_call_center_sk and - ( - d_year = 1999 or - ( d_year = 1999-1 and d_moy =12) or - ( d_year = 1999+1 and d_moy =1) - ) - group by i_category, i_brand, - cc_name , d_year, d_moy), - v2 as( - select v1.i_brand - ,v1.d_year, v1.d_moy - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1. cc_name = v1_lag. cc_name and - v1. cc_name = v1_lead. cc_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 1999 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, psum - limit 100; - --- end template query57.tpl query 64 in stream 10 --- start template query34.tpl query 65 in stream 10 -select /* TPC-DS query34.tpl 0.73 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (date_dim.d_dom between 1 and 3 or date_dim.d_dom between 25 and 28) - and (household_demographics.hd_buy_potential = '>10000' or - household_demographics.hd_buy_potential = '5001-10000') - and household_demographics.hd_vehicle_count > 0 - and (case when household_demographics.hd_vehicle_count > 0 - then household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count - else null - end) > 1.2 - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_county in ('Schley County','Allen County','Pulaski County','Tompkins County', - 'Tehama County','Conecuh County','Rush County','Richland County') - group by ss_ticket_number,ss_customer_sk) dn,customer - where ss_customer_sk = c_customer_sk - and cnt between 15 and 20 - order by c_last_name,c_first_name,c_salutation,c_preferred_cust_flag desc, ss_ticket_number; - --- end template query34.tpl query 65 in stream 10 --- start template query97.tpl query 66 in stream 10 -with /* TPC-DS query97.tpl 0.38 */ ssci as ( -select ss_customer_sk customer_sk - ,ss_item_sk item_sk -from store_sales,date_dim -where ss_sold_date_sk = d_date_sk - and d_month_seq between 1209 and 1209 + 11 -group by ss_customer_sk - ,ss_item_sk), -csci as( - select cs_bill_customer_sk customer_sk - ,cs_item_sk item_sk -from catalog_sales,date_dim -where cs_sold_date_sk = d_date_sk - and d_month_seq between 1209 and 1209 + 11 -group by cs_bill_customer_sk - ,cs_item_sk) - select sum(case when ssci.customer_sk is not null and csci.customer_sk is null then 1 else 0 end) store_only - ,sum(case when ssci.customer_sk is null and csci.customer_sk is not null then 1 else 0 end) catalog_only - ,sum(case when ssci.customer_sk is not null and csci.customer_sk is not null then 1 else 0 end) store_and_catalog -from ssci full outer join csci on (ssci.customer_sk=csci.customer_sk - and ssci.item_sk = csci.item_sk) -limit 100; - --- end template query97.tpl query 66 in stream 10 --- start template query72.tpl query 67 in stream 10 -select /* TPC-DS query72.tpl 0.87 */ i_item_desc - ,w_warehouse_name - ,d1.d_week_seq - ,sum(case when p_promo_sk is null then 1 else 0 end) no_promo - ,sum(case when p_promo_sk is not null then 1 else 0 end) promo - ,count(*) total_cnt -from catalog_sales -join inventory on (cs_item_sk = inv_item_sk) -join warehouse on (w_warehouse_sk=inv_warehouse_sk) -join item on (i_item_sk = cs_item_sk) -join customer_demographics on (cs_bill_cdemo_sk = cd_demo_sk) -join household_demographics on (cs_bill_hdemo_sk = hd_demo_sk) -join date_dim d1 on (cs_sold_date_sk = d1.d_date_sk) -join date_dim d2 on (inv_date_sk = d2.d_date_sk) -join date_dim d3 on (cs_ship_date_sk = d3.d_date_sk) -left outer join promotion on (cs_promo_sk=p_promo_sk) -left outer join catalog_returns on (cr_item_sk = cs_item_sk and cr_order_number = cs_order_number) -where d1.d_week_seq = d2.d_week_seq - and inv_quantity_on_hand < cs_quantity - and d3.d_date > d1.d_date + 5 - and hd_buy_potential = '1001-5000' - and d1.d_year = 1999 - and cd_marital_status = 'W' -group by i_item_desc,w_warehouse_name,d1.d_week_seq -order by total_cnt desc, i_item_desc, w_warehouse_name, d_week_seq -limit 100; - --- end template query72.tpl query 67 in stream 10 --- start template query75.tpl query 68 in stream 10 -WITH /* TPC-DS query75.tpl 0.3 */ all_sales AS ( - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,SUM(sales_cnt) AS sales_cnt - ,SUM(sales_amt) AS sales_amt - FROM (SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,cs_quantity - COALESCE(cr_return_quantity,0) AS sales_cnt - ,cs_ext_sales_price - COALESCE(cr_return_amount,0.0) AS sales_amt - FROM catalog_sales JOIN item ON i_item_sk=cs_item_sk - JOIN date_dim ON d_date_sk=cs_sold_date_sk - LEFT JOIN catalog_returns ON (cs_order_number=cr_order_number - AND cs_item_sk=cr_item_sk) - WHERE i_category='Men' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ss_quantity - COALESCE(sr_return_quantity,0) AS sales_cnt - ,ss_ext_sales_price - COALESCE(sr_return_amt,0.0) AS sales_amt - FROM store_sales JOIN item ON i_item_sk=ss_item_sk - JOIN date_dim ON d_date_sk=ss_sold_date_sk - LEFT JOIN store_returns ON (ss_ticket_number=sr_ticket_number - AND ss_item_sk=sr_item_sk) - WHERE i_category='Men' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ws_quantity - COALESCE(wr_return_quantity,0) AS sales_cnt - ,ws_ext_sales_price - COALESCE(wr_return_amt,0.0) AS sales_amt - FROM web_sales JOIN item ON i_item_sk=ws_item_sk - JOIN date_dim ON d_date_sk=ws_sold_date_sk - LEFT JOIN web_returns ON (ws_order_number=wr_order_number - AND ws_item_sk=wr_item_sk) - WHERE i_category='Men') sales_detail - GROUP BY d_year, i_brand_id, i_class_id, i_category_id, i_manufact_id) - SELECT prev_yr.d_year AS prev_year - ,curr_yr.d_year AS year - ,curr_yr.i_brand_id - ,curr_yr.i_class_id - ,curr_yr.i_category_id - ,curr_yr.i_manufact_id - ,prev_yr.sales_cnt AS prev_yr_cnt - ,curr_yr.sales_cnt AS curr_yr_cnt - ,curr_yr.sales_cnt-prev_yr.sales_cnt AS sales_cnt_diff - ,curr_yr.sales_amt-prev_yr.sales_amt AS sales_amt_diff - FROM all_sales curr_yr, all_sales prev_yr - WHERE curr_yr.i_brand_id=prev_yr.i_brand_id - AND curr_yr.i_class_id=prev_yr.i_class_id - AND curr_yr.i_category_id=prev_yr.i_category_id - AND curr_yr.i_manufact_id=prev_yr.i_manufact_id - AND curr_yr.d_year=2001 - AND prev_yr.d_year=2001-1 - AND CAST(curr_yr.sales_cnt AS DECIMAL(17,2))/CAST(prev_yr.sales_cnt AS DECIMAL(17,2))<0.9 - ORDER BY sales_cnt_diff,sales_amt_diff - limit 100; - --- end template query75.tpl query 68 in stream 10 --- start template query14a.tpl query 69 in stream 10 -with /* TPC-DS query14a.tpl 0.69 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1998 AND 1998 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1998 AND 1998 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1998 AND 1998 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as - (select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2) x) -, - results AS -(select channel, i_brand_id, i_class_id, i_category_id, sum(sales) sum_sales, sum(number_sales) number_sales - from ( - select 'store' channel, i_brand_id,i_class_id - ,i_category_id,sum(ss_quantity*ss_list_price) sales - , count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1998+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales) - union all - select 'catalog' channel, i_brand_id,i_class_id,i_category_id, sum(cs_quantity*cs_list_price) sales, count(*) number_sales - from catalog_sales - ,item - ,date_dim - where cs_item_sk in (select ss_item_sk from cross_items) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1998+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(cs_quantity*cs_list_price) > (select average_sales from avg_sales) - union all - select 'web' channel, i_brand_id,i_class_id,i_category_id, sum(ws_quantity*ws_list_price) sales , count(*) number_sales - from web_sales - ,item - ,date_dim - where ws_item_sk in (select ss_item_sk from cross_items) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1998+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ws_quantity*ws_list_price) > (select average_sales from avg_sales) - ) y - group by channel, i_brand_id,i_class_id,i_category_id) - - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales -from ( - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales from results - union - select channel, i_brand_id, i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id, i_class_id - union - select channel, i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id - union - select channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel - union - select null as channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results) z -order by channel, i_brand_id, i_class_id, i_category_id - limit 100; -with /* TPC-DS query14a.tpl 0.69 part2 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1998 AND 1998 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1998 AND 1998 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1998 AND 1998 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as -(select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2) x) - select this_year.channel ty_channel - ,this_year.i_brand_id ty_brand - ,this_year.i_class_id ty_class - ,this_year.i_category_id ty_category - ,this_year.sales ty_sales - ,this_year.number_sales ty_number_sales - ,last_year.channel ly_channel - ,last_year.i_brand_id ly_brand - ,last_year.i_class_id ly_class - ,last_year.i_category_id ly_category - ,last_year.sales ly_sales - ,last_year.number_sales ly_number_sales -from - (select 'store' channel, i_brand_id,i_class_id,i_category_id - ,sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1998 + 1 - and d_moy = 12 - and d_dom = 28) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) this_year, - (select 'store' channel, i_brand_id,i_class_id - ,i_category_id, sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1998 - and d_moy = 12 - and d_dom = 28) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) last_year - where this_year.i_brand_id= last_year.i_brand_id - and this_year.i_class_id = last_year.i_class_id - and this_year.i_category_id = last_year.i_category_id - order by this_year.channel, this_year.i_brand_id, this_year.i_class_id, this_year.i_category_id - limit 100; - --- end template query14a.tpl query 69 in stream 10 --- start template query40.tpl query 70 in stream 10 -select /* TPC-DS query40.tpl 0.86 */ - w_state - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('2000-04-19' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_before - ,sum(case when (cast(d_date as date) >= cast ('2000-04-19' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_after - from - catalog_sales left outer join catalog_returns on - (cs_order_number = cr_order_number - and cs_item_sk = cr_item_sk) - ,warehouse - ,item - ,date_dim - where - i_current_price between 0.99 and 1.49 - and i_item_sk = cs_item_sk - and cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('2000-04-19' as date)) - and dateadd(day,30,cast ('2000-04-19' as date)) - group by - w_state,i_item_id - order by w_state,i_item_id -limit 100; - --- end template query40.tpl query 70 in stream 10 --- start template query73.tpl query 71 in stream 10 -select /* TPC-DS query73.tpl 0.79 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_buy_potential = '1001-5000' or - household_demographics.hd_buy_potential = '0-500') - and household_demographics.hd_vehicle_count > 0 - and case when household_demographics.hd_vehicle_count > 0 then - household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count else null end > 1 - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_county in ('Dutchess County','Jack County','Wadena County','Itawamba County') - group by ss_ticket_number,ss_customer_sk) dj,customer - where ss_customer_sk = c_customer_sk - and cnt between 1 and 5 - order by cnt desc, c_last_name asc; - --- end template query73.tpl query 71 in stream 10 --- start template query79.tpl query 72 in stream 10 -select /* TPC-DS query79.tpl 0.89 */ - c_last_name,c_first_name,substring(s_city,1,30),ss_ticket_number,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,store.s_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (household_demographics.hd_dep_count = 6 or household_demographics.hd_vehicle_count > -1) - and date_dim.d_dow = 1 - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_number_employees between 200 and 295 - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,store.s_city) ms,customer - where ss_customer_sk = c_customer_sk - order by c_last_name,c_first_name,substring(s_city,1,30), profit -limit 100; - --- end template query79.tpl query 72 in stream 10 --- start template query11.tpl query 73 in stream 10 -with /* TPC-DS query11.tpl 0.51 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ss_ext_list_price-ss_ext_discount_amt) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ws_ext_list_price-ws_ext_discount_amt) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_email_address - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 1998 - and t_s_secyear.dyear = 1998+1 - and t_w_firstyear.dyear = 1998 - and t_w_secyear.dyear = 1998+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else 0.0 end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else 0.0 end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_email_address -limit 100; - --- end template query11.tpl query 73 in stream 10 --- start template query6.tpl query 74 in stream 10 -select /* TPC-DS query6.tpl 0.58 */ a.ca_state state, count(*) cnt - from customer_address a - ,customer c - ,store_sales s - ,date_dim d - ,item i - where a.ca_address_sk = c.c_current_addr_sk - and c.c_customer_sk = s.ss_customer_sk - and s.ss_sold_date_sk = d.d_date_sk - and s.ss_item_sk = i.i_item_sk - and d.d_month_seq = - (select distinct (d_month_seq) - from date_dim - where d_year = 1998 - and d_moy = 5 ) - and i.i_current_price > 1.2 * - (select avg(j.i_current_price) - from item j - where j.i_category = i.i_category) - group by a.ca_state - having count(*) >= 10 - order by cnt, a.ca_state - limit 100; - --- end template query6.tpl query 74 in stream 10 --- start template query17.tpl query 75 in stream 10 -select /* TPC-DS query17.tpl 0.41 */ i_item_id - ,i_item_desc - ,s_state - ,count(ss_quantity) as store_sales_quantitycount - ,avg(ss_quantity) as store_sales_quantityave - ,stddev_samp(ss_quantity) as store_sales_quantitystdev - ,stddev_samp(ss_quantity)/avg(ss_quantity) as store_sales_quantitycov - ,count(sr_return_quantity) as store_returns_quantitycount - ,avg(sr_return_quantity) as store_returns_quantityave - ,stddev_samp(sr_return_quantity) as store_returns_quantitystdev - ,stddev_samp(sr_return_quantity)/avg(sr_return_quantity) as store_returns_quantitycov - ,count(cs_quantity) as catalog_sales_quantitycount ,avg(cs_quantity) as catalog_sales_quantityave - ,stddev_samp(cs_quantity) as catalog_sales_quantitystdev - ,stddev_samp(cs_quantity)/avg(cs_quantity) as catalog_sales_quantitycov - from store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where d1.d_quarter_name = '1999Q1' - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_quarter_name in ('1999Q1','1999Q2','1999Q3') - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_quarter_name in ('1999Q1','1999Q2','1999Q3') - group by i_item_id - ,i_item_desc - ,s_state - order by i_item_id - ,i_item_desc - ,s_state -limit 100; - --- end template query17.tpl query 75 in stream 10 --- start template query58.tpl query 76 in stream 10 -with /* TPC-DS query58.tpl 0.19 */ ss_items as - (select i_item_id item_id - ,sum(ss_ext_sales_price) ss_item_rev - from store_sales - ,item - ,date_dim - where ss_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '2002-06-22')) - and ss_sold_date_sk = d_date_sk - group by i_item_id), - cs_items as - (select i_item_id item_id - ,sum(cs_ext_sales_price) cs_item_rev - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '2002-06-22')) - and cs_sold_date_sk = d_date_sk - group by i_item_id), - ws_items as - (select i_item_id item_id - ,sum(ws_ext_sales_price) ws_item_rev - from web_sales - ,item - ,date_dim - where ws_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq =(select d_week_seq - from date_dim - where d_date = '2002-06-22')) - and ws_sold_date_sk = d_date_sk - group by i_item_id) - select ss_items.item_id - ,ss_item_rev - ,ss_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ss_dev - ,cs_item_rev - ,cs_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 cs_dev - ,ws_item_rev - ,ws_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ws_dev - ,(ss_item_rev+cs_item_rev+ws_item_rev)/3 average - from ss_items,cs_items,ws_items - where ss_items.item_id=cs_items.item_id - and ss_items.item_id=ws_items.item_id - and ss_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - and ss_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and cs_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and cs_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and ws_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and ws_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - order by item_id - ,ss_item_rev - limit 100; - --- end template query58.tpl query 76 in stream 10 --- start template query56.tpl query 77 in stream 10 -with /* TPC-DS query56.tpl 0.83 */ ss as ( - select i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where i_item_id in (select - i_item_id -from item -where i_color in ('lime','slate','lawn')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 4 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id), - cs as ( - select i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('lime','slate','lawn')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 4 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id), - ws as ( - select i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('lime','slate','lawn')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 4 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id) - select i_item_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by total_sales, - i_item_id - limit 100; - --- end template query56.tpl query 77 in stream 10 --- start template query83.tpl query 78 in stream 10 -with /* TPC-DS query83.tpl 0.96 */ sr_items as - (select i_item_id item_id, - sum(sr_return_quantity) sr_item_qty - from store_returns, - item, - date_dim - where sr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('1999-05-13','1999-10-01','1999-11-02'))) - and sr_returned_date_sk = d_date_sk - group by i_item_id), - cr_items as - (select i_item_id item_id, - sum(cr_return_quantity) cr_item_qty - from catalog_returns, - item, - date_dim - where cr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('1999-05-13','1999-10-01','1999-11-02'))) - and cr_returned_date_sk = d_date_sk - group by i_item_id), - wr_items as - (select i_item_id item_id, - sum(wr_return_quantity) wr_item_qty - from web_returns, - item, - date_dim - where wr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('1999-05-13','1999-10-01','1999-11-02'))) - and wr_returned_date_sk = d_date_sk - group by i_item_id) - select sr_items.item_id - ,sr_item_qty - ,sr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 sr_dev - ,cr_item_qty - ,cr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 cr_dev - ,wr_item_qty - ,wr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 wr_dev - ,(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 average - from sr_items - ,cr_items - ,wr_items - where sr_items.item_id=cr_items.item_id - and sr_items.item_id=wr_items.item_id - order by sr_items.item_id - ,sr_item_qty - limit 100; - --- end template query83.tpl query 78 in stream 10 --- start template query51.tpl query 79 in stream 10 -WITH /* TPC-DS query51.tpl 0.46 */ web_v1 as ( -select - ws_item_sk item_sk, d_date, - sum(sum(ws_sales_price)) - over (partition by ws_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from web_sales - ,date_dim -where ws_sold_date_sk=d_date_sk - and d_month_seq between 1178 and 1178+11 - and ws_item_sk is not NULL -group by ws_item_sk, d_date), -store_v1 as ( -select - ss_item_sk item_sk, d_date, - sum(sum(ss_sales_price)) - over (partition by ss_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from store_sales - ,date_dim -where ss_sold_date_sk=d_date_sk - and d_month_seq between 1178 and 1178+11 - and ss_item_sk is not NULL -group by ss_item_sk, d_date) - select * -from (select item_sk - ,d_date - ,web_sales - ,store_sales - ,max(web_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) web_cumulative - ,max(store_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) store_cumulative - from (select case when web.item_sk is not null then web.item_sk else store.item_sk end item_sk - ,case when web.d_date is not null then web.d_date else store.d_date end d_date - ,web.cume_sales web_sales - ,store.cume_sales store_sales - from web_v1 web full outer join store_v1 store on (web.item_sk = store.item_sk - and web.d_date = store.d_date) - )x )y -where web_cumulative > store_cumulative -order by item_sk - ,d_date -limit 100; - --- end template query51.tpl query 79 in stream 10 --- start template query29.tpl query 80 in stream 10 -select /* TPC-DS query29.tpl 0.53 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,max(ss_quantity) as store_sales_quantity - ,max(sr_return_quantity) as store_returns_quantity - ,max(cs_quantity) as catalog_sales_quantity - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 1998 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 4 + 3 - and d2.d_year = 1998 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_year in (1998,1998+1,1998+2) - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query29.tpl query 80 in stream 10 --- start template query22a.tpl query 81 in stream 10 -with /* TPC-DS query22a.tpl 0.55 */ results as -(select i_product_name - ,i_brand - ,i_class - ,i_category - ,avg(inv_quantity_on_hand) qoh - from inventory - ,date_dim - ,item --- ,warehouse - where inv_date_sk=d_date_sk - and inv_item_sk=i_item_sk --- and inv_warehouse_sk = w_warehouse_sk - and d_month_seq between 1215 and 1215 + 11 - group by i_product_name,i_brand,i_class,i_category), -results_rollup as -(select i_product_name, i_brand, i_class, i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class,i_category -union all -select i_product_name, i_brand, i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class -union all -select i_product_name, i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand -union all -select i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name -union all -select null i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results) - select i_product_name, i_brand, i_class, i_category,qoh - from results_rollup - order by qoh, i_product_name, i_brand, i_class, i_category -limit 100; - --- end template query22a.tpl query 81 in stream 10 --- start template query71.tpl query 82 in stream 10 -select /* TPC-DS query71.tpl 0.72 */ i_brand_id brand_id, i_brand brand,t_hour,t_minute, - sum(ext_price) ext_price - from item, (select ws_ext_sales_price as ext_price, - ws_sold_date_sk as sold_date_sk, - ws_item_sk as sold_item_sk, - ws_sold_time_sk as time_sk - from web_sales,date_dim - where d_date_sk = ws_sold_date_sk - and d_moy=11 - and d_year=2002 - union all - select cs_ext_sales_price as ext_price, - cs_sold_date_sk as sold_date_sk, - cs_item_sk as sold_item_sk, - cs_sold_time_sk as time_sk - from catalog_sales,date_dim - where d_date_sk = cs_sold_date_sk - and d_moy=11 - and d_year=2002 - union all - select ss_ext_sales_price as ext_price, - ss_sold_date_sk as sold_date_sk, - ss_item_sk as sold_item_sk, - ss_sold_time_sk as time_sk - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - and d_moy=11 - and d_year=2002 - ) tmp,time_dim - where - sold_item_sk = i_item_sk - and i_manager_id=1 - and time_sk = t_time_sk - and (t_meal_time = 'breakfast' or t_meal_time = 'dinner') - group by i_brand, i_brand_id,t_hour,t_minute - order by ext_price desc, i_brand_id - ; - --- end template query71.tpl query 82 in stream 10 --- start template query68.tpl query 83 in stream 10 -select /* TPC-DS query68.tpl 0.95 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,extended_price - ,extended_tax - ,list_price - from (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_ext_sales_price) extended_price - ,sum(ss_ext_list_price) list_price - ,sum(ss_ext_tax) extended_tax - from store_sales - ,date_dim - ,store - ,household_demographics - ,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_dep_count = 5 or - household_demographics.hd_vehicle_count= 3) - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_city in ('Five Points','Concord') - group by ss_ticket_number - ,ss_customer_sk - ,ss_addr_sk,ca_city) dn - ,customer - ,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,ss_ticket_number - limit 100; - --- end template query68.tpl query 83 in stream 10 --- start template query60.tpl query 84 in stream 10 -with /* TPC-DS query60.tpl 0.29 */ ss as ( - select - i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Shoes')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 9 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - cs as ( - select - i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Shoes')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 9 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - ws as ( - select - i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Shoes')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 9 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id) - select - i_item_id -,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by i_item_id - ,total_sales - limit 100; - --- end template query60.tpl query 84 in stream 10 --- start template query12.tpl query 85 in stream 10 -select /* TPC-DS query12.tpl 0.64 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ws_ext_sales_price) as itemrevenue - ,sum(ws_ext_sales_price)*100/sum(sum(ws_ext_sales_price)) over - (partition by i_class) as revenueratio -from - web_sales - ,item - ,date_dim -where - ws_item_sk = i_item_sk - and i_category in ('Women', 'Home', 'Music') - and ws_sold_date_sk = d_date_sk - and d_date between cast('2001-02-18' as date) - and dateadd(day,30,cast('2001-02-18' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query12.tpl query 85 in stream 10 --- start template query4.tpl query 86 in stream 10 -with /* TPC-DS query4.tpl 0.93 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(((ss_ext_list_price-ss_ext_wholesale_cost-ss_ext_discount_amt)+ss_ext_sales_price)/2) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((cs_ext_list_price-cs_ext_wholesale_cost-cs_ext_discount_amt)+cs_ext_sales_price)/2) ) year_total - ,'c' sale_type - from customer - ,catalog_sales - ,date_dim - where c_customer_sk = cs_bill_customer_sk - and cs_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year -union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((ws_ext_list_price-ws_ext_wholesale_cost-ws_ext_discount_amt)+ws_ext_sales_price)/2) ) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_login - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_c_firstyear - ,year_total t_c_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_c_secyear.customer_id - and t_s_firstyear.customer_id = t_c_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_c_firstyear.sale_type = 'c' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_c_secyear.sale_type = 'c' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 1999 - and t_s_secyear.dyear = 1999+1 - and t_c_firstyear.dyear = 1999 - and t_c_secyear.dyear = 1999+1 - and t_w_firstyear.dyear = 1999 - and t_w_secyear.dyear = 1999+1 - and t_s_firstyear.year_total > 0 - and t_c_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_login -limit 100; - --- end template query4.tpl query 86 in stream 10 --- start template query89.tpl query 87 in stream 10 -select /* TPC-DS query89.tpl 0.56 */ * -from( -select i_category, i_class, i_brand, - s_store_name, s_company_name, - d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, s_store_name, s_company_name) - avg_monthly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - d_year in (2001) and - ((i_category in ('Men','Children','Home') and - i_class in ('pants','newborn','accent') - ) - or (i_category in ('Jewelry','Electronics','Music') and - i_class in ('custom','dvd/vcr players','pop') - )) -group by i_category, i_class, i_brand, - s_store_name, s_company_name, d_moy) tmp1 -where case when (avg_monthly_sales <> 0) then (abs(sum_sales - avg_monthly_sales) / avg_monthly_sales) else null end > 0.1 -order by sum_sales - avg_monthly_sales, s_store_name -limit 100; - --- end template query89.tpl query 87 in stream 10 --- start template query61.tpl query 88 in stream 10 -select /* TPC-DS query61.tpl 0.97 */ promotions,total,cast(promotions as decimal(15,4))/cast(total as decimal(15,4))*100 -from - (select sum(ss_ext_sales_price) promotions - from store_sales - ,store - ,promotion - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_promo_sk = p_promo_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -7 - and i_category = 'Electronics' - and (p_channel_dmail = 'Y' or p_channel_email = 'Y' or p_channel_tv = 'Y') - and s_gmt_offset = -7 - and d_year = 2000 - and d_moy = 11) promotional_sales, - (select sum(ss_ext_sales_price) total - from store_sales - ,store - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -7 - and i_category = 'Electronics' - and s_gmt_offset = -7 - and d_year = 2000 - and d_moy = 11) all_sales -order by promotions, total -limit 100; - --- end template query61.tpl query 88 in stream 10 --- start template query46.tpl query 89 in stream 10 -select /* TPC-DS query46.tpl 0.23 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and (household_demographics.hd_dep_count = 6 or - household_demographics.hd_vehicle_count= 0) - and date_dim.d_dow in (6,0) - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_city in ('Farmington','Winchester','Lowell','Mount Carmel','Woodville') - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,ca_city) dn,customer,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - limit 100; - --- end template query46.tpl query 89 in stream 10 --- start template query92.tpl query 90 in stream 10 -select /* TPC-DS query92.tpl 0.44 */ - sum(ws_ext_discount_amt) as "Excess Discount Amount" -from - web_sales - ,item - ,date_dim -where -i_manufact_id = 763 -and i_item_sk = ws_item_sk -and d_date between '1999-02-11' and - dateadd(day,90,cast('1999-02-11' as date)) -and d_date_sk = ws_sold_date_sk -and ws_ext_discount_amt - > ( - SELECT - 1.3 * avg(ws_ext_discount_amt) - FROM - web_sales - ,date_dim - WHERE - ws_item_sk = i_item_sk - and d_date between '1999-02-11' and - dateadd(day,90,cast('1999-02-11' as date)) - and d_date_sk = ws_sold_date_sk - ) -order by sum(ws_ext_discount_amt) -limit 100; - --- end template query92.tpl query 90 in stream 10 --- start template query13.tpl query 91 in stream 10 -select /* TPC-DS query13.tpl 0.91 */ avg(ss_quantity) - ,avg(ss_ext_sales_price) - ,avg(ss_ext_wholesale_cost) - ,sum(ss_ext_wholesale_cost) - from store_sales - ,store - ,customer_demographics - ,household_demographics - ,customer_address - ,date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2001 - and((ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'D' - and cd_education_status = 'Advanced Degree' - and ss_sales_price between 100.00 and 150.00 - and hd_dep_count = 3 - )or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'W' - and cd_education_status = 'Secondary' - and ss_sales_price between 50.00 and 100.00 - and hd_dep_count = 1 - ) or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'U' - and cd_education_status = 'Primary' - and ss_sales_price between 150.00 and 200.00 - and hd_dep_count = 1 - )) - and((ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('AL', 'TX', 'ID') - and ss_net_profit between 100 and 200 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('ND', 'VA', 'GA') - and ss_net_profit between 150 and 300 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('NV', 'MO', 'WA') - and ss_net_profit between 50 and 250 - )) -; - --- end template query13.tpl query 91 in stream 10 --- start template query9.tpl query 92 in stream 10 -select /* TPC-DS query9.tpl 0.49 */ case when (select count(*) - from store_sales - where ss_quantity between 1 and 20) > 1229207198 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 1 and 20) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 1 and 20) end bucket1 , - case when (select count(*) - from store_sales - where ss_quantity between 21 and 40) > 482523265 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 21 and 40) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 21 and 40) end bucket2, - case when (select count(*) - from store_sales - where ss_quantity between 41 and 60) > 656023248 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 41 and 60) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 41 and 60) end bucket3, - case when (select count(*) - from store_sales - where ss_quantity between 61 and 80) > 1342114999 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 61 and 80) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 61 and 80) end bucket4, - case when (select count(*) - from store_sales - where ss_quantity between 81 and 100) > 769244709 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 81 and 100) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 81 and 100) end bucket5 -from reason -where r_reason_sk = 1 -; - --- end template query9.tpl query 92 in stream 10 --- start template query74.tpl query 93 in stream 10 -with /* TPC-DS query74.tpl 0.76 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,avg(ss_net_paid) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1999,1999+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,avg(ws_net_paid) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - and d_year in (1999,1999+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - ) - select - t_s_secyear.customer_id, t_s_secyear.customer_first_name, t_s_secyear.customer_last_name - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.year = 1999 - and t_s_secyear.year = 1999+1 - and t_w_firstyear.year = 1999 - and t_w_secyear.year = 1999+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - order by 2,1,3 -limit 100; - --- end template query74.tpl query 93 in stream 10 --- start template query8.tpl query 94 in stream 10 -select /* TPC-DS query8.tpl 0.63 */ s_store_name - ,sum(ss_net_profit) - from store_sales - ,date_dim - ,store, - (select ca_zip - from ( - SELECT substring(ca_zip,1,5) ca_zip - FROM customer_address - WHERE substring(ca_zip,1,5) IN ( - '86137','21743','77950','96312','58420','86256', - '72164','58112','66066','56718','45412', - '21979','61494','27171','66940','34385', - '67997','72901','90807','17346','92956', - '11915','28342','36521','76999','15815', - '44225','44495','36523','70663','39853', - '27023','86760','38771','58783','46153', - '20418','26586','17615','11483','13125', - '95571','35511','19749','45259','83153', - '15574','10972','21852','70938','32809', - '84789','42424','56166','41883','54541', - '18240','66045','93194','44727','90349', - '43414','90613','66025','52825','57001', - '52250','93287','60612','55152','27865', - '60782','20736','23614','87375','33444', - '95139','89795','45333','17834','23641', - '58563','94811','63397','41933','24298', - '81911','78797','22210','40323','27874', - '95981','41152','18227','79379','12471', - '63301','46818','19229','71629','66376', - '49059','39387','27082','31830','74862', - '91659','22594','88996','53320','74955', - '73019','31633','72958','90085','84744', - '20504','62191','84206','66523','82521', - '25856','70926','49460','41948','14746', - '99366','60040','90128','22348','58079', - '52717','71046','37581','12494','48664', - '14527','94496','89739','59344','64935', - '50983','66081','85086','18441','90137', - '16896','55436','33517','45936','36174', - '10626','34847','53811','70122','40009', - '85960','73822','96539','49550','92615', - '10020','68897','27752','84527','32636', - '32582','89568','55461','90751','93325', - '64164','81806','94167','51400','66156', - '47060','21884','84899','78129','46636', - '28427','70299','65081','42537','12642', - '56546','53398','98051','98626','76438', - '98868','23816','42459','54254','86303', - '39541','70978','60370','88030','43965', - '24777','37632','80237','94797','30632', - '44749','10110','75532','69791','45058', - '67730','31244','99953','37277','57142', - '21986','33869','20648','62937','30144', - '13742','84420','80130','49978','23168', - '41781','17805','79067','70332','23375', - '50836','35046','68521','32035','57197', - '54657','25618','45137','39663','47989', - '81682','86701','35825','52922','22260', - '51535','15890','46711','49415','74121', - '57558','71700','93239','48335','20496', - '12812','72048','14476','58018','43781', - '79004','63515','77529','43780','94520', - '91528','75385','10344','17192','74742', - '99615','70530','57574','44298','46990', - '33753','39061','20726','91542','30664', - '54722','22349','11942','99263','78382', - '40248','96501','11026','23528','45514', - '62290','37895','81029','55909','56448', - '61024','77770','99125','10949','57932', - '22795','25976','69036','72250','57392', - '49922','56078','36653','47134','41567', - '31275','67209','83558','35189','78871', - '35248','75160','32802','79675','68670', - '30219','33677','38281','91815','22131', - '90710','90756','73743','85102','46191', - '83420','76970','93020','67740','48612', - '52732','59501','44520','41349','16922', - '93661','76645','14967','28015','50520', - '48097','47956','77096','66309','10754', - '84284','88932','75925','38079','76014', - '98634','14293','20618','66306','61569', - '56319','45331','65166','37557','93809', - '24127','14007','46802','16741','37472', - '15967','48360','90498','19281','96267', - '50384','27901','24301','99140','11349', - '36782','24517','11103','19720','76301', - '31764','72824','48832','77879','64061', - '87906','72673','38968','93890','50064', - '10448','80073','24700','97266') - intersect - select ca_zip - from (SELECT substring(ca_zip,1,5) ca_zip,count(*) cnt - FROM customer_address, customer - WHERE ca_address_sk = c_current_addr_sk and - c_preferred_cust_flag='Y' - group by ca_zip - having count(*) > 10)A1)A2) V1 - where ss_store_sk = s_store_sk - and ss_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 2002 - and (substring(s_zip,1,2) = substring(V1.ca_zip,1,2)) - group by s_store_name - order by s_store_name - limit 100; - --- end template query8.tpl query 94 in stream 10 --- start template query3.tpl query 95 in stream 10 -select /* TPC-DS query3.tpl 0.45 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_net_profit) sum_agg - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manufact_id = 602 - and dt.d_moy=12 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,sum_agg desc - ,brand_id - limit 100; - --- end template query3.tpl query 95 in stream 10 --- start template query95.tpl query 96 in stream 10 -with /* TPC-DS query95.tpl 0.43 */ ws_wh as -(select ws1.ws_order_number,ws1.ws_warehouse_sk wh1,ws2.ws_warehouse_sk wh2 - from web_sales ws1,web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) - select - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2002-5-01' and - dateadd(day,60,cast('2002-5-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'CA' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and ws1.ws_order_number in (select ws_order_number - from ws_wh) -and ws1.ws_order_number in (select wr_order_number - from web_returns,ws_wh - where wr_order_number = ws_wh.ws_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query95.tpl query 96 in stream 10 --- start template query26.tpl query 97 in stream 10 -select /* TPC-DS query26.tpl 0.85 */ i_item_id, - avg(cs_quantity) agg1, - avg(cs_list_price) agg2, - avg(cs_coupon_amt) agg3, - avg(cs_sales_price) agg4 - from catalog_sales, customer_demographics, date_dim, item, promotion - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd_demo_sk and - cs_promo_sk = p_promo_sk and - cd_gender = 'F' and - cd_marital_status = 'M' and - cd_education_status = 'College' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 2002 - group by i_item_id - order by i_item_id - limit 100; - --- end template query26.tpl query 97 in stream 10 --- start template query81.tpl query 98 in stream 10 -with /* TPC-DS query81.tpl 0.37 */ customer_total_return as - (select cr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(cr_return_amt_inc_tax) as ctr_total_return - from catalog_returns - ,date_dim - ,customer_address - where cr_returned_date_sk = d_date_sk - and d_year =2001 - and cr_returning_addr_sk = ca_address_sk - group by cr_returning_customer_sk - ,ca_state ) - select c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'NJ' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - limit 100; - --- end template query81.tpl query 98 in stream 10 --- start template query19.tpl query 99 in stream 10 -select /* TPC-DS query19.tpl 0.8 */ i_brand_id brand_id, i_brand brand, i_manufact_id, i_manufact, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item,customer,customer_address,store - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=37 - and d_moy=11 - and d_year=2001 - and ss_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and substring(ca_zip,1,5) <> substring(s_zip,1,5) - and ss_store_sk = s_store_sk - group by i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact - order by ext_price desc - ,i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact -limit 100 ; - --- end template query19.tpl query 99 in stream 10 diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/30TB/queries/query_2.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/30TB/queries/query_2.sql deleted file mode 100644 index ad770fa9..00000000 --- a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/30TB/queries/query_2.sql +++ /dev/null @@ -1,5027 +0,0 @@ --- start template query56.tpl query 1 in stream 2 -with /* TPC-DS query56.tpl 0.83 */ ss as ( - select i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where i_item_id in (select - i_item_id -from item -where i_color in ('antique','light','deep')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 5 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id), - cs as ( - select i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('antique','light','deep')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 5 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id), - ws as ( - select i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('antique','light','deep')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 5 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id) - select i_item_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by total_sales, - i_item_id - limit 100; - --- end template query56.tpl query 1 in stream 2 --- start template query98.tpl query 2 in stream 2 -select /* TPC-DS query98.tpl 0.32 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ss_ext_sales_price) as itemrevenue - ,sum(ss_ext_sales_price)*100/sum(sum(ss_ext_sales_price)) over - (partition by i_class) as revenueratio -from - store_sales - ,item - ,date_dim -where - ss_item_sk = i_item_sk - and i_category in ('Women', 'Home', 'Shoes') - and ss_sold_date_sk = d_date_sk - and d_date between cast('2001-01-30' as date) - and dateadd(day,30,cast('2001-01-30' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio; - --- end template query98.tpl query 2 in stream 2 --- start template query59.tpl query 3 in stream 2 -with /* TPC-DS query59.tpl 0.30 */ wss as - (select d_week_seq, - ss_store_sk, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - group by d_week_seq,ss_store_sk - ) - select s_store_name1,s_store_id1,d_week_seq1 - ,sun_sales1/sun_sales2,mon_sales1/mon_sales2 - ,tue_sales1/tue_sales2,wed_sales1/wed_sales2,thu_sales1/thu_sales2 - ,fri_sales1/fri_sales2,sat_sales1/sat_sales2 - from - (select s_store_name s_store_name1,wss.d_week_seq d_week_seq1 - ,s_store_id s_store_id1,sun_sales sun_sales1 - ,mon_sales mon_sales1,tue_sales tue_sales1 - ,wed_sales wed_sales1,thu_sales thu_sales1 - ,fri_sales fri_sales1,sat_sales sat_sales1 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1204 and 1204 + 11) y, - (select s_store_name s_store_name2,wss.d_week_seq d_week_seq2 - ,s_store_id s_store_id2,sun_sales sun_sales2 - ,mon_sales mon_sales2,tue_sales tue_sales2 - ,wed_sales wed_sales2,thu_sales thu_sales2 - ,fri_sales fri_sales2,sat_sales sat_sales2 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1204+ 12 and 1204 + 23) x - where s_store_id1=s_store_id2 - and d_week_seq1=d_week_seq2-52 - order by s_store_name1,s_store_id1,d_week_seq1 -limit 100; - --- end template query59.tpl query 3 in stream 2 --- start template query24.tpl query 4 in stream 2 -with /* TPC-DS query24.tpl 0.92 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_ext_sales_price) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip -and s_market_id=9 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'gainsboro' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; -with /* TPC-DS query24.tpl 0.92 part2 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_ext_sales_price) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip - and s_market_id = 9 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'yellow' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; - --- end template query24.tpl query 4 in stream 2 --- start template query88.tpl query 5 in stream 2 -select /* TPC-DS query88.tpl 0.66 */ * -from - (select count(*) h8_30_to_9 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s1, - (select count(*) h9_to_9_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s2, - (select count(*) h9_30_to_10 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s3, - (select count(*) h10_to_10_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s4, - (select count(*) h10_30_to_11 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s5, - (select count(*) h11_to_11_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s6, - (select count(*) h11_30_to_12 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s7, - (select count(*) h12_to_12_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 12 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s8 -; - --- end template query88.tpl query 5 in stream 2 --- start template query2.tpl query 6 in stream 2 -with /* TPC-DS query2.tpl 0.84 */ wscs as - (select sold_date_sk - ,sales_price - from (select ws_sold_date_sk sold_date_sk - ,ws_ext_sales_price sales_price - from web_sales - union all - select cs_sold_date_sk sold_date_sk - ,cs_ext_sales_price sales_price - from catalog_sales)), - wswscs as - (select d_week_seq, - sum(case when (d_day_name='Sunday') then sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then sales_price else null end) sat_sales - from wscs - ,date_dim - where d_date_sk = sold_date_sk - group by d_week_seq) - select d_week_seq1 - ,round(sun_sales1/sun_sales2,2) - ,round(mon_sales1/mon_sales2,2) - ,round(tue_sales1/tue_sales2,2) - ,round(wed_sales1/wed_sales2,2) - ,round(thu_sales1/thu_sales2,2) - ,round(fri_sales1/fri_sales2,2) - ,round(sat_sales1/sat_sales2,2) - from - (select wswscs.d_week_seq d_week_seq1 - ,sun_sales sun_sales1 - ,mon_sales mon_sales1 - ,tue_sales tue_sales1 - ,wed_sales wed_sales1 - ,thu_sales thu_sales1 - ,fri_sales fri_sales1 - ,sat_sales sat_sales1 - from wswscs,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 2001) y, - (select wswscs.d_week_seq d_week_seq2 - ,sun_sales sun_sales2 - ,mon_sales mon_sales2 - ,tue_sales tue_sales2 - ,wed_sales wed_sales2 - ,thu_sales thu_sales2 - ,fri_sales fri_sales2 - ,sat_sales sat_sales2 - from wswscs - ,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 2001+1) z - where d_week_seq1=d_week_seq2-53 - order by d_week_seq1; - --- end template query2.tpl query 6 in stream 2 --- start template query5a.tpl query 7 in stream 2 -with /* TPC-DS query5a.tpl 0.98 */ ssr as - (select s_store_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ss_store_sk as store_sk, - ss_sold_date_sk as date_sk, - ss_ext_sales_price as sales_price, - ss_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from store_sales - union all - select sr_store_sk as store_sk, - sr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - sr_return_amt as return_amt, - sr_net_loss as net_loss - from store_returns - ) salesreturns, - date_dim, - store - where date_sk = d_date_sk - and d_date between cast('1998-08-23' as date) - and dateadd(day,14,cast('1998-08-23' as date)) - and store_sk = s_store_sk - group by s_store_id) - , - csr as - (select cp_catalog_page_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select cs_catalog_page_sk as page_sk, - cs_sold_date_sk as date_sk, - cs_ext_sales_price as sales_price, - cs_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from catalog_sales - union all - select cr_catalog_page_sk as page_sk, - cr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - cr_return_amount as return_amt, - cr_net_loss as net_loss - from catalog_returns - ) salesreturns, - date_dim, - catalog_page - where date_sk = d_date_sk - and d_date between cast('1998-08-23' as date) - and dateadd(day,14,cast('1998-08-23' as date)) - and page_sk = cp_catalog_page_sk - group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ws_web_site_sk as wsr_web_site_sk, - ws_sold_date_sk as date_sk, - ws_ext_sales_price as sales_price, - ws_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from web_sales - union all - select ws_web_site_sk as wsr_web_site_sk, - wr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - wr_return_amt as return_amt, - wr_net_loss as net_loss - from web_returns left outer join web_sales on - ( wr_item_sk = ws_item_sk - and wr_order_number = ws_order_number) - ) salesreturns, - date_dim, - web_site - where date_sk = d_date_sk - and d_date between cast('1998-08-23' as date) - and dateadd(day,14,cast('1998-08-23' as date)) - and wsr_web_site_sk = web_site_sk - group by web_site_id) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || s_store_id as id - , sales - , returns - , (profit - profit_loss) as profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || cp_catalog_page_id as id - , sales - , returns - , (profit - profit_loss) as profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , (profit - profit_loss) as profit - from wsr - ) x - group by channel, id) - select channel, id, sales, returns, profit from ( - select channel, id, sales, returns, profit from results - union - select channel, null as id, sum(sales), sum(returns), sum(profit) from results group by channel - union - select null as channel, null as id, sum(sales), sum(returns), sum(profit) from results) foo -order by channel, id -limit 100; - --- end template query5a.tpl query 7 in stream 2 --- start template query6.tpl query 8 in stream 2 -select /* TPC-DS query6.tpl 0.58 */ a.ca_state state, count(*) cnt - from customer_address a - ,customer c - ,store_sales s - ,date_dim d - ,item i - where a.ca_address_sk = c.c_current_addr_sk - and c.c_customer_sk = s.ss_customer_sk - and s.ss_sold_date_sk = d.d_date_sk - and s.ss_item_sk = i.i_item_sk - and d.d_month_seq = - (select distinct (d_month_seq) - from date_dim - where d_year = 2001 - and d_moy = 4 ) - and i.i_current_price > 1.2 * - (select avg(j.i_current_price) - from item j - where j.i_category = i.i_category) - group by a.ca_state - having count(*) >= 10 - order by cnt, a.ca_state - limit 100; - --- end template query6.tpl query 8 in stream 2 --- start template query27a.tpl query 9 in stream 2 -with /* TPC-DS query27a.tpl 0.16 */ results as - (select i_item_id, - s_state, 0 as g_state, - ss_quantity agg1, - ss_list_price agg2, - ss_coupon_amt agg3, - ss_sales_price agg4 - from store_sales, customer_demographics, date_dim, store, item - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_store_sk = s_store_sk and - ss_cdemo_sk = cd_demo_sk and - cd_gender = 'F' and - cd_marital_status = 'S' and - cd_education_status = 'College' and - d_year = 1998 and - s_state in ('CO','MN', 'KY', 'WA', 'SC', 'KS') - ) - - select i_item_id, - s_state, g_state, agg1, agg2, agg3, agg4 - from ( - select i_item_id, s_state, 0 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4 from results - group by i_item_id, s_state - union all - select i_item_id, NULL AS s_state, 1 AS g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as s_state, 1 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - ) foo - order by i_item_id, s_state - limit 100; - --- end template query27a.tpl query 9 in stream 2 --- start template query87.tpl query 10 in stream 2 -select /* TPC-DS query87.tpl 0.77 */ count(*) -from ((select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1213 and 1213+11) - except - (select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1213 and 1213+11) - except - (select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1213 and 1213+11) -) cool_cust -; - --- end template query87.tpl query 10 in stream 2 --- start template query90.tpl query 11 in stream 2 -select /* TPC-DS query90.tpl 0.40 */ cast(amc as decimal(15,4))/cast(pmc as decimal(15,4)) am_pm_ratio - from ( select count(*) amc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 12 and 12+1 - and household_demographics.hd_dep_count = 3 - and web_page.wp_char_count between 5000 and 5200) at, - ( select count(*) pmc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 15 and 15+1 - and household_demographics.hd_dep_count = 3 - and web_page.wp_char_count between 5000 and 5200) pt - order by am_pm_ratio - limit 100; - --- end template query90.tpl query 11 in stream 2 --- start template query83.tpl query 12 in stream 2 -with /* TPC-DS query83.tpl 0.96 */ sr_items as - (select i_item_id item_id, - sum(sr_return_quantity) sr_item_qty - from store_returns, - item, - date_dim - where sr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('1999-04-23','1999-08-20','1999-11-12'))) - and sr_returned_date_sk = d_date_sk - group by i_item_id), - cr_items as - (select i_item_id item_id, - sum(cr_return_quantity) cr_item_qty - from catalog_returns, - item, - date_dim - where cr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('1999-04-23','1999-08-20','1999-11-12'))) - and cr_returned_date_sk = d_date_sk - group by i_item_id), - wr_items as - (select i_item_id item_id, - sum(wr_return_quantity) wr_item_qty - from web_returns, - item, - date_dim - where wr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('1999-04-23','1999-08-20','1999-11-12'))) - and wr_returned_date_sk = d_date_sk - group by i_item_id) - select sr_items.item_id - ,sr_item_qty - ,sr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 sr_dev - ,cr_item_qty - ,cr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 cr_dev - ,wr_item_qty - ,wr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 wr_dev - ,(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 average - from sr_items - ,cr_items - ,wr_items - where sr_items.item_id=cr_items.item_id - and sr_items.item_id=wr_items.item_id - order by sr_items.item_id - ,sr_item_qty - limit 100; - --- end template query83.tpl query 12 in stream 2 --- start template query91.tpl query 13 in stream 2 -select /* TPC-DS query91.tpl 0.13 */ - cc_call_center_id Call_Center, - cc_name Call_Center_Name, - cc_manager Manager, - sum(cr_net_loss) Returns_Loss -from - call_center, - catalog_returns, - date_dim, - customer, - customer_address, - customer_demographics, - household_demographics -where - cr_call_center_sk = cc_call_center_sk -and cr_returned_date_sk = d_date_sk -and cr_returning_customer_sk= c_customer_sk -and cd_demo_sk = c_current_cdemo_sk -and hd_demo_sk = c_current_hdemo_sk -and ca_address_sk = c_current_addr_sk -and d_year = 2000 -and d_moy = 11 -and ( (cd_marital_status = 'M' and cd_education_status = 'Unknown') - or(cd_marital_status = 'W' and cd_education_status = 'Advanced Degree')) -and hd_buy_potential like '501-1000%' -and ca_gmt_offset = -7 -group by cc_call_center_id,cc_name,cc_manager,cd_marital_status,cd_education_status -order by sum(cr_net_loss) desc; - --- end template query91.tpl query 13 in stream 2 --- start template query28.tpl query 14 in stream 2 -select /* TPC-DS query28.tpl 0.36 */ * -from (select avg(ss_list_price) B1_LP - ,count(ss_list_price) B1_CNT - ,count(distinct ss_list_price) B1_CNTD - from store_sales - where ss_quantity between 0 and 5 - and (ss_list_price between 40 and 40+10 - or ss_coupon_amt between 16698 and 16698+1000 - or ss_wholesale_cost between 33 and 33+20)) B1, - (select avg(ss_list_price) B2_LP - ,count(ss_list_price) B2_CNT - ,count(distinct ss_list_price) B2_CNTD - from store_sales - where ss_quantity between 6 and 10 - and (ss_list_price between 28 and 28+10 - or ss_coupon_amt between 10912 and 10912+1000 - or ss_wholesale_cost between 17 and 17+20)) B2, - (select avg(ss_list_price) B3_LP - ,count(ss_list_price) B3_CNT - ,count(distinct ss_list_price) B3_CNTD - from store_sales - where ss_quantity between 11 and 15 - and (ss_list_price between 160 and 160+10 - or ss_coupon_amt between 15758 and 15758+1000 - or ss_wholesale_cost between 57 and 57+20)) B3, - (select avg(ss_list_price) B4_LP - ,count(ss_list_price) B4_CNT - ,count(distinct ss_list_price) B4_CNTD - from store_sales - where ss_quantity between 16 and 20 - and (ss_list_price between 98 and 98+10 - or ss_coupon_amt between 7972 and 7972+1000 - or ss_wholesale_cost between 15 and 15+20)) B4, - (select avg(ss_list_price) B5_LP - ,count(ss_list_price) B5_CNT - ,count(distinct ss_list_price) B5_CNTD - from store_sales - where ss_quantity between 21 and 25 - and (ss_list_price between 3 and 3+10 - or ss_coupon_amt between 619 and 619+1000 - or ss_wholesale_cost between 48 and 48+20)) B5, - (select avg(ss_list_price) B6_LP - ,count(ss_list_price) B6_CNT - ,count(distinct ss_list_price) B6_CNTD - from store_sales - where ss_quantity between 26 and 30 - and (ss_list_price between 38 and 38+10 - or ss_coupon_amt between 5186 and 5186+1000 - or ss_wholesale_cost between 25 and 25+20)) B6 -limit 100; - --- end template query28.tpl query 14 in stream 2 --- start template query68.tpl query 15 in stream 2 -select /* TPC-DS query68.tpl 0.95 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,extended_price - ,extended_tax - ,list_price - from (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_ext_sales_price) extended_price - ,sum(ss_ext_list_price) list_price - ,sum(ss_ext_tax) extended_tax - from store_sales - ,date_dim - ,store - ,household_demographics - ,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_dep_count = 1 or - household_demographics.hd_vehicle_count= -1) - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_city in ('Hope','Dixie') - group by ss_ticket_number - ,ss_customer_sk - ,ss_addr_sk,ca_city) dn - ,customer - ,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,ss_ticket_number - limit 100; - --- end template query68.tpl query 15 in stream 2 --- start template query8.tpl query 16 in stream 2 -select /* TPC-DS query8.tpl 0.63 */ s_store_name - ,sum(ss_net_profit) - from store_sales - ,date_dim - ,store, - (select ca_zip - from ( - SELECT substring(ca_zip,1,5) ca_zip - FROM customer_address - WHERE substring(ca_zip,1,5) IN ( - '35509','88624','14891','40528','43750','41568', - '89057','55340','95110','33584','22754', - '18687','20445','40572','80812','99405', - '65801','91914','24930','17615','91489', - '56553','73760','82626','68885','18100', - '58419','38785','18193','36554','33094', - '84745','10989','86471','21678','67232', - '13286','75196','91024','44541','83242', - '17581','41230','22358','33747','22064', - '73215','73710','14108','62892','32107', - '20830','11310','44140','84929','70626', - '26446','89984','65523','79746','80677', - '59473','81856','53729','19166','30851', - '26537','93695','68431','78789','52219', - '97941','16214','10907','53609','96629', - '57991','97032','12514','72271','78878', - '51388','99155','90892','71563','52790', - '44392','94099','69103','24261','41387', - '46371','43781','55047','40760','27473', - '83220','20644','52068','50657','42440', - '68646','48462','28951','50834','99259', - '41107','60626','34291','85619','11645', - '17451','55160','39224','70451','13427', - '31341','58683','81630','14759','57345', - '91643','43135','88496','74051','27900', - '50965','66332','69921','51796','16912', - '56188','89465','76532','69838','50988', - '59439','76202','19172','32606','72979', - '75969','77746','89381','65641','76566', - '92038','21338','87022','89111','56795', - '86311','52056','39846','77229','58213', - '89298','94865','39679','84956','99376', - '24593','16370','27609','87985','93507', - '23833','45615','40257','91772','51349', - '54307','37810','97056','44090','33546', - '47616','18092','89937','65980','51983', - '44202','76610','84448','74754','75256', - '71637','66976','34701','58581','37010', - '62805','40480','95068','74199','78453', - '11194','64134','44907','83843','33508', - '15354','98100','80792','50758','91076', - '62603','41640','30814','45347','27972', - '69179','15357','41839','91519','87411', - '39541','57014','39841','35407','21123', - '36015','51279','47234','21490','21553', - '74486','68697','51344','30124','49775', - '78690','32977','24790','58515','31323', - '68312','13424','77866','61292','65425', - '52095','10838','95117','62484','50880', - '41940','56647','28106','57303','41354', - '78361','42794','80151','69665','36979', - '84254','49602','25328','94863','12604', - '80831','87225','25909','95877','91743', - '27354','21962','68758','54268','88251', - '64464','68125','13603','71348','52852', - '58744','69294','71078','65189','49727', - '35178','58193','87909','55815','19700', - '11732','46034','47493','91343','54700', - '42163','28151','32714','62015','33046', - '16052','50139','52738','43481','54233', - '63640','71159','27724','36971','18830', - '21782','84119','86428','73777','51934', - '52682','30926','22937','58397','75983', - '93660','55042','57009','49218','24634', - '70884','47046','75440','63671','71355', - '51567','46262','46426','38901','25853', - '29508','13967','16146','12175','54260', - '66178','32587','21728','75267','35644', - '31712','28462','54149','98995','94773', - '26298','31565','32715','63736','60015', - '42616','27582','66446','17737','63382', - '77794','60633','25763','55478','40847', - '37649','13402','88825','33881','62088', - '60288','21761','12560','37002','41500', - '92570','81196','74413','35637','67620', - '39638','27828','65930','79091','36491', - '33771','78500','38222','30834','87001', - '29054','11302','28164','27450','65454', - '50385','63769','74190','68235','21173', - '75687','88002','84742','14417') - intersect - select ca_zip - from (SELECT substring(ca_zip,1,5) ca_zip,count(*) cnt - FROM customer_address, customer - WHERE ca_address_sk = c_current_addr_sk and - c_preferred_cust_flag='Y' - group by ca_zip - having count(*) > 10)A1)A2) V1 - where ss_store_sk = s_store_sk - and ss_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 2000 - and (substring(s_zip,1,2) = substring(V1.ca_zip,1,2)) - group by s_store_name - order by s_store_name - limit 100; - --- end template query8.tpl query 16 in stream 2 --- start template query76.tpl query 17 in stream 2 -select /* TPC-DS query76.tpl 0.99 */ channel, col_name, d_year, d_qoy, i_category, COUNT(*) sales_cnt, SUM(ext_sales_price) sales_amt FROM ( - SELECT 'store' as channel, 'ss_hdemo_sk' col_name, d_year, d_qoy, i_category, ss_ext_sales_price ext_sales_price - FROM store_sales, item, date_dim - WHERE ss_hdemo_sk IS NULL - AND ss_sold_date_sk=d_date_sk - AND ss_item_sk=i_item_sk - UNION ALL - SELECT 'web' as channel, 'ws_promo_sk' col_name, d_year, d_qoy, i_category, ws_ext_sales_price ext_sales_price - FROM web_sales, item, date_dim - WHERE ws_promo_sk IS NULL - AND ws_sold_date_sk=d_date_sk - AND ws_item_sk=i_item_sk - UNION ALL - SELECT 'catalog' as channel, 'cs_ship_customer_sk' col_name, d_year, d_qoy, i_category, cs_ext_sales_price ext_sales_price - FROM catalog_sales, item, date_dim - WHERE cs_ship_customer_sk IS NULL - AND cs_sold_date_sk=d_date_sk - AND cs_item_sk=i_item_sk) foo -GROUP BY channel, col_name, d_year, d_qoy, i_category -ORDER BY channel, col_name, d_year, d_qoy, i_category -limit 100; - --- end template query76.tpl query 17 in stream 2 --- start template query75.tpl query 18 in stream 2 -WITH /* TPC-DS query75.tpl 0.3 */ all_sales AS ( - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,SUM(sales_cnt) AS sales_cnt - ,SUM(sales_amt) AS sales_amt - FROM (SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,cs_quantity - COALESCE(cr_return_quantity,0) AS sales_cnt - ,cs_ext_sales_price - COALESCE(cr_return_amount,0.0) AS sales_amt - FROM catalog_sales JOIN item ON i_item_sk=cs_item_sk - JOIN date_dim ON d_date_sk=cs_sold_date_sk - LEFT JOIN catalog_returns ON (cs_order_number=cr_order_number - AND cs_item_sk=cr_item_sk) - WHERE i_category='Home' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ss_quantity - COALESCE(sr_return_quantity,0) AS sales_cnt - ,ss_ext_sales_price - COALESCE(sr_return_amt,0.0) AS sales_amt - FROM store_sales JOIN item ON i_item_sk=ss_item_sk - JOIN date_dim ON d_date_sk=ss_sold_date_sk - LEFT JOIN store_returns ON (ss_ticket_number=sr_ticket_number - AND ss_item_sk=sr_item_sk) - WHERE i_category='Home' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ws_quantity - COALESCE(wr_return_quantity,0) AS sales_cnt - ,ws_ext_sales_price - COALESCE(wr_return_amt,0.0) AS sales_amt - FROM web_sales JOIN item ON i_item_sk=ws_item_sk - JOIN date_dim ON d_date_sk=ws_sold_date_sk - LEFT JOIN web_returns ON (ws_order_number=wr_order_number - AND ws_item_sk=wr_item_sk) - WHERE i_category='Home') sales_detail - GROUP BY d_year, i_brand_id, i_class_id, i_category_id, i_manufact_id) - SELECT prev_yr.d_year AS prev_year - ,curr_yr.d_year AS year - ,curr_yr.i_brand_id - ,curr_yr.i_class_id - ,curr_yr.i_category_id - ,curr_yr.i_manufact_id - ,prev_yr.sales_cnt AS prev_yr_cnt - ,curr_yr.sales_cnt AS curr_yr_cnt - ,curr_yr.sales_cnt-prev_yr.sales_cnt AS sales_cnt_diff - ,curr_yr.sales_amt-prev_yr.sales_amt AS sales_amt_diff - FROM all_sales curr_yr, all_sales prev_yr - WHERE curr_yr.i_brand_id=prev_yr.i_brand_id - AND curr_yr.i_class_id=prev_yr.i_class_id - AND curr_yr.i_category_id=prev_yr.i_category_id - AND curr_yr.i_manufact_id=prev_yr.i_manufact_id - AND curr_yr.d_year=1999 - AND prev_yr.d_year=1999-1 - AND CAST(curr_yr.sales_cnt AS DECIMAL(17,2))/CAST(prev_yr.sales_cnt AS DECIMAL(17,2))<0.9 - ORDER BY sales_cnt_diff,sales_amt_diff - limit 100; - --- end template query75.tpl query 18 in stream 2 --- start template query80a.tpl query 19 in stream 2 -with /* TPC-DS query80a.tpl 0.6 */ ssr as - (select s_store_id as store_id, - sum(ss_ext_sales_price) as sales, - sum(coalesce(sr_return_amt, 0)) as returns, - sum(ss_net_profit - coalesce(sr_net_loss, 0)) as profit - from store_sales left outer join store_returns on - (ss_item_sk = sr_item_sk and ss_ticket_number = sr_ticket_number), - date_dim, - store, - item, - promotion - where ss_sold_date_sk = d_date_sk - and d_date between cast('2002-08-25' as date) - and dateadd(day,30,cast('2002-08-25' as date)) - and ss_store_sk = s_store_sk - and ss_item_sk = i_item_sk - and i_current_price > 50 - and ss_promo_sk = p_promo_sk - and p_channel_tv = 'N' - group by s_store_id) - , - csr as - (select cp_catalog_page_id as catalog_page_id, - sum(cs_ext_sales_price) as sales, - sum(coalesce(cr_return_amount, 0)) as returns, - sum(cs_net_profit - coalesce(cr_net_loss, 0)) as profit - from catalog_sales left outer join catalog_returns on - (cs_item_sk = cr_item_sk and cs_order_number = cr_order_number), - date_dim, - catalog_page, - item, - promotion - where cs_sold_date_sk = d_date_sk - and d_date between cast('2002-08-25' as date) - and dateadd(day,30,cast('2002-08-25' as date)) - and cs_catalog_page_sk = cp_catalog_page_sk - and cs_item_sk = i_item_sk - and i_current_price > 50 - and cs_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(ws_ext_sales_price) as sales, - sum(coalesce(wr_return_amt, 0)) as returns, - sum(ws_net_profit - coalesce(wr_net_loss, 0)) as profit - from web_sales left outer join web_returns on - (ws_item_sk = wr_item_sk and ws_order_number = wr_order_number), - date_dim, - web_site, - item, - promotion - where ws_sold_date_sk = d_date_sk - and d_date between cast('2002-08-25' as date) - and dateadd(day,30,cast('2002-08-25' as date)) - and ws_web_site_sk = web_site_sk - and ws_item_sk = i_item_sk - and i_current_price > 50 - and ws_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by web_site_id) -, -results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || store_id as id - , sales - , returns - , profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || catalog_page_id as id - , sales - , returns - , profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , profit - from wsr - ) x - group by channel, id) - - select channel - , id - , sales - , returns - , profit - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results - ) foo - order by channel, id - limit 100; - --- end template query80a.tpl query 19 in stream 2 --- start template query1.tpl query 20 in stream 2 -with /* TPC-DS query1.tpl 0.12 */ customer_total_return as -(select sr_customer_sk as ctr_customer_sk -,sr_store_sk as ctr_store_sk -,sum(SR_RETURN_AMT) as ctr_total_return -from store_returns -,date_dim -where sr_returned_date_sk = d_date_sk -and d_year =2001 -group by sr_customer_sk -,sr_store_sk) - select c_customer_id -from customer_total_return ctr1 -,store -,customer -where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 -from customer_total_return ctr2 -where ctr1.ctr_store_sk = ctr2.ctr_store_sk) -and s_store_sk = ctr1.ctr_store_sk -and s_state = 'AR' -and ctr1.ctr_customer_sk = c_customer_sk -order by c_customer_id -limit 100; - --- end template query1.tpl query 20 in stream 2 --- start template query69.tpl query 21 in stream 2 -select /* TPC-DS query69.tpl 0.28 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_state in ('FL','AL','NC') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2001 and - d_moy between 2 and 2+2) and - (not exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2001 and - d_moy between 2 and 2+2) and - not exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2001 and - d_moy between 2 and 2+2)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - limit 100; - --- end template query69.tpl query 21 in stream 2 --- start template query26.tpl query 22 in stream 2 -select /* TPC-DS query26.tpl 0.85 */ i_item_id, - avg(cs_quantity) agg1, - avg(cs_list_price) agg2, - avg(cs_coupon_amt) agg3, - avg(cs_sales_price) agg4 - from catalog_sales, customer_demographics, date_dim, item, promotion - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd_demo_sk and - cs_promo_sk = p_promo_sk and - cd_gender = 'F' and - cd_marital_status = 'M' and - cd_education_status = 'Secondary' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 2002 - group by i_item_id - order by i_item_id - limit 100; - --- end template query26.tpl query 22 in stream 2 --- start template query11.tpl query 23 in stream 2 -with /* TPC-DS query11.tpl 0.51 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ss_ext_list_price-ss_ext_discount_amt) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ws_ext_list_price-ws_ext_discount_amt) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_preferred_cust_flag - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 2000 - and t_s_secyear.dyear = 2000+1 - and t_w_firstyear.dyear = 2000 - and t_w_secyear.dyear = 2000+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else 0.0 end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else 0.0 end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_preferred_cust_flag -limit 100; - --- end template query11.tpl query 23 in stream 2 --- start template query17.tpl query 24 in stream 2 -select /* TPC-DS query17.tpl 0.41 */ i_item_id - ,i_item_desc - ,s_state - ,count(ss_quantity) as store_sales_quantitycount - ,avg(ss_quantity) as store_sales_quantityave - ,stddev_samp(ss_quantity) as store_sales_quantitystdev - ,stddev_samp(ss_quantity)/avg(ss_quantity) as store_sales_quantitycov - ,count(sr_return_quantity) as store_returns_quantitycount - ,avg(sr_return_quantity) as store_returns_quantityave - ,stddev_samp(sr_return_quantity) as store_returns_quantitystdev - ,stddev_samp(sr_return_quantity)/avg(sr_return_quantity) as store_returns_quantitycov - ,count(cs_quantity) as catalog_sales_quantitycount ,avg(cs_quantity) as catalog_sales_quantityave - ,stddev_samp(cs_quantity) as catalog_sales_quantitystdev - ,stddev_samp(cs_quantity)/avg(cs_quantity) as catalog_sales_quantitycov - from store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where d1.d_quarter_name = '2002Q1' - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_quarter_name in ('2002Q1','2002Q2','2002Q3') - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_quarter_name in ('2002Q1','2002Q2','2002Q3') - group by i_item_id - ,i_item_desc - ,s_state - order by i_item_id - ,i_item_desc - ,s_state -limit 100; - --- end template query17.tpl query 24 in stream 2 --- start template query63.tpl query 25 in stream 2 -select /* TPC-DS query63.tpl 0.27 */ * -from (select i_manager_id - ,sum(ss_sales_price) sum_sales - ,avg(sum(ss_sales_price)) over (partition by i_manager_id) avg_monthly_sales - from item - ,store_sales - ,date_dim - ,store - where ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and d_month_seq in (1186,1186+1,1186+2,1186+3,1186+4,1186+5,1186+6,1186+7,1186+8,1186+9,1186+10,1186+11) - and (( i_category in ('Books','Children','Electronics') - and i_class in ('personal','portable','reference','self-help') - and i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) - or( i_category in ('Women','Music','Men') - and i_class in ('accessories','classical','fragrances','pants') - and i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manager_id, d_moy) tmp1 -where case when avg_monthly_sales > 0 then abs (sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 -order by i_manager_id - ,avg_monthly_sales - ,sum_sales -limit 100; - --- end template query63.tpl query 25 in stream 2 --- start template query77a.tpl query 26 in stream 2 -with /* TPC-DS query77a.tpl 0.78 */ ss as - (select s_store_sk, - sum(ss_ext_sales_price) as sales, - sum(ss_net_profit) as profit - from store_sales, - date_dim, - store - where ss_sold_date_sk = d_date_sk - and d_date between cast('2000-08-04' as date) - and dateadd(day,30,cast('2000-08-04' as date)) - and ss_store_sk = s_store_sk - group by s_store_sk) - , - sr as - (select s_store_sk, - sum(sr_return_amt) as returns, - sum(sr_net_loss) as profit_loss - from store_returns, - date_dim, - store - where sr_returned_date_sk = d_date_sk - and d_date between cast('2000-08-04' as date) - and dateadd(day,30,cast('2000-08-04' as date)) - and sr_store_sk = s_store_sk - group by s_store_sk), - cs as - (select cs_call_center_sk, - sum(cs_ext_sales_price) as sales, - sum(cs_net_profit) as profit - from catalog_sales, - date_dim - where cs_sold_date_sk = d_date_sk - and d_date between cast('2000-08-04' as date) - and dateadd(day,30,cast('2000-08-04' as date)) - group by cs_call_center_sk - ), - cr as - (select cr_call_center_sk, - sum(cr_return_amount) as returns, - sum(cr_net_loss) as profit_loss - from catalog_returns, - date_dim - where cr_returned_date_sk = d_date_sk - and d_date between cast('2000-08-04' as date) - and dateadd(day,30,cast('2000-08-04' as date)) - group by cr_call_center_sk), - ws as - ( select wp_web_page_sk, - sum(ws_ext_sales_price) as sales, - sum(ws_net_profit) as profit - from web_sales, - date_dim, - web_page - where ws_sold_date_sk = d_date_sk - and d_date between cast('2000-08-04' as date) - and dateadd(day,30,cast('2000-08-04' as date)) - and ws_web_page_sk = wp_web_page_sk - group by wp_web_page_sk), - wr as - (select wp_web_page_sk, - sum(wr_return_amt) as returns, - sum(wr_net_loss) as profit_loss - from web_returns, - date_dim, - web_page - where wr_returned_date_sk = d_date_sk - and d_date between cast('2000-08-04' as date) - and dateadd(day,30,cast('2000-08-04' as date)) - and wr_web_page_sk = wp_web_page_sk - group by wp_web_page_sk) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , ss.s_store_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ss left join sr - on ss.s_store_sk = sr.s_store_sk - union all - select 'catalog channel' as channel - , cs_call_center_sk as id - , sales - , returns - , (profit - profit_loss) as profit - from cs - , cr - union all - select 'web channel' as channel - , ws.wp_web_page_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ws left join wr - on ws.wp_web_page_sk = wr.wp_web_page_sk - ) x - group by channel, id ) - - select * - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results -) foo -order by channel, id - limit 100; - --- end template query77a.tpl query 26 in stream 2 --- start template query19.tpl query 27 in stream 2 -select /* TPC-DS query19.tpl 0.8 */ i_brand_id brand_id, i_brand brand, i_manufact_id, i_manufact, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item,customer,customer_address,store - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=62 - and d_moy=12 - and d_year=1998 - and ss_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and substring(ca_zip,1,5) <> substring(s_zip,1,5) - and ss_store_sk = s_store_sk - group by i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact - order by ext_price desc - ,i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact -limit 100 ; - --- end template query19.tpl query 27 in stream 2 --- start template query21.tpl query 28 in stream 2 -select /* TPC-DS query21.tpl 0.14 */ * - from(select w_warehouse_name - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('1998-05-09' as date)) - then inv_quantity_on_hand - else 0 end) as inv_before - ,sum(case when (cast(d_date as date) >= cast ('1998-05-09' as date)) - then inv_quantity_on_hand - else 0 end) as inv_after - from inventory - ,warehouse - ,item - ,date_dim - where i_current_price between 0.99 and 1.49 - and i_item_sk = inv_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('1998-05-09' as date)) - and dateadd(day,30,cast ('1998-05-09' as date)) - group by w_warehouse_name, i_item_id) x - where (case when inv_before > 0 - then inv_after / inv_before - else null - end) between 2.0/3.0 and 3.0/2.0 - order by w_warehouse_name - ,i_item_id - limit 100; - --- end template query21.tpl query 28 in stream 2 --- start template query31.tpl query 29 in stream 2 -with /* TPC-DS query31.tpl 0.50 */ ss as - (select ca_county,d_qoy, d_year,sum(ss_ext_sales_price) as store_sales - from store_sales,date_dim,customer_address - where ss_sold_date_sk = d_date_sk - and ss_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year), - ws as - (select ca_county,d_qoy, d_year,sum(ws_ext_sales_price) as web_sales - from web_sales,date_dim,customer_address - where ws_sold_date_sk = d_date_sk - and ws_bill_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year) - select - ss1.ca_county - ,ss1.d_year - ,ws2.web_sales/ws1.web_sales web_q1_q2_increase - ,ss2.store_sales/ss1.store_sales store_q1_q2_increase - ,ws3.web_sales/ws2.web_sales web_q2_q3_increase - ,ss3.store_sales/ss2.store_sales store_q2_q3_increase - from - ss ss1 - ,ss ss2 - ,ss ss3 - ,ws ws1 - ,ws ws2 - ,ws ws3 - where - ss1.d_qoy = 1 - and ss1.d_year = 1999 - and ss1.ca_county = ss2.ca_county - and ss2.d_qoy = 2 - and ss2.d_year = 1999 - and ss2.ca_county = ss3.ca_county - and ss3.d_qoy = 3 - and ss3.d_year = 1999 - and ss1.ca_county = ws1.ca_county - and ws1.d_qoy = 1 - and ws1.d_year = 1999 - and ws1.ca_county = ws2.ca_county - and ws2.d_qoy = 2 - and ws2.d_year = 1999 - and ws1.ca_county = ws3.ca_county - and ws3.d_qoy = 3 - and ws3.d_year =1999 - and case when ws1.web_sales > 0 then ws2.web_sales/ws1.web_sales else null end - > case when ss1.store_sales > 0 then ss2.store_sales/ss1.store_sales else null end - and case when ws2.web_sales > 0 then ws3.web_sales/ws2.web_sales else null end - > case when ss2.store_sales > 0 then ss3.store_sales/ss2.store_sales else null end - order by store_q2_q3_increase; - --- end template query31.tpl query 29 in stream 2 --- start template query93.tpl query 30 in stream 2 -select /* TPC-DS query93.tpl 0.52 */ ss_customer_sk - ,sum(act_sales) sumsales - from (select ss_item_sk - ,ss_ticket_number - ,ss_customer_sk - ,case when sr_return_quantity is not null then (ss_quantity-sr_return_quantity)*ss_sales_price - else (ss_quantity*ss_sales_price) end act_sales - from store_sales left outer join store_returns on (sr_item_sk = ss_item_sk - and sr_ticket_number = ss_ticket_number) - ,reason - where sr_reason_sk = r_reason_sk - and r_reason_desc = 'reason 25') t - group by ss_customer_sk - order by sumsales, ss_customer_sk -limit 100; - --- end template query93.tpl query 30 in stream 2 --- start template query54.tpl query 31 in stream 2 -with /* TPC-DS query54.tpl 0.81 */ my_customers as ( - select distinct c_customer_sk - , c_current_addr_sk - from - ( select cs_sold_date_sk sold_date_sk, - cs_bill_customer_sk customer_sk, - cs_item_sk item_sk - from catalog_sales - union all - select ws_sold_date_sk sold_date_sk, - ws_bill_customer_sk customer_sk, - ws_item_sk item_sk - from web_sales - ) cs_or_ws_sales, - item, - date_dim, - customer - where sold_date_sk = d_date_sk - and item_sk = i_item_sk - and i_category = 'Books' - and i_class = 'home repair' - and c_customer_sk = cs_or_ws_sales.customer_sk - and d_moy = 1 - and d_year = 1999 - ) - , my_revenue as ( - select c_customer_sk, - sum(ss_ext_sales_price) as revenue - from my_customers, - store_sales, - customer_address, - store, - date_dim - where c_current_addr_sk = ca_address_sk - and ca_county = s_county - and ca_state = s_state - and ss_sold_date_sk = d_date_sk - and c_customer_sk = ss_customer_sk - and d_month_seq between (select distinct d_month_seq+1 - from date_dim where d_year = 1999 and d_moy = 1) - and (select distinct d_month_seq+3 - from date_dim where d_year = 1999 and d_moy = 1) - group by c_customer_sk - ) - , segments as - (select cast((revenue/50) as bigint) as segment - from my_revenue - ) - select segment, count(*) as num_customers, segment*50 as segment_base - from segments - group by segment - order by segment, num_customers - limit 100; - --- end template query54.tpl query 31 in stream 2 --- start template query39.tpl query 32 in stream 2 -with /* TPC-DS query39.tpl 0.5 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =2000 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=2 - and inv2.d_moy=2+1 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; -with /* TPC-DS query39.tpl 0.5 part2 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =2000 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=2 - and inv2.d_moy=2+1 - and inv1.cov > 1.5 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; - --- end template query39.tpl query 32 in stream 2 --- start template query10.tpl query 33 in stream 2 -select /* TPC-DS query10.tpl 0.26 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3, - cd_dep_count, - count(*) cnt4, - cd_dep_employed_count, - count(*) cnt5, - cd_dep_college_count, - count(*) cnt6 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_county in ('Lawrence County','Union County','Madison County','Barton County','Humboldt County') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2001 and - d_moy between 1 and 1+3) and - (exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2001 and - d_moy between 1 ANd 1+3) or - exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2001 and - d_moy between 1 and 1+3)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count -limit 100; - --- end template query10.tpl query 33 in stream 2 --- start template query15.tpl query 34 in stream 2 -select /* TPC-DS query15.tpl 0.57 */ ca_zip - ,sum(cs_sales_price) - from catalog_sales - ,customer - ,customer_address - ,date_dim - where cs_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', - '85392', '85460', '80348', '81792') - or ca_state in ('CA','WA','GA') - or cs_sales_price > 500) - and cs_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 2000 - group by ca_zip - order by ca_zip - limit 100; - --- end template query15.tpl query 34 in stream 2 --- start template query55.tpl query 35 in stream 2 -select /* TPC-DS query55.tpl 0.82 */ i_brand_id brand_id, i_brand brand, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=45 - and d_moy=12 - and d_year=2000 - group by i_brand, i_brand_id - order by ext_price desc, i_brand_id -limit 100 ; - --- end template query55.tpl query 35 in stream 2 --- start template query14a.tpl query 36 in stream 2 -with /* TPC-DS query14a.tpl 0.69 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 2000 AND 2000 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 2000 AND 2000 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 2000 AND 2000 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as - (select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2) x) -, - results AS -(select channel, i_brand_id, i_class_id, i_category_id, sum(sales) sum_sales, sum(number_sales) number_sales - from ( - select 'store' channel, i_brand_id,i_class_id - ,i_category_id,sum(ss_quantity*ss_list_price) sales - , count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2000+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales) - union all - select 'catalog' channel, i_brand_id,i_class_id,i_category_id, sum(cs_quantity*cs_list_price) sales, count(*) number_sales - from catalog_sales - ,item - ,date_dim - where cs_item_sk in (select ss_item_sk from cross_items) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2000+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(cs_quantity*cs_list_price) > (select average_sales from avg_sales) - union all - select 'web' channel, i_brand_id,i_class_id,i_category_id, sum(ws_quantity*ws_list_price) sales , count(*) number_sales - from web_sales - ,item - ,date_dim - where ws_item_sk in (select ss_item_sk from cross_items) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2000+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ws_quantity*ws_list_price) > (select average_sales from avg_sales) - ) y - group by channel, i_brand_id,i_class_id,i_category_id) - - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales -from ( - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales from results - union - select channel, i_brand_id, i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id, i_class_id - union - select channel, i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id - union - select channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel - union - select null as channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results) z -order by channel, i_brand_id, i_class_id, i_category_id - limit 100; -with /* TPC-DS query14a.tpl 0.69 part2 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 2000 AND 2000 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 2000 AND 2000 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 2000 AND 2000 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as -(select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2) x) - select this_year.channel ty_channel - ,this_year.i_brand_id ty_brand - ,this_year.i_class_id ty_class - ,this_year.i_category_id ty_category - ,this_year.sales ty_sales - ,this_year.number_sales ty_number_sales - ,last_year.channel ly_channel - ,last_year.i_brand_id ly_brand - ,last_year.i_class_id ly_class - ,last_year.i_category_id ly_category - ,last_year.sales ly_sales - ,last_year.number_sales ly_number_sales -from - (select 'store' channel, i_brand_id,i_class_id,i_category_id - ,sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 2000 + 1 - and d_moy = 12 - and d_dom = 22) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) this_year, - (select 'store' channel, i_brand_id,i_class_id - ,i_category_id, sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 2000 - and d_moy = 12 - and d_dom = 22) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) last_year - where this_year.i_brand_id= last_year.i_brand_id - and this_year.i_class_id = last_year.i_class_id - and this_year.i_category_id = last_year.i_category_id - order by this_year.channel, this_year.i_brand_id, this_year.i_class_id, this_year.i_category_id - limit 100; - --- end template query14a.tpl query 36 in stream 2 --- start template query38.tpl query 37 in stream 2 -select /* TPC-DS query38.tpl 0.54 */ count(*) from ( - select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1212 and 1212 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1212 and 1212 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1212 and 1212 + 11 -) hot_cust -limit 100; - --- end template query38.tpl query 37 in stream 2 --- start template query42.tpl query 38 in stream 2 -select /* TPC-DS query42.tpl 0.61 */ dt.d_year - ,item.i_category_id - ,item.i_category - ,sum(ss_ext_sales_price) - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=11 - and dt.d_year=1998 - group by dt.d_year - ,item.i_category_id - ,item.i_category - order by sum(ss_ext_sales_price) desc,dt.d_year - ,item.i_category_id - ,item.i_category -limit 100 ; - --- end template query42.tpl query 38 in stream 2 --- start template query53.tpl query 39 in stream 2 -select /* TPC-DS query53.tpl 0.88 */ * from -(select i_manufact_id, -sum(ss_sales_price) sum_sales, -avg(sum(ss_sales_price)) over (partition by i_manufact_id) avg_quarterly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and -ss_sold_date_sk = d_date_sk and -ss_store_sk = s_store_sk and -d_month_seq in (1184,1184+1,1184+2,1184+3,1184+4,1184+5,1184+6,1184+7,1184+8,1184+9,1184+10,1184+11) and -((i_category in ('Books','Children','Electronics') and -i_class in ('personal','portable','reference','self-help') and -i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) -or(i_category in ('Women','Music','Men') and -i_class in ('accessories','classical','fragrances','pants') and -i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manufact_id, d_qoy ) tmp1 -where case when avg_quarterly_sales > 0 - then abs (sum_sales - avg_quarterly_sales)/ avg_quarterly_sales - else null end > 0.1 -order by avg_quarterly_sales, - sum_sales, - i_manufact_id -limit 100; - --- end template query53.tpl query 39 in stream 2 --- start template query45.tpl query 40 in stream 2 -select /* TPC-DS query45.tpl 0.18 */ ca_zip, ca_county, sum(ws_sales_price) - from web_sales, customer, customer_address, date_dim, item - where ws_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ws_item_sk = i_item_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', '85392', '85460', '80348', '81792') - or - i_item_id in (select i_item_id - from item - where i_item_sk in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29) - ) - ) - and ws_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 2002 - group by ca_zip, ca_county - order by ca_zip, ca_county - limit 100; - --- end template query45.tpl query 40 in stream 2 --- start template query99.tpl query 41 in stream 2 -select /* TPC-DS query99.tpl 0.94 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 30) and - (cs_ship_date_sk - cs_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 60) and - (cs_ship_date_sk - cs_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 90) and - (cs_ship_date_sk - cs_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - catalog_sales - ,warehouse - ,ship_mode - ,call_center - ,date_dim -where - d_month_seq between 1212 and 1212 + 11 -and cs_ship_date_sk = d_date_sk -and cs_warehouse_sk = w_warehouse_sk -and cs_ship_mode_sk = sm_ship_mode_sk -and cs_call_center_sk = cc_call_center_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -limit 100; - --- end template query99.tpl query 41 in stream 2 --- start template query67a.tpl query 42 in stream 2 -with /* TPC-DS query67a.tpl 0.35 */ results as -( select i_category ,i_class ,i_brand ,i_product_name ,d_year ,d_qoy ,d_moy ,s_store_id - ,sum(coalesce(ss_sales_price*ss_quantity,0)) sumsales - from store_sales ,date_dim ,store ,item - where ss_sold_date_sk=d_date_sk - and ss_item_sk=i_item_sk - and ss_store_sk = s_store_sk - and d_month_seq between 1203 and 1203 + 11 - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy,s_store_id) - , - results_rollup as - (select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, s_store_id, sumsales - from results - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy - union all - select i_category, i_class, i_brand, i_product_name, d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year - union all - select i_category, i_class, i_brand, i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name - union all - select i_category, i_class, i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand - union all - select i_category, i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class - union all - select i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category - union all - select null i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results) - - select * -from (select i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rank() over (partition by i_category order by sumsales desc) rk - from results_rollup) dw2 -where rk <= 100 -order by i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rk -limit 100; - --- end template query67a.tpl query 42 in stream 2 --- start template query23.tpl query 43 in stream 2 -with /* TPC-DS query23.tpl 0.68 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (2000,2000+1,2000+2,2000+3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (2000,2000+1,2000+2,2000+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * -from - max_store_sales)) - select sum(sales) - from (select cs_quantity*cs_list_price sales - from catalog_sales - ,date_dim - where d_year = 2000 - and d_moy = 7 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - union all - select ws_quantity*ws_list_price sales - from web_sales - ,date_dim - where d_year = 2000 - and d_moy = 7 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer)) - limit 100; -with /* TPC-DS query23.tpl 0.68 part2 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (2000,2000 + 1,2000 + 2,2000 + 3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (2000,2000+1,2000+2,2000+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * - from max_store_sales)) - select c_last_name,c_first_name,sales - from (select c_last_name,c_first_name,sum(cs_quantity*cs_list_price) sales - from catalog_sales - ,customer - ,date_dim - where d_year = 2000 - and d_moy = 7 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and cs_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name - union all - select c_last_name,c_first_name,sum(ws_quantity*ws_list_price) sales - from web_sales - ,customer - ,date_dim - where d_year = 2000 - and d_moy = 7 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and ws_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name) - order by c_last_name,c_first_name,sales - limit 100; - --- end template query23.tpl query 43 in stream 2 --- start template query62.tpl query 44 in stream 2 -select /* TPC-DS query62.tpl 0.24 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 30) and - (ws_ship_date_sk - ws_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 60) and - (ws_ship_date_sk - ws_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 90) and - (ws_ship_date_sk - ws_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - web_sales - ,warehouse - ,ship_mode - ,web_site - ,date_dim -where - d_month_seq between 1207 and 1207 + 11 -and ws_ship_date_sk = d_date_sk -and ws_warehouse_sk = w_warehouse_sk -and ws_ship_mode_sk = sm_ship_mode_sk -and ws_web_site_sk = web_site_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -limit 100; - --- end template query62.tpl query 44 in stream 2 --- start template query30.tpl query 45 in stream 2 -with /* TPC-DS query30.tpl 0.75 */ customer_total_return as - (select wr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(wr_return_amt) as ctr_total_return - from web_returns - ,date_dim - ,customer_address - where wr_returned_date_sk = d_date_sk - and d_year =2000 - and wr_returning_addr_sk = ca_address_sk - group by wr_returning_customer_sk - ,ca_state) - select c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'OR' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return -limit 100; - --- end template query30.tpl query 45 in stream 2 --- start template query86a.tpl query 46 in stream 2 -with /* TPC-DS query86a.tpl 0.11 */ results as -( select sum(ws_net_paid) as total_sum, i_category, i_class, 0 as g_category, 0 as g_class - from - web_sales - ,date_dim d1 - ,item - where - d1.d_month_seq between 1188 and 1188+11 - and d1.d_date_sk = ws_sold_date_sk - and i_item_sk = ws_item_sk - group by i_category,i_class - ) , - - results_rollup as -( select total_sum ,i_category ,i_class, g_category, g_class, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum, i_category, NULL as i_class, 0 as g_category, 1 as g_class, 1 as lochierarchy from results group by i_category - union - select sum(total_sum) as total_sum, NULL as i_category, NULL as i_class, 1 as g_category, 1 as g_class, 2 as lochierarchy from results) - select - total_sum ,i_category ,i_class, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_class = 0 then i_category end - order by total_sum desc) as rank_within_parent - from - results_rollup - order by - lochierarchy desc, - case when lochierarchy = 0 then i_category end, - rank_within_parent - limit 100; - --- end template query86a.tpl query 46 in stream 2 --- start template query82.tpl query 47 in stream 2 -select /* TPC-DS query82.tpl 0.67 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, store_sales - where i_current_price between 78 and 78+30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('2001-01-17' as date) and dateadd(day,60,cast('2001-01-17' as date)) - and i_manufact_id in (600,655,913,505) - and inv_quantity_on_hand between 100 and 500 - and ss_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query82.tpl query 47 in stream 2 --- start template query25.tpl query 48 in stream 2 -select /* TPC-DS query25.tpl 0.9 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,stddev_samp(ss_net_profit) as store_sales_profit - ,stddev_samp(sr_net_loss) as store_returns_loss - ,stddev_samp(cs_net_profit) as catalog_sales_profit - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 2001 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 10 - and d2.d_year = 2001 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_moy between 4 and 10 - and d3.d_year = 2001 - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query25.tpl query 48 in stream 2 --- start template query16.tpl query 49 in stream 2 -select /* TPC-DS query16.tpl 0.25 */ - count(distinct cs_order_number) as "order count" - ,sum(cs_ext_ship_cost) as "total shipping cost" - ,sum(cs_net_profit) as "total net profit" -from - catalog_sales cs1 - ,date_dim - ,customer_address - ,call_center -where - d_date between '2002-5-01' and - dateadd(day, 60, cast('2002-5-01' as date)) -and cs1.cs_ship_date_sk = d_date_sk -and cs1.cs_ship_addr_sk = ca_address_sk -and ca_state = 'FL' -and cs1.cs_call_center_sk = cc_call_center_sk -and cc_county in ('Luce County','Richland County','Franklin Parish','Daviess County', - 'Fairfield County' -) -and exists (select * - from catalog_sales cs2 - where cs1.cs_order_number = cs2.cs_order_number - and cs1.cs_warehouse_sk <> cs2.cs_warehouse_sk) -and not exists(select * - from catalog_returns cr1 - where cs1.cs_order_number = cr1.cr_order_number) -order by count(distinct cs_order_number) -limit 100; - --- end template query16.tpl query 49 in stream 2 --- start template query81.tpl query 50 in stream 2 -with /* TPC-DS query81.tpl 0.37 */ customer_total_return as - (select cr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(cr_return_amt_inc_tax) as ctr_total_return - from catalog_returns - ,date_dim - ,customer_address - where cr_returned_date_sk = d_date_sk - and d_year =1999 - and cr_returning_addr_sk = ca_address_sk - group by cr_returning_customer_sk - ,ca_state ) - select c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'TX' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - limit 100; - --- end template query81.tpl query 50 in stream 2 --- start template query40.tpl query 51 in stream 2 -select /* TPC-DS query40.tpl 0.86 */ - w_state - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('2000-04-10' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_before - ,sum(case when (cast(d_date as date) >= cast ('2000-04-10' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_after - from - catalog_sales left outer join catalog_returns on - (cs_order_number = cr_order_number - and cs_item_sk = cr_item_sk) - ,warehouse - ,item - ,date_dim - where - i_current_price between 0.99 and 1.49 - and i_item_sk = cs_item_sk - and cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('2000-04-10' as date)) - and dateadd(day,30,cast ('2000-04-10' as date)) - group by - w_state,i_item_id - order by w_state,i_item_id -limit 100; - --- end template query40.tpl query 51 in stream 2 --- start template query44.tpl query 52 in stream 2 -select /* TPC-DS query44.tpl 0.4 */ asceding.rnk, i1.i_product_name best_performing, i2.i_product_name worst_performing -from(select * - from (select item_sk,rank() over (order by rank_col asc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 809 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 809 - and ss_promo_sk is null - group by ss_store_sk))V1)V11 - where rnk < 11) asceding, - (select * - from (select item_sk,rank() over (order by rank_col desc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 809 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 809 - and ss_promo_sk is null - group by ss_store_sk))V2)V21 - where rnk < 11) descending, -item i1, -item i2 -where asceding.rnk = descending.rnk - and i1.i_item_sk=asceding.item_sk - and i2.i_item_sk=descending.item_sk -order by asceding.rnk -limit 100; - --- end template query44.tpl query 52 in stream 2 --- start template query50.tpl query 53 in stream 2 -select /* TPC-DS query50.tpl 0.60 */ - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 30) and - (sr_returned_date_sk - ss_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 60) and - (sr_returned_date_sk - ss_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 90) and - (sr_returned_date_sk - ss_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - store_sales - ,store_returns - ,store - ,date_dim d1 - ,date_dim d2 -where - d2.d_year = 2002 -and d2.d_moy = 10 -and ss_ticket_number = sr_ticket_number -and ss_item_sk = sr_item_sk -and ss_sold_date_sk = d1.d_date_sk -and sr_returned_date_sk = d2.d_date_sk -and ss_customer_sk = sr_customer_sk -and ss_store_sk = s_store_sk -group by - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -order by s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -limit 100; - --- end template query50.tpl query 53 in stream 2 --- start template query61.tpl query 54 in stream 2 -select /* TPC-DS query61.tpl 0.97 */ promotions,total,cast(promotions as decimal(15,4))/cast(total as decimal(15,4))*100 -from - (select sum(ss_ext_sales_price) promotions - from store_sales - ,store - ,promotion - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_promo_sk = p_promo_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -7 - and i_category = 'Electronics' - and (p_channel_dmail = 'Y' or p_channel_email = 'Y' or p_channel_tv = 'Y') - and s_gmt_offset = -7 - and d_year = 2000 - and d_moy = 12) promotional_sales, - (select sum(ss_ext_sales_price) total - from store_sales - ,store - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -7 - and i_category = 'Electronics' - and s_gmt_offset = -7 - and d_year = 2000 - and d_moy = 12) all_sales -order by promotions, total -limit 100; - --- end template query61.tpl query 54 in stream 2 --- start template query85.tpl query 55 in stream 2 -select /* TPC-DS query85.tpl 0.33 */ substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) - from web_sales, web_returns, web_page, customer_demographics cd1, - customer_demographics cd2, customer_address, date_dim, reason - where ws_web_page_sk = wp_web_page_sk - and ws_item_sk = wr_item_sk - and ws_order_number = wr_order_number - and ws_sold_date_sk = d_date_sk and d_year = 2000 - and cd1.cd_demo_sk = wr_refunded_cdemo_sk - and cd2.cd_demo_sk = wr_returning_cdemo_sk - and ca_address_sk = wr_refunded_addr_sk - and r_reason_sk = wr_reason_sk - and - ( - ( - cd1.cd_marital_status = 'D' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = '2 yr Degree' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 100.00 and 150.00 - ) - or - ( - cd1.cd_marital_status = 'M' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'College' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 50.00 and 100.00 - ) - or - ( - cd1.cd_marital_status = 'W' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Secondary' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ca_country = 'United States' - and - ca_state in ('IN', 'IA', 'NY') - and ws_net_profit between 100 and 200 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('NE', 'IL', 'FL') - and ws_net_profit between 150 and 300 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('TX', 'NJ', 'ND') - and ws_net_profit between 50 and 250 - ) - ) -group by r_reason_desc -order by substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) -limit 100; - --- end template query85.tpl query 55 in stream 2 --- start template query73.tpl query 56 in stream 2 -select /* TPC-DS query73.tpl 0.79 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_buy_potential = '>10000' or - household_demographics.hd_buy_potential = 'Unknown') - and household_demographics.hd_vehicle_count > 0 - and case when household_demographics.hd_vehicle_count > 0 then - household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count else null end > 1 - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_county in ('Dutchess County','Forsyth County','Stafford County','Appanoose County') - group by ss_ticket_number,ss_customer_sk) dj,customer - where ss_customer_sk = c_customer_sk - and cnt between 1 and 5 - order by cnt desc, c_last_name asc; - --- end template query73.tpl query 56 in stream 2 --- start template query95.tpl query 57 in stream 2 -with /* TPC-DS query95.tpl 0.43 */ ws_wh as -(select ws1.ws_order_number,ws1.ws_warehouse_sk wh1,ws2.ws_warehouse_sk wh2 - from web_sales ws1,web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) - select - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2002-3-01' and - dateadd(day,60,cast('2002-3-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'TN' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and ws1.ws_order_number in (select ws_order_number - from ws_wh) -and ws1.ws_order_number in (select wr_order_number - from web_returns,ws_wh - where wr_order_number = ws_wh.ws_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query95.tpl query 57 in stream 2 --- start template query84.tpl query 58 in stream 2 -select /* TPC-DS query84.tpl 0.80 */ c_customer_id as customer_id - , coalesce(c_last_name,'') || ', ' || coalesce(c_first_name,'') as customername - from customer - ,customer_address - ,customer_demographics - ,household_demographics - ,income_band - ,store_returns - where ca_city = 'Florence' - and c_current_addr_sk = ca_address_sk - and ib_lower_bound >= 36654 - and ib_upper_bound <= 36654 + 50000 - and ib_income_band_sk = hd_income_band_sk - and cd_demo_sk = c_current_cdemo_sk - and hd_demo_sk = c_current_hdemo_sk - and sr_cdemo_sk = cd_demo_sk - order by c_customer_id - limit 100; - --- end template query84.tpl query 58 in stream 2 --- start template query4.tpl query 59 in stream 2 -with /* TPC-DS query4.tpl 0.93 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(((ss_ext_list_price-ss_ext_wholesale_cost-ss_ext_discount_amt)+ss_ext_sales_price)/2) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((cs_ext_list_price-cs_ext_wholesale_cost-cs_ext_discount_amt)+cs_ext_sales_price)/2) ) year_total - ,'c' sale_type - from customer - ,catalog_sales - ,date_dim - where c_customer_sk = cs_bill_customer_sk - and cs_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year -union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((ws_ext_list_price-ws_ext_wholesale_cost-ws_ext_discount_amt)+ws_ext_sales_price)/2) ) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_login - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_c_firstyear - ,year_total t_c_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_c_secyear.customer_id - and t_s_firstyear.customer_id = t_c_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_c_firstyear.sale_type = 'c' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_c_secyear.sale_type = 'c' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 1998 - and t_s_secyear.dyear = 1998+1 - and t_c_firstyear.dyear = 1998 - and t_c_secyear.dyear = 1998+1 - and t_w_firstyear.dyear = 1998 - and t_w_secyear.dyear = 1998+1 - and t_s_firstyear.year_total > 0 - and t_c_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_login -limit 100; - --- end template query4.tpl query 59 in stream 2 --- start template query37.tpl query 60 in stream 2 -select /* TPC-DS query37.tpl 0.31 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, catalog_sales - where i_current_price between 33 and 33 + 30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('1998-03-13' as date) and dateadd(day,60,cast('1998-03-13' as date)) - and i_manufact_id in (996,760,827,721) - and inv_quantity_on_hand between 100 and 500 - and cs_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query37.tpl query 60 in stream 2 --- start template query35a.tpl query 61 in stream 2 -select /* TPC-DS query35a.tpl 0.47 */ - ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - count(*) cnt1, - stddev_samp(cd_dep_count), - sum(cd_dep_count), - avg(cd_dep_count), - cd_dep_employed_count, - count(*) cnt2, - stddev_samp(cd_dep_employed_count), - sum(cd_dep_employed_count), - avg(cd_dep_employed_count), - cd_dep_college_count, - count(*) cnt3, - stddev_samp(cd_dep_college_count), - sum(cd_dep_college_count), - avg(cd_dep_college_count) - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 1999 and - d_qoy < 4) and - exists (select * from - (select ws_bill_customer_sk customsk - from web_sales,date_dim - where - ws_sold_date_sk = d_date_sk and - d_year = 1999 and - d_qoy < 4 - union all - select cs_ship_customer_sk customsk - from catalog_sales,date_dim - where - cs_sold_date_sk = d_date_sk and - d_year = 1999 and - d_qoy < 4)x - where x.customsk = c.c_customer_sk) - group by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - limit 100; - --- end template query35a.tpl query 61 in stream 2 --- start template query94.tpl query 62 in stream 2 -select /* TPC-DS query94.tpl 0.17 */ - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2002-5-01' and - dateadd(day,60,cast('2002-5-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'WY' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and exists (select * - from web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) -and not exists(select * - from web_returns wr1 - where ws1.ws_order_number = wr1.wr_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query94.tpl query 62 in stream 2 --- start template query58.tpl query 63 in stream 2 -with /* TPC-DS query58.tpl 0.19 */ ss_items as - (select i_item_id item_id - ,sum(ss_ext_sales_price) ss_item_rev - from store_sales - ,item - ,date_dim - where ss_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '1999-06-13')) - and ss_sold_date_sk = d_date_sk - group by i_item_id), - cs_items as - (select i_item_id item_id - ,sum(cs_ext_sales_price) cs_item_rev - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '1999-06-13')) - and cs_sold_date_sk = d_date_sk - group by i_item_id), - ws_items as - (select i_item_id item_id - ,sum(ws_ext_sales_price) ws_item_rev - from web_sales - ,item - ,date_dim - where ws_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq =(select d_week_seq - from date_dim - where d_date = '1999-06-13')) - and ws_sold_date_sk = d_date_sk - group by i_item_id) - select ss_items.item_id - ,ss_item_rev - ,ss_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ss_dev - ,cs_item_rev - ,cs_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 cs_dev - ,ws_item_rev - ,ws_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ws_dev - ,(ss_item_rev+cs_item_rev+ws_item_rev)/3 average - from ss_items,cs_items,ws_items - where ss_items.item_id=cs_items.item_id - and ss_items.item_id=ws_items.item_id - and ss_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - and ss_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and cs_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and cs_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and ws_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and ws_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - order by item_id - ,ss_item_rev - limit 100; - --- end template query58.tpl query 63 in stream 2 --- start template query96.tpl query 64 in stream 2 -select /* TPC-DS query96.tpl 0.1 */ count(*) -from store_sales - ,household_demographics - ,time_dim, store -where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 15 - and time_dim.t_minute >= 30 - and household_demographics.hd_dep_count = 6 - and store.s_store_name = 'ese' -order by count(*) -limit 100; - --- end template query96.tpl query 64 in stream 2 --- start template query12.tpl query 65 in stream 2 -select /* TPC-DS query12.tpl 0.64 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ws_ext_sales_price) as itemrevenue - ,sum(ws_ext_sales_price)*100/sum(sum(ws_ext_sales_price)) over - (partition by i_class) as revenueratio -from - web_sales - ,item - ,date_dim -where - ws_item_sk = i_item_sk - and i_category in ('Women', 'Shoes', 'Music') - and ws_sold_date_sk = d_date_sk - and d_date between cast('2001-06-10' as date) - and dateadd(day,30,cast('2001-06-10' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query12.tpl query 65 in stream 2 --- start template query29.tpl query 66 in stream 2 -select /* TPC-DS query29.tpl 0.53 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,max(ss_quantity) as store_sales_quantity - ,max(sr_return_quantity) as store_returns_quantity - ,max(cs_quantity) as catalog_sales_quantity - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 1999 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 4 + 3 - and d2.d_year = 1999 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_year in (1999,1999+1,1999+2) - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query29.tpl query 66 in stream 2 --- start template query22a.tpl query 67 in stream 2 -with /* TPC-DS query22a.tpl 0.55 */ results as -(select i_product_name - ,i_brand - ,i_class - ,i_category - ,avg(inv_quantity_on_hand) qoh - from inventory - ,date_dim - ,item --- ,warehouse - where inv_date_sk=d_date_sk - and inv_item_sk=i_item_sk --- and inv_warehouse_sk = w_warehouse_sk - and d_month_seq between 1190 and 1190 + 11 - group by i_product_name,i_brand,i_class,i_category), -results_rollup as -(select i_product_name, i_brand, i_class, i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class,i_category -union all -select i_product_name, i_brand, i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class -union all -select i_product_name, i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand -union all -select i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name -union all -select null i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results) - select i_product_name, i_brand, i_class, i_category,qoh - from results_rollup - order by qoh, i_product_name, i_brand, i_class, i_category -limit 100; - --- end template query22a.tpl query 67 in stream 2 --- start template query51.tpl query 68 in stream 2 -WITH /* TPC-DS query51.tpl 0.46 */ web_v1 as ( -select - ws_item_sk item_sk, d_date, - sum(sum(ws_sales_price)) - over (partition by ws_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from web_sales - ,date_dim -where ws_sold_date_sk=d_date_sk - and d_month_seq between 1208 and 1208+11 - and ws_item_sk is not NULL -group by ws_item_sk, d_date), -store_v1 as ( -select - ss_item_sk item_sk, d_date, - sum(sum(ss_sales_price)) - over (partition by ss_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from store_sales - ,date_dim -where ss_sold_date_sk=d_date_sk - and d_month_seq between 1208 and 1208+11 - and ss_item_sk is not NULL -group by ss_item_sk, d_date) - select * -from (select item_sk - ,d_date - ,web_sales - ,store_sales - ,max(web_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) web_cumulative - ,max(store_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) store_cumulative - from (select case when web.item_sk is not null then web.item_sk else store.item_sk end item_sk - ,case when web.d_date is not null then web.d_date else store.d_date end d_date - ,web.cume_sales web_sales - ,store.cume_sales store_sales - from web_v1 web full outer join store_v1 store on (web.item_sk = store.item_sk - and web.d_date = store.d_date) - )x )y -where web_cumulative > store_cumulative -order by item_sk - ,d_date -limit 100; - --- end template query51.tpl query 68 in stream 2 --- start template query36a.tpl query 69 in stream 2 -with /* TPC-DS query36a.tpl 0.21 */ results as - (select - sum(ss_net_profit) as ss_net_profit, sum(ss_ext_sales_price) as ss_ext_sales_price, - sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin - ,i_category - ,i_class - ,0 as g_category, 0 as g_class - from - store_sales - ,date_dim d1 - ,item - ,store - where - d1.d_year = 2002 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and s_state in ('NM','WA','MI','TN', - 'MN','TN','AL','SC') - group by i_category,i_class) - , - results_rollup as - (select gross_margin ,i_category ,i_class,0 as t_category, 0 as t_class, 0 as lochierarchy from results - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - i_category, NULL AS i_class, 0 as t_category, 1 as t_class, 1 as lochierarchy from results group by i_category - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - NULL AS i_category ,NULL AS i_class, 1 as t_category, 1 as t_class, 2 as lochierarchy from results) - select - gross_margin ,i_category ,i_class, lochierarchy,rank() over ( - partition by lochierarchy, case when t_class = 0 then i_category end - order by gross_margin asc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then i_category end - ,rank_within_parent - limit 100; - --- end template query36a.tpl query 69 in stream 2 --- start template query43.tpl query 70 in stream 2 -select /* TPC-DS query43.tpl 0.15 */ s_store_name, s_store_id, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from date_dim, store_sales, store - where d_date_sk = ss_sold_date_sk and - s_store_sk = ss_store_sk and - s_gmt_offset = -5 and - d_year = 2002 - group by s_store_name, s_store_id - order by s_store_name, s_store_id,sun_sales,mon_sales,tue_sales,wed_sales,thu_sales,fri_sales,sat_sales - limit 100; - --- end template query43.tpl query 70 in stream 2 --- start template query64.tpl query 71 in stream 2 -with /* TPC-DS query64.tpl 0.20 */ cs_ui as - (select cs_item_sk - ,sum(cs_ext_list_price) as sale,sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit) as refund - from catalog_sales - ,catalog_returns - where cs_item_sk = cr_item_sk - and cs_order_number = cr_order_number - group by cs_item_sk - having sum(cs_ext_list_price)>2*sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit)), -cross_sales as - (select i_product_name product_name - ,i_item_sk item_sk - ,s_store_name store_name - ,s_zip store_zip - ,ad1.ca_street_number b_street_number - ,ad1.ca_street_name b_street_name - ,ad1.ca_city b_city - ,ad1.ca_zip b_zip - ,ad2.ca_street_number c_street_number - ,ad2.ca_street_name c_street_name - ,ad2.ca_city c_city - ,ad2.ca_zip c_zip - ,d1.d_year as syear - ,d2.d_year as fsyear - ,d3.d_year s2year - ,count(*) cnt - ,sum(ss_wholesale_cost) s1 - ,sum(ss_list_price) s2 - ,sum(ss_coupon_amt) s3 - FROM store_sales - ,store_returns - ,cs_ui - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,customer - ,customer_demographics cd1 - ,customer_demographics cd2 - ,promotion - ,household_demographics hd1 - ,household_demographics hd2 - ,customer_address ad1 - ,customer_address ad2 - ,income_band ib1 - ,income_band ib2 - ,item - WHERE ss_store_sk = s_store_sk AND - ss_sold_date_sk = d1.d_date_sk AND - ss_customer_sk = c_customer_sk AND - ss_cdemo_sk= cd1.cd_demo_sk AND - ss_hdemo_sk = hd1.hd_demo_sk AND - ss_addr_sk = ad1.ca_address_sk and - ss_item_sk = i_item_sk and - ss_item_sk = sr_item_sk and - ss_ticket_number = sr_ticket_number and - ss_item_sk = cs_ui.cs_item_sk and - c_current_cdemo_sk = cd2.cd_demo_sk AND - c_current_hdemo_sk = hd2.hd_demo_sk AND - c_current_addr_sk = ad2.ca_address_sk and - c_first_sales_date_sk = d2.d_date_sk and - c_first_shipto_date_sk = d3.d_date_sk and - ss_promo_sk = p_promo_sk and - hd1.hd_income_band_sk = ib1.ib_income_band_sk and - hd2.hd_income_band_sk = ib2.ib_income_band_sk and - cd1.cd_marital_status <> cd2.cd_marital_status and - i_color in ('hot','frosted','cornsilk','almond','turquoise','chartreuse') and - i_current_price between 43 and 43 + 10 and - i_current_price between 43 + 1 and 43 + 15 -group by i_product_name - ,i_item_sk - ,s_store_name - ,s_zip - ,ad1.ca_street_number - ,ad1.ca_street_name - ,ad1.ca_city - ,ad1.ca_zip - ,ad2.ca_street_number - ,ad2.ca_street_name - ,ad2.ca_city - ,ad2.ca_zip - ,d1.d_year - ,d2.d_year - ,d3.d_year -) -select cs1.product_name - ,cs1.store_name - ,cs1.store_zip - ,cs1.b_street_number - ,cs1.b_street_name - ,cs1.b_city - ,cs1.b_zip - ,cs1.c_street_number - ,cs1.c_street_name - ,cs1.c_city - ,cs1.c_zip - ,cs1.syear - ,cs1.cnt - ,cs1.s1 as s11 - ,cs1.s2 as s21 - ,cs1.s3 as s31 - ,cs2.s1 as s12 - ,cs2.s2 as s22 - ,cs2.s3 as s32 - ,cs2.syear - ,cs2.cnt -from cross_sales cs1,cross_sales cs2 -where cs1.item_sk=cs2.item_sk and - cs1.syear = 2000 and - cs2.syear = 2000 + 1 and - cs2.cnt <= cs1.cnt and - cs1.store_name = cs2.store_name and - cs1.store_zip = cs2.store_zip -order by cs1.product_name - ,cs1.store_name - ,cs2.cnt - ,cs1.s1 - ,cs2.s1; - --- end template query64.tpl query 71 in stream 2 --- start template query20.tpl query 72 in stream 2 -select /* TPC-DS query20.tpl 0.65 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(cs_ext_sales_price) as itemrevenue - ,sum(cs_ext_sales_price)*100/sum(sum(cs_ext_sales_price)) over - (partition by i_class) as revenueratio - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and i_category in ('Jewelry', 'Home', 'Electronics') - and cs_sold_date_sk = d_date_sk - and d_date between cast('1998-01-30' as date) - and dateadd(day,30,cast('1998-01-30' as date)) - group by i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - order by i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query20.tpl query 72 in stream 2 --- start template query57.tpl query 73 in stream 2 -with /* TPC-DS query57.tpl 0.70 */ v1 as( - select i_category, i_brand, - cc_name, - d_year, d_moy, - sum(cs_sales_price) sum_sales, - avg(sum(cs_sales_price)) over - (partition by i_category, i_brand, - cc_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - cc_name - order by d_year, d_moy) rn - from item, catalog_sales, date_dim, call_center - where cs_item_sk = i_item_sk and - cs_sold_date_sk = d_date_sk and - cc_call_center_sk= cs_call_center_sk and - ( - d_year = 2001 or - ( d_year = 2001-1 and d_moy =12) or - ( d_year = 2001+1 and d_moy =1) - ) - group by i_category, i_brand, - cc_name , d_year, d_moy), - v2 as( - select v1.cc_name - ,v1.d_year - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1. cc_name = v1_lag. cc_name and - v1. cc_name = v1_lead. cc_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 2001 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, nsum - limit 100; - --- end template query57.tpl query 73 in stream 2 --- start template query9.tpl query 74 in stream 2 -select /* TPC-DS query9.tpl 0.49 */ case when (select count(*) - from store_sales - where ss_quantity between 1 and 20) > 1367954516 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 1 and 20) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 1 and 20) end bucket1 , - case when (select count(*) - from store_sales - where ss_quantity between 21 and 40) > 846121970 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 21 and 40) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 21 and 40) end bucket2, - case when (select count(*) - from store_sales - where ss_quantity between 41 and 60) > 610625567 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 41 and 60) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 41 and 60) end bucket3, - case when (select count(*) - from store_sales - where ss_quantity between 61 and 80) > 1013435592 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 61 and 80) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 61 and 80) end bucket4, - case when (select count(*) - from store_sales - where ss_quantity between 81 and 100) > 67777199 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 81 and 100) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 81 and 100) end bucket5 -from reason -where r_reason_sk = 1 -; - --- end template query9.tpl query 74 in stream 2 --- start template query52.tpl query 75 in stream 2 -select /* TPC-DS query52.tpl 0.59 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_sales_price) ext_price - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=12 - and dt.d_year=2002 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,ext_price desc - ,brand_id -limit 100 ; - --- end template query52.tpl query 75 in stream 2 --- start template query49.tpl query 76 in stream 2 -select /* TPC-DS query49.tpl 0.48 */ channel, item, return_ratio, return_rank, currency_rank from - (select - 'web' as channel - ,web.item - ,web.return_ratio - ,web.return_rank - ,web.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select ws.ws_item_sk as item - ,(cast(sum(coalesce(wr.wr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(wr.wr_return_amt,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - web_sales ws left outer join web_returns wr - on (ws.ws_order_number = wr.wr_order_number and - ws.ws_item_sk = wr.wr_item_sk) - ,date_dim - where - wr.wr_return_amt > 10000 - and ws.ws_net_profit > 1 - and ws.ws_net_paid > 0 - and ws.ws_quantity > 0 - and ws_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 11 - group by ws.ws_item_sk - ) in_web - ) web - where - ( - web.return_rank <= 10 - or - web.currency_rank <= 10 - ) - union - select - 'catalog' as channel - ,catalog.item - ,catalog.return_ratio - ,catalog.return_rank - ,catalog.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select - cs.cs_item_sk as item - ,(cast(sum(coalesce(cr.cr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(cr.cr_return_amount,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - catalog_sales cs left outer join catalog_returns cr - on (cs.cs_order_number = cr.cr_order_number and - cs.cs_item_sk = cr.cr_item_sk) - ,date_dim - where - cr.cr_return_amount > 10000 - and cs.cs_net_profit > 1 - and cs.cs_net_paid > 0 - and cs.cs_quantity > 0 - and cs_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 11 - group by cs.cs_item_sk - ) in_cat - ) catalog - where - ( - catalog.return_rank <= 10 - or - catalog.currency_rank <=10 - ) - union - select - 'store' as channel - ,store.item - ,store.return_ratio - ,store.return_rank - ,store.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select sts.ss_item_sk as item - ,(cast(sum(coalesce(sr.sr_return_quantity,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(sr.sr_return_amt,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - store_sales sts left outer join store_returns sr - on (sts.ss_ticket_number = sr.sr_ticket_number and sts.ss_item_sk = sr.sr_item_sk) - ,date_dim - where - sr.sr_return_amt > 10000 - and sts.ss_net_profit > 1 - and sts.ss_net_paid > 0 - and sts.ss_quantity > 0 - and ss_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 11 - group by sts.ss_item_sk - ) in_store - ) store - where ( - store.return_rank <= 10 - or - store.currency_rank <= 10 - ) - ) - order by 1,4,5,2 - limit 100; - --- end template query49.tpl query 76 in stream 2 --- start template query71.tpl query 77 in stream 2 -select /* TPC-DS query71.tpl 0.72 */ i_brand_id brand_id, i_brand brand,t_hour,t_minute, - sum(ext_price) ext_price - from item, (select ws_ext_sales_price as ext_price, - ws_sold_date_sk as sold_date_sk, - ws_item_sk as sold_item_sk, - ws_sold_time_sk as time_sk - from web_sales,date_dim - where d_date_sk = ws_sold_date_sk - and d_moy=12 - and d_year=1998 - union all - select cs_ext_sales_price as ext_price, - cs_sold_date_sk as sold_date_sk, - cs_item_sk as sold_item_sk, - cs_sold_time_sk as time_sk - from catalog_sales,date_dim - where d_date_sk = cs_sold_date_sk - and d_moy=12 - and d_year=1998 - union all - select ss_ext_sales_price as ext_price, - ss_sold_date_sk as sold_date_sk, - ss_item_sk as sold_item_sk, - ss_sold_time_sk as time_sk - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - and d_moy=12 - and d_year=1998 - ) tmp,time_dim - where - sold_item_sk = i_item_sk - and i_manager_id=1 - and time_sk = t_time_sk - and (t_meal_time = 'breakfast' or t_meal_time = 'dinner') - group by i_brand, i_brand_id,t_hour,t_minute - order by ext_price desc, i_brand_id - ; - --- end template query71.tpl query 77 in stream 2 --- start template query72.tpl query 78 in stream 2 -select /* TPC-DS query72.tpl 0.87 */ i_item_desc - ,w_warehouse_name - ,d1.d_week_seq - ,sum(case when p_promo_sk is null then 1 else 0 end) no_promo - ,sum(case when p_promo_sk is not null then 1 else 0 end) promo - ,count(*) total_cnt -from catalog_sales -join inventory on (cs_item_sk = inv_item_sk) -join warehouse on (w_warehouse_sk=inv_warehouse_sk) -join item on (i_item_sk = cs_item_sk) -join customer_demographics on (cs_bill_cdemo_sk = cd_demo_sk) -join household_demographics on (cs_bill_hdemo_sk = hd_demo_sk) -join date_dim d1 on (cs_sold_date_sk = d1.d_date_sk) -join date_dim d2 on (inv_date_sk = d2.d_date_sk) -join date_dim d3 on (cs_ship_date_sk = d3.d_date_sk) -left outer join promotion on (cs_promo_sk=p_promo_sk) -left outer join catalog_returns on (cr_item_sk = cs_item_sk and cr_order_number = cs_order_number) -where d1.d_week_seq = d2.d_week_seq - and inv_quantity_on_hand < cs_quantity - and d3.d_date > d1.d_date + 5 - and hd_buy_potential = '1001-5000' - and d1.d_year = 2001 - and cd_marital_status = 'D' -group by i_item_desc,w_warehouse_name,d1.d_week_seq -order by total_cnt desc, i_item_desc, w_warehouse_name, d_week_seq -limit 100; - --- end template query72.tpl query 78 in stream 2 --- start template query70a.tpl query 79 in stream 2 -with /* TPC-DS query70a.tpl 0.34 */ results as -( select - sum(ss_net_profit) as total_sum ,s_state ,s_county, 0 as gstate, 0 as g_county - from - store_sales - ,date_dim d1 - ,store - where - d1.d_month_seq between 1195 and 1195 + 11 - and d1.d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - and s_state in - ( select s_state - from (select s_state as s_state, - rank() over ( partition by s_state order by sum(ss_net_profit) desc) as ranking - from store_sales, store, date_dim - where d_month_seq between 1195 and 1195 + 11 - and d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - group by s_state - ) tmp1 - where ranking <= 5) - group by s_state,s_county) , - results_rollup as -(select total_sum ,s_state ,s_county, 0 as g_state, 0 as g_county, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum,s_state, NULL as s_county, 0 as g_state, 1 as g_county, 1 as lochierarchy from results group by s_state - union - select sum(total_sum) as total_sum ,NULL as s_state ,NULL as s_county, 1 as g_state, 1 as g_county, 2 as lochierarchy from results) - select total_sum ,s_state ,s_county, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_county = 0 then s_state end - order by total_sum desc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then s_state end - ,rank_within_parent - limit 100; - --- end template query70a.tpl query 79 in stream 2 --- start template query7.tpl query 80 in stream 2 -select /* TPC-DS query7.tpl 0.2 */ i_item_id, - avg(ss_quantity) agg1, - avg(ss_list_price) agg2, - avg(ss_coupon_amt) agg3, - avg(ss_sales_price) agg4 - from store_sales, customer_demographics, date_dim, item, promotion - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_cdemo_sk = cd_demo_sk and - ss_promo_sk = p_promo_sk and - cd_gender = 'M' and - cd_marital_status = 'W' and - cd_education_status = 'Primary' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 1998 - group by i_item_id - order by i_item_id - limit 100; - --- end template query7.tpl query 80 in stream 2 --- start template query97.tpl query 81 in stream 2 -with /* TPC-DS query97.tpl 0.38 */ ssci as ( -select ss_customer_sk customer_sk - ,ss_item_sk item_sk -from store_sales,date_dim -where ss_sold_date_sk = d_date_sk - and d_month_seq between 1192 and 1192 + 11 -group by ss_customer_sk - ,ss_item_sk), -csci as( - select cs_bill_customer_sk customer_sk - ,cs_item_sk item_sk -from catalog_sales,date_dim -where cs_sold_date_sk = d_date_sk - and d_month_seq between 1192 and 1192 + 11 -group by cs_bill_customer_sk - ,cs_item_sk) - select sum(case when ssci.customer_sk is not null and csci.customer_sk is null then 1 else 0 end) store_only - ,sum(case when ssci.customer_sk is null and csci.customer_sk is not null then 1 else 0 end) catalog_only - ,sum(case when ssci.customer_sk is not null and csci.customer_sk is not null then 1 else 0 end) store_and_catalog -from ssci full outer join csci on (ssci.customer_sk=csci.customer_sk - and ssci.item_sk = csci.item_sk) -limit 100; - --- end template query97.tpl query 81 in stream 2 --- start template query33.tpl query 82 in stream 2 -with /* TPC-DS query33.tpl 0.22 */ ss as ( - select - i_manufact_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Sports')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 7 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_manufact_id), - cs as ( - select - i_manufact_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Sports')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 7 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_manufact_id), - ws as ( - select - i_manufact_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Sports')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 7 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_manufact_id) - select i_manufact_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_manufact_id - order by total_sales -limit 100; - --- end template query33.tpl query 82 in stream 2 --- start template query79.tpl query 83 in stream 2 -select /* TPC-DS query79.tpl 0.89 */ - c_last_name,c_first_name,substring(s_city,1,30),ss_ticket_number,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,store.s_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (household_demographics.hd_dep_count = 7 or household_demographics.hd_vehicle_count > 1) - and date_dim.d_dow = 1 - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_number_employees between 200 and 295 - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,store.s_city) ms,customer - where ss_customer_sk = c_customer_sk - order by c_last_name,c_first_name,substring(s_city,1,30), profit -limit 100; - --- end template query79.tpl query 83 in stream 2 --- start template query32.tpl query 84 in stream 2 -select /* TPC-DS query32.tpl 0.7 */ sum(cs_ext_discount_amt) as "excess discount amount" -from - catalog_sales - ,item - ,date_dim -where -i_manufact_id = 961 -and i_item_sk = cs_item_sk -and d_date between '2001-03-18' and - dateadd(day,90,cast('2001-03-18' as date)) -and d_date_sk = cs_sold_date_sk -and cs_ext_discount_amt - > ( - select - 1.3 * avg(cs_ext_discount_amt) - from - catalog_sales - ,date_dim - where - cs_item_sk = i_item_sk - and d_date between '2001-03-18' and - dateadd(day,90,cast('2001-03-18' as date)) - and d_date_sk = cs_sold_date_sk - ) -limit 100; - --- end template query32.tpl query 84 in stream 2 --- start template query78.tpl query 85 in stream 2 -with /* TPC-DS query78.tpl 0.10 */ ws as - (select d_year AS ws_sold_year, ws_item_sk, - ws_bill_customer_sk ws_customer_sk, - sum(ws_quantity) ws_qty, - sum(ws_wholesale_cost) ws_wc, - sum(ws_sales_price) ws_sp - from web_sales - left join web_returns on wr_order_number=ws_order_number and ws_item_sk=wr_item_sk - join date_dim on ws_sold_date_sk = d_date_sk - where wr_order_number is null - group by d_year, ws_item_sk, ws_bill_customer_sk - ), -cs as - (select d_year AS cs_sold_year, cs_item_sk, - cs_bill_customer_sk cs_customer_sk, - sum(cs_quantity) cs_qty, - sum(cs_wholesale_cost) cs_wc, - sum(cs_sales_price) cs_sp - from catalog_sales - left join catalog_returns on cr_order_number=cs_order_number and cs_item_sk=cr_item_sk - join date_dim on cs_sold_date_sk = d_date_sk - where cr_order_number is null - group by d_year, cs_item_sk, cs_bill_customer_sk - ), -ss as - (select d_year AS ss_sold_year, ss_item_sk, - ss_customer_sk, - sum(ss_quantity) ss_qty, - sum(ss_wholesale_cost) ss_wc, - sum(ss_sales_price) ss_sp - from store_sales - left join store_returns on sr_ticket_number=ss_ticket_number and ss_item_sk=sr_item_sk - join date_dim on ss_sold_date_sk = d_date_sk - where sr_ticket_number is null - group by d_year, ss_item_sk, ss_customer_sk - ) - select -ss_sold_year, ss_item_sk, ss_customer_sk, -round(ss_qty/(coalesce(ws_qty,0)+coalesce(cs_qty,0)),2) ratio, -ss_qty store_qty, ss_wc store_wholesale_cost, ss_sp store_sales_price, -coalesce(ws_qty,0)+coalesce(cs_qty,0) other_chan_qty, -coalesce(ws_wc,0)+coalesce(cs_wc,0) other_chan_wholesale_cost, -coalesce(ws_sp,0)+coalesce(cs_sp,0) other_chan_sales_price -from ss -left join ws on (ws_sold_year=ss_sold_year and ws_item_sk=ss_item_sk and ws_customer_sk=ss_customer_sk) -left join cs on (cs_sold_year=ss_sold_year and cs_item_sk=ss_item_sk and cs_customer_sk=ss_customer_sk) -where (coalesce(ws_qty,0)>0 or coalesce(cs_qty, 0)>0) and ss_sold_year=2000 -order by - ss_sold_year, ss_item_sk, ss_customer_sk, - ss_qty desc, ss_wc desc, ss_sp desc, - other_chan_qty, - other_chan_wholesale_cost, - other_chan_sales_price, - ratio -limit 100; - --- end template query78.tpl query 85 in stream 2 --- start template query18a.tpl query 86 in stream 2 -with /* TPC-DS query18a.tpl 0.90 */ results as - (select i_item_id, - ca_country, - ca_state, - ca_county, - cast(cs_quantity as decimal(12,2)) agg1, - cast(cs_list_price as decimal(12,2)) agg2, - cast(cs_coupon_amt as decimal(12,2)) agg3, - cast(cs_sales_price as decimal(12,2)) agg4, - cast(cs_net_profit as decimal(12,2)) agg5, - cast(c_birth_year as decimal(12,2)) agg6, - cast(cd1.cd_dep_count as decimal(12,2)) agg7 - from catalog_sales, customer_demographics cd1, customer_demographics cd2, customer, customer_address, date_dim, item - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd1.cd_demo_sk and - cs_bill_customer_sk = c_customer_sk and - cd1.cd_gender = 'F' and - cd1.cd_education_status = 'Primary' and - c_current_cdemo_sk = cd2.cd_demo_sk and - c_current_addr_sk = ca_address_sk and - c_birth_month in (8,3,4,2,5,6) and - d_year = 1999 and - ca_state in ('IA','IN','WI','GA','KY','TN','TX') - ) - select i_item_id, ca_country, ca_state, ca_county, agg1, agg2, agg3, agg4, agg5, agg6, agg7 - from ( - select i_item_id, ca_country, ca_state, ca_county, avg(agg1) agg1, - avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state, ca_county - union all - select i_item_id, ca_country, ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state - union all - select i_item_id, ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country - union all - select i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - ) foo - order by ca_country, ca_state, ca_county, i_item_id - limit 100; - --- end template query18a.tpl query 86 in stream 2 --- start template query65.tpl query 87 in stream 2 -select /* TPC-DS query65.tpl 0.71 */ - s_store_name, - i_item_desc, - sc.revenue, - i_current_price, - i_wholesale_cost, - i_brand - from store, item, - (select ss_store_sk, avg(revenue) as ave - from - (select ss_store_sk, ss_item_sk, - sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1199 and 1199+11 - group by ss_store_sk, ss_item_sk) sa - group by ss_store_sk) sb, - (select ss_store_sk, ss_item_sk, sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1199 and 1199+11 - group by ss_store_sk, ss_item_sk) sc - where sb.ss_store_sk = sc.ss_store_sk and - sc.revenue <= 0.1 * sb.ave and - s_store_sk = sc.ss_store_sk and - i_item_sk = sc.ss_item_sk - order by s_store_name, i_item_desc -limit 100; - --- end template query65.tpl query 87 in stream 2 --- start template query60.tpl query 88 in stream 2 -with /* TPC-DS query60.tpl 0.29 */ ss as ( - select - i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Jewelry')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 9 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -7 - group by i_item_id), - cs as ( - select - i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Jewelry')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 9 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -7 - group by i_item_id), - ws as ( - select - i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Jewelry')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 9 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -7 - group by i_item_id) - select - i_item_id -,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by i_item_id - ,total_sales - limit 100; - --- end template query60.tpl query 88 in stream 2 --- start template query34.tpl query 89 in stream 2 -select /* TPC-DS query34.tpl 0.73 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (date_dim.d_dom between 1 and 3 or date_dim.d_dom between 25 and 28) - and (household_demographics.hd_buy_potential = '>10000' or - household_demographics.hd_buy_potential = 'Unknown') - and household_demographics.hd_vehicle_count > 0 - and (case when household_demographics.hd_vehicle_count > 0 - then household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count - else null - end) > 1.2 - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_county in ('Perry County','San Miguel County','Levy County','Rush County', - 'Henry County','Tolland County','Carter County','Quay County') - group by ss_ticket_number,ss_customer_sk) dn,customer - where ss_customer_sk = c_customer_sk - and cnt between 15 and 20 - order by c_last_name,c_first_name,c_salutation,c_preferred_cust_flag desc, ss_ticket_number; - --- end template query34.tpl query 89 in stream 2 --- start template query3.tpl query 90 in stream 2 -select /* TPC-DS query3.tpl 0.45 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_sales_price) sum_agg - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manufact_id = 253 - and dt.d_moy=12 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,sum_agg desc - ,brand_id - limit 100; - --- end template query3.tpl query 90 in stream 2 --- start template query13.tpl query 91 in stream 2 -select /* TPC-DS query13.tpl 0.91 */ avg(ss_quantity) - ,avg(ss_ext_sales_price) - ,avg(ss_ext_wholesale_cost) - ,sum(ss_ext_wholesale_cost) - from store_sales - ,store - ,customer_demographics - ,household_demographics - ,customer_address - ,date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2001 - and((ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'D' - and cd_education_status = '4 yr Degree' - and ss_sales_price between 100.00 and 150.00 - and hd_dep_count = 3 - )or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'W' - and cd_education_status = 'Primary' - and ss_sales_price between 50.00 and 100.00 - and hd_dep_count = 1 - ) or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'U' - and cd_education_status = '2 yr Degree' - and ss_sales_price between 150.00 and 200.00 - and hd_dep_count = 1 - )) - and((ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('NE', 'NV', 'MA') - and ss_net_profit between 100 and 200 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('OR', 'ND', 'TX') - and ss_net_profit between 150 and 300 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('MO', 'IN', 'TN') - and ss_net_profit between 50 and 250 - )) -; - --- end template query13.tpl query 91 in stream 2 --- start template query41.tpl query 92 in stream 2 -select /* TPC-DS query41.tpl 0.62 */ distinct(i_product_name) - from item i1 - where i_manufact_id between 780 and 780+40 - and (select count(*) as item_cnt - from item - where (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'purple' or i_color = 'sky') and - (i_units = 'Tsp' or i_units = 'Tbl') and - (i_size = 'small' or i_size = 'large') - ) or - (i_category = 'Women' and - (i_color = 'ivory' or i_color = 'deep') and - (i_units = 'Gram' or i_units = 'Bundle') and - (i_size = 'N/A' or i_size = 'medium') - ) or - (i_category = 'Men' and - (i_color = 'rose' or i_color = 'plum') and - (i_units = 'Case' or i_units = 'Dram') and - (i_size = 'petite' or i_size = 'economy') - ) or - (i_category = 'Men' and - (i_color = 'cyan' or i_color = 'powder') and - (i_units = 'Unknown' or i_units = 'Ounce') and - (i_size = 'small' or i_size = 'large') - ))) or - (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'goldenrod' or i_color = 'turquoise') and - (i_units = 'Gross' or i_units = 'Cup') and - (i_size = 'small' or i_size = 'large') - ) or - (i_category = 'Women' and - (i_color = 'tomato' or i_color = 'ghost') and - (i_units = 'Box' or i_units = 'Oz') and - (i_size = 'N/A' or i_size = 'medium') - ) or - (i_category = 'Men' and - (i_color = 'floral' or i_color = 'magenta') and - (i_units = 'N/A' or i_units = 'Carton') and - (i_size = 'petite' or i_size = 'economy') - ) or - (i_category = 'Men' and - (i_color = 'thistle' or i_color = 'blanched') and - (i_units = 'Pallet' or i_units = 'Each') and - (i_size = 'small' or i_size = 'large') - )))) > 0 - order by i_product_name - limit 100; - --- end template query41.tpl query 92 in stream 2 --- start template query92.tpl query 93 in stream 2 -select /* TPC-DS query92.tpl 0.44 */ - sum(ws_ext_discount_amt) as "Excess Discount Amount" -from - web_sales - ,item - ,date_dim -where -i_manufact_id = 557 -and i_item_sk = ws_item_sk -and d_date between '2001-01-30' and - dateadd(day,90,cast('2001-01-30' as date)) -and d_date_sk = ws_sold_date_sk -and ws_ext_discount_amt - > ( - SELECT - 1.3 * avg(ws_ext_discount_amt) - FROM - web_sales - ,date_dim - WHERE - ws_item_sk = i_item_sk - and d_date between '2001-01-30' and - dateadd(day,90,cast('2001-01-30' as date)) - and d_date_sk = ws_sold_date_sk - ) -order by sum(ws_ext_discount_amt) -limit 100; - --- end template query92.tpl query 93 in stream 2 --- start template query74.tpl query 94 in stream 2 -with /* TPC-DS query74.tpl 0.76 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,min(ss_net_paid) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (2001,2001+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,min(ws_net_paid) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - and d_year in (2001,2001+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - ) - select - t_s_secyear.customer_id, t_s_secyear.customer_first_name, t_s_secyear.customer_last_name - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.year = 2001 - and t_s_secyear.year = 2001+1 - and t_w_firstyear.year = 2001 - and t_w_secyear.year = 2001+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - order by 1,2,3 -limit 100; - --- end template query74.tpl query 94 in stream 2 --- start template query46.tpl query 95 in stream 2 -select /* TPC-DS query46.tpl 0.23 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and (household_demographics.hd_dep_count = 5 or - household_demographics.hd_vehicle_count= -1) - and date_dim.d_dow in (6,0) - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_city in ('Douglas','Lowell','Oak Hill','Washington','Eureka') - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,ca_city) dn,customer,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - limit 100; - --- end template query46.tpl query 95 in stream 2 --- start template query89.tpl query 96 in stream 2 -select /* TPC-DS query89.tpl 0.56 */ * -from( -select i_category, i_class, i_brand, - s_store_name, s_company_name, - d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, s_store_name, s_company_name) - avg_monthly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - d_year in (2001) and - ((i_category in ('Shoes','Books','Music') and - i_class in ('athletic','parenting','country') - ) - or (i_category in ('Women','Electronics','Jewelry') and - i_class in ('maternity','personal','womens watch') - )) -group by i_category, i_class, i_brand, - s_store_name, s_company_name, d_moy) tmp1 -where case when (avg_monthly_sales <> 0) then (abs(sum_sales - avg_monthly_sales) / avg_monthly_sales) else null end > 0.1 -order by sum_sales - avg_monthly_sales, s_store_name -limit 100; - --- end template query89.tpl query 96 in stream 2 --- start template query47.tpl query 97 in stream 2 -with /* TPC-DS query47.tpl 0.42 */ v1 as( - select i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, - s_store_name, s_company_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - s_store_name, s_company_name - order by d_year, d_moy) rn - from item, store_sales, date_dim, store - where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - ( - d_year = 2001 or - ( d_year = 2001-1 and d_moy =12) or - ( d_year = 2001+1 and d_moy =1) - ) - group by i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy), - v2 as( - select v1.i_category - ,v1.d_year, v1.d_moy - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1.s_store_name = v1_lag.s_store_name and - v1.s_store_name = v1_lead.s_store_name and - v1.s_company_name = v1_lag.s_company_name and - v1.s_company_name = v1_lead.s_company_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 2001 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, psum - limit 100; - --- end template query47.tpl query 97 in stream 2 --- start template query66.tpl query 98 in stream 2 -select /* TPC-DS query66.tpl 0.39 */ - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - ,sum(jan_sales) as jan_sales - ,sum(feb_sales) as feb_sales - ,sum(mar_sales) as mar_sales - ,sum(apr_sales) as apr_sales - ,sum(may_sales) as may_sales - ,sum(jun_sales) as jun_sales - ,sum(jul_sales) as jul_sales - ,sum(aug_sales) as aug_sales - ,sum(sep_sales) as sep_sales - ,sum(oct_sales) as oct_sales - ,sum(nov_sales) as nov_sales - ,sum(dec_sales) as dec_sales - ,sum(jan_sales/w_warehouse_sq_ft) as jan_sales_per_sq_foot - ,sum(feb_sales/w_warehouse_sq_ft) as feb_sales_per_sq_foot - ,sum(mar_sales/w_warehouse_sq_ft) as mar_sales_per_sq_foot - ,sum(apr_sales/w_warehouse_sq_ft) as apr_sales_per_sq_foot - ,sum(may_sales/w_warehouse_sq_ft) as may_sales_per_sq_foot - ,sum(jun_sales/w_warehouse_sq_ft) as jun_sales_per_sq_foot - ,sum(jul_sales/w_warehouse_sq_ft) as jul_sales_per_sq_foot - ,sum(aug_sales/w_warehouse_sq_ft) as aug_sales_per_sq_foot - ,sum(sep_sales/w_warehouse_sq_ft) as sep_sales_per_sq_foot - ,sum(oct_sales/w_warehouse_sq_ft) as oct_sales_per_sq_foot - ,sum(nov_sales/w_warehouse_sq_ft) as nov_sales_per_sq_foot - ,sum(dec_sales/w_warehouse_sq_ft) as dec_sales_per_sq_foot - ,sum(jan_net) as jan_net - ,sum(feb_net) as feb_net - ,sum(mar_net) as mar_net - ,sum(apr_net) as apr_net - ,sum(may_net) as may_net - ,sum(jun_net) as jun_net - ,sum(jul_net) as jul_net - ,sum(aug_net) as aug_net - ,sum(sep_net) as sep_net - ,sum(oct_net) as oct_net - ,sum(nov_net) as nov_net - ,sum(dec_net) as dec_net - from ( - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'FEDEX' || ',' || 'MSC' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then ws_sales_price* ws_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then ws_sales_price* ws_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then ws_sales_price* ws_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then ws_sales_price* ws_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then ws_sales_price* ws_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then ws_sales_price* ws_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then ws_sales_price* ws_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then ws_sales_price* ws_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then ws_sales_price* ws_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then ws_sales_price* ws_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then ws_sales_price* ws_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then ws_sales_price* ws_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then ws_net_paid * ws_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then ws_net_paid * ws_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then ws_net_paid * ws_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then ws_net_paid * ws_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then ws_net_paid * ws_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then ws_net_paid * ws_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then ws_net_paid * ws_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then ws_net_paid * ws_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then ws_net_paid * ws_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then ws_net_paid * ws_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then ws_net_paid * ws_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then ws_net_paid * ws_quantity else 0 end) as dec_net - from - web_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - ws_warehouse_sk = w_warehouse_sk - and ws_sold_date_sk = d_date_sk - and ws_sold_time_sk = t_time_sk - and ws_ship_mode_sk = sm_ship_mode_sk - and d_year = 2000 - and t_time between 17905 and 17905+28800 - and sm_carrier in ('FEDEX','MSC') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - union all - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'FEDEX' || ',' || 'MSC' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then cs_sales_price* cs_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then cs_sales_price* cs_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then cs_sales_price* cs_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then cs_sales_price* cs_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then cs_sales_price* cs_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then cs_sales_price* cs_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then cs_sales_price* cs_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then cs_sales_price* cs_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then cs_sales_price* cs_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then cs_sales_price* cs_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then cs_sales_price* cs_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then cs_sales_price* cs_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as dec_net - from - catalog_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and cs_sold_time_sk = t_time_sk - and cs_ship_mode_sk = sm_ship_mode_sk - and d_year = 2000 - and t_time between 17905 AND 17905+28800 - and sm_carrier in ('FEDEX','MSC') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - ) x - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - order by w_warehouse_name - limit 100; - --- end template query66.tpl query 98 in stream 2 --- start template query48.tpl query 99 in stream 2 -select /* TPC-DS query48.tpl 0.74 */ sum (ss_quantity) - from store_sales, store, customer_demographics, customer_address, date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2002 - and - ( - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'M' - and - cd_education_status = 'Secondary' - and - ss_sales_price between 100.00 and 150.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'S' - and - cd_education_status = 'Primary' - and - ss_sales_price between 50.00 and 100.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'U' - and - cd_education_status = 'College' - and - ss_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('TX', 'MT', 'MO') - and ss_net_profit between 0 and 2000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('AL', 'MS', 'ID') - and ss_net_profit between 150 and 3000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('NC', 'IA', 'LA') - and ss_net_profit between 50 and 25000 - ) - ) -; - --- end template query48.tpl query 99 in stream 2 diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/30TB/queries/query_3.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/30TB/queries/query_3.sql deleted file mode 100644 index e20ec532..00000000 --- a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/30TB/queries/query_3.sql +++ /dev/null @@ -1,5027 +0,0 @@ --- start template query89.tpl query 1 in stream 3 -select /* TPC-DS query89.tpl 0.56 */ * -from( -select i_category, i_class, i_brand, - s_store_name, s_company_name, - d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, s_store_name, s_company_name) - avg_monthly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - d_year in (2002) and - ((i_category in ('Men','Children','Music') and - i_class in ('pants','infants','classical') - ) - or (i_category in ('Women','Sports','Home') and - i_class in ('swimwear','pools','lighting') - )) -group by i_category, i_class, i_brand, - s_store_name, s_company_name, d_moy) tmp1 -where case when (avg_monthly_sales <> 0) then (abs(sum_sales - avg_monthly_sales) / avg_monthly_sales) else null end > 0.1 -order by sum_sales - avg_monthly_sales, s_store_name -limit 100; - --- end template query89.tpl query 1 in stream 3 --- start template query5a.tpl query 2 in stream 3 -with /* TPC-DS query5a.tpl 0.98 */ ssr as - (select s_store_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ss_store_sk as store_sk, - ss_sold_date_sk as date_sk, - ss_ext_sales_price as sales_price, - ss_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from store_sales - union all - select sr_store_sk as store_sk, - sr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - sr_return_amt as return_amt, - sr_net_loss as net_loss - from store_returns - ) salesreturns, - date_dim, - store - where date_sk = d_date_sk - and d_date between cast('1999-08-09' as date) - and dateadd(day,14,cast('1999-08-09' as date)) - and store_sk = s_store_sk - group by s_store_id) - , - csr as - (select cp_catalog_page_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select cs_catalog_page_sk as page_sk, - cs_sold_date_sk as date_sk, - cs_ext_sales_price as sales_price, - cs_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from catalog_sales - union all - select cr_catalog_page_sk as page_sk, - cr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - cr_return_amount as return_amt, - cr_net_loss as net_loss - from catalog_returns - ) salesreturns, - date_dim, - catalog_page - where date_sk = d_date_sk - and d_date between cast('1999-08-09' as date) - and dateadd(day,14,cast('1999-08-09' as date)) - and page_sk = cp_catalog_page_sk - group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ws_web_site_sk as wsr_web_site_sk, - ws_sold_date_sk as date_sk, - ws_ext_sales_price as sales_price, - ws_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from web_sales - union all - select ws_web_site_sk as wsr_web_site_sk, - wr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - wr_return_amt as return_amt, - wr_net_loss as net_loss - from web_returns left outer join web_sales on - ( wr_item_sk = ws_item_sk - and wr_order_number = ws_order_number) - ) salesreturns, - date_dim, - web_site - where date_sk = d_date_sk - and d_date between cast('1999-08-09' as date) - and dateadd(day,14,cast('1999-08-09' as date)) - and wsr_web_site_sk = web_site_sk - group by web_site_id) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || s_store_id as id - , sales - , returns - , (profit - profit_loss) as profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || cp_catalog_page_id as id - , sales - , returns - , (profit - profit_loss) as profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , (profit - profit_loss) as profit - from wsr - ) x - group by channel, id) - select channel, id, sales, returns, profit from ( - select channel, id, sales, returns, profit from results - union - select channel, null as id, sum(sales), sum(returns), sum(profit) from results group by channel - union - select null as channel, null as id, sum(sales), sum(returns), sum(profit) from results) foo -order by channel, id -limit 100; - --- end template query5a.tpl query 2 in stream 3 --- start template query52.tpl query 3 in stream 3 -select /* TPC-DS query52.tpl 0.59 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_sales_price) ext_price - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=11 - and dt.d_year=2002 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,ext_price desc - ,brand_id -limit 100 ; - --- end template query52.tpl query 3 in stream 3 --- start template query62.tpl query 4 in stream 3 -select /* TPC-DS query62.tpl 0.24 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 30) and - (ws_ship_date_sk - ws_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 60) and - (ws_ship_date_sk - ws_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 90) and - (ws_ship_date_sk - ws_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - web_sales - ,warehouse - ,ship_mode - ,web_site - ,date_dim -where - d_month_seq between 1181 and 1181 + 11 -and ws_ship_date_sk = d_date_sk -and ws_warehouse_sk = w_warehouse_sk -and ws_ship_mode_sk = sm_ship_mode_sk -and ws_web_site_sk = web_site_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -limit 100; - --- end template query62.tpl query 4 in stream 3 --- start template query53.tpl query 5 in stream 3 -select /* TPC-DS query53.tpl 0.88 */ * from -(select i_manufact_id, -sum(ss_sales_price) sum_sales, -avg(sum(ss_sales_price)) over (partition by i_manufact_id) avg_quarterly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and -ss_sold_date_sk = d_date_sk and -ss_store_sk = s_store_sk and -d_month_seq in (1190,1190+1,1190+2,1190+3,1190+4,1190+5,1190+6,1190+7,1190+8,1190+9,1190+10,1190+11) and -((i_category in ('Books','Children','Electronics') and -i_class in ('personal','portable','reference','self-help') and -i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) -or(i_category in ('Women','Music','Men') and -i_class in ('accessories','classical','fragrances','pants') and -i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manufact_id, d_qoy ) tmp1 -where case when avg_quarterly_sales > 0 - then abs (sum_sales - avg_quarterly_sales)/ avg_quarterly_sales - else null end > 0.1 -order by avg_quarterly_sales, - sum_sales, - i_manufact_id -limit 100; - --- end template query53.tpl query 5 in stream 3 --- start template query7.tpl query 6 in stream 3 -select /* TPC-DS query7.tpl 0.2 */ i_item_id, - avg(ss_quantity) agg1, - avg(ss_list_price) agg2, - avg(ss_coupon_amt) agg3, - avg(ss_sales_price) agg4 - from store_sales, customer_demographics, date_dim, item, promotion - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_cdemo_sk = cd_demo_sk and - ss_promo_sk = p_promo_sk and - cd_gender = 'M' and - cd_marital_status = 'S' and - cd_education_status = '2 yr Degree' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 1998 - group by i_item_id - order by i_item_id - limit 100; - --- end template query7.tpl query 6 in stream 3 --- start template query39.tpl query 7 in stream 3 -with /* TPC-DS query39.tpl 0.5 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =1998 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=4 - and inv2.d_moy=4+1 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; -with /* TPC-DS query39.tpl 0.5 part2 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =1998 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=4 - and inv2.d_moy=4+1 - and inv1.cov > 1.5 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; - --- end template query39.tpl query 7 in stream 3 --- start template query80a.tpl query 8 in stream 3 -with /* TPC-DS query80a.tpl 0.6 */ ssr as - (select s_store_id as store_id, - sum(ss_ext_sales_price) as sales, - sum(coalesce(sr_return_amt, 0)) as returns, - sum(ss_net_profit - coalesce(sr_net_loss, 0)) as profit - from store_sales left outer join store_returns on - (ss_item_sk = sr_item_sk and ss_ticket_number = sr_ticket_number), - date_dim, - store, - item, - promotion - where ss_sold_date_sk = d_date_sk - and d_date between cast('1998-08-08' as date) - and dateadd(day,30,cast('1998-08-08' as date)) - and ss_store_sk = s_store_sk - and ss_item_sk = i_item_sk - and i_current_price > 50 - and ss_promo_sk = p_promo_sk - and p_channel_tv = 'N' - group by s_store_id) - , - csr as - (select cp_catalog_page_id as catalog_page_id, - sum(cs_ext_sales_price) as sales, - sum(coalesce(cr_return_amount, 0)) as returns, - sum(cs_net_profit - coalesce(cr_net_loss, 0)) as profit - from catalog_sales left outer join catalog_returns on - (cs_item_sk = cr_item_sk and cs_order_number = cr_order_number), - date_dim, - catalog_page, - item, - promotion - where cs_sold_date_sk = d_date_sk - and d_date between cast('1998-08-08' as date) - and dateadd(day,30,cast('1998-08-08' as date)) - and cs_catalog_page_sk = cp_catalog_page_sk - and cs_item_sk = i_item_sk - and i_current_price > 50 - and cs_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(ws_ext_sales_price) as sales, - sum(coalesce(wr_return_amt, 0)) as returns, - sum(ws_net_profit - coalesce(wr_net_loss, 0)) as profit - from web_sales left outer join web_returns on - (ws_item_sk = wr_item_sk and ws_order_number = wr_order_number), - date_dim, - web_site, - item, - promotion - where ws_sold_date_sk = d_date_sk - and d_date between cast('1998-08-08' as date) - and dateadd(day,30,cast('1998-08-08' as date)) - and ws_web_site_sk = web_site_sk - and ws_item_sk = i_item_sk - and i_current_price > 50 - and ws_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by web_site_id) -, -results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || store_id as id - , sales - , returns - , profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || catalog_page_id as id - , sales - , returns - , profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , profit - from wsr - ) x - group by channel, id) - - select channel - , id - , sales - , returns - , profit - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results - ) foo - order by channel, id - limit 100; - --- end template query80a.tpl query 8 in stream 3 --- start template query63.tpl query 9 in stream 3 -select /* TPC-DS query63.tpl 0.27 */ * -from (select i_manager_id - ,sum(ss_sales_price) sum_sales - ,avg(sum(ss_sales_price)) over (partition by i_manager_id) avg_monthly_sales - from item - ,store_sales - ,date_dim - ,store - where ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and d_month_seq in (1195,1195+1,1195+2,1195+3,1195+4,1195+5,1195+6,1195+7,1195+8,1195+9,1195+10,1195+11) - and (( i_category in ('Books','Children','Electronics') - and i_class in ('personal','portable','reference','self-help') - and i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) - or( i_category in ('Women','Music','Men') - and i_class in ('accessories','classical','fragrances','pants') - and i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manager_id, d_moy) tmp1 -where case when avg_monthly_sales > 0 then abs (sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 -order by i_manager_id - ,avg_monthly_sales - ,sum_sales -limit 100; - --- end template query63.tpl query 9 in stream 3 --- start template query72.tpl query 10 in stream 3 -select /* TPC-DS query72.tpl 0.87 */ i_item_desc - ,w_warehouse_name - ,d1.d_week_seq - ,sum(case when p_promo_sk is null then 1 else 0 end) no_promo - ,sum(case when p_promo_sk is not null then 1 else 0 end) promo - ,count(*) total_cnt -from catalog_sales -join inventory on (cs_item_sk = inv_item_sk) -join warehouse on (w_warehouse_sk=inv_warehouse_sk) -join item on (i_item_sk = cs_item_sk) -join customer_demographics on (cs_bill_cdemo_sk = cd_demo_sk) -join household_demographics on (cs_bill_hdemo_sk = hd_demo_sk) -join date_dim d1 on (cs_sold_date_sk = d1.d_date_sk) -join date_dim d2 on (inv_date_sk = d2.d_date_sk) -join date_dim d3 on (cs_ship_date_sk = d3.d_date_sk) -left outer join promotion on (cs_promo_sk=p_promo_sk) -left outer join catalog_returns on (cr_item_sk = cs_item_sk and cr_order_number = cs_order_number) -where d1.d_week_seq = d2.d_week_seq - and inv_quantity_on_hand < cs_quantity - and d3.d_date > d1.d_date + 5 - and hd_buy_potential = '501-1000' - and d1.d_year = 2002 - and cd_marital_status = 'D' -group by i_item_desc,w_warehouse_name,d1.d_week_seq -order by total_cnt desc, i_item_desc, w_warehouse_name, d_week_seq -limit 100; - --- end template query72.tpl query 10 in stream 3 --- start template query18a.tpl query 11 in stream 3 -with /* TPC-DS query18a.tpl 0.90 */ results as - (select i_item_id, - ca_country, - ca_state, - ca_county, - cast(cs_quantity as decimal(12,2)) agg1, - cast(cs_list_price as decimal(12,2)) agg2, - cast(cs_coupon_amt as decimal(12,2)) agg3, - cast(cs_sales_price as decimal(12,2)) agg4, - cast(cs_net_profit as decimal(12,2)) agg5, - cast(c_birth_year as decimal(12,2)) agg6, - cast(cd1.cd_dep_count as decimal(12,2)) agg7 - from catalog_sales, customer_demographics cd1, customer_demographics cd2, customer, customer_address, date_dim, item - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd1.cd_demo_sk and - cs_bill_customer_sk = c_customer_sk and - cd1.cd_gender = 'M' and - cd1.cd_education_status = '4 yr Degree' and - c_current_cdemo_sk = cd2.cd_demo_sk and - c_current_addr_sk = ca_address_sk and - c_birth_month in (8,10,12,2,3,1) and - d_year = 1998 and - ca_state in ('MI','VA','IA','AL','MT','SC','WI') - ) - select i_item_id, ca_country, ca_state, ca_county, agg1, agg2, agg3, agg4, agg5, agg6, agg7 - from ( - select i_item_id, ca_country, ca_state, ca_county, avg(agg1) agg1, - avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state, ca_county - union all - select i_item_id, ca_country, ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state - union all - select i_item_id, ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country - union all - select i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - ) foo - order by ca_country, ca_state, ca_county, i_item_id - limit 100; - --- end template query18a.tpl query 11 in stream 3 --- start template query56.tpl query 12 in stream 3 -with /* TPC-DS query56.tpl 0.83 */ ss as ( - select i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where i_item_id in (select - i_item_id -from item -where i_color in ('chiffon','magenta','tomato')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 2 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id), - cs as ( - select i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('chiffon','magenta','tomato')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 2 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id), - ws as ( - select i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('chiffon','magenta','tomato')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 2 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id) - select i_item_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by total_sales, - i_item_id - limit 100; - --- end template query56.tpl query 12 in stream 3 --- start template query13.tpl query 13 in stream 3 -select /* TPC-DS query13.tpl 0.91 */ avg(ss_quantity) - ,avg(ss_ext_sales_price) - ,avg(ss_ext_wholesale_cost) - ,sum(ss_ext_wholesale_cost) - from store_sales - ,store - ,customer_demographics - ,household_demographics - ,customer_address - ,date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2001 - and((ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'W' - and cd_education_status = '4 yr Degree' - and ss_sales_price between 100.00 and 150.00 - and hd_dep_count = 3 - )or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'M' - and cd_education_status = 'Unknown' - and ss_sales_price between 50.00 and 100.00 - and hd_dep_count = 1 - ) or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'U' - and cd_education_status = 'Secondary' - and ss_sales_price between 150.00 and 200.00 - and hd_dep_count = 1 - )) - and((ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('MS', 'OH', 'MO') - and ss_net_profit between 100 and 200 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('IL', 'KS', 'OK') - and ss_net_profit between 150 and 300 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('WA', 'UT', 'CA') - and ss_net_profit between 50 and 250 - )) -; - --- end template query13.tpl query 13 in stream 3 --- start template query69.tpl query 14 in stream 3 -select /* TPC-DS query69.tpl 0.28 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_state in ('IA','MN','WV') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 1999 and - d_moy between 3 and 3+2) and - (not exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 1999 and - d_moy between 3 and 3+2) and - not exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 1999 and - d_moy between 3 and 3+2)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - limit 100; - --- end template query69.tpl query 14 in stream 3 --- start template query23.tpl query 15 in stream 3 -with /* TPC-DS query23.tpl 0.68 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (2000,2000+1,2000+2,2000+3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (2000,2000+1,2000+2,2000+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * -from - max_store_sales)) - select sum(sales) - from (select cs_quantity*cs_list_price sales - from catalog_sales - ,date_dim - where d_year = 2000 - and d_moy = 6 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - union all - select ws_quantity*ws_list_price sales - from web_sales - ,date_dim - where d_year = 2000 - and d_moy = 6 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer)) - limit 100; -with /* TPC-DS query23.tpl 0.68 part2 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (2000,2000 + 1,2000 + 2,2000 + 3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (2000,2000+1,2000+2,2000+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * - from max_store_sales)) - select c_last_name,c_first_name,sales - from (select c_last_name,c_first_name,sum(cs_quantity*cs_list_price) sales - from catalog_sales - ,customer - ,date_dim - where d_year = 2000 - and d_moy = 6 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and cs_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name - union all - select c_last_name,c_first_name,sum(ws_quantity*ws_list_price) sales - from web_sales - ,customer - ,date_dim - where d_year = 2000 - and d_moy = 6 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and ws_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name) - order by c_last_name,c_first_name,sales - limit 100; - --- end template query23.tpl query 15 in stream 3 --- start template query19.tpl query 16 in stream 3 -select /* TPC-DS query19.tpl 0.8 */ i_brand_id brand_id, i_brand brand, i_manufact_id, i_manufact, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item,customer,customer_address,store - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=29 - and d_moy=11 - and d_year=1998 - and ss_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and substring(ca_zip,1,5) <> substring(s_zip,1,5) - and ss_store_sk = s_store_sk - group by i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact - order by ext_price desc - ,i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact -limit 100 ; - --- end template query19.tpl query 16 in stream 3 --- start template query74.tpl query 17 in stream 3 -with /* TPC-DS query74.tpl 0.76 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,max(ss_net_paid) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1999,1999+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,max(ws_net_paid) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - and d_year in (1999,1999+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - ) - select - t_s_secyear.customer_id, t_s_secyear.customer_first_name, t_s_secyear.customer_last_name - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.year = 1999 - and t_s_secyear.year = 1999+1 - and t_w_firstyear.year = 1999 - and t_w_secyear.year = 1999+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - order by 1,3,2 -limit 100; - --- end template query74.tpl query 17 in stream 3 --- start template query30.tpl query 18 in stream 3 -with /* TPC-DS query30.tpl 0.75 */ customer_total_return as - (select wr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(wr_return_amt) as ctr_total_return - from web_returns - ,date_dim - ,customer_address - where wr_returned_date_sk = d_date_sk - and d_year =1999 - and wr_returning_addr_sk = ca_address_sk - group by wr_returning_customer_sk - ,ca_state) - select c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'PA' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return -limit 100; - --- end template query30.tpl query 18 in stream 3 --- start template query84.tpl query 19 in stream 3 -select /* TPC-DS query84.tpl 0.80 */ c_customer_id as customer_id - , coalesce(c_last_name,'') || ', ' || coalesce(c_first_name,'') as customername - from customer - ,customer_address - ,customer_demographics - ,household_demographics - ,income_band - ,store_returns - where ca_city = 'Clifton' - and c_current_addr_sk = ca_address_sk - and ib_lower_bound >= 28170 - and ib_upper_bound <= 28170 + 50000 - and ib_income_band_sk = hd_income_band_sk - and cd_demo_sk = c_current_cdemo_sk - and hd_demo_sk = c_current_hdemo_sk - and sr_cdemo_sk = cd_demo_sk - order by c_customer_id - limit 100; - --- end template query84.tpl query 19 in stream 3 --- start template query96.tpl query 20 in stream 3 -select /* TPC-DS query96.tpl 0.1 */ count(*) -from store_sales - ,household_demographics - ,time_dim, store -where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 15 - and time_dim.t_minute >= 30 - and household_demographics.hd_dep_count = 0 - and store.s_store_name = 'ese' -order by count(*) -limit 100; - --- end template query96.tpl query 20 in stream 3 --- start template query14a.tpl query 21 in stream 3 -with /* TPC-DS query14a.tpl 0.69 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 2000 AND 2000 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 2000 AND 2000 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 2000 AND 2000 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as - (select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2) x) -, - results AS -(select channel, i_brand_id, i_class_id, i_category_id, sum(sales) sum_sales, sum(number_sales) number_sales - from ( - select 'store' channel, i_brand_id,i_class_id - ,i_category_id,sum(ss_quantity*ss_list_price) sales - , count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2000+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales) - union all - select 'catalog' channel, i_brand_id,i_class_id,i_category_id, sum(cs_quantity*cs_list_price) sales, count(*) number_sales - from catalog_sales - ,item - ,date_dim - where cs_item_sk in (select ss_item_sk from cross_items) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2000+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(cs_quantity*cs_list_price) > (select average_sales from avg_sales) - union all - select 'web' channel, i_brand_id,i_class_id,i_category_id, sum(ws_quantity*ws_list_price) sales , count(*) number_sales - from web_sales - ,item - ,date_dim - where ws_item_sk in (select ss_item_sk from cross_items) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2000+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ws_quantity*ws_list_price) > (select average_sales from avg_sales) - ) y - group by channel, i_brand_id,i_class_id,i_category_id) - - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales -from ( - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales from results - union - select channel, i_brand_id, i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id, i_class_id - union - select channel, i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id - union - select channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel - union - select null as channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results) z -order by channel, i_brand_id, i_class_id, i_category_id - limit 100; -with /* TPC-DS query14a.tpl 0.69 part2 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 2000 AND 2000 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 2000 AND 2000 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 2000 AND 2000 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as -(select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2) x) - select this_year.channel ty_channel - ,this_year.i_brand_id ty_brand - ,this_year.i_class_id ty_class - ,this_year.i_category_id ty_category - ,this_year.sales ty_sales - ,this_year.number_sales ty_number_sales - ,last_year.channel ly_channel - ,last_year.i_brand_id ly_brand - ,last_year.i_class_id ly_class - ,last_year.i_category_id ly_category - ,last_year.sales ly_sales - ,last_year.number_sales ly_number_sales -from - (select 'store' channel, i_brand_id,i_class_id,i_category_id - ,sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 2000 + 1 - and d_moy = 12 - and d_dom = 11) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) this_year, - (select 'store' channel, i_brand_id,i_class_id - ,i_category_id, sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 2000 - and d_moy = 12 - and d_dom = 11) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) last_year - where this_year.i_brand_id= last_year.i_brand_id - and this_year.i_class_id = last_year.i_class_id - and this_year.i_category_id = last_year.i_category_id - order by this_year.channel, this_year.i_brand_id, this_year.i_class_id, this_year.i_category_id - limit 100; - --- end template query14a.tpl query 21 in stream 3 --- start template query10.tpl query 22 in stream 3 -select /* TPC-DS query10.tpl 0.26 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3, - cd_dep_count, - count(*) cnt4, - cd_dep_employed_count, - count(*) cnt5, - cd_dep_college_count, - count(*) cnt6 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_county in ('Cherokee County','Lynchburg city','Covington County','Pratt County','Chouteau County') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 2 and 2+3) and - (exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 2 ANd 2+3) or - exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 2 and 2+3)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count -limit 100; - --- end template query10.tpl query 22 in stream 3 --- start template query86a.tpl query 23 in stream 3 -with /* TPC-DS query86a.tpl 0.11 */ results as -( select sum(ws_net_paid) as total_sum, i_category, i_class, 0 as g_category, 0 as g_class - from - web_sales - ,date_dim d1 - ,item - where - d1.d_month_seq between 1182 and 1182+11 - and d1.d_date_sk = ws_sold_date_sk - and i_item_sk = ws_item_sk - group by i_category,i_class - ) , - - results_rollup as -( select total_sum ,i_category ,i_class, g_category, g_class, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum, i_category, NULL as i_class, 0 as g_category, 1 as g_class, 1 as lochierarchy from results group by i_category - union - select sum(total_sum) as total_sum, NULL as i_category, NULL as i_class, 1 as g_category, 1 as g_class, 2 as lochierarchy from results) - select - total_sum ,i_category ,i_class, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_class = 0 then i_category end - order by total_sum desc) as rank_within_parent - from - results_rollup - order by - lochierarchy desc, - case when lochierarchy = 0 then i_category end, - rank_within_parent - limit 100; - --- end template query86a.tpl query 23 in stream 3 --- start template query94.tpl query 24 in stream 3 -select /* TPC-DS query94.tpl 0.17 */ - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2000-3-01' and - dateadd(day,60,cast('2000-3-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'TX' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and exists (select * - from web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) -and not exists(select * - from web_returns wr1 - where ws1.ws_order_number = wr1.wr_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query94.tpl query 24 in stream 3 --- start template query8.tpl query 25 in stream 3 -select /* TPC-DS query8.tpl 0.63 */ s_store_name - ,sum(ss_net_profit) - from store_sales - ,date_dim - ,store, - (select ca_zip - from ( - SELECT substring(ca_zip,1,5) ca_zip - FROM customer_address - WHERE substring(ca_zip,1,5) IN ( - '26892','67210','39699','78970','55435','80057', - '35729','30873','16002','47763','19957', - '89847','24461','91354','14930','64810', - '36480','86387','18588','18178','62500', - '49119','52071','92672','48569','77029', - '31665','44142','32015','57936','69735', - '44425','94856','14213','39912','21803', - '38666','17447','22891','43005','49194', - '91083','59735','83785','65995','22516', - '30419','29638','16916','70821','11802', - '21932','92557','57142','52876','45091', - '65578','16858','88620','78683','70826', - '61108','73706','94104','39628','40024', - '95084','12354','95207','27029','90461', - '78121','26439','40345','10802','56720', - '30673','37309','66111','58045','48859', - '26592','56193','64519','68413','65555', - '49362','70584','26898','42528','74278', - '19723','62156','43982','31366','12200', - '44718','79556','48751','28938','22328', - '19695','14820','14325','72090','91064', - '71305','32121','89425','31384','59859', - '94364','69549','13113','96860','50407', - '78410','32541','56702','47432','88294', - '47952','86809','41614','22699','14724', - '77781','79088','37608','14154','69245', - '65909','73062','43772','24148','27931', - '38491','65585','97124','15338','34045', - '40697','63899','11595','35257','77641', - '48858','18368','41491','50290','73431', - '46381','96309','74091','48016','35820', - '89541','44560','27106','34225','53929', - '41725','85413','30329','30177','34405', - '37561','82441','73351','86881','98468', - '31806','39847','38712','13961','91060', - '87379','19448','54241','74934','73448', - '10731','68895','72438','40532','68878', - '35578','51687','46076','18188','56787', - '93661','30965','18145','22377','55231', - '52146','35949','17294','76296','86449', - '81927','14696','59684','89997','35714', - '78244','64635','73490','88890','71118', - '32933','69846','71814','96803','67973', - '86529','67061','19122','61753','16434', - '75101','56049','59521','48693','75717', - '36016','95832','96573','59881','33695', - '59646','18882','43722','46457','17657', - '16376','79445','80936','75287','29712', - '48973','51435','82733','12399','47095', - '57186','30322','15392','54809','62564', - '51033','14215','46219','30008','69076', - '73413','52483','41406','44997','72612', - '93227','54789','70335','94560','55787', - '39391','19321','72733','20833','17289', - '25180','19206','98657','71583','91692', - '22257','32518','98942','65273','98707', - '18852','79802','44213','38859','90116', - '61954','42266','23290','84426','57843', - '94594','24469','92143','97716','97241', - '13216','81919','94405','28564','31014', - '10463','21557','95585','45720','24439', - '84174','84649','50344','84824','25923', - '62569','55756','85629','72874','77000', - '83535','35289','31491','57932','91261', - '15787','37957','38818','50414','79263', - '40566','66012','78333','72769','18561', - '13903','57979','42451','57549','70543', - '37505','28557','70725','32956','36394', - '68615','49997','63709','43078','82919', - '34072','22052','68630','48790','66539', - '44858','41608','68844','68024','38159', - '53061','44854','99972','65750','29616', - '76084','11240','57221','99371','63427', - '75010','79093','56394','50020','60828', - '33538','66447','87873','34295','16181', - '46257','48609','22862','66020','59213', - '66977','45929','21135','10607','86478', - '48337','43553','90539','75831','90100', - '55541','15089','68955','40626','53753', - '69012','82937','22844','84222') - intersect - select ca_zip - from (SELECT substring(ca_zip,1,5) ca_zip,count(*) cnt - FROM customer_address, customer - WHERE ca_address_sk = c_current_addr_sk and - c_preferred_cust_flag='Y' - group by ca_zip - having count(*) > 10)A1)A2) V1 - where ss_store_sk = s_store_sk - and ss_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 1998 - and (substring(s_zip,1,2) = substring(V1.ca_zip,1,2)) - group by s_store_name - order by s_store_name - limit 100; - --- end template query8.tpl query 25 in stream 3 --- start template query87.tpl query 26 in stream 3 -select /* TPC-DS query87.tpl 0.77 */ count(*) -from ((select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1218 and 1218+11) - except - (select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1218 and 1218+11) - except - (select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1218 and 1218+11) -) cool_cust -; - --- end template query87.tpl query 26 in stream 3 --- start template query58.tpl query 27 in stream 3 -with /* TPC-DS query58.tpl 0.19 */ ss_items as - (select i_item_id item_id - ,sum(ss_ext_sales_price) ss_item_rev - from store_sales - ,item - ,date_dim - where ss_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '1998-05-14')) - and ss_sold_date_sk = d_date_sk - group by i_item_id), - cs_items as - (select i_item_id item_id - ,sum(cs_ext_sales_price) cs_item_rev - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '1998-05-14')) - and cs_sold_date_sk = d_date_sk - group by i_item_id), - ws_items as - (select i_item_id item_id - ,sum(ws_ext_sales_price) ws_item_rev - from web_sales - ,item - ,date_dim - where ws_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq =(select d_week_seq - from date_dim - where d_date = '1998-05-14')) - and ws_sold_date_sk = d_date_sk - group by i_item_id) - select ss_items.item_id - ,ss_item_rev - ,ss_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ss_dev - ,cs_item_rev - ,cs_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 cs_dev - ,ws_item_rev - ,ws_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ws_dev - ,(ss_item_rev+cs_item_rev+ws_item_rev)/3 average - from ss_items,cs_items,ws_items - where ss_items.item_id=cs_items.item_id - and ss_items.item_id=ws_items.item_id - and ss_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - and ss_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and cs_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and cs_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and ws_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and ws_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - order by item_id - ,ss_item_rev - limit 100; - --- end template query58.tpl query 27 in stream 3 --- start template query36a.tpl query 28 in stream 3 -with /* TPC-DS query36a.tpl 0.21 */ results as - (select - sum(ss_net_profit) as ss_net_profit, sum(ss_ext_sales_price) as ss_ext_sales_price, - sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin - ,i_category - ,i_class - ,0 as g_category, 0 as g_class - from - store_sales - ,date_dim d1 - ,item - ,store - where - d1.d_year = 1998 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and s_state in ('SC','MI','GA','NE', - 'NM','NC','TN','FL') - group by i_category,i_class) - , - results_rollup as - (select gross_margin ,i_category ,i_class,0 as t_category, 0 as t_class, 0 as lochierarchy from results - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - i_category, NULL AS i_class, 0 as t_category, 1 as t_class, 1 as lochierarchy from results group by i_category - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - NULL AS i_category ,NULL AS i_class, 1 as t_category, 1 as t_class, 2 as lochierarchy from results) - select - gross_margin ,i_category ,i_class, lochierarchy,rank() over ( - partition by lochierarchy, case when t_class = 0 then i_category end - order by gross_margin asc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then i_category end - ,rank_within_parent - limit 100; - --- end template query36a.tpl query 28 in stream 3 --- start template query37.tpl query 29 in stream 3 -select /* TPC-DS query37.tpl 0.31 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, catalog_sales - where i_current_price between 19 and 19 + 30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('1999-03-14' as date) and dateadd(day,60,cast('1999-03-14' as date)) - and i_manufact_id in (788,737,870,670) - and inv_quantity_on_hand between 100 and 500 - and cs_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query37.tpl query 29 in stream 3 --- start template query4.tpl query 30 in stream 3 -with /* TPC-DS query4.tpl 0.93 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(((ss_ext_list_price-ss_ext_wholesale_cost-ss_ext_discount_amt)+ss_ext_sales_price)/2) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((cs_ext_list_price-cs_ext_wholesale_cost-cs_ext_discount_amt)+cs_ext_sales_price)/2) ) year_total - ,'c' sale_type - from customer - ,catalog_sales - ,date_dim - where c_customer_sk = cs_bill_customer_sk - and cs_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year -union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((ws_ext_list_price-ws_ext_wholesale_cost-ws_ext_discount_amt)+ws_ext_sales_price)/2) ) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_preferred_cust_flag - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_c_firstyear - ,year_total t_c_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_c_secyear.customer_id - and t_s_firstyear.customer_id = t_c_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_c_firstyear.sale_type = 'c' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_c_secyear.sale_type = 'c' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 2001 - and t_s_secyear.dyear = 2001+1 - and t_c_firstyear.dyear = 2001 - and t_c_secyear.dyear = 2001+1 - and t_w_firstyear.dyear = 2001 - and t_w_secyear.dyear = 2001+1 - and t_s_firstyear.year_total > 0 - and t_c_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_preferred_cust_flag -limit 100; - --- end template query4.tpl query 30 in stream 3 --- start template query38.tpl query 31 in stream 3 -select /* TPC-DS query38.tpl 0.54 */ count(*) from ( - select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1179 and 1179 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1179 and 1179 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1179 and 1179 + 11 -) hot_cust -limit 100; - --- end template query38.tpl query 31 in stream 3 --- start template query66.tpl query 32 in stream 3 -select /* TPC-DS query66.tpl 0.39 */ - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - ,sum(jan_sales) as jan_sales - ,sum(feb_sales) as feb_sales - ,sum(mar_sales) as mar_sales - ,sum(apr_sales) as apr_sales - ,sum(may_sales) as may_sales - ,sum(jun_sales) as jun_sales - ,sum(jul_sales) as jul_sales - ,sum(aug_sales) as aug_sales - ,sum(sep_sales) as sep_sales - ,sum(oct_sales) as oct_sales - ,sum(nov_sales) as nov_sales - ,sum(dec_sales) as dec_sales - ,sum(jan_sales/w_warehouse_sq_ft) as jan_sales_per_sq_foot - ,sum(feb_sales/w_warehouse_sq_ft) as feb_sales_per_sq_foot - ,sum(mar_sales/w_warehouse_sq_ft) as mar_sales_per_sq_foot - ,sum(apr_sales/w_warehouse_sq_ft) as apr_sales_per_sq_foot - ,sum(may_sales/w_warehouse_sq_ft) as may_sales_per_sq_foot - ,sum(jun_sales/w_warehouse_sq_ft) as jun_sales_per_sq_foot - ,sum(jul_sales/w_warehouse_sq_ft) as jul_sales_per_sq_foot - ,sum(aug_sales/w_warehouse_sq_ft) as aug_sales_per_sq_foot - ,sum(sep_sales/w_warehouse_sq_ft) as sep_sales_per_sq_foot - ,sum(oct_sales/w_warehouse_sq_ft) as oct_sales_per_sq_foot - ,sum(nov_sales/w_warehouse_sq_ft) as nov_sales_per_sq_foot - ,sum(dec_sales/w_warehouse_sq_ft) as dec_sales_per_sq_foot - ,sum(jan_net) as jan_net - ,sum(feb_net) as feb_net - ,sum(mar_net) as mar_net - ,sum(apr_net) as apr_net - ,sum(may_net) as may_net - ,sum(jun_net) as jun_net - ,sum(jul_net) as jul_net - ,sum(aug_net) as aug_net - ,sum(sep_net) as sep_net - ,sum(oct_net) as oct_net - ,sum(nov_net) as nov_net - ,sum(dec_net) as dec_net - from ( - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'PRIVATECARRIER' || ',' || 'LATVIAN' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then ws_ext_list_price* ws_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then ws_ext_list_price* ws_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then ws_ext_list_price* ws_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then ws_ext_list_price* ws_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then ws_ext_list_price* ws_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then ws_ext_list_price* ws_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then ws_ext_list_price* ws_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then ws_ext_list_price* ws_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then ws_ext_list_price* ws_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then ws_ext_list_price* ws_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then ws_ext_list_price* ws_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then ws_ext_list_price* ws_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as dec_net - from - web_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - ws_warehouse_sk = w_warehouse_sk - and ws_sold_date_sk = d_date_sk - and ws_sold_time_sk = t_time_sk - and ws_ship_mode_sk = sm_ship_mode_sk - and d_year = 1998 - and t_time between 36283 and 36283+28800 - and sm_carrier in ('PRIVATECARRIER','LATVIAN') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - union all - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'PRIVATECARRIER' || ',' || 'LATVIAN' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then cs_ext_sales_price* cs_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then cs_ext_sales_price* cs_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then cs_ext_sales_price* cs_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then cs_ext_sales_price* cs_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then cs_ext_sales_price* cs_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then cs_ext_sales_price* cs_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then cs_ext_sales_price* cs_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then cs_ext_sales_price* cs_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then cs_ext_sales_price* cs_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then cs_ext_sales_price* cs_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then cs_ext_sales_price* cs_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then cs_ext_sales_price* cs_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as dec_net - from - catalog_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and cs_sold_time_sk = t_time_sk - and cs_ship_mode_sk = sm_ship_mode_sk - and d_year = 1998 - and t_time between 36283 AND 36283+28800 - and sm_carrier in ('PRIVATECARRIER','LATVIAN') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - ) x - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - order by w_warehouse_name - limit 100; - --- end template query66.tpl query 32 in stream 3 --- start template query78.tpl query 33 in stream 3 -with /* TPC-DS query78.tpl 0.10 */ ws as - (select d_year AS ws_sold_year, ws_item_sk, - ws_bill_customer_sk ws_customer_sk, - sum(ws_quantity) ws_qty, - sum(ws_wholesale_cost) ws_wc, - sum(ws_sales_price) ws_sp - from web_sales - left join web_returns on wr_order_number=ws_order_number and ws_item_sk=wr_item_sk - join date_dim on ws_sold_date_sk = d_date_sk - where wr_order_number is null - group by d_year, ws_item_sk, ws_bill_customer_sk - ), -cs as - (select d_year AS cs_sold_year, cs_item_sk, - cs_bill_customer_sk cs_customer_sk, - sum(cs_quantity) cs_qty, - sum(cs_wholesale_cost) cs_wc, - sum(cs_sales_price) cs_sp - from catalog_sales - left join catalog_returns on cr_order_number=cs_order_number and cs_item_sk=cr_item_sk - join date_dim on cs_sold_date_sk = d_date_sk - where cr_order_number is null - group by d_year, cs_item_sk, cs_bill_customer_sk - ), -ss as - (select d_year AS ss_sold_year, ss_item_sk, - ss_customer_sk, - sum(ss_quantity) ss_qty, - sum(ss_wholesale_cost) ss_wc, - sum(ss_sales_price) ss_sp - from store_sales - left join store_returns on sr_ticket_number=ss_ticket_number and ss_item_sk=sr_item_sk - join date_dim on ss_sold_date_sk = d_date_sk - where sr_ticket_number is null - group by d_year, ss_item_sk, ss_customer_sk - ) - select -ss_item_sk, -round(ss_qty/(coalesce(ws_qty,0)+coalesce(cs_qty,0)),2) ratio, -ss_qty store_qty, ss_wc store_wholesale_cost, ss_sp store_sales_price, -coalesce(ws_qty,0)+coalesce(cs_qty,0) other_chan_qty, -coalesce(ws_wc,0)+coalesce(cs_wc,0) other_chan_wholesale_cost, -coalesce(ws_sp,0)+coalesce(cs_sp,0) other_chan_sales_price -from ss -left join ws on (ws_sold_year=ss_sold_year and ws_item_sk=ss_item_sk and ws_customer_sk=ss_customer_sk) -left join cs on (cs_sold_year=ss_sold_year and cs_item_sk=ss_item_sk and cs_customer_sk=ss_customer_sk) -where (coalesce(ws_qty,0)>0 or coalesce(cs_qty, 0)>0) and ss_sold_year=2001 -order by - ss_item_sk, - ss_qty desc, ss_wc desc, ss_sp desc, - other_chan_qty, - other_chan_wholesale_cost, - other_chan_sales_price, - ratio -limit 100; - --- end template query78.tpl query 33 in stream 3 --- start template query43.tpl query 34 in stream 3 -select /* TPC-DS query43.tpl 0.15 */ s_store_name, s_store_id, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from date_dim, store_sales, store - where d_date_sk = ss_sold_date_sk and - s_store_sk = ss_store_sk and - s_gmt_offset = -6 and - d_year = 1998 - group by s_store_name, s_store_id - order by s_store_name, s_store_id,sun_sales,mon_sales,tue_sales,wed_sales,thu_sales,fri_sales,sat_sales - limit 100; - --- end template query43.tpl query 34 in stream 3 --- start template query22a.tpl query 35 in stream 3 -with /* TPC-DS query22a.tpl 0.55 */ results as -(select i_product_name - ,i_brand - ,i_class - ,i_category - ,avg(inv_quantity_on_hand) qoh - from inventory - ,date_dim - ,item --- ,warehouse - where inv_date_sk=d_date_sk - and inv_item_sk=i_item_sk --- and inv_warehouse_sk = w_warehouse_sk - and d_month_seq between 1187 and 1187 + 11 - group by i_product_name,i_brand,i_class,i_category), -results_rollup as -(select i_product_name, i_brand, i_class, i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class,i_category -union all -select i_product_name, i_brand, i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class -union all -select i_product_name, i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand -union all -select i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name -union all -select null i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results) - select i_product_name, i_brand, i_class, i_category,qoh - from results_rollup - order by qoh, i_product_name, i_brand, i_class, i_category -limit 100; - --- end template query22a.tpl query 35 in stream 3 --- start template query21.tpl query 36 in stream 3 -select /* TPC-DS query21.tpl 0.14 */ * - from(select w_warehouse_name - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('2002-05-05' as date)) - then inv_quantity_on_hand - else 0 end) as inv_before - ,sum(case when (cast(d_date as date) >= cast ('2002-05-05' as date)) - then inv_quantity_on_hand - else 0 end) as inv_after - from inventory - ,warehouse - ,item - ,date_dim - where i_current_price between 0.99 and 1.49 - and i_item_sk = inv_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('2002-05-05' as date)) - and dateadd(day,30,cast ('2002-05-05' as date)) - group by w_warehouse_name, i_item_id) x - where (case when inv_before > 0 - then inv_after / inv_before - else null - end) between 2.0/3.0 and 3.0/2.0 - order by w_warehouse_name - ,i_item_id - limit 100; - --- end template query21.tpl query 36 in stream 3 --- start template query97.tpl query 37 in stream 3 -with /* TPC-DS query97.tpl 0.38 */ ssci as ( -select ss_customer_sk customer_sk - ,ss_item_sk item_sk -from store_sales,date_dim -where ss_sold_date_sk = d_date_sk - and d_month_seq between 1186 and 1186 + 11 -group by ss_customer_sk - ,ss_item_sk), -csci as( - select cs_bill_customer_sk customer_sk - ,cs_item_sk item_sk -from catalog_sales,date_dim -where cs_sold_date_sk = d_date_sk - and d_month_seq between 1186 and 1186 + 11 -group by cs_bill_customer_sk - ,cs_item_sk) - select sum(case when ssci.customer_sk is not null and csci.customer_sk is null then 1 else 0 end) store_only - ,sum(case when ssci.customer_sk is null and csci.customer_sk is not null then 1 else 0 end) catalog_only - ,sum(case when ssci.customer_sk is not null and csci.customer_sk is not null then 1 else 0 end) store_and_catalog -from ssci full outer join csci on (ssci.customer_sk=csci.customer_sk - and ssci.item_sk = csci.item_sk) -limit 100; - --- end template query97.tpl query 37 in stream 3 --- start template query47.tpl query 38 in stream 3 -with /* TPC-DS query47.tpl 0.42 */ v1 as( - select i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, - s_store_name, s_company_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - s_store_name, s_company_name - order by d_year, d_moy) rn - from item, store_sales, date_dim, store - where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - ( - d_year = 2001 or - ( d_year = 2001-1 and d_moy =12) or - ( d_year = 2001+1 and d_moy =1) - ) - group by i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy), - v2 as( - select v1.i_category, v1.i_brand, v1.s_store_name, v1.s_company_name - ,v1.d_year - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1.s_store_name = v1_lag.s_store_name and - v1.s_store_name = v1_lead.s_store_name and - v1.s_company_name = v1_lag.s_company_name and - v1.s_company_name = v1_lead.s_company_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 2001 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, nsum - limit 100; - --- end template query47.tpl query 38 in stream 3 --- start template query29.tpl query 39 in stream 3 -select /* TPC-DS query29.tpl 0.53 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,max(ss_quantity) as store_sales_quantity - ,max(sr_return_quantity) as store_returns_quantity - ,max(cs_quantity) as catalog_sales_quantity - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 2000 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 4 + 3 - and d2.d_year = 2000 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_year in (2000,2000+1,2000+2) - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query29.tpl query 39 in stream 3 --- start template query3.tpl query 40 in stream 3 -select /* TPC-DS query3.tpl 0.45 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_sales_price) sum_agg - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manufact_id = 665 - and dt.d_moy=11 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,sum_agg desc - ,brand_id - limit 100; - --- end template query3.tpl query 40 in stream 3 --- start template query76.tpl query 41 in stream 3 -select /* TPC-DS query76.tpl 0.99 */ channel, col_name, d_year, d_qoy, i_category, COUNT(*) sales_cnt, SUM(ext_sales_price) sales_amt FROM ( - SELECT 'store' as channel, 'ss_customer_sk' col_name, d_year, d_qoy, i_category, ss_ext_sales_price ext_sales_price - FROM store_sales, item, date_dim - WHERE ss_customer_sk IS NULL - AND ss_sold_date_sk=d_date_sk - AND ss_item_sk=i_item_sk - UNION ALL - SELECT 'web' as channel, 'ws_bill_addr_sk' col_name, d_year, d_qoy, i_category, ws_ext_sales_price ext_sales_price - FROM web_sales, item, date_dim - WHERE ws_bill_addr_sk IS NULL - AND ws_sold_date_sk=d_date_sk - AND ws_item_sk=i_item_sk - UNION ALL - SELECT 'catalog' as channel, 'cs_warehouse_sk' col_name, d_year, d_qoy, i_category, cs_ext_sales_price ext_sales_price - FROM catalog_sales, item, date_dim - WHERE cs_warehouse_sk IS NULL - AND cs_sold_date_sk=d_date_sk - AND cs_item_sk=i_item_sk) foo -GROUP BY channel, col_name, d_year, d_qoy, i_category -ORDER BY channel, col_name, d_year, d_qoy, i_category -limit 100; - --- end template query76.tpl query 41 in stream 3 --- start template query82.tpl query 42 in stream 3 -select /* TPC-DS query82.tpl 0.67 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, store_sales - where i_current_price between 31 and 31+30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('2000-01-07' as date) and dateadd(day,60,cast('2000-01-07' as date)) - and i_manufact_id in (332,24,418,298) - and inv_quantity_on_hand between 100 and 500 - and ss_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query82.tpl query 42 in stream 3 --- start template query46.tpl query 43 in stream 3 -select /* TPC-DS query46.tpl 0.23 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and (household_demographics.hd_dep_count = 1 or - household_demographics.hd_vehicle_count= 3) - and date_dim.d_dow in (6,0) - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_city in ('Spring Valley','Bristol','Clayton','Rosemont','Pinehurst') - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,ca_city) dn,customer,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - limit 100; - --- end template query46.tpl query 43 in stream 3 --- start template query41.tpl query 44 in stream 3 -select /* TPC-DS query41.tpl 0.62 */ distinct(i_product_name) - from item i1 - where i_manufact_id between 953 and 953+40 - and (select count(*) as item_cnt - from item - where (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'firebrick' or i_color = 'purple') and - (i_units = 'Oz' or i_units = 'Tbl') and - (i_size = 'large' or i_size = 'N/A') - ) or - (i_category = 'Women' and - (i_color = 'violet' or i_color = 'medium') and - (i_units = 'Dram' or i_units = 'N/A') and - (i_size = 'petite' or i_size = 'medium') - ) or - (i_category = 'Men' and - (i_color = 'grey' or i_color = 'thistle') and - (i_units = 'Bundle' or i_units = 'Ton') and - (i_size = 'economy' or i_size = 'small') - ) or - (i_category = 'Men' and - (i_color = 'sandy' or i_color = 'cornsilk') and - (i_units = 'Ounce' or i_units = 'Case') and - (i_size = 'large' or i_size = 'N/A') - ))) or - (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'bisque' or i_color = 'red') and - (i_units = 'Bunch' or i_units = 'Tsp') and - (i_size = 'large' or i_size = 'N/A') - ) or - (i_category = 'Women' and - (i_color = 'mint' or i_color = 'deep') and - (i_units = 'Unknown' or i_units = 'Pound') and - (i_size = 'petite' or i_size = 'medium') - ) or - (i_category = 'Men' and - (i_color = 'lavender' or i_color = 'spring') and - (i_units = 'Gross' or i_units = 'Lb') and - (i_size = 'economy' or i_size = 'small') - ) or - (i_category = 'Men' and - (i_color = 'linen' or i_color = 'cornflower') and - (i_units = 'Each' or i_units = 'Cup') and - (i_size = 'large' or i_size = 'N/A') - )))) > 0 - order by i_product_name - limit 100; - --- end template query41.tpl query 44 in stream 3 --- start template query59.tpl query 45 in stream 3 -with /* TPC-DS query59.tpl 0.30 */ wss as - (select d_week_seq, - ss_store_sk, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - group by d_week_seq,ss_store_sk - ) - select s_store_name1,s_store_id1,d_week_seq1 - ,sun_sales1/sun_sales2,mon_sales1/mon_sales2 - ,tue_sales1/tue_sales2,wed_sales1/wed_sales2,thu_sales1/thu_sales2 - ,fri_sales1/fri_sales2,sat_sales1/sat_sales2 - from - (select s_store_name s_store_name1,wss.d_week_seq d_week_seq1 - ,s_store_id s_store_id1,sun_sales sun_sales1 - ,mon_sales mon_sales1,tue_sales tue_sales1 - ,wed_sales wed_sales1,thu_sales thu_sales1 - ,fri_sales fri_sales1,sat_sales sat_sales1 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1181 and 1181 + 11) y, - (select s_store_name s_store_name2,wss.d_week_seq d_week_seq2 - ,s_store_id s_store_id2,sun_sales sun_sales2 - ,mon_sales mon_sales2,tue_sales tue_sales2 - ,wed_sales wed_sales2,thu_sales thu_sales2 - ,fri_sales fri_sales2,sat_sales sat_sales2 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1181+ 12 and 1181 + 23) x - where s_store_id1=s_store_id2 - and d_week_seq1=d_week_seq2-52 - order by s_store_name1,s_store_id1,d_week_seq1 -limit 100; - --- end template query59.tpl query 45 in stream 3 --- start template query40.tpl query 46 in stream 3 -select /* TPC-DS query40.tpl 0.86 */ - w_state - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('1999-04-11' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_before - ,sum(case when (cast(d_date as date) >= cast ('1999-04-11' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_after - from - catalog_sales left outer join catalog_returns on - (cs_order_number = cr_order_number - and cs_item_sk = cr_item_sk) - ,warehouse - ,item - ,date_dim - where - i_current_price between 0.99 and 1.49 - and i_item_sk = cs_item_sk - and cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('1999-04-11' as date)) - and dateadd(day,30,cast ('1999-04-11' as date)) - group by - w_state,i_item_id - order by w_state,i_item_id -limit 100; - --- end template query40.tpl query 46 in stream 3 --- start template query55.tpl query 47 in stream 3 -select /* TPC-DS query55.tpl 0.82 */ i_brand_id brand_id, i_brand brand, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=60 - and d_moy=12 - and d_year=2002 - group by i_brand, i_brand_id - order by ext_price desc, i_brand_id -limit 100 ; - --- end template query55.tpl query 47 in stream 3 --- start template query16.tpl query 48 in stream 3 -select /* TPC-DS query16.tpl 0.25 */ - count(distinct cs_order_number) as "order count" - ,sum(cs_ext_ship_cost) as "total shipping cost" - ,sum(cs_net_profit) as "total net profit" -from - catalog_sales cs1 - ,date_dim - ,customer_address - ,call_center -where - d_date between '2002-4-01' and - dateadd(day, 60, cast('2002-4-01' as date)) -and cs1.cs_ship_date_sk = d_date_sk -and cs1.cs_ship_addr_sk = ca_address_sk -and ca_state = 'GA' -and cs1.cs_call_center_sk = cc_call_center_sk -and cc_county in ('Maverick County','Gogebic County','Oglethorpe County','Richland County', - 'Levy County' -) -and exists (select * - from catalog_sales cs2 - where cs1.cs_order_number = cs2.cs_order_number - and cs1.cs_warehouse_sk <> cs2.cs_warehouse_sk) -and not exists(select * - from catalog_returns cr1 - where cs1.cs_order_number = cr1.cr_order_number) -order by count(distinct cs_order_number) -limit 100; - --- end template query16.tpl query 48 in stream 3 --- start template query27a.tpl query 49 in stream 3 -with /* TPC-DS query27a.tpl 0.16 */ results as - (select i_item_id, - s_state, 0 as g_state, - ss_quantity agg1, - ss_list_price agg2, - ss_coupon_amt agg3, - ss_sales_price agg4 - from store_sales, customer_demographics, date_dim, store, item - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_store_sk = s_store_sk and - ss_cdemo_sk = cd_demo_sk and - cd_gender = 'F' and - cd_marital_status = 'U' and - cd_education_status = 'Unknown' and - d_year = 1999 and - s_state in ('MI','OH', 'CA', 'GA', 'AL', 'TX') - ) - - select i_item_id, - s_state, g_state, agg1, agg2, agg3, agg4 - from ( - select i_item_id, s_state, 0 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4 from results - group by i_item_id, s_state - union all - select i_item_id, NULL AS s_state, 1 AS g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as s_state, 1 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - ) foo - order by i_item_id, s_state - limit 100; - --- end template query27a.tpl query 49 in stream 3 --- start template query54.tpl query 50 in stream 3 -with /* TPC-DS query54.tpl 0.81 */ my_customers as ( - select distinct c_customer_sk - , c_current_addr_sk - from - ( select cs_sold_date_sk sold_date_sk, - cs_bill_customer_sk customer_sk, - cs_item_sk item_sk - from catalog_sales - union all - select ws_sold_date_sk sold_date_sk, - ws_bill_customer_sk customer_sk, - ws_item_sk item_sk - from web_sales - ) cs_or_ws_sales, - item, - date_dim, - customer - where sold_date_sk = d_date_sk - and item_sk = i_item_sk - and i_category = 'Books' - and i_class = 'history' - and c_customer_sk = cs_or_ws_sales.customer_sk - and d_moy = 4 - and d_year = 2000 - ) - , my_revenue as ( - select c_customer_sk, - sum(ss_ext_sales_price) as revenue - from my_customers, - store_sales, - customer_address, - store, - date_dim - where c_current_addr_sk = ca_address_sk - and ca_county = s_county - and ca_state = s_state - and ss_sold_date_sk = d_date_sk - and c_customer_sk = ss_customer_sk - and d_month_seq between (select distinct d_month_seq+1 - from date_dim where d_year = 2000 and d_moy = 4) - and (select distinct d_month_seq+3 - from date_dim where d_year = 2000 and d_moy = 4) - group by c_customer_sk - ) - , segments as - (select cast((revenue/50) as bigint) as segment - from my_revenue - ) - select segment, count(*) as num_customers, segment*50 as segment_base - from segments - group by segment - order by segment, num_customers - limit 100; - --- end template query54.tpl query 50 in stream 3 --- start template query90.tpl query 51 in stream 3 -select /* TPC-DS query90.tpl 0.40 */ cast(amc as decimal(15,4))/cast(pmc as decimal(15,4)) am_pm_ratio - from ( select count(*) amc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 12 and 12+1 - and household_demographics.hd_dep_count = 2 - and web_page.wp_char_count between 5000 and 5200) at, - ( select count(*) pmc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 18 and 18+1 - and household_demographics.hd_dep_count = 2 - and web_page.wp_char_count between 5000 and 5200) pt - order by am_pm_ratio - limit 100; - --- end template query90.tpl query 51 in stream 3 --- start template query92.tpl query 52 in stream 3 -select /* TPC-DS query92.tpl 0.44 */ - sum(ws_ext_discount_amt) as "Excess Discount Amount" -from - web_sales - ,item - ,date_dim -where -i_manufact_id = 264 -and i_item_sk = ws_item_sk -and d_date between '1998-03-18' and - dateadd(day,90,cast('1998-03-18' as date)) -and d_date_sk = ws_sold_date_sk -and ws_ext_discount_amt - > ( - SELECT - 1.3 * avg(ws_ext_discount_amt) - FROM - web_sales - ,date_dim - WHERE - ws_item_sk = i_item_sk - and d_date between '1998-03-18' and - dateadd(day,90,cast('1998-03-18' as date)) - and d_date_sk = ws_sold_date_sk - ) -order by sum(ws_ext_discount_amt) -limit 100; - --- end template query92.tpl query 52 in stream 3 --- start template query31.tpl query 53 in stream 3 -with /* TPC-DS query31.tpl 0.50 */ ss as - (select ca_county,d_qoy, d_year,sum(ss_ext_sales_price) as store_sales - from store_sales,date_dim,customer_address - where ss_sold_date_sk = d_date_sk - and ss_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year), - ws as - (select ca_county,d_qoy, d_year,sum(ws_ext_sales_price) as web_sales - from web_sales,date_dim,customer_address - where ws_sold_date_sk = d_date_sk - and ws_bill_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year) - select - ss1.ca_county - ,ss1.d_year - ,ws2.web_sales/ws1.web_sales web_q1_q2_increase - ,ss2.store_sales/ss1.store_sales store_q1_q2_increase - ,ws3.web_sales/ws2.web_sales web_q2_q3_increase - ,ss3.store_sales/ss2.store_sales store_q2_q3_increase - from - ss ss1 - ,ss ss2 - ,ss ss3 - ,ws ws1 - ,ws ws2 - ,ws ws3 - where - ss1.d_qoy = 1 - and ss1.d_year = 2001 - and ss1.ca_county = ss2.ca_county - and ss2.d_qoy = 2 - and ss2.d_year = 2001 - and ss2.ca_county = ss3.ca_county - and ss3.d_qoy = 3 - and ss3.d_year = 2001 - and ss1.ca_county = ws1.ca_county - and ws1.d_qoy = 1 - and ws1.d_year = 2001 - and ws1.ca_county = ws2.ca_county - and ws2.d_qoy = 2 - and ws2.d_year = 2001 - and ws1.ca_county = ws3.ca_county - and ws3.d_qoy = 3 - and ws3.d_year =2001 - and case when ws1.web_sales > 0 then ws2.web_sales/ws1.web_sales else null end - > case when ss1.store_sales > 0 then ss2.store_sales/ss1.store_sales else null end - and case when ws2.web_sales > 0 then ws3.web_sales/ws2.web_sales else null end - > case when ss2.store_sales > 0 then ss3.store_sales/ss2.store_sales else null end - order by ss1.d_year; - --- end template query31.tpl query 53 in stream 3 --- start template query42.tpl query 54 in stream 3 -select /* TPC-DS query42.tpl 0.61 */ dt.d_year - ,item.i_category_id - ,item.i_category - ,sum(ss_ext_sales_price) - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=12 - and dt.d_year=1999 - group by dt.d_year - ,item.i_category_id - ,item.i_category - order by sum(ss_ext_sales_price) desc,dt.d_year - ,item.i_category_id - ,item.i_category -limit 100 ; - --- end template query42.tpl query 54 in stream 3 --- start template query26.tpl query 55 in stream 3 -select /* TPC-DS query26.tpl 0.85 */ i_item_id, - avg(cs_quantity) agg1, - avg(cs_list_price) agg2, - avg(cs_coupon_amt) agg3, - avg(cs_sales_price) agg4 - from catalog_sales, customer_demographics, date_dim, item, promotion - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd_demo_sk and - cs_promo_sk = p_promo_sk and - cd_gender = 'F' and - cd_marital_status = 'U' and - cd_education_status = 'Primary' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 1998 - group by i_item_id - order by i_item_id - limit 100; - --- end template query26.tpl query 55 in stream 3 --- start template query34.tpl query 56 in stream 3 -select /* TPC-DS query34.tpl 0.73 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (date_dim.d_dom between 1 and 3 or date_dim.d_dom between 25 and 28) - and (household_demographics.hd_buy_potential = '501-1000' or - household_demographics.hd_buy_potential = '5001-10000') - and household_demographics.hd_vehicle_count > 0 - and (case when household_demographics.hd_vehicle_count > 0 - then household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count - else null - end) > 1.2 - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_county in ('Rush County','Jack County','Miller County','Somerset County', - 'Klamath County','Tompkins County','Box Butte County','Terrell County') - group by ss_ticket_number,ss_customer_sk) dn,customer - where ss_customer_sk = c_customer_sk - and cnt between 15 and 20 - order by c_last_name,c_first_name,c_salutation,c_preferred_cust_flag desc, ss_ticket_number; - --- end template query34.tpl query 56 in stream 3 --- start template query68.tpl query 57 in stream 3 -select /* TPC-DS query68.tpl 0.95 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,extended_price - ,extended_tax - ,list_price - from (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_ext_sales_price) extended_price - ,sum(ss_ext_list_price) list_price - ,sum(ss_ext_tax) extended_tax - from store_sales - ,date_dim - ,store - ,household_demographics - ,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_dep_count = 7 or - household_demographics.hd_vehicle_count= 0) - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_city in ('Mount Olive','Campbell') - group by ss_ticket_number - ,ss_customer_sk - ,ss_addr_sk,ca_city) dn - ,customer - ,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,ss_ticket_number - limit 100; - --- end template query68.tpl query 57 in stream 3 --- start template query2.tpl query 58 in stream 3 -with /* TPC-DS query2.tpl 0.84 */ wscs as - (select sold_date_sk - ,sales_price - from (select ws_sold_date_sk sold_date_sk - ,ws_ext_sales_price sales_price - from web_sales - union all - select cs_sold_date_sk sold_date_sk - ,cs_ext_sales_price sales_price - from catalog_sales)), - wswscs as - (select d_week_seq, - sum(case when (d_day_name='Sunday') then sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then sales_price else null end) sat_sales - from wscs - ,date_dim - where d_date_sk = sold_date_sk - group by d_week_seq) - select d_week_seq1 - ,round(sun_sales1/sun_sales2,2) - ,round(mon_sales1/mon_sales2,2) - ,round(tue_sales1/tue_sales2,2) - ,round(wed_sales1/wed_sales2,2) - ,round(thu_sales1/thu_sales2,2) - ,round(fri_sales1/fri_sales2,2) - ,round(sat_sales1/sat_sales2,2) - from - (select wswscs.d_week_seq d_week_seq1 - ,sun_sales sun_sales1 - ,mon_sales mon_sales1 - ,tue_sales tue_sales1 - ,wed_sales wed_sales1 - ,thu_sales thu_sales1 - ,fri_sales fri_sales1 - ,sat_sales sat_sales1 - from wswscs,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 1998) y, - (select wswscs.d_week_seq d_week_seq2 - ,sun_sales sun_sales2 - ,mon_sales mon_sales2 - ,tue_sales tue_sales2 - ,wed_sales wed_sales2 - ,thu_sales thu_sales2 - ,fri_sales fri_sales2 - ,sat_sales sat_sales2 - from wswscs - ,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 1998+1) z - where d_week_seq1=d_week_seq2-53 - order by d_week_seq1; - --- end template query2.tpl query 58 in stream 3 --- start template query44.tpl query 59 in stream 3 -select /* TPC-DS query44.tpl 0.4 */ asceding.rnk, i1.i_product_name best_performing, i2.i_product_name worst_performing -from(select * - from (select item_sk,rank() over (order by rank_col asc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 259 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 259 - and ss_cdemo_sk is null - group by ss_store_sk))V1)V11 - where rnk < 11) asceding, - (select * - from (select item_sk,rank() over (order by rank_col desc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 259 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 259 - and ss_cdemo_sk is null - group by ss_store_sk))V2)V21 - where rnk < 11) descending, -item i1, -item i2 -where asceding.rnk = descending.rnk - and i1.i_item_sk=asceding.item_sk - and i2.i_item_sk=descending.item_sk -order by asceding.rnk -limit 100; - --- end template query44.tpl query 59 in stream 3 --- start template query81.tpl query 60 in stream 3 -with /* TPC-DS query81.tpl 0.37 */ customer_total_return as - (select cr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(cr_return_amt_inc_tax) as ctr_total_return - from catalog_returns - ,date_dim - ,customer_address - where cr_returned_date_sk = d_date_sk - and d_year =1999 - and cr_returning_addr_sk = ca_address_sk - group by cr_returning_customer_sk - ,ca_state ) - select c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'UT' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - limit 100; - --- end template query81.tpl query 60 in stream 3 --- start template query67a.tpl query 61 in stream 3 -with /* TPC-DS query67a.tpl 0.35 */ results as -( select i_category ,i_class ,i_brand ,i_product_name ,d_year ,d_qoy ,d_moy ,s_store_id - ,sum(coalesce(ss_sales_price*ss_quantity,0)) sumsales - from store_sales ,date_dim ,store ,item - where ss_sold_date_sk=d_date_sk - and ss_item_sk=i_item_sk - and ss_store_sk = s_store_sk - and d_month_seq between 1181 and 1181 + 11 - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy,s_store_id) - , - results_rollup as - (select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, s_store_id, sumsales - from results - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy - union all - select i_category, i_class, i_brand, i_product_name, d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year - union all - select i_category, i_class, i_brand, i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name - union all - select i_category, i_class, i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand - union all - select i_category, i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class - union all - select i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category - union all - select null i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results) - - select * -from (select i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rank() over (partition by i_category order by sumsales desc) rk - from results_rollup) dw2 -where rk <= 100 -order by i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rk -limit 100; - --- end template query67a.tpl query 61 in stream 3 --- start template query99.tpl query 62 in stream 3 -select /* TPC-DS query99.tpl 0.94 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 30) and - (cs_ship_date_sk - cs_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 60) and - (cs_ship_date_sk - cs_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 90) and - (cs_ship_date_sk - cs_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - catalog_sales - ,warehouse - ,ship_mode - ,call_center - ,date_dim -where - d_month_seq between 1178 and 1178 + 11 -and cs_ship_date_sk = d_date_sk -and cs_warehouse_sk = w_warehouse_sk -and cs_ship_mode_sk = sm_ship_mode_sk -and cs_call_center_sk = cc_call_center_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -limit 100; - --- end template query99.tpl query 62 in stream 3 --- start template query6.tpl query 63 in stream 3 -select /* TPC-DS query6.tpl 0.58 */ a.ca_state state, count(*) cnt - from customer_address a - ,customer c - ,store_sales s - ,date_dim d - ,item i - where a.ca_address_sk = c.c_current_addr_sk - and c.c_customer_sk = s.ss_customer_sk - and s.ss_sold_date_sk = d.d_date_sk - and s.ss_item_sk = i.i_item_sk - and d.d_month_seq = - (select distinct (d_month_seq) - from date_dim - where d_year = 2001 - and d_moy = 5 ) - and i.i_current_price > 1.2 * - (select avg(j.i_current_price) - from item j - where j.i_category = i.i_category) - group by a.ca_state - having count(*) >= 10 - order by cnt, a.ca_state - limit 100; - --- end template query6.tpl query 63 in stream 3 --- start template query83.tpl query 64 in stream 3 -with /* TPC-DS query83.tpl 0.96 */ sr_items as - (select i_item_id item_id, - sum(sr_return_quantity) sr_item_qty - from store_returns, - item, - date_dim - where sr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('1999-04-01','1999-10-23','1999-11-15'))) - and sr_returned_date_sk = d_date_sk - group by i_item_id), - cr_items as - (select i_item_id item_id, - sum(cr_return_quantity) cr_item_qty - from catalog_returns, - item, - date_dim - where cr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('1999-04-01','1999-10-23','1999-11-15'))) - and cr_returned_date_sk = d_date_sk - group by i_item_id), - wr_items as - (select i_item_id item_id, - sum(wr_return_quantity) wr_item_qty - from web_returns, - item, - date_dim - where wr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('1999-04-01','1999-10-23','1999-11-15'))) - and wr_returned_date_sk = d_date_sk - group by i_item_id) - select sr_items.item_id - ,sr_item_qty - ,sr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 sr_dev - ,cr_item_qty - ,cr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 cr_dev - ,wr_item_qty - ,wr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 wr_dev - ,(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 average - from sr_items - ,cr_items - ,wr_items - where sr_items.item_id=cr_items.item_id - and sr_items.item_id=wr_items.item_id - order by sr_items.item_id - ,sr_item_qty - limit 100; - --- end template query83.tpl query 64 in stream 3 --- start template query1.tpl query 65 in stream 3 -with /* TPC-DS query1.tpl 0.12 */ customer_total_return as -(select sr_customer_sk as ctr_customer_sk -,sr_store_sk as ctr_store_sk -,sum(SR_RETURN_AMT) as ctr_total_return -from store_returns -,date_dim -where sr_returned_date_sk = d_date_sk -and d_year =1999 -group by sr_customer_sk -,sr_store_sk) - select c_customer_id -from customer_total_return ctr1 -,store -,customer -where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 -from customer_total_return ctr2 -where ctr1.ctr_store_sk = ctr2.ctr_store_sk) -and s_store_sk = ctr1.ctr_store_sk -and s_state = 'MI' -and ctr1.ctr_customer_sk = c_customer_sk -order by c_customer_id -limit 100; - --- end template query1.tpl query 65 in stream 3 --- start template query60.tpl query 66 in stream 3 -with /* TPC-DS query60.tpl 0.29 */ ss as ( - select - i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Music')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 10 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - cs as ( - select - i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Music')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 10 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - ws as ( - select - i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Music')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 10 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id) - select - i_item_id -,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by i_item_id - ,total_sales - limit 100; - --- end template query60.tpl query 66 in stream 3 --- start template query33.tpl query 67 in stream 3 -with /* TPC-DS query33.tpl 0.22 */ ss as ( - select - i_manufact_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Jewelry')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 6 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id), - cs as ( - select - i_manufact_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Jewelry')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 6 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id), - ws as ( - select - i_manufact_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Jewelry')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 6 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id) - select i_manufact_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_manufact_id - order by total_sales -limit 100; - --- end template query33.tpl query 67 in stream 3 --- start template query11.tpl query 68 in stream 3 -with /* TPC-DS query11.tpl 0.51 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ss_ext_list_price-ss_ext_discount_amt) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ws_ext_list_price-ws_ext_discount_amt) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_preferred_cust_flag - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 1998 - and t_s_secyear.dyear = 1998+1 - and t_w_firstyear.dyear = 1998 - and t_w_secyear.dyear = 1998+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else 0.0 end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else 0.0 end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_preferred_cust_flag -limit 100; - --- end template query11.tpl query 68 in stream 3 --- start template query28.tpl query 69 in stream 3 -select /* TPC-DS query28.tpl 0.36 */ * -from (select avg(ss_list_price) B1_LP - ,count(ss_list_price) B1_CNT - ,count(distinct ss_list_price) B1_CNTD - from store_sales - where ss_quantity between 0 and 5 - and (ss_list_price between 113 and 113+10 - or ss_coupon_amt between 11546 and 11546+1000 - or ss_wholesale_cost between 41 and 41+20)) B1, - (select avg(ss_list_price) B2_LP - ,count(ss_list_price) B2_CNT - ,count(distinct ss_list_price) B2_CNTD - from store_sales - where ss_quantity between 6 and 10 - and (ss_list_price between 142 and 142+10 - or ss_coupon_amt between 1465 and 1465+1000 - or ss_wholesale_cost between 69 and 69+20)) B2, - (select avg(ss_list_price) B3_LP - ,count(ss_list_price) B3_CNT - ,count(distinct ss_list_price) B3_CNTD - from store_sales - where ss_quantity between 11 and 15 - and (ss_list_price between 53 and 53+10 - or ss_coupon_amt between 15238 and 15238+1000 - or ss_wholesale_cost between 64 and 64+20)) B3, - (select avg(ss_list_price) B4_LP - ,count(ss_list_price) B4_CNT - ,count(distinct ss_list_price) B4_CNTD - from store_sales - where ss_quantity between 16 and 20 - and (ss_list_price between 135 and 135+10 - or ss_coupon_amt between 17117 and 17117+1000 - or ss_wholesale_cost between 74 and 74+20)) B4, - (select avg(ss_list_price) B5_LP - ,count(ss_list_price) B5_CNT - ,count(distinct ss_list_price) B5_CNTD - from store_sales - where ss_quantity between 21 and 25 - and (ss_list_price between 29 and 29+10 - or ss_coupon_amt between 16152 and 16152+1000 - or ss_wholesale_cost between 78 and 78+20)) B5, - (select avg(ss_list_price) B6_LP - ,count(ss_list_price) B6_CNT - ,count(distinct ss_list_price) B6_CNTD - from store_sales - where ss_quantity between 26 and 30 - and (ss_list_price between 43 and 43+10 - or ss_coupon_amt between 2215 and 2215+1000 - or ss_wholesale_cost between 5 and 5+20)) B6 -limit 100; - --- end template query28.tpl query 69 in stream 3 --- start template query95.tpl query 70 in stream 3 -with /* TPC-DS query95.tpl 0.43 */ ws_wh as -(select ws1.ws_order_number,ws1.ws_warehouse_sk wh1,ws2.ws_warehouse_sk wh2 - from web_sales ws1,web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) - select - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '1999-2-01' and - dateadd(day,60,cast('1999-2-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'IL' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and ws1.ws_order_number in (select ws_order_number - from ws_wh) -and ws1.ws_order_number in (select wr_order_number - from web_returns,ws_wh - where wr_order_number = ws_wh.ws_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query95.tpl query 70 in stream 3 --- start template query12.tpl query 71 in stream 3 -select /* TPC-DS query12.tpl 0.64 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ws_ext_sales_price) as itemrevenue - ,sum(ws_ext_sales_price)*100/sum(sum(ws_ext_sales_price)) over - (partition by i_class) as revenueratio -from - web_sales - ,item - ,date_dim -where - ws_item_sk = i_item_sk - and i_category in ('Music', 'Electronics', 'Shoes') - and ws_sold_date_sk = d_date_sk - and d_date between cast('2001-01-04' as date) - and dateadd(day,30,cast('2001-01-04' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query12.tpl query 71 in stream 3 --- start template query64.tpl query 72 in stream 3 -with /* TPC-DS query64.tpl 0.20 */ cs_ui as - (select cs_item_sk - ,sum(cs_ext_list_price) as sale,sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit) as refund - from catalog_sales - ,catalog_returns - where cs_item_sk = cr_item_sk - and cs_order_number = cr_order_number - group by cs_item_sk - having sum(cs_ext_list_price)>2*sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit)), -cross_sales as - (select i_product_name product_name - ,i_item_sk item_sk - ,s_store_name store_name - ,s_zip store_zip - ,ad1.ca_street_number b_street_number - ,ad1.ca_street_name b_street_name - ,ad1.ca_city b_city - ,ad1.ca_zip b_zip - ,ad2.ca_street_number c_street_number - ,ad2.ca_street_name c_street_name - ,ad2.ca_city c_city - ,ad2.ca_zip c_zip - ,d1.d_year as syear - ,d2.d_year as fsyear - ,d3.d_year s2year - ,count(*) cnt - ,sum(ss_wholesale_cost) s1 - ,sum(ss_list_price) s2 - ,sum(ss_coupon_amt) s3 - FROM store_sales - ,store_returns - ,cs_ui - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,customer - ,customer_demographics cd1 - ,customer_demographics cd2 - ,promotion - ,household_demographics hd1 - ,household_demographics hd2 - ,customer_address ad1 - ,customer_address ad2 - ,income_band ib1 - ,income_band ib2 - ,item - WHERE ss_store_sk = s_store_sk AND - ss_sold_date_sk = d1.d_date_sk AND - ss_customer_sk = c_customer_sk AND - ss_cdemo_sk= cd1.cd_demo_sk AND - ss_hdemo_sk = hd1.hd_demo_sk AND - ss_addr_sk = ad1.ca_address_sk and - ss_item_sk = i_item_sk and - ss_item_sk = sr_item_sk and - ss_ticket_number = sr_ticket_number and - ss_item_sk = cs_ui.cs_item_sk and - c_current_cdemo_sk = cd2.cd_demo_sk AND - c_current_hdemo_sk = hd2.hd_demo_sk AND - c_current_addr_sk = ad2.ca_address_sk and - c_first_sales_date_sk = d2.d_date_sk and - c_first_shipto_date_sk = d3.d_date_sk and - ss_promo_sk = p_promo_sk and - hd1.hd_income_band_sk = ib1.ib_income_band_sk and - hd2.hd_income_band_sk = ib2.ib_income_band_sk and - cd1.cd_marital_status <> cd2.cd_marital_status and - i_color in ('blush','maroon','midnight','metallic','violet','burnished') and - i_current_price between 45 and 45 + 10 and - i_current_price between 45 + 1 and 45 + 15 -group by i_product_name - ,i_item_sk - ,s_store_name - ,s_zip - ,ad1.ca_street_number - ,ad1.ca_street_name - ,ad1.ca_city - ,ad1.ca_zip - ,ad2.ca_street_number - ,ad2.ca_street_name - ,ad2.ca_city - ,ad2.ca_zip - ,d1.d_year - ,d2.d_year - ,d3.d_year -) -select cs1.product_name - ,cs1.store_name - ,cs1.store_zip - ,cs1.b_street_number - ,cs1.b_street_name - ,cs1.b_city - ,cs1.b_zip - ,cs1.c_street_number - ,cs1.c_street_name - ,cs1.c_city - ,cs1.c_zip - ,cs1.syear - ,cs1.cnt - ,cs1.s1 as s11 - ,cs1.s2 as s21 - ,cs1.s3 as s31 - ,cs2.s1 as s12 - ,cs2.s2 as s22 - ,cs2.s3 as s32 - ,cs2.syear - ,cs2.cnt -from cross_sales cs1,cross_sales cs2 -where cs1.item_sk=cs2.item_sk and - cs1.syear = 2001 and - cs2.syear = 2001 + 1 and - cs2.cnt <= cs1.cnt and - cs1.store_name = cs2.store_name and - cs1.store_zip = cs2.store_zip -order by cs1.product_name - ,cs1.store_name - ,cs2.cnt - ,cs1.s1 - ,cs2.s1; - --- end template query64.tpl query 72 in stream 3 --- start template query15.tpl query 73 in stream 3 -select /* TPC-DS query15.tpl 0.57 */ ca_zip - ,sum(cs_sales_price) - from catalog_sales - ,customer - ,customer_address - ,date_dim - where cs_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', - '85392', '85460', '80348', '81792') - or ca_state in ('CA','WA','GA') - or cs_sales_price > 500) - and cs_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 1998 - group by ca_zip - order by ca_zip - limit 100; - --- end template query15.tpl query 73 in stream 3 --- start template query25.tpl query 74 in stream 3 -select /* TPC-DS query25.tpl 0.9 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,max(ss_net_profit) as store_sales_profit - ,max(sr_net_loss) as store_returns_loss - ,max(cs_net_profit) as catalog_sales_profit - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 1998 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 10 - and d2.d_year = 1998 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_moy between 4 and 10 - and d3.d_year = 1998 - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query25.tpl query 74 in stream 3 --- start template query93.tpl query 75 in stream 3 -select /* TPC-DS query93.tpl 0.52 */ ss_customer_sk - ,sum(act_sales) sumsales - from (select ss_item_sk - ,ss_ticket_number - ,ss_customer_sk - ,case when sr_return_quantity is not null then (ss_quantity-sr_return_quantity)*ss_sales_price - else (ss_quantity*ss_sales_price) end act_sales - from store_sales left outer join store_returns on (sr_item_sk = ss_item_sk - and sr_ticket_number = ss_ticket_number) - ,reason - where sr_reason_sk = r_reason_sk - and r_reason_desc = 'reason 56') t - group by ss_customer_sk - order by sumsales, ss_customer_sk -limit 100; - --- end template query93.tpl query 75 in stream 3 --- start template query9.tpl query 76 in stream 3 -select /* TPC-DS query9.tpl 0.49 */ case when (select count(*) - from store_sales - where ss_quantity between 1 and 20) > 361276800 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 1 and 20) - else (select avg(ss_net_profit) - from store_sales - where ss_quantity between 1 and 20) end bucket1 , - case when (select count(*) - from store_sales - where ss_quantity between 21 and 40) > 18663912 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 21 and 40) - else (select avg(ss_net_profit) - from store_sales - where ss_quantity between 21 and 40) end bucket2, - case when (select count(*) - from store_sales - where ss_quantity between 41 and 60) > 752929052 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 41 and 60) - else (select avg(ss_net_profit) - from store_sales - where ss_quantity between 41 and 60) end bucket3, - case when (select count(*) - from store_sales - where ss_quantity between 61 and 80) > 1095239148 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 61 and 80) - else (select avg(ss_net_profit) - from store_sales - where ss_quantity between 61 and 80) end bucket4, - case when (select count(*) - from store_sales - where ss_quantity between 81 and 100) > 123272137 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 81 and 100) - else (select avg(ss_net_profit) - from store_sales - where ss_quantity between 81 and 100) end bucket5 -from reason -where r_reason_sk = 1 -; - --- end template query9.tpl query 76 in stream 3 --- start template query65.tpl query 77 in stream 3 -select /* TPC-DS query65.tpl 0.71 */ - s_store_name, - i_item_desc, - sc.revenue, - i_current_price, - i_wholesale_cost, - i_brand - from store, item, - (select ss_store_sk, avg(revenue) as ave - from - (select ss_store_sk, ss_item_sk, - sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1208 and 1208+11 - group by ss_store_sk, ss_item_sk) sa - group by ss_store_sk) sb, - (select ss_store_sk, ss_item_sk, sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1208 and 1208+11 - group by ss_store_sk, ss_item_sk) sc - where sb.ss_store_sk = sc.ss_store_sk and - sc.revenue <= 0.1 * sb.ave and - s_store_sk = sc.ss_store_sk and - i_item_sk = sc.ss_item_sk - order by s_store_name, i_item_desc -limit 100; - --- end template query65.tpl query 77 in stream 3 --- start template query71.tpl query 78 in stream 3 -select /* TPC-DS query71.tpl 0.72 */ i_brand_id brand_id, i_brand brand,t_hour,t_minute, - sum(ext_price) ext_price - from item, (select ws_ext_sales_price as ext_price, - ws_sold_date_sk as sold_date_sk, - ws_item_sk as sold_item_sk, - ws_sold_time_sk as time_sk - from web_sales,date_dim - where d_date_sk = ws_sold_date_sk - and d_moy=12 - and d_year=2000 - union all - select cs_ext_sales_price as ext_price, - cs_sold_date_sk as sold_date_sk, - cs_item_sk as sold_item_sk, - cs_sold_time_sk as time_sk - from catalog_sales,date_dim - where d_date_sk = cs_sold_date_sk - and d_moy=12 - and d_year=2000 - union all - select ss_ext_sales_price as ext_price, - ss_sold_date_sk as sold_date_sk, - ss_item_sk as sold_item_sk, - ss_sold_time_sk as time_sk - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - and d_moy=12 - and d_year=2000 - ) tmp,time_dim - where - sold_item_sk = i_item_sk - and i_manager_id=1 - and time_sk = t_time_sk - and (t_meal_time = 'breakfast' or t_meal_time = 'dinner') - group by i_brand, i_brand_id,t_hour,t_minute - order by ext_price desc, i_brand_id - ; - --- end template query71.tpl query 78 in stream 3 --- start template query57.tpl query 79 in stream 3 -with /* TPC-DS query57.tpl 0.70 */ v1 as( - select i_category, i_brand, - cc_name, - d_year, d_moy, - sum(cs_sales_price) sum_sales, - avg(sum(cs_sales_price)) over - (partition by i_category, i_brand, - cc_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - cc_name - order by d_year, d_moy) rn - from item, catalog_sales, date_dim, call_center - where cs_item_sk = i_item_sk and - cs_sold_date_sk = d_date_sk and - cc_call_center_sk= cs_call_center_sk and - ( - d_year = 1999 or - ( d_year = 1999-1 and d_moy =12) or - ( d_year = 1999+1 and d_moy =1) - ) - group by i_category, i_brand, - cc_name , d_year, d_moy), - v2 as( - select v1.i_category, v1.i_brand - ,v1.d_year - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1. cc_name = v1_lag. cc_name and - v1. cc_name = v1_lead. cc_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 1999 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, avg_monthly_sales - limit 100; - --- end template query57.tpl query 79 in stream 3 --- start template query32.tpl query 80 in stream 3 -select /* TPC-DS query32.tpl 0.7 */ sum(cs_ext_discount_amt) as "excess discount amount" -from - catalog_sales - ,item - ,date_dim -where -i_manufact_id = 788 -and i_item_sk = cs_item_sk -and d_date between '1999-02-05' and - dateadd(day,90,cast('1999-02-05' as date)) -and d_date_sk = cs_sold_date_sk -and cs_ext_discount_amt - > ( - select - 1.3 * avg(cs_ext_discount_amt) - from - catalog_sales - ,date_dim - where - cs_item_sk = i_item_sk - and d_date between '1999-02-05' and - dateadd(day,90,cast('1999-02-05' as date)) - and d_date_sk = cs_sold_date_sk - ) -limit 100; - --- end template query32.tpl query 80 in stream 3 --- start template query61.tpl query 81 in stream 3 -select /* TPC-DS query61.tpl 0.97 */ promotions,total,cast(promotions as decimal(15,4))/cast(total as decimal(15,4))*100 -from - (select sum(ss_ext_sales_price) promotions - from store_sales - ,store - ,promotion - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_promo_sk = p_promo_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -6 - and i_category = 'Sports' - and (p_channel_dmail = 'Y' or p_channel_email = 'Y' or p_channel_tv = 'Y') - and s_gmt_offset = -6 - and d_year = 2000 - and d_moy = 11) promotional_sales, - (select sum(ss_ext_sales_price) total - from store_sales - ,store - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -6 - and i_category = 'Sports' - and s_gmt_offset = -6 - and d_year = 2000 - and d_moy = 11) all_sales -order by promotions, total -limit 100; - --- end template query61.tpl query 81 in stream 3 --- start template query85.tpl query 82 in stream 3 -select /* TPC-DS query85.tpl 0.33 */ substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) - from web_sales, web_returns, web_page, customer_demographics cd1, - customer_demographics cd2, customer_address, date_dim, reason - where ws_web_page_sk = wp_web_page_sk - and ws_item_sk = wr_item_sk - and ws_order_number = wr_order_number - and ws_sold_date_sk = d_date_sk and d_year = 2001 - and cd1.cd_demo_sk = wr_refunded_cdemo_sk - and cd2.cd_demo_sk = wr_returning_cdemo_sk - and ca_address_sk = wr_refunded_addr_sk - and r_reason_sk = wr_reason_sk - and - ( - ( - cd1.cd_marital_status = 'M' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Unknown' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 100.00 and 150.00 - ) - or - ( - cd1.cd_marital_status = 'W' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = '2 yr Degree' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 50.00 and 100.00 - ) - or - ( - cd1.cd_marital_status = 'S' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = '4 yr Degree' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ca_country = 'United States' - and - ca_state in ('CO', 'MS', 'AR') - and ws_net_profit between 100 and 200 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('MI', 'TN', 'NE') - and ws_net_profit between 150 and 300 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('IA', 'NM', 'WA') - and ws_net_profit between 50 and 250 - ) - ) -group by r_reason_desc -order by substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) -limit 100; - --- end template query85.tpl query 82 in stream 3 --- start template query73.tpl query 83 in stream 3 -select /* TPC-DS query73.tpl 0.79 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_buy_potential = '>10000' or - household_demographics.hd_buy_potential = '5001-10000') - and household_demographics.hd_vehicle_count > 0 - and case when household_demographics.hd_vehicle_count > 0 then - household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count else null end > 1 - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_county in ('Denali Borough','Pipestone County','Terrell County','Abbeville County') - group by ss_ticket_number,ss_customer_sk) dj,customer - where ss_customer_sk = c_customer_sk - and cnt between 1 and 5 - order by cnt desc, c_last_name asc; - --- end template query73.tpl query 83 in stream 3 --- start template query98.tpl query 84 in stream 3 -select /* TPC-DS query98.tpl 0.32 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ss_ext_sales_price) as itemrevenue - ,sum(ss_ext_sales_price)*100/sum(sum(ss_ext_sales_price)) over - (partition by i_class) as revenueratio -from - store_sales - ,item - ,date_dim -where - ss_item_sk = i_item_sk - and i_category in ('Women', 'Children', 'Jewelry') - and ss_sold_date_sk = d_date_sk - and d_date between cast('2001-03-17' as date) - and dateadd(day,30,cast('2001-03-17' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio; - --- end template query98.tpl query 84 in stream 3 --- start template query77a.tpl query 85 in stream 3 -with /* TPC-DS query77a.tpl 0.78 */ ss as - (select s_store_sk, - sum(ss_ext_sales_price) as sales, - sum(ss_net_profit) as profit - from store_sales, - date_dim, - store - where ss_sold_date_sk = d_date_sk - and d_date between cast('1999-08-04' as date) - and dateadd(day,30,cast('1999-08-04' as date)) - and ss_store_sk = s_store_sk - group by s_store_sk) - , - sr as - (select s_store_sk, - sum(sr_return_amt) as returns, - sum(sr_net_loss) as profit_loss - from store_returns, - date_dim, - store - where sr_returned_date_sk = d_date_sk - and d_date between cast('1999-08-04' as date) - and dateadd(day,30,cast('1999-08-04' as date)) - and sr_store_sk = s_store_sk - group by s_store_sk), - cs as - (select cs_call_center_sk, - sum(cs_ext_sales_price) as sales, - sum(cs_net_profit) as profit - from catalog_sales, - date_dim - where cs_sold_date_sk = d_date_sk - and d_date between cast('1999-08-04' as date) - and dateadd(day,30,cast('1999-08-04' as date)) - group by cs_call_center_sk - ), - cr as - (select cr_call_center_sk, - sum(cr_return_amount) as returns, - sum(cr_net_loss) as profit_loss - from catalog_returns, - date_dim - where cr_returned_date_sk = d_date_sk - and d_date between cast('1999-08-04' as date) - and dateadd(day,30,cast('1999-08-04' as date)) - group by cr_call_center_sk), - ws as - ( select wp_web_page_sk, - sum(ws_ext_sales_price) as sales, - sum(ws_net_profit) as profit - from web_sales, - date_dim, - web_page - where ws_sold_date_sk = d_date_sk - and d_date between cast('1999-08-04' as date) - and dateadd(day,30,cast('1999-08-04' as date)) - and ws_web_page_sk = wp_web_page_sk - group by wp_web_page_sk), - wr as - (select wp_web_page_sk, - sum(wr_return_amt) as returns, - sum(wr_net_loss) as profit_loss - from web_returns, - date_dim, - web_page - where wr_returned_date_sk = d_date_sk - and d_date between cast('1999-08-04' as date) - and dateadd(day,30,cast('1999-08-04' as date)) - and wr_web_page_sk = wp_web_page_sk - group by wp_web_page_sk) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , ss.s_store_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ss left join sr - on ss.s_store_sk = sr.s_store_sk - union all - select 'catalog channel' as channel - , cs_call_center_sk as id - , sales - , returns - , (profit - profit_loss) as profit - from cs - , cr - union all - select 'web channel' as channel - , ws.wp_web_page_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ws left join wr - on ws.wp_web_page_sk = wr.wp_web_page_sk - ) x - group by channel, id ) - - select * - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results -) foo -order by channel, id - limit 100; - --- end template query77a.tpl query 85 in stream 3 --- start template query45.tpl query 86 in stream 3 -select /* TPC-DS query45.tpl 0.18 */ ca_zip, ca_county, sum(ws_sales_price) - from web_sales, customer, customer_address, date_dim, item - where ws_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ws_item_sk = i_item_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', '85392', '85460', '80348', '81792') - or - i_item_id in (select i_item_id - from item - where i_item_sk in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29) - ) - ) - and ws_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 2000 - group by ca_zip, ca_county - order by ca_zip, ca_county - limit 100; - --- end template query45.tpl query 86 in stream 3 --- start template query20.tpl query 87 in stream 3 -select /* TPC-DS query20.tpl 0.65 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(cs_ext_sales_price) as itemrevenue - ,sum(cs_ext_sales_price)*100/sum(sum(cs_ext_sales_price)) over - (partition by i_class) as revenueratio - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and i_category in ('Music', 'Women', 'Jewelry') - and cs_sold_date_sk = d_date_sk - and d_date between cast('2002-04-01' as date) - and dateadd(day,30,cast('2002-04-01' as date)) - group by i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - order by i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query20.tpl query 87 in stream 3 --- start template query50.tpl query 88 in stream 3 -select /* TPC-DS query50.tpl 0.60 */ - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 30) and - (sr_returned_date_sk - ss_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 60) and - (sr_returned_date_sk - ss_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 90) and - (sr_returned_date_sk - ss_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - store_sales - ,store_returns - ,store - ,date_dim d1 - ,date_dim d2 -where - d2.d_year = 2002 -and d2.d_moy = 9 -and ss_ticket_number = sr_ticket_number -and ss_item_sk = sr_item_sk -and ss_sold_date_sk = d1.d_date_sk -and sr_returned_date_sk = d2.d_date_sk -and ss_customer_sk = sr_customer_sk -and ss_store_sk = s_store_sk -group by - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -order by s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -limit 100; - --- end template query50.tpl query 88 in stream 3 --- start template query70a.tpl query 89 in stream 3 -with /* TPC-DS query70a.tpl 0.34 */ results as -( select - sum(ss_net_profit) as total_sum ,s_state ,s_county, 0 as gstate, 0 as g_county - from - store_sales - ,date_dim d1 - ,store - where - d1.d_month_seq between 1205 and 1205 + 11 - and d1.d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - and s_state in - ( select s_state - from (select s_state as s_state, - rank() over ( partition by s_state order by sum(ss_net_profit) desc) as ranking - from store_sales, store, date_dim - where d_month_seq between 1205 and 1205 + 11 - and d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - group by s_state - ) tmp1 - where ranking <= 5) - group by s_state,s_county) , - results_rollup as -(select total_sum ,s_state ,s_county, 0 as g_state, 0 as g_county, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum,s_state, NULL as s_county, 0 as g_state, 1 as g_county, 1 as lochierarchy from results group by s_state - union - select sum(total_sum) as total_sum ,NULL as s_state ,NULL as s_county, 1 as g_state, 1 as g_county, 2 as lochierarchy from results) - select total_sum ,s_state ,s_county, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_county = 0 then s_state end - order by total_sum desc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then s_state end - ,rank_within_parent - limit 100; - --- end template query70a.tpl query 89 in stream 3 --- start template query75.tpl query 90 in stream 3 -WITH /* TPC-DS query75.tpl 0.3 */ all_sales AS ( - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,SUM(sales_cnt) AS sales_cnt - ,SUM(sales_amt) AS sales_amt - FROM (SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,cs_quantity - COALESCE(cr_return_quantity,0) AS sales_cnt - ,cs_ext_sales_price - COALESCE(cr_return_amount,0.0) AS sales_amt - FROM catalog_sales JOIN item ON i_item_sk=cs_item_sk - JOIN date_dim ON d_date_sk=cs_sold_date_sk - LEFT JOIN catalog_returns ON (cs_order_number=cr_order_number - AND cs_item_sk=cr_item_sk) - WHERE i_category='Sports' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ss_quantity - COALESCE(sr_return_quantity,0) AS sales_cnt - ,ss_ext_sales_price - COALESCE(sr_return_amt,0.0) AS sales_amt - FROM store_sales JOIN item ON i_item_sk=ss_item_sk - JOIN date_dim ON d_date_sk=ss_sold_date_sk - LEFT JOIN store_returns ON (ss_ticket_number=sr_ticket_number - AND ss_item_sk=sr_item_sk) - WHERE i_category='Sports' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ws_quantity - COALESCE(wr_return_quantity,0) AS sales_cnt - ,ws_ext_sales_price - COALESCE(wr_return_amt,0.0) AS sales_amt - FROM web_sales JOIN item ON i_item_sk=ws_item_sk - JOIN date_dim ON d_date_sk=ws_sold_date_sk - LEFT JOIN web_returns ON (ws_order_number=wr_order_number - AND ws_item_sk=wr_item_sk) - WHERE i_category='Sports') sales_detail - GROUP BY d_year, i_brand_id, i_class_id, i_category_id, i_manufact_id) - SELECT prev_yr.d_year AS prev_year - ,curr_yr.d_year AS year - ,curr_yr.i_brand_id - ,curr_yr.i_class_id - ,curr_yr.i_category_id - ,curr_yr.i_manufact_id - ,prev_yr.sales_cnt AS prev_yr_cnt - ,curr_yr.sales_cnt AS curr_yr_cnt - ,curr_yr.sales_cnt-prev_yr.sales_cnt AS sales_cnt_diff - ,curr_yr.sales_amt-prev_yr.sales_amt AS sales_amt_diff - FROM all_sales curr_yr, all_sales prev_yr - WHERE curr_yr.i_brand_id=prev_yr.i_brand_id - AND curr_yr.i_class_id=prev_yr.i_class_id - AND curr_yr.i_category_id=prev_yr.i_category_id - AND curr_yr.i_manufact_id=prev_yr.i_manufact_id - AND curr_yr.d_year=2001 - AND prev_yr.d_year=2001-1 - AND CAST(curr_yr.sales_cnt AS DECIMAL(17,2))/CAST(prev_yr.sales_cnt AS DECIMAL(17,2))<0.9 - ORDER BY sales_cnt_diff,sales_amt_diff - limit 100; - --- end template query75.tpl query 90 in stream 3 --- start template query91.tpl query 91 in stream 3 -select /* TPC-DS query91.tpl 0.13 */ - cc_call_center_id Call_Center, - cc_name Call_Center_Name, - cc_manager Manager, - sum(cr_net_loss) Returns_Loss -from - call_center, - catalog_returns, - date_dim, - customer, - customer_address, - customer_demographics, - household_demographics -where - cr_call_center_sk = cc_call_center_sk -and cr_returned_date_sk = d_date_sk -and cr_returning_customer_sk= c_customer_sk -and cd_demo_sk = c_current_cdemo_sk -and hd_demo_sk = c_current_hdemo_sk -and ca_address_sk = c_current_addr_sk -and d_year = 2001 -and d_moy = 12 -and ( (cd_marital_status = 'M' and cd_education_status = 'Unknown') - or(cd_marital_status = 'W' and cd_education_status = 'Advanced Degree')) -and hd_buy_potential like '1001-5000%' -and ca_gmt_offset = -7 -group by cc_call_center_id,cc_name,cc_manager,cd_marital_status,cd_education_status -order by sum(cr_net_loss) desc; - --- end template query91.tpl query 91 in stream 3 --- start template query17.tpl query 92 in stream 3 -select /* TPC-DS query17.tpl 0.41 */ i_item_id - ,i_item_desc - ,s_state - ,count(ss_quantity) as store_sales_quantitycount - ,avg(ss_quantity) as store_sales_quantityave - ,stddev_samp(ss_quantity) as store_sales_quantitystdev - ,stddev_samp(ss_quantity)/avg(ss_quantity) as store_sales_quantitycov - ,count(sr_return_quantity) as store_returns_quantitycount - ,avg(sr_return_quantity) as store_returns_quantityave - ,stddev_samp(sr_return_quantity) as store_returns_quantitystdev - ,stddev_samp(sr_return_quantity)/avg(sr_return_quantity) as store_returns_quantitycov - ,count(cs_quantity) as catalog_sales_quantitycount ,avg(cs_quantity) as catalog_sales_quantityave - ,stddev_samp(cs_quantity) as catalog_sales_quantitystdev - ,stddev_samp(cs_quantity)/avg(cs_quantity) as catalog_sales_quantitycov - from store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where d1.d_quarter_name = '2002Q1' - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_quarter_name in ('2002Q1','2002Q2','2002Q3') - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_quarter_name in ('2002Q1','2002Q2','2002Q3') - group by i_item_id - ,i_item_desc - ,s_state - order by i_item_id - ,i_item_desc - ,s_state -limit 100; - --- end template query17.tpl query 92 in stream 3 --- start template query24.tpl query 93 in stream 3 -with /* TPC-DS query24.tpl 0.92 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_net_paid) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip -and s_market_id=8 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'firebrick' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; -with /* TPC-DS query24.tpl 0.92 part2 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_net_paid) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip - and s_market_id = 8 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'gainsboro' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; - --- end template query24.tpl query 93 in stream 3 --- start template query48.tpl query 94 in stream 3 -select /* TPC-DS query48.tpl 0.74 */ sum (ss_quantity) - from store_sales, store, customer_demographics, customer_address, date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2002 - and - ( - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'U' - and - cd_education_status = 'Advanced Degree' - and - ss_sales_price between 100.00 and 150.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'D' - and - cd_education_status = '2 yr Degree' - and - ss_sales_price between 50.00 and 100.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'M' - and - cd_education_status = 'Primary' - and - ss_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('NC', 'TX', 'IL') - and ss_net_profit between 0 and 2000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('GA', 'OK', 'LA') - and ss_net_profit between 150 and 3000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('CA', 'NJ', 'OH') - and ss_net_profit between 50 and 25000 - ) - ) -; - --- end template query48.tpl query 94 in stream 3 --- start template query51.tpl query 95 in stream 3 -WITH /* TPC-DS query51.tpl 0.46 */ web_v1 as ( -select - ws_item_sk item_sk, d_date, - sum(sum(ws_sales_price)) - over (partition by ws_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from web_sales - ,date_dim -where ws_sold_date_sk=d_date_sk - and d_month_seq between 1220 and 1220+11 - and ws_item_sk is not NULL -group by ws_item_sk, d_date), -store_v1 as ( -select - ss_item_sk item_sk, d_date, - sum(sum(ss_sales_price)) - over (partition by ss_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from store_sales - ,date_dim -where ss_sold_date_sk=d_date_sk - and d_month_seq between 1220 and 1220+11 - and ss_item_sk is not NULL -group by ss_item_sk, d_date) - select * -from (select item_sk - ,d_date - ,web_sales - ,store_sales - ,max(web_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) web_cumulative - ,max(store_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) store_cumulative - from (select case when web.item_sk is not null then web.item_sk else store.item_sk end item_sk - ,case when web.d_date is not null then web.d_date else store.d_date end d_date - ,web.cume_sales web_sales - ,store.cume_sales store_sales - from web_v1 web full outer join store_v1 store on (web.item_sk = store.item_sk - and web.d_date = store.d_date) - )x )y -where web_cumulative > store_cumulative -order by item_sk - ,d_date -limit 100; - --- end template query51.tpl query 95 in stream 3 --- start template query79.tpl query 96 in stream 3 -select /* TPC-DS query79.tpl 0.89 */ - c_last_name,c_first_name,substring(s_city,1,30),ss_ticket_number,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,store.s_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (household_demographics.hd_dep_count = 7 or household_demographics.hd_vehicle_count > -1) - and date_dim.d_dow = 1 - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_number_employees between 200 and 295 - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,store.s_city) ms,customer - where ss_customer_sk = c_customer_sk - order by c_last_name,c_first_name,substring(s_city,1,30), profit -limit 100; - --- end template query79.tpl query 96 in stream 3 --- start template query35a.tpl query 97 in stream 3 -select /* TPC-DS query35a.tpl 0.47 */ - ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - count(*) cnt1, - min(cd_dep_count), - stddev_samp(cd_dep_count), - max(cd_dep_count), - cd_dep_employed_count, - count(*) cnt2, - min(cd_dep_employed_count), - stddev_samp(cd_dep_employed_count), - max(cd_dep_employed_count), - cd_dep_college_count, - count(*) cnt3, - min(cd_dep_college_count), - stddev_samp(cd_dep_college_count), - max(cd_dep_college_count) - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 1999 and - d_qoy < 4) and - exists (select * from - (select ws_bill_customer_sk customsk - from web_sales,date_dim - where - ws_sold_date_sk = d_date_sk and - d_year = 1999 and - d_qoy < 4 - union all - select cs_ship_customer_sk customsk - from catalog_sales,date_dim - where - cs_sold_date_sk = d_date_sk and - d_year = 1999 and - d_qoy < 4)x - where x.customsk = c.c_customer_sk) - group by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - limit 100; - --- end template query35a.tpl query 97 in stream 3 --- start template query88.tpl query 98 in stream 3 -select /* TPC-DS query88.tpl 0.66 */ * -from - (select count(*) h8_30_to_9 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s1, - (select count(*) h9_to_9_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s2, - (select count(*) h9_30_to_10 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s3, - (select count(*) h10_to_10_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s4, - (select count(*) h10_30_to_11 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s5, - (select count(*) h11_to_11_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s6, - (select count(*) h11_30_to_12 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s7, - (select count(*) h12_to_12_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 12 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s8 -; - --- end template query88.tpl query 98 in stream 3 --- start template query49.tpl query 99 in stream 3 -select /* TPC-DS query49.tpl 0.48 */ channel, item, return_ratio, return_rank, currency_rank from - (select - 'web' as channel - ,web.item - ,web.return_ratio - ,web.return_rank - ,web.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select ws.ws_item_sk as item - ,(cast(sum(coalesce(wr.wr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(wr.wr_return_amt,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - web_sales ws left outer join web_returns wr - on (ws.ws_order_number = wr.wr_order_number and - ws.ws_item_sk = wr.wr_item_sk) - ,date_dim - where - wr.wr_return_amt > 10000 - and ws.ws_net_profit > 1 - and ws.ws_net_paid > 0 - and ws.ws_quantity > 0 - and ws_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 11 - group by ws.ws_item_sk - ) in_web - ) web - where - ( - web.return_rank <= 10 - or - web.currency_rank <= 10 - ) - union - select - 'catalog' as channel - ,catalog.item - ,catalog.return_ratio - ,catalog.return_rank - ,catalog.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select - cs.cs_item_sk as item - ,(cast(sum(coalesce(cr.cr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(cr.cr_return_amount,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - catalog_sales cs left outer join catalog_returns cr - on (cs.cs_order_number = cr.cr_order_number and - cs.cs_item_sk = cr.cr_item_sk) - ,date_dim - where - cr.cr_return_amount > 10000 - and cs.cs_net_profit > 1 - and cs.cs_net_paid > 0 - and cs.cs_quantity > 0 - and cs_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 11 - group by cs.cs_item_sk - ) in_cat - ) catalog - where - ( - catalog.return_rank <= 10 - or - catalog.currency_rank <=10 - ) - union - select - 'store' as channel - ,store.item - ,store.return_ratio - ,store.return_rank - ,store.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select sts.ss_item_sk as item - ,(cast(sum(coalesce(sr.sr_return_quantity,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(sr.sr_return_amt,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - store_sales sts left outer join store_returns sr - on (sts.ss_ticket_number = sr.sr_ticket_number and sts.ss_item_sk = sr.sr_item_sk) - ,date_dim - where - sr.sr_return_amt > 10000 - and sts.ss_net_profit > 1 - and sts.ss_net_paid > 0 - and sts.ss_quantity > 0 - and ss_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 11 - group by sts.ss_item_sk - ) in_store - ) store - where ( - store.return_rank <= 10 - or - store.currency_rank <= 10 - ) - ) - order by 1,4,5,2 - limit 100; - --- end template query49.tpl query 99 in stream 3 diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/30TB/queries/query_4.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/30TB/queries/query_4.sql deleted file mode 100644 index 5b441a2f..00000000 --- a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/30TB/queries/query_4.sql +++ /dev/null @@ -1,5027 +0,0 @@ --- start template query79.tpl query 1 in stream 4 -select /* TPC-DS query79.tpl 0.89 */ - c_last_name,c_first_name,substring(s_city,1,30),ss_ticket_number,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,store.s_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (household_demographics.hd_dep_count = 7 or household_demographics.hd_vehicle_count > 0) - and date_dim.d_dow = 1 - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_number_employees between 200 and 295 - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,store.s_city) ms,customer - where ss_customer_sk = c_customer_sk - order by c_last_name,c_first_name,substring(s_city,1,30), profit -limit 100; - --- end template query79.tpl query 1 in stream 4 --- start template query39.tpl query 2 in stream 4 -with /* TPC-DS query39.tpl 0.5 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =1998 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=4 - and inv2.d_moy=4+1 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; -with /* TPC-DS query39.tpl 0.5 part2 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =1998 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=4 - and inv2.d_moy=4+1 - and inv1.cov > 1.5 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; - --- end template query39.tpl query 2 in stream 4 --- start template query93.tpl query 3 in stream 4 -select /* TPC-DS query93.tpl 0.52 */ ss_customer_sk - ,sum(act_sales) sumsales - from (select ss_item_sk - ,ss_ticket_number - ,ss_customer_sk - ,case when sr_return_quantity is not null then (ss_quantity-sr_return_quantity)*ss_sales_price - else (ss_quantity*ss_sales_price) end act_sales - from store_sales left outer join store_returns on (sr_item_sk = ss_item_sk - and sr_ticket_number = ss_ticket_number) - ,reason - where sr_reason_sk = r_reason_sk - and r_reason_desc = 'reason 71') t - group by ss_customer_sk - order by sumsales, ss_customer_sk -limit 100; - --- end template query93.tpl query 3 in stream 4 --- start template query41.tpl query 4 in stream 4 -select /* TPC-DS query41.tpl 0.62 */ distinct(i_product_name) - from item i1 - where i_manufact_id between 990 and 990+40 - and (select count(*) as item_cnt - from item - where (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'slate' or i_color = 'linen') and - (i_units = 'Ounce' or i_units = 'Pallet') and - (i_size = 'petite' or i_size = 'N/A') - ) or - (i_category = 'Women' and - (i_color = 'firebrick' or i_color = 'honeydew') and - (i_units = 'Dozen' or i_units = 'Oz') and - (i_size = 'large' or i_size = 'economy') - ) or - (i_category = 'Men' and - (i_color = 'coral' or i_color = 'rose') and - (i_units = 'Ton' or i_units = 'Bundle') and - (i_size = 'small' or i_size = 'extra large') - ) or - (i_category = 'Men' and - (i_color = 'frosted' or i_color = 'maroon') and - (i_units = 'Cup' or i_units = 'Carton') and - (i_size = 'petite' or i_size = 'N/A') - ))) or - (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'sky' or i_color = 'sienna') and - (i_units = 'Box' or i_units = 'Gross') and - (i_size = 'petite' or i_size = 'N/A') - ) or - (i_category = 'Women' and - (i_color = 'blush' or i_color = 'spring') and - (i_units = 'Unknown' or i_units = 'Bunch') and - (i_size = 'large' or i_size = 'economy') - ) or - (i_category = 'Men' and - (i_color = 'seashell' or i_color = 'indian') and - (i_units = 'Tsp' or i_units = 'Lb') and - (i_size = 'small' or i_size = 'extra large') - ) or - (i_category = 'Men' and - (i_color = 'burlywood' or i_color = 'grey') and - (i_units = 'Case' or i_units = 'Pound') and - (i_size = 'petite' or i_size = 'N/A') - )))) > 0 - order by i_product_name - limit 100; - --- end template query41.tpl query 4 in stream 4 --- start template query29.tpl query 5 in stream 4 -select /* TPC-DS query29.tpl 0.53 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,min(ss_quantity) as store_sales_quantity - ,min(sr_return_quantity) as store_returns_quantity - ,min(cs_quantity) as catalog_sales_quantity - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 1998 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 4 + 3 - and d2.d_year = 1998 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_year in (1998,1998+1,1998+2) - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query29.tpl query 5 in stream 4 --- start template query32.tpl query 6 in stream 4 -select /* TPC-DS query32.tpl 0.7 */ sum(cs_ext_discount_amt) as "excess discount amount" -from - catalog_sales - ,item - ,date_dim -where -i_manufact_id = 688 -and i_item_sk = cs_item_sk -and d_date between '1999-02-06' and - dateadd(day,90,cast('1999-02-06' as date)) -and d_date_sk = cs_sold_date_sk -and cs_ext_discount_amt - > ( - select - 1.3 * avg(cs_ext_discount_amt) - from - catalog_sales - ,date_dim - where - cs_item_sk = i_item_sk - and d_date between '1999-02-06' and - dateadd(day,90,cast('1999-02-06' as date)) - and d_date_sk = cs_sold_date_sk - ) -limit 100; - --- end template query32.tpl query 6 in stream 4 --- start template query66.tpl query 7 in stream 4 -select /* TPC-DS query66.tpl 0.39 */ - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - ,sum(jan_sales) as jan_sales - ,sum(feb_sales) as feb_sales - ,sum(mar_sales) as mar_sales - ,sum(apr_sales) as apr_sales - ,sum(may_sales) as may_sales - ,sum(jun_sales) as jun_sales - ,sum(jul_sales) as jul_sales - ,sum(aug_sales) as aug_sales - ,sum(sep_sales) as sep_sales - ,sum(oct_sales) as oct_sales - ,sum(nov_sales) as nov_sales - ,sum(dec_sales) as dec_sales - ,sum(jan_sales/w_warehouse_sq_ft) as jan_sales_per_sq_foot - ,sum(feb_sales/w_warehouse_sq_ft) as feb_sales_per_sq_foot - ,sum(mar_sales/w_warehouse_sq_ft) as mar_sales_per_sq_foot - ,sum(apr_sales/w_warehouse_sq_ft) as apr_sales_per_sq_foot - ,sum(may_sales/w_warehouse_sq_ft) as may_sales_per_sq_foot - ,sum(jun_sales/w_warehouse_sq_ft) as jun_sales_per_sq_foot - ,sum(jul_sales/w_warehouse_sq_ft) as jul_sales_per_sq_foot - ,sum(aug_sales/w_warehouse_sq_ft) as aug_sales_per_sq_foot - ,sum(sep_sales/w_warehouse_sq_ft) as sep_sales_per_sq_foot - ,sum(oct_sales/w_warehouse_sq_ft) as oct_sales_per_sq_foot - ,sum(nov_sales/w_warehouse_sq_ft) as nov_sales_per_sq_foot - ,sum(dec_sales/w_warehouse_sq_ft) as dec_sales_per_sq_foot - ,sum(jan_net) as jan_net - ,sum(feb_net) as feb_net - ,sum(mar_net) as mar_net - ,sum(apr_net) as apr_net - ,sum(may_net) as may_net - ,sum(jun_net) as jun_net - ,sum(jul_net) as jul_net - ,sum(aug_net) as aug_net - ,sum(sep_net) as sep_net - ,sum(oct_net) as oct_net - ,sum(nov_net) as nov_net - ,sum(dec_net) as dec_net - from ( - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'GREAT EASTERN' || ',' || 'ORIENTAL' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then ws_ext_list_price* ws_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then ws_ext_list_price* ws_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then ws_ext_list_price* ws_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then ws_ext_list_price* ws_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then ws_ext_list_price* ws_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then ws_ext_list_price* ws_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then ws_ext_list_price* ws_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then ws_ext_list_price* ws_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then ws_ext_list_price* ws_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then ws_ext_list_price* ws_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then ws_ext_list_price* ws_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then ws_ext_list_price* ws_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as dec_net - from - web_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - ws_warehouse_sk = w_warehouse_sk - and ws_sold_date_sk = d_date_sk - and ws_sold_time_sk = t_time_sk - and ws_ship_mode_sk = sm_ship_mode_sk - and d_year = 2001 - and t_time between 56485 and 56485+28800 - and sm_carrier in ('GREAT EASTERN','ORIENTAL') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - union all - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'GREAT EASTERN' || ',' || 'ORIENTAL' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then cs_ext_list_price* cs_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then cs_ext_list_price* cs_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then cs_ext_list_price* cs_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then cs_ext_list_price* cs_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then cs_ext_list_price* cs_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then cs_ext_list_price* cs_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then cs_ext_list_price* cs_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then cs_ext_list_price* cs_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then cs_ext_list_price* cs_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then cs_ext_list_price* cs_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then cs_ext_list_price* cs_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then cs_ext_list_price* cs_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then cs_net_profit * cs_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then cs_net_profit * cs_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then cs_net_profit * cs_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then cs_net_profit * cs_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then cs_net_profit * cs_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then cs_net_profit * cs_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then cs_net_profit * cs_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then cs_net_profit * cs_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then cs_net_profit * cs_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then cs_net_profit * cs_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then cs_net_profit * cs_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then cs_net_profit * cs_quantity else 0 end) as dec_net - from - catalog_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and cs_sold_time_sk = t_time_sk - and cs_ship_mode_sk = sm_ship_mode_sk - and d_year = 2001 - and t_time between 56485 AND 56485+28800 - and sm_carrier in ('GREAT EASTERN','ORIENTAL') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - ) x - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - order by w_warehouse_name - limit 100; - --- end template query66.tpl query 7 in stream 4 --- start template query84.tpl query 8 in stream 4 -select /* TPC-DS query84.tpl 0.80 */ c_customer_id as customer_id - , coalesce(c_last_name,'') || ', ' || coalesce(c_first_name,'') as customername - from customer - ,customer_address - ,customer_demographics - ,household_demographics - ,income_band - ,store_returns - where ca_city = 'Springfield' - and c_current_addr_sk = ca_address_sk - and ib_lower_bound >= 33365 - and ib_upper_bound <= 33365 + 50000 - and ib_income_band_sk = hd_income_band_sk - and cd_demo_sk = c_current_cdemo_sk - and hd_demo_sk = c_current_hdemo_sk - and sr_cdemo_sk = cd_demo_sk - order by c_customer_id - limit 100; - --- end template query84.tpl query 8 in stream 4 --- start template query8.tpl query 9 in stream 4 -select /* TPC-DS query8.tpl 0.63 */ s_store_name - ,sum(ss_net_profit) - from store_sales - ,date_dim - ,store, - (select ca_zip - from ( - SELECT substring(ca_zip,1,5) ca_zip - FROM customer_address - WHERE substring(ca_zip,1,5) IN ( - '67765','19292','15841','56044','99881','83830', - '45333','81782','16394','17286','42886', - '48353','99668','15676','71634','90163', - '32767','89344','72083','97026','46246', - '29864','22376','76410','24313','83803', - '97548','94959','57256','21486','45203', - '93699','81765','13713','33267','44846', - '52915','66355','83424','15717','31091', - '27186','57449','97010','66292','64764', - '82856','80094','22996','52117','65751', - '50610','70212','15182','58049','67837', - '42349','47786','49589','11257','82566', - '47904','34002','78800','48751','47940', - '77724','32591','38404','78475','62541', - '32644','15863','26504','44283','93228', - '16949','58601','19407','61617','35809', - '49915','78109','39240','43012','65679', - '23095','89521','14874','55903','63522', - '81345','12638','42060','98020','33651', - '63559','91939','91572','43965','14833', - '95737','90835','83145','99686','35505', - '91941','21798','89666','74203','44433', - '12398','32685','37444','36537','63734', - '89339','88520','69387','86964','62679', - '55359','24242','28685','41493','90136', - '82122','87365','92590','87231','17807', - '44635','47325','66764','80208','39478', - '83755','51858','29840','82220','55649', - '53242','62413','47246','84668','45509', - '32905','47905','24631','61894','50850', - '87415','34539','21444','71969','72749', - '79598','62835','30195','95052','54476', - '22003','31394','13569','82410','71487', - '23287','73438','55616','85571','62759', - '22055','27097','72739','70164','44300', - '52064','84424','86779','40010','48554', - '51407','82645','73373','86653','11325', - '27777','54992','93245','68879','65684', - '36209','64522','15218','34919','74486', - '65133','40615','69147','93615','38703', - '14291','87464','91850','75008','50168', - '31988','13022','50993','56453','42008', - '47714','70547','99509','46912','68768', - '81251','77855','48283','54283','14594', - '39139','50441','62807','17280','22806', - '98231','17674','48029','33630','54024', - '12244','77766','89583','28088','66878', - '78903','72585','71930','35343','45790', - '81507','89881','65405','71381','32523', - '92638','26067','78847','50052','92645', - '81767','45015','86704','94948','67142', - '99364','87135','84047','83342','48335', - '20250','90552','28066','27480','55168', - '90508','28469','25232','90510','95121', - '53969','90055','40418','56129','51235', - '71588','23953','50981','13113','44279', - '95079','32545','82364','45017','38405', - '51356','55127','93541','94185','84572', - '91872','64147','45803','11177','91632', - '17793','98324','99378','48238','59013', - '33418','68579','34264','60806','79601', - '39768','22062','77164','20217','12126', - '28149','40968','38936','72143','10602', - '26316','36872','91039','64304','57182', - '89753','33553','64493','14818','67550', - '77415','84896','43269','66410','48895', - '39128','26710','49404','78114','31569', - '51082','33407','62675','67991','89444', - '69705','74756','39600','94194','93218', - '30553','49403','11095','48483','62352', - '78040','48729','42965','87713','45046', - '81702','53430','84818','67223','80062', - '64825','15495','72468','37617','80787', - '25041','67200','34897','10623','19278', - '66809','95479','74482','25710','80952', - '63298','58355','46548','66554','60137', - '25889','65843','77396','59992','79506', - '31958','54165','11455','73674','21829', - '43241','47946','81217','42932','67153', - '44801','75190','57619','88047') - intersect - select ca_zip - from (SELECT substring(ca_zip,1,5) ca_zip,count(*) cnt - FROM customer_address, customer - WHERE ca_address_sk = c_current_addr_sk and - c_preferred_cust_flag='Y' - group by ca_zip - having count(*) > 10)A1)A2) V1 - where ss_store_sk = s_store_sk - and ss_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 1999 - and (substring(s_zip,1,2) = substring(V1.ca_zip,1,2)) - group by s_store_name - order by s_store_name - limit 100; - --- end template query8.tpl query 9 in stream 4 --- start template query71.tpl query 10 in stream 4 -select /* TPC-DS query71.tpl 0.72 */ i_brand_id brand_id, i_brand brand,t_hour,t_minute, - sum(ext_price) ext_price - from item, (select ws_ext_sales_price as ext_price, - ws_sold_date_sk as sold_date_sk, - ws_item_sk as sold_item_sk, - ws_sold_time_sk as time_sk - from web_sales,date_dim - where d_date_sk = ws_sold_date_sk - and d_moy=11 - and d_year=2000 - union all - select cs_ext_sales_price as ext_price, - cs_sold_date_sk as sold_date_sk, - cs_item_sk as sold_item_sk, - cs_sold_time_sk as time_sk - from catalog_sales,date_dim - where d_date_sk = cs_sold_date_sk - and d_moy=11 - and d_year=2000 - union all - select ss_ext_sales_price as ext_price, - ss_sold_date_sk as sold_date_sk, - ss_item_sk as sold_item_sk, - ss_sold_time_sk as time_sk - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - and d_moy=11 - and d_year=2000 - ) tmp,time_dim - where - sold_item_sk = i_item_sk - and i_manager_id=1 - and time_sk = t_time_sk - and (t_meal_time = 'breakfast' or t_meal_time = 'dinner') - group by i_brand, i_brand_id,t_hour,t_minute - order by ext_price desc, i_brand_id - ; - --- end template query71.tpl query 10 in stream 4 --- start template query45.tpl query 11 in stream 4 -select /* TPC-DS query45.tpl 0.18 */ ca_zip, ca_state, sum(ws_sales_price) - from web_sales, customer, customer_address, date_dim, item - where ws_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ws_item_sk = i_item_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', '85392', '85460', '80348', '81792') - or - i_item_id in (select i_item_id - from item - where i_item_sk in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29) - ) - ) - and ws_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 2000 - group by ca_zip, ca_state - order by ca_zip, ca_state - limit 100; - --- end template query45.tpl query 11 in stream 4 --- start template query89.tpl query 12 in stream 4 -select /* TPC-DS query89.tpl 0.56 */ * -from( -select i_category, i_class, i_brand, - s_store_name, s_company_name, - d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, s_store_name, s_company_name) - avg_monthly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - d_year in (1999) and - ((i_category in ('Home','Shoes','Children') and - i_class in ('decor','mens','infants') - ) - or (i_category in ('Sports','Books','Men') and - i_class in ('pools','reference','sports-apparel') - )) -group by i_category, i_class, i_brand, - s_store_name, s_company_name, d_moy) tmp1 -where case when (avg_monthly_sales <> 0) then (abs(sum_sales - avg_monthly_sales) / avg_monthly_sales) else null end > 0.1 -order by sum_sales - avg_monthly_sales, s_store_name -limit 100; - --- end template query89.tpl query 12 in stream 4 --- start template query91.tpl query 13 in stream 4 -select /* TPC-DS query91.tpl 0.13 */ - cc_call_center_id Call_Center, - cc_name Call_Center_Name, - cc_manager Manager, - sum(cr_net_loss) Returns_Loss -from - call_center, - catalog_returns, - date_dim, - customer, - customer_address, - customer_demographics, - household_demographics -where - cr_call_center_sk = cc_call_center_sk -and cr_returned_date_sk = d_date_sk -and cr_returning_customer_sk= c_customer_sk -and cd_demo_sk = c_current_cdemo_sk -and hd_demo_sk = c_current_hdemo_sk -and ca_address_sk = c_current_addr_sk -and d_year = 2002 -and d_moy = 11 -and ( (cd_marital_status = 'M' and cd_education_status = 'Unknown') - or(cd_marital_status = 'W' and cd_education_status = 'Advanced Degree')) -and hd_buy_potential like '5001-10000%' -and ca_gmt_offset = -6 -group by cc_call_center_id,cc_name,cc_manager,cd_marital_status,cd_education_status -order by sum(cr_net_loss) desc; - --- end template query91.tpl query 13 in stream 4 --- start template query14a.tpl query 14 in stream 4 -with /* TPC-DS query14a.tpl 0.69 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1999 AND 1999 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1999 AND 1999 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1999 AND 1999 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as - (select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2) x) -, - results AS -(select channel, i_brand_id, i_class_id, i_category_id, sum(sales) sum_sales, sum(number_sales) number_sales - from ( - select 'store' channel, i_brand_id,i_class_id - ,i_category_id,sum(ss_quantity*ss_list_price) sales - , count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1999+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales) - union all - select 'catalog' channel, i_brand_id,i_class_id,i_category_id, sum(cs_quantity*cs_list_price) sales, count(*) number_sales - from catalog_sales - ,item - ,date_dim - where cs_item_sk in (select ss_item_sk from cross_items) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1999+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(cs_quantity*cs_list_price) > (select average_sales from avg_sales) - union all - select 'web' channel, i_brand_id,i_class_id,i_category_id, sum(ws_quantity*ws_list_price) sales , count(*) number_sales - from web_sales - ,item - ,date_dim - where ws_item_sk in (select ss_item_sk from cross_items) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1999+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ws_quantity*ws_list_price) > (select average_sales from avg_sales) - ) y - group by channel, i_brand_id,i_class_id,i_category_id) - - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales -from ( - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales from results - union - select channel, i_brand_id, i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id, i_class_id - union - select channel, i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id - union - select channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel - union - select null as channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results) z -order by channel, i_brand_id, i_class_id, i_category_id - limit 100; -with /* TPC-DS query14a.tpl 0.69 part2 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1999 AND 1999 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1999 AND 1999 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1999 AND 1999 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as -(select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2) x) - select this_year.channel ty_channel - ,this_year.i_brand_id ty_brand - ,this_year.i_class_id ty_class - ,this_year.i_category_id ty_category - ,this_year.sales ty_sales - ,this_year.number_sales ty_number_sales - ,last_year.channel ly_channel - ,last_year.i_brand_id ly_brand - ,last_year.i_class_id ly_class - ,last_year.i_category_id ly_category - ,last_year.sales ly_sales - ,last_year.number_sales ly_number_sales -from - (select 'store' channel, i_brand_id,i_class_id,i_category_id - ,sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1999 + 1 - and d_moy = 12 - and d_dom = 7) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) this_year, - (select 'store' channel, i_brand_id,i_class_id - ,i_category_id, sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1999 - and d_moy = 12 - and d_dom = 7) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) last_year - where this_year.i_brand_id= last_year.i_brand_id - and this_year.i_class_id = last_year.i_class_id - and this_year.i_category_id = last_year.i_category_id - order by this_year.channel, this_year.i_brand_id, this_year.i_class_id, this_year.i_category_id - limit 100; - --- end template query14a.tpl query 14 in stream 4 --- start template query46.tpl query 15 in stream 4 -select /* TPC-DS query46.tpl 0.23 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and (household_demographics.hd_dep_count = 2 or - household_demographics.hd_vehicle_count= 1) - and date_dim.d_dow in (6,0) - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_city in ('Weston','Brighton','Smyrna','Sunrise','Unionville') - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,ca_city) dn,customer,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - limit 100; - --- end template query46.tpl query 15 in stream 4 --- start template query58.tpl query 16 in stream 4 -with /* TPC-DS query58.tpl 0.19 */ ss_items as - (select i_item_id item_id - ,sum(ss_ext_sales_price) ss_item_rev - from store_sales - ,item - ,date_dim - where ss_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '1999-07-17')) - and ss_sold_date_sk = d_date_sk - group by i_item_id), - cs_items as - (select i_item_id item_id - ,sum(cs_ext_sales_price) cs_item_rev - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '1999-07-17')) - and cs_sold_date_sk = d_date_sk - group by i_item_id), - ws_items as - (select i_item_id item_id - ,sum(ws_ext_sales_price) ws_item_rev - from web_sales - ,item - ,date_dim - where ws_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq =(select d_week_seq - from date_dim - where d_date = '1999-07-17')) - and ws_sold_date_sk = d_date_sk - group by i_item_id) - select ss_items.item_id - ,ss_item_rev - ,ss_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ss_dev - ,cs_item_rev - ,cs_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 cs_dev - ,ws_item_rev - ,ws_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ws_dev - ,(ss_item_rev+cs_item_rev+ws_item_rev)/3 average - from ss_items,cs_items,ws_items - where ss_items.item_id=cs_items.item_id - and ss_items.item_id=ws_items.item_id - and ss_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - and ss_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and cs_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and cs_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and ws_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and ws_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - order by item_id - ,ss_item_rev - limit 100; - --- end template query58.tpl query 16 in stream 4 --- start template query48.tpl query 17 in stream 4 -select /* TPC-DS query48.tpl 0.74 */ sum (ss_quantity) - from store_sales, store, customer_demographics, customer_address, date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 1999 - and - ( - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'W' - and - cd_education_status = '4 yr Degree' - and - ss_sales_price between 100.00 and 150.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'D' - and - cd_education_status = 'College' - and - ss_sales_price between 50.00 and 100.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'S' - and - cd_education_status = 'Primary' - and - ss_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('NE', 'GA', 'LA') - and ss_net_profit between 0 and 2000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('TX', 'SD', 'PA') - and ss_net_profit between 150 and 3000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('MS', 'VA', 'UT') - and ss_net_profit between 50 and 25000 - ) - ) -; - --- end template query48.tpl query 17 in stream 4 --- start template query59.tpl query 18 in stream 4 -with /* TPC-DS query59.tpl 0.30 */ wss as - (select d_week_seq, - ss_store_sk, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - group by d_week_seq,ss_store_sk - ) - select s_store_name1,s_store_id1,d_week_seq1 - ,sun_sales1/sun_sales2,mon_sales1/mon_sales2 - ,tue_sales1/tue_sales2,wed_sales1/wed_sales2,thu_sales1/thu_sales2 - ,fri_sales1/fri_sales2,sat_sales1/sat_sales2 - from - (select s_store_name s_store_name1,wss.d_week_seq d_week_seq1 - ,s_store_id s_store_id1,sun_sales sun_sales1 - ,mon_sales mon_sales1,tue_sales tue_sales1 - ,wed_sales wed_sales1,thu_sales thu_sales1 - ,fri_sales fri_sales1,sat_sales sat_sales1 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1194 and 1194 + 11) y, - (select s_store_name s_store_name2,wss.d_week_seq d_week_seq2 - ,s_store_id s_store_id2,sun_sales sun_sales2 - ,mon_sales mon_sales2,tue_sales tue_sales2 - ,wed_sales wed_sales2,thu_sales thu_sales2 - ,fri_sales fri_sales2,sat_sales sat_sales2 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1194+ 12 and 1194 + 23) x - where s_store_id1=s_store_id2 - and d_week_seq1=d_week_seq2-52 - order by s_store_name1,s_store_id1,d_week_seq1 -limit 100; - --- end template query59.tpl query 18 in stream 4 --- start template query2.tpl query 19 in stream 4 -with /* TPC-DS query2.tpl 0.84 */ wscs as - (select sold_date_sk - ,sales_price - from (select ws_sold_date_sk sold_date_sk - ,ws_ext_sales_price sales_price - from web_sales - union all - select cs_sold_date_sk sold_date_sk - ,cs_ext_sales_price sales_price - from catalog_sales)), - wswscs as - (select d_week_seq, - sum(case when (d_day_name='Sunday') then sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then sales_price else null end) sat_sales - from wscs - ,date_dim - where d_date_sk = sold_date_sk - group by d_week_seq) - select d_week_seq1 - ,round(sun_sales1/sun_sales2,2) - ,round(mon_sales1/mon_sales2,2) - ,round(tue_sales1/tue_sales2,2) - ,round(wed_sales1/wed_sales2,2) - ,round(thu_sales1/thu_sales2,2) - ,round(fri_sales1/fri_sales2,2) - ,round(sat_sales1/sat_sales2,2) - from - (select wswscs.d_week_seq d_week_seq1 - ,sun_sales sun_sales1 - ,mon_sales mon_sales1 - ,tue_sales tue_sales1 - ,wed_sales wed_sales1 - ,thu_sales thu_sales1 - ,fri_sales fri_sales1 - ,sat_sales sat_sales1 - from wswscs,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 1998) y, - (select wswscs.d_week_seq d_week_seq2 - ,sun_sales sun_sales2 - ,mon_sales mon_sales2 - ,tue_sales tue_sales2 - ,wed_sales wed_sales2 - ,thu_sales thu_sales2 - ,fri_sales fri_sales2 - ,sat_sales sat_sales2 - from wswscs - ,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 1998+1) z - where d_week_seq1=d_week_seq2-53 - order by d_week_seq1; - --- end template query2.tpl query 19 in stream 4 --- start template query83.tpl query 20 in stream 4 -with /* TPC-DS query83.tpl 0.96 */ sr_items as - (select i_item_id item_id, - sum(sr_return_quantity) sr_item_qty - from store_returns, - item, - date_dim - where sr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('1998-04-04','1998-08-24','1998-11-04'))) - and sr_returned_date_sk = d_date_sk - group by i_item_id), - cr_items as - (select i_item_id item_id, - sum(cr_return_quantity) cr_item_qty - from catalog_returns, - item, - date_dim - where cr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('1998-04-04','1998-08-24','1998-11-04'))) - and cr_returned_date_sk = d_date_sk - group by i_item_id), - wr_items as - (select i_item_id item_id, - sum(wr_return_quantity) wr_item_qty - from web_returns, - item, - date_dim - where wr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('1998-04-04','1998-08-24','1998-11-04'))) - and wr_returned_date_sk = d_date_sk - group by i_item_id) - select sr_items.item_id - ,sr_item_qty - ,sr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 sr_dev - ,cr_item_qty - ,cr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 cr_dev - ,wr_item_qty - ,wr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 wr_dev - ,(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 average - from sr_items - ,cr_items - ,wr_items - where sr_items.item_id=cr_items.item_id - and sr_items.item_id=wr_items.item_id - order by sr_items.item_id - ,sr_item_qty - limit 100; - --- end template query83.tpl query 20 in stream 4 --- start template query21.tpl query 21 in stream 4 -select /* TPC-DS query21.tpl 0.14 */ * - from(select w_warehouse_name - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('2002-03-31' as date)) - then inv_quantity_on_hand - else 0 end) as inv_before - ,sum(case when (cast(d_date as date) >= cast ('2002-03-31' as date)) - then inv_quantity_on_hand - else 0 end) as inv_after - from inventory - ,warehouse - ,item - ,date_dim - where i_current_price between 0.99 and 1.49 - and i_item_sk = inv_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('2002-03-31' as date)) - and dateadd(day,30,cast ('2002-03-31' as date)) - group by w_warehouse_name, i_item_id) x - where (case when inv_before > 0 - then inv_after / inv_before - else null - end) between 2.0/3.0 and 3.0/2.0 - order by w_warehouse_name - ,i_item_id - limit 100; - --- end template query21.tpl query 21 in stream 4 --- start template query78.tpl query 22 in stream 4 -with /* TPC-DS query78.tpl 0.10 */ ws as - (select d_year AS ws_sold_year, ws_item_sk, - ws_bill_customer_sk ws_customer_sk, - sum(ws_quantity) ws_qty, - sum(ws_wholesale_cost) ws_wc, - sum(ws_sales_price) ws_sp - from web_sales - left join web_returns on wr_order_number=ws_order_number and ws_item_sk=wr_item_sk - join date_dim on ws_sold_date_sk = d_date_sk - where wr_order_number is null - group by d_year, ws_item_sk, ws_bill_customer_sk - ), -cs as - (select d_year AS cs_sold_year, cs_item_sk, - cs_bill_customer_sk cs_customer_sk, - sum(cs_quantity) cs_qty, - sum(cs_wholesale_cost) cs_wc, - sum(cs_sales_price) cs_sp - from catalog_sales - left join catalog_returns on cr_order_number=cs_order_number and cs_item_sk=cr_item_sk - join date_dim on cs_sold_date_sk = d_date_sk - where cr_order_number is null - group by d_year, cs_item_sk, cs_bill_customer_sk - ), -ss as - (select d_year AS ss_sold_year, ss_item_sk, - ss_customer_sk, - sum(ss_quantity) ss_qty, - sum(ss_wholesale_cost) ss_wc, - sum(ss_sales_price) ss_sp - from store_sales - left join store_returns on sr_ticket_number=ss_ticket_number and ss_item_sk=sr_item_sk - join date_dim on ss_sold_date_sk = d_date_sk - where sr_ticket_number is null - group by d_year, ss_item_sk, ss_customer_sk - ) - select -ss_item_sk, -round(ss_qty/(coalesce(ws_qty,0)+coalesce(cs_qty,0)),2) ratio, -ss_qty store_qty, ss_wc store_wholesale_cost, ss_sp store_sales_price, -coalesce(ws_qty,0)+coalesce(cs_qty,0) other_chan_qty, -coalesce(ws_wc,0)+coalesce(cs_wc,0) other_chan_wholesale_cost, -coalesce(ws_sp,0)+coalesce(cs_sp,0) other_chan_sales_price -from ss -left join ws on (ws_sold_year=ss_sold_year and ws_item_sk=ss_item_sk and ws_customer_sk=ss_customer_sk) -left join cs on (cs_sold_year=ss_sold_year and cs_item_sk=ss_item_sk and cs_customer_sk=ss_customer_sk) -where (coalesce(ws_qty,0)>0 or coalesce(cs_qty, 0)>0) and ss_sold_year=2002 -order by - ss_item_sk, - ss_qty desc, ss_wc desc, ss_sp desc, - other_chan_qty, - other_chan_wholesale_cost, - other_chan_sales_price, - ratio -limit 100; - --- end template query78.tpl query 22 in stream 4 --- start template query40.tpl query 23 in stream 4 -select /* TPC-DS query40.tpl 0.86 */ - w_state - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('1998-02-28' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_before - ,sum(case when (cast(d_date as date) >= cast ('1998-02-28' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_after - from - catalog_sales left outer join catalog_returns on - (cs_order_number = cr_order_number - and cs_item_sk = cr_item_sk) - ,warehouse - ,item - ,date_dim - where - i_current_price between 0.99 and 1.49 - and i_item_sk = cs_item_sk - and cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('1998-02-28' as date)) - and dateadd(day,30,cast ('1998-02-28' as date)) - group by - w_state,i_item_id - order by w_state,i_item_id -limit 100; - --- end template query40.tpl query 23 in stream 4 --- start template query99.tpl query 24 in stream 4 -select /* TPC-DS query99.tpl 0.94 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 30) and - (cs_ship_date_sk - cs_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 60) and - (cs_ship_date_sk - cs_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 90) and - (cs_ship_date_sk - cs_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - catalog_sales - ,warehouse - ,ship_mode - ,call_center - ,date_dim -where - d_month_seq between 1214 and 1214 + 11 -and cs_ship_date_sk = d_date_sk -and cs_warehouse_sk = w_warehouse_sk -and cs_ship_mode_sk = sm_ship_mode_sk -and cs_call_center_sk = cc_call_center_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -limit 100; - --- end template query99.tpl query 24 in stream 4 --- start template query19.tpl query 25 in stream 4 -select /* TPC-DS query19.tpl 0.8 */ i_brand_id brand_id, i_brand brand, i_manufact_id, i_manufact, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item,customer,customer_address,store - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=31 - and d_moy=11 - and d_year=2002 - and ss_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and substring(ca_zip,1,5) <> substring(s_zip,1,5) - and ss_store_sk = s_store_sk - group by i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact - order by ext_price desc - ,i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact -limit 100 ; - --- end template query19.tpl query 25 in stream 4 --- start template query72.tpl query 26 in stream 4 -select /* TPC-DS query72.tpl 0.87 */ i_item_desc - ,w_warehouse_name - ,d1.d_week_seq - ,sum(case when p_promo_sk is null then 1 else 0 end) no_promo - ,sum(case when p_promo_sk is not null then 1 else 0 end) promo - ,count(*) total_cnt -from catalog_sales -join inventory on (cs_item_sk = inv_item_sk) -join warehouse on (w_warehouse_sk=inv_warehouse_sk) -join item on (i_item_sk = cs_item_sk) -join customer_demographics on (cs_bill_cdemo_sk = cd_demo_sk) -join household_demographics on (cs_bill_hdemo_sk = hd_demo_sk) -join date_dim d1 on (cs_sold_date_sk = d1.d_date_sk) -join date_dim d2 on (inv_date_sk = d2.d_date_sk) -join date_dim d3 on (cs_ship_date_sk = d3.d_date_sk) -left outer join promotion on (cs_promo_sk=p_promo_sk) -left outer join catalog_returns on (cr_item_sk = cs_item_sk and cr_order_number = cs_order_number) -where d1.d_week_seq = d2.d_week_seq - and inv_quantity_on_hand < cs_quantity - and d3.d_date > d1.d_date + 5 - and hd_buy_potential = '1001-5000' - and d1.d_year = 2000 - and cd_marital_status = 'W' -group by i_item_desc,w_warehouse_name,d1.d_week_seq -order by total_cnt desc, i_item_desc, w_warehouse_name, d_week_seq -limit 100; - --- end template query72.tpl query 26 in stream 4 --- start template query6.tpl query 27 in stream 4 -select /* TPC-DS query6.tpl 0.58 */ a.ca_state state, count(*) cnt - from customer_address a - ,customer c - ,store_sales s - ,date_dim d - ,item i - where a.ca_address_sk = c.c_current_addr_sk - and c.c_customer_sk = s.ss_customer_sk - and s.ss_sold_date_sk = d.d_date_sk - and s.ss_item_sk = i.i_item_sk - and d.d_month_seq = - (select distinct (d_month_seq) - from date_dim - where d_year = 2000 - and d_moy = 2 ) - and i.i_current_price > 1.2 * - (select avg(j.i_current_price) - from item j - where j.i_category = i.i_category) - group by a.ca_state - having count(*) >= 10 - order by cnt, a.ca_state - limit 100; - --- end template query6.tpl query 27 in stream 4 --- start template query28.tpl query 28 in stream 4 -select /* TPC-DS query28.tpl 0.36 */ * -from (select avg(ss_list_price) B1_LP - ,count(ss_list_price) B1_CNT - ,count(distinct ss_list_price) B1_CNTD - from store_sales - where ss_quantity between 0 and 5 - and (ss_list_price between 83 and 83+10 - or ss_coupon_amt between 7842 and 7842+1000 - or ss_wholesale_cost between 54 and 54+20)) B1, - (select avg(ss_list_price) B2_LP - ,count(ss_list_price) B2_CNT - ,count(distinct ss_list_price) B2_CNTD - from store_sales - where ss_quantity between 6 and 10 - and (ss_list_price between 33 and 33+10 - or ss_coupon_amt between 4192 and 4192+1000 - or ss_wholesale_cost between 69 and 69+20)) B2, - (select avg(ss_list_price) B3_LP - ,count(ss_list_price) B3_CNT - ,count(distinct ss_list_price) B3_CNTD - from store_sales - where ss_quantity between 11 and 15 - and (ss_list_price between 109 and 109+10 - or ss_coupon_amt between 3933 and 3933+1000 - or ss_wholesale_cost between 76 and 76+20)) B3, - (select avg(ss_list_price) B4_LP - ,count(ss_list_price) B4_CNT - ,count(distinct ss_list_price) B4_CNTD - from store_sales - where ss_quantity between 16 and 20 - and (ss_list_price between 99 and 99+10 - or ss_coupon_amt between 4051 and 4051+1000 - or ss_wholesale_cost between 51 and 51+20)) B4, - (select avg(ss_list_price) B5_LP - ,count(ss_list_price) B5_CNT - ,count(distinct ss_list_price) B5_CNTD - from store_sales - where ss_quantity between 21 and 25 - and (ss_list_price between 129 and 129+10 - or ss_coupon_amt between 15475 and 15475+1000 - or ss_wholesale_cost between 12 and 12+20)) B5, - (select avg(ss_list_price) B6_LP - ,count(ss_list_price) B6_CNT - ,count(distinct ss_list_price) B6_CNTD - from store_sales - where ss_quantity between 26 and 30 - and (ss_list_price between 161 and 161+10 - or ss_coupon_amt between 15477 and 15477+1000 - or ss_wholesale_cost between 22 and 22+20)) B6 -limit 100; - --- end template query28.tpl query 28 in stream 4 --- start template query81.tpl query 29 in stream 4 -with /* TPC-DS query81.tpl 0.37 */ customer_total_return as - (select cr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(cr_return_amt_inc_tax) as ctr_total_return - from catalog_returns - ,date_dim - ,customer_address - where cr_returned_date_sk = d_date_sk - and d_year =2002 - and cr_returning_addr_sk = ca_address_sk - group by cr_returning_customer_sk - ,ca_state ) - select c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'SD' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - limit 100; - --- end template query81.tpl query 29 in stream 4 --- start template query44.tpl query 30 in stream 4 -select /* TPC-DS query44.tpl 0.4 */ asceding.rnk, i1.i_product_name best_performing, i2.i_product_name worst_performing -from(select * - from (select item_sk,rank() over (order by rank_col asc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 404 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 404 - and ss_addr_sk is null - group by ss_store_sk))V1)V11 - where rnk < 11) asceding, - (select * - from (select item_sk,rank() over (order by rank_col desc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 404 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 404 - and ss_addr_sk is null - group by ss_store_sk))V2)V21 - where rnk < 11) descending, -item i1, -item i2 -where asceding.rnk = descending.rnk - and i1.i_item_sk=asceding.item_sk - and i2.i_item_sk=descending.item_sk -order by asceding.rnk -limit 100; - --- end template query44.tpl query 30 in stream 4 --- start template query97.tpl query 31 in stream 4 -with /* TPC-DS query97.tpl 0.38 */ ssci as ( -select ss_customer_sk customer_sk - ,ss_item_sk item_sk -from store_sales,date_dim -where ss_sold_date_sk = d_date_sk - and d_month_seq between 1185 and 1185 + 11 -group by ss_customer_sk - ,ss_item_sk), -csci as( - select cs_bill_customer_sk customer_sk - ,cs_item_sk item_sk -from catalog_sales,date_dim -where cs_sold_date_sk = d_date_sk - and d_month_seq between 1185 and 1185 + 11 -group by cs_bill_customer_sk - ,cs_item_sk) - select sum(case when ssci.customer_sk is not null and csci.customer_sk is null then 1 else 0 end) store_only - ,sum(case when ssci.customer_sk is null and csci.customer_sk is not null then 1 else 0 end) catalog_only - ,sum(case when ssci.customer_sk is not null and csci.customer_sk is not null then 1 else 0 end) store_and_catalog -from ssci full outer join csci on (ssci.customer_sk=csci.customer_sk - and ssci.item_sk = csci.item_sk) -limit 100; - --- end template query97.tpl query 31 in stream 4 --- start template query88.tpl query 32 in stream 4 -select /* TPC-DS query88.tpl 0.66 */ * -from - (select count(*) h8_30_to_9 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s1, - (select count(*) h9_to_9_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s2, - (select count(*) h9_30_to_10 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s3, - (select count(*) h10_to_10_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s4, - (select count(*) h10_30_to_11 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s5, - (select count(*) h11_to_11_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s6, - (select count(*) h11_30_to_12 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s7, - (select count(*) h12_to_12_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 12 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s8 -; - --- end template query88.tpl query 32 in stream 4 --- start template query77a.tpl query 33 in stream 4 -with /* TPC-DS query77a.tpl 0.78 */ ss as - (select s_store_sk, - sum(ss_ext_sales_price) as sales, - sum(ss_net_profit) as profit - from store_sales, - date_dim, - store - where ss_sold_date_sk = d_date_sk - and d_date between cast('1999-08-09' as date) - and dateadd(day,30,cast('1999-08-09' as date)) - and ss_store_sk = s_store_sk - group by s_store_sk) - , - sr as - (select s_store_sk, - sum(sr_return_amt) as returns, - sum(sr_net_loss) as profit_loss - from store_returns, - date_dim, - store - where sr_returned_date_sk = d_date_sk - and d_date between cast('1999-08-09' as date) - and dateadd(day,30,cast('1999-08-09' as date)) - and sr_store_sk = s_store_sk - group by s_store_sk), - cs as - (select cs_call_center_sk, - sum(cs_ext_sales_price) as sales, - sum(cs_net_profit) as profit - from catalog_sales, - date_dim - where cs_sold_date_sk = d_date_sk - and d_date between cast('1999-08-09' as date) - and dateadd(day,30,cast('1999-08-09' as date)) - group by cs_call_center_sk - ), - cr as - (select cr_call_center_sk, - sum(cr_return_amount) as returns, - sum(cr_net_loss) as profit_loss - from catalog_returns, - date_dim - where cr_returned_date_sk = d_date_sk - and d_date between cast('1999-08-09' as date) - and dateadd(day,30,cast('1999-08-09' as date)) - group by cr_call_center_sk), - ws as - ( select wp_web_page_sk, - sum(ws_ext_sales_price) as sales, - sum(ws_net_profit) as profit - from web_sales, - date_dim, - web_page - where ws_sold_date_sk = d_date_sk - and d_date between cast('1999-08-09' as date) - and dateadd(day,30,cast('1999-08-09' as date)) - and ws_web_page_sk = wp_web_page_sk - group by wp_web_page_sk), - wr as - (select wp_web_page_sk, - sum(wr_return_amt) as returns, - sum(wr_net_loss) as profit_loss - from web_returns, - date_dim, - web_page - where wr_returned_date_sk = d_date_sk - and d_date between cast('1999-08-09' as date) - and dateadd(day,30,cast('1999-08-09' as date)) - and wr_web_page_sk = wp_web_page_sk - group by wp_web_page_sk) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , ss.s_store_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ss left join sr - on ss.s_store_sk = sr.s_store_sk - union all - select 'catalog channel' as channel - , cs_call_center_sk as id - , sales - , returns - , (profit - profit_loss) as profit - from cs - , cr - union all - select 'web channel' as channel - , ws.wp_web_page_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ws left join wr - on ws.wp_web_page_sk = wr.wp_web_page_sk - ) x - group by channel, id ) - - select * - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results -) foo -order by channel, id - limit 100; - --- end template query77a.tpl query 33 in stream 4 --- start template query95.tpl query 34 in stream 4 -with /* TPC-DS query95.tpl 0.43 */ ws_wh as -(select ws1.ws_order_number,ws1.ws_warehouse_sk wh1,ws2.ws_warehouse_sk wh2 - from web_sales ws1,web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) - select - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '1999-2-01' and - dateadd(day,60,cast('1999-2-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'CA' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and ws1.ws_order_number in (select ws_order_number - from ws_wh) -and ws1.ws_order_number in (select wr_order_number - from web_returns,ws_wh - where wr_order_number = ws_wh.ws_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query95.tpl query 34 in stream 4 --- start template query33.tpl query 35 in stream 4 -with /* TPC-DS query33.tpl 0.22 */ ss as ( - select - i_manufact_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Sports')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 2 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_manufact_id), - cs as ( - select - i_manufact_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Sports')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 2 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_manufact_id), - ws as ( - select - i_manufact_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Sports')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 2 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_manufact_id) - select i_manufact_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_manufact_id - order by total_sales -limit 100; - --- end template query33.tpl query 35 in stream 4 --- start template query36a.tpl query 36 in stream 4 -with /* TPC-DS query36a.tpl 0.21 */ results as - (select - sum(ss_net_profit) as ss_net_profit, sum(ss_ext_sales_price) as ss_ext_sales_price, - sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin - ,i_category - ,i_class - ,0 as g_category, 0 as g_class - from - store_sales - ,date_dim d1 - ,item - ,store - where - d1.d_year = 2000 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and s_state in ('LA','CA','LA','NE', - 'MN','GA','OK','NE') - group by i_category,i_class) - , - results_rollup as - (select gross_margin ,i_category ,i_class,0 as t_category, 0 as t_class, 0 as lochierarchy from results - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - i_category, NULL AS i_class, 0 as t_category, 1 as t_class, 1 as lochierarchy from results group by i_category - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - NULL AS i_category ,NULL AS i_class, 1 as t_category, 1 as t_class, 2 as lochierarchy from results) - select - gross_margin ,i_category ,i_class, lochierarchy,rank() over ( - partition by lochierarchy, case when t_class = 0 then i_category end - order by gross_margin asc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then i_category end - ,rank_within_parent - limit 100; - --- end template query36a.tpl query 36 in stream 4 --- start template query61.tpl query 37 in stream 4 -select /* TPC-DS query61.tpl 0.97 */ promotions,total,cast(promotions as decimal(15,4))/cast(total as decimal(15,4))*100 -from - (select sum(ss_ext_sales_price) promotions - from store_sales - ,store - ,promotion - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_promo_sk = p_promo_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -6 - and i_category = 'Jewelry' - and (p_channel_dmail = 'Y' or p_channel_email = 'Y' or p_channel_tv = 'Y') - and s_gmt_offset = -6 - and d_year = 1999 - and d_moy = 11) promotional_sales, - (select sum(ss_ext_sales_price) total - from store_sales - ,store - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -6 - and i_category = 'Jewelry' - and s_gmt_offset = -6 - and d_year = 1999 - and d_moy = 11) all_sales -order by promotions, total -limit 100; - --- end template query61.tpl query 37 in stream 4 --- start template query35a.tpl query 38 in stream 4 -select /* TPC-DS query35a.tpl 0.47 */ - ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - count(*) cnt1, - sum(cd_dep_count), - stddev_samp(cd_dep_count), - avg(cd_dep_count), - cd_dep_employed_count, - count(*) cnt2, - sum(cd_dep_employed_count), - stddev_samp(cd_dep_employed_count), - avg(cd_dep_employed_count), - cd_dep_college_count, - count(*) cnt3, - sum(cd_dep_college_count), - stddev_samp(cd_dep_college_count), - avg(cd_dep_college_count) - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2002 and - d_qoy < 4) and - exists (select * from - (select ws_bill_customer_sk customsk - from web_sales,date_dim - where - ws_sold_date_sk = d_date_sk and - d_year = 2002 and - d_qoy < 4 - union all - select cs_ship_customer_sk customsk - from catalog_sales,date_dim - where - cs_sold_date_sk = d_date_sk and - d_year = 2002 and - d_qoy < 4)x - where x.customsk = c.c_customer_sk) - group by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - limit 100; - --- end template query35a.tpl query 38 in stream 4 --- start template query60.tpl query 39 in stream 4 -with /* TPC-DS query60.tpl 0.29 */ ss as ( - select - i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Jewelry')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 10 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -7 - group by i_item_id), - cs as ( - select - i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Jewelry')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 10 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -7 - group by i_item_id), - ws as ( - select - i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Jewelry')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 10 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -7 - group by i_item_id) - select - i_item_id -,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by i_item_id - ,total_sales - limit 100; - --- end template query60.tpl query 39 in stream 4 --- start template query75.tpl query 40 in stream 4 -WITH /* TPC-DS query75.tpl 0.3 */ all_sales AS ( - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,SUM(sales_cnt) AS sales_cnt - ,SUM(sales_amt) AS sales_amt - FROM (SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,cs_quantity - COALESCE(cr_return_quantity,0) AS sales_cnt - ,cs_ext_sales_price - COALESCE(cr_return_amount,0.0) AS sales_amt - FROM catalog_sales JOIN item ON i_item_sk=cs_item_sk - JOIN date_dim ON d_date_sk=cs_sold_date_sk - LEFT JOIN catalog_returns ON (cs_order_number=cr_order_number - AND cs_item_sk=cr_item_sk) - WHERE i_category='Electronics' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ss_quantity - COALESCE(sr_return_quantity,0) AS sales_cnt - ,ss_ext_sales_price - COALESCE(sr_return_amt,0.0) AS sales_amt - FROM store_sales JOIN item ON i_item_sk=ss_item_sk - JOIN date_dim ON d_date_sk=ss_sold_date_sk - LEFT JOIN store_returns ON (ss_ticket_number=sr_ticket_number - AND ss_item_sk=sr_item_sk) - WHERE i_category='Electronics' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ws_quantity - COALESCE(wr_return_quantity,0) AS sales_cnt - ,ws_ext_sales_price - COALESCE(wr_return_amt,0.0) AS sales_amt - FROM web_sales JOIN item ON i_item_sk=ws_item_sk - JOIN date_dim ON d_date_sk=ws_sold_date_sk - LEFT JOIN web_returns ON (ws_order_number=wr_order_number - AND ws_item_sk=wr_item_sk) - WHERE i_category='Electronics') sales_detail - GROUP BY d_year, i_brand_id, i_class_id, i_category_id, i_manufact_id) - SELECT prev_yr.d_year AS prev_year - ,curr_yr.d_year AS year - ,curr_yr.i_brand_id - ,curr_yr.i_class_id - ,curr_yr.i_category_id - ,curr_yr.i_manufact_id - ,prev_yr.sales_cnt AS prev_yr_cnt - ,curr_yr.sales_cnt AS curr_yr_cnt - ,curr_yr.sales_cnt-prev_yr.sales_cnt AS sales_cnt_diff - ,curr_yr.sales_amt-prev_yr.sales_amt AS sales_amt_diff - FROM all_sales curr_yr, all_sales prev_yr - WHERE curr_yr.i_brand_id=prev_yr.i_brand_id - AND curr_yr.i_class_id=prev_yr.i_class_id - AND curr_yr.i_category_id=prev_yr.i_category_id - AND curr_yr.i_manufact_id=prev_yr.i_manufact_id - AND curr_yr.d_year=1999 - AND prev_yr.d_year=1999-1 - AND CAST(curr_yr.sales_cnt AS DECIMAL(17,2))/CAST(prev_yr.sales_cnt AS DECIMAL(17,2))<0.9 - ORDER BY sales_cnt_diff,sales_amt_diff - limit 100; - --- end template query75.tpl query 40 in stream 4 --- start template query74.tpl query 41 in stream 4 -with /* TPC-DS query74.tpl 0.76 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,stddev_samp(ss_net_paid) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (2001,2001+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,stddev_samp(ws_net_paid) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - and d_year in (2001,2001+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - ) - select - t_s_secyear.customer_id, t_s_secyear.customer_first_name, t_s_secyear.customer_last_name - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.year = 2001 - and t_s_secyear.year = 2001+1 - and t_w_firstyear.year = 2001 - and t_w_secyear.year = 2001+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - order by 3,1,2 -limit 100; - --- end template query74.tpl query 41 in stream 4 --- start template query55.tpl query 42 in stream 4 -select /* TPC-DS query55.tpl 0.82 */ i_brand_id brand_id, i_brand brand, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=14 - and d_moy=12 - and d_year=1998 - group by i_brand, i_brand_id - order by ext_price desc, i_brand_id -limit 100 ; - --- end template query55.tpl query 42 in stream 4 --- start template query51.tpl query 43 in stream 4 -WITH /* TPC-DS query51.tpl 0.46 */ web_v1 as ( -select - ws_item_sk item_sk, d_date, - sum(sum(ws_sales_price)) - over (partition by ws_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from web_sales - ,date_dim -where ws_sold_date_sk=d_date_sk - and d_month_seq between 1204 and 1204+11 - and ws_item_sk is not NULL -group by ws_item_sk, d_date), -store_v1 as ( -select - ss_item_sk item_sk, d_date, - sum(sum(ss_sales_price)) - over (partition by ss_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from store_sales - ,date_dim -where ss_sold_date_sk=d_date_sk - and d_month_seq between 1204 and 1204+11 - and ss_item_sk is not NULL -group by ss_item_sk, d_date) - select * -from (select item_sk - ,d_date - ,web_sales - ,store_sales - ,max(web_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) web_cumulative - ,max(store_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) store_cumulative - from (select case when web.item_sk is not null then web.item_sk else store.item_sk end item_sk - ,case when web.d_date is not null then web.d_date else store.d_date end d_date - ,web.cume_sales web_sales - ,store.cume_sales store_sales - from web_v1 web full outer join store_v1 store on (web.item_sk = store.item_sk - and web.d_date = store.d_date) - )x )y -where web_cumulative > store_cumulative -order by item_sk - ,d_date -limit 100; - --- end template query51.tpl query 43 in stream 4 --- start template query17.tpl query 44 in stream 4 -select /* TPC-DS query17.tpl 0.41 */ i_item_id - ,i_item_desc - ,s_state - ,count(ss_quantity) as store_sales_quantitycount - ,avg(ss_quantity) as store_sales_quantityave - ,stddev_samp(ss_quantity) as store_sales_quantitystdev - ,stddev_samp(ss_quantity)/avg(ss_quantity) as store_sales_quantitycov - ,count(sr_return_quantity) as store_returns_quantitycount - ,avg(sr_return_quantity) as store_returns_quantityave - ,stddev_samp(sr_return_quantity) as store_returns_quantitystdev - ,stddev_samp(sr_return_quantity)/avg(sr_return_quantity) as store_returns_quantitycov - ,count(cs_quantity) as catalog_sales_quantitycount ,avg(cs_quantity) as catalog_sales_quantityave - ,stddev_samp(cs_quantity) as catalog_sales_quantitystdev - ,stddev_samp(cs_quantity)/avg(cs_quantity) as catalog_sales_quantitycov - from store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where d1.d_quarter_name = '2002Q1' - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_quarter_name in ('2002Q1','2002Q2','2002Q3') - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_quarter_name in ('2002Q1','2002Q2','2002Q3') - group by i_item_id - ,i_item_desc - ,s_state - order by i_item_id - ,i_item_desc - ,s_state -limit 100; - --- end template query17.tpl query 44 in stream 4 --- start template query52.tpl query 45 in stream 4 -select /* TPC-DS query52.tpl 0.59 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_sales_price) ext_price - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=11 - and dt.d_year=1999 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,ext_price desc - ,brand_id -limit 100 ; - --- end template query52.tpl query 45 in stream 4 --- start template query90.tpl query 46 in stream 4 -select /* TPC-DS query90.tpl 0.40 */ cast(amc as decimal(15,4))/cast(pmc as decimal(15,4)) am_pm_ratio - from ( select count(*) amc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 8 and 8+1 - and household_demographics.hd_dep_count = 3 - and web_page.wp_char_count between 5000 and 5200) at, - ( select count(*) pmc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 16 and 16+1 - and household_demographics.hd_dep_count = 3 - and web_page.wp_char_count between 5000 and 5200) pt - order by am_pm_ratio - limit 100; - --- end template query90.tpl query 46 in stream 4 --- start template query22a.tpl query 47 in stream 4 -with /* TPC-DS query22a.tpl 0.55 */ results as -(select i_product_name - ,i_brand - ,i_class - ,i_category - ,avg(inv_quantity_on_hand) qoh - from inventory - ,date_dim - ,item --- ,warehouse - where inv_date_sk=d_date_sk - and inv_item_sk=i_item_sk --- and inv_warehouse_sk = w_warehouse_sk - and d_month_seq between 1177 and 1177 + 11 - group by i_product_name,i_brand,i_class,i_category), -results_rollup as -(select i_product_name, i_brand, i_class, i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class,i_category -union all -select i_product_name, i_brand, i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class -union all -select i_product_name, i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand -union all -select i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name -union all -select null i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results) - select i_product_name, i_brand, i_class, i_category,qoh - from results_rollup - order by qoh, i_product_name, i_brand, i_class, i_category -limit 100; - --- end template query22a.tpl query 47 in stream 4 --- start template query27a.tpl query 48 in stream 4 -with /* TPC-DS query27a.tpl 0.16 */ results as - (select i_item_id, - s_state, 0 as g_state, - ss_quantity agg1, - ss_list_price agg2, - ss_coupon_amt agg3, - ss_sales_price agg4 - from store_sales, customer_demographics, date_dim, store, item - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_store_sk = s_store_sk and - ss_cdemo_sk = cd_demo_sk and - cd_gender = 'F' and - cd_marital_status = 'W' and - cd_education_status = 'Unknown' and - d_year = 2002 and - s_state in ('MI','GA', 'GA', 'MI', 'OK', 'MO') - ) - - select i_item_id, - s_state, g_state, agg1, agg2, agg3, agg4 - from ( - select i_item_id, s_state, 0 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4 from results - group by i_item_id, s_state - union all - select i_item_id, NULL AS s_state, 1 AS g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as s_state, 1 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - ) foo - order by i_item_id, s_state - limit 100; - --- end template query27a.tpl query 48 in stream 4 --- start template query63.tpl query 49 in stream 4 -select /* TPC-DS query63.tpl 0.27 */ * -from (select i_manager_id - ,sum(ss_sales_price) sum_sales - ,avg(sum(ss_sales_price)) over (partition by i_manager_id) avg_monthly_sales - from item - ,store_sales - ,date_dim - ,store - where ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and d_month_seq in (1185,1185+1,1185+2,1185+3,1185+4,1185+5,1185+6,1185+7,1185+8,1185+9,1185+10,1185+11) - and (( i_category in ('Books','Children','Electronics') - and i_class in ('personal','portable','reference','self-help') - and i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) - or( i_category in ('Women','Music','Men') - and i_class in ('accessories','classical','fragrances','pants') - and i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manager_id, d_moy) tmp1 -where case when avg_monthly_sales > 0 then abs (sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 -order by i_manager_id - ,avg_monthly_sales - ,sum_sales -limit 100; - --- end template query63.tpl query 49 in stream 4 --- start template query38.tpl query 50 in stream 4 -select /* TPC-DS query38.tpl 0.54 */ count(*) from ( - select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1220 and 1220 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1220 and 1220 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1220 and 1220 + 11 -) hot_cust -limit 100; - --- end template query38.tpl query 50 in stream 4 --- start template query18a.tpl query 51 in stream 4 -with /* TPC-DS query18a.tpl 0.90 */ results as - (select i_item_id, - ca_country, - ca_state, - ca_county, - cast(cs_quantity as decimal(12,2)) agg1, - cast(cs_list_price as decimal(12,2)) agg2, - cast(cs_coupon_amt as decimal(12,2)) agg3, - cast(cs_sales_price as decimal(12,2)) agg4, - cast(cs_net_profit as decimal(12,2)) agg5, - cast(c_birth_year as decimal(12,2)) agg6, - cast(cd1.cd_dep_count as decimal(12,2)) agg7 - from catalog_sales, customer_demographics cd1, customer_demographics cd2, customer, customer_address, date_dim, item - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd1.cd_demo_sk and - cs_bill_customer_sk = c_customer_sk and - cd1.cd_gender = 'F' and - cd1.cd_education_status = 'Unknown' and - c_current_cdemo_sk = cd2.cd_demo_sk and - c_current_addr_sk = ca_address_sk and - c_birth_month in (11,7,1,9,4,8) and - d_year = 2000 and - ca_state in ('MO','IN','UT','TN','LA','TX','KY') - ) - select i_item_id, ca_country, ca_state, ca_county, agg1, agg2, agg3, agg4, agg5, agg6, agg7 - from ( - select i_item_id, ca_country, ca_state, ca_county, avg(agg1) agg1, - avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state, ca_county - union all - select i_item_id, ca_country, ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state - union all - select i_item_id, ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country - union all - select i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - ) foo - order by ca_country, ca_state, ca_county, i_item_id - limit 100; - --- end template query18a.tpl query 51 in stream 4 --- start template query24.tpl query 52 in stream 4 -with /* TPC-DS query24.tpl 0.92 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_net_paid) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip -and s_market_id=10 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'coral' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; -with /* TPC-DS query24.tpl 0.92 part2 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_net_paid) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip - and s_market_id = 10 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'indian' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; - --- end template query24.tpl query 52 in stream 4 --- start template query37.tpl query 53 in stream 4 -select /* TPC-DS query37.tpl 0.31 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, catalog_sales - where i_current_price between 52 and 52 + 30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('2002-01-24' as date) and dateadd(day,60,cast('2002-01-24' as date)) - and i_manufact_id in (716,815,868,680) - and inv_quantity_on_hand between 100 and 500 - and cs_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query37.tpl query 53 in stream 4 --- start template query47.tpl query 54 in stream 4 -with /* TPC-DS query47.tpl 0.42 */ v1 as( - select i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, - s_store_name, s_company_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - s_store_name, s_company_name - order by d_year, d_moy) rn - from item, store_sales, date_dim, store - where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - ( - d_year = 2001 or - ( d_year = 2001-1 and d_moy =12) or - ( d_year = 2001+1 and d_moy =1) - ) - group by i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy), - v2 as( - select v1.s_store_name - ,v1.d_year - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1.s_store_name = v1_lag.s_store_name and - v1.s_store_name = v1_lead.s_store_name and - v1.s_company_name = v1_lag.s_company_name and - v1.s_company_name = v1_lead.s_company_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 2001 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, avg_monthly_sales - limit 100; - --- end template query47.tpl query 54 in stream 4 --- start template query10.tpl query 55 in stream 4 -select /* TPC-DS query10.tpl 0.26 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3, - cd_dep_count, - count(*) cnt4, - cd_dep_employed_count, - count(*) cnt5, - cd_dep_college_count, - count(*) cnt6 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_county in ('Howard County','East Baton Rouge Parish','Becker County','Big Horn County','Suffolk County') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 3 and 3+3) and - (exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 3 ANd 3+3) or - exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 3 and 3+3)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count -limit 100; - --- end template query10.tpl query 55 in stream 4 --- start template query70a.tpl query 56 in stream 4 -with /* TPC-DS query70a.tpl 0.34 */ results as -( select - sum(ss_net_profit) as total_sum ,s_state ,s_county, 0 as gstate, 0 as g_county - from - store_sales - ,date_dim d1 - ,store - where - d1.d_month_seq between 1223 and 1223 + 11 - and d1.d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - and s_state in - ( select s_state - from (select s_state as s_state, - rank() over ( partition by s_state order by sum(ss_net_profit) desc) as ranking - from store_sales, store, date_dim - where d_month_seq between 1223 and 1223 + 11 - and d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - group by s_state - ) tmp1 - where ranking <= 5) - group by s_state,s_county) , - results_rollup as -(select total_sum ,s_state ,s_county, 0 as g_state, 0 as g_county, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum,s_state, NULL as s_county, 0 as g_state, 1 as g_county, 1 as lochierarchy from results group by s_state - union - select sum(total_sum) as total_sum ,NULL as s_state ,NULL as s_county, 1 as g_state, 1 as g_county, 2 as lochierarchy from results) - select total_sum ,s_state ,s_county, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_county = 0 then s_state end - order by total_sum desc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then s_state end - ,rank_within_parent - limit 100; - --- end template query70a.tpl query 56 in stream 4 --- start template query23.tpl query 57 in stream 4 -with /* TPC-DS query23.tpl 0.68 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (2000,2000+1,2000+2,2000+3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (2000,2000+1,2000+2,2000+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * -from - max_store_sales)) - select sum(sales) - from (select cs_quantity*cs_list_price sales - from catalog_sales - ,date_dim - where d_year = 2000 - and d_moy = 4 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - union all - select ws_quantity*ws_list_price sales - from web_sales - ,date_dim - where d_year = 2000 - and d_moy = 4 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer)) - limit 100; -with /* TPC-DS query23.tpl 0.68 part2 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (2000,2000 + 1,2000 + 2,2000 + 3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (2000,2000+1,2000+2,2000+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * - from max_store_sales)) - select c_last_name,c_first_name,sales - from (select c_last_name,c_first_name,sum(cs_quantity*cs_list_price) sales - from catalog_sales - ,customer - ,date_dim - where d_year = 2000 - and d_moy = 4 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and cs_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name - union all - select c_last_name,c_first_name,sum(ws_quantity*ws_list_price) sales - from web_sales - ,customer - ,date_dim - where d_year = 2000 - and d_moy = 4 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and ws_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name) - order by c_last_name,c_first_name,sales - limit 100; - --- end template query23.tpl query 57 in stream 4 --- start template query7.tpl query 58 in stream 4 -select /* TPC-DS query7.tpl 0.2 */ i_item_id, - avg(ss_quantity) agg1, - avg(ss_list_price) agg2, - avg(ss_coupon_amt) agg3, - avg(ss_sales_price) agg4 - from store_sales, customer_demographics, date_dim, item, promotion - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_cdemo_sk = cd_demo_sk and - ss_promo_sk = p_promo_sk and - cd_gender = 'M' and - cd_marital_status = 'S' and - cd_education_status = 'College' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 2001 - group by i_item_id - order by i_item_id - limit 100; - --- end template query7.tpl query 58 in stream 4 --- start template query92.tpl query 59 in stream 4 -select /* TPC-DS query92.tpl 0.44 */ - sum(ws_ext_discount_amt) as "Excess Discount Amount" -from - web_sales - ,item - ,date_dim -where -i_manufact_id = 836 -and i_item_sk = ws_item_sk -and d_date between '2000-02-11' and - dateadd(day,90,cast('2000-02-11' as date)) -and d_date_sk = ws_sold_date_sk -and ws_ext_discount_amt - > ( - SELECT - 1.3 * avg(ws_ext_discount_amt) - FROM - web_sales - ,date_dim - WHERE - ws_item_sk = i_item_sk - and d_date between '2000-02-11' and - dateadd(day,90,cast('2000-02-11' as date)) - and d_date_sk = ws_sold_date_sk - ) -order by sum(ws_ext_discount_amt) -limit 100; - --- end template query92.tpl query 59 in stream 4 --- start template query54.tpl query 60 in stream 4 -with /* TPC-DS query54.tpl 0.81 */ my_customers as ( - select distinct c_customer_sk - , c_current_addr_sk - from - ( select cs_sold_date_sk sold_date_sk, - cs_bill_customer_sk customer_sk, - cs_item_sk item_sk - from catalog_sales - union all - select ws_sold_date_sk sold_date_sk, - ws_bill_customer_sk customer_sk, - ws_item_sk item_sk - from web_sales - ) cs_or_ws_sales, - item, - date_dim, - customer - where sold_date_sk = d_date_sk - and item_sk = i_item_sk - and i_category = 'Shoes' - and i_class = 'womens' - and c_customer_sk = cs_or_ws_sales.customer_sk - and d_moy = 7 - and d_year = 2001 - ) - , my_revenue as ( - select c_customer_sk, - sum(ss_ext_sales_price) as revenue - from my_customers, - store_sales, - customer_address, - store, - date_dim - where c_current_addr_sk = ca_address_sk - and ca_county = s_county - and ca_state = s_state - and ss_sold_date_sk = d_date_sk - and c_customer_sk = ss_customer_sk - and d_month_seq between (select distinct d_month_seq+1 - from date_dim where d_year = 2001 and d_moy = 7) - and (select distinct d_month_seq+3 - from date_dim where d_year = 2001 and d_moy = 7) - group by c_customer_sk - ) - , segments as - (select cast((revenue/50) as bigint) as segment - from my_revenue - ) - select segment, count(*) as num_customers, segment*50 as segment_base - from segments - group by segment - order by segment, num_customers - limit 100; - --- end template query54.tpl query 60 in stream 4 --- start template query82.tpl query 61 in stream 4 -select /* TPC-DS query82.tpl 0.67 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, store_sales - where i_current_price between 15 and 15+30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('2000-05-07' as date) and dateadd(day,60,cast('2000-05-07' as date)) - and i_manufact_id in (355,612,304,402) - and inv_quantity_on_hand between 100 and 500 - and ss_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query82.tpl query 61 in stream 4 --- start template query76.tpl query 62 in stream 4 -select /* TPC-DS query76.tpl 0.99 */ channel, col_name, d_year, d_qoy, i_category, COUNT(*) sales_cnt, SUM(ext_sales_price) sales_amt FROM ( - SELECT 'store' as channel, 'ss_addr_sk' col_name, d_year, d_qoy, i_category, ss_ext_sales_price ext_sales_price - FROM store_sales, item, date_dim - WHERE ss_addr_sk IS NULL - AND ss_sold_date_sk=d_date_sk - AND ss_item_sk=i_item_sk - UNION ALL - SELECT 'web' as channel, 'ws_warehouse_sk' col_name, d_year, d_qoy, i_category, ws_ext_sales_price ext_sales_price - FROM web_sales, item, date_dim - WHERE ws_warehouse_sk IS NULL - AND ws_sold_date_sk=d_date_sk - AND ws_item_sk=i_item_sk - UNION ALL - SELECT 'catalog' as channel, 'cs_warehouse_sk' col_name, d_year, d_qoy, i_category, cs_ext_sales_price ext_sales_price - FROM catalog_sales, item, date_dim - WHERE cs_warehouse_sk IS NULL - AND cs_sold_date_sk=d_date_sk - AND cs_item_sk=i_item_sk) foo -GROUP BY channel, col_name, d_year, d_qoy, i_category -ORDER BY channel, col_name, d_year, d_qoy, i_category -limit 100; - --- end template query76.tpl query 62 in stream 4 --- start template query80a.tpl query 63 in stream 4 -with /* TPC-DS query80a.tpl 0.6 */ ssr as - (select s_store_id as store_id, - sum(ss_ext_sales_price) as sales, - sum(coalesce(sr_return_amt, 0)) as returns, - sum(ss_net_profit - coalesce(sr_net_loss, 0)) as profit - from store_sales left outer join store_returns on - (ss_item_sk = sr_item_sk and ss_ticket_number = sr_ticket_number), - date_dim, - store, - item, - promotion - where ss_sold_date_sk = d_date_sk - and d_date between cast('2000-08-10' as date) - and dateadd(day,30,cast('2000-08-10' as date)) - and ss_store_sk = s_store_sk - and ss_item_sk = i_item_sk - and i_current_price > 50 - and ss_promo_sk = p_promo_sk - and p_channel_tv = 'N' - group by s_store_id) - , - csr as - (select cp_catalog_page_id as catalog_page_id, - sum(cs_ext_sales_price) as sales, - sum(coalesce(cr_return_amount, 0)) as returns, - sum(cs_net_profit - coalesce(cr_net_loss, 0)) as profit - from catalog_sales left outer join catalog_returns on - (cs_item_sk = cr_item_sk and cs_order_number = cr_order_number), - date_dim, - catalog_page, - item, - promotion - where cs_sold_date_sk = d_date_sk - and d_date between cast('2000-08-10' as date) - and dateadd(day,30,cast('2000-08-10' as date)) - and cs_catalog_page_sk = cp_catalog_page_sk - and cs_item_sk = i_item_sk - and i_current_price > 50 - and cs_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(ws_ext_sales_price) as sales, - sum(coalesce(wr_return_amt, 0)) as returns, - sum(ws_net_profit - coalesce(wr_net_loss, 0)) as profit - from web_sales left outer join web_returns on - (ws_item_sk = wr_item_sk and ws_order_number = wr_order_number), - date_dim, - web_site, - item, - promotion - where ws_sold_date_sk = d_date_sk - and d_date between cast('2000-08-10' as date) - and dateadd(day,30,cast('2000-08-10' as date)) - and ws_web_site_sk = web_site_sk - and ws_item_sk = i_item_sk - and i_current_price > 50 - and ws_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by web_site_id) -, -results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || store_id as id - , sales - , returns - , profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || catalog_page_id as id - , sales - , returns - , profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , profit - from wsr - ) x - group by channel, id) - - select channel - , id - , sales - , returns - , profit - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results - ) foo - order by channel, id - limit 100; - --- end template query80a.tpl query 63 in stream 4 --- start template query56.tpl query 64 in stream 4 -with /* TPC-DS query56.tpl 0.83 */ ss as ( - select i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where i_item_id in (select - i_item_id -from item -where i_color in ('linen','lavender','moccasin')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 4 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id), - cs as ( - select i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('linen','lavender','moccasin')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 4 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id), - ws as ( - select i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('linen','lavender','moccasin')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 4 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id) - select i_item_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by total_sales, - i_item_id - limit 100; - --- end template query56.tpl query 64 in stream 4 --- start template query96.tpl query 65 in stream 4 -select /* TPC-DS query96.tpl 0.1 */ count(*) -from store_sales - ,household_demographics - ,time_dim, store -where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 15 - and time_dim.t_minute >= 30 - and household_demographics.hd_dep_count = 0 - and store.s_store_name = 'ese' -order by count(*) -limit 100; - --- end template query96.tpl query 65 in stream 4 --- start template query50.tpl query 66 in stream 4 -select /* TPC-DS query50.tpl 0.60 */ - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 30) and - (sr_returned_date_sk - ss_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 60) and - (sr_returned_date_sk - ss_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 90) and - (sr_returned_date_sk - ss_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - store_sales - ,store_returns - ,store - ,date_dim d1 - ,date_dim d2 -where - d2.d_year = 2002 -and d2.d_moy = 8 -and ss_ticket_number = sr_ticket_number -and ss_item_sk = sr_item_sk -and ss_sold_date_sk = d1.d_date_sk -and sr_returned_date_sk = d2.d_date_sk -and ss_customer_sk = sr_customer_sk -and ss_store_sk = s_store_sk -group by - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -order by s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -limit 100; - --- end template query50.tpl query 66 in stream 4 --- start template query85.tpl query 67 in stream 4 -select /* TPC-DS query85.tpl 0.33 */ substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) - from web_sales, web_returns, web_page, customer_demographics cd1, - customer_demographics cd2, customer_address, date_dim, reason - where ws_web_page_sk = wp_web_page_sk - and ws_item_sk = wr_item_sk - and ws_order_number = wr_order_number - and ws_sold_date_sk = d_date_sk and d_year = 2000 - and cd1.cd_demo_sk = wr_refunded_cdemo_sk - and cd2.cd_demo_sk = wr_returning_cdemo_sk - and ca_address_sk = wr_refunded_addr_sk - and r_reason_sk = wr_reason_sk - and - ( - ( - cd1.cd_marital_status = 'D' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Advanced Degree' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 100.00 and 150.00 - ) - or - ( - cd1.cd_marital_status = 'U' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'College' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 50.00 and 100.00 - ) - or - ( - cd1.cd_marital_status = 'W' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Primary' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ca_country = 'United States' - and - ca_state in ('TX', 'IN', 'MO') - and ws_net_profit between 100 and 200 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('MI', 'MS', 'OK') - and ws_net_profit between 150 and 300 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('WY', 'TN', 'SD') - and ws_net_profit between 50 and 250 - ) - ) -group by r_reason_desc -order by substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) -limit 100; - --- end template query85.tpl query 67 in stream 4 --- start template query86a.tpl query 68 in stream 4 -with /* TPC-DS query86a.tpl 0.11 */ results as -( select sum(ws_net_paid) as total_sum, i_category, i_class, 0 as g_category, 0 as g_class - from - web_sales - ,date_dim d1 - ,item - where - d1.d_month_seq between 1215 and 1215+11 - and d1.d_date_sk = ws_sold_date_sk - and i_item_sk = ws_item_sk - group by i_category,i_class - ) , - - results_rollup as -( select total_sum ,i_category ,i_class, g_category, g_class, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum, i_category, NULL as i_class, 0 as g_category, 1 as g_class, 1 as lochierarchy from results group by i_category - union - select sum(total_sum) as total_sum, NULL as i_category, NULL as i_class, 1 as g_category, 1 as g_class, 2 as lochierarchy from results) - select - total_sum ,i_category ,i_class, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_class = 0 then i_category end - order by total_sum desc) as rank_within_parent - from - results_rollup - order by - lochierarchy desc, - case when lochierarchy = 0 then i_category end, - rank_within_parent - limit 100; - --- end template query86a.tpl query 68 in stream 4 --- start template query69.tpl query 69 in stream 4 -select /* TPC-DS query69.tpl 0.28 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_state in ('SD','VA','IL') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2004 and - d_moy between 4 and 4+2) and - (not exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2004 and - d_moy between 4 and 4+2) and - not exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2004 and - d_moy between 4 and 4+2)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - limit 100; - --- end template query69.tpl query 69 in stream 4 --- start template query68.tpl query 70 in stream 4 -select /* TPC-DS query68.tpl 0.95 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,extended_price - ,extended_tax - ,list_price - from (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_ext_sales_price) extended_price - ,sum(ss_ext_list_price) list_price - ,sum(ss_ext_tax) extended_tax - from store_sales - ,date_dim - ,store - ,household_demographics - ,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_dep_count = 5 or - household_demographics.hd_vehicle_count= 3) - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_city in ('Sherwood Forest','Dayton') - group by ss_ticket_number - ,ss_customer_sk - ,ss_addr_sk,ca_city) dn - ,customer - ,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,ss_ticket_number - limit 100; - --- end template query68.tpl query 70 in stream 4 --- start template query1.tpl query 71 in stream 4 -with /* TPC-DS query1.tpl 0.12 */ customer_total_return as -(select sr_customer_sk as ctr_customer_sk -,sr_store_sk as ctr_store_sk -,sum(SR_STORE_CREDIT) as ctr_total_return -from store_returns -,date_dim -where sr_returned_date_sk = d_date_sk -and d_year =1998 -group by sr_customer_sk -,sr_store_sk) - select c_customer_id -from customer_total_return ctr1 -,store -,customer -where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 -from customer_total_return ctr2 -where ctr1.ctr_store_sk = ctr2.ctr_store_sk) -and s_store_sk = ctr1.ctr_store_sk -and s_state = 'GA' -and ctr1.ctr_customer_sk = c_customer_sk -order by c_customer_id -limit 100; - --- end template query1.tpl query 71 in stream 4 --- start template query12.tpl query 72 in stream 4 -select /* TPC-DS query12.tpl 0.64 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ws_ext_sales_price) as itemrevenue - ,sum(ws_ext_sales_price)*100/sum(sum(ws_ext_sales_price)) over - (partition by i_class) as revenueratio -from - web_sales - ,item - ,date_dim -where - ws_item_sk = i_item_sk - and i_category in ('Music', 'Women', 'Children') - and ws_sold_date_sk = d_date_sk - and d_date between cast('2002-04-25' as date) - and dateadd(day,30,cast('2002-04-25' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query12.tpl query 72 in stream 4 --- start template query43.tpl query 73 in stream 4 -select /* TPC-DS query43.tpl 0.15 */ s_store_name, s_store_id, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from date_dim, store_sales, store - where d_date_sk = ss_sold_date_sk and - s_store_sk = ss_store_sk and - s_gmt_offset = -5 and - d_year = 2001 - group by s_store_name, s_store_id - order by s_store_name, s_store_id,sun_sales,mon_sales,tue_sales,wed_sales,thu_sales,fri_sales,sat_sales - limit 100; - --- end template query43.tpl query 73 in stream 4 --- start template query16.tpl query 74 in stream 4 -select /* TPC-DS query16.tpl 0.25 */ - count(distinct cs_order_number) as "order count" - ,sum(cs_ext_ship_cost) as "total shipping cost" - ,sum(cs_net_profit) as "total net profit" -from - catalog_sales cs1 - ,date_dim - ,customer_address - ,call_center -where - d_date between '2002-5-01' and - dateadd(day, 60, cast('2002-5-01' as date)) -and cs1.cs_ship_date_sk = d_date_sk -and cs1.cs_ship_addr_sk = ca_address_sk -and ca_state = 'CO' -and cs1.cs_call_center_sk = cc_call_center_sk -and cc_county in ('Pennington County','San Miguel County','Raleigh County','Barrow County', - 'Fairfield County' -) -and exists (select * - from catalog_sales cs2 - where cs1.cs_order_number = cs2.cs_order_number - and cs1.cs_warehouse_sk <> cs2.cs_warehouse_sk) -and not exists(select * - from catalog_returns cr1 - where cs1.cs_order_number = cr1.cr_order_number) -order by count(distinct cs_order_number) -limit 100; - --- end template query16.tpl query 74 in stream 4 --- start template query4.tpl query 75 in stream 4 -with /* TPC-DS query4.tpl 0.93 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(((ss_ext_list_price-ss_ext_wholesale_cost-ss_ext_discount_amt)+ss_ext_sales_price)/2) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((cs_ext_list_price-cs_ext_wholesale_cost-cs_ext_discount_amt)+cs_ext_sales_price)/2) ) year_total - ,'c' sale_type - from customer - ,catalog_sales - ,date_dim - where c_customer_sk = cs_bill_customer_sk - and cs_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year -union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((ws_ext_list_price-ws_ext_wholesale_cost-ws_ext_discount_amt)+ws_ext_sales_price)/2) ) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_login - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_c_firstyear - ,year_total t_c_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_c_secyear.customer_id - and t_s_firstyear.customer_id = t_c_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_c_firstyear.sale_type = 'c' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_c_secyear.sale_type = 'c' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 1999 - and t_s_secyear.dyear = 1999+1 - and t_c_firstyear.dyear = 1999 - and t_c_secyear.dyear = 1999+1 - and t_w_firstyear.dyear = 1999 - and t_w_secyear.dyear = 1999+1 - and t_s_firstyear.year_total > 0 - and t_c_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_login -limit 100; - --- end template query4.tpl query 75 in stream 4 --- start template query25.tpl query 76 in stream 4 -select /* TPC-DS query25.tpl 0.9 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,max(ss_net_profit) as store_sales_profit - ,max(sr_net_loss) as store_returns_loss - ,max(cs_net_profit) as catalog_sales_profit - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 1998 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 10 - and d2.d_year = 1998 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_moy between 4 and 10 - and d3.d_year = 1998 - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query25.tpl query 76 in stream 4 --- start template query20.tpl query 77 in stream 4 -select /* TPC-DS query20.tpl 0.65 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(cs_ext_sales_price) as itemrevenue - ,sum(cs_ext_sales_price)*100/sum(sum(cs_ext_sales_price)) over - (partition by i_class) as revenueratio - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and i_category in ('Music', 'Home', 'Shoes') - and cs_sold_date_sk = d_date_sk - and d_date between cast('2001-02-17' as date) - and dateadd(day,30,cast('2001-02-17' as date)) - group by i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - order by i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query20.tpl query 77 in stream 4 --- start template query65.tpl query 78 in stream 4 -select /* TPC-DS query65.tpl 0.71 */ - s_store_name, - i_item_desc, - sc.revenue, - i_current_price, - i_wholesale_cost, - i_brand - from store, item, - (select ss_store_sk, avg(revenue) as ave - from - (select ss_store_sk, ss_item_sk, - sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1208 and 1208+11 - group by ss_store_sk, ss_item_sk) sa - group by ss_store_sk) sb, - (select ss_store_sk, ss_item_sk, sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1208 and 1208+11 - group by ss_store_sk, ss_item_sk) sc - where sb.ss_store_sk = sc.ss_store_sk and - sc.revenue <= 0.1 * sb.ave and - s_store_sk = sc.ss_store_sk and - i_item_sk = sc.ss_item_sk - order by s_store_name, i_item_desc -limit 100; - --- end template query65.tpl query 78 in stream 4 --- start template query15.tpl query 79 in stream 4 -select /* TPC-DS query15.tpl 0.57 */ ca_zip - ,sum(cs_sales_price) - from catalog_sales - ,customer - ,customer_address - ,date_dim - where cs_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', - '85392', '85460', '80348', '81792') - or ca_state in ('CA','WA','GA') - or cs_sales_price > 500) - and cs_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 2002 - group by ca_zip - order by ca_zip - limit 100; - --- end template query15.tpl query 79 in stream 4 --- start template query98.tpl query 80 in stream 4 -select /* TPC-DS query98.tpl 0.32 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ss_ext_sales_price) as itemrevenue - ,sum(ss_ext_sales_price)*100/sum(sum(ss_ext_sales_price)) over - (partition by i_class) as revenueratio -from - store_sales - ,item - ,date_dim -where - ss_item_sk = i_item_sk - and i_category in ('Women', 'Men', 'Books') - and ss_sold_date_sk = d_date_sk - and d_date between cast('1998-01-31' as date) - and dateadd(day,30,cast('1998-01-31' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio; - --- end template query98.tpl query 80 in stream 4 --- start template query42.tpl query 81 in stream 4 -select /* TPC-DS query42.tpl 0.61 */ dt.d_year - ,item.i_category_id - ,item.i_category - ,sum(ss_ext_sales_price) - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=11 - and dt.d_year=1999 - group by dt.d_year - ,item.i_category_id - ,item.i_category - order by sum(ss_ext_sales_price) desc,dt.d_year - ,item.i_category_id - ,item.i_category -limit 100 ; - --- end template query42.tpl query 81 in stream 4 --- start template query26.tpl query 82 in stream 4 -select /* TPC-DS query26.tpl 0.85 */ i_item_id, - avg(cs_quantity) agg1, - avg(cs_list_price) agg2, - avg(cs_coupon_amt) agg3, - avg(cs_sales_price) agg4 - from catalog_sales, customer_demographics, date_dim, item, promotion - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd_demo_sk and - cs_promo_sk = p_promo_sk and - cd_gender = 'F' and - cd_marital_status = 'U' and - cd_education_status = '4 yr Degree' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 2002 - group by i_item_id - order by i_item_id - limit 100; - --- end template query26.tpl query 82 in stream 4 --- start template query34.tpl query 83 in stream 4 -select /* TPC-DS query34.tpl 0.73 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (date_dim.d_dom between 1 and 3 or date_dim.d_dom between 25 and 28) - and (household_demographics.hd_buy_potential = '1001-5000' or - household_demographics.hd_buy_potential = 'Unknown') - and household_demographics.hd_vehicle_count > 0 - and (case when household_demographics.hd_vehicle_count > 0 - then household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count - else null - end) > 1.2 - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_county in ('Walker County','Orangeburg County','Chambers County','Appomattox County', - 'Jackson County','Brown County','Nowata County','Anderson County') - group by ss_ticket_number,ss_customer_sk) dn,customer - where ss_customer_sk = c_customer_sk - and cnt between 15 and 20 - order by c_last_name,c_first_name,c_salutation,c_preferred_cust_flag desc, ss_ticket_number; - --- end template query34.tpl query 83 in stream 4 --- start template query5a.tpl query 84 in stream 4 -with /* TPC-DS query5a.tpl 0.98 */ ssr as - (select s_store_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ss_store_sk as store_sk, - ss_sold_date_sk as date_sk, - ss_ext_sales_price as sales_price, - ss_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from store_sales - union all - select sr_store_sk as store_sk, - sr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - sr_return_amt as return_amt, - sr_net_loss as net_loss - from store_returns - ) salesreturns, - date_dim, - store - where date_sk = d_date_sk - and d_date between cast('2001-08-09' as date) - and dateadd(day,14,cast('2001-08-09' as date)) - and store_sk = s_store_sk - group by s_store_id) - , - csr as - (select cp_catalog_page_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select cs_catalog_page_sk as page_sk, - cs_sold_date_sk as date_sk, - cs_ext_sales_price as sales_price, - cs_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from catalog_sales - union all - select cr_catalog_page_sk as page_sk, - cr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - cr_return_amount as return_amt, - cr_net_loss as net_loss - from catalog_returns - ) salesreturns, - date_dim, - catalog_page - where date_sk = d_date_sk - and d_date between cast('2001-08-09' as date) - and dateadd(day,14,cast('2001-08-09' as date)) - and page_sk = cp_catalog_page_sk - group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ws_web_site_sk as wsr_web_site_sk, - ws_sold_date_sk as date_sk, - ws_ext_sales_price as sales_price, - ws_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from web_sales - union all - select ws_web_site_sk as wsr_web_site_sk, - wr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - wr_return_amt as return_amt, - wr_net_loss as net_loss - from web_returns left outer join web_sales on - ( wr_item_sk = ws_item_sk - and wr_order_number = ws_order_number) - ) salesreturns, - date_dim, - web_site - where date_sk = d_date_sk - and d_date between cast('2001-08-09' as date) - and dateadd(day,14,cast('2001-08-09' as date)) - and wsr_web_site_sk = web_site_sk - group by web_site_id) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || s_store_id as id - , sales - , returns - , (profit - profit_loss) as profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || cp_catalog_page_id as id - , sales - , returns - , (profit - profit_loss) as profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , (profit - profit_loss) as profit - from wsr - ) x - group by channel, id) - select channel, id, sales, returns, profit from ( - select channel, id, sales, returns, profit from results - union - select channel, null as id, sum(sales), sum(returns), sum(profit) from results group by channel - union - select null as channel, null as id, sum(sales), sum(returns), sum(profit) from results) foo -order by channel, id -limit 100; - --- end template query5a.tpl query 84 in stream 4 --- start template query87.tpl query 85 in stream 4 -select /* TPC-DS query87.tpl 0.77 */ count(*) -from ((select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1210 and 1210+11) - except - (select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1210 and 1210+11) - except - (select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1210 and 1210+11) -) cool_cust -; - --- end template query87.tpl query 85 in stream 4 --- start template query3.tpl query 86 in stream 4 -select /* TPC-DS query3.tpl 0.45 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_net_profit) sum_agg - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manufact_id = 201 - and dt.d_moy=12 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,sum_agg desc - ,brand_id - limit 100; - --- end template query3.tpl query 86 in stream 4 --- start template query64.tpl query 87 in stream 4 -with /* TPC-DS query64.tpl 0.20 */ cs_ui as - (select cs_item_sk - ,sum(cs_ext_list_price) as sale,sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit) as refund - from catalog_sales - ,catalog_returns - where cs_item_sk = cr_item_sk - and cs_order_number = cr_order_number - group by cs_item_sk - having sum(cs_ext_list_price)>2*sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit)), -cross_sales as - (select i_product_name product_name - ,i_item_sk item_sk - ,s_store_name store_name - ,s_zip store_zip - ,ad1.ca_street_number b_street_number - ,ad1.ca_street_name b_street_name - ,ad1.ca_city b_city - ,ad1.ca_zip b_zip - ,ad2.ca_street_number c_street_number - ,ad2.ca_street_name c_street_name - ,ad2.ca_city c_city - ,ad2.ca_zip c_zip - ,d1.d_year as syear - ,d2.d_year as fsyear - ,d3.d_year s2year - ,count(*) cnt - ,sum(ss_wholesale_cost) s1 - ,sum(ss_list_price) s2 - ,sum(ss_coupon_amt) s3 - FROM store_sales - ,store_returns - ,cs_ui - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,customer - ,customer_demographics cd1 - ,customer_demographics cd2 - ,promotion - ,household_demographics hd1 - ,household_demographics hd2 - ,customer_address ad1 - ,customer_address ad2 - ,income_band ib1 - ,income_band ib2 - ,item - WHERE ss_store_sk = s_store_sk AND - ss_sold_date_sk = d1.d_date_sk AND - ss_customer_sk = c_customer_sk AND - ss_cdemo_sk= cd1.cd_demo_sk AND - ss_hdemo_sk = hd1.hd_demo_sk AND - ss_addr_sk = ad1.ca_address_sk and - ss_item_sk = i_item_sk and - ss_item_sk = sr_item_sk and - ss_ticket_number = sr_ticket_number and - ss_item_sk = cs_ui.cs_item_sk and - c_current_cdemo_sk = cd2.cd_demo_sk AND - c_current_hdemo_sk = hd2.hd_demo_sk AND - c_current_addr_sk = ad2.ca_address_sk and - c_first_sales_date_sk = d2.d_date_sk and - c_first_shipto_date_sk = d3.d_date_sk and - ss_promo_sk = p_promo_sk and - hd1.hd_income_band_sk = ib1.ib_income_band_sk and - hd2.hd_income_band_sk = ib2.ib_income_band_sk and - cd1.cd_marital_status <> cd2.cd_marital_status and - i_color in ('orange','lawn','snow','almond','navajo','rosy') and - i_current_price between 13 and 13 + 10 and - i_current_price between 13 + 1 and 13 + 15 -group by i_product_name - ,i_item_sk - ,s_store_name - ,s_zip - ,ad1.ca_street_number - ,ad1.ca_street_name - ,ad1.ca_city - ,ad1.ca_zip - ,ad2.ca_street_number - ,ad2.ca_street_name - ,ad2.ca_city - ,ad2.ca_zip - ,d1.d_year - ,d2.d_year - ,d3.d_year -) -select cs1.product_name - ,cs1.store_name - ,cs1.store_zip - ,cs1.b_street_number - ,cs1.b_street_name - ,cs1.b_city - ,cs1.b_zip - ,cs1.c_street_number - ,cs1.c_street_name - ,cs1.c_city - ,cs1.c_zip - ,cs1.syear - ,cs1.cnt - ,cs1.s1 as s11 - ,cs1.s2 as s21 - ,cs1.s3 as s31 - ,cs2.s1 as s12 - ,cs2.s2 as s22 - ,cs2.s3 as s32 - ,cs2.syear - ,cs2.cnt -from cross_sales cs1,cross_sales cs2 -where cs1.item_sk=cs2.item_sk and - cs1.syear = 2000 and - cs2.syear = 2000 + 1 and - cs2.cnt <= cs1.cnt and - cs1.store_name = cs2.store_name and - cs1.store_zip = cs2.store_zip -order by cs1.product_name - ,cs1.store_name - ,cs2.cnt - ,cs1.s1 - ,cs2.s1; - --- end template query64.tpl query 87 in stream 4 --- start template query31.tpl query 88 in stream 4 -with /* TPC-DS query31.tpl 0.50 */ ss as - (select ca_county,d_qoy, d_year,sum(ss_ext_sales_price) as store_sales - from store_sales,date_dim,customer_address - where ss_sold_date_sk = d_date_sk - and ss_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year), - ws as - (select ca_county,d_qoy, d_year,sum(ws_ext_sales_price) as web_sales - from web_sales,date_dim,customer_address - where ws_sold_date_sk = d_date_sk - and ws_bill_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year) - select - ss1.ca_county - ,ss1.d_year - ,ws2.web_sales/ws1.web_sales web_q1_q2_increase - ,ss2.store_sales/ss1.store_sales store_q1_q2_increase - ,ws3.web_sales/ws2.web_sales web_q2_q3_increase - ,ss3.store_sales/ss2.store_sales store_q2_q3_increase - from - ss ss1 - ,ss ss2 - ,ss ss3 - ,ws ws1 - ,ws ws2 - ,ws ws3 - where - ss1.d_qoy = 1 - and ss1.d_year = 2000 - and ss1.ca_county = ss2.ca_county - and ss2.d_qoy = 2 - and ss2.d_year = 2000 - and ss2.ca_county = ss3.ca_county - and ss3.d_qoy = 3 - and ss3.d_year = 2000 - and ss1.ca_county = ws1.ca_county - and ws1.d_qoy = 1 - and ws1.d_year = 2000 - and ws1.ca_county = ws2.ca_county - and ws2.d_qoy = 2 - and ws2.d_year = 2000 - and ws1.ca_county = ws3.ca_county - and ws3.d_qoy = 3 - and ws3.d_year =2000 - and case when ws1.web_sales > 0 then ws2.web_sales/ws1.web_sales else null end - > case when ss1.store_sales > 0 then ss2.store_sales/ss1.store_sales else null end - and case when ws2.web_sales > 0 then ws3.web_sales/ws2.web_sales else null end - > case when ss2.store_sales > 0 then ss3.store_sales/ss2.store_sales else null end - order by web_q1_q2_increase; - --- end template query31.tpl query 88 in stream 4 --- start template query57.tpl query 89 in stream 4 -with /* TPC-DS query57.tpl 0.70 */ v1 as( - select i_category, i_brand, - cc_name, - d_year, d_moy, - sum(cs_sales_price) sum_sales, - avg(sum(cs_sales_price)) over - (partition by i_category, i_brand, - cc_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - cc_name - order by d_year, d_moy) rn - from item, catalog_sales, date_dim, call_center - where cs_item_sk = i_item_sk and - cs_sold_date_sk = d_date_sk and - cc_call_center_sk= cs_call_center_sk and - ( - d_year = 1999 or - ( d_year = 1999-1 and d_moy =12) or - ( d_year = 1999+1 and d_moy =1) - ) - group by i_category, i_brand, - cc_name , d_year, d_moy), - v2 as( - select v1.i_category, v1.i_brand, v1.cc_name - ,v1.d_year - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1. cc_name = v1_lag. cc_name and - v1. cc_name = v1_lead. cc_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 1999 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, nsum - limit 100; - --- end template query57.tpl query 89 in stream 4 --- start template query30.tpl query 90 in stream 4 -with /* TPC-DS query30.tpl 0.75 */ customer_total_return as - (select wr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(wr_return_amt) as ctr_total_return - from web_returns - ,date_dim - ,customer_address - where wr_returned_date_sk = d_date_sk - and d_year =2000 - and wr_returning_addr_sk = ca_address_sk - group by wr_returning_customer_sk - ,ca_state) - select c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'MT' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return -limit 100; - --- end template query30.tpl query 90 in stream 4 --- start template query13.tpl query 91 in stream 4 -select /* TPC-DS query13.tpl 0.91 */ avg(ss_quantity) - ,avg(ss_ext_sales_price) - ,avg(ss_ext_wholesale_cost) - ,sum(ss_ext_wholesale_cost) - from store_sales - ,store - ,customer_demographics - ,household_demographics - ,customer_address - ,date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2001 - and((ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'M' - and cd_education_status = 'Primary' - and ss_sales_price between 100.00 and 150.00 - and hd_dep_count = 3 - )or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'W' - and cd_education_status = 'Unknown' - and ss_sales_price between 50.00 and 100.00 - and hd_dep_count = 1 - ) or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'U' - and cd_education_status = '4 yr Degree' - and ss_sales_price between 150.00 and 200.00 - and hd_dep_count = 1 - )) - and((ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('TX', 'OR', 'IN') - and ss_net_profit between 100 and 200 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('IL', 'NE', 'WI') - and ss_net_profit between 150 and 300 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('IA', 'VT', 'SC') - and ss_net_profit between 50 and 250 - )) -; - --- end template query13.tpl query 91 in stream 4 --- start template query94.tpl query 92 in stream 4 -select /* TPC-DS query94.tpl 0.17 */ - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2001-3-01' and - dateadd(day,60,cast('2001-3-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'NC' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and exists (select * - from web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) -and not exists(select * - from web_returns wr1 - where ws1.ws_order_number = wr1.wr_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query94.tpl query 92 in stream 4 --- start template query62.tpl query 93 in stream 4 -select /* TPC-DS query62.tpl 0.24 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 30) and - (ws_ship_date_sk - ws_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 60) and - (ws_ship_date_sk - ws_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 90) and - (ws_ship_date_sk - ws_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - web_sales - ,warehouse - ,ship_mode - ,web_site - ,date_dim -where - d_month_seq between 1200 and 1200 + 11 -and ws_ship_date_sk = d_date_sk -and ws_warehouse_sk = w_warehouse_sk -and ws_ship_mode_sk = sm_ship_mode_sk -and ws_web_site_sk = web_site_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -limit 100; - --- end template query62.tpl query 93 in stream 4 --- start template query49.tpl query 94 in stream 4 -select /* TPC-DS query49.tpl 0.48 */ channel, item, return_ratio, return_rank, currency_rank from - (select - 'web' as channel - ,web.item - ,web.return_ratio - ,web.return_rank - ,web.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select ws.ws_item_sk as item - ,(cast(sum(coalesce(wr.wr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(wr.wr_return_amt,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - web_sales ws left outer join web_returns wr - on (ws.ws_order_number = wr.wr_order_number and - ws.ws_item_sk = wr.wr_item_sk) - ,date_dim - where - wr.wr_return_amt > 10000 - and ws.ws_net_profit > 1 - and ws.ws_net_paid > 0 - and ws.ws_quantity > 0 - and ws_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 12 - group by ws.ws_item_sk - ) in_web - ) web - where - ( - web.return_rank <= 10 - or - web.currency_rank <= 10 - ) - union - select - 'catalog' as channel - ,catalog.item - ,catalog.return_ratio - ,catalog.return_rank - ,catalog.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select - cs.cs_item_sk as item - ,(cast(sum(coalesce(cr.cr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(cr.cr_return_amount,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - catalog_sales cs left outer join catalog_returns cr - on (cs.cs_order_number = cr.cr_order_number and - cs.cs_item_sk = cr.cr_item_sk) - ,date_dim - where - cr.cr_return_amount > 10000 - and cs.cs_net_profit > 1 - and cs.cs_net_paid > 0 - and cs.cs_quantity > 0 - and cs_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 12 - group by cs.cs_item_sk - ) in_cat - ) catalog - where - ( - catalog.return_rank <= 10 - or - catalog.currency_rank <=10 - ) - union - select - 'store' as channel - ,store.item - ,store.return_ratio - ,store.return_rank - ,store.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select sts.ss_item_sk as item - ,(cast(sum(coalesce(sr.sr_return_quantity,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(sr.sr_return_amt,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - store_sales sts left outer join store_returns sr - on (sts.ss_ticket_number = sr.sr_ticket_number and sts.ss_item_sk = sr.sr_item_sk) - ,date_dim - where - sr.sr_return_amt > 10000 - and sts.ss_net_profit > 1 - and sts.ss_net_paid > 0 - and sts.ss_quantity > 0 - and ss_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 12 - group by sts.ss_item_sk - ) in_store - ) store - where ( - store.return_rank <= 10 - or - store.currency_rank <= 10 - ) - ) - order by 1,4,5,2 - limit 100; - --- end template query49.tpl query 94 in stream 4 --- start template query11.tpl query 95 in stream 4 -with /* TPC-DS query11.tpl 0.51 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ss_ext_list_price-ss_ext_discount_amt) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ws_ext_list_price-ws_ext_discount_amt) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_preferred_cust_flag - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 2000 - and t_s_secyear.dyear = 2000+1 - and t_w_firstyear.dyear = 2000 - and t_w_secyear.dyear = 2000+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else 0.0 end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else 0.0 end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_preferred_cust_flag -limit 100; - --- end template query11.tpl query 95 in stream 4 --- start template query73.tpl query 96 in stream 4 -select /* TPC-DS query73.tpl 0.79 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_buy_potential = '1001-5000' or - household_demographics.hd_buy_potential = '5001-10000') - and household_demographics.hd_vehicle_count > 0 - and case when household_demographics.hd_vehicle_count > 0 then - household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count else null end > 1 - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_county in ('Wilkinson County','Luce County','Box Butte County','Brown County') - group by ss_ticket_number,ss_customer_sk) dj,customer - where ss_customer_sk = c_customer_sk - and cnt between 1 and 5 - order by cnt desc, c_last_name asc; - --- end template query73.tpl query 96 in stream 4 --- start template query67a.tpl query 97 in stream 4 -with /* TPC-DS query67a.tpl 0.35 */ results as -( select i_category ,i_class ,i_brand ,i_product_name ,d_year ,d_qoy ,d_moy ,s_store_id - ,sum(coalesce(ss_sales_price*ss_quantity,0)) sumsales - from store_sales ,date_dim ,store ,item - where ss_sold_date_sk=d_date_sk - and ss_item_sk=i_item_sk - and ss_store_sk = s_store_sk - and d_month_seq between 1209 and 1209 + 11 - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy,s_store_id) - , - results_rollup as - (select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, s_store_id, sumsales - from results - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy - union all - select i_category, i_class, i_brand, i_product_name, d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year - union all - select i_category, i_class, i_brand, i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name - union all - select i_category, i_class, i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand - union all - select i_category, i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class - union all - select i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category - union all - select null i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results) - - select * -from (select i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rank() over (partition by i_category order by sumsales desc) rk - from results_rollup) dw2 -where rk <= 100 -order by i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rk -limit 100; - --- end template query67a.tpl query 97 in stream 4 --- start template query53.tpl query 98 in stream 4 -select /* TPC-DS query53.tpl 0.88 */ * from -(select i_manufact_id, -sum(ss_sales_price) sum_sales, -avg(sum(ss_sales_price)) over (partition by i_manufact_id) avg_quarterly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and -ss_sold_date_sk = d_date_sk and -ss_store_sk = s_store_sk and -d_month_seq in (1209,1209+1,1209+2,1209+3,1209+4,1209+5,1209+6,1209+7,1209+8,1209+9,1209+10,1209+11) and -((i_category in ('Books','Children','Electronics') and -i_class in ('personal','portable','reference','self-help') and -i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) -or(i_category in ('Women','Music','Men') and -i_class in ('accessories','classical','fragrances','pants') and -i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manufact_id, d_qoy ) tmp1 -where case when avg_quarterly_sales > 0 - then abs (sum_sales - avg_quarterly_sales)/ avg_quarterly_sales - else null end > 0.1 -order by avg_quarterly_sales, - sum_sales, - i_manufact_id -limit 100; - --- end template query53.tpl query 98 in stream 4 --- start template query9.tpl query 99 in stream 4 -select /* TPC-DS query9.tpl 0.49 */ case when (select count(*) - from store_sales - where ss_quantity between 1 and 20) > 1004751084 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 1 and 20) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 1 and 20) end bucket1 , - case when (select count(*) - from store_sales - where ss_quantity between 21 and 40) > 247309516 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 21 and 40) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 21 and 40) end bucket2, - case when (select count(*) - from store_sales - where ss_quantity between 41 and 60) > 945401129 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 41 and 60) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 41 and 60) end bucket3, - case when (select count(*) - from store_sales - where ss_quantity between 61 and 80) > 258417842 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 61 and 80) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 61 and 80) end bucket4, - case when (select count(*) - from store_sales - where ss_quantity between 81 and 100) > 753010906 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 81 and 100) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 81 and 100) end bucket5 -from reason -where r_reason_sk = 1 -; - --- end template query9.tpl query 99 in stream 4 diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/30TB/queries/query_5.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/30TB/queries/query_5.sql deleted file mode 100644 index e6094a75..00000000 --- a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/30TB/queries/query_5.sql +++ /dev/null @@ -1,5027 +0,0 @@ --- start template query73.tpl query 1 in stream 5 -select /* TPC-DS query73.tpl 0.79 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_buy_potential = '501-1000' or - household_demographics.hd_buy_potential = '5001-10000') - and household_demographics.hd_vehicle_count > 0 - and case when household_demographics.hd_vehicle_count > 0 then - household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count else null end > 1 - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_county in ('Hoke County','Lunenburg County','Baltimore County','Porter County') - group by ss_ticket_number,ss_customer_sk) dj,customer - where ss_customer_sk = c_customer_sk - and cnt between 1 and 5 - order by cnt desc, c_last_name asc; - --- end template query73.tpl query 1 in stream 5 --- start template query66.tpl query 2 in stream 5 -select /* TPC-DS query66.tpl 0.39 */ - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - ,sum(jan_sales) as jan_sales - ,sum(feb_sales) as feb_sales - ,sum(mar_sales) as mar_sales - ,sum(apr_sales) as apr_sales - ,sum(may_sales) as may_sales - ,sum(jun_sales) as jun_sales - ,sum(jul_sales) as jul_sales - ,sum(aug_sales) as aug_sales - ,sum(sep_sales) as sep_sales - ,sum(oct_sales) as oct_sales - ,sum(nov_sales) as nov_sales - ,sum(dec_sales) as dec_sales - ,sum(jan_sales/w_warehouse_sq_ft) as jan_sales_per_sq_foot - ,sum(feb_sales/w_warehouse_sq_ft) as feb_sales_per_sq_foot - ,sum(mar_sales/w_warehouse_sq_ft) as mar_sales_per_sq_foot - ,sum(apr_sales/w_warehouse_sq_ft) as apr_sales_per_sq_foot - ,sum(may_sales/w_warehouse_sq_ft) as may_sales_per_sq_foot - ,sum(jun_sales/w_warehouse_sq_ft) as jun_sales_per_sq_foot - ,sum(jul_sales/w_warehouse_sq_ft) as jul_sales_per_sq_foot - ,sum(aug_sales/w_warehouse_sq_ft) as aug_sales_per_sq_foot - ,sum(sep_sales/w_warehouse_sq_ft) as sep_sales_per_sq_foot - ,sum(oct_sales/w_warehouse_sq_ft) as oct_sales_per_sq_foot - ,sum(nov_sales/w_warehouse_sq_ft) as nov_sales_per_sq_foot - ,sum(dec_sales/w_warehouse_sq_ft) as dec_sales_per_sq_foot - ,sum(jan_net) as jan_net - ,sum(feb_net) as feb_net - ,sum(mar_net) as mar_net - ,sum(apr_net) as apr_net - ,sum(may_net) as may_net - ,sum(jun_net) as jun_net - ,sum(jul_net) as jul_net - ,sum(aug_net) as aug_net - ,sum(sep_net) as sep_net - ,sum(oct_net) as oct_net - ,sum(nov_net) as nov_net - ,sum(dec_net) as dec_net - from ( - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'GREAT EASTERN' || ',' || 'BARIAN' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then ws_ext_sales_price* ws_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then ws_ext_sales_price* ws_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then ws_ext_sales_price* ws_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then ws_ext_sales_price* ws_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then ws_ext_sales_price* ws_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then ws_ext_sales_price* ws_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then ws_ext_sales_price* ws_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then ws_ext_sales_price* ws_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then ws_ext_sales_price* ws_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then ws_ext_sales_price* ws_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then ws_ext_sales_price* ws_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then ws_ext_sales_price* ws_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then ws_net_paid * ws_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then ws_net_paid * ws_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then ws_net_paid * ws_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then ws_net_paid * ws_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then ws_net_paid * ws_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then ws_net_paid * ws_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then ws_net_paid * ws_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then ws_net_paid * ws_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then ws_net_paid * ws_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then ws_net_paid * ws_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then ws_net_paid * ws_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then ws_net_paid * ws_quantity else 0 end) as dec_net - from - web_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - ws_warehouse_sk = w_warehouse_sk - and ws_sold_date_sk = d_date_sk - and ws_sold_time_sk = t_time_sk - and ws_ship_mode_sk = sm_ship_mode_sk - and d_year = 1999 - and t_time between 10465 and 10465+28800 - and sm_carrier in ('GREAT EASTERN','BARIAN') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - union all - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'GREAT EASTERN' || ',' || 'BARIAN' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then cs_sales_price* cs_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then cs_sales_price* cs_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then cs_sales_price* cs_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then cs_sales_price* cs_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then cs_sales_price* cs_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then cs_sales_price* cs_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then cs_sales_price* cs_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then cs_sales_price* cs_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then cs_sales_price* cs_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then cs_sales_price* cs_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then cs_sales_price* cs_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then cs_sales_price* cs_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as dec_net - from - catalog_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and cs_sold_time_sk = t_time_sk - and cs_ship_mode_sk = sm_ship_mode_sk - and d_year = 1999 - and t_time between 10465 AND 10465+28800 - and sm_carrier in ('GREAT EASTERN','BARIAN') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - ) x - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - order by w_warehouse_name - limit 100; - --- end template query66.tpl query 2 in stream 5 --- start template query4.tpl query 3 in stream 5 -with /* TPC-DS query4.tpl 0.93 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(((ss_ext_list_price-ss_ext_wholesale_cost-ss_ext_discount_amt)+ss_ext_sales_price)/2) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((cs_ext_list_price-cs_ext_wholesale_cost-cs_ext_discount_amt)+cs_ext_sales_price)/2) ) year_total - ,'c' sale_type - from customer - ,catalog_sales - ,date_dim - where c_customer_sk = cs_bill_customer_sk - and cs_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year -union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((ws_ext_list_price-ws_ext_wholesale_cost-ws_ext_discount_amt)+ws_ext_sales_price)/2) ) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_email_address - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_c_firstyear - ,year_total t_c_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_c_secyear.customer_id - and t_s_firstyear.customer_id = t_c_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_c_firstyear.sale_type = 'c' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_c_secyear.sale_type = 'c' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 2000 - and t_s_secyear.dyear = 2000+1 - and t_c_firstyear.dyear = 2000 - and t_c_secyear.dyear = 2000+1 - and t_w_firstyear.dyear = 2000 - and t_w_secyear.dyear = 2000+1 - and t_s_firstyear.year_total > 0 - and t_c_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_email_address -limit 100; - --- end template query4.tpl query 3 in stream 5 --- start template query17.tpl query 4 in stream 5 -select /* TPC-DS query17.tpl 0.41 */ i_item_id - ,i_item_desc - ,s_state - ,count(ss_quantity) as store_sales_quantitycount - ,avg(ss_quantity) as store_sales_quantityave - ,stddev_samp(ss_quantity) as store_sales_quantitystdev - ,stddev_samp(ss_quantity)/avg(ss_quantity) as store_sales_quantitycov - ,count(sr_return_quantity) as store_returns_quantitycount - ,avg(sr_return_quantity) as store_returns_quantityave - ,stddev_samp(sr_return_quantity) as store_returns_quantitystdev - ,stddev_samp(sr_return_quantity)/avg(sr_return_quantity) as store_returns_quantitycov - ,count(cs_quantity) as catalog_sales_quantitycount ,avg(cs_quantity) as catalog_sales_quantityave - ,stddev_samp(cs_quantity) as catalog_sales_quantitystdev - ,stddev_samp(cs_quantity)/avg(cs_quantity) as catalog_sales_quantitycov - from store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where d1.d_quarter_name = '2001Q1' - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_quarter_name in ('2001Q1','2001Q2','2001Q3') - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_quarter_name in ('2001Q1','2001Q2','2001Q3') - group by i_item_id - ,i_item_desc - ,s_state - order by i_item_id - ,i_item_desc - ,s_state -limit 100; - --- end template query17.tpl query 4 in stream 5 --- start template query60.tpl query 5 in stream 5 -with /* TPC-DS query60.tpl 0.29 */ ss as ( - select - i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Music')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 8 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - cs as ( - select - i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Music')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 8 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - ws as ( - select - i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Music')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 8 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id) - select - i_item_id -,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by i_item_id - ,total_sales - limit 100; - --- end template query60.tpl query 5 in stream 5 --- start template query98.tpl query 6 in stream 5 -select /* TPC-DS query98.tpl 0.32 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ss_ext_sales_price) as itemrevenue - ,sum(ss_ext_sales_price)*100/sum(sum(ss_ext_sales_price)) over - (partition by i_class) as revenueratio -from - store_sales - ,item - ,date_dim -where - ss_item_sk = i_item_sk - and i_category in ('Sports', 'Children', 'Music') - and ss_sold_date_sk = d_date_sk - and d_date between cast('2000-06-25' as date) - and dateadd(day,30,cast('2000-06-25' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio; - --- end template query98.tpl query 6 in stream 5 --- start template query88.tpl query 7 in stream 5 -select /* TPC-DS query88.tpl 0.66 */ * -from - (select count(*) h8_30_to_9 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2)) - and store.s_store_name = 'ese') s1, - (select count(*) h9_to_9_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2)) - and store.s_store_name = 'ese') s2, - (select count(*) h9_30_to_10 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2)) - and store.s_store_name = 'ese') s3, - (select count(*) h10_to_10_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2)) - and store.s_store_name = 'ese') s4, - (select count(*) h10_30_to_11 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2)) - and store.s_store_name = 'ese') s5, - (select count(*) h11_to_11_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2)) - and store.s_store_name = 'ese') s6, - (select count(*) h11_30_to_12 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2)) - and store.s_store_name = 'ese') s7, - (select count(*) h12_to_12_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 12 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2)) - and store.s_store_name = 'ese') s8 -; - --- end template query88.tpl query 7 in stream 5 --- start template query2.tpl query 8 in stream 5 -with /* TPC-DS query2.tpl 0.84 */ wscs as - (select sold_date_sk - ,sales_price - from (select ws_sold_date_sk sold_date_sk - ,ws_ext_sales_price sales_price - from web_sales - union all - select cs_sold_date_sk sold_date_sk - ,cs_ext_sales_price sales_price - from catalog_sales)), - wswscs as - (select d_week_seq, - sum(case when (d_day_name='Sunday') then sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then sales_price else null end) sat_sales - from wscs - ,date_dim - where d_date_sk = sold_date_sk - group by d_week_seq) - select d_week_seq1 - ,round(sun_sales1/sun_sales2,2) - ,round(mon_sales1/mon_sales2,2) - ,round(tue_sales1/tue_sales2,2) - ,round(wed_sales1/wed_sales2,2) - ,round(thu_sales1/thu_sales2,2) - ,round(fri_sales1/fri_sales2,2) - ,round(sat_sales1/sat_sales2,2) - from - (select wswscs.d_week_seq d_week_seq1 - ,sun_sales sun_sales1 - ,mon_sales mon_sales1 - ,tue_sales tue_sales1 - ,wed_sales wed_sales1 - ,thu_sales thu_sales1 - ,fri_sales fri_sales1 - ,sat_sales sat_sales1 - from wswscs,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 2000) y, - (select wswscs.d_week_seq d_week_seq2 - ,sun_sales sun_sales2 - ,mon_sales mon_sales2 - ,tue_sales tue_sales2 - ,wed_sales wed_sales2 - ,thu_sales thu_sales2 - ,fri_sales fri_sales2 - ,sat_sales sat_sales2 - from wswscs - ,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 2000+1) z - where d_week_seq1=d_week_seq2-53 - order by d_week_seq1; - --- end template query2.tpl query 8 in stream 5 --- start template query19.tpl query 9 in stream 5 -select /* TPC-DS query19.tpl 0.8 */ i_brand_id brand_id, i_brand brand, i_manufact_id, i_manufact, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item,customer,customer_address,store - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=55 - and d_moy=11 - and d_year=1998 - and ss_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and substring(ca_zip,1,5) <> substring(s_zip,1,5) - and ss_store_sk = s_store_sk - group by i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact - order by ext_price desc - ,i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact -limit 100 ; - --- end template query19.tpl query 9 in stream 5 --- start template query65.tpl query 10 in stream 5 -select /* TPC-DS query65.tpl 0.71 */ - s_store_name, - i_item_desc, - sc.revenue, - i_current_price, - i_wholesale_cost, - i_brand - from store, item, - (select ss_store_sk, avg(revenue) as ave - from - (select ss_store_sk, ss_item_sk, - sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1186 and 1186+11 - group by ss_store_sk, ss_item_sk) sa - group by ss_store_sk) sb, - (select ss_store_sk, ss_item_sk, sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1186 and 1186+11 - group by ss_store_sk, ss_item_sk) sc - where sb.ss_store_sk = sc.ss_store_sk and - sc.revenue <= 0.1 * sb.ave and - s_store_sk = sc.ss_store_sk and - i_item_sk = sc.ss_item_sk - order by s_store_name, i_item_desc -limit 100; - --- end template query65.tpl query 10 in stream 5 --- start template query3.tpl query 11 in stream 5 -select /* TPC-DS query3.tpl 0.45 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_sales_price) sum_agg - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manufact_id = 128 - and dt.d_moy=11 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,sum_agg desc - ,brand_id - limit 100; - --- end template query3.tpl query 11 in stream 5 --- start template query79.tpl query 12 in stream 5 -select /* TPC-DS query79.tpl 0.89 */ - c_last_name,c_first_name,substring(s_city,1,30),ss_ticket_number,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,store.s_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (household_demographics.hd_dep_count = 5 or household_demographics.hd_vehicle_count > 4) - and date_dim.d_dow = 1 - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_number_employees between 200 and 295 - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,store.s_city) ms,customer - where ss_customer_sk = c_customer_sk - order by c_last_name,c_first_name,substring(s_city,1,30), profit -limit 100; - --- end template query79.tpl query 12 in stream 5 --- start template query13.tpl query 13 in stream 5 -select /* TPC-DS query13.tpl 0.91 */ avg(ss_quantity) - ,avg(ss_ext_sales_price) - ,avg(ss_ext_wholesale_cost) - ,sum(ss_ext_wholesale_cost) - from store_sales - ,store - ,customer_demographics - ,household_demographics - ,customer_address - ,date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2001 - and((ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'S' - and cd_education_status = 'Unknown' - and ss_sales_price between 100.00 and 150.00 - and hd_dep_count = 3 - )or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'W' - and cd_education_status = '4 yr Degree' - and ss_sales_price between 50.00 and 100.00 - and hd_dep_count = 1 - ) or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'D' - and cd_education_status = 'Secondary' - and ss_sales_price between 150.00 and 200.00 - and hd_dep_count = 1 - )) - and((ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('OK', 'TN', 'ID') - and ss_net_profit between 100 and 200 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('FL', 'OH', 'GA') - and ss_net_profit between 150 and 300 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('IL', 'IN', 'KS') - and ss_net_profit between 50 and 250 - )) -; - --- end template query13.tpl query 13 in stream 5 --- start template query21.tpl query 14 in stream 5 -select /* TPC-DS query21.tpl 0.14 */ * - from(select w_warehouse_name - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('2002-06-11' as date)) - then inv_quantity_on_hand - else 0 end) as inv_before - ,sum(case when (cast(d_date as date) >= cast ('2002-06-11' as date)) - then inv_quantity_on_hand - else 0 end) as inv_after - from inventory - ,warehouse - ,item - ,date_dim - where i_current_price between 0.99 and 1.49 - and i_item_sk = inv_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('2002-06-11' as date)) - and dateadd(day,30,cast ('2002-06-11' as date)) - group by w_warehouse_name, i_item_id) x - where (case when inv_before > 0 - then inv_after / inv_before - else null - end) between 2.0/3.0 and 3.0/2.0 - order by w_warehouse_name - ,i_item_id - limit 100; - --- end template query21.tpl query 14 in stream 5 --- start template query51.tpl query 15 in stream 5 -WITH /* TPC-DS query51.tpl 0.46 */ web_v1 as ( -select - ws_item_sk item_sk, d_date, - sum(sum(ws_sales_price)) - over (partition by ws_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from web_sales - ,date_dim -where ws_sold_date_sk=d_date_sk - and d_month_seq between 1188 and 1188+11 - and ws_item_sk is not NULL -group by ws_item_sk, d_date), -store_v1 as ( -select - ss_item_sk item_sk, d_date, - sum(sum(ss_sales_price)) - over (partition by ss_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from store_sales - ,date_dim -where ss_sold_date_sk=d_date_sk - and d_month_seq between 1188 and 1188+11 - and ss_item_sk is not NULL -group by ss_item_sk, d_date) - select * -from (select item_sk - ,d_date - ,web_sales - ,store_sales - ,max(web_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) web_cumulative - ,max(store_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) store_cumulative - from (select case when web.item_sk is not null then web.item_sk else store.item_sk end item_sk - ,case when web.d_date is not null then web.d_date else store.d_date end d_date - ,web.cume_sales web_sales - ,store.cume_sales store_sales - from web_v1 web full outer join store_v1 store on (web.item_sk = store.item_sk - and web.d_date = store.d_date) - )x )y -where web_cumulative > store_cumulative -order by item_sk - ,d_date -limit 100; - --- end template query51.tpl query 15 in stream 5 --- start template query6.tpl query 16 in stream 5 -select /* TPC-DS query6.tpl 0.58 */ a.ca_state state, count(*) cnt - from customer_address a - ,customer c - ,store_sales s - ,date_dim d - ,item i - where a.ca_address_sk = c.c_current_addr_sk - and c.c_customer_sk = s.ss_customer_sk - and s.ss_sold_date_sk = d.d_date_sk - and s.ss_item_sk = i.i_item_sk - and d.d_month_seq = - (select distinct (d_month_seq) - from date_dim - where d_year = 1999 - and d_moy = 2 ) - and i.i_current_price > 1.2 * - (select avg(j.i_current_price) - from item j - where j.i_category = i.i_category) - group by a.ca_state - having count(*) >= 10 - order by cnt, a.ca_state - limit 100; - --- end template query6.tpl query 16 in stream 5 --- start template query49.tpl query 17 in stream 5 -select /* TPC-DS query49.tpl 0.48 */ channel, item, return_ratio, return_rank, currency_rank from - (select - 'web' as channel - ,web.item - ,web.return_ratio - ,web.return_rank - ,web.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select ws.ws_item_sk as item - ,(cast(sum(coalesce(wr.wr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(wr.wr_return_amt,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - web_sales ws left outer join web_returns wr - on (ws.ws_order_number = wr.wr_order_number and - ws.ws_item_sk = wr.wr_item_sk) - ,date_dim - where - wr.wr_return_amt > 10000 - and ws.ws_net_profit > 1 - and ws.ws_net_paid > 0 - and ws.ws_quantity > 0 - and ws_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 11 - group by ws.ws_item_sk - ) in_web - ) web - where - ( - web.return_rank <= 10 - or - web.currency_rank <= 10 - ) - union - select - 'catalog' as channel - ,catalog.item - ,catalog.return_ratio - ,catalog.return_rank - ,catalog.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select - cs.cs_item_sk as item - ,(cast(sum(coalesce(cr.cr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(cr.cr_return_amount,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - catalog_sales cs left outer join catalog_returns cr - on (cs.cs_order_number = cr.cr_order_number and - cs.cs_item_sk = cr.cr_item_sk) - ,date_dim - where - cr.cr_return_amount > 10000 - and cs.cs_net_profit > 1 - and cs.cs_net_paid > 0 - and cs.cs_quantity > 0 - and cs_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 11 - group by cs.cs_item_sk - ) in_cat - ) catalog - where - ( - catalog.return_rank <= 10 - or - catalog.currency_rank <=10 - ) - union - select - 'store' as channel - ,store.item - ,store.return_ratio - ,store.return_rank - ,store.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select sts.ss_item_sk as item - ,(cast(sum(coalesce(sr.sr_return_quantity,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(sr.sr_return_amt,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - store_sales sts left outer join store_returns sr - on (sts.ss_ticket_number = sr.sr_ticket_number and sts.ss_item_sk = sr.sr_item_sk) - ,date_dim - where - sr.sr_return_amt > 10000 - and sts.ss_net_profit > 1 - and sts.ss_net_paid > 0 - and sts.ss_quantity > 0 - and ss_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 11 - group by sts.ss_item_sk - ) in_store - ) store - where ( - store.return_rank <= 10 - or - store.currency_rank <= 10 - ) - ) - order by 1,4,5,2 - limit 100; - --- end template query49.tpl query 17 in stream 5 --- start template query52.tpl query 18 in stream 5 -select /* TPC-DS query52.tpl 0.59 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_sales_price) ext_price - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=11 - and dt.d_year=2000 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,ext_price desc - ,brand_id -limit 100 ; - --- end template query52.tpl query 18 in stream 5 --- start template query7.tpl query 19 in stream 5 -select /* TPC-DS query7.tpl 0.2 */ i_item_id, - avg(ss_quantity) agg1, - avg(ss_list_price) agg2, - avg(ss_coupon_amt) agg3, - avg(ss_sales_price) agg4 - from store_sales, customer_demographics, date_dim, item, promotion - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_cdemo_sk = cd_demo_sk and - ss_promo_sk = p_promo_sk and - cd_gender = 'M' and - cd_marital_status = 'U' and - cd_education_status = 'Primary' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 2002 - group by i_item_id - order by i_item_id - limit 100; - --- end template query7.tpl query 19 in stream 5 --- start template query56.tpl query 20 in stream 5 -with /* TPC-DS query56.tpl 0.83 */ ss as ( - select i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where i_item_id in (select - i_item_id -from item -where i_color in ('navy','lawn','floral')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 4 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id), - cs as ( - select i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('navy','lawn','floral')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 4 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id), - ws as ( - select i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('navy','lawn','floral')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 4 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id) - select i_item_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by total_sales, - i_item_id - limit 100; - --- end template query56.tpl query 20 in stream 5 --- start template query36a.tpl query 21 in stream 5 -with /* TPC-DS query36a.tpl 0.21 */ results as - (select - sum(ss_net_profit) as ss_net_profit, sum(ss_ext_sales_price) as ss_ext_sales_price, - sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin - ,i_category - ,i_class - ,0 as g_category, 0 as g_class - from - store_sales - ,date_dim d1 - ,item - ,store - where - d1.d_year = 1998 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and s_state in ('SC','KS','NE','OK', - 'NM','WV','NM','MI') - group by i_category,i_class) - , - results_rollup as - (select gross_margin ,i_category ,i_class,0 as t_category, 0 as t_class, 0 as lochierarchy from results - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - i_category, NULL AS i_class, 0 as t_category, 1 as t_class, 1 as lochierarchy from results group by i_category - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - NULL AS i_category ,NULL AS i_class, 1 as t_category, 1 as t_class, 2 as lochierarchy from results) - select - gross_margin ,i_category ,i_class, lochierarchy,rank() over ( - partition by lochierarchy, case when t_class = 0 then i_category end - order by gross_margin asc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then i_category end - ,rank_within_parent - limit 100; - --- end template query36a.tpl query 21 in stream 5 --- start template query77a.tpl query 22 in stream 5 -with /* TPC-DS query77a.tpl 0.78 */ ss as - (select s_store_sk, - sum(ss_ext_sales_price) as sales, - sum(ss_net_profit) as profit - from store_sales, - date_dim, - store - where ss_sold_date_sk = d_date_sk - and d_date between cast('1998-08-09' as date) - and dateadd(day,30,cast('1998-08-09' as date)) - and ss_store_sk = s_store_sk - group by s_store_sk) - , - sr as - (select s_store_sk, - sum(sr_return_amt) as returns, - sum(sr_net_loss) as profit_loss - from store_returns, - date_dim, - store - where sr_returned_date_sk = d_date_sk - and d_date between cast('1998-08-09' as date) - and dateadd(day,30,cast('1998-08-09' as date)) - and sr_store_sk = s_store_sk - group by s_store_sk), - cs as - (select cs_call_center_sk, - sum(cs_ext_sales_price) as sales, - sum(cs_net_profit) as profit - from catalog_sales, - date_dim - where cs_sold_date_sk = d_date_sk - and d_date between cast('1998-08-09' as date) - and dateadd(day,30,cast('1998-08-09' as date)) - group by cs_call_center_sk - ), - cr as - (select cr_call_center_sk, - sum(cr_return_amount) as returns, - sum(cr_net_loss) as profit_loss - from catalog_returns, - date_dim - where cr_returned_date_sk = d_date_sk - and d_date between cast('1998-08-09' as date) - and dateadd(day,30,cast('1998-08-09' as date)) - group by cr_call_center_sk), - ws as - ( select wp_web_page_sk, - sum(ws_ext_sales_price) as sales, - sum(ws_net_profit) as profit - from web_sales, - date_dim, - web_page - where ws_sold_date_sk = d_date_sk - and d_date between cast('1998-08-09' as date) - and dateadd(day,30,cast('1998-08-09' as date)) - and ws_web_page_sk = wp_web_page_sk - group by wp_web_page_sk), - wr as - (select wp_web_page_sk, - sum(wr_return_amt) as returns, - sum(wr_net_loss) as profit_loss - from web_returns, - date_dim, - web_page - where wr_returned_date_sk = d_date_sk - and d_date between cast('1998-08-09' as date) - and dateadd(day,30,cast('1998-08-09' as date)) - and wr_web_page_sk = wp_web_page_sk - group by wp_web_page_sk) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , ss.s_store_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ss left join sr - on ss.s_store_sk = sr.s_store_sk - union all - select 'catalog channel' as channel - , cs_call_center_sk as id - , sales - , returns - , (profit - profit_loss) as profit - from cs - , cr - union all - select 'web channel' as channel - , ws.wp_web_page_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ws left join wr - on ws.wp_web_page_sk = wr.wp_web_page_sk - ) x - group by channel, id ) - - select * - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results -) foo -order by channel, id - limit 100; - --- end template query77a.tpl query 22 in stream 5 --- start template query90.tpl query 23 in stream 5 -select /* TPC-DS query90.tpl 0.40 */ cast(amc as decimal(15,4))/cast(pmc as decimal(15,4)) am_pm_ratio - from ( select count(*) amc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 12 and 12+1 - and household_demographics.hd_dep_count = 7 - and web_page.wp_char_count between 5000 and 5200) at, - ( select count(*) pmc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 21 and 21+1 - and household_demographics.hd_dep_count = 7 - and web_page.wp_char_count between 5000 and 5200) pt - order by am_pm_ratio - limit 100; - --- end template query90.tpl query 23 in stream 5 --- start template query76.tpl query 24 in stream 5 -select /* TPC-DS query76.tpl 0.99 */ channel, col_name, d_year, d_qoy, i_category, COUNT(*) sales_cnt, SUM(ext_sales_price) sales_amt FROM ( - SELECT 'store' as channel, 'ss_promo_sk' col_name, d_year, d_qoy, i_category, ss_ext_sales_price ext_sales_price - FROM store_sales, item, date_dim - WHERE ss_promo_sk IS NULL - AND ss_sold_date_sk=d_date_sk - AND ss_item_sk=i_item_sk - UNION ALL - SELECT 'web' as channel, 'ws_bill_hdemo_sk' col_name, d_year, d_qoy, i_category, ws_ext_sales_price ext_sales_price - FROM web_sales, item, date_dim - WHERE ws_bill_hdemo_sk IS NULL - AND ws_sold_date_sk=d_date_sk - AND ws_item_sk=i_item_sk - UNION ALL - SELECT 'catalog' as channel, 'cs_ship_hdemo_sk' col_name, d_year, d_qoy, i_category, cs_ext_sales_price ext_sales_price - FROM catalog_sales, item, date_dim - WHERE cs_ship_hdemo_sk IS NULL - AND cs_sold_date_sk=d_date_sk - AND cs_item_sk=i_item_sk) foo -GROUP BY channel, col_name, d_year, d_qoy, i_category -ORDER BY channel, col_name, d_year, d_qoy, i_category -limit 100; - --- end template query76.tpl query 24 in stream 5 --- start template query58.tpl query 25 in stream 5 -with /* TPC-DS query58.tpl 0.19 */ ss_items as - (select i_item_id item_id - ,sum(ss_ext_sales_price) ss_item_rev - from store_sales - ,item - ,date_dim - where ss_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '1999-03-17')) - and ss_sold_date_sk = d_date_sk - group by i_item_id), - cs_items as - (select i_item_id item_id - ,sum(cs_ext_sales_price) cs_item_rev - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '1999-03-17')) - and cs_sold_date_sk = d_date_sk - group by i_item_id), - ws_items as - (select i_item_id item_id - ,sum(ws_ext_sales_price) ws_item_rev - from web_sales - ,item - ,date_dim - where ws_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq =(select d_week_seq - from date_dim - where d_date = '1999-03-17')) - and ws_sold_date_sk = d_date_sk - group by i_item_id) - select ss_items.item_id - ,ss_item_rev - ,ss_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ss_dev - ,cs_item_rev - ,cs_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 cs_dev - ,ws_item_rev - ,ws_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ws_dev - ,(ss_item_rev+cs_item_rev+ws_item_rev)/3 average - from ss_items,cs_items,ws_items - where ss_items.item_id=cs_items.item_id - and ss_items.item_id=ws_items.item_id - and ss_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - and ss_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and cs_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and cs_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and ws_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and ws_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - order by item_id - ,ss_item_rev - limit 100; - --- end template query58.tpl query 25 in stream 5 --- start template query71.tpl query 26 in stream 5 -select /* TPC-DS query71.tpl 0.72 */ i_brand_id brand_id, i_brand brand,t_hour,t_minute, - sum(ext_price) ext_price - from item, (select ws_ext_sales_price as ext_price, - ws_sold_date_sk as sold_date_sk, - ws_item_sk as sold_item_sk, - ws_sold_time_sk as time_sk - from web_sales,date_dim - where d_date_sk = ws_sold_date_sk - and d_moy=11 - and d_year=1999 - union all - select cs_ext_sales_price as ext_price, - cs_sold_date_sk as sold_date_sk, - cs_item_sk as sold_item_sk, - cs_sold_time_sk as time_sk - from catalog_sales,date_dim - where d_date_sk = cs_sold_date_sk - and d_moy=11 - and d_year=1999 - union all - select ss_ext_sales_price as ext_price, - ss_sold_date_sk as sold_date_sk, - ss_item_sk as sold_item_sk, - ss_sold_time_sk as time_sk - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - and d_moy=11 - and d_year=1999 - ) tmp,time_dim - where - sold_item_sk = i_item_sk - and i_manager_id=1 - and time_sk = t_time_sk - and (t_meal_time = 'breakfast' or t_meal_time = 'dinner') - group by i_brand, i_brand_id,t_hour,t_minute - order by ext_price desc, i_brand_id - ; - --- end template query71.tpl query 26 in stream 5 --- start template query80a.tpl query 27 in stream 5 -with /* TPC-DS query80a.tpl 0.6 */ ssr as - (select s_store_id as store_id, - sum(ss_ext_sales_price) as sales, - sum(coalesce(sr_return_amt, 0)) as returns, - sum(ss_net_profit - coalesce(sr_net_loss, 0)) as profit - from store_sales left outer join store_returns on - (ss_item_sk = sr_item_sk and ss_ticket_number = sr_ticket_number), - date_dim, - store, - item, - promotion - where ss_sold_date_sk = d_date_sk - and d_date between cast('1999-08-04' as date) - and dateadd(day,30,cast('1999-08-04' as date)) - and ss_store_sk = s_store_sk - and ss_item_sk = i_item_sk - and i_current_price > 50 - and ss_promo_sk = p_promo_sk - and p_channel_tv = 'N' - group by s_store_id) - , - csr as - (select cp_catalog_page_id as catalog_page_id, - sum(cs_ext_sales_price) as sales, - sum(coalesce(cr_return_amount, 0)) as returns, - sum(cs_net_profit - coalesce(cr_net_loss, 0)) as profit - from catalog_sales left outer join catalog_returns on - (cs_item_sk = cr_item_sk and cs_order_number = cr_order_number), - date_dim, - catalog_page, - item, - promotion - where cs_sold_date_sk = d_date_sk - and d_date between cast('1999-08-04' as date) - and dateadd(day,30,cast('1999-08-04' as date)) - and cs_catalog_page_sk = cp_catalog_page_sk - and cs_item_sk = i_item_sk - and i_current_price > 50 - and cs_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(ws_ext_sales_price) as sales, - sum(coalesce(wr_return_amt, 0)) as returns, - sum(ws_net_profit - coalesce(wr_net_loss, 0)) as profit - from web_sales left outer join web_returns on - (ws_item_sk = wr_item_sk and ws_order_number = wr_order_number), - date_dim, - web_site, - item, - promotion - where ws_sold_date_sk = d_date_sk - and d_date between cast('1999-08-04' as date) - and dateadd(day,30,cast('1999-08-04' as date)) - and ws_web_site_sk = web_site_sk - and ws_item_sk = i_item_sk - and i_current_price > 50 - and ws_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by web_site_id) -, -results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || store_id as id - , sales - , returns - , profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || catalog_page_id as id - , sales - , returns - , profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , profit - from wsr - ) x - group by channel, id) - - select channel - , id - , sales - , returns - , profit - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results - ) foo - order by channel, id - limit 100; - --- end template query80a.tpl query 27 in stream 5 --- start template query69.tpl query 28 in stream 5 -select /* TPC-DS query69.tpl 0.28 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_state in ('MD','ND','VA') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 1 and 1+2) and - (not exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 1 and 1+2) and - not exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 1 and 1+2)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - limit 100; - --- end template query69.tpl query 28 in stream 5 --- start template query54.tpl query 29 in stream 5 -with /* TPC-DS query54.tpl 0.81 */ my_customers as ( - select distinct c_customer_sk - , c_current_addr_sk - from - ( select cs_sold_date_sk sold_date_sk, - cs_bill_customer_sk customer_sk, - cs_item_sk item_sk - from catalog_sales - union all - select ws_sold_date_sk sold_date_sk, - ws_bill_customer_sk customer_sk, - ws_item_sk item_sk - from web_sales - ) cs_or_ws_sales, - item, - date_dim, - customer - where sold_date_sk = d_date_sk - and item_sk = i_item_sk - and i_category = 'Children' - and i_class = 'infants' - and c_customer_sk = cs_or_ws_sales.customer_sk - and d_moy = 1 - and d_year = 1998 - ) - , my_revenue as ( - select c_customer_sk, - sum(ss_ext_sales_price) as revenue - from my_customers, - store_sales, - customer_address, - store, - date_dim - where c_current_addr_sk = ca_address_sk - and ca_county = s_county - and ca_state = s_state - and ss_sold_date_sk = d_date_sk - and c_customer_sk = ss_customer_sk - and d_month_seq between (select distinct d_month_seq+1 - from date_dim where d_year = 1998 and d_moy = 1) - and (select distinct d_month_seq+3 - from date_dim where d_year = 1998 and d_moy = 1) - group by c_customer_sk - ) - , segments as - (select cast((revenue/50) as bigint) as segment - from my_revenue - ) - select segment, count(*) as num_customers, segment*50 as segment_base - from segments - group by segment - order by segment, num_customers - limit 100; - --- end template query54.tpl query 29 in stream 5 --- start template query92.tpl query 30 in stream 5 -select /* TPC-DS query92.tpl 0.44 */ - sum(ws_ext_discount_amt) as "Excess Discount Amount" -from - web_sales - ,item - ,date_dim -where -i_manufact_id = 325 -and i_item_sk = ws_item_sk -and d_date between '2000-01-13' and - dateadd(day,90,cast('2000-01-13' as date)) -and d_date_sk = ws_sold_date_sk -and ws_ext_discount_amt - > ( - SELECT - 1.3 * avg(ws_ext_discount_amt) - FROM - web_sales - ,date_dim - WHERE - ws_item_sk = i_item_sk - and d_date between '2000-01-13' and - dateadd(day,90,cast('2000-01-13' as date)) - and d_date_sk = ws_sold_date_sk - ) -order by sum(ws_ext_discount_amt) -limit 100; - --- end template query92.tpl query 30 in stream 5 --- start template query61.tpl query 31 in stream 5 -select /* TPC-DS query61.tpl 0.97 */ promotions,total,cast(promotions as decimal(15,4))/cast(total as decimal(15,4))*100 -from - (select sum(ss_ext_sales_price) promotions - from store_sales - ,store - ,promotion - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_promo_sk = p_promo_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -7 - and i_category = 'Books' - and (p_channel_dmail = 'Y' or p_channel_email = 'Y' or p_channel_tv = 'Y') - and s_gmt_offset = -7 - and d_year = 2000 - and d_moy = 11) promotional_sales, - (select sum(ss_ext_sales_price) total - from store_sales - ,store - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -7 - and i_category = 'Books' - and s_gmt_offset = -7 - and d_year = 2000 - and d_moy = 11) all_sales -order by promotions, total -limit 100; - --- end template query61.tpl query 31 in stream 5 --- start template query53.tpl query 32 in stream 5 -select /* TPC-DS query53.tpl 0.88 */ * from -(select i_manufact_id, -sum(ss_sales_price) sum_sales, -avg(sum(ss_sales_price)) over (partition by i_manufact_id) avg_quarterly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and -ss_sold_date_sk = d_date_sk and -ss_store_sk = s_store_sk and -d_month_seq in (1181,1181+1,1181+2,1181+3,1181+4,1181+5,1181+6,1181+7,1181+8,1181+9,1181+10,1181+11) and -((i_category in ('Books','Children','Electronics') and -i_class in ('personal','portable','reference','self-help') and -i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) -or(i_category in ('Women','Music','Men') and -i_class in ('accessories','classical','fragrances','pants') and -i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manufact_id, d_qoy ) tmp1 -where case when avg_quarterly_sales > 0 - then abs (sum_sales - avg_quarterly_sales)/ avg_quarterly_sales - else null end > 0.1 -order by avg_quarterly_sales, - sum_sales, - i_manufact_id -limit 100; - --- end template query53.tpl query 32 in stream 5 --- start template query87.tpl query 33 in stream 5 -select /* TPC-DS query87.tpl 0.77 */ count(*) -from ((select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1184 and 1184+11) - except - (select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1184 and 1184+11) - except - (select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1184 and 1184+11) -) cool_cust -; - --- end template query87.tpl query 33 in stream 5 --- start template query68.tpl query 34 in stream 5 -select /* TPC-DS query68.tpl 0.95 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,extended_price - ,extended_tax - ,list_price - from (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_ext_sales_price) extended_price - ,sum(ss_ext_list_price) list_price - ,sum(ss_ext_tax) extended_tax - from store_sales - ,date_dim - ,store - ,household_demographics - ,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_dep_count = 6 or - household_demographics.hd_vehicle_count= 1) - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_city in ('Mount Olive','Germantown') - group by ss_ticket_number - ,ss_customer_sk - ,ss_addr_sk,ca_city) dn - ,customer - ,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,ss_ticket_number - limit 100; - --- end template query68.tpl query 34 in stream 5 --- start template query85.tpl query 35 in stream 5 -select /* TPC-DS query85.tpl 0.33 */ substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) - from web_sales, web_returns, web_page, customer_demographics cd1, - customer_demographics cd2, customer_address, date_dim, reason - where ws_web_page_sk = wp_web_page_sk - and ws_item_sk = wr_item_sk - and ws_order_number = wr_order_number - and ws_sold_date_sk = d_date_sk and d_year = 2001 - and cd1.cd_demo_sk = wr_refunded_cdemo_sk - and cd2.cd_demo_sk = wr_returning_cdemo_sk - and ca_address_sk = wr_refunded_addr_sk - and r_reason_sk = wr_reason_sk - and - ( - ( - cd1.cd_marital_status = 'U' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'College' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 100.00 and 150.00 - ) - or - ( - cd1.cd_marital_status = 'S' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Unknown' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 50.00 and 100.00 - ) - or - ( - cd1.cd_marital_status = 'M' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = '2 yr Degree' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ca_country = 'United States' - and - ca_state in ('AR', 'VA', 'KS') - and ws_net_profit between 100 and 200 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('NC', 'ND', 'MO') - and ws_net_profit between 150 and 300 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('SD', 'NY', 'ME') - and ws_net_profit between 50 and 250 - ) - ) -group by r_reason_desc -order by substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) -limit 100; - --- end template query85.tpl query 35 in stream 5 --- start template query28.tpl query 36 in stream 5 -select /* TPC-DS query28.tpl 0.36 */ * -from (select avg(ss_list_price) B1_LP - ,count(ss_list_price) B1_CNT - ,count(distinct ss_list_price) B1_CNTD - from store_sales - where ss_quantity between 0 and 5 - and (ss_list_price between 133 and 133+10 - or ss_coupon_amt between 471 and 471+1000 - or ss_wholesale_cost between 61 and 61+20)) B1, - (select avg(ss_list_price) B2_LP - ,count(ss_list_price) B2_CNT - ,count(distinct ss_list_price) B2_CNTD - from store_sales - where ss_quantity between 6 and 10 - and (ss_list_price between 144 and 144+10 - or ss_coupon_amt between 2647 and 2647+1000 - or ss_wholesale_cost between 59 and 59+20)) B2, - (select avg(ss_list_price) B3_LP - ,count(ss_list_price) B3_CNT - ,count(distinct ss_list_price) B3_CNTD - from store_sales - where ss_quantity between 11 and 15 - and (ss_list_price between 107 and 107+10 - or ss_coupon_amt between 4736 and 4736+1000 - or ss_wholesale_cost between 32 and 32+20)) B3, - (select avg(ss_list_price) B4_LP - ,count(ss_list_price) B4_CNT - ,count(distinct ss_list_price) B4_CNTD - from store_sales - where ss_quantity between 16 and 20 - and (ss_list_price between 162 and 162+10 - or ss_coupon_amt between 9673 and 9673+1000 - or ss_wholesale_cost between 6 and 6+20)) B4, - (select avg(ss_list_price) B5_LP - ,count(ss_list_price) B5_CNT - ,count(distinct ss_list_price) B5_CNTD - from store_sales - where ss_quantity between 21 and 25 - and (ss_list_price between 108 and 108+10 - or ss_coupon_amt between 6147 and 6147+1000 - or ss_wholesale_cost between 13 and 13+20)) B5, - (select avg(ss_list_price) B6_LP - ,count(ss_list_price) B6_CNT - ,count(distinct ss_list_price) B6_CNTD - from store_sales - where ss_quantity between 26 and 30 - and (ss_list_price between 122 and 122+10 - or ss_coupon_amt between 2686 and 2686+1000 - or ss_wholesale_cost between 51 and 51+20)) B6 -limit 100; - --- end template query28.tpl query 36 in stream 5 --- start template query42.tpl query 37 in stream 5 -select /* TPC-DS query42.tpl 0.61 */ dt.d_year - ,item.i_category_id - ,item.i_category - ,sum(ss_ext_sales_price) - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=12 - and dt.d_year=2002 - group by dt.d_year - ,item.i_category_id - ,item.i_category - order by sum(ss_ext_sales_price) desc,dt.d_year - ,item.i_category_id - ,item.i_category -limit 100 ; - --- end template query42.tpl query 37 in stream 5 --- start template query67a.tpl query 38 in stream 5 -with /* TPC-DS query67a.tpl 0.35 */ results as -( select i_category ,i_class ,i_brand ,i_product_name ,d_year ,d_qoy ,d_moy ,s_store_id - ,sum(coalesce(ss_sales_price*ss_quantity,0)) sumsales - from store_sales ,date_dim ,store ,item - where ss_sold_date_sk=d_date_sk - and ss_item_sk=i_item_sk - and ss_store_sk = s_store_sk - and d_month_seq between 1188 and 1188 + 11 - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy,s_store_id) - , - results_rollup as - (select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, s_store_id, sumsales - from results - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy - union all - select i_category, i_class, i_brand, i_product_name, d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year - union all - select i_category, i_class, i_brand, i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name - union all - select i_category, i_class, i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand - union all - select i_category, i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class - union all - select i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category - union all - select null i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results) - - select * -from (select i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rank() over (partition by i_category order by sumsales desc) rk - from results_rollup) dw2 -where rk <= 100 -order by i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rk -limit 100; - --- end template query67a.tpl query 38 in stream 5 --- start template query50.tpl query 39 in stream 5 -select /* TPC-DS query50.tpl 0.60 */ - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 30) and - (sr_returned_date_sk - ss_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 60) and - (sr_returned_date_sk - ss_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 90) and - (sr_returned_date_sk - ss_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - store_sales - ,store_returns - ,store - ,date_dim d1 - ,date_dim d2 -where - d2.d_year = 2002 -and d2.d_moy = 9 -and ss_ticket_number = sr_ticket_number -and ss_item_sk = sr_item_sk -and ss_sold_date_sk = d1.d_date_sk -and sr_returned_date_sk = d2.d_date_sk -and ss_customer_sk = sr_customer_sk -and ss_store_sk = s_store_sk -group by - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -order by s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -limit 100; - --- end template query50.tpl query 39 in stream 5 --- start template query30.tpl query 40 in stream 5 -with /* TPC-DS query30.tpl 0.75 */ customer_total_return as - (select wr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(wr_return_amt) as ctr_total_return - from web_returns - ,date_dim - ,customer_address - where wr_returned_date_sk = d_date_sk - and d_year =2002 - and wr_returning_addr_sk = ca_address_sk - group by wr_returning_customer_sk - ,ca_state) - select c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'WV' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return -limit 100; - --- end template query30.tpl query 40 in stream 5 --- start template query48.tpl query 41 in stream 5 -select /* TPC-DS query48.tpl 0.74 */ sum (ss_quantity) - from store_sales, store, customer_demographics, customer_address, date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2002 - and - ( - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'D' - and - cd_education_status = 'Primary' - and - ss_sales_price between 100.00 and 150.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'S' - and - cd_education_status = '2 yr Degree' - and - ss_sales_price between 50.00 and 100.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'M' - and - cd_education_status = 'Unknown' - and - ss_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('ND', 'KY', 'CA') - and ss_net_profit between 0 and 2000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('NY', 'MT', 'NC') - and ss_net_profit between 150 and 3000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('IN', 'TX', 'WV') - and ss_net_profit between 50 and 25000 - ) - ) -; - --- end template query48.tpl query 41 in stream 5 --- start template query22a.tpl query 42 in stream 5 -with /* TPC-DS query22a.tpl 0.55 */ results as -(select i_product_name - ,i_brand - ,i_class - ,i_category - ,avg(inv_quantity_on_hand) qoh - from inventory - ,date_dim - ,item --- ,warehouse - where inv_date_sk=d_date_sk - and inv_item_sk=i_item_sk --- and inv_warehouse_sk = w_warehouse_sk - and d_month_seq between 1202 and 1202 + 11 - group by i_product_name,i_brand,i_class,i_category), -results_rollup as -(select i_product_name, i_brand, i_class, i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class,i_category -union all -select i_product_name, i_brand, i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class -union all -select i_product_name, i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand -union all -select i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name -union all -select null i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results) - select i_product_name, i_brand, i_class, i_category,qoh - from results_rollup - order by qoh, i_product_name, i_brand, i_class, i_category -limit 100; - --- end template query22a.tpl query 42 in stream 5 --- start template query11.tpl query 43 in stream 5 -with /* TPC-DS query11.tpl 0.51 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ss_ext_list_price-ss_ext_discount_amt) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ws_ext_list_price-ws_ext_discount_amt) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_preferred_cust_flag - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 1999 - and t_s_secyear.dyear = 1999+1 - and t_w_firstyear.dyear = 1999 - and t_w_secyear.dyear = 1999+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else 0.0 end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else 0.0 end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_preferred_cust_flag -limit 100; - --- end template query11.tpl query 43 in stream 5 --- start template query94.tpl query 44 in stream 5 -select /* TPC-DS query94.tpl 0.17 */ - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2002-2-01' and - dateadd(day,60,cast('2002-2-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'TX' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and exists (select * - from web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) -and not exists(select * - from web_returns wr1 - where ws1.ws_order_number = wr1.wr_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query94.tpl query 44 in stream 5 --- start template query93.tpl query 45 in stream 5 -select /* TPC-DS query93.tpl 0.52 */ ss_customer_sk - ,sum(act_sales) sumsales - from (select ss_item_sk - ,ss_ticket_number - ,ss_customer_sk - ,case when sr_return_quantity is not null then (ss_quantity-sr_return_quantity)*ss_sales_price - else (ss_quantity*ss_sales_price) end act_sales - from store_sales left outer join store_returns on (sr_item_sk = ss_item_sk - and sr_ticket_number = ss_ticket_number) - ,reason - where sr_reason_sk = r_reason_sk - and r_reason_desc = 'reason 74') t - group by ss_customer_sk - order by sumsales, ss_customer_sk -limit 100; - --- end template query93.tpl query 45 in stream 5 --- start template query18a.tpl query 46 in stream 5 -with /* TPC-DS query18a.tpl 0.90 */ results as - (select i_item_id, - ca_country, - ca_state, - ca_county, - cast(cs_quantity as decimal(12,2)) agg1, - cast(cs_list_price as decimal(12,2)) agg2, - cast(cs_coupon_amt as decimal(12,2)) agg3, - cast(cs_sales_price as decimal(12,2)) agg4, - cast(cs_net_profit as decimal(12,2)) agg5, - cast(c_birth_year as decimal(12,2)) agg6, - cast(cd1.cd_dep_count as decimal(12,2)) agg7 - from catalog_sales, customer_demographics cd1, customer_demographics cd2, customer, customer_address, date_dim, item - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd1.cd_demo_sk and - cs_bill_customer_sk = c_customer_sk and - cd1.cd_gender = 'M' and - cd1.cd_education_status = '4 yr Degree' and - c_current_cdemo_sk = cd2.cd_demo_sk and - c_current_addr_sk = ca_address_sk and - c_birth_month in (2,3,9,7,4,10) and - d_year = 1998 and - ca_state in ('UT','MD','KY','OH','IL','MT','MS') - ) - select i_item_id, ca_country, ca_state, ca_county, agg1, agg2, agg3, agg4, agg5, agg6, agg7 - from ( - select i_item_id, ca_country, ca_state, ca_county, avg(agg1) agg1, - avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state, ca_county - union all - select i_item_id, ca_country, ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state - union all - select i_item_id, ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country - union all - select i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - ) foo - order by ca_country, ca_state, ca_county, i_item_id - limit 100; - --- end template query18a.tpl query 46 in stream 5 --- start template query33.tpl query 47 in stream 5 -with /* TPC-DS query33.tpl 0.22 */ ss as ( - select - i_manufact_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Sports')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 1 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id), - cs as ( - select - i_manufact_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Sports')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 1 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id), - ws as ( - select - i_manufact_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Sports')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 1 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id) - select i_manufact_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_manufact_id - order by total_sales -limit 100; - --- end template query33.tpl query 47 in stream 5 --- start template query63.tpl query 48 in stream 5 -select /* TPC-DS query63.tpl 0.27 */ * -from (select i_manager_id - ,sum(ss_sales_price) sum_sales - ,avg(sum(ss_sales_price)) over (partition by i_manager_id) avg_monthly_sales - from item - ,store_sales - ,date_dim - ,store - where ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and d_month_seq in (1199,1199+1,1199+2,1199+3,1199+4,1199+5,1199+6,1199+7,1199+8,1199+9,1199+10,1199+11) - and (( i_category in ('Books','Children','Electronics') - and i_class in ('personal','portable','reference','self-help') - and i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) - or( i_category in ('Women','Music','Men') - and i_class in ('accessories','classical','fragrances','pants') - and i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manager_id, d_moy) tmp1 -where case when avg_monthly_sales > 0 then abs (sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 -order by i_manager_id - ,avg_monthly_sales - ,sum_sales -limit 100; - --- end template query63.tpl query 48 in stream 5 --- start template query8.tpl query 49 in stream 5 -select /* TPC-DS query8.tpl 0.63 */ s_store_name - ,sum(ss_net_profit) - from store_sales - ,date_dim - ,store, - (select ca_zip - from ( - SELECT substring(ca_zip,1,5) ca_zip - FROM customer_address - WHERE substring(ca_zip,1,5) IN ( - '98392','82936','87075','79535','45723','73264', - '40084','89676','11702','78704','72461', - '94531','17853','43507','55909','19526', - '72416','55875','22362','55303','28767', - '88269','69318','51924','49899','19562', - '94626','92582','55567','49081','41399', - '22809','67715','66319','18505','44268', - '94010','73413','83522','94752','18079', - '96565','98382','10036','29897','77136', - '22239','34433','31957','57348','36396', - '44803','43245','13679','42038','28859', - '51746','26138','67637','25427','60122', - '52604','74035','10922','39786','29111', - '67464','48631','91063','20827','77713', - '24614','34953','36547','20353','98173', - '93142','83682','82144','72837','91179', - '49607','67630','68192','40204','72593', - '93879','89341','83001','25808','92213', - '27344','86715','33949','17796','50014', - '94823','61821','61083','19905','37742', - '51931','31683','25651','51317','87513', - '57450','91935','49819','13518','26879', - '54560','75291','37715','13467','24629', - '91952','44777','45283','59391','69825', - '11806','64157','90682','55054','29571', - '93026','23146','86322','60112','48176', - '52415','11184','11375','21852','76306', - '78369','77499','30204','43393','44993', - '60750','66225','74962','43615','10914', - '33536','64260','42235','23071','82760', - '33204','57633','72243','82702','76131', - '71169','78648','91057','56882','29230', - '62167','71669','24631','85746','50221', - '76896','89114','72875','71158','71572', - '67345','15784','38423','86606','47924', - '78868','50516','25811','37395','81240', - '84410','44730','79990','27540','18631', - '89518','35119','69649','99586','65061', - '90334','16299','29675','35590','57165', - '90552','29431','86542','70606','91240', - '88508','22356','82577','21358','45246', - '64562','43586','35220','51792','50692', - '91059','49965','30478','53414','21602', - '48624','18119','22439','73129','80580', - '50898','83323','43016','56561','60587', - '57422','61916','89152','23533','20070', - '97542','96085','19487','63536','38645', - '48536','76593','16279','30313','70894', - '43369','27222','42826','13537','89726', - '61950','64389','34697','47921','19346', - '75990','84700','51618','52981','92914', - '95280','14085','70711','73134','55399', - '19236','72841','45373','56752','68245', - '36595','25858','63134','81232','42005', - '16917','44283','51379','17862','88090', - '82688','85973','22220','66084','67700', - '88934','78743','49104','42341','19904', - '75703','57076','24499','92712','95617', - '39971','77452','60052','33410','73616', - '80816','55190','98112','37305','95332', - '15047','50241','78547','15454','91680', - '49827','66933','19656','81833','57669', - '20928','12555','11032','84955','50919', - '70462','18851','26445','31337','19509', - '77667','37479','83334','29743','68832', - '36158','20758','67331','17932','51511', - '26378','61986','73292','32978','93408', - '28748','38927','99609','10594','36425', - '86308','44324','18018','54408','24199', - '68487','71886','96096','18305','21646', - '40901','79985','83966','22301','45106', - '44273','65900','71890','55884','60472', - '34297','79377','99171','43091','31104', - '78932','15110','18408','79986','76275', - '25031','21950','90370','97383','13926', - '43787','15117','97138','41422','83151', - '72434','10894','20934','55450','38318', - '37246','26522','69683','12399','78028', - '65298','44688','38649','87291','26035', - '12372','66359','78444','54440') - intersect - select ca_zip - from (SELECT substring(ca_zip,1,5) ca_zip,count(*) cnt - FROM customer_address, customer - WHERE ca_address_sk = c_current_addr_sk and - c_preferred_cust_flag='Y' - group by ca_zip - having count(*) > 10)A1)A2) V1 - where ss_store_sk = s_store_sk - and ss_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 2000 - and (substring(s_zip,1,2) = substring(V1.ca_zip,1,2)) - group by s_store_name - order by s_store_name - limit 100; - --- end template query8.tpl query 49 in stream 5 --- start template query97.tpl query 50 in stream 5 -with /* TPC-DS query97.tpl 0.38 */ ssci as ( -select ss_customer_sk customer_sk - ,ss_item_sk item_sk -from store_sales,date_dim -where ss_sold_date_sk = d_date_sk - and d_month_seq between 1197 and 1197 + 11 -group by ss_customer_sk - ,ss_item_sk), -csci as( - select cs_bill_customer_sk customer_sk - ,cs_item_sk item_sk -from catalog_sales,date_dim -where cs_sold_date_sk = d_date_sk - and d_month_seq between 1197 and 1197 + 11 -group by cs_bill_customer_sk - ,cs_item_sk) - select sum(case when ssci.customer_sk is not null and csci.customer_sk is null then 1 else 0 end) store_only - ,sum(case when ssci.customer_sk is null and csci.customer_sk is not null then 1 else 0 end) catalog_only - ,sum(case when ssci.customer_sk is not null and csci.customer_sk is not null then 1 else 0 end) store_and_catalog -from ssci full outer join csci on (ssci.customer_sk=csci.customer_sk - and ssci.item_sk = csci.item_sk) -limit 100; - --- end template query97.tpl query 50 in stream 5 --- start template query45.tpl query 51 in stream 5 -select /* TPC-DS query45.tpl 0.18 */ ca_zip, ca_city, sum(ws_sales_price) - from web_sales, customer, customer_address, date_dim, item - where ws_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ws_item_sk = i_item_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', '85392', '85460', '80348', '81792') - or - i_item_id in (select i_item_id - from item - where i_item_sk in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29) - ) - ) - and ws_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 1999 - group by ca_zip, ca_city - order by ca_zip, ca_city - limit 100; - --- end template query45.tpl query 51 in stream 5 --- start template query62.tpl query 52 in stream 5 -select /* TPC-DS query62.tpl 0.24 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 30) and - (ws_ship_date_sk - ws_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 60) and - (ws_ship_date_sk - ws_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 90) and - (ws_ship_date_sk - ws_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - web_sales - ,warehouse - ,ship_mode - ,web_site - ,date_dim -where - d_month_seq between 1189 and 1189 + 11 -and ws_ship_date_sk = d_date_sk -and ws_warehouse_sk = w_warehouse_sk -and ws_ship_mode_sk = sm_ship_mode_sk -and ws_web_site_sk = web_site_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -limit 100; - --- end template query62.tpl query 52 in stream 5 --- start template query81.tpl query 53 in stream 5 -with /* TPC-DS query81.tpl 0.37 */ customer_total_return as - (select cr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(cr_return_amt_inc_tax) as ctr_total_return - from catalog_returns - ,date_dim - ,customer_address - where cr_returned_date_sk = d_date_sk - and d_year =1999 - and cr_returning_addr_sk = ca_address_sk - group by cr_returning_customer_sk - ,ca_state ) - select c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'LA' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - limit 100; - --- end template query81.tpl query 53 in stream 5 --- start template query35a.tpl query 54 in stream 5 -select /* TPC-DS query35a.tpl 0.47 */ - ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - count(*) cnt1, - sum(cd_dep_count), - stddev_samp(cd_dep_count), - avg(cd_dep_count), - cd_dep_employed_count, - count(*) cnt2, - sum(cd_dep_employed_count), - stddev_samp(cd_dep_employed_count), - avg(cd_dep_employed_count), - cd_dep_college_count, - count(*) cnt3, - sum(cd_dep_college_count), - stddev_samp(cd_dep_college_count), - avg(cd_dep_college_count) - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 1999 and - d_qoy < 4) and - exists (select * from - (select ws_bill_customer_sk customsk - from web_sales,date_dim - where - ws_sold_date_sk = d_date_sk and - d_year = 1999 and - d_qoy < 4 - union all - select cs_ship_customer_sk customsk - from catalog_sales,date_dim - where - cs_sold_date_sk = d_date_sk and - d_year = 1999 and - d_qoy < 4)x - where x.customsk = c.c_customer_sk) - group by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - limit 100; - --- end template query35a.tpl query 54 in stream 5 --- start template query78.tpl query 55 in stream 5 -with /* TPC-DS query78.tpl 0.10 */ ws as - (select d_year AS ws_sold_year, ws_item_sk, - ws_bill_customer_sk ws_customer_sk, - sum(ws_quantity) ws_qty, - sum(ws_wholesale_cost) ws_wc, - sum(ws_sales_price) ws_sp - from web_sales - left join web_returns on wr_order_number=ws_order_number and ws_item_sk=wr_item_sk - join date_dim on ws_sold_date_sk = d_date_sk - where wr_order_number is null - group by d_year, ws_item_sk, ws_bill_customer_sk - ), -cs as - (select d_year AS cs_sold_year, cs_item_sk, - cs_bill_customer_sk cs_customer_sk, - sum(cs_quantity) cs_qty, - sum(cs_wholesale_cost) cs_wc, - sum(cs_sales_price) cs_sp - from catalog_sales - left join catalog_returns on cr_order_number=cs_order_number and cs_item_sk=cr_item_sk - join date_dim on cs_sold_date_sk = d_date_sk - where cr_order_number is null - group by d_year, cs_item_sk, cs_bill_customer_sk - ), -ss as - (select d_year AS ss_sold_year, ss_item_sk, - ss_customer_sk, - sum(ss_quantity) ss_qty, - sum(ss_wholesale_cost) ss_wc, - sum(ss_sales_price) ss_sp - from store_sales - left join store_returns on sr_ticket_number=ss_ticket_number and ss_item_sk=sr_item_sk - join date_dim on ss_sold_date_sk = d_date_sk - where sr_ticket_number is null - group by d_year, ss_item_sk, ss_customer_sk - ) - select -ss_item_sk, -round(ss_qty/(coalesce(ws_qty,0)+coalesce(cs_qty,0)),2) ratio, -ss_qty store_qty, ss_wc store_wholesale_cost, ss_sp store_sales_price, -coalesce(ws_qty,0)+coalesce(cs_qty,0) other_chan_qty, -coalesce(ws_wc,0)+coalesce(cs_wc,0) other_chan_wholesale_cost, -coalesce(ws_sp,0)+coalesce(cs_sp,0) other_chan_sales_price -from ss -left join ws on (ws_sold_year=ss_sold_year and ws_item_sk=ss_item_sk and ws_customer_sk=ss_customer_sk) -left join cs on (cs_sold_year=ss_sold_year and cs_item_sk=ss_item_sk and cs_customer_sk=ss_customer_sk) -where (coalesce(ws_qty,0)>0 or coalesce(cs_qty, 0)>0) and ss_sold_year=2000 -order by - ss_item_sk, - ss_qty desc, ss_wc desc, ss_sp desc, - other_chan_qty, - other_chan_wholesale_cost, - other_chan_sales_price, - ratio -limit 100; - --- end template query78.tpl query 55 in stream 5 --- start template query57.tpl query 56 in stream 5 -with /* TPC-DS query57.tpl 0.70 */ v1 as( - select i_category, i_brand, - cc_name, - d_year, d_moy, - sum(cs_sales_price) sum_sales, - avg(sum(cs_sales_price)) over - (partition by i_category, i_brand, - cc_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - cc_name - order by d_year, d_moy) rn - from item, catalog_sales, date_dim, call_center - where cs_item_sk = i_item_sk and - cs_sold_date_sk = d_date_sk and - cc_call_center_sk= cs_call_center_sk and - ( - d_year = 2000 or - ( d_year = 2000-1 and d_moy =12) or - ( d_year = 2000+1 and d_moy =1) - ) - group by i_category, i_brand, - cc_name , d_year, d_moy), - v2 as( - select v1.i_category - ,v1.d_year, v1.d_moy - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1. cc_name = v1_lag. cc_name and - v1. cc_name = v1_lead. cc_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 2000 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, nsum - limit 100; - --- end template query57.tpl query 56 in stream 5 --- start template query46.tpl query 57 in stream 5 -select /* TPC-DS query46.tpl 0.23 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and (household_demographics.hd_dep_count = 4 or - household_demographics.hd_vehicle_count= 0) - and date_dim.d_dow in (6,0) - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_city in ('Clayton','Sharon','Oxford','Fairview','Smithville') - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,ca_city) dn,customer,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - limit 100; - --- end template query46.tpl query 57 in stream 5 --- start template query32.tpl query 58 in stream 5 -select /* TPC-DS query32.tpl 0.7 */ sum(cs_ext_discount_amt) as "excess discount amount" -from - catalog_sales - ,item - ,date_dim -where -i_manufact_id = 223 -and i_item_sk = cs_item_sk -and d_date between '2001-02-17' and - dateadd(day,90,cast('2001-02-17' as date)) -and d_date_sk = cs_sold_date_sk -and cs_ext_discount_amt - > ( - select - 1.3 * avg(cs_ext_discount_amt) - from - catalog_sales - ,date_dim - where - cs_item_sk = i_item_sk - and d_date between '2001-02-17' and - dateadd(day,90,cast('2001-02-17' as date)) - and d_date_sk = cs_sold_date_sk - ) -limit 100; - --- end template query32.tpl query 58 in stream 5 --- start template query24.tpl query 59 in stream 5 -with /* TPC-DS query24.tpl 0.92 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_net_paid_inc_tax) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip -and s_market_id=8 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'pink' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; -with /* TPC-DS query24.tpl 0.92 part2 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_net_paid_inc_tax) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip - and s_market_id = 8 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'seashell' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; - --- end template query24.tpl query 59 in stream 5 --- start template query38.tpl query 60 in stream 5 -select /* TPC-DS query38.tpl 0.54 */ count(*) from ( - select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1181 and 1181 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1181 and 1181 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1181 and 1181 + 11 -) hot_cust -limit 100; - --- end template query38.tpl query 60 in stream 5 --- start template query55.tpl query 61 in stream 5 -select /* TPC-DS query55.tpl 0.82 */ i_brand_id brand_id, i_brand brand, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=98 - and d_moy=11 - and d_year=1999 - group by i_brand, i_brand_id - order by ext_price desc, i_brand_id -limit 100 ; - --- end template query55.tpl query 61 in stream 5 --- start template query74.tpl query 62 in stream 5 -with /* TPC-DS query74.tpl 0.76 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,sum(ss_net_paid) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (2001,2001+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,sum(ws_net_paid) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - and d_year in (2001,2001+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - ) - select - t_s_secyear.customer_id, t_s_secyear.customer_first_name, t_s_secyear.customer_last_name - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.year = 2001 - and t_s_secyear.year = 2001+1 - and t_w_firstyear.year = 2001 - and t_w_secyear.year = 2001+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - order by 1,3,2 -limit 100; - --- end template query74.tpl query 62 in stream 5 --- start template query84.tpl query 63 in stream 5 -select /* TPC-DS query84.tpl 0.80 */ c_customer_id as customer_id - , coalesce(c_last_name,'') || ', ' || coalesce(c_first_name,'') as customername - from customer - ,customer_address - ,customer_demographics - ,household_demographics - ,income_band - ,store_returns - where ca_city = 'Jamestown' - and c_current_addr_sk = ca_address_sk - and ib_lower_bound >= 61969 - and ib_upper_bound <= 61969 + 50000 - and ib_income_band_sk = hd_income_band_sk - and cd_demo_sk = c_current_cdemo_sk - and hd_demo_sk = c_current_hdemo_sk - and sr_cdemo_sk = cd_demo_sk - order by c_customer_id - limit 100; - --- end template query84.tpl query 63 in stream 5 --- start template query89.tpl query 64 in stream 5 -select /* TPC-DS query89.tpl 0.56 */ * -from( -select i_category, i_class, i_brand, - s_store_name, s_company_name, - d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, s_store_name, s_company_name) - avg_monthly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - d_year in (2002) and - ((i_category in ('Women','Jewelry','Men') and - i_class in ('dresses','womens watch','shirts') - ) - or (i_category in ('Books','Music','Electronics') and - i_class in ('travel','pop','dvd/vcr players') - )) -group by i_category, i_class, i_brand, - s_store_name, s_company_name, d_moy) tmp1 -where case when (avg_monthly_sales <> 0) then (abs(sum_sales - avg_monthly_sales) / avg_monthly_sales) else null end > 0.1 -order by sum_sales - avg_monthly_sales, s_store_name -limit 100; - --- end template query89.tpl query 64 in stream 5 --- start template query83.tpl query 65 in stream 5 -with /* TPC-DS query83.tpl 0.96 */ sr_items as - (select i_item_id item_id, - sum(sr_return_quantity) sr_item_qty - from store_returns, - item, - date_dim - where sr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('1998-03-15','1998-10-02','1998-11-08'))) - and sr_returned_date_sk = d_date_sk - group by i_item_id), - cr_items as - (select i_item_id item_id, - sum(cr_return_quantity) cr_item_qty - from catalog_returns, - item, - date_dim - where cr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('1998-03-15','1998-10-02','1998-11-08'))) - and cr_returned_date_sk = d_date_sk - group by i_item_id), - wr_items as - (select i_item_id item_id, - sum(wr_return_quantity) wr_item_qty - from web_returns, - item, - date_dim - where wr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('1998-03-15','1998-10-02','1998-11-08'))) - and wr_returned_date_sk = d_date_sk - group by i_item_id) - select sr_items.item_id - ,sr_item_qty - ,sr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 sr_dev - ,cr_item_qty - ,cr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 cr_dev - ,wr_item_qty - ,wr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 wr_dev - ,(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 average - from sr_items - ,cr_items - ,wr_items - where sr_items.item_id=cr_items.item_id - and sr_items.item_id=wr_items.item_id - order by sr_items.item_id - ,sr_item_qty - limit 100; - --- end template query83.tpl query 65 in stream 5 --- start template query31.tpl query 66 in stream 5 -with /* TPC-DS query31.tpl 0.50 */ ss as - (select ca_county,d_qoy, d_year,sum(ss_ext_sales_price) as store_sales - from store_sales,date_dim,customer_address - where ss_sold_date_sk = d_date_sk - and ss_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year), - ws as - (select ca_county,d_qoy, d_year,sum(ws_ext_sales_price) as web_sales - from web_sales,date_dim,customer_address - where ws_sold_date_sk = d_date_sk - and ws_bill_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year) - select - ss1.ca_county - ,ss1.d_year - ,ws2.web_sales/ws1.web_sales web_q1_q2_increase - ,ss2.store_sales/ss1.store_sales store_q1_q2_increase - ,ws3.web_sales/ws2.web_sales web_q2_q3_increase - ,ss3.store_sales/ss2.store_sales store_q2_q3_increase - from - ss ss1 - ,ss ss2 - ,ss ss3 - ,ws ws1 - ,ws ws2 - ,ws ws3 - where - ss1.d_qoy = 1 - and ss1.d_year = 2002 - and ss1.ca_county = ss2.ca_county - and ss2.d_qoy = 2 - and ss2.d_year = 2002 - and ss2.ca_county = ss3.ca_county - and ss3.d_qoy = 3 - and ss3.d_year = 2002 - and ss1.ca_county = ws1.ca_county - and ws1.d_qoy = 1 - and ws1.d_year = 2002 - and ws1.ca_county = ws2.ca_county - and ws2.d_qoy = 2 - and ws2.d_year = 2002 - and ws1.ca_county = ws3.ca_county - and ws3.d_qoy = 3 - and ws3.d_year =2002 - and case when ws1.web_sales > 0 then ws2.web_sales/ws1.web_sales else null end - > case when ss1.store_sales > 0 then ss2.store_sales/ss1.store_sales else null end - and case when ws2.web_sales > 0 then ws3.web_sales/ws2.web_sales else null end - > case when ss2.store_sales > 0 then ss3.store_sales/ss2.store_sales else null end - order by ss1.d_year; - --- end template query31.tpl query 66 in stream 5 --- start template query26.tpl query 67 in stream 5 -select /* TPC-DS query26.tpl 0.85 */ i_item_id, - avg(cs_quantity) agg1, - avg(cs_list_price) agg2, - avg(cs_coupon_amt) agg3, - avg(cs_sales_price) agg4 - from catalog_sales, customer_demographics, date_dim, item, promotion - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd_demo_sk and - cs_promo_sk = p_promo_sk and - cd_gender = 'M' and - cd_marital_status = 'M' and - cd_education_status = 'College' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 2002 - group by i_item_id - order by i_item_id - limit 100; - --- end template query26.tpl query 67 in stream 5 --- start template query40.tpl query 68 in stream 5 -select /* TPC-DS query40.tpl 0.86 */ - w_state - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('2002-06-07' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_before - ,sum(case when (cast(d_date as date) >= cast ('2002-06-07' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_after - from - catalog_sales left outer join catalog_returns on - (cs_order_number = cr_order_number - and cs_item_sk = cr_item_sk) - ,warehouse - ,item - ,date_dim - where - i_current_price between 0.99 and 1.49 - and i_item_sk = cs_item_sk - and cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('2002-06-07' as date)) - and dateadd(day,30,cast ('2002-06-07' as date)) - group by - w_state,i_item_id - order by w_state,i_item_id -limit 100; - --- end template query40.tpl query 68 in stream 5 --- start template query14a.tpl query 69 in stream 5 -with /* TPC-DS query14a.tpl 0.69 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1998 AND 1998 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1998 AND 1998 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1998 AND 1998 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as - (select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2) x) -, - results AS -(select channel, i_brand_id, i_class_id, i_category_id, sum(sales) sum_sales, sum(number_sales) number_sales - from ( - select 'store' channel, i_brand_id,i_class_id - ,i_category_id,sum(ss_quantity*ss_list_price) sales - , count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1998+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales) - union all - select 'catalog' channel, i_brand_id,i_class_id,i_category_id, sum(cs_quantity*cs_list_price) sales, count(*) number_sales - from catalog_sales - ,item - ,date_dim - where cs_item_sk in (select ss_item_sk from cross_items) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1998+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(cs_quantity*cs_list_price) > (select average_sales from avg_sales) - union all - select 'web' channel, i_brand_id,i_class_id,i_category_id, sum(ws_quantity*ws_list_price) sales , count(*) number_sales - from web_sales - ,item - ,date_dim - where ws_item_sk in (select ss_item_sk from cross_items) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1998+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ws_quantity*ws_list_price) > (select average_sales from avg_sales) - ) y - group by channel, i_brand_id,i_class_id,i_category_id) - - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales -from ( - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales from results - union - select channel, i_brand_id, i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id, i_class_id - union - select channel, i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id - union - select channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel - union - select null as channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results) z -order by channel, i_brand_id, i_class_id, i_category_id - limit 100; -with /* TPC-DS query14a.tpl 0.69 part2 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1998 AND 1998 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1998 AND 1998 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1998 AND 1998 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as -(select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2) x) - select this_year.channel ty_channel - ,this_year.i_brand_id ty_brand - ,this_year.i_class_id ty_class - ,this_year.i_category_id ty_category - ,this_year.sales ty_sales - ,this_year.number_sales ty_number_sales - ,last_year.channel ly_channel - ,last_year.i_brand_id ly_brand - ,last_year.i_class_id ly_class - ,last_year.i_category_id ly_category - ,last_year.sales ly_sales - ,last_year.number_sales ly_number_sales -from - (select 'store' channel, i_brand_id,i_class_id,i_category_id - ,sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1998 + 1 - and d_moy = 12 - and d_dom = 22) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) this_year, - (select 'store' channel, i_brand_id,i_class_id - ,i_category_id, sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1998 - and d_moy = 12 - and d_dom = 22) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) last_year - where this_year.i_brand_id= last_year.i_brand_id - and this_year.i_class_id = last_year.i_class_id - and this_year.i_category_id = last_year.i_category_id - order by this_year.channel, this_year.i_brand_id, this_year.i_class_id, this_year.i_category_id - limit 100; - --- end template query14a.tpl query 69 in stream 5 --- start template query23.tpl query 70 in stream 5 -with /* TPC-DS query23.tpl 0.68 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (1998,1998+1,1998+2,1998+3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1998,1998+1,1998+2,1998+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * -from - max_store_sales)) - select sum(sales) - from (select cs_quantity*cs_list_price sales - from catalog_sales - ,date_dim - where d_year = 1998 - and d_moy = 6 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - union all - select ws_quantity*ws_list_price sales - from web_sales - ,date_dim - where d_year = 1998 - and d_moy = 6 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer)) - limit 100; -with /* TPC-DS query23.tpl 0.68 part2 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (1998,1998 + 1,1998 + 2,1998 + 3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1998,1998+1,1998+2,1998+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * - from max_store_sales)) - select c_last_name,c_first_name,sales - from (select c_last_name,c_first_name,sum(cs_quantity*cs_list_price) sales - from catalog_sales - ,customer - ,date_dim - where d_year = 1998 - and d_moy = 6 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and cs_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name - union all - select c_last_name,c_first_name,sum(ws_quantity*ws_list_price) sales - from web_sales - ,customer - ,date_dim - where d_year = 1998 - and d_moy = 6 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and ws_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name) - order by c_last_name,c_first_name,sales - limit 100; - --- end template query23.tpl query 70 in stream 5 --- start template query96.tpl query 71 in stream 5 -select /* TPC-DS query96.tpl 0.1 */ count(*) -from store_sales - ,household_demographics - ,time_dim, store -where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 20 - and time_dim.t_minute >= 30 - and household_demographics.hd_dep_count = 4 - and store.s_store_name = 'ese' -order by count(*) -limit 100; - --- end template query96.tpl query 71 in stream 5 --- start template query1.tpl query 72 in stream 5 -with /* TPC-DS query1.tpl 0.12 */ customer_total_return as -(select sr_customer_sk as ctr_customer_sk -,sr_store_sk as ctr_store_sk -,sum(SR_RETURN_AMT) as ctr_total_return -from store_returns -,date_dim -where sr_returned_date_sk = d_date_sk -and d_year =2002 -group by sr_customer_sk -,sr_store_sk) - select c_customer_id -from customer_total_return ctr1 -,store -,customer -where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 -from customer_total_return ctr2 -where ctr1.ctr_store_sk = ctr2.ctr_store_sk) -and s_store_sk = ctr1.ctr_store_sk -and s_state = 'OK' -and ctr1.ctr_customer_sk = c_customer_sk -order by c_customer_id -limit 100; - --- end template query1.tpl query 72 in stream 5 --- start template query95.tpl query 73 in stream 5 -with /* TPC-DS query95.tpl 0.43 */ ws_wh as -(select ws1.ws_order_number,ws1.ws_warehouse_sk wh1,ws2.ws_warehouse_sk wh2 - from web_sales ws1,web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) - select - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2002-4-01' and - dateadd(day,60,cast('2002-4-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'IL' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and ws1.ws_order_number in (select ws_order_number - from ws_wh) -and ws1.ws_order_number in (select wr_order_number - from web_returns,ws_wh - where wr_order_number = ws_wh.ws_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query95.tpl query 73 in stream 5 --- start template query27a.tpl query 74 in stream 5 -with /* TPC-DS query27a.tpl 0.16 */ results as - (select i_item_id, - s_state, 0 as g_state, - ss_quantity agg1, - ss_list_price agg2, - ss_coupon_amt agg3, - ss_sales_price agg4 - from store_sales, customer_demographics, date_dim, store, item - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_store_sk = s_store_sk and - ss_cdemo_sk = cd_demo_sk and - cd_gender = 'M' and - cd_marital_status = 'M' and - cd_education_status = 'Secondary' and - d_year = 1998 and - s_state in ('CO','OK', 'MO', 'VT', 'NM', 'KY') - ) - - select i_item_id, - s_state, g_state, agg1, agg2, agg3, agg4 - from ( - select i_item_id, s_state, 0 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4 from results - group by i_item_id, s_state - union all - select i_item_id, NULL AS s_state, 1 AS g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as s_state, 1 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - ) foo - order by i_item_id, s_state - limit 100; - --- end template query27a.tpl query 74 in stream 5 --- start template query44.tpl query 75 in stream 5 -select /* TPC-DS query44.tpl 0.4 */ asceding.rnk, i1.i_product_name best_performing, i2.i_product_name worst_performing -from(select * - from (select item_sk,rank() over (order by rank_col asc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 481 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 481 - and ss_hdemo_sk is null - group by ss_store_sk))V1)V11 - where rnk < 11) asceding, - (select * - from (select item_sk,rank() over (order by rank_col desc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 481 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 481 - and ss_hdemo_sk is null - group by ss_store_sk))V2)V21 - where rnk < 11) descending, -item i1, -item i2 -where asceding.rnk = descending.rnk - and i1.i_item_sk=asceding.item_sk - and i2.i_item_sk=descending.item_sk -order by asceding.rnk -limit 100; - --- end template query44.tpl query 75 in stream 5 --- start template query16.tpl query 76 in stream 5 -select /* TPC-DS query16.tpl 0.25 */ - count(distinct cs_order_number) as "order count" - ,sum(cs_ext_ship_cost) as "total shipping cost" - ,sum(cs_net_profit) as "total net profit" -from - catalog_sales cs1 - ,date_dim - ,customer_address - ,call_center -where - d_date between '2000-2-01' and - dateadd(day, 60, cast('2000-2-01' as date)) -and cs1.cs_ship_date_sk = d_date_sk -and cs1.cs_ship_addr_sk = ca_address_sk -and ca_state = 'NY' -and cs1.cs_call_center_sk = cc_call_center_sk -and cc_county in ('Perry County','Ziebach County','Huron County','Wadena County', - 'Franklin Parish' -) -and exists (select * - from catalog_sales cs2 - where cs1.cs_order_number = cs2.cs_order_number - and cs1.cs_warehouse_sk <> cs2.cs_warehouse_sk) -and not exists(select * - from catalog_returns cr1 - where cs1.cs_order_number = cr1.cr_order_number) -order by count(distinct cs_order_number) -limit 100; - --- end template query16.tpl query 76 in stream 5 --- start template query64.tpl query 77 in stream 5 -with /* TPC-DS query64.tpl 0.20 */ cs_ui as - (select cs_item_sk - ,sum(cs_ext_list_price) as sale,sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit) as refund - from catalog_sales - ,catalog_returns - where cs_item_sk = cr_item_sk - and cs_order_number = cr_order_number - group by cs_item_sk - having sum(cs_ext_list_price)>2*sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit)), -cross_sales as - (select i_product_name product_name - ,i_item_sk item_sk - ,s_store_name store_name - ,s_zip store_zip - ,ad1.ca_street_number b_street_number - ,ad1.ca_street_name b_street_name - ,ad1.ca_city b_city - ,ad1.ca_zip b_zip - ,ad2.ca_street_number c_street_number - ,ad2.ca_street_name c_street_name - ,ad2.ca_city c_city - ,ad2.ca_zip c_zip - ,d1.d_year as syear - ,d2.d_year as fsyear - ,d3.d_year s2year - ,count(*) cnt - ,sum(ss_wholesale_cost) s1 - ,sum(ss_list_price) s2 - ,sum(ss_coupon_amt) s3 - FROM store_sales - ,store_returns - ,cs_ui - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,customer - ,customer_demographics cd1 - ,customer_demographics cd2 - ,promotion - ,household_demographics hd1 - ,household_demographics hd2 - ,customer_address ad1 - ,customer_address ad2 - ,income_band ib1 - ,income_band ib2 - ,item - WHERE ss_store_sk = s_store_sk AND - ss_sold_date_sk = d1.d_date_sk AND - ss_customer_sk = c_customer_sk AND - ss_cdemo_sk= cd1.cd_demo_sk AND - ss_hdemo_sk = hd1.hd_demo_sk AND - ss_addr_sk = ad1.ca_address_sk and - ss_item_sk = i_item_sk and - ss_item_sk = sr_item_sk and - ss_ticket_number = sr_ticket_number and - ss_item_sk = cs_ui.cs_item_sk and - c_current_cdemo_sk = cd2.cd_demo_sk AND - c_current_hdemo_sk = hd2.hd_demo_sk AND - c_current_addr_sk = ad2.ca_address_sk and - c_first_sales_date_sk = d2.d_date_sk and - c_first_shipto_date_sk = d3.d_date_sk and - ss_promo_sk = p_promo_sk and - hd1.hd_income_band_sk = ib1.ib_income_band_sk and - hd2.hd_income_band_sk = ib2.ib_income_band_sk and - cd1.cd_marital_status <> cd2.cd_marital_status and - i_color in ('seashell','cream','wheat','moccasin','peru','blush') and - i_current_price between 44 and 44 + 10 and - i_current_price between 44 + 1 and 44 + 15 -group by i_product_name - ,i_item_sk - ,s_store_name - ,s_zip - ,ad1.ca_street_number - ,ad1.ca_street_name - ,ad1.ca_city - ,ad1.ca_zip - ,ad2.ca_street_number - ,ad2.ca_street_name - ,ad2.ca_city - ,ad2.ca_zip - ,d1.d_year - ,d2.d_year - ,d3.d_year -) -select cs1.product_name - ,cs1.store_name - ,cs1.store_zip - ,cs1.b_street_number - ,cs1.b_street_name - ,cs1.b_city - ,cs1.b_zip - ,cs1.c_street_number - ,cs1.c_street_name - ,cs1.c_city - ,cs1.c_zip - ,cs1.syear - ,cs1.cnt - ,cs1.s1 as s11 - ,cs1.s2 as s21 - ,cs1.s3 as s31 - ,cs2.s1 as s12 - ,cs2.s2 as s22 - ,cs2.s3 as s32 - ,cs2.syear - ,cs2.cnt -from cross_sales cs1,cross_sales cs2 -where cs1.item_sk=cs2.item_sk and - cs1.syear = 2000 and - cs2.syear = 2000 + 1 and - cs2.cnt <= cs1.cnt and - cs1.store_name = cs2.store_name and - cs1.store_zip = cs2.store_zip -order by cs1.product_name - ,cs1.store_name - ,cs2.cnt - ,cs1.s1 - ,cs2.s1; - --- end template query64.tpl query 77 in stream 5 --- start template query20.tpl query 78 in stream 5 -select /* TPC-DS query20.tpl 0.65 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(cs_ext_sales_price) as itemrevenue - ,sum(cs_ext_sales_price)*100/sum(sum(cs_ext_sales_price)) over - (partition by i_class) as revenueratio - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and i_category in ('Shoes', 'Women', 'Sports') - and cs_sold_date_sk = d_date_sk - and d_date between cast('2002-01-06' as date) - and dateadd(day,30,cast('2002-01-06' as date)) - group by i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - order by i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query20.tpl query 78 in stream 5 --- start template query43.tpl query 79 in stream 5 -select /* TPC-DS query43.tpl 0.15 */ s_store_name, s_store_id, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from date_dim, store_sales, store - where d_date_sk = ss_sold_date_sk and - s_store_sk = ss_store_sk and - s_gmt_offset = -5 and - d_year = 2000 - group by s_store_name, s_store_id - order by s_store_name, s_store_id,sun_sales,mon_sales,tue_sales,wed_sales,thu_sales,fri_sales,sat_sales - limit 100; - --- end template query43.tpl query 79 in stream 5 --- start template query5a.tpl query 80 in stream 5 -with /* TPC-DS query5a.tpl 0.98 */ ssr as - (select s_store_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ss_store_sk as store_sk, - ss_sold_date_sk as date_sk, - ss_ext_sales_price as sales_price, - ss_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from store_sales - union all - select sr_store_sk as store_sk, - sr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - sr_return_amt as return_amt, - sr_net_loss as net_loss - from store_returns - ) salesreturns, - date_dim, - store - where date_sk = d_date_sk - and d_date between cast('2000-08-28' as date) - and dateadd(day,14,cast('2000-08-28' as date)) - and store_sk = s_store_sk - group by s_store_id) - , - csr as - (select cp_catalog_page_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select cs_catalog_page_sk as page_sk, - cs_sold_date_sk as date_sk, - cs_ext_sales_price as sales_price, - cs_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from catalog_sales - union all - select cr_catalog_page_sk as page_sk, - cr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - cr_return_amount as return_amt, - cr_net_loss as net_loss - from catalog_returns - ) salesreturns, - date_dim, - catalog_page - where date_sk = d_date_sk - and d_date between cast('2000-08-28' as date) - and dateadd(day,14,cast('2000-08-28' as date)) - and page_sk = cp_catalog_page_sk - group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ws_web_site_sk as wsr_web_site_sk, - ws_sold_date_sk as date_sk, - ws_ext_sales_price as sales_price, - ws_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from web_sales - union all - select ws_web_site_sk as wsr_web_site_sk, - wr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - wr_return_amt as return_amt, - wr_net_loss as net_loss - from web_returns left outer join web_sales on - ( wr_item_sk = ws_item_sk - and wr_order_number = ws_order_number) - ) salesreturns, - date_dim, - web_site - where date_sk = d_date_sk - and d_date between cast('2000-08-28' as date) - and dateadd(day,14,cast('2000-08-28' as date)) - and wsr_web_site_sk = web_site_sk - group by web_site_id) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || s_store_id as id - , sales - , returns - , (profit - profit_loss) as profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || cp_catalog_page_id as id - , sales - , returns - , (profit - profit_loss) as profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , (profit - profit_loss) as profit - from wsr - ) x - group by channel, id) - select channel, id, sales, returns, profit from ( - select channel, id, sales, returns, profit from results - union - select channel, null as id, sum(sales), sum(returns), sum(profit) from results group by channel - union - select null as channel, null as id, sum(sales), sum(returns), sum(profit) from results) foo -order by channel, id -limit 100; - --- end template query5a.tpl query 80 in stream 5 --- start template query47.tpl query 81 in stream 5 -with /* TPC-DS query47.tpl 0.42 */ v1 as( - select i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, - s_store_name, s_company_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - s_store_name, s_company_name - order by d_year, d_moy) rn - from item, store_sales, date_dim, store - where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - ( - d_year = 1999 or - ( d_year = 1999-1 and d_moy =12) or - ( d_year = 1999+1 and d_moy =1) - ) - group by i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy), - v2 as( - select v1.i_brand - ,v1.d_year - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1.s_store_name = v1_lag.s_store_name and - v1.s_store_name = v1_lead.s_store_name and - v1.s_company_name = v1_lag.s_company_name and - v1.s_company_name = v1_lead.s_company_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 1999 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, psum - limit 100; - --- end template query47.tpl query 81 in stream 5 --- start template query10.tpl query 82 in stream 5 -select /* TPC-DS query10.tpl 0.26 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3, - cd_dep_count, - count(*) cnt4, - cd_dep_employed_count, - count(*) cnt5, - cd_dep_college_count, - count(*) cnt6 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_county in ('Union County','Wise County','Mobile County','Douglas County','Schoolcraft County') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 3 and 3+3) and - (exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 3 ANd 3+3) or - exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 3 and 3+3)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count -limit 100; - --- end template query10.tpl query 82 in stream 5 --- start template query70a.tpl query 83 in stream 5 -with /* TPC-DS query70a.tpl 0.34 */ results as -( select - sum(ss_net_profit) as total_sum ,s_state ,s_county, 0 as gstate, 0 as g_county - from - store_sales - ,date_dim d1 - ,store - where - d1.d_month_seq between 1178 and 1178 + 11 - and d1.d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - and s_state in - ( select s_state - from (select s_state as s_state, - rank() over ( partition by s_state order by sum(ss_net_profit) desc) as ranking - from store_sales, store, date_dim - where d_month_seq between 1178 and 1178 + 11 - and d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - group by s_state - ) tmp1 - where ranking <= 5) - group by s_state,s_county) , - results_rollup as -(select total_sum ,s_state ,s_county, 0 as g_state, 0 as g_county, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum,s_state, NULL as s_county, 0 as g_state, 1 as g_county, 1 as lochierarchy from results group by s_state - union - select sum(total_sum) as total_sum ,NULL as s_state ,NULL as s_county, 1 as g_state, 1 as g_county, 2 as lochierarchy from results) - select total_sum ,s_state ,s_county, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_county = 0 then s_state end - order by total_sum desc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then s_state end - ,rank_within_parent - limit 100; - --- end template query70a.tpl query 83 in stream 5 --- start template query39.tpl query 84 in stream 5 -with /* TPC-DS query39.tpl 0.5 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =2000 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=1 - and inv2.d_moy=1+1 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; -with /* TPC-DS query39.tpl 0.5 part2 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =2000 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=1 - and inv2.d_moy=1+1 - and inv1.cov > 1.5 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; - --- end template query39.tpl query 84 in stream 5 --- start template query72.tpl query 85 in stream 5 -select /* TPC-DS query72.tpl 0.87 */ i_item_desc - ,w_warehouse_name - ,d1.d_week_seq - ,sum(case when p_promo_sk is null then 1 else 0 end) no_promo - ,sum(case when p_promo_sk is not null then 1 else 0 end) promo - ,count(*) total_cnt -from catalog_sales -join inventory on (cs_item_sk = inv_item_sk) -join warehouse on (w_warehouse_sk=inv_warehouse_sk) -join item on (i_item_sk = cs_item_sk) -join customer_demographics on (cs_bill_cdemo_sk = cd_demo_sk) -join household_demographics on (cs_bill_hdemo_sk = hd_demo_sk) -join date_dim d1 on (cs_sold_date_sk = d1.d_date_sk) -join date_dim d2 on (inv_date_sk = d2.d_date_sk) -join date_dim d3 on (cs_ship_date_sk = d3.d_date_sk) -left outer join promotion on (cs_promo_sk=p_promo_sk) -left outer join catalog_returns on (cr_item_sk = cs_item_sk and cr_order_number = cs_order_number) -where d1.d_week_seq = d2.d_week_seq - and inv_quantity_on_hand < cs_quantity - and d3.d_date > d1.d_date + 5 - and hd_buy_potential = '501-1000' - and d1.d_year = 2000 - and cd_marital_status = 'S' -group by i_item_desc,w_warehouse_name,d1.d_week_seq -order by total_cnt desc, i_item_desc, w_warehouse_name, d_week_seq -limit 100; - --- end template query72.tpl query 85 in stream 5 --- start template query75.tpl query 86 in stream 5 -WITH /* TPC-DS query75.tpl 0.3 */ all_sales AS ( - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,SUM(sales_cnt) AS sales_cnt - ,SUM(sales_amt) AS sales_amt - FROM (SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,cs_quantity - COALESCE(cr_return_quantity,0) AS sales_cnt - ,cs_ext_sales_price - COALESCE(cr_return_amount,0.0) AS sales_amt - FROM catalog_sales JOIN item ON i_item_sk=cs_item_sk - JOIN date_dim ON d_date_sk=cs_sold_date_sk - LEFT JOIN catalog_returns ON (cs_order_number=cr_order_number - AND cs_item_sk=cr_item_sk) - WHERE i_category='Women' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ss_quantity - COALESCE(sr_return_quantity,0) AS sales_cnt - ,ss_ext_sales_price - COALESCE(sr_return_amt,0.0) AS sales_amt - FROM store_sales JOIN item ON i_item_sk=ss_item_sk - JOIN date_dim ON d_date_sk=ss_sold_date_sk - LEFT JOIN store_returns ON (ss_ticket_number=sr_ticket_number - AND ss_item_sk=sr_item_sk) - WHERE i_category='Women' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ws_quantity - COALESCE(wr_return_quantity,0) AS sales_cnt - ,ws_ext_sales_price - COALESCE(wr_return_amt,0.0) AS sales_amt - FROM web_sales JOIN item ON i_item_sk=ws_item_sk - JOIN date_dim ON d_date_sk=ws_sold_date_sk - LEFT JOIN web_returns ON (ws_order_number=wr_order_number - AND ws_item_sk=wr_item_sk) - WHERE i_category='Women') sales_detail - GROUP BY d_year, i_brand_id, i_class_id, i_category_id, i_manufact_id) - SELECT prev_yr.d_year AS prev_year - ,curr_yr.d_year AS year - ,curr_yr.i_brand_id - ,curr_yr.i_class_id - ,curr_yr.i_category_id - ,curr_yr.i_manufact_id - ,prev_yr.sales_cnt AS prev_yr_cnt - ,curr_yr.sales_cnt AS curr_yr_cnt - ,curr_yr.sales_cnt-prev_yr.sales_cnt AS sales_cnt_diff - ,curr_yr.sales_amt-prev_yr.sales_amt AS sales_amt_diff - FROM all_sales curr_yr, all_sales prev_yr - WHERE curr_yr.i_brand_id=prev_yr.i_brand_id - AND curr_yr.i_class_id=prev_yr.i_class_id - AND curr_yr.i_category_id=prev_yr.i_category_id - AND curr_yr.i_manufact_id=prev_yr.i_manufact_id - AND curr_yr.d_year=2002 - AND prev_yr.d_year=2002-1 - AND CAST(curr_yr.sales_cnt AS DECIMAL(17,2))/CAST(prev_yr.sales_cnt AS DECIMAL(17,2))<0.9 - ORDER BY sales_cnt_diff,sales_amt_diff - limit 100; - --- end template query75.tpl query 86 in stream 5 --- start template query12.tpl query 87 in stream 5 -select /* TPC-DS query12.tpl 0.64 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ws_ext_sales_price) as itemrevenue - ,sum(ws_ext_sales_price)*100/sum(sum(ws_ext_sales_price)) over - (partition by i_class) as revenueratio -from - web_sales - ,item - ,date_dim -where - ws_item_sk = i_item_sk - and i_category in ('Music', 'Women', 'Jewelry') - and ws_sold_date_sk = d_date_sk - and d_date between cast('2000-01-12' as date) - and dateadd(day,30,cast('2000-01-12' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query12.tpl query 87 in stream 5 --- start template query37.tpl query 88 in stream 5 -select /* TPC-DS query37.tpl 0.31 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, catalog_sales - where i_current_price between 28 and 28 + 30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('2002-06-06' as date) and dateadd(day,60,cast('2002-06-06' as date)) - and i_manufact_id in (875,853,677,830) - and inv_quantity_on_hand between 100 and 500 - and cs_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query37.tpl query 88 in stream 5 --- start template query15.tpl query 89 in stream 5 -select /* TPC-DS query15.tpl 0.57 */ ca_zip - ,sum(cs_sales_price) - from catalog_sales - ,customer - ,customer_address - ,date_dim - where cs_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', - '85392', '85460', '80348', '81792') - or ca_state in ('CA','WA','GA') - or cs_sales_price > 500) - and cs_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 1999 - group by ca_zip - order by ca_zip - limit 100; - --- end template query15.tpl query 89 in stream 5 --- start template query59.tpl query 90 in stream 5 -with /* TPC-DS query59.tpl 0.30 */ wss as - (select d_week_seq, - ss_store_sk, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - group by d_week_seq,ss_store_sk - ) - select s_store_name1,s_store_id1,d_week_seq1 - ,sun_sales1/sun_sales2,mon_sales1/mon_sales2 - ,tue_sales1/tue_sales2,wed_sales1/wed_sales2,thu_sales1/thu_sales2 - ,fri_sales1/fri_sales2,sat_sales1/sat_sales2 - from - (select s_store_name s_store_name1,wss.d_week_seq d_week_seq1 - ,s_store_id s_store_id1,sun_sales sun_sales1 - ,mon_sales mon_sales1,tue_sales tue_sales1 - ,wed_sales wed_sales1,thu_sales thu_sales1 - ,fri_sales fri_sales1,sat_sales sat_sales1 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1205 and 1205 + 11) y, - (select s_store_name s_store_name2,wss.d_week_seq d_week_seq2 - ,s_store_id s_store_id2,sun_sales sun_sales2 - ,mon_sales mon_sales2,tue_sales tue_sales2 - ,wed_sales wed_sales2,thu_sales thu_sales2 - ,fri_sales fri_sales2,sat_sales sat_sales2 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1205+ 12 and 1205 + 23) x - where s_store_id1=s_store_id2 - and d_week_seq1=d_week_seq2-52 - order by s_store_name1,s_store_id1,d_week_seq1 -limit 100; - --- end template query59.tpl query 90 in stream 5 --- start template query91.tpl query 91 in stream 5 -select /* TPC-DS query91.tpl 0.13 */ - cc_call_center_id Call_Center, - cc_name Call_Center_Name, - cc_manager Manager, - sum(cr_net_loss) Returns_Loss -from - call_center, - catalog_returns, - date_dim, - customer, - customer_address, - customer_demographics, - household_demographics -where - cr_call_center_sk = cc_call_center_sk -and cr_returned_date_sk = d_date_sk -and cr_returning_customer_sk= c_customer_sk -and cd_demo_sk = c_current_cdemo_sk -and hd_demo_sk = c_current_hdemo_sk -and ca_address_sk = c_current_addr_sk -and d_year = 2001 -and d_moy = 12 -and ( (cd_marital_status = 'M' and cd_education_status = 'Unknown') - or(cd_marital_status = 'W' and cd_education_status = 'Advanced Degree')) -and hd_buy_potential like '501-1000%' -and ca_gmt_offset = -6 -group by cc_call_center_id,cc_name,cc_manager,cd_marital_status,cd_education_status -order by sum(cr_net_loss) desc; - --- end template query91.tpl query 91 in stream 5 --- start template query99.tpl query 92 in stream 5 -select /* TPC-DS query99.tpl 0.94 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 30) and - (cs_ship_date_sk - cs_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 60) and - (cs_ship_date_sk - cs_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 90) and - (cs_ship_date_sk - cs_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - catalog_sales - ,warehouse - ,ship_mode - ,call_center - ,date_dim -where - d_month_seq between 1213 and 1213 + 11 -and cs_ship_date_sk = d_date_sk -and cs_warehouse_sk = w_warehouse_sk -and cs_ship_mode_sk = sm_ship_mode_sk -and cs_call_center_sk = cc_call_center_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -limit 100; - --- end template query99.tpl query 92 in stream 5 --- start template query41.tpl query 93 in stream 5 -select /* TPC-DS query41.tpl 0.62 */ distinct(i_product_name) - from item i1 - where i_manufact_id between 893 and 893+40 - and (select count(*) as item_cnt - from item - where (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'burnished' or i_color = 'antique') and - (i_units = 'Carton' or i_units = 'Ton') and - (i_size = 'N/A' or i_size = 'economy') - ) or - (i_category = 'Women' and - (i_color = 'sandy' or i_color = 'peru') and - (i_units = 'Dram' or i_units = 'Gross') and - (i_size = 'extra large' or i_size = 'small') - ) or - (i_category = 'Men' and - (i_color = 'gainsboro' or i_color = 'rosy') and - (i_units = 'Oz' or i_units = 'Case') and - (i_size = 'large' or i_size = 'medium') - ) or - (i_category = 'Men' and - (i_color = 'green' or i_color = 'olive') and - (i_units = 'Ounce' or i_units = 'N/A') and - (i_size = 'N/A' or i_size = 'economy') - ))) or - (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'hot' or i_color = 'firebrick') and - (i_units = 'Tsp' or i_units = 'Pound') and - (i_size = 'N/A' or i_size = 'economy') - ) or - (i_category = 'Women' and - (i_color = 'medium' or i_color = 'puff') and - (i_units = 'Gram' or i_units = 'Each') and - (i_size = 'extra large' or i_size = 'small') - ) or - (i_category = 'Men' and - (i_color = 'navy' or i_color = 'slate') and - (i_units = 'Dozen' or i_units = 'Unknown') and - (i_size = 'large' or i_size = 'medium') - ) or - (i_category = 'Men' and - (i_color = 'navajo' or i_color = 'chiffon') and - (i_units = 'Bundle' or i_units = 'Box') and - (i_size = 'N/A' or i_size = 'economy') - )))) > 0 - order by i_product_name - limit 100; - --- end template query41.tpl query 93 in stream 5 --- start template query9.tpl query 94 in stream 5 -select /* TPC-DS query9.tpl 0.49 */ case when (select count(*) - from store_sales - where ss_quantity between 1 and 20) > 1017365585 - then (select avg(ss_ext_list_price) - from store_sales - where ss_quantity between 1 and 20) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 1 and 20) end bucket1 , - case when (select count(*) - from store_sales - where ss_quantity between 21 and 40) > 1385532911 - then (select avg(ss_ext_list_price) - from store_sales - where ss_quantity between 21 and 40) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 21 and 40) end bucket2, - case when (select count(*) - from store_sales - where ss_quantity between 41 and 60) > 788763142 - then (select avg(ss_ext_list_price) - from store_sales - where ss_quantity between 41 and 60) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 41 and 60) end bucket3, - case when (select count(*) - from store_sales - where ss_quantity between 61 and 80) > 1383493630 - then (select avg(ss_ext_list_price) - from store_sales - where ss_quantity between 61 and 80) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 61 and 80) end bucket4, - case when (select count(*) - from store_sales - where ss_quantity between 81 and 100) > 476124433 - then (select avg(ss_ext_list_price) - from store_sales - where ss_quantity between 81 and 100) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 81 and 100) end bucket5 -from reason -where r_reason_sk = 1 -; - --- end template query9.tpl query 94 in stream 5 --- start template query86a.tpl query 95 in stream 5 -with /* TPC-DS query86a.tpl 0.11 */ results as -( select sum(ws_net_paid) as total_sum, i_category, i_class, 0 as g_category, 0 as g_class - from - web_sales - ,date_dim d1 - ,item - where - d1.d_month_seq between 1188 and 1188+11 - and d1.d_date_sk = ws_sold_date_sk - and i_item_sk = ws_item_sk - group by i_category,i_class - ) , - - results_rollup as -( select total_sum ,i_category ,i_class, g_category, g_class, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum, i_category, NULL as i_class, 0 as g_category, 1 as g_class, 1 as lochierarchy from results group by i_category - union - select sum(total_sum) as total_sum, NULL as i_category, NULL as i_class, 1 as g_category, 1 as g_class, 2 as lochierarchy from results) - select - total_sum ,i_category ,i_class, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_class = 0 then i_category end - order by total_sum desc) as rank_within_parent - from - results_rollup - order by - lochierarchy desc, - case when lochierarchy = 0 then i_category end, - rank_within_parent - limit 100; - --- end template query86a.tpl query 95 in stream 5 --- start template query34.tpl query 96 in stream 5 -select /* TPC-DS query34.tpl 0.73 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (date_dim.d_dom between 1 and 3 or date_dim.d_dom between 25 and 28) - and (household_demographics.hd_buy_potential = '501-1000' or - household_demographics.hd_buy_potential = '5001-10000') - and household_demographics.hd_vehicle_count > 0 - and (case when household_demographics.hd_vehicle_count > 0 - then household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count - else null - end) > 1.2 - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_county in ('Hinds County','Big Horn County','Huron County','Marshall County', - 'Greene County','Mercer County','Appanoose County','Schley County') - group by ss_ticket_number,ss_customer_sk) dn,customer - where ss_customer_sk = c_customer_sk - and cnt between 15 and 20 - order by c_last_name,c_first_name,c_salutation,c_preferred_cust_flag desc, ss_ticket_number; - --- end template query34.tpl query 96 in stream 5 --- start template query82.tpl query 97 in stream 5 -select /* TPC-DS query82.tpl 0.67 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, store_sales - where i_current_price between 83 and 83+30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('2001-03-15' as date) and dateadd(day,60,cast('2001-03-15' as date)) - and i_manufact_id in (293,328,785,886) - and inv_quantity_on_hand between 100 and 500 - and ss_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query82.tpl query 97 in stream 5 --- start template query29.tpl query 98 in stream 5 -select /* TPC-DS query29.tpl 0.53 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,max(ss_quantity) as store_sales_quantity - ,max(sr_return_quantity) as store_returns_quantity - ,max(cs_quantity) as catalog_sales_quantity - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 2000 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 4 + 3 - and d2.d_year = 2000 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_year in (2000,2000+1,2000+2) - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query29.tpl query 98 in stream 5 --- start template query25.tpl query 99 in stream 5 -select /* TPC-DS query25.tpl 0.9 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,min(ss_net_profit) as store_sales_profit - ,min(sr_net_loss) as store_returns_loss - ,min(cs_net_profit) as catalog_sales_profit - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 1998 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 10 - and d2.d_year = 1998 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_moy between 4 and 10 - and d3.d_year = 1998 - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query25.tpl query 99 in stream 5 diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/30TB/queries/query_6.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/30TB/queries/query_6.sql deleted file mode 100644 index cb2efbf7..00000000 --- a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/30TB/queries/query_6.sql +++ /dev/null @@ -1,5027 +0,0 @@ --- start template query34.tpl query 1 in stream 6 -select /* TPC-DS query34.tpl 0.73 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (date_dim.d_dom between 1 and 3 or date_dim.d_dom between 25 and 28) - and (household_demographics.hd_buy_potential = '1001-5000' or - household_demographics.hd_buy_potential = 'Unknown') - and household_demographics.hd_vehicle_count > 0 - and (case when household_demographics.hd_vehicle_count > 0 - then household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count - else null - end) > 1.2 - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_county in ('La Crosse County','Harding County','Barrow County','Camden County', - 'Conecuh County','Sandusky County','Cocke County','Piute County') - group by ss_ticket_number,ss_customer_sk) dn,customer - where ss_customer_sk = c_customer_sk - and cnt between 15 and 20 - order by c_last_name,c_first_name,c_salutation,c_preferred_cust_flag desc, ss_ticket_number; - --- end template query34.tpl query 1 in stream 6 --- start template query88.tpl query 2 in stream 6 -select /* TPC-DS query88.tpl 0.66 */ * -from - (select count(*) h8_30_to_9 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s1, - (select count(*) h9_to_9_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s2, - (select count(*) h9_30_to_10 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s3, - (select count(*) h10_to_10_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s4, - (select count(*) h10_30_to_11 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s5, - (select count(*) h11_to_11_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s6, - (select count(*) h11_30_to_12 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s7, - (select count(*) h12_to_12_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 12 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s8 -; - --- end template query88.tpl query 2 in stream 6 --- start template query44.tpl query 3 in stream 6 -select /* TPC-DS query44.tpl 0.4 */ asceding.rnk, i1.i_product_name best_performing, i2.i_product_name worst_performing -from(select * - from (select item_sk,rank() over (order by rank_col asc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 459 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 459 - and ss_cdemo_sk is null - group by ss_store_sk))V1)V11 - where rnk < 11) asceding, - (select * - from (select item_sk,rank() over (order by rank_col desc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 459 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 459 - and ss_cdemo_sk is null - group by ss_store_sk))V2)V21 - where rnk < 11) descending, -item i1, -item i2 -where asceding.rnk = descending.rnk - and i1.i_item_sk=asceding.item_sk - and i2.i_item_sk=descending.item_sk -order by asceding.rnk -limit 100; - --- end template query44.tpl query 3 in stream 6 --- start template query94.tpl query 4 in stream 6 -select /* TPC-DS query94.tpl 0.17 */ - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2001-4-01' and - dateadd(day,60,cast('2001-4-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'ND' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and exists (select * - from web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) -and not exists(select * - from web_returns wr1 - where ws1.ws_order_number = wr1.wr_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query94.tpl query 4 in stream 6 --- start template query50.tpl query 5 in stream 6 -select /* TPC-DS query50.tpl 0.60 */ - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 30) and - (sr_returned_date_sk - ss_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 60) and - (sr_returned_date_sk - ss_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 90) and - (sr_returned_date_sk - ss_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - store_sales - ,store_returns - ,store - ,date_dim d1 - ,date_dim d2 -where - d2.d_year = 2000 -and d2.d_moy = 10 -and ss_ticket_number = sr_ticket_number -and ss_item_sk = sr_item_sk -and ss_sold_date_sk = d1.d_date_sk -and sr_returned_date_sk = d2.d_date_sk -and ss_customer_sk = sr_customer_sk -and ss_store_sk = s_store_sk -group by - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -order by s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -limit 100; - --- end template query50.tpl query 5 in stream 6 --- start template query5a.tpl query 6 in stream 6 -with /* TPC-DS query5a.tpl 0.98 */ ssr as - (select s_store_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ss_store_sk as store_sk, - ss_sold_date_sk as date_sk, - ss_ext_sales_price as sales_price, - ss_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from store_sales - union all - select sr_store_sk as store_sk, - sr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - sr_return_amt as return_amt, - sr_net_loss as net_loss - from store_returns - ) salesreturns, - date_dim, - store - where date_sk = d_date_sk - and d_date between cast('1999-08-14' as date) - and dateadd(day,14,cast('1999-08-14' as date)) - and store_sk = s_store_sk - group by s_store_id) - , - csr as - (select cp_catalog_page_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select cs_catalog_page_sk as page_sk, - cs_sold_date_sk as date_sk, - cs_ext_sales_price as sales_price, - cs_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from catalog_sales - union all - select cr_catalog_page_sk as page_sk, - cr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - cr_return_amount as return_amt, - cr_net_loss as net_loss - from catalog_returns - ) salesreturns, - date_dim, - catalog_page - where date_sk = d_date_sk - and d_date between cast('1999-08-14' as date) - and dateadd(day,14,cast('1999-08-14' as date)) - and page_sk = cp_catalog_page_sk - group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ws_web_site_sk as wsr_web_site_sk, - ws_sold_date_sk as date_sk, - ws_ext_sales_price as sales_price, - ws_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from web_sales - union all - select ws_web_site_sk as wsr_web_site_sk, - wr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - wr_return_amt as return_amt, - wr_net_loss as net_loss - from web_returns left outer join web_sales on - ( wr_item_sk = ws_item_sk - and wr_order_number = ws_order_number) - ) salesreturns, - date_dim, - web_site - where date_sk = d_date_sk - and d_date between cast('1999-08-14' as date) - and dateadd(day,14,cast('1999-08-14' as date)) - and wsr_web_site_sk = web_site_sk - group by web_site_id) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || s_store_id as id - , sales - , returns - , (profit - profit_loss) as profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || cp_catalog_page_id as id - , sales - , returns - , (profit - profit_loss) as profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , (profit - profit_loss) as profit - from wsr - ) x - group by channel, id) - select channel, id, sales, returns, profit from ( - select channel, id, sales, returns, profit from results - union - select channel, null as id, sum(sales), sum(returns), sum(profit) from results group by channel - union - select null as channel, null as id, sum(sales), sum(returns), sum(profit) from results) foo -order by channel, id -limit 100; - --- end template query5a.tpl query 6 in stream 6 --- start template query53.tpl query 7 in stream 6 -select /* TPC-DS query53.tpl 0.88 */ * from -(select i_manufact_id, -sum(ss_sales_price) sum_sales, -avg(sum(ss_sales_price)) over (partition by i_manufact_id) avg_quarterly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and -ss_sold_date_sk = d_date_sk and -ss_store_sk = s_store_sk and -d_month_seq in (1182,1182+1,1182+2,1182+3,1182+4,1182+5,1182+6,1182+7,1182+8,1182+9,1182+10,1182+11) and -((i_category in ('Books','Children','Electronics') and -i_class in ('personal','portable','reference','self-help') and -i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) -or(i_category in ('Women','Music','Men') and -i_class in ('accessories','classical','fragrances','pants') and -i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manufact_id, d_qoy ) tmp1 -where case when avg_quarterly_sales > 0 - then abs (sum_sales - avg_quarterly_sales)/ avg_quarterly_sales - else null end > 0.1 -order by avg_quarterly_sales, - sum_sales, - i_manufact_id -limit 100; - --- end template query53.tpl query 7 in stream 6 --- start template query7.tpl query 8 in stream 6 -select /* TPC-DS query7.tpl 0.2 */ i_item_id, - avg(ss_quantity) agg1, - avg(ss_list_price) agg2, - avg(ss_coupon_amt) agg3, - avg(ss_sales_price) agg4 - from store_sales, customer_demographics, date_dim, item, promotion - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_cdemo_sk = cd_demo_sk and - ss_promo_sk = p_promo_sk and - cd_gender = 'M' and - cd_marital_status = 'S' and - cd_education_status = 'Unknown' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 1998 - group by i_item_id - order by i_item_id - limit 100; - --- end template query7.tpl query 8 in stream 6 --- start template query58.tpl query 9 in stream 6 -with /* TPC-DS query58.tpl 0.19 */ ss_items as - (select i_item_id item_id - ,sum(ss_ext_sales_price) ss_item_rev - from store_sales - ,item - ,date_dim - where ss_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '2002-05-02')) - and ss_sold_date_sk = d_date_sk - group by i_item_id), - cs_items as - (select i_item_id item_id - ,sum(cs_ext_sales_price) cs_item_rev - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '2002-05-02')) - and cs_sold_date_sk = d_date_sk - group by i_item_id), - ws_items as - (select i_item_id item_id - ,sum(ws_ext_sales_price) ws_item_rev - from web_sales - ,item - ,date_dim - where ws_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq =(select d_week_seq - from date_dim - where d_date = '2002-05-02')) - and ws_sold_date_sk = d_date_sk - group by i_item_id) - select ss_items.item_id - ,ss_item_rev - ,ss_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ss_dev - ,cs_item_rev - ,cs_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 cs_dev - ,ws_item_rev - ,ws_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ws_dev - ,(ss_item_rev+cs_item_rev+ws_item_rev)/3 average - from ss_items,cs_items,ws_items - where ss_items.item_id=cs_items.item_id - and ss_items.item_id=ws_items.item_id - and ss_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - and ss_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and cs_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and cs_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and ws_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and ws_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - order by item_id - ,ss_item_rev - limit 100; - --- end template query58.tpl query 9 in stream 6 --- start template query20.tpl query 10 in stream 6 -select /* TPC-DS query20.tpl 0.65 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(cs_ext_sales_price) as itemrevenue - ,sum(cs_ext_sales_price)*100/sum(sum(cs_ext_sales_price)) over - (partition by i_class) as revenueratio - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and i_category in ('Home', 'Electronics', 'Music') - and cs_sold_date_sk = d_date_sk - and d_date between cast('1999-04-14' as date) - and dateadd(day,30,cast('1999-04-14' as date)) - group by i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - order by i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query20.tpl query 10 in stream 6 --- start template query75.tpl query 11 in stream 6 -WITH /* TPC-DS query75.tpl 0.3 */ all_sales AS ( - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,SUM(sales_cnt) AS sales_cnt - ,SUM(sales_amt) AS sales_amt - FROM (SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,cs_quantity - COALESCE(cr_return_quantity,0) AS sales_cnt - ,cs_ext_sales_price - COALESCE(cr_return_amount,0.0) AS sales_amt - FROM catalog_sales JOIN item ON i_item_sk=cs_item_sk - JOIN date_dim ON d_date_sk=cs_sold_date_sk - LEFT JOIN catalog_returns ON (cs_order_number=cr_order_number - AND cs_item_sk=cr_item_sk) - WHERE i_category='Women' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ss_quantity - COALESCE(sr_return_quantity,0) AS sales_cnt - ,ss_ext_sales_price - COALESCE(sr_return_amt,0.0) AS sales_amt - FROM store_sales JOIN item ON i_item_sk=ss_item_sk - JOIN date_dim ON d_date_sk=ss_sold_date_sk - LEFT JOIN store_returns ON (ss_ticket_number=sr_ticket_number - AND ss_item_sk=sr_item_sk) - WHERE i_category='Women' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ws_quantity - COALESCE(wr_return_quantity,0) AS sales_cnt - ,ws_ext_sales_price - COALESCE(wr_return_amt,0.0) AS sales_amt - FROM web_sales JOIN item ON i_item_sk=ws_item_sk - JOIN date_dim ON d_date_sk=ws_sold_date_sk - LEFT JOIN web_returns ON (ws_order_number=wr_order_number - AND ws_item_sk=wr_item_sk) - WHERE i_category='Women') sales_detail - GROUP BY d_year, i_brand_id, i_class_id, i_category_id, i_manufact_id) - SELECT prev_yr.d_year AS prev_year - ,curr_yr.d_year AS year - ,curr_yr.i_brand_id - ,curr_yr.i_class_id - ,curr_yr.i_category_id - ,curr_yr.i_manufact_id - ,prev_yr.sales_cnt AS prev_yr_cnt - ,curr_yr.sales_cnt AS curr_yr_cnt - ,curr_yr.sales_cnt-prev_yr.sales_cnt AS sales_cnt_diff - ,curr_yr.sales_amt-prev_yr.sales_amt AS sales_amt_diff - FROM all_sales curr_yr, all_sales prev_yr - WHERE curr_yr.i_brand_id=prev_yr.i_brand_id - AND curr_yr.i_class_id=prev_yr.i_class_id - AND curr_yr.i_category_id=prev_yr.i_category_id - AND curr_yr.i_manufact_id=prev_yr.i_manufact_id - AND curr_yr.d_year=2001 - AND prev_yr.d_year=2001-1 - AND CAST(curr_yr.sales_cnt AS DECIMAL(17,2))/CAST(prev_yr.sales_cnt AS DECIMAL(17,2))<0.9 - ORDER BY sales_cnt_diff,sales_amt_diff - limit 100; - --- end template query75.tpl query 11 in stream 6 --- start template query73.tpl query 12 in stream 6 -select /* TPC-DS query73.tpl 0.79 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_buy_potential = '501-1000' or - household_demographics.hd_buy_potential = 'Unknown') - and household_demographics.hd_vehicle_count > 0 - and case when household_demographics.hd_vehicle_count > 0 then - household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count else null end > 1 - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_county in ('Mercer County','Rush County','Stafford County','Tallapoosa County') - group by ss_ticket_number,ss_customer_sk) dj,customer - where ss_customer_sk = c_customer_sk - and cnt between 1 and 5 - order by cnt desc, c_last_name asc; - --- end template query73.tpl query 12 in stream 6 --- start template query91.tpl query 13 in stream 6 -select /* TPC-DS query91.tpl 0.13 */ - cc_call_center_id Call_Center, - cc_name Call_Center_Name, - cc_manager Manager, - sum(cr_net_loss) Returns_Loss -from - call_center, - catalog_returns, - date_dim, - customer, - customer_address, - customer_demographics, - household_demographics -where - cr_call_center_sk = cc_call_center_sk -and cr_returned_date_sk = d_date_sk -and cr_returning_customer_sk= c_customer_sk -and cd_demo_sk = c_current_cdemo_sk -and hd_demo_sk = c_current_hdemo_sk -and ca_address_sk = c_current_addr_sk -and d_year = 1998 -and d_moy = 11 -and ( (cd_marital_status = 'M' and cd_education_status = 'Unknown') - or(cd_marital_status = 'W' and cd_education_status = 'Advanced Degree')) -and hd_buy_potential like '0-500%' -and ca_gmt_offset = -6 -group by cc_call_center_id,cc_name,cc_manager,cd_marital_status,cd_education_status -order by sum(cr_net_loss) desc; - --- end template query91.tpl query 13 in stream 6 --- start template query36a.tpl query 14 in stream 6 -with /* TPC-DS query36a.tpl 0.21 */ results as - (select - sum(ss_net_profit) as ss_net_profit, sum(ss_ext_sales_price) as ss_ext_sales_price, - sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin - ,i_category - ,i_class - ,0 as g_category, 0 as g_class - from - store_sales - ,date_dim d1 - ,item - ,store - where - d1.d_year = 1999 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and s_state in ('GA','AL','TX','FL', - 'GA','LA','MN','NY') - group by i_category,i_class) - , - results_rollup as - (select gross_margin ,i_category ,i_class,0 as t_category, 0 as t_class, 0 as lochierarchy from results - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - i_category, NULL AS i_class, 0 as t_category, 1 as t_class, 1 as lochierarchy from results group by i_category - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - NULL AS i_category ,NULL AS i_class, 1 as t_category, 1 as t_class, 2 as lochierarchy from results) - select - gross_margin ,i_category ,i_class, lochierarchy,rank() over ( - partition by lochierarchy, case when t_class = 0 then i_category end - order by gross_margin asc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then i_category end - ,rank_within_parent - limit 100; - --- end template query36a.tpl query 14 in stream 6 --- start template query11.tpl query 15 in stream 6 -with /* TPC-DS query11.tpl 0.51 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ss_ext_list_price-ss_ext_discount_amt) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ws_ext_list_price-ws_ext_discount_amt) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_preferred_cust_flag - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 2000 - and t_s_secyear.dyear = 2000+1 - and t_w_firstyear.dyear = 2000 - and t_w_secyear.dyear = 2000+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else 0.0 end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else 0.0 end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_preferred_cust_flag -limit 100; - --- end template query11.tpl query 15 in stream 6 --- start template query80a.tpl query 16 in stream 6 -with /* TPC-DS query80a.tpl 0.6 */ ssr as - (select s_store_id as store_id, - sum(ss_ext_sales_price) as sales, - sum(coalesce(sr_return_amt, 0)) as returns, - sum(ss_net_profit - coalesce(sr_net_loss, 0)) as profit - from store_sales left outer join store_returns on - (ss_item_sk = sr_item_sk and ss_ticket_number = sr_ticket_number), - date_dim, - store, - item, - promotion - where ss_sold_date_sk = d_date_sk - and d_date between cast('2000-08-10' as date) - and dateadd(day,30,cast('2000-08-10' as date)) - and ss_store_sk = s_store_sk - and ss_item_sk = i_item_sk - and i_current_price > 50 - and ss_promo_sk = p_promo_sk - and p_channel_tv = 'N' - group by s_store_id) - , - csr as - (select cp_catalog_page_id as catalog_page_id, - sum(cs_ext_sales_price) as sales, - sum(coalesce(cr_return_amount, 0)) as returns, - sum(cs_net_profit - coalesce(cr_net_loss, 0)) as profit - from catalog_sales left outer join catalog_returns on - (cs_item_sk = cr_item_sk and cs_order_number = cr_order_number), - date_dim, - catalog_page, - item, - promotion - where cs_sold_date_sk = d_date_sk - and d_date between cast('2000-08-10' as date) - and dateadd(day,30,cast('2000-08-10' as date)) - and cs_catalog_page_sk = cp_catalog_page_sk - and cs_item_sk = i_item_sk - and i_current_price > 50 - and cs_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(ws_ext_sales_price) as sales, - sum(coalesce(wr_return_amt, 0)) as returns, - sum(ws_net_profit - coalesce(wr_net_loss, 0)) as profit - from web_sales left outer join web_returns on - (ws_item_sk = wr_item_sk and ws_order_number = wr_order_number), - date_dim, - web_site, - item, - promotion - where ws_sold_date_sk = d_date_sk - and d_date between cast('2000-08-10' as date) - and dateadd(day,30,cast('2000-08-10' as date)) - and ws_web_site_sk = web_site_sk - and ws_item_sk = i_item_sk - and i_current_price > 50 - and ws_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by web_site_id) -, -results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || store_id as id - , sales - , returns - , profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || catalog_page_id as id - , sales - , returns - , profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , profit - from wsr - ) x - group by channel, id) - - select channel - , id - , sales - , returns - , profit - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results - ) foo - order by channel, id - limit 100; - --- end template query80a.tpl query 16 in stream 6 --- start template query9.tpl query 17 in stream 6 -select /* TPC-DS query9.tpl 0.49 */ case when (select count(*) - from store_sales - where ss_quantity between 1 and 20) > 1227866222 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 1 and 20) - else (select avg(ss_net_profit) - from store_sales - where ss_quantity between 1 and 20) end bucket1 , - case when (select count(*) - from store_sales - where ss_quantity between 21 and 40) > 171432737 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 21 and 40) - else (select avg(ss_net_profit) - from store_sales - where ss_quantity between 21 and 40) end bucket2, - case when (select count(*) - from store_sales - where ss_quantity between 41 and 60) > 908842769 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 41 and 60) - else (select avg(ss_net_profit) - from store_sales - where ss_quantity between 41 and 60) end bucket3, - case when (select count(*) - from store_sales - where ss_quantity between 61 and 80) > 1146865278 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 61 and 80) - else (select avg(ss_net_profit) - from store_sales - where ss_quantity between 61 and 80) end bucket4, - case when (select count(*) - from store_sales - where ss_quantity between 81 and 100) > 753653591 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 81 and 100) - else (select avg(ss_net_profit) - from store_sales - where ss_quantity between 81 and 100) end bucket5 -from reason -where r_reason_sk = 1 -; - --- end template query9.tpl query 17 in stream 6 --- start template query93.tpl query 18 in stream 6 -select /* TPC-DS query93.tpl 0.52 */ ss_customer_sk - ,sum(act_sales) sumsales - from (select ss_item_sk - ,ss_ticket_number - ,ss_customer_sk - ,case when sr_return_quantity is not null then (ss_quantity-sr_return_quantity)*ss_sales_price - else (ss_quantity*ss_sales_price) end act_sales - from store_sales left outer join store_returns on (sr_item_sk = ss_item_sk - and sr_ticket_number = ss_ticket_number) - ,reason - where sr_reason_sk = r_reason_sk - and r_reason_desc = 'reason 73') t - group by ss_customer_sk - order by sumsales, ss_customer_sk -limit 100; - --- end template query93.tpl query 18 in stream 6 --- start template query32.tpl query 19 in stream 6 -select /* TPC-DS query32.tpl 0.7 */ sum(cs_ext_discount_amt) as "excess discount amount" -from - catalog_sales - ,item - ,date_dim -where -i_manufact_id = 96 -and i_item_sk = cs_item_sk -and d_date between '2000-02-16' and - dateadd(day,90,cast('2000-02-16' as date)) -and d_date_sk = cs_sold_date_sk -and cs_ext_discount_amt - > ( - select - 1.3 * avg(cs_ext_discount_amt) - from - catalog_sales - ,date_dim - where - cs_item_sk = i_item_sk - and d_date between '2000-02-16' and - dateadd(day,90,cast('2000-02-16' as date)) - and d_date_sk = cs_sold_date_sk - ) -limit 100; - --- end template query32.tpl query 19 in stream 6 --- start template query89.tpl query 20 in stream 6 -select /* TPC-DS query89.tpl 0.56 */ * -from( -select i_category, i_class, i_brand, - s_store_name, s_company_name, - d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, s_store_name, s_company_name) - avg_monthly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - d_year in (2002) and - ((i_category in ('Books','Electronics','Home') and - i_class in ('entertainments','scanners','lighting') - ) - or (i_category in ('Jewelry','Women','Sports') and - i_class in ('loose stones','fragrances','pools') - )) -group by i_category, i_class, i_brand, - s_store_name, s_company_name, d_moy) tmp1 -where case when (avg_monthly_sales <> 0) then (abs(sum_sales - avg_monthly_sales) / avg_monthly_sales) else null end > 0.1 -order by sum_sales - avg_monthly_sales, s_store_name -limit 100; - --- end template query89.tpl query 20 in stream 6 --- start template query28.tpl query 21 in stream 6 -select /* TPC-DS query28.tpl 0.36 */ * -from (select avg(ss_list_price) B1_LP - ,count(ss_list_price) B1_CNT - ,count(distinct ss_list_price) B1_CNTD - from store_sales - where ss_quantity between 0 and 5 - and (ss_list_price between 67 and 67+10 - or ss_coupon_amt between 1042 and 1042+1000 - or ss_wholesale_cost between 33 and 33+20)) B1, - (select avg(ss_list_price) B2_LP - ,count(ss_list_price) B2_CNT - ,count(distinct ss_list_price) B2_CNTD - from store_sales - where ss_quantity between 6 and 10 - and (ss_list_price between 103 and 103+10 - or ss_coupon_amt between 11143 and 11143+1000 - or ss_wholesale_cost between 44 and 44+20)) B2, - (select avg(ss_list_price) B3_LP - ,count(ss_list_price) B3_CNT - ,count(distinct ss_list_price) B3_CNTD - from store_sales - where ss_quantity between 11 and 15 - and (ss_list_price between 166 and 166+10 - or ss_coupon_amt between 15330 and 15330+1000 - or ss_wholesale_cost between 13 and 13+20)) B3, - (select avg(ss_list_price) B4_LP - ,count(ss_list_price) B4_CNT - ,count(distinct ss_list_price) B4_CNTD - from store_sales - where ss_quantity between 16 and 20 - and (ss_list_price between 162 and 162+10 - or ss_coupon_amt between 14031 and 14031+1000 - or ss_wholesale_cost between 11 and 11+20)) B4, - (select avg(ss_list_price) B5_LP - ,count(ss_list_price) B5_CNT - ,count(distinct ss_list_price) B5_CNTD - from store_sales - where ss_quantity between 21 and 25 - and (ss_list_price between 30 and 30+10 - or ss_coupon_amt between 10392 and 10392+1000 - or ss_wholesale_cost between 39 and 39+20)) B5, - (select avg(ss_list_price) B6_LP - ,count(ss_list_price) B6_CNT - ,count(distinct ss_list_price) B6_CNTD - from store_sales - where ss_quantity between 26 and 30 - and (ss_list_price between 181 and 181+10 - or ss_coupon_amt between 2773 and 2773+1000 - or ss_wholesale_cost between 29 and 29+20)) B6 -limit 100; - --- end template query28.tpl query 21 in stream 6 --- start template query87.tpl query 22 in stream 6 -select /* TPC-DS query87.tpl 0.77 */ count(*) -from ((select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1190 and 1190+11) - except - (select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1190 and 1190+11) - except - (select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1190 and 1190+11) -) cool_cust -; - --- end template query87.tpl query 22 in stream 6 --- start template query18a.tpl query 23 in stream 6 -with /* TPC-DS query18a.tpl 0.90 */ results as - (select i_item_id, - ca_country, - ca_state, - ca_county, - cast(cs_quantity as decimal(12,2)) agg1, - cast(cs_list_price as decimal(12,2)) agg2, - cast(cs_coupon_amt as decimal(12,2)) agg3, - cast(cs_sales_price as decimal(12,2)) agg4, - cast(cs_net_profit as decimal(12,2)) agg5, - cast(c_birth_year as decimal(12,2)) agg6, - cast(cd1.cd_dep_count as decimal(12,2)) agg7 - from catalog_sales, customer_demographics cd1, customer_demographics cd2, customer, customer_address, date_dim, item - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd1.cd_demo_sk and - cs_bill_customer_sk = c_customer_sk and - cd1.cd_gender = 'F' and - cd1.cd_education_status = '2 yr Degree' and - c_current_cdemo_sk = cd2.cd_demo_sk and - c_current_addr_sk = ca_address_sk and - c_birth_month in (12,11,6,9,8,2) and - d_year = 2002 and - ca_state in ('MA','MS','KY','AK','VA','AL','GA') - ) - select i_item_id, ca_country, ca_state, ca_county, agg1, agg2, agg3, agg4, agg5, agg6, agg7 - from ( - select i_item_id, ca_country, ca_state, ca_county, avg(agg1) agg1, - avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state, ca_county - union all - select i_item_id, ca_country, ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state - union all - select i_item_id, ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country - union all - select i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - ) foo - order by ca_country, ca_state, ca_county, i_item_id - limit 100; - --- end template query18a.tpl query 23 in stream 6 --- start template query74.tpl query 24 in stream 6 -with /* TPC-DS query74.tpl 0.76 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,max(ss_net_paid) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1998,1998+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,max(ws_net_paid) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - and d_year in (1998,1998+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - ) - select - t_s_secyear.customer_id, t_s_secyear.customer_first_name, t_s_secyear.customer_last_name - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.year = 1998 - and t_s_secyear.year = 1998+1 - and t_w_firstyear.year = 1998 - and t_w_secyear.year = 1998+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - order by 1,3,2 -limit 100; - --- end template query74.tpl query 24 in stream 6 --- start template query6.tpl query 25 in stream 6 -select /* TPC-DS query6.tpl 0.58 */ a.ca_state state, count(*) cnt - from customer_address a - ,customer c - ,store_sales s - ,date_dim d - ,item i - where a.ca_address_sk = c.c_current_addr_sk - and c.c_customer_sk = s.ss_customer_sk - and s.ss_sold_date_sk = d.d_date_sk - and s.ss_item_sk = i.i_item_sk - and d.d_month_seq = - (select distinct (d_month_seq) - from date_dim - where d_year = 1998 - and d_moy = 1 ) - and i.i_current_price > 1.2 * - (select avg(j.i_current_price) - from item j - where j.i_category = i.i_category) - group by a.ca_state - having count(*) >= 10 - order by cnt, a.ca_state - limit 100; - --- end template query6.tpl query 25 in stream 6 --- start template query65.tpl query 26 in stream 6 -select /* TPC-DS query65.tpl 0.71 */ - s_store_name, - i_item_desc, - sc.revenue, - i_current_price, - i_wholesale_cost, - i_brand - from store, item, - (select ss_store_sk, avg(revenue) as ave - from - (select ss_store_sk, ss_item_sk, - sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1195 and 1195+11 - group by ss_store_sk, ss_item_sk) sa - group by ss_store_sk) sb, - (select ss_store_sk, ss_item_sk, sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1195 and 1195+11 - group by ss_store_sk, ss_item_sk) sc - where sb.ss_store_sk = sc.ss_store_sk and - sc.revenue <= 0.1 * sb.ave and - s_store_sk = sc.ss_store_sk and - i_item_sk = sc.ss_item_sk - order by s_store_name, i_item_desc -limit 100; - --- end template query65.tpl query 26 in stream 6 --- start template query84.tpl query 27 in stream 6 -select /* TPC-DS query84.tpl 0.80 */ c_customer_id as customer_id - , coalesce(c_last_name,'') || ', ' || coalesce(c_first_name,'') as customername - from customer - ,customer_address - ,customer_demographics - ,household_demographics - ,income_band - ,store_returns - where ca_city = 'Spring Valley' - and c_current_addr_sk = ca_address_sk - and ib_lower_bound >= 6856 - and ib_upper_bound <= 6856 + 50000 - and ib_income_band_sk = hd_income_band_sk - and cd_demo_sk = c_current_cdemo_sk - and hd_demo_sk = c_current_hdemo_sk - and sr_cdemo_sk = cd_demo_sk - order by c_customer_id - limit 100; - --- end template query84.tpl query 27 in stream 6 --- start template query14a.tpl query 28 in stream 6 -with /* TPC-DS query14a.tpl 0.69 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1999 AND 1999 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1999 AND 1999 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1999 AND 1999 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as - (select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2) x) -, - results AS -(select channel, i_brand_id, i_class_id, i_category_id, sum(sales) sum_sales, sum(number_sales) number_sales - from ( - select 'store' channel, i_brand_id,i_class_id - ,i_category_id,sum(ss_quantity*ss_list_price) sales - , count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1999+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales) - union all - select 'catalog' channel, i_brand_id,i_class_id,i_category_id, sum(cs_quantity*cs_list_price) sales, count(*) number_sales - from catalog_sales - ,item - ,date_dim - where cs_item_sk in (select ss_item_sk from cross_items) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1999+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(cs_quantity*cs_list_price) > (select average_sales from avg_sales) - union all - select 'web' channel, i_brand_id,i_class_id,i_category_id, sum(ws_quantity*ws_list_price) sales , count(*) number_sales - from web_sales - ,item - ,date_dim - where ws_item_sk in (select ss_item_sk from cross_items) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1999+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ws_quantity*ws_list_price) > (select average_sales from avg_sales) - ) y - group by channel, i_brand_id,i_class_id,i_category_id) - - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales -from ( - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales from results - union - select channel, i_brand_id, i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id, i_class_id - union - select channel, i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id - union - select channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel - union - select null as channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results) z -order by channel, i_brand_id, i_class_id, i_category_id - limit 100; -with /* TPC-DS query14a.tpl 0.69 part2 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1999 AND 1999 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1999 AND 1999 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1999 AND 1999 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as -(select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2) x) - select this_year.channel ty_channel - ,this_year.i_brand_id ty_brand - ,this_year.i_class_id ty_class - ,this_year.i_category_id ty_category - ,this_year.sales ty_sales - ,this_year.number_sales ty_number_sales - ,last_year.channel ly_channel - ,last_year.i_brand_id ly_brand - ,last_year.i_class_id ly_class - ,last_year.i_category_id ly_category - ,last_year.sales ly_sales - ,last_year.number_sales ly_number_sales -from - (select 'store' channel, i_brand_id,i_class_id,i_category_id - ,sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1999 + 1 - and d_moy = 12 - and d_dom = 8) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) this_year, - (select 'store' channel, i_brand_id,i_class_id - ,i_category_id, sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1999 - and d_moy = 12 - and d_dom = 8) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) last_year - where this_year.i_brand_id= last_year.i_brand_id - and this_year.i_class_id = last_year.i_class_id - and this_year.i_category_id = last_year.i_category_id - order by this_year.channel, this_year.i_brand_id, this_year.i_class_id, this_year.i_category_id - limit 100; - --- end template query14a.tpl query 28 in stream 6 --- start template query38.tpl query 29 in stream 6 -select /* TPC-DS query38.tpl 0.54 */ count(*) from ( - select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1212 and 1212 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1212 and 1212 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1212 and 1212 + 11 -) hot_cust -limit 100; - --- end template query38.tpl query 29 in stream 6 --- start template query24.tpl query 30 in stream 6 -with /* TPC-DS query24.tpl 0.92 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_ext_sales_price) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip -and s_market_id=10 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'beige' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; -with /* TPC-DS query24.tpl 0.92 part2 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_ext_sales_price) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip - and s_market_id = 10 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'plum' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; - --- end template query24.tpl query 30 in stream 6 --- start template query42.tpl query 31 in stream 6 -select /* TPC-DS query42.tpl 0.61 */ dt.d_year - ,item.i_category_id - ,item.i_category - ,sum(ss_ext_sales_price) - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=11 - and dt.d_year=1999 - group by dt.d_year - ,item.i_category_id - ,item.i_category - order by sum(ss_ext_sales_price) desc,dt.d_year - ,item.i_category_id - ,item.i_category -limit 100 ; - --- end template query42.tpl query 31 in stream 6 --- start template query29.tpl query 32 in stream 6 -select /* TPC-DS query29.tpl 0.53 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,stddev_samp(ss_quantity) as store_sales_quantity - ,stddev_samp(sr_return_quantity) as store_returns_quantity - ,stddev_samp(cs_quantity) as catalog_sales_quantity - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 2000 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 4 + 3 - and d2.d_year = 2000 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_year in (2000,2000+1,2000+2) - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query29.tpl query 32 in stream 6 --- start template query72.tpl query 33 in stream 6 -select /* TPC-DS query72.tpl 0.87 */ i_item_desc - ,w_warehouse_name - ,d1.d_week_seq - ,sum(case when p_promo_sk is null then 1 else 0 end) no_promo - ,sum(case when p_promo_sk is not null then 1 else 0 end) promo - ,count(*) total_cnt -from catalog_sales -join inventory on (cs_item_sk = inv_item_sk) -join warehouse on (w_warehouse_sk=inv_warehouse_sk) -join item on (i_item_sk = cs_item_sk) -join customer_demographics on (cs_bill_cdemo_sk = cd_demo_sk) -join household_demographics on (cs_bill_hdemo_sk = hd_demo_sk) -join date_dim d1 on (cs_sold_date_sk = d1.d_date_sk) -join date_dim d2 on (inv_date_sk = d2.d_date_sk) -join date_dim d3 on (cs_ship_date_sk = d3.d_date_sk) -left outer join promotion on (cs_promo_sk=p_promo_sk) -left outer join catalog_returns on (cr_item_sk = cs_item_sk and cr_order_number = cs_order_number) -where d1.d_week_seq = d2.d_week_seq - and inv_quantity_on_hand < cs_quantity - and d3.d_date > d1.d_date + 5 - and hd_buy_potential = '1001-5000' - and d1.d_year = 2001 - and cd_marital_status = 'M' -group by i_item_desc,w_warehouse_name,d1.d_week_seq -order by total_cnt desc, i_item_desc, w_warehouse_name, d_week_seq -limit 100; - --- end template query72.tpl query 33 in stream 6 --- start template query23.tpl query 34 in stream 6 -with /* TPC-DS query23.tpl 0.68 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (1998,1998+1,1998+2,1998+3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1998,1998+1,1998+2,1998+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * -from - max_store_sales)) - select sum(sales) - from (select cs_quantity*cs_list_price sales - from catalog_sales - ,date_dim - where d_year = 1998 - and d_moy = 2 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - union all - select ws_quantity*ws_list_price sales - from web_sales - ,date_dim - where d_year = 1998 - and d_moy = 2 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer)) - limit 100; -with /* TPC-DS query23.tpl 0.68 part2 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (1998,1998 + 1,1998 + 2,1998 + 3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1998,1998+1,1998+2,1998+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * - from max_store_sales)) - select c_last_name,c_first_name,sales - from (select c_last_name,c_first_name,sum(cs_quantity*cs_list_price) sales - from catalog_sales - ,customer - ,date_dim - where d_year = 1998 - and d_moy = 2 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and cs_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name - union all - select c_last_name,c_first_name,sum(ws_quantity*ws_list_price) sales - from web_sales - ,customer - ,date_dim - where d_year = 1998 - and d_moy = 2 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and ws_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name) - order by c_last_name,c_first_name,sales - limit 100; - --- end template query23.tpl query 34 in stream 6 --- start template query26.tpl query 35 in stream 6 -select /* TPC-DS query26.tpl 0.85 */ i_item_id, - avg(cs_quantity) agg1, - avg(cs_list_price) agg2, - avg(cs_coupon_amt) agg3, - avg(cs_sales_price) agg4 - from catalog_sales, customer_demographics, date_dim, item, promotion - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd_demo_sk and - cs_promo_sk = p_promo_sk and - cd_gender = 'M' and - cd_marital_status = 'U' and - cd_education_status = '2 yr Degree' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 2000 - group by i_item_id - order by i_item_id - limit 100; - --- end template query26.tpl query 35 in stream 6 --- start template query69.tpl query 36 in stream 6 -select /* TPC-DS query69.tpl 0.28 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_state in ('KY','MN','MT') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2003 and - d_moy between 4 and 4+2) and - (not exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2003 and - d_moy between 4 and 4+2) and - not exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2003 and - d_moy between 4 and 4+2)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - limit 100; - --- end template query69.tpl query 36 in stream 6 --- start template query47.tpl query 37 in stream 6 -with /* TPC-DS query47.tpl 0.42 */ v1 as( - select i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, - s_store_name, s_company_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - s_store_name, s_company_name - order by d_year, d_moy) rn - from item, store_sales, date_dim, store - where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - ( - d_year = 1999 or - ( d_year = 1999-1 and d_moy =12) or - ( d_year = 1999+1 and d_moy =1) - ) - group by i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy), - v2 as( - select v1.i_brand - ,v1.d_year, v1.d_moy - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1.s_store_name = v1_lag.s_store_name and - v1.s_store_name = v1_lead.s_store_name and - v1.s_company_name = v1_lag.s_company_name and - v1.s_company_name = v1_lead.s_company_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 1999 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, psum - limit 100; - --- end template query47.tpl query 37 in stream 6 --- start template query82.tpl query 38 in stream 6 -select /* TPC-DS query82.tpl 0.67 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, store_sales - where i_current_price between 32 and 32+30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('1999-04-14' as date) and dateadd(day,60,cast('1999-04-14' as date)) - and i_manufact_id in (520,934,67,55) - and inv_quantity_on_hand between 100 and 500 - and ss_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query82.tpl query 38 in stream 6 --- start template query31.tpl query 39 in stream 6 -with /* TPC-DS query31.tpl 0.50 */ ss as - (select ca_county,d_qoy, d_year,sum(ss_ext_sales_price) as store_sales - from store_sales,date_dim,customer_address - where ss_sold_date_sk = d_date_sk - and ss_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year), - ws as - (select ca_county,d_qoy, d_year,sum(ws_ext_sales_price) as web_sales - from web_sales,date_dim,customer_address - where ws_sold_date_sk = d_date_sk - and ws_bill_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year) - select - ss1.ca_county - ,ss1.d_year - ,ws2.web_sales/ws1.web_sales web_q1_q2_increase - ,ss2.store_sales/ss1.store_sales store_q1_q2_increase - ,ws3.web_sales/ws2.web_sales web_q2_q3_increase - ,ss3.store_sales/ss2.store_sales store_q2_q3_increase - from - ss ss1 - ,ss ss2 - ,ss ss3 - ,ws ws1 - ,ws ws2 - ,ws ws3 - where - ss1.d_qoy = 1 - and ss1.d_year = 1999 - and ss1.ca_county = ss2.ca_county - and ss2.d_qoy = 2 - and ss2.d_year = 1999 - and ss2.ca_county = ss3.ca_county - and ss3.d_qoy = 3 - and ss3.d_year = 1999 - and ss1.ca_county = ws1.ca_county - and ws1.d_qoy = 1 - and ws1.d_year = 1999 - and ws1.ca_county = ws2.ca_county - and ws2.d_qoy = 2 - and ws2.d_year = 1999 - and ws1.ca_county = ws3.ca_county - and ws3.d_qoy = 3 - and ws3.d_year =1999 - and case when ws1.web_sales > 0 then ws2.web_sales/ws1.web_sales else null end - > case when ss1.store_sales > 0 then ss2.store_sales/ss1.store_sales else null end - and case when ws2.web_sales > 0 then ws3.web_sales/ws2.web_sales else null end - > case when ss2.store_sales > 0 then ss3.store_sales/ss2.store_sales else null end - order by web_q1_q2_increase; - --- end template query31.tpl query 39 in stream 6 --- start template query59.tpl query 40 in stream 6 -with /* TPC-DS query59.tpl 0.30 */ wss as - (select d_week_seq, - ss_store_sk, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - group by d_week_seq,ss_store_sk - ) - select s_store_name1,s_store_id1,d_week_seq1 - ,sun_sales1/sun_sales2,mon_sales1/mon_sales2 - ,tue_sales1/tue_sales2,wed_sales1/wed_sales2,thu_sales1/thu_sales2 - ,fri_sales1/fri_sales2,sat_sales1/sat_sales2 - from - (select s_store_name s_store_name1,wss.d_week_seq d_week_seq1 - ,s_store_id s_store_id1,sun_sales sun_sales1 - ,mon_sales mon_sales1,tue_sales tue_sales1 - ,wed_sales wed_sales1,thu_sales thu_sales1 - ,fri_sales fri_sales1,sat_sales sat_sales1 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1181 and 1181 + 11) y, - (select s_store_name s_store_name2,wss.d_week_seq d_week_seq2 - ,s_store_id s_store_id2,sun_sales sun_sales2 - ,mon_sales mon_sales2,tue_sales tue_sales2 - ,wed_sales wed_sales2,thu_sales thu_sales2 - ,fri_sales fri_sales2,sat_sales sat_sales2 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1181+ 12 and 1181 + 23) x - where s_store_id1=s_store_id2 - and d_week_seq1=d_week_seq2-52 - order by s_store_name1,s_store_id1,d_week_seq1 -limit 100; - --- end template query59.tpl query 40 in stream 6 --- start template query49.tpl query 41 in stream 6 -select /* TPC-DS query49.tpl 0.48 */ channel, item, return_ratio, return_rank, currency_rank from - (select - 'web' as channel - ,web.item - ,web.return_ratio - ,web.return_rank - ,web.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select ws.ws_item_sk as item - ,(cast(sum(coalesce(wr.wr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(wr.wr_return_amt,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - web_sales ws left outer join web_returns wr - on (ws.ws_order_number = wr.wr_order_number and - ws.ws_item_sk = wr.wr_item_sk) - ,date_dim - where - wr.wr_return_amt > 10000 - and ws.ws_net_profit > 1 - and ws.ws_net_paid > 0 - and ws.ws_quantity > 0 - and ws_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 12 - group by ws.ws_item_sk - ) in_web - ) web - where - ( - web.return_rank <= 10 - or - web.currency_rank <= 10 - ) - union - select - 'catalog' as channel - ,catalog.item - ,catalog.return_ratio - ,catalog.return_rank - ,catalog.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select - cs.cs_item_sk as item - ,(cast(sum(coalesce(cr.cr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(cr.cr_return_amount,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - catalog_sales cs left outer join catalog_returns cr - on (cs.cs_order_number = cr.cr_order_number and - cs.cs_item_sk = cr.cr_item_sk) - ,date_dim - where - cr.cr_return_amount > 10000 - and cs.cs_net_profit > 1 - and cs.cs_net_paid > 0 - and cs.cs_quantity > 0 - and cs_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 12 - group by cs.cs_item_sk - ) in_cat - ) catalog - where - ( - catalog.return_rank <= 10 - or - catalog.currency_rank <=10 - ) - union - select - 'store' as channel - ,store.item - ,store.return_ratio - ,store.return_rank - ,store.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select sts.ss_item_sk as item - ,(cast(sum(coalesce(sr.sr_return_quantity,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(sr.sr_return_amt,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - store_sales sts left outer join store_returns sr - on (sts.ss_ticket_number = sr.sr_ticket_number and sts.ss_item_sk = sr.sr_item_sk) - ,date_dim - where - sr.sr_return_amt > 10000 - and sts.ss_net_profit > 1 - and sts.ss_net_paid > 0 - and sts.ss_quantity > 0 - and ss_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 12 - group by sts.ss_item_sk - ) in_store - ) store - where ( - store.return_rank <= 10 - or - store.currency_rank <= 10 - ) - ) - order by 1,4,5,2 - limit 100; - --- end template query49.tpl query 41 in stream 6 --- start template query33.tpl query 42 in stream 6 -with /* TPC-DS query33.tpl 0.22 */ ss as ( - select - i_manufact_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Jewelry')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 5 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -7 - group by i_manufact_id), - cs as ( - select - i_manufact_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Jewelry')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 5 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -7 - group by i_manufact_id), - ws as ( - select - i_manufact_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Jewelry')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 5 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -7 - group by i_manufact_id) - select i_manufact_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_manufact_id - order by total_sales -limit 100; - --- end template query33.tpl query 42 in stream 6 --- start template query86a.tpl query 43 in stream 6 -with /* TPC-DS query86a.tpl 0.11 */ results as -( select sum(ws_net_paid) as total_sum, i_category, i_class, 0 as g_category, 0 as g_class - from - web_sales - ,date_dim d1 - ,item - where - d1.d_month_seq between 1177 and 1177+11 - and d1.d_date_sk = ws_sold_date_sk - and i_item_sk = ws_item_sk - group by i_category,i_class - ) , - - results_rollup as -( select total_sum ,i_category ,i_class, g_category, g_class, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum, i_category, NULL as i_class, 0 as g_category, 1 as g_class, 1 as lochierarchy from results group by i_category - union - select sum(total_sum) as total_sum, NULL as i_category, NULL as i_class, 1 as g_category, 1 as g_class, 2 as lochierarchy from results) - select - total_sum ,i_category ,i_class, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_class = 0 then i_category end - order by total_sum desc) as rank_within_parent - from - results_rollup - order by - lochierarchy desc, - case when lochierarchy = 0 then i_category end, - rank_within_parent - limit 100; - --- end template query86a.tpl query 43 in stream 6 --- start template query99.tpl query 44 in stream 6 -select /* TPC-DS query99.tpl 0.94 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 30) and - (cs_ship_date_sk - cs_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 60) and - (cs_ship_date_sk - cs_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 90) and - (cs_ship_date_sk - cs_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - catalog_sales - ,warehouse - ,ship_mode - ,call_center - ,date_dim -where - d_month_seq between 1191 and 1191 + 11 -and cs_ship_date_sk = d_date_sk -and cs_warehouse_sk = w_warehouse_sk -and cs_ship_mode_sk = sm_ship_mode_sk -and cs_call_center_sk = cc_call_center_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -limit 100; - --- end template query99.tpl query 44 in stream 6 --- start template query4.tpl query 45 in stream 6 -with /* TPC-DS query4.tpl 0.93 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(((ss_ext_list_price-ss_ext_wholesale_cost-ss_ext_discount_amt)+ss_ext_sales_price)/2) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((cs_ext_list_price-cs_ext_wholesale_cost-cs_ext_discount_amt)+cs_ext_sales_price)/2) ) year_total - ,'c' sale_type - from customer - ,catalog_sales - ,date_dim - where c_customer_sk = cs_bill_customer_sk - and cs_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year -union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((ws_ext_list_price-ws_ext_wholesale_cost-ws_ext_discount_amt)+ws_ext_sales_price)/2) ) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_email_address - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_c_firstyear - ,year_total t_c_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_c_secyear.customer_id - and t_s_firstyear.customer_id = t_c_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_c_firstyear.sale_type = 'c' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_c_secyear.sale_type = 'c' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 1999 - and t_s_secyear.dyear = 1999+1 - and t_c_firstyear.dyear = 1999 - and t_c_secyear.dyear = 1999+1 - and t_w_firstyear.dyear = 1999 - and t_w_secyear.dyear = 1999+1 - and t_s_firstyear.year_total > 0 - and t_c_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_email_address -limit 100; - --- end template query4.tpl query 45 in stream 6 --- start template query45.tpl query 46 in stream 6 -select /* TPC-DS query45.tpl 0.18 */ ca_zip, ca_city, sum(ws_sales_price) - from web_sales, customer, customer_address, date_dim, item - where ws_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ws_item_sk = i_item_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', '85392', '85460', '80348', '81792') - or - i_item_id in (select i_item_id - from item - where i_item_sk in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29) - ) - ) - and ws_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 2000 - group by ca_zip, ca_city - order by ca_zip, ca_city - limit 100; - --- end template query45.tpl query 46 in stream 6 --- start template query85.tpl query 47 in stream 6 -select /* TPC-DS query85.tpl 0.33 */ substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) - from web_sales, web_returns, web_page, customer_demographics cd1, - customer_demographics cd2, customer_address, date_dim, reason - where ws_web_page_sk = wp_web_page_sk - and ws_item_sk = wr_item_sk - and ws_order_number = wr_order_number - and ws_sold_date_sk = d_date_sk and d_year = 2002 - and cd1.cd_demo_sk = wr_refunded_cdemo_sk - and cd2.cd_demo_sk = wr_returning_cdemo_sk - and ca_address_sk = wr_refunded_addr_sk - and r_reason_sk = wr_reason_sk - and - ( - ( - cd1.cd_marital_status = 'D' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'College' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 100.00 and 150.00 - ) - or - ( - cd1.cd_marital_status = 'M' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = '4 yr Degree' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 50.00 and 100.00 - ) - or - ( - cd1.cd_marital_status = 'W' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Primary' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ca_country = 'United States' - and - ca_state in ('CA', 'MT', 'WI') - and ws_net_profit between 100 and 200 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('GA', 'WV', 'KS') - and ws_net_profit between 150 and 300 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('AR', 'WA', 'IL') - and ws_net_profit between 50 and 250 - ) - ) -group by r_reason_desc -order by substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) -limit 100; - --- end template query85.tpl query 47 in stream 6 --- start template query8.tpl query 48 in stream 6 -select /* TPC-DS query8.tpl 0.63 */ s_store_name - ,sum(ss_net_profit) - from store_sales - ,date_dim - ,store, - (select ca_zip - from ( - SELECT substring(ca_zip,1,5) ca_zip - FROM customer_address - WHERE substring(ca_zip,1,5) IN ( - '47623','83749','87078','71403','21711','64297', - '80579','46884','91366','34975','44737', - '69027','91387','23828','53317','46129', - '31399','92670','99103','60999','65896', - '69247','65518','54562','90318','19444', - '95034','16666','43130','97213','15176', - '53293','94336','27926','72771','62412', - '60962','36896','22165','77722','55558', - '77882','70840','43043','30487','90320', - '14510','66343','61017','86201','76084', - '77435','57867','21792','75084','47717', - '99987','16995','51629','45318','71600', - '69479','53073','93205','93944','77696', - '68167','96170','45857','58363','19559', - '40311','35190','53637','61492','89387', - '39188','43906','81523','71449','11878', - '23758','78854','62137','84981','39513', - '60825','82993','33374','85061','13174', - '84743','76056','23640','51323','46153', - '88661','86783','20619','41060','45330', - '41324','85785','72392','99217','33478', - '93099','83597','44035','33741','29209', - '21794','70063','11509','79393','16817', - '33528','90297','96040','18085','20149', - '52760','63465','56145','20103','16457', - '81540','50417','55168','42311','81681', - '43371','51684','70984','15004','35751', - '14041','16243','93791','65318','35537', - '87521','71024','37141','40115','73383', - '62386','80962','11798','97528','16365', - '26679','98109','64089','71888','48829', - '44106','76773','77065','81514','39927', - '14877','63400','60840','74885','63788', - '11570','62581','94195','23966','99473', - '26600','94192','81345','81887','94168', - '78383','92771','19084','29992','76964', - '13044','44329','25878','30870','62698', - '31069','81940','23350','63112','16326', - '36292','64470','16825','30669','40259', - '38015','78103','78151','63448','29069', - '90724','11482','76895','46593','62088', - '17882','40452','19114','31729','47210', - '53243','75399','68833','45165','31384', - '86659','25650','63618','55233','59289', - '57195','83201','19472','13234','19876', - '15218','21186','58979','95530','64116', - '22128','39284','95018','12027','62460', - '11448','37461','42227','38960','30092', - '37651','57794','88839','32395','60105', - '83243','24367','81683','28292','60504', - '47864','97269','49065','95943','25193', - '39662','43864','46540','63262','41777', - '58900','30241','16807','64838','32527', - '20459','79037','82857','29683','65624', - '34578','62973','78477','97946','98395', - '70625','80058','18018','58678','50033', - '39582','30494','51211','49231','62536', - '30438','78990','38950','49623','85618', - '75132','36809','46159','10349','92134', - '12541','30239','50459','21135','71136', - '33799','36571','10273','64729','62251', - '66606','54795','40965','98202','41274', - '45472','91162','47273','68582','50784', - '26700','45221','64278','36913','38423', - '36089','68332','54170','47514','86754', - '32827','35715','10429','62138','62811', - '70616','47275','36595','34164','44381', - '87358','89317','71288','40220','74524', - '20848','60781','30912','77572','57641', - '75713','65049','89143','90901','24431', - '33107','49192','56294','67822','57900', - '22994','41625','15442','58063','88841', - '40553','48347','25689','12950','36948', - '90304','81670','87684','36677','37390', - '14073','59110','53722','93810','68556', - '87500','69232','83332','86778','54526', - '72021','88920','66691','88741','92133', - '34874','39676','13300','45575','72992', - '26122','33462','44448','27855','82655', - '51143','83549','93630','92723') - intersect - select ca_zip - from (SELECT substring(ca_zip,1,5) ca_zip,count(*) cnt - FROM customer_address, customer - WHERE ca_address_sk = c_current_addr_sk and - c_preferred_cust_flag='Y' - group by ca_zip - having count(*) > 10)A1)A2) V1 - where ss_store_sk = s_store_sk - and ss_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 2002 - and (substring(s_zip,1,2) = substring(V1.ca_zip,1,2)) - group by s_store_name - order by s_store_name - limit 100; - --- end template query8.tpl query 48 in stream 6 --- start template query19.tpl query 49 in stream 6 -select /* TPC-DS query19.tpl 0.8 */ i_brand_id brand_id, i_brand brand, i_manufact_id, i_manufact, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item,customer,customer_address,store - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=12 - and d_moy=11 - and d_year=2002 - and ss_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and substring(ca_zip,1,5) <> substring(s_zip,1,5) - and ss_store_sk = s_store_sk - group by i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact - order by ext_price desc - ,i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact -limit 100 ; - --- end template query19.tpl query 49 in stream 6 --- start template query61.tpl query 50 in stream 6 -select /* TPC-DS query61.tpl 0.97 */ promotions,total,cast(promotions as decimal(15,4))/cast(total as decimal(15,4))*100 -from - (select sum(ss_ext_sales_price) promotions - from store_sales - ,store - ,promotion - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_promo_sk = p_promo_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -7 - and i_category = 'Jewelry' - and (p_channel_dmail = 'Y' or p_channel_email = 'Y' or p_channel_tv = 'Y') - and s_gmt_offset = -7 - and d_year = 2001 - and d_moy = 11) promotional_sales, - (select sum(ss_ext_sales_price) total - from store_sales - ,store - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -7 - and i_category = 'Jewelry' - and s_gmt_offset = -7 - and d_year = 2001 - and d_moy = 11) all_sales -order by promotions, total -limit 100; - --- end template query61.tpl query 50 in stream 6 --- start template query3.tpl query 51 in stream 6 -select /* TPC-DS query3.tpl 0.45 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_net_profit) sum_agg - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manufact_id = 727 - and dt.d_moy=11 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,sum_agg desc - ,brand_id - limit 100; - --- end template query3.tpl query 51 in stream 6 --- start template query41.tpl query 52 in stream 6 -select /* TPC-DS query41.tpl 0.62 */ distinct(i_product_name) - from item i1 - where i_manufact_id between 905 and 905+40 - and (select count(*) as item_cnt - from item - where (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'burnished' or i_color = 'bisque') and - (i_units = 'Ounce' or i_units = 'Carton') and - (i_size = 'N/A' or i_size = 'large') - ) or - (i_category = 'Women' and - (i_color = 'violet' or i_color = 'floral') and - (i_units = 'N/A' or i_units = 'Bundle') and - (i_size = 'economy' or i_size = 'small') - ) or - (i_category = 'Men' and - (i_color = 'aquamarine' or i_color = 'tan') and - (i_units = 'Dozen' or i_units = 'Unknown') and - (i_size = 'extra large' or i_size = 'medium') - ) or - (i_category = 'Men' and - (i_color = 'peach' or i_color = 'wheat') and - (i_units = 'Oz' or i_units = 'Gross') and - (i_size = 'N/A' or i_size = 'large') - ))) or - (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'mint' or i_color = 'cream') and - (i_units = 'Pound' or i_units = 'Cup') and - (i_size = 'N/A' or i_size = 'large') - ) or - (i_category = 'Women' and - (i_color = 'rose' or i_color = 'peru') and - (i_units = 'Lb' or i_units = 'Tbl') and - (i_size = 'economy' or i_size = 'small') - ) or - (i_category = 'Men' and - (i_color = 'sienna' or i_color = 'saddle') and - (i_units = 'Gram' or i_units = 'Ton') and - (i_size = 'extra large' or i_size = 'medium') - ) or - (i_category = 'Men' and - (i_color = 'dim' or i_color = 'plum') and - (i_units = 'Tsp' or i_units = 'Each') and - (i_size = 'N/A' or i_size = 'large') - )))) > 0 - order by i_product_name - limit 100; - --- end template query41.tpl query 52 in stream 6 --- start template query54.tpl query 53 in stream 6 -with /* TPC-DS query54.tpl 0.81 */ my_customers as ( - select distinct c_customer_sk - , c_current_addr_sk - from - ( select cs_sold_date_sk sold_date_sk, - cs_bill_customer_sk customer_sk, - cs_item_sk item_sk - from catalog_sales - union all - select ws_sold_date_sk sold_date_sk, - ws_bill_customer_sk customer_sk, - ws_item_sk item_sk - from web_sales - ) cs_or_ws_sales, - item, - date_dim, - customer - where sold_date_sk = d_date_sk - and item_sk = i_item_sk - and i_category = 'Music' - and i_class = 'rock' - and c_customer_sk = cs_or_ws_sales.customer_sk - and d_moy = 6 - and d_year = 1999 - ) - , my_revenue as ( - select c_customer_sk, - sum(ss_ext_sales_price) as revenue - from my_customers, - store_sales, - customer_address, - store, - date_dim - where c_current_addr_sk = ca_address_sk - and ca_county = s_county - and ca_state = s_state - and ss_sold_date_sk = d_date_sk - and c_customer_sk = ss_customer_sk - and d_month_seq between (select distinct d_month_seq+1 - from date_dim where d_year = 1999 and d_moy = 6) - and (select distinct d_month_seq+3 - from date_dim where d_year = 1999 and d_moy = 6) - group by c_customer_sk - ) - , segments as - (select cast((revenue/50) as bigint) as segment - from my_revenue - ) - select segment, count(*) as num_customers, segment*50 as segment_base - from segments - group by segment - order by segment, num_customers - limit 100; - --- end template query54.tpl query 53 in stream 6 --- start template query67a.tpl query 54 in stream 6 -with /* TPC-DS query67a.tpl 0.35 */ results as -( select i_category ,i_class ,i_brand ,i_product_name ,d_year ,d_qoy ,d_moy ,s_store_id - ,sum(coalesce(ss_sales_price*ss_quantity,0)) sumsales - from store_sales ,date_dim ,store ,item - where ss_sold_date_sk=d_date_sk - and ss_item_sk=i_item_sk - and ss_store_sk = s_store_sk - and d_month_seq between 1216 and 1216 + 11 - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy,s_store_id) - , - results_rollup as - (select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, s_store_id, sumsales - from results - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy - union all - select i_category, i_class, i_brand, i_product_name, d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year - union all - select i_category, i_class, i_brand, i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name - union all - select i_category, i_class, i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand - union all - select i_category, i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class - union all - select i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category - union all - select null i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results) - - select * -from (select i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rank() over (partition by i_category order by sumsales desc) rk - from results_rollup) dw2 -where rk <= 100 -order by i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rk -limit 100; - --- end template query67a.tpl query 54 in stream 6 --- start template query77a.tpl query 55 in stream 6 -with /* TPC-DS query77a.tpl 0.78 */ ss as - (select s_store_sk, - sum(ss_ext_sales_price) as sales, - sum(ss_net_profit) as profit - from store_sales, - date_dim, - store - where ss_sold_date_sk = d_date_sk - and d_date between cast('2001-08-03' as date) - and dateadd(day,30,cast('2001-08-03' as date)) - and ss_store_sk = s_store_sk - group by s_store_sk) - , - sr as - (select s_store_sk, - sum(sr_return_amt) as returns, - sum(sr_net_loss) as profit_loss - from store_returns, - date_dim, - store - where sr_returned_date_sk = d_date_sk - and d_date between cast('2001-08-03' as date) - and dateadd(day,30,cast('2001-08-03' as date)) - and sr_store_sk = s_store_sk - group by s_store_sk), - cs as - (select cs_call_center_sk, - sum(cs_ext_sales_price) as sales, - sum(cs_net_profit) as profit - from catalog_sales, - date_dim - where cs_sold_date_sk = d_date_sk - and d_date between cast('2001-08-03' as date) - and dateadd(day,30,cast('2001-08-03' as date)) - group by cs_call_center_sk - ), - cr as - (select cr_call_center_sk, - sum(cr_return_amount) as returns, - sum(cr_net_loss) as profit_loss - from catalog_returns, - date_dim - where cr_returned_date_sk = d_date_sk - and d_date between cast('2001-08-03' as date) - and dateadd(day,30,cast('2001-08-03' as date)) - group by cr_call_center_sk), - ws as - ( select wp_web_page_sk, - sum(ws_ext_sales_price) as sales, - sum(ws_net_profit) as profit - from web_sales, - date_dim, - web_page - where ws_sold_date_sk = d_date_sk - and d_date between cast('2001-08-03' as date) - and dateadd(day,30,cast('2001-08-03' as date)) - and ws_web_page_sk = wp_web_page_sk - group by wp_web_page_sk), - wr as - (select wp_web_page_sk, - sum(wr_return_amt) as returns, - sum(wr_net_loss) as profit_loss - from web_returns, - date_dim, - web_page - where wr_returned_date_sk = d_date_sk - and d_date between cast('2001-08-03' as date) - and dateadd(day,30,cast('2001-08-03' as date)) - and wr_web_page_sk = wp_web_page_sk - group by wp_web_page_sk) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , ss.s_store_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ss left join sr - on ss.s_store_sk = sr.s_store_sk - union all - select 'catalog channel' as channel - , cs_call_center_sk as id - , sales - , returns - , (profit - profit_loss) as profit - from cs - , cr - union all - select 'web channel' as channel - , ws.wp_web_page_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ws left join wr - on ws.wp_web_page_sk = wr.wp_web_page_sk - ) x - group by channel, id ) - - select * - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results -) foo -order by channel, id - limit 100; - --- end template query77a.tpl query 55 in stream 6 --- start template query15.tpl query 56 in stream 6 -select /* TPC-DS query15.tpl 0.57 */ ca_zip - ,sum(cs_sales_price) - from catalog_sales - ,customer - ,customer_address - ,date_dim - where cs_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', - '85392', '85460', '80348', '81792') - or ca_state in ('CA','WA','GA') - or cs_sales_price > 500) - and cs_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 1998 - group by ca_zip - order by ca_zip - limit 100; - --- end template query15.tpl query 56 in stream 6 --- start template query51.tpl query 57 in stream 6 -WITH /* TPC-DS query51.tpl 0.46 */ web_v1 as ( -select - ws_item_sk item_sk, d_date, - sum(sum(ws_sales_price)) - over (partition by ws_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from web_sales - ,date_dim -where ws_sold_date_sk=d_date_sk - and d_month_seq between 1219 and 1219+11 - and ws_item_sk is not NULL -group by ws_item_sk, d_date), -store_v1 as ( -select - ss_item_sk item_sk, d_date, - sum(sum(ss_sales_price)) - over (partition by ss_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from store_sales - ,date_dim -where ss_sold_date_sk=d_date_sk - and d_month_seq between 1219 and 1219+11 - and ss_item_sk is not NULL -group by ss_item_sk, d_date) - select * -from (select item_sk - ,d_date - ,web_sales - ,store_sales - ,max(web_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) web_cumulative - ,max(store_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) store_cumulative - from (select case when web.item_sk is not null then web.item_sk else store.item_sk end item_sk - ,case when web.d_date is not null then web.d_date else store.d_date end d_date - ,web.cume_sales web_sales - ,store.cume_sales store_sales - from web_v1 web full outer join store_v1 store on (web.item_sk = store.item_sk - and web.d_date = store.d_date) - )x )y -where web_cumulative > store_cumulative -order by item_sk - ,d_date -limit 100; - --- end template query51.tpl query 57 in stream 6 --- start template query98.tpl query 58 in stream 6 -select /* TPC-DS query98.tpl 0.32 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ss_ext_sales_price) as itemrevenue - ,sum(ss_ext_sales_price)*100/sum(sum(ss_ext_sales_price)) over - (partition by i_class) as revenueratio -from - store_sales - ,item - ,date_dim -where - ss_item_sk = i_item_sk - and i_category in ('Home', 'Shoes', 'Music') - and ss_sold_date_sk = d_date_sk - and d_date between cast('1999-06-29' as date) - and dateadd(day,30,cast('1999-06-29' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio; - --- end template query98.tpl query 58 in stream 6 --- start template query62.tpl query 59 in stream 6 -select /* TPC-DS query62.tpl 0.24 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 30) and - (ws_ship_date_sk - ws_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 60) and - (ws_ship_date_sk - ws_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 90) and - (ws_ship_date_sk - ws_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - web_sales - ,warehouse - ,ship_mode - ,web_site - ,date_dim -where - d_month_seq between 1198 and 1198 + 11 -and ws_ship_date_sk = d_date_sk -and ws_warehouse_sk = w_warehouse_sk -and ws_ship_mode_sk = sm_ship_mode_sk -and ws_web_site_sk = web_site_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -limit 100; - --- end template query62.tpl query 59 in stream 6 --- start template query97.tpl query 60 in stream 6 -with /* TPC-DS query97.tpl 0.38 */ ssci as ( -select ss_customer_sk customer_sk - ,ss_item_sk item_sk -from store_sales,date_dim -where ss_sold_date_sk = d_date_sk - and d_month_seq between 1203 and 1203 + 11 -group by ss_customer_sk - ,ss_item_sk), -csci as( - select cs_bill_customer_sk customer_sk - ,cs_item_sk item_sk -from catalog_sales,date_dim -where cs_sold_date_sk = d_date_sk - and d_month_seq between 1203 and 1203 + 11 -group by cs_bill_customer_sk - ,cs_item_sk) - select sum(case when ssci.customer_sk is not null and csci.customer_sk is null then 1 else 0 end) store_only - ,sum(case when ssci.customer_sk is null and csci.customer_sk is not null then 1 else 0 end) catalog_only - ,sum(case when ssci.customer_sk is not null and csci.customer_sk is not null then 1 else 0 end) store_and_catalog -from ssci full outer join csci on (ssci.customer_sk=csci.customer_sk - and ssci.item_sk = csci.item_sk) -limit 100; - --- end template query97.tpl query 60 in stream 6 --- start template query22a.tpl query 61 in stream 6 -with /* TPC-DS query22a.tpl 0.55 */ results as -(select i_product_name - ,i_brand - ,i_class - ,i_category - ,avg(inv_quantity_on_hand) qoh - from inventory - ,date_dim - ,item --- ,warehouse - where inv_date_sk=d_date_sk - and inv_item_sk=i_item_sk --- and inv_warehouse_sk = w_warehouse_sk - and d_month_seq between 1197 and 1197 + 11 - group by i_product_name,i_brand,i_class,i_category), -results_rollup as -(select i_product_name, i_brand, i_class, i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class,i_category -union all -select i_product_name, i_brand, i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class -union all -select i_product_name, i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand -union all -select i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name -union all -select null i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results) - select i_product_name, i_brand, i_class, i_category,qoh - from results_rollup - order by qoh, i_product_name, i_brand, i_class, i_category -limit 100; - --- end template query22a.tpl query 61 in stream 6 --- start template query48.tpl query 62 in stream 6 -select /* TPC-DS query48.tpl 0.74 */ sum (ss_quantity) - from store_sales, store, customer_demographics, customer_address, date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 1998 - and - ( - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'W' - and - cd_education_status = 'Unknown' - and - ss_sales_price between 100.00 and 150.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'M' - and - cd_education_status = 'College' - and - ss_sales_price between 50.00 and 100.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'U' - and - cd_education_status = '2 yr Degree' - and - ss_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('PA', 'MI', 'GA') - and ss_net_profit between 0 and 2000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('ND', 'IA', 'IN') - and ss_net_profit between 150 and 3000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('MO', 'KS', 'OR') - and ss_net_profit between 50 and 25000 - ) - ) -; - --- end template query48.tpl query 62 in stream 6 --- start template query2.tpl query 63 in stream 6 -with /* TPC-DS query2.tpl 0.84 */ wscs as - (select sold_date_sk - ,sales_price - from (select ws_sold_date_sk sold_date_sk - ,ws_ext_sales_price sales_price - from web_sales - union all - select cs_sold_date_sk sold_date_sk - ,cs_ext_sales_price sales_price - from catalog_sales)), - wswscs as - (select d_week_seq, - sum(case when (d_day_name='Sunday') then sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then sales_price else null end) sat_sales - from wscs - ,date_dim - where d_date_sk = sold_date_sk - group by d_week_seq) - select d_week_seq1 - ,round(sun_sales1/sun_sales2,2) - ,round(mon_sales1/mon_sales2,2) - ,round(tue_sales1/tue_sales2,2) - ,round(wed_sales1/wed_sales2,2) - ,round(thu_sales1/thu_sales2,2) - ,round(fri_sales1/fri_sales2,2) - ,round(sat_sales1/sat_sales2,2) - from - (select wswscs.d_week_seq d_week_seq1 - ,sun_sales sun_sales1 - ,mon_sales mon_sales1 - ,tue_sales tue_sales1 - ,wed_sales wed_sales1 - ,thu_sales thu_sales1 - ,fri_sales fri_sales1 - ,sat_sales sat_sales1 - from wswscs,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 2000) y, - (select wswscs.d_week_seq d_week_seq2 - ,sun_sales sun_sales2 - ,mon_sales mon_sales2 - ,tue_sales tue_sales2 - ,wed_sales wed_sales2 - ,thu_sales thu_sales2 - ,fri_sales fri_sales2 - ,sat_sales sat_sales2 - from wswscs - ,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 2000+1) z - where d_week_seq1=d_week_seq2-53 - order by d_week_seq1; - --- end template query2.tpl query 63 in stream 6 --- start template query79.tpl query 64 in stream 6 -select /* TPC-DS query79.tpl 0.89 */ - c_last_name,c_first_name,substring(s_city,1,30),ss_ticket_number,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,store.s_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (household_demographics.hd_dep_count = 1 or household_demographics.hd_vehicle_count > 4) - and date_dim.d_dow = 1 - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_number_employees between 200 and 295 - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,store.s_city) ms,customer - where ss_customer_sk = c_customer_sk - order by c_last_name,c_first_name,substring(s_city,1,30), profit -limit 100; - --- end template query79.tpl query 64 in stream 6 --- start template query56.tpl query 65 in stream 6 -with /* TPC-DS query56.tpl 0.83 */ ss as ( - select i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where i_item_id in (select - i_item_id -from item -where i_color in ('sandy','saddle','midnight')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 6 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - cs as ( - select i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('sandy','saddle','midnight')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 6 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - ws as ( - select i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('sandy','saddle','midnight')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 6 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id) - select i_item_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by total_sales, - i_item_id - limit 100; - --- end template query56.tpl query 65 in stream 6 --- start template query37.tpl query 66 in stream 6 -select /* TPC-DS query37.tpl 0.31 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, catalog_sales - where i_current_price between 40 and 40 + 30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('2001-03-20' as date) and dateadd(day,60,cast('2001-03-20' as date)) - and i_manufact_id in (984,924,898,766) - and inv_quantity_on_hand between 100 and 500 - and cs_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query37.tpl query 66 in stream 6 --- start template query10.tpl query 67 in stream 6 -select /* TPC-DS query10.tpl 0.26 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3, - cd_dep_count, - count(*) cnt4, - cd_dep_employed_count, - count(*) cnt5, - cd_dep_college_count, - count(*) cnt6 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_county in ('Wood County','Hendry County','Freestone County','Crook County','Livingston County') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 1999 and - d_moy between 3 and 3+3) and - (exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 1999 and - d_moy between 3 ANd 3+3) or - exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 1999 and - d_moy between 3 and 3+3)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count -limit 100; - --- end template query10.tpl query 67 in stream 6 --- start template query90.tpl query 68 in stream 6 -select /* TPC-DS query90.tpl 0.40 */ cast(amc as decimal(15,4))/cast(pmc as decimal(15,4)) am_pm_ratio - from ( select count(*) amc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 11 and 11+1 - and household_demographics.hd_dep_count = 5 - and web_page.wp_char_count between 5000 and 5200) at, - ( select count(*) pmc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 15 and 15+1 - and household_demographics.hd_dep_count = 5 - and web_page.wp_char_count between 5000 and 5200) pt - order by am_pm_ratio - limit 100; - --- end template query90.tpl query 68 in stream 6 --- start template query21.tpl query 69 in stream 6 -select /* TPC-DS query21.tpl 0.14 */ * - from(select w_warehouse_name - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('2000-05-13' as date)) - then inv_quantity_on_hand - else 0 end) as inv_before - ,sum(case when (cast(d_date as date) >= cast ('2000-05-13' as date)) - then inv_quantity_on_hand - else 0 end) as inv_after - from inventory - ,warehouse - ,item - ,date_dim - where i_current_price between 0.99 and 1.49 - and i_item_sk = inv_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('2000-05-13' as date)) - and dateadd(day,30,cast ('2000-05-13' as date)) - group by w_warehouse_name, i_item_id) x - where (case when inv_before > 0 - then inv_after / inv_before - else null - end) between 2.0/3.0 and 3.0/2.0 - order by w_warehouse_name - ,i_item_id - limit 100; - --- end template query21.tpl query 69 in stream 6 --- start template query46.tpl query 70 in stream 6 -select /* TPC-DS query46.tpl 0.23 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and (household_demographics.hd_dep_count = 4 or - household_demographics.hd_vehicle_count= -1) - and date_dim.d_dow in (6,0) - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_city in ('Oak Ridge','Mount Carmel','Canton','Farmington','Fairmount') - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,ca_city) dn,customer,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - limit 100; - --- end template query46.tpl query 70 in stream 6 --- start template query83.tpl query 71 in stream 6 -with /* TPC-DS query83.tpl 0.96 */ sr_items as - (select i_item_id item_id, - sum(sr_return_quantity) sr_item_qty - from store_returns, - item, - date_dim - where sr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2001-05-07','2001-10-16','2001-11-17'))) - and sr_returned_date_sk = d_date_sk - group by i_item_id), - cr_items as - (select i_item_id item_id, - sum(cr_return_quantity) cr_item_qty - from catalog_returns, - item, - date_dim - where cr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2001-05-07','2001-10-16','2001-11-17'))) - and cr_returned_date_sk = d_date_sk - group by i_item_id), - wr_items as - (select i_item_id item_id, - sum(wr_return_quantity) wr_item_qty - from web_returns, - item, - date_dim - where wr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2001-05-07','2001-10-16','2001-11-17'))) - and wr_returned_date_sk = d_date_sk - group by i_item_id) - select sr_items.item_id - ,sr_item_qty - ,sr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 sr_dev - ,cr_item_qty - ,cr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 cr_dev - ,wr_item_qty - ,wr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 wr_dev - ,(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 average - from sr_items - ,cr_items - ,wr_items - where sr_items.item_id=cr_items.item_id - and sr_items.item_id=wr_items.item_id - order by sr_items.item_id - ,sr_item_qty - limit 100; - --- end template query83.tpl query 71 in stream 6 --- start template query96.tpl query 72 in stream 6 -select /* TPC-DS query96.tpl 0.1 */ count(*) -from store_sales - ,household_demographics - ,time_dim, store -where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and household_demographics.hd_dep_count = 4 - and store.s_store_name = 'ese' -order by count(*) -limit 100; - --- end template query96.tpl query 72 in stream 6 --- start template query68.tpl query 73 in stream 6 -select /* TPC-DS query68.tpl 0.95 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,extended_price - ,extended_tax - ,list_price - from (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_ext_sales_price) extended_price - ,sum(ss_ext_list_price) list_price - ,sum(ss_ext_tax) extended_tax - from store_sales - ,date_dim - ,store - ,household_demographics - ,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_dep_count = 5 or - household_demographics.hd_vehicle_count= 1) - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_city in ('Somerset','Portland') - group by ss_ticket_number - ,ss_customer_sk - ,ss_addr_sk,ca_city) dn - ,customer - ,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,ss_ticket_number - limit 100; - --- end template query68.tpl query 73 in stream 6 --- start template query63.tpl query 74 in stream 6 -select /* TPC-DS query63.tpl 0.27 */ * -from (select i_manager_id - ,sum(ss_sales_price) sum_sales - ,avg(sum(ss_sales_price)) over (partition by i_manager_id) avg_monthly_sales - from item - ,store_sales - ,date_dim - ,store - where ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and d_month_seq in (1206,1206+1,1206+2,1206+3,1206+4,1206+5,1206+6,1206+7,1206+8,1206+9,1206+10,1206+11) - and (( i_category in ('Books','Children','Electronics') - and i_class in ('personal','portable','reference','self-help') - and i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) - or( i_category in ('Women','Music','Men') - and i_class in ('accessories','classical','fragrances','pants') - and i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manager_id, d_moy) tmp1 -where case when avg_monthly_sales > 0 then abs (sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 -order by i_manager_id - ,avg_monthly_sales - ,sum_sales -limit 100; - --- end template query63.tpl query 74 in stream 6 --- start template query92.tpl query 75 in stream 6 -select /* TPC-DS query92.tpl 0.44 */ - sum(ws_ext_discount_amt) as "Excess Discount Amount" -from - web_sales - ,item - ,date_dim -where -i_manufact_id = 332 -and i_item_sk = ws_item_sk -and d_date between '2000-02-07' and - dateadd(day,90,cast('2000-02-07' as date)) -and d_date_sk = ws_sold_date_sk -and ws_ext_discount_amt - > ( - SELECT - 1.3 * avg(ws_ext_discount_amt) - FROM - web_sales - ,date_dim - WHERE - ws_item_sk = i_item_sk - and d_date between '2000-02-07' and - dateadd(day,90,cast('2000-02-07' as date)) - and d_date_sk = ws_sold_date_sk - ) -order by sum(ws_ext_discount_amt) -limit 100; - --- end template query92.tpl query 75 in stream 6 --- start template query27a.tpl query 76 in stream 6 -with /* TPC-DS query27a.tpl 0.16 */ results as - (select i_item_id, - s_state, 0 as g_state, - ss_quantity agg1, - ss_list_price agg2, - ss_coupon_amt agg3, - ss_sales_price agg4 - from store_sales, customer_demographics, date_dim, store, item - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_store_sk = s_store_sk and - ss_cdemo_sk = cd_demo_sk and - cd_gender = 'M' and - cd_marital_status = 'W' and - cd_education_status = '2 yr Degree' and - d_year = 2002 and - s_state in ('NY','GA', 'NM', 'MN', 'NE', 'MN') - ) - - select i_item_id, - s_state, g_state, agg1, agg2, agg3, agg4 - from ( - select i_item_id, s_state, 0 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4 from results - group by i_item_id, s_state - union all - select i_item_id, NULL AS s_state, 1 AS g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as s_state, 1 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - ) foo - order by i_item_id, s_state - limit 100; - --- end template query27a.tpl query 76 in stream 6 --- start template query12.tpl query 77 in stream 6 -select /* TPC-DS query12.tpl 0.64 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ws_ext_sales_price) as itemrevenue - ,sum(ws_ext_sales_price)*100/sum(sum(ws_ext_sales_price)) over - (partition by i_class) as revenueratio -from - web_sales - ,item - ,date_dim -where - ws_item_sk = i_item_sk - and i_category in ('Home', 'Jewelry', 'Shoes') - and ws_sold_date_sk = d_date_sk - and d_date between cast('1999-05-06' as date) - and dateadd(day,30,cast('1999-05-06' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query12.tpl query 77 in stream 6 --- start template query64.tpl query 78 in stream 6 -with /* TPC-DS query64.tpl 0.20 */ cs_ui as - (select cs_item_sk - ,sum(cs_ext_list_price) as sale,sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit) as refund - from catalog_sales - ,catalog_returns - where cs_item_sk = cr_item_sk - and cs_order_number = cr_order_number - group by cs_item_sk - having sum(cs_ext_list_price)>2*sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit)), -cross_sales as - (select i_product_name product_name - ,i_item_sk item_sk - ,s_store_name store_name - ,s_zip store_zip - ,ad1.ca_street_number b_street_number - ,ad1.ca_street_name b_street_name - ,ad1.ca_city b_city - ,ad1.ca_zip b_zip - ,ad2.ca_street_number c_street_number - ,ad2.ca_street_name c_street_name - ,ad2.ca_city c_city - ,ad2.ca_zip c_zip - ,d1.d_year as syear - ,d2.d_year as fsyear - ,d3.d_year s2year - ,count(*) cnt - ,sum(ss_wholesale_cost) s1 - ,sum(ss_list_price) s2 - ,sum(ss_coupon_amt) s3 - FROM store_sales - ,store_returns - ,cs_ui - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,customer - ,customer_demographics cd1 - ,customer_demographics cd2 - ,promotion - ,household_demographics hd1 - ,household_demographics hd2 - ,customer_address ad1 - ,customer_address ad2 - ,income_band ib1 - ,income_band ib2 - ,item - WHERE ss_store_sk = s_store_sk AND - ss_sold_date_sk = d1.d_date_sk AND - ss_customer_sk = c_customer_sk AND - ss_cdemo_sk= cd1.cd_demo_sk AND - ss_hdemo_sk = hd1.hd_demo_sk AND - ss_addr_sk = ad1.ca_address_sk and - ss_item_sk = i_item_sk and - ss_item_sk = sr_item_sk and - ss_ticket_number = sr_ticket_number and - ss_item_sk = cs_ui.cs_item_sk and - c_current_cdemo_sk = cd2.cd_demo_sk AND - c_current_hdemo_sk = hd2.hd_demo_sk AND - c_current_addr_sk = ad2.ca_address_sk and - c_first_sales_date_sk = d2.d_date_sk and - c_first_shipto_date_sk = d3.d_date_sk and - ss_promo_sk = p_promo_sk and - hd1.hd_income_band_sk = ib1.ib_income_band_sk and - hd2.hd_income_band_sk = ib2.ib_income_band_sk and - cd1.cd_marital_status <> cd2.cd_marital_status and - i_color in ('violet','orange','almond','chiffon','slate','black') and - i_current_price between 55 and 55 + 10 and - i_current_price between 55 + 1 and 55 + 15 -group by i_product_name - ,i_item_sk - ,s_store_name - ,s_zip - ,ad1.ca_street_number - ,ad1.ca_street_name - ,ad1.ca_city - ,ad1.ca_zip - ,ad2.ca_street_number - ,ad2.ca_street_name - ,ad2.ca_city - ,ad2.ca_zip - ,d1.d_year - ,d2.d_year - ,d3.d_year -) -select cs1.product_name - ,cs1.store_name - ,cs1.store_zip - ,cs1.b_street_number - ,cs1.b_street_name - ,cs1.b_city - ,cs1.b_zip - ,cs1.c_street_number - ,cs1.c_street_name - ,cs1.c_city - ,cs1.c_zip - ,cs1.syear - ,cs1.cnt - ,cs1.s1 as s11 - ,cs1.s2 as s21 - ,cs1.s3 as s31 - ,cs2.s1 as s12 - ,cs2.s2 as s22 - ,cs2.s3 as s32 - ,cs2.syear - ,cs2.cnt -from cross_sales cs1,cross_sales cs2 -where cs1.item_sk=cs2.item_sk and - cs1.syear = 2000 and - cs2.syear = 2000 + 1 and - cs2.cnt <= cs1.cnt and - cs1.store_name = cs2.store_name and - cs1.store_zip = cs2.store_zip -order by cs1.product_name - ,cs1.store_name - ,cs2.cnt - ,cs1.s1 - ,cs2.s1; - --- end template query64.tpl query 78 in stream 6 --- start template query95.tpl query 79 in stream 6 -with /* TPC-DS query95.tpl 0.43 */ ws_wh as -(select ws1.ws_order_number,ws1.ws_warehouse_sk wh1,ws2.ws_warehouse_sk wh2 - from web_sales ws1,web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) - select - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2000-5-01' and - dateadd(day,60,cast('2000-5-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'IN' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and ws1.ws_order_number in (select ws_order_number - from ws_wh) -and ws1.ws_order_number in (select wr_order_number - from web_returns,ws_wh - where wr_order_number = ws_wh.ws_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query95.tpl query 79 in stream 6 --- start template query39.tpl query 80 in stream 6 -with /* TPC-DS query39.tpl 0.5 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =2002 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=3 - and inv2.d_moy=3+1 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; -with /* TPC-DS query39.tpl 0.5 part2 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =2002 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=3 - and inv2.d_moy=3+1 - and inv1.cov > 1.5 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; - --- end template query39.tpl query 80 in stream 6 --- start template query35a.tpl query 81 in stream 6 -select /* TPC-DS query35a.tpl 0.47 */ - ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - count(*) cnt1, - max(cd_dep_count), - min(cd_dep_count), - avg(cd_dep_count), - cd_dep_employed_count, - count(*) cnt2, - max(cd_dep_employed_count), - min(cd_dep_employed_count), - avg(cd_dep_employed_count), - cd_dep_college_count, - count(*) cnt3, - max(cd_dep_college_count), - min(cd_dep_college_count), - avg(cd_dep_college_count) - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2000 and - d_qoy < 4) and - exists (select * from - (select ws_bill_customer_sk customsk - from web_sales,date_dim - where - ws_sold_date_sk = d_date_sk and - d_year = 2000 and - d_qoy < 4 - union all - select cs_ship_customer_sk customsk - from catalog_sales,date_dim - where - cs_sold_date_sk = d_date_sk and - d_year = 2000 and - d_qoy < 4)x - where x.customsk = c.c_customer_sk) - group by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - limit 100; - --- end template query35a.tpl query 81 in stream 6 --- start template query78.tpl query 82 in stream 6 -with /* TPC-DS query78.tpl 0.10 */ ws as - (select d_year AS ws_sold_year, ws_item_sk, - ws_bill_customer_sk ws_customer_sk, - sum(ws_quantity) ws_qty, - sum(ws_wholesale_cost) ws_wc, - sum(ws_sales_price) ws_sp - from web_sales - left join web_returns on wr_order_number=ws_order_number and ws_item_sk=wr_item_sk - join date_dim on ws_sold_date_sk = d_date_sk - where wr_order_number is null - group by d_year, ws_item_sk, ws_bill_customer_sk - ), -cs as - (select d_year AS cs_sold_year, cs_item_sk, - cs_bill_customer_sk cs_customer_sk, - sum(cs_quantity) cs_qty, - sum(cs_wholesale_cost) cs_wc, - sum(cs_sales_price) cs_sp - from catalog_sales - left join catalog_returns on cr_order_number=cs_order_number and cs_item_sk=cr_item_sk - join date_dim on cs_sold_date_sk = d_date_sk - where cr_order_number is null - group by d_year, cs_item_sk, cs_bill_customer_sk - ), -ss as - (select d_year AS ss_sold_year, ss_item_sk, - ss_customer_sk, - sum(ss_quantity) ss_qty, - sum(ss_wholesale_cost) ss_wc, - sum(ss_sales_price) ss_sp - from store_sales - left join store_returns on sr_ticket_number=ss_ticket_number and ss_item_sk=sr_item_sk - join date_dim on ss_sold_date_sk = d_date_sk - where sr_ticket_number is null - group by d_year, ss_item_sk, ss_customer_sk - ) - select -ss_sold_year, -round(ss_qty/(coalesce(ws_qty,0)+coalesce(cs_qty,0)),2) ratio, -ss_qty store_qty, ss_wc store_wholesale_cost, ss_sp store_sales_price, -coalesce(ws_qty,0)+coalesce(cs_qty,0) other_chan_qty, -coalesce(ws_wc,0)+coalesce(cs_wc,0) other_chan_wholesale_cost, -coalesce(ws_sp,0)+coalesce(cs_sp,0) other_chan_sales_price -from ss -left join ws on (ws_sold_year=ss_sold_year and ws_item_sk=ss_item_sk and ws_customer_sk=ss_customer_sk) -left join cs on (cs_sold_year=ss_sold_year and cs_item_sk=ss_item_sk and cs_customer_sk=ss_customer_sk) -where (coalesce(ws_qty,0)>0 or coalesce(cs_qty, 0)>0) and ss_sold_year=2001 -order by - ss_sold_year, - ss_qty desc, ss_wc desc, ss_sp desc, - other_chan_qty, - other_chan_wholesale_cost, - other_chan_sales_price, - ratio -limit 100; - --- end template query78.tpl query 82 in stream 6 --- start template query57.tpl query 83 in stream 6 -with /* TPC-DS query57.tpl 0.70 */ v1 as( - select i_category, i_brand, - cc_name, - d_year, d_moy, - sum(cs_sales_price) sum_sales, - avg(sum(cs_sales_price)) over - (partition by i_category, i_brand, - cc_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - cc_name - order by d_year, d_moy) rn - from item, catalog_sales, date_dim, call_center - where cs_item_sk = i_item_sk and - cs_sold_date_sk = d_date_sk and - cc_call_center_sk= cs_call_center_sk and - ( - d_year = 2001 or - ( d_year = 2001-1 and d_moy =12) or - ( d_year = 2001+1 and d_moy =1) - ) - group by i_category, i_brand, - cc_name , d_year, d_moy), - v2 as( - select v1.i_brand - ,v1.d_year - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1. cc_name = v1_lag. cc_name and - v1. cc_name = v1_lead. cc_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 2001 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, sum_sales - limit 100; - --- end template query57.tpl query 83 in stream 6 --- start template query66.tpl query 84 in stream 6 -select /* TPC-DS query66.tpl 0.39 */ - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - ,sum(jan_sales) as jan_sales - ,sum(feb_sales) as feb_sales - ,sum(mar_sales) as mar_sales - ,sum(apr_sales) as apr_sales - ,sum(may_sales) as may_sales - ,sum(jun_sales) as jun_sales - ,sum(jul_sales) as jul_sales - ,sum(aug_sales) as aug_sales - ,sum(sep_sales) as sep_sales - ,sum(oct_sales) as oct_sales - ,sum(nov_sales) as nov_sales - ,sum(dec_sales) as dec_sales - ,sum(jan_sales/w_warehouse_sq_ft) as jan_sales_per_sq_foot - ,sum(feb_sales/w_warehouse_sq_ft) as feb_sales_per_sq_foot - ,sum(mar_sales/w_warehouse_sq_ft) as mar_sales_per_sq_foot - ,sum(apr_sales/w_warehouse_sq_ft) as apr_sales_per_sq_foot - ,sum(may_sales/w_warehouse_sq_ft) as may_sales_per_sq_foot - ,sum(jun_sales/w_warehouse_sq_ft) as jun_sales_per_sq_foot - ,sum(jul_sales/w_warehouse_sq_ft) as jul_sales_per_sq_foot - ,sum(aug_sales/w_warehouse_sq_ft) as aug_sales_per_sq_foot - ,sum(sep_sales/w_warehouse_sq_ft) as sep_sales_per_sq_foot - ,sum(oct_sales/w_warehouse_sq_ft) as oct_sales_per_sq_foot - ,sum(nov_sales/w_warehouse_sq_ft) as nov_sales_per_sq_foot - ,sum(dec_sales/w_warehouse_sq_ft) as dec_sales_per_sq_foot - ,sum(jan_net) as jan_net - ,sum(feb_net) as feb_net - ,sum(mar_net) as mar_net - ,sum(apr_net) as apr_net - ,sum(may_net) as may_net - ,sum(jun_net) as jun_net - ,sum(jul_net) as jul_net - ,sum(aug_net) as aug_net - ,sum(sep_net) as sep_net - ,sum(oct_net) as oct_net - ,sum(nov_net) as nov_net - ,sum(dec_net) as dec_net - from ( - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'DIAMOND' || ',' || 'MSC' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then ws_ext_list_price* ws_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then ws_ext_list_price* ws_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then ws_ext_list_price* ws_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then ws_ext_list_price* ws_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then ws_ext_list_price* ws_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then ws_ext_list_price* ws_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then ws_ext_list_price* ws_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then ws_ext_list_price* ws_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then ws_ext_list_price* ws_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then ws_ext_list_price* ws_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then ws_ext_list_price* ws_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then ws_ext_list_price* ws_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then ws_net_paid * ws_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then ws_net_paid * ws_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then ws_net_paid * ws_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then ws_net_paid * ws_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then ws_net_paid * ws_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then ws_net_paid * ws_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then ws_net_paid * ws_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then ws_net_paid * ws_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then ws_net_paid * ws_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then ws_net_paid * ws_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then ws_net_paid * ws_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then ws_net_paid * ws_quantity else 0 end) as dec_net - from - web_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - ws_warehouse_sk = w_warehouse_sk - and ws_sold_date_sk = d_date_sk - and ws_sold_time_sk = t_time_sk - and ws_ship_mode_sk = sm_ship_mode_sk - and d_year = 1998 - and t_time between 30404 and 30404+28800 - and sm_carrier in ('DIAMOND','MSC') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - union all - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'DIAMOND' || ',' || 'MSC' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then cs_ext_sales_price* cs_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then cs_ext_sales_price* cs_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then cs_ext_sales_price* cs_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then cs_ext_sales_price* cs_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then cs_ext_sales_price* cs_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then cs_ext_sales_price* cs_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then cs_ext_sales_price* cs_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then cs_ext_sales_price* cs_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then cs_ext_sales_price* cs_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then cs_ext_sales_price* cs_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then cs_ext_sales_price* cs_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then cs_ext_sales_price* cs_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as dec_net - from - catalog_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and cs_sold_time_sk = t_time_sk - and cs_ship_mode_sk = sm_ship_mode_sk - and d_year = 1998 - and t_time between 30404 AND 30404+28800 - and sm_carrier in ('DIAMOND','MSC') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - ) x - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - order by w_warehouse_name - limit 100; - --- end template query66.tpl query 84 in stream 6 --- start template query71.tpl query 85 in stream 6 -select /* TPC-DS query71.tpl 0.72 */ i_brand_id brand_id, i_brand brand,t_hour,t_minute, - sum(ext_price) ext_price - from item, (select ws_ext_sales_price as ext_price, - ws_sold_date_sk as sold_date_sk, - ws_item_sk as sold_item_sk, - ws_sold_time_sk as time_sk - from web_sales,date_dim - where d_date_sk = ws_sold_date_sk - and d_moy=11 - and d_year=2002 - union all - select cs_ext_sales_price as ext_price, - cs_sold_date_sk as sold_date_sk, - cs_item_sk as sold_item_sk, - cs_sold_time_sk as time_sk - from catalog_sales,date_dim - where d_date_sk = cs_sold_date_sk - and d_moy=11 - and d_year=2002 - union all - select ss_ext_sales_price as ext_price, - ss_sold_date_sk as sold_date_sk, - ss_item_sk as sold_item_sk, - ss_sold_time_sk as time_sk - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - and d_moy=11 - and d_year=2002 - ) tmp,time_dim - where - sold_item_sk = i_item_sk - and i_manager_id=1 - and time_sk = t_time_sk - and (t_meal_time = 'breakfast' or t_meal_time = 'dinner') - group by i_brand, i_brand_id,t_hour,t_minute - order by ext_price desc, i_brand_id - ; - --- end template query71.tpl query 85 in stream 6 --- start template query30.tpl query 86 in stream 6 -with /* TPC-DS query30.tpl 0.75 */ customer_total_return as - (select wr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(wr_return_amt) as ctr_total_return - from web_returns - ,date_dim - ,customer_address - where wr_returned_date_sk = d_date_sk - and d_year =2000 - and wr_returning_addr_sk = ca_address_sk - group by wr_returning_customer_sk - ,ca_state) - select c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'IN' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return -limit 100; - --- end template query30.tpl query 86 in stream 6 --- start template query1.tpl query 87 in stream 6 -with /* TPC-DS query1.tpl 0.12 */ customer_total_return as -(select sr_customer_sk as ctr_customer_sk -,sr_store_sk as ctr_store_sk -,sum(SR_RETURN_AMT_INC_TAX) as ctr_total_return -from store_returns -,date_dim -where sr_returned_date_sk = d_date_sk -and d_year =2002 -group by sr_customer_sk -,sr_store_sk) - select c_customer_id -from customer_total_return ctr1 -,store -,customer -where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 -from customer_total_return ctr2 -where ctr1.ctr_store_sk = ctr2.ctr_store_sk) -and s_store_sk = ctr1.ctr_store_sk -and s_state = 'AL' -and ctr1.ctr_customer_sk = c_customer_sk -order by c_customer_id -limit 100; - --- end template query1.tpl query 87 in stream 6 --- start template query81.tpl query 88 in stream 6 -with /* TPC-DS query81.tpl 0.37 */ customer_total_return as - (select cr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(cr_return_amt_inc_tax) as ctr_total_return - from catalog_returns - ,date_dim - ,customer_address - where cr_returned_date_sk = d_date_sk - and d_year =2002 - and cr_returning_addr_sk = ca_address_sk - group by cr_returning_customer_sk - ,ca_state ) - select c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'KS' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - limit 100; - --- end template query81.tpl query 88 in stream 6 --- start template query43.tpl query 89 in stream 6 -select /* TPC-DS query43.tpl 0.15 */ s_store_name, s_store_id, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from date_dim, store_sales, store - where d_date_sk = ss_sold_date_sk and - s_store_sk = ss_store_sk and - s_gmt_offset = -5 and - d_year = 1998 - group by s_store_name, s_store_id - order by s_store_name, s_store_id,sun_sales,mon_sales,tue_sales,wed_sales,thu_sales,fri_sales,sat_sales - limit 100; - --- end template query43.tpl query 89 in stream 6 --- start template query52.tpl query 90 in stream 6 -select /* TPC-DS query52.tpl 0.59 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_sales_price) ext_price - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=11 - and dt.d_year=2001 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,ext_price desc - ,brand_id -limit 100 ; - --- end template query52.tpl query 90 in stream 6 --- start template query13.tpl query 91 in stream 6 -select /* TPC-DS query13.tpl 0.91 */ avg(ss_quantity) - ,avg(ss_ext_sales_price) - ,avg(ss_ext_wholesale_cost) - ,sum(ss_ext_wholesale_cost) - from store_sales - ,store - ,customer_demographics - ,household_demographics - ,customer_address - ,date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2001 - and((ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'D' - and cd_education_status = '2 yr Degree' - and ss_sales_price between 100.00 and 150.00 - and hd_dep_count = 3 - )or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'W' - and cd_education_status = 'Advanced Degree' - and ss_sales_price between 50.00 and 100.00 - and hd_dep_count = 1 - ) or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'S' - and cd_education_status = 'Unknown' - and ss_sales_price between 150.00 and 200.00 - and hd_dep_count = 1 - )) - and((ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('MO', 'MD', 'VA') - and ss_net_profit between 100 and 200 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('GA', 'WV', 'NY') - and ss_net_profit between 150 and 300 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('TN', 'NC', 'AL') - and ss_net_profit between 50 and 250 - )) -; - --- end template query13.tpl query 91 in stream 6 --- start template query76.tpl query 92 in stream 6 -select /* TPC-DS query76.tpl 0.99 */ channel, col_name, d_year, d_qoy, i_category, COUNT(*) sales_cnt, SUM(ext_sales_price) sales_amt FROM ( - SELECT 'store' as channel, 'ss_hdemo_sk' col_name, d_year, d_qoy, i_category, ss_ext_sales_price ext_sales_price - FROM store_sales, item, date_dim - WHERE ss_hdemo_sk IS NULL - AND ss_sold_date_sk=d_date_sk - AND ss_item_sk=i_item_sk - UNION ALL - SELECT 'web' as channel, 'ws_bill_customer_sk' col_name, d_year, d_qoy, i_category, ws_ext_sales_price ext_sales_price - FROM web_sales, item, date_dim - WHERE ws_bill_customer_sk IS NULL - AND ws_sold_date_sk=d_date_sk - AND ws_item_sk=i_item_sk - UNION ALL - SELECT 'catalog' as channel, 'cs_warehouse_sk' col_name, d_year, d_qoy, i_category, cs_ext_sales_price ext_sales_price - FROM catalog_sales, item, date_dim - WHERE cs_warehouse_sk IS NULL - AND cs_sold_date_sk=d_date_sk - AND cs_item_sk=i_item_sk) foo -GROUP BY channel, col_name, d_year, d_qoy, i_category -ORDER BY channel, col_name, d_year, d_qoy, i_category -limit 100; - --- end template query76.tpl query 92 in stream 6 --- start template query17.tpl query 93 in stream 6 -select /* TPC-DS query17.tpl 0.41 */ i_item_id - ,i_item_desc - ,s_state - ,count(ss_quantity) as store_sales_quantitycount - ,avg(ss_quantity) as store_sales_quantityave - ,stddev_samp(ss_quantity) as store_sales_quantitystdev - ,stddev_samp(ss_quantity)/avg(ss_quantity) as store_sales_quantitycov - ,count(sr_return_quantity) as store_returns_quantitycount - ,avg(sr_return_quantity) as store_returns_quantityave - ,stddev_samp(sr_return_quantity) as store_returns_quantitystdev - ,stddev_samp(sr_return_quantity)/avg(sr_return_quantity) as store_returns_quantitycov - ,count(cs_quantity) as catalog_sales_quantitycount ,avg(cs_quantity) as catalog_sales_quantityave - ,stddev_samp(cs_quantity) as catalog_sales_quantitystdev - ,stddev_samp(cs_quantity)/avg(cs_quantity) as catalog_sales_quantitycov - from store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where d1.d_quarter_name = '2000Q1' - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_quarter_name in ('2000Q1','2000Q2','2000Q3') - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_quarter_name in ('2000Q1','2000Q2','2000Q3') - group by i_item_id - ,i_item_desc - ,s_state - order by i_item_id - ,i_item_desc - ,s_state -limit 100; - --- end template query17.tpl query 93 in stream 6 --- start template query25.tpl query 94 in stream 6 -select /* TPC-DS query25.tpl 0.9 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,stddev_samp(ss_net_profit) as store_sales_profit - ,stddev_samp(sr_net_loss) as store_returns_loss - ,stddev_samp(cs_net_profit) as catalog_sales_profit - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 2002 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 10 - and d2.d_year = 2002 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_moy between 4 and 10 - and d3.d_year = 2002 - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query25.tpl query 94 in stream 6 --- start template query40.tpl query 95 in stream 6 -select /* TPC-DS query40.tpl 0.86 */ - w_state - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('1998-05-26' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_before - ,sum(case when (cast(d_date as date) >= cast ('1998-05-26' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_after - from - catalog_sales left outer join catalog_returns on - (cs_order_number = cr_order_number - and cs_item_sk = cr_item_sk) - ,warehouse - ,item - ,date_dim - where - i_current_price between 0.99 and 1.49 - and i_item_sk = cs_item_sk - and cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('1998-05-26' as date)) - and dateadd(day,30,cast ('1998-05-26' as date)) - group by - w_state,i_item_id - order by w_state,i_item_id -limit 100; - --- end template query40.tpl query 95 in stream 6 --- start template query70a.tpl query 96 in stream 6 -with /* TPC-DS query70a.tpl 0.34 */ results as -( select - sum(ss_net_profit) as total_sum ,s_state ,s_county, 0 as gstate, 0 as g_county - from - store_sales - ,date_dim d1 - ,store - where - d1.d_month_seq between 1187 and 1187 + 11 - and d1.d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - and s_state in - ( select s_state - from (select s_state as s_state, - rank() over ( partition by s_state order by sum(ss_net_profit) desc) as ranking - from store_sales, store, date_dim - where d_month_seq between 1187 and 1187 + 11 - and d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - group by s_state - ) tmp1 - where ranking <= 5) - group by s_state,s_county) , - results_rollup as -(select total_sum ,s_state ,s_county, 0 as g_state, 0 as g_county, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum,s_state, NULL as s_county, 0 as g_state, 1 as g_county, 1 as lochierarchy from results group by s_state - union - select sum(total_sum) as total_sum ,NULL as s_state ,NULL as s_county, 1 as g_state, 1 as g_county, 2 as lochierarchy from results) - select total_sum ,s_state ,s_county, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_county = 0 then s_state end - order by total_sum desc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then s_state end - ,rank_within_parent - limit 100; - --- end template query70a.tpl query 96 in stream 6 --- start template query55.tpl query 97 in stream 6 -select /* TPC-DS query55.tpl 0.82 */ i_brand_id brand_id, i_brand brand, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=95 - and d_moy=11 - and d_year=1998 - group by i_brand, i_brand_id - order by ext_price desc, i_brand_id -limit 100 ; - --- end template query55.tpl query 97 in stream 6 --- start template query60.tpl query 98 in stream 6 -with /* TPC-DS query60.tpl 0.29 */ ss as ( - select - i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Shoes')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 10 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -7 - group by i_item_id), - cs as ( - select - i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Shoes')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 10 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -7 - group by i_item_id), - ws as ( - select - i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Shoes')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 10 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -7 - group by i_item_id) - select - i_item_id -,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by i_item_id - ,total_sales - limit 100; - --- end template query60.tpl query 98 in stream 6 --- start template query16.tpl query 99 in stream 6 -select /* TPC-DS query16.tpl 0.25 */ - count(distinct cs_order_number) as "order count" - ,sum(cs_ext_ship_cost) as "total shipping cost" - ,sum(cs_net_profit) as "total net profit" -from - catalog_sales cs1 - ,date_dim - ,customer_address - ,call_center -where - d_date between '2001-3-01' and - dateadd(day, 60, cast('2001-3-01' as date)) -and cs1.cs_ship_date_sk = d_date_sk -and cs1.cs_ship_addr_sk = ca_address_sk -and ca_state = 'MN' -and cs1.cs_call_center_sk = cc_call_center_sk -and cc_county in ('Wadena County','Kittitas County','Jackson County','Walker County', - 'San Miguel County' -) -and exists (select * - from catalog_sales cs2 - where cs1.cs_order_number = cs2.cs_order_number - and cs1.cs_warehouse_sk <> cs2.cs_warehouse_sk) -and not exists(select * - from catalog_returns cr1 - where cs1.cs_order_number = cr1.cr_order_number) -order by count(distinct cs_order_number) -limit 100; - --- end template query16.tpl query 99 in stream 6 diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/30TB/queries/query_7.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/30TB/queries/query_7.sql deleted file mode 100644 index 46cc5031..00000000 --- a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/30TB/queries/query_7.sql +++ /dev/null @@ -1,5027 +0,0 @@ --- start template query70a.tpl query 1 in stream 7 -with /* TPC-DS query70a.tpl 0.34 */ results as -( select - sum(ss_net_profit) as total_sum ,s_state ,s_county, 0 as gstate, 0 as g_county - from - store_sales - ,date_dim d1 - ,store - where - d1.d_month_seq between 1196 and 1196 + 11 - and d1.d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - and s_state in - ( select s_state - from (select s_state as s_state, - rank() over ( partition by s_state order by sum(ss_net_profit) desc) as ranking - from store_sales, store, date_dim - where d_month_seq between 1196 and 1196 + 11 - and d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - group by s_state - ) tmp1 - where ranking <= 5) - group by s_state,s_county) , - results_rollup as -(select total_sum ,s_state ,s_county, 0 as g_state, 0 as g_county, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum,s_state, NULL as s_county, 0 as g_state, 1 as g_county, 1 as lochierarchy from results group by s_state - union - select sum(total_sum) as total_sum ,NULL as s_state ,NULL as s_county, 1 as g_state, 1 as g_county, 2 as lochierarchy from results) - select total_sum ,s_state ,s_county, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_county = 0 then s_state end - order by total_sum desc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then s_state end - ,rank_within_parent - limit 100; - --- end template query70a.tpl query 1 in stream 7 --- start template query53.tpl query 2 in stream 7 -select /* TPC-DS query53.tpl 0.88 */ * from -(select i_manufact_id, -sum(ss_sales_price) sum_sales, -avg(sum(ss_sales_price)) over (partition by i_manufact_id) avg_quarterly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and -ss_sold_date_sk = d_date_sk and -ss_store_sk = s_store_sk and -d_month_seq in (1219,1219+1,1219+2,1219+3,1219+4,1219+5,1219+6,1219+7,1219+8,1219+9,1219+10,1219+11) and -((i_category in ('Books','Children','Electronics') and -i_class in ('personal','portable','reference','self-help') and -i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) -or(i_category in ('Women','Music','Men') and -i_class in ('accessories','classical','fragrances','pants') and -i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manufact_id, d_qoy ) tmp1 -where case when avg_quarterly_sales > 0 - then abs (sum_sales - avg_quarterly_sales)/ avg_quarterly_sales - else null end > 0.1 -order by avg_quarterly_sales, - sum_sales, - i_manufact_id -limit 100; - --- end template query53.tpl query 2 in stream 7 --- start template query92.tpl query 3 in stream 7 -select /* TPC-DS query92.tpl 0.44 */ - sum(ws_ext_discount_amt) as "Excess Discount Amount" -from - web_sales - ,item - ,date_dim -where -i_manufact_id = 675 -and i_item_sk = ws_item_sk -and d_date between '2002-03-03' and - dateadd(day,90,cast('2002-03-03' as date)) -and d_date_sk = ws_sold_date_sk -and ws_ext_discount_amt - > ( - SELECT - 1.3 * avg(ws_ext_discount_amt) - FROM - web_sales - ,date_dim - WHERE - ws_item_sk = i_item_sk - and d_date between '2002-03-03' and - dateadd(day,90,cast('2002-03-03' as date)) - and d_date_sk = ws_sold_date_sk - ) -order by sum(ws_ext_discount_amt) -limit 100; - --- end template query92.tpl query 3 in stream 7 --- start template query99.tpl query 4 in stream 7 -select /* TPC-DS query99.tpl 0.94 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 30) and - (cs_ship_date_sk - cs_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 60) and - (cs_ship_date_sk - cs_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 90) and - (cs_ship_date_sk - cs_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - catalog_sales - ,warehouse - ,ship_mode - ,call_center - ,date_dim -where - d_month_seq between 1181 and 1181 + 11 -and cs_ship_date_sk = d_date_sk -and cs_warehouse_sk = w_warehouse_sk -and cs_ship_mode_sk = sm_ship_mode_sk -and cs_call_center_sk = cc_call_center_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -limit 100; - --- end template query99.tpl query 4 in stream 7 --- start template query31.tpl query 5 in stream 7 -with /* TPC-DS query31.tpl 0.50 */ ss as - (select ca_county,d_qoy, d_year,sum(ss_ext_sales_price) as store_sales - from store_sales,date_dim,customer_address - where ss_sold_date_sk = d_date_sk - and ss_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year), - ws as - (select ca_county,d_qoy, d_year,sum(ws_ext_sales_price) as web_sales - from web_sales,date_dim,customer_address - where ws_sold_date_sk = d_date_sk - and ws_bill_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year) - select - ss1.ca_county - ,ss1.d_year - ,ws2.web_sales/ws1.web_sales web_q1_q2_increase - ,ss2.store_sales/ss1.store_sales store_q1_q2_increase - ,ws3.web_sales/ws2.web_sales web_q2_q3_increase - ,ss3.store_sales/ss2.store_sales store_q2_q3_increase - from - ss ss1 - ,ss ss2 - ,ss ss3 - ,ws ws1 - ,ws ws2 - ,ws ws3 - where - ss1.d_qoy = 1 - and ss1.d_year = 2002 - and ss1.ca_county = ss2.ca_county - and ss2.d_qoy = 2 - and ss2.d_year = 2002 - and ss2.ca_county = ss3.ca_county - and ss3.d_qoy = 3 - and ss3.d_year = 2002 - and ss1.ca_county = ws1.ca_county - and ws1.d_qoy = 1 - and ws1.d_year = 2002 - and ws1.ca_county = ws2.ca_county - and ws2.d_qoy = 2 - and ws2.d_year = 2002 - and ws1.ca_county = ws3.ca_county - and ws3.d_qoy = 3 - and ws3.d_year =2002 - and case when ws1.web_sales > 0 then ws2.web_sales/ws1.web_sales else null end - > case when ss1.store_sales > 0 then ss2.store_sales/ss1.store_sales else null end - and case when ws2.web_sales > 0 then ws3.web_sales/ws2.web_sales else null end - > case when ss2.store_sales > 0 then ss3.store_sales/ss2.store_sales else null end - order by web_q2_q3_increase; - --- end template query31.tpl query 5 in stream 7 --- start template query39.tpl query 6 in stream 7 -with /* TPC-DS query39.tpl 0.5 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =2001 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=3 - and inv2.d_moy=3+1 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; -with /* TPC-DS query39.tpl 0.5 part2 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =2001 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=3 - and inv2.d_moy=3+1 - and inv1.cov > 1.5 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; - --- end template query39.tpl query 6 in stream 7 --- start template query29.tpl query 7 in stream 7 -select /* TPC-DS query29.tpl 0.53 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,max(ss_quantity) as store_sales_quantity - ,max(sr_return_quantity) as store_returns_quantity - ,max(cs_quantity) as catalog_sales_quantity - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 1998 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 4 + 3 - and d2.d_year = 1998 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_year in (1998,1998+1,1998+2) - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query29.tpl query 7 in stream 7 --- start template query32.tpl query 8 in stream 7 -select /* TPC-DS query32.tpl 0.7 */ sum(cs_ext_discount_amt) as "excess discount amount" -from - catalog_sales - ,item - ,date_dim -where -i_manufact_id = 990 -and i_item_sk = cs_item_sk -and d_date between '2000-03-20' and - dateadd(day,90,cast('2000-03-20' as date)) -and d_date_sk = cs_sold_date_sk -and cs_ext_discount_amt - > ( - select - 1.3 * avg(cs_ext_discount_amt) - from - catalog_sales - ,date_dim - where - cs_item_sk = i_item_sk - and d_date between '2000-03-20' and - dateadd(day,90,cast('2000-03-20' as date)) - and d_date_sk = cs_sold_date_sk - ) -limit 100; - --- end template query32.tpl query 8 in stream 7 --- start template query6.tpl query 9 in stream 7 -select /* TPC-DS query6.tpl 0.58 */ a.ca_state state, count(*) cnt - from customer_address a - ,customer c - ,store_sales s - ,date_dim d - ,item i - where a.ca_address_sk = c.c_current_addr_sk - and c.c_customer_sk = s.ss_customer_sk - and s.ss_sold_date_sk = d.d_date_sk - and s.ss_item_sk = i.i_item_sk - and d.d_month_seq = - (select distinct (d_month_seq) - from date_dim - where d_year = 2001 - and d_moy = 1 ) - and i.i_current_price > 1.2 * - (select avg(j.i_current_price) - from item j - where j.i_category = i.i_category) - group by a.ca_state - having count(*) >= 10 - order by cnt, a.ca_state - limit 100; - --- end template query6.tpl query 9 in stream 7 --- start template query64.tpl query 10 in stream 7 -with /* TPC-DS query64.tpl 0.20 */ cs_ui as - (select cs_item_sk - ,sum(cs_ext_list_price) as sale,sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit) as refund - from catalog_sales - ,catalog_returns - where cs_item_sk = cr_item_sk - and cs_order_number = cr_order_number - group by cs_item_sk - having sum(cs_ext_list_price)>2*sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit)), -cross_sales as - (select i_product_name product_name - ,i_item_sk item_sk - ,s_store_name store_name - ,s_zip store_zip - ,ad1.ca_street_number b_street_number - ,ad1.ca_street_name b_street_name - ,ad1.ca_city b_city - ,ad1.ca_zip b_zip - ,ad2.ca_street_number c_street_number - ,ad2.ca_street_name c_street_name - ,ad2.ca_city c_city - ,ad2.ca_zip c_zip - ,d1.d_year as syear - ,d2.d_year as fsyear - ,d3.d_year s2year - ,count(*) cnt - ,sum(ss_wholesale_cost) s1 - ,sum(ss_list_price) s2 - ,sum(ss_coupon_amt) s3 - FROM store_sales - ,store_returns - ,cs_ui - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,customer - ,customer_demographics cd1 - ,customer_demographics cd2 - ,promotion - ,household_demographics hd1 - ,household_demographics hd2 - ,customer_address ad1 - ,customer_address ad2 - ,income_band ib1 - ,income_band ib2 - ,item - WHERE ss_store_sk = s_store_sk AND - ss_sold_date_sk = d1.d_date_sk AND - ss_customer_sk = c_customer_sk AND - ss_cdemo_sk= cd1.cd_demo_sk AND - ss_hdemo_sk = hd1.hd_demo_sk AND - ss_addr_sk = ad1.ca_address_sk and - ss_item_sk = i_item_sk and - ss_item_sk = sr_item_sk and - ss_ticket_number = sr_ticket_number and - ss_item_sk = cs_ui.cs_item_sk and - c_current_cdemo_sk = cd2.cd_demo_sk AND - c_current_hdemo_sk = hd2.hd_demo_sk AND - c_current_addr_sk = ad2.ca_address_sk and - c_first_sales_date_sk = d2.d_date_sk and - c_first_shipto_date_sk = d3.d_date_sk and - ss_promo_sk = p_promo_sk and - hd1.hd_income_band_sk = ib1.ib_income_band_sk and - hd2.hd_income_band_sk = ib2.ib_income_band_sk and - cd1.cd_marital_status <> cd2.cd_marital_status and - i_color in ('rose','mint','metallic','seashell','yellow','blanched') and - i_current_price between 82 and 82 + 10 and - i_current_price between 82 + 1 and 82 + 15 -group by i_product_name - ,i_item_sk - ,s_store_name - ,s_zip - ,ad1.ca_street_number - ,ad1.ca_street_name - ,ad1.ca_city - ,ad1.ca_zip - ,ad2.ca_street_number - ,ad2.ca_street_name - ,ad2.ca_city - ,ad2.ca_zip - ,d1.d_year - ,d2.d_year - ,d3.d_year -) -select cs1.product_name - ,cs1.store_name - ,cs1.store_zip - ,cs1.b_street_number - ,cs1.b_street_name - ,cs1.b_city - ,cs1.b_zip - ,cs1.c_street_number - ,cs1.c_street_name - ,cs1.c_city - ,cs1.c_zip - ,cs1.syear - ,cs1.cnt - ,cs1.s1 as s11 - ,cs1.s2 as s21 - ,cs1.s3 as s31 - ,cs2.s1 as s12 - ,cs2.s2 as s22 - ,cs2.s3 as s32 - ,cs2.syear - ,cs2.cnt -from cross_sales cs1,cross_sales cs2 -where cs1.item_sk=cs2.item_sk and - cs1.syear = 2000 and - cs2.syear = 2000 + 1 and - cs2.cnt <= cs1.cnt and - cs1.store_name = cs2.store_name and - cs1.store_zip = cs2.store_zip -order by cs1.product_name - ,cs1.store_name - ,cs2.cnt - ,cs1.s1 - ,cs2.s1; - --- end template query64.tpl query 10 in stream 7 --- start template query30.tpl query 11 in stream 7 -with /* TPC-DS query30.tpl 0.75 */ customer_total_return as - (select wr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(wr_return_amt) as ctr_total_return - from web_returns - ,date_dim - ,customer_address - where wr_returned_date_sk = d_date_sk - and d_year =2001 - and wr_returning_addr_sk = ca_address_sk - group by wr_returning_customer_sk - ,ca_state) - select c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'AL' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return -limit 100; - --- end template query30.tpl query 11 in stream 7 --- start template query34.tpl query 12 in stream 7 -select /* TPC-DS query34.tpl 0.73 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (date_dim.d_dom between 1 and 3 or date_dim.d_dom between 25 and 28) - and (household_demographics.hd_buy_potential = '1001-5000' or - household_demographics.hd_buy_potential = '5001-10000') - and household_demographics.hd_vehicle_count > 0 - and (case when household_demographics.hd_vehicle_count > 0 - then household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count - else null - end) > 1.2 - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_county in ('Arthur County','Cocke County','Jackson County','Ziebach County', - 'Baltimore County','Tehama County','Nuckolls County','Anderson County') - group by ss_ticket_number,ss_customer_sk) dn,customer - where ss_customer_sk = c_customer_sk - and cnt between 15 and 20 - order by c_last_name,c_first_name,c_salutation,c_preferred_cust_flag desc, ss_ticket_number; - --- end template query34.tpl query 12 in stream 7 --- start template query13.tpl query 13 in stream 7 -select /* TPC-DS query13.tpl 0.91 */ avg(ss_quantity) - ,avg(ss_ext_sales_price) - ,avg(ss_ext_wholesale_cost) - ,sum(ss_ext_wholesale_cost) - from store_sales - ,store - ,customer_demographics - ,household_demographics - ,customer_address - ,date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2001 - and((ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'D' - and cd_education_status = 'Advanced Degree' - and ss_sales_price between 100.00 and 150.00 - and hd_dep_count = 3 - )or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'U' - and cd_education_status = '2 yr Degree' - and ss_sales_price between 50.00 and 100.00 - and hd_dep_count = 1 - ) or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'W' - and cd_education_status = 'Unknown' - and ss_sales_price between 150.00 and 200.00 - and hd_dep_count = 1 - )) - and((ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('CO', 'ID', 'KS') - and ss_net_profit between 100 and 200 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('TX', 'IL', 'TN') - and ss_net_profit between 150 and 300 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('DE', 'ND', 'WV') - and ss_net_profit between 50 and 250 - )) -; - --- end template query13.tpl query 13 in stream 7 --- start template query28.tpl query 14 in stream 7 -select /* TPC-DS query28.tpl 0.36 */ * -from (select avg(ss_list_price) B1_LP - ,count(ss_list_price) B1_CNT - ,count(distinct ss_list_price) B1_CNTD - from store_sales - where ss_quantity between 0 and 5 - and (ss_list_price between 179 and 179+10 - or ss_coupon_amt between 14184 and 14184+1000 - or ss_wholesale_cost between 58 and 58+20)) B1, - (select avg(ss_list_price) B2_LP - ,count(ss_list_price) B2_CNT - ,count(distinct ss_list_price) B2_CNTD - from store_sales - where ss_quantity between 6 and 10 - and (ss_list_price between 18 and 18+10 - or ss_coupon_amt between 2121 and 2121+1000 - or ss_wholesale_cost between 8 and 8+20)) B2, - (select avg(ss_list_price) B3_LP - ,count(ss_list_price) B3_CNT - ,count(distinct ss_list_price) B3_CNTD - from store_sales - where ss_quantity between 11 and 15 - and (ss_list_price between 0 and 0+10 - or ss_coupon_amt between 17349 and 17349+1000 - or ss_wholesale_cost between 71 and 71+20)) B3, - (select avg(ss_list_price) B4_LP - ,count(ss_list_price) B4_CNT - ,count(distinct ss_list_price) B4_CNTD - from store_sales - where ss_quantity between 16 and 20 - and (ss_list_price between 54 and 54+10 - or ss_coupon_amt between 17118 and 17118+1000 - or ss_wholesale_cost between 48 and 48+20)) B4, - (select avg(ss_list_price) B5_LP - ,count(ss_list_price) B5_CNT - ,count(distinct ss_list_price) B5_CNTD - from store_sales - where ss_quantity between 21 and 25 - and (ss_list_price between 180 and 180+10 - or ss_coupon_amt between 15795 and 15795+1000 - or ss_wholesale_cost between 38 and 38+20)) B5, - (select avg(ss_list_price) B6_LP - ,count(ss_list_price) B6_CNT - ,count(distinct ss_list_price) B6_CNTD - from store_sales - where ss_quantity between 26 and 30 - and (ss_list_price between 117 and 117+10 - or ss_coupon_amt between 11242 and 11242+1000 - or ss_wholesale_cost between 32 and 32+20)) B6 -limit 100; - --- end template query28.tpl query 14 in stream 7 --- start template query86a.tpl query 15 in stream 7 -with /* TPC-DS query86a.tpl 0.11 */ results as -( select sum(ws_net_paid) as total_sum, i_category, i_class, 0 as g_category, 0 as g_class - from - web_sales - ,date_dim d1 - ,item - where - d1.d_month_seq between 1223 and 1223+11 - and d1.d_date_sk = ws_sold_date_sk - and i_item_sk = ws_item_sk - group by i_category,i_class - ) , - - results_rollup as -( select total_sum ,i_category ,i_class, g_category, g_class, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum, i_category, NULL as i_class, 0 as g_category, 1 as g_class, 1 as lochierarchy from results group by i_category - union - select sum(total_sum) as total_sum, NULL as i_category, NULL as i_class, 1 as g_category, 1 as g_class, 2 as lochierarchy from results) - select - total_sum ,i_category ,i_class, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_class = 0 then i_category end - order by total_sum desc) as rank_within_parent - from - results_rollup - order by - lochierarchy desc, - case when lochierarchy = 0 then i_category end, - rank_within_parent - limit 100; - --- end template query86a.tpl query 15 in stream 7 --- start template query84.tpl query 16 in stream 7 -select /* TPC-DS query84.tpl 0.80 */ c_customer_id as customer_id - , coalesce(c_last_name,'') || ', ' || coalesce(c_first_name,'') as customername - from customer - ,customer_address - ,customer_demographics - ,household_demographics - ,income_band - ,store_returns - where ca_city = 'Hillcrest' - and c_current_addr_sk = ca_address_sk - and ib_lower_bound >= 40717 - and ib_upper_bound <= 40717 + 50000 - and ib_income_band_sk = hd_income_band_sk - and cd_demo_sk = c_current_cdemo_sk - and hd_demo_sk = c_current_hdemo_sk - and sr_cdemo_sk = cd_demo_sk - order by c_customer_id - limit 100; - --- end template query84.tpl query 16 in stream 7 --- start template query25.tpl query 17 in stream 7 -select /* TPC-DS query25.tpl 0.9 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,min(ss_net_profit) as store_sales_profit - ,min(sr_net_loss) as store_returns_loss - ,min(cs_net_profit) as catalog_sales_profit - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 2000 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 10 - and d2.d_year = 2000 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_moy between 4 and 10 - and d3.d_year = 2000 - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query25.tpl query 17 in stream 7 --- start template query4.tpl query 18 in stream 7 -with /* TPC-DS query4.tpl 0.93 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(((ss_ext_list_price-ss_ext_wholesale_cost-ss_ext_discount_amt)+ss_ext_sales_price)/2) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((cs_ext_list_price-cs_ext_wholesale_cost-cs_ext_discount_amt)+cs_ext_sales_price)/2) ) year_total - ,'c' sale_type - from customer - ,catalog_sales - ,date_dim - where c_customer_sk = cs_bill_customer_sk - and cs_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year -union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((ws_ext_list_price-ws_ext_wholesale_cost-ws_ext_discount_amt)+ws_ext_sales_price)/2) ) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_email_address - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_c_firstyear - ,year_total t_c_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_c_secyear.customer_id - and t_s_firstyear.customer_id = t_c_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_c_firstyear.sale_type = 'c' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_c_secyear.sale_type = 'c' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 2001 - and t_s_secyear.dyear = 2001+1 - and t_c_firstyear.dyear = 2001 - and t_c_secyear.dyear = 2001+1 - and t_w_firstyear.dyear = 2001 - and t_w_secyear.dyear = 2001+1 - and t_s_firstyear.year_total > 0 - and t_c_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_email_address -limit 100; - --- end template query4.tpl query 18 in stream 7 --- start template query98.tpl query 19 in stream 7 -select /* TPC-DS query98.tpl 0.32 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ss_ext_sales_price) as itemrevenue - ,sum(ss_ext_sales_price)*100/sum(sum(ss_ext_sales_price)) over - (partition by i_class) as revenueratio -from - store_sales - ,item - ,date_dim -where - ss_item_sk = i_item_sk - and i_category in ('Music', 'Women', 'Electronics') - and ss_sold_date_sk = d_date_sk - and d_date between cast('1998-03-07' as date) - and dateadd(day,30,cast('1998-03-07' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio; - --- end template query98.tpl query 19 in stream 7 --- start template query79.tpl query 20 in stream 7 -select /* TPC-DS query79.tpl 0.89 */ - c_last_name,c_first_name,substring(s_city,1,30),ss_ticket_number,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,store.s_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (household_demographics.hd_dep_count = 5 or household_demographics.hd_vehicle_count > 2) - and date_dim.d_dow = 1 - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_number_employees between 200 and 295 - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,store.s_city) ms,customer - where ss_customer_sk = c_customer_sk - order by c_last_name,c_first_name,substring(s_city,1,30), profit -limit 100; - --- end template query79.tpl query 20 in stream 7 --- start template query69.tpl query 21 in stream 7 -select /* TPC-DS query69.tpl 0.28 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_state in ('OH','IA','GA') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2001 and - d_moy between 2 and 2+2) and - (not exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2001 and - d_moy between 2 and 2+2) and - not exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2001 and - d_moy between 2 and 2+2)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - limit 100; - --- end template query69.tpl query 21 in stream 7 --- start template query72.tpl query 22 in stream 7 -select /* TPC-DS query72.tpl 0.87 */ i_item_desc - ,w_warehouse_name - ,d1.d_week_seq - ,sum(case when p_promo_sk is null then 1 else 0 end) no_promo - ,sum(case when p_promo_sk is not null then 1 else 0 end) promo - ,count(*) total_cnt -from catalog_sales -join inventory on (cs_item_sk = inv_item_sk) -join warehouse on (w_warehouse_sk=inv_warehouse_sk) -join item on (i_item_sk = cs_item_sk) -join customer_demographics on (cs_bill_cdemo_sk = cd_demo_sk) -join household_demographics on (cs_bill_hdemo_sk = hd_demo_sk) -join date_dim d1 on (cs_sold_date_sk = d1.d_date_sk) -join date_dim d2 on (inv_date_sk = d2.d_date_sk) -join date_dim d3 on (cs_ship_date_sk = d3.d_date_sk) -left outer join promotion on (cs_promo_sk=p_promo_sk) -left outer join catalog_returns on (cr_item_sk = cs_item_sk and cr_order_number = cs_order_number) -where d1.d_week_seq = d2.d_week_seq - and inv_quantity_on_hand < cs_quantity - and d3.d_date > d1.d_date + 5 - and hd_buy_potential = '501-1000' - and d1.d_year = 2000 - and cd_marital_status = 'S' -group by i_item_desc,w_warehouse_name,d1.d_week_seq -order by total_cnt desc, i_item_desc, w_warehouse_name, d_week_seq -limit 100; - --- end template query72.tpl query 22 in stream 7 --- start template query45.tpl query 23 in stream 7 -select /* TPC-DS query45.tpl 0.18 */ ca_zip, ca_city, sum(ws_sales_price) - from web_sales, customer, customer_address, date_dim, item - where ws_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ws_item_sk = i_item_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', '85392', '85460', '80348', '81792') - or - i_item_id in (select i_item_id - from item - where i_item_sk in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29) - ) - ) - and ws_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 1999 - group by ca_zip, ca_city - order by ca_zip, ca_city - limit 100; - --- end template query45.tpl query 23 in stream 7 --- start template query48.tpl query 24 in stream 7 -select /* TPC-DS query48.tpl 0.74 */ sum (ss_quantity) - from store_sales, store, customer_demographics, customer_address, date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2001 - and - ( - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'D' - and - cd_education_status = '2 yr Degree' - and - ss_sales_price between 100.00 and 150.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'U' - and - cd_education_status = 'Advanced Degree' - and - ss_sales_price between 50.00 and 100.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'S' - and - cd_education_status = 'Primary' - and - ss_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('IA', 'TX', 'GA') - and ss_net_profit between 0 and 2000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('AL', 'WY', 'KS') - and ss_net_profit between 150 and 3000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('PA', 'MS', 'SC') - and ss_net_profit between 50 and 25000 - ) - ) -; - --- end template query48.tpl query 24 in stream 7 --- start template query80a.tpl query 25 in stream 7 -with /* TPC-DS query80a.tpl 0.6 */ ssr as - (select s_store_id as store_id, - sum(ss_ext_sales_price) as sales, - sum(coalesce(sr_return_amt, 0)) as returns, - sum(ss_net_profit - coalesce(sr_net_loss, 0)) as profit - from store_sales left outer join store_returns on - (ss_item_sk = sr_item_sk and ss_ticket_number = sr_ticket_number), - date_dim, - store, - item, - promotion - where ss_sold_date_sk = d_date_sk - and d_date between cast('1999-08-15' as date) - and dateadd(day,30,cast('1999-08-15' as date)) - and ss_store_sk = s_store_sk - and ss_item_sk = i_item_sk - and i_current_price > 50 - and ss_promo_sk = p_promo_sk - and p_channel_tv = 'N' - group by s_store_id) - , - csr as - (select cp_catalog_page_id as catalog_page_id, - sum(cs_ext_sales_price) as sales, - sum(coalesce(cr_return_amount, 0)) as returns, - sum(cs_net_profit - coalesce(cr_net_loss, 0)) as profit - from catalog_sales left outer join catalog_returns on - (cs_item_sk = cr_item_sk and cs_order_number = cr_order_number), - date_dim, - catalog_page, - item, - promotion - where cs_sold_date_sk = d_date_sk - and d_date between cast('1999-08-15' as date) - and dateadd(day,30,cast('1999-08-15' as date)) - and cs_catalog_page_sk = cp_catalog_page_sk - and cs_item_sk = i_item_sk - and i_current_price > 50 - and cs_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(ws_ext_sales_price) as sales, - sum(coalesce(wr_return_amt, 0)) as returns, - sum(ws_net_profit - coalesce(wr_net_loss, 0)) as profit - from web_sales left outer join web_returns on - (ws_item_sk = wr_item_sk and ws_order_number = wr_order_number), - date_dim, - web_site, - item, - promotion - where ws_sold_date_sk = d_date_sk - and d_date between cast('1999-08-15' as date) - and dateadd(day,30,cast('1999-08-15' as date)) - and ws_web_site_sk = web_site_sk - and ws_item_sk = i_item_sk - and i_current_price > 50 - and ws_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by web_site_id) -, -results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || store_id as id - , sales - , returns - , profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || catalog_page_id as id - , sales - , returns - , profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , profit - from wsr - ) x - group by channel, id) - - select channel - , id - , sales - , returns - , profit - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results - ) foo - order by channel, id - limit 100; - --- end template query80a.tpl query 25 in stream 7 --- start template query20.tpl query 26 in stream 7 -select /* TPC-DS query20.tpl 0.65 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(cs_ext_sales_price) as itemrevenue - ,sum(cs_ext_sales_price)*100/sum(sum(cs_ext_sales_price)) over - (partition by i_class) as revenueratio - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and i_category in ('Home', 'Electronics', 'Children') - and cs_sold_date_sk = d_date_sk - and d_date between cast('1999-03-27' as date) - and dateadd(day,30,cast('1999-03-27' as date)) - group by i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - order by i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query20.tpl query 26 in stream 7 --- start template query2.tpl query 27 in stream 7 -with /* TPC-DS query2.tpl 0.84 */ wscs as - (select sold_date_sk - ,sales_price - from (select ws_sold_date_sk sold_date_sk - ,ws_ext_sales_price sales_price - from web_sales - union all - select cs_sold_date_sk sold_date_sk - ,cs_ext_sales_price sales_price - from catalog_sales)), - wswscs as - (select d_week_seq, - sum(case when (d_day_name='Sunday') then sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then sales_price else null end) sat_sales - from wscs - ,date_dim - where d_date_sk = sold_date_sk - group by d_week_seq) - select d_week_seq1 - ,round(sun_sales1/sun_sales2,2) - ,round(mon_sales1/mon_sales2,2) - ,round(tue_sales1/tue_sales2,2) - ,round(wed_sales1/wed_sales2,2) - ,round(thu_sales1/thu_sales2,2) - ,round(fri_sales1/fri_sales2,2) - ,round(sat_sales1/sat_sales2,2) - from - (select wswscs.d_week_seq d_week_seq1 - ,sun_sales sun_sales1 - ,mon_sales mon_sales1 - ,tue_sales tue_sales1 - ,wed_sales wed_sales1 - ,thu_sales thu_sales1 - ,fri_sales fri_sales1 - ,sat_sales sat_sales1 - from wswscs,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 1999) y, - (select wswscs.d_week_seq d_week_seq2 - ,sun_sales sun_sales2 - ,mon_sales mon_sales2 - ,tue_sales tue_sales2 - ,wed_sales wed_sales2 - ,thu_sales thu_sales2 - ,fri_sales fri_sales2 - ,sat_sales sat_sales2 - from wswscs - ,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 1999+1) z - where d_week_seq1=d_week_seq2-53 - order by d_week_seq1; - --- end template query2.tpl query 27 in stream 7 --- start template query21.tpl query 28 in stream 7 -select /* TPC-DS query21.tpl 0.14 */ * - from(select w_warehouse_name - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('2000-02-27' as date)) - then inv_quantity_on_hand - else 0 end) as inv_before - ,sum(case when (cast(d_date as date) >= cast ('2000-02-27' as date)) - then inv_quantity_on_hand - else 0 end) as inv_after - from inventory - ,warehouse - ,item - ,date_dim - where i_current_price between 0.99 and 1.49 - and i_item_sk = inv_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('2000-02-27' as date)) - and dateadd(day,30,cast ('2000-02-27' as date)) - group by w_warehouse_name, i_item_id) x - where (case when inv_before > 0 - then inv_after / inv_before - else null - end) between 2.0/3.0 and 3.0/2.0 - order by w_warehouse_name - ,i_item_id - limit 100; - --- end template query21.tpl query 28 in stream 7 --- start template query97.tpl query 29 in stream 7 -with /* TPC-DS query97.tpl 0.38 */ ssci as ( -select ss_customer_sk customer_sk - ,ss_item_sk item_sk -from store_sales,date_dim -where ss_sold_date_sk = d_date_sk - and d_month_seq between 1224 and 1224 + 11 -group by ss_customer_sk - ,ss_item_sk), -csci as( - select cs_bill_customer_sk customer_sk - ,cs_item_sk item_sk -from catalog_sales,date_dim -where cs_sold_date_sk = d_date_sk - and d_month_seq between 1224 and 1224 + 11 -group by cs_bill_customer_sk - ,cs_item_sk) - select sum(case when ssci.customer_sk is not null and csci.customer_sk is null then 1 else 0 end) store_only - ,sum(case when ssci.customer_sk is null and csci.customer_sk is not null then 1 else 0 end) catalog_only - ,sum(case when ssci.customer_sk is not null and csci.customer_sk is not null then 1 else 0 end) store_and_catalog -from ssci full outer join csci on (ssci.customer_sk=csci.customer_sk - and ssci.item_sk = csci.item_sk) -limit 100; - --- end template query97.tpl query 29 in stream 7 --- start template query62.tpl query 30 in stream 7 -select /* TPC-DS query62.tpl 0.24 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 30) and - (ws_ship_date_sk - ws_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 60) and - (ws_ship_date_sk - ws_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 90) and - (ws_ship_date_sk - ws_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - web_sales - ,warehouse - ,ship_mode - ,web_site - ,date_dim -where - d_month_seq between 1224 and 1224 + 11 -and ws_ship_date_sk = d_date_sk -and ws_warehouse_sk = w_warehouse_sk -and ws_ship_mode_sk = sm_ship_mode_sk -and ws_web_site_sk = web_site_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -limit 100; - --- end template query62.tpl query 30 in stream 7 --- start template query47.tpl query 31 in stream 7 -with /* TPC-DS query47.tpl 0.42 */ v1 as( - select i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, - s_store_name, s_company_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - s_store_name, s_company_name - order by d_year, d_moy) rn - from item, store_sales, date_dim, store - where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - ( - d_year = 2000 or - ( d_year = 2000-1 and d_moy =12) or - ( d_year = 2000+1 and d_moy =1) - ) - group by i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy), - v2 as( - select v1.i_category - ,v1.d_year - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1.s_store_name = v1_lag.s_store_name and - v1.s_store_name = v1_lead.s_store_name and - v1.s_company_name = v1_lag.s_company_name and - v1.s_company_name = v1_lead.s_company_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 2000 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, psum - limit 100; - --- end template query47.tpl query 31 in stream 7 --- start template query60.tpl query 32 in stream 7 -with /* TPC-DS query60.tpl 0.29 */ ss as ( - select - i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Jewelry')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 8 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -7 - group by i_item_id), - cs as ( - select - i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Jewelry')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 8 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -7 - group by i_item_id), - ws as ( - select - i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Jewelry')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 8 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -7 - group by i_item_id) - select - i_item_id -,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by i_item_id - ,total_sales - limit 100; - --- end template query60.tpl query 32 in stream 7 --- start template query71.tpl query 33 in stream 7 -select /* TPC-DS query71.tpl 0.72 */ i_brand_id brand_id, i_brand brand,t_hour,t_minute, - sum(ext_price) ext_price - from item, (select ws_ext_sales_price as ext_price, - ws_sold_date_sk as sold_date_sk, - ws_item_sk as sold_item_sk, - ws_sold_time_sk as time_sk - from web_sales,date_dim - where d_date_sk = ws_sold_date_sk - and d_moy=11 - and d_year=2001 - union all - select cs_ext_sales_price as ext_price, - cs_sold_date_sk as sold_date_sk, - cs_item_sk as sold_item_sk, - cs_sold_time_sk as time_sk - from catalog_sales,date_dim - where d_date_sk = cs_sold_date_sk - and d_moy=11 - and d_year=2001 - union all - select ss_ext_sales_price as ext_price, - ss_sold_date_sk as sold_date_sk, - ss_item_sk as sold_item_sk, - ss_sold_time_sk as time_sk - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - and d_moy=11 - and d_year=2001 - ) tmp,time_dim - where - sold_item_sk = i_item_sk - and i_manager_id=1 - and time_sk = t_time_sk - and (t_meal_time = 'breakfast' or t_meal_time = 'dinner') - group by i_brand, i_brand_id,t_hour,t_minute - order by ext_price desc, i_brand_id - ; - --- end template query71.tpl query 33 in stream 7 --- start template query46.tpl query 34 in stream 7 -select /* TPC-DS query46.tpl 0.23 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and (household_demographics.hd_dep_count = 2 or - household_demographics.hd_vehicle_count= -1) - and date_dim.d_dow in (6,0) - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_city in ('Mount Olive','Winchester','Jefferson','Smyrna','Riverdale') - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,ca_city) dn,customer,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - limit 100; - --- end template query46.tpl query 34 in stream 7 --- start template query10.tpl query 35 in stream 7 -select /* TPC-DS query10.tpl 0.26 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3, - cd_dep_count, - count(*) cnt4, - cd_dep_employed_count, - count(*) cnt5, - cd_dep_college_count, - count(*) cnt6 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_county in ('Medina County','Jefferson Davis County','Howard County','Hamlin County','Calumet County') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 1 and 1+3) and - (exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 1 ANd 1+3) or - exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 1 and 1+3)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count -limit 100; - --- end template query10.tpl query 35 in stream 7 --- start template query14a.tpl query 36 in stream 7 -with /* TPC-DS query14a.tpl 0.69 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1998 AND 1998 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1998 AND 1998 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1998 AND 1998 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as - (select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2) x) -, - results AS -(select channel, i_brand_id, i_class_id, i_category_id, sum(sales) sum_sales, sum(number_sales) number_sales - from ( - select 'store' channel, i_brand_id,i_class_id - ,i_category_id,sum(ss_quantity*ss_list_price) sales - , count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1998+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales) - union all - select 'catalog' channel, i_brand_id,i_class_id,i_category_id, sum(cs_quantity*cs_list_price) sales, count(*) number_sales - from catalog_sales - ,item - ,date_dim - where cs_item_sk in (select ss_item_sk from cross_items) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1998+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(cs_quantity*cs_list_price) > (select average_sales from avg_sales) - union all - select 'web' channel, i_brand_id,i_class_id,i_category_id, sum(ws_quantity*ws_list_price) sales , count(*) number_sales - from web_sales - ,item - ,date_dim - where ws_item_sk in (select ss_item_sk from cross_items) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1998+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ws_quantity*ws_list_price) > (select average_sales from avg_sales) - ) y - group by channel, i_brand_id,i_class_id,i_category_id) - - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales -from ( - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales from results - union - select channel, i_brand_id, i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id, i_class_id - union - select channel, i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id - union - select channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel - union - select null as channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results) z -order by channel, i_brand_id, i_class_id, i_category_id - limit 100; -with /* TPC-DS query14a.tpl 0.69 part2 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1998 AND 1998 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1998 AND 1998 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1998 AND 1998 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as -(select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2) x) - select this_year.channel ty_channel - ,this_year.i_brand_id ty_brand - ,this_year.i_class_id ty_class - ,this_year.i_category_id ty_category - ,this_year.sales ty_sales - ,this_year.number_sales ty_number_sales - ,last_year.channel ly_channel - ,last_year.i_brand_id ly_brand - ,last_year.i_class_id ly_class - ,last_year.i_category_id ly_category - ,last_year.sales ly_sales - ,last_year.number_sales ly_number_sales -from - (select 'store' channel, i_brand_id,i_class_id,i_category_id - ,sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1998 + 1 - and d_moy = 12 - and d_dom = 8) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) this_year, - (select 'store' channel, i_brand_id,i_class_id - ,i_category_id, sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1998 - and d_moy = 12 - and d_dom = 8) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) last_year - where this_year.i_brand_id= last_year.i_brand_id - and this_year.i_class_id = last_year.i_class_id - and this_year.i_category_id = last_year.i_category_id - order by this_year.channel, this_year.i_brand_id, this_year.i_class_id, this_year.i_category_id - limit 100; - --- end template query14a.tpl query 36 in stream 7 --- start template query35a.tpl query 37 in stream 7 -select /* TPC-DS query35a.tpl 0.47 */ - ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - count(*) cnt1, - avg(cd_dep_count), - avg(cd_dep_count), - min(cd_dep_count), - cd_dep_employed_count, - count(*) cnt2, - avg(cd_dep_employed_count), - avg(cd_dep_employed_count), - min(cd_dep_employed_count), - cd_dep_college_count, - count(*) cnt3, - avg(cd_dep_college_count), - avg(cd_dep_college_count), - min(cd_dep_college_count) - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2001 and - d_qoy < 4) and - exists (select * from - (select ws_bill_customer_sk customsk - from web_sales,date_dim - where - ws_sold_date_sk = d_date_sk and - d_year = 2001 and - d_qoy < 4 - union all - select cs_ship_customer_sk customsk - from catalog_sales,date_dim - where - cs_sold_date_sk = d_date_sk and - d_year = 2001 and - d_qoy < 4)x - where x.customsk = c.c_customer_sk) - group by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - limit 100; - --- end template query35a.tpl query 37 in stream 7 --- start template query55.tpl query 38 in stream 7 -select /* TPC-DS query55.tpl 0.82 */ i_brand_id brand_id, i_brand brand, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=39 - and d_moy=11 - and d_year=2002 - group by i_brand, i_brand_id - order by ext_price desc, i_brand_id -limit 100 ; - --- end template query55.tpl query 38 in stream 7 --- start template query37.tpl query 39 in stream 7 -select /* TPC-DS query37.tpl 0.31 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, catalog_sales - where i_current_price between 11 and 11 + 30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('2002-01-25' as date) and dateadd(day,60,cast('2002-01-25' as date)) - and i_manufact_id in (972,856,918,809) - and inv_quantity_on_hand between 100 and 500 - and cs_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query37.tpl query 39 in stream 7 --- start template query52.tpl query 40 in stream 7 -select /* TPC-DS query52.tpl 0.59 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_sales_price) ext_price - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=11 - and dt.d_year=2000 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,ext_price desc - ,brand_id -limit 100 ; - --- end template query52.tpl query 40 in stream 7 --- start template query9.tpl query 41 in stream 7 -select /* TPC-DS query9.tpl 0.49 */ case when (select count(*) - from store_sales - where ss_quantity between 1 and 20) > 107521604 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 1 and 20) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 1 and 20) end bucket1 , - case when (select count(*) - from store_sales - where ss_quantity between 21 and 40) > 299620105 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 21 and 40) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 21 and 40) end bucket2, - case when (select count(*) - from store_sales - where ss_quantity between 41 and 60) > 1017110300 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 41 and 60) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 41 and 60) end bucket3, - case when (select count(*) - from store_sales - where ss_quantity between 61 and 80) > 735933470 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 61 and 80) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 61 and 80) end bucket4, - case when (select count(*) - from store_sales - where ss_quantity between 81 and 100) > 324007091 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 81 and 100) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 81 and 100) end bucket5 -from reason -where r_reason_sk = 1 -; - --- end template query9.tpl query 41 in stream 7 --- start template query85.tpl query 42 in stream 7 -select /* TPC-DS query85.tpl 0.33 */ substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) - from web_sales, web_returns, web_page, customer_demographics cd1, - customer_demographics cd2, customer_address, date_dim, reason - where ws_web_page_sk = wp_web_page_sk - and ws_item_sk = wr_item_sk - and ws_order_number = wr_order_number - and ws_sold_date_sk = d_date_sk and d_year = 2001 - and cd1.cd_demo_sk = wr_refunded_cdemo_sk - and cd2.cd_demo_sk = wr_returning_cdemo_sk - and ca_address_sk = wr_refunded_addr_sk - and r_reason_sk = wr_reason_sk - and - ( - ( - cd1.cd_marital_status = 'M' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Primary' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 100.00 and 150.00 - ) - or - ( - cd1.cd_marital_status = 'D' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Secondary' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 50.00 and 100.00 - ) - or - ( - cd1.cd_marital_status = 'W' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'College' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ca_country = 'United States' - and - ca_state in ('AK', 'IA', 'UT') - and ws_net_profit between 100 and 200 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('KS', 'MO', 'WA') - and ws_net_profit between 150 and 300 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('SD', 'VA', 'NH') - and ws_net_profit between 50 and 250 - ) - ) -group by r_reason_desc -order by substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) -limit 100; - --- end template query85.tpl query 42 in stream 7 --- start template query40.tpl query 43 in stream 7 -select /* TPC-DS query40.tpl 0.86 */ - w_state - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('2000-06-09' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_before - ,sum(case when (cast(d_date as date) >= cast ('2000-06-09' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_after - from - catalog_sales left outer join catalog_returns on - (cs_order_number = cr_order_number - and cs_item_sk = cr_item_sk) - ,warehouse - ,item - ,date_dim - where - i_current_price between 0.99 and 1.49 - and i_item_sk = cs_item_sk - and cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('2000-06-09' as date)) - and dateadd(day,30,cast ('2000-06-09' as date)) - group by - w_state,i_item_id - order by w_state,i_item_id -limit 100; - --- end template query40.tpl query 43 in stream 7 --- start template query76.tpl query 44 in stream 7 -select /* TPC-DS query76.tpl 0.99 */ channel, col_name, d_year, d_qoy, i_category, COUNT(*) sales_cnt, SUM(ext_sales_price) sales_amt FROM ( - SELECT 'store' as channel, 'ss_cdemo_sk' col_name, d_year, d_qoy, i_category, ss_ext_sales_price ext_sales_price - FROM store_sales, item, date_dim - WHERE ss_cdemo_sk IS NULL - AND ss_sold_date_sk=d_date_sk - AND ss_item_sk=i_item_sk - UNION ALL - SELECT 'web' as channel, 'ws_ship_mode_sk' col_name, d_year, d_qoy, i_category, ws_ext_sales_price ext_sales_price - FROM web_sales, item, date_dim - WHERE ws_ship_mode_sk IS NULL - AND ws_sold_date_sk=d_date_sk - AND ws_item_sk=i_item_sk - UNION ALL - SELECT 'catalog' as channel, 'cs_ship_customer_sk' col_name, d_year, d_qoy, i_category, cs_ext_sales_price ext_sales_price - FROM catalog_sales, item, date_dim - WHERE cs_ship_customer_sk IS NULL - AND cs_sold_date_sk=d_date_sk - AND cs_item_sk=i_item_sk) foo -GROUP BY channel, col_name, d_year, d_qoy, i_category -ORDER BY channel, col_name, d_year, d_qoy, i_category -limit 100; - --- end template query76.tpl query 44 in stream 7 --- start template query44.tpl query 45 in stream 7 -select /* TPC-DS query44.tpl 0.4 */ asceding.rnk, i1.i_product_name best_performing, i2.i_product_name worst_performing -from(select * - from (select item_sk,rank() over (order by rank_col asc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 532 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 532 - and ss_promo_sk is null - group by ss_store_sk))V1)V11 - where rnk < 11) asceding, - (select * - from (select item_sk,rank() over (order by rank_col desc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 532 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 532 - and ss_promo_sk is null - group by ss_store_sk))V2)V21 - where rnk < 11) descending, -item i1, -item i2 -where asceding.rnk = descending.rnk - and i1.i_item_sk=asceding.item_sk - and i2.i_item_sk=descending.item_sk -order by asceding.rnk -limit 100; - --- end template query44.tpl query 45 in stream 7 --- start template query3.tpl query 46 in stream 7 -select /* TPC-DS query3.tpl 0.45 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_discount_amt) sum_agg - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manufact_id = 367 - and dt.d_moy=12 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,sum_agg desc - ,brand_id - limit 100; - --- end template query3.tpl query 46 in stream 7 --- start template query26.tpl query 47 in stream 7 -select /* TPC-DS query26.tpl 0.85 */ i_item_id, - avg(cs_quantity) agg1, - avg(cs_list_price) agg2, - avg(cs_coupon_amt) agg3, - avg(cs_sales_price) agg4 - from catalog_sales, customer_demographics, date_dim, item, promotion - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd_demo_sk and - cs_promo_sk = p_promo_sk and - cd_gender = 'F' and - cd_marital_status = 'W' and - cd_education_status = '2 yr Degree' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 2002 - group by i_item_id - order by i_item_id - limit 100; - --- end template query26.tpl query 47 in stream 7 --- start template query19.tpl query 48 in stream 7 -select /* TPC-DS query19.tpl 0.8 */ i_brand_id brand_id, i_brand brand, i_manufact_id, i_manufact, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item,customer,customer_address,store - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=30 - and d_moy=11 - and d_year=2000 - and ss_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and substring(ca_zip,1,5) <> substring(s_zip,1,5) - and ss_store_sk = s_store_sk - group by i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact - order by ext_price desc - ,i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact -limit 100 ; - --- end template query19.tpl query 48 in stream 7 --- start template query58.tpl query 49 in stream 7 -with /* TPC-DS query58.tpl 0.19 */ ss_items as - (select i_item_id item_id - ,sum(ss_ext_sales_price) ss_item_rev - from store_sales - ,item - ,date_dim - where ss_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '1998-07-14')) - and ss_sold_date_sk = d_date_sk - group by i_item_id), - cs_items as - (select i_item_id item_id - ,sum(cs_ext_sales_price) cs_item_rev - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '1998-07-14')) - and cs_sold_date_sk = d_date_sk - group by i_item_id), - ws_items as - (select i_item_id item_id - ,sum(ws_ext_sales_price) ws_item_rev - from web_sales - ,item - ,date_dim - where ws_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq =(select d_week_seq - from date_dim - where d_date = '1998-07-14')) - and ws_sold_date_sk = d_date_sk - group by i_item_id) - select ss_items.item_id - ,ss_item_rev - ,ss_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ss_dev - ,cs_item_rev - ,cs_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 cs_dev - ,ws_item_rev - ,ws_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ws_dev - ,(ss_item_rev+cs_item_rev+ws_item_rev)/3 average - from ss_items,cs_items,ws_items - where ss_items.item_id=cs_items.item_id - and ss_items.item_id=ws_items.item_id - and ss_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - and ss_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and cs_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and cs_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and ws_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and ws_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - order by item_id - ,ss_item_rev - limit 100; - --- end template query58.tpl query 49 in stream 7 --- start template query42.tpl query 50 in stream 7 -select /* TPC-DS query42.tpl 0.61 */ dt.d_year - ,item.i_category_id - ,item.i_category - ,sum(ss_ext_sales_price) - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=11 - and dt.d_year=2001 - group by dt.d_year - ,item.i_category_id - ,item.i_category - order by sum(ss_ext_sales_price) desc,dt.d_year - ,item.i_category_id - ,item.i_category -limit 100 ; - --- end template query42.tpl query 50 in stream 7 --- start template query75.tpl query 51 in stream 7 -WITH /* TPC-DS query75.tpl 0.3 */ all_sales AS ( - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,SUM(sales_cnt) AS sales_cnt - ,SUM(sales_amt) AS sales_amt - FROM (SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,cs_quantity - COALESCE(cr_return_quantity,0) AS sales_cnt - ,cs_ext_sales_price - COALESCE(cr_return_amount,0.0) AS sales_amt - FROM catalog_sales JOIN item ON i_item_sk=cs_item_sk - JOIN date_dim ON d_date_sk=cs_sold_date_sk - LEFT JOIN catalog_returns ON (cs_order_number=cr_order_number - AND cs_item_sk=cr_item_sk) - WHERE i_category='Electronics' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ss_quantity - COALESCE(sr_return_quantity,0) AS sales_cnt - ,ss_ext_sales_price - COALESCE(sr_return_amt,0.0) AS sales_amt - FROM store_sales JOIN item ON i_item_sk=ss_item_sk - JOIN date_dim ON d_date_sk=ss_sold_date_sk - LEFT JOIN store_returns ON (ss_ticket_number=sr_ticket_number - AND ss_item_sk=sr_item_sk) - WHERE i_category='Electronics' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ws_quantity - COALESCE(wr_return_quantity,0) AS sales_cnt - ,ws_ext_sales_price - COALESCE(wr_return_amt,0.0) AS sales_amt - FROM web_sales JOIN item ON i_item_sk=ws_item_sk - JOIN date_dim ON d_date_sk=ws_sold_date_sk - LEFT JOIN web_returns ON (ws_order_number=wr_order_number - AND ws_item_sk=wr_item_sk) - WHERE i_category='Electronics') sales_detail - GROUP BY d_year, i_brand_id, i_class_id, i_category_id, i_manufact_id) - SELECT prev_yr.d_year AS prev_year - ,curr_yr.d_year AS year - ,curr_yr.i_brand_id - ,curr_yr.i_class_id - ,curr_yr.i_category_id - ,curr_yr.i_manufact_id - ,prev_yr.sales_cnt AS prev_yr_cnt - ,curr_yr.sales_cnt AS curr_yr_cnt - ,curr_yr.sales_cnt-prev_yr.sales_cnt AS sales_cnt_diff - ,curr_yr.sales_amt-prev_yr.sales_amt AS sales_amt_diff - FROM all_sales curr_yr, all_sales prev_yr - WHERE curr_yr.i_brand_id=prev_yr.i_brand_id - AND curr_yr.i_class_id=prev_yr.i_class_id - AND curr_yr.i_category_id=prev_yr.i_category_id - AND curr_yr.i_manufact_id=prev_yr.i_manufact_id - AND curr_yr.d_year=1999 - AND prev_yr.d_year=1999-1 - AND CAST(curr_yr.sales_cnt AS DECIMAL(17,2))/CAST(prev_yr.sales_cnt AS DECIMAL(17,2))<0.9 - ORDER BY sales_cnt_diff,sales_amt_diff - limit 100; - --- end template query75.tpl query 51 in stream 7 --- start template query17.tpl query 52 in stream 7 -select /* TPC-DS query17.tpl 0.41 */ i_item_id - ,i_item_desc - ,s_state - ,count(ss_quantity) as store_sales_quantitycount - ,avg(ss_quantity) as store_sales_quantityave - ,stddev_samp(ss_quantity) as store_sales_quantitystdev - ,stddev_samp(ss_quantity)/avg(ss_quantity) as store_sales_quantitycov - ,count(sr_return_quantity) as store_returns_quantitycount - ,avg(sr_return_quantity) as store_returns_quantityave - ,stddev_samp(sr_return_quantity) as store_returns_quantitystdev - ,stddev_samp(sr_return_quantity)/avg(sr_return_quantity) as store_returns_quantitycov - ,count(cs_quantity) as catalog_sales_quantitycount ,avg(cs_quantity) as catalog_sales_quantityave - ,stddev_samp(cs_quantity) as catalog_sales_quantitystdev - ,stddev_samp(cs_quantity)/avg(cs_quantity) as catalog_sales_quantitycov - from store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where d1.d_quarter_name = '2000Q1' - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_quarter_name in ('2000Q1','2000Q2','2000Q3') - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_quarter_name in ('2000Q1','2000Q2','2000Q3') - group by i_item_id - ,i_item_desc - ,s_state - order by i_item_id - ,i_item_desc - ,s_state -limit 100; - --- end template query17.tpl query 52 in stream 7 --- start template query38.tpl query 53 in stream 7 -select /* TPC-DS query38.tpl 0.54 */ count(*) from ( - select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1199 and 1199 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1199 and 1199 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1199 and 1199 + 11 -) hot_cust -limit 100; - --- end template query38.tpl query 53 in stream 7 --- start template query82.tpl query 54 in stream 7 -select /* TPC-DS query82.tpl 0.67 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, store_sales - where i_current_price between 26 and 26+30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('1998-05-11' as date) and dateadd(day,60,cast('1998-05-11' as date)) - and i_manufact_id in (523,775,291,930) - and inv_quantity_on_hand between 100 and 500 - and ss_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query82.tpl query 54 in stream 7 --- start template query87.tpl query 55 in stream 7 -select /* TPC-DS query87.tpl 0.77 */ count(*) -from ((select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1213 and 1213+11) - except - (select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1213 and 1213+11) - except - (select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1213 and 1213+11) -) cool_cust -; - --- end template query87.tpl query 55 in stream 7 --- start template query43.tpl query 56 in stream 7 -select /* TPC-DS query43.tpl 0.15 */ s_store_name, s_store_id, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from date_dim, store_sales, store - where d_date_sk = ss_sold_date_sk and - s_store_sk = ss_store_sk and - s_gmt_offset = -6 and - d_year = 1998 - group by s_store_name, s_store_id - order by s_store_name, s_store_id,sun_sales,mon_sales,tue_sales,wed_sales,thu_sales,fri_sales,sat_sales - limit 100; - --- end template query43.tpl query 56 in stream 7 --- start template query11.tpl query 57 in stream 7 -with /* TPC-DS query11.tpl 0.51 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ss_ext_list_price-ss_ext_discount_amt) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ws_ext_list_price-ws_ext_discount_amt) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_email_address - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 2001 - and t_s_secyear.dyear = 2001+1 - and t_w_firstyear.dyear = 2001 - and t_w_secyear.dyear = 2001+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else 0.0 end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else 0.0 end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_email_address -limit 100; - --- end template query11.tpl query 57 in stream 7 --- start template query5a.tpl query 58 in stream 7 -with /* TPC-DS query5a.tpl 0.98 */ ssr as - (select s_store_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ss_store_sk as store_sk, - ss_sold_date_sk as date_sk, - ss_ext_sales_price as sales_price, - ss_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from store_sales - union all - select sr_store_sk as store_sk, - sr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - sr_return_amt as return_amt, - sr_net_loss as net_loss - from store_returns - ) salesreturns, - date_dim, - store - where date_sk = d_date_sk - and d_date between cast('2000-08-09' as date) - and dateadd(day,14,cast('2000-08-09' as date)) - and store_sk = s_store_sk - group by s_store_id) - , - csr as - (select cp_catalog_page_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select cs_catalog_page_sk as page_sk, - cs_sold_date_sk as date_sk, - cs_ext_sales_price as sales_price, - cs_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from catalog_sales - union all - select cr_catalog_page_sk as page_sk, - cr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - cr_return_amount as return_amt, - cr_net_loss as net_loss - from catalog_returns - ) salesreturns, - date_dim, - catalog_page - where date_sk = d_date_sk - and d_date between cast('2000-08-09' as date) - and dateadd(day,14,cast('2000-08-09' as date)) - and page_sk = cp_catalog_page_sk - group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ws_web_site_sk as wsr_web_site_sk, - ws_sold_date_sk as date_sk, - ws_ext_sales_price as sales_price, - ws_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from web_sales - union all - select ws_web_site_sk as wsr_web_site_sk, - wr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - wr_return_amt as return_amt, - wr_net_loss as net_loss - from web_returns left outer join web_sales on - ( wr_item_sk = ws_item_sk - and wr_order_number = ws_order_number) - ) salesreturns, - date_dim, - web_site - where date_sk = d_date_sk - and d_date between cast('2000-08-09' as date) - and dateadd(day,14,cast('2000-08-09' as date)) - and wsr_web_site_sk = web_site_sk - group by web_site_id) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || s_store_id as id - , sales - , returns - , (profit - profit_loss) as profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || cp_catalog_page_id as id - , sales - , returns - , (profit - profit_loss) as profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , (profit - profit_loss) as profit - from wsr - ) x - group by channel, id) - select channel, id, sales, returns, profit from ( - select channel, id, sales, returns, profit from results - union - select channel, null as id, sum(sales), sum(returns), sum(profit) from results group by channel - union - select null as channel, null as id, sum(sales), sum(returns), sum(profit) from results) foo -order by channel, id -limit 100; - --- end template query5a.tpl query 58 in stream 7 --- start template query41.tpl query 59 in stream 7 -select /* TPC-DS query41.tpl 0.62 */ distinct(i_product_name) - from item i1 - where i_manufact_id between 677 and 677+40 - and (select count(*) as item_cnt - from item - where (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'seashell' or i_color = 'antique') and - (i_units = 'Dram' or i_units = 'Pallet') and - (i_size = 'economy' or i_size = 'N/A') - ) or - (i_category = 'Women' and - (i_color = 'goldenrod' or i_color = 'peach') and - (i_units = 'Oz' or i_units = 'Gross') and - (i_size = 'petite' or i_size = 'medium') - ) or - (i_category = 'Men' and - (i_color = 'blue' or i_color = 'papaya') and - (i_units = 'Bundle' or i_units = 'Cup') and - (i_size = 'extra large' or i_size = 'large') - ) or - (i_category = 'Men' and - (i_color = 'ivory' or i_color = 'dark') and - (i_units = 'Tsp' or i_units = 'Lb') and - (i_size = 'economy' or i_size = 'N/A') - ))) or - (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'magenta' or i_color = 'yellow') and - (i_units = 'Dozen' or i_units = 'Carton') and - (i_size = 'economy' or i_size = 'N/A') - ) or - (i_category = 'Women' and - (i_color = 'white' or i_color = 'green') and - (i_units = 'Tbl' or i_units = 'Ton') and - (i_size = 'petite' or i_size = 'medium') - ) or - (i_category = 'Men' and - (i_color = 'linen' or i_color = 'deep') and - (i_units = 'Unknown' or i_units = 'N/A') and - (i_size = 'extra large' or i_size = 'large') - ) or - (i_category = 'Men' and - (i_color = 'purple' or i_color = 'brown') and - (i_units = 'Bunch' or i_units = 'Gram') and - (i_size = 'economy' or i_size = 'N/A') - )))) > 0 - order by i_product_name - limit 100; - --- end template query41.tpl query 59 in stream 7 --- start template query61.tpl query 60 in stream 7 -select /* TPC-DS query61.tpl 0.97 */ promotions,total,cast(promotions as decimal(15,4))/cast(total as decimal(15,4))*100 -from - (select sum(ss_ext_sales_price) promotions - from store_sales - ,store - ,promotion - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_promo_sk = p_promo_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -7 - and i_category = 'Sports' - and (p_channel_dmail = 'Y' or p_channel_email = 'Y' or p_channel_tv = 'Y') - and s_gmt_offset = -7 - and d_year = 1999 - and d_moy = 12) promotional_sales, - (select sum(ss_ext_sales_price) total - from store_sales - ,store - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -7 - and i_category = 'Sports' - and s_gmt_offset = -7 - and d_year = 1999 - and d_moy = 12) all_sales -order by promotions, total -limit 100; - --- end template query61.tpl query 60 in stream 7 --- start template query33.tpl query 61 in stream 7 -with /* TPC-DS query33.tpl 0.22 */ ss as ( - select - i_manufact_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Home')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 2 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id), - cs as ( - select - i_manufact_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Home')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 2 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id), - ws as ( - select - i_manufact_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Home')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 2 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id) - select i_manufact_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_manufact_id - order by total_sales -limit 100; - --- end template query33.tpl query 61 in stream 7 --- start template query49.tpl query 62 in stream 7 -select /* TPC-DS query49.tpl 0.48 */ channel, item, return_ratio, return_rank, currency_rank from - (select - 'web' as channel - ,web.item - ,web.return_ratio - ,web.return_rank - ,web.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select ws.ws_item_sk as item - ,(cast(sum(coalesce(wr.wr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(wr.wr_return_amt,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - web_sales ws left outer join web_returns wr - on (ws.ws_order_number = wr.wr_order_number and - ws.ws_item_sk = wr.wr_item_sk) - ,date_dim - where - wr.wr_return_amt > 10000 - and ws.ws_net_profit > 1 - and ws.ws_net_paid > 0 - and ws.ws_quantity > 0 - and ws_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 11 - group by ws.ws_item_sk - ) in_web - ) web - where - ( - web.return_rank <= 10 - or - web.currency_rank <= 10 - ) - union - select - 'catalog' as channel - ,catalog.item - ,catalog.return_ratio - ,catalog.return_rank - ,catalog.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select - cs.cs_item_sk as item - ,(cast(sum(coalesce(cr.cr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(cr.cr_return_amount,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - catalog_sales cs left outer join catalog_returns cr - on (cs.cs_order_number = cr.cr_order_number and - cs.cs_item_sk = cr.cr_item_sk) - ,date_dim - where - cr.cr_return_amount > 10000 - and cs.cs_net_profit > 1 - and cs.cs_net_paid > 0 - and cs.cs_quantity > 0 - and cs_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 11 - group by cs.cs_item_sk - ) in_cat - ) catalog - where - ( - catalog.return_rank <= 10 - or - catalog.currency_rank <=10 - ) - union - select - 'store' as channel - ,store.item - ,store.return_ratio - ,store.return_rank - ,store.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select sts.ss_item_sk as item - ,(cast(sum(coalesce(sr.sr_return_quantity,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(sr.sr_return_amt,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - store_sales sts left outer join store_returns sr - on (sts.ss_ticket_number = sr.sr_ticket_number and sts.ss_item_sk = sr.sr_item_sk) - ,date_dim - where - sr.sr_return_amt > 10000 - and sts.ss_net_profit > 1 - and sts.ss_net_paid > 0 - and sts.ss_quantity > 0 - and ss_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 11 - group by sts.ss_item_sk - ) in_store - ) store - where ( - store.return_rank <= 10 - or - store.currency_rank <= 10 - ) - ) - order by 1,4,5,2 - limit 100; - --- end template query49.tpl query 62 in stream 7 --- start template query7.tpl query 63 in stream 7 -select /* TPC-DS query7.tpl 0.2 */ i_item_id, - avg(ss_quantity) agg1, - avg(ss_list_price) agg2, - avg(ss_coupon_amt) agg3, - avg(ss_sales_price) agg4 - from store_sales, customer_demographics, date_dim, item, promotion - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_cdemo_sk = cd_demo_sk and - ss_promo_sk = p_promo_sk and - cd_gender = 'F' and - cd_marital_status = 'M' and - cd_education_status = '4 yr Degree' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 2000 - group by i_item_id - order by i_item_id - limit 100; - --- end template query7.tpl query 63 in stream 7 --- start template query73.tpl query 64 in stream 7 -select /* TPC-DS query73.tpl 0.79 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_buy_potential = '1001-5000' or - household_demographics.hd_buy_potential = 'Unknown') - and household_demographics.hd_vehicle_count > 0 - and case when household_demographics.hd_vehicle_count > 0 then - household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count else null end > 1 - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_county in ('Stafford County','Miller County','Coal County','Bronx County') - group by ss_ticket_number,ss_customer_sk) dj,customer - where ss_customer_sk = c_customer_sk - and cnt between 1 and 5 - order by cnt desc, c_last_name asc; - --- end template query73.tpl query 64 in stream 7 --- start template query89.tpl query 65 in stream 7 -select /* TPC-DS query89.tpl 0.56 */ * -from( -select i_category, i_class, i_brand, - s_store_name, s_company_name, - d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, s_store_name, s_company_name) - avg_monthly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - d_year in (2001) and - ((i_category in ('Electronics','Home','Children') and - i_class in ('audio','accent','school-uniforms') - ) - or (i_category in ('Jewelry','Books','Music') and - i_class in ('estate','fiction','country') - )) -group by i_category, i_class, i_brand, - s_store_name, s_company_name, d_moy) tmp1 -where case when (avg_monthly_sales <> 0) then (abs(sum_sales - avg_monthly_sales) / avg_monthly_sales) else null end > 0.1 -order by sum_sales - avg_monthly_sales, s_store_name -limit 100; - --- end template query89.tpl query 65 in stream 7 --- start template query81.tpl query 66 in stream 7 -with /* TPC-DS query81.tpl 0.37 */ customer_total_return as - (select cr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(cr_return_amt_inc_tax) as ctr_total_return - from catalog_returns - ,date_dim - ,customer_address - where cr_returned_date_sk = d_date_sk - and d_year =1998 - and cr_returning_addr_sk = ca_address_sk - group by cr_returning_customer_sk - ,ca_state ) - select c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'WA' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - limit 100; - --- end template query81.tpl query 66 in stream 7 --- start template query78.tpl query 67 in stream 7 -with /* TPC-DS query78.tpl 0.10 */ ws as - (select d_year AS ws_sold_year, ws_item_sk, - ws_bill_customer_sk ws_customer_sk, - sum(ws_quantity) ws_qty, - sum(ws_wholesale_cost) ws_wc, - sum(ws_sales_price) ws_sp - from web_sales - left join web_returns on wr_order_number=ws_order_number and ws_item_sk=wr_item_sk - join date_dim on ws_sold_date_sk = d_date_sk - where wr_order_number is null - group by d_year, ws_item_sk, ws_bill_customer_sk - ), -cs as - (select d_year AS cs_sold_year, cs_item_sk, - cs_bill_customer_sk cs_customer_sk, - sum(cs_quantity) cs_qty, - sum(cs_wholesale_cost) cs_wc, - sum(cs_sales_price) cs_sp - from catalog_sales - left join catalog_returns on cr_order_number=cs_order_number and cs_item_sk=cr_item_sk - join date_dim on cs_sold_date_sk = d_date_sk - where cr_order_number is null - group by d_year, cs_item_sk, cs_bill_customer_sk - ), -ss as - (select d_year AS ss_sold_year, ss_item_sk, - ss_customer_sk, - sum(ss_quantity) ss_qty, - sum(ss_wholesale_cost) ss_wc, - sum(ss_sales_price) ss_sp - from store_sales - left join store_returns on sr_ticket_number=ss_ticket_number and ss_item_sk=sr_item_sk - join date_dim on ss_sold_date_sk = d_date_sk - where sr_ticket_number is null - group by d_year, ss_item_sk, ss_customer_sk - ) - select -ss_item_sk, -round(ss_qty/(coalesce(ws_qty,0)+coalesce(cs_qty,0)),2) ratio, -ss_qty store_qty, ss_wc store_wholesale_cost, ss_sp store_sales_price, -coalesce(ws_qty,0)+coalesce(cs_qty,0) other_chan_qty, -coalesce(ws_wc,0)+coalesce(cs_wc,0) other_chan_wholesale_cost, -coalesce(ws_sp,0)+coalesce(cs_sp,0) other_chan_sales_price -from ss -left join ws on (ws_sold_year=ss_sold_year and ws_item_sk=ss_item_sk and ws_customer_sk=ss_customer_sk) -left join cs on (cs_sold_year=ss_sold_year and cs_item_sk=ss_item_sk and cs_customer_sk=ss_customer_sk) -where (coalesce(ws_qty,0)>0 or coalesce(cs_qty, 0)>0) and ss_sold_year=1998 -order by - ss_item_sk, - ss_qty desc, ss_wc desc, ss_sp desc, - other_chan_qty, - other_chan_wholesale_cost, - other_chan_sales_price, - ratio -limit 100; - --- end template query78.tpl query 67 in stream 7 --- start template query18a.tpl query 68 in stream 7 -with /* TPC-DS query18a.tpl 0.90 */ results as - (select i_item_id, - ca_country, - ca_state, - ca_county, - cast(cs_quantity as decimal(12,2)) agg1, - cast(cs_list_price as decimal(12,2)) agg2, - cast(cs_coupon_amt as decimal(12,2)) agg3, - cast(cs_sales_price as decimal(12,2)) agg4, - cast(cs_net_profit as decimal(12,2)) agg5, - cast(c_birth_year as decimal(12,2)) agg6, - cast(cd1.cd_dep_count as decimal(12,2)) agg7 - from catalog_sales, customer_demographics cd1, customer_demographics cd2, customer, customer_address, date_dim, item - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd1.cd_demo_sk and - cs_bill_customer_sk = c_customer_sk and - cd1.cd_gender = 'M' and - cd1.cd_education_status = 'Secondary' and - c_current_cdemo_sk = cd2.cd_demo_sk and - c_current_addr_sk = ca_address_sk and - c_birth_month in (9,6,10,5,12,8) and - d_year = 1999 and - ca_state in ('NE','KY','LA','IA','IL','TX','MO') - ) - select i_item_id, ca_country, ca_state, ca_county, agg1, agg2, agg3, agg4, agg5, agg6, agg7 - from ( - select i_item_id, ca_country, ca_state, ca_county, avg(agg1) agg1, - avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state, ca_county - union all - select i_item_id, ca_country, ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state - union all - select i_item_id, ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country - union all - select i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - ) foo - order by ca_country, ca_state, ca_county, i_item_id - limit 100; - --- end template query18a.tpl query 68 in stream 7 --- start template query36a.tpl query 69 in stream 7 -with /* TPC-DS query36a.tpl 0.21 */ results as - (select - sum(ss_net_profit) as ss_net_profit, sum(ss_ext_sales_price) as ss_ext_sales_price, - sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin - ,i_category - ,i_class - ,0 as g_category, 0 as g_class - from - store_sales - ,date_dim d1 - ,item - ,store - where - d1.d_year = 2001 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and s_state in ('TN','KS','MO','NE', - 'IN','WV','LA','CO') - group by i_category,i_class) - , - results_rollup as - (select gross_margin ,i_category ,i_class,0 as t_category, 0 as t_class, 0 as lochierarchy from results - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - i_category, NULL AS i_class, 0 as t_category, 1 as t_class, 1 as lochierarchy from results group by i_category - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - NULL AS i_category ,NULL AS i_class, 1 as t_category, 1 as t_class, 2 as lochierarchy from results) - select - gross_margin ,i_category ,i_class, lochierarchy,rank() over ( - partition by lochierarchy, case when t_class = 0 then i_category end - order by gross_margin asc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then i_category end - ,rank_within_parent - limit 100; - --- end template query36a.tpl query 69 in stream 7 --- start template query51.tpl query 70 in stream 7 -WITH /* TPC-DS query51.tpl 0.46 */ web_v1 as ( -select - ws_item_sk item_sk, d_date, - sum(sum(ws_sales_price)) - over (partition by ws_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from web_sales - ,date_dim -where ws_sold_date_sk=d_date_sk - and d_month_seq between 1179 and 1179+11 - and ws_item_sk is not NULL -group by ws_item_sk, d_date), -store_v1 as ( -select - ss_item_sk item_sk, d_date, - sum(sum(ss_sales_price)) - over (partition by ss_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from store_sales - ,date_dim -where ss_sold_date_sk=d_date_sk - and d_month_seq between 1179 and 1179+11 - and ss_item_sk is not NULL -group by ss_item_sk, d_date) - select * -from (select item_sk - ,d_date - ,web_sales - ,store_sales - ,max(web_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) web_cumulative - ,max(store_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) store_cumulative - from (select case when web.item_sk is not null then web.item_sk else store.item_sk end item_sk - ,case when web.d_date is not null then web.d_date else store.d_date end d_date - ,web.cume_sales web_sales - ,store.cume_sales store_sales - from web_v1 web full outer join store_v1 store on (web.item_sk = store.item_sk - and web.d_date = store.d_date) - )x )y -where web_cumulative > store_cumulative -order by item_sk - ,d_date -limit 100; - --- end template query51.tpl query 70 in stream 7 --- start template query56.tpl query 71 in stream 7 -with /* TPC-DS query56.tpl 0.83 */ ss as ( - select i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where i_item_id in (select - i_item_id -from item -where i_color in ('navy','dark','midnight')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 3 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - cs as ( - select i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('navy','dark','midnight')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 3 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - ws as ( - select i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('navy','dark','midnight')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 3 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id) - select i_item_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by total_sales, - i_item_id - limit 100; - --- end template query56.tpl query 71 in stream 7 --- start template query83.tpl query 72 in stream 7 -with /* TPC-DS query83.tpl 0.96 */ sr_items as - (select i_item_id item_id, - sum(sr_return_quantity) sr_item_qty - from store_returns, - item, - date_dim - where sr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2000-06-01','2000-09-03','2000-11-03'))) - and sr_returned_date_sk = d_date_sk - group by i_item_id), - cr_items as - (select i_item_id item_id, - sum(cr_return_quantity) cr_item_qty - from catalog_returns, - item, - date_dim - where cr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2000-06-01','2000-09-03','2000-11-03'))) - and cr_returned_date_sk = d_date_sk - group by i_item_id), - wr_items as - (select i_item_id item_id, - sum(wr_return_quantity) wr_item_qty - from web_returns, - item, - date_dim - where wr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2000-06-01','2000-09-03','2000-11-03'))) - and wr_returned_date_sk = d_date_sk - group by i_item_id) - select sr_items.item_id - ,sr_item_qty - ,sr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 sr_dev - ,cr_item_qty - ,cr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 cr_dev - ,wr_item_qty - ,wr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 wr_dev - ,(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 average - from sr_items - ,cr_items - ,wr_items - where sr_items.item_id=cr_items.item_id - and sr_items.item_id=wr_items.item_id - order by sr_items.item_id - ,sr_item_qty - limit 100; - --- end template query83.tpl query 72 in stream 7 --- start template query23.tpl query 73 in stream 7 -with /* TPC-DS query23.tpl 0.68 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (1999,1999+1,1999+2,1999+3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1999,1999+1,1999+2,1999+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * -from - max_store_sales)) - select sum(sales) - from (select cs_quantity*cs_list_price sales - from catalog_sales - ,date_dim - where d_year = 1999 - and d_moy = 5 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - union all - select ws_quantity*ws_list_price sales - from web_sales - ,date_dim - where d_year = 1999 - and d_moy = 5 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer)) - limit 100; -with /* TPC-DS query23.tpl 0.68 part2 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (1999,1999 + 1,1999 + 2,1999 + 3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1999,1999+1,1999+2,1999+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * - from max_store_sales)) - select c_last_name,c_first_name,sales - from (select c_last_name,c_first_name,sum(cs_quantity*cs_list_price) sales - from catalog_sales - ,customer - ,date_dim - where d_year = 1999 - and d_moy = 5 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and cs_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name - union all - select c_last_name,c_first_name,sum(ws_quantity*ws_list_price) sales - from web_sales - ,customer - ,date_dim - where d_year = 1999 - and d_moy = 5 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and ws_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name) - order by c_last_name,c_first_name,sales - limit 100; - --- end template query23.tpl query 73 in stream 7 --- start template query8.tpl query 74 in stream 7 -select /* TPC-DS query8.tpl 0.63 */ s_store_name - ,sum(ss_net_profit) - from store_sales - ,date_dim - ,store, - (select ca_zip - from ( - SELECT substring(ca_zip,1,5) ca_zip - FROM customer_address - WHERE substring(ca_zip,1,5) IN ( - '21175','72322','67968','34313','32304','61466', - '94492','20722','52514','98190','63121', - '39823','10655','45218','26886','45640', - '36206','70903','56459','78339','97390', - '32809','26094','88869','53172','10929', - '94961','95664','50207','25724','77133', - '30607','87578','59453','45486','66014', - '95535','43818','39694','69554','27021', - '99649','46606','65402','43324','40478', - '92827','66121','62475','51212','40739', - '82094','86475','36125','94259','43393', - '29978','87940','35097','55377','87116', - '77508','21376','14240','61828','43121', - '91185','25503','75483','48942','16496', - '12216','33874','20793','57872','60568', - '54345','53148','29659','24832','78140', - '96328','91010','42828','34072','11775', - '71758','63524','35738','99516','32860', - '18927','85363','22075','56657','73664', - '92121','25801','72985','11444','40183', - '72579','48471','93952','80240','32196', - '24539','56294','57569','80932','98118', - '10595','70793','72964','77462','41853', - '81557','46827','76783','98489','34762', - '96818','34322','86802','35849','31756', - '79464','69801','92637','24958','83047', - '81407','29957','96662','78849','24455', - '81620','42290','38798','86627','91693', - '74843','22903','15546','79931','79036', - '13783','84706','18272','68250','41140', - '88007','83741','84110','78053','86880', - '55050','40818','85591','88039','12392', - '75071','67938','51389','32172','97764', - '49450','89934','53405','88902','79884', - '92512','93785','60591','16651','12290', - '85613','47623','64776','87490','77465', - '80889','67197','23144','42801','82414', - '81918','77629','13166','61566','34444', - '63325','34493','79005','35821','39003', - '17882','66398','47936','77623','15145', - '64623','22967','38577','76596','32024', - '51135','29755','39505','64239','47958', - '92927','19665','28131','47975','13218', - '16330','93530','41248','37352','57237', - '39244','50179','20096','98347','18045', - '69508','30848','90450','73878','24166', - '21434','68505','85492','10924','12326', - '32959','32104','12555','16242','89560', - '69188','72392','89607','93492','72216', - '63876','17547','53936','26990','54519', - '82730','77521','57900','91666','17627', - '55708','86562','96763','36638','86865', - '33305','27317','49512','12975','37263', - '58797','58491','89378','59164','91894', - '35512','13955','25949','17278','71954', - '56337','57519','69090','88420','26602', - '44109','36599','11093','74686','69762', - '42711','59339','84724','13810','61653', - '73921','24929','57264','58276','68246', - '33186','10399','37989','50915','35832', - '78847','19650','24937','51051','67603', - '51285','29576','57200','74451','11768', - '60381','18499','23927','53633','82339', - '49395','94410','43363','45590','58753', - '29047','48561','59311','84780','93113', - '42627','20388','53565','57871','97242', - '77302','92439','21029','76672','79996', - '86490','52908','40733','18728','87561', - '53171','42735','78186','36065','69412', - '97402','69772','86439','67010','36808', - '38641','67872','64611','73372','18646', - '99186','97495','10664','33694','13903', - '42883','14702','66127','90518','50157', - '87670','73485','41786','25896','48476', - '11779','43322','75163','97039','12824', - '21333','13107','25888','66140','39458', - '11524','59072','41841','72901','19180', - '38695','98288','27237','69469','26826', - '78974','41299','53804','10093','90061', - '60320','11237','76697','36217') - intersect - select ca_zip - from (SELECT substring(ca_zip,1,5) ca_zip,count(*) cnt - FROM customer_address, customer - WHERE ca_address_sk = c_current_addr_sk and - c_preferred_cust_flag='Y' - group by ca_zip - having count(*) > 10)A1)A2) V1 - where ss_store_sk = s_store_sk - and ss_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 2002 - and (substring(s_zip,1,2) = substring(V1.ca_zip,1,2)) - group by s_store_name - order by s_store_name - limit 100; - --- end template query8.tpl query 74 in stream 7 --- start template query24.tpl query 75 in stream 7 -with /* TPC-DS query24.tpl 0.92 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_net_paid) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip -and s_market_id=6 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'moccasin' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; -with /* TPC-DS query24.tpl 0.92 part2 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_net_paid) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip - and s_market_id = 6 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'white' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; - --- end template query24.tpl query 75 in stream 7 --- start template query63.tpl query 76 in stream 7 -select /* TPC-DS query63.tpl 0.27 */ * -from (select i_manager_id - ,sum(ss_sales_price) sum_sales - ,avg(sum(ss_sales_price)) over (partition by i_manager_id) avg_monthly_sales - from item - ,store_sales - ,date_dim - ,store - where ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and d_month_seq in (1219,1219+1,1219+2,1219+3,1219+4,1219+5,1219+6,1219+7,1219+8,1219+9,1219+10,1219+11) - and (( i_category in ('Books','Children','Electronics') - and i_class in ('personal','portable','reference','self-help') - and i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) - or( i_category in ('Women','Music','Men') - and i_class in ('accessories','classical','fragrances','pants') - and i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manager_id, d_moy) tmp1 -where case when avg_monthly_sales > 0 then abs (sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 -order by i_manager_id - ,avg_monthly_sales - ,sum_sales -limit 100; - --- end template query63.tpl query 76 in stream 7 --- start template query1.tpl query 77 in stream 7 -with /* TPC-DS query1.tpl 0.12 */ customer_total_return as -(select sr_customer_sk as ctr_customer_sk -,sr_store_sk as ctr_store_sk -,sum(SR_FEE) as ctr_total_return -from store_returns -,date_dim -where sr_returned_date_sk = d_date_sk -and d_year =1998 -group by sr_customer_sk -,sr_store_sk) - select c_customer_id -from customer_total_return ctr1 -,store -,customer -where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 -from customer_total_return ctr2 -where ctr1.ctr_store_sk = ctr2.ctr_store_sk) -and s_store_sk = ctr1.ctr_store_sk -and s_state = 'LA' -and ctr1.ctr_customer_sk = c_customer_sk -order by c_customer_id -limit 100; - --- end template query1.tpl query 77 in stream 7 --- start template query12.tpl query 78 in stream 7 -select /* TPC-DS query12.tpl 0.64 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ws_ext_sales_price) as itemrevenue - ,sum(ws_ext_sales_price)*100/sum(sum(ws_ext_sales_price)) over - (partition by i_class) as revenueratio -from - web_sales - ,item - ,date_dim -where - ws_item_sk = i_item_sk - and i_category in ('Jewelry', 'Sports', 'Books') - and ws_sold_date_sk = d_date_sk - and d_date between cast('1999-04-10' as date) - and dateadd(day,30,cast('1999-04-10' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query12.tpl query 78 in stream 7 --- start template query68.tpl query 79 in stream 7 -select /* TPC-DS query68.tpl 0.95 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,extended_price - ,extended_tax - ,list_price - from (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_ext_sales_price) extended_price - ,sum(ss_ext_list_price) list_price - ,sum(ss_ext_tax) extended_tax - from store_sales - ,date_dim - ,store - ,household_demographics - ,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_dep_count = 5 or - household_demographics.hd_vehicle_count= 2) - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_city in ('Logan','Ebenezer') - group by ss_ticket_number - ,ss_customer_sk - ,ss_addr_sk,ca_city) dn - ,customer - ,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,ss_ticket_number - limit 100; - --- end template query68.tpl query 79 in stream 7 --- start template query66.tpl query 80 in stream 7 -select /* TPC-DS query66.tpl 0.39 */ - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - ,sum(jan_sales) as jan_sales - ,sum(feb_sales) as feb_sales - ,sum(mar_sales) as mar_sales - ,sum(apr_sales) as apr_sales - ,sum(may_sales) as may_sales - ,sum(jun_sales) as jun_sales - ,sum(jul_sales) as jul_sales - ,sum(aug_sales) as aug_sales - ,sum(sep_sales) as sep_sales - ,sum(oct_sales) as oct_sales - ,sum(nov_sales) as nov_sales - ,sum(dec_sales) as dec_sales - ,sum(jan_sales/w_warehouse_sq_ft) as jan_sales_per_sq_foot - ,sum(feb_sales/w_warehouse_sq_ft) as feb_sales_per_sq_foot - ,sum(mar_sales/w_warehouse_sq_ft) as mar_sales_per_sq_foot - ,sum(apr_sales/w_warehouse_sq_ft) as apr_sales_per_sq_foot - ,sum(may_sales/w_warehouse_sq_ft) as may_sales_per_sq_foot - ,sum(jun_sales/w_warehouse_sq_ft) as jun_sales_per_sq_foot - ,sum(jul_sales/w_warehouse_sq_ft) as jul_sales_per_sq_foot - ,sum(aug_sales/w_warehouse_sq_ft) as aug_sales_per_sq_foot - ,sum(sep_sales/w_warehouse_sq_ft) as sep_sales_per_sq_foot - ,sum(oct_sales/w_warehouse_sq_ft) as oct_sales_per_sq_foot - ,sum(nov_sales/w_warehouse_sq_ft) as nov_sales_per_sq_foot - ,sum(dec_sales/w_warehouse_sq_ft) as dec_sales_per_sq_foot - ,sum(jan_net) as jan_net - ,sum(feb_net) as feb_net - ,sum(mar_net) as mar_net - ,sum(apr_net) as apr_net - ,sum(may_net) as may_net - ,sum(jun_net) as jun_net - ,sum(jul_net) as jul_net - ,sum(aug_net) as aug_net - ,sum(sep_net) as sep_net - ,sum(oct_net) as oct_net - ,sum(nov_net) as nov_net - ,sum(dec_net) as dec_net - from ( - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'HARMSTORF' || ',' || 'USPS' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then ws_sales_price* ws_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then ws_sales_price* ws_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then ws_sales_price* ws_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then ws_sales_price* ws_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then ws_sales_price* ws_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then ws_sales_price* ws_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then ws_sales_price* ws_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then ws_sales_price* ws_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then ws_sales_price* ws_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then ws_sales_price* ws_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then ws_sales_price* ws_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then ws_sales_price* ws_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as dec_net - from - web_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - ws_warehouse_sk = w_warehouse_sk - and ws_sold_date_sk = d_date_sk - and ws_sold_time_sk = t_time_sk - and ws_ship_mode_sk = sm_ship_mode_sk - and d_year = 2000 - and t_time between 35249 and 35249+28800 - and sm_carrier in ('HARMSTORF','USPS') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - union all - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'HARMSTORF' || ',' || 'USPS' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then cs_ext_list_price* cs_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then cs_ext_list_price* cs_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then cs_ext_list_price* cs_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then cs_ext_list_price* cs_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then cs_ext_list_price* cs_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then cs_ext_list_price* cs_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then cs_ext_list_price* cs_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then cs_ext_list_price* cs_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then cs_ext_list_price* cs_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then cs_ext_list_price* cs_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then cs_ext_list_price* cs_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then cs_ext_list_price* cs_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then cs_net_paid * cs_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then cs_net_paid * cs_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then cs_net_paid * cs_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then cs_net_paid * cs_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then cs_net_paid * cs_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then cs_net_paid * cs_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then cs_net_paid * cs_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then cs_net_paid * cs_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then cs_net_paid * cs_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then cs_net_paid * cs_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then cs_net_paid * cs_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then cs_net_paid * cs_quantity else 0 end) as dec_net - from - catalog_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and cs_sold_time_sk = t_time_sk - and cs_ship_mode_sk = sm_ship_mode_sk - and d_year = 2000 - and t_time between 35249 AND 35249+28800 - and sm_carrier in ('HARMSTORF','USPS') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - ) x - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - order by w_warehouse_name - limit 100; - --- end template query66.tpl query 80 in stream 7 --- start template query67a.tpl query 81 in stream 7 -with /* TPC-DS query67a.tpl 0.35 */ results as -( select i_category ,i_class ,i_brand ,i_product_name ,d_year ,d_qoy ,d_moy ,s_store_id - ,sum(coalesce(ss_sales_price*ss_quantity,0)) sumsales - from store_sales ,date_dim ,store ,item - where ss_sold_date_sk=d_date_sk - and ss_item_sk=i_item_sk - and ss_store_sk = s_store_sk - and d_month_seq between 1211 and 1211 + 11 - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy,s_store_id) - , - results_rollup as - (select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, s_store_id, sumsales - from results - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy - union all - select i_category, i_class, i_brand, i_product_name, d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year - union all - select i_category, i_class, i_brand, i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name - union all - select i_category, i_class, i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand - union all - select i_category, i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class - union all - select i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category - union all - select null i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results) - - select * -from (select i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rank() over (partition by i_category order by sumsales desc) rk - from results_rollup) dw2 -where rk <= 100 -order by i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rk -limit 100; - --- end template query67a.tpl query 81 in stream 7 --- start template query77a.tpl query 82 in stream 7 -with /* TPC-DS query77a.tpl 0.78 */ ss as - (select s_store_sk, - sum(ss_ext_sales_price) as sales, - sum(ss_net_profit) as profit - from store_sales, - date_dim, - store - where ss_sold_date_sk = d_date_sk - and d_date between cast('1998-08-02' as date) - and dateadd(day,30,cast('1998-08-02' as date)) - and ss_store_sk = s_store_sk - group by s_store_sk) - , - sr as - (select s_store_sk, - sum(sr_return_amt) as returns, - sum(sr_net_loss) as profit_loss - from store_returns, - date_dim, - store - where sr_returned_date_sk = d_date_sk - and d_date between cast('1998-08-02' as date) - and dateadd(day,30,cast('1998-08-02' as date)) - and sr_store_sk = s_store_sk - group by s_store_sk), - cs as - (select cs_call_center_sk, - sum(cs_ext_sales_price) as sales, - sum(cs_net_profit) as profit - from catalog_sales, - date_dim - where cs_sold_date_sk = d_date_sk - and d_date between cast('1998-08-02' as date) - and dateadd(day,30,cast('1998-08-02' as date)) - group by cs_call_center_sk - ), - cr as - (select cr_call_center_sk, - sum(cr_return_amount) as returns, - sum(cr_net_loss) as profit_loss - from catalog_returns, - date_dim - where cr_returned_date_sk = d_date_sk - and d_date between cast('1998-08-02' as date) - and dateadd(day,30,cast('1998-08-02' as date)) - group by cr_call_center_sk), - ws as - ( select wp_web_page_sk, - sum(ws_ext_sales_price) as sales, - sum(ws_net_profit) as profit - from web_sales, - date_dim, - web_page - where ws_sold_date_sk = d_date_sk - and d_date between cast('1998-08-02' as date) - and dateadd(day,30,cast('1998-08-02' as date)) - and ws_web_page_sk = wp_web_page_sk - group by wp_web_page_sk), - wr as - (select wp_web_page_sk, - sum(wr_return_amt) as returns, - sum(wr_net_loss) as profit_loss - from web_returns, - date_dim, - web_page - where wr_returned_date_sk = d_date_sk - and d_date between cast('1998-08-02' as date) - and dateadd(day,30,cast('1998-08-02' as date)) - and wr_web_page_sk = wp_web_page_sk - group by wp_web_page_sk) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , ss.s_store_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ss left join sr - on ss.s_store_sk = sr.s_store_sk - union all - select 'catalog channel' as channel - , cs_call_center_sk as id - , sales - , returns - , (profit - profit_loss) as profit - from cs - , cr - union all - select 'web channel' as channel - , ws.wp_web_page_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ws left join wr - on ws.wp_web_page_sk = wr.wp_web_page_sk - ) x - group by channel, id ) - - select * - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results -) foo -order by channel, id - limit 100; - --- end template query77a.tpl query 82 in stream 7 --- start template query15.tpl query 83 in stream 7 -select /* TPC-DS query15.tpl 0.57 */ ca_zip - ,sum(cs_sales_price) - from catalog_sales - ,customer - ,customer_address - ,date_dim - where cs_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', - '85392', '85460', '80348', '81792') - or ca_state in ('CA','WA','GA') - or cs_sales_price > 500) - and cs_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 2000 - group by ca_zip - order by ca_zip - limit 100; - --- end template query15.tpl query 83 in stream 7 --- start template query88.tpl query 84 in stream 7 -select /* TPC-DS query88.tpl 0.66 */ * -from - (select count(*) h8_30_to_9 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s1, - (select count(*) h9_to_9_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s2, - (select count(*) h9_30_to_10 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s3, - (select count(*) h10_to_10_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s4, - (select count(*) h10_30_to_11 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s5, - (select count(*) h11_to_11_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s6, - (select count(*) h11_30_to_12 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s7, - (select count(*) h12_to_12_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 12 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s8 -; - --- end template query88.tpl query 84 in stream 7 --- start template query65.tpl query 85 in stream 7 -select /* TPC-DS query65.tpl 0.71 */ - s_store_name, - i_item_desc, - sc.revenue, - i_current_price, - i_wholesale_cost, - i_brand - from store, item, - (select ss_store_sk, avg(revenue) as ave - from - (select ss_store_sk, ss_item_sk, - sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1208 and 1208+11 - group by ss_store_sk, ss_item_sk) sa - group by ss_store_sk) sb, - (select ss_store_sk, ss_item_sk, sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1208 and 1208+11 - group by ss_store_sk, ss_item_sk) sc - where sb.ss_store_sk = sc.ss_store_sk and - sc.revenue <= 0.1 * sb.ave and - s_store_sk = sc.ss_store_sk and - i_item_sk = sc.ss_item_sk - order by s_store_name, i_item_desc -limit 100; - --- end template query65.tpl query 85 in stream 7 --- start template query59.tpl query 86 in stream 7 -with /* TPC-DS query59.tpl 0.30 */ wss as - (select d_week_seq, - ss_store_sk, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - group by d_week_seq,ss_store_sk - ) - select s_store_name1,s_store_id1,d_week_seq1 - ,sun_sales1/sun_sales2,mon_sales1/mon_sales2 - ,tue_sales1/tue_sales2,wed_sales1/wed_sales2,thu_sales1/thu_sales2 - ,fri_sales1/fri_sales2,sat_sales1/sat_sales2 - from - (select s_store_name s_store_name1,wss.d_week_seq d_week_seq1 - ,s_store_id s_store_id1,sun_sales sun_sales1 - ,mon_sales mon_sales1,tue_sales tue_sales1 - ,wed_sales wed_sales1,thu_sales thu_sales1 - ,fri_sales fri_sales1,sat_sales sat_sales1 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1204 and 1204 + 11) y, - (select s_store_name s_store_name2,wss.d_week_seq d_week_seq2 - ,s_store_id s_store_id2,sun_sales sun_sales2 - ,mon_sales mon_sales2,tue_sales tue_sales2 - ,wed_sales wed_sales2,thu_sales thu_sales2 - ,fri_sales fri_sales2,sat_sales sat_sales2 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1204+ 12 and 1204 + 23) x - where s_store_id1=s_store_id2 - and d_week_seq1=d_week_seq2-52 - order by s_store_name1,s_store_id1,d_week_seq1 -limit 100; - --- end template query59.tpl query 86 in stream 7 --- start template query96.tpl query 87 in stream 7 -select /* TPC-DS query96.tpl 0.1 */ count(*) -from store_sales - ,household_demographics - ,time_dim, store -where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 16 - and time_dim.t_minute >= 30 - and household_demographics.hd_dep_count = 5 - and store.s_store_name = 'ese' -order by count(*) -limit 100; - --- end template query96.tpl query 87 in stream 7 --- start template query54.tpl query 88 in stream 7 -with /* TPC-DS query54.tpl 0.81 */ my_customers as ( - select distinct c_customer_sk - , c_current_addr_sk - from - ( select cs_sold_date_sk sold_date_sk, - cs_bill_customer_sk customer_sk, - cs_item_sk item_sk - from catalog_sales - union all - select ws_sold_date_sk sold_date_sk, - ws_bill_customer_sk customer_sk, - ws_item_sk item_sk - from web_sales - ) cs_or_ws_sales, - item, - date_dim, - customer - where sold_date_sk = d_date_sk - and item_sk = i_item_sk - and i_category = 'Books' - and i_class = 'parenting' - and c_customer_sk = cs_or_ws_sales.customer_sk - and d_moy = 7 - and d_year = 2002 - ) - , my_revenue as ( - select c_customer_sk, - sum(ss_ext_sales_price) as revenue - from my_customers, - store_sales, - customer_address, - store, - date_dim - where c_current_addr_sk = ca_address_sk - and ca_county = s_county - and ca_state = s_state - and ss_sold_date_sk = d_date_sk - and c_customer_sk = ss_customer_sk - and d_month_seq between (select distinct d_month_seq+1 - from date_dim where d_year = 2002 and d_moy = 7) - and (select distinct d_month_seq+3 - from date_dim where d_year = 2002 and d_moy = 7) - group by c_customer_sk - ) - , segments as - (select cast((revenue/50) as bigint) as segment - from my_revenue - ) - select segment, count(*) as num_customers, segment*50 as segment_base - from segments - group by segment - order by segment, num_customers - limit 100; - --- end template query54.tpl query 88 in stream 7 --- start template query95.tpl query 89 in stream 7 -with /* TPC-DS query95.tpl 0.43 */ ws_wh as -(select ws1.ws_order_number,ws1.ws_warehouse_sk wh1,ws2.ws_warehouse_sk wh2 - from web_sales ws1,web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) - select - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2000-4-01' and - dateadd(day,60,cast('2000-4-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'MD' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and ws1.ws_order_number in (select ws_order_number - from ws_wh) -and ws1.ws_order_number in (select wr_order_number - from web_returns,ws_wh - where wr_order_number = ws_wh.ws_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query95.tpl query 89 in stream 7 --- start template query93.tpl query 90 in stream 7 -select /* TPC-DS query93.tpl 0.52 */ ss_customer_sk - ,sum(act_sales) sumsales - from (select ss_item_sk - ,ss_ticket_number - ,ss_customer_sk - ,case when sr_return_quantity is not null then (ss_quantity-sr_return_quantity)*ss_sales_price - else (ss_quantity*ss_sales_price) end act_sales - from store_sales left outer join store_returns on (sr_item_sk = ss_item_sk - and sr_ticket_number = ss_ticket_number) - ,reason - where sr_reason_sk = r_reason_sk - and r_reason_desc = 'reason 60') t - group by ss_customer_sk - order by sumsales, ss_customer_sk -limit 100; - --- end template query93.tpl query 90 in stream 7 --- start template query91.tpl query 91 in stream 7 -select /* TPC-DS query91.tpl 0.13 */ - cc_call_center_id Call_Center, - cc_name Call_Center_Name, - cc_manager Manager, - sum(cr_net_loss) Returns_Loss -from - call_center, - catalog_returns, - date_dim, - customer, - customer_address, - customer_demographics, - household_demographics -where - cr_call_center_sk = cc_call_center_sk -and cr_returned_date_sk = d_date_sk -and cr_returning_customer_sk= c_customer_sk -and cd_demo_sk = c_current_cdemo_sk -and hd_demo_sk = c_current_hdemo_sk -and ca_address_sk = c_current_addr_sk -and d_year = 1998 -and d_moy = 11 -and ( (cd_marital_status = 'M' and cd_education_status = 'Unknown') - or(cd_marital_status = 'W' and cd_education_status = 'Advanced Degree')) -and hd_buy_potential like '>10000%' -and ca_gmt_offset = -7 -group by cc_call_center_id,cc_name,cc_manager,cd_marital_status,cd_education_status -order by sum(cr_net_loss) desc; - --- end template query91.tpl query 91 in stream 7 --- start template query74.tpl query 92 in stream 7 -with /* TPC-DS query74.tpl 0.76 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,avg(ss_net_paid) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (2001,2001+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,avg(ws_net_paid) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - and d_year in (2001,2001+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - ) - select - t_s_secyear.customer_id, t_s_secyear.customer_first_name, t_s_secyear.customer_last_name - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.year = 2001 - and t_s_secyear.year = 2001+1 - and t_w_firstyear.year = 2001 - and t_w_secyear.year = 2001+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - order by 1,2,3 -limit 100; - --- end template query74.tpl query 92 in stream 7 --- start template query94.tpl query 93 in stream 7 -select /* TPC-DS query94.tpl 0.17 */ - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2000-5-01' and - dateadd(day,60,cast('2000-5-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'TX' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and exists (select * - from web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) -and not exists(select * - from web_returns wr1 - where ws1.ws_order_number = wr1.wr_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query94.tpl query 93 in stream 7 --- start template query16.tpl query 94 in stream 7 -select /* TPC-DS query16.tpl 0.25 */ - count(distinct cs_order_number) as "order count" - ,sum(cs_ext_ship_cost) as "total shipping cost" - ,sum(cs_net_profit) as "total net profit" -from - catalog_sales cs1 - ,date_dim - ,customer_address - ,call_center -where - d_date between '1999-5-01' and - dateadd(day, 60, cast('1999-5-01' as date)) -and cs1.cs_ship_date_sk = d_date_sk -and cs1.cs_ship_addr_sk = ca_address_sk -and ca_state = 'NE' -and cs1.cs_call_center_sk = cc_call_center_sk -and cc_county in ('Barrow County','Marshall County','Bronx County','Levy County', - 'Raleigh County' -) -and exists (select * - from catalog_sales cs2 - where cs1.cs_order_number = cs2.cs_order_number - and cs1.cs_warehouse_sk <> cs2.cs_warehouse_sk) -and not exists(select * - from catalog_returns cr1 - where cs1.cs_order_number = cr1.cr_order_number) -order by count(distinct cs_order_number) -limit 100; - --- end template query16.tpl query 94 in stream 7 --- start template query90.tpl query 95 in stream 7 -select /* TPC-DS query90.tpl 0.40 */ cast(amc as decimal(15,4))/cast(pmc as decimal(15,4)) am_pm_ratio - from ( select count(*) amc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 11 and 11+1 - and household_demographics.hd_dep_count = 2 - and web_page.wp_char_count between 5000 and 5200) at, - ( select count(*) pmc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 13 and 13+1 - and household_demographics.hd_dep_count = 2 - and web_page.wp_char_count between 5000 and 5200) pt - order by am_pm_ratio - limit 100; - --- end template query90.tpl query 95 in stream 7 --- start template query57.tpl query 96 in stream 7 -with /* TPC-DS query57.tpl 0.70 */ v1 as( - select i_category, i_brand, - cc_name, - d_year, d_moy, - sum(cs_sales_price) sum_sales, - avg(sum(cs_sales_price)) over - (partition by i_category, i_brand, - cc_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - cc_name - order by d_year, d_moy) rn - from item, catalog_sales, date_dim, call_center - where cs_item_sk = i_item_sk and - cs_sold_date_sk = d_date_sk and - cc_call_center_sk= cs_call_center_sk and - ( - d_year = 2000 or - ( d_year = 2000-1 and d_moy =12) or - ( d_year = 2000+1 and d_moy =1) - ) - group by i_category, i_brand, - cc_name , d_year, d_moy), - v2 as( - select v1.i_category, v1.i_brand, v1.cc_name - ,v1.d_year, v1.d_moy - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1. cc_name = v1_lag. cc_name and - v1. cc_name = v1_lead. cc_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 2000 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, avg_monthly_sales - limit 100; - --- end template query57.tpl query 96 in stream 7 --- start template query22a.tpl query 97 in stream 7 -with /* TPC-DS query22a.tpl 0.55 */ results as -(select i_product_name - ,i_brand - ,i_class - ,i_category - ,avg(inv_quantity_on_hand) qoh - from inventory - ,date_dim - ,item --- ,warehouse - where inv_date_sk=d_date_sk - and inv_item_sk=i_item_sk --- and inv_warehouse_sk = w_warehouse_sk - and d_month_seq between 1185 and 1185 + 11 - group by i_product_name,i_brand,i_class,i_category), -results_rollup as -(select i_product_name, i_brand, i_class, i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class,i_category -union all -select i_product_name, i_brand, i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class -union all -select i_product_name, i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand -union all -select i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name -union all -select null i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results) - select i_product_name, i_brand, i_class, i_category,qoh - from results_rollup - order by qoh, i_product_name, i_brand, i_class, i_category -limit 100; - --- end template query22a.tpl query 97 in stream 7 --- start template query50.tpl query 98 in stream 7 -select /* TPC-DS query50.tpl 0.60 */ - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 30) and - (sr_returned_date_sk - ss_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 60) and - (sr_returned_date_sk - ss_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 90) and - (sr_returned_date_sk - ss_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - store_sales - ,store_returns - ,store - ,date_dim d1 - ,date_dim d2 -where - d2.d_year = 1999 -and d2.d_moy = 10 -and ss_ticket_number = sr_ticket_number -and ss_item_sk = sr_item_sk -and ss_sold_date_sk = d1.d_date_sk -and sr_returned_date_sk = d2.d_date_sk -and ss_customer_sk = sr_customer_sk -and ss_store_sk = s_store_sk -group by - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -order by s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -limit 100; - --- end template query50.tpl query 98 in stream 7 --- start template query27a.tpl query 99 in stream 7 -with /* TPC-DS query27a.tpl 0.16 */ results as - (select i_item_id, - s_state, 0 as g_state, - ss_quantity agg1, - ss_list_price agg2, - ss_coupon_amt agg3, - ss_sales_price agg4 - from store_sales, customer_demographics, date_dim, store, item - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_store_sk = s_store_sk and - ss_cdemo_sk = cd_demo_sk and - cd_gender = 'M' and - cd_marital_status = 'S' and - cd_education_status = '2 yr Degree' and - d_year = 1999 and - s_state in ('TX','SD', 'MI', 'GA', 'IN', 'IN') - ) - - select i_item_id, - s_state, g_state, agg1, agg2, agg3, agg4 - from ( - select i_item_id, s_state, 0 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4 from results - group by i_item_id, s_state - union all - select i_item_id, NULL AS s_state, 1 AS g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as s_state, 1 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - ) foo - order by i_item_id, s_state - limit 100; - --- end template query27a.tpl query 99 in stream 7 diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/30TB/queries/query_8.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/30TB/queries/query_8.sql deleted file mode 100644 index a4d2d93f..00000000 --- a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/30TB/queries/query_8.sql +++ /dev/null @@ -1,5027 +0,0 @@ --- start template query57.tpl query 1 in stream 8 -with /* TPC-DS query57.tpl 0.70 */ v1 as( - select i_category, i_brand, - cc_name, - d_year, d_moy, - sum(cs_sales_price) sum_sales, - avg(sum(cs_sales_price)) over - (partition by i_category, i_brand, - cc_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - cc_name - order by d_year, d_moy) rn - from item, catalog_sales, date_dim, call_center - where cs_item_sk = i_item_sk and - cs_sold_date_sk = d_date_sk and - cc_call_center_sk= cs_call_center_sk and - ( - d_year = 2000 or - ( d_year = 2000-1 and d_moy =12) or - ( d_year = 2000+1 and d_moy =1) - ) - group by i_category, i_brand, - cc_name , d_year, d_moy), - v2 as( - select v1.i_category, v1.i_brand - ,v1.d_year - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1. cc_name = v1_lag. cc_name and - v1. cc_name = v1_lead. cc_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 2000 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, sum_sales - limit 100; - --- end template query57.tpl query 1 in stream 8 --- start template query29.tpl query 2 in stream 8 -select /* TPC-DS query29.tpl 0.53 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,avg(ss_quantity) as store_sales_quantity - ,avg(sr_return_quantity) as store_returns_quantity - ,avg(cs_quantity) as catalog_sales_quantity - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 1999 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 4 + 3 - and d2.d_year = 1999 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_year in (1999,1999+1,1999+2) - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query29.tpl query 2 in stream 8 --- start template query24.tpl query 3 in stream 8 -with /* TPC-DS query24.tpl 0.92 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_net_paid_inc_tax) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip -and s_market_id=7 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'red' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; -with /* TPC-DS query24.tpl 0.92 part2 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_net_paid_inc_tax) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip - and s_market_id = 7 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'blue' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; - --- end template query24.tpl query 3 in stream 8 --- start template query76.tpl query 4 in stream 8 -select /* TPC-DS query76.tpl 0.99 */ channel, col_name, d_year, d_qoy, i_category, COUNT(*) sales_cnt, SUM(ext_sales_price) sales_amt FROM ( - SELECT 'store' as channel, 'ss_cdemo_sk' col_name, d_year, d_qoy, i_category, ss_ext_sales_price ext_sales_price - FROM store_sales, item, date_dim - WHERE ss_cdemo_sk IS NULL - AND ss_sold_date_sk=d_date_sk - AND ss_item_sk=i_item_sk - UNION ALL - SELECT 'web' as channel, 'ws_ship_customer_sk' col_name, d_year, d_qoy, i_category, ws_ext_sales_price ext_sales_price - FROM web_sales, item, date_dim - WHERE ws_ship_customer_sk IS NULL - AND ws_sold_date_sk=d_date_sk - AND ws_item_sk=i_item_sk - UNION ALL - SELECT 'catalog' as channel, 'cs_ship_mode_sk' col_name, d_year, d_qoy, i_category, cs_ext_sales_price ext_sales_price - FROM catalog_sales, item, date_dim - WHERE cs_ship_mode_sk IS NULL - AND cs_sold_date_sk=d_date_sk - AND cs_item_sk=i_item_sk) foo -GROUP BY channel, col_name, d_year, d_qoy, i_category -ORDER BY channel, col_name, d_year, d_qoy, i_category -limit 100; - --- end template query76.tpl query 4 in stream 8 --- start template query37.tpl query 5 in stream 8 -select /* TPC-DS query37.tpl 0.31 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, catalog_sales - where i_current_price between 24 and 24 + 30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('1999-04-06' as date) and dateadd(day,60,cast('1999-04-06' as date)) - and i_manufact_id in (717,694,828,830) - and inv_quantity_on_hand between 100 and 500 - and cs_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query37.tpl query 5 in stream 8 --- start template query66.tpl query 6 in stream 8 -select /* TPC-DS query66.tpl 0.39 */ - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - ,sum(jan_sales) as jan_sales - ,sum(feb_sales) as feb_sales - ,sum(mar_sales) as mar_sales - ,sum(apr_sales) as apr_sales - ,sum(may_sales) as may_sales - ,sum(jun_sales) as jun_sales - ,sum(jul_sales) as jul_sales - ,sum(aug_sales) as aug_sales - ,sum(sep_sales) as sep_sales - ,sum(oct_sales) as oct_sales - ,sum(nov_sales) as nov_sales - ,sum(dec_sales) as dec_sales - ,sum(jan_sales/w_warehouse_sq_ft) as jan_sales_per_sq_foot - ,sum(feb_sales/w_warehouse_sq_ft) as feb_sales_per_sq_foot - ,sum(mar_sales/w_warehouse_sq_ft) as mar_sales_per_sq_foot - ,sum(apr_sales/w_warehouse_sq_ft) as apr_sales_per_sq_foot - ,sum(may_sales/w_warehouse_sq_ft) as may_sales_per_sq_foot - ,sum(jun_sales/w_warehouse_sq_ft) as jun_sales_per_sq_foot - ,sum(jul_sales/w_warehouse_sq_ft) as jul_sales_per_sq_foot - ,sum(aug_sales/w_warehouse_sq_ft) as aug_sales_per_sq_foot - ,sum(sep_sales/w_warehouse_sq_ft) as sep_sales_per_sq_foot - ,sum(oct_sales/w_warehouse_sq_ft) as oct_sales_per_sq_foot - ,sum(nov_sales/w_warehouse_sq_ft) as nov_sales_per_sq_foot - ,sum(dec_sales/w_warehouse_sq_ft) as dec_sales_per_sq_foot - ,sum(jan_net) as jan_net - ,sum(feb_net) as feb_net - ,sum(mar_net) as mar_net - ,sum(apr_net) as apr_net - ,sum(may_net) as may_net - ,sum(jun_net) as jun_net - ,sum(jul_net) as jul_net - ,sum(aug_net) as aug_net - ,sum(sep_net) as sep_net - ,sum(oct_net) as oct_net - ,sum(nov_net) as nov_net - ,sum(dec_net) as dec_net - from ( - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'DIAMOND' || ',' || 'FEDEX' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then ws_ext_list_price* ws_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then ws_ext_list_price* ws_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then ws_ext_list_price* ws_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then ws_ext_list_price* ws_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then ws_ext_list_price* ws_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then ws_ext_list_price* ws_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then ws_ext_list_price* ws_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then ws_ext_list_price* ws_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then ws_ext_list_price* ws_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then ws_ext_list_price* ws_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then ws_ext_list_price* ws_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then ws_ext_list_price* ws_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as dec_net - from - web_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - ws_warehouse_sk = w_warehouse_sk - and ws_sold_date_sk = d_date_sk - and ws_sold_time_sk = t_time_sk - and ws_ship_mode_sk = sm_ship_mode_sk - and d_year = 1999 - and t_time between 54367 and 54367+28800 - and sm_carrier in ('DIAMOND','FEDEX') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - union all - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'DIAMOND' || ',' || 'FEDEX' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then cs_sales_price* cs_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then cs_sales_price* cs_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then cs_sales_price* cs_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then cs_sales_price* cs_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then cs_sales_price* cs_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then cs_sales_price* cs_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then cs_sales_price* cs_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then cs_sales_price* cs_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then cs_sales_price* cs_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then cs_sales_price* cs_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then cs_sales_price* cs_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then cs_sales_price* cs_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as dec_net - from - catalog_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and cs_sold_time_sk = t_time_sk - and cs_ship_mode_sk = sm_ship_mode_sk - and d_year = 1999 - and t_time between 54367 AND 54367+28800 - and sm_carrier in ('DIAMOND','FEDEX') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - ) x - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - order by w_warehouse_name - limit 100; - --- end template query66.tpl query 6 in stream 8 --- start template query60.tpl query 7 in stream 8 -with /* TPC-DS query60.tpl 0.29 */ ss as ( - select - i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Jewelry')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 9 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -7 - group by i_item_id), - cs as ( - select - i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Jewelry')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 9 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -7 - group by i_item_id), - ws as ( - select - i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Jewelry')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 9 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -7 - group by i_item_id) - select - i_item_id -,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by i_item_id - ,total_sales - limit 100; - --- end template query60.tpl query 7 in stream 8 --- start template query98.tpl query 8 in stream 8 -select /* TPC-DS query98.tpl 0.32 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ss_ext_sales_price) as itemrevenue - ,sum(ss_ext_sales_price)*100/sum(sum(ss_ext_sales_price)) over - (partition by i_class) as revenueratio -from - store_sales - ,item - ,date_dim -where - ss_item_sk = i_item_sk - and i_category in ('Men', 'Jewelry', 'Sports') - and ss_sold_date_sk = d_date_sk - and d_date between cast('2000-01-18' as date) - and dateadd(day,30,cast('2000-01-18' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio; - --- end template query98.tpl query 8 in stream 8 --- start template query80a.tpl query 9 in stream 8 -with /* TPC-DS query80a.tpl 0.6 */ ssr as - (select s_store_id as store_id, - sum(ss_ext_sales_price) as sales, - sum(coalesce(sr_return_amt, 0)) as returns, - sum(ss_net_profit - coalesce(sr_net_loss, 0)) as profit - from store_sales left outer join store_returns on - (ss_item_sk = sr_item_sk and ss_ticket_number = sr_ticket_number), - date_dim, - store, - item, - promotion - where ss_sold_date_sk = d_date_sk - and d_date between cast('2002-08-29' as date) - and dateadd(day,30,cast('2002-08-29' as date)) - and ss_store_sk = s_store_sk - and ss_item_sk = i_item_sk - and i_current_price > 50 - and ss_promo_sk = p_promo_sk - and p_channel_tv = 'N' - group by s_store_id) - , - csr as - (select cp_catalog_page_id as catalog_page_id, - sum(cs_ext_sales_price) as sales, - sum(coalesce(cr_return_amount, 0)) as returns, - sum(cs_net_profit - coalesce(cr_net_loss, 0)) as profit - from catalog_sales left outer join catalog_returns on - (cs_item_sk = cr_item_sk and cs_order_number = cr_order_number), - date_dim, - catalog_page, - item, - promotion - where cs_sold_date_sk = d_date_sk - and d_date between cast('2002-08-29' as date) - and dateadd(day,30,cast('2002-08-29' as date)) - and cs_catalog_page_sk = cp_catalog_page_sk - and cs_item_sk = i_item_sk - and i_current_price > 50 - and cs_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(ws_ext_sales_price) as sales, - sum(coalesce(wr_return_amt, 0)) as returns, - sum(ws_net_profit - coalesce(wr_net_loss, 0)) as profit - from web_sales left outer join web_returns on - (ws_item_sk = wr_item_sk and ws_order_number = wr_order_number), - date_dim, - web_site, - item, - promotion - where ws_sold_date_sk = d_date_sk - and d_date between cast('2002-08-29' as date) - and dateadd(day,30,cast('2002-08-29' as date)) - and ws_web_site_sk = web_site_sk - and ws_item_sk = i_item_sk - and i_current_price > 50 - and ws_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by web_site_id) -, -results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || store_id as id - , sales - , returns - , profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || catalog_page_id as id - , sales - , returns - , profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , profit - from wsr - ) x - group by channel, id) - - select channel - , id - , sales - , returns - , profit - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results - ) foo - order by channel, id - limit 100; - --- end template query80a.tpl query 9 in stream 8 --- start template query12.tpl query 10 in stream 8 -select /* TPC-DS query12.tpl 0.64 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ws_ext_sales_price) as itemrevenue - ,sum(ws_ext_sales_price)*100/sum(sum(ws_ext_sales_price)) over - (partition by i_class) as revenueratio -from - web_sales - ,item - ,date_dim -where - ws_item_sk = i_item_sk - and i_category in ('Children', 'Electronics', 'Music') - and ws_sold_date_sk = d_date_sk - and d_date between cast('2002-04-26' as date) - and dateadd(day,30,cast('2002-04-26' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query12.tpl query 10 in stream 8 --- start template query59.tpl query 11 in stream 8 -with /* TPC-DS query59.tpl 0.30 */ wss as - (select d_week_seq, - ss_store_sk, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - group by d_week_seq,ss_store_sk - ) - select s_store_name1,s_store_id1,d_week_seq1 - ,sun_sales1/sun_sales2,mon_sales1/mon_sales2 - ,tue_sales1/tue_sales2,wed_sales1/wed_sales2,thu_sales1/thu_sales2 - ,fri_sales1/fri_sales2,sat_sales1/sat_sales2 - from - (select s_store_name s_store_name1,wss.d_week_seq d_week_seq1 - ,s_store_id s_store_id1,sun_sales sun_sales1 - ,mon_sales mon_sales1,tue_sales tue_sales1 - ,wed_sales wed_sales1,thu_sales thu_sales1 - ,fri_sales fri_sales1,sat_sales sat_sales1 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1210 and 1210 + 11) y, - (select s_store_name s_store_name2,wss.d_week_seq d_week_seq2 - ,s_store_id s_store_id2,sun_sales sun_sales2 - ,mon_sales mon_sales2,tue_sales tue_sales2 - ,wed_sales wed_sales2,thu_sales thu_sales2 - ,fri_sales fri_sales2,sat_sales sat_sales2 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1210+ 12 and 1210 + 23) x - where s_store_id1=s_store_id2 - and d_week_seq1=d_week_seq2-52 - order by s_store_name1,s_store_id1,d_week_seq1 -limit 100; - --- end template query59.tpl query 11 in stream 8 --- start template query70a.tpl query 12 in stream 8 -with /* TPC-DS query70a.tpl 0.34 */ results as -( select - sum(ss_net_profit) as total_sum ,s_state ,s_county, 0 as gstate, 0 as g_county - from - store_sales - ,date_dim d1 - ,store - where - d1.d_month_seq between 1219 and 1219 + 11 - and d1.d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - and s_state in - ( select s_state - from (select s_state as s_state, - rank() over ( partition by s_state order by sum(ss_net_profit) desc) as ranking - from store_sales, store, date_dim - where d_month_seq between 1219 and 1219 + 11 - and d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - group by s_state - ) tmp1 - where ranking <= 5) - group by s_state,s_county) , - results_rollup as -(select total_sum ,s_state ,s_county, 0 as g_state, 0 as g_county, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum,s_state, NULL as s_county, 0 as g_state, 1 as g_county, 1 as lochierarchy from results group by s_state - union - select sum(total_sum) as total_sum ,NULL as s_state ,NULL as s_county, 1 as g_state, 1 as g_county, 2 as lochierarchy from results) - select total_sum ,s_state ,s_county, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_county = 0 then s_state end - order by total_sum desc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then s_state end - ,rank_within_parent - limit 100; - --- end template query70a.tpl query 12 in stream 8 --- start template query91.tpl query 13 in stream 8 -select /* TPC-DS query91.tpl 0.13 */ - cc_call_center_id Call_Center, - cc_name Call_Center_Name, - cc_manager Manager, - sum(cr_net_loss) Returns_Loss -from - call_center, - catalog_returns, - date_dim, - customer, - customer_address, - customer_demographics, - household_demographics -where - cr_call_center_sk = cc_call_center_sk -and cr_returned_date_sk = d_date_sk -and cr_returning_customer_sk= c_customer_sk -and cd_demo_sk = c_current_cdemo_sk -and hd_demo_sk = c_current_hdemo_sk -and ca_address_sk = c_current_addr_sk -and d_year = 1998 -and d_moy = 12 -and ( (cd_marital_status = 'M' and cd_education_status = 'Unknown') - or(cd_marital_status = 'W' and cd_education_status = 'Advanced Degree')) -and hd_buy_potential like '501-1000%' -and ca_gmt_offset = -6 -group by cc_call_center_id,cc_name,cc_manager,cd_marital_status,cd_education_status -order by sum(cr_net_loss) desc; - --- end template query91.tpl query 13 in stream 8 --- start template query69.tpl query 14 in stream 8 -select /* TPC-DS query69.tpl 0.28 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_state in ('TX','AR','OK') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 1999 and - d_moy between 4 and 4+2) and - (not exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 1999 and - d_moy between 4 and 4+2) and - not exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 1999 and - d_moy between 4 and 4+2)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - limit 100; - --- end template query69.tpl query 14 in stream 8 --- start template query40.tpl query 15 in stream 8 -select /* TPC-DS query40.tpl 0.86 */ - w_state - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('2000-03-26' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_before - ,sum(case when (cast(d_date as date) >= cast ('2000-03-26' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_after - from - catalog_sales left outer join catalog_returns on - (cs_order_number = cr_order_number - and cs_item_sk = cr_item_sk) - ,warehouse - ,item - ,date_dim - where - i_current_price between 0.99 and 1.49 - and i_item_sk = cs_item_sk - and cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('2000-03-26' as date)) - and dateadd(day,30,cast ('2000-03-26' as date)) - group by - w_state,i_item_id - order by w_state,i_item_id -limit 100; - --- end template query40.tpl query 15 in stream 8 --- start template query2.tpl query 16 in stream 8 -with /* TPC-DS query2.tpl 0.84 */ wscs as - (select sold_date_sk - ,sales_price - from (select ws_sold_date_sk sold_date_sk - ,ws_ext_sales_price sales_price - from web_sales - union all - select cs_sold_date_sk sold_date_sk - ,cs_ext_sales_price sales_price - from catalog_sales)), - wswscs as - (select d_week_seq, - sum(case when (d_day_name='Sunday') then sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then sales_price else null end) sat_sales - from wscs - ,date_dim - where d_date_sk = sold_date_sk - group by d_week_seq) - select d_week_seq1 - ,round(sun_sales1/sun_sales2,2) - ,round(mon_sales1/mon_sales2,2) - ,round(tue_sales1/tue_sales2,2) - ,round(wed_sales1/wed_sales2,2) - ,round(thu_sales1/thu_sales2,2) - ,round(fri_sales1/fri_sales2,2) - ,round(sat_sales1/sat_sales2,2) - from - (select wswscs.d_week_seq d_week_seq1 - ,sun_sales sun_sales1 - ,mon_sales mon_sales1 - ,tue_sales tue_sales1 - ,wed_sales wed_sales1 - ,thu_sales thu_sales1 - ,fri_sales fri_sales1 - ,sat_sales sat_sales1 - from wswscs,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 2000) y, - (select wswscs.d_week_seq d_week_seq2 - ,sun_sales sun_sales2 - ,mon_sales mon_sales2 - ,tue_sales tue_sales2 - ,wed_sales wed_sales2 - ,thu_sales thu_sales2 - ,fri_sales fri_sales2 - ,sat_sales sat_sales2 - from wswscs - ,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 2000+1) z - where d_week_seq1=d_week_seq2-53 - order by d_week_seq1; - --- end template query2.tpl query 16 in stream 8 --- start template query16.tpl query 17 in stream 8 -select /* TPC-DS query16.tpl 0.25 */ - count(distinct cs_order_number) as "order count" - ,sum(cs_ext_ship_cost) as "total shipping cost" - ,sum(cs_net_profit) as "total net profit" -from - catalog_sales cs1 - ,date_dim - ,customer_address - ,call_center -where - d_date between '2002-2-01' and - dateadd(day, 60, cast('2002-2-01' as date)) -and cs1.cs_ship_date_sk = d_date_sk -and cs1.cs_ship_addr_sk = ca_address_sk -and ca_state = 'GA' -and cs1.cs_call_center_sk = cc_call_center_sk -and cc_county in ('Wadena County','Jackson County','Barrow County','Jefferson Davis Parish', - 'Maverick County' -) -and exists (select * - from catalog_sales cs2 - where cs1.cs_order_number = cs2.cs_order_number - and cs1.cs_warehouse_sk <> cs2.cs_warehouse_sk) -and not exists(select * - from catalog_returns cr1 - where cs1.cs_order_number = cr1.cr_order_number) -order by count(distinct cs_order_number) -limit 100; - --- end template query16.tpl query 17 in stream 8 --- start template query44.tpl query 18 in stream 8 -select /* TPC-DS query44.tpl 0.4 */ asceding.rnk, i1.i_product_name best_performing, i2.i_product_name worst_performing -from(select * - from (select item_sk,rank() over (order by rank_col asc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 417 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 417 - and ss_customer_sk is null - group by ss_store_sk))V1)V11 - where rnk < 11) asceding, - (select * - from (select item_sk,rank() over (order by rank_col desc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 417 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 417 - and ss_customer_sk is null - group by ss_store_sk))V2)V21 - where rnk < 11) descending, -item i1, -item i2 -where asceding.rnk = descending.rnk - and i1.i_item_sk=asceding.item_sk - and i2.i_item_sk=descending.item_sk -order by asceding.rnk -limit 100; - --- end template query44.tpl query 18 in stream 8 --- start template query5a.tpl query 19 in stream 8 -with /* TPC-DS query5a.tpl 0.98 */ ssr as - (select s_store_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ss_store_sk as store_sk, - ss_sold_date_sk as date_sk, - ss_ext_sales_price as sales_price, - ss_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from store_sales - union all - select sr_store_sk as store_sk, - sr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - sr_return_amt as return_amt, - sr_net_loss as net_loss - from store_returns - ) salesreturns, - date_dim, - store - where date_sk = d_date_sk - and d_date between cast('2000-08-18' as date) - and dateadd(day,14,cast('2000-08-18' as date)) - and store_sk = s_store_sk - group by s_store_id) - , - csr as - (select cp_catalog_page_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select cs_catalog_page_sk as page_sk, - cs_sold_date_sk as date_sk, - cs_ext_sales_price as sales_price, - cs_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from catalog_sales - union all - select cr_catalog_page_sk as page_sk, - cr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - cr_return_amount as return_amt, - cr_net_loss as net_loss - from catalog_returns - ) salesreturns, - date_dim, - catalog_page - where date_sk = d_date_sk - and d_date between cast('2000-08-18' as date) - and dateadd(day,14,cast('2000-08-18' as date)) - and page_sk = cp_catalog_page_sk - group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ws_web_site_sk as wsr_web_site_sk, - ws_sold_date_sk as date_sk, - ws_ext_sales_price as sales_price, - ws_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from web_sales - union all - select ws_web_site_sk as wsr_web_site_sk, - wr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - wr_return_amt as return_amt, - wr_net_loss as net_loss - from web_returns left outer join web_sales on - ( wr_item_sk = ws_item_sk - and wr_order_number = ws_order_number) - ) salesreturns, - date_dim, - web_site - where date_sk = d_date_sk - and d_date between cast('2000-08-18' as date) - and dateadd(day,14,cast('2000-08-18' as date)) - and wsr_web_site_sk = web_site_sk - group by web_site_id) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || s_store_id as id - , sales - , returns - , (profit - profit_loss) as profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || cp_catalog_page_id as id - , sales - , returns - , (profit - profit_loss) as profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , (profit - profit_loss) as profit - from wsr - ) x - group by channel, id) - select channel, id, sales, returns, profit from ( - select channel, id, sales, returns, profit from results - union - select channel, null as id, sum(sales), sum(returns), sum(profit) from results group by channel - union - select null as channel, null as id, sum(sales), sum(returns), sum(profit) from results) foo -order by channel, id -limit 100; - --- end template query5a.tpl query 19 in stream 8 --- start template query73.tpl query 20 in stream 8 -select /* TPC-DS query73.tpl 0.79 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_buy_potential = '>10000' or - household_demographics.hd_buy_potential = '0-500') - and household_demographics.hd_vehicle_count > 0 - and case when household_demographics.hd_vehicle_count > 0 then - household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count else null end > 1 - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_county in ('Wilkinson County','Porter County','Val Verde County','Levy County') - group by ss_ticket_number,ss_customer_sk) dj,customer - where ss_customer_sk = c_customer_sk - and cnt between 1 and 5 - order by cnt desc, c_last_name asc; - --- end template query73.tpl query 20 in stream 8 --- start template query14a.tpl query 21 in stream 8 -with /* TPC-DS query14a.tpl 0.69 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 2000 AND 2000 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 2000 AND 2000 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 2000 AND 2000 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as - (select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2) x) -, - results AS -(select channel, i_brand_id, i_class_id, i_category_id, sum(sales) sum_sales, sum(number_sales) number_sales - from ( - select 'store' channel, i_brand_id,i_class_id - ,i_category_id,sum(ss_quantity*ss_list_price) sales - , count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2000+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales) - union all - select 'catalog' channel, i_brand_id,i_class_id,i_category_id, sum(cs_quantity*cs_list_price) sales, count(*) number_sales - from catalog_sales - ,item - ,date_dim - where cs_item_sk in (select ss_item_sk from cross_items) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2000+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(cs_quantity*cs_list_price) > (select average_sales from avg_sales) - union all - select 'web' channel, i_brand_id,i_class_id,i_category_id, sum(ws_quantity*ws_list_price) sales , count(*) number_sales - from web_sales - ,item - ,date_dim - where ws_item_sk in (select ss_item_sk from cross_items) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2000+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ws_quantity*ws_list_price) > (select average_sales from avg_sales) - ) y - group by channel, i_brand_id,i_class_id,i_category_id) - - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales -from ( - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales from results - union - select channel, i_brand_id, i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id, i_class_id - union - select channel, i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id - union - select channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel - union - select null as channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results) z -order by channel, i_brand_id, i_class_id, i_category_id - limit 100; -with /* TPC-DS query14a.tpl 0.69 part2 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 2000 AND 2000 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 2000 AND 2000 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 2000 AND 2000 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as -(select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2) x) - select this_year.channel ty_channel - ,this_year.i_brand_id ty_brand - ,this_year.i_class_id ty_class - ,this_year.i_category_id ty_category - ,this_year.sales ty_sales - ,this_year.number_sales ty_number_sales - ,last_year.channel ly_channel - ,last_year.i_brand_id ly_brand - ,last_year.i_class_id ly_class - ,last_year.i_category_id ly_category - ,last_year.sales ly_sales - ,last_year.number_sales ly_number_sales -from - (select 'store' channel, i_brand_id,i_class_id,i_category_id - ,sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 2000 + 1 - and d_moy = 12 - and d_dom = 6) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) this_year, - (select 'store' channel, i_brand_id,i_class_id - ,i_category_id, sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 2000 - and d_moy = 12 - and d_dom = 6) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) last_year - where this_year.i_brand_id= last_year.i_brand_id - and this_year.i_class_id = last_year.i_class_id - and this_year.i_category_id = last_year.i_category_id - order by this_year.channel, this_year.i_brand_id, this_year.i_class_id, this_year.i_category_id - limit 100; - --- end template query14a.tpl query 21 in stream 8 --- start template query71.tpl query 22 in stream 8 -select /* TPC-DS query71.tpl 0.72 */ i_brand_id brand_id, i_brand brand,t_hour,t_minute, - sum(ext_price) ext_price - from item, (select ws_ext_sales_price as ext_price, - ws_sold_date_sk as sold_date_sk, - ws_item_sk as sold_item_sk, - ws_sold_time_sk as time_sk - from web_sales,date_dim - where d_date_sk = ws_sold_date_sk - and d_moy=12 - and d_year=2000 - union all - select cs_ext_sales_price as ext_price, - cs_sold_date_sk as sold_date_sk, - cs_item_sk as sold_item_sk, - cs_sold_time_sk as time_sk - from catalog_sales,date_dim - where d_date_sk = cs_sold_date_sk - and d_moy=12 - and d_year=2000 - union all - select ss_ext_sales_price as ext_price, - ss_sold_date_sk as sold_date_sk, - ss_item_sk as sold_item_sk, - ss_sold_time_sk as time_sk - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - and d_moy=12 - and d_year=2000 - ) tmp,time_dim - where - sold_item_sk = i_item_sk - and i_manager_id=1 - and time_sk = t_time_sk - and (t_meal_time = 'breakfast' or t_meal_time = 'dinner') - group by i_brand, i_brand_id,t_hour,t_minute - order by ext_price desc, i_brand_id - ; - --- end template query71.tpl query 22 in stream 8 --- start template query3.tpl query 23 in stream 8 -select /* TPC-DS query3.tpl 0.45 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_discount_amt) sum_agg - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manufact_id = 609 - and dt.d_moy=11 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,sum_agg desc - ,brand_id - limit 100; - --- end template query3.tpl query 23 in stream 8 --- start template query49.tpl query 24 in stream 8 -select /* TPC-DS query49.tpl 0.48 */ channel, item, return_ratio, return_rank, currency_rank from - (select - 'web' as channel - ,web.item - ,web.return_ratio - ,web.return_rank - ,web.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select ws.ws_item_sk as item - ,(cast(sum(coalesce(wr.wr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(wr.wr_return_amt,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - web_sales ws left outer join web_returns wr - on (ws.ws_order_number = wr.wr_order_number and - ws.ws_item_sk = wr.wr_item_sk) - ,date_dim - where - wr.wr_return_amt > 10000 - and ws.ws_net_profit > 1 - and ws.ws_net_paid > 0 - and ws.ws_quantity > 0 - and ws_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 12 - group by ws.ws_item_sk - ) in_web - ) web - where - ( - web.return_rank <= 10 - or - web.currency_rank <= 10 - ) - union - select - 'catalog' as channel - ,catalog.item - ,catalog.return_ratio - ,catalog.return_rank - ,catalog.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select - cs.cs_item_sk as item - ,(cast(sum(coalesce(cr.cr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(cr.cr_return_amount,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - catalog_sales cs left outer join catalog_returns cr - on (cs.cs_order_number = cr.cr_order_number and - cs.cs_item_sk = cr.cr_item_sk) - ,date_dim - where - cr.cr_return_amount > 10000 - and cs.cs_net_profit > 1 - and cs.cs_net_paid > 0 - and cs.cs_quantity > 0 - and cs_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 12 - group by cs.cs_item_sk - ) in_cat - ) catalog - where - ( - catalog.return_rank <= 10 - or - catalog.currency_rank <=10 - ) - union - select - 'store' as channel - ,store.item - ,store.return_ratio - ,store.return_rank - ,store.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select sts.ss_item_sk as item - ,(cast(sum(coalesce(sr.sr_return_quantity,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(sr.sr_return_amt,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - store_sales sts left outer join store_returns sr - on (sts.ss_ticket_number = sr.sr_ticket_number and sts.ss_item_sk = sr.sr_item_sk) - ,date_dim - where - sr.sr_return_amt > 10000 - and sts.ss_net_profit > 1 - and sts.ss_net_paid > 0 - and sts.ss_quantity > 0 - and ss_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 12 - group by sts.ss_item_sk - ) in_store - ) store - where ( - store.return_rank <= 10 - or - store.currency_rank <= 10 - ) - ) - order by 1,4,5,2 - limit 100; - --- end template query49.tpl query 24 in stream 8 --- start template query84.tpl query 25 in stream 8 -select /* TPC-DS query84.tpl 0.80 */ c_customer_id as customer_id - , coalesce(c_last_name,'') || ', ' || coalesce(c_first_name,'') as customername - from customer - ,customer_address - ,customer_demographics - ,household_demographics - ,income_band - ,store_returns - where ca_city = 'Oakland' - and c_current_addr_sk = ca_address_sk - and ib_lower_bound >= 33990 - and ib_upper_bound <= 33990 + 50000 - and ib_income_band_sk = hd_income_band_sk - and cd_demo_sk = c_current_cdemo_sk - and hd_demo_sk = c_current_hdemo_sk - and sr_cdemo_sk = cd_demo_sk - order by c_customer_id - limit 100; - --- end template query84.tpl query 25 in stream 8 --- start template query64.tpl query 26 in stream 8 -with /* TPC-DS query64.tpl 0.20 */ cs_ui as - (select cs_item_sk - ,sum(cs_ext_list_price) as sale,sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit) as refund - from catalog_sales - ,catalog_returns - where cs_item_sk = cr_item_sk - and cs_order_number = cr_order_number - group by cs_item_sk - having sum(cs_ext_list_price)>2*sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit)), -cross_sales as - (select i_product_name product_name - ,i_item_sk item_sk - ,s_store_name store_name - ,s_zip store_zip - ,ad1.ca_street_number b_street_number - ,ad1.ca_street_name b_street_name - ,ad1.ca_city b_city - ,ad1.ca_zip b_zip - ,ad2.ca_street_number c_street_number - ,ad2.ca_street_name c_street_name - ,ad2.ca_city c_city - ,ad2.ca_zip c_zip - ,d1.d_year as syear - ,d2.d_year as fsyear - ,d3.d_year s2year - ,count(*) cnt - ,sum(ss_wholesale_cost) s1 - ,sum(ss_list_price) s2 - ,sum(ss_coupon_amt) s3 - FROM store_sales - ,store_returns - ,cs_ui - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,customer - ,customer_demographics cd1 - ,customer_demographics cd2 - ,promotion - ,household_demographics hd1 - ,household_demographics hd2 - ,customer_address ad1 - ,customer_address ad2 - ,income_band ib1 - ,income_band ib2 - ,item - WHERE ss_store_sk = s_store_sk AND - ss_sold_date_sk = d1.d_date_sk AND - ss_customer_sk = c_customer_sk AND - ss_cdemo_sk= cd1.cd_demo_sk AND - ss_hdemo_sk = hd1.hd_demo_sk AND - ss_addr_sk = ad1.ca_address_sk and - ss_item_sk = i_item_sk and - ss_item_sk = sr_item_sk and - ss_ticket_number = sr_ticket_number and - ss_item_sk = cs_ui.cs_item_sk and - c_current_cdemo_sk = cd2.cd_demo_sk AND - c_current_hdemo_sk = hd2.hd_demo_sk AND - c_current_addr_sk = ad2.ca_address_sk and - c_first_sales_date_sk = d2.d_date_sk and - c_first_shipto_date_sk = d3.d_date_sk and - ss_promo_sk = p_promo_sk and - hd1.hd_income_band_sk = ib1.ib_income_band_sk and - hd2.hd_income_band_sk = ib2.ib_income_band_sk and - cd1.cd_marital_status <> cd2.cd_marital_status and - i_color in ('pink','bisque','blanched','steel','plum','goldenrod') and - i_current_price between 17 and 17 + 10 and - i_current_price between 17 + 1 and 17 + 15 -group by i_product_name - ,i_item_sk - ,s_store_name - ,s_zip - ,ad1.ca_street_number - ,ad1.ca_street_name - ,ad1.ca_city - ,ad1.ca_zip - ,ad2.ca_street_number - ,ad2.ca_street_name - ,ad2.ca_city - ,ad2.ca_zip - ,d1.d_year - ,d2.d_year - ,d3.d_year -) -select cs1.product_name - ,cs1.store_name - ,cs1.store_zip - ,cs1.b_street_number - ,cs1.b_street_name - ,cs1.b_city - ,cs1.b_zip - ,cs1.c_street_number - ,cs1.c_street_name - ,cs1.c_city - ,cs1.c_zip - ,cs1.syear - ,cs1.cnt - ,cs1.s1 as s11 - ,cs1.s2 as s21 - ,cs1.s3 as s31 - ,cs2.s1 as s12 - ,cs2.s2 as s22 - ,cs2.s3 as s32 - ,cs2.syear - ,cs2.cnt -from cross_sales cs1,cross_sales cs2 -where cs1.item_sk=cs2.item_sk and - cs1.syear = 2000 and - cs2.syear = 2000 + 1 and - cs2.cnt <= cs1.cnt and - cs1.store_name = cs2.store_name and - cs1.store_zip = cs2.store_zip -order by cs1.product_name - ,cs1.store_name - ,cs2.cnt - ,cs1.s1 - ,cs2.s1; - --- end template query64.tpl query 26 in stream 8 --- start template query7.tpl query 27 in stream 8 -select /* TPC-DS query7.tpl 0.2 */ i_item_id, - avg(ss_quantity) agg1, - avg(ss_list_price) agg2, - avg(ss_coupon_amt) agg3, - avg(ss_sales_price) agg4 - from store_sales, customer_demographics, date_dim, item, promotion - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_cdemo_sk = cd_demo_sk and - ss_promo_sk = p_promo_sk and - cd_gender = 'F' and - cd_marital_status = 'S' and - cd_education_status = 'Unknown' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 1999 - group by i_item_id - order by i_item_id - limit 100; - --- end template query7.tpl query 27 in stream 8 --- start template query36a.tpl query 28 in stream 8 -with /* TPC-DS query36a.tpl 0.21 */ results as - (select - sum(ss_net_profit) as ss_net_profit, sum(ss_ext_sales_price) as ss_ext_sales_price, - sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin - ,i_category - ,i_class - ,0 as g_category, 0 as g_class - from - store_sales - ,date_dim d1 - ,item - ,store - where - d1.d_year = 1998 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and s_state in ('MI','IN','WA','MN', - 'OH','GA','GA','TX') - group by i_category,i_class) - , - results_rollup as - (select gross_margin ,i_category ,i_class,0 as t_category, 0 as t_class, 0 as lochierarchy from results - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - i_category, NULL AS i_class, 0 as t_category, 1 as t_class, 1 as lochierarchy from results group by i_category - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - NULL AS i_category ,NULL AS i_class, 1 as t_category, 1 as t_class, 2 as lochierarchy from results) - select - gross_margin ,i_category ,i_class, lochierarchy,rank() over ( - partition by lochierarchy, case when t_class = 0 then i_category end - order by gross_margin asc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then i_category end - ,rank_within_parent - limit 100; - --- end template query36a.tpl query 28 in stream 8 --- start template query61.tpl query 29 in stream 8 -select /* TPC-DS query61.tpl 0.97 */ promotions,total,cast(promotions as decimal(15,4))/cast(total as decimal(15,4))*100 -from - (select sum(ss_ext_sales_price) promotions - from store_sales - ,store - ,promotion - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_promo_sk = p_promo_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -6 - and i_category = 'Books' - and (p_channel_dmail = 'Y' or p_channel_email = 'Y' or p_channel_tv = 'Y') - and s_gmt_offset = -6 - and d_year = 2000 - and d_moy = 12) promotional_sales, - (select sum(ss_ext_sales_price) total - from store_sales - ,store - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -6 - and i_category = 'Books' - and s_gmt_offset = -6 - and d_year = 2000 - and d_moy = 12) all_sales -order by promotions, total -limit 100; - --- end template query61.tpl query 29 in stream 8 --- start template query41.tpl query 30 in stream 8 -select /* TPC-DS query41.tpl 0.62 */ distinct(i_product_name) - from item i1 - where i_manufact_id between 984 and 984+40 - and (select count(*) as item_cnt - from item - where (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'hot' or i_color = 'almond') and - (i_units = 'Tbl' or i_units = 'Each') and - (i_size = 'large' or i_size = 'small') - ) or - (i_category = 'Women' and - (i_color = 'moccasin' or i_color = 'light') and - (i_units = 'Bundle' or i_units = 'Gross') and - (i_size = 'medium' or i_size = 'N/A') - ) or - (i_category = 'Men' and - (i_color = 'beige' or i_color = 'green') and - (i_units = 'N/A' or i_units = 'Unknown') and - (i_size = 'extra large' or i_size = 'petite') - ) or - (i_category = 'Men' and - (i_color = 'lavender' or i_color = 'white') and - (i_units = 'Box' or i_units = 'Gram') and - (i_size = 'large' or i_size = 'small') - ))) or - (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'blanched' or i_color = 'navy') and - (i_units = 'Pound' or i_units = 'Cup') and - (i_size = 'large' or i_size = 'small') - ) or - (i_category = 'Women' and - (i_color = 'frosted' or i_color = 'papaya') and - (i_units = 'Pallet' or i_units = 'Dram') and - (i_size = 'medium' or i_size = 'N/A') - ) or - (i_category = 'Men' and - (i_color = 'salmon' or i_color = 'khaki') and - (i_units = 'Ounce' or i_units = 'Bunch') and - (i_size = 'extra large' or i_size = 'petite') - ) or - (i_category = 'Men' and - (i_color = 'forest' or i_color = 'lace') and - (i_units = 'Dozen' or i_units = 'Lb') and - (i_size = 'large' or i_size = 'small') - )))) > 0 - order by i_product_name - limit 100; - --- end template query41.tpl query 30 in stream 8 --- start template query35a.tpl query 31 in stream 8 -select /* TPC-DS query35a.tpl 0.47 */ - ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - count(*) cnt1, - max(cd_dep_count), - sum(cd_dep_count), - max(cd_dep_count), - cd_dep_employed_count, - count(*) cnt2, - max(cd_dep_employed_count), - sum(cd_dep_employed_count), - max(cd_dep_employed_count), - cd_dep_college_count, - count(*) cnt3, - max(cd_dep_college_count), - sum(cd_dep_college_count), - max(cd_dep_college_count) - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2002 and - d_qoy < 4) and - exists (select * from - (select ws_bill_customer_sk customsk - from web_sales,date_dim - where - ws_sold_date_sk = d_date_sk and - d_year = 2002 and - d_qoy < 4 - union all - select cs_ship_customer_sk customsk - from catalog_sales,date_dim - where - cs_sold_date_sk = d_date_sk and - d_year = 2002 and - d_qoy < 4)x - where x.customsk = c.c_customer_sk) - group by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - limit 100; - --- end template query35a.tpl query 31 in stream 8 --- start template query50.tpl query 32 in stream 8 -select /* TPC-DS query50.tpl 0.60 */ - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 30) and - (sr_returned_date_sk - ss_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 60) and - (sr_returned_date_sk - ss_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 90) and - (sr_returned_date_sk - ss_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - store_sales - ,store_returns - ,store - ,date_dim d1 - ,date_dim d2 -where - d2.d_year = 2002 -and d2.d_moy = 10 -and ss_ticket_number = sr_ticket_number -and ss_item_sk = sr_item_sk -and ss_sold_date_sk = d1.d_date_sk -and sr_returned_date_sk = d2.d_date_sk -and ss_customer_sk = sr_customer_sk -and ss_store_sk = s_store_sk -group by - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -order by s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -limit 100; - --- end template query50.tpl query 32 in stream 8 --- start template query65.tpl query 33 in stream 8 -select /* TPC-DS query65.tpl 0.71 */ - s_store_name, - i_item_desc, - sc.revenue, - i_current_price, - i_wholesale_cost, - i_brand - from store, item, - (select ss_store_sk, avg(revenue) as ave - from - (select ss_store_sk, ss_item_sk, - sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1188 and 1188+11 - group by ss_store_sk, ss_item_sk) sa - group by ss_store_sk) sb, - (select ss_store_sk, ss_item_sk, sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1188 and 1188+11 - group by ss_store_sk, ss_item_sk) sc - where sb.ss_store_sk = sc.ss_store_sk and - sc.revenue <= 0.1 * sb.ave and - s_store_sk = sc.ss_store_sk and - i_item_sk = sc.ss_item_sk - order by s_store_name, i_item_desc -limit 100; - --- end template query65.tpl query 33 in stream 8 --- start template query51.tpl query 34 in stream 8 -WITH /* TPC-DS query51.tpl 0.46 */ web_v1 as ( -select - ws_item_sk item_sk, d_date, - sum(sum(ws_sales_price)) - over (partition by ws_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from web_sales - ,date_dim -where ws_sold_date_sk=d_date_sk - and d_month_seq between 1197 and 1197+11 - and ws_item_sk is not NULL -group by ws_item_sk, d_date), -store_v1 as ( -select - ss_item_sk item_sk, d_date, - sum(sum(ss_sales_price)) - over (partition by ss_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from store_sales - ,date_dim -where ss_sold_date_sk=d_date_sk - and d_month_seq between 1197 and 1197+11 - and ss_item_sk is not NULL -group by ss_item_sk, d_date) - select * -from (select item_sk - ,d_date - ,web_sales - ,store_sales - ,max(web_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) web_cumulative - ,max(store_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) store_cumulative - from (select case when web.item_sk is not null then web.item_sk else store.item_sk end item_sk - ,case when web.d_date is not null then web.d_date else store.d_date end d_date - ,web.cume_sales web_sales - ,store.cume_sales store_sales - from web_v1 web full outer join store_v1 store on (web.item_sk = store.item_sk - and web.d_date = store.d_date) - )x )y -where web_cumulative > store_cumulative -order by item_sk - ,d_date -limit 100; - --- end template query51.tpl query 34 in stream 8 --- start template query78.tpl query 35 in stream 8 -with /* TPC-DS query78.tpl 0.10 */ ws as - (select d_year AS ws_sold_year, ws_item_sk, - ws_bill_customer_sk ws_customer_sk, - sum(ws_quantity) ws_qty, - sum(ws_wholesale_cost) ws_wc, - sum(ws_sales_price) ws_sp - from web_sales - left join web_returns on wr_order_number=ws_order_number and ws_item_sk=wr_item_sk - join date_dim on ws_sold_date_sk = d_date_sk - where wr_order_number is null - group by d_year, ws_item_sk, ws_bill_customer_sk - ), -cs as - (select d_year AS cs_sold_year, cs_item_sk, - cs_bill_customer_sk cs_customer_sk, - sum(cs_quantity) cs_qty, - sum(cs_wholesale_cost) cs_wc, - sum(cs_sales_price) cs_sp - from catalog_sales - left join catalog_returns on cr_order_number=cs_order_number and cs_item_sk=cr_item_sk - join date_dim on cs_sold_date_sk = d_date_sk - where cr_order_number is null - group by d_year, cs_item_sk, cs_bill_customer_sk - ), -ss as - (select d_year AS ss_sold_year, ss_item_sk, - ss_customer_sk, - sum(ss_quantity) ss_qty, - sum(ss_wholesale_cost) ss_wc, - sum(ss_sales_price) ss_sp - from store_sales - left join store_returns on sr_ticket_number=ss_ticket_number and ss_item_sk=sr_item_sk - join date_dim on ss_sold_date_sk = d_date_sk - where sr_ticket_number is null - group by d_year, ss_item_sk, ss_customer_sk - ) - select -ss_customer_sk, -round(ss_qty/(coalesce(ws_qty,0)+coalesce(cs_qty,0)),2) ratio, -ss_qty store_qty, ss_wc store_wholesale_cost, ss_sp store_sales_price, -coalesce(ws_qty,0)+coalesce(cs_qty,0) other_chan_qty, -coalesce(ws_wc,0)+coalesce(cs_wc,0) other_chan_wholesale_cost, -coalesce(ws_sp,0)+coalesce(cs_sp,0) other_chan_sales_price -from ss -left join ws on (ws_sold_year=ss_sold_year and ws_item_sk=ss_item_sk and ws_customer_sk=ss_customer_sk) -left join cs on (cs_sold_year=ss_sold_year and cs_item_sk=ss_item_sk and cs_customer_sk=ss_customer_sk) -where (coalesce(ws_qty,0)>0 or coalesce(cs_qty, 0)>0) and ss_sold_year=2002 -order by - ss_customer_sk, - ss_qty desc, ss_wc desc, ss_sp desc, - other_chan_qty, - other_chan_wholesale_cost, - other_chan_sales_price, - ratio -limit 100; - --- end template query78.tpl query 35 in stream 8 --- start template query21.tpl query 36 in stream 8 -select /* TPC-DS query21.tpl 0.14 */ * - from(select w_warehouse_name - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('1998-06-24' as date)) - then inv_quantity_on_hand - else 0 end) as inv_before - ,sum(case when (cast(d_date as date) >= cast ('1998-06-24' as date)) - then inv_quantity_on_hand - else 0 end) as inv_after - from inventory - ,warehouse - ,item - ,date_dim - where i_current_price between 0.99 and 1.49 - and i_item_sk = inv_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('1998-06-24' as date)) - and dateadd(day,30,cast ('1998-06-24' as date)) - group by w_warehouse_name, i_item_id) x - where (case when inv_before > 0 - then inv_after / inv_before - else null - end) between 2.0/3.0 and 3.0/2.0 - order by w_warehouse_name - ,i_item_id - limit 100; - --- end template query21.tpl query 36 in stream 8 --- start template query67a.tpl query 37 in stream 8 -with /* TPC-DS query67a.tpl 0.35 */ results as -( select i_category ,i_class ,i_brand ,i_product_name ,d_year ,d_qoy ,d_moy ,s_store_id - ,sum(coalesce(ss_sales_price*ss_quantity,0)) sumsales - from store_sales ,date_dim ,store ,item - where ss_sold_date_sk=d_date_sk - and ss_item_sk=i_item_sk - and ss_store_sk = s_store_sk - and d_month_seq between 1179 and 1179 + 11 - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy,s_store_id) - , - results_rollup as - (select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, s_store_id, sumsales - from results - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy - union all - select i_category, i_class, i_brand, i_product_name, d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year - union all - select i_category, i_class, i_brand, i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name - union all - select i_category, i_class, i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand - union all - select i_category, i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class - union all - select i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category - union all - select null i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results) - - select * -from (select i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rank() over (partition by i_category order by sumsales desc) rk - from results_rollup) dw2 -where rk <= 100 -order by i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rk -limit 100; - --- end template query67a.tpl query 37 in stream 8 --- start template query22a.tpl query 38 in stream 8 -with /* TPC-DS query22a.tpl 0.55 */ results as -(select i_product_name - ,i_brand - ,i_class - ,i_category - ,avg(inv_quantity_on_hand) qoh - from inventory - ,date_dim - ,item --- ,warehouse - where inv_date_sk=d_date_sk - and inv_item_sk=i_item_sk --- and inv_warehouse_sk = w_warehouse_sk - and d_month_seq between 1177 and 1177 + 11 - group by i_product_name,i_brand,i_class,i_category), -results_rollup as -(select i_product_name, i_brand, i_class, i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class,i_category -union all -select i_product_name, i_brand, i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class -union all -select i_product_name, i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand -union all -select i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name -union all -select null i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results) - select i_product_name, i_brand, i_class, i_category,qoh - from results_rollup - order by qoh, i_product_name, i_brand, i_class, i_category -limit 100; - --- end template query22a.tpl query 38 in stream 8 --- start template query81.tpl query 39 in stream 8 -with /* TPC-DS query81.tpl 0.37 */ customer_total_return as - (select cr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(cr_return_amt_inc_tax) as ctr_total_return - from catalog_returns - ,date_dim - ,customer_address - where cr_returned_date_sk = d_date_sk - and d_year =1999 - and cr_returning_addr_sk = ca_address_sk - group by cr_returning_customer_sk - ,ca_state ) - select c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'VA' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - limit 100; - --- end template query81.tpl query 39 in stream 8 --- start template query93.tpl query 40 in stream 8 -select /* TPC-DS query93.tpl 0.52 */ ss_customer_sk - ,sum(act_sales) sumsales - from (select ss_item_sk - ,ss_ticket_number - ,ss_customer_sk - ,case when sr_return_quantity is not null then (ss_quantity-sr_return_quantity)*ss_sales_price - else (ss_quantity*ss_sales_price) end act_sales - from store_sales left outer join store_returns on (sr_item_sk = ss_item_sk - and sr_ticket_number = ss_ticket_number) - ,reason - where sr_reason_sk = r_reason_sk - and r_reason_desc = 'reason 52') t - group by ss_customer_sk - order by sumsales, ss_customer_sk -limit 100; - --- end template query93.tpl query 40 in stream 8 --- start template query25.tpl query 41 in stream 8 -select /* TPC-DS query25.tpl 0.9 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,stddev_samp(ss_net_profit) as store_sales_profit - ,stddev_samp(sr_net_loss) as store_returns_loss - ,stddev_samp(cs_net_profit) as catalog_sales_profit - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 2002 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 10 - and d2.d_year = 2002 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_moy between 4 and 10 - and d3.d_year = 2002 - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query25.tpl query 41 in stream 8 --- start template query26.tpl query 42 in stream 8 -select /* TPC-DS query26.tpl 0.85 */ i_item_id, - avg(cs_quantity) agg1, - avg(cs_list_price) agg2, - avg(cs_coupon_amt) agg3, - avg(cs_sales_price) agg4 - from catalog_sales, customer_demographics, date_dim, item, promotion - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd_demo_sk and - cs_promo_sk = p_promo_sk and - cd_gender = 'M' and - cd_marital_status = 'M' and - cd_education_status = 'Secondary' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 1998 - group by i_item_id - order by i_item_id - limit 100; - --- end template query26.tpl query 42 in stream 8 --- start template query90.tpl query 43 in stream 8 -select /* TPC-DS query90.tpl 0.40 */ cast(amc as decimal(15,4))/cast(pmc as decimal(15,4)) am_pm_ratio - from ( select count(*) amc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 12 and 12+1 - and household_demographics.hd_dep_count = 2 - and web_page.wp_char_count between 5000 and 5200) at, - ( select count(*) pmc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 16 and 16+1 - and household_demographics.hd_dep_count = 2 - and web_page.wp_char_count between 5000 and 5200) pt - order by am_pm_ratio - limit 100; - --- end template query90.tpl query 43 in stream 8 --- start template query74.tpl query 44 in stream 8 -with /* TPC-DS query74.tpl 0.76 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,max(ss_net_paid) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1999,1999+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,max(ws_net_paid) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - and d_year in (1999,1999+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - ) - select - t_s_secyear.customer_id, t_s_secyear.customer_first_name, t_s_secyear.customer_last_name - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.year = 1999 - and t_s_secyear.year = 1999+1 - and t_w_firstyear.year = 1999 - and t_w_secyear.year = 1999+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - order by 1,3,2 -limit 100; - --- end template query74.tpl query 44 in stream 8 --- start template query92.tpl query 45 in stream 8 -select /* TPC-DS query92.tpl 0.44 */ - sum(ws_ext_discount_amt) as "Excess Discount Amount" -from - web_sales - ,item - ,date_dim -where -i_manufact_id = 278 -and i_item_sk = ws_item_sk -and d_date between '2002-01-07' and - dateadd(day,90,cast('2002-01-07' as date)) -and d_date_sk = ws_sold_date_sk -and ws_ext_discount_amt - > ( - SELECT - 1.3 * avg(ws_ext_discount_amt) - FROM - web_sales - ,date_dim - WHERE - ws_item_sk = i_item_sk - and d_date between '2002-01-07' and - dateadd(day,90,cast('2002-01-07' as date)) - and d_date_sk = ws_sold_date_sk - ) -order by sum(ws_ext_discount_amt) -limit 100; - --- end template query92.tpl query 45 in stream 8 --- start template query75.tpl query 46 in stream 8 -WITH /* TPC-DS query75.tpl 0.3 */ all_sales AS ( - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,SUM(sales_cnt) AS sales_cnt - ,SUM(sales_amt) AS sales_amt - FROM (SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,cs_quantity - COALESCE(cr_return_quantity,0) AS sales_cnt - ,cs_ext_sales_price - COALESCE(cr_return_amount,0.0) AS sales_amt - FROM catalog_sales JOIN item ON i_item_sk=cs_item_sk - JOIN date_dim ON d_date_sk=cs_sold_date_sk - LEFT JOIN catalog_returns ON (cs_order_number=cr_order_number - AND cs_item_sk=cr_item_sk) - WHERE i_category='Children' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ss_quantity - COALESCE(sr_return_quantity,0) AS sales_cnt - ,ss_ext_sales_price - COALESCE(sr_return_amt,0.0) AS sales_amt - FROM store_sales JOIN item ON i_item_sk=ss_item_sk - JOIN date_dim ON d_date_sk=ss_sold_date_sk - LEFT JOIN store_returns ON (ss_ticket_number=sr_ticket_number - AND ss_item_sk=sr_item_sk) - WHERE i_category='Children' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ws_quantity - COALESCE(wr_return_quantity,0) AS sales_cnt - ,ws_ext_sales_price - COALESCE(wr_return_amt,0.0) AS sales_amt - FROM web_sales JOIN item ON i_item_sk=ws_item_sk - JOIN date_dim ON d_date_sk=ws_sold_date_sk - LEFT JOIN web_returns ON (ws_order_number=wr_order_number - AND ws_item_sk=wr_item_sk) - WHERE i_category='Children') sales_detail - GROUP BY d_year, i_brand_id, i_class_id, i_category_id, i_manufact_id) - SELECT prev_yr.d_year AS prev_year - ,curr_yr.d_year AS year - ,curr_yr.i_brand_id - ,curr_yr.i_class_id - ,curr_yr.i_category_id - ,curr_yr.i_manufact_id - ,prev_yr.sales_cnt AS prev_yr_cnt - ,curr_yr.sales_cnt AS curr_yr_cnt - ,curr_yr.sales_cnt-prev_yr.sales_cnt AS sales_cnt_diff - ,curr_yr.sales_amt-prev_yr.sales_amt AS sales_amt_diff - FROM all_sales curr_yr, all_sales prev_yr - WHERE curr_yr.i_brand_id=prev_yr.i_brand_id - AND curr_yr.i_class_id=prev_yr.i_class_id - AND curr_yr.i_category_id=prev_yr.i_category_id - AND curr_yr.i_manufact_id=prev_yr.i_manufact_id - AND curr_yr.d_year=2002 - AND prev_yr.d_year=2002-1 - AND CAST(curr_yr.sales_cnt AS DECIMAL(17,2))/CAST(prev_yr.sales_cnt AS DECIMAL(17,2))<0.9 - ORDER BY sales_cnt_diff,sales_amt_diff - limit 100; - --- end template query75.tpl query 46 in stream 8 --- start template query10.tpl query 47 in stream 8 -select /* TPC-DS query10.tpl 0.26 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3, - cd_dep_count, - count(*) cnt4, - cd_dep_employed_count, - count(*) cnt5, - cd_dep_college_count, - count(*) cnt6 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_county in ('Broward County','Roseau County','Sussex County','Walker County','Northampton County') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 1999 and - d_moy between 3 and 3+3) and - (exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 1999 and - d_moy between 3 ANd 3+3) or - exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 1999 and - d_moy between 3 and 3+3)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count -limit 100; - --- end template query10.tpl query 47 in stream 8 --- start template query58.tpl query 48 in stream 8 -with /* TPC-DS query58.tpl 0.19 */ ss_items as - (select i_item_id item_id - ,sum(ss_ext_sales_price) ss_item_rev - from store_sales - ,item - ,date_dim - where ss_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '2000-06-02')) - and ss_sold_date_sk = d_date_sk - group by i_item_id), - cs_items as - (select i_item_id item_id - ,sum(cs_ext_sales_price) cs_item_rev - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '2000-06-02')) - and cs_sold_date_sk = d_date_sk - group by i_item_id), - ws_items as - (select i_item_id item_id - ,sum(ws_ext_sales_price) ws_item_rev - from web_sales - ,item - ,date_dim - where ws_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq =(select d_week_seq - from date_dim - where d_date = '2000-06-02')) - and ws_sold_date_sk = d_date_sk - group by i_item_id) - select ss_items.item_id - ,ss_item_rev - ,ss_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ss_dev - ,cs_item_rev - ,cs_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 cs_dev - ,ws_item_rev - ,ws_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ws_dev - ,(ss_item_rev+cs_item_rev+ws_item_rev)/3 average - from ss_items,cs_items,ws_items - where ss_items.item_id=cs_items.item_id - and ss_items.item_id=ws_items.item_id - and ss_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - and ss_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and cs_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and cs_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and ws_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and ws_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - order by item_id - ,ss_item_rev - limit 100; - --- end template query58.tpl query 48 in stream 8 --- start template query6.tpl query 49 in stream 8 -select /* TPC-DS query6.tpl 0.58 */ a.ca_state state, count(*) cnt - from customer_address a - ,customer c - ,store_sales s - ,date_dim d - ,item i - where a.ca_address_sk = c.c_current_addr_sk - and c.c_customer_sk = s.ss_customer_sk - and s.ss_sold_date_sk = d.d_date_sk - and s.ss_item_sk = i.i_item_sk - and d.d_month_seq = - (select distinct (d_month_seq) - from date_dim - where d_year = 1999 - and d_moy = 5 ) - and i.i_current_price > 1.2 * - (select avg(j.i_current_price) - from item j - where j.i_category = i.i_category) - group by a.ca_state - having count(*) >= 10 - order by cnt, a.ca_state - limit 100; - --- end template query6.tpl query 49 in stream 8 --- start template query47.tpl query 50 in stream 8 -with /* TPC-DS query47.tpl 0.42 */ v1 as( - select i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, - s_store_name, s_company_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - s_store_name, s_company_name - order by d_year, d_moy) rn - from item, store_sales, date_dim, store - where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - ( - d_year = 2000 or - ( d_year = 2000-1 and d_moy =12) or - ( d_year = 2000+1 and d_moy =1) - ) - group by i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy), - v2 as( - select v1.s_store_name, v1.s_company_name - ,v1.d_year, v1.d_moy - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1.s_store_name = v1_lag.s_store_name and - v1.s_store_name = v1_lead.s_store_name and - v1.s_company_name = v1_lag.s_company_name and - v1.s_company_name = v1_lead.s_company_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 2000 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, psum - limit 100; - --- end template query47.tpl query 50 in stream 8 --- start template query30.tpl query 51 in stream 8 -with /* TPC-DS query30.tpl 0.75 */ customer_total_return as - (select wr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(wr_return_amt) as ctr_total_return - from web_returns - ,date_dim - ,customer_address - where wr_returned_date_sk = d_date_sk - and d_year =2001 - and wr_returning_addr_sk = ca_address_sk - group by wr_returning_customer_sk - ,ca_state) - select c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'MN' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return -limit 100; - --- end template query30.tpl query 51 in stream 8 --- start template query94.tpl query 52 in stream 8 -select /* TPC-DS query94.tpl 0.17 */ - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '1999-3-01' and - dateadd(day,60,cast('1999-3-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'TX' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and exists (select * - from web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) -and not exists(select * - from web_returns wr1 - where ws1.ws_order_number = wr1.wr_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query94.tpl query 52 in stream 8 --- start template query97.tpl query 53 in stream 8 -with /* TPC-DS query97.tpl 0.38 */ ssci as ( -select ss_customer_sk customer_sk - ,ss_item_sk item_sk -from store_sales,date_dim -where ss_sold_date_sk = d_date_sk - and d_month_seq between 1216 and 1216 + 11 -group by ss_customer_sk - ,ss_item_sk), -csci as( - select cs_bill_customer_sk customer_sk - ,cs_item_sk item_sk -from catalog_sales,date_dim -where cs_sold_date_sk = d_date_sk - and d_month_seq between 1216 and 1216 + 11 -group by cs_bill_customer_sk - ,cs_item_sk) - select sum(case when ssci.customer_sk is not null and csci.customer_sk is null then 1 else 0 end) store_only - ,sum(case when ssci.customer_sk is null and csci.customer_sk is not null then 1 else 0 end) catalog_only - ,sum(case when ssci.customer_sk is not null and csci.customer_sk is not null then 1 else 0 end) store_and_catalog -from ssci full outer join csci on (ssci.customer_sk=csci.customer_sk - and ssci.item_sk = csci.item_sk) -limit 100; - --- end template query97.tpl query 53 in stream 8 --- start template query55.tpl query 54 in stream 8 -select /* TPC-DS query55.tpl 0.82 */ i_brand_id brand_id, i_brand brand, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=4 - and d_moy=12 - and d_year=1998 - group by i_brand, i_brand_id - order by ext_price desc, i_brand_id -limit 100 ; - --- end template query55.tpl query 54 in stream 8 --- start template query72.tpl query 55 in stream 8 -select /* TPC-DS query72.tpl 0.87 */ i_item_desc - ,w_warehouse_name - ,d1.d_week_seq - ,sum(case when p_promo_sk is null then 1 else 0 end) no_promo - ,sum(case when p_promo_sk is not null then 1 else 0 end) promo - ,count(*) total_cnt -from catalog_sales -join inventory on (cs_item_sk = inv_item_sk) -join warehouse on (w_warehouse_sk=inv_warehouse_sk) -join item on (i_item_sk = cs_item_sk) -join customer_demographics on (cs_bill_cdemo_sk = cd_demo_sk) -join household_demographics on (cs_bill_hdemo_sk = hd_demo_sk) -join date_dim d1 on (cs_sold_date_sk = d1.d_date_sk) -join date_dim d2 on (inv_date_sk = d2.d_date_sk) -join date_dim d3 on (cs_ship_date_sk = d3.d_date_sk) -left outer join promotion on (cs_promo_sk=p_promo_sk) -left outer join catalog_returns on (cr_item_sk = cs_item_sk and cr_order_number = cs_order_number) -where d1.d_week_seq = d2.d_week_seq - and inv_quantity_on_hand < cs_quantity - and d3.d_date > d1.d_date + 5 - and hd_buy_potential = '1001-5000' - and d1.d_year = 2000 - and cd_marital_status = 'U' -group by i_item_desc,w_warehouse_name,d1.d_week_seq -order by total_cnt desc, i_item_desc, w_warehouse_name, d_week_seq -limit 100; - --- end template query72.tpl query 55 in stream 8 --- start template query95.tpl query 56 in stream 8 -with /* TPC-DS query95.tpl 0.43 */ ws_wh as -(select ws1.ws_order_number,ws1.ws_warehouse_sk wh1,ws2.ws_warehouse_sk wh2 - from web_sales ws1,web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) - select - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2001-5-01' and - dateadd(day,60,cast('2001-5-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'MN' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and ws1.ws_order_number in (select ws_order_number - from ws_wh) -and ws1.ws_order_number in (select wr_order_number - from web_returns,ws_wh - where wr_order_number = ws_wh.ws_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query95.tpl query 56 in stream 8 --- start template query86a.tpl query 57 in stream 8 -with /* TPC-DS query86a.tpl 0.11 */ results as -( select sum(ws_net_paid) as total_sum, i_category, i_class, 0 as g_category, 0 as g_class - from - web_sales - ,date_dim d1 - ,item - where - d1.d_month_seq between 1193 and 1193+11 - and d1.d_date_sk = ws_sold_date_sk - and i_item_sk = ws_item_sk - group by i_category,i_class - ) , - - results_rollup as -( select total_sum ,i_category ,i_class, g_category, g_class, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum, i_category, NULL as i_class, 0 as g_category, 1 as g_class, 1 as lochierarchy from results group by i_category - union - select sum(total_sum) as total_sum, NULL as i_category, NULL as i_class, 1 as g_category, 1 as g_class, 2 as lochierarchy from results) - select - total_sum ,i_category ,i_class, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_class = 0 then i_category end - order by total_sum desc) as rank_within_parent - from - results_rollup - order by - lochierarchy desc, - case when lochierarchy = 0 then i_category end, - rank_within_parent - limit 100; - --- end template query86a.tpl query 57 in stream 8 --- start template query39.tpl query 58 in stream 8 -with /* TPC-DS query39.tpl 0.5 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =1998 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=4 - and inv2.d_moy=4+1 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; -with /* TPC-DS query39.tpl 0.5 part2 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =1998 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=4 - and inv2.d_moy=4+1 - and inv1.cov > 1.5 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; - --- end template query39.tpl query 58 in stream 8 --- start template query17.tpl query 59 in stream 8 -select /* TPC-DS query17.tpl 0.41 */ i_item_id - ,i_item_desc - ,s_state - ,count(ss_quantity) as store_sales_quantitycount - ,avg(ss_quantity) as store_sales_quantityave - ,stddev_samp(ss_quantity) as store_sales_quantitystdev - ,stddev_samp(ss_quantity)/avg(ss_quantity) as store_sales_quantitycov - ,count(sr_return_quantity) as store_returns_quantitycount - ,avg(sr_return_quantity) as store_returns_quantityave - ,stddev_samp(sr_return_quantity) as store_returns_quantitystdev - ,stddev_samp(sr_return_quantity)/avg(sr_return_quantity) as store_returns_quantitycov - ,count(cs_quantity) as catalog_sales_quantitycount ,avg(cs_quantity) as catalog_sales_quantityave - ,stddev_samp(cs_quantity) as catalog_sales_quantitystdev - ,stddev_samp(cs_quantity)/avg(cs_quantity) as catalog_sales_quantitycov - from store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where d1.d_quarter_name = '2001Q1' - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_quarter_name in ('2001Q1','2001Q2','2001Q3') - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_quarter_name in ('2001Q1','2001Q2','2001Q3') - group by i_item_id - ,i_item_desc - ,s_state - order by i_item_id - ,i_item_desc - ,s_state -limit 100; - --- end template query17.tpl query 59 in stream 8 --- start template query42.tpl query 60 in stream 8 -select /* TPC-DS query42.tpl 0.61 */ dt.d_year - ,item.i_category_id - ,item.i_category - ,sum(ss_ext_sales_price) - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=12 - and dt.d_year=1998 - group by dt.d_year - ,item.i_category_id - ,item.i_category - order by sum(ss_ext_sales_price) desc,dt.d_year - ,item.i_category_id - ,item.i_category -limit 100 ; - --- end template query42.tpl query 60 in stream 8 --- start template query85.tpl query 61 in stream 8 -select /* TPC-DS query85.tpl 0.33 */ substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) - from web_sales, web_returns, web_page, customer_demographics cd1, - customer_demographics cd2, customer_address, date_dim, reason - where ws_web_page_sk = wp_web_page_sk - and ws_item_sk = wr_item_sk - and ws_order_number = wr_order_number - and ws_sold_date_sk = d_date_sk and d_year = 1998 - and cd1.cd_demo_sk = wr_refunded_cdemo_sk - and cd2.cd_demo_sk = wr_returning_cdemo_sk - and ca_address_sk = wr_refunded_addr_sk - and r_reason_sk = wr_reason_sk - and - ( - ( - cd1.cd_marital_status = 'S' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Primary' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 100.00 and 150.00 - ) - or - ( - cd1.cd_marital_status = 'W' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = '2 yr Degree' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 50.00 and 100.00 - ) - or - ( - cd1.cd_marital_status = 'M' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Unknown' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ca_country = 'United States' - and - ca_state in ('TX', 'CA', 'KY') - and ws_net_profit between 100 and 200 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('AL', 'LA', 'MT') - and ws_net_profit between 150 and 300 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('MO', 'ND', 'KS') - and ws_net_profit between 50 and 250 - ) - ) -group by r_reason_desc -order by substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) -limit 100; - --- end template query85.tpl query 61 in stream 8 --- start template query9.tpl query 62 in stream 8 -select /* TPC-DS query9.tpl 0.49 */ case when (select count(*) - from store_sales - where ss_quantity between 1 and 20) > 378382331 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 1 and 20) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 1 and 20) end bucket1 , - case when (select count(*) - from store_sales - where ss_quantity between 21 and 40) > 512942160 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 21 and 40) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 21 and 40) end bucket2, - case when (select count(*) - from store_sales - where ss_quantity between 41 and 60) > 1235307501 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 41 and 60) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 41 and 60) end bucket3, - case when (select count(*) - from store_sales - where ss_quantity between 61 and 80) > 897669097 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 61 and 80) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 61 and 80) end bucket4, - case when (select count(*) - from store_sales - where ss_quantity between 81 and 100) > 466207173 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 81 and 100) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 81 and 100) end bucket5 -from reason -where r_reason_sk = 1 -; - --- end template query9.tpl query 62 in stream 8 --- start template query32.tpl query 63 in stream 8 -select /* TPC-DS query32.tpl 0.7 */ sum(cs_ext_discount_amt) as "excess discount amount" -from - catalog_sales - ,item - ,date_dim -where -i_manufact_id = 875 -and i_item_sk = cs_item_sk -and d_date between '2000-02-10' and - dateadd(day,90,cast('2000-02-10' as date)) -and d_date_sk = cs_sold_date_sk -and cs_ext_discount_amt - > ( - select - 1.3 * avg(cs_ext_discount_amt) - from - catalog_sales - ,date_dim - where - cs_item_sk = i_item_sk - and d_date between '2000-02-10' and - dateadd(day,90,cast('2000-02-10' as date)) - and d_date_sk = cs_sold_date_sk - ) -limit 100; - --- end template query32.tpl query 63 in stream 8 --- start template query34.tpl query 64 in stream 8 -select /* TPC-DS query34.tpl 0.73 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (date_dim.d_dom between 1 and 3 or date_dim.d_dom between 25 and 28) - and (household_demographics.hd_buy_potential = '501-1000' or - household_demographics.hd_buy_potential = '0-500') - and household_demographics.hd_vehicle_count > 0 - and (case when household_demographics.hd_vehicle_count > 0 - then household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count - else null - end) > 1.2 - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_county in ('Jefferson County','Miller County','Coal County','Warren County', - 'Franklin Parish','Richland County','Piute County','Stillwater County') - group by ss_ticket_number,ss_customer_sk) dn,customer - where ss_customer_sk = c_customer_sk - and cnt between 15 and 20 - order by c_last_name,c_first_name,c_salutation,c_preferred_cust_flag desc, ss_ticket_number; - --- end template query34.tpl query 64 in stream 8 --- start template query79.tpl query 65 in stream 8 -select /* TPC-DS query79.tpl 0.89 */ - c_last_name,c_first_name,substring(s_city,1,30),ss_ticket_number,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,store.s_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (household_demographics.hd_dep_count = 9 or household_demographics.hd_vehicle_count > 0) - and date_dim.d_dow = 1 - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_number_employees between 200 and 295 - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,store.s_city) ms,customer - where ss_customer_sk = c_customer_sk - order by c_last_name,c_first_name,substring(s_city,1,30), profit -limit 100; - --- end template query79.tpl query 65 in stream 8 --- start template query54.tpl query 66 in stream 8 -with /* TPC-DS query54.tpl 0.81 */ my_customers as ( - select distinct c_customer_sk - , c_current_addr_sk - from - ( select cs_sold_date_sk sold_date_sk, - cs_bill_customer_sk customer_sk, - cs_item_sk item_sk - from catalog_sales - union all - select ws_sold_date_sk sold_date_sk, - ws_bill_customer_sk customer_sk, - ws_item_sk item_sk - from web_sales - ) cs_or_ws_sales, - item, - date_dim, - customer - where sold_date_sk = d_date_sk - and item_sk = i_item_sk - and i_category = 'Men' - and i_class = 'sports-apparel' - and c_customer_sk = cs_or_ws_sales.customer_sk - and d_moy = 3 - and d_year = 1999 - ) - , my_revenue as ( - select c_customer_sk, - sum(ss_ext_sales_price) as revenue - from my_customers, - store_sales, - customer_address, - store, - date_dim - where c_current_addr_sk = ca_address_sk - and ca_county = s_county - and ca_state = s_state - and ss_sold_date_sk = d_date_sk - and c_customer_sk = ss_customer_sk - and d_month_seq between (select distinct d_month_seq+1 - from date_dim where d_year = 1999 and d_moy = 3) - and (select distinct d_month_seq+3 - from date_dim where d_year = 1999 and d_moy = 3) - group by c_customer_sk - ) - , segments as - (select cast((revenue/50) as bigint) as segment - from my_revenue - ) - select segment, count(*) as num_customers, segment*50 as segment_base - from segments - group by segment - order by segment, num_customers - limit 100; - --- end template query54.tpl query 66 in stream 8 --- start template query77a.tpl query 67 in stream 8 -with /* TPC-DS query77a.tpl 0.78 */ ss as - (select s_store_sk, - sum(ss_ext_sales_price) as sales, - sum(ss_net_profit) as profit - from store_sales, - date_dim, - store - where ss_sold_date_sk = d_date_sk - and d_date between cast('1998-08-20' as date) - and dateadd(day,30,cast('1998-08-20' as date)) - and ss_store_sk = s_store_sk - group by s_store_sk) - , - sr as - (select s_store_sk, - sum(sr_return_amt) as returns, - sum(sr_net_loss) as profit_loss - from store_returns, - date_dim, - store - where sr_returned_date_sk = d_date_sk - and d_date between cast('1998-08-20' as date) - and dateadd(day,30,cast('1998-08-20' as date)) - and sr_store_sk = s_store_sk - group by s_store_sk), - cs as - (select cs_call_center_sk, - sum(cs_ext_sales_price) as sales, - sum(cs_net_profit) as profit - from catalog_sales, - date_dim - where cs_sold_date_sk = d_date_sk - and d_date between cast('1998-08-20' as date) - and dateadd(day,30,cast('1998-08-20' as date)) - group by cs_call_center_sk - ), - cr as - (select cr_call_center_sk, - sum(cr_return_amount) as returns, - sum(cr_net_loss) as profit_loss - from catalog_returns, - date_dim - where cr_returned_date_sk = d_date_sk - and d_date between cast('1998-08-20' as date) - and dateadd(day,30,cast('1998-08-20' as date)) - group by cr_call_center_sk), - ws as - ( select wp_web_page_sk, - sum(ws_ext_sales_price) as sales, - sum(ws_net_profit) as profit - from web_sales, - date_dim, - web_page - where ws_sold_date_sk = d_date_sk - and d_date between cast('1998-08-20' as date) - and dateadd(day,30,cast('1998-08-20' as date)) - and ws_web_page_sk = wp_web_page_sk - group by wp_web_page_sk), - wr as - (select wp_web_page_sk, - sum(wr_return_amt) as returns, - sum(wr_net_loss) as profit_loss - from web_returns, - date_dim, - web_page - where wr_returned_date_sk = d_date_sk - and d_date between cast('1998-08-20' as date) - and dateadd(day,30,cast('1998-08-20' as date)) - and wr_web_page_sk = wp_web_page_sk - group by wp_web_page_sk) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , ss.s_store_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ss left join sr - on ss.s_store_sk = sr.s_store_sk - union all - select 'catalog channel' as channel - , cs_call_center_sk as id - , sales - , returns - , (profit - profit_loss) as profit - from cs - , cr - union all - select 'web channel' as channel - , ws.wp_web_page_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ws left join wr - on ws.wp_web_page_sk = wr.wp_web_page_sk - ) x - group by channel, id ) - - select * - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results -) foo -order by channel, id - limit 100; - --- end template query77a.tpl query 67 in stream 8 --- start template query45.tpl query 68 in stream 8 -select /* TPC-DS query45.tpl 0.18 */ ca_zip, ca_county, sum(ws_sales_price) - from web_sales, customer, customer_address, date_dim, item - where ws_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ws_item_sk = i_item_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', '85392', '85460', '80348', '81792') - or - i_item_id in (select i_item_id - from item - where i_item_sk in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29) - ) - ) - and ws_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 2000 - group by ca_zip, ca_county - order by ca_zip, ca_county - limit 100; - --- end template query45.tpl query 68 in stream 8 --- start template query28.tpl query 69 in stream 8 -select /* TPC-DS query28.tpl 0.36 */ * -from (select avg(ss_list_price) B1_LP - ,count(ss_list_price) B1_CNT - ,count(distinct ss_list_price) B1_CNTD - from store_sales - where ss_quantity between 0 and 5 - and (ss_list_price between 144 and 144+10 - or ss_coupon_amt between 5845 and 5845+1000 - or ss_wholesale_cost between 8 and 8+20)) B1, - (select avg(ss_list_price) B2_LP - ,count(ss_list_price) B2_CNT - ,count(distinct ss_list_price) B2_CNTD - from store_sales - where ss_quantity between 6 and 10 - and (ss_list_price between 89 and 89+10 - or ss_coupon_amt between 13544 and 13544+1000 - or ss_wholesale_cost between 62 and 62+20)) B2, - (select avg(ss_list_price) B3_LP - ,count(ss_list_price) B3_CNT - ,count(distinct ss_list_price) B3_CNTD - from store_sales - where ss_quantity between 11 and 15 - and (ss_list_price between 11 and 11+10 - or ss_coupon_amt between 13985 and 13985+1000 - or ss_wholesale_cost between 74 and 74+20)) B3, - (select avg(ss_list_price) B4_LP - ,count(ss_list_price) B4_CNT - ,count(distinct ss_list_price) B4_CNTD - from store_sales - where ss_quantity between 16 and 20 - and (ss_list_price between 110 and 110+10 - or ss_coupon_amt between 14625 and 14625+1000 - or ss_wholesale_cost between 4 and 4+20)) B4, - (select avg(ss_list_price) B5_LP - ,count(ss_list_price) B5_CNT - ,count(distinct ss_list_price) B5_CNTD - from store_sales - where ss_quantity between 21 and 25 - and (ss_list_price between 141 and 141+10 - or ss_coupon_amt between 1589 and 1589+1000 - or ss_wholesale_cost between 32 and 32+20)) B5, - (select avg(ss_list_price) B6_LP - ,count(ss_list_price) B6_CNT - ,count(distinct ss_list_price) B6_CNTD - from store_sales - where ss_quantity between 26 and 30 - and (ss_list_price between 152 and 152+10 - or ss_coupon_amt between 15380 and 15380+1000 - or ss_wholesale_cost between 46 and 46+20)) B6 -limit 100; - --- end template query28.tpl query 69 in stream 8 --- start template query11.tpl query 70 in stream 8 -with /* TPC-DS query11.tpl 0.51 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ss_ext_list_price-ss_ext_discount_amt) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ws_ext_list_price-ws_ext_discount_amt) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_birth_country - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 1998 - and t_s_secyear.dyear = 1998+1 - and t_w_firstyear.dyear = 1998 - and t_w_secyear.dyear = 1998+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else 0.0 end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else 0.0 end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_birth_country -limit 100; - --- end template query11.tpl query 70 in stream 8 --- start template query89.tpl query 71 in stream 8 -select /* TPC-DS query89.tpl 0.56 */ * -from( -select i_category, i_class, i_brand, - s_store_name, s_company_name, - d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, s_store_name, s_company_name) - avg_monthly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - d_year in (2001) and - ((i_category in ('Sports','Jewelry','Electronics') and - i_class in ('football','birdal','musical') - ) - or (i_category in ('Music','Home','Women') and - i_class in ('pop','rugs','maternity') - )) -group by i_category, i_class, i_brand, - s_store_name, s_company_name, d_moy) tmp1 -where case when (avg_monthly_sales <> 0) then (abs(sum_sales - avg_monthly_sales) / avg_monthly_sales) else null end > 0.1 -order by sum_sales - avg_monthly_sales, s_store_name -limit 100; - --- end template query89.tpl query 71 in stream 8 --- start template query56.tpl query 72 in stream 8 -with /* TPC-DS query56.tpl 0.83 */ ss as ( - select i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where i_item_id in (select - i_item_id -from item -where i_color in ('turquoise','beige','violet')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 5 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - cs as ( - select i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('turquoise','beige','violet')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 5 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - ws as ( - select i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('turquoise','beige','violet')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 5 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id) - select i_item_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by total_sales, - i_item_id - limit 100; - --- end template query56.tpl query 72 in stream 8 --- start template query46.tpl query 73 in stream 8 -select /* TPC-DS query46.tpl 0.23 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and (household_demographics.hd_dep_count = 7 or - household_demographics.hd_vehicle_count= 4) - and date_dim.d_dow in (6,0) - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_city in ('Marion','Woodlawn','Johnson','Cross Roads','Rockville') - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,ca_city) dn,customer,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - limit 100; - --- end template query46.tpl query 73 in stream 8 --- start template query19.tpl query 74 in stream 8 -select /* TPC-DS query19.tpl 0.8 */ i_brand_id brand_id, i_brand brand, i_manufact_id, i_manufact, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item,customer,customer_address,store - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=9 - and d_moy=11 - and d_year=1998 - and ss_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and substring(ca_zip,1,5) <> substring(s_zip,1,5) - and ss_store_sk = s_store_sk - group by i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact - order by ext_price desc - ,i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact -limit 100 ; - --- end template query19.tpl query 74 in stream 8 --- start template query62.tpl query 75 in stream 8 -select /* TPC-DS query62.tpl 0.24 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 30) and - (ws_ship_date_sk - ws_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 60) and - (ws_ship_date_sk - ws_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 90) and - (ws_ship_date_sk - ws_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - web_sales - ,warehouse - ,ship_mode - ,web_site - ,date_dim -where - d_month_seq between 1206 and 1206 + 11 -and ws_ship_date_sk = d_date_sk -and ws_warehouse_sk = w_warehouse_sk -and ws_ship_mode_sk = sm_ship_mode_sk -and ws_web_site_sk = web_site_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -limit 100; - --- end template query62.tpl query 75 in stream 8 --- start template query8.tpl query 76 in stream 8 -select /* TPC-DS query8.tpl 0.63 */ s_store_name - ,sum(ss_net_profit) - from store_sales - ,date_dim - ,store, - (select ca_zip - from ( - SELECT substring(ca_zip,1,5) ca_zip - FROM customer_address - WHERE substring(ca_zip,1,5) IN ( - '68853','85062','82519','38394','38708','98506', - '62182','95730','11854','96941','44504', - '70281','89504','40168','69207','31019', - '15334','92179','15021','64512','79470', - '14962','30774','58834','17685','28052', - '71398','14745','45449','39470','36298', - '94257','81077','47447','19534','85710', - '38646','57967','34990','58452','10258', - '42280','75872','97050','33723','46451', - '48872','27073','51885','56413','93499', - '14509','69491','24222','34549','98232', - '88580','32575','29756','25384','69941', - '98265','99029','43934','33510','60690', - '63955','13684','59735','39059','87329', - '66685','87277','27304','59610','35349', - '74894','75083','13908','57639','75185', - '31667','91314','61894','87366','60685', - '93081','69541','34583','70304','65383', - '63158','66714','66683','11961','42474', - '27257','38881','92625','75030','66733', - '67085','49434','44186','91609','40077', - '72442','88935','69474','79649','50212', - '22115','27856','90264','36781','12422', - '22515','59526','55064','18643','17273', - '64766','37625','45070','28183','38389', - '52593','34120','27358','67355','89784', - '36925','82074','15115','77737','89019', - '65902','50165','93577','55890','90004', - '28393','88241','45423','71990','57177', - '88130','54401','70595','65153','33662', - '31715','83365','88385','13552','18224', - '13568','76110','17528','87167','40125', - '30004','41608','42046','56368','49556', - '79771','22757','90518','69226','53903', - '34992','19063','16041','23034','92538', - '56361','84179','30990','15904','97659', - '74778','11998','57676','32129','47634', - '20817','61193','69290','23736','26792', - '84288','36443','26767','64620','31824', - '54667','61742','63331','31262','95879', - '12100','37784','15344','54389','77856', - '42871','26095','21424','19499','44842', - '86026','20183','24049','84178','12107', - '52594','63490','48552','44201','75019', - '57528','28631','41657','52151','16601', - '86476','61405','15501','49032','64319', - '81618','29863','50685','44020','24973', - '19411','22299','74184','13490','45088', - '75677','30674','44763','20902','37225', - '72065','67911','74084','15916','15316', - '74741','25836','98059','19090','35608', - '67785','52161','75714','60277','37727', - '17669','56082','98053','14609','68858', - '19169','36418','75155','32637','27184', - '40159','13723','88995','87871','86043', - '43873','99047','71677','16037','84359', - '19427','80028','22636','38633','28013', - '86707','51453','46540','61646','58166', - '38471','63429','91189','54227','78955', - '22596','55140','74357','38194','74313', - '44825','73723','47664','38508','78829', - '93496','76048','15143','27771','49449', - '57800','70899','41041','71248','50932', - '20903','62832','84801','77321','76994', - '84567','98649','86323','46209','92546', - '69430','19213','50306','46530','93930', - '28823','56362','35128','63697','93972', - '87654','16695','97082','16919','48893', - '64411','71399','82432','23371','77481', - '82791','31781','32502','81638','36987', - '20141','14768','51081','80790','92795', - '65931','68002','99724','50063','85490', - '30207','19126','54825','35912','90126', - '35627','48918','95470','41383','84371', - '86288','35070','45211','55244','64017', - '56478','13269','11819','27855','45605', - '94407','93234','15118','16653','75810', - '10235','46832','68175','84399','48122', - '38669','57409','83738','38397','44453', - '20634','70855','10846','63726') - intersect - select ca_zip - from (SELECT substring(ca_zip,1,5) ca_zip,count(*) cnt - FROM customer_address, customer - WHERE ca_address_sk = c_current_addr_sk and - c_preferred_cust_flag='Y' - group by ca_zip - having count(*) > 10)A1)A2) V1 - where ss_store_sk = s_store_sk - and ss_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 2002 - and (substring(s_zip,1,2) = substring(V1.ca_zip,1,2)) - group by s_store_name - order by s_store_name - limit 100; - --- end template query8.tpl query 76 in stream 8 --- start template query96.tpl query 77 in stream 8 -select /* TPC-DS query96.tpl 0.1 */ count(*) -from store_sales - ,household_demographics - ,time_dim, store -where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 16 - and time_dim.t_minute >= 30 - and household_demographics.hd_dep_count = 2 - and store.s_store_name = 'ese' -order by count(*) -limit 100; - --- end template query96.tpl query 77 in stream 8 --- start template query1.tpl query 78 in stream 8 -with /* TPC-DS query1.tpl 0.12 */ customer_total_return as -(select sr_customer_sk as ctr_customer_sk -,sr_store_sk as ctr_store_sk -,sum(SR_FEE) as ctr_total_return -from store_returns -,date_dim -where sr_returned_date_sk = d_date_sk -and d_year =2000 -group by sr_customer_sk -,sr_store_sk) - select c_customer_id -from customer_total_return ctr1 -,store -,customer -where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 -from customer_total_return ctr2 -where ctr1.ctr_store_sk = ctr2.ctr_store_sk) -and s_store_sk = ctr1.ctr_store_sk -and s_state = 'FL' -and ctr1.ctr_customer_sk = c_customer_sk -order by c_customer_id -limit 100; - --- end template query1.tpl query 78 in stream 8 --- start template query23.tpl query 79 in stream 8 -with /* TPC-DS query23.tpl 0.68 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (1998,1998+1,1998+2,1998+3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1998,1998+1,1998+2,1998+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * -from - max_store_sales)) - select sum(sales) - from (select cs_quantity*cs_list_price sales - from catalog_sales - ,date_dim - where d_year = 1998 - and d_moy = 5 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - union all - select ws_quantity*ws_list_price sales - from web_sales - ,date_dim - where d_year = 1998 - and d_moy = 5 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer)) - limit 100; -with /* TPC-DS query23.tpl 0.68 part2 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (1998,1998 + 1,1998 + 2,1998 + 3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1998,1998+1,1998+2,1998+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * - from max_store_sales)) - select c_last_name,c_first_name,sales - from (select c_last_name,c_first_name,sum(cs_quantity*cs_list_price) sales - from catalog_sales - ,customer - ,date_dim - where d_year = 1998 - and d_moy = 5 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and cs_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name - union all - select c_last_name,c_first_name,sum(ws_quantity*ws_list_price) sales - from web_sales - ,customer - ,date_dim - where d_year = 1998 - and d_moy = 5 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and ws_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name) - order by c_last_name,c_first_name,sales - limit 100; - --- end template query23.tpl query 79 in stream 8 --- start template query88.tpl query 80 in stream 8 -select /* TPC-DS query88.tpl 0.66 */ * -from - (select count(*) h8_30_to_9 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2)) - and store.s_store_name = 'ese') s1, - (select count(*) h9_to_9_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2)) - and store.s_store_name = 'ese') s2, - (select count(*) h9_30_to_10 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2)) - and store.s_store_name = 'ese') s3, - (select count(*) h10_to_10_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2)) - and store.s_store_name = 'ese') s4, - (select count(*) h10_30_to_11 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2)) - and store.s_store_name = 'ese') s5, - (select count(*) h11_to_11_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2)) - and store.s_store_name = 'ese') s6, - (select count(*) h11_30_to_12 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2)) - and store.s_store_name = 'ese') s7, - (select count(*) h12_to_12_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 12 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2)) - and store.s_store_name = 'ese') s8 -; - --- end template query88.tpl query 80 in stream 8 --- start template query82.tpl query 81 in stream 8 -select /* TPC-DS query82.tpl 0.67 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, store_sales - where i_current_price between 8 and 8+30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('2001-05-11' as date) and dateadd(day,60,cast('2001-05-11' as date)) - and i_manufact_id in (376,702,199,290) - and inv_quantity_on_hand between 100 and 500 - and ss_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query82.tpl query 81 in stream 8 --- start template query87.tpl query 82 in stream 8 -select /* TPC-DS query87.tpl 0.77 */ count(*) -from ((select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1183 and 1183+11) - except - (select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1183 and 1183+11) - except - (select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1183 and 1183+11) -) cool_cust -; - --- end template query87.tpl query 82 in stream 8 --- start template query43.tpl query 83 in stream 8 -select /* TPC-DS query43.tpl 0.15 */ s_store_name, s_store_id, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from date_dim, store_sales, store - where d_date_sk = ss_sold_date_sk and - s_store_sk = ss_store_sk and - s_gmt_offset = -6 and - d_year = 2000 - group by s_store_name, s_store_id - order by s_store_name, s_store_id,sun_sales,mon_sales,tue_sales,wed_sales,thu_sales,fri_sales,sat_sales - limit 100; - --- end template query43.tpl query 83 in stream 8 --- start template query53.tpl query 84 in stream 8 -select /* TPC-DS query53.tpl 0.88 */ * from -(select i_manufact_id, -sum(ss_sales_price) sum_sales, -avg(sum(ss_sales_price)) over (partition by i_manufact_id) avg_quarterly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and -ss_sold_date_sk = d_date_sk and -ss_store_sk = s_store_sk and -d_month_seq in (1185,1185+1,1185+2,1185+3,1185+4,1185+5,1185+6,1185+7,1185+8,1185+9,1185+10,1185+11) and -((i_category in ('Books','Children','Electronics') and -i_class in ('personal','portable','reference','self-help') and -i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) -or(i_category in ('Women','Music','Men') and -i_class in ('accessories','classical','fragrances','pants') and -i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manufact_id, d_qoy ) tmp1 -where case when avg_quarterly_sales > 0 - then abs (sum_sales - avg_quarterly_sales)/ avg_quarterly_sales - else null end > 0.1 -order by avg_quarterly_sales, - sum_sales, - i_manufact_id -limit 100; - --- end template query53.tpl query 84 in stream 8 --- start template query20.tpl query 85 in stream 8 -select /* TPC-DS query20.tpl 0.65 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(cs_ext_sales_price) as itemrevenue - ,sum(cs_ext_sales_price)*100/sum(sum(cs_ext_sales_price)) over - (partition by i_class) as revenueratio - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and i_category in ('Sports', 'Men', 'Jewelry') - and cs_sold_date_sk = d_date_sk - and d_date between cast('2000-03-31' as date) - and dateadd(day,30,cast('2000-03-31' as date)) - group by i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - order by i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query20.tpl query 85 in stream 8 --- start template query52.tpl query 86 in stream 8 -select /* TPC-DS query52.tpl 0.59 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_sales_price) ext_price - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=11 - and dt.d_year=2001 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,ext_price desc - ,brand_id -limit 100 ; - --- end template query52.tpl query 86 in stream 8 --- start template query83.tpl query 87 in stream 8 -with /* TPC-DS query83.tpl 0.96 */ sr_items as - (select i_item_id item_id, - sum(sr_return_quantity) sr_item_qty - from store_returns, - item, - date_dim - where sr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2000-06-22','2000-09-16','2000-11-15'))) - and sr_returned_date_sk = d_date_sk - group by i_item_id), - cr_items as - (select i_item_id item_id, - sum(cr_return_quantity) cr_item_qty - from catalog_returns, - item, - date_dim - where cr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2000-06-22','2000-09-16','2000-11-15'))) - and cr_returned_date_sk = d_date_sk - group by i_item_id), - wr_items as - (select i_item_id item_id, - sum(wr_return_quantity) wr_item_qty - from web_returns, - item, - date_dim - where wr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2000-06-22','2000-09-16','2000-11-15'))) - and wr_returned_date_sk = d_date_sk - group by i_item_id) - select sr_items.item_id - ,sr_item_qty - ,sr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 sr_dev - ,cr_item_qty - ,cr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 cr_dev - ,wr_item_qty - ,wr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 wr_dev - ,(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 average - from sr_items - ,cr_items - ,wr_items - where sr_items.item_id=cr_items.item_id - and sr_items.item_id=wr_items.item_id - order by sr_items.item_id - ,sr_item_qty - limit 100; - --- end template query83.tpl query 87 in stream 8 --- start template query38.tpl query 88 in stream 8 -select /* TPC-DS query38.tpl 0.54 */ count(*) from ( - select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1191 and 1191 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1191 and 1191 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1191 and 1191 + 11 -) hot_cust -limit 100; - --- end template query38.tpl query 88 in stream 8 --- start template query68.tpl query 89 in stream 8 -select /* TPC-DS query68.tpl 0.95 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,extended_price - ,extended_tax - ,list_price - from (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_ext_sales_price) extended_price - ,sum(ss_ext_list_price) list_price - ,sum(ss_ext_tax) extended_tax - from store_sales - ,date_dim - ,store - ,household_demographics - ,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_dep_count = 7 or - household_demographics.hd_vehicle_count= 4) - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_city in ('Paradise','Jordan') - group by ss_ticket_number - ,ss_customer_sk - ,ss_addr_sk,ca_city) dn - ,customer - ,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,ss_ticket_number - limit 100; - --- end template query68.tpl query 89 in stream 8 --- start template query4.tpl query 90 in stream 8 -with /* TPC-DS query4.tpl 0.93 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(((ss_ext_list_price-ss_ext_wholesale_cost-ss_ext_discount_amt)+ss_ext_sales_price)/2) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((cs_ext_list_price-cs_ext_wholesale_cost-cs_ext_discount_amt)+cs_ext_sales_price)/2) ) year_total - ,'c' sale_type - from customer - ,catalog_sales - ,date_dim - where c_customer_sk = cs_bill_customer_sk - and cs_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year -union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((ws_ext_list_price-ws_ext_wholesale_cost-ws_ext_discount_amt)+ws_ext_sales_price)/2) ) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_email_address - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_c_firstyear - ,year_total t_c_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_c_secyear.customer_id - and t_s_firstyear.customer_id = t_c_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_c_firstyear.sale_type = 'c' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_c_secyear.sale_type = 'c' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 1999 - and t_s_secyear.dyear = 1999+1 - and t_c_firstyear.dyear = 1999 - and t_c_secyear.dyear = 1999+1 - and t_w_firstyear.dyear = 1999 - and t_w_secyear.dyear = 1999+1 - and t_s_firstyear.year_total > 0 - and t_c_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_email_address -limit 100; - --- end template query4.tpl query 90 in stream 8 --- start template query13.tpl query 91 in stream 8 -select /* TPC-DS query13.tpl 0.91 */ avg(ss_quantity) - ,avg(ss_ext_sales_price) - ,avg(ss_ext_wholesale_cost) - ,sum(ss_ext_wholesale_cost) - from store_sales - ,store - ,customer_demographics - ,household_demographics - ,customer_address - ,date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2001 - and((ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'W' - and cd_education_status = '4 yr Degree' - and ss_sales_price between 100.00 and 150.00 - and hd_dep_count = 3 - )or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'S' - and cd_education_status = 'College' - and ss_sales_price between 50.00 and 100.00 - and hd_dep_count = 1 - ) or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'D' - and cd_education_status = 'Advanced Degree' - and ss_sales_price between 150.00 and 200.00 - and hd_dep_count = 1 - )) - and((ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('KY', 'TN', 'GA') - and ss_net_profit between 100 and 200 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('MO', 'WI', 'VA') - and ss_net_profit between 150 and 300 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('MN', 'KS', 'MI') - and ss_net_profit between 50 and 250 - )) -; - --- end template query13.tpl query 91 in stream 8 --- start template query48.tpl query 92 in stream 8 -select /* TPC-DS query48.tpl 0.74 */ sum (ss_quantity) - from store_sales, store, customer_demographics, customer_address, date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 1998 - and - ( - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'W' - and - cd_education_status = '4 yr Degree' - and - ss_sales_price between 100.00 and 150.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'S' - and - cd_education_status = 'Primary' - and - ss_sales_price between 50.00 and 100.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'U' - and - cd_education_status = 'Unknown' - and - ss_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('MS', 'WV', 'RI') - and ss_net_profit between 0 and 2000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('AR', 'LA', 'GA') - and ss_net_profit between 150 and 3000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('NY', 'KS', 'OH') - and ss_net_profit between 50 and 25000 - ) - ) -; - --- end template query48.tpl query 92 in stream 8 --- start template query99.tpl query 93 in stream 8 -select /* TPC-DS query99.tpl 0.94 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 30) and - (cs_ship_date_sk - cs_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 60) and - (cs_ship_date_sk - cs_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 90) and - (cs_ship_date_sk - cs_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - catalog_sales - ,warehouse - ,ship_mode - ,call_center - ,date_dim -where - d_month_seq between 1224 and 1224 + 11 -and cs_ship_date_sk = d_date_sk -and cs_warehouse_sk = w_warehouse_sk -and cs_ship_mode_sk = sm_ship_mode_sk -and cs_call_center_sk = cc_call_center_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -limit 100; - --- end template query99.tpl query 93 in stream 8 --- start template query27a.tpl query 94 in stream 8 -with /* TPC-DS query27a.tpl 0.16 */ results as - (select i_item_id, - s_state, 0 as g_state, - ss_quantity agg1, - ss_list_price agg2, - ss_coupon_amt agg3, - ss_sales_price agg4 - from store_sales, customer_demographics, date_dim, store, item - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_store_sk = s_store_sk and - ss_cdemo_sk = cd_demo_sk and - cd_gender = 'M' and - cd_marital_status = 'S' and - cd_education_status = 'Advanced Degree' and - d_year = 1998 and - s_state in ('MI','TN', 'TX', 'SD', 'MI', 'TX') - ) - - select i_item_id, - s_state, g_state, agg1, agg2, agg3, agg4 - from ( - select i_item_id, s_state, 0 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4 from results - group by i_item_id, s_state - union all - select i_item_id, NULL AS s_state, 1 AS g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as s_state, 1 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - ) foo - order by i_item_id, s_state - limit 100; - --- end template query27a.tpl query 94 in stream 8 --- start template query18a.tpl query 95 in stream 8 -with /* TPC-DS query18a.tpl 0.90 */ results as - (select i_item_id, - ca_country, - ca_state, - ca_county, - cast(cs_quantity as decimal(12,2)) agg1, - cast(cs_list_price as decimal(12,2)) agg2, - cast(cs_coupon_amt as decimal(12,2)) agg3, - cast(cs_sales_price as decimal(12,2)) agg4, - cast(cs_net_profit as decimal(12,2)) agg5, - cast(c_birth_year as decimal(12,2)) agg6, - cast(cd1.cd_dep_count as decimal(12,2)) agg7 - from catalog_sales, customer_demographics cd1, customer_demographics cd2, customer, customer_address, date_dim, item - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd1.cd_demo_sk and - cs_bill_customer_sk = c_customer_sk and - cd1.cd_gender = 'M' and - cd1.cd_education_status = 'Secondary' and - c_current_cdemo_sk = cd2.cd_demo_sk and - c_current_addr_sk = ca_address_sk and - c_birth_month in (8,9,7,10,1,11) and - d_year = 2001 and - ca_state in ('MS','MI','IN','ND','CO','ID','KS') - ) - select i_item_id, ca_country, ca_state, ca_county, agg1, agg2, agg3, agg4, agg5, agg6, agg7 - from ( - select i_item_id, ca_country, ca_state, ca_county, avg(agg1) agg1, - avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state, ca_county - union all - select i_item_id, ca_country, ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state - union all - select i_item_id, ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country - union all - select i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - ) foo - order by ca_country, ca_state, ca_county, i_item_id - limit 100; - --- end template query18a.tpl query 95 in stream 8 --- start template query15.tpl query 96 in stream 8 -select /* TPC-DS query15.tpl 0.57 */ ca_zip - ,sum(cs_sales_price) - from catalog_sales - ,customer - ,customer_address - ,date_dim - where cs_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', - '85392', '85460', '80348', '81792') - or ca_state in ('CA','WA','GA') - or cs_sales_price > 500) - and cs_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 2000 - group by ca_zip - order by ca_zip - limit 100; - --- end template query15.tpl query 96 in stream 8 --- start template query33.tpl query 97 in stream 8 -with /* TPC-DS query33.tpl 0.22 */ ss as ( - select - i_manufact_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Sports')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 2 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -8 - group by i_manufact_id), - cs as ( - select - i_manufact_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Sports')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 2 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -8 - group by i_manufact_id), - ws as ( - select - i_manufact_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Sports')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 2 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -8 - group by i_manufact_id) - select i_manufact_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_manufact_id - order by total_sales -limit 100; - --- end template query33.tpl query 97 in stream 8 --- start template query31.tpl query 98 in stream 8 -with /* TPC-DS query31.tpl 0.50 */ ss as - (select ca_county,d_qoy, d_year,sum(ss_ext_sales_price) as store_sales - from store_sales,date_dim,customer_address - where ss_sold_date_sk = d_date_sk - and ss_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year), - ws as - (select ca_county,d_qoy, d_year,sum(ws_ext_sales_price) as web_sales - from web_sales,date_dim,customer_address - where ws_sold_date_sk = d_date_sk - and ws_bill_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year) - select - ss1.ca_county - ,ss1.d_year - ,ws2.web_sales/ws1.web_sales web_q1_q2_increase - ,ss2.store_sales/ss1.store_sales store_q1_q2_increase - ,ws3.web_sales/ws2.web_sales web_q2_q3_increase - ,ss3.store_sales/ss2.store_sales store_q2_q3_increase - from - ss ss1 - ,ss ss2 - ,ss ss3 - ,ws ws1 - ,ws ws2 - ,ws ws3 - where - ss1.d_qoy = 1 - and ss1.d_year = 2002 - and ss1.ca_county = ss2.ca_county - and ss2.d_qoy = 2 - and ss2.d_year = 2002 - and ss2.ca_county = ss3.ca_county - and ss3.d_qoy = 3 - and ss3.d_year = 2002 - and ss1.ca_county = ws1.ca_county - and ws1.d_qoy = 1 - and ws1.d_year = 2002 - and ws1.ca_county = ws2.ca_county - and ws2.d_qoy = 2 - and ws2.d_year = 2002 - and ws1.ca_county = ws3.ca_county - and ws3.d_qoy = 3 - and ws3.d_year =2002 - and case when ws1.web_sales > 0 then ws2.web_sales/ws1.web_sales else null end - > case when ss1.store_sales > 0 then ss2.store_sales/ss1.store_sales else null end - and case when ws2.web_sales > 0 then ws3.web_sales/ws2.web_sales else null end - > case when ss2.store_sales > 0 then ss3.store_sales/ss2.store_sales else null end - order by store_q2_q3_increase; - --- end template query31.tpl query 98 in stream 8 --- start template query63.tpl query 99 in stream 8 -select /* TPC-DS query63.tpl 0.27 */ * -from (select i_manager_id - ,sum(ss_sales_price) sum_sales - ,avg(sum(ss_sales_price)) over (partition by i_manager_id) avg_monthly_sales - from item - ,store_sales - ,date_dim - ,store - where ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and d_month_seq in (1223,1223+1,1223+2,1223+3,1223+4,1223+5,1223+6,1223+7,1223+8,1223+9,1223+10,1223+11) - and (( i_category in ('Books','Children','Electronics') - and i_class in ('personal','portable','reference','self-help') - and i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) - or( i_category in ('Women','Music','Men') - and i_class in ('accessories','classical','fragrances','pants') - and i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manager_id, d_moy) tmp1 -where case when avg_monthly_sales > 0 then abs (sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 -order by i_manager_id - ,avg_monthly_sales - ,sum_sales -limit 100; - --- end template query63.tpl query 99 in stream 8 diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/30TB/queries/query_9.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/30TB/queries/query_9.sql deleted file mode 100644 index 4d7c5f7a..00000000 --- a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/30TB/queries/query_9.sql +++ /dev/null @@ -1,5027 +0,0 @@ --- start template query15.tpl query 1 in stream 9 -select /* TPC-DS query15.tpl 0.57 */ ca_zip - ,sum(cs_sales_price) - from catalog_sales - ,customer - ,customer_address - ,date_dim - where cs_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', - '85392', '85460', '80348', '81792') - or ca_state in ('CA','WA','GA') - or cs_sales_price > 500) - and cs_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 2002 - group by ca_zip - order by ca_zip - limit 100; - --- end template query15.tpl query 1 in stream 9 --- start template query60.tpl query 2 in stream 9 -with /* TPC-DS query60.tpl 0.29 */ ss as ( - select - i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Shoes')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 9 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - cs as ( - select - i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Shoes')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 9 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - ws as ( - select - i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Shoes')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 9 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id) - select - i_item_id -,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by i_item_id - ,total_sales - limit 100; - --- end template query60.tpl query 2 in stream 9 --- start template query62.tpl query 3 in stream 9 -select /* TPC-DS query62.tpl 0.24 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 30) and - (ws_ship_date_sk - ws_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 60) and - (ws_ship_date_sk - ws_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 90) and - (ws_ship_date_sk - ws_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - web_sales - ,warehouse - ,ship_mode - ,web_site - ,date_dim -where - d_month_seq between 1182 and 1182 + 11 -and ws_ship_date_sk = d_date_sk -and ws_warehouse_sk = w_warehouse_sk -and ws_ship_mode_sk = sm_ship_mode_sk -and ws_web_site_sk = web_site_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -limit 100; - --- end template query62.tpl query 3 in stream 9 --- start template query74.tpl query 4 in stream 9 -with /* TPC-DS query74.tpl 0.76 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,sum(ss_net_paid) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (2001,2001+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,sum(ws_net_paid) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - and d_year in (2001,2001+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - ) - select - t_s_secyear.customer_id, t_s_secyear.customer_first_name, t_s_secyear.customer_last_name - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.year = 2001 - and t_s_secyear.year = 2001+1 - and t_w_firstyear.year = 2001 - and t_w_secyear.year = 2001+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - order by 1,2,3 -limit 100; - --- end template query74.tpl query 4 in stream 9 --- start template query81.tpl query 5 in stream 9 -with /* TPC-DS query81.tpl 0.37 */ customer_total_return as - (select cr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(cr_return_amt_inc_tax) as ctr_total_return - from catalog_returns - ,date_dim - ,customer_address - where cr_returned_date_sk = d_date_sk - and d_year =1998 - and cr_returning_addr_sk = ca_address_sk - group by cr_returning_customer_sk - ,ca_state ) - select c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'AK' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - limit 100; - --- end template query81.tpl query 5 in stream 9 --- start template query88.tpl query 6 in stream 9 -select /* TPC-DS query88.tpl 0.66 */ * -from - (select count(*) h8_30_to_9 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s1, - (select count(*) h9_to_9_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s2, - (select count(*) h9_30_to_10 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s3, - (select count(*) h10_to_10_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s4, - (select count(*) h10_30_to_11 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s5, - (select count(*) h11_to_11_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s6, - (select count(*) h11_30_to_12 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s7, - (select count(*) h12_to_12_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 12 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s8 -; - --- end template query88.tpl query 6 in stream 9 --- start template query50.tpl query 7 in stream 9 -select /* TPC-DS query50.tpl 0.60 */ - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 30) and - (sr_returned_date_sk - ss_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 60) and - (sr_returned_date_sk - ss_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 90) and - (sr_returned_date_sk - ss_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - store_sales - ,store_returns - ,store - ,date_dim d1 - ,date_dim d2 -where - d2.d_year = 2000 -and d2.d_moy = 8 -and ss_ticket_number = sr_ticket_number -and ss_item_sk = sr_item_sk -and ss_sold_date_sk = d1.d_date_sk -and sr_returned_date_sk = d2.d_date_sk -and ss_customer_sk = sr_customer_sk -and ss_store_sk = s_store_sk -group by - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -order by s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -limit 100; - --- end template query50.tpl query 7 in stream 9 --- start template query5a.tpl query 8 in stream 9 -with /* TPC-DS query5a.tpl 0.98 */ ssr as - (select s_store_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ss_store_sk as store_sk, - ss_sold_date_sk as date_sk, - ss_ext_sales_price as sales_price, - ss_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from store_sales - union all - select sr_store_sk as store_sk, - sr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - sr_return_amt as return_amt, - sr_net_loss as net_loss - from store_returns - ) salesreturns, - date_dim, - store - where date_sk = d_date_sk - and d_date between cast('2002-08-22' as date) - and dateadd(day,14,cast('2002-08-22' as date)) - and store_sk = s_store_sk - group by s_store_id) - , - csr as - (select cp_catalog_page_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select cs_catalog_page_sk as page_sk, - cs_sold_date_sk as date_sk, - cs_ext_sales_price as sales_price, - cs_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from catalog_sales - union all - select cr_catalog_page_sk as page_sk, - cr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - cr_return_amount as return_amt, - cr_net_loss as net_loss - from catalog_returns - ) salesreturns, - date_dim, - catalog_page - where date_sk = d_date_sk - and d_date between cast('2002-08-22' as date) - and dateadd(day,14,cast('2002-08-22' as date)) - and page_sk = cp_catalog_page_sk - group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ws_web_site_sk as wsr_web_site_sk, - ws_sold_date_sk as date_sk, - ws_ext_sales_price as sales_price, - ws_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from web_sales - union all - select ws_web_site_sk as wsr_web_site_sk, - wr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - wr_return_amt as return_amt, - wr_net_loss as net_loss - from web_returns left outer join web_sales on - ( wr_item_sk = ws_item_sk - and wr_order_number = ws_order_number) - ) salesreturns, - date_dim, - web_site - where date_sk = d_date_sk - and d_date between cast('2002-08-22' as date) - and dateadd(day,14,cast('2002-08-22' as date)) - and wsr_web_site_sk = web_site_sk - group by web_site_id) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || s_store_id as id - , sales - , returns - , (profit - profit_loss) as profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || cp_catalog_page_id as id - , sales - , returns - , (profit - profit_loss) as profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , (profit - profit_loss) as profit - from wsr - ) x - group by channel, id) - select channel, id, sales, returns, profit from ( - select channel, id, sales, returns, profit from results - union - select channel, null as id, sum(sales), sum(returns), sum(profit) from results group by channel - union - select null as channel, null as id, sum(sales), sum(returns), sum(profit) from results) foo -order by channel, id -limit 100; - --- end template query5a.tpl query 8 in stream 9 --- start template query84.tpl query 9 in stream 9 -select /* TPC-DS query84.tpl 0.80 */ c_customer_id as customer_id - , coalesce(c_last_name,'') || ', ' || coalesce(c_first_name,'') as customername - from customer - ,customer_address - ,customer_demographics - ,household_demographics - ,income_band - ,store_returns - where ca_city = 'Union Hill' - and c_current_addr_sk = ca_address_sk - and ib_lower_bound >= 26731 - and ib_upper_bound <= 26731 + 50000 - and ib_income_band_sk = hd_income_band_sk - and cd_demo_sk = c_current_cdemo_sk - and hd_demo_sk = c_current_hdemo_sk - and sr_cdemo_sk = cd_demo_sk - order by c_customer_id - limit 100; - --- end template query84.tpl query 9 in stream 9 --- start template query1.tpl query 10 in stream 9 -with /* TPC-DS query1.tpl 0.12 */ customer_total_return as -(select sr_customer_sk as ctr_customer_sk -,sr_store_sk as ctr_store_sk -,sum(SR_RETURN_AMT_INC_TAX) as ctr_total_return -from store_returns -,date_dim -where sr_returned_date_sk = d_date_sk -and d_year =1999 -group by sr_customer_sk -,sr_store_sk) - select c_customer_id -from customer_total_return ctr1 -,store -,customer -where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 -from customer_total_return ctr2 -where ctr1.ctr_store_sk = ctr2.ctr_store_sk) -and s_store_sk = ctr1.ctr_store_sk -and s_state = 'OH' -and ctr1.ctr_customer_sk = c_customer_sk -order by c_customer_id -limit 100; - --- end template query1.tpl query 10 in stream 9 --- start template query52.tpl query 11 in stream 9 -select /* TPC-DS query52.tpl 0.59 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_sales_price) ext_price - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=11 - and dt.d_year=1999 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,ext_price desc - ,brand_id -limit 100 ; - --- end template query52.tpl query 11 in stream 9 --- start template query57.tpl query 12 in stream 9 -with /* TPC-DS query57.tpl 0.70 */ v1 as( - select i_category, i_brand, - cc_name, - d_year, d_moy, - sum(cs_sales_price) sum_sales, - avg(sum(cs_sales_price)) over - (partition by i_category, i_brand, - cc_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - cc_name - order by d_year, d_moy) rn - from item, catalog_sales, date_dim, call_center - where cs_item_sk = i_item_sk and - cs_sold_date_sk = d_date_sk and - cc_call_center_sk= cs_call_center_sk and - ( - d_year = 2000 or - ( d_year = 2000-1 and d_moy =12) or - ( d_year = 2000+1 and d_moy =1) - ) - group by i_category, i_brand, - cc_name , d_year, d_moy), - v2 as( - select v1.cc_name - ,v1.d_year - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1. cc_name = v1_lag. cc_name and - v1. cc_name = v1_lead. cc_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 2000 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, psum - limit 100; - --- end template query57.tpl query 12 in stream 9 --- start template query13.tpl query 13 in stream 9 -select /* TPC-DS query13.tpl 0.91 */ avg(ss_quantity) - ,avg(ss_ext_sales_price) - ,avg(ss_ext_wholesale_cost) - ,sum(ss_ext_wholesale_cost) - from store_sales - ,store - ,customer_demographics - ,household_demographics - ,customer_address - ,date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2001 - and((ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'M' - and cd_education_status = 'Primary' - and ss_sales_price between 100.00 and 150.00 - and hd_dep_count = 3 - )or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'W' - and cd_education_status = 'Secondary' - and ss_sales_price between 50.00 and 100.00 - and hd_dep_count = 1 - ) or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'S' - and cd_education_status = 'Advanced Degree' - and ss_sales_price between 150.00 and 200.00 - and hd_dep_count = 1 - )) - and((ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('FL', 'AL', 'KS') - and ss_net_profit between 100 and 200 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('LA', 'VT', 'MT') - and ss_net_profit between 150 and 300 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('WV', 'OH', 'TX') - and ss_net_profit between 50 and 250 - )) -; - --- end template query13.tpl query 13 in stream 9 --- start template query14a.tpl query 14 in stream 9 -with /* TPC-DS query14a.tpl 0.69 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 2000 AND 2000 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 2000 AND 2000 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 2000 AND 2000 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as - (select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2) x) -, - results AS -(select channel, i_brand_id, i_class_id, i_category_id, sum(sales) sum_sales, sum(number_sales) number_sales - from ( - select 'store' channel, i_brand_id,i_class_id - ,i_category_id,sum(ss_quantity*ss_list_price) sales - , count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2000+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales) - union all - select 'catalog' channel, i_brand_id,i_class_id,i_category_id, sum(cs_quantity*cs_list_price) sales, count(*) number_sales - from catalog_sales - ,item - ,date_dim - where cs_item_sk in (select ss_item_sk from cross_items) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2000+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(cs_quantity*cs_list_price) > (select average_sales from avg_sales) - union all - select 'web' channel, i_brand_id,i_class_id,i_category_id, sum(ws_quantity*ws_list_price) sales , count(*) number_sales - from web_sales - ,item - ,date_dim - where ws_item_sk in (select ss_item_sk from cross_items) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2000+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ws_quantity*ws_list_price) > (select average_sales from avg_sales) - ) y - group by channel, i_brand_id,i_class_id,i_category_id) - - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales -from ( - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales from results - union - select channel, i_brand_id, i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id, i_class_id - union - select channel, i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id - union - select channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel - union - select null as channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results) z -order by channel, i_brand_id, i_class_id, i_category_id - limit 100; -with /* TPC-DS query14a.tpl 0.69 part2 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 2000 AND 2000 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 2000 AND 2000 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 2000 AND 2000 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as -(select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2) x) - select this_year.channel ty_channel - ,this_year.i_brand_id ty_brand - ,this_year.i_class_id ty_class - ,this_year.i_category_id ty_category - ,this_year.sales ty_sales - ,this_year.number_sales ty_number_sales - ,last_year.channel ly_channel - ,last_year.i_brand_id ly_brand - ,last_year.i_class_id ly_class - ,last_year.i_category_id ly_category - ,last_year.sales ly_sales - ,last_year.number_sales ly_number_sales -from - (select 'store' channel, i_brand_id,i_class_id,i_category_id - ,sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 2000 + 1 - and d_moy = 12 - and d_dom = 6) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) this_year, - (select 'store' channel, i_brand_id,i_class_id - ,i_category_id, sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 2000 - and d_moy = 12 - and d_dom = 6) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) last_year - where this_year.i_brand_id= last_year.i_brand_id - and this_year.i_class_id = last_year.i_class_id - and this_year.i_category_id = last_year.i_category_id - order by this_year.channel, this_year.i_brand_id, this_year.i_class_id, this_year.i_category_id - limit 100; - --- end template query14a.tpl query 14 in stream 9 --- start template query90.tpl query 15 in stream 9 -select /* TPC-DS query90.tpl 0.40 */ cast(amc as decimal(15,4))/cast(pmc as decimal(15,4)) am_pm_ratio - from ( select count(*) amc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 7 and 7+1 - and household_demographics.hd_dep_count = 2 - and web_page.wp_char_count between 5000 and 5200) at, - ( select count(*) pmc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 15 and 15+1 - and household_demographics.hd_dep_count = 2 - and web_page.wp_char_count between 5000 and 5200) pt - order by am_pm_ratio - limit 100; - --- end template query90.tpl query 15 in stream 9 --- start template query7.tpl query 16 in stream 9 -select /* TPC-DS query7.tpl 0.2 */ i_item_id, - avg(ss_quantity) agg1, - avg(ss_list_price) agg2, - avg(ss_coupon_amt) agg3, - avg(ss_sales_price) agg4 - from store_sales, customer_demographics, date_dim, item, promotion - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_cdemo_sk = cd_demo_sk and - ss_promo_sk = p_promo_sk and - cd_gender = 'M' and - cd_marital_status = 'S' and - cd_education_status = 'Advanced Degree' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 2002 - group by i_item_id - order by i_item_id - limit 100; - --- end template query7.tpl query 16 in stream 9 --- start template query27a.tpl query 17 in stream 9 -with /* TPC-DS query27a.tpl 0.16 */ results as - (select i_item_id, - s_state, 0 as g_state, - ss_quantity agg1, - ss_list_price agg2, - ss_coupon_amt agg3, - ss_sales_price agg4 - from store_sales, customer_demographics, date_dim, store, item - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_store_sk = s_store_sk and - ss_cdemo_sk = cd_demo_sk and - cd_gender = 'F' and - cd_marital_status = 'M' and - cd_education_status = 'Primary' and - d_year = 2000 and - s_state in ('TN','SC', 'IN', 'MN', 'KY', 'TX') - ) - - select i_item_id, - s_state, g_state, agg1, agg2, agg3, agg4 - from ( - select i_item_id, s_state, 0 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4 from results - group by i_item_id, s_state - union all - select i_item_id, NULL AS s_state, 1 AS g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as s_state, 1 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - ) foo - order by i_item_id, s_state - limit 100; - --- end template query27a.tpl query 17 in stream 9 --- start template query92.tpl query 18 in stream 9 -select /* TPC-DS query92.tpl 0.44 */ - sum(ws_ext_discount_amt) as "Excess Discount Amount" -from - web_sales - ,item - ,date_dim -where -i_manufact_id = 404 -and i_item_sk = ws_item_sk -and d_date between '1998-01-30' and - dateadd(day,90,cast('1998-01-30' as date)) -and d_date_sk = ws_sold_date_sk -and ws_ext_discount_amt - > ( - SELECT - 1.3 * avg(ws_ext_discount_amt) - FROM - web_sales - ,date_dim - WHERE - ws_item_sk = i_item_sk - and d_date between '1998-01-30' and - dateadd(day,90,cast('1998-01-30' as date)) - and d_date_sk = ws_sold_date_sk - ) -order by sum(ws_ext_discount_amt) -limit 100; - --- end template query92.tpl query 18 in stream 9 --- start template query39.tpl query 19 in stream 9 -with /* TPC-DS query39.tpl 0.5 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =1998 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=2 - and inv2.d_moy=2+1 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; -with /* TPC-DS query39.tpl 0.5 part2 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =1998 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=2 - and inv2.d_moy=2+1 - and inv1.cov > 1.5 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; - --- end template query39.tpl query 19 in stream 9 --- start template query34.tpl query 20 in stream 9 -select /* TPC-DS query34.tpl 0.73 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (date_dim.d_dom between 1 and 3 or date_dim.d_dom between 25 and 28) - and (household_demographics.hd_buy_potential = '501-1000' or - household_demographics.hd_buy_potential = 'Unknown') - and household_demographics.hd_vehicle_count > 0 - and (case when household_demographics.hd_vehicle_count > 0 - then household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count - else null - end) > 1.2 - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_county in ('Luce County','Anderson County','Maverick County','Morgan County', - 'Camden County','Mercer County','Lea County','San Miguel County') - group by ss_ticket_number,ss_customer_sk) dn,customer - where ss_customer_sk = c_customer_sk - and cnt between 15 and 20 - order by c_last_name,c_first_name,c_salutation,c_preferred_cust_flag desc, ss_ticket_number; - --- end template query34.tpl query 20 in stream 9 --- start template query21.tpl query 21 in stream 9 -select /* TPC-DS query21.tpl 0.14 */ * - from(select w_warehouse_name - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('1999-05-28' as date)) - then inv_quantity_on_hand - else 0 end) as inv_before - ,sum(case when (cast(d_date as date) >= cast ('1999-05-28' as date)) - then inv_quantity_on_hand - else 0 end) as inv_after - from inventory - ,warehouse - ,item - ,date_dim - where i_current_price between 0.99 and 1.49 - and i_item_sk = inv_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('1999-05-28' as date)) - and dateadd(day,30,cast ('1999-05-28' as date)) - group by w_warehouse_name, i_item_id) x - where (case when inv_before > 0 - then inv_after / inv_before - else null - end) between 2.0/3.0 and 3.0/2.0 - order by w_warehouse_name - ,i_item_id - limit 100; - --- end template query21.tpl query 21 in stream 9 --- start template query65.tpl query 22 in stream 9 -select /* TPC-DS query65.tpl 0.71 */ - s_store_name, - i_item_desc, - sc.revenue, - i_current_price, - i_wholesale_cost, - i_brand - from store, item, - (select ss_store_sk, avg(revenue) as ave - from - (select ss_store_sk, ss_item_sk, - sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1224 and 1224+11 - group by ss_store_sk, ss_item_sk) sa - group by ss_store_sk) sb, - (select ss_store_sk, ss_item_sk, sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1224 and 1224+11 - group by ss_store_sk, ss_item_sk) sc - where sb.ss_store_sk = sc.ss_store_sk and - sc.revenue <= 0.1 * sb.ave and - s_store_sk = sc.ss_store_sk and - i_item_sk = sc.ss_item_sk - order by s_store_name, i_item_desc -limit 100; - --- end template query65.tpl query 22 in stream 9 --- start template query75.tpl query 23 in stream 9 -WITH /* TPC-DS query75.tpl 0.3 */ all_sales AS ( - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,SUM(sales_cnt) AS sales_cnt - ,SUM(sales_amt) AS sales_amt - FROM (SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,cs_quantity - COALESCE(cr_return_quantity,0) AS sales_cnt - ,cs_ext_sales_price - COALESCE(cr_return_amount,0.0) AS sales_amt - FROM catalog_sales JOIN item ON i_item_sk=cs_item_sk - JOIN date_dim ON d_date_sk=cs_sold_date_sk - LEFT JOIN catalog_returns ON (cs_order_number=cr_order_number - AND cs_item_sk=cr_item_sk) - WHERE i_category='Books' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ss_quantity - COALESCE(sr_return_quantity,0) AS sales_cnt - ,ss_ext_sales_price - COALESCE(sr_return_amt,0.0) AS sales_amt - FROM store_sales JOIN item ON i_item_sk=ss_item_sk - JOIN date_dim ON d_date_sk=ss_sold_date_sk - LEFT JOIN store_returns ON (ss_ticket_number=sr_ticket_number - AND ss_item_sk=sr_item_sk) - WHERE i_category='Books' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ws_quantity - COALESCE(wr_return_quantity,0) AS sales_cnt - ,ws_ext_sales_price - COALESCE(wr_return_amt,0.0) AS sales_amt - FROM web_sales JOIN item ON i_item_sk=ws_item_sk - JOIN date_dim ON d_date_sk=ws_sold_date_sk - LEFT JOIN web_returns ON (ws_order_number=wr_order_number - AND ws_item_sk=wr_item_sk) - WHERE i_category='Books') sales_detail - GROUP BY d_year, i_brand_id, i_class_id, i_category_id, i_manufact_id) - SELECT prev_yr.d_year AS prev_year - ,curr_yr.d_year AS year - ,curr_yr.i_brand_id - ,curr_yr.i_class_id - ,curr_yr.i_category_id - ,curr_yr.i_manufact_id - ,prev_yr.sales_cnt AS prev_yr_cnt - ,curr_yr.sales_cnt AS curr_yr_cnt - ,curr_yr.sales_cnt-prev_yr.sales_cnt AS sales_cnt_diff - ,curr_yr.sales_amt-prev_yr.sales_amt AS sales_amt_diff - FROM all_sales curr_yr, all_sales prev_yr - WHERE curr_yr.i_brand_id=prev_yr.i_brand_id - AND curr_yr.i_class_id=prev_yr.i_class_id - AND curr_yr.i_category_id=prev_yr.i_category_id - AND curr_yr.i_manufact_id=prev_yr.i_manufact_id - AND curr_yr.d_year=2001 - AND prev_yr.d_year=2001-1 - AND CAST(curr_yr.sales_cnt AS DECIMAL(17,2))/CAST(prev_yr.sales_cnt AS DECIMAL(17,2))<0.9 - ORDER BY sales_cnt_diff,sales_amt_diff - limit 100; - --- end template query75.tpl query 23 in stream 9 --- start template query9.tpl query 24 in stream 9 -select /* TPC-DS query9.tpl 0.49 */ case when (select count(*) - from store_sales - where ss_quantity between 1 and 20) > 1309008429 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 1 and 20) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 1 and 20) end bucket1 , - case when (select count(*) - from store_sales - where ss_quantity between 21 and 40) > 37949019 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 21 and 40) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 21 and 40) end bucket2, - case when (select count(*) - from store_sales - where ss_quantity between 41 and 60) > 1307977573 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 41 and 60) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 41 and 60) end bucket3, - case when (select count(*) - from store_sales - where ss_quantity between 61 and 80) > 140610725 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 61 and 80) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 61 and 80) end bucket4, - case when (select count(*) - from store_sales - where ss_quantity between 81 and 100) > 1081275073 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 81 and 100) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 81 and 100) end bucket5 -from reason -where r_reason_sk = 1 -; - --- end template query9.tpl query 24 in stream 9 --- start template query2.tpl query 25 in stream 9 -with /* TPC-DS query2.tpl 0.84 */ wscs as - (select sold_date_sk - ,sales_price - from (select ws_sold_date_sk sold_date_sk - ,ws_ext_sales_price sales_price - from web_sales - union all - select cs_sold_date_sk sold_date_sk - ,cs_ext_sales_price sales_price - from catalog_sales)), - wswscs as - (select d_week_seq, - sum(case when (d_day_name='Sunday') then sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then sales_price else null end) sat_sales - from wscs - ,date_dim - where d_date_sk = sold_date_sk - group by d_week_seq) - select d_week_seq1 - ,round(sun_sales1/sun_sales2,2) - ,round(mon_sales1/mon_sales2,2) - ,round(tue_sales1/tue_sales2,2) - ,round(wed_sales1/wed_sales2,2) - ,round(thu_sales1/thu_sales2,2) - ,round(fri_sales1/fri_sales2,2) - ,round(sat_sales1/sat_sales2,2) - from - (select wswscs.d_week_seq d_week_seq1 - ,sun_sales sun_sales1 - ,mon_sales mon_sales1 - ,tue_sales tue_sales1 - ,wed_sales wed_sales1 - ,thu_sales thu_sales1 - ,fri_sales fri_sales1 - ,sat_sales sat_sales1 - from wswscs,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 1999) y, - (select wswscs.d_week_seq d_week_seq2 - ,sun_sales sun_sales2 - ,mon_sales mon_sales2 - ,tue_sales tue_sales2 - ,wed_sales wed_sales2 - ,thu_sales thu_sales2 - ,fri_sales fri_sales2 - ,sat_sales sat_sales2 - from wswscs - ,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 1999+1) z - where d_week_seq1=d_week_seq2-53 - order by d_week_seq1; - --- end template query2.tpl query 25 in stream 9 --- start template query12.tpl query 26 in stream 9 -select /* TPC-DS query12.tpl 0.64 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ws_ext_sales_price) as itemrevenue - ,sum(ws_ext_sales_price)*100/sum(sum(ws_ext_sales_price)) over - (partition by i_class) as revenueratio -from - web_sales - ,item - ,date_dim -where - ws_item_sk = i_item_sk - and i_category in ('Children', 'Electronics', 'Men') - and ws_sold_date_sk = d_date_sk - and d_date between cast('2001-05-14' as date) - and dateadd(day,30,cast('2001-05-14' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query12.tpl query 26 in stream 9 --- start template query32.tpl query 27 in stream 9 -select /* TPC-DS query32.tpl 0.7 */ sum(cs_ext_discount_amt) as "excess discount amount" -from - catalog_sales - ,item - ,date_dim -where -i_manufact_id = 761 -and i_item_sk = cs_item_sk -and d_date between '2001-02-03' and - dateadd(day,90,cast('2001-02-03' as date)) -and d_date_sk = cs_sold_date_sk -and cs_ext_discount_amt - > ( - select - 1.3 * avg(cs_ext_discount_amt) - from - catalog_sales - ,date_dim - where - cs_item_sk = i_item_sk - and d_date between '2001-02-03' and - dateadd(day,90,cast('2001-02-03' as date)) - and d_date_sk = cs_sold_date_sk - ) -limit 100; - --- end template query32.tpl query 27 in stream 9 --- start template query28.tpl query 28 in stream 9 -select /* TPC-DS query28.tpl 0.36 */ * -from (select avg(ss_list_price) B1_LP - ,count(ss_list_price) B1_CNT - ,count(distinct ss_list_price) B1_CNTD - from store_sales - where ss_quantity between 0 and 5 - and (ss_list_price between 16 and 16+10 - or ss_coupon_amt between 6047 and 6047+1000 - or ss_wholesale_cost between 70 and 70+20)) B1, - (select avg(ss_list_price) B2_LP - ,count(ss_list_price) B2_CNT - ,count(distinct ss_list_price) B2_CNTD - from store_sales - where ss_quantity between 6 and 10 - and (ss_list_price between 134 and 134+10 - or ss_coupon_amt between 15962 and 15962+1000 - or ss_wholesale_cost between 72 and 72+20)) B2, - (select avg(ss_list_price) B3_LP - ,count(ss_list_price) B3_CNT - ,count(distinct ss_list_price) B3_CNTD - from store_sales - where ss_quantity between 11 and 15 - and (ss_list_price between 37 and 37+10 - or ss_coupon_amt between 1892 and 1892+1000 - or ss_wholesale_cost between 18 and 18+20)) B3, - (select avg(ss_list_price) B4_LP - ,count(ss_list_price) B4_CNT - ,count(distinct ss_list_price) B4_CNTD - from store_sales - where ss_quantity between 16 and 20 - and (ss_list_price between 82 and 82+10 - or ss_coupon_amt between 13556 and 13556+1000 - or ss_wholesale_cost between 77 and 77+20)) B4, - (select avg(ss_list_price) B5_LP - ,count(ss_list_price) B5_CNT - ,count(distinct ss_list_price) B5_CNTD - from store_sales - where ss_quantity between 21 and 25 - and (ss_list_price between 44 and 44+10 - or ss_coupon_amt between 7541 and 7541+1000 - or ss_wholesale_cost between 24 and 24+20)) B5, - (select avg(ss_list_price) B6_LP - ,count(ss_list_price) B6_CNT - ,count(distinct ss_list_price) B6_CNTD - from store_sales - where ss_quantity between 26 and 30 - and (ss_list_price between 115 and 115+10 - or ss_coupon_amt between 5391 and 5391+1000 - or ss_wholesale_cost between 36 and 36+20)) B6 -limit 100; - --- end template query28.tpl query 28 in stream 9 --- start template query42.tpl query 29 in stream 9 -select /* TPC-DS query42.tpl 0.61 */ dt.d_year - ,item.i_category_id - ,item.i_category - ,sum(ss_ext_sales_price) - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=11 - and dt.d_year=1999 - group by dt.d_year - ,item.i_category_id - ,item.i_category - order by sum(ss_ext_sales_price) desc,dt.d_year - ,item.i_category_id - ,item.i_category -limit 100 ; - --- end template query42.tpl query 29 in stream 9 --- start template query17.tpl query 30 in stream 9 -select /* TPC-DS query17.tpl 0.41 */ i_item_id - ,i_item_desc - ,s_state - ,count(ss_quantity) as store_sales_quantitycount - ,avg(ss_quantity) as store_sales_quantityave - ,stddev_samp(ss_quantity) as store_sales_quantitystdev - ,stddev_samp(ss_quantity)/avg(ss_quantity) as store_sales_quantitycov - ,count(sr_return_quantity) as store_returns_quantitycount - ,avg(sr_return_quantity) as store_returns_quantityave - ,stddev_samp(sr_return_quantity) as store_returns_quantitystdev - ,stddev_samp(sr_return_quantity)/avg(sr_return_quantity) as store_returns_quantitycov - ,count(cs_quantity) as catalog_sales_quantitycount ,avg(cs_quantity) as catalog_sales_quantityave - ,stddev_samp(cs_quantity) as catalog_sales_quantitystdev - ,stddev_samp(cs_quantity)/avg(cs_quantity) as catalog_sales_quantitycov - from store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where d1.d_quarter_name = '2001Q1' - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_quarter_name in ('2001Q1','2001Q2','2001Q3') - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_quarter_name in ('2001Q1','2001Q2','2001Q3') - group by i_item_id - ,i_item_desc - ,s_state - order by i_item_id - ,i_item_desc - ,s_state -limit 100; - --- end template query17.tpl query 30 in stream 9 --- start template query67a.tpl query 31 in stream 9 -with /* TPC-DS query67a.tpl 0.35 */ results as -( select i_category ,i_class ,i_brand ,i_product_name ,d_year ,d_qoy ,d_moy ,s_store_id - ,sum(coalesce(ss_sales_price*ss_quantity,0)) sumsales - from store_sales ,date_dim ,store ,item - where ss_sold_date_sk=d_date_sk - and ss_item_sk=i_item_sk - and ss_store_sk = s_store_sk - and d_month_seq between 1190 and 1190 + 11 - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy,s_store_id) - , - results_rollup as - (select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, s_store_id, sumsales - from results - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy - union all - select i_category, i_class, i_brand, i_product_name, d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year - union all - select i_category, i_class, i_brand, i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name - union all - select i_category, i_class, i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand - union all - select i_category, i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class - union all - select i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category - union all - select null i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results) - - select * -from (select i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rank() over (partition by i_category order by sumsales desc) rk - from results_rollup) dw2 -where rk <= 100 -order by i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rk -limit 100; - --- end template query67a.tpl query 31 in stream 9 --- start template query31.tpl query 32 in stream 9 -with /* TPC-DS query31.tpl 0.50 */ ss as - (select ca_county,d_qoy, d_year,sum(ss_ext_sales_price) as store_sales - from store_sales,date_dim,customer_address - where ss_sold_date_sk = d_date_sk - and ss_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year), - ws as - (select ca_county,d_qoy, d_year,sum(ws_ext_sales_price) as web_sales - from web_sales,date_dim,customer_address - where ws_sold_date_sk = d_date_sk - and ws_bill_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year) - select - ss1.ca_county - ,ss1.d_year - ,ws2.web_sales/ws1.web_sales web_q1_q2_increase - ,ss2.store_sales/ss1.store_sales store_q1_q2_increase - ,ws3.web_sales/ws2.web_sales web_q2_q3_increase - ,ss3.store_sales/ss2.store_sales store_q2_q3_increase - from - ss ss1 - ,ss ss2 - ,ss ss3 - ,ws ws1 - ,ws ws2 - ,ws ws3 - where - ss1.d_qoy = 1 - and ss1.d_year = 1998 - and ss1.ca_county = ss2.ca_county - and ss2.d_qoy = 2 - and ss2.d_year = 1998 - and ss2.ca_county = ss3.ca_county - and ss3.d_qoy = 3 - and ss3.d_year = 1998 - and ss1.ca_county = ws1.ca_county - and ws1.d_qoy = 1 - and ws1.d_year = 1998 - and ws1.ca_county = ws2.ca_county - and ws2.d_qoy = 2 - and ws2.d_year = 1998 - and ws1.ca_county = ws3.ca_county - and ws3.d_qoy = 3 - and ws3.d_year =1998 - and case when ws1.web_sales > 0 then ws2.web_sales/ws1.web_sales else null end - > case when ss1.store_sales > 0 then ss2.store_sales/ss1.store_sales else null end - and case when ws2.web_sales > 0 then ws3.web_sales/ws2.web_sales else null end - > case when ss2.store_sales > 0 then ss3.store_sales/ss2.store_sales else null end - order by store_q2_q3_increase; - --- end template query31.tpl query 32 in stream 9 --- start template query20.tpl query 33 in stream 9 -select /* TPC-DS query20.tpl 0.65 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(cs_ext_sales_price) as itemrevenue - ,sum(cs_ext_sales_price)*100/sum(sum(cs_ext_sales_price)) over - (partition by i_class) as revenueratio - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and i_category in ('Shoes', 'Music', 'Home') - and cs_sold_date_sk = d_date_sk - and d_date between cast('2002-05-16' as date) - and dateadd(day,30,cast('2002-05-16' as date)) - group by i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - order by i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query20.tpl query 33 in stream 9 --- start template query11.tpl query 34 in stream 9 -with /* TPC-DS query11.tpl 0.51 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ss_ext_list_price-ss_ext_discount_amt) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ws_ext_list_price-ws_ext_discount_amt) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_birth_country - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 1998 - and t_s_secyear.dyear = 1998+1 - and t_w_firstyear.dyear = 1998 - and t_w_secyear.dyear = 1998+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else 0.0 end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else 0.0 end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_birth_country -limit 100; - --- end template query11.tpl query 34 in stream 9 --- start template query77a.tpl query 35 in stream 9 -with /* TPC-DS query77a.tpl 0.78 */ ss as - (select s_store_sk, - sum(ss_ext_sales_price) as sales, - sum(ss_net_profit) as profit - from store_sales, - date_dim, - store - where ss_sold_date_sk = d_date_sk - and d_date between cast('1998-08-19' as date) - and dateadd(day,30,cast('1998-08-19' as date)) - and ss_store_sk = s_store_sk - group by s_store_sk) - , - sr as - (select s_store_sk, - sum(sr_return_amt) as returns, - sum(sr_net_loss) as profit_loss - from store_returns, - date_dim, - store - where sr_returned_date_sk = d_date_sk - and d_date between cast('1998-08-19' as date) - and dateadd(day,30,cast('1998-08-19' as date)) - and sr_store_sk = s_store_sk - group by s_store_sk), - cs as - (select cs_call_center_sk, - sum(cs_ext_sales_price) as sales, - sum(cs_net_profit) as profit - from catalog_sales, - date_dim - where cs_sold_date_sk = d_date_sk - and d_date between cast('1998-08-19' as date) - and dateadd(day,30,cast('1998-08-19' as date)) - group by cs_call_center_sk - ), - cr as - (select cr_call_center_sk, - sum(cr_return_amount) as returns, - sum(cr_net_loss) as profit_loss - from catalog_returns, - date_dim - where cr_returned_date_sk = d_date_sk - and d_date between cast('1998-08-19' as date) - and dateadd(day,30,cast('1998-08-19' as date)) - group by cr_call_center_sk), - ws as - ( select wp_web_page_sk, - sum(ws_ext_sales_price) as sales, - sum(ws_net_profit) as profit - from web_sales, - date_dim, - web_page - where ws_sold_date_sk = d_date_sk - and d_date between cast('1998-08-19' as date) - and dateadd(day,30,cast('1998-08-19' as date)) - and ws_web_page_sk = wp_web_page_sk - group by wp_web_page_sk), - wr as - (select wp_web_page_sk, - sum(wr_return_amt) as returns, - sum(wr_net_loss) as profit_loss - from web_returns, - date_dim, - web_page - where wr_returned_date_sk = d_date_sk - and d_date between cast('1998-08-19' as date) - and dateadd(day,30,cast('1998-08-19' as date)) - and wr_web_page_sk = wp_web_page_sk - group by wp_web_page_sk) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , ss.s_store_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ss left join sr - on ss.s_store_sk = sr.s_store_sk - union all - select 'catalog channel' as channel - , cs_call_center_sk as id - , sales - , returns - , (profit - profit_loss) as profit - from cs - , cr - union all - select 'web channel' as channel - , ws.wp_web_page_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ws left join wr - on ws.wp_web_page_sk = wr.wp_web_page_sk - ) x - group by channel, id ) - - select * - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results -) foo -order by channel, id - limit 100; - --- end template query77a.tpl query 35 in stream 9 --- start template query36a.tpl query 36 in stream 9 -with /* TPC-DS query36a.tpl 0.21 */ results as - (select - sum(ss_net_profit) as ss_net_profit, sum(ss_ext_sales_price) as ss_ext_sales_price, - sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin - ,i_category - ,i_class - ,0 as g_category, 0 as g_class - from - store_sales - ,date_dim d1 - ,item - ,store - where - d1.d_year = 1999 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and s_state in ('LA','OK','KS','SC', - 'NY','WA','AL','VT') - group by i_category,i_class) - , - results_rollup as - (select gross_margin ,i_category ,i_class,0 as t_category, 0 as t_class, 0 as lochierarchy from results - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - i_category, NULL AS i_class, 0 as t_category, 1 as t_class, 1 as lochierarchy from results group by i_category - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - NULL AS i_category ,NULL AS i_class, 1 as t_category, 1 as t_class, 2 as lochierarchy from results) - select - gross_margin ,i_category ,i_class, lochierarchy,rank() over ( - partition by lochierarchy, case when t_class = 0 then i_category end - order by gross_margin asc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then i_category end - ,rank_within_parent - limit 100; - --- end template query36a.tpl query 36 in stream 9 --- start template query82.tpl query 37 in stream 9 -select /* TPC-DS query82.tpl 0.67 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, store_sales - where i_current_price between 39 and 39+30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('2001-05-09' as date) and dateadd(day,60,cast('2001-05-09' as date)) - and i_manufact_id in (437,24,777,446) - and inv_quantity_on_hand between 100 and 500 - and ss_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query82.tpl query 37 in stream 9 --- start template query33.tpl query 38 in stream 9 -with /* TPC-DS query33.tpl 0.22 */ ss as ( - select - i_manufact_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Books')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 4 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_manufact_id), - cs as ( - select - i_manufact_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Books')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 4 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_manufact_id), - ws as ( - select - i_manufact_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Books')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 4 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_manufact_id) - select i_manufact_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_manufact_id - order by total_sales -limit 100; - --- end template query33.tpl query 38 in stream 9 --- start template query54.tpl query 39 in stream 9 -with /* TPC-DS query54.tpl 0.81 */ my_customers as ( - select distinct c_customer_sk - , c_current_addr_sk - from - ( select cs_sold_date_sk sold_date_sk, - cs_bill_customer_sk customer_sk, - cs_item_sk item_sk - from catalog_sales - union all - select ws_sold_date_sk sold_date_sk, - ws_bill_customer_sk customer_sk, - ws_item_sk item_sk - from web_sales - ) cs_or_ws_sales, - item, - date_dim, - customer - where sold_date_sk = d_date_sk - and item_sk = i_item_sk - and i_category = 'Women' - and i_class = 'dresses' - and c_customer_sk = cs_or_ws_sales.customer_sk - and d_moy = 6 - and d_year = 1999 - ) - , my_revenue as ( - select c_customer_sk, - sum(ss_ext_sales_price) as revenue - from my_customers, - store_sales, - customer_address, - store, - date_dim - where c_current_addr_sk = ca_address_sk - and ca_county = s_county - and ca_state = s_state - and ss_sold_date_sk = d_date_sk - and c_customer_sk = ss_customer_sk - and d_month_seq between (select distinct d_month_seq+1 - from date_dim where d_year = 1999 and d_moy = 6) - and (select distinct d_month_seq+3 - from date_dim where d_year = 1999 and d_moy = 6) - group by c_customer_sk - ) - , segments as - (select cast((revenue/50) as bigint) as segment - from my_revenue - ) - select segment, count(*) as num_customers, segment*50 as segment_base - from segments - group by segment - order by segment, num_customers - limit 100; - --- end template query54.tpl query 39 in stream 9 --- start template query4.tpl query 40 in stream 9 -with /* TPC-DS query4.tpl 0.93 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(((ss_ext_list_price-ss_ext_wholesale_cost-ss_ext_discount_amt)+ss_ext_sales_price)/2) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((cs_ext_list_price-cs_ext_wholesale_cost-cs_ext_discount_amt)+cs_ext_sales_price)/2) ) year_total - ,'c' sale_type - from customer - ,catalog_sales - ,date_dim - where c_customer_sk = cs_bill_customer_sk - and cs_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year -union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((ws_ext_list_price-ws_ext_wholesale_cost-ws_ext_discount_amt)+ws_ext_sales_price)/2) ) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_login - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_c_firstyear - ,year_total t_c_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_c_secyear.customer_id - and t_s_firstyear.customer_id = t_c_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_c_firstyear.sale_type = 'c' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_c_secyear.sale_type = 'c' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 1999 - and t_s_secyear.dyear = 1999+1 - and t_c_firstyear.dyear = 1999 - and t_c_secyear.dyear = 1999+1 - and t_w_firstyear.dyear = 1999 - and t_w_secyear.dyear = 1999+1 - and t_s_firstyear.year_total > 0 - and t_c_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_login -limit 100; - --- end template query4.tpl query 40 in stream 9 --- start template query16.tpl query 41 in stream 9 -select /* TPC-DS query16.tpl 0.25 */ - count(distinct cs_order_number) as "order count" - ,sum(cs_ext_ship_cost) as "total shipping cost" - ,sum(cs_net_profit) as "total net profit" -from - catalog_sales cs1 - ,date_dim - ,customer_address - ,call_center -where - d_date between '1999-5-01' and - dateadd(day, 60, cast('1999-5-01' as date)) -and cs1.cs_ship_date_sk = d_date_sk -and cs1.cs_ship_addr_sk = ca_address_sk -and ca_state = 'CA' -and cs1.cs_call_center_sk = cc_call_center_sk -and cc_county in ('San Miguel County','Gage County','Daviess County','Maverick County', - 'Williamson County' -) -and exists (select * - from catalog_sales cs2 - where cs1.cs_order_number = cs2.cs_order_number - and cs1.cs_warehouse_sk <> cs2.cs_warehouse_sk) -and not exists(select * - from catalog_returns cr1 - where cs1.cs_order_number = cr1.cr_order_number) -order by count(distinct cs_order_number) -limit 100; - --- end template query16.tpl query 41 in stream 9 --- start template query10.tpl query 42 in stream 9 -select /* TPC-DS query10.tpl 0.26 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3, - cd_dep_count, - count(*) cnt4, - cd_dep_employed_count, - count(*) cnt5, - cd_dep_college_count, - count(*) cnt6 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_county in ('New Hanover County','Humphreys County','Arenac County','Montour County','Mason County') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 1999 and - d_moy between 4 and 4+3) and - (exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 1999 and - d_moy between 4 ANd 4+3) or - exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 1999 and - d_moy between 4 and 4+3)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count -limit 100; - --- end template query10.tpl query 42 in stream 9 --- start template query18a.tpl query 43 in stream 9 -with /* TPC-DS query18a.tpl 0.90 */ results as - (select i_item_id, - ca_country, - ca_state, - ca_county, - cast(cs_quantity as decimal(12,2)) agg1, - cast(cs_list_price as decimal(12,2)) agg2, - cast(cs_coupon_amt as decimal(12,2)) agg3, - cast(cs_sales_price as decimal(12,2)) agg4, - cast(cs_net_profit as decimal(12,2)) agg5, - cast(c_birth_year as decimal(12,2)) agg6, - cast(cd1.cd_dep_count as decimal(12,2)) agg7 - from catalog_sales, customer_demographics cd1, customer_demographics cd2, customer, customer_address, date_dim, item - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd1.cd_demo_sk and - cs_bill_customer_sk = c_customer_sk and - cd1.cd_gender = 'M' and - cd1.cd_education_status = 'College' and - c_current_cdemo_sk = cd2.cd_demo_sk and - c_current_addr_sk = ca_address_sk and - c_birth_month in (1,7,2,11,10,9) and - d_year = 2001 and - ca_state in ('VA','TX','AK','AZ','TN','MI','OK') - ) - select i_item_id, ca_country, ca_state, ca_county, agg1, agg2, agg3, agg4, agg5, agg6, agg7 - from ( - select i_item_id, ca_country, ca_state, ca_county, avg(agg1) agg1, - avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state, ca_county - union all - select i_item_id, ca_country, ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state - union all - select i_item_id, ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country - union all - select i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - ) foo - order by ca_country, ca_state, ca_county, i_item_id - limit 100; - --- end template query18a.tpl query 43 in stream 9 --- start template query48.tpl query 44 in stream 9 -select /* TPC-DS query48.tpl 0.74 */ sum (ss_quantity) - from store_sales, store, customer_demographics, customer_address, date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2002 - and - ( - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'D' - and - cd_education_status = 'Primary' - and - ss_sales_price between 100.00 and 150.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'W' - and - cd_education_status = '4 yr Degree' - and - ss_sales_price between 50.00 and 100.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'S' - and - cd_education_status = 'Secondary' - and - ss_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('AL', 'TX', 'MT') - and ss_net_profit between 0 and 2000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('TN', 'ME', 'NJ') - and ss_net_profit between 150 and 3000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('NE', 'KS', 'AR') - and ss_net_profit between 50 and 25000 - ) - ) -; - --- end template query48.tpl query 44 in stream 9 --- start template query24.tpl query 45 in stream 9 -with /* TPC-DS query24.tpl 0.92 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_net_profit) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip -and s_market_id=5 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'violet' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; -with /* TPC-DS query24.tpl 0.92 part2 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_net_profit) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip - and s_market_id = 5 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'deep' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; - --- end template query24.tpl query 45 in stream 9 --- start template query30.tpl query 46 in stream 9 -with /* TPC-DS query30.tpl 0.75 */ customer_total_return as - (select wr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(wr_return_amt) as ctr_total_return - from web_returns - ,date_dim - ,customer_address - where wr_returned_date_sk = d_date_sk - and d_year =2000 - and wr_returning_addr_sk = ca_address_sk - group by wr_returning_customer_sk - ,ca_state) - select c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'ME' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return -limit 100; - --- end template query30.tpl query 46 in stream 9 --- start template query78.tpl query 47 in stream 9 -with /* TPC-DS query78.tpl 0.10 */ ws as - (select d_year AS ws_sold_year, ws_item_sk, - ws_bill_customer_sk ws_customer_sk, - sum(ws_quantity) ws_qty, - sum(ws_wholesale_cost) ws_wc, - sum(ws_sales_price) ws_sp - from web_sales - left join web_returns on wr_order_number=ws_order_number and ws_item_sk=wr_item_sk - join date_dim on ws_sold_date_sk = d_date_sk - where wr_order_number is null - group by d_year, ws_item_sk, ws_bill_customer_sk - ), -cs as - (select d_year AS cs_sold_year, cs_item_sk, - cs_bill_customer_sk cs_customer_sk, - sum(cs_quantity) cs_qty, - sum(cs_wholesale_cost) cs_wc, - sum(cs_sales_price) cs_sp - from catalog_sales - left join catalog_returns on cr_order_number=cs_order_number and cs_item_sk=cr_item_sk - join date_dim on cs_sold_date_sk = d_date_sk - where cr_order_number is null - group by d_year, cs_item_sk, cs_bill_customer_sk - ), -ss as - (select d_year AS ss_sold_year, ss_item_sk, - ss_customer_sk, - sum(ss_quantity) ss_qty, - sum(ss_wholesale_cost) ss_wc, - sum(ss_sales_price) ss_sp - from store_sales - left join store_returns on sr_ticket_number=ss_ticket_number and ss_item_sk=sr_item_sk - join date_dim on ss_sold_date_sk = d_date_sk - where sr_ticket_number is null - group by d_year, ss_item_sk, ss_customer_sk - ) - select -ss_sold_year, ss_item_sk, ss_customer_sk, -round(ss_qty/(coalesce(ws_qty,0)+coalesce(cs_qty,0)),2) ratio, -ss_qty store_qty, ss_wc store_wholesale_cost, ss_sp store_sales_price, -coalesce(ws_qty,0)+coalesce(cs_qty,0) other_chan_qty, -coalesce(ws_wc,0)+coalesce(cs_wc,0) other_chan_wholesale_cost, -coalesce(ws_sp,0)+coalesce(cs_sp,0) other_chan_sales_price -from ss -left join ws on (ws_sold_year=ss_sold_year and ws_item_sk=ss_item_sk and ws_customer_sk=ss_customer_sk) -left join cs on (cs_sold_year=ss_sold_year and cs_item_sk=ss_item_sk and cs_customer_sk=ss_customer_sk) -where (coalesce(ws_qty,0)>0 or coalesce(cs_qty, 0)>0) and ss_sold_year=2000 -order by - ss_sold_year, ss_item_sk, ss_customer_sk, - ss_qty desc, ss_wc desc, ss_sp desc, - other_chan_qty, - other_chan_wholesale_cost, - other_chan_sales_price, - ratio -limit 100; - --- end template query78.tpl query 47 in stream 9 --- start template query6.tpl query 48 in stream 9 -select /* TPC-DS query6.tpl 0.58 */ a.ca_state state, count(*) cnt - from customer_address a - ,customer c - ,store_sales s - ,date_dim d - ,item i - where a.ca_address_sk = c.c_current_addr_sk - and c.c_customer_sk = s.ss_customer_sk - and s.ss_sold_date_sk = d.d_date_sk - and s.ss_item_sk = i.i_item_sk - and d.d_month_seq = - (select distinct (d_month_seq) - from date_dim - where d_year = 2002 - and d_moy = 7 ) - and i.i_current_price > 1.2 * - (select avg(j.i_current_price) - from item j - where j.i_category = i.i_category) - group by a.ca_state - having count(*) >= 10 - order by cnt, a.ca_state - limit 100; - --- end template query6.tpl query 48 in stream 9 --- start template query80a.tpl query 49 in stream 9 -with /* TPC-DS query80a.tpl 0.6 */ ssr as - (select s_store_id as store_id, - sum(ss_ext_sales_price) as sales, - sum(coalesce(sr_return_amt, 0)) as returns, - sum(ss_net_profit - coalesce(sr_net_loss, 0)) as profit - from store_sales left outer join store_returns on - (ss_item_sk = sr_item_sk and ss_ticket_number = sr_ticket_number), - date_dim, - store, - item, - promotion - where ss_sold_date_sk = d_date_sk - and d_date between cast('1998-08-07' as date) - and dateadd(day,30,cast('1998-08-07' as date)) - and ss_store_sk = s_store_sk - and ss_item_sk = i_item_sk - and i_current_price > 50 - and ss_promo_sk = p_promo_sk - and p_channel_tv = 'N' - group by s_store_id) - , - csr as - (select cp_catalog_page_id as catalog_page_id, - sum(cs_ext_sales_price) as sales, - sum(coalesce(cr_return_amount, 0)) as returns, - sum(cs_net_profit - coalesce(cr_net_loss, 0)) as profit - from catalog_sales left outer join catalog_returns on - (cs_item_sk = cr_item_sk and cs_order_number = cr_order_number), - date_dim, - catalog_page, - item, - promotion - where cs_sold_date_sk = d_date_sk - and d_date between cast('1998-08-07' as date) - and dateadd(day,30,cast('1998-08-07' as date)) - and cs_catalog_page_sk = cp_catalog_page_sk - and cs_item_sk = i_item_sk - and i_current_price > 50 - and cs_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(ws_ext_sales_price) as sales, - sum(coalesce(wr_return_amt, 0)) as returns, - sum(ws_net_profit - coalesce(wr_net_loss, 0)) as profit - from web_sales left outer join web_returns on - (ws_item_sk = wr_item_sk and ws_order_number = wr_order_number), - date_dim, - web_site, - item, - promotion - where ws_sold_date_sk = d_date_sk - and d_date between cast('1998-08-07' as date) - and dateadd(day,30,cast('1998-08-07' as date)) - and ws_web_site_sk = web_site_sk - and ws_item_sk = i_item_sk - and i_current_price > 50 - and ws_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by web_site_id) -, -results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || store_id as id - , sales - , returns - , profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || catalog_page_id as id - , sales - , returns - , profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , profit - from wsr - ) x - group by channel, id) - - select channel - , id - , sales - , returns - , profit - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results - ) foo - order by channel, id - limit 100; - --- end template query80a.tpl query 49 in stream 9 --- start template query35a.tpl query 50 in stream 9 -select /* TPC-DS query35a.tpl 0.47 */ - ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - count(*) cnt1, - min(cd_dep_count), - max(cd_dep_count), - max(cd_dep_count), - cd_dep_employed_count, - count(*) cnt2, - min(cd_dep_employed_count), - max(cd_dep_employed_count), - max(cd_dep_employed_count), - cd_dep_college_count, - count(*) cnt3, - min(cd_dep_college_count), - max(cd_dep_college_count), - max(cd_dep_college_count) - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2001 and - d_qoy < 4) and - exists (select * from - (select ws_bill_customer_sk customsk - from web_sales,date_dim - where - ws_sold_date_sk = d_date_sk and - d_year = 2001 and - d_qoy < 4 - union all - select cs_ship_customer_sk customsk - from catalog_sales,date_dim - where - cs_sold_date_sk = d_date_sk and - d_year = 2001 and - d_qoy < 4)x - where x.customsk = c.c_customer_sk) - group by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - limit 100; - --- end template query35a.tpl query 50 in stream 9 --- start template query59.tpl query 51 in stream 9 -with /* TPC-DS query59.tpl 0.30 */ wss as - (select d_week_seq, - ss_store_sk, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - group by d_week_seq,ss_store_sk - ) - select s_store_name1,s_store_id1,d_week_seq1 - ,sun_sales1/sun_sales2,mon_sales1/mon_sales2 - ,tue_sales1/tue_sales2,wed_sales1/wed_sales2,thu_sales1/thu_sales2 - ,fri_sales1/fri_sales2,sat_sales1/sat_sales2 - from - (select s_store_name s_store_name1,wss.d_week_seq d_week_seq1 - ,s_store_id s_store_id1,sun_sales sun_sales1 - ,mon_sales mon_sales1,tue_sales tue_sales1 - ,wed_sales wed_sales1,thu_sales thu_sales1 - ,fri_sales fri_sales1,sat_sales sat_sales1 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1212 and 1212 + 11) y, - (select s_store_name s_store_name2,wss.d_week_seq d_week_seq2 - ,s_store_id s_store_id2,sun_sales sun_sales2 - ,mon_sales mon_sales2,tue_sales tue_sales2 - ,wed_sales wed_sales2,thu_sales thu_sales2 - ,fri_sales fri_sales2,sat_sales sat_sales2 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1212+ 12 and 1212 + 23) x - where s_store_id1=s_store_id2 - and d_week_seq1=d_week_seq2-52 - order by s_store_name1,s_store_id1,d_week_seq1 -limit 100; - --- end template query59.tpl query 51 in stream 9 --- start template query99.tpl query 52 in stream 9 -select /* TPC-DS query99.tpl 0.94 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 30) and - (cs_ship_date_sk - cs_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 60) and - (cs_ship_date_sk - cs_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 90) and - (cs_ship_date_sk - cs_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - catalog_sales - ,warehouse - ,ship_mode - ,call_center - ,date_dim -where - d_month_seq between 1180 and 1180 + 11 -and cs_ship_date_sk = d_date_sk -and cs_warehouse_sk = w_warehouse_sk -and cs_ship_mode_sk = sm_ship_mode_sk -and cs_call_center_sk = cc_call_center_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -limit 100; - --- end template query99.tpl query 52 in stream 9 --- start template query61.tpl query 53 in stream 9 -select /* TPC-DS query61.tpl 0.97 */ promotions,total,cast(promotions as decimal(15,4))/cast(total as decimal(15,4))*100 -from - (select sum(ss_ext_sales_price) promotions - from store_sales - ,store - ,promotion - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_promo_sk = p_promo_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -6 - and i_category = 'Sports' - and (p_channel_dmail = 'Y' or p_channel_email = 'Y' or p_channel_tv = 'Y') - and s_gmt_offset = -6 - and d_year = 2000 - and d_moy = 12) promotional_sales, - (select sum(ss_ext_sales_price) total - from store_sales - ,store - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -6 - and i_category = 'Sports' - and s_gmt_offset = -6 - and d_year = 2000 - and d_moy = 12) all_sales -order by promotions, total -limit 100; - --- end template query61.tpl query 53 in stream 9 --- start template query22a.tpl query 54 in stream 9 -with /* TPC-DS query22a.tpl 0.55 */ results as -(select i_product_name - ,i_brand - ,i_class - ,i_category - ,avg(inv_quantity_on_hand) qoh - from inventory - ,date_dim - ,item --- ,warehouse - where inv_date_sk=d_date_sk - and inv_item_sk=i_item_sk --- and inv_warehouse_sk = w_warehouse_sk - and d_month_seq between 1184 and 1184 + 11 - group by i_product_name,i_brand,i_class,i_category), -results_rollup as -(select i_product_name, i_brand, i_class, i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class,i_category -union all -select i_product_name, i_brand, i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class -union all -select i_product_name, i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand -union all -select i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name -union all -select null i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results) - select i_product_name, i_brand, i_class, i_category,qoh - from results_rollup - order by qoh, i_product_name, i_brand, i_class, i_category -limit 100; - --- end template query22a.tpl query 54 in stream 9 --- start template query71.tpl query 55 in stream 9 -select /* TPC-DS query71.tpl 0.72 */ i_brand_id brand_id, i_brand brand,t_hour,t_minute, - sum(ext_price) ext_price - from item, (select ws_ext_sales_price as ext_price, - ws_sold_date_sk as sold_date_sk, - ws_item_sk as sold_item_sk, - ws_sold_time_sk as time_sk - from web_sales,date_dim - where d_date_sk = ws_sold_date_sk - and d_moy=12 - and d_year=2000 - union all - select cs_ext_sales_price as ext_price, - cs_sold_date_sk as sold_date_sk, - cs_item_sk as sold_item_sk, - cs_sold_time_sk as time_sk - from catalog_sales,date_dim - where d_date_sk = cs_sold_date_sk - and d_moy=12 - and d_year=2000 - union all - select ss_ext_sales_price as ext_price, - ss_sold_date_sk as sold_date_sk, - ss_item_sk as sold_item_sk, - ss_sold_time_sk as time_sk - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - and d_moy=12 - and d_year=2000 - ) tmp,time_dim - where - sold_item_sk = i_item_sk - and i_manager_id=1 - and time_sk = t_time_sk - and (t_meal_time = 'breakfast' or t_meal_time = 'dinner') - group by i_brand, i_brand_id,t_hour,t_minute - order by ext_price desc, i_brand_id - ; - --- end template query71.tpl query 55 in stream 9 --- start template query68.tpl query 56 in stream 9 -select /* TPC-DS query68.tpl 0.95 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,extended_price - ,extended_tax - ,list_price - from (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_ext_sales_price) extended_price - ,sum(ss_ext_list_price) list_price - ,sum(ss_ext_tax) extended_tax - from store_sales - ,date_dim - ,store - ,household_demographics - ,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_dep_count = 7 or - household_demographics.hd_vehicle_count= 3) - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_city in ('Brownsville','Kingston') - group by ss_ticket_number - ,ss_customer_sk - ,ss_addr_sk,ca_city) dn - ,customer - ,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,ss_ticket_number - limit 100; - --- end template query68.tpl query 56 in stream 9 --- start template query40.tpl query 57 in stream 9 -select /* TPC-DS query40.tpl 0.86 */ - w_state - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('1999-04-29' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_before - ,sum(case when (cast(d_date as date) >= cast ('1999-04-29' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_after - from - catalog_sales left outer join catalog_returns on - (cs_order_number = cr_order_number - and cs_item_sk = cr_item_sk) - ,warehouse - ,item - ,date_dim - where - i_current_price between 0.99 and 1.49 - and i_item_sk = cs_item_sk - and cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('1999-04-29' as date)) - and dateadd(day,30,cast ('1999-04-29' as date)) - group by - w_state,i_item_id - order by w_state,i_item_id -limit 100; - --- end template query40.tpl query 57 in stream 9 --- start template query66.tpl query 58 in stream 9 -select /* TPC-DS query66.tpl 0.39 */ - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - ,sum(jan_sales) as jan_sales - ,sum(feb_sales) as feb_sales - ,sum(mar_sales) as mar_sales - ,sum(apr_sales) as apr_sales - ,sum(may_sales) as may_sales - ,sum(jun_sales) as jun_sales - ,sum(jul_sales) as jul_sales - ,sum(aug_sales) as aug_sales - ,sum(sep_sales) as sep_sales - ,sum(oct_sales) as oct_sales - ,sum(nov_sales) as nov_sales - ,sum(dec_sales) as dec_sales - ,sum(jan_sales/w_warehouse_sq_ft) as jan_sales_per_sq_foot - ,sum(feb_sales/w_warehouse_sq_ft) as feb_sales_per_sq_foot - ,sum(mar_sales/w_warehouse_sq_ft) as mar_sales_per_sq_foot - ,sum(apr_sales/w_warehouse_sq_ft) as apr_sales_per_sq_foot - ,sum(may_sales/w_warehouse_sq_ft) as may_sales_per_sq_foot - ,sum(jun_sales/w_warehouse_sq_ft) as jun_sales_per_sq_foot - ,sum(jul_sales/w_warehouse_sq_ft) as jul_sales_per_sq_foot - ,sum(aug_sales/w_warehouse_sq_ft) as aug_sales_per_sq_foot - ,sum(sep_sales/w_warehouse_sq_ft) as sep_sales_per_sq_foot - ,sum(oct_sales/w_warehouse_sq_ft) as oct_sales_per_sq_foot - ,sum(nov_sales/w_warehouse_sq_ft) as nov_sales_per_sq_foot - ,sum(dec_sales/w_warehouse_sq_ft) as dec_sales_per_sq_foot - ,sum(jan_net) as jan_net - ,sum(feb_net) as feb_net - ,sum(mar_net) as mar_net - ,sum(apr_net) as apr_net - ,sum(may_net) as may_net - ,sum(jun_net) as jun_net - ,sum(jul_net) as jul_net - ,sum(aug_net) as aug_net - ,sum(sep_net) as sep_net - ,sum(oct_net) as oct_net - ,sum(nov_net) as nov_net - ,sum(dec_net) as dec_net - from ( - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'GREAT EASTERN' || ',' || 'USPS' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then ws_ext_list_price* ws_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then ws_ext_list_price* ws_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then ws_ext_list_price* ws_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then ws_ext_list_price* ws_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then ws_ext_list_price* ws_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then ws_ext_list_price* ws_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then ws_ext_list_price* ws_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then ws_ext_list_price* ws_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then ws_ext_list_price* ws_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then ws_ext_list_price* ws_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then ws_ext_list_price* ws_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then ws_ext_list_price* ws_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as dec_net - from - web_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - ws_warehouse_sk = w_warehouse_sk - and ws_sold_date_sk = d_date_sk - and ws_sold_time_sk = t_time_sk - and ws_ship_mode_sk = sm_ship_mode_sk - and d_year = 2002 - and t_time between 46895 and 46895+28800 - and sm_carrier in ('GREAT EASTERN','USPS') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - union all - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'GREAT EASTERN' || ',' || 'USPS' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then cs_ext_sales_price* cs_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then cs_ext_sales_price* cs_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then cs_ext_sales_price* cs_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then cs_ext_sales_price* cs_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then cs_ext_sales_price* cs_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then cs_ext_sales_price* cs_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then cs_ext_sales_price* cs_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then cs_ext_sales_price* cs_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then cs_ext_sales_price* cs_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then cs_ext_sales_price* cs_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then cs_ext_sales_price* cs_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then cs_ext_sales_price* cs_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as dec_net - from - catalog_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and cs_sold_time_sk = t_time_sk - and cs_ship_mode_sk = sm_ship_mode_sk - and d_year = 2002 - and t_time between 46895 AND 46895+28800 - and sm_carrier in ('GREAT EASTERN','USPS') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - ) x - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - order by w_warehouse_name - limit 100; - --- end template query66.tpl query 58 in stream 9 --- start template query94.tpl query 59 in stream 9 -select /* TPC-DS query94.tpl 0.17 */ - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2001-2-01' and - dateadd(day,60,cast('2001-2-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'MO' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and exists (select * - from web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) -and not exists(select * - from web_returns wr1 - where ws1.ws_order_number = wr1.wr_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query94.tpl query 59 in stream 9 --- start template query47.tpl query 60 in stream 9 -with /* TPC-DS query47.tpl 0.42 */ v1 as( - select i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, - s_store_name, s_company_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - s_store_name, s_company_name - order by d_year, d_moy) rn - from item, store_sales, date_dim, store - where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - ( - d_year = 2000 or - ( d_year = 2000-1 and d_moy =12) or - ( d_year = 2000+1 and d_moy =1) - ) - group by i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy), - v2 as( - select v1.i_category, v1.i_brand, v1.s_store_name, v1.s_company_name - ,v1.d_year - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1.s_store_name = v1_lag.s_store_name and - v1.s_store_name = v1_lead.s_store_name and - v1.s_company_name = v1_lag.s_company_name and - v1.s_company_name = v1_lead.s_company_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 2000 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, nsum - limit 100; - --- end template query47.tpl query 60 in stream 9 --- start template query26.tpl query 61 in stream 9 -select /* TPC-DS query26.tpl 0.85 */ i_item_id, - avg(cs_quantity) agg1, - avg(cs_list_price) agg2, - avg(cs_coupon_amt) agg3, - avg(cs_sales_price) agg4 - from catalog_sales, customer_demographics, date_dim, item, promotion - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd_demo_sk and - cs_promo_sk = p_promo_sk and - cd_gender = 'M' and - cd_marital_status = 'U' and - cd_education_status = '4 yr Degree' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 2000 - group by i_item_id - order by i_item_id - limit 100; - --- end template query26.tpl query 61 in stream 9 --- start template query25.tpl query 62 in stream 9 -select /* TPC-DS query25.tpl 0.9 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,avg(ss_net_profit) as store_sales_profit - ,avg(sr_net_loss) as store_returns_loss - ,avg(cs_net_profit) as catalog_sales_profit - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 2001 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 10 - and d2.d_year = 2001 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_moy between 4 and 10 - and d3.d_year = 2001 - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query25.tpl query 62 in stream 9 --- start template query98.tpl query 63 in stream 9 -select /* TPC-DS query98.tpl 0.32 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ss_ext_sales_price) as itemrevenue - ,sum(ss_ext_sales_price)*100/sum(sum(ss_ext_sales_price)) over - (partition by i_class) as revenueratio -from - store_sales - ,item - ,date_dim -where - ss_item_sk = i_item_sk - and i_category in ('Shoes', 'Music', 'Women') - and ss_sold_date_sk = d_date_sk - and d_date between cast('2002-06-26' as date) - and dateadd(day,30,cast('2002-06-26' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio; - --- end template query98.tpl query 63 in stream 9 --- start template query70a.tpl query 64 in stream 9 -with /* TPC-DS query70a.tpl 0.34 */ results as -( select - sum(ss_net_profit) as total_sum ,s_state ,s_county, 0 as gstate, 0 as g_county - from - store_sales - ,date_dim d1 - ,store - where - d1.d_month_seq between 1214 and 1214 + 11 - and d1.d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - and s_state in - ( select s_state - from (select s_state as s_state, - rank() over ( partition by s_state order by sum(ss_net_profit) desc) as ranking - from store_sales, store, date_dim - where d_month_seq between 1214 and 1214 + 11 - and d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - group by s_state - ) tmp1 - where ranking <= 5) - group by s_state,s_county) , - results_rollup as -(select total_sum ,s_state ,s_county, 0 as g_state, 0 as g_county, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum,s_state, NULL as s_county, 0 as g_state, 1 as g_county, 1 as lochierarchy from results group by s_state - union - select sum(total_sum) as total_sum ,NULL as s_state ,NULL as s_county, 1 as g_state, 1 as g_county, 2 as lochierarchy from results) - select total_sum ,s_state ,s_county, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_county = 0 then s_state end - order by total_sum desc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then s_state end - ,rank_within_parent - limit 100; - --- end template query70a.tpl query 64 in stream 9 --- start template query73.tpl query 65 in stream 9 -select /* TPC-DS query73.tpl 0.79 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_buy_potential = '1001-5000' or - household_demographics.hd_buy_potential = '5001-10000') - and household_demographics.hd_vehicle_count > 0 - and case when household_demographics.hd_vehicle_count > 0 then - household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count else null end > 1 - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_county in ('Appomattox County','Harding County','Conecuh County','Hoke County') - group by ss_ticket_number,ss_customer_sk) dj,customer - where ss_customer_sk = c_customer_sk - and cnt between 1 and 5 - order by cnt desc, c_last_name asc; - --- end template query73.tpl query 65 in stream 9 --- start template query38.tpl query 66 in stream 9 -select /* TPC-DS query38.tpl 0.54 */ count(*) from ( - select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1214 and 1214 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1214 and 1214 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1214 and 1214 + 11 -) hot_cust -limit 100; - --- end template query38.tpl query 66 in stream 9 --- start template query87.tpl query 67 in stream 9 -select /* TPC-DS query87.tpl 0.77 */ count(*) -from ((select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1217 and 1217+11) - except - (select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1217 and 1217+11) - except - (select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1217 and 1217+11) -) cool_cust -; - --- end template query87.tpl query 67 in stream 9 --- start template query3.tpl query 68 in stream 9 -select /* TPC-DS query3.tpl 0.45 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_discount_amt) sum_agg - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manufact_id = 822 - and dt.d_moy=11 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,sum_agg desc - ,brand_id - limit 100; - --- end template query3.tpl query 68 in stream 9 --- start template query69.tpl query 69 in stream 9 -select /* TPC-DS query69.tpl 0.28 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_state in ('VA','NC','PA') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 1999 and - d_moy between 1 and 1+2) and - (not exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 1999 and - d_moy between 1 and 1+2) and - not exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 1999 and - d_moy between 1 and 1+2)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - limit 100; - --- end template query69.tpl query 69 in stream 9 --- start template query86a.tpl query 70 in stream 9 -with /* TPC-DS query86a.tpl 0.11 */ results as -( select sum(ws_net_paid) as total_sum, i_category, i_class, 0 as g_category, 0 as g_class - from - web_sales - ,date_dim d1 - ,item - where - d1.d_month_seq between 1215 and 1215+11 - and d1.d_date_sk = ws_sold_date_sk - and i_item_sk = ws_item_sk - group by i_category,i_class - ) , - - results_rollup as -( select total_sum ,i_category ,i_class, g_category, g_class, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum, i_category, NULL as i_class, 0 as g_category, 1 as g_class, 1 as lochierarchy from results group by i_category - union - select sum(total_sum) as total_sum, NULL as i_category, NULL as i_class, 1 as g_category, 1 as g_class, 2 as lochierarchy from results) - select - total_sum ,i_category ,i_class, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_class = 0 then i_category end - order by total_sum desc) as rank_within_parent - from - results_rollup - order by - lochierarchy desc, - case when lochierarchy = 0 then i_category end, - rank_within_parent - limit 100; - --- end template query86a.tpl query 70 in stream 9 --- start template query79.tpl query 71 in stream 9 -select /* TPC-DS query79.tpl 0.89 */ - c_last_name,c_first_name,substring(s_city,1,30),ss_ticket_number,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,store.s_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (household_demographics.hd_dep_count = 6 or household_demographics.hd_vehicle_count > 1) - and date_dim.d_dow = 1 - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_number_employees between 200 and 295 - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,store.s_city) ms,customer - where ss_customer_sk = c_customer_sk - order by c_last_name,c_first_name,substring(s_city,1,30), profit -limit 100; - --- end template query79.tpl query 71 in stream 9 --- start template query89.tpl query 72 in stream 9 -select /* TPC-DS query89.tpl 0.56 */ * -from( -select i_category, i_class, i_brand, - s_store_name, s_company_name, - d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, s_store_name, s_company_name) - avg_monthly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - d_year in (2002) and - ((i_category in ('Books','Men','Sports') and - i_class in ('mystery','pants','hockey') - ) - or (i_category in ('Electronics','Children','Jewelry') and - i_class in ('automotive','newborn','custom') - )) -group by i_category, i_class, i_brand, - s_store_name, s_company_name, d_moy) tmp1 -where case when (avg_monthly_sales <> 0) then (abs(sum_sales - avg_monthly_sales) / avg_monthly_sales) else null end > 0.1 -order by sum_sales - avg_monthly_sales, s_store_name -limit 100; - --- end template query89.tpl query 72 in stream 9 --- start template query51.tpl query 73 in stream 9 -WITH /* TPC-DS query51.tpl 0.46 */ web_v1 as ( -select - ws_item_sk item_sk, d_date, - sum(sum(ws_sales_price)) - over (partition by ws_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from web_sales - ,date_dim -where ws_sold_date_sk=d_date_sk - and d_month_seq between 1200 and 1200+11 - and ws_item_sk is not NULL -group by ws_item_sk, d_date), -store_v1 as ( -select - ss_item_sk item_sk, d_date, - sum(sum(ss_sales_price)) - over (partition by ss_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from store_sales - ,date_dim -where ss_sold_date_sk=d_date_sk - and d_month_seq between 1200 and 1200+11 - and ss_item_sk is not NULL -group by ss_item_sk, d_date) - select * -from (select item_sk - ,d_date - ,web_sales - ,store_sales - ,max(web_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) web_cumulative - ,max(store_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) store_cumulative - from (select case when web.item_sk is not null then web.item_sk else store.item_sk end item_sk - ,case when web.d_date is not null then web.d_date else store.d_date end d_date - ,web.cume_sales web_sales - ,store.cume_sales store_sales - from web_v1 web full outer join store_v1 store on (web.item_sk = store.item_sk - and web.d_date = store.d_date) - )x )y -where web_cumulative > store_cumulative -order by item_sk - ,d_date -limit 100; - --- end template query51.tpl query 73 in stream 9 --- start template query58.tpl query 74 in stream 9 -with /* TPC-DS query58.tpl 0.19 */ ss_items as - (select i_item_id item_id - ,sum(ss_ext_sales_price) ss_item_rev - from store_sales - ,item - ,date_dim - where ss_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '2002-01-14')) - and ss_sold_date_sk = d_date_sk - group by i_item_id), - cs_items as - (select i_item_id item_id - ,sum(cs_ext_sales_price) cs_item_rev - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '2002-01-14')) - and cs_sold_date_sk = d_date_sk - group by i_item_id), - ws_items as - (select i_item_id item_id - ,sum(ws_ext_sales_price) ws_item_rev - from web_sales - ,item - ,date_dim - where ws_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq =(select d_week_seq - from date_dim - where d_date = '2002-01-14')) - and ws_sold_date_sk = d_date_sk - group by i_item_id) - select ss_items.item_id - ,ss_item_rev - ,ss_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ss_dev - ,cs_item_rev - ,cs_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 cs_dev - ,ws_item_rev - ,ws_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ws_dev - ,(ss_item_rev+cs_item_rev+ws_item_rev)/3 average - from ss_items,cs_items,ws_items - where ss_items.item_id=cs_items.item_id - and ss_items.item_id=ws_items.item_id - and ss_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - and ss_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and cs_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and cs_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and ws_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and ws_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - order by item_id - ,ss_item_rev - limit 100; - --- end template query58.tpl query 74 in stream 9 --- start template query41.tpl query 75 in stream 9 -select /* TPC-DS query41.tpl 0.62 */ distinct(i_product_name) - from item i1 - where i_manufact_id between 949 and 949+40 - and (select count(*) as item_cnt - from item - where (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'rosy' or i_color = 'gainsboro') and - (i_units = 'Bundle' or i_units = 'Gross') and - (i_size = 'large' or i_size = 'medium') - ) or - (i_category = 'Women' and - (i_color = 'khaki' or i_color = 'drab') and - (i_units = 'Dozen' or i_units = 'Lb') and - (i_size = 'petite' or i_size = 'extra large') - ) or - (i_category = 'Men' and - (i_color = 'slate' or i_color = 'saddle') and - (i_units = 'Pound' or i_units = 'N/A') and - (i_size = 'economy' or i_size = 'N/A') - ) or - (i_category = 'Men' and - (i_color = 'pink' or i_color = 'green') and - (i_units = 'Bunch' or i_units = 'Ounce') and - (i_size = 'large' or i_size = 'medium') - ))) or - (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'moccasin' or i_color = 'lavender') and - (i_units = 'Each' or i_units = 'Unknown') and - (i_size = 'large' or i_size = 'medium') - ) or - (i_category = 'Women' and - (i_color = 'smoke' or i_color = 'light') and - (i_units = 'Oz' or i_units = 'Dram') and - (i_size = 'petite' or i_size = 'extra large') - ) or - (i_category = 'Men' and - (i_color = 'papaya' or i_color = 'ghost') and - (i_units = 'Ton' or i_units = 'Tbl') and - (i_size = 'economy' or i_size = 'N/A') - ) or - (i_category = 'Men' and - (i_color = 'goldenrod' or i_color = 'chiffon') and - (i_units = 'Gram' or i_units = 'Box') and - (i_size = 'large' or i_size = 'medium') - )))) > 0 - order by i_product_name - limit 100; - --- end template query41.tpl query 75 in stream 9 --- start template query19.tpl query 76 in stream 9 -select /* TPC-DS query19.tpl 0.8 */ i_brand_id brand_id, i_brand brand, i_manufact_id, i_manufact, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item,customer,customer_address,store - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=71 - and d_moy=11 - and d_year=2001 - and ss_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and substring(ca_zip,1,5) <> substring(s_zip,1,5) - and ss_store_sk = s_store_sk - group by i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact - order by ext_price desc - ,i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact -limit 100 ; - --- end template query19.tpl query 76 in stream 9 --- start template query83.tpl query 77 in stream 9 -with /* TPC-DS query83.tpl 0.96 */ sr_items as - (select i_item_id item_id, - sum(sr_return_quantity) sr_item_qty - from store_returns, - item, - date_dim - where sr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2002-03-28','2002-09-21','2002-11-21'))) - and sr_returned_date_sk = d_date_sk - group by i_item_id), - cr_items as - (select i_item_id item_id, - sum(cr_return_quantity) cr_item_qty - from catalog_returns, - item, - date_dim - where cr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2002-03-28','2002-09-21','2002-11-21'))) - and cr_returned_date_sk = d_date_sk - group by i_item_id), - wr_items as - (select i_item_id item_id, - sum(wr_return_quantity) wr_item_qty - from web_returns, - item, - date_dim - where wr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2002-03-28','2002-09-21','2002-11-21'))) - and wr_returned_date_sk = d_date_sk - group by i_item_id) - select sr_items.item_id - ,sr_item_qty - ,sr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 sr_dev - ,cr_item_qty - ,cr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 cr_dev - ,wr_item_qty - ,wr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 wr_dev - ,(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 average - from sr_items - ,cr_items - ,wr_items - where sr_items.item_id=cr_items.item_id - and sr_items.item_id=wr_items.item_id - order by sr_items.item_id - ,sr_item_qty - limit 100; - --- end template query83.tpl query 77 in stream 9 --- start template query96.tpl query 78 in stream 9 -select /* TPC-DS query96.tpl 0.1 */ count(*) -from store_sales - ,household_demographics - ,time_dim, store -where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and household_demographics.hd_dep_count = 4 - and store.s_store_name = 'ese' -order by count(*) -limit 100; - --- end template query96.tpl query 78 in stream 9 --- start template query46.tpl query 79 in stream 9 -select /* TPC-DS query46.tpl 0.23 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and (household_demographics.hd_dep_count = 4 or - household_demographics.hd_vehicle_count= 3) - and date_dim.d_dow in (6,0) - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_city in ('Grandview','Trenton','Ebenezer','Cottonwood','Five Forks') - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,ca_city) dn,customer,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - limit 100; - --- end template query46.tpl query 79 in stream 9 --- start template query53.tpl query 80 in stream 9 -select /* TPC-DS query53.tpl 0.88 */ * from -(select i_manufact_id, -sum(ss_sales_price) sum_sales, -avg(sum(ss_sales_price)) over (partition by i_manufact_id) avg_quarterly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and -ss_sold_date_sk = d_date_sk and -ss_store_sk = s_store_sk and -d_month_seq in (1182,1182+1,1182+2,1182+3,1182+4,1182+5,1182+6,1182+7,1182+8,1182+9,1182+10,1182+11) and -((i_category in ('Books','Children','Electronics') and -i_class in ('personal','portable','reference','self-help') and -i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) -or(i_category in ('Women','Music','Men') and -i_class in ('accessories','classical','fragrances','pants') and -i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manufact_id, d_qoy ) tmp1 -where case when avg_quarterly_sales > 0 - then abs (sum_sales - avg_quarterly_sales)/ avg_quarterly_sales - else null end > 0.1 -order by avg_quarterly_sales, - sum_sales, - i_manufact_id -limit 100; - --- end template query53.tpl query 80 in stream 9 --- start template query55.tpl query 81 in stream 9 -select /* TPC-DS query55.tpl 0.82 */ i_brand_id brand_id, i_brand brand, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=5 - and d_moy=11 - and d_year=1998 - group by i_brand, i_brand_id - order by ext_price desc, i_brand_id -limit 100 ; - --- end template query55.tpl query 81 in stream 9 --- start template query72.tpl query 82 in stream 9 -select /* TPC-DS query72.tpl 0.87 */ i_item_desc - ,w_warehouse_name - ,d1.d_week_seq - ,sum(case when p_promo_sk is null then 1 else 0 end) no_promo - ,sum(case when p_promo_sk is not null then 1 else 0 end) promo - ,count(*) total_cnt -from catalog_sales -join inventory on (cs_item_sk = inv_item_sk) -join warehouse on (w_warehouse_sk=inv_warehouse_sk) -join item on (i_item_sk = cs_item_sk) -join customer_demographics on (cs_bill_cdemo_sk = cd_demo_sk) -join household_demographics on (cs_bill_hdemo_sk = hd_demo_sk) -join date_dim d1 on (cs_sold_date_sk = d1.d_date_sk) -join date_dim d2 on (inv_date_sk = d2.d_date_sk) -join date_dim d3 on (cs_ship_date_sk = d3.d_date_sk) -left outer join promotion on (cs_promo_sk=p_promo_sk) -left outer join catalog_returns on (cr_item_sk = cs_item_sk and cr_order_number = cs_order_number) -where d1.d_week_seq = d2.d_week_seq - and inv_quantity_on_hand < cs_quantity - and d3.d_date > d1.d_date + 5 - and hd_buy_potential = '>10000' - and d1.d_year = 2000 - and cd_marital_status = 'M' -group by i_item_desc,w_warehouse_name,d1.d_week_seq -order by total_cnt desc, i_item_desc, w_warehouse_name, d_week_seq -limit 100; - --- end template query72.tpl query 82 in stream 9 --- start template query95.tpl query 83 in stream 9 -with /* TPC-DS query95.tpl 0.43 */ ws_wh as -(select ws1.ws_order_number,ws1.ws_warehouse_sk wh1,ws2.ws_warehouse_sk wh2 - from web_sales ws1,web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) - select - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2001-4-01' and - dateadd(day,60,cast('2001-4-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'MT' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and ws1.ws_order_number in (select ws_order_number - from ws_wh) -and ws1.ws_order_number in (select wr_order_number - from web_returns,ws_wh - where wr_order_number = ws_wh.ws_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query95.tpl query 83 in stream 9 --- start template query29.tpl query 84 in stream 9 -select /* TPC-DS query29.tpl 0.53 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,max(ss_quantity) as store_sales_quantity - ,max(sr_return_quantity) as store_returns_quantity - ,max(cs_quantity) as catalog_sales_quantity - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 2000 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 4 + 3 - and d2.d_year = 2000 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_year in (2000,2000+1,2000+2) - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query29.tpl query 84 in stream 9 --- start template query64.tpl query 85 in stream 9 -with /* TPC-DS query64.tpl 0.20 */ cs_ui as - (select cs_item_sk - ,sum(cs_ext_list_price) as sale,sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit) as refund - from catalog_sales - ,catalog_returns - where cs_item_sk = cr_item_sk - and cs_order_number = cr_order_number - group by cs_item_sk - having sum(cs_ext_list_price)>2*sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit)), -cross_sales as - (select i_product_name product_name - ,i_item_sk item_sk - ,s_store_name store_name - ,s_zip store_zip - ,ad1.ca_street_number b_street_number - ,ad1.ca_street_name b_street_name - ,ad1.ca_city b_city - ,ad1.ca_zip b_zip - ,ad2.ca_street_number c_street_number - ,ad2.ca_street_name c_street_name - ,ad2.ca_city c_city - ,ad2.ca_zip c_zip - ,d1.d_year as syear - ,d2.d_year as fsyear - ,d3.d_year s2year - ,count(*) cnt - ,sum(ss_wholesale_cost) s1 - ,sum(ss_list_price) s2 - ,sum(ss_coupon_amt) s3 - FROM store_sales - ,store_returns - ,cs_ui - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,customer - ,customer_demographics cd1 - ,customer_demographics cd2 - ,promotion - ,household_demographics hd1 - ,household_demographics hd2 - ,customer_address ad1 - ,customer_address ad2 - ,income_band ib1 - ,income_band ib2 - ,item - WHERE ss_store_sk = s_store_sk AND - ss_sold_date_sk = d1.d_date_sk AND - ss_customer_sk = c_customer_sk AND - ss_cdemo_sk= cd1.cd_demo_sk AND - ss_hdemo_sk = hd1.hd_demo_sk AND - ss_addr_sk = ad1.ca_address_sk and - ss_item_sk = i_item_sk and - ss_item_sk = sr_item_sk and - ss_ticket_number = sr_ticket_number and - ss_item_sk = cs_ui.cs_item_sk and - c_current_cdemo_sk = cd2.cd_demo_sk AND - c_current_hdemo_sk = hd2.hd_demo_sk AND - c_current_addr_sk = ad2.ca_address_sk and - c_first_sales_date_sk = d2.d_date_sk and - c_first_shipto_date_sk = d3.d_date_sk and - ss_promo_sk = p_promo_sk and - hd1.hd_income_band_sk = ib1.ib_income_band_sk and - hd2.hd_income_band_sk = ib2.ib_income_band_sk and - cd1.cd_marital_status <> cd2.cd_marital_status and - i_color in ('lawn','dim','thistle','firebrick','dodger','brown') and - i_current_price between 65 and 65 + 10 and - i_current_price between 65 + 1 and 65 + 15 -group by i_product_name - ,i_item_sk - ,s_store_name - ,s_zip - ,ad1.ca_street_number - ,ad1.ca_street_name - ,ad1.ca_city - ,ad1.ca_zip - ,ad2.ca_street_number - ,ad2.ca_street_name - ,ad2.ca_city - ,ad2.ca_zip - ,d1.d_year - ,d2.d_year - ,d3.d_year -) -select cs1.product_name - ,cs1.store_name - ,cs1.store_zip - ,cs1.b_street_number - ,cs1.b_street_name - ,cs1.b_city - ,cs1.b_zip - ,cs1.c_street_number - ,cs1.c_street_name - ,cs1.c_city - ,cs1.c_zip - ,cs1.syear - ,cs1.cnt - ,cs1.s1 as s11 - ,cs1.s2 as s21 - ,cs1.s3 as s31 - ,cs2.s1 as s12 - ,cs2.s2 as s22 - ,cs2.s3 as s32 - ,cs2.syear - ,cs2.cnt -from cross_sales cs1,cross_sales cs2 -where cs1.item_sk=cs2.item_sk and - cs1.syear = 2001 and - cs2.syear = 2001 + 1 and - cs2.cnt <= cs1.cnt and - cs1.store_name = cs2.store_name and - cs1.store_zip = cs2.store_zip -order by cs1.product_name - ,cs1.store_name - ,cs2.cnt - ,cs1.s1 - ,cs2.s1; - --- end template query64.tpl query 85 in stream 9 --- start template query93.tpl query 86 in stream 9 -select /* TPC-DS query93.tpl 0.52 */ ss_customer_sk - ,sum(act_sales) sumsales - from (select ss_item_sk - ,ss_ticket_number - ,ss_customer_sk - ,case when sr_return_quantity is not null then (ss_quantity-sr_return_quantity)*ss_sales_price - else (ss_quantity*ss_sales_price) end act_sales - from store_sales left outer join store_returns on (sr_item_sk = ss_item_sk - and sr_ticket_number = ss_ticket_number) - ,reason - where sr_reason_sk = r_reason_sk - and r_reason_desc = 'reason 62') t - group by ss_customer_sk - order by sumsales, ss_customer_sk -limit 100; - --- end template query93.tpl query 86 in stream 9 --- start template query56.tpl query 87 in stream 9 -with /* TPC-DS query56.tpl 0.83 */ ss as ( - select i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where i_item_id in (select - i_item_id -from item -where i_color in ('turquoise','salmon','drab')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 6 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -8 - group by i_item_id), - cs as ( - select i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('turquoise','salmon','drab')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 6 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -8 - group by i_item_id), - ws as ( - select i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('turquoise','salmon','drab')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 6 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -8 - group by i_item_id) - select i_item_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by total_sales, - i_item_id - limit 100; - --- end template query56.tpl query 87 in stream 9 --- start template query97.tpl query 88 in stream 9 -with /* TPC-DS query97.tpl 0.38 */ ssci as ( -select ss_customer_sk customer_sk - ,ss_item_sk item_sk -from store_sales,date_dim -where ss_sold_date_sk = d_date_sk - and d_month_seq between 1205 and 1205 + 11 -group by ss_customer_sk - ,ss_item_sk), -csci as( - select cs_bill_customer_sk customer_sk - ,cs_item_sk item_sk -from catalog_sales,date_dim -where cs_sold_date_sk = d_date_sk - and d_month_seq between 1205 and 1205 + 11 -group by cs_bill_customer_sk - ,cs_item_sk) - select sum(case when ssci.customer_sk is not null and csci.customer_sk is null then 1 else 0 end) store_only - ,sum(case when ssci.customer_sk is null and csci.customer_sk is not null then 1 else 0 end) catalog_only - ,sum(case when ssci.customer_sk is not null and csci.customer_sk is not null then 1 else 0 end) store_and_catalog -from ssci full outer join csci on (ssci.customer_sk=csci.customer_sk - and ssci.item_sk = csci.item_sk) -limit 100; - --- end template query97.tpl query 88 in stream 9 --- start template query23.tpl query 89 in stream 9 -with /* TPC-DS query23.tpl 0.68 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (2000,2000+1,2000+2,2000+3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (2000,2000+1,2000+2,2000+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * -from - max_store_sales)) - select sum(sales) - from (select cs_quantity*cs_list_price sales - from catalog_sales - ,date_dim - where d_year = 2000 - and d_moy = 3 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - union all - select ws_quantity*ws_list_price sales - from web_sales - ,date_dim - where d_year = 2000 - and d_moy = 3 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer)) - limit 100; -with /* TPC-DS query23.tpl 0.68 part2 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (2000,2000 + 1,2000 + 2,2000 + 3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (2000,2000+1,2000+2,2000+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * - from max_store_sales)) - select c_last_name,c_first_name,sales - from (select c_last_name,c_first_name,sum(cs_quantity*cs_list_price) sales - from catalog_sales - ,customer - ,date_dim - where d_year = 2000 - and d_moy = 3 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and cs_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name - union all - select c_last_name,c_first_name,sum(ws_quantity*ws_list_price) sales - from web_sales - ,customer - ,date_dim - where d_year = 2000 - and d_moy = 3 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and ws_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name) - order by c_last_name,c_first_name,sales - limit 100; - --- end template query23.tpl query 89 in stream 9 --- start template query44.tpl query 90 in stream 9 -select /* TPC-DS query44.tpl 0.4 */ asceding.rnk, i1.i_product_name best_performing, i2.i_product_name worst_performing -from(select * - from (select item_sk,rank() over (order by rank_col asc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 214 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 214 - and ss_customer_sk is null - group by ss_store_sk))V1)V11 - where rnk < 11) asceding, - (select * - from (select item_sk,rank() over (order by rank_col desc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 214 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 214 - and ss_customer_sk is null - group by ss_store_sk))V2)V21 - where rnk < 11) descending, -item i1, -item i2 -where asceding.rnk = descending.rnk - and i1.i_item_sk=asceding.item_sk - and i2.i_item_sk=descending.item_sk -order by asceding.rnk -limit 100; - --- end template query44.tpl query 90 in stream 9 --- start template query91.tpl query 91 in stream 9 -select /* TPC-DS query91.tpl 0.13 */ - cc_call_center_id Call_Center, - cc_name Call_Center_Name, - cc_manager Manager, - sum(cr_net_loss) Returns_Loss -from - call_center, - catalog_returns, - date_dim, - customer, - customer_address, - customer_demographics, - household_demographics -where - cr_call_center_sk = cc_call_center_sk -and cr_returned_date_sk = d_date_sk -and cr_returning_customer_sk= c_customer_sk -and cd_demo_sk = c_current_cdemo_sk -and hd_demo_sk = c_current_hdemo_sk -and ca_address_sk = c_current_addr_sk -and d_year = 2000 -and d_moy = 12 -and ( (cd_marital_status = 'M' and cd_education_status = 'Unknown') - or(cd_marital_status = 'W' and cd_education_status = 'Advanced Degree')) -and hd_buy_potential like '1001-5000%' -and ca_gmt_offset = -6 -group by cc_call_center_id,cc_name,cc_manager,cd_marital_status,cd_education_status -order by sum(cr_net_loss) desc; - --- end template query91.tpl query 91 in stream 9 --- start template query49.tpl query 92 in stream 9 -select /* TPC-DS query49.tpl 0.48 */ channel, item, return_ratio, return_rank, currency_rank from - (select - 'web' as channel - ,web.item - ,web.return_ratio - ,web.return_rank - ,web.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select ws.ws_item_sk as item - ,(cast(sum(coalesce(wr.wr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(wr.wr_return_amt,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - web_sales ws left outer join web_returns wr - on (ws.ws_order_number = wr.wr_order_number and - ws.ws_item_sk = wr.wr_item_sk) - ,date_dim - where - wr.wr_return_amt > 10000 - and ws.ws_net_profit > 1 - and ws.ws_net_paid > 0 - and ws.ws_quantity > 0 - and ws_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 12 - group by ws.ws_item_sk - ) in_web - ) web - where - ( - web.return_rank <= 10 - or - web.currency_rank <= 10 - ) - union - select - 'catalog' as channel - ,catalog.item - ,catalog.return_ratio - ,catalog.return_rank - ,catalog.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select - cs.cs_item_sk as item - ,(cast(sum(coalesce(cr.cr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(cr.cr_return_amount,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - catalog_sales cs left outer join catalog_returns cr - on (cs.cs_order_number = cr.cr_order_number and - cs.cs_item_sk = cr.cr_item_sk) - ,date_dim - where - cr.cr_return_amount > 10000 - and cs.cs_net_profit > 1 - and cs.cs_net_paid > 0 - and cs.cs_quantity > 0 - and cs_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 12 - group by cs.cs_item_sk - ) in_cat - ) catalog - where - ( - catalog.return_rank <= 10 - or - catalog.currency_rank <=10 - ) - union - select - 'store' as channel - ,store.item - ,store.return_ratio - ,store.return_rank - ,store.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select sts.ss_item_sk as item - ,(cast(sum(coalesce(sr.sr_return_quantity,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(sr.sr_return_amt,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - store_sales sts left outer join store_returns sr - on (sts.ss_ticket_number = sr.sr_ticket_number and sts.ss_item_sk = sr.sr_item_sk) - ,date_dim - where - sr.sr_return_amt > 10000 - and sts.ss_net_profit > 1 - and sts.ss_net_paid > 0 - and sts.ss_quantity > 0 - and ss_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 12 - group by sts.ss_item_sk - ) in_store - ) store - where ( - store.return_rank <= 10 - or - store.currency_rank <= 10 - ) - ) - order by 1,4,5,2 - limit 100; - --- end template query49.tpl query 92 in stream 9 --- start template query76.tpl query 93 in stream 9 -select /* TPC-DS query76.tpl 0.99 */ channel, col_name, d_year, d_qoy, i_category, COUNT(*) sales_cnt, SUM(ext_sales_price) sales_amt FROM ( - SELECT 'store' as channel, 'ss_addr_sk' col_name, d_year, d_qoy, i_category, ss_ext_sales_price ext_sales_price - FROM store_sales, item, date_dim - WHERE ss_addr_sk IS NULL - AND ss_sold_date_sk=d_date_sk - AND ss_item_sk=i_item_sk - UNION ALL - SELECT 'web' as channel, 'ws_ship_addr_sk' col_name, d_year, d_qoy, i_category, ws_ext_sales_price ext_sales_price - FROM web_sales, item, date_dim - WHERE ws_ship_addr_sk IS NULL - AND ws_sold_date_sk=d_date_sk - AND ws_item_sk=i_item_sk - UNION ALL - SELECT 'catalog' as channel, 'cs_ship_addr_sk' col_name, d_year, d_qoy, i_category, cs_ext_sales_price ext_sales_price - FROM catalog_sales, item, date_dim - WHERE cs_ship_addr_sk IS NULL - AND cs_sold_date_sk=d_date_sk - AND cs_item_sk=i_item_sk) foo -GROUP BY channel, col_name, d_year, d_qoy, i_category -ORDER BY channel, col_name, d_year, d_qoy, i_category -limit 100; - --- end template query76.tpl query 93 in stream 9 --- start template query63.tpl query 94 in stream 9 -select /* TPC-DS query63.tpl 0.27 */ * -from (select i_manager_id - ,sum(ss_sales_price) sum_sales - ,avg(sum(ss_sales_price)) over (partition by i_manager_id) avg_monthly_sales - from item - ,store_sales - ,date_dim - ,store - where ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and d_month_seq in (1190,1190+1,1190+2,1190+3,1190+4,1190+5,1190+6,1190+7,1190+8,1190+9,1190+10,1190+11) - and (( i_category in ('Books','Children','Electronics') - and i_class in ('personal','portable','reference','self-help') - and i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) - or( i_category in ('Women','Music','Men') - and i_class in ('accessories','classical','fragrances','pants') - and i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manager_id, d_moy) tmp1 -where case when avg_monthly_sales > 0 then abs (sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 -order by i_manager_id - ,avg_monthly_sales - ,sum_sales -limit 100; - --- end template query63.tpl query 94 in stream 9 --- start template query45.tpl query 95 in stream 9 -select /* TPC-DS query45.tpl 0.18 */ ca_zip, ca_city, sum(ws_sales_price) - from web_sales, customer, customer_address, date_dim, item - where ws_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ws_item_sk = i_item_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', '85392', '85460', '80348', '81792') - or - i_item_id in (select i_item_id - from item - where i_item_sk in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29) - ) - ) - and ws_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 1999 - group by ca_zip, ca_city - order by ca_zip, ca_city - limit 100; - --- end template query45.tpl query 95 in stream 9 --- start template query43.tpl query 96 in stream 9 -select /* TPC-DS query43.tpl 0.15 */ s_store_name, s_store_id, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from date_dim, store_sales, store - where d_date_sk = ss_sold_date_sk and - s_store_sk = ss_store_sk and - s_gmt_offset = -7 and - d_year = 1999 - group by s_store_name, s_store_id - order by s_store_name, s_store_id,sun_sales,mon_sales,tue_sales,wed_sales,thu_sales,fri_sales,sat_sales - limit 100; - --- end template query43.tpl query 96 in stream 9 --- start template query85.tpl query 97 in stream 9 -select /* TPC-DS query85.tpl 0.33 */ substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) - from web_sales, web_returns, web_page, customer_demographics cd1, - customer_demographics cd2, customer_address, date_dim, reason - where ws_web_page_sk = wp_web_page_sk - and ws_item_sk = wr_item_sk - and ws_order_number = wr_order_number - and ws_sold_date_sk = d_date_sk and d_year = 1998 - and cd1.cd_demo_sk = wr_refunded_cdemo_sk - and cd2.cd_demo_sk = wr_returning_cdemo_sk - and ca_address_sk = wr_refunded_addr_sk - and r_reason_sk = wr_reason_sk - and - ( - ( - cd1.cd_marital_status = 'S' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Unknown' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 100.00 and 150.00 - ) - or - ( - cd1.cd_marital_status = 'U' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = '4 yr Degree' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 50.00 and 100.00 - ) - or - ( - cd1.cd_marital_status = 'D' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = '2 yr Degree' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ca_country = 'United States' - and - ca_state in ('TN', 'WV', 'MI') - and ws_net_profit between 100 and 200 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('IL', 'GA', 'NE') - and ws_net_profit between 150 and 300 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('NJ', 'AR', 'MT') - and ws_net_profit between 50 and 250 - ) - ) -group by r_reason_desc -order by substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) -limit 100; - --- end template query85.tpl query 97 in stream 9 --- start template query37.tpl query 98 in stream 9 -select /* TPC-DS query37.tpl 0.31 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, catalog_sales - where i_current_price between 20 and 20 + 30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('2001-05-12' as date) and dateadd(day,60,cast('2001-05-12' as date)) - and i_manufact_id in (709,849,973,828) - and inv_quantity_on_hand between 100 and 500 - and cs_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query37.tpl query 98 in stream 9 --- start template query8.tpl query 99 in stream 9 -select /* TPC-DS query8.tpl 0.63 */ s_store_name - ,sum(ss_net_profit) - from store_sales - ,date_dim - ,store, - (select ca_zip - from ( - SELECT substring(ca_zip,1,5) ca_zip - FROM customer_address - WHERE substring(ca_zip,1,5) IN ( - '79533','10859','82317','81779','62397','25353', - '97401','29646','22682','50414','43960', - '70278','20279','46337','25274','61365', - '70626','84760','60251','52099','49818', - '78207','77784','28067','62406','21790', - '60558','32755','31869','80459','79663', - '11446','16113','26202','23018','57111', - '54741','18148','89094','75371','13258', - '42014','27650','14633','71588','63544', - '58310','59073','18848','43925','49136', - '16819','94318','77343','88954','66040', - '27952','26694','39101','90144','47759', - '95791','29460','26984','24009','30486', - '64301','79353','87539','46820','39689', - '31399','24699','28790','63005','90369', - '88809','23448','40225','96838','43837', - '14350','74785','77830','59765','73191', - '91705','34648','92883','87290','31657', - '49938','96489','82242','53331','89796', - '74830','36701','30344','32260','61744', - '16804','72273','13623','17722','98012', - '62629','41243','97116','40790','57724', - '30506','12583','70380','80026','45301', - '60452','72870','16080','74519','72473', - '49753','87615','98802','77772','72469', - '27327','92506','31436','25917','32941', - '99187','27833','29071','44927','28517', - '26335','44042','12903','76086','20988', - '12878','12554','28311','11630','67931', - '27921','76019','27565','50010','64069', - '55182','72004','41274','42891','75735', - '17556','20012','37861','26473','37176', - '58088','92116','27182','77005','92234', - '19637','90851','86146','30470','14852', - '90963','70611','55907','56402','94565', - '82050','57110','24408','92877','82647', - '63474','36535','93714','76398','84064', - '78285','63650','27559','23224','46367', - '81343','53264','42177','35129','16122', - '71953','53758','22302','31011','35915', - '82611','69908','18539','13416','80351', - '50843','34089','86924','37360','32462', - '14816','46416','85758','35390','69082', - '50101','38375','97204','66627','56887', - '93147','15717','55397','34092','52937', - '43556','93854','99670','33145','69826', - '64511','39514','44603','72700','50531', - '31201','25434','41993','17973','55541', - '81024','40928','57806','43014','89411', - '92604','96513','37677','77554','76400', - '15087','23811','19367','71584','89074', - '67115','29823','73105','91932','46285', - '71416','58161','27314','69369','96597', - '60036','14141','61464','31773','94806', - '59303','52576','19319','27893','32206', - '26254','86219','53361','20794','47993', - '86182','10740','57118','36874','37567', - '13486','37332','57217','71706','33436', - '88099','89769','27381','11070','74570', - '35057','11612','93127','16401','21487', - '27601','24398','40372','15994','79564', - '53952','67266','66707','12646','70645', - '48024','86291','26544','56774','54639', - '50216','40880','99297','80966','51947', - '16362','62315','93204','92530','14880', - '39998','61483','24511','26344','84686', - '70374','25478','96340','11884','33603', - '67141','27586','48188','69812','44455', - '38964','25007','75257','46032','92458', - '79537','81090','16461','45133','47653', - '35268','78600','84504','43963','85093', - '47585','45924','88052','26346','60406', - '24174','61807','32181','73260','46068', - '66461','72113','77433','44391','27400', - '23510','64176','79983','93133','41465', - '89125','92079','37968','45343','40673', - '35778','28742','85570','15882','69183', - '50607','13371','34462','14796','97483', - '36982','94154','21678','34396','21828', - '67993','50844','67841','15392') - intersect - select ca_zip - from (SELECT substring(ca_zip,1,5) ca_zip,count(*) cnt - FROM customer_address, customer - WHERE ca_address_sk = c_current_addr_sk and - c_preferred_cust_flag='Y' - group by ca_zip - having count(*) > 10)A1)A2) V1 - where ss_store_sk = s_store_sk - and ss_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 2001 - and (substring(s_zip,1,2) = substring(V1.ca_zip,1,2)) - group by s_store_name - order by s_store_name - limit 100; - --- end template query8.tpl query 99 in stream 9 diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/3TB/queries/query_0.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/3TB/queries/query_0.sql index 7757eddc..a749e983 100644 --- a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/3TB/queries/query_0.sql +++ b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/3TB/queries/query_0.sql @@ -194,8 +194,8 @@ order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov ; -- end template query39.tpl query 5 in stream 0 --- start template query80a.tpl query 6 in stream 0 -with /* TPC-DS query80a.tpl 0.6 */ ssr as +-- start template query80.tpl query 6 in stream 0 +with /* TPC-DS query80.tpl 0.6 */ ssr as (select s_store_id as store_id, sum(ss_ext_sales_price) as sales, sum(coalesce(sr_return_amt, 0)) as returns, @@ -207,8 +207,8 @@ with /* TPC-DS query80a.tpl 0.6 */ ssr as item, promotion where ss_sold_date_sk = d_date_sk - and d_date between cast('2002-08-04' as date) - and dateadd(day,30,cast('2002-08-04' as date)) + and d_date between cast('2002-08-04' as date) + and dateadd(day,30,cast('2002-08-04' as date)) and ss_store_sk = s_store_sk and ss_item_sk = i_item_sk and i_current_price > 50 @@ -257,14 +257,12 @@ group by cp_catalog_page_id) and ws_promo_sk = p_promo_sk and p_channel_tv = 'N' group by web_site_id) -, -results as - (select channel + select channel , id , sum(sales) as sales , sum(returns) as returns , sum(profit) as profit - from + from (select 'store channel' as channel , 'store' || store_id as id , sales @@ -286,24 +284,12 @@ results as , profit from wsr ) x - group by channel, id) - - select channel - , id - , sales - , returns - , profit - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results - ) foo - order by channel, id + group by rollup (channel, id) + order by channel + ,id limit 100; --- end template query80a.tpl query 6 in stream 0 +-- end template query80.tpl query 6 in stream 0 -- start template query32.tpl query 7 in stream 0 select /* TPC-DS query32.tpl 0.7 */ sum(cs_ext_discount_amt) as "excess discount amount" from @@ -463,9 +449,16 @@ order by limit 100; -- end template query78.tpl query 10 in stream 0 --- start template query86a.tpl query 11 in stream 0 -with /* TPC-DS query86a.tpl 0.11 */ results as -( select sum(ws_net_paid) as total_sum, i_category, i_class, 0 as g_category, 0 as g_class +-- start template query86.tpl query 11 in stream 0 +select /* TPC-DS query86.tpl 0.11 */ + sum(ws_net_paid) as total_sum + ,i_category + ,i_class + ,grouping(i_category)+grouping(i_class) as lochierarchy + ,rank() over ( + partition by grouping(i_category)+grouping(i_class), + case when grouping(i_class) = 0 then i_category end + order by sum(ws_net_paid) desc) as rank_within_parent from web_sales ,date_dim d1 @@ -474,30 +467,14 @@ with /* TPC-DS query86a.tpl 0.11 */ results as d1.d_month_seq between 1205 and 1205+11 and d1.d_date_sk = ws_sold_date_sk and i_item_sk = ws_item_sk - group by i_category,i_class - ) , - - results_rollup as -( select total_sum ,i_category ,i_class, g_category, g_class, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum, i_category, NULL as i_class, 0 as g_category, 1 as g_class, 1 as lochierarchy from results group by i_category - union - select sum(total_sum) as total_sum, NULL as i_category, NULL as i_class, 1 as g_category, 1 as g_class, 2 as lochierarchy from results) - select - total_sum ,i_category ,i_class, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_class = 0 then i_category end - order by total_sum desc) as rank_within_parent - from - results_rollup + group by rollup(i_category,i_class) order by lochierarchy desc, - case when lochierarchy = 0 then i_category end, - rank_within_parent + case when grouping(i_category)+grouping(i_class) = 0 then i_category end, + rank_within_parent limit 100; --- end template query86a.tpl query 11 in stream 0 +-- end template query86.tpl query 11 in stream 0 -- start template query1.tpl query 12 in stream 0 with /* TPC-DS query1.tpl 0.12 */ customer_total_return as (select sr_customer_sk as ctr_customer_sk @@ -603,14 +580,13 @@ select /* TPC-DS query43.tpl 0.15 */ s_store_name, s_store_id, limit 100; -- end template query43.tpl query 15 in stream 0 --- start template query27a.tpl query 16 in stream 0 -with /* TPC-DS query27a.tpl 0.16 */ results as - (select i_item_id, - s_state, 0 as g_state, - ss_quantity agg1, - ss_list_price agg2, - ss_coupon_amt agg3, - ss_sales_price agg4 +-- start template query27.tpl query 16 in stream 0 +select /* TPC-DS query27.tpl 0.16 */ i_item_id, + s_state, grouping(s_state) g_state, + avg(ss_quantity) agg1, + avg(ss_list_price) agg2, + avg(ss_coupon_amt) agg3, + avg(ss_sales_price) agg4 from store_sales, customer_demographics, date_dim, store, item where ss_sold_date_sk = d_date_sk and ss_item_sk = i_item_sk and @@ -621,25 +597,12 @@ with /* TPC-DS query27a.tpl 0.16 */ results as cd_education_status = 'Advanced Degree' and d_year = 1999 and s_state in ('TX','MI', 'IL', 'MN', 'NM', 'SD') - ) - - select i_item_id, - s_state, g_state, agg1, agg2, agg3, agg4 - from ( - select i_item_id, s_state, 0 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4 from results - group by i_item_id, s_state - union all - select i_item_id, NULL AS s_state, 1 AS g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as s_state, 1 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - ) foo - order by i_item_id, s_state + group by rollup (i_item_id, s_state) + order by i_item_id + ,s_state limit 100; --- end template query27a.tpl query 16 in stream 0 +-- end template query27.tpl query 16 in stream 0 -- start template query94.tpl query 17 in stream 0 select /* TPC-DS query94.tpl 0.17 */ count(distinct ws_order_number) as "order count" @@ -875,48 +838,36 @@ order by cs1.product_name ,cs2.s1; -- end template query64.tpl query 20 in stream 0 --- start template query36a.tpl query 21 in stream 0 -with /* TPC-DS query36a.tpl 0.21 */ results as - (select - sum(ss_net_profit) as ss_net_profit, sum(ss_ext_sales_price) as ss_ext_sales_price, +-- start template query36.tpl query 21 in stream 0 +select /* TPC-DS query36.tpl 0.21 */ sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin ,i_category ,i_class - ,0 as g_category, 0 as g_class + ,grouping(i_category)+grouping(i_class) as lochierarchy + ,rank() over ( + partition by grouping(i_category)+grouping(i_class), + case when grouping(i_class) = 0 then i_category end + order by sum(ss_net_profit)/sum(ss_ext_sales_price) asc) as rank_within_parent from store_sales ,date_dim d1 ,item ,store where - d1.d_year = 2002 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and s_state in ('MN','TN','MI','WV', + d1.d_year = 2002 + and d1.d_date_sk = ss_sold_date_sk + and i_item_sk = ss_item_sk + and s_store_sk = ss_store_sk + and s_state in ('MN','TN','MI','WV', 'NC','GA','TN','OH') - group by i_category,i_class) - , - results_rollup as - (select gross_margin ,i_category ,i_class,0 as t_category, 0 as t_class, 0 as lochierarchy from results - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - i_category, NULL AS i_class, 0 as t_category, 1 as t_class, 1 as lochierarchy from results group by i_category - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - NULL AS i_category ,NULL AS i_class, 1 as t_category, 1 as t_class, 2 as lochierarchy from results) - select - gross_margin ,i_category ,i_class, lochierarchy,rank() over ( - partition by lochierarchy, case when t_class = 0 then i_category end - order by gross_margin asc) as rank_within_parent - from results_rollup + group by rollup(i_category,i_class) order by lochierarchy desc - ,case when lochierarchy = 0 then i_category end + ,case when grouping(i_category)+grouping(i_class) = 0 then i_category end ,rank_within_parent limit 100; --- end template query36a.tpl query 21 in stream 0 +-- end template query36.tpl query 21 in stream 0 -- start template query33.tpl query 22 in stream 0 with /* TPC-DS query33.tpl 0.22 */ ss as ( select @@ -1484,96 +1435,46 @@ order by substring(r_reason_desc,1,20) limit 100; -- end template query85.tpl query 33 in stream 0 --- start template query70a.tpl query 34 in stream 0 -with /* TPC-DS query70a.tpl 0.34 */ results as -( select - sum(ss_net_profit) as total_sum ,s_state ,s_county, 0 as gstate, 0 as g_county +-- start template query70.tpl query 34 in stream 0 +select /* TPC-DS query70.tpl 0.34 */ + sum(ss_net_profit) as total_sum + ,s_state + ,s_county + ,grouping(s_state)+grouping(s_county) as lochierarchy + ,rank() over ( + partition by grouping(s_state)+grouping(s_county), + case when grouping(s_county) = 0 then s_state end + order by sum(ss_net_profit) desc) as rank_within_parent from store_sales - ,date_dim d1 - ,store + ,date_dim d1 + ,store where - d1.d_month_seq between 1188 and 1188 + 11 + d1.d_month_seq between 1188 and 1188+11 and d1.d_date_sk = ss_sold_date_sk and s_store_sk = ss_store_sk and s_state in - ( select s_state - from (select s_state as s_state, - rank() over ( partition by s_state order by sum(ss_net_profit) desc) as ranking - from store_sales, store, date_dim - where d_month_seq between 1188 and 1188 + 11 - and d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk + ( select s_state + from (select s_state as s_state, + rank() over ( partition by s_state order by sum(ss_net_profit) desc) as ranking + from store_sales, store, date_dim + where d_month_seq between 1188 and 1188+11 + and d_date_sk = ss_sold_date_sk + and s_store_sk = ss_store_sk group by s_state - ) tmp1 - where ranking <= 5) - group by s_state,s_county) , - results_rollup as -(select total_sum ,s_state ,s_county, 0 as g_state, 0 as g_county, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum,s_state, NULL as s_county, 0 as g_state, 1 as g_county, 1 as lochierarchy from results group by s_state - union - select sum(total_sum) as total_sum ,NULL as s_state ,NULL as s_county, 1 as g_state, 1 as g_county, 2 as lochierarchy from results) - select total_sum ,s_state ,s_county, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_county = 0 then s_state end - order by total_sum desc) as rank_within_parent - from results_rollup + ) tmp1 + where ranking <= 5 + ) + group by rollup(s_state,s_county) order by - lochierarchy desc - ,case when lochierarchy = 0 then s_state end + lochierarchy desc + ,case when grouping(s_state)+grouping(s_county) = 0 then s_state end ,rank_within_parent limit 100; --- end template query70a.tpl query 34 in stream 0 --- start template query67a.tpl query 35 in stream 0 -with /* TPC-DS query67a.tpl 0.35 */ results as -( select i_category ,i_class ,i_brand ,i_product_name ,d_year ,d_qoy ,d_moy ,s_store_id - ,sum(coalesce(ss_sales_price*ss_quantity,0)) sumsales - from store_sales ,date_dim ,store ,item - where ss_sold_date_sk=d_date_sk - and ss_item_sk=i_item_sk - and ss_store_sk = s_store_sk - and d_month_seq between 1219 and 1219 + 11 - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy,s_store_id) - , - results_rollup as - (select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, s_store_id, sumsales - from results - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy - union all - select i_category, i_class, i_brand, i_product_name, d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year - union all - select i_category, i_class, i_brand, i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name - union all - select i_category, i_class, i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand - union all - select i_category, i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class - union all - select i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category - union all - select null i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results) - - select * +-- end template query70.tpl query 34 in stream 0 +-- start template query67.tpl query 35 in stream 0 +select /* TPC-DS query67.tpl 0.35 */ * from (select i_category ,i_class ,i_brand @@ -1584,7 +1485,24 @@ from (select i_category ,s_store_id ,sumsales ,rank() over (partition by i_category order by sumsales desc) rk - from results_rollup) dw2 + from (select i_category + ,i_class + ,i_brand + ,i_product_name + ,d_year + ,d_qoy + ,d_moy + ,s_store_id + ,sum(coalesce(ss_sales_price*ss_quantity,0)) sumsales + from store_sales + ,date_dim + ,store + ,item + where ss_sold_date_sk=d_date_sk + and ss_item_sk=i_item_sk + and ss_store_sk = s_store_sk + and d_month_seq between 1219 and 1219+11 + group by rollup(i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy,s_store_id))dw1) dw2 where rk <= 100 order by i_category ,i_class @@ -1598,7 +1516,7 @@ order by i_category ,rk limit 100; --- end template query67a.tpl query 35 in stream 0 +-- end template query67.tpl query 35 in stream 0 -- start template query28.tpl query 36 in stream 0 select /* TPC-DS query28.tpl 0.36 */ * from (select avg(ss_list_price) B1_LP @@ -2174,8 +2092,8 @@ order by item_sk limit 100; -- end template query51.tpl query 46 in stream 0 --- start template query35a.tpl query 47 in stream 0 -select /* TPC-DS query35a.tpl 0.47 */ +-- start template query35.tpl query 47 in stream 0 +select /* TPC-DS query35.tpl 0.47 */ ca_state, cd_gender, cd_marital_status, @@ -2198,28 +2116,25 @@ select /* TPC-DS query35a.tpl 0.47 */ customer c,customer_address ca,customer_demographics where c.c_current_addr_sk = ca.ca_address_sk and - cd_demo_sk = c.c_current_cdemo_sk and + cd_demo_sk = c.c_current_cdemo_sk and exists (select * from store_sales,date_dim where c.c_customer_sk = ss_customer_sk and ss_sold_date_sk = d_date_sk and d_year = 1999 and d_qoy < 4) and - exists (select * from - (select ws_bill_customer_sk customsk + (exists (select * from web_sales,date_dim - where + where c.c_customer_sk = ws_bill_customer_sk and ws_sold_date_sk = d_date_sk and d_year = 1999 and - d_qoy < 4 - union all - select cs_ship_customer_sk customsk + d_qoy < 4) or + exists (select * from catalog_sales,date_dim - where + where c.c_customer_sk = cs_ship_customer_sk and cs_sold_date_sk = d_date_sk and d_year = 1999 and - d_qoy < 4)x - where x.customsk = c.c_customer_sk) + d_qoy < 4)) group by ca_state, cd_gender, cd_marital_status, @@ -2234,7 +2149,7 @@ select /* TPC-DS query35a.tpl 0.47 */ cd_dep_college_count limit 100; --- end template query35a.tpl query 47 in stream 0 +-- end template query35.tpl query 47 in stream 0 -- start template query49.tpl query 48 in stream 0 select /* TPC-DS query49.tpl 0.48 */ channel, item, return_ratio, return_rank, currency_rank from (select @@ -2636,9 +2551,8 @@ select /* TPC-DS query38.tpl 0.54 */ count(*) from ( limit 100; -- end template query38.tpl query 54 in stream 0 --- start template query22a.tpl query 55 in stream 0 -with /* TPC-DS query22a.tpl 0.55 */ results as -(select i_product_name +-- start template query22.tpl query 55 in stream 0 +select /* TPC-DS query22.tpl 0.55 */ i_product_name ,i_brand ,i_class ,i_category @@ -2646,37 +2560,17 @@ with /* TPC-DS query22a.tpl 0.55 */ results as from inventory ,date_dim ,item --- ,warehouse - where inv_date_sk=d_date_sk + where inv_date_sk=d_date_sk and inv_item_sk=i_item_sk --- and inv_warehouse_sk = w_warehouse_sk and d_month_seq between 1183 and 1183 + 11 - group by i_product_name,i_brand,i_class,i_category), -results_rollup as -(select i_product_name, i_brand, i_class, i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class,i_category -union all -select i_product_name, i_brand, i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class -union all -select i_product_name, i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand -union all -select i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name -union all -select null i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results) - select i_product_name, i_brand, i_class, i_category,qoh - from results_rollup - order by qoh, i_product_name, i_brand, i_class, i_category + group by rollup(i_product_name + ,i_brand + ,i_class + ,i_category) +order by qoh, i_product_name, i_brand, i_class, i_category limit 100; --- end template query22a.tpl query 55 in stream 0 +-- end template query22.tpl query 55 in stream 0 -- start template query89.tpl query 56 in stream 0 select /* TPC-DS query89.tpl 0.56 */ * from( @@ -3296,8 +3190,8 @@ with /* TPC-DS query23.tpl 0.68 part2 */ frequent_ss_items as limit 100; -- end template query23.tpl query 68 in stream 0 --- start template query14a.tpl query 69 in stream 0 -with /* TPC-DS query14a.tpl 0.69 */ cross_items as +-- start template query14.tpl query 69 in stream 0 +with /* TPC-DS query14.tpl 0.69 */ cross_items as (select i_item_sk ss_item_sk from item, (select iss.i_brand_id brand_id @@ -3309,7 +3203,7 @@ with /* TPC-DS query14a.tpl 0.69 */ cross_items as where ss_item_sk = iss.i_item_sk and ss_sold_date_sk = d1.d_date_sk and d1.d_year between 1999 AND 1999 + 2 - intersect + intersect select ics.i_brand_id ,ics.i_class_id ,ics.i_category_id @@ -3328,7 +3222,7 @@ with /* TPC-DS query14a.tpl 0.69 */ cross_items as ,date_dim d3 where ws_item_sk = iws.i_item_sk and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1999 AND 1999 + 2) x + and d3.d_year between 1999 AND 1999 + 2) where i_brand_id = brand_id and i_class_id = class_id and i_category_id = category_id @@ -3340,14 +3234,14 @@ with /* TPC-DS query14a.tpl 0.69 */ cross_items as from store_sales ,date_dim where ss_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select cs_quantity quantity + and d_year between 1999 and 1999 + 2 + union all + select cs_quantity quantity ,cs_list_price list_price from catalog_sales ,date_dim where cs_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 + and d_year between 1999 and 1999 + 2 union all select ws_quantity quantity ,ws_list_price list_price @@ -3355,10 +3249,8 @@ with /* TPC-DS query14a.tpl 0.69 */ cross_items as ,date_dim where ws_sold_date_sk = d_date_sk and d_year between 1999 and 1999 + 2) x) -, - results AS -(select channel, i_brand_id, i_class_id, i_category_id, sum(sales) sum_sales, sum(number_sales) number_sales - from ( + select channel, i_brand_id,i_class_id,i_category_id,sum(sales), sum(number_sales) + from( select 'store' channel, i_brand_id,i_class_id ,i_category_id,sum(ss_quantity*ss_list_price) sales , count(*) number_sales @@ -3368,7 +3260,7 @@ with /* TPC-DS query14a.tpl 0.69 */ cross_items as where ss_item_sk in (select ss_item_sk from cross_items) and ss_item_sk = i_item_sk and ss_sold_date_sk = d_date_sk - and d_year = 1999+2 + and d_year = 1999+2 and d_moy = 11 group by i_brand_id,i_class_id,i_category_id having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales) @@ -3380,7 +3272,7 @@ with /* TPC-DS query14a.tpl 0.69 */ cross_items as where cs_item_sk in (select ss_item_sk from cross_items) and cs_item_sk = i_item_sk and cs_sold_date_sk = d_date_sk - and d_year = 1999+2 + and d_year = 1999+2 and d_moy = 11 group by i_brand_id,i_class_id,i_category_id having sum(cs_quantity*cs_list_price) > (select average_sales from avg_sales) @@ -3397,25 +3289,10 @@ with /* TPC-DS query14a.tpl 0.69 */ cross_items as group by i_brand_id,i_class_id,i_category_id having sum(ws_quantity*ws_list_price) > (select average_sales from avg_sales) ) y - group by channel, i_brand_id,i_class_id,i_category_id) - - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales -from ( - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales from results - union - select channel, i_brand_id, i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id, i_class_id - union - select channel, i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id - union - select channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel - union - select null as channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results) z -order by channel, i_brand_id, i_class_id, i_category_id + group by rollup (channel, i_brand_id,i_class_id,i_category_id) + order by channel,i_brand_id,i_class_id,i_category_id limit 100; -with /* TPC-DS query14a.tpl 0.69 part2 */ cross_items as +with /* TPC-DS query14.tpl 0.69 part2 */ cross_items as (select i_item_sk ss_item_sk from item, (select iss.i_brand_id brand_id @@ -3485,10 +3362,10 @@ with /* TPC-DS query14a.tpl 0.69 part2 */ cross_items as ,last_year.i_category_id ly_category ,last_year.sales ly_sales ,last_year.number_sales ly_number_sales -from + from (select 'store' channel, i_brand_id,i_class_id,i_category_id ,sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales + from store_sales ,item ,date_dim where ss_item_sk in (select ss_item_sk from cross_items) @@ -3522,7 +3399,7 @@ from order by this_year.channel, this_year.i_brand_id, this_year.i_class_id, this_year.i_category_id limit 100; --- end template query14a.tpl query 69 in stream 0 +-- end template query14.tpl query 69 in stream 0 -- start template query57.tpl query 70 in stream 0 with /* TPC-DS query57.tpl 0.70 */ v1 as( select i_category, i_brand, @@ -3853,8 +3730,8 @@ from ((select distinct c_last_name, c_first_name, d_date ; -- end template query87.tpl query 77 in stream 0 --- start template query77a.tpl query 78 in stream 0 -with /* TPC-DS query77a.tpl 0.78 */ ss as +-- start template query77.tpl query 78 in stream 0 +with /* TPC-DS query77.tpl 0.78 */ ss as (select s_store_sk, sum(ss_ext_sales_price) as sales, sum(ss_net_profit) as profit @@ -3862,8 +3739,8 @@ with /* TPC-DS query77a.tpl 0.78 */ ss as date_dim, store where ss_sold_date_sk = d_date_sk - and d_date between cast('2000-08-02' as date) - and dateadd(day,30,cast('2000-08-02' as date)) + and d_date between cast('2000-08-02' as date) + and dateadd(day,30,cast('2000-08-02' as date)) and ss_store_sk = s_store_sk group by s_store_sk) , @@ -3876,9 +3753,9 @@ with /* TPC-DS query77a.tpl 0.78 */ ss as store where sr_returned_date_sk = d_date_sk and d_date between cast('2000-08-02' as date) - and dateadd(day,30,cast('2000-08-02' as date)) + and dateadd(day,30,cast('2000-08-02' as date)) and sr_store_sk = s_store_sk - group by s_store_sk), + group by s_store_sk), cs as (select cs_call_center_sk, sum(cs_ext_sales_price) as sales, @@ -3887,9 +3764,9 @@ with /* TPC-DS query77a.tpl 0.78 */ ss as date_dim where cs_sold_date_sk = d_date_sk and d_date between cast('2000-08-02' as date) - and dateadd(day,30,cast('2000-08-02' as date)) - group by cs_call_center_sk - ), + and dateadd(day,30,cast('2000-08-02' as date)) + group by cs_call_center_sk + ), cr as (select cr_call_center_sk, sum(cr_return_amount) as returns, @@ -3898,8 +3775,9 @@ with /* TPC-DS query77a.tpl 0.78 */ ss as date_dim where cr_returned_date_sk = d_date_sk and d_date between cast('2000-08-02' as date) - and dateadd(day,30,cast('2000-08-02' as date)) - group by cr_call_center_sk), + and dateadd(day,30,cast('2000-08-02' as date)) + group by cr_call_center_sk + ), ws as ( select wp_web_page_sk, sum(ws_ext_sales_price) as sales, @@ -3909,9 +3787,9 @@ with /* TPC-DS query77a.tpl 0.78 */ ss as web_page where ws_sold_date_sk = d_date_sk and d_date between cast('2000-08-02' as date) - and dateadd(day,30,cast('2000-08-02' as date)) + and dateadd(day,30,cast('2000-08-02' as date)) and ws_web_page_sk = wp_web_page_sk - group by wp_web_page_sk), + group by wp_web_page_sk), wr as (select wp_web_page_sk, sum(wr_return_amt) as returns, @@ -3921,17 +3799,15 @@ with /* TPC-DS query77a.tpl 0.78 */ ss as web_page where wr_returned_date_sk = d_date_sk and d_date between cast('2000-08-02' as date) - and dateadd(day,30,cast('2000-08-02' as date)) + and dateadd(day,30,cast('2000-08-02' as date)) and wr_web_page_sk = wp_web_page_sk group by wp_web_page_sk) - , - results as - (select channel + select channel , id , sum(sales) as sales , sum(returns) as returns , sum(profit) as profit - from + from (select 'store channel' as channel , ss.s_store_sk as id , sales @@ -3956,20 +3832,12 @@ with /* TPC-DS query77a.tpl 0.78 */ ss as from ws left join wr on ws.wp_web_page_sk = wr.wp_web_page_sk ) x - group by channel, id ) - - select * - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results -) foo -order by channel, id + group by rollup (channel, id) + order by channel + ,id limit 100; --- end template query77a.tpl query 78 in stream 0 +-- end template query77.tpl query 78 in stream 0 -- start template query73.tpl query 79 in stream 0 select /* TPC-DS query73.tpl 0.79 */ c_last_name ,c_first_name @@ -4347,62 +4215,40 @@ select /* TPC-DS query79.tpl 0.89 */ limit 100; -- end template query79.tpl query 89 in stream 0 --- start template query18a.tpl query 90 in stream 0 -with /* TPC-DS query18a.tpl 0.90 */ results as - (select i_item_id, +-- start template query18.tpl query 90 in stream 0 +select /* TPC-DS query18.tpl 0.90 */ i_item_id, ca_country, - ca_state, + ca_state, ca_county, - cast(cs_quantity as decimal(12,2)) agg1, - cast(cs_list_price as decimal(12,2)) agg2, - cast(cs_coupon_amt as decimal(12,2)) agg3, - cast(cs_sales_price as decimal(12,2)) agg4, - cast(cs_net_profit as decimal(12,2)) agg5, - cast(c_birth_year as decimal(12,2)) agg6, - cast(cd1.cd_dep_count as decimal(12,2)) agg7 - from catalog_sales, customer_demographics cd1, customer_demographics cd2, customer, customer_address, date_dim, item + avg( cast(cs_quantity as decimal(12,2))) agg1, + avg( cast(cs_list_price as decimal(12,2))) agg2, + avg( cast(cs_coupon_amt as decimal(12,2))) agg3, + avg( cast(cs_sales_price as decimal(12,2))) agg4, + avg( cast(cs_net_profit as decimal(12,2))) agg5, + avg( cast(c_birth_year as decimal(12,2))) agg6, + avg( cast(cd1.cd_dep_count as decimal(12,2))) agg7 + from catalog_sales, customer_demographics cd1, + customer_demographics cd2, customer, customer_address, date_dim, item where cs_sold_date_sk = d_date_sk and cs_item_sk = i_item_sk and cs_bill_cdemo_sk = cd1.cd_demo_sk and cs_bill_customer_sk = c_customer_sk and - cd1.cd_gender = 'M' and + cd1.cd_gender = 'M' and cd1.cd_education_status = 'Primary' and c_current_cdemo_sk = cd2.cd_demo_sk and c_current_addr_sk = ca_address_sk and c_birth_month in (9,5,1,2,3,8) and d_year = 1999 and - ca_state in ('NV','AL','CA','WI','SD','OK','KY') - ) - select i_item_id, ca_country, ca_state, ca_county, agg1, agg2, agg3, agg4, agg5, agg6, agg7 - from ( - select i_item_id, ca_country, ca_state, ca_county, avg(agg1) agg1, - avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state, ca_county - union all - select i_item_id, ca_country, ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state - union all - select i_item_id, ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country - union all - select i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - ) foo - order by ca_country, ca_state, ca_county, i_item_id + ca_state in ('NV','AL','CA' + ,'WI','SD','OK','KY') + group by rollup (i_item_id, ca_country, ca_state, ca_county) + order by ca_country, + ca_state, + ca_county, + i_item_id limit 100; --- end template query18a.tpl query 90 in stream 0 +-- end template query18.tpl query 90 in stream 0 -- start template query13.tpl query 91 in stream 0 select /* TPC-DS query13.tpl 0.91 */ avg(ss_quantity) ,avg(ss_ext_sales_price) @@ -4866,8 +4712,8 @@ order by promotions, total limit 100; -- end template query61.tpl query 97 in stream 0 --- start template query5a.tpl query 98 in stream 0 -with /* TPC-DS query5a.tpl 0.98 */ ssr as +-- start template query5.tpl query 98 in stream 0 +with /* TPC-DS query5.tpl 0.98 */ ssr as (select s_store_id, sum(sales_price) as sales, sum(profit) as profit, @@ -4893,7 +4739,7 @@ with /* TPC-DS query5a.tpl 0.98 */ ssr as date_dim, store where date_sk = d_date_sk - and d_date between cast('1998-08-11' as date) + and d_date between cast('1998-08-11' as date) and dateadd(day,14,cast('1998-08-11' as date)) and store_sk = s_store_sk group by s_store_id) @@ -4961,14 +4807,12 @@ with /* TPC-DS query5a.tpl 0.98 */ ssr as and dateadd(day,14,cast('1998-08-11' as date)) and wsr_web_site_sk = web_site_sk group by web_site_id) - , - results as - (select channel + select channel , id , sum(sales) as sales , sum(returns) as returns , sum(profit) as profit - from + from (select 'store channel' as channel , 'store' || s_store_id as id , sales @@ -4990,17 +4834,12 @@ with /* TPC-DS query5a.tpl 0.98 */ ssr as , (profit - profit_loss) as profit from wsr ) x - group by channel, id) - select channel, id, sales, returns, profit from ( - select channel, id, sales, returns, profit from results - union - select channel, null as id, sum(sales), sum(returns), sum(profit) from results group by channel - union - select null as channel, null as id, sum(sales), sum(returns), sum(profit) from results) foo -order by channel, id -limit 100; + group by rollup (channel, id) + order by channel + ,id + limit 100; --- end template query5a.tpl query 98 in stream 0 +-- end template query5.tpl query 98 in stream 0 -- start template query76.tpl query 99 in stream 0 select /* TPC-DS query76.tpl 0.99 */ channel, col_name, d_year, d_qoy, i_category, COUNT(*) sales_cnt, SUM(ext_sales_price) sales_amt FROM ( SELECT 'store' as channel, 'ss_addr_sk' col_name, d_year, d_qoy, i_category, ss_ext_sales_price ext_sales_price diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/3TB/queries/query_1.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/3TB/queries/query_1.sql deleted file mode 100644 index a99f745c..00000000 --- a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/3TB/queries/query_1.sql +++ /dev/null @@ -1,5027 +0,0 @@ --- start template query83.tpl query 1 in stream 1 -with /* TPC-DS query83.tpl 0.96 */ sr_items as - (select i_item_id item_id, - sum(sr_return_quantity) sr_item_qty - from store_returns, - item, - date_dim - where sr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2002-02-24','2002-08-27','2002-11-17'))) - and sr_returned_date_sk = d_date_sk - group by i_item_id), - cr_items as - (select i_item_id item_id, - sum(cr_return_quantity) cr_item_qty - from catalog_returns, - item, - date_dim - where cr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2002-02-24','2002-08-27','2002-11-17'))) - and cr_returned_date_sk = d_date_sk - group by i_item_id), - wr_items as - (select i_item_id item_id, - sum(wr_return_quantity) wr_item_qty - from web_returns, - item, - date_dim - where wr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2002-02-24','2002-08-27','2002-11-17'))) - and wr_returned_date_sk = d_date_sk - group by i_item_id) - select sr_items.item_id - ,sr_item_qty - ,sr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 sr_dev - ,cr_item_qty - ,cr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 cr_dev - ,wr_item_qty - ,wr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 wr_dev - ,(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 average - from sr_items - ,cr_items - ,wr_items - where sr_items.item_id=cr_items.item_id - and sr_items.item_id=wr_items.item_id - order by sr_items.item_id - ,sr_item_qty - limit 100; - --- end template query83.tpl query 1 in stream 1 --- start template query32.tpl query 2 in stream 1 -select /* TPC-DS query32.tpl 0.7 */ sum(cs_ext_discount_amt) as "excess discount amount" -from - catalog_sales - ,item - ,date_dim -where -i_manufact_id = 661 -and i_item_sk = cs_item_sk -and d_date between '2001-02-17' and - dateadd(day,90,cast('2001-02-17' as date)) -and d_date_sk = cs_sold_date_sk -and cs_ext_discount_amt - > ( - select - 1.3 * avg(cs_ext_discount_amt) - from - catalog_sales - ,date_dim - where - cs_item_sk = i_item_sk - and d_date between '2001-02-17' and - dateadd(day,90,cast('2001-02-17' as date)) - and d_date_sk = cs_sold_date_sk - ) -limit 100; - --- end template query32.tpl query 2 in stream 1 --- start template query30.tpl query 3 in stream 1 -with /* TPC-DS query30.tpl 0.75 */ customer_total_return as - (select wr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(wr_return_amt) as ctr_total_return - from web_returns - ,date_dim - ,customer_address - where wr_returned_date_sk = d_date_sk - and d_year =2002 - and wr_returning_addr_sk = ca_address_sk - group by wr_returning_customer_sk - ,ca_state) - select c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'OH' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return -limit 100; - --- end template query30.tpl query 3 in stream 1 --- start template query92.tpl query 4 in stream 1 -select /* TPC-DS query92.tpl 0.44 */ - sum(ws_ext_discount_amt) as "Excess Discount Amount" -from - web_sales - ,item - ,date_dim -where -i_manufact_id = 690 -and i_item_sk = ws_item_sk -and d_date between '1998-02-01' and - dateadd(day,90,cast('1998-02-01' as date)) -and d_date_sk = ws_sold_date_sk -and ws_ext_discount_amt - > ( - SELECT - 1.3 * avg(ws_ext_discount_amt) - FROM - web_sales - ,date_dim - WHERE - ws_item_sk = i_item_sk - and d_date between '1998-02-01' and - dateadd(day,90,cast('1998-02-01' as date)) - and d_date_sk = ws_sold_date_sk - ) -order by sum(ws_ext_discount_amt) -limit 100; - --- end template query92.tpl query 4 in stream 1 --- start template query66.tpl query 5 in stream 1 -select /* TPC-DS query66.tpl 0.39 */ - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - ,sum(jan_sales) as jan_sales - ,sum(feb_sales) as feb_sales - ,sum(mar_sales) as mar_sales - ,sum(apr_sales) as apr_sales - ,sum(may_sales) as may_sales - ,sum(jun_sales) as jun_sales - ,sum(jul_sales) as jul_sales - ,sum(aug_sales) as aug_sales - ,sum(sep_sales) as sep_sales - ,sum(oct_sales) as oct_sales - ,sum(nov_sales) as nov_sales - ,sum(dec_sales) as dec_sales - ,sum(jan_sales/w_warehouse_sq_ft) as jan_sales_per_sq_foot - ,sum(feb_sales/w_warehouse_sq_ft) as feb_sales_per_sq_foot - ,sum(mar_sales/w_warehouse_sq_ft) as mar_sales_per_sq_foot - ,sum(apr_sales/w_warehouse_sq_ft) as apr_sales_per_sq_foot - ,sum(may_sales/w_warehouse_sq_ft) as may_sales_per_sq_foot - ,sum(jun_sales/w_warehouse_sq_ft) as jun_sales_per_sq_foot - ,sum(jul_sales/w_warehouse_sq_ft) as jul_sales_per_sq_foot - ,sum(aug_sales/w_warehouse_sq_ft) as aug_sales_per_sq_foot - ,sum(sep_sales/w_warehouse_sq_ft) as sep_sales_per_sq_foot - ,sum(oct_sales/w_warehouse_sq_ft) as oct_sales_per_sq_foot - ,sum(nov_sales/w_warehouse_sq_ft) as nov_sales_per_sq_foot - ,sum(dec_sales/w_warehouse_sq_ft) as dec_sales_per_sq_foot - ,sum(jan_net) as jan_net - ,sum(feb_net) as feb_net - ,sum(mar_net) as mar_net - ,sum(apr_net) as apr_net - ,sum(may_net) as may_net - ,sum(jun_net) as jun_net - ,sum(jul_net) as jul_net - ,sum(aug_net) as aug_net - ,sum(sep_net) as sep_net - ,sum(oct_net) as oct_net - ,sum(nov_net) as nov_net - ,sum(dec_net) as dec_net - from ( - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'AIRBORNE' || ',' || 'MSC' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then ws_sales_price* ws_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then ws_sales_price* ws_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then ws_sales_price* ws_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then ws_sales_price* ws_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then ws_sales_price* ws_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then ws_sales_price* ws_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then ws_sales_price* ws_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then ws_sales_price* ws_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then ws_sales_price* ws_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then ws_sales_price* ws_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then ws_sales_price* ws_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then ws_sales_price* ws_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then ws_net_profit * ws_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then ws_net_profit * ws_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then ws_net_profit * ws_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then ws_net_profit * ws_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then ws_net_profit * ws_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then ws_net_profit * ws_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then ws_net_profit * ws_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then ws_net_profit * ws_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then ws_net_profit * ws_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then ws_net_profit * ws_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then ws_net_profit * ws_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then ws_net_profit * ws_quantity else 0 end) as dec_net - from - web_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - ws_warehouse_sk = w_warehouse_sk - and ws_sold_date_sk = d_date_sk - and ws_sold_time_sk = t_time_sk - and ws_ship_mode_sk = sm_ship_mode_sk - and d_year = 2001 - and t_time between 6152 and 6152+28800 - and sm_carrier in ('AIRBORNE','MSC') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - union all - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'AIRBORNE' || ',' || 'MSC' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then cs_sales_price* cs_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then cs_sales_price* cs_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then cs_sales_price* cs_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then cs_sales_price* cs_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then cs_sales_price* cs_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then cs_sales_price* cs_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then cs_sales_price* cs_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then cs_sales_price* cs_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then cs_sales_price* cs_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then cs_sales_price* cs_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then cs_sales_price* cs_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then cs_sales_price* cs_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as dec_net - from - catalog_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and cs_sold_time_sk = t_time_sk - and cs_ship_mode_sk = sm_ship_mode_sk - and d_year = 2001 - and t_time between 6152 AND 6152+28800 - and sm_carrier in ('AIRBORNE','MSC') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - ) x - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - order by w_warehouse_name - limit 100; - --- end template query66.tpl query 5 in stream 1 --- start template query84.tpl query 6 in stream 1 -select /* TPC-DS query84.tpl 0.80 */ c_customer_id as customer_id - , coalesce(c_last_name,'') || ', ' || coalesce(c_first_name,'') as customername - from customer - ,customer_address - ,customer_demographics - ,household_demographics - ,income_band - ,store_returns - where ca_city = 'Sunnyside' - and c_current_addr_sk = ca_address_sk - and ib_lower_bound >= 23067 - and ib_upper_bound <= 23067 + 50000 - and ib_income_band_sk = hd_income_band_sk - and cd_demo_sk = c_current_cdemo_sk - and hd_demo_sk = c_current_hdemo_sk - and sr_cdemo_sk = cd_demo_sk - order by c_customer_id - limit 100; - --- end template query84.tpl query 6 in stream 1 --- start template query98.tpl query 7 in stream 1 -select /* TPC-DS query98.tpl 0.32 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ss_ext_sales_price) as itemrevenue - ,sum(ss_ext_sales_price)*100/sum(sum(ss_ext_sales_price)) over - (partition by i_class) as revenueratio -from - store_sales - ,item - ,date_dim -where - ss_item_sk = i_item_sk - and i_category in ('Women', 'Home', 'Music') - and ss_sold_date_sk = d_date_sk - and d_date between cast('2000-06-25' as date) - and dateadd(day,30,cast('2000-06-25' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio; - --- end template query98.tpl query 7 in stream 1 --- start template query58.tpl query 8 in stream 1 -with /* TPC-DS query58.tpl 0.19 */ ss_items as - (select i_item_id item_id - ,sum(ss_ext_sales_price) ss_item_rev - from store_sales - ,item - ,date_dim - where ss_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '1999-05-29')) - and ss_sold_date_sk = d_date_sk - group by i_item_id), - cs_items as - (select i_item_id item_id - ,sum(cs_ext_sales_price) cs_item_rev - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '1999-05-29')) - and cs_sold_date_sk = d_date_sk - group by i_item_id), - ws_items as - (select i_item_id item_id - ,sum(ws_ext_sales_price) ws_item_rev - from web_sales - ,item - ,date_dim - where ws_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq =(select d_week_seq - from date_dim - where d_date = '1999-05-29')) - and ws_sold_date_sk = d_date_sk - group by i_item_id) - select ss_items.item_id - ,ss_item_rev - ,ss_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ss_dev - ,cs_item_rev - ,cs_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 cs_dev - ,ws_item_rev - ,ws_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ws_dev - ,(ss_item_rev+cs_item_rev+ws_item_rev)/3 average - from ss_items,cs_items,ws_items - where ss_items.item_id=cs_items.item_id - and ss_items.item_id=ws_items.item_id - and ss_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - and ss_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and cs_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and cs_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and ws_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and ws_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - order by item_id - ,ss_item_rev - limit 100; - --- end template query58.tpl query 8 in stream 1 --- start template query16.tpl query 9 in stream 1 -select /* TPC-DS query16.tpl 0.25 */ - count(distinct cs_order_number) as "order count" - ,sum(cs_ext_ship_cost) as "total shipping cost" - ,sum(cs_net_profit) as "total net profit" -from - catalog_sales cs1 - ,date_dim - ,customer_address - ,call_center -where - d_date between '2002-3-01' and - dateadd(day, 60, cast('2002-3-01' as date)) -and cs1.cs_ship_date_sk = d_date_sk -and cs1.cs_ship_addr_sk = ca_address_sk -and ca_state = 'MN' -and cs1.cs_call_center_sk = cc_call_center_sk -and cc_county in ('Jackson County','Marshall County','San Miguel County','Oglethorpe County', - 'Huron County' -) -and exists (select * - from catalog_sales cs2 - where cs1.cs_order_number = cs2.cs_order_number - and cs1.cs_warehouse_sk <> cs2.cs_warehouse_sk) -and not exists(select * - from catalog_returns cr1 - where cs1.cs_order_number = cr1.cr_order_number) -order by count(distinct cs_order_number) -limit 100; - --- end template query16.tpl query 9 in stream 1 --- start template query77a.tpl query 10 in stream 1 -with /* TPC-DS query77a.tpl 0.78 */ ss as - (select s_store_sk, - sum(ss_ext_sales_price) as sales, - sum(ss_net_profit) as profit - from store_sales, - date_dim, - store - where ss_sold_date_sk = d_date_sk - and d_date between cast('2002-08-17' as date) - and dateadd(day,30,cast('2002-08-17' as date)) - and ss_store_sk = s_store_sk - group by s_store_sk) - , - sr as - (select s_store_sk, - sum(sr_return_amt) as returns, - sum(sr_net_loss) as profit_loss - from store_returns, - date_dim, - store - where sr_returned_date_sk = d_date_sk - and d_date between cast('2002-08-17' as date) - and dateadd(day,30,cast('2002-08-17' as date)) - and sr_store_sk = s_store_sk - group by s_store_sk), - cs as - (select cs_call_center_sk, - sum(cs_ext_sales_price) as sales, - sum(cs_net_profit) as profit - from catalog_sales, - date_dim - where cs_sold_date_sk = d_date_sk - and d_date between cast('2002-08-17' as date) - and dateadd(day,30,cast('2002-08-17' as date)) - group by cs_call_center_sk - ), - cr as - (select cr_call_center_sk, - sum(cr_return_amount) as returns, - sum(cr_net_loss) as profit_loss - from catalog_returns, - date_dim - where cr_returned_date_sk = d_date_sk - and d_date between cast('2002-08-17' as date) - and dateadd(day,30,cast('2002-08-17' as date)) - group by cr_call_center_sk), - ws as - ( select wp_web_page_sk, - sum(ws_ext_sales_price) as sales, - sum(ws_net_profit) as profit - from web_sales, - date_dim, - web_page - where ws_sold_date_sk = d_date_sk - and d_date between cast('2002-08-17' as date) - and dateadd(day,30,cast('2002-08-17' as date)) - and ws_web_page_sk = wp_web_page_sk - group by wp_web_page_sk), - wr as - (select wp_web_page_sk, - sum(wr_return_amt) as returns, - sum(wr_net_loss) as profit_loss - from web_returns, - date_dim, - web_page - where wr_returned_date_sk = d_date_sk - and d_date between cast('2002-08-17' as date) - and dateadd(day,30,cast('2002-08-17' as date)) - and wr_web_page_sk = wp_web_page_sk - group by wp_web_page_sk) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , ss.s_store_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ss left join sr - on ss.s_store_sk = sr.s_store_sk - union all - select 'catalog channel' as channel - , cs_call_center_sk as id - , sales - , returns - , (profit - profit_loss) as profit - from cs - , cr - union all - select 'web channel' as channel - , ws.wp_web_page_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ws left join wr - on ws.wp_web_page_sk = wr.wp_web_page_sk - ) x - group by channel, id ) - - select * - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results -) foo -order by channel, id - limit 100; - --- end template query77a.tpl query 10 in stream 1 --- start template query40.tpl query 11 in stream 1 -select /* TPC-DS query40.tpl 0.86 */ - w_state - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('1998-05-07' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_before - ,sum(case when (cast(d_date as date) >= cast ('1998-05-07' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_after - from - catalog_sales left outer join catalog_returns on - (cs_order_number = cr_order_number - and cs_item_sk = cr_item_sk) - ,warehouse - ,item - ,date_dim - where - i_current_price between 0.99 and 1.49 - and i_item_sk = cs_item_sk - and cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('1998-05-07' as date)) - and dateadd(day,30,cast ('1998-05-07' as date)) - group by - w_state,i_item_id - order by w_state,i_item_id -limit 100; - --- end template query40.tpl query 11 in stream 1 --- start template query96.tpl query 12 in stream 1 -select /* TPC-DS query96.tpl 0.1 */ count(*) -from store_sales - ,household_demographics - ,time_dim, store -where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 16 - and time_dim.t_minute >= 30 - and household_demographics.hd_dep_count = 7 - and store.s_store_name = 'ese' -order by count(*) -limit 100; - --- end template query96.tpl query 12 in stream 1 --- start template query13.tpl query 13 in stream 1 -select /* TPC-DS query13.tpl 0.91 */ avg(ss_quantity) - ,avg(ss_ext_sales_price) - ,avg(ss_ext_wholesale_cost) - ,sum(ss_ext_wholesale_cost) - from store_sales - ,store - ,customer_demographics - ,household_demographics - ,customer_address - ,date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2001 - and((ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'D' - and cd_education_status = 'Unknown' - and ss_sales_price between 100.00 and 150.00 - and hd_dep_count = 3 - )or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'S' - and cd_education_status = 'Advanced Degree' - and ss_sales_price between 50.00 and 100.00 - and hd_dep_count = 1 - ) or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'W' - and cd_education_status = 'College' - and ss_sales_price between 150.00 and 200.00 - and hd_dep_count = 1 - )) - and((ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('LA', 'IN', 'VA') - and ss_net_profit between 100 and 200 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('MS', 'SD', 'ND') - and ss_net_profit between 150 and 300 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('IA', 'OH', 'MN') - and ss_net_profit between 50 and 250 - )) -; - --- end template query13.tpl query 13 in stream 1 --- start template query36a.tpl query 14 in stream 1 -with /* TPC-DS query36a.tpl 0.21 */ results as - (select - sum(ss_net_profit) as ss_net_profit, sum(ss_ext_sales_price) as ss_ext_sales_price, - sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin - ,i_category - ,i_class - ,0 as g_category, 0 as g_class - from - store_sales - ,date_dim d1 - ,item - ,store - where - d1.d_year = 1998 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and s_state in ('PA','GA','MI','MI', - 'MO','NY','TN','AL') - group by i_category,i_class) - , - results_rollup as - (select gross_margin ,i_category ,i_class,0 as t_category, 0 as t_class, 0 as lochierarchy from results - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - i_category, NULL AS i_class, 0 as t_category, 1 as t_class, 1 as lochierarchy from results group by i_category - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - NULL AS i_category ,NULL AS i_class, 1 as t_category, 1 as t_class, 2 as lochierarchy from results) - select - gross_margin ,i_category ,i_class, lochierarchy,rank() over ( - partition by lochierarchy, case when t_class = 0 then i_category end - order by gross_margin asc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then i_category end - ,rank_within_parent - limit 100; - --- end template query36a.tpl query 14 in stream 1 --- start template query95.tpl query 15 in stream 1 -with /* TPC-DS query95.tpl 0.43 */ ws_wh as -(select ws1.ws_order_number,ws1.ws_warehouse_sk wh1,ws2.ws_warehouse_sk wh2 - from web_sales ws1,web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) - select - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2002-3-01' and - dateadd(day,60,cast('2002-3-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'VA' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and ws1.ws_order_number in (select ws_order_number - from ws_wh) -and ws1.ws_order_number in (select wr_order_number - from web_returns,ws_wh - where wr_order_number = ws_wh.ws_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query95.tpl query 15 in stream 1 --- start template query63.tpl query 16 in stream 1 -select /* TPC-DS query63.tpl 0.27 */ * -from (select i_manager_id - ,sum(ss_sales_price) sum_sales - ,avg(sum(ss_sales_price)) over (partition by i_manager_id) avg_monthly_sales - from item - ,store_sales - ,date_dim - ,store - where ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and d_month_seq in (1202,1202+1,1202+2,1202+3,1202+4,1202+5,1202+6,1202+7,1202+8,1202+9,1202+10,1202+11) - and (( i_category in ('Books','Children','Electronics') - and i_class in ('personal','portable','reference','self-help') - and i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) - or( i_category in ('Women','Music','Men') - and i_class in ('accessories','classical','fragrances','pants') - and i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manager_id, d_moy) tmp1 -where case when avg_monthly_sales > 0 then abs (sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 -order by i_manager_id - ,avg_monthly_sales - ,sum_sales -limit 100; - --- end template query63.tpl query 16 in stream 1 --- start template query99.tpl query 17 in stream 1 -select /* TPC-DS query99.tpl 0.94 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 30) and - (cs_ship_date_sk - cs_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 60) and - (cs_ship_date_sk - cs_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 90) and - (cs_ship_date_sk - cs_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - catalog_sales - ,warehouse - ,ship_mode - ,call_center - ,date_dim -where - d_month_seq between 1218 and 1218 + 11 -and cs_ship_date_sk = d_date_sk -and cs_warehouse_sk = w_warehouse_sk -and cs_ship_mode_sk = sm_ship_mode_sk -and cs_call_center_sk = cc_call_center_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -limit 100; - --- end template query99.tpl query 17 in stream 1 --- start template query3.tpl query 18 in stream 1 -select /* TPC-DS query3.tpl 0.45 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_net_profit) sum_agg - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manufact_id = 826 - and dt.d_moy=12 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,sum_agg desc - ,brand_id - limit 100; - --- end template query3.tpl query 18 in stream 1 --- start template query6.tpl query 19 in stream 1 -select /* TPC-DS query6.tpl 0.58 */ a.ca_state state, count(*) cnt - from customer_address a - ,customer c - ,store_sales s - ,date_dim d - ,item i - where a.ca_address_sk = c.c_current_addr_sk - and c.c_customer_sk = s.ss_customer_sk - and s.ss_sold_date_sk = d.d_date_sk - and s.ss_item_sk = i.i_item_sk - and d.d_month_seq = - (select distinct (d_month_seq) - from date_dim - where d_year = 1999 - and d_moy = 4 ) - and i.i_current_price > 1.2 * - (select avg(j.i_current_price) - from item j - where j.i_category = i.i_category) - group by a.ca_state - having count(*) >= 10 - order by cnt, a.ca_state - limit 100; - --- end template query6.tpl query 19 in stream 1 --- start template query12.tpl query 20 in stream 1 -select /* TPC-DS query12.tpl 0.64 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ws_ext_sales_price) as itemrevenue - ,sum(ws_ext_sales_price)*100/sum(sum(ws_ext_sales_price)) over - (partition by i_class) as revenueratio -from - web_sales - ,item - ,date_dim -where - ws_item_sk = i_item_sk - and i_category in ('Men', 'Jewelry', 'Women') - and ws_sold_date_sk = d_date_sk - and d_date between cast('2000-01-21' as date) - and dateadd(day,30,cast('2000-01-21' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query12.tpl query 20 in stream 1 --- start template query28.tpl query 21 in stream 1 -select /* TPC-DS query28.tpl 0.36 */ * -from (select avg(ss_list_price) B1_LP - ,count(ss_list_price) B1_CNT - ,count(distinct ss_list_price) B1_CNTD - from store_sales - where ss_quantity between 0 and 5 - and (ss_list_price between 2 and 2+10 - or ss_coupon_amt between 4869 and 4869+1000 - or ss_wholesale_cost between 15 and 15+20)) B1, - (select avg(ss_list_price) B2_LP - ,count(ss_list_price) B2_CNT - ,count(distinct ss_list_price) B2_CNTD - from store_sales - where ss_quantity between 6 and 10 - and (ss_list_price between 28 and 28+10 - or ss_coupon_amt between 13932 and 13932+1000 - or ss_wholesale_cost between 17 and 17+20)) B2, - (select avg(ss_list_price) B3_LP - ,count(ss_list_price) B3_CNT - ,count(distinct ss_list_price) B3_CNTD - from store_sales - where ss_quantity between 11 and 15 - and (ss_list_price between 131 and 131+10 - or ss_coupon_amt between 6064 and 6064+1000 - or ss_wholesale_cost between 73 and 73+20)) B3, - (select avg(ss_list_price) B4_LP - ,count(ss_list_price) B4_CNT - ,count(distinct ss_list_price) B4_CNTD - from store_sales - where ss_quantity between 16 and 20 - and (ss_list_price between 147 and 147+10 - or ss_coupon_amt between 15739 and 15739+1000 - or ss_wholesale_cost between 60 and 60+20)) B4, - (select avg(ss_list_price) B5_LP - ,count(ss_list_price) B5_CNT - ,count(distinct ss_list_price) B5_CNTD - from store_sales - where ss_quantity between 21 and 25 - and (ss_list_price between 146 and 146+10 - or ss_coupon_amt between 2128 and 2128+1000 - or ss_wholesale_cost between 51 and 51+20)) B5, - (select avg(ss_list_price) B6_LP - ,count(ss_list_price) B6_CNT - ,count(distinct ss_list_price) B6_CNTD - from store_sales - where ss_quantity between 26 and 30 - and (ss_list_price between 41 and 41+10 - or ss_coupon_amt between 4345 and 4345+1000 - or ss_wholesale_cost between 48 and 48+20)) B6 -limit 100; - --- end template query28.tpl query 21 in stream 1 --- start template query85.tpl query 22 in stream 1 -select /* TPC-DS query85.tpl 0.33 */ substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) - from web_sales, web_returns, web_page, customer_demographics cd1, - customer_demographics cd2, customer_address, date_dim, reason - where ws_web_page_sk = wp_web_page_sk - and ws_item_sk = wr_item_sk - and ws_order_number = wr_order_number - and ws_sold_date_sk = d_date_sk and d_year = 2002 - and cd1.cd_demo_sk = wr_refunded_cdemo_sk - and cd2.cd_demo_sk = wr_returning_cdemo_sk - and ca_address_sk = wr_refunded_addr_sk - and r_reason_sk = wr_reason_sk - and - ( - ( - cd1.cd_marital_status = 'W' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Advanced Degree' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 100.00 and 150.00 - ) - or - ( - cd1.cd_marital_status = 'S' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Primary' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 50.00 and 100.00 - ) - or - ( - cd1.cd_marital_status = 'U' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Unknown' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ca_country = 'United States' - and - ca_state in ('OH', 'MI', 'PA') - and ws_net_profit between 100 and 200 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('NY', 'IN', 'FL') - and ws_net_profit between 150 and 300 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('IA', 'TN', 'OK') - and ws_net_profit between 50 and 250 - ) - ) -group by r_reason_desc -order by substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) -limit 100; - --- end template query85.tpl query 22 in stream 1 --- start template query51.tpl query 23 in stream 1 -WITH /* TPC-DS query51.tpl 0.46 */ web_v1 as ( -select - ws_item_sk item_sk, d_date, - sum(sum(ws_sales_price)) - over (partition by ws_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from web_sales - ,date_dim -where ws_sold_date_sk=d_date_sk - and d_month_seq between 1198 and 1198+11 - and ws_item_sk is not NULL -group by ws_item_sk, d_date), -store_v1 as ( -select - ss_item_sk item_sk, d_date, - sum(sum(ss_sales_price)) - over (partition by ss_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from store_sales - ,date_dim -where ss_sold_date_sk=d_date_sk - and d_month_seq between 1198 and 1198+11 - and ss_item_sk is not NULL -group by ss_item_sk, d_date) - select * -from (select item_sk - ,d_date - ,web_sales - ,store_sales - ,max(web_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) web_cumulative - ,max(store_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) store_cumulative - from (select case when web.item_sk is not null then web.item_sk else store.item_sk end item_sk - ,case when web.d_date is not null then web.d_date else store.d_date end d_date - ,web.cume_sales web_sales - ,store.cume_sales store_sales - from web_v1 web full outer join store_v1 store on (web.item_sk = store.item_sk - and web.d_date = store.d_date) - )x )y -where web_cumulative > store_cumulative -order by item_sk - ,d_date -limit 100; - --- end template query51.tpl query 23 in stream 1 --- start template query41.tpl query 24 in stream 1 -select /* TPC-DS query41.tpl 0.62 */ distinct(i_product_name) - from item i1 - where i_manufact_id between 985 and 985+40 - and (select count(*) as item_cnt - from item - where (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'peach' or i_color = 'cyan') and - (i_units = 'N/A' or i_units = 'Pallet') and - (i_size = 'N/A' or i_size = 'small') - ) or - (i_category = 'Women' and - (i_color = 'deep' or i_color = 'orchid') and - (i_units = 'Gross' or i_units = 'Bunch') and - (i_size = 'extra large' or i_size = 'economy') - ) or - (i_category = 'Men' and - (i_color = 'khaki' or i_color = 'goldenrod') and - (i_units = 'Gram' or i_units = 'Tsp') and - (i_size = 'petite' or i_size = 'large') - ) or - (i_category = 'Men' and - (i_color = 'midnight' or i_color = 'wheat') and - (i_units = 'Ton' or i_units = 'Dozen') and - (i_size = 'N/A' or i_size = 'small') - ))) or - (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'violet' or i_color = 'ivory') and - (i_units = 'Case' or i_units = 'Carton') and - (i_size = 'N/A' or i_size = 'small') - ) or - (i_category = 'Women' and - (i_color = 'sky' or i_color = 'lavender') and - (i_units = 'Cup' or i_units = 'Dram') and - (i_size = 'extra large' or i_size = 'economy') - ) or - (i_category = 'Men' and - (i_color = 'puff' or i_color = 'rosy') and - (i_units = 'Each' or i_units = 'Ounce') and - (i_size = 'petite' or i_size = 'large') - ) or - (i_category = 'Men' and - (i_color = 'rose' or i_color = 'olive') and - (i_units = 'Oz' or i_units = 'Pound') and - (i_size = 'N/A' or i_size = 'small') - )))) > 0 - order by i_product_name - limit 100; - --- end template query41.tpl query 24 in stream 1 --- start template query27a.tpl query 25 in stream 1 -with /* TPC-DS query27a.tpl 0.16 */ results as - (select i_item_id, - s_state, 0 as g_state, - ss_quantity agg1, - ss_list_price agg2, - ss_coupon_amt agg3, - ss_sales_price agg4 - from store_sales, customer_demographics, date_dim, store, item - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_store_sk = s_store_sk and - ss_cdemo_sk = cd_demo_sk and - cd_gender = 'M' and - cd_marital_status = 'D' and - cd_education_status = 'College' and - d_year = 1999 and - s_state in ('NM','PA', 'WA', 'TX', 'AL', 'MO') - ) - - select i_item_id, - s_state, g_state, agg1, agg2, agg3, agg4 - from ( - select i_item_id, s_state, 0 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4 from results - group by i_item_id, s_state - union all - select i_item_id, NULL AS s_state, 1 AS g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as s_state, 1 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - ) foo - order by i_item_id, s_state - limit 100; - --- end template query27a.tpl query 25 in stream 1 --- start template query78.tpl query 26 in stream 1 -with /* TPC-DS query78.tpl 0.10 */ ws as - (select d_year AS ws_sold_year, ws_item_sk, - ws_bill_customer_sk ws_customer_sk, - sum(ws_quantity) ws_qty, - sum(ws_wholesale_cost) ws_wc, - sum(ws_sales_price) ws_sp - from web_sales - left join web_returns on wr_order_number=ws_order_number and ws_item_sk=wr_item_sk - join date_dim on ws_sold_date_sk = d_date_sk - where wr_order_number is null - group by d_year, ws_item_sk, ws_bill_customer_sk - ), -cs as - (select d_year AS cs_sold_year, cs_item_sk, - cs_bill_customer_sk cs_customer_sk, - sum(cs_quantity) cs_qty, - sum(cs_wholesale_cost) cs_wc, - sum(cs_sales_price) cs_sp - from catalog_sales - left join catalog_returns on cr_order_number=cs_order_number and cs_item_sk=cr_item_sk - join date_dim on cs_sold_date_sk = d_date_sk - where cr_order_number is null - group by d_year, cs_item_sk, cs_bill_customer_sk - ), -ss as - (select d_year AS ss_sold_year, ss_item_sk, - ss_customer_sk, - sum(ss_quantity) ss_qty, - sum(ss_wholesale_cost) ss_wc, - sum(ss_sales_price) ss_sp - from store_sales - left join store_returns on sr_ticket_number=ss_ticket_number and ss_item_sk=sr_item_sk - join date_dim on ss_sold_date_sk = d_date_sk - where sr_ticket_number is null - group by d_year, ss_item_sk, ss_customer_sk - ) - select -ss_sold_year, ss_item_sk, ss_customer_sk, -round(ss_qty/(coalesce(ws_qty,0)+coalesce(cs_qty,0)),2) ratio, -ss_qty store_qty, ss_wc store_wholesale_cost, ss_sp store_sales_price, -coalesce(ws_qty,0)+coalesce(cs_qty,0) other_chan_qty, -coalesce(ws_wc,0)+coalesce(cs_wc,0) other_chan_wholesale_cost, -coalesce(ws_sp,0)+coalesce(cs_sp,0) other_chan_sales_price -from ss -left join ws on (ws_sold_year=ss_sold_year and ws_item_sk=ss_item_sk and ws_customer_sk=ss_customer_sk) -left join cs on (cs_sold_year=ss_sold_year and cs_item_sk=ss_item_sk and cs_customer_sk=ss_customer_sk) -where (coalesce(ws_qty,0)>0 or coalesce(cs_qty, 0)>0) and ss_sold_year=2002 -order by - ss_sold_year, ss_item_sk, ss_customer_sk, - ss_qty desc, ss_wc desc, ss_sp desc, - other_chan_qty, - other_chan_wholesale_cost, - other_chan_sales_price, - ratio -limit 100; - --- end template query78.tpl query 26 in stream 1 --- start template query8.tpl query 27 in stream 1 -select /* TPC-DS query8.tpl 0.63 */ s_store_name - ,sum(ss_net_profit) - from store_sales - ,date_dim - ,store, - (select ca_zip - from ( - SELECT substring(ca_zip,1,5) ca_zip - FROM customer_address - WHERE substring(ca_zip,1,5) IN ( - '31269','62978','24771','75908','26633','58807', - '91823','46238','46217','30888','82296', - '15031','61670','59715','98486','53342', - '35183','73499','58660','16750','46584', - '49175','17240','73061','40114','52140', - '41731','21764','26217','22312','40718', - '27875','26621','67481','19205','66059', - '56942','60701','98608','80016','68865', - '82808','57915','95643','47035','44491', - '78926','15630','46264','70791','41486', - '48014','20084','25385','40531','21011', - '91104','29457','20842','10447','40637', - '35745','41195','24747','97386','54687', - '25476','61167','57566','65744','34121', - '54959','86192','63258','80664','20951', - '10813','41908','76419','47735','80990', - '92768','27935','63216','91444','35227', - '52389','87666','25920','72443','53615', - '32332','70064','43058','75022','39293', - '11398','79515','94539','95825','54591', - '41684','20429','65088','16558','94163', - '63673','30818','92386','87118','87601', - '38203','19047','44848','68948','42477', - '79734','98424','93565','81591','16200', - '65720','56494','38236','27711','18651', - '68920','69560','62567','61847','23900', - '77840','10540','98865','71716','36214', - '56403','41470','37409','24517','99038', - '12449','40682','38379','20090','41321', - '24534','63217','48584','66954','76196', - '20435','14513','88692','59058','50177', - '97620','43525','10563','27604','33815', - '80134','19911','19558','63626','66867', - '56643','79911','95326','92834','86481', - '47209','31274','45962','36409','12235', - '24887','98953','31123','92823','55662', - '23220','91799','10234','59327','10778', - '38878','50756','19340','96761','61794', - '19200','91732','86726','49274','95286', - '70120','10774','16362','19629','84302', - '55826','64497','81089','69969','86323', - '16203','70828','37735','84782','26226', - '25155','15054','24459','30254','96473', - '53553','62496','83336','68111','69856', - '19907','97815','13523','65881','46711', - '16620','95053','59072','53685','69865', - '13471','87339','82731','93521','49294', - '57454','83098','95213','70967','30424', - '43636','74877','27332','74396','54115', - '83816','92832','31942','92178','66192', - '25450','47951','65618','37587','57300', - '50936','18439','55603','73435','67730', - '79136','48046','42288','51727','93138', - '73315','28088','40487','34271','42118', - '78187','49747','57559','73675','39639', - '12395','18415','85347','52779','37364', - '88177','89232','92678','15721','29855', - '67332','11422','71634','95807','41451', - '60932','70205','95133','88461','14545', - '69194','38064','34275','90543','98442', - '43466','26349','87807','84040','57546', - '59693','60294','16669','74794','64728', - '14831','44796','29661','87115','93843', - '49261','10707','79281','84707','82761', - '79865','55364','88944','65426','92184', - '45993','73346','88551','14660','37541', - '42738','99844','74207','92947','30767', - '58667','57172','11787','51089','94496', - '88984','26912','28399','62632','24871', - '49485','50402','79324','63338','34202', - '37653','70307','45036','68885','69648', - '65231','28814','66838','29933','45684', - '83782','93023','72602','14311','95487', - '47057','77739','33708','71129','18050', - '91362','29764','68930','16213','14355', - '79995','67095','23389','69788','58036', - '17182','69533','91913','84814','32039', - '82983','61327','17017','68776','22961', - '55006','91792','81722','37087','26060', - '56454','90011','26724','24746') - intersect - select ca_zip - from (SELECT substring(ca_zip,1,5) ca_zip,count(*) cnt - FROM customer_address, customer - WHERE ca_address_sk = c_current_addr_sk and - c_preferred_cust_flag='Y' - group by ca_zip - having count(*) > 10)A1)A2) V1 - where ss_store_sk = s_store_sk - and ss_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 2000 - and (substring(s_zip,1,2) = substring(V1.ca_zip,1,2)) - group by s_store_name - order by s_store_name - limit 100; - --- end template query8.tpl query 27 in stream 1 --- start template query14a.tpl query 28 in stream 1 -with /* TPC-DS query14a.tpl 0.69 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1998 AND 1998 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1998 AND 1998 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1998 AND 1998 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as - (select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2) x) -, - results AS -(select channel, i_brand_id, i_class_id, i_category_id, sum(sales) sum_sales, sum(number_sales) number_sales - from ( - select 'store' channel, i_brand_id,i_class_id - ,i_category_id,sum(ss_quantity*ss_list_price) sales - , count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1998+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales) - union all - select 'catalog' channel, i_brand_id,i_class_id,i_category_id, sum(cs_quantity*cs_list_price) sales, count(*) number_sales - from catalog_sales - ,item - ,date_dim - where cs_item_sk in (select ss_item_sk from cross_items) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1998+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(cs_quantity*cs_list_price) > (select average_sales from avg_sales) - union all - select 'web' channel, i_brand_id,i_class_id,i_category_id, sum(ws_quantity*ws_list_price) sales , count(*) number_sales - from web_sales - ,item - ,date_dim - where ws_item_sk in (select ss_item_sk from cross_items) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1998+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ws_quantity*ws_list_price) > (select average_sales from avg_sales) - ) y - group by channel, i_brand_id,i_class_id,i_category_id) - - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales -from ( - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales from results - union - select channel, i_brand_id, i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id, i_class_id - union - select channel, i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id - union - select channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel - union - select null as channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results) z -order by channel, i_brand_id, i_class_id, i_category_id - limit 100; -with /* TPC-DS query14a.tpl 0.69 part2 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1998 AND 1998 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1998 AND 1998 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1998 AND 1998 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as -(select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2) x) - select this_year.channel ty_channel - ,this_year.i_brand_id ty_brand - ,this_year.i_class_id ty_class - ,this_year.i_category_id ty_category - ,this_year.sales ty_sales - ,this_year.number_sales ty_number_sales - ,last_year.channel ly_channel - ,last_year.i_brand_id ly_brand - ,last_year.i_class_id ly_class - ,last_year.i_category_id ly_category - ,last_year.sales ly_sales - ,last_year.number_sales ly_number_sales -from - (select 'store' channel, i_brand_id,i_class_id,i_category_id - ,sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1998 + 1 - and d_moy = 12 - and d_dom = 4) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) this_year, - (select 'store' channel, i_brand_id,i_class_id - ,i_category_id, sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1998 - and d_moy = 12 - and d_dom = 4) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) last_year - where this_year.i_brand_id= last_year.i_brand_id - and this_year.i_class_id = last_year.i_class_id - and this_year.i_category_id = last_year.i_category_id - order by this_year.channel, this_year.i_brand_id, this_year.i_class_id, this_year.i_category_id - limit 100; - --- end template query14a.tpl query 28 in stream 1 --- start template query50.tpl query 29 in stream 1 -select /* TPC-DS query50.tpl 0.60 */ - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 30) and - (sr_returned_date_sk - ss_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 60) and - (sr_returned_date_sk - ss_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 90) and - (sr_returned_date_sk - ss_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - store_sales - ,store_returns - ,store - ,date_dim d1 - ,date_dim d2 -where - d2.d_year = 2001 -and d2.d_moy = 8 -and ss_ticket_number = sr_ticket_number -and ss_item_sk = sr_item_sk -and ss_sold_date_sk = d1.d_date_sk -and sr_returned_date_sk = d2.d_date_sk -and ss_customer_sk = sr_customer_sk -and ss_store_sk = s_store_sk -group by - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -order by s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -limit 100; - --- end template query50.tpl query 29 in stream 1 --- start template query52.tpl query 30 in stream 1 -select /* TPC-DS query52.tpl 0.59 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_sales_price) ext_price - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=12 - and dt.d_year=2002 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,ext_price desc - ,brand_id -limit 100 ; - --- end template query52.tpl query 30 in stream 1 --- start template query81.tpl query 31 in stream 1 -with /* TPC-DS query81.tpl 0.37 */ customer_total_return as - (select cr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(cr_return_amt_inc_tax) as ctr_total_return - from catalog_returns - ,date_dim - ,customer_address - where cr_returned_date_sk = d_date_sk - and d_year =2002 - and cr_returning_addr_sk = ca_address_sk - group by cr_returning_customer_sk - ,ca_state ) - select c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'CT' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - limit 100; - --- end template query81.tpl query 31 in stream 1 --- start template query5a.tpl query 32 in stream 1 -with /* TPC-DS query5a.tpl 0.98 */ ssr as - (select s_store_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ss_store_sk as store_sk, - ss_sold_date_sk as date_sk, - ss_ext_sales_price as sales_price, - ss_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from store_sales - union all - select sr_store_sk as store_sk, - sr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - sr_return_amt as return_amt, - sr_net_loss as net_loss - from store_returns - ) salesreturns, - date_dim, - store - where date_sk = d_date_sk - and d_date between cast('2001-08-11' as date) - and dateadd(day,14,cast('2001-08-11' as date)) - and store_sk = s_store_sk - group by s_store_id) - , - csr as - (select cp_catalog_page_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select cs_catalog_page_sk as page_sk, - cs_sold_date_sk as date_sk, - cs_ext_sales_price as sales_price, - cs_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from catalog_sales - union all - select cr_catalog_page_sk as page_sk, - cr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - cr_return_amount as return_amt, - cr_net_loss as net_loss - from catalog_returns - ) salesreturns, - date_dim, - catalog_page - where date_sk = d_date_sk - and d_date between cast('2001-08-11' as date) - and dateadd(day,14,cast('2001-08-11' as date)) - and page_sk = cp_catalog_page_sk - group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ws_web_site_sk as wsr_web_site_sk, - ws_sold_date_sk as date_sk, - ws_ext_sales_price as sales_price, - ws_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from web_sales - union all - select ws_web_site_sk as wsr_web_site_sk, - wr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - wr_return_amt as return_amt, - wr_net_loss as net_loss - from web_returns left outer join web_sales on - ( wr_item_sk = ws_item_sk - and wr_order_number = ws_order_number) - ) salesreturns, - date_dim, - web_site - where date_sk = d_date_sk - and d_date between cast('2001-08-11' as date) - and dateadd(day,14,cast('2001-08-11' as date)) - and wsr_web_site_sk = web_site_sk - group by web_site_id) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || s_store_id as id - , sales - , returns - , (profit - profit_loss) as profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || cp_catalog_page_id as id - , sales - , returns - , (profit - profit_loss) as profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , (profit - profit_loss) as profit - from wsr - ) x - group by channel, id) - select channel, id, sales, returns, profit from ( - select channel, id, sales, returns, profit from results - union - select channel, null as id, sum(sales), sum(returns), sum(profit) from results group by channel - union - select null as channel, null as id, sum(sales), sum(returns), sum(profit) from results) foo -order by channel, id -limit 100; - --- end template query5a.tpl query 32 in stream 1 --- start template query26.tpl query 33 in stream 1 -select /* TPC-DS query26.tpl 0.85 */ i_item_id, - avg(cs_quantity) agg1, - avg(cs_list_price) agg2, - avg(cs_coupon_amt) agg3, - avg(cs_sales_price) agg4 - from catalog_sales, customer_demographics, date_dim, item, promotion - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd_demo_sk and - cs_promo_sk = p_promo_sk and - cd_gender = 'F' and - cd_marital_status = 'D' and - cd_education_status = 'Secondary' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 1999 - group by i_item_id - order by i_item_id - limit 100; - --- end template query26.tpl query 33 in stream 1 --- start template query57.tpl query 34 in stream 1 -with /* TPC-DS query57.tpl 0.70 */ v1 as( - select i_category, i_brand, - cc_name, - d_year, d_moy, - sum(cs_sales_price) sum_sales, - avg(sum(cs_sales_price)) over - (partition by i_category, i_brand, - cc_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - cc_name - order by d_year, d_moy) rn - from item, catalog_sales, date_dim, call_center - where cs_item_sk = i_item_sk and - cs_sold_date_sk = d_date_sk and - cc_call_center_sk= cs_call_center_sk and - ( - d_year = 1999 or - ( d_year = 1999-1 and d_moy =12) or - ( d_year = 1999+1 and d_moy =1) - ) - group by i_category, i_brand, - cc_name , d_year, d_moy), - v2 as( - select v1.cc_name - ,v1.d_year, v1.d_moy - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1. cc_name = v1_lag. cc_name and - v1. cc_name = v1_lead. cc_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 1999 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, psum - limit 100; - --- end template query57.tpl query 34 in stream 1 --- start template query82.tpl query 35 in stream 1 -select /* TPC-DS query82.tpl 0.67 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, store_sales - where i_current_price between 26 and 26+30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('2002-06-26' as date) and dateadd(day,60,cast('2002-06-26' as date)) - and i_manufact_id in (889,568,806,360) - and inv_quantity_on_hand between 100 and 500 - and ss_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query82.tpl query 35 in stream 1 --- start template query69.tpl query 36 in stream 1 -select /* TPC-DS query69.tpl 0.28 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_state in ('TX','OH','VA') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 4 and 4+2) and - (not exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 4 and 4+2) and - not exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 4 and 4+2)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - limit 100; - --- end template query69.tpl query 36 in stream 1 --- start template query54.tpl query 37 in stream 1 -with /* TPC-DS query54.tpl 0.81 */ my_customers as ( - select distinct c_customer_sk - , c_current_addr_sk - from - ( select cs_sold_date_sk sold_date_sk, - cs_bill_customer_sk customer_sk, - cs_item_sk item_sk - from catalog_sales - union all - select ws_sold_date_sk sold_date_sk, - ws_bill_customer_sk customer_sk, - ws_item_sk item_sk - from web_sales - ) cs_or_ws_sales, - item, - date_dim, - customer - where sold_date_sk = d_date_sk - and item_sk = i_item_sk - and i_category = 'Electronics' - and i_class = 'automotive' - and c_customer_sk = cs_or_ws_sales.customer_sk - and d_moy = 3 - and d_year = 2002 - ) - , my_revenue as ( - select c_customer_sk, - sum(ss_ext_sales_price) as revenue - from my_customers, - store_sales, - customer_address, - store, - date_dim - where c_current_addr_sk = ca_address_sk - and ca_county = s_county - and ca_state = s_state - and ss_sold_date_sk = d_date_sk - and c_customer_sk = ss_customer_sk - and d_month_seq between (select distinct d_month_seq+1 - from date_dim where d_year = 2002 and d_moy = 3) - and (select distinct d_month_seq+3 - from date_dim where d_year = 2002 and d_moy = 3) - group by c_customer_sk - ) - , segments as - (select cast((revenue/50) as int) as segment - from my_revenue - ) - select segment, count(*) as num_customers, segment*50 as segment_base - from segments - group by segment - order by segment, num_customers - limit 100; - --- end template query54.tpl query 37 in stream 1 --- start template query61.tpl query 38 in stream 1 -select /* TPC-DS query61.tpl 0.97 */ promotions,total,cast(promotions as decimal(15,4))/cast(total as decimal(15,4))*100 -from - (select sum(ss_ext_sales_price) promotions - from store_sales - ,store - ,promotion - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_promo_sk = p_promo_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -7 - and i_category = 'Sports' - and (p_channel_dmail = 'Y' or p_channel_email = 'Y' or p_channel_tv = 'Y') - and s_gmt_offset = -7 - and d_year = 2000 - and d_moy = 11) promotional_sales, - (select sum(ss_ext_sales_price) total - from store_sales - ,store - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -7 - and i_category = 'Sports' - and s_gmt_offset = -7 - and d_year = 2000 - and d_moy = 11) all_sales -order by promotions, total -limit 100; - --- end template query61.tpl query 38 in stream 1 --- start template query88.tpl query 39 in stream 1 -select /* TPC-DS query88.tpl 0.66 */ * -from - (select count(*) h8_30_to_9 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s1, - (select count(*) h9_to_9_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s2, - (select count(*) h9_30_to_10 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s3, - (select count(*) h10_to_10_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s4, - (select count(*) h10_30_to_11 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s5, - (select count(*) h11_to_11_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s6, - (select count(*) h11_30_to_12 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s7, - (select count(*) h12_to_12_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 12 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s8 -; - --- end template query88.tpl query 39 in stream 1 --- start template query18a.tpl query 40 in stream 1 -with /* TPC-DS query18a.tpl 0.90 */ results as - (select i_item_id, - ca_country, - ca_state, - ca_county, - cast(cs_quantity as decimal(12,2)) agg1, - cast(cs_list_price as decimal(12,2)) agg2, - cast(cs_coupon_amt as decimal(12,2)) agg3, - cast(cs_sales_price as decimal(12,2)) agg4, - cast(cs_net_profit as decimal(12,2)) agg5, - cast(c_birth_year as decimal(12,2)) agg6, - cast(cd1.cd_dep_count as decimal(12,2)) agg7 - from catalog_sales, customer_demographics cd1, customer_demographics cd2, customer, customer_address, date_dim, item - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd1.cd_demo_sk and - cs_bill_customer_sk = c_customer_sk and - cd1.cd_gender = 'F' and - cd1.cd_education_status = 'Unknown' and - c_current_cdemo_sk = cd2.cd_demo_sk and - c_current_addr_sk = ca_address_sk and - c_birth_month in (12,10,4,9,7,8) and - d_year = 2002 and - ca_state in ('WV','NC','MI','GA','AR','LA','KS') - ) - select i_item_id, ca_country, ca_state, ca_county, agg1, agg2, agg3, agg4, agg5, agg6, agg7 - from ( - select i_item_id, ca_country, ca_state, ca_county, avg(agg1) agg1, - avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state, ca_county - union all - select i_item_id, ca_country, ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state - union all - select i_item_id, ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country - union all - select i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - ) foo - order by ca_country, ca_state, ca_county, i_item_id - limit 100; - --- end template query18a.tpl query 40 in stream 1 --- start template query94.tpl query 41 in stream 1 -select /* TPC-DS query94.tpl 0.17 */ - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2001-2-01' and - dateadd(day,60,cast('2001-2-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'TX' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and exists (select * - from web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) -and not exists(select * - from web_returns wr1 - where ws1.ws_order_number = wr1.wr_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query94.tpl query 41 in stream 1 --- start template query35a.tpl query 42 in stream 1 -select /* TPC-DS query35a.tpl 0.47 */ - ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - count(*) cnt1, - max(cd_dep_count), - max(cd_dep_count), - avg(cd_dep_count), - cd_dep_employed_count, - count(*) cnt2, - max(cd_dep_employed_count), - max(cd_dep_employed_count), - avg(cd_dep_employed_count), - cd_dep_college_count, - count(*) cnt3, - max(cd_dep_college_count), - max(cd_dep_college_count), - avg(cd_dep_college_count) - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2000 and - d_qoy < 4) and - exists (select * from - (select ws_bill_customer_sk customsk - from web_sales,date_dim - where - ws_sold_date_sk = d_date_sk and - d_year = 2000 and - d_qoy < 4 - union all - select cs_ship_customer_sk customsk - from catalog_sales,date_dim - where - cs_sold_date_sk = d_date_sk and - d_year = 2000 and - d_qoy < 4)x - where x.customsk = c.c_customer_sk) - group by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - limit 100; - --- end template query35a.tpl query 42 in stream 1 --- start template query68.tpl query 43 in stream 1 -select /* TPC-DS query68.tpl 0.95 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,extended_price - ,extended_tax - ,list_price - from (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_ext_sales_price) extended_price - ,sum(ss_ext_list_price) list_price - ,sum(ss_ext_tax) extended_tax - from store_sales - ,date_dim - ,store - ,household_demographics - ,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_dep_count = 4 or - household_demographics.hd_vehicle_count= 3) - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_city in ('Concord','Hopewell') - group by ss_ticket_number - ,ss_customer_sk - ,ss_addr_sk,ca_city) dn - ,customer - ,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,ss_ticket_number - limit 100; - --- end template query68.tpl query 43 in stream 1 --- start template query24.tpl query 44 in stream 1 -with /* TPC-DS query24.tpl 0.92 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_ext_sales_price) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip -and s_market_id=10 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'moccasin' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; -with /* TPC-DS query24.tpl 0.92 part2 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_ext_sales_price) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip - and s_market_id = 10 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'lime' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; - --- end template query24.tpl query 44 in stream 1 --- start template query75.tpl query 45 in stream 1 -WITH /* TPC-DS query75.tpl 0.3 */ all_sales AS ( - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,SUM(sales_cnt) AS sales_cnt - ,SUM(sales_amt) AS sales_amt - FROM (SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,cs_quantity - COALESCE(cr_return_quantity,0) AS sales_cnt - ,cs_ext_sales_price - COALESCE(cr_return_amount,0.0) AS sales_amt - FROM catalog_sales JOIN item ON i_item_sk=cs_item_sk - JOIN date_dim ON d_date_sk=cs_sold_date_sk - LEFT JOIN catalog_returns ON (cs_order_number=cr_order_number - AND cs_item_sk=cr_item_sk) - WHERE i_category='Home' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ss_quantity - COALESCE(sr_return_quantity,0) AS sales_cnt - ,ss_ext_sales_price - COALESCE(sr_return_amt,0.0) AS sales_amt - FROM store_sales JOIN item ON i_item_sk=ss_item_sk - JOIN date_dim ON d_date_sk=ss_sold_date_sk - LEFT JOIN store_returns ON (ss_ticket_number=sr_ticket_number - AND ss_item_sk=sr_item_sk) - WHERE i_category='Home' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ws_quantity - COALESCE(wr_return_quantity,0) AS sales_cnt - ,ws_ext_sales_price - COALESCE(wr_return_amt,0.0) AS sales_amt - FROM web_sales JOIN item ON i_item_sk=ws_item_sk - JOIN date_dim ON d_date_sk=ws_sold_date_sk - LEFT JOIN web_returns ON (ws_order_number=wr_order_number - AND ws_item_sk=wr_item_sk) - WHERE i_category='Home') sales_detail - GROUP BY d_year, i_brand_id, i_class_id, i_category_id, i_manufact_id) - SELECT prev_yr.d_year AS prev_year - ,curr_yr.d_year AS year - ,curr_yr.i_brand_id - ,curr_yr.i_class_id - ,curr_yr.i_category_id - ,curr_yr.i_manufact_id - ,prev_yr.sales_cnt AS prev_yr_cnt - ,curr_yr.sales_cnt AS curr_yr_cnt - ,curr_yr.sales_cnt-prev_yr.sales_cnt AS sales_cnt_diff - ,curr_yr.sales_amt-prev_yr.sales_amt AS sales_amt_diff - FROM all_sales curr_yr, all_sales prev_yr - WHERE curr_yr.i_brand_id=prev_yr.i_brand_id - AND curr_yr.i_class_id=prev_yr.i_class_id - AND curr_yr.i_category_id=prev_yr.i_category_id - AND curr_yr.i_manufact_id=prev_yr.i_manufact_id - AND curr_yr.d_year=2000 - AND prev_yr.d_year=2000-1 - AND CAST(curr_yr.sales_cnt AS DECIMAL(17,2))/CAST(prev_yr.sales_cnt AS DECIMAL(17,2))<0.9 - ORDER BY sales_cnt_diff,sales_amt_diff - limit 100; - --- end template query75.tpl query 45 in stream 1 --- start template query11.tpl query 46 in stream 1 -with /* TPC-DS query11.tpl 0.51 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ss_ext_list_price-ss_ext_discount_amt) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ws_ext_list_price-ws_ext_discount_amt) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_preferred_cust_flag - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 2001 - and t_s_secyear.dyear = 2001+1 - and t_w_firstyear.dyear = 2001 - and t_w_secyear.dyear = 2001+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else 0.0 end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else 0.0 end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_preferred_cust_flag -limit 100; - --- end template query11.tpl query 46 in stream 1 --- start template query67a.tpl query 47 in stream 1 -with /* TPC-DS query67a.tpl 0.35 */ results as -( select i_category ,i_class ,i_brand ,i_product_name ,d_year ,d_qoy ,d_moy ,s_store_id - ,sum(coalesce(ss_sales_price*ss_quantity,0)) sumsales - from store_sales ,date_dim ,store ,item - where ss_sold_date_sk=d_date_sk - and ss_item_sk=i_item_sk - and ss_store_sk = s_store_sk - and d_month_seq between 1200 and 1200 + 11 - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy,s_store_id) - , - results_rollup as - (select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, s_store_id, sumsales - from results - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy - union all - select i_category, i_class, i_brand, i_product_name, d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year - union all - select i_category, i_class, i_brand, i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name - union all - select i_category, i_class, i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand - union all - select i_category, i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class - union all - select i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category - union all - select null i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results) - - select * -from (select i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rank() over (partition by i_category order by sumsales desc) rk - from results_rollup) dw2 -where rk <= 100 -order by i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rk -limit 100; - --- end template query67a.tpl query 47 in stream 1 --- start template query9.tpl query 48 in stream 1 -select /* TPC-DS query9.tpl 0.49 */ case when (select count(*) - from store_sales - where ss_quantity between 1 and 20) > 109221918 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 1 and 20) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 1 and 20) end bucket1 , - case when (select count(*) - from store_sales - where ss_quantity between 21 and 40) > 97086998 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 21 and 40) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 21 and 40) end bucket2, - case when (select count(*) - from store_sales - where ss_quantity between 41 and 60) > 91922583 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 41 and 60) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 41 and 60) end bucket3, - case when (select count(*) - from store_sales - where ss_quantity between 61 and 80) > 19390379 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 61 and 80) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 61 and 80) end bucket4, - case when (select count(*) - from store_sales - where ss_quantity between 81 and 100) > 91543850 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 81 and 100) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 81 and 100) end bucket5 -from reason -where r_reason_sk = 1 -; - --- end template query9.tpl query 48 in stream 1 --- start template query25.tpl query 49 in stream 1 -select /* TPC-DS query25.tpl 0.9 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,max(ss_net_profit) as store_sales_profit - ,max(sr_net_loss) as store_returns_loss - ,max(cs_net_profit) as catalog_sales_profit - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 1998 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 10 - and d2.d_year = 1998 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_moy between 4 and 10 - and d3.d_year = 1998 - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query25.tpl query 49 in stream 1 --- start template query37.tpl query 50 in stream 1 -select /* TPC-DS query37.tpl 0.31 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, catalog_sales - where i_current_price between 70 and 70 + 30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('2001-01-18' as date) and dateadd(day,60,cast('2001-01-18' as date)) - and i_manufact_id in (678,902,874,801) - and inv_quantity_on_hand between 100 and 500 - and cs_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query37.tpl query 50 in stream 1 --- start template query86a.tpl query 51 in stream 1 -with /* TPC-DS query86a.tpl 0.11 */ results as -( select sum(ws_net_paid) as total_sum, i_category, i_class, 0 as g_category, 0 as g_class - from - web_sales - ,date_dim d1 - ,item - where - d1.d_month_seq between 1208 and 1208+11 - and d1.d_date_sk = ws_sold_date_sk - and i_item_sk = ws_item_sk - group by i_category,i_class - ) , - - results_rollup as -( select total_sum ,i_category ,i_class, g_category, g_class, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum, i_category, NULL as i_class, 0 as g_category, 1 as g_class, 1 as lochierarchy from results group by i_category - union - select sum(total_sum) as total_sum, NULL as i_category, NULL as i_class, 1 as g_category, 1 as g_class, 2 as lochierarchy from results) - select - total_sum ,i_category ,i_class, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_class = 0 then i_category end - order by total_sum desc) as rank_within_parent - from - results_rollup - order by - lochierarchy desc, - case when lochierarchy = 0 then i_category end, - rank_within_parent - limit 100; - --- end template query86a.tpl query 51 in stream 1 --- start template query4.tpl query 52 in stream 1 -with /* TPC-DS query4.tpl 0.93 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(((ss_ext_list_price-ss_ext_wholesale_cost-ss_ext_discount_amt)+ss_ext_sales_price)/2) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((cs_ext_list_price-cs_ext_wholesale_cost-cs_ext_discount_amt)+cs_ext_sales_price)/2) ) year_total - ,'c' sale_type - from customer - ,catalog_sales - ,date_dim - where c_customer_sk = cs_bill_customer_sk - and cs_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year -union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((ws_ext_list_price-ws_ext_wholesale_cost-ws_ext_discount_amt)+ws_ext_sales_price)/2) ) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_preferred_cust_flag - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_c_firstyear - ,year_total t_c_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_c_secyear.customer_id - and t_s_firstyear.customer_id = t_c_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_c_firstyear.sale_type = 'c' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_c_secyear.sale_type = 'c' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 2001 - and t_s_secyear.dyear = 2001+1 - and t_c_firstyear.dyear = 2001 - and t_c_secyear.dyear = 2001+1 - and t_w_firstyear.dyear = 2001 - and t_w_secyear.dyear = 2001+1 - and t_s_firstyear.year_total > 0 - and t_c_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_preferred_cust_flag -limit 100; - --- end template query4.tpl query 52 in stream 1 --- start template query60.tpl query 53 in stream 1 -with /* TPC-DS query60.tpl 0.29 */ ss as ( - select - i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Shoes')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 10 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id), - cs as ( - select - i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Shoes')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 10 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id), - ws as ( - select - i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Shoes')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 10 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id) - select - i_item_id -,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by i_item_id - ,total_sales - limit 100; - --- end template query60.tpl query 53 in stream 1 --- start template query97.tpl query 54 in stream 1 -with /* TPC-DS query97.tpl 0.38 */ ssci as ( -select ss_customer_sk customer_sk - ,ss_item_sk item_sk -from store_sales,date_dim -where ss_sold_date_sk = d_date_sk - and d_month_seq between 1201 and 1201 + 11 -group by ss_customer_sk - ,ss_item_sk), -csci as( - select cs_bill_customer_sk customer_sk - ,cs_item_sk item_sk -from catalog_sales,date_dim -where cs_sold_date_sk = d_date_sk - and d_month_seq between 1201 and 1201 + 11 -group by cs_bill_customer_sk - ,cs_item_sk) - select sum(case when ssci.customer_sk is not null and csci.customer_sk is null then 1 else 0 end) store_only - ,sum(case when ssci.customer_sk is null and csci.customer_sk is not null then 1 else 0 end) catalog_only - ,sum(case when ssci.customer_sk is not null and csci.customer_sk is not null then 1 else 0 end) store_and_catalog -from ssci full outer join csci on (ssci.customer_sk=csci.customer_sk - and ssci.item_sk = csci.item_sk) -limit 100; - --- end template query97.tpl query 54 in stream 1 --- start template query33.tpl query 55 in stream 1 -with /* TPC-DS query33.tpl 0.22 */ ss as ( - select - i_manufact_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Electronics')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 2 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id), - cs as ( - select - i_manufact_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Electronics')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 2 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id), - ws as ( - select - i_manufact_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Electronics')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 2 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id) - select i_manufact_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_manufact_id - order by total_sales -limit 100; - --- end template query33.tpl query 55 in stream 1 --- start template query79.tpl query 56 in stream 1 -select /* TPC-DS query79.tpl 0.89 */ - c_last_name,c_first_name,substring(s_city,1,30),ss_ticket_number,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,store.s_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (household_demographics.hd_dep_count = 4 or household_demographics.hd_vehicle_count > 1) - and date_dim.d_dow = 1 - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_number_employees between 200 and 295 - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,store.s_city) ms,customer - where ss_customer_sk = c_customer_sk - order by c_last_name,c_first_name,substring(s_city,1,30), profit -limit 100; - --- end template query79.tpl query 56 in stream 1 --- start template query43.tpl query 57 in stream 1 -select /* TPC-DS query43.tpl 0.15 */ s_store_name, s_store_id, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from date_dim, store_sales, store - where d_date_sk = ss_sold_date_sk and - s_store_sk = ss_store_sk and - s_gmt_offset = -5 and - d_year = 2002 - group by s_store_name, s_store_id - order by s_store_name, s_store_id,sun_sales,mon_sales,tue_sales,wed_sales,thu_sales,fri_sales,sat_sales - limit 100; - --- end template query43.tpl query 57 in stream 1 --- start template query80a.tpl query 58 in stream 1 -with /* TPC-DS query80a.tpl 0.6 */ ssr as - (select s_store_id as store_id, - sum(ss_ext_sales_price) as sales, - sum(coalesce(sr_return_amt, 0)) as returns, - sum(ss_net_profit - coalesce(sr_net_loss, 0)) as profit - from store_sales left outer join store_returns on - (ss_item_sk = sr_item_sk and ss_ticket_number = sr_ticket_number), - date_dim, - store, - item, - promotion - where ss_sold_date_sk = d_date_sk - and d_date between cast('1998-08-23' as date) - and dateadd(day,30,cast('1998-08-23' as date)) - and ss_store_sk = s_store_sk - and ss_item_sk = i_item_sk - and i_current_price > 50 - and ss_promo_sk = p_promo_sk - and p_channel_tv = 'N' - group by s_store_id) - , - csr as - (select cp_catalog_page_id as catalog_page_id, - sum(cs_ext_sales_price) as sales, - sum(coalesce(cr_return_amount, 0)) as returns, - sum(cs_net_profit - coalesce(cr_net_loss, 0)) as profit - from catalog_sales left outer join catalog_returns on - (cs_item_sk = cr_item_sk and cs_order_number = cr_order_number), - date_dim, - catalog_page, - item, - promotion - where cs_sold_date_sk = d_date_sk - and d_date between cast('1998-08-23' as date) - and dateadd(day,30,cast('1998-08-23' as date)) - and cs_catalog_page_sk = cp_catalog_page_sk - and cs_item_sk = i_item_sk - and i_current_price > 50 - and cs_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(ws_ext_sales_price) as sales, - sum(coalesce(wr_return_amt, 0)) as returns, - sum(ws_net_profit - coalesce(wr_net_loss, 0)) as profit - from web_sales left outer join web_returns on - (ws_item_sk = wr_item_sk and ws_order_number = wr_order_number), - date_dim, - web_site, - item, - promotion - where ws_sold_date_sk = d_date_sk - and d_date between cast('1998-08-23' as date) - and dateadd(day,30,cast('1998-08-23' as date)) - and ws_web_site_sk = web_site_sk - and ws_item_sk = i_item_sk - and i_current_price > 50 - and ws_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by web_site_id) -, -results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || store_id as id - , sales - , returns - , profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || catalog_page_id as id - , sales - , returns - , profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , profit - from wsr - ) x - group by channel, id) - - select channel - , id - , sales - , returns - , profit - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results - ) foo - order by channel, id - limit 100; - --- end template query80a.tpl query 58 in stream 1 --- start template query93.tpl query 59 in stream 1 -select /* TPC-DS query93.tpl 0.52 */ ss_customer_sk - ,sum(act_sales) sumsales - from (select ss_item_sk - ,ss_ticket_number - ,ss_customer_sk - ,case when sr_return_quantity is not null then (ss_quantity-sr_return_quantity)*ss_sales_price - else (ss_quantity*ss_sales_price) end act_sales - from store_sales left outer join store_returns on (sr_item_sk = ss_item_sk - and sr_ticket_number = ss_ticket_number) - ,reason - where sr_reason_sk = r_reason_sk - and r_reason_desc = 'reason 47') t - group by ss_customer_sk - order by sumsales, ss_customer_sk -limit 100; - --- end template query93.tpl query 59 in stream 1 --- start template query31.tpl query 60 in stream 1 -with /* TPC-DS query31.tpl 0.50 */ ss as - (select ca_county,d_qoy, d_year,sum(ss_ext_sales_price) as store_sales - from store_sales,date_dim,customer_address - where ss_sold_date_sk = d_date_sk - and ss_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year), - ws as - (select ca_county,d_qoy, d_year,sum(ws_ext_sales_price) as web_sales - from web_sales,date_dim,customer_address - where ws_sold_date_sk = d_date_sk - and ws_bill_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year) - select - ss1.ca_county - ,ss1.d_year - ,ws2.web_sales/ws1.web_sales web_q1_q2_increase - ,ss2.store_sales/ss1.store_sales store_q1_q2_increase - ,ws3.web_sales/ws2.web_sales web_q2_q3_increase - ,ss3.store_sales/ss2.store_sales store_q2_q3_increase - from - ss ss1 - ,ss ss2 - ,ss ss3 - ,ws ws1 - ,ws ws2 - ,ws ws3 - where - ss1.d_qoy = 1 - and ss1.d_year = 2000 - and ss1.ca_county = ss2.ca_county - and ss2.d_qoy = 2 - and ss2.d_year = 2000 - and ss2.ca_county = ss3.ca_county - and ss3.d_qoy = 3 - and ss3.d_year = 2000 - and ss1.ca_county = ws1.ca_county - and ws1.d_qoy = 1 - and ws1.d_year = 2000 - and ws1.ca_county = ws2.ca_county - and ws2.d_qoy = 2 - and ws2.d_year = 2000 - and ws1.ca_county = ws3.ca_county - and ws3.d_qoy = 3 - and ws3.d_year =2000 - and case when ws1.web_sales > 0 then ws2.web_sales/ws1.web_sales else null end - > case when ss1.store_sales > 0 then ss2.store_sales/ss1.store_sales else null end - and case when ws2.web_sales > 0 then ws3.web_sales/ws2.web_sales else null end - > case when ss2.store_sales > 0 then ss3.store_sales/ss2.store_sales else null end - order by web_q1_q2_increase; - --- end template query31.tpl query 60 in stream 1 --- start template query47.tpl query 61 in stream 1 -with /* TPC-DS query47.tpl 0.42 */ v1 as( - select i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, - s_store_name, s_company_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - s_store_name, s_company_name - order by d_year, d_moy) rn - from item, store_sales, date_dim, store - where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - ( - d_year = 1999 or - ( d_year = 1999-1 and d_moy =12) or - ( d_year = 1999+1 and d_moy =1) - ) - group by i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy), - v2 as( - select v1.i_category, v1.i_brand - ,v1.d_year - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1.s_store_name = v1_lag.s_store_name and - v1.s_store_name = v1_lead.s_store_name and - v1.s_company_name = v1_lag.s_company_name and - v1.s_company_name = v1_lead.s_company_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 1999 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, sum_sales - limit 100; - --- end template query47.tpl query 61 in stream 1 --- start template query17.tpl query 62 in stream 1 -select /* TPC-DS query17.tpl 0.41 */ i_item_id - ,i_item_desc - ,s_state - ,count(ss_quantity) as store_sales_quantitycount - ,avg(ss_quantity) as store_sales_quantityave - ,stddev_samp(ss_quantity) as store_sales_quantitystdev - ,stddev_samp(ss_quantity)/avg(ss_quantity) as store_sales_quantitycov - ,count(sr_return_quantity) as store_returns_quantitycount - ,avg(sr_return_quantity) as store_returns_quantityave - ,stddev_samp(sr_return_quantity) as store_returns_quantitystdev - ,stddev_samp(sr_return_quantity)/avg(sr_return_quantity) as store_returns_quantitycov - ,count(cs_quantity) as catalog_sales_quantitycount ,avg(cs_quantity) as catalog_sales_quantityave - ,stddev_samp(cs_quantity) as catalog_sales_quantitystdev - ,stddev_samp(cs_quantity)/avg(cs_quantity) as catalog_sales_quantitycov - from store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where d1.d_quarter_name = '1999Q1' - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_quarter_name in ('1999Q1','1999Q2','1999Q3') - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_quarter_name in ('1999Q1','1999Q2','1999Q3') - group by i_item_id - ,i_item_desc - ,s_state - order by i_item_id - ,i_item_desc - ,s_state -limit 100; - --- end template query17.tpl query 62 in stream 1 --- start template query19.tpl query 63 in stream 1 -select /* TPC-DS query19.tpl 0.8 */ i_brand_id brand_id, i_brand brand, i_manufact_id, i_manufact, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item,customer,customer_address,store - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=1 - and d_moy=12 - and d_year=1999 - and ss_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and substring(ca_zip,1,5) <> substring(s_zip,1,5) - and ss_store_sk = s_store_sk - group by i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact - order by ext_price desc - ,i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact -limit 100 ; - --- end template query19.tpl query 63 in stream 1 --- start template query1.tpl query 64 in stream 1 -with /* TPC-DS query1.tpl 0.12 */ customer_total_return as -(select sr_customer_sk as ctr_customer_sk -,sr_store_sk as ctr_store_sk -,sum(SR_RETURN_AMT_INC_TAX) as ctr_total_return -from store_returns -,date_dim -where sr_returned_date_sk = d_date_sk -and d_year =1998 -group by sr_customer_sk -,sr_store_sk) - select c_customer_id -from customer_total_return ctr1 -,store -,customer -where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 -from customer_total_return ctr2 -where ctr1.ctr_store_sk = ctr2.ctr_store_sk) -and s_store_sk = ctr1.ctr_store_sk -and s_state = 'OK' -and ctr1.ctr_customer_sk = c_customer_sk -order by c_customer_id -limit 100; - --- end template query1.tpl query 64 in stream 1 --- start template query64.tpl query 65 in stream 1 -with /* TPC-DS query64.tpl 0.20 */ cs_ui as - (select cs_item_sk - ,sum(cs_ext_list_price) as sale,sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit) as refund - from catalog_sales - ,catalog_returns - where cs_item_sk = cr_item_sk - and cs_order_number = cr_order_number - group by cs_item_sk - having sum(cs_ext_list_price)>2*sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit)), -cross_sales as - (select i_product_name product_name - ,i_item_sk item_sk - ,s_store_name store_name - ,s_zip store_zip - ,ad1.ca_street_number b_street_number - ,ad1.ca_street_name b_street_name - ,ad1.ca_city b_city - ,ad1.ca_zip b_zip - ,ad2.ca_street_number c_street_number - ,ad2.ca_street_name c_street_name - ,ad2.ca_city c_city - ,ad2.ca_zip c_zip - ,d1.d_year as syear - ,d2.d_year as fsyear - ,d3.d_year s2year - ,count(*) cnt - ,sum(ss_wholesale_cost) s1 - ,sum(ss_list_price) s2 - ,sum(ss_coupon_amt) s3 - FROM store_sales - ,store_returns - ,cs_ui - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,customer - ,customer_demographics cd1 - ,customer_demographics cd2 - ,promotion - ,household_demographics hd1 - ,household_demographics hd2 - ,customer_address ad1 - ,customer_address ad2 - ,income_band ib1 - ,income_band ib2 - ,item - WHERE ss_store_sk = s_store_sk AND - ss_sold_date_sk = d1.d_date_sk AND - ss_customer_sk = c_customer_sk AND - ss_cdemo_sk= cd1.cd_demo_sk AND - ss_hdemo_sk = hd1.hd_demo_sk AND - ss_addr_sk = ad1.ca_address_sk and - ss_item_sk = i_item_sk and - ss_item_sk = sr_item_sk and - ss_ticket_number = sr_ticket_number and - ss_item_sk = cs_ui.cs_item_sk and - c_current_cdemo_sk = cd2.cd_demo_sk AND - c_current_hdemo_sk = hd2.hd_demo_sk AND - c_current_addr_sk = ad2.ca_address_sk and - c_first_sales_date_sk = d2.d_date_sk and - c_first_shipto_date_sk = d3.d_date_sk and - ss_promo_sk = p_promo_sk and - hd1.hd_income_band_sk = ib1.ib_income_band_sk and - hd2.hd_income_band_sk = ib2.ib_income_band_sk and - cd1.cd_marital_status <> cd2.cd_marital_status and - i_color in ('snow','midnight','azure','antique','ghost','slate') and - i_current_price between 47 and 47 + 10 and - i_current_price between 47 + 1 and 47 + 15 -group by i_product_name - ,i_item_sk - ,s_store_name - ,s_zip - ,ad1.ca_street_number - ,ad1.ca_street_name - ,ad1.ca_city - ,ad1.ca_zip - ,ad2.ca_street_number - ,ad2.ca_street_name - ,ad2.ca_city - ,ad2.ca_zip - ,d1.d_year - ,d2.d_year - ,d3.d_year -) -select cs1.product_name - ,cs1.store_name - ,cs1.store_zip - ,cs1.b_street_number - ,cs1.b_street_name - ,cs1.b_city - ,cs1.b_zip - ,cs1.c_street_number - ,cs1.c_street_name - ,cs1.c_city - ,cs1.c_zip - ,cs1.syear - ,cs1.cnt - ,cs1.s1 as s11 - ,cs1.s2 as s21 - ,cs1.s3 as s31 - ,cs2.s1 as s12 - ,cs2.s2 as s22 - ,cs2.s3 as s32 - ,cs2.syear - ,cs2.cnt -from cross_sales cs1,cross_sales cs2 -where cs1.item_sk=cs2.item_sk and - cs1.syear = 2001 and - cs2.syear = 2001 + 1 and - cs2.cnt <= cs1.cnt and - cs1.store_name = cs2.store_name and - cs1.store_zip = cs2.store_zip -order by cs1.product_name - ,cs1.store_name - ,cs2.cnt - ,cs1.s1 - ,cs2.s1; - --- end template query64.tpl query 65 in stream 1 --- start template query53.tpl query 66 in stream 1 -select /* TPC-DS query53.tpl 0.88 */ * from -(select i_manufact_id, -sum(ss_sales_price) sum_sales, -avg(sum(ss_sales_price)) over (partition by i_manufact_id) avg_quarterly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and -ss_sold_date_sk = d_date_sk and -ss_store_sk = s_store_sk and -d_month_seq in (1177,1177+1,1177+2,1177+3,1177+4,1177+5,1177+6,1177+7,1177+8,1177+9,1177+10,1177+11) and -((i_category in ('Books','Children','Electronics') and -i_class in ('personal','portable','reference','self-help') and -i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) -or(i_category in ('Women','Music','Men') and -i_class in ('accessories','classical','fragrances','pants') and -i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manufact_id, d_qoy ) tmp1 -where case when avg_quarterly_sales > 0 - then abs (sum_sales - avg_quarterly_sales)/ avg_quarterly_sales - else null end > 0.1 -order by avg_quarterly_sales, - sum_sales, - i_manufact_id -limit 100; - --- end template query53.tpl query 66 in stream 1 --- start template query55.tpl query 67 in stream 1 -select /* TPC-DS query55.tpl 0.82 */ i_brand_id brand_id, i_brand brand, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=57 - and d_moy=12 - and d_year=1999 - group by i_brand, i_brand_id - order by ext_price desc, i_brand_id -limit 100 ; - --- end template query55.tpl query 67 in stream 1 --- start template query46.tpl query 68 in stream 1 -select /* TPC-DS query46.tpl 0.23 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and (household_demographics.hd_dep_count = 6 or - household_demographics.hd_vehicle_count= 2) - and date_dim.d_dow in (6,0) - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_city in ('Oak Grove','Brownsville','Greenwood','Harmony','Newtown') - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,ca_city) dn,customer,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - limit 100; - --- end template query46.tpl query 68 in stream 1 --- start template query21.tpl query 69 in stream 1 -select /* TPC-DS query21.tpl 0.14 */ * - from(select w_warehouse_name - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('1999-05-21' as date)) - then inv_quantity_on_hand - else 0 end) as inv_before - ,sum(case when (cast(d_date as date) >= cast ('1999-05-21' as date)) - then inv_quantity_on_hand - else 0 end) as inv_after - from inventory - ,warehouse - ,item - ,date_dim - where i_current_price between 0.99 and 1.49 - and i_item_sk = inv_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('1999-05-21' as date)) - and dateadd(day,30,cast ('1999-05-21' as date)) - group by w_warehouse_name, i_item_id) x - where (case when inv_before > 0 - then inv_after / inv_before - else null - end) between 2.0/3.0 and 3.0/2.0 - order by w_warehouse_name - ,i_item_id - limit 100; - --- end template query21.tpl query 69 in stream 1 --- start template query15.tpl query 70 in stream 1 -select /* TPC-DS query15.tpl 0.57 */ ca_zip - ,sum(cs_sales_price) - from catalog_sales - ,customer - ,customer_address - ,date_dim - where cs_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', - '85392', '85460', '80348', '81792') - or ca_state in ('CA','WA','GA') - or cs_sales_price > 500) - and cs_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 2002 - group by ca_zip - order by ca_zip - limit 100; - --- end template query15.tpl query 70 in stream 1 --- start template query20.tpl query 71 in stream 1 -select /* TPC-DS query20.tpl 0.65 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(cs_ext_sales_price) as itemrevenue - ,sum(cs_ext_sales_price)*100/sum(sum(cs_ext_sales_price)) over - (partition by i_class) as revenueratio - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and i_category in ('Jewelry', 'Women', 'Men') - and cs_sold_date_sk = d_date_sk - and d_date between cast('1999-02-23' as date) - and dateadd(day,30,cast('1999-02-23' as date)) - group by i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - order by i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query20.tpl query 71 in stream 1 --- start template query65.tpl query 72 in stream 1 -select /* TPC-DS query65.tpl 0.71 */ - s_store_name, - i_item_desc, - sc.revenue, - i_current_price, - i_wholesale_cost, - i_brand - from store, item, - (select ss_store_sk, avg(revenue) as ave - from - (select ss_store_sk, ss_item_sk, - sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1214 and 1214+11 - group by ss_store_sk, ss_item_sk) sa - group by ss_store_sk) sb, - (select ss_store_sk, ss_item_sk, sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1214 and 1214+11 - group by ss_store_sk, ss_item_sk) sc - where sb.ss_store_sk = sc.ss_store_sk and - sc.revenue <= 0.1 * sb.ave and - s_store_sk = sc.ss_store_sk and - i_item_sk = sc.ss_item_sk - order by s_store_name, i_item_desc -limit 100; - --- end template query65.tpl query 72 in stream 1 --- start template query70a.tpl query 73 in stream 1 -with /* TPC-DS query70a.tpl 0.34 */ results as -( select - sum(ss_net_profit) as total_sum ,s_state ,s_county, 0 as gstate, 0 as g_county - from - store_sales - ,date_dim d1 - ,store - where - d1.d_month_seq between 1214 and 1214 + 11 - and d1.d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - and s_state in - ( select s_state - from (select s_state as s_state, - rank() over ( partition by s_state order by sum(ss_net_profit) desc) as ranking - from store_sales, store, date_dim - where d_month_seq between 1214 and 1214 + 11 - and d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - group by s_state - ) tmp1 - where ranking <= 5) - group by s_state,s_county) , - results_rollup as -(select total_sum ,s_state ,s_county, 0 as g_state, 0 as g_county, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum,s_state, NULL as s_county, 0 as g_state, 1 as g_county, 1 as lochierarchy from results group by s_state - union - select sum(total_sum) as total_sum ,NULL as s_state ,NULL as s_county, 1 as g_state, 1 as g_county, 2 as lochierarchy from results) - select total_sum ,s_state ,s_county, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_county = 0 then s_state end - order by total_sum desc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then s_state end - ,rank_within_parent - limit 100; - --- end template query70a.tpl query 73 in stream 1 --- start template query49.tpl query 74 in stream 1 -select /* TPC-DS query49.tpl 0.48 */ channel, item, return_ratio, return_rank, currency_rank from - (select - 'web' as channel - ,web.item - ,web.return_ratio - ,web.return_rank - ,web.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select ws.ws_item_sk as item - ,(cast(sum(coalesce(wr.wr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(wr.wr_return_amt,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - web_sales ws left outer join web_returns wr - on (ws.ws_order_number = wr.wr_order_number and - ws.ws_item_sk = wr.wr_item_sk) - ,date_dim - where - wr.wr_return_amt > 10000 - and ws.ws_net_profit > 1 - and ws.ws_net_paid > 0 - and ws.ws_quantity > 0 - and ws_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 12 - group by ws.ws_item_sk - ) in_web - ) web - where - ( - web.return_rank <= 10 - or - web.currency_rank <= 10 - ) - union - select - 'catalog' as channel - ,catalog.item - ,catalog.return_ratio - ,catalog.return_rank - ,catalog.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select - cs.cs_item_sk as item - ,(cast(sum(coalesce(cr.cr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(cr.cr_return_amount,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - catalog_sales cs left outer join catalog_returns cr - on (cs.cs_order_number = cr.cr_order_number and - cs.cs_item_sk = cr.cr_item_sk) - ,date_dim - where - cr.cr_return_amount > 10000 - and cs.cs_net_profit > 1 - and cs.cs_net_paid > 0 - and cs.cs_quantity > 0 - and cs_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 12 - group by cs.cs_item_sk - ) in_cat - ) catalog - where - ( - catalog.return_rank <= 10 - or - catalog.currency_rank <=10 - ) - union - select - 'store' as channel - ,store.item - ,store.return_ratio - ,store.return_rank - ,store.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select sts.ss_item_sk as item - ,(cast(sum(coalesce(sr.sr_return_quantity,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(sr.sr_return_amt,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - store_sales sts left outer join store_returns sr - on (sts.ss_ticket_number = sr.sr_ticket_number and sts.ss_item_sk = sr.sr_item_sk) - ,date_dim - where - sr.sr_return_amt > 10000 - and sts.ss_net_profit > 1 - and sts.ss_net_paid > 0 - and sts.ss_quantity > 0 - and ss_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 12 - group by sts.ss_item_sk - ) in_store - ) store - where ( - store.return_rank <= 10 - or - store.currency_rank <= 10 - ) - ) - order by 1,4,5,2 - limit 100; - --- end template query49.tpl query 74 in stream 1 --- start template query59.tpl query 75 in stream 1 -with /* TPC-DS query59.tpl 0.30 */ wss as - (select d_week_seq, - ss_store_sk, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - group by d_week_seq,ss_store_sk - ) - select s_store_name1,s_store_id1,d_week_seq1 - ,sun_sales1/sun_sales2,mon_sales1/mon_sales2 - ,tue_sales1/tue_sales2,wed_sales1/wed_sales2,thu_sales1/thu_sales2 - ,fri_sales1/fri_sales2,sat_sales1/sat_sales2 - from - (select s_store_name s_store_name1,wss.d_week_seq d_week_seq1 - ,s_store_id s_store_id1,sun_sales sun_sales1 - ,mon_sales mon_sales1,tue_sales tue_sales1 - ,wed_sales wed_sales1,thu_sales thu_sales1 - ,fri_sales fri_sales1,sat_sales sat_sales1 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1212 and 1212 + 11) y, - (select s_store_name s_store_name2,wss.d_week_seq d_week_seq2 - ,s_store_id s_store_id2,sun_sales sun_sales2 - ,mon_sales mon_sales2,tue_sales tue_sales2 - ,wed_sales wed_sales2,thu_sales thu_sales2 - ,fri_sales fri_sales2,sat_sales sat_sales2 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1212+ 12 and 1212 + 23) x - where s_store_id1=s_store_id2 - and d_week_seq1=d_week_seq2-52 - order by s_store_name1,s_store_id1,d_week_seq1 -limit 100; - --- end template query59.tpl query 75 in stream 1 --- start template query48.tpl query 76 in stream 1 -select /* TPC-DS query48.tpl 0.74 */ sum (ss_quantity) - from store_sales, store, customer_demographics, customer_address, date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2001 - and - ( - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'D' - and - cd_education_status = 'Unknown' - and - ss_sales_price between 100.00 and 150.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'S' - and - cd_education_status = 'Advanced Degree' - and - ss_sales_price between 50.00 and 100.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'U' - and - cd_education_status = '4 yr Degree' - and - ss_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('TN', 'CA', 'MS') - and ss_net_profit between 0 and 2000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('AR', 'TX', 'MO') - and ss_net_profit between 150 and 3000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('NJ', 'NM', 'OH') - and ss_net_profit between 50 and 25000 - ) - ) -; - --- end template query48.tpl query 76 in stream 1 --- start template query72.tpl query 77 in stream 1 -select /* TPC-DS query72.tpl 0.87 */ i_item_desc - ,w_warehouse_name - ,d1.d_week_seq - ,sum(case when p_promo_sk is null then 1 else 0 end) no_promo - ,sum(case when p_promo_sk is not null then 1 else 0 end) promo - ,count(*) total_cnt -from catalog_sales -join inventory on (cs_item_sk = inv_item_sk) -join warehouse on (w_warehouse_sk=inv_warehouse_sk) -join item on (i_item_sk = cs_item_sk) -join customer_demographics on (cs_bill_cdemo_sk = cd_demo_sk) -join household_demographics on (cs_bill_hdemo_sk = hd_demo_sk) -join date_dim d1 on (cs_sold_date_sk = d1.d_date_sk) -join date_dim d2 on (inv_date_sk = d2.d_date_sk) -join date_dim d3 on (cs_ship_date_sk = d3.d_date_sk) -left outer join promotion on (cs_promo_sk=p_promo_sk) -left outer join catalog_returns on (cr_item_sk = cs_item_sk and cr_order_number = cs_order_number) -where d1.d_week_seq = d2.d_week_seq - and inv_quantity_on_hand < cs_quantity - and d3.d_date > d1.d_date + 5 - and hd_buy_potential = '1001-5000' - and d1.d_year = 2000 - and cd_marital_status = 'M' -group by i_item_desc,w_warehouse_name,d1.d_week_seq -order by total_cnt desc, i_item_desc, w_warehouse_name, d_week_seq -limit 100; - --- end template query72.tpl query 77 in stream 1 --- start template query87.tpl query 78 in stream 1 -select /* TPC-DS query87.tpl 0.77 */ count(*) -from ((select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1189 and 1189+11) - except - (select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1189 and 1189+11) - except - (select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1189 and 1189+11) -) cool_cust -; - --- end template query87.tpl query 78 in stream 1 --- start template query34.tpl query 79 in stream 1 -select /* TPC-DS query34.tpl 0.73 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (date_dim.d_dom between 1 and 3 or date_dim.d_dom between 25 and 28) - and (household_demographics.hd_buy_potential = '501-1000' or - household_demographics.hd_buy_potential = 'Unknown') - and household_demographics.hd_vehicle_count > 0 - and (case when household_demographics.hd_vehicle_count > 0 - then household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count - else null - end) > 1.2 - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_county in ('Sumner County','Gage County','Bronx County','Essex County', - 'Arthur County','Mobile County','Oglethorpe County','Maverick County') - group by ss_ticket_number,ss_customer_sk) dn,customer - where ss_customer_sk = c_customer_sk - and cnt between 15 and 20 - order by c_last_name,c_first_name,c_salutation,c_preferred_cust_flag desc, ss_ticket_number; - --- end template query34.tpl query 79 in stream 1 --- start template query2.tpl query 80 in stream 1 -with /* TPC-DS query2.tpl 0.84 */ wscs as - (select sold_date_sk - ,sales_price - from (select ws_sold_date_sk sold_date_sk - ,ws_ext_sales_price sales_price - from web_sales - union all - select cs_sold_date_sk sold_date_sk - ,cs_ext_sales_price sales_price - from catalog_sales)), - wswscs as - (select d_week_seq, - sum(case when (d_day_name='Sunday') then sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then sales_price else null end) sat_sales - from wscs - ,date_dim - where d_date_sk = sold_date_sk - group by d_week_seq) - select d_week_seq1 - ,round(sun_sales1/sun_sales2,2) - ,round(mon_sales1/mon_sales2,2) - ,round(tue_sales1/tue_sales2,2) - ,round(wed_sales1/wed_sales2,2) - ,round(thu_sales1/thu_sales2,2) - ,round(fri_sales1/fri_sales2,2) - ,round(sat_sales1/sat_sales2,2) - from - (select wswscs.d_week_seq d_week_seq1 - ,sun_sales sun_sales1 - ,mon_sales mon_sales1 - ,tue_sales tue_sales1 - ,wed_sales wed_sales1 - ,thu_sales thu_sales1 - ,fri_sales fri_sales1 - ,sat_sales sat_sales1 - from wswscs,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 2001) y, - (select wswscs.d_week_seq d_week_seq2 - ,sun_sales sun_sales2 - ,mon_sales mon_sales2 - ,tue_sales tue_sales2 - ,wed_sales wed_sales2 - ,thu_sales thu_sales2 - ,fri_sales fri_sales2 - ,sat_sales sat_sales2 - from wswscs - ,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 2001+1) z - where d_week_seq1=d_week_seq2-53 - order by d_week_seq1; - --- end template query2.tpl query 80 in stream 1 --- start template query38.tpl query 81 in stream 1 -select /* TPC-DS query38.tpl 0.54 */ count(*) from ( - select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1207 and 1207 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1207 and 1207 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1207 and 1207 + 11 -) hot_cust -limit 100; - --- end template query38.tpl query 81 in stream 1 --- start template query22a.tpl query 82 in stream 1 -with /* TPC-DS query22a.tpl 0.55 */ results as -(select i_product_name - ,i_brand - ,i_class - ,i_category - ,avg(inv_quantity_on_hand) qoh - from inventory - ,date_dim - ,item --- ,warehouse - where inv_date_sk=d_date_sk - and inv_item_sk=i_item_sk --- and inv_warehouse_sk = w_warehouse_sk - and d_month_seq between 1188 and 1188 + 11 - group by i_product_name,i_brand,i_class,i_category), -results_rollup as -(select i_product_name, i_brand, i_class, i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class,i_category -union all -select i_product_name, i_brand, i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class -union all -select i_product_name, i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand -union all -select i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name -union all -select null i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results) - select i_product_name, i_brand, i_class, i_category,qoh - from results_rollup - order by qoh, i_product_name, i_brand, i_class, i_category -limit 100; - --- end template query22a.tpl query 82 in stream 1 --- start template query89.tpl query 83 in stream 1 -select /* TPC-DS query89.tpl 0.56 */ * -from( -select i_category, i_class, i_brand, - s_store_name, s_company_name, - d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, s_store_name, s_company_name) - avg_monthly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - d_year in (1998) and - ((i_category in ('Men','Electronics','Music') and - i_class in ('sports-apparel','musical','country') - ) - or (i_category in ('Sports','Children','Books') and - i_class in ('baseball','toddlers','science') - )) -group by i_category, i_class, i_brand, - s_store_name, s_company_name, d_moy) tmp1 -where case when (avg_monthly_sales <> 0) then (abs(sum_sales - avg_monthly_sales) / avg_monthly_sales) else null end > 0.1 -order by sum_sales - avg_monthly_sales, s_store_name -limit 100; - --- end template query89.tpl query 83 in stream 1 --- start template query7.tpl query 84 in stream 1 -select /* TPC-DS query7.tpl 0.2 */ i_item_id, - avg(ss_quantity) agg1, - avg(ss_list_price) agg2, - avg(ss_coupon_amt) agg3, - avg(ss_sales_price) agg4 - from store_sales, customer_demographics, date_dim, item, promotion - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_cdemo_sk = cd_demo_sk and - ss_promo_sk = p_promo_sk and - cd_gender = 'M' and - cd_marital_status = 'S' and - cd_education_status = 'Primary' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 2002 - group by i_item_id - order by i_item_id - limit 100; - --- end template query7.tpl query 84 in stream 1 --- start template query10.tpl query 85 in stream 1 -select /* TPC-DS query10.tpl 0.26 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3, - cd_dep_count, - count(*) cnt4, - cd_dep_employed_count, - count(*) cnt5, - cd_dep_college_count, - count(*) cnt6 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_county in ('Lincoln County','Spotsylvania County','Dunklin County','Jones County','Gosper County') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 1999 and - d_moy between 4 and 4+3) and - (exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 1999 and - d_moy between 4 ANd 4+3) or - exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 1999 and - d_moy between 4 and 4+3)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count -limit 100; - --- end template query10.tpl query 85 in stream 1 --- start template query90.tpl query 86 in stream 1 -select /* TPC-DS query90.tpl 0.40 */ cast(amc as decimal(15,4))/cast(pmc as decimal(15,4)) am_pm_ratio - from ( select count(*) amc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 7 and 7+1 - and household_demographics.hd_dep_count = 4 - and web_page.wp_char_count between 5000 and 5200) at, - ( select count(*) pmc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 14 and 14+1 - and household_demographics.hd_dep_count = 4 - and web_page.wp_char_count between 5000 and 5200) pt - order by am_pm_ratio - limit 100; - --- end template query90.tpl query 86 in stream 1 --- start template query71.tpl query 87 in stream 1 -select /* TPC-DS query71.tpl 0.72 */ i_brand_id brand_id, i_brand brand,t_hour,t_minute, - sum(ext_price) ext_price - from item, (select ws_ext_sales_price as ext_price, - ws_sold_date_sk as sold_date_sk, - ws_item_sk as sold_item_sk, - ws_sold_time_sk as time_sk - from web_sales,date_dim - where d_date_sk = ws_sold_date_sk - and d_moy=11 - and d_year=1998 - union all - select cs_ext_sales_price as ext_price, - cs_sold_date_sk as sold_date_sk, - cs_item_sk as sold_item_sk, - cs_sold_time_sk as time_sk - from catalog_sales,date_dim - where d_date_sk = cs_sold_date_sk - and d_moy=11 - and d_year=1998 - union all - select ss_ext_sales_price as ext_price, - ss_sold_date_sk as sold_date_sk, - ss_item_sk as sold_item_sk, - ss_sold_time_sk as time_sk - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - and d_moy=11 - and d_year=1998 - ) tmp,time_dim - where - sold_item_sk = i_item_sk - and i_manager_id=1 - and time_sk = t_time_sk - and (t_meal_time = 'breakfast' or t_meal_time = 'dinner') - group by i_brand, i_brand_id,t_hour,t_minute - order by ext_price desc, i_brand_id - ; - --- end template query71.tpl query 87 in stream 1 --- start template query29.tpl query 88 in stream 1 -select /* TPC-DS query29.tpl 0.53 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,avg(ss_quantity) as store_sales_quantity - ,avg(sr_return_quantity) as store_returns_quantity - ,avg(cs_quantity) as catalog_sales_quantity - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 1998 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 4 + 3 - and d2.d_year = 1998 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_year in (1998,1998+1,1998+2) - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query29.tpl query 88 in stream 1 --- start template query73.tpl query 89 in stream 1 -select /* TPC-DS query73.tpl 0.79 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_buy_potential = '501-1000' or - household_demographics.hd_buy_potential = '0-500') - and household_demographics.hd_vehicle_count > 0 - and case when household_demographics.hd_vehicle_count > 0 then - household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count else null end > 1 - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_county in ('Essex County','Mesa County','Terry County','Sierra County') - group by ss_ticket_number,ss_customer_sk) dj,customer - where ss_customer_sk = c_customer_sk - and cnt between 1 and 5 - order by cnt desc, c_last_name asc; - --- end template query73.tpl query 89 in stream 1 --- start template query45.tpl query 90 in stream 1 -select /* TPC-DS query45.tpl 0.18 */ ca_zip, ca_state, sum(ws_sales_price) - from web_sales, customer, customer_address, date_dim, item - where ws_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ws_item_sk = i_item_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', '85392', '85460', '80348', '81792') - or - i_item_id in (select i_item_id - from item - where i_item_sk in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29) - ) - ) - and ws_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 1998 - group by ca_zip, ca_state - order by ca_zip, ca_state - limit 100; - --- end template query45.tpl query 90 in stream 1 --- start template query91.tpl query 91 in stream 1 -select /* TPC-DS query91.tpl 0.13 */ - cc_call_center_id Call_Center, - cc_name Call_Center_Name, - cc_manager Manager, - sum(cr_net_loss) Returns_Loss -from - call_center, - catalog_returns, - date_dim, - customer, - customer_address, - customer_demographics, - household_demographics -where - cr_call_center_sk = cc_call_center_sk -and cr_returned_date_sk = d_date_sk -and cr_returning_customer_sk= c_customer_sk -and cd_demo_sk = c_current_cdemo_sk -and hd_demo_sk = c_current_hdemo_sk -and ca_address_sk = c_current_addr_sk -and d_year = 1999 -and d_moy = 12 -and ( (cd_marital_status = 'M' and cd_education_status = 'Unknown') - or(cd_marital_status = 'W' and cd_education_status = 'Advanced Degree')) -and hd_buy_potential like 'Unknown%' -and ca_gmt_offset = -7 -group by cc_call_center_id,cc_name,cc_manager,cd_marital_status,cd_education_status -order by sum(cr_net_loss) desc; - --- end template query91.tpl query 91 in stream 1 --- start template query62.tpl query 92 in stream 1 -select /* TPC-DS query62.tpl 0.24 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 30) and - (ws_ship_date_sk - ws_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 60) and - (ws_ship_date_sk - ws_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 90) and - (ws_ship_date_sk - ws_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - web_sales - ,warehouse - ,ship_mode - ,web_site - ,date_dim -where - d_month_seq between 1195 and 1195 + 11 -and ws_ship_date_sk = d_date_sk -and ws_warehouse_sk = w_warehouse_sk -and ws_ship_mode_sk = sm_ship_mode_sk -and ws_web_site_sk = web_site_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -limit 100; - --- end template query62.tpl query 92 in stream 1 --- start template query44.tpl query 93 in stream 1 -select /* TPC-DS query44.tpl 0.4 */ asceding.rnk, i1.i_product_name best_performing, i2.i_product_name worst_performing -from(select * - from (select item_sk,rank() over (order by rank_col asc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 92 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 92 - and ss_customer_sk is null - group by ss_store_sk))V1)V11 - where rnk < 11) asceding, - (select * - from (select item_sk,rank() over (order by rank_col desc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 92 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 92 - and ss_customer_sk is null - group by ss_store_sk))V2)V21 - where rnk < 11) descending, -item i1, -item i2 -where asceding.rnk = descending.rnk - and i1.i_item_sk=asceding.item_sk - and i2.i_item_sk=descending.item_sk -order by asceding.rnk -limit 100; - --- end template query44.tpl query 93 in stream 1 --- start template query76.tpl query 94 in stream 1 -select /* TPC-DS query76.tpl 0.99 */ channel, col_name, d_year, d_qoy, i_category, COUNT(*) sales_cnt, SUM(ext_sales_price) sales_amt FROM ( - SELECT 'store' as channel, 'ss_promo_sk' col_name, d_year, d_qoy, i_category, ss_ext_sales_price ext_sales_price - FROM store_sales, item, date_dim - WHERE ss_promo_sk IS NULL - AND ss_sold_date_sk=d_date_sk - AND ss_item_sk=i_item_sk - UNION ALL - SELECT 'web' as channel, 'ws_warehouse_sk' col_name, d_year, d_qoy, i_category, ws_ext_sales_price ext_sales_price - FROM web_sales, item, date_dim - WHERE ws_warehouse_sk IS NULL - AND ws_sold_date_sk=d_date_sk - AND ws_item_sk=i_item_sk - UNION ALL - SELECT 'catalog' as channel, 'cs_ship_hdemo_sk' col_name, d_year, d_qoy, i_category, cs_ext_sales_price ext_sales_price - FROM catalog_sales, item, date_dim - WHERE cs_ship_hdemo_sk IS NULL - AND cs_sold_date_sk=d_date_sk - AND cs_item_sk=i_item_sk) foo -GROUP BY channel, col_name, d_year, d_qoy, i_category -ORDER BY channel, col_name, d_year, d_qoy, i_category -limit 100; - --- end template query76.tpl query 94 in stream 1 --- start template query23.tpl query 95 in stream 1 -with /* TPC-DS query23.tpl 0.68 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (1998,1998+1,1998+2,1998+3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1998,1998+1,1998+2,1998+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * -from - max_store_sales)) - select sum(sales) - from (select cs_quantity*cs_list_price sales - from catalog_sales - ,date_dim - where d_year = 1998 - and d_moy = 1 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - union all - select ws_quantity*ws_list_price sales - from web_sales - ,date_dim - where d_year = 1998 - and d_moy = 1 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer)) - limit 100; -with /* TPC-DS query23.tpl 0.68 part2 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (1998,1998 + 1,1998 + 2,1998 + 3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1998,1998+1,1998+2,1998+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * - from max_store_sales)) - select c_last_name,c_first_name,sales - from (select c_last_name,c_first_name,sum(cs_quantity*cs_list_price) sales - from catalog_sales - ,customer - ,date_dim - where d_year = 1998 - and d_moy = 1 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and cs_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name - union all - select c_last_name,c_first_name,sum(ws_quantity*ws_list_price) sales - from web_sales - ,customer - ,date_dim - where d_year = 1998 - and d_moy = 1 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and ws_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name) - order by c_last_name,c_first_name,sales - limit 100; - --- end template query23.tpl query 95 in stream 1 --- start template query56.tpl query 96 in stream 1 -with /* TPC-DS query56.tpl 0.83 */ ss as ( - select i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where i_item_id in (select - i_item_id -from item -where i_color in ('salmon','orchid','purple')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 1 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id), - cs as ( - select i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('salmon','orchid','purple')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 1 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id), - ws as ( - select i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('salmon','orchid','purple')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 1 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id) - select i_item_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by total_sales, - i_item_id - limit 100; - --- end template query56.tpl query 96 in stream 1 --- start template query42.tpl query 97 in stream 1 -select /* TPC-DS query42.tpl 0.61 */ dt.d_year - ,item.i_category_id - ,item.i_category - ,sum(ss_ext_sales_price) - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=12 - and dt.d_year=1999 - group by dt.d_year - ,item.i_category_id - ,item.i_category - order by sum(ss_ext_sales_price) desc,dt.d_year - ,item.i_category_id - ,item.i_category -limit 100 ; - --- end template query42.tpl query 97 in stream 1 --- start template query39.tpl query 98 in stream 1 -with /* TPC-DS query39.tpl 0.5 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =1999 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=1 - and inv2.d_moy=1+1 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; -with /* TPC-DS query39.tpl 0.5 part2 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =1999 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=1 - and inv2.d_moy=1+1 - and inv1.cov > 1.5 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; - --- end template query39.tpl query 98 in stream 1 --- start template query74.tpl query 99 in stream 1 -with /* TPC-DS query74.tpl 0.76 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,avg(ss_net_paid) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1999,1999+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,avg(ws_net_paid) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - and d_year in (1999,1999+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - ) - select - t_s_secyear.customer_id, t_s_secyear.customer_first_name, t_s_secyear.customer_last_name - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.year = 1999 - and t_s_secyear.year = 1999+1 - and t_w_firstyear.year = 1999 - and t_w_secyear.year = 1999+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - order by 3,1,2 -limit 100; - --- end template query74.tpl query 99 in stream 1 diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/3TB/queries/query_10.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/3TB/queries/query_10.sql deleted file mode 100644 index efda975d..00000000 --- a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/3TB/queries/query_10.sql +++ /dev/null @@ -1,5027 +0,0 @@ --- start template query43.tpl query 1 in stream 10 -select /* TPC-DS query43.tpl 0.15 */ s_store_name, s_store_id, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from date_dim, store_sales, store - where d_date_sk = ss_sold_date_sk and - s_store_sk = ss_store_sk and - s_gmt_offset = -6 and - d_year = 1998 - group by s_store_name, s_store_id - order by s_store_name, s_store_id,sun_sales,mon_sales,tue_sales,wed_sales,thu_sales,fri_sales,sat_sales - limit 100; - --- end template query43.tpl query 1 in stream 10 --- start template query50.tpl query 2 in stream 10 -select /* TPC-DS query50.tpl 0.60 */ - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 30) and - (sr_returned_date_sk - ss_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 60) and - (sr_returned_date_sk - ss_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 90) and - (sr_returned_date_sk - ss_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - store_sales - ,store_returns - ,store - ,date_dim d1 - ,date_dim d2 -where - d2.d_year = 1999 -and d2.d_moy = 9 -and ss_ticket_number = sr_ticket_number -and ss_item_sk = sr_item_sk -and ss_sold_date_sk = d1.d_date_sk -and sr_returned_date_sk = d2.d_date_sk -and ss_customer_sk = sr_customer_sk -and ss_store_sk = s_store_sk -group by - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -order by s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -limit 100; - --- end template query50.tpl query 2 in stream 10 --- start template query41.tpl query 3 in stream 10 -select /* TPC-DS query41.tpl 0.62 */ distinct(i_product_name) - from item i1 - where i_manufact_id between 964 and 964+40 - and (select count(*) as item_cnt - from item - where (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'hot' or i_color = 'chartreuse') and - (i_units = 'Bunch' or i_units = 'Case') and - (i_size = 'medium' or i_size = 'economy') - ) or - (i_category = 'Women' and - (i_color = 'honeydew' or i_color = 'dark') and - (i_units = 'Ounce' or i_units = 'Bundle') and - (i_size = 'N/A' or i_size = 'extra large') - ) or - (i_category = 'Men' and - (i_color = 'tomato' or i_color = 'snow') and - (i_units = 'Pallet' or i_units = 'Pound') and - (i_size = 'petite' or i_size = 'small') - ) or - (i_category = 'Men' and - (i_color = 'goldenrod' or i_color = 'lavender') and - (i_units = 'Lb' or i_units = 'N/A') and - (i_size = 'medium' or i_size = 'economy') - ))) or - (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'white' or i_color = 'burlywood') and - (i_units = 'Gram' or i_units = 'Gross') and - (i_size = 'medium' or i_size = 'economy') - ) or - (i_category = 'Women' and - (i_color = 'black' or i_color = 'saddle') and - (i_units = 'Oz' or i_units = 'Tbl') and - (i_size = 'N/A' or i_size = 'extra large') - ) or - (i_category = 'Men' and - (i_color = 'lawn' or i_color = 'pale') and - (i_units = 'Ton' or i_units = 'Dozen') and - (i_size = 'petite' or i_size = 'small') - ) or - (i_category = 'Men' and - (i_color = 'indian' or i_color = 'brown') and - (i_units = 'Dram' or i_units = 'Each') and - (i_size = 'medium' or i_size = 'economy') - )))) > 0 - order by i_product_name - limit 100; - --- end template query41.tpl query 3 in stream 10 --- start template query48.tpl query 4 in stream 10 -select /* TPC-DS query48.tpl 0.74 */ sum (ss_quantity) - from store_sales, store, customer_demographics, customer_address, date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 1998 - and - ( - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'D' - and - cd_education_status = 'Primary' - and - ss_sales_price between 100.00 and 150.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'U' - and - cd_education_status = 'College' - and - ss_sales_price between 50.00 and 100.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'S' - and - cd_education_status = '2 yr Degree' - and - ss_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('CO', 'TX', 'IL') - and ss_net_profit between 0 and 2000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('IN', 'MO', 'VA') - and ss_net_profit between 150 and 3000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('IA', 'AR', 'KY') - and ss_net_profit between 50 and 25000 - ) - ) -; - --- end template query48.tpl query 4 in stream 10 --- start template query54.tpl query 5 in stream 10 -with /* TPC-DS query54.tpl 0.81 */ my_customers as ( - select distinct c_customer_sk - , c_current_addr_sk - from - ( select cs_sold_date_sk sold_date_sk, - cs_bill_customer_sk customer_sk, - cs_item_sk item_sk - from catalog_sales - union all - select ws_sold_date_sk sold_date_sk, - ws_bill_customer_sk customer_sk, - ws_item_sk item_sk - from web_sales - ) cs_or_ws_sales, - item, - date_dim, - customer - where sold_date_sk = d_date_sk - and item_sk = i_item_sk - and i_category = 'Jewelry' - and i_class = 'custom' - and c_customer_sk = cs_or_ws_sales.customer_sk - and d_moy = 6 - and d_year = 2000 - ) - , my_revenue as ( - select c_customer_sk, - sum(ss_ext_sales_price) as revenue - from my_customers, - store_sales, - customer_address, - store, - date_dim - where c_current_addr_sk = ca_address_sk - and ca_county = s_county - and ca_state = s_state - and ss_sold_date_sk = d_date_sk - and c_customer_sk = ss_customer_sk - and d_month_seq between (select distinct d_month_seq+1 - from date_dim where d_year = 2000 and d_moy = 6) - and (select distinct d_month_seq+3 - from date_dim where d_year = 2000 and d_moy = 6) - group by c_customer_sk - ) - , segments as - (select cast((revenue/50) as int) as segment - from my_revenue - ) - select segment, count(*) as num_customers, segment*50 as segment_base - from segments - group by segment - order by segment, num_customers - limit 100; - --- end template query54.tpl query 5 in stream 10 --- start template query53.tpl query 6 in stream 10 -select /* TPC-DS query53.tpl 0.88 */ * from -(select i_manufact_id, -sum(ss_sales_price) sum_sales, -avg(sum(ss_sales_price)) over (partition by i_manufact_id) avg_quarterly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and -ss_sold_date_sk = d_date_sk and -ss_store_sk = s_store_sk and -d_month_seq in (1180,1180+1,1180+2,1180+3,1180+4,1180+5,1180+6,1180+7,1180+8,1180+9,1180+10,1180+11) and -((i_category in ('Books','Children','Electronics') and -i_class in ('personal','portable','reference','self-help') and -i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) -or(i_category in ('Women','Music','Men') and -i_class in ('accessories','classical','fragrances','pants') and -i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manufact_id, d_qoy ) tmp1 -where case when avg_quarterly_sales > 0 - then abs (sum_sales - avg_quarterly_sales)/ avg_quarterly_sales - else null end > 0.1 -order by avg_quarterly_sales, - sum_sales, - i_manufact_id -limit 100; - --- end template query53.tpl query 6 in stream 10 --- start template query31.tpl query 7 in stream 10 -with /* TPC-DS query31.tpl 0.50 */ ss as - (select ca_county,d_qoy, d_year,sum(ss_ext_sales_price) as store_sales - from store_sales,date_dim,customer_address - where ss_sold_date_sk = d_date_sk - and ss_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year), - ws as - (select ca_county,d_qoy, d_year,sum(ws_ext_sales_price) as web_sales - from web_sales,date_dim,customer_address - where ws_sold_date_sk = d_date_sk - and ws_bill_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year) - select - ss1.ca_county - ,ss1.d_year - ,ws2.web_sales/ws1.web_sales web_q1_q2_increase - ,ss2.store_sales/ss1.store_sales store_q1_q2_increase - ,ws3.web_sales/ws2.web_sales web_q2_q3_increase - ,ss3.store_sales/ss2.store_sales store_q2_q3_increase - from - ss ss1 - ,ss ss2 - ,ss ss3 - ,ws ws1 - ,ws ws2 - ,ws ws3 - where - ss1.d_qoy = 1 - and ss1.d_year = 1998 - and ss1.ca_county = ss2.ca_county - and ss2.d_qoy = 2 - and ss2.d_year = 1998 - and ss2.ca_county = ss3.ca_county - and ss3.d_qoy = 3 - and ss3.d_year = 1998 - and ss1.ca_county = ws1.ca_county - and ws1.d_qoy = 1 - and ws1.d_year = 1998 - and ws1.ca_county = ws2.ca_county - and ws2.d_qoy = 2 - and ws2.d_year = 1998 - and ws1.ca_county = ws3.ca_county - and ws3.d_qoy = 3 - and ws3.d_year =1998 - and case when ws1.web_sales > 0 then ws2.web_sales/ws1.web_sales else null end - > case when ss1.store_sales > 0 then ss2.store_sales/ss1.store_sales else null end - and case when ws2.web_sales > 0 then ws3.web_sales/ws2.web_sales else null end - > case when ss2.store_sales > 0 then ss3.store_sales/ss2.store_sales else null end - order by web_q2_q3_increase; - --- end template query31.tpl query 7 in stream 10 --- start template query39.tpl query 8 in stream 10 -with /* TPC-DS query39.tpl 0.5 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =2000 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=4 - and inv2.d_moy=4+1 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; -with /* TPC-DS query39.tpl 0.5 part2 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =2000 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=4 - and inv2.d_moy=4+1 - and inv1.cov > 1.5 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; - --- end template query39.tpl query 8 in stream 10 --- start template query2.tpl query 9 in stream 10 -with /* TPC-DS query2.tpl 0.84 */ wscs as - (select sold_date_sk - ,sales_price - from (select ws_sold_date_sk sold_date_sk - ,ws_ext_sales_price sales_price - from web_sales - union all - select cs_sold_date_sk sold_date_sk - ,cs_ext_sales_price sales_price - from catalog_sales)), - wswscs as - (select d_week_seq, - sum(case when (d_day_name='Sunday') then sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then sales_price else null end) sat_sales - from wscs - ,date_dim - where d_date_sk = sold_date_sk - group by d_week_seq) - select d_week_seq1 - ,round(sun_sales1/sun_sales2,2) - ,round(mon_sales1/mon_sales2,2) - ,round(tue_sales1/tue_sales2,2) - ,round(wed_sales1/wed_sales2,2) - ,round(thu_sales1/thu_sales2,2) - ,round(fri_sales1/fri_sales2,2) - ,round(sat_sales1/sat_sales2,2) - from - (select wswscs.d_week_seq d_week_seq1 - ,sun_sales sun_sales1 - ,mon_sales mon_sales1 - ,tue_sales tue_sales1 - ,wed_sales wed_sales1 - ,thu_sales thu_sales1 - ,fri_sales fri_sales1 - ,sat_sales sat_sales1 - from wswscs,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 1999) y, - (select wswscs.d_week_seq d_week_seq2 - ,sun_sales sun_sales2 - ,mon_sales mon_sales2 - ,tue_sales tue_sales2 - ,wed_sales wed_sales2 - ,thu_sales thu_sales2 - ,fri_sales fri_sales2 - ,sat_sales sat_sales2 - from wswscs - ,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 1999+1) z - where d_week_seq1=d_week_seq2-53 - order by d_week_seq1; - --- end template query2.tpl query 9 in stream 10 --- start template query96.tpl query 10 in stream 10 -select /* TPC-DS query96.tpl 0.1 */ count(*) -from store_sales - ,household_demographics - ,time_dim, store -where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and household_demographics.hd_dep_count = 3 - and store.s_store_name = 'ese' -order by count(*) -limit 100; - --- end template query96.tpl query 10 in stream 10 --- start template query93.tpl query 11 in stream 10 -select /* TPC-DS query93.tpl 0.52 */ ss_customer_sk - ,sum(act_sales) sumsales - from (select ss_item_sk - ,ss_ticket_number - ,ss_customer_sk - ,case when sr_return_quantity is not null then (ss_quantity-sr_return_quantity)*ss_sales_price - else (ss_quantity*ss_sales_price) end act_sales - from store_sales left outer join store_returns on (sr_item_sk = ss_item_sk - and sr_ticket_number = ss_ticket_number) - ,reason - where sr_reason_sk = r_reason_sk - and r_reason_desc = 'reason 54') t - group by ss_customer_sk - order by sumsales, ss_customer_sk -limit 100; - --- end template query93.tpl query 11 in stream 10 --- start template query15.tpl query 12 in stream 10 -select /* TPC-DS query15.tpl 0.57 */ ca_zip - ,sum(cs_sales_price) - from catalog_sales - ,customer - ,customer_address - ,date_dim - where cs_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', - '85392', '85460', '80348', '81792') - or ca_state in ('CA','WA','GA') - or cs_sales_price > 500) - and cs_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 2000 - group by ca_zip - order by ca_zip - limit 100; - --- end template query15.tpl query 12 in stream 10 --- start template query91.tpl query 13 in stream 10 -select /* TPC-DS query91.tpl 0.13 */ - cc_call_center_id Call_Center, - cc_name Call_Center_Name, - cc_manager Manager, - sum(cr_net_loss) Returns_Loss -from - call_center, - catalog_returns, - date_dim, - customer, - customer_address, - customer_demographics, - household_demographics -where - cr_call_center_sk = cc_call_center_sk -and cr_returned_date_sk = d_date_sk -and cr_returning_customer_sk= c_customer_sk -and cd_demo_sk = c_current_cdemo_sk -and hd_demo_sk = c_current_hdemo_sk -and ca_address_sk = c_current_addr_sk -and d_year = 1998 -and d_moy = 11 -and ( (cd_marital_status = 'M' and cd_education_status = 'Unknown') - or(cd_marital_status = 'W' and cd_education_status = 'Advanced Degree')) -and hd_buy_potential like 'Unknown%' -and ca_gmt_offset = -7 -group by cc_call_center_id,cc_name,cc_manager,cd_marital_status,cd_education_status -order by sum(cr_net_loss) desc; - --- end template query91.tpl query 13 in stream 10 --- start template query21.tpl query 14 in stream 10 -select /* TPC-DS query21.tpl 0.14 */ * - from(select w_warehouse_name - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('1999-06-06' as date)) - then inv_quantity_on_hand - else 0 end) as inv_before - ,sum(case when (cast(d_date as date) >= cast ('1999-06-06' as date)) - then inv_quantity_on_hand - else 0 end) as inv_after - from inventory - ,warehouse - ,item - ,date_dim - where i_current_price between 0.99 and 1.49 - and i_item_sk = inv_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('1999-06-06' as date)) - and dateadd(day,30,cast ('1999-06-06' as date)) - group by w_warehouse_name, i_item_id) x - where (case when inv_before > 0 - then inv_after / inv_before - else null - end) between 2.0/3.0 and 3.0/2.0 - order by w_warehouse_name - ,i_item_id - limit 100; - --- end template query21.tpl query 14 in stream 10 --- start template query18a.tpl query 15 in stream 10 -with /* TPC-DS query18a.tpl 0.90 */ results as - (select i_item_id, - ca_country, - ca_state, - ca_county, - cast(cs_quantity as decimal(12,2)) agg1, - cast(cs_list_price as decimal(12,2)) agg2, - cast(cs_coupon_amt as decimal(12,2)) agg3, - cast(cs_sales_price as decimal(12,2)) agg4, - cast(cs_net_profit as decimal(12,2)) agg5, - cast(c_birth_year as decimal(12,2)) agg6, - cast(cd1.cd_dep_count as decimal(12,2)) agg7 - from catalog_sales, customer_demographics cd1, customer_demographics cd2, customer, customer_address, date_dim, item - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd1.cd_demo_sk and - cs_bill_customer_sk = c_customer_sk and - cd1.cd_gender = 'M' and - cd1.cd_education_status = 'Advanced Degree' and - c_current_cdemo_sk = cd2.cd_demo_sk and - c_current_addr_sk = ca_address_sk and - c_birth_month in (7,5,11,3,8,10) and - d_year = 1999 and - ca_state in ('GA','OK','KY','LA','TX','NH','WV') - ) - select i_item_id, ca_country, ca_state, ca_county, agg1, agg2, agg3, agg4, agg5, agg6, agg7 - from ( - select i_item_id, ca_country, ca_state, ca_county, avg(agg1) agg1, - avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state, ca_county - union all - select i_item_id, ca_country, ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state - union all - select i_item_id, ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country - union all - select i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - ) foo - order by ca_country, ca_state, ca_county, i_item_id - limit 100; - --- end template query18a.tpl query 15 in stream 10 --- start template query32.tpl query 16 in stream 10 -select /* TPC-DS query32.tpl 0.7 */ sum(cs_ext_discount_amt) as "excess discount amount" -from - catalog_sales - ,item - ,date_dim -where -i_manufact_id = 27 -and i_item_sk = cs_item_sk -and d_date between '2001-02-23' and - dateadd(day,90,cast('2001-02-23' as date)) -and d_date_sk = cs_sold_date_sk -and cs_ext_discount_amt - > ( - select - 1.3 * avg(cs_ext_discount_amt) - from - catalog_sales - ,date_dim - where - cs_item_sk = i_item_sk - and d_date between '2001-02-23' and - dateadd(day,90,cast('2001-02-23' as date)) - and d_date_sk = cs_sold_date_sk - ) -limit 100; - --- end template query32.tpl query 16 in stream 10 --- start template query63.tpl query 17 in stream 10 -select /* TPC-DS query63.tpl 0.27 */ * -from (select i_manager_id - ,sum(ss_sales_price) sum_sales - ,avg(sum(ss_sales_price)) over (partition by i_manager_id) avg_monthly_sales - from item - ,store_sales - ,date_dim - ,store - where ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and d_month_seq in (1186,1186+1,1186+2,1186+3,1186+4,1186+5,1186+6,1186+7,1186+8,1186+9,1186+10,1186+11) - and (( i_category in ('Books','Children','Electronics') - and i_class in ('personal','portable','reference','self-help') - and i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) - or( i_category in ('Women','Music','Men') - and i_class in ('accessories','classical','fragrances','pants') - and i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manager_id, d_moy) tmp1 -where case when avg_monthly_sales > 0 then abs (sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 -order by i_manager_id - ,avg_monthly_sales - ,sum_sales -limit 100; - --- end template query63.tpl query 17 in stream 10 --- start template query24.tpl query 18 in stream 10 -with /* TPC-DS query24.tpl 0.92 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_net_paid) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip -and s_market_id=5 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'burnished' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; -with /* TPC-DS query24.tpl 0.92 part2 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_net_paid) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip - and s_market_id = 5 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'navajo' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; - --- end template query24.tpl query 18 in stream 10 --- start template query66.tpl query 19 in stream 10 -select /* TPC-DS query66.tpl 0.39 */ - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - ,sum(jan_sales) as jan_sales - ,sum(feb_sales) as feb_sales - ,sum(mar_sales) as mar_sales - ,sum(apr_sales) as apr_sales - ,sum(may_sales) as may_sales - ,sum(jun_sales) as jun_sales - ,sum(jul_sales) as jul_sales - ,sum(aug_sales) as aug_sales - ,sum(sep_sales) as sep_sales - ,sum(oct_sales) as oct_sales - ,sum(nov_sales) as nov_sales - ,sum(dec_sales) as dec_sales - ,sum(jan_sales/w_warehouse_sq_ft) as jan_sales_per_sq_foot - ,sum(feb_sales/w_warehouse_sq_ft) as feb_sales_per_sq_foot - ,sum(mar_sales/w_warehouse_sq_ft) as mar_sales_per_sq_foot - ,sum(apr_sales/w_warehouse_sq_ft) as apr_sales_per_sq_foot - ,sum(may_sales/w_warehouse_sq_ft) as may_sales_per_sq_foot - ,sum(jun_sales/w_warehouse_sq_ft) as jun_sales_per_sq_foot - ,sum(jul_sales/w_warehouse_sq_ft) as jul_sales_per_sq_foot - ,sum(aug_sales/w_warehouse_sq_ft) as aug_sales_per_sq_foot - ,sum(sep_sales/w_warehouse_sq_ft) as sep_sales_per_sq_foot - ,sum(oct_sales/w_warehouse_sq_ft) as oct_sales_per_sq_foot - ,sum(nov_sales/w_warehouse_sq_ft) as nov_sales_per_sq_foot - ,sum(dec_sales/w_warehouse_sq_ft) as dec_sales_per_sq_foot - ,sum(jan_net) as jan_net - ,sum(feb_net) as feb_net - ,sum(mar_net) as mar_net - ,sum(apr_net) as apr_net - ,sum(may_net) as may_net - ,sum(jun_net) as jun_net - ,sum(jul_net) as jul_net - ,sum(aug_net) as aug_net - ,sum(sep_net) as sep_net - ,sum(oct_net) as oct_net - ,sum(nov_net) as nov_net - ,sum(dec_net) as dec_net - from ( - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'HARMSTORF' || ',' || 'DIAMOND' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then ws_ext_list_price* ws_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then ws_ext_list_price* ws_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then ws_ext_list_price* ws_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then ws_ext_list_price* ws_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then ws_ext_list_price* ws_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then ws_ext_list_price* ws_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then ws_ext_list_price* ws_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then ws_ext_list_price* ws_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then ws_ext_list_price* ws_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then ws_ext_list_price* ws_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then ws_ext_list_price* ws_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then ws_ext_list_price* ws_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as dec_net - from - web_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - ws_warehouse_sk = w_warehouse_sk - and ws_sold_date_sk = d_date_sk - and ws_sold_time_sk = t_time_sk - and ws_ship_mode_sk = sm_ship_mode_sk - and d_year = 1998 - and t_time between 18403 and 18403+28800 - and sm_carrier in ('HARMSTORF','DIAMOND') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - union all - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'HARMSTORF' || ',' || 'DIAMOND' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then cs_sales_price* cs_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then cs_sales_price* cs_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then cs_sales_price* cs_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then cs_sales_price* cs_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then cs_sales_price* cs_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then cs_sales_price* cs_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then cs_sales_price* cs_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then cs_sales_price* cs_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then cs_sales_price* cs_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then cs_sales_price* cs_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then cs_sales_price* cs_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then cs_sales_price* cs_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as dec_net - from - catalog_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and cs_sold_time_sk = t_time_sk - and cs_ship_mode_sk = sm_ship_mode_sk - and d_year = 1998 - and t_time between 18403 AND 18403+28800 - and sm_carrier in ('HARMSTORF','DIAMOND') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - ) x - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - order by w_warehouse_name - limit 100; - --- end template query66.tpl query 19 in stream 10 --- start template query70a.tpl query 20 in stream 10 -with /* TPC-DS query70a.tpl 0.34 */ results as -( select - sum(ss_net_profit) as total_sum ,s_state ,s_county, 0 as gstate, 0 as g_county - from - store_sales - ,date_dim d1 - ,store - where - d1.d_month_seq between 1205 and 1205 + 11 - and d1.d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - and s_state in - ( select s_state - from (select s_state as s_state, - rank() over ( partition by s_state order by sum(ss_net_profit) desc) as ranking - from store_sales, store, date_dim - where d_month_seq between 1205 and 1205 + 11 - and d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - group by s_state - ) tmp1 - where ranking <= 5) - group by s_state,s_county) , - results_rollup as -(select total_sum ,s_state ,s_county, 0 as g_state, 0 as g_county, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum,s_state, NULL as s_county, 0 as g_state, 1 as g_county, 1 as lochierarchy from results group by s_state - union - select sum(total_sum) as total_sum ,NULL as s_state ,NULL as s_county, 1 as g_state, 1 as g_county, 2 as lochierarchy from results) - select total_sum ,s_state ,s_county, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_county = 0 then s_state end - order by total_sum desc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then s_state end - ,rank_within_parent - limit 100; - --- end template query70a.tpl query 20 in stream 10 --- start template query36a.tpl query 21 in stream 10 -with /* TPC-DS query36a.tpl 0.21 */ results as - (select - sum(ss_net_profit) as ss_net_profit, sum(ss_ext_sales_price) as ss_ext_sales_price, - sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin - ,i_category - ,i_class - ,0 as g_category, 0 as g_class - from - store_sales - ,date_dim d1 - ,item - ,store - where - d1.d_year = 1999 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and s_state in ('IL','CO','MN','MI', - 'NM','PA','TN','TX') - group by i_category,i_class) - , - results_rollup as - (select gross_margin ,i_category ,i_class,0 as t_category, 0 as t_class, 0 as lochierarchy from results - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - i_category, NULL AS i_class, 0 as t_category, 1 as t_class, 1 as lochierarchy from results group by i_category - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - NULL AS i_category ,NULL AS i_class, 1 as t_category, 1 as t_class, 2 as lochierarchy from results) - select - gross_margin ,i_category ,i_class, lochierarchy,rank() over ( - partition by lochierarchy, case when t_class = 0 then i_category end - order by gross_margin asc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then i_category end - ,rank_within_parent - limit 100; - --- end template query36a.tpl query 21 in stream 10 --- start template query20.tpl query 22 in stream 10 -select /* TPC-DS query20.tpl 0.65 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(cs_ext_sales_price) as itemrevenue - ,sum(cs_ext_sales_price)*100/sum(sum(cs_ext_sales_price)) over - (partition by i_class) as revenueratio - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and i_category in ('Books', 'Sports', 'Home') - and cs_sold_date_sk = d_date_sk - and d_date between cast('1998-05-28' as date) - and dateadd(day,30,cast('1998-05-28' as date)) - group by i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - order by i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query20.tpl query 22 in stream 10 --- start template query30.tpl query 23 in stream 10 -with /* TPC-DS query30.tpl 0.75 */ customer_total_return as - (select wr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(wr_return_amt) as ctr_total_return - from web_returns - ,date_dim - ,customer_address - where wr_returned_date_sk = d_date_sk - and d_year =2001 - and wr_returning_addr_sk = ca_address_sk - group by wr_returning_customer_sk - ,ca_state) - select c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'MO' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return -limit 100; - --- end template query30.tpl query 23 in stream 10 --- start template query25.tpl query 24 in stream 10 -select /* TPC-DS query25.tpl 0.9 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,max(ss_net_profit) as store_sales_profit - ,max(sr_net_loss) as store_returns_loss - ,max(cs_net_profit) as catalog_sales_profit - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 2000 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 10 - and d2.d_year = 2000 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_moy between 4 and 10 - and d3.d_year = 2000 - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query25.tpl query 24 in stream 10 --- start template query7.tpl query 25 in stream 10 -select /* TPC-DS query7.tpl 0.2 */ i_item_id, - avg(ss_quantity) agg1, - avg(ss_list_price) agg2, - avg(ss_coupon_amt) agg3, - avg(ss_sales_price) agg4 - from store_sales, customer_demographics, date_dim, item, promotion - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_cdemo_sk = cd_demo_sk and - ss_promo_sk = p_promo_sk and - cd_gender = 'M' and - cd_marital_status = 'D' and - cd_education_status = 'Primary' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 1999 - group by i_item_id - order by i_item_id - limit 100; - --- end template query7.tpl query 25 in stream 10 --- start template query1.tpl query 26 in stream 10 -with /* TPC-DS query1.tpl 0.12 */ customer_total_return as -(select sr_customer_sk as ctr_customer_sk -,sr_store_sk as ctr_store_sk -,sum(SR_REFUNDED_CASH) as ctr_total_return -from store_returns -,date_dim -where sr_returned_date_sk = d_date_sk -and d_year =1998 -group by sr_customer_sk -,sr_store_sk) - select c_customer_id -from customer_total_return ctr1 -,store -,customer -where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 -from customer_total_return ctr2 -where ctr1.ctr_store_sk = ctr2.ctr_store_sk) -and s_store_sk = ctr1.ctr_store_sk -and s_state = 'GA' -and ctr1.ctr_customer_sk = c_customer_sk -order by c_customer_id -limit 100; - --- end template query1.tpl query 26 in stream 10 --- start template query98.tpl query 27 in stream 10 -select /* TPC-DS query98.tpl 0.32 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ss_ext_sales_price) as itemrevenue - ,sum(ss_ext_sales_price)*100/sum(sum(ss_ext_sales_price)) over - (partition by i_class) as revenueratio -from - store_sales - ,item - ,date_dim -where - ss_item_sk = i_item_sk - and i_category in ('Children', 'Sports', 'Music') - and ss_sold_date_sk = d_date_sk - and d_date between cast('2001-04-26' as date) - and dateadd(day,30,cast('2001-04-26' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio; - --- end template query98.tpl query 27 in stream 10 --- start template query69.tpl query 28 in stream 10 -select /* TPC-DS query69.tpl 0.28 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_state in ('IL','KY','MT') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 4 and 4+2) and - (not exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 4 and 4+2) and - not exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 4 and 4+2)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - limit 100; - --- end template query69.tpl query 28 in stream 10 --- start template query47.tpl query 29 in stream 10 -with /* TPC-DS query47.tpl 0.42 */ v1 as( - select i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, - s_store_name, s_company_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - s_store_name, s_company_name - order by d_year, d_moy) rn - from item, store_sales, date_dim, store - where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - ( - d_year = 1999 or - ( d_year = 1999-1 and d_moy =12) or - ( d_year = 1999+1 and d_moy =1) - ) - group by i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy), - v2 as( - select v1.i_brand - ,v1.d_year - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1.s_store_name = v1_lag.s_store_name and - v1.s_store_name = v1_lead.s_store_name and - v1.s_company_name = v1_lag.s_company_name and - v1.s_company_name = v1_lead.s_company_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 1999 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, avg_monthly_sales - limit 100; - --- end template query47.tpl query 29 in stream 10 --- start template query94.tpl query 30 in stream 10 -select /* TPC-DS query94.tpl 0.17 */ - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '1999-2-01' and - dateadd(day,60,cast('1999-2-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'KS' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and exists (select * - from web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) -and not exists(select * - from web_returns wr1 - where ws1.ws_order_number = wr1.wr_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query94.tpl query 30 in stream 10 --- start template query82.tpl query 31 in stream 10 -select /* TPC-DS query82.tpl 0.67 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, store_sales - where i_current_price between 55 and 55+30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('2002-04-27' as date) and dateadd(day,60,cast('2002-04-27' as date)) - and i_manufact_id in (592,492,400,480) - and inv_quantity_on_hand between 100 and 500 - and ss_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query82.tpl query 31 in stream 10 --- start template query37.tpl query 32 in stream 10 -select /* TPC-DS query37.tpl 0.31 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, catalog_sales - where i_current_price between 33 and 33 + 30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('2002-05-01' as date) and dateadd(day,60,cast('2002-05-01' as date)) - and i_manufact_id in (712,948,979,675) - and inv_quantity_on_hand between 100 and 500 - and cs_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query37.tpl query 32 in stream 10 --- start template query64.tpl query 33 in stream 10 -with /* TPC-DS query64.tpl 0.20 */ cs_ui as - (select cs_item_sk - ,sum(cs_ext_list_price) as sale,sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit) as refund - from catalog_sales - ,catalog_returns - where cs_item_sk = cr_item_sk - and cs_order_number = cr_order_number - group by cs_item_sk - having sum(cs_ext_list_price)>2*sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit)), -cross_sales as - (select i_product_name product_name - ,i_item_sk item_sk - ,s_store_name store_name - ,s_zip store_zip - ,ad1.ca_street_number b_street_number - ,ad1.ca_street_name b_street_name - ,ad1.ca_city b_city - ,ad1.ca_zip b_zip - ,ad2.ca_street_number c_street_number - ,ad2.ca_street_name c_street_name - ,ad2.ca_city c_city - ,ad2.ca_zip c_zip - ,d1.d_year as syear - ,d2.d_year as fsyear - ,d3.d_year s2year - ,count(*) cnt - ,sum(ss_wholesale_cost) s1 - ,sum(ss_list_price) s2 - ,sum(ss_coupon_amt) s3 - FROM store_sales - ,store_returns - ,cs_ui - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,customer - ,customer_demographics cd1 - ,customer_demographics cd2 - ,promotion - ,household_demographics hd1 - ,household_demographics hd2 - ,customer_address ad1 - ,customer_address ad2 - ,income_band ib1 - ,income_band ib2 - ,item - WHERE ss_store_sk = s_store_sk AND - ss_sold_date_sk = d1.d_date_sk AND - ss_customer_sk = c_customer_sk AND - ss_cdemo_sk= cd1.cd_demo_sk AND - ss_hdemo_sk = hd1.hd_demo_sk AND - ss_addr_sk = ad1.ca_address_sk and - ss_item_sk = i_item_sk and - ss_item_sk = sr_item_sk and - ss_ticket_number = sr_ticket_number and - ss_item_sk = cs_ui.cs_item_sk and - c_current_cdemo_sk = cd2.cd_demo_sk AND - c_current_hdemo_sk = hd2.hd_demo_sk AND - c_current_addr_sk = ad2.ca_address_sk and - c_first_sales_date_sk = d2.d_date_sk and - c_first_shipto_date_sk = d3.d_date_sk and - ss_promo_sk = p_promo_sk and - hd1.hd_income_band_sk = ib1.ib_income_band_sk and - hd2.hd_income_band_sk = ib2.ib_income_band_sk and - cd1.cd_marital_status <> cd2.cd_marital_status and - i_color in ('lawn','lavender','royal','blue','cyan','spring') and - i_current_price between 58 and 58 + 10 and - i_current_price between 58 + 1 and 58 + 15 -group by i_product_name - ,i_item_sk - ,s_store_name - ,s_zip - ,ad1.ca_street_number - ,ad1.ca_street_name - ,ad1.ca_city - ,ad1.ca_zip - ,ad2.ca_street_number - ,ad2.ca_street_name - ,ad2.ca_city - ,ad2.ca_zip - ,d1.d_year - ,d2.d_year - ,d3.d_year -) -select cs1.product_name - ,cs1.store_name - ,cs1.store_zip - ,cs1.b_street_number - ,cs1.b_street_name - ,cs1.b_city - ,cs1.b_zip - ,cs1.c_street_number - ,cs1.c_street_name - ,cs1.c_city - ,cs1.c_zip - ,cs1.syear - ,cs1.cnt - ,cs1.s1 as s11 - ,cs1.s2 as s21 - ,cs1.s3 as s31 - ,cs2.s1 as s12 - ,cs2.s2 as s22 - ,cs2.s3 as s32 - ,cs2.syear - ,cs2.cnt -from cross_sales cs1,cross_sales cs2 -where cs1.item_sk=cs2.item_sk and - cs1.syear = 2000 and - cs2.syear = 2000 + 1 and - cs2.cnt <= cs1.cnt and - cs1.store_name = cs2.store_name and - cs1.store_zip = cs2.store_zip -order by cs1.product_name - ,cs1.store_name - ,cs2.cnt - ,cs1.s1 - ,cs2.s1; - --- end template query64.tpl query 33 in stream 10 --- start template query86a.tpl query 34 in stream 10 -with /* TPC-DS query86a.tpl 0.11 */ results as -( select sum(ws_net_paid) as total_sum, i_category, i_class, 0 as g_category, 0 as g_class - from - web_sales - ,date_dim d1 - ,item - where - d1.d_month_seq between 1210 and 1210+11 - and d1.d_date_sk = ws_sold_date_sk - and i_item_sk = ws_item_sk - group by i_category,i_class - ) , - - results_rollup as -( select total_sum ,i_category ,i_class, g_category, g_class, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum, i_category, NULL as i_class, 0 as g_category, 1 as g_class, 1 as lochierarchy from results group by i_category - union - select sum(total_sum) as total_sum, NULL as i_category, NULL as i_class, 1 as g_category, 1 as g_class, 2 as lochierarchy from results) - select - total_sum ,i_category ,i_class, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_class = 0 then i_category end - order by total_sum desc) as rank_within_parent - from - results_rollup - order by - lochierarchy desc, - case when lochierarchy = 0 then i_category end, - rank_within_parent - limit 100; - --- end template query86a.tpl query 34 in stream 10 --- start template query87.tpl query 35 in stream 10 -select /* TPC-DS query87.tpl 0.77 */ count(*) -from ((select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1206 and 1206+11) - except - (select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1206 and 1206+11) - except - (select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1206 and 1206+11) -) cool_cust -; - --- end template query87.tpl query 35 in stream 10 --- start template query28.tpl query 36 in stream 10 -select /* TPC-DS query28.tpl 0.36 */ * -from (select avg(ss_list_price) B1_LP - ,count(ss_list_price) B1_CNT - ,count(distinct ss_list_price) B1_CNTD - from store_sales - where ss_quantity between 0 and 5 - and (ss_list_price between 124 and 124+10 - or ss_coupon_amt between 6195 and 6195+1000 - or ss_wholesale_cost between 4 and 4+20)) B1, - (select avg(ss_list_price) B2_LP - ,count(ss_list_price) B2_CNT - ,count(distinct ss_list_price) B2_CNTD - from store_sales - where ss_quantity between 6 and 10 - and (ss_list_price between 69 and 69+10 - or ss_coupon_amt between 10056 and 10056+1000 - or ss_wholesale_cost between 23 and 23+20)) B2, - (select avg(ss_list_price) B3_LP - ,count(ss_list_price) B3_CNT - ,count(distinct ss_list_price) B3_CNTD - from store_sales - where ss_quantity between 11 and 15 - and (ss_list_price between 80 and 80+10 - or ss_coupon_amt between 17668 and 17668+1000 - or ss_wholesale_cost between 6 and 6+20)) B3, - (select avg(ss_list_price) B4_LP - ,count(ss_list_price) B4_CNT - ,count(distinct ss_list_price) B4_CNTD - from store_sales - where ss_quantity between 16 and 20 - and (ss_list_price between 13 and 13+10 - or ss_coupon_amt between 12799 and 12799+1000 - or ss_wholesale_cost between 72 and 72+20)) B4, - (select avg(ss_list_price) B5_LP - ,count(ss_list_price) B5_CNT - ,count(distinct ss_list_price) B5_CNTD - from store_sales - where ss_quantity between 21 and 25 - and (ss_list_price between 135 and 135+10 - or ss_coupon_amt between 11976 and 11976+1000 - or ss_wholesale_cost between 33 and 33+20)) B5, - (select avg(ss_list_price) B6_LP - ,count(ss_list_price) B6_CNT - ,count(distinct ss_list_price) B6_CNTD - from store_sales - where ss_quantity between 26 and 30 - and (ss_list_price between 103 and 103+10 - or ss_coupon_amt between 1405 and 1405+1000 - or ss_wholesale_cost between 0 and 0+20)) B6 -limit 100; - --- end template query28.tpl query 36 in stream 10 --- start template query55.tpl query 37 in stream 10 -select /* TPC-DS query55.tpl 0.82 */ i_brand_id brand_id, i_brand brand, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=34 - and d_moy=11 - and d_year=2002 - group by i_brand, i_brand_id - order by ext_price desc, i_brand_id -limit 100 ; - --- end template query55.tpl query 37 in stream 10 --- start template query85.tpl query 38 in stream 10 -select /* TPC-DS query85.tpl 0.33 */ substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) - from web_sales, web_returns, web_page, customer_demographics cd1, - customer_demographics cd2, customer_address, date_dim, reason - where ws_web_page_sk = wp_web_page_sk - and ws_item_sk = wr_item_sk - and ws_order_number = wr_order_number - and ws_sold_date_sk = d_date_sk and d_year = 2001 - and cd1.cd_demo_sk = wr_refunded_cdemo_sk - and cd2.cd_demo_sk = wr_returning_cdemo_sk - and ca_address_sk = wr_refunded_addr_sk - and r_reason_sk = wr_reason_sk - and - ( - ( - cd1.cd_marital_status = 'S' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = '4 yr Degree' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 100.00 and 150.00 - ) - or - ( - cd1.cd_marital_status = 'W' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Unknown' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 50.00 and 100.00 - ) - or - ( - cd1.cd_marital_status = 'M' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Primary' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ca_country = 'United States' - and - ca_state in ('AZ', 'NY', 'OH') - and ws_net_profit between 100 and 200 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('AL', 'GA', 'KS') - and ws_net_profit between 150 and 300 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('IL', 'MN', 'SC') - and ws_net_profit between 50 and 250 - ) - ) -group by r_reason_desc -order by substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) -limit 100; - --- end template query85.tpl query 38 in stream 10 --- start template query38.tpl query 39 in stream 10 -select /* TPC-DS query38.tpl 0.54 */ count(*) from ( - select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1199 and 1199 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1199 and 1199 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1199 and 1199 + 11 -) hot_cust -limit 100; - --- end template query38.tpl query 39 in stream 10 --- start template query44.tpl query 40 in stream 10 -select /* TPC-DS query44.tpl 0.4 */ asceding.rnk, i1.i_product_name best_performing, i2.i_product_name worst_performing -from(select * - from (select item_sk,rank() over (order by rank_col asc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 362 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 362 - and ss_cdemo_sk is null - group by ss_store_sk))V1)V11 - where rnk < 11) asceding, - (select * - from (select item_sk,rank() over (order by rank_col desc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 362 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 362 - and ss_cdemo_sk is null - group by ss_store_sk))V2)V21 - where rnk < 11) descending, -item i1, -item i2 -where asceding.rnk = descending.rnk - and i1.i_item_sk=asceding.item_sk - and i2.i_item_sk=descending.item_sk -order by asceding.rnk -limit 100; - --- end template query44.tpl query 40 in stream 10 --- start template query27a.tpl query 41 in stream 10 -with /* TPC-DS query27a.tpl 0.16 */ results as - (select i_item_id, - s_state, 0 as g_state, - ss_quantity agg1, - ss_list_price agg2, - ss_coupon_amt agg3, - ss_sales_price agg4 - from store_sales, customer_demographics, date_dim, store, item - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_store_sk = s_store_sk and - ss_cdemo_sk = cd_demo_sk and - cd_gender = 'M' and - cd_marital_status = 'M' and - cd_education_status = 'Unknown' and - d_year = 2000 and - s_state in ('LA','CO', 'FL', 'TN', 'MI', 'IN') - ) - - select i_item_id, - s_state, g_state, agg1, agg2, agg3, agg4 - from ( - select i_item_id, s_state, 0 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4 from results - group by i_item_id, s_state - union all - select i_item_id, NULL AS s_state, 1 AS g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as s_state, 1 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - ) foo - order by i_item_id, s_state - limit 100; - --- end template query27a.tpl query 41 in stream 10 --- start template query78.tpl query 42 in stream 10 -with /* TPC-DS query78.tpl 0.10 */ ws as - (select d_year AS ws_sold_year, ws_item_sk, - ws_bill_customer_sk ws_customer_sk, - sum(ws_quantity) ws_qty, - sum(ws_wholesale_cost) ws_wc, - sum(ws_sales_price) ws_sp - from web_sales - left join web_returns on wr_order_number=ws_order_number and ws_item_sk=wr_item_sk - join date_dim on ws_sold_date_sk = d_date_sk - where wr_order_number is null - group by d_year, ws_item_sk, ws_bill_customer_sk - ), -cs as - (select d_year AS cs_sold_year, cs_item_sk, - cs_bill_customer_sk cs_customer_sk, - sum(cs_quantity) cs_qty, - sum(cs_wholesale_cost) cs_wc, - sum(cs_sales_price) cs_sp - from catalog_sales - left join catalog_returns on cr_order_number=cs_order_number and cs_item_sk=cr_item_sk - join date_dim on cs_sold_date_sk = d_date_sk - where cr_order_number is null - group by d_year, cs_item_sk, cs_bill_customer_sk - ), -ss as - (select d_year AS ss_sold_year, ss_item_sk, - ss_customer_sk, - sum(ss_quantity) ss_qty, - sum(ss_wholesale_cost) ss_wc, - sum(ss_sales_price) ss_sp - from store_sales - left join store_returns on sr_ticket_number=ss_ticket_number and ss_item_sk=sr_item_sk - join date_dim on ss_sold_date_sk = d_date_sk - where sr_ticket_number is null - group by d_year, ss_item_sk, ss_customer_sk - ) - select -ss_sold_year, -round(ss_qty/(coalesce(ws_qty,0)+coalesce(cs_qty,0)),2) ratio, -ss_qty store_qty, ss_wc store_wholesale_cost, ss_sp store_sales_price, -coalesce(ws_qty,0)+coalesce(cs_qty,0) other_chan_qty, -coalesce(ws_wc,0)+coalesce(cs_wc,0) other_chan_wholesale_cost, -coalesce(ws_sp,0)+coalesce(cs_sp,0) other_chan_sales_price -from ss -left join ws on (ws_sold_year=ss_sold_year and ws_item_sk=ss_item_sk and ws_customer_sk=ss_customer_sk) -left join cs on (cs_sold_year=ss_sold_year and cs_item_sk=ss_item_sk and cs_customer_sk=ss_customer_sk) -where (coalesce(ws_qty,0)>0 or coalesce(cs_qty, 0)>0) and ss_sold_year=2001 -order by - ss_sold_year, - ss_qty desc, ss_wc desc, ss_sp desc, - other_chan_qty, - other_chan_wholesale_cost, - other_chan_sales_price, - ratio -limit 100; - --- end template query78.tpl query 42 in stream 10 --- start template query45.tpl query 43 in stream 10 -select /* TPC-DS query45.tpl 0.18 */ ca_zip, ca_county, sum(ws_sales_price) - from web_sales, customer, customer_address, date_dim, item - where ws_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ws_item_sk = i_item_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', '85392', '85460', '80348', '81792') - or - i_item_id in (select i_item_id - from item - where i_item_sk in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29) - ) - ) - and ws_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 2000 - group by ca_zip, ca_county - order by ca_zip, ca_county - limit 100; - --- end template query45.tpl query 43 in stream 10 --- start template query49.tpl query 44 in stream 10 -select /* TPC-DS query49.tpl 0.48 */ channel, item, return_ratio, return_rank, currency_rank from - (select - 'web' as channel - ,web.item - ,web.return_ratio - ,web.return_rank - ,web.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select ws.ws_item_sk as item - ,(cast(sum(coalesce(wr.wr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(wr.wr_return_amt,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - web_sales ws left outer join web_returns wr - on (ws.ws_order_number = wr.wr_order_number and - ws.ws_item_sk = wr.wr_item_sk) - ,date_dim - where - wr.wr_return_amt > 10000 - and ws.ws_net_profit > 1 - and ws.ws_net_paid > 0 - and ws.ws_quantity > 0 - and ws_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 11 - group by ws.ws_item_sk - ) in_web - ) web - where - ( - web.return_rank <= 10 - or - web.currency_rank <= 10 - ) - union - select - 'catalog' as channel - ,catalog.item - ,catalog.return_ratio - ,catalog.return_rank - ,catalog.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select - cs.cs_item_sk as item - ,(cast(sum(coalesce(cr.cr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(cr.cr_return_amount,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - catalog_sales cs left outer join catalog_returns cr - on (cs.cs_order_number = cr.cr_order_number and - cs.cs_item_sk = cr.cr_item_sk) - ,date_dim - where - cr.cr_return_amount > 10000 - and cs.cs_net_profit > 1 - and cs.cs_net_paid > 0 - and cs.cs_quantity > 0 - and cs_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 11 - group by cs.cs_item_sk - ) in_cat - ) catalog - where - ( - catalog.return_rank <= 10 - or - catalog.currency_rank <=10 - ) - union - select - 'store' as channel - ,store.item - ,store.return_ratio - ,store.return_rank - ,store.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select sts.ss_item_sk as item - ,(cast(sum(coalesce(sr.sr_return_quantity,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(sr.sr_return_amt,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - store_sales sts left outer join store_returns sr - on (sts.ss_ticket_number = sr.sr_ticket_number and sts.ss_item_sk = sr.sr_item_sk) - ,date_dim - where - sr.sr_return_amt > 10000 - and sts.ss_net_profit > 1 - and sts.ss_net_paid > 0 - and sts.ss_quantity > 0 - and ss_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 11 - group by sts.ss_item_sk - ) in_store - ) store - where ( - store.return_rank <= 10 - or - store.currency_rank <= 10 - ) - ) - order by 1,4,5,2 - limit 100; - --- end template query49.tpl query 44 in stream 10 --- start template query62.tpl query 45 in stream 10 -select /* TPC-DS query62.tpl 0.24 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 30) and - (ws_ship_date_sk - ws_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 60) and - (ws_ship_date_sk - ws_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 90) and - (ws_ship_date_sk - ws_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - web_sales - ,warehouse - ,ship_mode - ,web_site - ,date_dim -where - d_month_seq between 1202 and 1202 + 11 -and ws_ship_date_sk = d_date_sk -and ws_warehouse_sk = w_warehouse_sk -and ws_ship_mode_sk = sm_ship_mode_sk -and ws_web_site_sk = web_site_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -limit 100; - --- end template query62.tpl query 45 in stream 10 --- start template query59.tpl query 46 in stream 10 -with /* TPC-DS query59.tpl 0.30 */ wss as - (select d_week_seq, - ss_store_sk, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - group by d_week_seq,ss_store_sk - ) - select s_store_name1,s_store_id1,d_week_seq1 - ,sun_sales1/sun_sales2,mon_sales1/mon_sales2 - ,tue_sales1/tue_sales2,wed_sales1/wed_sales2,thu_sales1/thu_sales2 - ,fri_sales1/fri_sales2,sat_sales1/sat_sales2 - from - (select s_store_name s_store_name1,wss.d_week_seq d_week_seq1 - ,s_store_id s_store_id1,sun_sales sun_sales1 - ,mon_sales mon_sales1,tue_sales tue_sales1 - ,wed_sales wed_sales1,thu_sales thu_sales1 - ,fri_sales fri_sales1,sat_sales sat_sales1 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1187 and 1187 + 11) y, - (select s_store_name s_store_name2,wss.d_week_seq d_week_seq2 - ,s_store_id s_store_id2,sun_sales sun_sales2 - ,mon_sales mon_sales2,tue_sales tue_sales2 - ,wed_sales wed_sales2,thu_sales thu_sales2 - ,fri_sales fri_sales2,sat_sales sat_sales2 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1187+ 12 and 1187 + 23) x - where s_store_id1=s_store_id2 - and d_week_seq1=d_week_seq2-52 - order by s_store_name1,s_store_id1,d_week_seq1 -limit 100; - --- end template query59.tpl query 46 in stream 10 --- start template query77a.tpl query 47 in stream 10 -with /* TPC-DS query77a.tpl 0.78 */ ss as - (select s_store_sk, - sum(ss_ext_sales_price) as sales, - sum(ss_net_profit) as profit - from store_sales, - date_dim, - store - where ss_sold_date_sk = d_date_sk - and d_date between cast('2000-08-03' as date) - and dateadd(day,30,cast('2000-08-03' as date)) - and ss_store_sk = s_store_sk - group by s_store_sk) - , - sr as - (select s_store_sk, - sum(sr_return_amt) as returns, - sum(sr_net_loss) as profit_loss - from store_returns, - date_dim, - store - where sr_returned_date_sk = d_date_sk - and d_date between cast('2000-08-03' as date) - and dateadd(day,30,cast('2000-08-03' as date)) - and sr_store_sk = s_store_sk - group by s_store_sk), - cs as - (select cs_call_center_sk, - sum(cs_ext_sales_price) as sales, - sum(cs_net_profit) as profit - from catalog_sales, - date_dim - where cs_sold_date_sk = d_date_sk - and d_date between cast('2000-08-03' as date) - and dateadd(day,30,cast('2000-08-03' as date)) - group by cs_call_center_sk - ), - cr as - (select cr_call_center_sk, - sum(cr_return_amount) as returns, - sum(cr_net_loss) as profit_loss - from catalog_returns, - date_dim - where cr_returned_date_sk = d_date_sk - and d_date between cast('2000-08-03' as date) - and dateadd(day,30,cast('2000-08-03' as date)) - group by cr_call_center_sk), - ws as - ( select wp_web_page_sk, - sum(ws_ext_sales_price) as sales, - sum(ws_net_profit) as profit - from web_sales, - date_dim, - web_page - where ws_sold_date_sk = d_date_sk - and d_date between cast('2000-08-03' as date) - and dateadd(day,30,cast('2000-08-03' as date)) - and ws_web_page_sk = wp_web_page_sk - group by wp_web_page_sk), - wr as - (select wp_web_page_sk, - sum(wr_return_amt) as returns, - sum(wr_net_loss) as profit_loss - from web_returns, - date_dim, - web_page - where wr_returned_date_sk = d_date_sk - and d_date between cast('2000-08-03' as date) - and dateadd(day,30,cast('2000-08-03' as date)) - and wr_web_page_sk = wp_web_page_sk - group by wp_web_page_sk) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , ss.s_store_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ss left join sr - on ss.s_store_sk = sr.s_store_sk - union all - select 'catalog channel' as channel - , cs_call_center_sk as id - , sales - , returns - , (profit - profit_loss) as profit - from cs - , cr - union all - select 'web channel' as channel - , ws.wp_web_page_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ws left join wr - on ws.wp_web_page_sk = wr.wp_web_page_sk - ) x - group by channel, id ) - - select * - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results -) foo -order by channel, id - limit 100; - --- end template query77a.tpl query 47 in stream 10 --- start template query80a.tpl query 48 in stream 10 -with /* TPC-DS query80a.tpl 0.6 */ ssr as - (select s_store_id as store_id, - sum(ss_ext_sales_price) as sales, - sum(coalesce(sr_return_amt, 0)) as returns, - sum(ss_net_profit - coalesce(sr_net_loss, 0)) as profit - from store_sales left outer join store_returns on - (ss_item_sk = sr_item_sk and ss_ticket_number = sr_ticket_number), - date_dim, - store, - item, - promotion - where ss_sold_date_sk = d_date_sk - and d_date between cast('2002-08-15' as date) - and dateadd(day,30,cast('2002-08-15' as date)) - and ss_store_sk = s_store_sk - and ss_item_sk = i_item_sk - and i_current_price > 50 - and ss_promo_sk = p_promo_sk - and p_channel_tv = 'N' - group by s_store_id) - , - csr as - (select cp_catalog_page_id as catalog_page_id, - sum(cs_ext_sales_price) as sales, - sum(coalesce(cr_return_amount, 0)) as returns, - sum(cs_net_profit - coalesce(cr_net_loss, 0)) as profit - from catalog_sales left outer join catalog_returns on - (cs_item_sk = cr_item_sk and cs_order_number = cr_order_number), - date_dim, - catalog_page, - item, - promotion - where cs_sold_date_sk = d_date_sk - and d_date between cast('2002-08-15' as date) - and dateadd(day,30,cast('2002-08-15' as date)) - and cs_catalog_page_sk = cp_catalog_page_sk - and cs_item_sk = i_item_sk - and i_current_price > 50 - and cs_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(ws_ext_sales_price) as sales, - sum(coalesce(wr_return_amt, 0)) as returns, - sum(ws_net_profit - coalesce(wr_net_loss, 0)) as profit - from web_sales left outer join web_returns on - (ws_item_sk = wr_item_sk and ws_order_number = wr_order_number), - date_dim, - web_site, - item, - promotion - where ws_sold_date_sk = d_date_sk - and d_date between cast('2002-08-15' as date) - and dateadd(day,30,cast('2002-08-15' as date)) - and ws_web_site_sk = web_site_sk - and ws_item_sk = i_item_sk - and i_current_price > 50 - and ws_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by web_site_id) -, -results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || store_id as id - , sales - , returns - , profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || catalog_page_id as id - , sales - , returns - , profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , profit - from wsr - ) x - group by channel, id) - - select channel - , id - , sales - , returns - , profit - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results - ) foo - order by channel, id - limit 100; - --- end template query80a.tpl query 48 in stream 10 --- start template query84.tpl query 49 in stream 10 -select /* TPC-DS query84.tpl 0.80 */ c_customer_id as customer_id - , coalesce(c_last_name,'') || ', ' || coalesce(c_first_name,'') as customername - from customer - ,customer_address - ,customer_demographics - ,household_demographics - ,income_band - ,store_returns - where ca_city = 'Buena Vista' - and c_current_addr_sk = ca_address_sk - and ib_lower_bound >= 40429 - and ib_upper_bound <= 40429 + 50000 - and ib_income_band_sk = hd_income_band_sk - and cd_demo_sk = c_current_cdemo_sk - and hd_demo_sk = c_current_hdemo_sk - and sr_cdemo_sk = cd_demo_sk - order by c_customer_id - limit 100; - --- end template query84.tpl query 49 in stream 10 --- start template query67a.tpl query 50 in stream 10 -with /* TPC-DS query67a.tpl 0.35 */ results as -( select i_category ,i_class ,i_brand ,i_product_name ,d_year ,d_qoy ,d_moy ,s_store_id - ,sum(coalesce(ss_sales_price*ss_quantity,0)) sumsales - from store_sales ,date_dim ,store ,item - where ss_sold_date_sk=d_date_sk - and ss_item_sk=i_item_sk - and ss_store_sk = s_store_sk - and d_month_seq between 1187 and 1187 + 11 - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy,s_store_id) - , - results_rollup as - (select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, s_store_id, sumsales - from results - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy - union all - select i_category, i_class, i_brand, i_product_name, d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year - union all - select i_category, i_class, i_brand, i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name - union all - select i_category, i_class, i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand - union all - select i_category, i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class - union all - select i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category - union all - select null i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results) - - select * -from (select i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rank() over (partition by i_category order by sumsales desc) rk - from results_rollup) dw2 -where rk <= 100 -order by i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rk -limit 100; - --- end template query67a.tpl query 50 in stream 10 --- start template query52.tpl query 51 in stream 10 -select /* TPC-DS query52.tpl 0.59 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_sales_price) ext_price - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=12 - and dt.d_year=2001 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,ext_price desc - ,brand_id -limit 100 ; - --- end template query52.tpl query 51 in stream 10 --- start template query76.tpl query 52 in stream 10 -select /* TPC-DS query76.tpl 0.99 */ channel, col_name, d_year, d_qoy, i_category, COUNT(*) sales_cnt, SUM(ext_sales_price) sales_amt FROM ( - SELECT 'store' as channel, 'ss_customer_sk' col_name, d_year, d_qoy, i_category, ss_ext_sales_price ext_sales_price - FROM store_sales, item, date_dim - WHERE ss_customer_sk IS NULL - AND ss_sold_date_sk=d_date_sk - AND ss_item_sk=i_item_sk - UNION ALL - SELECT 'web' as channel, 'ws_ship_addr_sk' col_name, d_year, d_qoy, i_category, ws_ext_sales_price ext_sales_price - FROM web_sales, item, date_dim - WHERE ws_ship_addr_sk IS NULL - AND ws_sold_date_sk=d_date_sk - AND ws_item_sk=i_item_sk - UNION ALL - SELECT 'catalog' as channel, 'cs_ship_addr_sk' col_name, d_year, d_qoy, i_category, cs_ext_sales_price ext_sales_price - FROM catalog_sales, item, date_dim - WHERE cs_ship_addr_sk IS NULL - AND cs_sold_date_sk=d_date_sk - AND cs_item_sk=i_item_sk) foo -GROUP BY channel, col_name, d_year, d_qoy, i_category -ORDER BY channel, col_name, d_year, d_qoy, i_category -limit 100; - --- end template query76.tpl query 52 in stream 10 --- start template query42.tpl query 53 in stream 10 -select /* TPC-DS query42.tpl 0.61 */ dt.d_year - ,item.i_category_id - ,item.i_category - ,sum(ss_ext_sales_price) - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=11 - and dt.d_year=1998 - group by dt.d_year - ,item.i_category_id - ,item.i_category - order by sum(ss_ext_sales_price) desc,dt.d_year - ,item.i_category_id - ,item.i_category -limit 100 ; - --- end template query42.tpl query 53 in stream 10 --- start template query33.tpl query 54 in stream 10 -with /* TPC-DS query33.tpl 0.22 */ ss as ( - select - i_manufact_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Home')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 6 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id), - cs as ( - select - i_manufact_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Home')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 6 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id), - ws as ( - select - i_manufact_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Home')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 6 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id) - select i_manufact_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_manufact_id - order by total_sales -limit 100; - --- end template query33.tpl query 54 in stream 10 --- start template query65.tpl query 55 in stream 10 -select /* TPC-DS query65.tpl 0.71 */ - s_store_name, - i_item_desc, - sc.revenue, - i_current_price, - i_wholesale_cost, - i_brand - from store, item, - (select ss_store_sk, avg(revenue) as ave - from - (select ss_store_sk, ss_item_sk, - sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1196 and 1196+11 - group by ss_store_sk, ss_item_sk) sa - group by ss_store_sk) sb, - (select ss_store_sk, ss_item_sk, sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1196 and 1196+11 - group by ss_store_sk, ss_item_sk) sc - where sb.ss_store_sk = sc.ss_store_sk and - sc.revenue <= 0.1 * sb.ave and - s_store_sk = sc.ss_store_sk and - i_item_sk = sc.ss_item_sk - order by s_store_name, i_item_desc -limit 100; - --- end template query65.tpl query 55 in stream 10 --- start template query23.tpl query 56 in stream 10 -with /* TPC-DS query23.tpl 0.68 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (1998,1998+1,1998+2,1998+3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1998,1998+1,1998+2,1998+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * -from - max_store_sales)) - select sum(sales) - from (select cs_quantity*cs_list_price sales - from catalog_sales - ,date_dim - where d_year = 1998 - and d_moy = 7 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - union all - select ws_quantity*ws_list_price sales - from web_sales - ,date_dim - where d_year = 1998 - and d_moy = 7 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer)) - limit 100; -with /* TPC-DS query23.tpl 0.68 part2 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (1998,1998 + 1,1998 + 2,1998 + 3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1998,1998+1,1998+2,1998+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * - from max_store_sales)) - select c_last_name,c_first_name,sales - from (select c_last_name,c_first_name,sum(cs_quantity*cs_list_price) sales - from catalog_sales - ,customer - ,date_dim - where d_year = 1998 - and d_moy = 7 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and cs_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name - union all - select c_last_name,c_first_name,sum(ws_quantity*ws_list_price) sales - from web_sales - ,customer - ,date_dim - where d_year = 1998 - and d_moy = 7 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and ws_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name) - order by c_last_name,c_first_name,sales - limit 100; - --- end template query23.tpl query 56 in stream 10 --- start template query90.tpl query 57 in stream 10 -select /* TPC-DS query90.tpl 0.40 */ cast(amc as decimal(15,4))/cast(pmc as decimal(15,4)) am_pm_ratio - from ( select count(*) amc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 6 and 6+1 - and household_demographics.hd_dep_count = 9 - and web_page.wp_char_count between 5000 and 5200) at, - ( select count(*) pmc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 20 and 20+1 - and household_demographics.hd_dep_count = 9 - and web_page.wp_char_count between 5000 and 5200) pt - order by am_pm_ratio - limit 100; - --- end template query90.tpl query 57 in stream 10 --- start template query88.tpl query 58 in stream 10 -select /* TPC-DS query88.tpl 0.66 */ * -from - (select count(*) h8_30_to_9 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s1, - (select count(*) h9_to_9_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s2, - (select count(*) h9_30_to_10 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s3, - (select count(*) h10_to_10_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s4, - (select count(*) h10_30_to_11 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s5, - (select count(*) h11_to_11_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s6, - (select count(*) h11_30_to_12 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s7, - (select count(*) h12_to_12_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 12 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s8 -; - --- end template query88.tpl query 58 in stream 10 --- start template query99.tpl query 59 in stream 10 -select /* TPC-DS query99.tpl 0.94 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 30) and - (cs_ship_date_sk - cs_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 60) and - (cs_ship_date_sk - cs_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 90) and - (cs_ship_date_sk - cs_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - catalog_sales - ,warehouse - ,ship_mode - ,call_center - ,date_dim -where - d_month_seq between 1190 and 1190 + 11 -and cs_ship_date_sk = d_date_sk -and cs_warehouse_sk = w_warehouse_sk -and cs_ship_mode_sk = sm_ship_mode_sk -and cs_call_center_sk = cc_call_center_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -limit 100; - --- end template query99.tpl query 59 in stream 10 --- start template query35a.tpl query 60 in stream 10 -select /* TPC-DS query35a.tpl 0.47 */ - ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - count(*) cnt1, - max(cd_dep_count), - min(cd_dep_count), - stddev_samp(cd_dep_count), - cd_dep_employed_count, - count(*) cnt2, - max(cd_dep_employed_count), - min(cd_dep_employed_count), - stddev_samp(cd_dep_employed_count), - cd_dep_college_count, - count(*) cnt3, - max(cd_dep_college_count), - min(cd_dep_college_count), - stddev_samp(cd_dep_college_count) - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2002 and - d_qoy < 4) and - exists (select * from - (select ws_bill_customer_sk customsk - from web_sales,date_dim - where - ws_sold_date_sk = d_date_sk and - d_year = 2002 and - d_qoy < 4 - union all - select cs_ship_customer_sk customsk - from catalog_sales,date_dim - where - cs_sold_date_sk = d_date_sk and - d_year = 2002 and - d_qoy < 4)x - where x.customsk = c.c_customer_sk) - group by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - limit 100; - --- end template query35a.tpl query 60 in stream 10 --- start template query10.tpl query 61 in stream 10 -select /* TPC-DS query10.tpl 0.26 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3, - cd_dep_count, - count(*) cnt4, - cd_dep_employed_count, - count(*) cnt5, - cd_dep_college_count, - count(*) cnt6 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_county in ('Wayne County','Tazewell County','King County','Geneva County','Marion County') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 1999 and - d_moy between 3 and 3+3) and - (exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 1999 and - d_moy between 3 ANd 3+3) or - exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 1999 and - d_moy between 3 and 3+3)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count -limit 100; - --- end template query10.tpl query 61 in stream 10 --- start template query16.tpl query 62 in stream 10 -select /* TPC-DS query16.tpl 0.25 */ - count(distinct cs_order_number) as "order count" - ,sum(cs_ext_ship_cost) as "total shipping cost" - ,sum(cs_net_profit) as "total net profit" -from - catalog_sales cs1 - ,date_dim - ,customer_address - ,call_center -where - d_date between '2001-3-01' and - dateadd(day, 60, cast('2001-3-01' as date)) -and cs1.cs_ship_date_sk = d_date_sk -and cs1.cs_ship_addr_sk = ca_address_sk -and ca_state = 'TX' -and cs1.cs_call_center_sk = cc_call_center_sk -and cc_county in ('Franklin Parish','Kittitas County','Jefferson Davis Parish','Walker County', - 'Huron County' -) -and exists (select * - from catalog_sales cs2 - where cs1.cs_order_number = cs2.cs_order_number - and cs1.cs_warehouse_sk <> cs2.cs_warehouse_sk) -and not exists(select * - from catalog_returns cr1 - where cs1.cs_order_number = cr1.cr_order_number) -order by count(distinct cs_order_number) -limit 100; - --- end template query16.tpl query 62 in stream 10 --- start template query5a.tpl query 63 in stream 10 -with /* TPC-DS query5a.tpl 0.98 */ ssr as - (select s_store_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ss_store_sk as store_sk, - ss_sold_date_sk as date_sk, - ss_ext_sales_price as sales_price, - ss_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from store_sales - union all - select sr_store_sk as store_sk, - sr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - sr_return_amt as return_amt, - sr_net_loss as net_loss - from store_returns - ) salesreturns, - date_dim, - store - where date_sk = d_date_sk - and d_date between cast('2001-08-19' as date) - and dateadd(day,14,cast('2001-08-19' as date)) - and store_sk = s_store_sk - group by s_store_id) - , - csr as - (select cp_catalog_page_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select cs_catalog_page_sk as page_sk, - cs_sold_date_sk as date_sk, - cs_ext_sales_price as sales_price, - cs_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from catalog_sales - union all - select cr_catalog_page_sk as page_sk, - cr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - cr_return_amount as return_amt, - cr_net_loss as net_loss - from catalog_returns - ) salesreturns, - date_dim, - catalog_page - where date_sk = d_date_sk - and d_date between cast('2001-08-19' as date) - and dateadd(day,14,cast('2001-08-19' as date)) - and page_sk = cp_catalog_page_sk - group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ws_web_site_sk as wsr_web_site_sk, - ws_sold_date_sk as date_sk, - ws_ext_sales_price as sales_price, - ws_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from web_sales - union all - select ws_web_site_sk as wsr_web_site_sk, - wr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - wr_return_amt as return_amt, - wr_net_loss as net_loss - from web_returns left outer join web_sales on - ( wr_item_sk = ws_item_sk - and wr_order_number = ws_order_number) - ) salesreturns, - date_dim, - web_site - where date_sk = d_date_sk - and d_date between cast('2001-08-19' as date) - and dateadd(day,14,cast('2001-08-19' as date)) - and wsr_web_site_sk = web_site_sk - group by web_site_id) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || s_store_id as id - , sales - , returns - , (profit - profit_loss) as profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || cp_catalog_page_id as id - , sales - , returns - , (profit - profit_loss) as profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , (profit - profit_loss) as profit - from wsr - ) x - group by channel, id) - select channel, id, sales, returns, profit from ( - select channel, id, sales, returns, profit from results - union - select channel, null as id, sum(sales), sum(returns), sum(profit) from results group by channel - union - select null as channel, null as id, sum(sales), sum(returns), sum(profit) from results) foo -order by channel, id -limit 100; - --- end template query5a.tpl query 63 in stream 10 --- start template query57.tpl query 64 in stream 10 -with /* TPC-DS query57.tpl 0.70 */ v1 as( - select i_category, i_brand, - cc_name, - d_year, d_moy, - sum(cs_sales_price) sum_sales, - avg(sum(cs_sales_price)) over - (partition by i_category, i_brand, - cc_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - cc_name - order by d_year, d_moy) rn - from item, catalog_sales, date_dim, call_center - where cs_item_sk = i_item_sk and - cs_sold_date_sk = d_date_sk and - cc_call_center_sk= cs_call_center_sk and - ( - d_year = 2000 or - ( d_year = 2000-1 and d_moy =12) or - ( d_year = 2000+1 and d_moy =1) - ) - group by i_category, i_brand, - cc_name , d_year, d_moy), - v2 as( - select v1.i_brand - ,v1.d_year - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1. cc_name = v1_lag. cc_name and - v1. cc_name = v1_lead. cc_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 2000 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, nsum - limit 100; - --- end template query57.tpl query 64 in stream 10 --- start template query34.tpl query 65 in stream 10 -select /* TPC-DS query34.tpl 0.73 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (date_dim.d_dom between 1 and 3 or date_dim.d_dom between 25 and 28) - and (household_demographics.hd_buy_potential = '>10000' or - household_demographics.hd_buy_potential = '0-500') - and household_demographics.hd_vehicle_count > 0 - and (case when household_demographics.hd_vehicle_count > 0 - then household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count - else null - end) > 1.2 - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_county in ('Harmon County','Saginaw County','Walker County','Wadena County', - 'Mesa County','Essex County','Richland County','Sierra County') - group by ss_ticket_number,ss_customer_sk) dn,customer - where ss_customer_sk = c_customer_sk - and cnt between 15 and 20 - order by c_last_name,c_first_name,c_salutation,c_preferred_cust_flag desc, ss_ticket_number; - --- end template query34.tpl query 65 in stream 10 --- start template query97.tpl query 66 in stream 10 -with /* TPC-DS query97.tpl 0.38 */ ssci as ( -select ss_customer_sk customer_sk - ,ss_item_sk item_sk -from store_sales,date_dim -where ss_sold_date_sk = d_date_sk - and d_month_seq between 1208 and 1208 + 11 -group by ss_customer_sk - ,ss_item_sk), -csci as( - select cs_bill_customer_sk customer_sk - ,cs_item_sk item_sk -from catalog_sales,date_dim -where cs_sold_date_sk = d_date_sk - and d_month_seq between 1208 and 1208 + 11 -group by cs_bill_customer_sk - ,cs_item_sk) - select sum(case when ssci.customer_sk is not null and csci.customer_sk is null then 1 else 0 end) store_only - ,sum(case when ssci.customer_sk is null and csci.customer_sk is not null then 1 else 0 end) catalog_only - ,sum(case when ssci.customer_sk is not null and csci.customer_sk is not null then 1 else 0 end) store_and_catalog -from ssci full outer join csci on (ssci.customer_sk=csci.customer_sk - and ssci.item_sk = csci.item_sk) -limit 100; - --- end template query97.tpl query 66 in stream 10 --- start template query72.tpl query 67 in stream 10 -select /* TPC-DS query72.tpl 0.87 */ i_item_desc - ,w_warehouse_name - ,d1.d_week_seq - ,sum(case when p_promo_sk is null then 1 else 0 end) no_promo - ,sum(case when p_promo_sk is not null then 1 else 0 end) promo - ,count(*) total_cnt -from catalog_sales -join inventory on (cs_item_sk = inv_item_sk) -join warehouse on (w_warehouse_sk=inv_warehouse_sk) -join item on (i_item_sk = cs_item_sk) -join customer_demographics on (cs_bill_cdemo_sk = cd_demo_sk) -join household_demographics on (cs_bill_hdemo_sk = hd_demo_sk) -join date_dim d1 on (cs_sold_date_sk = d1.d_date_sk) -join date_dim d2 on (inv_date_sk = d2.d_date_sk) -join date_dim d3 on (cs_ship_date_sk = d3.d_date_sk) -left outer join promotion on (cs_promo_sk=p_promo_sk) -left outer join catalog_returns on (cr_item_sk = cs_item_sk and cr_order_number = cs_order_number) -where d1.d_week_seq = d2.d_week_seq - and inv_quantity_on_hand < cs_quantity - and d3.d_date > d1.d_date + 5 - and hd_buy_potential = '501-1000' - and d1.d_year = 1999 - and cd_marital_status = 'U' -group by i_item_desc,w_warehouse_name,d1.d_week_seq -order by total_cnt desc, i_item_desc, w_warehouse_name, d_week_seq -limit 100; - --- end template query72.tpl query 67 in stream 10 --- start template query75.tpl query 68 in stream 10 -WITH /* TPC-DS query75.tpl 0.3 */ all_sales AS ( - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,SUM(sales_cnt) AS sales_cnt - ,SUM(sales_amt) AS sales_amt - FROM (SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,cs_quantity - COALESCE(cr_return_quantity,0) AS sales_cnt - ,cs_ext_sales_price - COALESCE(cr_return_amount,0.0) AS sales_amt - FROM catalog_sales JOIN item ON i_item_sk=cs_item_sk - JOIN date_dim ON d_date_sk=cs_sold_date_sk - LEFT JOIN catalog_returns ON (cs_order_number=cr_order_number - AND cs_item_sk=cr_item_sk) - WHERE i_category='Women' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ss_quantity - COALESCE(sr_return_quantity,0) AS sales_cnt - ,ss_ext_sales_price - COALESCE(sr_return_amt,0.0) AS sales_amt - FROM store_sales JOIN item ON i_item_sk=ss_item_sk - JOIN date_dim ON d_date_sk=ss_sold_date_sk - LEFT JOIN store_returns ON (ss_ticket_number=sr_ticket_number - AND ss_item_sk=sr_item_sk) - WHERE i_category='Women' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ws_quantity - COALESCE(wr_return_quantity,0) AS sales_cnt - ,ws_ext_sales_price - COALESCE(wr_return_amt,0.0) AS sales_amt - FROM web_sales JOIN item ON i_item_sk=ws_item_sk - JOIN date_dim ON d_date_sk=ws_sold_date_sk - LEFT JOIN web_returns ON (ws_order_number=wr_order_number - AND ws_item_sk=wr_item_sk) - WHERE i_category='Women') sales_detail - GROUP BY d_year, i_brand_id, i_class_id, i_category_id, i_manufact_id) - SELECT prev_yr.d_year AS prev_year - ,curr_yr.d_year AS year - ,curr_yr.i_brand_id - ,curr_yr.i_class_id - ,curr_yr.i_category_id - ,curr_yr.i_manufact_id - ,prev_yr.sales_cnt AS prev_yr_cnt - ,curr_yr.sales_cnt AS curr_yr_cnt - ,curr_yr.sales_cnt-prev_yr.sales_cnt AS sales_cnt_diff - ,curr_yr.sales_amt-prev_yr.sales_amt AS sales_amt_diff - FROM all_sales curr_yr, all_sales prev_yr - WHERE curr_yr.i_brand_id=prev_yr.i_brand_id - AND curr_yr.i_class_id=prev_yr.i_class_id - AND curr_yr.i_category_id=prev_yr.i_category_id - AND curr_yr.i_manufact_id=prev_yr.i_manufact_id - AND curr_yr.d_year=2001 - AND prev_yr.d_year=2001-1 - AND CAST(curr_yr.sales_cnt AS DECIMAL(17,2))/CAST(prev_yr.sales_cnt AS DECIMAL(17,2))<0.9 - ORDER BY sales_cnt_diff,sales_amt_diff - limit 100; - --- end template query75.tpl query 68 in stream 10 --- start template query14a.tpl query 69 in stream 10 -with /* TPC-DS query14a.tpl 0.69 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1998 AND 1998 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1998 AND 1998 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1998 AND 1998 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as - (select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2) x) -, - results AS -(select channel, i_brand_id, i_class_id, i_category_id, sum(sales) sum_sales, sum(number_sales) number_sales - from ( - select 'store' channel, i_brand_id,i_class_id - ,i_category_id,sum(ss_quantity*ss_list_price) sales - , count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1998+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales) - union all - select 'catalog' channel, i_brand_id,i_class_id,i_category_id, sum(cs_quantity*cs_list_price) sales, count(*) number_sales - from catalog_sales - ,item - ,date_dim - where cs_item_sk in (select ss_item_sk from cross_items) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1998+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(cs_quantity*cs_list_price) > (select average_sales from avg_sales) - union all - select 'web' channel, i_brand_id,i_class_id,i_category_id, sum(ws_quantity*ws_list_price) sales , count(*) number_sales - from web_sales - ,item - ,date_dim - where ws_item_sk in (select ss_item_sk from cross_items) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1998+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ws_quantity*ws_list_price) > (select average_sales from avg_sales) - ) y - group by channel, i_brand_id,i_class_id,i_category_id) - - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales -from ( - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales from results - union - select channel, i_brand_id, i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id, i_class_id - union - select channel, i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id - union - select channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel - union - select null as channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results) z -order by channel, i_brand_id, i_class_id, i_category_id - limit 100; -with /* TPC-DS query14a.tpl 0.69 part2 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1998 AND 1998 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1998 AND 1998 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1998 AND 1998 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as -(select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2) x) - select this_year.channel ty_channel - ,this_year.i_brand_id ty_brand - ,this_year.i_class_id ty_class - ,this_year.i_category_id ty_category - ,this_year.sales ty_sales - ,this_year.number_sales ty_number_sales - ,last_year.channel ly_channel - ,last_year.i_brand_id ly_brand - ,last_year.i_class_id ly_class - ,last_year.i_category_id ly_category - ,last_year.sales ly_sales - ,last_year.number_sales ly_number_sales -from - (select 'store' channel, i_brand_id,i_class_id,i_category_id - ,sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1998 + 1 - and d_moy = 12 - and d_dom = 1) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) this_year, - (select 'store' channel, i_brand_id,i_class_id - ,i_category_id, sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1998 - and d_moy = 12 - and d_dom = 1) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) last_year - where this_year.i_brand_id= last_year.i_brand_id - and this_year.i_class_id = last_year.i_class_id - and this_year.i_category_id = last_year.i_category_id - order by this_year.channel, this_year.i_brand_id, this_year.i_class_id, this_year.i_category_id - limit 100; - --- end template query14a.tpl query 69 in stream 10 --- start template query40.tpl query 70 in stream 10 -select /* TPC-DS query40.tpl 0.86 */ - w_state - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('1999-02-02' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_before - ,sum(case when (cast(d_date as date) >= cast ('1999-02-02' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_after - from - catalog_sales left outer join catalog_returns on - (cs_order_number = cr_order_number - and cs_item_sk = cr_item_sk) - ,warehouse - ,item - ,date_dim - where - i_current_price between 0.99 and 1.49 - and i_item_sk = cs_item_sk - and cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('1999-02-02' as date)) - and dateadd(day,30,cast ('1999-02-02' as date)) - group by - w_state,i_item_id - order by w_state,i_item_id -limit 100; - --- end template query40.tpl query 70 in stream 10 --- start template query73.tpl query 71 in stream 10 -select /* TPC-DS query73.tpl 0.79 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_buy_potential = '501-1000' or - household_demographics.hd_buy_potential = '5001-10000') - and household_demographics.hd_vehicle_count > 0 - and case when household_demographics.hd_vehicle_count > 0 then - household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count else null end > 1 - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_county in ('Marshall County','Levy County','Kittitas County','Sumner County') - group by ss_ticket_number,ss_customer_sk) dj,customer - where ss_customer_sk = c_customer_sk - and cnt between 1 and 5 - order by cnt desc, c_last_name asc; - --- end template query73.tpl query 71 in stream 10 --- start template query79.tpl query 72 in stream 10 -select /* TPC-DS query79.tpl 0.89 */ - c_last_name,c_first_name,substring(s_city,1,30),ss_ticket_number,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,store.s_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (household_demographics.hd_dep_count = 4 or household_demographics.hd_vehicle_count > 4) - and date_dim.d_dow = 1 - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_number_employees between 200 and 295 - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,store.s_city) ms,customer - where ss_customer_sk = c_customer_sk - order by c_last_name,c_first_name,substring(s_city,1,30), profit -limit 100; - --- end template query79.tpl query 72 in stream 10 --- start template query11.tpl query 73 in stream 10 -with /* TPC-DS query11.tpl 0.51 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ss_ext_list_price-ss_ext_discount_amt) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ws_ext_list_price-ws_ext_discount_amt) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_birth_country - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 1999 - and t_s_secyear.dyear = 1999+1 - and t_w_firstyear.dyear = 1999 - and t_w_secyear.dyear = 1999+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else 0.0 end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else 0.0 end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_birth_country -limit 100; - --- end template query11.tpl query 73 in stream 10 --- start template query6.tpl query 74 in stream 10 -select /* TPC-DS query6.tpl 0.58 */ a.ca_state state, count(*) cnt - from customer_address a - ,customer c - ,store_sales s - ,date_dim d - ,item i - where a.ca_address_sk = c.c_current_addr_sk - and c.c_customer_sk = s.ss_customer_sk - and s.ss_sold_date_sk = d.d_date_sk - and s.ss_item_sk = i.i_item_sk - and d.d_month_seq = - (select distinct (d_month_seq) - from date_dim - where d_year = 1998 - and d_moy = 4 ) - and i.i_current_price > 1.2 * - (select avg(j.i_current_price) - from item j - where j.i_category = i.i_category) - group by a.ca_state - having count(*) >= 10 - order by cnt, a.ca_state - limit 100; - --- end template query6.tpl query 74 in stream 10 --- start template query17.tpl query 75 in stream 10 -select /* TPC-DS query17.tpl 0.41 */ i_item_id - ,i_item_desc - ,s_state - ,count(ss_quantity) as store_sales_quantitycount - ,avg(ss_quantity) as store_sales_quantityave - ,stddev_samp(ss_quantity) as store_sales_quantitystdev - ,stddev_samp(ss_quantity)/avg(ss_quantity) as store_sales_quantitycov - ,count(sr_return_quantity) as store_returns_quantitycount - ,avg(sr_return_quantity) as store_returns_quantityave - ,stddev_samp(sr_return_quantity) as store_returns_quantitystdev - ,stddev_samp(sr_return_quantity)/avg(sr_return_quantity) as store_returns_quantitycov - ,count(cs_quantity) as catalog_sales_quantitycount ,avg(cs_quantity) as catalog_sales_quantityave - ,stddev_samp(cs_quantity) as catalog_sales_quantitystdev - ,stddev_samp(cs_quantity)/avg(cs_quantity) as catalog_sales_quantitycov - from store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where d1.d_quarter_name = '2002Q1' - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_quarter_name in ('2002Q1','2002Q2','2002Q3') - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_quarter_name in ('2002Q1','2002Q2','2002Q3') - group by i_item_id - ,i_item_desc - ,s_state - order by i_item_id - ,i_item_desc - ,s_state -limit 100; - --- end template query17.tpl query 75 in stream 10 --- start template query58.tpl query 76 in stream 10 -with /* TPC-DS query58.tpl 0.19 */ ss_items as - (select i_item_id item_id - ,sum(ss_ext_sales_price) ss_item_rev - from store_sales - ,item - ,date_dim - where ss_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '2002-05-24')) - and ss_sold_date_sk = d_date_sk - group by i_item_id), - cs_items as - (select i_item_id item_id - ,sum(cs_ext_sales_price) cs_item_rev - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '2002-05-24')) - and cs_sold_date_sk = d_date_sk - group by i_item_id), - ws_items as - (select i_item_id item_id - ,sum(ws_ext_sales_price) ws_item_rev - from web_sales - ,item - ,date_dim - where ws_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq =(select d_week_seq - from date_dim - where d_date = '2002-05-24')) - and ws_sold_date_sk = d_date_sk - group by i_item_id) - select ss_items.item_id - ,ss_item_rev - ,ss_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ss_dev - ,cs_item_rev - ,cs_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 cs_dev - ,ws_item_rev - ,ws_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ws_dev - ,(ss_item_rev+cs_item_rev+ws_item_rev)/3 average - from ss_items,cs_items,ws_items - where ss_items.item_id=cs_items.item_id - and ss_items.item_id=ws_items.item_id - and ss_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - and ss_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and cs_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and cs_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and ws_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and ws_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - order by item_id - ,ss_item_rev - limit 100; - --- end template query58.tpl query 76 in stream 10 --- start template query56.tpl query 77 in stream 10 -with /* TPC-DS query56.tpl 0.83 */ ss as ( - select i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where i_item_id in (select - i_item_id -from item -where i_color in ('salmon','coral','burlywood')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 4 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - cs as ( - select i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('salmon','coral','burlywood')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 4 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - ws as ( - select i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('salmon','coral','burlywood')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 4 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id) - select i_item_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by total_sales, - i_item_id - limit 100; - --- end template query56.tpl query 77 in stream 10 --- start template query83.tpl query 78 in stream 10 -with /* TPC-DS query83.tpl 0.96 */ sr_items as - (select i_item_id item_id, - sum(sr_return_quantity) sr_item_qty - from store_returns, - item, - date_dim - where sr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2002-06-12','2002-08-15','2002-11-05'))) - and sr_returned_date_sk = d_date_sk - group by i_item_id), - cr_items as - (select i_item_id item_id, - sum(cr_return_quantity) cr_item_qty - from catalog_returns, - item, - date_dim - where cr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2002-06-12','2002-08-15','2002-11-05'))) - and cr_returned_date_sk = d_date_sk - group by i_item_id), - wr_items as - (select i_item_id item_id, - sum(wr_return_quantity) wr_item_qty - from web_returns, - item, - date_dim - where wr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2002-06-12','2002-08-15','2002-11-05'))) - and wr_returned_date_sk = d_date_sk - group by i_item_id) - select sr_items.item_id - ,sr_item_qty - ,sr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 sr_dev - ,cr_item_qty - ,cr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 cr_dev - ,wr_item_qty - ,wr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 wr_dev - ,(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 average - from sr_items - ,cr_items - ,wr_items - where sr_items.item_id=cr_items.item_id - and sr_items.item_id=wr_items.item_id - order by sr_items.item_id - ,sr_item_qty - limit 100; - --- end template query83.tpl query 78 in stream 10 --- start template query51.tpl query 79 in stream 10 -WITH /* TPC-DS query51.tpl 0.46 */ web_v1 as ( -select - ws_item_sk item_sk, d_date, - sum(sum(ws_sales_price)) - over (partition by ws_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from web_sales - ,date_dim -where ws_sold_date_sk=d_date_sk - and d_month_seq between 1202 and 1202+11 - and ws_item_sk is not NULL -group by ws_item_sk, d_date), -store_v1 as ( -select - ss_item_sk item_sk, d_date, - sum(sum(ss_sales_price)) - over (partition by ss_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from store_sales - ,date_dim -where ss_sold_date_sk=d_date_sk - and d_month_seq between 1202 and 1202+11 - and ss_item_sk is not NULL -group by ss_item_sk, d_date) - select * -from (select item_sk - ,d_date - ,web_sales - ,store_sales - ,max(web_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) web_cumulative - ,max(store_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) store_cumulative - from (select case when web.item_sk is not null then web.item_sk else store.item_sk end item_sk - ,case when web.d_date is not null then web.d_date else store.d_date end d_date - ,web.cume_sales web_sales - ,store.cume_sales store_sales - from web_v1 web full outer join store_v1 store on (web.item_sk = store.item_sk - and web.d_date = store.d_date) - )x )y -where web_cumulative > store_cumulative -order by item_sk - ,d_date -limit 100; - --- end template query51.tpl query 79 in stream 10 --- start template query29.tpl query 80 in stream 10 -select /* TPC-DS query29.tpl 0.53 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,avg(ss_quantity) as store_sales_quantity - ,avg(sr_return_quantity) as store_returns_quantity - ,avg(cs_quantity) as catalog_sales_quantity - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 1998 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 4 + 3 - and d2.d_year = 1998 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_year in (1998,1998+1,1998+2) - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query29.tpl query 80 in stream 10 --- start template query22a.tpl query 81 in stream 10 -with /* TPC-DS query22a.tpl 0.55 */ results as -(select i_product_name - ,i_brand - ,i_class - ,i_category - ,avg(inv_quantity_on_hand) qoh - from inventory - ,date_dim - ,item --- ,warehouse - where inv_date_sk=d_date_sk - and inv_item_sk=i_item_sk --- and inv_warehouse_sk = w_warehouse_sk - and d_month_seq between 1201 and 1201 + 11 - group by i_product_name,i_brand,i_class,i_category), -results_rollup as -(select i_product_name, i_brand, i_class, i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class,i_category -union all -select i_product_name, i_brand, i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class -union all -select i_product_name, i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand -union all -select i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name -union all -select null i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results) - select i_product_name, i_brand, i_class, i_category,qoh - from results_rollup - order by qoh, i_product_name, i_brand, i_class, i_category -limit 100; - --- end template query22a.tpl query 81 in stream 10 --- start template query71.tpl query 82 in stream 10 -select /* TPC-DS query71.tpl 0.72 */ i_brand_id brand_id, i_brand brand,t_hour,t_minute, - sum(ext_price) ext_price - from item, (select ws_ext_sales_price as ext_price, - ws_sold_date_sk as sold_date_sk, - ws_item_sk as sold_item_sk, - ws_sold_time_sk as time_sk - from web_sales,date_dim - where d_date_sk = ws_sold_date_sk - and d_moy=12 - and d_year=1998 - union all - select cs_ext_sales_price as ext_price, - cs_sold_date_sk as sold_date_sk, - cs_item_sk as sold_item_sk, - cs_sold_time_sk as time_sk - from catalog_sales,date_dim - where d_date_sk = cs_sold_date_sk - and d_moy=12 - and d_year=1998 - union all - select ss_ext_sales_price as ext_price, - ss_sold_date_sk as sold_date_sk, - ss_item_sk as sold_item_sk, - ss_sold_time_sk as time_sk - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - and d_moy=12 - and d_year=1998 - ) tmp,time_dim - where - sold_item_sk = i_item_sk - and i_manager_id=1 - and time_sk = t_time_sk - and (t_meal_time = 'breakfast' or t_meal_time = 'dinner') - group by i_brand, i_brand_id,t_hour,t_minute - order by ext_price desc, i_brand_id - ; - --- end template query71.tpl query 82 in stream 10 --- start template query68.tpl query 83 in stream 10 -select /* TPC-DS query68.tpl 0.95 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,extended_price - ,extended_tax - ,list_price - from (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_ext_sales_price) extended_price - ,sum(ss_ext_list_price) list_price - ,sum(ss_ext_tax) extended_tax - from store_sales - ,date_dim - ,store - ,household_demographics - ,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_dep_count = 1 or - household_demographics.hd_vehicle_count= -1) - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_city in ('Shady Grove','Oak Ridge') - group by ss_ticket_number - ,ss_customer_sk - ,ss_addr_sk,ca_city) dn - ,customer - ,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,ss_ticket_number - limit 100; - --- end template query68.tpl query 83 in stream 10 --- start template query60.tpl query 84 in stream 10 -with /* TPC-DS query60.tpl 0.29 */ ss as ( - select - i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Music')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 8 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id), - cs as ( - select - i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Music')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 8 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id), - ws as ( - select - i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Music')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 8 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id) - select - i_item_id -,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by i_item_id - ,total_sales - limit 100; - --- end template query60.tpl query 84 in stream 10 --- start template query12.tpl query 85 in stream 10 -select /* TPC-DS query12.tpl 0.64 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ws_ext_sales_price) as itemrevenue - ,sum(ws_ext_sales_price)*100/sum(sum(ws_ext_sales_price)) over - (partition by i_class) as revenueratio -from - web_sales - ,item - ,date_dim -where - ws_item_sk = i_item_sk - and i_category in ('Shoes', 'Women', 'Sports') - and ws_sold_date_sk = d_date_sk - and d_date between cast('2001-05-24' as date) - and dateadd(day,30,cast('2001-05-24' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query12.tpl query 85 in stream 10 --- start template query4.tpl query 86 in stream 10 -with /* TPC-DS query4.tpl 0.93 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(((ss_ext_list_price-ss_ext_wholesale_cost-ss_ext_discount_amt)+ss_ext_sales_price)/2) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((cs_ext_list_price-cs_ext_wholesale_cost-cs_ext_discount_amt)+cs_ext_sales_price)/2) ) year_total - ,'c' sale_type - from customer - ,catalog_sales - ,date_dim - where c_customer_sk = cs_bill_customer_sk - and cs_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year -union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((ws_ext_list_price-ws_ext_wholesale_cost-ws_ext_discount_amt)+ws_ext_sales_price)/2) ) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_email_address - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_c_firstyear - ,year_total t_c_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_c_secyear.customer_id - and t_s_firstyear.customer_id = t_c_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_c_firstyear.sale_type = 'c' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_c_secyear.sale_type = 'c' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 1999 - and t_s_secyear.dyear = 1999+1 - and t_c_firstyear.dyear = 1999 - and t_c_secyear.dyear = 1999+1 - and t_w_firstyear.dyear = 1999 - and t_w_secyear.dyear = 1999+1 - and t_s_firstyear.year_total > 0 - and t_c_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_email_address -limit 100; - --- end template query4.tpl query 86 in stream 10 --- start template query89.tpl query 87 in stream 10 -select /* TPC-DS query89.tpl 0.56 */ * -from( -select i_category, i_class, i_brand, - s_store_name, s_company_name, - d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, s_store_name, s_company_name) - avg_monthly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - d_year in (1999) and - ((i_category in ('Music','Men','Electronics') and - i_class in ('rock','shirts','monitors') - ) - or (i_category in ('Children','Sports','Shoes') and - i_class in ('toddlers','pools','mens') - )) -group by i_category, i_class, i_brand, - s_store_name, s_company_name, d_moy) tmp1 -where case when (avg_monthly_sales <> 0) then (abs(sum_sales - avg_monthly_sales) / avg_monthly_sales) else null end > 0.1 -order by sum_sales - avg_monthly_sales, s_store_name -limit 100; - --- end template query89.tpl query 87 in stream 10 --- start template query61.tpl query 88 in stream 10 -select /* TPC-DS query61.tpl 0.97 */ promotions,total,cast(promotions as decimal(15,4))/cast(total as decimal(15,4))*100 -from - (select sum(ss_ext_sales_price) promotions - from store_sales - ,store - ,promotion - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_promo_sk = p_promo_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -7 - and i_category = 'Jewelry' - and (p_channel_dmail = 'Y' or p_channel_email = 'Y' or p_channel_tv = 'Y') - and s_gmt_offset = -7 - and d_year = 1998 - and d_moy = 12) promotional_sales, - (select sum(ss_ext_sales_price) total - from store_sales - ,store - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -7 - and i_category = 'Jewelry' - and s_gmt_offset = -7 - and d_year = 1998 - and d_moy = 12) all_sales -order by promotions, total -limit 100; - --- end template query61.tpl query 88 in stream 10 --- start template query46.tpl query 89 in stream 10 -select /* TPC-DS query46.tpl 0.23 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and (household_demographics.hd_dep_count = 7 or - household_demographics.hd_vehicle_count= 0) - and date_dim.d_dow in (6,0) - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_city in ('Clifton','Riverview','Stringtown','Woodville','Mount Vernon') - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,ca_city) dn,customer,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - limit 100; - --- end template query46.tpl query 89 in stream 10 --- start template query92.tpl query 90 in stream 10 -select /* TPC-DS query92.tpl 0.44 */ - sum(ws_ext_discount_amt) as "Excess Discount Amount" -from - web_sales - ,item - ,date_dim -where -i_manufact_id = 643 -and i_item_sk = ws_item_sk -and d_date between '1999-03-12' and - dateadd(day,90,cast('1999-03-12' as date)) -and d_date_sk = ws_sold_date_sk -and ws_ext_discount_amt - > ( - SELECT - 1.3 * avg(ws_ext_discount_amt) - FROM - web_sales - ,date_dim - WHERE - ws_item_sk = i_item_sk - and d_date between '1999-03-12' and - dateadd(day,90,cast('1999-03-12' as date)) - and d_date_sk = ws_sold_date_sk - ) -order by sum(ws_ext_discount_amt) -limit 100; - --- end template query92.tpl query 90 in stream 10 --- start template query13.tpl query 91 in stream 10 -select /* TPC-DS query13.tpl 0.91 */ avg(ss_quantity) - ,avg(ss_ext_sales_price) - ,avg(ss_ext_wholesale_cost) - ,sum(ss_ext_wholesale_cost) - from store_sales - ,store - ,customer_demographics - ,household_demographics - ,customer_address - ,date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2001 - and((ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'S' - and cd_education_status = '4 yr Degree' - and ss_sales_price between 100.00 and 150.00 - and hd_dep_count = 3 - )or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'W' - and cd_education_status = 'Secondary' - and ss_sales_price between 50.00 and 100.00 - and hd_dep_count = 1 - ) or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'D' - and cd_education_status = 'Advanced Degree' - and ss_sales_price between 150.00 and 200.00 - and hd_dep_count = 1 - )) - and((ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('KS', 'OH', 'CA') - and ss_net_profit between 100 and 200 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('IA', 'IL', 'WI') - and ss_net_profit between 150 and 300 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('PA', 'TX', 'NJ') - and ss_net_profit between 50 and 250 - )) -; - --- end template query13.tpl query 91 in stream 10 --- start template query9.tpl query 92 in stream 10 -select /* TPC-DS query9.tpl 0.49 */ case when (select count(*) - from store_sales - where ss_quantity between 1 and 20) > 54286959 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 1 and 20) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 1 and 20) end bucket1 , - case when (select count(*) - from store_sales - where ss_quantity between 21 and 40) > 128172808 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 21 and 40) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 21 and 40) end bucket2, - case when (select count(*) - from store_sales - where ss_quantity between 41 and 60) > 15948959 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 41 and 60) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 41 and 60) end bucket3, - case when (select count(*) - from store_sales - where ss_quantity between 61 and 80) > 7664642 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 61 and 80) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 61 and 80) end bucket4, - case when (select count(*) - from store_sales - where ss_quantity between 81 and 100) > 30700090 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 81 and 100) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 81 and 100) end bucket5 -from reason -where r_reason_sk = 1 -; - --- end template query9.tpl query 92 in stream 10 --- start template query74.tpl query 93 in stream 10 -with /* TPC-DS query74.tpl 0.76 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,min(ss_net_paid) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (2000,2000+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,min(ws_net_paid) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - and d_year in (2000,2000+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - ) - select - t_s_secyear.customer_id, t_s_secyear.customer_first_name, t_s_secyear.customer_last_name - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.year = 2000 - and t_s_secyear.year = 2000+1 - and t_w_firstyear.year = 2000 - and t_w_secyear.year = 2000+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - order by 3,1,2 -limit 100; - --- end template query74.tpl query 93 in stream 10 --- start template query8.tpl query 94 in stream 10 -select /* TPC-DS query8.tpl 0.63 */ s_store_name - ,sum(ss_net_profit) - from store_sales - ,date_dim - ,store, - (select ca_zip - from ( - SELECT substring(ca_zip,1,5) ca_zip - FROM customer_address - WHERE substring(ca_zip,1,5) IN ( - '55450','90516','81277','70764','17234','41349', - '95067','28262','74462','95913','84854', - '60972','95597','35589','56554','35346', - '23514','38334','11919','35908','35353', - '35434','14326','32198','58559','88017', - '64397','76301','99560','85481','66733', - '92758','20993','26222','45543','73029', - '99719','44400','77543','83616','76641', - '94342','88834','94818','65770','48314', - '82084','49404','43470','61534','74626', - '71361','12279','44531','53223','31346', - '24545','52587','22250','40221','64819', - '86063','29059','98980','95439','92571', - '67324','68918','64065','62539','10155', - '32556','86818','27272','29675','59359', - '82324','59936','61136','10904','12463', - '21204','31445','33279','84515','80802', - '37229','48593','10428','21358','69697', - '67373','77506','24532','23244','88161', - '83775','81714','44444','51181','62005', - '25197','47185','59301','10750','92663', - '67578','84199','86089','54082','71251', - '98235','58947','69311','55083','62360', - '24911','10543','87501','81044','92879', - '19586','68063','81721','88712','72769', - '20799','44911','58016','46070','78729', - '62221','45952','29418','74664','71172', - '37889','81943','13616','37823','94684', - '94244','53234','82280','19210','79460', - '11820','64499','86547','72145','45904', - '96972','11792','72997','62144','33012', - '43403','86785','11817','98357','40801', - '41087','67539','38940','91012','84379', - '35226','13936','85945','49641','10658', - '83360','74443','94021','65796','82984', - '16210','50069','18052','72519','42170', - '73727','13460','48986','73794','54939', - '34245','21373','57817','96154','65699', - '75098','59078','97143','36108','90272', - '27466','51075','91034','49463','68627', - '97202','67213','26841','19255','33825', - '19588','28422','65378','57737','20855', - '68159','39130','20120','88282','74163', - '94773','17987','41375','48068','97405', - '65685','13428','88584','75122','11249', - '16065','92361','38576','33573','21891', - '28164','60504','75558','76901','82091', - '17700','38328','29126','46344','93429', - '33926','30575','53925','84706','46506', - '37564','29506','99596','50471','98091', - '61371','97119','66179','70749','67094', - '71837','32564','49005','66531','87958', - '26558','42985','29450','21875','40367', - '19639','45002','90766','57463','11383', - '83514','13921','75067','39842','13343', - '71199','20952','11797','24334','89837', - '21641','86931','80518','71144','83367', - '94849','32896','96636','48400','82595', - '56813','84704','57959','60758','34285', - '37929','73127','17691','22778','18438', - '65441','87706','39171','82488','67786', - '47591','65591','14287','88340','26673', - '80626','10012','16978','21845','71569', - '25463','34443','24797','22252','93498', - '94304','61495','70119','98548','31005', - '60067','29606','17427','83889','45365', - '56231','28753','83825','96337','53893', - '95221','24308','81797','13898','53782', - '91319','45335','81675','43071','56892', - '71961','89321','92661','14715','51669', - '30767','40863','72373','36321','89451', - '52498','35303','10449','26715','60142', - '20180','45873','71372','20334','97638', - '98237','45614','89517','93468','86284', - '56119','54328','18249','75229','88157', - '54376','19676','86934','99653','75729', - '57076','62264','65637','56464','24214', - '23028','72100','79438','64628','52988', - '34129','52373','37013','23803','67789', - '27591','81464','26887','40759') - intersect - select ca_zip - from (SELECT substring(ca_zip,1,5) ca_zip,count(*) cnt - FROM customer_address, customer - WHERE ca_address_sk = c_current_addr_sk and - c_preferred_cust_flag='Y' - group by ca_zip - having count(*) > 10)A1)A2) V1 - where ss_store_sk = s_store_sk - and ss_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 2001 - and (substring(s_zip,1,2) = substring(V1.ca_zip,1,2)) - group by s_store_name - order by s_store_name - limit 100; - --- end template query8.tpl query 94 in stream 10 --- start template query3.tpl query 95 in stream 10 -select /* TPC-DS query3.tpl 0.45 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_discount_amt) sum_agg - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manufact_id = 400 - and dt.d_moy=11 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,sum_agg desc - ,brand_id - limit 100; - --- end template query3.tpl query 95 in stream 10 --- start template query95.tpl query 96 in stream 10 -with /* TPC-DS query95.tpl 0.43 */ ws_wh as -(select ws1.ws_order_number,ws1.ws_warehouse_sk wh1,ws2.ws_warehouse_sk wh2 - from web_sales ws1,web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) - select - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2000-2-01' and - dateadd(day,60,cast('2000-2-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'NC' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and ws1.ws_order_number in (select ws_order_number - from ws_wh) -and ws1.ws_order_number in (select wr_order_number - from web_returns,ws_wh - where wr_order_number = ws_wh.ws_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query95.tpl query 96 in stream 10 --- start template query26.tpl query 97 in stream 10 -select /* TPC-DS query26.tpl 0.85 */ i_item_id, - avg(cs_quantity) agg1, - avg(cs_list_price) agg2, - avg(cs_coupon_amt) agg3, - avg(cs_sales_price) agg4 - from catalog_sales, customer_demographics, date_dim, item, promotion - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd_demo_sk and - cs_promo_sk = p_promo_sk and - cd_gender = 'M' and - cd_marital_status = 'U' and - cd_education_status = 'Unknown' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 2001 - group by i_item_id - order by i_item_id - limit 100; - --- end template query26.tpl query 97 in stream 10 --- start template query81.tpl query 98 in stream 10 -with /* TPC-DS query81.tpl 0.37 */ customer_total_return as - (select cr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(cr_return_amt_inc_tax) as ctr_total_return - from catalog_returns - ,date_dim - ,customer_address - where cr_returned_date_sk = d_date_sk - and d_year =2000 - and cr_returning_addr_sk = ca_address_sk - group by cr_returning_customer_sk - ,ca_state ) - select c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'IA' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - limit 100; - --- end template query81.tpl query 98 in stream 10 --- start template query19.tpl query 99 in stream 10 -select /* TPC-DS query19.tpl 0.8 */ i_brand_id brand_id, i_brand brand, i_manufact_id, i_manufact, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item,customer,customer_address,store - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=14 - and d_moy=11 - and d_year=2000 - and ss_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and substring(ca_zip,1,5) <> substring(s_zip,1,5) - and ss_store_sk = s_store_sk - group by i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact - order by ext_price desc - ,i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact -limit 100 ; - --- end template query19.tpl query 99 in stream 10 diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/3TB/queries/query_2.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/3TB/queries/query_2.sql deleted file mode 100644 index 66abac20..00000000 --- a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/3TB/queries/query_2.sql +++ /dev/null @@ -1,5027 +0,0 @@ --- start template query56.tpl query 1 in stream 2 -with /* TPC-DS query56.tpl 0.83 */ ss as ( - select i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where i_item_id in (select - i_item_id -from item -where i_color in ('antique','orchid','beige')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 3 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - cs as ( - select i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('antique','orchid','beige')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 3 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - ws as ( - select i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('antique','orchid','beige')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 3 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id) - select i_item_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by total_sales, - i_item_id - limit 100; - --- end template query56.tpl query 1 in stream 2 --- start template query98.tpl query 2 in stream 2 -select /* TPC-DS query98.tpl 0.32 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ss_ext_sales_price) as itemrevenue - ,sum(ss_ext_sales_price)*100/sum(sum(ss_ext_sales_price)) over - (partition by i_class) as revenueratio -from - store_sales - ,item - ,date_dim -where - ss_item_sk = i_item_sk - and i_category in ('Music', 'Electronics', 'Books') - and ss_sold_date_sk = d_date_sk - and d_date between cast('1999-02-26' as date) - and dateadd(day,30,cast('1999-02-26' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio; - --- end template query98.tpl query 2 in stream 2 --- start template query59.tpl query 3 in stream 2 -with /* TPC-DS query59.tpl 0.30 */ wss as - (select d_week_seq, - ss_store_sk, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - group by d_week_seq,ss_store_sk - ) - select s_store_name1,s_store_id1,d_week_seq1 - ,sun_sales1/sun_sales2,mon_sales1/mon_sales2 - ,tue_sales1/tue_sales2,wed_sales1/wed_sales2,thu_sales1/thu_sales2 - ,fri_sales1/fri_sales2,sat_sales1/sat_sales2 - from - (select s_store_name s_store_name1,wss.d_week_seq d_week_seq1 - ,s_store_id s_store_id1,sun_sales sun_sales1 - ,mon_sales mon_sales1,tue_sales tue_sales1 - ,wed_sales wed_sales1,thu_sales thu_sales1 - ,fri_sales fri_sales1,sat_sales sat_sales1 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1203 and 1203 + 11) y, - (select s_store_name s_store_name2,wss.d_week_seq d_week_seq2 - ,s_store_id s_store_id2,sun_sales sun_sales2 - ,mon_sales mon_sales2,tue_sales tue_sales2 - ,wed_sales wed_sales2,thu_sales thu_sales2 - ,fri_sales fri_sales2,sat_sales sat_sales2 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1203+ 12 and 1203 + 23) x - where s_store_id1=s_store_id2 - and d_week_seq1=d_week_seq2-52 - order by s_store_name1,s_store_id1,d_week_seq1 -limit 100; - --- end template query59.tpl query 3 in stream 2 --- start template query24.tpl query 4 in stream 2 -with /* TPC-DS query24.tpl 0.92 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_net_profit) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip -and s_market_id=6 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'cyan' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; -with /* TPC-DS query24.tpl 0.92 part2 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_net_profit) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip - and s_market_id = 6 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'grey' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; - --- end template query24.tpl query 4 in stream 2 --- start template query88.tpl query 5 in stream 2 -select /* TPC-DS query88.tpl 0.66 */ * -from - (select count(*) h8_30_to_9 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s1, - (select count(*) h9_to_9_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s2, - (select count(*) h9_30_to_10 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s3, - (select count(*) h10_to_10_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s4, - (select count(*) h10_30_to_11 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s5, - (select count(*) h11_to_11_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s6, - (select count(*) h11_30_to_12 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s7, - (select count(*) h12_to_12_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 12 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s8 -; - --- end template query88.tpl query 5 in stream 2 --- start template query2.tpl query 6 in stream 2 -with /* TPC-DS query2.tpl 0.84 */ wscs as - (select sold_date_sk - ,sales_price - from (select ws_sold_date_sk sold_date_sk - ,ws_ext_sales_price sales_price - from web_sales - union all - select cs_sold_date_sk sold_date_sk - ,cs_ext_sales_price sales_price - from catalog_sales)), - wswscs as - (select d_week_seq, - sum(case when (d_day_name='Sunday') then sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then sales_price else null end) sat_sales - from wscs - ,date_dim - where d_date_sk = sold_date_sk - group by d_week_seq) - select d_week_seq1 - ,round(sun_sales1/sun_sales2,2) - ,round(mon_sales1/mon_sales2,2) - ,round(tue_sales1/tue_sales2,2) - ,round(wed_sales1/wed_sales2,2) - ,round(thu_sales1/thu_sales2,2) - ,round(fri_sales1/fri_sales2,2) - ,round(sat_sales1/sat_sales2,2) - from - (select wswscs.d_week_seq d_week_seq1 - ,sun_sales sun_sales1 - ,mon_sales mon_sales1 - ,tue_sales tue_sales1 - ,wed_sales wed_sales1 - ,thu_sales thu_sales1 - ,fri_sales fri_sales1 - ,sat_sales sat_sales1 - from wswscs,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 2001) y, - (select wswscs.d_week_seq d_week_seq2 - ,sun_sales sun_sales2 - ,mon_sales mon_sales2 - ,tue_sales tue_sales2 - ,wed_sales wed_sales2 - ,thu_sales thu_sales2 - ,fri_sales fri_sales2 - ,sat_sales sat_sales2 - from wswscs - ,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 2001+1) z - where d_week_seq1=d_week_seq2-53 - order by d_week_seq1; - --- end template query2.tpl query 6 in stream 2 --- start template query5a.tpl query 7 in stream 2 -with /* TPC-DS query5a.tpl 0.98 */ ssr as - (select s_store_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ss_store_sk as store_sk, - ss_sold_date_sk as date_sk, - ss_ext_sales_price as sales_price, - ss_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from store_sales - union all - select sr_store_sk as store_sk, - sr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - sr_return_amt as return_amt, - sr_net_loss as net_loss - from store_returns - ) salesreturns, - date_dim, - store - where date_sk = d_date_sk - and d_date between cast('2001-08-15' as date) - and dateadd(day,14,cast('2001-08-15' as date)) - and store_sk = s_store_sk - group by s_store_id) - , - csr as - (select cp_catalog_page_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select cs_catalog_page_sk as page_sk, - cs_sold_date_sk as date_sk, - cs_ext_sales_price as sales_price, - cs_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from catalog_sales - union all - select cr_catalog_page_sk as page_sk, - cr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - cr_return_amount as return_amt, - cr_net_loss as net_loss - from catalog_returns - ) salesreturns, - date_dim, - catalog_page - where date_sk = d_date_sk - and d_date between cast('2001-08-15' as date) - and dateadd(day,14,cast('2001-08-15' as date)) - and page_sk = cp_catalog_page_sk - group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ws_web_site_sk as wsr_web_site_sk, - ws_sold_date_sk as date_sk, - ws_ext_sales_price as sales_price, - ws_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from web_sales - union all - select ws_web_site_sk as wsr_web_site_sk, - wr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - wr_return_amt as return_amt, - wr_net_loss as net_loss - from web_returns left outer join web_sales on - ( wr_item_sk = ws_item_sk - and wr_order_number = ws_order_number) - ) salesreturns, - date_dim, - web_site - where date_sk = d_date_sk - and d_date between cast('2001-08-15' as date) - and dateadd(day,14,cast('2001-08-15' as date)) - and wsr_web_site_sk = web_site_sk - group by web_site_id) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || s_store_id as id - , sales - , returns - , (profit - profit_loss) as profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || cp_catalog_page_id as id - , sales - , returns - , (profit - profit_loss) as profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , (profit - profit_loss) as profit - from wsr - ) x - group by channel, id) - select channel, id, sales, returns, profit from ( - select channel, id, sales, returns, profit from results - union - select channel, null as id, sum(sales), sum(returns), sum(profit) from results group by channel - union - select null as channel, null as id, sum(sales), sum(returns), sum(profit) from results) foo -order by channel, id -limit 100; - --- end template query5a.tpl query 7 in stream 2 --- start template query6.tpl query 8 in stream 2 -select /* TPC-DS query6.tpl 0.58 */ a.ca_state state, count(*) cnt - from customer_address a - ,customer c - ,store_sales s - ,date_dim d - ,item i - where a.ca_address_sk = c.c_current_addr_sk - and c.c_customer_sk = s.ss_customer_sk - and s.ss_sold_date_sk = d.d_date_sk - and s.ss_item_sk = i.i_item_sk - and d.d_month_seq = - (select distinct (d_month_seq) - from date_dim - where d_year = 2002 - and d_moy = 7 ) - and i.i_current_price > 1.2 * - (select avg(j.i_current_price) - from item j - where j.i_category = i.i_category) - group by a.ca_state - having count(*) >= 10 - order by cnt, a.ca_state - limit 100; - --- end template query6.tpl query 8 in stream 2 --- start template query27a.tpl query 9 in stream 2 -with /* TPC-DS query27a.tpl 0.16 */ results as - (select i_item_id, - s_state, 0 as g_state, - ss_quantity agg1, - ss_list_price agg2, - ss_coupon_amt agg3, - ss_sales_price agg4 - from store_sales, customer_demographics, date_dim, store, item - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_store_sk = s_store_sk and - ss_cdemo_sk = cd_demo_sk and - cd_gender = 'M' and - cd_marital_status = 'S' and - cd_education_status = 'College' and - d_year = 2001 and - s_state in ('NY','AL', 'MN', 'WV', 'NC', 'GA') - ) - - select i_item_id, - s_state, g_state, agg1, agg2, agg3, agg4 - from ( - select i_item_id, s_state, 0 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4 from results - group by i_item_id, s_state - union all - select i_item_id, NULL AS s_state, 1 AS g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as s_state, 1 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - ) foo - order by i_item_id, s_state - limit 100; - --- end template query27a.tpl query 9 in stream 2 --- start template query87.tpl query 10 in stream 2 -select /* TPC-DS query87.tpl 0.77 */ count(*) -from ((select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1197 and 1197+11) - except - (select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1197 and 1197+11) - except - (select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1197 and 1197+11) -) cool_cust -; - --- end template query87.tpl query 10 in stream 2 --- start template query90.tpl query 11 in stream 2 -select /* TPC-DS query90.tpl 0.40 */ cast(amc as decimal(15,4))/cast(pmc as decimal(15,4)) am_pm_ratio - from ( select count(*) amc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 8 and 8+1 - and household_demographics.hd_dep_count = 1 - and web_page.wp_char_count between 5000 and 5200) at, - ( select count(*) pmc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 21 and 21+1 - and household_demographics.hd_dep_count = 1 - and web_page.wp_char_count between 5000 and 5200) pt - order by am_pm_ratio - limit 100; - --- end template query90.tpl query 11 in stream 2 --- start template query83.tpl query 12 in stream 2 -with /* TPC-DS query83.tpl 0.96 */ sr_items as - (select i_item_id item_id, - sum(sr_return_quantity) sr_item_qty - from store_returns, - item, - date_dim - where sr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2002-06-29','2002-09-09','2002-11-10'))) - and sr_returned_date_sk = d_date_sk - group by i_item_id), - cr_items as - (select i_item_id item_id, - sum(cr_return_quantity) cr_item_qty - from catalog_returns, - item, - date_dim - where cr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2002-06-29','2002-09-09','2002-11-10'))) - and cr_returned_date_sk = d_date_sk - group by i_item_id), - wr_items as - (select i_item_id item_id, - sum(wr_return_quantity) wr_item_qty - from web_returns, - item, - date_dim - where wr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2002-06-29','2002-09-09','2002-11-10'))) - and wr_returned_date_sk = d_date_sk - group by i_item_id) - select sr_items.item_id - ,sr_item_qty - ,sr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 sr_dev - ,cr_item_qty - ,cr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 cr_dev - ,wr_item_qty - ,wr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 wr_dev - ,(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 average - from sr_items - ,cr_items - ,wr_items - where sr_items.item_id=cr_items.item_id - and sr_items.item_id=wr_items.item_id - order by sr_items.item_id - ,sr_item_qty - limit 100; - --- end template query83.tpl query 12 in stream 2 --- start template query91.tpl query 13 in stream 2 -select /* TPC-DS query91.tpl 0.13 */ - cc_call_center_id Call_Center, - cc_name Call_Center_Name, - cc_manager Manager, - sum(cr_net_loss) Returns_Loss -from - call_center, - catalog_returns, - date_dim, - customer, - customer_address, - customer_demographics, - household_demographics -where - cr_call_center_sk = cc_call_center_sk -and cr_returned_date_sk = d_date_sk -and cr_returning_customer_sk= c_customer_sk -and cd_demo_sk = c_current_cdemo_sk -and hd_demo_sk = c_current_hdemo_sk -and ca_address_sk = c_current_addr_sk -and d_year = 1999 -and d_moy = 11 -and ( (cd_marital_status = 'M' and cd_education_status = 'Unknown') - or(cd_marital_status = 'W' and cd_education_status = 'Advanced Degree')) -and hd_buy_potential like '501-1000%' -and ca_gmt_offset = -6 -group by cc_call_center_id,cc_name,cc_manager,cd_marital_status,cd_education_status -order by sum(cr_net_loss) desc; - --- end template query91.tpl query 13 in stream 2 --- start template query28.tpl query 14 in stream 2 -select /* TPC-DS query28.tpl 0.36 */ * -from (select avg(ss_list_price) B1_LP - ,count(ss_list_price) B1_CNT - ,count(distinct ss_list_price) B1_CNTD - from store_sales - where ss_quantity between 0 and 5 - and (ss_list_price between 100 and 100+10 - or ss_coupon_amt between 7313 and 7313+1000 - or ss_wholesale_cost between 71 and 71+20)) B1, - (select avg(ss_list_price) B2_LP - ,count(ss_list_price) B2_CNT - ,count(distinct ss_list_price) B2_CNTD - from store_sales - where ss_quantity between 6 and 10 - and (ss_list_price between 187 and 187+10 - or ss_coupon_amt between 2738 and 2738+1000 - or ss_wholesale_cost between 49 and 49+20)) B2, - (select avg(ss_list_price) B3_LP - ,count(ss_list_price) B3_CNT - ,count(distinct ss_list_price) B3_CNTD - from store_sales - where ss_quantity between 11 and 15 - and (ss_list_price between 133 and 133+10 - or ss_coupon_amt between 4856 and 4856+1000 - or ss_wholesale_cost between 51 and 51+20)) B3, - (select avg(ss_list_price) B4_LP - ,count(ss_list_price) B4_CNT - ,count(distinct ss_list_price) B4_CNTD - from store_sales - where ss_quantity between 16 and 20 - and (ss_list_price between 28 and 28+10 - or ss_coupon_amt between 14150 and 14150+1000 - or ss_wholesale_cost between 22 and 22+20)) B4, - (select avg(ss_list_price) B5_LP - ,count(ss_list_price) B5_CNT - ,count(distinct ss_list_price) B5_CNTD - from store_sales - where ss_quantity between 21 and 25 - and (ss_list_price between 45 and 45+10 - or ss_coupon_amt between 15100 and 15100+1000 - or ss_wholesale_cost between 60 and 60+20)) B5, - (select avg(ss_list_price) B6_LP - ,count(ss_list_price) B6_CNT - ,count(distinct ss_list_price) B6_CNTD - from store_sales - where ss_quantity between 26 and 30 - and (ss_list_price between 57 and 57+10 - or ss_coupon_amt between 10201 and 10201+1000 - or ss_wholesale_cost between 40 and 40+20)) B6 -limit 100; - --- end template query28.tpl query 14 in stream 2 --- start template query68.tpl query 15 in stream 2 -select /* TPC-DS query68.tpl 0.95 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,extended_price - ,extended_tax - ,list_price - from (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_ext_sales_price) extended_price - ,sum(ss_ext_list_price) list_price - ,sum(ss_ext_tax) extended_tax - from store_sales - ,date_dim - ,store - ,household_demographics - ,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_dep_count = 2 or - household_demographics.hd_vehicle_count= 3) - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_city in ('Greenville','Woodland') - group by ss_ticket_number - ,ss_customer_sk - ,ss_addr_sk,ca_city) dn - ,customer - ,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,ss_ticket_number - limit 100; - --- end template query68.tpl query 15 in stream 2 --- start template query8.tpl query 16 in stream 2 -select /* TPC-DS query8.tpl 0.63 */ s_store_name - ,sum(ss_net_profit) - from store_sales - ,date_dim - ,store, - (select ca_zip - from ( - SELECT substring(ca_zip,1,5) ca_zip - FROM customer_address - WHERE substring(ca_zip,1,5) IN ( - '97227','57646','63537','49508','82778','21291', - '91710','24128','76063','58775','18777', - '61264','75764','39055','51840','34692', - '22165','78129','76783','50126','78322', - '27320','96606','71001','22721','15020', - '72641','41670','16239','39591','25328', - '64810','11337','29043','69600','59064', - '70615','50995','98908','21696','76474', - '83845','53410','81652','31543','47757', - '58590','80368','84577','28208','48023', - '76174','35762','24399','16942','24377', - '74498','52149','37686','55512','77050', - '74138','83021','47835','44846','46138', - '44823','15340','16533','50061','54042', - '84736','70642','63077','29144','84604', - '56386','90287','48651','12092','83709', - '21251','96744','40916','22215','70685', - '25325','79798','32778','77230','27033', - '31920','56375','25356','10061','14868', - '23702','36581','48360','86298','36997', - '67961','97211','44504','19917','44007', - '26699','10569','10389','33713','38623', - '96580','62288','51153','49824','93603', - '60498','33437','11533','37436','24375', - '63864','86231','67381','76680','85653', - '14440','95191','54206','42928','78108', - '22857','40400','84650','64456','54331', - '42367','53134','30214','62399','97679', - '61808','79008','51930','24060','64203', - '61200','33279','43462','56326','74061', - '63272','50455','99677','10238','55304', - '44225','62495','94805','88842','40461', - '88068','51666','96160','13428','13402', - '93249','83010','64855','69688','78523', - '51614','42841','30055','34320','85949', - '67914','65974','56289','49547','87986', - '51306','12056','49421','32238','21665', - '29796','90196','41320','83210','54911', - '42523','98954','14647','40555','11069', - '70565','59650','87464','57483','16119', - '61484','22098','49912','82942','87590', - '55856','18844','12334','64875','77264', - '69117','77917','55972','96707','18872', - '34815','58704','79430','51261','13532', - '48258','53322','47314','59699','58430', - '64988','44160','93990','80205','99720', - '89322','57193','81384','56419','81326', - '30970','14880','11026','94383','46959', - '72943','10433','64389','18213','45832', - '67945','51736','20378','44911','34498', - '69375','58066','69624','35627','65616', - '90096','44413','87619','57721','20011', - '42059','59502','68567','42887','72658', - '12818','71422','89707','87218','86363', - '36001','65140','66026','39306','87755', - '64809','22660','94039','60193','24675', - '29345','72959','23978','13106','81307', - '44979','69441','84948','10092','38312', - '60289','33249','75696','46569','42165', - '33825','41632','67273','76716','56327', - '58540','91270','61492','99690','10981', - '20282','53422','51822','72411','65250', - '65550','65239','41731','88723','73994', - '87156','12044','20389','92235','96233', - '89382','21396','62951','13829','26681', - '32736','43016','53491','24435','96148', - '43272','14576','30919','52819','87364', - '77439','84184','79309','15334','26794', - '67848','86448','32837','60146','94880', - '38975','39474','94173','11020','34504', - '48781','91477','69996','25896','52842', - '75563','40408','67967','89903','15846', - '62161','37454','28997','37851','42766', - '52910','38961','92344','74156','46673', - '39399','98752','15613','44332','82192', - '17329','45965','54808','76219','46512', - '51279','70084','82155','20917','59092', - '60529','61002','79957','23954','56549', - '73687','14545','47974','73695','18119', - '23623','12964','32154','59768') - intersect - select ca_zip - from (SELECT substring(ca_zip,1,5) ca_zip,count(*) cnt - FROM customer_address, customer - WHERE ca_address_sk = c_current_addr_sk and - c_preferred_cust_flag='Y' - group by ca_zip - having count(*) > 10)A1)A2) V1 - where ss_store_sk = s_store_sk - and ss_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 2001 - and (substring(s_zip,1,2) = substring(V1.ca_zip,1,2)) - group by s_store_name - order by s_store_name - limit 100; - --- end template query8.tpl query 16 in stream 2 --- start template query76.tpl query 17 in stream 2 -select /* TPC-DS query76.tpl 0.99 */ channel, col_name, d_year, d_qoy, i_category, COUNT(*) sales_cnt, SUM(ext_sales_price) sales_amt FROM ( - SELECT 'store' as channel, 'ss_customer_sk' col_name, d_year, d_qoy, i_category, ss_ext_sales_price ext_sales_price - FROM store_sales, item, date_dim - WHERE ss_customer_sk IS NULL - AND ss_sold_date_sk=d_date_sk - AND ss_item_sk=i_item_sk - UNION ALL - SELECT 'web' as channel, 'ws_bill_addr_sk' col_name, d_year, d_qoy, i_category, ws_ext_sales_price ext_sales_price - FROM web_sales, item, date_dim - WHERE ws_bill_addr_sk IS NULL - AND ws_sold_date_sk=d_date_sk - AND ws_item_sk=i_item_sk - UNION ALL - SELECT 'catalog' as channel, 'cs_bill_addr_sk' col_name, d_year, d_qoy, i_category, cs_ext_sales_price ext_sales_price - FROM catalog_sales, item, date_dim - WHERE cs_bill_addr_sk IS NULL - AND cs_sold_date_sk=d_date_sk - AND cs_item_sk=i_item_sk) foo -GROUP BY channel, col_name, d_year, d_qoy, i_category -ORDER BY channel, col_name, d_year, d_qoy, i_category -limit 100; - --- end template query76.tpl query 17 in stream 2 --- start template query75.tpl query 18 in stream 2 -WITH /* TPC-DS query75.tpl 0.3 */ all_sales AS ( - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,SUM(sales_cnt) AS sales_cnt - ,SUM(sales_amt) AS sales_amt - FROM (SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,cs_quantity - COALESCE(cr_return_quantity,0) AS sales_cnt - ,cs_ext_sales_price - COALESCE(cr_return_amount,0.0) AS sales_amt - FROM catalog_sales JOIN item ON i_item_sk=cs_item_sk - JOIN date_dim ON d_date_sk=cs_sold_date_sk - LEFT JOIN catalog_returns ON (cs_order_number=cr_order_number - AND cs_item_sk=cr_item_sk) - WHERE i_category='Electronics' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ss_quantity - COALESCE(sr_return_quantity,0) AS sales_cnt - ,ss_ext_sales_price - COALESCE(sr_return_amt,0.0) AS sales_amt - FROM store_sales JOIN item ON i_item_sk=ss_item_sk - JOIN date_dim ON d_date_sk=ss_sold_date_sk - LEFT JOIN store_returns ON (ss_ticket_number=sr_ticket_number - AND ss_item_sk=sr_item_sk) - WHERE i_category='Electronics' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ws_quantity - COALESCE(wr_return_quantity,0) AS sales_cnt - ,ws_ext_sales_price - COALESCE(wr_return_amt,0.0) AS sales_amt - FROM web_sales JOIN item ON i_item_sk=ws_item_sk - JOIN date_dim ON d_date_sk=ws_sold_date_sk - LEFT JOIN web_returns ON (ws_order_number=wr_order_number - AND ws_item_sk=wr_item_sk) - WHERE i_category='Electronics') sales_detail - GROUP BY d_year, i_brand_id, i_class_id, i_category_id, i_manufact_id) - SELECT prev_yr.d_year AS prev_year - ,curr_yr.d_year AS year - ,curr_yr.i_brand_id - ,curr_yr.i_class_id - ,curr_yr.i_category_id - ,curr_yr.i_manufact_id - ,prev_yr.sales_cnt AS prev_yr_cnt - ,curr_yr.sales_cnt AS curr_yr_cnt - ,curr_yr.sales_cnt-prev_yr.sales_cnt AS sales_cnt_diff - ,curr_yr.sales_amt-prev_yr.sales_amt AS sales_amt_diff - FROM all_sales curr_yr, all_sales prev_yr - WHERE curr_yr.i_brand_id=prev_yr.i_brand_id - AND curr_yr.i_class_id=prev_yr.i_class_id - AND curr_yr.i_category_id=prev_yr.i_category_id - AND curr_yr.i_manufact_id=prev_yr.i_manufact_id - AND curr_yr.d_year=2002 - AND prev_yr.d_year=2002-1 - AND CAST(curr_yr.sales_cnt AS DECIMAL(17,2))/CAST(prev_yr.sales_cnt AS DECIMAL(17,2))<0.9 - ORDER BY sales_cnt_diff,sales_amt_diff - limit 100; - --- end template query75.tpl query 18 in stream 2 --- start template query80a.tpl query 19 in stream 2 -with /* TPC-DS query80a.tpl 0.6 */ ssr as - (select s_store_id as store_id, - sum(ss_ext_sales_price) as sales, - sum(coalesce(sr_return_amt, 0)) as returns, - sum(ss_net_profit - coalesce(sr_net_loss, 0)) as profit - from store_sales left outer join store_returns on - (ss_item_sk = sr_item_sk and ss_ticket_number = sr_ticket_number), - date_dim, - store, - item, - promotion - where ss_sold_date_sk = d_date_sk - and d_date between cast('2002-08-16' as date) - and dateadd(day,30,cast('2002-08-16' as date)) - and ss_store_sk = s_store_sk - and ss_item_sk = i_item_sk - and i_current_price > 50 - and ss_promo_sk = p_promo_sk - and p_channel_tv = 'N' - group by s_store_id) - , - csr as - (select cp_catalog_page_id as catalog_page_id, - sum(cs_ext_sales_price) as sales, - sum(coalesce(cr_return_amount, 0)) as returns, - sum(cs_net_profit - coalesce(cr_net_loss, 0)) as profit - from catalog_sales left outer join catalog_returns on - (cs_item_sk = cr_item_sk and cs_order_number = cr_order_number), - date_dim, - catalog_page, - item, - promotion - where cs_sold_date_sk = d_date_sk - and d_date between cast('2002-08-16' as date) - and dateadd(day,30,cast('2002-08-16' as date)) - and cs_catalog_page_sk = cp_catalog_page_sk - and cs_item_sk = i_item_sk - and i_current_price > 50 - and cs_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(ws_ext_sales_price) as sales, - sum(coalesce(wr_return_amt, 0)) as returns, - sum(ws_net_profit - coalesce(wr_net_loss, 0)) as profit - from web_sales left outer join web_returns on - (ws_item_sk = wr_item_sk and ws_order_number = wr_order_number), - date_dim, - web_site, - item, - promotion - where ws_sold_date_sk = d_date_sk - and d_date between cast('2002-08-16' as date) - and dateadd(day,30,cast('2002-08-16' as date)) - and ws_web_site_sk = web_site_sk - and ws_item_sk = i_item_sk - and i_current_price > 50 - and ws_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by web_site_id) -, -results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || store_id as id - , sales - , returns - , profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || catalog_page_id as id - , sales - , returns - , profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , profit - from wsr - ) x - group by channel, id) - - select channel - , id - , sales - , returns - , profit - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results - ) foo - order by channel, id - limit 100; - --- end template query80a.tpl query 19 in stream 2 --- start template query1.tpl query 20 in stream 2 -with /* TPC-DS query1.tpl 0.12 */ customer_total_return as -(select sr_customer_sk as ctr_customer_sk -,sr_store_sk as ctr_store_sk -,sum(SR_RETURN_AMT) as ctr_total_return -from store_returns -,date_dim -where sr_returned_date_sk = d_date_sk -and d_year =2001 -group by sr_customer_sk -,sr_store_sk) - select c_customer_id -from customer_total_return ctr1 -,store -,customer -where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 -from customer_total_return ctr2 -where ctr1.ctr_store_sk = ctr2.ctr_store_sk) -and s_store_sk = ctr1.ctr_store_sk -and s_state = 'FL' -and ctr1.ctr_customer_sk = c_customer_sk -order by c_customer_id -limit 100; - --- end template query1.tpl query 20 in stream 2 --- start template query69.tpl query 21 in stream 2 -select /* TPC-DS query69.tpl 0.28 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_state in ('NV','OK','NY') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 2 and 2+2) and - (not exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 2 and 2+2) and - not exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 2 and 2+2)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - limit 100; - --- end template query69.tpl query 21 in stream 2 --- start template query26.tpl query 22 in stream 2 -select /* TPC-DS query26.tpl 0.85 */ i_item_id, - avg(cs_quantity) agg1, - avg(cs_list_price) agg2, - avg(cs_coupon_amt) agg3, - avg(cs_sales_price) agg4 - from catalog_sales, customer_demographics, date_dim, item, promotion - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd_demo_sk and - cs_promo_sk = p_promo_sk and - cd_gender = 'M' and - cd_marital_status = 'M' and - cd_education_status = 'College' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 2000 - group by i_item_id - order by i_item_id - limit 100; - --- end template query26.tpl query 22 in stream 2 --- start template query11.tpl query 23 in stream 2 -with /* TPC-DS query11.tpl 0.51 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ss_ext_list_price-ss_ext_discount_amt) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ws_ext_list_price-ws_ext_discount_amt) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_login - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 1998 - and t_s_secyear.dyear = 1998+1 - and t_w_firstyear.dyear = 1998 - and t_w_secyear.dyear = 1998+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else 0.0 end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else 0.0 end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_login -limit 100; - --- end template query11.tpl query 23 in stream 2 --- start template query17.tpl query 24 in stream 2 -select /* TPC-DS query17.tpl 0.41 */ i_item_id - ,i_item_desc - ,s_state - ,count(ss_quantity) as store_sales_quantitycount - ,avg(ss_quantity) as store_sales_quantityave - ,stddev_samp(ss_quantity) as store_sales_quantitystdev - ,stddev_samp(ss_quantity)/avg(ss_quantity) as store_sales_quantitycov - ,count(sr_return_quantity) as store_returns_quantitycount - ,avg(sr_return_quantity) as store_returns_quantityave - ,stddev_samp(sr_return_quantity) as store_returns_quantitystdev - ,stddev_samp(sr_return_quantity)/avg(sr_return_quantity) as store_returns_quantitycov - ,count(cs_quantity) as catalog_sales_quantitycount ,avg(cs_quantity) as catalog_sales_quantityave - ,stddev_samp(cs_quantity) as catalog_sales_quantitystdev - ,stddev_samp(cs_quantity)/avg(cs_quantity) as catalog_sales_quantitycov - from store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where d1.d_quarter_name = '2002Q1' - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_quarter_name in ('2002Q1','2002Q2','2002Q3') - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_quarter_name in ('2002Q1','2002Q2','2002Q3') - group by i_item_id - ,i_item_desc - ,s_state - order by i_item_id - ,i_item_desc - ,s_state -limit 100; - --- end template query17.tpl query 24 in stream 2 --- start template query63.tpl query 25 in stream 2 -select /* TPC-DS query63.tpl 0.27 */ * -from (select i_manager_id - ,sum(ss_sales_price) sum_sales - ,avg(sum(ss_sales_price)) over (partition by i_manager_id) avg_monthly_sales - from item - ,store_sales - ,date_dim - ,store - where ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and d_month_seq in (1209,1209+1,1209+2,1209+3,1209+4,1209+5,1209+6,1209+7,1209+8,1209+9,1209+10,1209+11) - and (( i_category in ('Books','Children','Electronics') - and i_class in ('personal','portable','reference','self-help') - and i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) - or( i_category in ('Women','Music','Men') - and i_class in ('accessories','classical','fragrances','pants') - and i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manager_id, d_moy) tmp1 -where case when avg_monthly_sales > 0 then abs (sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 -order by i_manager_id - ,avg_monthly_sales - ,sum_sales -limit 100; - --- end template query63.tpl query 25 in stream 2 --- start template query77a.tpl query 26 in stream 2 -with /* TPC-DS query77a.tpl 0.78 */ ss as - (select s_store_sk, - sum(ss_ext_sales_price) as sales, - sum(ss_net_profit) as profit - from store_sales, - date_dim, - store - where ss_sold_date_sk = d_date_sk - and d_date between cast('1998-08-28' as date) - and dateadd(day,30,cast('1998-08-28' as date)) - and ss_store_sk = s_store_sk - group by s_store_sk) - , - sr as - (select s_store_sk, - sum(sr_return_amt) as returns, - sum(sr_net_loss) as profit_loss - from store_returns, - date_dim, - store - where sr_returned_date_sk = d_date_sk - and d_date between cast('1998-08-28' as date) - and dateadd(day,30,cast('1998-08-28' as date)) - and sr_store_sk = s_store_sk - group by s_store_sk), - cs as - (select cs_call_center_sk, - sum(cs_ext_sales_price) as sales, - sum(cs_net_profit) as profit - from catalog_sales, - date_dim - where cs_sold_date_sk = d_date_sk - and d_date between cast('1998-08-28' as date) - and dateadd(day,30,cast('1998-08-28' as date)) - group by cs_call_center_sk - ), - cr as - (select cr_call_center_sk, - sum(cr_return_amount) as returns, - sum(cr_net_loss) as profit_loss - from catalog_returns, - date_dim - where cr_returned_date_sk = d_date_sk - and d_date between cast('1998-08-28' as date) - and dateadd(day,30,cast('1998-08-28' as date)) - group by cr_call_center_sk), - ws as - ( select wp_web_page_sk, - sum(ws_ext_sales_price) as sales, - sum(ws_net_profit) as profit - from web_sales, - date_dim, - web_page - where ws_sold_date_sk = d_date_sk - and d_date between cast('1998-08-28' as date) - and dateadd(day,30,cast('1998-08-28' as date)) - and ws_web_page_sk = wp_web_page_sk - group by wp_web_page_sk), - wr as - (select wp_web_page_sk, - sum(wr_return_amt) as returns, - sum(wr_net_loss) as profit_loss - from web_returns, - date_dim, - web_page - where wr_returned_date_sk = d_date_sk - and d_date between cast('1998-08-28' as date) - and dateadd(day,30,cast('1998-08-28' as date)) - and wr_web_page_sk = wp_web_page_sk - group by wp_web_page_sk) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , ss.s_store_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ss left join sr - on ss.s_store_sk = sr.s_store_sk - union all - select 'catalog channel' as channel - , cs_call_center_sk as id - , sales - , returns - , (profit - profit_loss) as profit - from cs - , cr - union all - select 'web channel' as channel - , ws.wp_web_page_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ws left join wr - on ws.wp_web_page_sk = wr.wp_web_page_sk - ) x - group by channel, id ) - - select * - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results -) foo -order by channel, id - limit 100; - --- end template query77a.tpl query 26 in stream 2 --- start template query19.tpl query 27 in stream 2 -select /* TPC-DS query19.tpl 0.8 */ i_brand_id brand_id, i_brand brand, i_manufact_id, i_manufact, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item,customer,customer_address,store - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=6 - and d_moy=12 - and d_year=2002 - and ss_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and substring(ca_zip,1,5) <> substring(s_zip,1,5) - and ss_store_sk = s_store_sk - group by i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact - order by ext_price desc - ,i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact -limit 100 ; - --- end template query19.tpl query 27 in stream 2 --- start template query21.tpl query 28 in stream 2 -select /* TPC-DS query21.tpl 0.14 */ * - from(select w_warehouse_name - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('2001-03-16' as date)) - then inv_quantity_on_hand - else 0 end) as inv_before - ,sum(case when (cast(d_date as date) >= cast ('2001-03-16' as date)) - then inv_quantity_on_hand - else 0 end) as inv_after - from inventory - ,warehouse - ,item - ,date_dim - where i_current_price between 0.99 and 1.49 - and i_item_sk = inv_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('2001-03-16' as date)) - and dateadd(day,30,cast ('2001-03-16' as date)) - group by w_warehouse_name, i_item_id) x - where (case when inv_before > 0 - then inv_after / inv_before - else null - end) between 2.0/3.0 and 3.0/2.0 - order by w_warehouse_name - ,i_item_id - limit 100; - --- end template query21.tpl query 28 in stream 2 --- start template query31.tpl query 29 in stream 2 -with /* TPC-DS query31.tpl 0.50 */ ss as - (select ca_county,d_qoy, d_year,sum(ss_ext_sales_price) as store_sales - from store_sales,date_dim,customer_address - where ss_sold_date_sk = d_date_sk - and ss_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year), - ws as - (select ca_county,d_qoy, d_year,sum(ws_ext_sales_price) as web_sales - from web_sales,date_dim,customer_address - where ws_sold_date_sk = d_date_sk - and ws_bill_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year) - select - ss1.ca_county - ,ss1.d_year - ,ws2.web_sales/ws1.web_sales web_q1_q2_increase - ,ss2.store_sales/ss1.store_sales store_q1_q2_increase - ,ws3.web_sales/ws2.web_sales web_q2_q3_increase - ,ss3.store_sales/ss2.store_sales store_q2_q3_increase - from - ss ss1 - ,ss ss2 - ,ss ss3 - ,ws ws1 - ,ws ws2 - ,ws ws3 - where - ss1.d_qoy = 1 - and ss1.d_year = 2001 - and ss1.ca_county = ss2.ca_county - and ss2.d_qoy = 2 - and ss2.d_year = 2001 - and ss2.ca_county = ss3.ca_county - and ss3.d_qoy = 3 - and ss3.d_year = 2001 - and ss1.ca_county = ws1.ca_county - and ws1.d_qoy = 1 - and ws1.d_year = 2001 - and ws1.ca_county = ws2.ca_county - and ws2.d_qoy = 2 - and ws2.d_year = 2001 - and ws1.ca_county = ws3.ca_county - and ws3.d_qoy = 3 - and ws3.d_year =2001 - and case when ws1.web_sales > 0 then ws2.web_sales/ws1.web_sales else null end - > case when ss1.store_sales > 0 then ss2.store_sales/ss1.store_sales else null end - and case when ws2.web_sales > 0 then ws3.web_sales/ws2.web_sales else null end - > case when ss2.store_sales > 0 then ss3.store_sales/ss2.store_sales else null end - order by store_q1_q2_increase; - --- end template query31.tpl query 29 in stream 2 --- start template query93.tpl query 30 in stream 2 -select /* TPC-DS query93.tpl 0.52 */ ss_customer_sk - ,sum(act_sales) sumsales - from (select ss_item_sk - ,ss_ticket_number - ,ss_customer_sk - ,case when sr_return_quantity is not null then (ss_quantity-sr_return_quantity)*ss_sales_price - else (ss_quantity*ss_sales_price) end act_sales - from store_sales left outer join store_returns on (sr_item_sk = ss_item_sk - and sr_ticket_number = ss_ticket_number) - ,reason - where sr_reason_sk = r_reason_sk - and r_reason_desc = 'reason 41') t - group by ss_customer_sk - order by sumsales, ss_customer_sk -limit 100; - --- end template query93.tpl query 30 in stream 2 --- start template query54.tpl query 31 in stream 2 -with /* TPC-DS query54.tpl 0.81 */ my_customers as ( - select distinct c_customer_sk - , c_current_addr_sk - from - ( select cs_sold_date_sk sold_date_sk, - cs_bill_customer_sk customer_sk, - cs_item_sk item_sk - from catalog_sales - union all - select ws_sold_date_sk sold_date_sk, - ws_bill_customer_sk customer_sk, - ws_item_sk item_sk - from web_sales - ) cs_or_ws_sales, - item, - date_dim, - customer - where sold_date_sk = d_date_sk - and item_sk = i_item_sk - and i_category = 'Jewelry' - and i_class = 'mens watch' - and c_customer_sk = cs_or_ws_sales.customer_sk - and d_moy = 6 - and d_year = 1999 - ) - , my_revenue as ( - select c_customer_sk, - sum(ss_ext_sales_price) as revenue - from my_customers, - store_sales, - customer_address, - store, - date_dim - where c_current_addr_sk = ca_address_sk - and ca_county = s_county - and ca_state = s_state - and ss_sold_date_sk = d_date_sk - and c_customer_sk = ss_customer_sk - and d_month_seq between (select distinct d_month_seq+1 - from date_dim where d_year = 1999 and d_moy = 6) - and (select distinct d_month_seq+3 - from date_dim where d_year = 1999 and d_moy = 6) - group by c_customer_sk - ) - , segments as - (select cast((revenue/50) as int) as segment - from my_revenue - ) - select segment, count(*) as num_customers, segment*50 as segment_base - from segments - group by segment - order by segment, num_customers - limit 100; - --- end template query54.tpl query 31 in stream 2 --- start template query39.tpl query 32 in stream 2 -with /* TPC-DS query39.tpl 0.5 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =1999 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=4 - and inv2.d_moy=4+1 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; -with /* TPC-DS query39.tpl 0.5 part2 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =1999 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=4 - and inv2.d_moy=4+1 - and inv1.cov > 1.5 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; - --- end template query39.tpl query 32 in stream 2 --- start template query10.tpl query 33 in stream 2 -select /* TPC-DS query10.tpl 0.26 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3, - cd_dep_count, - count(*) cnt4, - cd_dep_employed_count, - count(*) cnt5, - cd_dep_college_count, - count(*) cnt6 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_county in ('Fayette County','Niagara County','Pike County','Morgan County','Union County') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 4 and 4+3) and - (exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 4 ANd 4+3) or - exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 4 and 4+3)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count -limit 100; - --- end template query10.tpl query 33 in stream 2 --- start template query15.tpl query 34 in stream 2 -select /* TPC-DS query15.tpl 0.57 */ ca_zip - ,sum(cs_sales_price) - from catalog_sales - ,customer - ,customer_address - ,date_dim - where cs_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', - '85392', '85460', '80348', '81792') - or ca_state in ('CA','WA','GA') - or cs_sales_price > 500) - and cs_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 2002 - group by ca_zip - order by ca_zip - limit 100; - --- end template query15.tpl query 34 in stream 2 --- start template query55.tpl query 35 in stream 2 -select /* TPC-DS query55.tpl 0.82 */ i_brand_id brand_id, i_brand brand, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=31 - and d_moy=11 - and d_year=1999 - group by i_brand, i_brand_id - order by ext_price desc, i_brand_id -limit 100 ; - --- end template query55.tpl query 35 in stream 2 --- start template query14a.tpl query 36 in stream 2 -with /* TPC-DS query14a.tpl 0.69 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1999 AND 1999 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1999 AND 1999 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1999 AND 1999 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as - (select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2) x) -, - results AS -(select channel, i_brand_id, i_class_id, i_category_id, sum(sales) sum_sales, sum(number_sales) number_sales - from ( - select 'store' channel, i_brand_id,i_class_id - ,i_category_id,sum(ss_quantity*ss_list_price) sales - , count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1999+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales) - union all - select 'catalog' channel, i_brand_id,i_class_id,i_category_id, sum(cs_quantity*cs_list_price) sales, count(*) number_sales - from catalog_sales - ,item - ,date_dim - where cs_item_sk in (select ss_item_sk from cross_items) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1999+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(cs_quantity*cs_list_price) > (select average_sales from avg_sales) - union all - select 'web' channel, i_brand_id,i_class_id,i_category_id, sum(ws_quantity*ws_list_price) sales , count(*) number_sales - from web_sales - ,item - ,date_dim - where ws_item_sk in (select ss_item_sk from cross_items) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1999+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ws_quantity*ws_list_price) > (select average_sales from avg_sales) - ) y - group by channel, i_brand_id,i_class_id,i_category_id) - - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales -from ( - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales from results - union - select channel, i_brand_id, i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id, i_class_id - union - select channel, i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id - union - select channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel - union - select null as channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results) z -order by channel, i_brand_id, i_class_id, i_category_id - limit 100; -with /* TPC-DS query14a.tpl 0.69 part2 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1999 AND 1999 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1999 AND 1999 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1999 AND 1999 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as -(select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2) x) - select this_year.channel ty_channel - ,this_year.i_brand_id ty_brand - ,this_year.i_class_id ty_class - ,this_year.i_category_id ty_category - ,this_year.sales ty_sales - ,this_year.number_sales ty_number_sales - ,last_year.channel ly_channel - ,last_year.i_brand_id ly_brand - ,last_year.i_class_id ly_class - ,last_year.i_category_id ly_category - ,last_year.sales ly_sales - ,last_year.number_sales ly_number_sales -from - (select 'store' channel, i_brand_id,i_class_id,i_category_id - ,sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1999 + 1 - and d_moy = 12 - and d_dom = 15) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) this_year, - (select 'store' channel, i_brand_id,i_class_id - ,i_category_id, sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1999 - and d_moy = 12 - and d_dom = 15) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) last_year - where this_year.i_brand_id= last_year.i_brand_id - and this_year.i_class_id = last_year.i_class_id - and this_year.i_category_id = last_year.i_category_id - order by this_year.channel, this_year.i_brand_id, this_year.i_class_id, this_year.i_category_id - limit 100; - --- end template query14a.tpl query 36 in stream 2 --- start template query38.tpl query 37 in stream 2 -select /* TPC-DS query38.tpl 0.54 */ count(*) from ( - select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1180 and 1180 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1180 and 1180 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1180 and 1180 + 11 -) hot_cust -limit 100; - --- end template query38.tpl query 37 in stream 2 --- start template query42.tpl query 38 in stream 2 -select /* TPC-DS query42.tpl 0.61 */ dt.d_year - ,item.i_category_id - ,item.i_category - ,sum(ss_ext_sales_price) - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=12 - and dt.d_year=2001 - group by dt.d_year - ,item.i_category_id - ,item.i_category - order by sum(ss_ext_sales_price) desc,dt.d_year - ,item.i_category_id - ,item.i_category -limit 100 ; - --- end template query42.tpl query 38 in stream 2 --- start template query53.tpl query 39 in stream 2 -select /* TPC-DS query53.tpl 0.88 */ * from -(select i_manufact_id, -sum(ss_sales_price) sum_sales, -avg(sum(ss_sales_price)) over (partition by i_manufact_id) avg_quarterly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and -ss_sold_date_sk = d_date_sk and -ss_store_sk = s_store_sk and -d_month_seq in (1218,1218+1,1218+2,1218+3,1218+4,1218+5,1218+6,1218+7,1218+8,1218+9,1218+10,1218+11) and -((i_category in ('Books','Children','Electronics') and -i_class in ('personal','portable','reference','self-help') and -i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) -or(i_category in ('Women','Music','Men') and -i_class in ('accessories','classical','fragrances','pants') and -i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manufact_id, d_qoy ) tmp1 -where case when avg_quarterly_sales > 0 - then abs (sum_sales - avg_quarterly_sales)/ avg_quarterly_sales - else null end > 0.1 -order by avg_quarterly_sales, - sum_sales, - i_manufact_id -limit 100; - --- end template query53.tpl query 39 in stream 2 --- start template query45.tpl query 40 in stream 2 -select /* TPC-DS query45.tpl 0.18 */ ca_zip, ca_county, sum(ws_sales_price) - from web_sales, customer, customer_address, date_dim, item - where ws_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ws_item_sk = i_item_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', '85392', '85460', '80348', '81792') - or - i_item_id in (select i_item_id - from item - where i_item_sk in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29) - ) - ) - and ws_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 2002 - group by ca_zip, ca_county - order by ca_zip, ca_county - limit 100; - --- end template query45.tpl query 40 in stream 2 --- start template query99.tpl query 41 in stream 2 -select /* TPC-DS query99.tpl 0.94 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 30) and - (cs_ship_date_sk - cs_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 60) and - (cs_ship_date_sk - cs_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 90) and - (cs_ship_date_sk - cs_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - catalog_sales - ,warehouse - ,ship_mode - ,call_center - ,date_dim -where - d_month_seq between 1194 and 1194 + 11 -and cs_ship_date_sk = d_date_sk -and cs_warehouse_sk = w_warehouse_sk -and cs_ship_mode_sk = sm_ship_mode_sk -and cs_call_center_sk = cc_call_center_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -limit 100; - --- end template query99.tpl query 41 in stream 2 --- start template query67a.tpl query 42 in stream 2 -with /* TPC-DS query67a.tpl 0.35 */ results as -( select i_category ,i_class ,i_brand ,i_product_name ,d_year ,d_qoy ,d_moy ,s_store_id - ,sum(coalesce(ss_sales_price*ss_quantity,0)) sumsales - from store_sales ,date_dim ,store ,item - where ss_sold_date_sk=d_date_sk - and ss_item_sk=i_item_sk - and ss_store_sk = s_store_sk - and d_month_seq between 1184 and 1184 + 11 - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy,s_store_id) - , - results_rollup as - (select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, s_store_id, sumsales - from results - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy - union all - select i_category, i_class, i_brand, i_product_name, d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year - union all - select i_category, i_class, i_brand, i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name - union all - select i_category, i_class, i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand - union all - select i_category, i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class - union all - select i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category - union all - select null i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results) - - select * -from (select i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rank() over (partition by i_category order by sumsales desc) rk - from results_rollup) dw2 -where rk <= 100 -order by i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rk -limit 100; - --- end template query67a.tpl query 42 in stream 2 --- start template query23.tpl query 43 in stream 2 -with /* TPC-DS query23.tpl 0.68 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (2000,2000+1,2000+2,2000+3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (2000,2000+1,2000+2,2000+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * -from - max_store_sales)) - select sum(sales) - from (select cs_quantity*cs_list_price sales - from catalog_sales - ,date_dim - where d_year = 2000 - and d_moy = 3 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - union all - select ws_quantity*ws_list_price sales - from web_sales - ,date_dim - where d_year = 2000 - and d_moy = 3 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer)) - limit 100; -with /* TPC-DS query23.tpl 0.68 part2 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (2000,2000 + 1,2000 + 2,2000 + 3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (2000,2000+1,2000+2,2000+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * - from max_store_sales)) - select c_last_name,c_first_name,sales - from (select c_last_name,c_first_name,sum(cs_quantity*cs_list_price) sales - from catalog_sales - ,customer - ,date_dim - where d_year = 2000 - and d_moy = 3 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and cs_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name - union all - select c_last_name,c_first_name,sum(ws_quantity*ws_list_price) sales - from web_sales - ,customer - ,date_dim - where d_year = 2000 - and d_moy = 3 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and ws_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name) - order by c_last_name,c_first_name,sales - limit 100; - --- end template query23.tpl query 43 in stream 2 --- start template query62.tpl query 44 in stream 2 -select /* TPC-DS query62.tpl 0.24 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 30) and - (ws_ship_date_sk - ws_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 60) and - (ws_ship_date_sk - ws_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 90) and - (ws_ship_date_sk - ws_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - web_sales - ,warehouse - ,ship_mode - ,web_site - ,date_dim -where - d_month_seq between 1207 and 1207 + 11 -and ws_ship_date_sk = d_date_sk -and ws_warehouse_sk = w_warehouse_sk -and ws_ship_mode_sk = sm_ship_mode_sk -and ws_web_site_sk = web_site_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -limit 100; - --- end template query62.tpl query 44 in stream 2 --- start template query30.tpl query 45 in stream 2 -with /* TPC-DS query30.tpl 0.75 */ customer_total_return as - (select wr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(wr_return_amt) as ctr_total_return - from web_returns - ,date_dim - ,customer_address - where wr_returned_date_sk = d_date_sk - and d_year =2002 - and wr_returning_addr_sk = ca_address_sk - group by wr_returning_customer_sk - ,ca_state) - select c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'MS' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return -limit 100; - --- end template query30.tpl query 45 in stream 2 --- start template query86a.tpl query 46 in stream 2 -with /* TPC-DS query86a.tpl 0.11 */ results as -( select sum(ws_net_paid) as total_sum, i_category, i_class, 0 as g_category, 0 as g_class - from - web_sales - ,date_dim d1 - ,item - where - d1.d_month_seq between 1187 and 1187+11 - and d1.d_date_sk = ws_sold_date_sk - and i_item_sk = ws_item_sk - group by i_category,i_class - ) , - - results_rollup as -( select total_sum ,i_category ,i_class, g_category, g_class, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum, i_category, NULL as i_class, 0 as g_category, 1 as g_class, 1 as lochierarchy from results group by i_category - union - select sum(total_sum) as total_sum, NULL as i_category, NULL as i_class, 1 as g_category, 1 as g_class, 2 as lochierarchy from results) - select - total_sum ,i_category ,i_class, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_class = 0 then i_category end - order by total_sum desc) as rank_within_parent - from - results_rollup - order by - lochierarchy desc, - case when lochierarchy = 0 then i_category end, - rank_within_parent - limit 100; - --- end template query86a.tpl query 46 in stream 2 --- start template query82.tpl query 47 in stream 2 -select /* TPC-DS query82.tpl 0.67 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, store_sales - where i_current_price between 21 and 21+30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('1998-05-12' as date) and dateadd(day,60,cast('1998-05-12' as date)) - and i_manufact_id in (76,979,308,402) - and inv_quantity_on_hand between 100 and 500 - and ss_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query82.tpl query 47 in stream 2 --- start template query25.tpl query 48 in stream 2 -select /* TPC-DS query25.tpl 0.9 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,min(ss_net_profit) as store_sales_profit - ,min(sr_net_loss) as store_returns_loss - ,min(cs_net_profit) as catalog_sales_profit - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 1999 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 10 - and d2.d_year = 1999 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_moy between 4 and 10 - and d3.d_year = 1999 - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query25.tpl query 48 in stream 2 --- start template query16.tpl query 49 in stream 2 -select /* TPC-DS query16.tpl 0.25 */ - count(distinct cs_order_number) as "order count" - ,sum(cs_ext_ship_cost) as "total shipping cost" - ,sum(cs_net_profit) as "total net profit" -from - catalog_sales cs1 - ,date_dim - ,customer_address - ,call_center -where - d_date between '1999-2-01' and - dateadd(day, 60, cast('1999-2-01' as date)) -and cs1.cs_ship_date_sk = d_date_sk -and cs1.cs_ship_addr_sk = ca_address_sk -and ca_state = 'WI' -and cs1.cs_call_center_sk = cc_call_center_sk -and cc_county in ('Barrow County','Williamson County','Jackson County','Dauphin County', - 'Pennington County' -) -and exists (select * - from catalog_sales cs2 - where cs1.cs_order_number = cs2.cs_order_number - and cs1.cs_warehouse_sk <> cs2.cs_warehouse_sk) -and not exists(select * - from catalog_returns cr1 - where cs1.cs_order_number = cr1.cr_order_number) -order by count(distinct cs_order_number) -limit 100; - --- end template query16.tpl query 49 in stream 2 --- start template query81.tpl query 50 in stream 2 -with /* TPC-DS query81.tpl 0.37 */ customer_total_return as - (select cr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(cr_return_amt_inc_tax) as ctr_total_return - from catalog_returns - ,date_dim - ,customer_address - where cr_returned_date_sk = d_date_sk - and d_year =2000 - and cr_returning_addr_sk = ca_address_sk - group by cr_returning_customer_sk - ,ca_state ) - select c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'FL' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - limit 100; - --- end template query81.tpl query 50 in stream 2 --- start template query40.tpl query 51 in stream 2 -select /* TPC-DS query40.tpl 0.86 */ - w_state - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('1999-03-06' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_before - ,sum(case when (cast(d_date as date) >= cast ('1999-03-06' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_after - from - catalog_sales left outer join catalog_returns on - (cs_order_number = cr_order_number - and cs_item_sk = cr_item_sk) - ,warehouse - ,item - ,date_dim - where - i_current_price between 0.99 and 1.49 - and i_item_sk = cs_item_sk - and cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('1999-03-06' as date)) - and dateadd(day,30,cast ('1999-03-06' as date)) - group by - w_state,i_item_id - order by w_state,i_item_id -limit 100; - --- end template query40.tpl query 51 in stream 2 --- start template query44.tpl query 52 in stream 2 -select /* TPC-DS query44.tpl 0.4 */ asceding.rnk, i1.i_product_name best_performing, i2.i_product_name worst_performing -from(select * - from (select item_sk,rank() over (order by rank_col asc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 451 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 451 - and ss_hdemo_sk is null - group by ss_store_sk))V1)V11 - where rnk < 11) asceding, - (select * - from (select item_sk,rank() over (order by rank_col desc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 451 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 451 - and ss_hdemo_sk is null - group by ss_store_sk))V2)V21 - where rnk < 11) descending, -item i1, -item i2 -where asceding.rnk = descending.rnk - and i1.i_item_sk=asceding.item_sk - and i2.i_item_sk=descending.item_sk -order by asceding.rnk -limit 100; - --- end template query44.tpl query 52 in stream 2 --- start template query50.tpl query 53 in stream 2 -select /* TPC-DS query50.tpl 0.60 */ - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 30) and - (sr_returned_date_sk - ss_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 60) and - (sr_returned_date_sk - ss_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 90) and - (sr_returned_date_sk - ss_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - store_sales - ,store_returns - ,store - ,date_dim d1 - ,date_dim d2 -where - d2.d_year = 2001 -and d2.d_moy = 9 -and ss_ticket_number = sr_ticket_number -and ss_item_sk = sr_item_sk -and ss_sold_date_sk = d1.d_date_sk -and sr_returned_date_sk = d2.d_date_sk -and ss_customer_sk = sr_customer_sk -and ss_store_sk = s_store_sk -group by - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -order by s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -limit 100; - --- end template query50.tpl query 53 in stream 2 --- start template query61.tpl query 54 in stream 2 -select /* TPC-DS query61.tpl 0.97 */ promotions,total,cast(promotions as decimal(15,4))/cast(total as decimal(15,4))*100 -from - (select sum(ss_ext_sales_price) promotions - from store_sales - ,store - ,promotion - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_promo_sk = p_promo_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -6 - and i_category = 'Sports' - and (p_channel_dmail = 'Y' or p_channel_email = 'Y' or p_channel_tv = 'Y') - and s_gmt_offset = -6 - and d_year = 1998 - and d_moy = 11) promotional_sales, - (select sum(ss_ext_sales_price) total - from store_sales - ,store - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -6 - and i_category = 'Sports' - and s_gmt_offset = -6 - and d_year = 1998 - and d_moy = 11) all_sales -order by promotions, total -limit 100; - --- end template query61.tpl query 54 in stream 2 --- start template query85.tpl query 55 in stream 2 -select /* TPC-DS query85.tpl 0.33 */ substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) - from web_sales, web_returns, web_page, customer_demographics cd1, - customer_demographics cd2, customer_address, date_dim, reason - where ws_web_page_sk = wp_web_page_sk - and ws_item_sk = wr_item_sk - and ws_order_number = wr_order_number - and ws_sold_date_sk = d_date_sk and d_year = 2001 - and cd1.cd_demo_sk = wr_refunded_cdemo_sk - and cd2.cd_demo_sk = wr_returning_cdemo_sk - and ca_address_sk = wr_refunded_addr_sk - and r_reason_sk = wr_reason_sk - and - ( - ( - cd1.cd_marital_status = 'U' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Advanced Degree' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 100.00 and 150.00 - ) - or - ( - cd1.cd_marital_status = 'M' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = '4 yr Degree' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 50.00 and 100.00 - ) - or - ( - cd1.cd_marital_status = 'S' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'College' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ca_country = 'United States' - and - ca_state in ('KY', 'PA', 'SC') - and ws_net_profit between 100 and 200 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('VT', 'NE', 'VA') - and ws_net_profit between 150 and 300 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('ME', 'GA', 'NY') - and ws_net_profit between 50 and 250 - ) - ) -group by r_reason_desc -order by substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) -limit 100; - --- end template query85.tpl query 55 in stream 2 --- start template query73.tpl query 56 in stream 2 -select /* TPC-DS query73.tpl 0.79 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_buy_potential = '>10000' or - household_demographics.hd_buy_potential = '0-500') - and household_demographics.hd_vehicle_count > 0 - and case when household_demographics.hd_vehicle_count > 0 then - household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count else null end > 1 - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_county in ('Jackson County','Wadena County','Terrell County','San Miguel County') - group by ss_ticket_number,ss_customer_sk) dj,customer - where ss_customer_sk = c_customer_sk - and cnt between 1 and 5 - order by cnt desc, c_last_name asc; - --- end template query73.tpl query 56 in stream 2 --- start template query95.tpl query 57 in stream 2 -with /* TPC-DS query95.tpl 0.43 */ ws_wh as -(select ws1.ws_order_number,ws1.ws_warehouse_sk wh1,ws2.ws_warehouse_sk wh2 - from web_sales ws1,web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) - select - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2002-2-01' and - dateadd(day,60,cast('2002-2-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'CO' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and ws1.ws_order_number in (select ws_order_number - from ws_wh) -and ws1.ws_order_number in (select wr_order_number - from web_returns,ws_wh - where wr_order_number = ws_wh.ws_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query95.tpl query 57 in stream 2 --- start template query84.tpl query 58 in stream 2 -select /* TPC-DS query84.tpl 0.80 */ c_customer_id as customer_id - , coalesce(c_last_name,'') || ', ' || coalesce(c_first_name,'') as customername - from customer - ,customer_address - ,customer_demographics - ,household_demographics - ,income_band - ,store_returns - where ca_city = 'Cedar Grove' - and c_current_addr_sk = ca_address_sk - and ib_lower_bound >= 32432 - and ib_upper_bound <= 32432 + 50000 - and ib_income_band_sk = hd_income_band_sk - and cd_demo_sk = c_current_cdemo_sk - and hd_demo_sk = c_current_hdemo_sk - and sr_cdemo_sk = cd_demo_sk - order by c_customer_id - limit 100; - --- end template query84.tpl query 58 in stream 2 --- start template query4.tpl query 59 in stream 2 -with /* TPC-DS query4.tpl 0.93 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(((ss_ext_list_price-ss_ext_wholesale_cost-ss_ext_discount_amt)+ss_ext_sales_price)/2) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((cs_ext_list_price-cs_ext_wholesale_cost-cs_ext_discount_amt)+cs_ext_sales_price)/2) ) year_total - ,'c' sale_type - from customer - ,catalog_sales - ,date_dim - where c_customer_sk = cs_bill_customer_sk - and cs_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year -union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((ws_ext_list_price-ws_ext_wholesale_cost-ws_ext_discount_amt)+ws_ext_sales_price)/2) ) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_birth_country - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_c_firstyear - ,year_total t_c_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_c_secyear.customer_id - and t_s_firstyear.customer_id = t_c_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_c_firstyear.sale_type = 'c' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_c_secyear.sale_type = 'c' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 1998 - and t_s_secyear.dyear = 1998+1 - and t_c_firstyear.dyear = 1998 - and t_c_secyear.dyear = 1998+1 - and t_w_firstyear.dyear = 1998 - and t_w_secyear.dyear = 1998+1 - and t_s_firstyear.year_total > 0 - and t_c_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_birth_country -limit 100; - --- end template query4.tpl query 59 in stream 2 --- start template query37.tpl query 60 in stream 2 -select /* TPC-DS query37.tpl 0.31 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, catalog_sales - where i_current_price between 26 and 26 + 30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('2002-05-20' as date) and dateadd(day,60,cast('2002-05-20' as date)) - and i_manufact_id in (754,855,932,911) - and inv_quantity_on_hand between 100 and 500 - and cs_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query37.tpl query 60 in stream 2 --- start template query35a.tpl query 61 in stream 2 -select /* TPC-DS query35a.tpl 0.47 */ - ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - count(*) cnt1, - avg(cd_dep_count), - max(cd_dep_count), - max(cd_dep_count), - cd_dep_employed_count, - count(*) cnt2, - avg(cd_dep_employed_count), - max(cd_dep_employed_count), - max(cd_dep_employed_count), - cd_dep_college_count, - count(*) cnt3, - avg(cd_dep_college_count), - max(cd_dep_college_count), - max(cd_dep_college_count) - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2000 and - d_qoy < 4) and - exists (select * from - (select ws_bill_customer_sk customsk - from web_sales,date_dim - where - ws_sold_date_sk = d_date_sk and - d_year = 2000 and - d_qoy < 4 - union all - select cs_ship_customer_sk customsk - from catalog_sales,date_dim - where - cs_sold_date_sk = d_date_sk and - d_year = 2000 and - d_qoy < 4)x - where x.customsk = c.c_customer_sk) - group by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - limit 100; - --- end template query35a.tpl query 61 in stream 2 --- start template query94.tpl query 62 in stream 2 -select /* TPC-DS query94.tpl 0.17 */ - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '1999-2-01' and - dateadd(day,60,cast('1999-2-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'VA' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and exists (select * - from web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) -and not exists(select * - from web_returns wr1 - where ws1.ws_order_number = wr1.wr_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query94.tpl query 62 in stream 2 --- start template query58.tpl query 63 in stream 2 -with /* TPC-DS query58.tpl 0.19 */ ss_items as - (select i_item_id item_id - ,sum(ss_ext_sales_price) ss_item_rev - from store_sales - ,item - ,date_dim - where ss_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '2001-06-28')) - and ss_sold_date_sk = d_date_sk - group by i_item_id), - cs_items as - (select i_item_id item_id - ,sum(cs_ext_sales_price) cs_item_rev - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '2001-06-28')) - and cs_sold_date_sk = d_date_sk - group by i_item_id), - ws_items as - (select i_item_id item_id - ,sum(ws_ext_sales_price) ws_item_rev - from web_sales - ,item - ,date_dim - where ws_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq =(select d_week_seq - from date_dim - where d_date = '2001-06-28')) - and ws_sold_date_sk = d_date_sk - group by i_item_id) - select ss_items.item_id - ,ss_item_rev - ,ss_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ss_dev - ,cs_item_rev - ,cs_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 cs_dev - ,ws_item_rev - ,ws_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ws_dev - ,(ss_item_rev+cs_item_rev+ws_item_rev)/3 average - from ss_items,cs_items,ws_items - where ss_items.item_id=cs_items.item_id - and ss_items.item_id=ws_items.item_id - and ss_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - and ss_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and cs_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and cs_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and ws_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and ws_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - order by item_id - ,ss_item_rev - limit 100; - --- end template query58.tpl query 63 in stream 2 --- start template query96.tpl query 64 in stream 2 -select /* TPC-DS query96.tpl 0.1 */ count(*) -from store_sales - ,household_demographics - ,time_dim, store -where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 15 - and time_dim.t_minute >= 30 - and household_demographics.hd_dep_count = 0 - and store.s_store_name = 'ese' -order by count(*) -limit 100; - --- end template query96.tpl query 64 in stream 2 --- start template query12.tpl query 65 in stream 2 -select /* TPC-DS query12.tpl 0.64 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ws_ext_sales_price) as itemrevenue - ,sum(ws_ext_sales_price)*100/sum(sum(ws_ext_sales_price)) over - (partition by i_class) as revenueratio -from - web_sales - ,item - ,date_dim -where - ws_item_sk = i_item_sk - and i_category in ('Women', 'Shoes', 'Electronics') - and ws_sold_date_sk = d_date_sk - and d_date between cast('2000-06-15' as date) - and dateadd(day,30,cast('2000-06-15' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query12.tpl query 65 in stream 2 --- start template query29.tpl query 66 in stream 2 -select /* TPC-DS query29.tpl 0.53 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,max(ss_quantity) as store_sales_quantity - ,max(sr_return_quantity) as store_returns_quantity - ,max(cs_quantity) as catalog_sales_quantity - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 1999 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 4 + 3 - and d2.d_year = 1999 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_year in (1999,1999+1,1999+2) - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query29.tpl query 66 in stream 2 --- start template query22a.tpl query 67 in stream 2 -with /* TPC-DS query22a.tpl 0.55 */ results as -(select i_product_name - ,i_brand - ,i_class - ,i_category - ,avg(inv_quantity_on_hand) qoh - from inventory - ,date_dim - ,item --- ,warehouse - where inv_date_sk=d_date_sk - and inv_item_sk=i_item_sk --- and inv_warehouse_sk = w_warehouse_sk - and d_month_seq between 1218 and 1218 + 11 - group by i_product_name,i_brand,i_class,i_category), -results_rollup as -(select i_product_name, i_brand, i_class, i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class,i_category -union all -select i_product_name, i_brand, i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class -union all -select i_product_name, i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand -union all -select i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name -union all -select null i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results) - select i_product_name, i_brand, i_class, i_category,qoh - from results_rollup - order by qoh, i_product_name, i_brand, i_class, i_category -limit 100; - --- end template query22a.tpl query 67 in stream 2 --- start template query51.tpl query 68 in stream 2 -WITH /* TPC-DS query51.tpl 0.46 */ web_v1 as ( -select - ws_item_sk item_sk, d_date, - sum(sum(ws_sales_price)) - over (partition by ws_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from web_sales - ,date_dim -where ws_sold_date_sk=d_date_sk - and d_month_seq between 1190 and 1190+11 - and ws_item_sk is not NULL -group by ws_item_sk, d_date), -store_v1 as ( -select - ss_item_sk item_sk, d_date, - sum(sum(ss_sales_price)) - over (partition by ss_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from store_sales - ,date_dim -where ss_sold_date_sk=d_date_sk - and d_month_seq between 1190 and 1190+11 - and ss_item_sk is not NULL -group by ss_item_sk, d_date) - select * -from (select item_sk - ,d_date - ,web_sales - ,store_sales - ,max(web_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) web_cumulative - ,max(store_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) store_cumulative - from (select case when web.item_sk is not null then web.item_sk else store.item_sk end item_sk - ,case when web.d_date is not null then web.d_date else store.d_date end d_date - ,web.cume_sales web_sales - ,store.cume_sales store_sales - from web_v1 web full outer join store_v1 store on (web.item_sk = store.item_sk - and web.d_date = store.d_date) - )x )y -where web_cumulative > store_cumulative -order by item_sk - ,d_date -limit 100; - --- end template query51.tpl query 68 in stream 2 --- start template query36a.tpl query 69 in stream 2 -with /* TPC-DS query36a.tpl 0.21 */ results as - (select - sum(ss_net_profit) as ss_net_profit, sum(ss_ext_sales_price) as ss_ext_sales_price, - sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin - ,i_category - ,i_class - ,0 as g_category, 0 as g_class - from - store_sales - ,date_dim d1 - ,item - ,store - where - d1.d_year = 2002 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and s_state in ('WV','NE','MN','OH', - 'SD','IN','MI','AL') - group by i_category,i_class) - , - results_rollup as - (select gross_margin ,i_category ,i_class,0 as t_category, 0 as t_class, 0 as lochierarchy from results - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - i_category, NULL AS i_class, 0 as t_category, 1 as t_class, 1 as lochierarchy from results group by i_category - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - NULL AS i_category ,NULL AS i_class, 1 as t_category, 1 as t_class, 2 as lochierarchy from results) - select - gross_margin ,i_category ,i_class, lochierarchy,rank() over ( - partition by lochierarchy, case when t_class = 0 then i_category end - order by gross_margin asc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then i_category end - ,rank_within_parent - limit 100; - --- end template query36a.tpl query 69 in stream 2 --- start template query43.tpl query 70 in stream 2 -select /* TPC-DS query43.tpl 0.15 */ s_store_name, s_store_id, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from date_dim, store_sales, store - where d_date_sk = ss_sold_date_sk and - s_store_sk = ss_store_sk and - s_gmt_offset = -5 and - d_year = 2000 - group by s_store_name, s_store_id - order by s_store_name, s_store_id,sun_sales,mon_sales,tue_sales,wed_sales,thu_sales,fri_sales,sat_sales - limit 100; - --- end template query43.tpl query 70 in stream 2 --- start template query64.tpl query 71 in stream 2 -with /* TPC-DS query64.tpl 0.20 */ cs_ui as - (select cs_item_sk - ,sum(cs_ext_list_price) as sale,sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit) as refund - from catalog_sales - ,catalog_returns - where cs_item_sk = cr_item_sk - and cs_order_number = cr_order_number - group by cs_item_sk - having sum(cs_ext_list_price)>2*sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit)), -cross_sales as - (select i_product_name product_name - ,i_item_sk item_sk - ,s_store_name store_name - ,s_zip store_zip - ,ad1.ca_street_number b_street_number - ,ad1.ca_street_name b_street_name - ,ad1.ca_city b_city - ,ad1.ca_zip b_zip - ,ad2.ca_street_number c_street_number - ,ad2.ca_street_name c_street_name - ,ad2.ca_city c_city - ,ad2.ca_zip c_zip - ,d1.d_year as syear - ,d2.d_year as fsyear - ,d3.d_year s2year - ,count(*) cnt - ,sum(ss_wholesale_cost) s1 - ,sum(ss_list_price) s2 - ,sum(ss_coupon_amt) s3 - FROM store_sales - ,store_returns - ,cs_ui - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,customer - ,customer_demographics cd1 - ,customer_demographics cd2 - ,promotion - ,household_demographics hd1 - ,household_demographics hd2 - ,customer_address ad1 - ,customer_address ad2 - ,income_band ib1 - ,income_band ib2 - ,item - WHERE ss_store_sk = s_store_sk AND - ss_sold_date_sk = d1.d_date_sk AND - ss_customer_sk = c_customer_sk AND - ss_cdemo_sk= cd1.cd_demo_sk AND - ss_hdemo_sk = hd1.hd_demo_sk AND - ss_addr_sk = ad1.ca_address_sk and - ss_item_sk = i_item_sk and - ss_item_sk = sr_item_sk and - ss_ticket_number = sr_ticket_number and - ss_item_sk = cs_ui.cs_item_sk and - c_current_cdemo_sk = cd2.cd_demo_sk AND - c_current_hdemo_sk = hd2.hd_demo_sk AND - c_current_addr_sk = ad2.ca_address_sk and - c_first_sales_date_sk = d2.d_date_sk and - c_first_shipto_date_sk = d3.d_date_sk and - ss_promo_sk = p_promo_sk and - hd1.hd_income_band_sk = ib1.ib_income_band_sk and - hd2.hd_income_band_sk = ib2.ib_income_band_sk and - cd1.cd_marital_status <> cd2.cd_marital_status and - i_color in ('drab','puff','olive','chartreuse','sky','maroon') and - i_current_price between 1 and 1 + 10 and - i_current_price between 1 + 1 and 1 + 15 -group by i_product_name - ,i_item_sk - ,s_store_name - ,s_zip - ,ad1.ca_street_number - ,ad1.ca_street_name - ,ad1.ca_city - ,ad1.ca_zip - ,ad2.ca_street_number - ,ad2.ca_street_name - ,ad2.ca_city - ,ad2.ca_zip - ,d1.d_year - ,d2.d_year - ,d3.d_year -) -select cs1.product_name - ,cs1.store_name - ,cs1.store_zip - ,cs1.b_street_number - ,cs1.b_street_name - ,cs1.b_city - ,cs1.b_zip - ,cs1.c_street_number - ,cs1.c_street_name - ,cs1.c_city - ,cs1.c_zip - ,cs1.syear - ,cs1.cnt - ,cs1.s1 as s11 - ,cs1.s2 as s21 - ,cs1.s3 as s31 - ,cs2.s1 as s12 - ,cs2.s2 as s22 - ,cs2.s3 as s32 - ,cs2.syear - ,cs2.cnt -from cross_sales cs1,cross_sales cs2 -where cs1.item_sk=cs2.item_sk and - cs1.syear = 1999 and - cs2.syear = 1999 + 1 and - cs2.cnt <= cs1.cnt and - cs1.store_name = cs2.store_name and - cs1.store_zip = cs2.store_zip -order by cs1.product_name - ,cs1.store_name - ,cs2.cnt - ,cs1.s1 - ,cs2.s1; - --- end template query64.tpl query 71 in stream 2 --- start template query20.tpl query 72 in stream 2 -select /* TPC-DS query20.tpl 0.65 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(cs_ext_sales_price) as itemrevenue - ,sum(cs_ext_sales_price)*100/sum(sum(cs_ext_sales_price)) over - (partition by i_class) as revenueratio - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and i_category in ('Electronics', 'Sports', 'Shoes') - and cs_sold_date_sk = d_date_sk - and d_date between cast('1999-05-22' as date) - and dateadd(day,30,cast('1999-05-22' as date)) - group by i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - order by i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query20.tpl query 72 in stream 2 --- start template query57.tpl query 73 in stream 2 -with /* TPC-DS query57.tpl 0.70 */ v1 as( - select i_category, i_brand, - cc_name, - d_year, d_moy, - sum(cs_sales_price) sum_sales, - avg(sum(cs_sales_price)) over - (partition by i_category, i_brand, - cc_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - cc_name - order by d_year, d_moy) rn - from item, catalog_sales, date_dim, call_center - where cs_item_sk = i_item_sk and - cs_sold_date_sk = d_date_sk and - cc_call_center_sk= cs_call_center_sk and - ( - d_year = 2001 or - ( d_year = 2001-1 and d_moy =12) or - ( d_year = 2001+1 and d_moy =1) - ) - group by i_category, i_brand, - cc_name , d_year, d_moy), - v2 as( - select v1.i_brand - ,v1.d_year, v1.d_moy - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1. cc_name = v1_lag. cc_name and - v1. cc_name = v1_lead. cc_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 2001 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, nsum - limit 100; - --- end template query57.tpl query 73 in stream 2 --- start template query9.tpl query 74 in stream 2 -select /* TPC-DS query9.tpl 0.49 */ case when (select count(*) - from store_sales - where ss_quantity between 1 and 20) > 138306382 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 1 and 20) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 1 and 20) end bucket1 , - case when (select count(*) - from store_sales - where ss_quantity between 21 and 40) > 15599360 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 21 and 40) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 21 and 40) end bucket2, - case when (select count(*) - from store_sales - where ss_quantity between 41 and 60) > 47846449 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 41 and 60) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 41 and 60) end bucket3, - case when (select count(*) - from store_sales - where ss_quantity between 61 and 80) > 37509033 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 61 and 80) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 61 and 80) end bucket4, - case when (select count(*) - from store_sales - where ss_quantity between 81 and 100) > 128429629 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 81 and 100) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 81 and 100) end bucket5 -from reason -where r_reason_sk = 1 -; - --- end template query9.tpl query 74 in stream 2 --- start template query52.tpl query 75 in stream 2 -select /* TPC-DS query52.tpl 0.59 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_sales_price) ext_price - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=12 - and dt.d_year=2001 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,ext_price desc - ,brand_id -limit 100 ; - --- end template query52.tpl query 75 in stream 2 --- start template query49.tpl query 76 in stream 2 -select /* TPC-DS query49.tpl 0.48 */ channel, item, return_ratio, return_rank, currency_rank from - (select - 'web' as channel - ,web.item - ,web.return_ratio - ,web.return_rank - ,web.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select ws.ws_item_sk as item - ,(cast(sum(coalesce(wr.wr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(wr.wr_return_amt,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - web_sales ws left outer join web_returns wr - on (ws.ws_order_number = wr.wr_order_number and - ws.ws_item_sk = wr.wr_item_sk) - ,date_dim - where - wr.wr_return_amt > 10000 - and ws.ws_net_profit > 1 - and ws.ws_net_paid > 0 - and ws.ws_quantity > 0 - and ws_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 11 - group by ws.ws_item_sk - ) in_web - ) web - where - ( - web.return_rank <= 10 - or - web.currency_rank <= 10 - ) - union - select - 'catalog' as channel - ,catalog.item - ,catalog.return_ratio - ,catalog.return_rank - ,catalog.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select - cs.cs_item_sk as item - ,(cast(sum(coalesce(cr.cr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(cr.cr_return_amount,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - catalog_sales cs left outer join catalog_returns cr - on (cs.cs_order_number = cr.cr_order_number and - cs.cs_item_sk = cr.cr_item_sk) - ,date_dim - where - cr.cr_return_amount > 10000 - and cs.cs_net_profit > 1 - and cs.cs_net_paid > 0 - and cs.cs_quantity > 0 - and cs_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 11 - group by cs.cs_item_sk - ) in_cat - ) catalog - where - ( - catalog.return_rank <= 10 - or - catalog.currency_rank <=10 - ) - union - select - 'store' as channel - ,store.item - ,store.return_ratio - ,store.return_rank - ,store.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select sts.ss_item_sk as item - ,(cast(sum(coalesce(sr.sr_return_quantity,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(sr.sr_return_amt,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - store_sales sts left outer join store_returns sr - on (sts.ss_ticket_number = sr.sr_ticket_number and sts.ss_item_sk = sr.sr_item_sk) - ,date_dim - where - sr.sr_return_amt > 10000 - and sts.ss_net_profit > 1 - and sts.ss_net_paid > 0 - and sts.ss_quantity > 0 - and ss_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 11 - group by sts.ss_item_sk - ) in_store - ) store - where ( - store.return_rank <= 10 - or - store.currency_rank <= 10 - ) - ) - order by 1,4,5,2 - limit 100; - --- end template query49.tpl query 76 in stream 2 --- start template query71.tpl query 77 in stream 2 -select /* TPC-DS query71.tpl 0.72 */ i_brand_id brand_id, i_brand brand,t_hour,t_minute, - sum(ext_price) ext_price - from item, (select ws_ext_sales_price as ext_price, - ws_sold_date_sk as sold_date_sk, - ws_item_sk as sold_item_sk, - ws_sold_time_sk as time_sk - from web_sales,date_dim - where d_date_sk = ws_sold_date_sk - and d_moy=11 - and d_year=1998 - union all - select cs_ext_sales_price as ext_price, - cs_sold_date_sk as sold_date_sk, - cs_item_sk as sold_item_sk, - cs_sold_time_sk as time_sk - from catalog_sales,date_dim - where d_date_sk = cs_sold_date_sk - and d_moy=11 - and d_year=1998 - union all - select ss_ext_sales_price as ext_price, - ss_sold_date_sk as sold_date_sk, - ss_item_sk as sold_item_sk, - ss_sold_time_sk as time_sk - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - and d_moy=11 - and d_year=1998 - ) tmp,time_dim - where - sold_item_sk = i_item_sk - and i_manager_id=1 - and time_sk = t_time_sk - and (t_meal_time = 'breakfast' or t_meal_time = 'dinner') - group by i_brand, i_brand_id,t_hour,t_minute - order by ext_price desc, i_brand_id - ; - --- end template query71.tpl query 77 in stream 2 --- start template query72.tpl query 78 in stream 2 -select /* TPC-DS query72.tpl 0.87 */ i_item_desc - ,w_warehouse_name - ,d1.d_week_seq - ,sum(case when p_promo_sk is null then 1 else 0 end) no_promo - ,sum(case when p_promo_sk is not null then 1 else 0 end) promo - ,count(*) total_cnt -from catalog_sales -join inventory on (cs_item_sk = inv_item_sk) -join warehouse on (w_warehouse_sk=inv_warehouse_sk) -join item on (i_item_sk = cs_item_sk) -join customer_demographics on (cs_bill_cdemo_sk = cd_demo_sk) -join household_demographics on (cs_bill_hdemo_sk = hd_demo_sk) -join date_dim d1 on (cs_sold_date_sk = d1.d_date_sk) -join date_dim d2 on (inv_date_sk = d2.d_date_sk) -join date_dim d3 on (cs_ship_date_sk = d3.d_date_sk) -left outer join promotion on (cs_promo_sk=p_promo_sk) -left outer join catalog_returns on (cr_item_sk = cs_item_sk and cr_order_number = cs_order_number) -where d1.d_week_seq = d2.d_week_seq - and inv_quantity_on_hand < cs_quantity - and d3.d_date > d1.d_date + 5 - and hd_buy_potential = '1001-5000' - and d1.d_year = 1999 - and cd_marital_status = 'M' -group by i_item_desc,w_warehouse_name,d1.d_week_seq -order by total_cnt desc, i_item_desc, w_warehouse_name, d_week_seq -limit 100; - --- end template query72.tpl query 78 in stream 2 --- start template query70a.tpl query 79 in stream 2 -with /* TPC-DS query70a.tpl 0.34 */ results as -( select - sum(ss_net_profit) as total_sum ,s_state ,s_county, 0 as gstate, 0 as g_county - from - store_sales - ,date_dim d1 - ,store - where - d1.d_month_seq between 1222 and 1222 + 11 - and d1.d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - and s_state in - ( select s_state - from (select s_state as s_state, - rank() over ( partition by s_state order by sum(ss_net_profit) desc) as ranking - from store_sales, store, date_dim - where d_month_seq between 1222 and 1222 + 11 - and d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - group by s_state - ) tmp1 - where ranking <= 5) - group by s_state,s_county) , - results_rollup as -(select total_sum ,s_state ,s_county, 0 as g_state, 0 as g_county, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum,s_state, NULL as s_county, 0 as g_state, 1 as g_county, 1 as lochierarchy from results group by s_state - union - select sum(total_sum) as total_sum ,NULL as s_state ,NULL as s_county, 1 as g_state, 1 as g_county, 2 as lochierarchy from results) - select total_sum ,s_state ,s_county, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_county = 0 then s_state end - order by total_sum desc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then s_state end - ,rank_within_parent - limit 100; - --- end template query70a.tpl query 79 in stream 2 --- start template query7.tpl query 80 in stream 2 -select /* TPC-DS query7.tpl 0.2 */ i_item_id, - avg(ss_quantity) agg1, - avg(ss_list_price) agg2, - avg(ss_coupon_amt) agg3, - avg(ss_sales_price) agg4 - from store_sales, customer_demographics, date_dim, item, promotion - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_cdemo_sk = cd_demo_sk and - ss_promo_sk = p_promo_sk and - cd_gender = 'F' and - cd_marital_status = 'U' and - cd_education_status = 'College' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 2001 - group by i_item_id - order by i_item_id - limit 100; - --- end template query7.tpl query 80 in stream 2 --- start template query97.tpl query 81 in stream 2 -with /* TPC-DS query97.tpl 0.38 */ ssci as ( -select ss_customer_sk customer_sk - ,ss_item_sk item_sk -from store_sales,date_dim -where ss_sold_date_sk = d_date_sk - and d_month_seq between 1184 and 1184 + 11 -group by ss_customer_sk - ,ss_item_sk), -csci as( - select cs_bill_customer_sk customer_sk - ,cs_item_sk item_sk -from catalog_sales,date_dim -where cs_sold_date_sk = d_date_sk - and d_month_seq between 1184 and 1184 + 11 -group by cs_bill_customer_sk - ,cs_item_sk) - select sum(case when ssci.customer_sk is not null and csci.customer_sk is null then 1 else 0 end) store_only - ,sum(case when ssci.customer_sk is null and csci.customer_sk is not null then 1 else 0 end) catalog_only - ,sum(case when ssci.customer_sk is not null and csci.customer_sk is not null then 1 else 0 end) store_and_catalog -from ssci full outer join csci on (ssci.customer_sk=csci.customer_sk - and ssci.item_sk = csci.item_sk) -limit 100; - --- end template query97.tpl query 81 in stream 2 --- start template query33.tpl query 82 in stream 2 -with /* TPC-DS query33.tpl 0.22 */ ss as ( - select - i_manufact_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Books')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 7 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id), - cs as ( - select - i_manufact_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Books')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 7 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id), - ws as ( - select - i_manufact_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Books')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 7 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id) - select i_manufact_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_manufact_id - order by total_sales -limit 100; - --- end template query33.tpl query 82 in stream 2 --- start template query79.tpl query 83 in stream 2 -select /* TPC-DS query79.tpl 0.89 */ - c_last_name,c_first_name,substring(s_city,1,30),ss_ticket_number,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,store.s_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (household_demographics.hd_dep_count = 0 or household_demographics.hd_vehicle_count > 2) - and date_dim.d_dow = 1 - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_number_employees between 200 and 295 - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,store.s_city) ms,customer - where ss_customer_sk = c_customer_sk - order by c_last_name,c_first_name,substring(s_city,1,30), profit -limit 100; - --- end template query79.tpl query 83 in stream 2 --- start template query32.tpl query 84 in stream 2 -select /* TPC-DS query32.tpl 0.7 */ sum(cs_ext_discount_amt) as "excess discount amount" -from - catalog_sales - ,item - ,date_dim -where -i_manufact_id = 457 -and i_item_sk = cs_item_sk -and d_date between '1998-01-11' and - dateadd(day,90,cast('1998-01-11' as date)) -and d_date_sk = cs_sold_date_sk -and cs_ext_discount_amt - > ( - select - 1.3 * avg(cs_ext_discount_amt) - from - catalog_sales - ,date_dim - where - cs_item_sk = i_item_sk - and d_date between '1998-01-11' and - dateadd(day,90,cast('1998-01-11' as date)) - and d_date_sk = cs_sold_date_sk - ) -limit 100; - --- end template query32.tpl query 84 in stream 2 --- start template query78.tpl query 85 in stream 2 -with /* TPC-DS query78.tpl 0.10 */ ws as - (select d_year AS ws_sold_year, ws_item_sk, - ws_bill_customer_sk ws_customer_sk, - sum(ws_quantity) ws_qty, - sum(ws_wholesale_cost) ws_wc, - sum(ws_sales_price) ws_sp - from web_sales - left join web_returns on wr_order_number=ws_order_number and ws_item_sk=wr_item_sk - join date_dim on ws_sold_date_sk = d_date_sk - where wr_order_number is null - group by d_year, ws_item_sk, ws_bill_customer_sk - ), -cs as - (select d_year AS cs_sold_year, cs_item_sk, - cs_bill_customer_sk cs_customer_sk, - sum(cs_quantity) cs_qty, - sum(cs_wholesale_cost) cs_wc, - sum(cs_sales_price) cs_sp - from catalog_sales - left join catalog_returns on cr_order_number=cs_order_number and cs_item_sk=cr_item_sk - join date_dim on cs_sold_date_sk = d_date_sk - where cr_order_number is null - group by d_year, cs_item_sk, cs_bill_customer_sk - ), -ss as - (select d_year AS ss_sold_year, ss_item_sk, - ss_customer_sk, - sum(ss_quantity) ss_qty, - sum(ss_wholesale_cost) ss_wc, - sum(ss_sales_price) ss_sp - from store_sales - left join store_returns on sr_ticket_number=ss_ticket_number and ss_item_sk=sr_item_sk - join date_dim on ss_sold_date_sk = d_date_sk - where sr_ticket_number is null - group by d_year, ss_item_sk, ss_customer_sk - ) - select -ss_sold_year, ss_item_sk, ss_customer_sk, -round(ss_qty/(coalesce(ws_qty,0)+coalesce(cs_qty,0)),2) ratio, -ss_qty store_qty, ss_wc store_wholesale_cost, ss_sp store_sales_price, -coalesce(ws_qty,0)+coalesce(cs_qty,0) other_chan_qty, -coalesce(ws_wc,0)+coalesce(cs_wc,0) other_chan_wholesale_cost, -coalesce(ws_sp,0)+coalesce(cs_sp,0) other_chan_sales_price -from ss -left join ws on (ws_sold_year=ss_sold_year and ws_item_sk=ss_item_sk and ws_customer_sk=ss_customer_sk) -left join cs on (cs_sold_year=ss_sold_year and cs_item_sk=ss_item_sk and cs_customer_sk=ss_customer_sk) -where (coalesce(ws_qty,0)>0 or coalesce(cs_qty, 0)>0) and ss_sold_year=2000 -order by - ss_sold_year, ss_item_sk, ss_customer_sk, - ss_qty desc, ss_wc desc, ss_sp desc, - other_chan_qty, - other_chan_wholesale_cost, - other_chan_sales_price, - ratio -limit 100; - --- end template query78.tpl query 85 in stream 2 --- start template query18a.tpl query 86 in stream 2 -with /* TPC-DS query18a.tpl 0.90 */ results as - (select i_item_id, - ca_country, - ca_state, - ca_county, - cast(cs_quantity as decimal(12,2)) agg1, - cast(cs_list_price as decimal(12,2)) agg2, - cast(cs_coupon_amt as decimal(12,2)) agg3, - cast(cs_sales_price as decimal(12,2)) agg4, - cast(cs_net_profit as decimal(12,2)) agg5, - cast(c_birth_year as decimal(12,2)) agg6, - cast(cd1.cd_dep_count as decimal(12,2)) agg7 - from catalog_sales, customer_demographics cd1, customer_demographics cd2, customer, customer_address, date_dim, item - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd1.cd_demo_sk and - cs_bill_customer_sk = c_customer_sk and - cd1.cd_gender = 'M' and - cd1.cd_education_status = 'Unknown' and - c_current_cdemo_sk = cd2.cd_demo_sk and - c_current_addr_sk = ca_address_sk and - c_birth_month in (12,10,2,11,3,9) and - d_year = 2002 and - ca_state in ('AL','FL','NC','OH','SC','NY','MS') - ) - select i_item_id, ca_country, ca_state, ca_county, agg1, agg2, agg3, agg4, agg5, agg6, agg7 - from ( - select i_item_id, ca_country, ca_state, ca_county, avg(agg1) agg1, - avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state, ca_county - union all - select i_item_id, ca_country, ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state - union all - select i_item_id, ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country - union all - select i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - ) foo - order by ca_country, ca_state, ca_county, i_item_id - limit 100; - --- end template query18a.tpl query 86 in stream 2 --- start template query65.tpl query 87 in stream 2 -select /* TPC-DS query65.tpl 0.71 */ - s_store_name, - i_item_desc, - sc.revenue, - i_current_price, - i_wholesale_cost, - i_brand - from store, item, - (select ss_store_sk, avg(revenue) as ave - from - (select ss_store_sk, ss_item_sk, - sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1209 and 1209+11 - group by ss_store_sk, ss_item_sk) sa - group by ss_store_sk) sb, - (select ss_store_sk, ss_item_sk, sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1209 and 1209+11 - group by ss_store_sk, ss_item_sk) sc - where sb.ss_store_sk = sc.ss_store_sk and - sc.revenue <= 0.1 * sb.ave and - s_store_sk = sc.ss_store_sk and - i_item_sk = sc.ss_item_sk - order by s_store_name, i_item_desc -limit 100; - --- end template query65.tpl query 87 in stream 2 --- start template query60.tpl query 88 in stream 2 -with /* TPC-DS query60.tpl 0.29 */ ss as ( - select - i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Jewelry')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 8 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -7 - group by i_item_id), - cs as ( - select - i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Jewelry')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 8 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -7 - group by i_item_id), - ws as ( - select - i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Jewelry')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 8 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -7 - group by i_item_id) - select - i_item_id -,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by i_item_id - ,total_sales - limit 100; - --- end template query60.tpl query 88 in stream 2 --- start template query34.tpl query 89 in stream 2 -select /* TPC-DS query34.tpl 0.73 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (date_dim.d_dom between 1 and 3 or date_dim.d_dom between 25 and 28) - and (household_demographics.hd_buy_potential = '1001-5000' or - household_demographics.hd_buy_potential = 'Unknown') - and household_demographics.hd_vehicle_count > 0 - and (case when household_demographics.hd_vehicle_count > 0 - then household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count - else null - end) > 1.2 - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_county in ('Daviess County','Huron County','Mobile County','Pennington County', - 'Williamson County','Coal County','Marshall County','Sumner County') - group by ss_ticket_number,ss_customer_sk) dn,customer - where ss_customer_sk = c_customer_sk - and cnt between 15 and 20 - order by c_last_name,c_first_name,c_salutation,c_preferred_cust_flag desc, ss_ticket_number; - --- end template query34.tpl query 89 in stream 2 --- start template query3.tpl query 90 in stream 2 -select /* TPC-DS query3.tpl 0.45 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_discount_amt) sum_agg - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manufact_id = 568 - and dt.d_moy=11 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,sum_agg desc - ,brand_id - limit 100; - --- end template query3.tpl query 90 in stream 2 --- start template query13.tpl query 91 in stream 2 -select /* TPC-DS query13.tpl 0.91 */ avg(ss_quantity) - ,avg(ss_ext_sales_price) - ,avg(ss_ext_wholesale_cost) - ,sum(ss_ext_wholesale_cost) - from store_sales - ,store - ,customer_demographics - ,household_demographics - ,customer_address - ,date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2001 - and((ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'W' - and cd_education_status = '2 yr Degree' - and ss_sales_price between 100.00 and 150.00 - and hd_dep_count = 3 - )or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'D' - and cd_education_status = 'Secondary' - and ss_sales_price between 50.00 and 100.00 - and hd_dep_count = 1 - ) or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'M' - and cd_education_status = 'Advanced Degree' - and ss_sales_price between 150.00 and 200.00 - and hd_dep_count = 1 - )) - and((ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('IN', 'MI', 'WV') - and ss_net_profit between 100 and 200 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('KY', 'GA', 'SD') - and ss_net_profit between 150 and 300 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('CO', 'IL', 'ND') - and ss_net_profit between 50 and 250 - )) -; - --- end template query13.tpl query 91 in stream 2 --- start template query41.tpl query 92 in stream 2 -select /* TPC-DS query41.tpl 0.62 */ distinct(i_product_name) - from item i1 - where i_manufact_id between 966 and 966+40 - and (select count(*) as item_cnt - from item - where (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'sky' or i_color = 'lemon') and - (i_units = 'Pound' or i_units = 'Gross') and - (i_size = 'medium' or i_size = 'small') - ) or - (i_category = 'Women' and - (i_color = 'wheat' or i_color = 'thistle') and - (i_units = 'Ton' or i_units = 'Bundle') and - (i_size = 'N/A' or i_size = 'economy') - ) or - (i_category = 'Men' and - (i_color = 'steel' or i_color = 'seashell') and - (i_units = 'Bunch' or i_units = 'Unknown') and - (i_size = 'large' or i_size = 'extra large') - ) or - (i_category = 'Men' and - (i_color = 'khaki' or i_color = 'cyan') and - (i_units = 'Lb' or i_units = 'Tsp') and - (i_size = 'medium' or i_size = 'small') - ))) or - (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'pale' or i_color = 'cornflower') and - (i_units = 'Tbl' or i_units = 'Box') and - (i_size = 'medium' or i_size = 'small') - ) or - (i_category = 'Women' and - (i_color = 'forest' or i_color = 'blush') and - (i_units = 'Gram' or i_units = 'Ounce') and - (i_size = 'N/A' or i_size = 'economy') - ) or - (i_category = 'Men' and - (i_color = 'dim' or i_color = 'royal') and - (i_units = 'Oz' or i_units = 'Pallet') and - (i_size = 'large' or i_size = 'extra large') - ) or - (i_category = 'Men' and - (i_color = 'lime' or i_color = 'chiffon') and - (i_units = 'Each' or i_units = 'Cup') and - (i_size = 'medium' or i_size = 'small') - )))) > 0 - order by i_product_name - limit 100; - --- end template query41.tpl query 92 in stream 2 --- start template query92.tpl query 93 in stream 2 -select /* TPC-DS query92.tpl 0.44 */ - sum(ws_ext_discount_amt) as "Excess Discount Amount" -from - web_sales - ,item - ,date_dim -where -i_manufact_id = 483 -and i_item_sk = ws_item_sk -and d_date between '2002-03-25' and - dateadd(day,90,cast('2002-03-25' as date)) -and d_date_sk = ws_sold_date_sk -and ws_ext_discount_amt - > ( - SELECT - 1.3 * avg(ws_ext_discount_amt) - FROM - web_sales - ,date_dim - WHERE - ws_item_sk = i_item_sk - and d_date between '2002-03-25' and - dateadd(day,90,cast('2002-03-25' as date)) - and d_date_sk = ws_sold_date_sk - ) -order by sum(ws_ext_discount_amt) -limit 100; - --- end template query92.tpl query 93 in stream 2 --- start template query74.tpl query 94 in stream 2 -with /* TPC-DS query74.tpl 0.76 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,max(ss_net_paid) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1999,1999+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,max(ws_net_paid) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - and d_year in (1999,1999+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - ) - select - t_s_secyear.customer_id, t_s_secyear.customer_first_name, t_s_secyear.customer_last_name - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.year = 1999 - and t_s_secyear.year = 1999+1 - and t_w_firstyear.year = 1999 - and t_w_secyear.year = 1999+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - order by 3,1,2 -limit 100; - --- end template query74.tpl query 94 in stream 2 --- start template query46.tpl query 95 in stream 2 -select /* TPC-DS query46.tpl 0.23 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and (household_demographics.hd_dep_count = 9 or - household_demographics.hd_vehicle_count= -1) - and date_dim.d_dow in (6,0) - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_city in ('Centerville','Highland','Woodville','Pleasant Hill','Woodlawn') - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,ca_city) dn,customer,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - limit 100; - --- end template query46.tpl query 95 in stream 2 --- start template query89.tpl query 96 in stream 2 -select /* TPC-DS query89.tpl 0.56 */ * -from( -select i_category, i_class, i_brand, - s_store_name, s_company_name, - d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, s_store_name, s_company_name) - avg_monthly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - d_year in (1999) and - ((i_category in ('Music','Men','Books') and - i_class in ('country','sports-apparel','sports') - ) - or (i_category in ('Shoes','Children','Women') and - i_class in ('mens','newborn','fragrances') - )) -group by i_category, i_class, i_brand, - s_store_name, s_company_name, d_moy) tmp1 -where case when (avg_monthly_sales <> 0) then (abs(sum_sales - avg_monthly_sales) / avg_monthly_sales) else null end > 0.1 -order by sum_sales - avg_monthly_sales, s_store_name -limit 100; - --- end template query89.tpl query 96 in stream 2 --- start template query47.tpl query 97 in stream 2 -with /* TPC-DS query47.tpl 0.42 */ v1 as( - select i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, - s_store_name, s_company_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - s_store_name, s_company_name - order by d_year, d_moy) rn - from item, store_sales, date_dim, store - where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - ( - d_year = 2000 or - ( d_year = 2000-1 and d_moy =12) or - ( d_year = 2000+1 and d_moy =1) - ) - group by i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy), - v2 as( - select v1.s_company_name - ,v1.d_year, v1.d_moy - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1.s_store_name = v1_lag.s_store_name and - v1.s_store_name = v1_lead.s_store_name and - v1.s_company_name = v1_lag.s_company_name and - v1.s_company_name = v1_lead.s_company_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 2000 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, sum_sales - limit 100; - --- end template query47.tpl query 97 in stream 2 --- start template query66.tpl query 98 in stream 2 -select /* TPC-DS query66.tpl 0.39 */ - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - ,sum(jan_sales) as jan_sales - ,sum(feb_sales) as feb_sales - ,sum(mar_sales) as mar_sales - ,sum(apr_sales) as apr_sales - ,sum(may_sales) as may_sales - ,sum(jun_sales) as jun_sales - ,sum(jul_sales) as jul_sales - ,sum(aug_sales) as aug_sales - ,sum(sep_sales) as sep_sales - ,sum(oct_sales) as oct_sales - ,sum(nov_sales) as nov_sales - ,sum(dec_sales) as dec_sales - ,sum(jan_sales/w_warehouse_sq_ft) as jan_sales_per_sq_foot - ,sum(feb_sales/w_warehouse_sq_ft) as feb_sales_per_sq_foot - ,sum(mar_sales/w_warehouse_sq_ft) as mar_sales_per_sq_foot - ,sum(apr_sales/w_warehouse_sq_ft) as apr_sales_per_sq_foot - ,sum(may_sales/w_warehouse_sq_ft) as may_sales_per_sq_foot - ,sum(jun_sales/w_warehouse_sq_ft) as jun_sales_per_sq_foot - ,sum(jul_sales/w_warehouse_sq_ft) as jul_sales_per_sq_foot - ,sum(aug_sales/w_warehouse_sq_ft) as aug_sales_per_sq_foot - ,sum(sep_sales/w_warehouse_sq_ft) as sep_sales_per_sq_foot - ,sum(oct_sales/w_warehouse_sq_ft) as oct_sales_per_sq_foot - ,sum(nov_sales/w_warehouse_sq_ft) as nov_sales_per_sq_foot - ,sum(dec_sales/w_warehouse_sq_ft) as dec_sales_per_sq_foot - ,sum(jan_net) as jan_net - ,sum(feb_net) as feb_net - ,sum(mar_net) as mar_net - ,sum(apr_net) as apr_net - ,sum(may_net) as may_net - ,sum(jun_net) as jun_net - ,sum(jul_net) as jul_net - ,sum(aug_net) as aug_net - ,sum(sep_net) as sep_net - ,sum(oct_net) as oct_net - ,sum(nov_net) as nov_net - ,sum(dec_net) as dec_net - from ( - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'BARIAN' || ',' || 'DHL' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then ws_ext_sales_price* ws_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then ws_ext_sales_price* ws_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then ws_ext_sales_price* ws_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then ws_ext_sales_price* ws_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then ws_ext_sales_price* ws_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then ws_ext_sales_price* ws_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then ws_ext_sales_price* ws_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then ws_ext_sales_price* ws_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then ws_ext_sales_price* ws_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then ws_ext_sales_price* ws_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then ws_ext_sales_price* ws_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then ws_ext_sales_price* ws_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as dec_net - from - web_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - ws_warehouse_sk = w_warehouse_sk - and ws_sold_date_sk = d_date_sk - and ws_sold_time_sk = t_time_sk - and ws_ship_mode_sk = sm_ship_mode_sk - and d_year = 2000 - and t_time between 4524 and 4524+28800 - and sm_carrier in ('BARIAN','DHL') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - union all - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'BARIAN' || ',' || 'DHL' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then cs_sales_price* cs_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then cs_sales_price* cs_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then cs_sales_price* cs_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then cs_sales_price* cs_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then cs_sales_price* cs_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then cs_sales_price* cs_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then cs_sales_price* cs_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then cs_sales_price* cs_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then cs_sales_price* cs_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then cs_sales_price* cs_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then cs_sales_price* cs_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then cs_sales_price* cs_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then cs_net_paid * cs_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then cs_net_paid * cs_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then cs_net_paid * cs_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then cs_net_paid * cs_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then cs_net_paid * cs_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then cs_net_paid * cs_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then cs_net_paid * cs_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then cs_net_paid * cs_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then cs_net_paid * cs_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then cs_net_paid * cs_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then cs_net_paid * cs_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then cs_net_paid * cs_quantity else 0 end) as dec_net - from - catalog_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and cs_sold_time_sk = t_time_sk - and cs_ship_mode_sk = sm_ship_mode_sk - and d_year = 2000 - and t_time between 4524 AND 4524+28800 - and sm_carrier in ('BARIAN','DHL') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - ) x - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - order by w_warehouse_name - limit 100; - --- end template query66.tpl query 98 in stream 2 --- start template query48.tpl query 99 in stream 2 -select /* TPC-DS query48.tpl 0.74 */ sum (ss_quantity) - from store_sales, store, customer_demographics, customer_address, date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2002 - and - ( - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'D' - and - cd_education_status = '2 yr Degree' - and - ss_sales_price between 100.00 and 150.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'W' - and - cd_education_status = 'Secondary' - and - ss_sales_price between 50.00 and 100.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'M' - and - cd_education_status = '4 yr Degree' - and - ss_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('NC', 'SC', 'CA') - and ss_net_profit between 0 and 2000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('NE', 'GA', 'IL') - and ss_net_profit between 150 and 3000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('KY', 'AK', 'OR') - and ss_net_profit between 50 and 25000 - ) - ) -; - --- end template query48.tpl query 99 in stream 2 diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/3TB/queries/query_3.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/3TB/queries/query_3.sql deleted file mode 100644 index 3f679b19..00000000 --- a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/3TB/queries/query_3.sql +++ /dev/null @@ -1,5027 +0,0 @@ --- start template query89.tpl query 1 in stream 3 -select /* TPC-DS query89.tpl 0.56 */ * -from( -select i_category, i_class, i_brand, - s_store_name, s_company_name, - d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, s_store_name, s_company_name) - avg_monthly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - d_year in (2002) and - ((i_category in ('Books','Men','Music') and - i_class in ('mystery','shirts','country') - ) - or (i_category in ('Women','Children','Sports') and - i_class in ('fragrances','infants','sailing') - )) -group by i_category, i_class, i_brand, - s_store_name, s_company_name, d_moy) tmp1 -where case when (avg_monthly_sales <> 0) then (abs(sum_sales - avg_monthly_sales) / avg_monthly_sales) else null end > 0.1 -order by sum_sales - avg_monthly_sales, s_store_name -limit 100; - --- end template query89.tpl query 1 in stream 3 --- start template query5a.tpl query 2 in stream 3 -with /* TPC-DS query5a.tpl 0.98 */ ssr as - (select s_store_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ss_store_sk as store_sk, - ss_sold_date_sk as date_sk, - ss_ext_sales_price as sales_price, - ss_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from store_sales - union all - select sr_store_sk as store_sk, - sr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - sr_return_amt as return_amt, - sr_net_loss as net_loss - from store_returns - ) salesreturns, - date_dim, - store - where date_sk = d_date_sk - and d_date between cast('2000-08-23' as date) - and dateadd(day,14,cast('2000-08-23' as date)) - and store_sk = s_store_sk - group by s_store_id) - , - csr as - (select cp_catalog_page_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select cs_catalog_page_sk as page_sk, - cs_sold_date_sk as date_sk, - cs_ext_sales_price as sales_price, - cs_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from catalog_sales - union all - select cr_catalog_page_sk as page_sk, - cr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - cr_return_amount as return_amt, - cr_net_loss as net_loss - from catalog_returns - ) salesreturns, - date_dim, - catalog_page - where date_sk = d_date_sk - and d_date between cast('2000-08-23' as date) - and dateadd(day,14,cast('2000-08-23' as date)) - and page_sk = cp_catalog_page_sk - group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ws_web_site_sk as wsr_web_site_sk, - ws_sold_date_sk as date_sk, - ws_ext_sales_price as sales_price, - ws_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from web_sales - union all - select ws_web_site_sk as wsr_web_site_sk, - wr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - wr_return_amt as return_amt, - wr_net_loss as net_loss - from web_returns left outer join web_sales on - ( wr_item_sk = ws_item_sk - and wr_order_number = ws_order_number) - ) salesreturns, - date_dim, - web_site - where date_sk = d_date_sk - and d_date between cast('2000-08-23' as date) - and dateadd(day,14,cast('2000-08-23' as date)) - and wsr_web_site_sk = web_site_sk - group by web_site_id) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || s_store_id as id - , sales - , returns - , (profit - profit_loss) as profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || cp_catalog_page_id as id - , sales - , returns - , (profit - profit_loss) as profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , (profit - profit_loss) as profit - from wsr - ) x - group by channel, id) - select channel, id, sales, returns, profit from ( - select channel, id, sales, returns, profit from results - union - select channel, null as id, sum(sales), sum(returns), sum(profit) from results group by channel - union - select null as channel, null as id, sum(sales), sum(returns), sum(profit) from results) foo -order by channel, id -limit 100; - --- end template query5a.tpl query 2 in stream 3 --- start template query52.tpl query 3 in stream 3 -select /* TPC-DS query52.tpl 0.59 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_sales_price) ext_price - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=11 - and dt.d_year=1998 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,ext_price desc - ,brand_id -limit 100 ; - --- end template query52.tpl query 3 in stream 3 --- start template query62.tpl query 4 in stream 3 -select /* TPC-DS query62.tpl 0.24 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 30) and - (ws_ship_date_sk - ws_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 60) and - (ws_ship_date_sk - ws_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 90) and - (ws_ship_date_sk - ws_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - web_sales - ,warehouse - ,ship_mode - ,web_site - ,date_dim -where - d_month_seq between 1203 and 1203 + 11 -and ws_ship_date_sk = d_date_sk -and ws_warehouse_sk = w_warehouse_sk -and ws_ship_mode_sk = sm_ship_mode_sk -and ws_web_site_sk = web_site_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -limit 100; - --- end template query62.tpl query 4 in stream 3 --- start template query53.tpl query 5 in stream 3 -select /* TPC-DS query53.tpl 0.88 */ * from -(select i_manufact_id, -sum(ss_sales_price) sum_sales, -avg(sum(ss_sales_price)) over (partition by i_manufact_id) avg_quarterly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and -ss_sold_date_sk = d_date_sk and -ss_store_sk = s_store_sk and -d_month_seq in (1222,1222+1,1222+2,1222+3,1222+4,1222+5,1222+6,1222+7,1222+8,1222+9,1222+10,1222+11) and -((i_category in ('Books','Children','Electronics') and -i_class in ('personal','portable','reference','self-help') and -i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) -or(i_category in ('Women','Music','Men') and -i_class in ('accessories','classical','fragrances','pants') and -i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manufact_id, d_qoy ) tmp1 -where case when avg_quarterly_sales > 0 - then abs (sum_sales - avg_quarterly_sales)/ avg_quarterly_sales - else null end > 0.1 -order by avg_quarterly_sales, - sum_sales, - i_manufact_id -limit 100; - --- end template query53.tpl query 5 in stream 3 --- start template query7.tpl query 6 in stream 3 -select /* TPC-DS query7.tpl 0.2 */ i_item_id, - avg(ss_quantity) agg1, - avg(ss_list_price) agg2, - avg(ss_coupon_amt) agg3, - avg(ss_sales_price) agg4 - from store_sales, customer_demographics, date_dim, item, promotion - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_cdemo_sk = cd_demo_sk and - ss_promo_sk = p_promo_sk and - cd_gender = 'F' and - cd_marital_status = 'U' and - cd_education_status = '2 yr Degree' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 2001 - group by i_item_id - order by i_item_id - limit 100; - --- end template query7.tpl query 6 in stream 3 --- start template query39.tpl query 7 in stream 3 -with /* TPC-DS query39.tpl 0.5 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =1998 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=3 - and inv2.d_moy=3+1 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; -with /* TPC-DS query39.tpl 0.5 part2 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =1998 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=3 - and inv2.d_moy=3+1 - and inv1.cov > 1.5 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; - --- end template query39.tpl query 7 in stream 3 --- start template query80a.tpl query 8 in stream 3 -with /* TPC-DS query80a.tpl 0.6 */ ssr as - (select s_store_id as store_id, - sum(ss_ext_sales_price) as sales, - sum(coalesce(sr_return_amt, 0)) as returns, - sum(ss_net_profit - coalesce(sr_net_loss, 0)) as profit - from store_sales left outer join store_returns on - (ss_item_sk = sr_item_sk and ss_ticket_number = sr_ticket_number), - date_dim, - store, - item, - promotion - where ss_sold_date_sk = d_date_sk - and d_date between cast('1999-08-05' as date) - and dateadd(day,30,cast('1999-08-05' as date)) - and ss_store_sk = s_store_sk - and ss_item_sk = i_item_sk - and i_current_price > 50 - and ss_promo_sk = p_promo_sk - and p_channel_tv = 'N' - group by s_store_id) - , - csr as - (select cp_catalog_page_id as catalog_page_id, - sum(cs_ext_sales_price) as sales, - sum(coalesce(cr_return_amount, 0)) as returns, - sum(cs_net_profit - coalesce(cr_net_loss, 0)) as profit - from catalog_sales left outer join catalog_returns on - (cs_item_sk = cr_item_sk and cs_order_number = cr_order_number), - date_dim, - catalog_page, - item, - promotion - where cs_sold_date_sk = d_date_sk - and d_date between cast('1999-08-05' as date) - and dateadd(day,30,cast('1999-08-05' as date)) - and cs_catalog_page_sk = cp_catalog_page_sk - and cs_item_sk = i_item_sk - and i_current_price > 50 - and cs_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(ws_ext_sales_price) as sales, - sum(coalesce(wr_return_amt, 0)) as returns, - sum(ws_net_profit - coalesce(wr_net_loss, 0)) as profit - from web_sales left outer join web_returns on - (ws_item_sk = wr_item_sk and ws_order_number = wr_order_number), - date_dim, - web_site, - item, - promotion - where ws_sold_date_sk = d_date_sk - and d_date between cast('1999-08-05' as date) - and dateadd(day,30,cast('1999-08-05' as date)) - and ws_web_site_sk = web_site_sk - and ws_item_sk = i_item_sk - and i_current_price > 50 - and ws_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by web_site_id) -, -results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || store_id as id - , sales - , returns - , profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || catalog_page_id as id - , sales - , returns - , profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , profit - from wsr - ) x - group by channel, id) - - select channel - , id - , sales - , returns - , profit - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results - ) foo - order by channel, id - limit 100; - --- end template query80a.tpl query 8 in stream 3 --- start template query63.tpl query 9 in stream 3 -select /* TPC-DS query63.tpl 0.27 */ * -from (select i_manager_id - ,sum(ss_sales_price) sum_sales - ,avg(sum(ss_sales_price)) over (partition by i_manager_id) avg_monthly_sales - from item - ,store_sales - ,date_dim - ,store - where ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and d_month_seq in (1182,1182+1,1182+2,1182+3,1182+4,1182+5,1182+6,1182+7,1182+8,1182+9,1182+10,1182+11) - and (( i_category in ('Books','Children','Electronics') - and i_class in ('personal','portable','reference','self-help') - and i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) - or( i_category in ('Women','Music','Men') - and i_class in ('accessories','classical','fragrances','pants') - and i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manager_id, d_moy) tmp1 -where case when avg_monthly_sales > 0 then abs (sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 -order by i_manager_id - ,avg_monthly_sales - ,sum_sales -limit 100; - --- end template query63.tpl query 9 in stream 3 --- start template query72.tpl query 10 in stream 3 -select /* TPC-DS query72.tpl 0.87 */ i_item_desc - ,w_warehouse_name - ,d1.d_week_seq - ,sum(case when p_promo_sk is null then 1 else 0 end) no_promo - ,sum(case when p_promo_sk is not null then 1 else 0 end) promo - ,count(*) total_cnt -from catalog_sales -join inventory on (cs_item_sk = inv_item_sk) -join warehouse on (w_warehouse_sk=inv_warehouse_sk) -join item on (i_item_sk = cs_item_sk) -join customer_demographics on (cs_bill_cdemo_sk = cd_demo_sk) -join household_demographics on (cs_bill_hdemo_sk = hd_demo_sk) -join date_dim d1 on (cs_sold_date_sk = d1.d_date_sk) -join date_dim d2 on (inv_date_sk = d2.d_date_sk) -join date_dim d3 on (cs_ship_date_sk = d3.d_date_sk) -left outer join promotion on (cs_promo_sk=p_promo_sk) -left outer join catalog_returns on (cr_item_sk = cs_item_sk and cr_order_number = cs_order_number) -where d1.d_week_seq = d2.d_week_seq - and inv_quantity_on_hand < cs_quantity - and d3.d_date > d1.d_date + 5 - and hd_buy_potential = '501-1000' - and d1.d_year = 2001 - and cd_marital_status = 'M' -group by i_item_desc,w_warehouse_name,d1.d_week_seq -order by total_cnt desc, i_item_desc, w_warehouse_name, d_week_seq -limit 100; - --- end template query72.tpl query 10 in stream 3 --- start template query18a.tpl query 11 in stream 3 -with /* TPC-DS query18a.tpl 0.90 */ results as - (select i_item_id, - ca_country, - ca_state, - ca_county, - cast(cs_quantity as decimal(12,2)) agg1, - cast(cs_list_price as decimal(12,2)) agg2, - cast(cs_coupon_amt as decimal(12,2)) agg3, - cast(cs_sales_price as decimal(12,2)) agg4, - cast(cs_net_profit as decimal(12,2)) agg5, - cast(c_birth_year as decimal(12,2)) agg6, - cast(cd1.cd_dep_count as decimal(12,2)) agg7 - from catalog_sales, customer_demographics cd1, customer_demographics cd2, customer, customer_address, date_dim, item - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd1.cd_demo_sk and - cs_bill_customer_sk = c_customer_sk and - cd1.cd_gender = 'M' and - cd1.cd_education_status = 'Advanced Degree' and - c_current_cdemo_sk = cd2.cd_demo_sk and - c_current_addr_sk = ca_address_sk and - c_birth_month in (7,9,6,2,4,1) and - d_year = 2000 and - ca_state in ('KY','IN','MO','MN','GA','ND','CO') - ) - select i_item_id, ca_country, ca_state, ca_county, agg1, agg2, agg3, agg4, agg5, agg6, agg7 - from ( - select i_item_id, ca_country, ca_state, ca_county, avg(agg1) agg1, - avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state, ca_county - union all - select i_item_id, ca_country, ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state - union all - select i_item_id, ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country - union all - select i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - ) foo - order by ca_country, ca_state, ca_county, i_item_id - limit 100; - --- end template query18a.tpl query 11 in stream 3 --- start template query56.tpl query 12 in stream 3 -with /* TPC-DS query56.tpl 0.83 */ ss as ( - select i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where i_item_id in (select - i_item_id -from item -where i_color in ('green','misty','chocolate')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 6 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - cs as ( - select i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('green','misty','chocolate')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 6 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - ws as ( - select i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('green','misty','chocolate')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 6 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id) - select i_item_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by total_sales, - i_item_id - limit 100; - --- end template query56.tpl query 12 in stream 3 --- start template query13.tpl query 13 in stream 3 -select /* TPC-DS query13.tpl 0.91 */ avg(ss_quantity) - ,avg(ss_ext_sales_price) - ,avg(ss_ext_wholesale_cost) - ,sum(ss_ext_wholesale_cost) - from store_sales - ,store - ,customer_demographics - ,household_demographics - ,customer_address - ,date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2001 - and((ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'M' - and cd_education_status = 'Secondary' - and ss_sales_price between 100.00 and 150.00 - and hd_dep_count = 3 - )or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'U' - and cd_education_status = 'Unknown' - and ss_sales_price between 50.00 and 100.00 - and hd_dep_count = 1 - ) or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'S' - and cd_education_status = '2 yr Degree' - and ss_sales_price between 150.00 and 200.00 - and hd_dep_count = 1 - )) - and((ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('TX', 'WA', 'MN') - and ss_net_profit between 100 and 200 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('ND', 'KY', 'IA') - and ss_net_profit between 150 and 300 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('SC', 'AK', 'IL') - and ss_net_profit between 50 and 250 - )) -; - --- end template query13.tpl query 13 in stream 3 --- start template query69.tpl query 14 in stream 3 -select /* TPC-DS query69.tpl 0.28 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_state in ('NE','KY','UT') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2001 and - d_moy between 4 and 4+2) and - (not exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2001 and - d_moy between 4 and 4+2) and - not exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2001 and - d_moy between 4 and 4+2)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - limit 100; - --- end template query69.tpl query 14 in stream 3 --- start template query23.tpl query 15 in stream 3 -with /* TPC-DS query23.tpl 0.68 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (1999,1999+1,1999+2,1999+3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1999,1999+1,1999+2,1999+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * -from - max_store_sales)) - select sum(sales) - from (select cs_quantity*cs_list_price sales - from catalog_sales - ,date_dim - where d_year = 1999 - and d_moy = 1 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - union all - select ws_quantity*ws_list_price sales - from web_sales - ,date_dim - where d_year = 1999 - and d_moy = 1 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer)) - limit 100; -with /* TPC-DS query23.tpl 0.68 part2 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (1999,1999 + 1,1999 + 2,1999 + 3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1999,1999+1,1999+2,1999+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * - from max_store_sales)) - select c_last_name,c_first_name,sales - from (select c_last_name,c_first_name,sum(cs_quantity*cs_list_price) sales - from catalog_sales - ,customer - ,date_dim - where d_year = 1999 - and d_moy = 1 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and cs_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name - union all - select c_last_name,c_first_name,sum(ws_quantity*ws_list_price) sales - from web_sales - ,customer - ,date_dim - where d_year = 1999 - and d_moy = 1 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and ws_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name) - order by c_last_name,c_first_name,sales - limit 100; - --- end template query23.tpl query 15 in stream 3 --- start template query19.tpl query 16 in stream 3 -select /* TPC-DS query19.tpl 0.8 */ i_brand_id brand_id, i_brand brand, i_manufact_id, i_manufact, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item,customer,customer_address,store - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=5 - and d_moy=12 - and d_year=1999 - and ss_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and substring(ca_zip,1,5) <> substring(s_zip,1,5) - and ss_store_sk = s_store_sk - group by i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact - order by ext_price desc - ,i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact -limit 100 ; - --- end template query19.tpl query 16 in stream 3 --- start template query74.tpl query 17 in stream 3 -with /* TPC-DS query74.tpl 0.76 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,sum(ss_net_paid) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (2001,2001+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,sum(ws_net_paid) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - and d_year in (2001,2001+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - ) - select - t_s_secyear.customer_id, t_s_secyear.customer_first_name, t_s_secyear.customer_last_name - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.year = 2001 - and t_s_secyear.year = 2001+1 - and t_w_firstyear.year = 2001 - and t_w_secyear.year = 2001+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - order by 3,2,1 -limit 100; - --- end template query74.tpl query 17 in stream 3 --- start template query30.tpl query 18 in stream 3 -with /* TPC-DS query30.tpl 0.75 */ customer_total_return as - (select wr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(wr_return_amt) as ctr_total_return - from web_returns - ,date_dim - ,customer_address - where wr_returned_date_sk = d_date_sk - and d_year =2002 - and wr_returning_addr_sk = ca_address_sk - group by wr_returning_customer_sk - ,ca_state) - select c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'KS' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return -limit 100; - --- end template query30.tpl query 18 in stream 3 --- start template query84.tpl query 19 in stream 3 -select /* TPC-DS query84.tpl 0.80 */ c_customer_id as customer_id - , coalesce(c_last_name,'') || ', ' || coalesce(c_first_name,'') as customername - from customer - ,customer_address - ,customer_demographics - ,household_demographics - ,income_band - ,store_returns - where ca_city = 'Belmont' - and c_current_addr_sk = ca_address_sk - and ib_lower_bound >= 22617 - and ib_upper_bound <= 22617 + 50000 - and ib_income_band_sk = hd_income_band_sk - and cd_demo_sk = c_current_cdemo_sk - and hd_demo_sk = c_current_hdemo_sk - and sr_cdemo_sk = cd_demo_sk - order by c_customer_id - limit 100; - --- end template query84.tpl query 19 in stream 3 --- start template query96.tpl query 20 in stream 3 -select /* TPC-DS query96.tpl 0.1 */ count(*) -from store_sales - ,household_demographics - ,time_dim, store -where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 20 - and time_dim.t_minute >= 30 - and household_demographics.hd_dep_count = 7 - and store.s_store_name = 'ese' -order by count(*) -limit 100; - --- end template query96.tpl query 20 in stream 3 --- start template query14a.tpl query 21 in stream 3 -with /* TPC-DS query14a.tpl 0.69 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1999 AND 1999 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1999 AND 1999 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1999 AND 1999 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as - (select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2) x) -, - results AS -(select channel, i_brand_id, i_class_id, i_category_id, sum(sales) sum_sales, sum(number_sales) number_sales - from ( - select 'store' channel, i_brand_id,i_class_id - ,i_category_id,sum(ss_quantity*ss_list_price) sales - , count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1999+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales) - union all - select 'catalog' channel, i_brand_id,i_class_id,i_category_id, sum(cs_quantity*cs_list_price) sales, count(*) number_sales - from catalog_sales - ,item - ,date_dim - where cs_item_sk in (select ss_item_sk from cross_items) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1999+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(cs_quantity*cs_list_price) > (select average_sales from avg_sales) - union all - select 'web' channel, i_brand_id,i_class_id,i_category_id, sum(ws_quantity*ws_list_price) sales , count(*) number_sales - from web_sales - ,item - ,date_dim - where ws_item_sk in (select ss_item_sk from cross_items) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1999+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ws_quantity*ws_list_price) > (select average_sales from avg_sales) - ) y - group by channel, i_brand_id,i_class_id,i_category_id) - - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales -from ( - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales from results - union - select channel, i_brand_id, i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id, i_class_id - union - select channel, i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id - union - select channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel - union - select null as channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results) z -order by channel, i_brand_id, i_class_id, i_category_id - limit 100; -with /* TPC-DS query14a.tpl 0.69 part2 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1999 AND 1999 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1999 AND 1999 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1999 AND 1999 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as -(select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2) x) - select this_year.channel ty_channel - ,this_year.i_brand_id ty_brand - ,this_year.i_class_id ty_class - ,this_year.i_category_id ty_category - ,this_year.sales ty_sales - ,this_year.number_sales ty_number_sales - ,last_year.channel ly_channel - ,last_year.i_brand_id ly_brand - ,last_year.i_class_id ly_class - ,last_year.i_category_id ly_category - ,last_year.sales ly_sales - ,last_year.number_sales ly_number_sales -from - (select 'store' channel, i_brand_id,i_class_id,i_category_id - ,sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1999 + 1 - and d_moy = 12 - and d_dom = 7) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) this_year, - (select 'store' channel, i_brand_id,i_class_id - ,i_category_id, sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1999 - and d_moy = 12 - and d_dom = 7) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) last_year - where this_year.i_brand_id= last_year.i_brand_id - and this_year.i_class_id = last_year.i_class_id - and this_year.i_category_id = last_year.i_category_id - order by this_year.channel, this_year.i_brand_id, this_year.i_class_id, this_year.i_category_id - limit 100; - --- end template query14a.tpl query 21 in stream 3 --- start template query10.tpl query 22 in stream 3 -select /* TPC-DS query10.tpl 0.26 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3, - cd_dep_count, - count(*) cnt4, - cd_dep_employed_count, - count(*) cnt5, - cd_dep_college_count, - count(*) cnt6 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_county in ('Bleckley County','Lancaster County','Aroostook County','Marion County','Jefferson County') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2001 and - d_moy between 2 and 2+3) and - (exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2001 and - d_moy between 2 ANd 2+3) or - exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2001 and - d_moy between 2 and 2+3)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count -limit 100; - --- end template query10.tpl query 22 in stream 3 --- start template query86a.tpl query 23 in stream 3 -with /* TPC-DS query86a.tpl 0.11 */ results as -( select sum(ws_net_paid) as total_sum, i_category, i_class, 0 as g_category, 0 as g_class - from - web_sales - ,date_dim d1 - ,item - where - d1.d_month_seq between 1215 and 1215+11 - and d1.d_date_sk = ws_sold_date_sk - and i_item_sk = ws_item_sk - group by i_category,i_class - ) , - - results_rollup as -( select total_sum ,i_category ,i_class, g_category, g_class, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum, i_category, NULL as i_class, 0 as g_category, 1 as g_class, 1 as lochierarchy from results group by i_category - union - select sum(total_sum) as total_sum, NULL as i_category, NULL as i_class, 1 as g_category, 1 as g_class, 2 as lochierarchy from results) - select - total_sum ,i_category ,i_class, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_class = 0 then i_category end - order by total_sum desc) as rank_within_parent - from - results_rollup - order by - lochierarchy desc, - case when lochierarchy = 0 then i_category end, - rank_within_parent - limit 100; - --- end template query86a.tpl query 23 in stream 3 --- start template query94.tpl query 24 in stream 3 -select /* TPC-DS query94.tpl 0.17 */ - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '1999-4-01' and - dateadd(day,60,cast('1999-4-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'OH' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and exists (select * - from web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) -and not exists(select * - from web_returns wr1 - where ws1.ws_order_number = wr1.wr_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query94.tpl query 24 in stream 3 --- start template query8.tpl query 25 in stream 3 -select /* TPC-DS query8.tpl 0.63 */ s_store_name - ,sum(ss_net_profit) - from store_sales - ,date_dim - ,store, - (select ca_zip - from ( - SELECT substring(ca_zip,1,5) ca_zip - FROM customer_address - WHERE substring(ca_zip,1,5) IN ( - '84361','78842','59990','32122','60171','67842', - '37239','93338','65118','34995','53752', - '54823','86526','87442','43885','24133', - '34072','86647','86602','73543','53406', - '80729','83339','87237','54003','41917', - '41978','55168','88304','23984','88548', - '86328','73913','32336','56452','55568', - '48804','83811','11901','90870','10053', - '73537','72057','39045','66837','15093', - '51226','72962','53193','73746','93822', - '19940','47337','41644','13498','91706', - '35419','38328','60298','45011','64561', - '21190','35500','79781','94944','77135', - '48660','55382','14565','11895','85085', - '63977','55332','40791','99461','95716', - '61925','90851','24705','98920','47297', - '60899','60826','52548','66244','30319', - '49512','27254','77188','82445','42854', - '62067','37149','91888','59020','33334', - '61276','30954','47499','43917','94835', - '88978','94795','21525','80172','83247', - '61681','22762','33212','46417','29480', - '82656','38202','82330','20843','19900', - '84313','39598','45673','99280','56203', - '82225','80384','93889','89360','80438', - '48150','72353','17512','12643','28035', - '44737','99217','71663','91707','87044', - '68754','44213','74706','34858','76573', - '80770','99404','85607','29837','41899', - '31972','51095','49027','78196','31227', - '43647','10416','26000','48860','49728', - '12532','22398','99510','96055','49582', - '82392','10749','29425','79041','85314', - '74292','10758','21558','73839','99284', - '35135','84226','43518','99532','96365', - '43928','60880','97073','32436','55405', - '19667','33519','27211','60510','59270', - '60976','20813','17214','99302','92106', - '43471','58967','84214','51897','93139', - '57871','52859','65153','63841','55530', - '23655','27177','58981','45533','27640', - '99744','49655','18012','43980','78098', - '66011','61837','82932','76116','20065', - '65979','22059','26901','74636','39654', - '14151','45764','73721','83894','43356', - '61278','34443','66247','28709','93966', - '22337','22999','62719','34691','39405', - '17596','25613','80697','30505','43307', - '12481','24624','83531','75227','97810', - '28813','69851','36427','15967','35032', - '49979','43388','20919','95638','33921', - '79045','51982','42201','93197','68933', - '83909','64123','59613','15994','65766', - '62645','41691','22744','27304','33747', - '41568','33851','11370','93377','70718', - '16123','52293','66430','93005','50428', - '60778','65392','22931','52897','58668', - '56175','88815','11898','17590','25895', - '60221','48473','10675','44926','41376', - '61701','98151','29169','54112','72889', - '94965','77943','30307','82406','92019', - '87382','96003','69821','82690','87701', - '76127','77788','44453','47027','33124', - '70744','52714','85649','47942','24797', - '37316','40634','23448','18749','55718', - '54651','87619','32349','25912','17921', - '12971','69066','85461','91732','51831', - '17130','33698','23817','55882','33231', - '33955','23425','88859','17897','69976', - '63466','66686','47310','99038','17754', - '32994','62178','88950','99166','59604', - '84432','89582','20307','46854','84058', - '21570','63947','25570','66769','23960', - '51472','67047','13635','13428','95169', - '50744','63644','36229','16636','79406', - '76656','62098','38648','48931','84093', - '93801','73135','18298','53037','13245', - '47599','18148','27769','67499','25192', - '32376','36432','22729','59494','90043', - '94509','16765','97937','63331') - intersect - select ca_zip - from (SELECT substring(ca_zip,1,5) ca_zip,count(*) cnt - FROM customer_address, customer - WHERE ca_address_sk = c_current_addr_sk and - c_preferred_cust_flag='Y' - group by ca_zip - having count(*) > 10)A1)A2) V1 - where ss_store_sk = s_store_sk - and ss_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 2001 - and (substring(s_zip,1,2) = substring(V1.ca_zip,1,2)) - group by s_store_name - order by s_store_name - limit 100; - --- end template query8.tpl query 25 in stream 3 --- start template query87.tpl query 26 in stream 3 -select /* TPC-DS query87.tpl 0.77 */ count(*) -from ((select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1217 and 1217+11) - except - (select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1217 and 1217+11) - except - (select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1217 and 1217+11) -) cool_cust -; - --- end template query87.tpl query 26 in stream 3 --- start template query58.tpl query 27 in stream 3 -with /* TPC-DS query58.tpl 0.19 */ ss_items as - (select i_item_id item_id - ,sum(ss_ext_sales_price) ss_item_rev - from store_sales - ,item - ,date_dim - where ss_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '2000-06-07')) - and ss_sold_date_sk = d_date_sk - group by i_item_id), - cs_items as - (select i_item_id item_id - ,sum(cs_ext_sales_price) cs_item_rev - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '2000-06-07')) - and cs_sold_date_sk = d_date_sk - group by i_item_id), - ws_items as - (select i_item_id item_id - ,sum(ws_ext_sales_price) ws_item_rev - from web_sales - ,item - ,date_dim - where ws_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq =(select d_week_seq - from date_dim - where d_date = '2000-06-07')) - and ws_sold_date_sk = d_date_sk - group by i_item_id) - select ss_items.item_id - ,ss_item_rev - ,ss_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ss_dev - ,cs_item_rev - ,cs_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 cs_dev - ,ws_item_rev - ,ws_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ws_dev - ,(ss_item_rev+cs_item_rev+ws_item_rev)/3 average - from ss_items,cs_items,ws_items - where ss_items.item_id=cs_items.item_id - and ss_items.item_id=ws_items.item_id - and ss_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - and ss_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and cs_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and cs_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and ws_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and ws_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - order by item_id - ,ss_item_rev - limit 100; - --- end template query58.tpl query 27 in stream 3 --- start template query36a.tpl query 28 in stream 3 -with /* TPC-DS query36a.tpl 0.21 */ results as - (select - sum(ss_net_profit) as ss_net_profit, sum(ss_ext_sales_price) as ss_ext_sales_price, - sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin - ,i_category - ,i_class - ,0 as g_category, 0 as g_class - from - store_sales - ,date_dim d1 - ,item - ,store - where - d1.d_year = 1998 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and s_state in ('MO','TX','LA','OH', - 'NM','TN','TN','AL') - group by i_category,i_class) - , - results_rollup as - (select gross_margin ,i_category ,i_class,0 as t_category, 0 as t_class, 0 as lochierarchy from results - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - i_category, NULL AS i_class, 0 as t_category, 1 as t_class, 1 as lochierarchy from results group by i_category - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - NULL AS i_category ,NULL AS i_class, 1 as t_category, 1 as t_class, 2 as lochierarchy from results) - select - gross_margin ,i_category ,i_class, lochierarchy,rank() over ( - partition by lochierarchy, case when t_class = 0 then i_category end - order by gross_margin asc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then i_category end - ,rank_within_parent - limit 100; - --- end template query36a.tpl query 28 in stream 3 --- start template query37.tpl query 29 in stream 3 -select /* TPC-DS query37.tpl 0.31 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, catalog_sales - where i_current_price between 25 and 25 + 30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('1998-03-14' as date) and dateadd(day,60,cast('1998-03-14' as date)) - and i_manufact_id in (816,791,815,882) - and inv_quantity_on_hand between 100 and 500 - and cs_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query37.tpl query 29 in stream 3 --- start template query4.tpl query 30 in stream 3 -with /* TPC-DS query4.tpl 0.93 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(((ss_ext_list_price-ss_ext_wholesale_cost-ss_ext_discount_amt)+ss_ext_sales_price)/2) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((cs_ext_list_price-cs_ext_wholesale_cost-cs_ext_discount_amt)+cs_ext_sales_price)/2) ) year_total - ,'c' sale_type - from customer - ,catalog_sales - ,date_dim - where c_customer_sk = cs_bill_customer_sk - and cs_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year -union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((ws_ext_list_price-ws_ext_wholesale_cost-ws_ext_discount_amt)+ws_ext_sales_price)/2) ) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_email_address - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_c_firstyear - ,year_total t_c_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_c_secyear.customer_id - and t_s_firstyear.customer_id = t_c_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_c_firstyear.sale_type = 'c' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_c_secyear.sale_type = 'c' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 2001 - and t_s_secyear.dyear = 2001+1 - and t_c_firstyear.dyear = 2001 - and t_c_secyear.dyear = 2001+1 - and t_w_firstyear.dyear = 2001 - and t_w_secyear.dyear = 2001+1 - and t_s_firstyear.year_total > 0 - and t_c_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_email_address -limit 100; - --- end template query4.tpl query 30 in stream 3 --- start template query38.tpl query 31 in stream 3 -select /* TPC-DS query38.tpl 0.54 */ count(*) from ( - select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1203 and 1203 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1203 and 1203 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1203 and 1203 + 11 -) hot_cust -limit 100; - --- end template query38.tpl query 31 in stream 3 --- start template query66.tpl query 32 in stream 3 -select /* TPC-DS query66.tpl 0.39 */ - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - ,sum(jan_sales) as jan_sales - ,sum(feb_sales) as feb_sales - ,sum(mar_sales) as mar_sales - ,sum(apr_sales) as apr_sales - ,sum(may_sales) as may_sales - ,sum(jun_sales) as jun_sales - ,sum(jul_sales) as jul_sales - ,sum(aug_sales) as aug_sales - ,sum(sep_sales) as sep_sales - ,sum(oct_sales) as oct_sales - ,sum(nov_sales) as nov_sales - ,sum(dec_sales) as dec_sales - ,sum(jan_sales/w_warehouse_sq_ft) as jan_sales_per_sq_foot - ,sum(feb_sales/w_warehouse_sq_ft) as feb_sales_per_sq_foot - ,sum(mar_sales/w_warehouse_sq_ft) as mar_sales_per_sq_foot - ,sum(apr_sales/w_warehouse_sq_ft) as apr_sales_per_sq_foot - ,sum(may_sales/w_warehouse_sq_ft) as may_sales_per_sq_foot - ,sum(jun_sales/w_warehouse_sq_ft) as jun_sales_per_sq_foot - ,sum(jul_sales/w_warehouse_sq_ft) as jul_sales_per_sq_foot - ,sum(aug_sales/w_warehouse_sq_ft) as aug_sales_per_sq_foot - ,sum(sep_sales/w_warehouse_sq_ft) as sep_sales_per_sq_foot - ,sum(oct_sales/w_warehouse_sq_ft) as oct_sales_per_sq_foot - ,sum(nov_sales/w_warehouse_sq_ft) as nov_sales_per_sq_foot - ,sum(dec_sales/w_warehouse_sq_ft) as dec_sales_per_sq_foot - ,sum(jan_net) as jan_net - ,sum(feb_net) as feb_net - ,sum(mar_net) as mar_net - ,sum(apr_net) as apr_net - ,sum(may_net) as may_net - ,sum(jun_net) as jun_net - ,sum(jul_net) as jul_net - ,sum(aug_net) as aug_net - ,sum(sep_net) as sep_net - ,sum(oct_net) as oct_net - ,sum(nov_net) as nov_net - ,sum(dec_net) as dec_net - from ( - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'FEDEX' || ',' || 'TBS' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then ws_ext_list_price* ws_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then ws_ext_list_price* ws_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then ws_ext_list_price* ws_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then ws_ext_list_price* ws_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then ws_ext_list_price* ws_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then ws_ext_list_price* ws_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then ws_ext_list_price* ws_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then ws_ext_list_price* ws_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then ws_ext_list_price* ws_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then ws_ext_list_price* ws_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then ws_ext_list_price* ws_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then ws_ext_list_price* ws_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as dec_net - from - web_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - ws_warehouse_sk = w_warehouse_sk - and ws_sold_date_sk = d_date_sk - and ws_sold_time_sk = t_time_sk - and ws_ship_mode_sk = sm_ship_mode_sk - and d_year = 1998 - and t_time between 20417 and 20417+28800 - and sm_carrier in ('FEDEX','TBS') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - union all - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'FEDEX' || ',' || 'TBS' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then cs_sales_price* cs_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then cs_sales_price* cs_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then cs_sales_price* cs_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then cs_sales_price* cs_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then cs_sales_price* cs_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then cs_sales_price* cs_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then cs_sales_price* cs_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then cs_sales_price* cs_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then cs_sales_price* cs_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then cs_sales_price* cs_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then cs_sales_price* cs_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then cs_sales_price* cs_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as dec_net - from - catalog_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and cs_sold_time_sk = t_time_sk - and cs_ship_mode_sk = sm_ship_mode_sk - and d_year = 1998 - and t_time between 20417 AND 20417+28800 - and sm_carrier in ('FEDEX','TBS') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - ) x - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - order by w_warehouse_name - limit 100; - --- end template query66.tpl query 32 in stream 3 --- start template query78.tpl query 33 in stream 3 -with /* TPC-DS query78.tpl 0.10 */ ws as - (select d_year AS ws_sold_year, ws_item_sk, - ws_bill_customer_sk ws_customer_sk, - sum(ws_quantity) ws_qty, - sum(ws_wholesale_cost) ws_wc, - sum(ws_sales_price) ws_sp - from web_sales - left join web_returns on wr_order_number=ws_order_number and ws_item_sk=wr_item_sk - join date_dim on ws_sold_date_sk = d_date_sk - where wr_order_number is null - group by d_year, ws_item_sk, ws_bill_customer_sk - ), -cs as - (select d_year AS cs_sold_year, cs_item_sk, - cs_bill_customer_sk cs_customer_sk, - sum(cs_quantity) cs_qty, - sum(cs_wholesale_cost) cs_wc, - sum(cs_sales_price) cs_sp - from catalog_sales - left join catalog_returns on cr_order_number=cs_order_number and cs_item_sk=cr_item_sk - join date_dim on cs_sold_date_sk = d_date_sk - where cr_order_number is null - group by d_year, cs_item_sk, cs_bill_customer_sk - ), -ss as - (select d_year AS ss_sold_year, ss_item_sk, - ss_customer_sk, - sum(ss_quantity) ss_qty, - sum(ss_wholesale_cost) ss_wc, - sum(ss_sales_price) ss_sp - from store_sales - left join store_returns on sr_ticket_number=ss_ticket_number and ss_item_sk=sr_item_sk - join date_dim on ss_sold_date_sk = d_date_sk - where sr_ticket_number is null - group by d_year, ss_item_sk, ss_customer_sk - ) - select -ss_item_sk, -round(ss_qty/(coalesce(ws_qty,0)+coalesce(cs_qty,0)),2) ratio, -ss_qty store_qty, ss_wc store_wholesale_cost, ss_sp store_sales_price, -coalesce(ws_qty,0)+coalesce(cs_qty,0) other_chan_qty, -coalesce(ws_wc,0)+coalesce(cs_wc,0) other_chan_wholesale_cost, -coalesce(ws_sp,0)+coalesce(cs_sp,0) other_chan_sales_price -from ss -left join ws on (ws_sold_year=ss_sold_year and ws_item_sk=ss_item_sk and ws_customer_sk=ss_customer_sk) -left join cs on (cs_sold_year=ss_sold_year and cs_item_sk=ss_item_sk and cs_customer_sk=ss_customer_sk) -where (coalesce(ws_qty,0)>0 or coalesce(cs_qty, 0)>0) and ss_sold_year=1999 -order by - ss_item_sk, - ss_qty desc, ss_wc desc, ss_sp desc, - other_chan_qty, - other_chan_wholesale_cost, - other_chan_sales_price, - ratio -limit 100; - --- end template query78.tpl query 33 in stream 3 --- start template query43.tpl query 34 in stream 3 -select /* TPC-DS query43.tpl 0.15 */ s_store_name, s_store_id, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from date_dim, store_sales, store - where d_date_sk = ss_sold_date_sk and - s_store_sk = ss_store_sk and - s_gmt_offset = -7 and - d_year = 2000 - group by s_store_name, s_store_id - order by s_store_name, s_store_id,sun_sales,mon_sales,tue_sales,wed_sales,thu_sales,fri_sales,sat_sales - limit 100; - --- end template query43.tpl query 34 in stream 3 --- start template query22a.tpl query 35 in stream 3 -with /* TPC-DS query22a.tpl 0.55 */ results as -(select i_product_name - ,i_brand - ,i_class - ,i_category - ,avg(inv_quantity_on_hand) qoh - from inventory - ,date_dim - ,item --- ,warehouse - where inv_date_sk=d_date_sk - and inv_item_sk=i_item_sk --- and inv_warehouse_sk = w_warehouse_sk - and d_month_seq between 1188 and 1188 + 11 - group by i_product_name,i_brand,i_class,i_category), -results_rollup as -(select i_product_name, i_brand, i_class, i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class,i_category -union all -select i_product_name, i_brand, i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class -union all -select i_product_name, i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand -union all -select i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name -union all -select null i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results) - select i_product_name, i_brand, i_class, i_category,qoh - from results_rollup - order by qoh, i_product_name, i_brand, i_class, i_category -limit 100; - --- end template query22a.tpl query 35 in stream 3 --- start template query21.tpl query 36 in stream 3 -select /* TPC-DS query21.tpl 0.14 */ * - from(select w_warehouse_name - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('2001-03-01' as date)) - then inv_quantity_on_hand - else 0 end) as inv_before - ,sum(case when (cast(d_date as date) >= cast ('2001-03-01' as date)) - then inv_quantity_on_hand - else 0 end) as inv_after - from inventory - ,warehouse - ,item - ,date_dim - where i_current_price between 0.99 and 1.49 - and i_item_sk = inv_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('2001-03-01' as date)) - and dateadd(day,30,cast ('2001-03-01' as date)) - group by w_warehouse_name, i_item_id) x - where (case when inv_before > 0 - then inv_after / inv_before - else null - end) between 2.0/3.0 and 3.0/2.0 - order by w_warehouse_name - ,i_item_id - limit 100; - --- end template query21.tpl query 36 in stream 3 --- start template query97.tpl query 37 in stream 3 -with /* TPC-DS query97.tpl 0.38 */ ssci as ( -select ss_customer_sk customer_sk - ,ss_item_sk item_sk -from store_sales,date_dim -where ss_sold_date_sk = d_date_sk - and d_month_seq between 1212 and 1212 + 11 -group by ss_customer_sk - ,ss_item_sk), -csci as( - select cs_bill_customer_sk customer_sk - ,cs_item_sk item_sk -from catalog_sales,date_dim -where cs_sold_date_sk = d_date_sk - and d_month_seq between 1212 and 1212 + 11 -group by cs_bill_customer_sk - ,cs_item_sk) - select sum(case when ssci.customer_sk is not null and csci.customer_sk is null then 1 else 0 end) store_only - ,sum(case when ssci.customer_sk is null and csci.customer_sk is not null then 1 else 0 end) catalog_only - ,sum(case when ssci.customer_sk is not null and csci.customer_sk is not null then 1 else 0 end) store_and_catalog -from ssci full outer join csci on (ssci.customer_sk=csci.customer_sk - and ssci.item_sk = csci.item_sk) -limit 100; - --- end template query97.tpl query 37 in stream 3 --- start template query47.tpl query 38 in stream 3 -with /* TPC-DS query47.tpl 0.42 */ v1 as( - select i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, - s_store_name, s_company_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - s_store_name, s_company_name - order by d_year, d_moy) rn - from item, store_sales, date_dim, store - where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - ( - d_year = 2000 or - ( d_year = 2000-1 and d_moy =12) or - ( d_year = 2000+1 and d_moy =1) - ) - group by i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy), - v2 as( - select v1.s_company_name - ,v1.d_year, v1.d_moy - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1.s_store_name = v1_lag.s_store_name and - v1.s_store_name = v1_lead.s_store_name and - v1.s_company_name = v1_lag.s_company_name and - v1.s_company_name = v1_lead.s_company_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 2000 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, nsum - limit 100; - --- end template query47.tpl query 38 in stream 3 --- start template query29.tpl query 39 in stream 3 -select /* TPC-DS query29.tpl 0.53 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,stddev_samp(ss_quantity) as store_sales_quantity - ,stddev_samp(sr_return_quantity) as store_returns_quantity - ,stddev_samp(cs_quantity) as catalog_sales_quantity - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 1999 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 4 + 3 - and d2.d_year = 1999 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_year in (1999,1999+1,1999+2) - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query29.tpl query 39 in stream 3 --- start template query3.tpl query 40 in stream 3 -select /* TPC-DS query3.tpl 0.45 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_sales_price) sum_agg - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manufact_id = 819 - and dt.d_moy=12 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,sum_agg desc - ,brand_id - limit 100; - --- end template query3.tpl query 40 in stream 3 --- start template query76.tpl query 41 in stream 3 -select /* TPC-DS query76.tpl 0.99 */ channel, col_name, d_year, d_qoy, i_category, COUNT(*) sales_cnt, SUM(ext_sales_price) sales_amt FROM ( - SELECT 'store' as channel, 'ss_store_sk' col_name, d_year, d_qoy, i_category, ss_ext_sales_price ext_sales_price - FROM store_sales, item, date_dim - WHERE ss_store_sk IS NULL - AND ss_sold_date_sk=d_date_sk - AND ss_item_sk=i_item_sk - UNION ALL - SELECT 'web' as channel, 'ws_promo_sk' col_name, d_year, d_qoy, i_category, ws_ext_sales_price ext_sales_price - FROM web_sales, item, date_dim - WHERE ws_promo_sk IS NULL - AND ws_sold_date_sk=d_date_sk - AND ws_item_sk=i_item_sk - UNION ALL - SELECT 'catalog' as channel, 'cs_bill_addr_sk' col_name, d_year, d_qoy, i_category, cs_ext_sales_price ext_sales_price - FROM catalog_sales, item, date_dim - WHERE cs_bill_addr_sk IS NULL - AND cs_sold_date_sk=d_date_sk - AND cs_item_sk=i_item_sk) foo -GROUP BY channel, col_name, d_year, d_qoy, i_category -ORDER BY channel, col_name, d_year, d_qoy, i_category -limit 100; - --- end template query76.tpl query 41 in stream 3 --- start template query82.tpl query 42 in stream 3 -select /* TPC-DS query82.tpl 0.67 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, store_sales - where i_current_price between 56 and 56+30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('1999-04-15' as date) and dateadd(day,60,cast('1999-04-15' as date)) - and i_manufact_id in (812,479,428,661) - and inv_quantity_on_hand between 100 and 500 - and ss_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query82.tpl query 42 in stream 3 --- start template query46.tpl query 43 in stream 3 -select /* TPC-DS query46.tpl 0.23 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and (household_demographics.hd_dep_count = 7 or - household_demographics.hd_vehicle_count= -1) - and date_dim.d_dow in (6,0) - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_city in ('Edgewood','Oakdale','Unionville','Summit','Hamilton') - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,ca_city) dn,customer,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - limit 100; - --- end template query46.tpl query 43 in stream 3 --- start template query41.tpl query 44 in stream 3 -select /* TPC-DS query41.tpl 0.62 */ distinct(i_product_name) - from item i1 - where i_manufact_id between 736 and 736+40 - and (select count(*) as item_cnt - from item - where (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'floral' or i_color = 'lime') and - (i_units = 'Tsp' or i_units = 'Each') and - (i_size = 'medium' or i_size = 'petite') - ) or - (i_category = 'Women' and - (i_color = 'rose' or i_color = 'cyan') and - (i_units = 'N/A' or i_units = 'Tbl') and - (i_size = 'economy' or i_size = 'N/A') - ) or - (i_category = 'Men' and - (i_color = 'magenta' or i_color = 'plum') and - (i_units = 'Dram' or i_units = 'Lb') and - (i_size = 'extra large' or i_size = 'small') - ) or - (i_category = 'Men' and - (i_color = 'midnight' or i_color = 'seashell') and - (i_units = 'Carton' or i_units = 'Pallet') and - (i_size = 'medium' or i_size = 'petite') - ))) or - (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'metallic' or i_color = 'steel') and - (i_units = 'Box' or i_units = 'Gross') and - (i_size = 'medium' or i_size = 'petite') - ) or - (i_category = 'Women' and - (i_color = 'cornsilk' or i_color = 'white') and - (i_units = 'Cup' or i_units = 'Case') and - (i_size = 'economy' or i_size = 'N/A') - ) or - (i_category = 'Men' and - (i_color = 'hot' or i_color = 'blanched') and - (i_units = 'Bunch' or i_units = 'Dozen') and - (i_size = 'extra large' or i_size = 'small') - ) or - (i_category = 'Men' and - (i_color = 'sienna' or i_color = 'lavender') and - (i_units = 'Oz' or i_units = 'Pound') and - (i_size = 'medium' or i_size = 'petite') - )))) > 0 - order by i_product_name - limit 100; - --- end template query41.tpl query 44 in stream 3 --- start template query59.tpl query 45 in stream 3 -with /* TPC-DS query59.tpl 0.30 */ wss as - (select d_week_seq, - ss_store_sk, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - group by d_week_seq,ss_store_sk - ) - select s_store_name1,s_store_id1,d_week_seq1 - ,sun_sales1/sun_sales2,mon_sales1/mon_sales2 - ,tue_sales1/tue_sales2,wed_sales1/wed_sales2,thu_sales1/thu_sales2 - ,fri_sales1/fri_sales2,sat_sales1/sat_sales2 - from - (select s_store_name s_store_name1,wss.d_week_seq d_week_seq1 - ,s_store_id s_store_id1,sun_sales sun_sales1 - ,mon_sales mon_sales1,tue_sales tue_sales1 - ,wed_sales wed_sales1,thu_sales thu_sales1 - ,fri_sales fri_sales1,sat_sales sat_sales1 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1206 and 1206 + 11) y, - (select s_store_name s_store_name2,wss.d_week_seq d_week_seq2 - ,s_store_id s_store_id2,sun_sales sun_sales2 - ,mon_sales mon_sales2,tue_sales tue_sales2 - ,wed_sales wed_sales2,thu_sales thu_sales2 - ,fri_sales fri_sales2,sat_sales sat_sales2 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1206+ 12 and 1206 + 23) x - where s_store_id1=s_store_id2 - and d_week_seq1=d_week_seq2-52 - order by s_store_name1,s_store_id1,d_week_seq1 -limit 100; - --- end template query59.tpl query 45 in stream 3 --- start template query40.tpl query 46 in stream 3 -select /* TPC-DS query40.tpl 0.86 */ - w_state - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('2001-04-04' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_before - ,sum(case when (cast(d_date as date) >= cast ('2001-04-04' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_after - from - catalog_sales left outer join catalog_returns on - (cs_order_number = cr_order_number - and cs_item_sk = cr_item_sk) - ,warehouse - ,item - ,date_dim - where - i_current_price between 0.99 and 1.49 - and i_item_sk = cs_item_sk - and cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('2001-04-04' as date)) - and dateadd(day,30,cast ('2001-04-04' as date)) - group by - w_state,i_item_id - order by w_state,i_item_id -limit 100; - --- end template query40.tpl query 46 in stream 3 --- start template query55.tpl query 47 in stream 3 -select /* TPC-DS query55.tpl 0.82 */ i_brand_id brand_id, i_brand brand, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=16 - and d_moy=12 - and d_year=2000 - group by i_brand, i_brand_id - order by ext_price desc, i_brand_id -limit 100 ; - --- end template query55.tpl query 47 in stream 3 --- start template query16.tpl query 48 in stream 3 -select /* TPC-DS query16.tpl 0.25 */ - count(distinct cs_order_number) as "order count" - ,sum(cs_ext_ship_cost) as "total shipping cost" - ,sum(cs_net_profit) as "total net profit" -from - catalog_sales cs1 - ,date_dim - ,customer_address - ,call_center -where - d_date between '2002-5-01' and - dateadd(day, 60, cast('2002-5-01' as date)) -and cs1.cs_ship_date_sk = d_date_sk -and cs1.cs_ship_addr_sk = ca_address_sk -and ca_state = 'WV' -and cs1.cs_call_center_sk = cc_call_center_sk -and cc_county in ('Daviess County','Jefferson Davis Parish','Luce County','San Miguel County', - 'Williamson County' -) -and exists (select * - from catalog_sales cs2 - where cs1.cs_order_number = cs2.cs_order_number - and cs1.cs_warehouse_sk <> cs2.cs_warehouse_sk) -and not exists(select * - from catalog_returns cr1 - where cs1.cs_order_number = cr1.cr_order_number) -order by count(distinct cs_order_number) -limit 100; - --- end template query16.tpl query 48 in stream 3 --- start template query27a.tpl query 49 in stream 3 -with /* TPC-DS query27a.tpl 0.16 */ results as - (select i_item_id, - s_state, 0 as g_state, - ss_quantity agg1, - ss_list_price agg2, - ss_coupon_amt agg3, - ss_sales_price agg4 - from store_sales, customer_demographics, date_dim, store, item - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_store_sk = s_store_sk and - ss_cdemo_sk = cd_demo_sk and - cd_gender = 'F' and - cd_marital_status = 'M' and - cd_education_status = 'College' and - d_year = 2000 and - s_state in ('MI','GA', 'MI', 'AL', 'NC', 'FL') - ) - - select i_item_id, - s_state, g_state, agg1, agg2, agg3, agg4 - from ( - select i_item_id, s_state, 0 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4 from results - group by i_item_id, s_state - union all - select i_item_id, NULL AS s_state, 1 AS g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as s_state, 1 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - ) foo - order by i_item_id, s_state - limit 100; - --- end template query27a.tpl query 49 in stream 3 --- start template query54.tpl query 50 in stream 3 -with /* TPC-DS query54.tpl 0.81 */ my_customers as ( - select distinct c_customer_sk - , c_current_addr_sk - from - ( select cs_sold_date_sk sold_date_sk, - cs_bill_customer_sk customer_sk, - cs_item_sk item_sk - from catalog_sales - union all - select ws_sold_date_sk sold_date_sk, - ws_bill_customer_sk customer_sk, - ws_item_sk item_sk - from web_sales - ) cs_or_ws_sales, - item, - date_dim, - customer - where sold_date_sk = d_date_sk - and item_sk = i_item_sk - and i_category = 'Home' - and i_class = 'wallpaper' - and c_customer_sk = cs_or_ws_sales.customer_sk - and d_moy = 6 - and d_year = 1998 - ) - , my_revenue as ( - select c_customer_sk, - sum(ss_ext_sales_price) as revenue - from my_customers, - store_sales, - customer_address, - store, - date_dim - where c_current_addr_sk = ca_address_sk - and ca_county = s_county - and ca_state = s_state - and ss_sold_date_sk = d_date_sk - and c_customer_sk = ss_customer_sk - and d_month_seq between (select distinct d_month_seq+1 - from date_dim where d_year = 1998 and d_moy = 6) - and (select distinct d_month_seq+3 - from date_dim where d_year = 1998 and d_moy = 6) - group by c_customer_sk - ) - , segments as - (select cast((revenue/50) as int) as segment - from my_revenue - ) - select segment, count(*) as num_customers, segment*50 as segment_base - from segments - group by segment - order by segment, num_customers - limit 100; - --- end template query54.tpl query 50 in stream 3 --- start template query90.tpl query 51 in stream 3 -select /* TPC-DS query90.tpl 0.40 */ cast(amc as decimal(15,4))/cast(pmc as decimal(15,4)) am_pm_ratio - from ( select count(*) amc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 10 and 10+1 - and household_demographics.hd_dep_count = 8 - and web_page.wp_char_count between 5000 and 5200) at, - ( select count(*) pmc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 15 and 15+1 - and household_demographics.hd_dep_count = 8 - and web_page.wp_char_count between 5000 and 5200) pt - order by am_pm_ratio - limit 100; - --- end template query90.tpl query 51 in stream 3 --- start template query92.tpl query 52 in stream 3 -select /* TPC-DS query92.tpl 0.44 */ - sum(ws_ext_discount_amt) as "Excess Discount Amount" -from - web_sales - ,item - ,date_dim -where -i_manufact_id = 84 -and i_item_sk = ws_item_sk -and d_date between '1998-01-09' and - dateadd(day,90,cast('1998-01-09' as date)) -and d_date_sk = ws_sold_date_sk -and ws_ext_discount_amt - > ( - SELECT - 1.3 * avg(ws_ext_discount_amt) - FROM - web_sales - ,date_dim - WHERE - ws_item_sk = i_item_sk - and d_date between '1998-01-09' and - dateadd(day,90,cast('1998-01-09' as date)) - and d_date_sk = ws_sold_date_sk - ) -order by sum(ws_ext_discount_amt) -limit 100; - --- end template query92.tpl query 52 in stream 3 --- start template query31.tpl query 53 in stream 3 -with /* TPC-DS query31.tpl 0.50 */ ss as - (select ca_county,d_qoy, d_year,sum(ss_ext_sales_price) as store_sales - from store_sales,date_dim,customer_address - where ss_sold_date_sk = d_date_sk - and ss_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year), - ws as - (select ca_county,d_qoy, d_year,sum(ws_ext_sales_price) as web_sales - from web_sales,date_dim,customer_address - where ws_sold_date_sk = d_date_sk - and ws_bill_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year) - select - ss1.ca_county - ,ss1.d_year - ,ws2.web_sales/ws1.web_sales web_q1_q2_increase - ,ss2.store_sales/ss1.store_sales store_q1_q2_increase - ,ws3.web_sales/ws2.web_sales web_q2_q3_increase - ,ss3.store_sales/ss2.store_sales store_q2_q3_increase - from - ss ss1 - ,ss ss2 - ,ss ss3 - ,ws ws1 - ,ws ws2 - ,ws ws3 - where - ss1.d_qoy = 1 - and ss1.d_year = 2002 - and ss1.ca_county = ss2.ca_county - and ss2.d_qoy = 2 - and ss2.d_year = 2002 - and ss2.ca_county = ss3.ca_county - and ss3.d_qoy = 3 - and ss3.d_year = 2002 - and ss1.ca_county = ws1.ca_county - and ws1.d_qoy = 1 - and ws1.d_year = 2002 - and ws1.ca_county = ws2.ca_county - and ws2.d_qoy = 2 - and ws2.d_year = 2002 - and ws1.ca_county = ws3.ca_county - and ws3.d_qoy = 3 - and ws3.d_year =2002 - and case when ws1.web_sales > 0 then ws2.web_sales/ws1.web_sales else null end - > case when ss1.store_sales > 0 then ss2.store_sales/ss1.store_sales else null end - and case when ws2.web_sales > 0 then ws3.web_sales/ws2.web_sales else null end - > case when ss2.store_sales > 0 then ss3.store_sales/ss2.store_sales else null end - order by ss1.d_year; - --- end template query31.tpl query 53 in stream 3 --- start template query42.tpl query 54 in stream 3 -select /* TPC-DS query42.tpl 0.61 */ dt.d_year - ,item.i_category_id - ,item.i_category - ,sum(ss_ext_sales_price) - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=12 - and dt.d_year=1998 - group by dt.d_year - ,item.i_category_id - ,item.i_category - order by sum(ss_ext_sales_price) desc,dt.d_year - ,item.i_category_id - ,item.i_category -limit 100 ; - --- end template query42.tpl query 54 in stream 3 --- start template query26.tpl query 55 in stream 3 -select /* TPC-DS query26.tpl 0.85 */ i_item_id, - avg(cs_quantity) agg1, - avg(cs_list_price) agg2, - avg(cs_coupon_amt) agg3, - avg(cs_sales_price) agg4 - from catalog_sales, customer_demographics, date_dim, item, promotion - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd_demo_sk and - cs_promo_sk = p_promo_sk and - cd_gender = 'M' and - cd_marital_status = 'D' and - cd_education_status = 'Advanced Degree' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 2001 - group by i_item_id - order by i_item_id - limit 100; - --- end template query26.tpl query 55 in stream 3 --- start template query34.tpl query 56 in stream 3 -select /* TPC-DS query34.tpl 0.73 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (date_dim.d_dom between 1 and 3 or date_dim.d_dom between 25 and 28) - and (household_demographics.hd_buy_potential = '>10000' or - household_demographics.hd_buy_potential = '0-500') - and household_demographics.hd_vehicle_count > 0 - and (case when household_demographics.hd_vehicle_count > 0 - then household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count - else null - end) > 1.2 - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_county in ('Mobile County','Franklin Parish','Pennington County','Wadena County', - 'Ziebach County','Adams County','Anderson County','Maverick County') - group by ss_ticket_number,ss_customer_sk) dn,customer - where ss_customer_sk = c_customer_sk - and cnt between 15 and 20 - order by c_last_name,c_first_name,c_salutation,c_preferred_cust_flag desc, ss_ticket_number; - --- end template query34.tpl query 56 in stream 3 --- start template query68.tpl query 57 in stream 3 -select /* TPC-DS query68.tpl 0.95 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,extended_price - ,extended_tax - ,list_price - from (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_ext_sales_price) extended_price - ,sum(ss_ext_list_price) list_price - ,sum(ss_ext_tax) extended_tax - from store_sales - ,date_dim - ,store - ,household_demographics - ,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_dep_count = 1 or - household_demographics.hd_vehicle_count= 1) - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_city in ('Pleasant Valley','Sunnyside') - group by ss_ticket_number - ,ss_customer_sk - ,ss_addr_sk,ca_city) dn - ,customer - ,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,ss_ticket_number - limit 100; - --- end template query68.tpl query 57 in stream 3 --- start template query2.tpl query 58 in stream 3 -with /* TPC-DS query2.tpl 0.84 */ wscs as - (select sold_date_sk - ,sales_price - from (select ws_sold_date_sk sold_date_sk - ,ws_ext_sales_price sales_price - from web_sales - union all - select cs_sold_date_sk sold_date_sk - ,cs_ext_sales_price sales_price - from catalog_sales)), - wswscs as - (select d_week_seq, - sum(case when (d_day_name='Sunday') then sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then sales_price else null end) sat_sales - from wscs - ,date_dim - where d_date_sk = sold_date_sk - group by d_week_seq) - select d_week_seq1 - ,round(sun_sales1/sun_sales2,2) - ,round(mon_sales1/mon_sales2,2) - ,round(tue_sales1/tue_sales2,2) - ,round(wed_sales1/wed_sales2,2) - ,round(thu_sales1/thu_sales2,2) - ,round(fri_sales1/fri_sales2,2) - ,round(sat_sales1/sat_sales2,2) - from - (select wswscs.d_week_seq d_week_seq1 - ,sun_sales sun_sales1 - ,mon_sales mon_sales1 - ,tue_sales tue_sales1 - ,wed_sales wed_sales1 - ,thu_sales thu_sales1 - ,fri_sales fri_sales1 - ,sat_sales sat_sales1 - from wswscs,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 2000) y, - (select wswscs.d_week_seq d_week_seq2 - ,sun_sales sun_sales2 - ,mon_sales mon_sales2 - ,tue_sales tue_sales2 - ,wed_sales wed_sales2 - ,thu_sales thu_sales2 - ,fri_sales fri_sales2 - ,sat_sales sat_sales2 - from wswscs - ,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 2000+1) z - where d_week_seq1=d_week_seq2-53 - order by d_week_seq1; - --- end template query2.tpl query 58 in stream 3 --- start template query44.tpl query 59 in stream 3 -select /* TPC-DS query44.tpl 0.4 */ asceding.rnk, i1.i_product_name best_performing, i2.i_product_name worst_performing -from(select * - from (select item_sk,rank() over (order by rank_col asc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 491 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 491 - and ss_hdemo_sk is null - group by ss_store_sk))V1)V11 - where rnk < 11) asceding, - (select * - from (select item_sk,rank() over (order by rank_col desc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 491 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 491 - and ss_hdemo_sk is null - group by ss_store_sk))V2)V21 - where rnk < 11) descending, -item i1, -item i2 -where asceding.rnk = descending.rnk - and i1.i_item_sk=asceding.item_sk - and i2.i_item_sk=descending.item_sk -order by asceding.rnk -limit 100; - --- end template query44.tpl query 59 in stream 3 --- start template query81.tpl query 60 in stream 3 -with /* TPC-DS query81.tpl 0.37 */ customer_total_return as - (select cr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(cr_return_amt_inc_tax) as ctr_total_return - from catalog_returns - ,date_dim - ,customer_address - where cr_returned_date_sk = d_date_sk - and d_year =2002 - and cr_returning_addr_sk = ca_address_sk - group by cr_returning_customer_sk - ,ca_state ) - select c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'KY' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - limit 100; - --- end template query81.tpl query 60 in stream 3 --- start template query67a.tpl query 61 in stream 3 -with /* TPC-DS query67a.tpl 0.35 */ results as -( select i_category ,i_class ,i_brand ,i_product_name ,d_year ,d_qoy ,d_moy ,s_store_id - ,sum(coalesce(ss_sales_price*ss_quantity,0)) sumsales - from store_sales ,date_dim ,store ,item - where ss_sold_date_sk=d_date_sk - and ss_item_sk=i_item_sk - and ss_store_sk = s_store_sk - and d_month_seq between 1179 and 1179 + 11 - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy,s_store_id) - , - results_rollup as - (select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, s_store_id, sumsales - from results - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy - union all - select i_category, i_class, i_brand, i_product_name, d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year - union all - select i_category, i_class, i_brand, i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name - union all - select i_category, i_class, i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand - union all - select i_category, i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class - union all - select i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category - union all - select null i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results) - - select * -from (select i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rank() over (partition by i_category order by sumsales desc) rk - from results_rollup) dw2 -where rk <= 100 -order by i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rk -limit 100; - --- end template query67a.tpl query 61 in stream 3 --- start template query99.tpl query 62 in stream 3 -select /* TPC-DS query99.tpl 0.94 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 30) and - (cs_ship_date_sk - cs_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 60) and - (cs_ship_date_sk - cs_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 90) and - (cs_ship_date_sk - cs_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - catalog_sales - ,warehouse - ,ship_mode - ,call_center - ,date_dim -where - d_month_seq between 1208 and 1208 + 11 -and cs_ship_date_sk = d_date_sk -and cs_warehouse_sk = w_warehouse_sk -and cs_ship_mode_sk = sm_ship_mode_sk -and cs_call_center_sk = cc_call_center_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -limit 100; - --- end template query99.tpl query 62 in stream 3 --- start template query6.tpl query 63 in stream 3 -select /* TPC-DS query6.tpl 0.58 */ a.ca_state state, count(*) cnt - from customer_address a - ,customer c - ,store_sales s - ,date_dim d - ,item i - where a.ca_address_sk = c.c_current_addr_sk - and c.c_customer_sk = s.ss_customer_sk - and s.ss_sold_date_sk = d.d_date_sk - and s.ss_item_sk = i.i_item_sk - and d.d_month_seq = - (select distinct (d_month_seq) - from date_dim - where d_year = 2000 - and d_moy = 4 ) - and i.i_current_price > 1.2 * - (select avg(j.i_current_price) - from item j - where j.i_category = i.i_category) - group by a.ca_state - having count(*) >= 10 - order by cnt, a.ca_state - limit 100; - --- end template query6.tpl query 63 in stream 3 --- start template query83.tpl query 64 in stream 3 -with /* TPC-DS query83.tpl 0.96 */ sr_items as - (select i_item_id item_id, - sum(sr_return_quantity) sr_item_qty - from store_returns, - item, - date_dim - where sr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2001-02-11','2001-09-22','2001-11-16'))) - and sr_returned_date_sk = d_date_sk - group by i_item_id), - cr_items as - (select i_item_id item_id, - sum(cr_return_quantity) cr_item_qty - from catalog_returns, - item, - date_dim - where cr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2001-02-11','2001-09-22','2001-11-16'))) - and cr_returned_date_sk = d_date_sk - group by i_item_id), - wr_items as - (select i_item_id item_id, - sum(wr_return_quantity) wr_item_qty - from web_returns, - item, - date_dim - where wr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2001-02-11','2001-09-22','2001-11-16'))) - and wr_returned_date_sk = d_date_sk - group by i_item_id) - select sr_items.item_id - ,sr_item_qty - ,sr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 sr_dev - ,cr_item_qty - ,cr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 cr_dev - ,wr_item_qty - ,wr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 wr_dev - ,(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 average - from sr_items - ,cr_items - ,wr_items - where sr_items.item_id=cr_items.item_id - and sr_items.item_id=wr_items.item_id - order by sr_items.item_id - ,sr_item_qty - limit 100; - --- end template query83.tpl query 64 in stream 3 --- start template query1.tpl query 65 in stream 3 -with /* TPC-DS query1.tpl 0.12 */ customer_total_return as -(select sr_customer_sk as ctr_customer_sk -,sr_store_sk as ctr_store_sk -,sum(SR_FEE) as ctr_total_return -from store_returns -,date_dim -where sr_returned_date_sk = d_date_sk -and d_year =2000 -group by sr_customer_sk -,sr_store_sk) - select c_customer_id -from customer_total_return ctr1 -,store -,customer -where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 -from customer_total_return ctr2 -where ctr1.ctr_store_sk = ctr2.ctr_store_sk) -and s_store_sk = ctr1.ctr_store_sk -and s_state = 'VT' -and ctr1.ctr_customer_sk = c_customer_sk -order by c_customer_id -limit 100; - --- end template query1.tpl query 65 in stream 3 --- start template query60.tpl query 66 in stream 3 -with /* TPC-DS query60.tpl 0.29 */ ss as ( - select - i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Shoes')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 10 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -8 - group by i_item_id), - cs as ( - select - i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Shoes')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 10 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -8 - group by i_item_id), - ws as ( - select - i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Shoes')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 10 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -8 - group by i_item_id) - select - i_item_id -,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by i_item_id - ,total_sales - limit 100; - --- end template query60.tpl query 66 in stream 3 --- start template query33.tpl query 67 in stream 3 -with /* TPC-DS query33.tpl 0.22 */ ss as ( - select - i_manufact_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Jewelry')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 7 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id), - cs as ( - select - i_manufact_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Jewelry')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 7 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id), - ws as ( - select - i_manufact_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Jewelry')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 7 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id) - select i_manufact_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_manufact_id - order by total_sales -limit 100; - --- end template query33.tpl query 67 in stream 3 --- start template query11.tpl query 68 in stream 3 -with /* TPC-DS query11.tpl 0.51 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ss_ext_list_price-ss_ext_discount_amt) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ws_ext_list_price-ws_ext_discount_amt) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_birth_country - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 1999 - and t_s_secyear.dyear = 1999+1 - and t_w_firstyear.dyear = 1999 - and t_w_secyear.dyear = 1999+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else 0.0 end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else 0.0 end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_birth_country -limit 100; - --- end template query11.tpl query 68 in stream 3 --- start template query28.tpl query 69 in stream 3 -select /* TPC-DS query28.tpl 0.36 */ * -from (select avg(ss_list_price) B1_LP - ,count(ss_list_price) B1_CNT - ,count(distinct ss_list_price) B1_CNTD - from store_sales - where ss_quantity between 0 and 5 - and (ss_list_price between 84 and 84+10 - or ss_coupon_amt between 5544 and 5544+1000 - or ss_wholesale_cost between 14 and 14+20)) B1, - (select avg(ss_list_price) B2_LP - ,count(ss_list_price) B2_CNT - ,count(distinct ss_list_price) B2_CNTD - from store_sales - where ss_quantity between 6 and 10 - and (ss_list_price between 66 and 66+10 - or ss_coupon_amt between 12933 and 12933+1000 - or ss_wholesale_cost between 6 and 6+20)) B2, - (select avg(ss_list_price) B3_LP - ,count(ss_list_price) B3_CNT - ,count(distinct ss_list_price) B3_CNTD - from store_sales - where ss_quantity between 11 and 15 - and (ss_list_price between 170 and 170+10 - or ss_coupon_amt between 16576 and 16576+1000 - or ss_wholesale_cost between 2 and 2+20)) B3, - (select avg(ss_list_price) B4_LP - ,count(ss_list_price) B4_CNT - ,count(distinct ss_list_price) B4_CNTD - from store_sales - where ss_quantity between 16 and 20 - and (ss_list_price between 160 and 160+10 - or ss_coupon_amt between 787 and 787+1000 - or ss_wholesale_cost between 69 and 69+20)) B4, - (select avg(ss_list_price) B5_LP - ,count(ss_list_price) B5_CNT - ,count(distinct ss_list_price) B5_CNTD - from store_sales - where ss_quantity between 21 and 25 - and (ss_list_price between 45 and 45+10 - or ss_coupon_amt between 8822 and 8822+1000 - or ss_wholesale_cost between 50 and 50+20)) B5, - (select avg(ss_list_price) B6_LP - ,count(ss_list_price) B6_CNT - ,count(distinct ss_list_price) B6_CNTD - from store_sales - where ss_quantity between 26 and 30 - and (ss_list_price between 159 and 159+10 - or ss_coupon_amt between 11804 and 11804+1000 - or ss_wholesale_cost between 62 and 62+20)) B6 -limit 100; - --- end template query28.tpl query 69 in stream 3 --- start template query95.tpl query 70 in stream 3 -with /* TPC-DS query95.tpl 0.43 */ ws_wh as -(select ws1.ws_order_number,ws1.ws_warehouse_sk wh1,ws2.ws_warehouse_sk wh2 - from web_sales ws1,web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) - select - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2000-4-01' and - dateadd(day,60,cast('2000-4-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'MT' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and ws1.ws_order_number in (select ws_order_number - from ws_wh) -and ws1.ws_order_number in (select wr_order_number - from web_returns,ws_wh - where wr_order_number = ws_wh.ws_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query95.tpl query 70 in stream 3 --- start template query12.tpl query 71 in stream 3 -select /* TPC-DS query12.tpl 0.64 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ws_ext_sales_price) as itemrevenue - ,sum(ws_ext_sales_price)*100/sum(sum(ws_ext_sales_price)) over - (partition by i_class) as revenueratio -from - web_sales - ,item - ,date_dim -where - ws_item_sk = i_item_sk - and i_category in ('Men', 'Books', 'Women') - and ws_sold_date_sk = d_date_sk - and d_date between cast('1999-03-18' as date) - and dateadd(day,30,cast('1999-03-18' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query12.tpl query 71 in stream 3 --- start template query64.tpl query 72 in stream 3 -with /* TPC-DS query64.tpl 0.20 */ cs_ui as - (select cs_item_sk - ,sum(cs_ext_list_price) as sale,sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit) as refund - from catalog_sales - ,catalog_returns - where cs_item_sk = cr_item_sk - and cs_order_number = cr_order_number - group by cs_item_sk - having sum(cs_ext_list_price)>2*sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit)), -cross_sales as - (select i_product_name product_name - ,i_item_sk item_sk - ,s_store_name store_name - ,s_zip store_zip - ,ad1.ca_street_number b_street_number - ,ad1.ca_street_name b_street_name - ,ad1.ca_city b_city - ,ad1.ca_zip b_zip - ,ad2.ca_street_number c_street_number - ,ad2.ca_street_name c_street_name - ,ad2.ca_city c_city - ,ad2.ca_zip c_zip - ,d1.d_year as syear - ,d2.d_year as fsyear - ,d3.d_year s2year - ,count(*) cnt - ,sum(ss_wholesale_cost) s1 - ,sum(ss_list_price) s2 - ,sum(ss_coupon_amt) s3 - FROM store_sales - ,store_returns - ,cs_ui - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,customer - ,customer_demographics cd1 - ,customer_demographics cd2 - ,promotion - ,household_demographics hd1 - ,household_demographics hd2 - ,customer_address ad1 - ,customer_address ad2 - ,income_band ib1 - ,income_band ib2 - ,item - WHERE ss_store_sk = s_store_sk AND - ss_sold_date_sk = d1.d_date_sk AND - ss_customer_sk = c_customer_sk AND - ss_cdemo_sk= cd1.cd_demo_sk AND - ss_hdemo_sk = hd1.hd_demo_sk AND - ss_addr_sk = ad1.ca_address_sk and - ss_item_sk = i_item_sk and - ss_item_sk = sr_item_sk and - ss_ticket_number = sr_ticket_number and - ss_item_sk = cs_ui.cs_item_sk and - c_current_cdemo_sk = cd2.cd_demo_sk AND - c_current_hdemo_sk = hd2.hd_demo_sk AND - c_current_addr_sk = ad2.ca_address_sk and - c_first_sales_date_sk = d2.d_date_sk and - c_first_shipto_date_sk = d3.d_date_sk and - ss_promo_sk = p_promo_sk and - hd1.hd_income_band_sk = ib1.ib_income_band_sk and - hd2.hd_income_band_sk = ib2.ib_income_band_sk and - cd1.cd_marital_status <> cd2.cd_marital_status and - i_color in ('dim','brown','magenta','lavender','midnight','rosy') and - i_current_price between 18 and 18 + 10 and - i_current_price between 18 + 1 and 18 + 15 -group by i_product_name - ,i_item_sk - ,s_store_name - ,s_zip - ,ad1.ca_street_number - ,ad1.ca_street_name - ,ad1.ca_city - ,ad1.ca_zip - ,ad2.ca_street_number - ,ad2.ca_street_name - ,ad2.ca_city - ,ad2.ca_zip - ,d1.d_year - ,d2.d_year - ,d3.d_year -) -select cs1.product_name - ,cs1.store_name - ,cs1.store_zip - ,cs1.b_street_number - ,cs1.b_street_name - ,cs1.b_city - ,cs1.b_zip - ,cs1.c_street_number - ,cs1.c_street_name - ,cs1.c_city - ,cs1.c_zip - ,cs1.syear - ,cs1.cnt - ,cs1.s1 as s11 - ,cs1.s2 as s21 - ,cs1.s3 as s31 - ,cs2.s1 as s12 - ,cs2.s2 as s22 - ,cs2.s3 as s32 - ,cs2.syear - ,cs2.cnt -from cross_sales cs1,cross_sales cs2 -where cs1.item_sk=cs2.item_sk and - cs1.syear = 2001 and - cs2.syear = 2001 + 1 and - cs2.cnt <= cs1.cnt and - cs1.store_name = cs2.store_name and - cs1.store_zip = cs2.store_zip -order by cs1.product_name - ,cs1.store_name - ,cs2.cnt - ,cs1.s1 - ,cs2.s1; - --- end template query64.tpl query 72 in stream 3 --- start template query15.tpl query 73 in stream 3 -select /* TPC-DS query15.tpl 0.57 */ ca_zip - ,sum(cs_sales_price) - from catalog_sales - ,customer - ,customer_address - ,date_dim - where cs_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', - '85392', '85460', '80348', '81792') - or ca_state in ('CA','WA','GA') - or cs_sales_price > 500) - and cs_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 2001 - group by ca_zip - order by ca_zip - limit 100; - --- end template query15.tpl query 73 in stream 3 --- start template query25.tpl query 74 in stream 3 -select /* TPC-DS query25.tpl 0.9 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,avg(ss_net_profit) as store_sales_profit - ,avg(sr_net_loss) as store_returns_loss - ,avg(cs_net_profit) as catalog_sales_profit - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 1999 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 10 - and d2.d_year = 1999 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_moy between 4 and 10 - and d3.d_year = 1999 - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query25.tpl query 74 in stream 3 --- start template query93.tpl query 75 in stream 3 -select /* TPC-DS query93.tpl 0.52 */ ss_customer_sk - ,sum(act_sales) sumsales - from (select ss_item_sk - ,ss_ticket_number - ,ss_customer_sk - ,case when sr_return_quantity is not null then (ss_quantity-sr_return_quantity)*ss_sales_price - else (ss_quantity*ss_sales_price) end act_sales - from store_sales left outer join store_returns on (sr_item_sk = ss_item_sk - and sr_ticket_number = ss_ticket_number) - ,reason - where sr_reason_sk = r_reason_sk - and r_reason_desc = 'reason 66') t - group by ss_customer_sk - order by sumsales, ss_customer_sk -limit 100; - --- end template query93.tpl query 75 in stream 3 --- start template query9.tpl query 76 in stream 3 -select /* TPC-DS query9.tpl 0.49 */ case when (select count(*) - from store_sales - where ss_quantity between 1 and 20) > 78028047 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 1 and 20) - else (select avg(ss_net_profit) - from store_sales - where ss_quantity between 1 and 20) end bucket1 , - case when (select count(*) - from store_sales - where ss_quantity between 21 and 40) > 50389503 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 21 and 40) - else (select avg(ss_net_profit) - from store_sales - where ss_quantity between 21 and 40) end bucket2, - case when (select count(*) - from store_sales - where ss_quantity between 41 and 60) > 79367181 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 41 and 60) - else (select avg(ss_net_profit) - from store_sales - where ss_quantity between 41 and 60) end bucket3, - case when (select count(*) - from store_sales - where ss_quantity between 61 and 80) > 119906456 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 61 and 80) - else (select avg(ss_net_profit) - from store_sales - where ss_quantity between 61 and 80) end bucket4, - case when (select count(*) - from store_sales - where ss_quantity between 81 and 100) > 128467526 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 81 and 100) - else (select avg(ss_net_profit) - from store_sales - where ss_quantity between 81 and 100) end bucket5 -from reason -where r_reason_sk = 1 -; - --- end template query9.tpl query 76 in stream 3 --- start template query65.tpl query 77 in stream 3 -select /* TPC-DS query65.tpl 0.71 */ - s_store_name, - i_item_desc, - sc.revenue, - i_current_price, - i_wholesale_cost, - i_brand - from store, item, - (select ss_store_sk, avg(revenue) as ave - from - (select ss_store_sk, ss_item_sk, - sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1209 and 1209+11 - group by ss_store_sk, ss_item_sk) sa - group by ss_store_sk) sb, - (select ss_store_sk, ss_item_sk, sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1209 and 1209+11 - group by ss_store_sk, ss_item_sk) sc - where sb.ss_store_sk = sc.ss_store_sk and - sc.revenue <= 0.1 * sb.ave and - s_store_sk = sc.ss_store_sk and - i_item_sk = sc.ss_item_sk - order by s_store_name, i_item_desc -limit 100; - --- end template query65.tpl query 77 in stream 3 --- start template query71.tpl query 78 in stream 3 -select /* TPC-DS query71.tpl 0.72 */ i_brand_id brand_id, i_brand brand,t_hour,t_minute, - sum(ext_price) ext_price - from item, (select ws_ext_sales_price as ext_price, - ws_sold_date_sk as sold_date_sk, - ws_item_sk as sold_item_sk, - ws_sold_time_sk as time_sk - from web_sales,date_dim - where d_date_sk = ws_sold_date_sk - and d_moy=11 - and d_year=1999 - union all - select cs_ext_sales_price as ext_price, - cs_sold_date_sk as sold_date_sk, - cs_item_sk as sold_item_sk, - cs_sold_time_sk as time_sk - from catalog_sales,date_dim - where d_date_sk = cs_sold_date_sk - and d_moy=11 - and d_year=1999 - union all - select ss_ext_sales_price as ext_price, - ss_sold_date_sk as sold_date_sk, - ss_item_sk as sold_item_sk, - ss_sold_time_sk as time_sk - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - and d_moy=11 - and d_year=1999 - ) tmp,time_dim - where - sold_item_sk = i_item_sk - and i_manager_id=1 - and time_sk = t_time_sk - and (t_meal_time = 'breakfast' or t_meal_time = 'dinner') - group by i_brand, i_brand_id,t_hour,t_minute - order by ext_price desc, i_brand_id - ; - --- end template query71.tpl query 78 in stream 3 --- start template query57.tpl query 79 in stream 3 -with /* TPC-DS query57.tpl 0.70 */ v1 as( - select i_category, i_brand, - cc_name, - d_year, d_moy, - sum(cs_sales_price) sum_sales, - avg(sum(cs_sales_price)) over - (partition by i_category, i_brand, - cc_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - cc_name - order by d_year, d_moy) rn - from item, catalog_sales, date_dim, call_center - where cs_item_sk = i_item_sk and - cs_sold_date_sk = d_date_sk and - cc_call_center_sk= cs_call_center_sk and - ( - d_year = 1999 or - ( d_year = 1999-1 and d_moy =12) or - ( d_year = 1999+1 and d_moy =1) - ) - group by i_category, i_brand, - cc_name , d_year, d_moy), - v2 as( - select v1.i_category, v1.i_brand - ,v1.d_year, v1.d_moy - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1. cc_name = v1_lag. cc_name and - v1. cc_name = v1_lead. cc_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 1999 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, sum_sales - limit 100; - --- end template query57.tpl query 79 in stream 3 --- start template query32.tpl query 80 in stream 3 -select /* TPC-DS query32.tpl 0.7 */ sum(cs_ext_discount_amt) as "excess discount amount" -from - catalog_sales - ,item - ,date_dim -where -i_manufact_id = 369 -and i_item_sk = cs_item_sk -and d_date between '1998-03-10' and - dateadd(day,90,cast('1998-03-10' as date)) -and d_date_sk = cs_sold_date_sk -and cs_ext_discount_amt - > ( - select - 1.3 * avg(cs_ext_discount_amt) - from - catalog_sales - ,date_dim - where - cs_item_sk = i_item_sk - and d_date between '1998-03-10' and - dateadd(day,90,cast('1998-03-10' as date)) - and d_date_sk = cs_sold_date_sk - ) -limit 100; - --- end template query32.tpl query 80 in stream 3 --- start template query61.tpl query 81 in stream 3 -select /* TPC-DS query61.tpl 0.97 */ promotions,total,cast(promotions as decimal(15,4))/cast(total as decimal(15,4))*100 -from - (select sum(ss_ext_sales_price) promotions - from store_sales - ,store - ,promotion - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_promo_sk = p_promo_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -6 - and i_category = 'Books' - and (p_channel_dmail = 'Y' or p_channel_email = 'Y' or p_channel_tv = 'Y') - and s_gmt_offset = -6 - and d_year = 2002 - and d_moy = 12) promotional_sales, - (select sum(ss_ext_sales_price) total - from store_sales - ,store - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -6 - and i_category = 'Books' - and s_gmt_offset = -6 - and d_year = 2002 - and d_moy = 12) all_sales -order by promotions, total -limit 100; - --- end template query61.tpl query 81 in stream 3 --- start template query85.tpl query 82 in stream 3 -select /* TPC-DS query85.tpl 0.33 */ substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) - from web_sales, web_returns, web_page, customer_demographics cd1, - customer_demographics cd2, customer_address, date_dim, reason - where ws_web_page_sk = wp_web_page_sk - and ws_item_sk = wr_item_sk - and ws_order_number = wr_order_number - and ws_sold_date_sk = d_date_sk and d_year = 1999 - and cd1.cd_demo_sk = wr_refunded_cdemo_sk - and cd2.cd_demo_sk = wr_returning_cdemo_sk - and ca_address_sk = wr_refunded_addr_sk - and r_reason_sk = wr_reason_sk - and - ( - ( - cd1.cd_marital_status = 'U' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Primary' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 100.00 and 150.00 - ) - or - ( - cd1.cd_marital_status = 'W' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'College' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 50.00 and 100.00 - ) - or - ( - cd1.cd_marital_status = 'D' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = '2 yr Degree' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ca_country = 'United States' - and - ca_state in ('OK', 'OH', 'IN') - and ws_net_profit between 100 and 200 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('SD', 'MI', 'MO') - and ws_net_profit between 150 and 300 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('GA', 'VA', 'CO') - and ws_net_profit between 50 and 250 - ) - ) -group by r_reason_desc -order by substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) -limit 100; - --- end template query85.tpl query 82 in stream 3 --- start template query73.tpl query 83 in stream 3 -select /* TPC-DS query73.tpl 0.79 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_buy_potential = '1001-5000' or - household_demographics.hd_buy_potential = '5001-10000') - and household_demographics.hd_vehicle_count > 0 - and case when household_demographics.hd_vehicle_count > 0 then - household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count else null end > 1 - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_county in ('Anderson County','Huron County','Arthur County','Luce County') - group by ss_ticket_number,ss_customer_sk) dj,customer - where ss_customer_sk = c_customer_sk - and cnt between 1 and 5 - order by cnt desc, c_last_name asc; - --- end template query73.tpl query 83 in stream 3 --- start template query98.tpl query 84 in stream 3 -select /* TPC-DS query98.tpl 0.32 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ss_ext_sales_price) as itemrevenue - ,sum(ss_ext_sales_price)*100/sum(sum(ss_ext_sales_price)) over - (partition by i_class) as revenueratio -from - store_sales - ,item - ,date_dim -where - ss_item_sk = i_item_sk - and i_category in ('Sports', 'Music', 'Electronics') - and ss_sold_date_sk = d_date_sk - and d_date between cast('1999-06-22' as date) - and dateadd(day,30,cast('1999-06-22' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio; - --- end template query98.tpl query 84 in stream 3 --- start template query77a.tpl query 85 in stream 3 -with /* TPC-DS query77a.tpl 0.78 */ ss as - (select s_store_sk, - sum(ss_ext_sales_price) as sales, - sum(ss_net_profit) as profit - from store_sales, - date_dim, - store - where ss_sold_date_sk = d_date_sk - and d_date between cast('1999-08-13' as date) - and dateadd(day,30,cast('1999-08-13' as date)) - and ss_store_sk = s_store_sk - group by s_store_sk) - , - sr as - (select s_store_sk, - sum(sr_return_amt) as returns, - sum(sr_net_loss) as profit_loss - from store_returns, - date_dim, - store - where sr_returned_date_sk = d_date_sk - and d_date between cast('1999-08-13' as date) - and dateadd(day,30,cast('1999-08-13' as date)) - and sr_store_sk = s_store_sk - group by s_store_sk), - cs as - (select cs_call_center_sk, - sum(cs_ext_sales_price) as sales, - sum(cs_net_profit) as profit - from catalog_sales, - date_dim - where cs_sold_date_sk = d_date_sk - and d_date between cast('1999-08-13' as date) - and dateadd(day,30,cast('1999-08-13' as date)) - group by cs_call_center_sk - ), - cr as - (select cr_call_center_sk, - sum(cr_return_amount) as returns, - sum(cr_net_loss) as profit_loss - from catalog_returns, - date_dim - where cr_returned_date_sk = d_date_sk - and d_date between cast('1999-08-13' as date) - and dateadd(day,30,cast('1999-08-13' as date)) - group by cr_call_center_sk), - ws as - ( select wp_web_page_sk, - sum(ws_ext_sales_price) as sales, - sum(ws_net_profit) as profit - from web_sales, - date_dim, - web_page - where ws_sold_date_sk = d_date_sk - and d_date between cast('1999-08-13' as date) - and dateadd(day,30,cast('1999-08-13' as date)) - and ws_web_page_sk = wp_web_page_sk - group by wp_web_page_sk), - wr as - (select wp_web_page_sk, - sum(wr_return_amt) as returns, - sum(wr_net_loss) as profit_loss - from web_returns, - date_dim, - web_page - where wr_returned_date_sk = d_date_sk - and d_date between cast('1999-08-13' as date) - and dateadd(day,30,cast('1999-08-13' as date)) - and wr_web_page_sk = wp_web_page_sk - group by wp_web_page_sk) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , ss.s_store_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ss left join sr - on ss.s_store_sk = sr.s_store_sk - union all - select 'catalog channel' as channel - , cs_call_center_sk as id - , sales - , returns - , (profit - profit_loss) as profit - from cs - , cr - union all - select 'web channel' as channel - , ws.wp_web_page_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ws left join wr - on ws.wp_web_page_sk = wr.wp_web_page_sk - ) x - group by channel, id ) - - select * - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results -) foo -order by channel, id - limit 100; - --- end template query77a.tpl query 85 in stream 3 --- start template query45.tpl query 86 in stream 3 -select /* TPC-DS query45.tpl 0.18 */ ca_zip, ca_county, sum(ws_sales_price) - from web_sales, customer, customer_address, date_dim, item - where ws_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ws_item_sk = i_item_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', '85392', '85460', '80348', '81792') - or - i_item_id in (select i_item_id - from item - where i_item_sk in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29) - ) - ) - and ws_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 2001 - group by ca_zip, ca_county - order by ca_zip, ca_county - limit 100; - --- end template query45.tpl query 86 in stream 3 --- start template query20.tpl query 87 in stream 3 -select /* TPC-DS query20.tpl 0.65 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(cs_ext_sales_price) as itemrevenue - ,sum(cs_ext_sales_price)*100/sum(sum(cs_ext_sales_price)) over - (partition by i_class) as revenueratio - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and i_category in ('Electronics', 'Music', 'Women') - and cs_sold_date_sk = d_date_sk - and d_date between cast('1999-01-30' as date) - and dateadd(day,30,cast('1999-01-30' as date)) - group by i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - order by i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query20.tpl query 87 in stream 3 --- start template query50.tpl query 88 in stream 3 -select /* TPC-DS query50.tpl 0.60 */ - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 30) and - (sr_returned_date_sk - ss_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 60) and - (sr_returned_date_sk - ss_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 90) and - (sr_returned_date_sk - ss_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - store_sales - ,store_returns - ,store - ,date_dim d1 - ,date_dim d2 -where - d2.d_year = 1998 -and d2.d_moy = 9 -and ss_ticket_number = sr_ticket_number -and ss_item_sk = sr_item_sk -and ss_sold_date_sk = d1.d_date_sk -and sr_returned_date_sk = d2.d_date_sk -and ss_customer_sk = sr_customer_sk -and ss_store_sk = s_store_sk -group by - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -order by s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -limit 100; - --- end template query50.tpl query 88 in stream 3 --- start template query70a.tpl query 89 in stream 3 -with /* TPC-DS query70a.tpl 0.34 */ results as -( select - sum(ss_net_profit) as total_sum ,s_state ,s_county, 0 as gstate, 0 as g_county - from - store_sales - ,date_dim d1 - ,store - where - d1.d_month_seq between 1210 and 1210 + 11 - and d1.d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - and s_state in - ( select s_state - from (select s_state as s_state, - rank() over ( partition by s_state order by sum(ss_net_profit) desc) as ranking - from store_sales, store, date_dim - where d_month_seq between 1210 and 1210 + 11 - and d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - group by s_state - ) tmp1 - where ranking <= 5) - group by s_state,s_county) , - results_rollup as -(select total_sum ,s_state ,s_county, 0 as g_state, 0 as g_county, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum,s_state, NULL as s_county, 0 as g_state, 1 as g_county, 1 as lochierarchy from results group by s_state - union - select sum(total_sum) as total_sum ,NULL as s_state ,NULL as s_county, 1 as g_state, 1 as g_county, 2 as lochierarchy from results) - select total_sum ,s_state ,s_county, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_county = 0 then s_state end - order by total_sum desc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then s_state end - ,rank_within_parent - limit 100; - --- end template query70a.tpl query 89 in stream 3 --- start template query75.tpl query 90 in stream 3 -WITH /* TPC-DS query75.tpl 0.3 */ all_sales AS ( - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,SUM(sales_cnt) AS sales_cnt - ,SUM(sales_amt) AS sales_amt - FROM (SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,cs_quantity - COALESCE(cr_return_quantity,0) AS sales_cnt - ,cs_ext_sales_price - COALESCE(cr_return_amount,0.0) AS sales_amt - FROM catalog_sales JOIN item ON i_item_sk=cs_item_sk - JOIN date_dim ON d_date_sk=cs_sold_date_sk - LEFT JOIN catalog_returns ON (cs_order_number=cr_order_number - AND cs_item_sk=cr_item_sk) - WHERE i_category='Electronics' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ss_quantity - COALESCE(sr_return_quantity,0) AS sales_cnt - ,ss_ext_sales_price - COALESCE(sr_return_amt,0.0) AS sales_amt - FROM store_sales JOIN item ON i_item_sk=ss_item_sk - JOIN date_dim ON d_date_sk=ss_sold_date_sk - LEFT JOIN store_returns ON (ss_ticket_number=sr_ticket_number - AND ss_item_sk=sr_item_sk) - WHERE i_category='Electronics' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ws_quantity - COALESCE(wr_return_quantity,0) AS sales_cnt - ,ws_ext_sales_price - COALESCE(wr_return_amt,0.0) AS sales_amt - FROM web_sales JOIN item ON i_item_sk=ws_item_sk - JOIN date_dim ON d_date_sk=ws_sold_date_sk - LEFT JOIN web_returns ON (ws_order_number=wr_order_number - AND ws_item_sk=wr_item_sk) - WHERE i_category='Electronics') sales_detail - GROUP BY d_year, i_brand_id, i_class_id, i_category_id, i_manufact_id) - SELECT prev_yr.d_year AS prev_year - ,curr_yr.d_year AS year - ,curr_yr.i_brand_id - ,curr_yr.i_class_id - ,curr_yr.i_category_id - ,curr_yr.i_manufact_id - ,prev_yr.sales_cnt AS prev_yr_cnt - ,curr_yr.sales_cnt AS curr_yr_cnt - ,curr_yr.sales_cnt-prev_yr.sales_cnt AS sales_cnt_diff - ,curr_yr.sales_amt-prev_yr.sales_amt AS sales_amt_diff - FROM all_sales curr_yr, all_sales prev_yr - WHERE curr_yr.i_brand_id=prev_yr.i_brand_id - AND curr_yr.i_class_id=prev_yr.i_class_id - AND curr_yr.i_category_id=prev_yr.i_category_id - AND curr_yr.i_manufact_id=prev_yr.i_manufact_id - AND curr_yr.d_year=2001 - AND prev_yr.d_year=2001-1 - AND CAST(curr_yr.sales_cnt AS DECIMAL(17,2))/CAST(prev_yr.sales_cnt AS DECIMAL(17,2))<0.9 - ORDER BY sales_cnt_diff,sales_amt_diff - limit 100; - --- end template query75.tpl query 90 in stream 3 --- start template query91.tpl query 91 in stream 3 -select /* TPC-DS query91.tpl 0.13 */ - cc_call_center_id Call_Center, - cc_name Call_Center_Name, - cc_manager Manager, - sum(cr_net_loss) Returns_Loss -from - call_center, - catalog_returns, - date_dim, - customer, - customer_address, - customer_demographics, - household_demographics -where - cr_call_center_sk = cc_call_center_sk -and cr_returned_date_sk = d_date_sk -and cr_returning_customer_sk= c_customer_sk -and cd_demo_sk = c_current_cdemo_sk -and hd_demo_sk = c_current_hdemo_sk -and ca_address_sk = c_current_addr_sk -and d_year = 1999 -and d_moy = 11 -and ( (cd_marital_status = 'M' and cd_education_status = 'Unknown') - or(cd_marital_status = 'W' and cd_education_status = 'Advanced Degree')) -and hd_buy_potential like '1001-5000%' -and ca_gmt_offset = -6 -group by cc_call_center_id,cc_name,cc_manager,cd_marital_status,cd_education_status -order by sum(cr_net_loss) desc; - --- end template query91.tpl query 91 in stream 3 --- start template query17.tpl query 92 in stream 3 -select /* TPC-DS query17.tpl 0.41 */ i_item_id - ,i_item_desc - ,s_state - ,count(ss_quantity) as store_sales_quantitycount - ,avg(ss_quantity) as store_sales_quantityave - ,stddev_samp(ss_quantity) as store_sales_quantitystdev - ,stddev_samp(ss_quantity)/avg(ss_quantity) as store_sales_quantitycov - ,count(sr_return_quantity) as store_returns_quantitycount - ,avg(sr_return_quantity) as store_returns_quantityave - ,stddev_samp(sr_return_quantity) as store_returns_quantitystdev - ,stddev_samp(sr_return_quantity)/avg(sr_return_quantity) as store_returns_quantitycov - ,count(cs_quantity) as catalog_sales_quantitycount ,avg(cs_quantity) as catalog_sales_quantityave - ,stddev_samp(cs_quantity) as catalog_sales_quantitystdev - ,stddev_samp(cs_quantity)/avg(cs_quantity) as catalog_sales_quantitycov - from store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where d1.d_quarter_name = '2001Q1' - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_quarter_name in ('2001Q1','2001Q2','2001Q3') - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_quarter_name in ('2001Q1','2001Q2','2001Q3') - group by i_item_id - ,i_item_desc - ,s_state - order by i_item_id - ,i_item_desc - ,s_state -limit 100; - --- end template query17.tpl query 92 in stream 3 --- start template query24.tpl query 93 in stream 3 -with /* TPC-DS query24.tpl 0.92 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_sales_price) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip -and s_market_id=8 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'navajo' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; -with /* TPC-DS query24.tpl 0.92 part2 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_sales_price) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip - and s_market_id = 8 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'bisque' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; - --- end template query24.tpl query 93 in stream 3 --- start template query48.tpl query 94 in stream 3 -select /* TPC-DS query48.tpl 0.74 */ sum (ss_quantity) - from store_sales, store, customer_demographics, customer_address, date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2001 - and - ( - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'U' - and - cd_education_status = '2 yr Degree' - and - ss_sales_price between 100.00 and 150.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'D' - and - cd_education_status = 'Primary' - and - ss_sales_price between 50.00 and 100.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'S' - and - cd_education_status = 'Advanced Degree' - and - ss_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('TX', 'IA', 'ID') - and ss_net_profit between 0 and 2000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('NY', 'MA', 'GA') - and ss_net_profit between 150 and 3000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('IN', 'AK', 'MS') - and ss_net_profit between 50 and 25000 - ) - ) -; - --- end template query48.tpl query 94 in stream 3 --- start template query51.tpl query 95 in stream 3 -WITH /* TPC-DS query51.tpl 0.46 */ web_v1 as ( -select - ws_item_sk item_sk, d_date, - sum(sum(ws_sales_price)) - over (partition by ws_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from web_sales - ,date_dim -where ws_sold_date_sk=d_date_sk - and d_month_seq between 1205 and 1205+11 - and ws_item_sk is not NULL -group by ws_item_sk, d_date), -store_v1 as ( -select - ss_item_sk item_sk, d_date, - sum(sum(ss_sales_price)) - over (partition by ss_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from store_sales - ,date_dim -where ss_sold_date_sk=d_date_sk - and d_month_seq between 1205 and 1205+11 - and ss_item_sk is not NULL -group by ss_item_sk, d_date) - select * -from (select item_sk - ,d_date - ,web_sales - ,store_sales - ,max(web_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) web_cumulative - ,max(store_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) store_cumulative - from (select case when web.item_sk is not null then web.item_sk else store.item_sk end item_sk - ,case when web.d_date is not null then web.d_date else store.d_date end d_date - ,web.cume_sales web_sales - ,store.cume_sales store_sales - from web_v1 web full outer join store_v1 store on (web.item_sk = store.item_sk - and web.d_date = store.d_date) - )x )y -where web_cumulative > store_cumulative -order by item_sk - ,d_date -limit 100; - --- end template query51.tpl query 95 in stream 3 --- start template query79.tpl query 96 in stream 3 -select /* TPC-DS query79.tpl 0.89 */ - c_last_name,c_first_name,substring(s_city,1,30),ss_ticket_number,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,store.s_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (household_demographics.hd_dep_count = 2 or household_demographics.hd_vehicle_count > -1) - and date_dim.d_dow = 1 - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_number_employees between 200 and 295 - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,store.s_city) ms,customer - where ss_customer_sk = c_customer_sk - order by c_last_name,c_first_name,substring(s_city,1,30), profit -limit 100; - --- end template query79.tpl query 96 in stream 3 --- start template query35a.tpl query 97 in stream 3 -select /* TPC-DS query35a.tpl 0.47 */ - ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - count(*) cnt1, - stddev_samp(cd_dep_count), - max(cd_dep_count), - avg(cd_dep_count), - cd_dep_employed_count, - count(*) cnt2, - stddev_samp(cd_dep_employed_count), - max(cd_dep_employed_count), - avg(cd_dep_employed_count), - cd_dep_college_count, - count(*) cnt3, - stddev_samp(cd_dep_college_count), - max(cd_dep_college_count), - avg(cd_dep_college_count) - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2000 and - d_qoy < 4) and - exists (select * from - (select ws_bill_customer_sk customsk - from web_sales,date_dim - where - ws_sold_date_sk = d_date_sk and - d_year = 2000 and - d_qoy < 4 - union all - select cs_ship_customer_sk customsk - from catalog_sales,date_dim - where - cs_sold_date_sk = d_date_sk and - d_year = 2000 and - d_qoy < 4)x - where x.customsk = c.c_customer_sk) - group by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - limit 100; - --- end template query35a.tpl query 97 in stream 3 --- start template query88.tpl query 98 in stream 3 -select /* TPC-DS query88.tpl 0.66 */ * -from - (select count(*) h8_30_to_9 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s1, - (select count(*) h9_to_9_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s2, - (select count(*) h9_30_to_10 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s3, - (select count(*) h10_to_10_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s4, - (select count(*) h10_30_to_11 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s5, - (select count(*) h11_to_11_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s6, - (select count(*) h11_30_to_12 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s7, - (select count(*) h12_to_12_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 12 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s8 -; - --- end template query88.tpl query 98 in stream 3 --- start template query49.tpl query 99 in stream 3 -select /* TPC-DS query49.tpl 0.48 */ channel, item, return_ratio, return_rank, currency_rank from - (select - 'web' as channel - ,web.item - ,web.return_ratio - ,web.return_rank - ,web.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select ws.ws_item_sk as item - ,(cast(sum(coalesce(wr.wr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(wr.wr_return_amt,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - web_sales ws left outer join web_returns wr - on (ws.ws_order_number = wr.wr_order_number and - ws.ws_item_sk = wr.wr_item_sk) - ,date_dim - where - wr.wr_return_amt > 10000 - and ws.ws_net_profit > 1 - and ws.ws_net_paid > 0 - and ws.ws_quantity > 0 - and ws_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 11 - group by ws.ws_item_sk - ) in_web - ) web - where - ( - web.return_rank <= 10 - or - web.currency_rank <= 10 - ) - union - select - 'catalog' as channel - ,catalog.item - ,catalog.return_ratio - ,catalog.return_rank - ,catalog.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select - cs.cs_item_sk as item - ,(cast(sum(coalesce(cr.cr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(cr.cr_return_amount,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - catalog_sales cs left outer join catalog_returns cr - on (cs.cs_order_number = cr.cr_order_number and - cs.cs_item_sk = cr.cr_item_sk) - ,date_dim - where - cr.cr_return_amount > 10000 - and cs.cs_net_profit > 1 - and cs.cs_net_paid > 0 - and cs.cs_quantity > 0 - and cs_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 11 - group by cs.cs_item_sk - ) in_cat - ) catalog - where - ( - catalog.return_rank <= 10 - or - catalog.currency_rank <=10 - ) - union - select - 'store' as channel - ,store.item - ,store.return_ratio - ,store.return_rank - ,store.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select sts.ss_item_sk as item - ,(cast(sum(coalesce(sr.sr_return_quantity,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(sr.sr_return_amt,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - store_sales sts left outer join store_returns sr - on (sts.ss_ticket_number = sr.sr_ticket_number and sts.ss_item_sk = sr.sr_item_sk) - ,date_dim - where - sr.sr_return_amt > 10000 - and sts.ss_net_profit > 1 - and sts.ss_net_paid > 0 - and sts.ss_quantity > 0 - and ss_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 11 - group by sts.ss_item_sk - ) in_store - ) store - where ( - store.return_rank <= 10 - or - store.currency_rank <= 10 - ) - ) - order by 1,4,5,2 - limit 100; - --- end template query49.tpl query 99 in stream 3 diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/3TB/queries/query_4.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/3TB/queries/query_4.sql deleted file mode 100644 index 9eb02e79..00000000 --- a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/3TB/queries/query_4.sql +++ /dev/null @@ -1,5027 +0,0 @@ --- start template query79.tpl query 1 in stream 4 -select /* TPC-DS query79.tpl 0.89 */ - c_last_name,c_first_name,substring(s_city,1,30),ss_ticket_number,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,store.s_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (household_demographics.hd_dep_count = 5 or household_demographics.hd_vehicle_count > 3) - and date_dim.d_dow = 1 - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_number_employees between 200 and 295 - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,store.s_city) ms,customer - where ss_customer_sk = c_customer_sk - order by c_last_name,c_first_name,substring(s_city,1,30), profit -limit 100; - --- end template query79.tpl query 1 in stream 4 --- start template query39.tpl query 2 in stream 4 -with /* TPC-DS query39.tpl 0.5 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =1998 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=1 - and inv2.d_moy=1+1 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; -with /* TPC-DS query39.tpl 0.5 part2 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =1998 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=1 - and inv2.d_moy=1+1 - and inv1.cov > 1.5 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; - --- end template query39.tpl query 2 in stream 4 --- start template query93.tpl query 3 in stream 4 -select /* TPC-DS query93.tpl 0.52 */ ss_customer_sk - ,sum(act_sales) sumsales - from (select ss_item_sk - ,ss_ticket_number - ,ss_customer_sk - ,case when sr_return_quantity is not null then (ss_quantity-sr_return_quantity)*ss_sales_price - else (ss_quantity*ss_sales_price) end act_sales - from store_sales left outer join store_returns on (sr_item_sk = ss_item_sk - and sr_ticket_number = ss_ticket_number) - ,reason - where sr_reason_sk = r_reason_sk - and r_reason_desc = 'reason 40') t - group by ss_customer_sk - order by sumsales, ss_customer_sk -limit 100; - --- end template query93.tpl query 3 in stream 4 --- start template query41.tpl query 4 in stream 4 -select /* TPC-DS query41.tpl 0.62 */ distinct(i_product_name) - from item i1 - where i_manufact_id between 989 and 989+40 - and (select count(*) as item_cnt - from item - where (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'blush' or i_color = 'brown') and - (i_units = 'Ton' or i_units = 'Dram') and - (i_size = 'small' or i_size = 'economy') - ) or - (i_category = 'Women' and - (i_color = 'smoke' or i_color = 'bisque') and - (i_units = 'Box' or i_units = 'Tsp') and - (i_size = 'N/A' or i_size = 'extra large') - ) or - (i_category = 'Men' and - (i_color = 'almond' or i_color = 'beige') and - (i_units = 'Dozen' or i_units = 'Gross') and - (i_size = 'large' or i_size = 'medium') - ) or - (i_category = 'Men' and - (i_color = 'chiffon' or i_color = 'rose') and - (i_units = 'N/A' or i_units = 'Gram') and - (i_size = 'small' or i_size = 'economy') - ))) or - (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'lace' or i_color = 'honeydew') and - (i_units = 'Carton' or i_units = 'Bunch') and - (i_size = 'small' or i_size = 'economy') - ) or - (i_category = 'Women' and - (i_color = 'saddle' or i_color = 'goldenrod') and - (i_units = 'Case' or i_units = 'Pound') and - (i_size = 'N/A' or i_size = 'extra large') - ) or - (i_category = 'Men' and - (i_color = 'midnight' or i_color = 'ivory') and - (i_units = 'Ounce' or i_units = 'Bundle') and - (i_size = 'large' or i_size = 'medium') - ) or - (i_category = 'Men' and - (i_color = 'snow' or i_color = 'sienna') and - (i_units = 'Oz' or i_units = 'Lb') and - (i_size = 'small' or i_size = 'economy') - )))) > 0 - order by i_product_name - limit 100; - --- end template query41.tpl query 4 in stream 4 --- start template query29.tpl query 5 in stream 4 -select /* TPC-DS query29.tpl 0.53 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,avg(ss_quantity) as store_sales_quantity - ,avg(sr_return_quantity) as store_returns_quantity - ,avg(cs_quantity) as catalog_sales_quantity - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 2000 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 4 + 3 - and d2.d_year = 2000 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_year in (2000,2000+1,2000+2) - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query29.tpl query 5 in stream 4 --- start template query32.tpl query 6 in stream 4 -select /* TPC-DS query32.tpl 0.7 */ sum(cs_ext_discount_amt) as "excess discount amount" -from - catalog_sales - ,item - ,date_dim -where -i_manufact_id = 48 -and i_item_sk = cs_item_sk -and d_date between '2001-01-18' and - dateadd(day,90,cast('2001-01-18' as date)) -and d_date_sk = cs_sold_date_sk -and cs_ext_discount_amt - > ( - select - 1.3 * avg(cs_ext_discount_amt) - from - catalog_sales - ,date_dim - where - cs_item_sk = i_item_sk - and d_date between '2001-01-18' and - dateadd(day,90,cast('2001-01-18' as date)) - and d_date_sk = cs_sold_date_sk - ) -limit 100; - --- end template query32.tpl query 6 in stream 4 --- start template query66.tpl query 7 in stream 4 -select /* TPC-DS query66.tpl 0.39 */ - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - ,sum(jan_sales) as jan_sales - ,sum(feb_sales) as feb_sales - ,sum(mar_sales) as mar_sales - ,sum(apr_sales) as apr_sales - ,sum(may_sales) as may_sales - ,sum(jun_sales) as jun_sales - ,sum(jul_sales) as jul_sales - ,sum(aug_sales) as aug_sales - ,sum(sep_sales) as sep_sales - ,sum(oct_sales) as oct_sales - ,sum(nov_sales) as nov_sales - ,sum(dec_sales) as dec_sales - ,sum(jan_sales/w_warehouse_sq_ft) as jan_sales_per_sq_foot - ,sum(feb_sales/w_warehouse_sq_ft) as feb_sales_per_sq_foot - ,sum(mar_sales/w_warehouse_sq_ft) as mar_sales_per_sq_foot - ,sum(apr_sales/w_warehouse_sq_ft) as apr_sales_per_sq_foot - ,sum(may_sales/w_warehouse_sq_ft) as may_sales_per_sq_foot - ,sum(jun_sales/w_warehouse_sq_ft) as jun_sales_per_sq_foot - ,sum(jul_sales/w_warehouse_sq_ft) as jul_sales_per_sq_foot - ,sum(aug_sales/w_warehouse_sq_ft) as aug_sales_per_sq_foot - ,sum(sep_sales/w_warehouse_sq_ft) as sep_sales_per_sq_foot - ,sum(oct_sales/w_warehouse_sq_ft) as oct_sales_per_sq_foot - ,sum(nov_sales/w_warehouse_sq_ft) as nov_sales_per_sq_foot - ,sum(dec_sales/w_warehouse_sq_ft) as dec_sales_per_sq_foot - ,sum(jan_net) as jan_net - ,sum(feb_net) as feb_net - ,sum(mar_net) as mar_net - ,sum(apr_net) as apr_net - ,sum(may_net) as may_net - ,sum(jun_net) as jun_net - ,sum(jul_net) as jul_net - ,sum(aug_net) as aug_net - ,sum(sep_net) as sep_net - ,sum(oct_net) as oct_net - ,sum(nov_net) as nov_net - ,sum(dec_net) as dec_net - from ( - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'BOXBUNDLES' || ',' || 'DHL' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then ws_sales_price* ws_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then ws_sales_price* ws_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then ws_sales_price* ws_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then ws_sales_price* ws_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then ws_sales_price* ws_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then ws_sales_price* ws_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then ws_sales_price* ws_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then ws_sales_price* ws_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then ws_sales_price* ws_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then ws_sales_price* ws_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then ws_sales_price* ws_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then ws_sales_price* ws_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as dec_net - from - web_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - ws_warehouse_sk = w_warehouse_sk - and ws_sold_date_sk = d_date_sk - and ws_sold_time_sk = t_time_sk - and ws_ship_mode_sk = sm_ship_mode_sk - and d_year = 2001 - and t_time between 6623 and 6623+28800 - and sm_carrier in ('BOXBUNDLES','DHL') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - union all - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'BOXBUNDLES' || ',' || 'DHL' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then cs_ext_sales_price* cs_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then cs_ext_sales_price* cs_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then cs_ext_sales_price* cs_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then cs_ext_sales_price* cs_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then cs_ext_sales_price* cs_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then cs_ext_sales_price* cs_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then cs_ext_sales_price* cs_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then cs_ext_sales_price* cs_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then cs_ext_sales_price* cs_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then cs_ext_sales_price* cs_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then cs_ext_sales_price* cs_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then cs_ext_sales_price* cs_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as dec_net - from - catalog_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and cs_sold_time_sk = t_time_sk - and cs_ship_mode_sk = sm_ship_mode_sk - and d_year = 2001 - and t_time between 6623 AND 6623+28800 - and sm_carrier in ('BOXBUNDLES','DHL') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - ) x - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - order by w_warehouse_name - limit 100; - --- end template query66.tpl query 7 in stream 4 --- start template query84.tpl query 8 in stream 4 -select /* TPC-DS query84.tpl 0.80 */ c_customer_id as customer_id - , coalesce(c_last_name,'') || ', ' || coalesce(c_first_name,'') as customername - from customer - ,customer_address - ,customer_demographics - ,household_demographics - ,income_band - ,store_returns - where ca_city = 'Fairfield' - and c_current_addr_sk = ca_address_sk - and ib_lower_bound >= 25899 - and ib_upper_bound <= 25899 + 50000 - and ib_income_band_sk = hd_income_band_sk - and cd_demo_sk = c_current_cdemo_sk - and hd_demo_sk = c_current_hdemo_sk - and sr_cdemo_sk = cd_demo_sk - order by c_customer_id - limit 100; - --- end template query84.tpl query 8 in stream 4 --- start template query8.tpl query 9 in stream 4 -select /* TPC-DS query8.tpl 0.63 */ s_store_name - ,sum(ss_net_profit) - from store_sales - ,date_dim - ,store, - (select ca_zip - from ( - SELECT substring(ca_zip,1,5) ca_zip - FROM customer_address - WHERE substring(ca_zip,1,5) IN ( - '58255','36652','11086','80037','52737','48814', - '36037','94098','79272','35919','23140', - '81735','11761','41499','67168','22978', - '18088','27714','14448','76557','82730', - '65344','62745','61147','79665','86460', - '66958','47606','60141','31776','91174', - '17420','79444','14591','72012','98988', - '40195','81960','93484','58932','57002', - '82477','78187','87612','96252','94046', - '30395','32364','62142','39046','86931', - '27382','80612','63362','94312','33451', - '12196','56335','79422','34776','23654', - '39290','53034','61946','11921','93465', - '80288','90248','47558','73995','82000', - '55356','69037','64767','15415','72545', - '57354','28045','16264','52804','40420', - '76527','11807','34105','90927','17685', - '15641','12539','39360','98519','22249', - '28834','47487','78549','88956','18192', - '43649','47034','61205','11246','34316', - '62534','11602','49331','61466','99701', - '82545','25856','62468','58319','41472', - '82891','62027','62065','18624','94296', - '88041','79582','95536','23543','18289', - '34151','51520','87895','87987','57447', - '51112','41301','59644','98515','73524', - '18986','68062','48773','24015','88722', - '21751','61820','11787','52971','41523', - '30614','93103','25393','55871','22128', - '82072','86719','99070','13274','37677', - '51825','42712','42128','36034','70023', - '91418','18034','76105','45508','67292', - '75957','62554','93257','98512','28447', - '65503','15829','84801','83242','28660', - '99074','54555','71998','68282','67335', - '43646','90835','20867','29164','20382', - '14750','18080','96199','73142','37226', - '63358','35562','39799','43266','47608', - '50028','33797','41792','45030','57573', - '98580','60170','92420','17218','73741', - '67305','68832','56619','54247','86129', - '61140','31730','31219','65339','51141', - '32788','41208','45439','64877','83337', - '85084','14763','28075','90489','76473', - '79135','35674','89186','63091','92371', - '84601','97249','21321','58530','65770', - '83768','25806','95313','52542','51660', - '17293','70783','95147','37986','69732', - '14040','23990','32209','11931','12897', - '26016','73066','49653','99192','45704', - '20245','35150','11262','11701','74353', - '13383','50341','39254','86847','95843', - '58849','74262','50448','68668','24990', - '11261','16594','61180','91842','21594', - '66811','20412','68741','60083','30717', - '69465','18475','49303','92239','52395', - '31472','77147','97779','15496','41498', - '88204','56729','86621','39843','15548', - '47796','86285','12347','67584','34637', - '17692','62178','61923','77211','70579', - '15516','80119','98143','16423','93724', - '37024','67557','64828','48147','52580', - '65317','11793','58734','78343','31273', - '42177','20509','59168','77283','72741', - '59509','20121','64387','48629','91371', - '97911','85210','41334','92673','26937', - '46145','40070','97780','23416','74098', - '86046','63603','62055','79750','85789', - '78470','32994','48581','17103','37745', - '74274','82348','74327','29689','60124', - '74850','12748','72704','89603','91341', - '13851','48726','57790','99337','25712', - '52745','89466','37555','51955','67473', - '25562','54558','58879','88501','21019', - '73668','18196','19314','23028','56743', - '41475','54237','80619','13940','75353', - '38216','40371','18248','22689','38730', - '39542','25531','32676','18380','28573', - '58078','14829','17126','36217','98936', - '49390','24467','25274','25878') - intersect - select ca_zip - from (SELECT substring(ca_zip,1,5) ca_zip,count(*) cnt - FROM customer_address, customer - WHERE ca_address_sk = c_current_addr_sk and - c_preferred_cust_flag='Y' - group by ca_zip - having count(*) > 10)A1)A2) V1 - where ss_store_sk = s_store_sk - and ss_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 2001 - and (substring(s_zip,1,2) = substring(V1.ca_zip,1,2)) - group by s_store_name - order by s_store_name - limit 100; - --- end template query8.tpl query 9 in stream 4 --- start template query71.tpl query 10 in stream 4 -select /* TPC-DS query71.tpl 0.72 */ i_brand_id brand_id, i_brand brand,t_hour,t_minute, - sum(ext_price) ext_price - from item, (select ws_ext_sales_price as ext_price, - ws_sold_date_sk as sold_date_sk, - ws_item_sk as sold_item_sk, - ws_sold_time_sk as time_sk - from web_sales,date_dim - where d_date_sk = ws_sold_date_sk - and d_moy=11 - and d_year=2002 - union all - select cs_ext_sales_price as ext_price, - cs_sold_date_sk as sold_date_sk, - cs_item_sk as sold_item_sk, - cs_sold_time_sk as time_sk - from catalog_sales,date_dim - where d_date_sk = cs_sold_date_sk - and d_moy=11 - and d_year=2002 - union all - select ss_ext_sales_price as ext_price, - ss_sold_date_sk as sold_date_sk, - ss_item_sk as sold_item_sk, - ss_sold_time_sk as time_sk - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - and d_moy=11 - and d_year=2002 - ) tmp,time_dim - where - sold_item_sk = i_item_sk - and i_manager_id=1 - and time_sk = t_time_sk - and (t_meal_time = 'breakfast' or t_meal_time = 'dinner') - group by i_brand, i_brand_id,t_hour,t_minute - order by ext_price desc, i_brand_id - ; - --- end template query71.tpl query 10 in stream 4 --- start template query45.tpl query 11 in stream 4 -select /* TPC-DS query45.tpl 0.18 */ ca_zip, ca_city, sum(ws_sales_price) - from web_sales, customer, customer_address, date_dim, item - where ws_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ws_item_sk = i_item_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', '85392', '85460', '80348', '81792') - or - i_item_id in (select i_item_id - from item - where i_item_sk in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29) - ) - ) - and ws_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 2001 - group by ca_zip, ca_city - order by ca_zip, ca_city - limit 100; - --- end template query45.tpl query 11 in stream 4 --- start template query89.tpl query 12 in stream 4 -select /* TPC-DS query89.tpl 0.56 */ * -from( -select i_category, i_class, i_brand, - s_store_name, s_company_name, - d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, s_store_name, s_company_name) - avg_monthly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - d_year in (2002) and - ((i_category in ('Jewelry','Music','Electronics') and - i_class in ('diamonds','rock','memory') - ) - or (i_category in ('Men','Home','Books') and - i_class in ('pants','glassware','history') - )) -group by i_category, i_class, i_brand, - s_store_name, s_company_name, d_moy) tmp1 -where case when (avg_monthly_sales <> 0) then (abs(sum_sales - avg_monthly_sales) / avg_monthly_sales) else null end > 0.1 -order by sum_sales - avg_monthly_sales, s_store_name -limit 100; - --- end template query89.tpl query 12 in stream 4 --- start template query91.tpl query 13 in stream 4 -select /* TPC-DS query91.tpl 0.13 */ - cc_call_center_id Call_Center, - cc_name Call_Center_Name, - cc_manager Manager, - sum(cr_net_loss) Returns_Loss -from - call_center, - catalog_returns, - date_dim, - customer, - customer_address, - customer_demographics, - household_demographics -where - cr_call_center_sk = cc_call_center_sk -and cr_returned_date_sk = d_date_sk -and cr_returning_customer_sk= c_customer_sk -and cd_demo_sk = c_current_cdemo_sk -and hd_demo_sk = c_current_hdemo_sk -and ca_address_sk = c_current_addr_sk -and d_year = 2001 -and d_moy = 11 -and ( (cd_marital_status = 'M' and cd_education_status = 'Unknown') - or(cd_marital_status = 'W' and cd_education_status = 'Advanced Degree')) -and hd_buy_potential like '501-1000%' -and ca_gmt_offset = -6 -group by cc_call_center_id,cc_name,cc_manager,cd_marital_status,cd_education_status -order by sum(cr_net_loss) desc; - --- end template query91.tpl query 13 in stream 4 --- start template query14a.tpl query 14 in stream 4 -with /* TPC-DS query14a.tpl 0.69 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1999 AND 1999 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1999 AND 1999 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1999 AND 1999 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as - (select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2) x) -, - results AS -(select channel, i_brand_id, i_class_id, i_category_id, sum(sales) sum_sales, sum(number_sales) number_sales - from ( - select 'store' channel, i_brand_id,i_class_id - ,i_category_id,sum(ss_quantity*ss_list_price) sales - , count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1999+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales) - union all - select 'catalog' channel, i_brand_id,i_class_id,i_category_id, sum(cs_quantity*cs_list_price) sales, count(*) number_sales - from catalog_sales - ,item - ,date_dim - where cs_item_sk in (select ss_item_sk from cross_items) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1999+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(cs_quantity*cs_list_price) > (select average_sales from avg_sales) - union all - select 'web' channel, i_brand_id,i_class_id,i_category_id, sum(ws_quantity*ws_list_price) sales , count(*) number_sales - from web_sales - ,item - ,date_dim - where ws_item_sk in (select ss_item_sk from cross_items) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1999+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ws_quantity*ws_list_price) > (select average_sales from avg_sales) - ) y - group by channel, i_brand_id,i_class_id,i_category_id) - - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales -from ( - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales from results - union - select channel, i_brand_id, i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id, i_class_id - union - select channel, i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id - union - select channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel - union - select null as channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results) z -order by channel, i_brand_id, i_class_id, i_category_id - limit 100; -with /* TPC-DS query14a.tpl 0.69 part2 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1999 AND 1999 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1999 AND 1999 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1999 AND 1999 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as -(select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2) x) - select this_year.channel ty_channel - ,this_year.i_brand_id ty_brand - ,this_year.i_class_id ty_class - ,this_year.i_category_id ty_category - ,this_year.sales ty_sales - ,this_year.number_sales ty_number_sales - ,last_year.channel ly_channel - ,last_year.i_brand_id ly_brand - ,last_year.i_class_id ly_class - ,last_year.i_category_id ly_category - ,last_year.sales ly_sales - ,last_year.number_sales ly_number_sales -from - (select 'store' channel, i_brand_id,i_class_id,i_category_id - ,sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1999 + 1 - and d_moy = 12 - and d_dom = 5) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) this_year, - (select 'store' channel, i_brand_id,i_class_id - ,i_category_id, sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1999 - and d_moy = 12 - and d_dom = 5) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) last_year - where this_year.i_brand_id= last_year.i_brand_id - and this_year.i_class_id = last_year.i_class_id - and this_year.i_category_id = last_year.i_category_id - order by this_year.channel, this_year.i_brand_id, this_year.i_class_id, this_year.i_category_id - limit 100; - --- end template query14a.tpl query 14 in stream 4 --- start template query46.tpl query 15 in stream 4 -select /* TPC-DS query46.tpl 0.23 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and (household_demographics.hd_dep_count = 4 or - household_demographics.hd_vehicle_count= 4) - and date_dim.d_dow in (6,0) - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_city in ('Red Hill','Harmony','Jamestown','Forest Hills','Wildwood') - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,ca_city) dn,customer,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - limit 100; - --- end template query46.tpl query 15 in stream 4 --- start template query58.tpl query 16 in stream 4 -with /* TPC-DS query58.tpl 0.19 */ ss_items as - (select i_item_id item_id - ,sum(ss_ext_sales_price) ss_item_rev - from store_sales - ,item - ,date_dim - where ss_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '2002-07-02')) - and ss_sold_date_sk = d_date_sk - group by i_item_id), - cs_items as - (select i_item_id item_id - ,sum(cs_ext_sales_price) cs_item_rev - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '2002-07-02')) - and cs_sold_date_sk = d_date_sk - group by i_item_id), - ws_items as - (select i_item_id item_id - ,sum(ws_ext_sales_price) ws_item_rev - from web_sales - ,item - ,date_dim - where ws_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq =(select d_week_seq - from date_dim - where d_date = '2002-07-02')) - and ws_sold_date_sk = d_date_sk - group by i_item_id) - select ss_items.item_id - ,ss_item_rev - ,ss_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ss_dev - ,cs_item_rev - ,cs_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 cs_dev - ,ws_item_rev - ,ws_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ws_dev - ,(ss_item_rev+cs_item_rev+ws_item_rev)/3 average - from ss_items,cs_items,ws_items - where ss_items.item_id=cs_items.item_id - and ss_items.item_id=ws_items.item_id - and ss_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - and ss_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and cs_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and cs_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and ws_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and ws_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - order by item_id - ,ss_item_rev - limit 100; - --- end template query58.tpl query 16 in stream 4 --- start template query48.tpl query 17 in stream 4 -select /* TPC-DS query48.tpl 0.74 */ sum (ss_quantity) - from store_sales, store, customer_demographics, customer_address, date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2002 - and - ( - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'W' - and - cd_education_status = 'Secondary' - and - ss_sales_price between 100.00 and 150.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'U' - and - cd_education_status = 'Unknown' - and - ss_sales_price between 50.00 and 100.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'S' - and - cd_education_status = '4 yr Degree' - and - ss_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('NC', 'CO', 'PA') - and ss_net_profit between 0 and 2000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('WA', 'NV', 'IA') - and ss_net_profit between 150 and 3000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('OR', 'SD', 'NE') - and ss_net_profit between 50 and 25000 - ) - ) -; - --- end template query48.tpl query 17 in stream 4 --- start template query59.tpl query 18 in stream 4 -with /* TPC-DS query59.tpl 0.30 */ wss as - (select d_week_seq, - ss_store_sk, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - group by d_week_seq,ss_store_sk - ) - select s_store_name1,s_store_id1,d_week_seq1 - ,sun_sales1/sun_sales2,mon_sales1/mon_sales2 - ,tue_sales1/tue_sales2,wed_sales1/wed_sales2,thu_sales1/thu_sales2 - ,fri_sales1/fri_sales2,sat_sales1/sat_sales2 - from - (select s_store_name s_store_name1,wss.d_week_seq d_week_seq1 - ,s_store_id s_store_id1,sun_sales sun_sales1 - ,mon_sales mon_sales1,tue_sales tue_sales1 - ,wed_sales wed_sales1,thu_sales thu_sales1 - ,fri_sales fri_sales1,sat_sales sat_sales1 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1193 and 1193 + 11) y, - (select s_store_name s_store_name2,wss.d_week_seq d_week_seq2 - ,s_store_id s_store_id2,sun_sales sun_sales2 - ,mon_sales mon_sales2,tue_sales tue_sales2 - ,wed_sales wed_sales2,thu_sales thu_sales2 - ,fri_sales fri_sales2,sat_sales sat_sales2 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1193+ 12 and 1193 + 23) x - where s_store_id1=s_store_id2 - and d_week_seq1=d_week_seq2-52 - order by s_store_name1,s_store_id1,d_week_seq1 -limit 100; - --- end template query59.tpl query 18 in stream 4 --- start template query2.tpl query 19 in stream 4 -with /* TPC-DS query2.tpl 0.84 */ wscs as - (select sold_date_sk - ,sales_price - from (select ws_sold_date_sk sold_date_sk - ,ws_ext_sales_price sales_price - from web_sales - union all - select cs_sold_date_sk sold_date_sk - ,cs_ext_sales_price sales_price - from catalog_sales)), - wswscs as - (select d_week_seq, - sum(case when (d_day_name='Sunday') then sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then sales_price else null end) sat_sales - from wscs - ,date_dim - where d_date_sk = sold_date_sk - group by d_week_seq) - select d_week_seq1 - ,round(sun_sales1/sun_sales2,2) - ,round(mon_sales1/mon_sales2,2) - ,round(tue_sales1/tue_sales2,2) - ,round(wed_sales1/wed_sales2,2) - ,round(thu_sales1/thu_sales2,2) - ,round(fri_sales1/fri_sales2,2) - ,round(sat_sales1/sat_sales2,2) - from - (select wswscs.d_week_seq d_week_seq1 - ,sun_sales sun_sales1 - ,mon_sales mon_sales1 - ,tue_sales tue_sales1 - ,wed_sales wed_sales1 - ,thu_sales thu_sales1 - ,fri_sales fri_sales1 - ,sat_sales sat_sales1 - from wswscs,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 1999) y, - (select wswscs.d_week_seq d_week_seq2 - ,sun_sales sun_sales2 - ,mon_sales mon_sales2 - ,tue_sales tue_sales2 - ,wed_sales wed_sales2 - ,thu_sales thu_sales2 - ,fri_sales fri_sales2 - ,sat_sales sat_sales2 - from wswscs - ,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 1999+1) z - where d_week_seq1=d_week_seq2-53 - order by d_week_seq1; - --- end template query2.tpl query 19 in stream 4 --- start template query83.tpl query 20 in stream 4 -with /* TPC-DS query83.tpl 0.96 */ sr_items as - (select i_item_id item_id, - sum(sr_return_quantity) sr_item_qty - from store_returns, - item, - date_dim - where sr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2001-04-06','2001-08-19','2001-11-16'))) - and sr_returned_date_sk = d_date_sk - group by i_item_id), - cr_items as - (select i_item_id item_id, - sum(cr_return_quantity) cr_item_qty - from catalog_returns, - item, - date_dim - where cr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2001-04-06','2001-08-19','2001-11-16'))) - and cr_returned_date_sk = d_date_sk - group by i_item_id), - wr_items as - (select i_item_id item_id, - sum(wr_return_quantity) wr_item_qty - from web_returns, - item, - date_dim - where wr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2001-04-06','2001-08-19','2001-11-16'))) - and wr_returned_date_sk = d_date_sk - group by i_item_id) - select sr_items.item_id - ,sr_item_qty - ,sr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 sr_dev - ,cr_item_qty - ,cr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 cr_dev - ,wr_item_qty - ,wr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 wr_dev - ,(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 average - from sr_items - ,cr_items - ,wr_items - where sr_items.item_id=cr_items.item_id - and sr_items.item_id=wr_items.item_id - order by sr_items.item_id - ,sr_item_qty - limit 100; - --- end template query83.tpl query 20 in stream 4 --- start template query21.tpl query 21 in stream 4 -select /* TPC-DS query21.tpl 0.14 */ * - from(select w_warehouse_name - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('1998-06-01' as date)) - then inv_quantity_on_hand - else 0 end) as inv_before - ,sum(case when (cast(d_date as date) >= cast ('1998-06-01' as date)) - then inv_quantity_on_hand - else 0 end) as inv_after - from inventory - ,warehouse - ,item - ,date_dim - where i_current_price between 0.99 and 1.49 - and i_item_sk = inv_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('1998-06-01' as date)) - and dateadd(day,30,cast ('1998-06-01' as date)) - group by w_warehouse_name, i_item_id) x - where (case when inv_before > 0 - then inv_after / inv_before - else null - end) between 2.0/3.0 and 3.0/2.0 - order by w_warehouse_name - ,i_item_id - limit 100; - --- end template query21.tpl query 21 in stream 4 --- start template query78.tpl query 22 in stream 4 -with /* TPC-DS query78.tpl 0.10 */ ws as - (select d_year AS ws_sold_year, ws_item_sk, - ws_bill_customer_sk ws_customer_sk, - sum(ws_quantity) ws_qty, - sum(ws_wholesale_cost) ws_wc, - sum(ws_sales_price) ws_sp - from web_sales - left join web_returns on wr_order_number=ws_order_number and ws_item_sk=wr_item_sk - join date_dim on ws_sold_date_sk = d_date_sk - where wr_order_number is null - group by d_year, ws_item_sk, ws_bill_customer_sk - ), -cs as - (select d_year AS cs_sold_year, cs_item_sk, - cs_bill_customer_sk cs_customer_sk, - sum(cs_quantity) cs_qty, - sum(cs_wholesale_cost) cs_wc, - sum(cs_sales_price) cs_sp - from catalog_sales - left join catalog_returns on cr_order_number=cs_order_number and cs_item_sk=cr_item_sk - join date_dim on cs_sold_date_sk = d_date_sk - where cr_order_number is null - group by d_year, cs_item_sk, cs_bill_customer_sk - ), -ss as - (select d_year AS ss_sold_year, ss_item_sk, - ss_customer_sk, - sum(ss_quantity) ss_qty, - sum(ss_wholesale_cost) ss_wc, - sum(ss_sales_price) ss_sp - from store_sales - left join store_returns on sr_ticket_number=ss_ticket_number and ss_item_sk=sr_item_sk - join date_dim on ss_sold_date_sk = d_date_sk - where sr_ticket_number is null - group by d_year, ss_item_sk, ss_customer_sk - ) - select -ss_item_sk, -round(ss_qty/(coalesce(ws_qty,0)+coalesce(cs_qty,0)),2) ratio, -ss_qty store_qty, ss_wc store_wholesale_cost, ss_sp store_sales_price, -coalesce(ws_qty,0)+coalesce(cs_qty,0) other_chan_qty, -coalesce(ws_wc,0)+coalesce(cs_wc,0) other_chan_wholesale_cost, -coalesce(ws_sp,0)+coalesce(cs_sp,0) other_chan_sales_price -from ss -left join ws on (ws_sold_year=ss_sold_year and ws_item_sk=ss_item_sk and ws_customer_sk=ss_customer_sk) -left join cs on (cs_sold_year=ss_sold_year and cs_item_sk=ss_item_sk and cs_customer_sk=ss_customer_sk) -where (coalesce(ws_qty,0)>0 or coalesce(cs_qty, 0)>0) and ss_sold_year=1999 -order by - ss_item_sk, - ss_qty desc, ss_wc desc, ss_sp desc, - other_chan_qty, - other_chan_wholesale_cost, - other_chan_sales_price, - ratio -limit 100; - --- end template query78.tpl query 22 in stream 4 --- start template query40.tpl query 23 in stream 4 -select /* TPC-DS query40.tpl 0.86 */ - w_state - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('1999-02-05' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_before - ,sum(case when (cast(d_date as date) >= cast ('1999-02-05' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_after - from - catalog_sales left outer join catalog_returns on - (cs_order_number = cr_order_number - and cs_item_sk = cr_item_sk) - ,warehouse - ,item - ,date_dim - where - i_current_price between 0.99 and 1.49 - and i_item_sk = cs_item_sk - and cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('1999-02-05' as date)) - and dateadd(day,30,cast ('1999-02-05' as date)) - group by - w_state,i_item_id - order by w_state,i_item_id -limit 100; - --- end template query40.tpl query 23 in stream 4 --- start template query99.tpl query 24 in stream 4 -select /* TPC-DS query99.tpl 0.94 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 30) and - (cs_ship_date_sk - cs_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 60) and - (cs_ship_date_sk - cs_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 90) and - (cs_ship_date_sk - cs_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - catalog_sales - ,warehouse - ,ship_mode - ,call_center - ,date_dim -where - d_month_seq between 1188 and 1188 + 11 -and cs_ship_date_sk = d_date_sk -and cs_warehouse_sk = w_warehouse_sk -and cs_ship_mode_sk = sm_ship_mode_sk -and cs_call_center_sk = cc_call_center_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -limit 100; - --- end template query99.tpl query 24 in stream 4 --- start template query19.tpl query 25 in stream 4 -select /* TPC-DS query19.tpl 0.8 */ i_brand_id brand_id, i_brand brand, i_manufact_id, i_manufact, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item,customer,customer_address,store - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=7 - and d_moy=11 - and d_year=2001 - and ss_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and substring(ca_zip,1,5) <> substring(s_zip,1,5) - and ss_store_sk = s_store_sk - group by i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact - order by ext_price desc - ,i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact -limit 100 ; - --- end template query19.tpl query 25 in stream 4 --- start template query72.tpl query 26 in stream 4 -select /* TPC-DS query72.tpl 0.87 */ i_item_desc - ,w_warehouse_name - ,d1.d_week_seq - ,sum(case when p_promo_sk is null then 1 else 0 end) no_promo - ,sum(case when p_promo_sk is not null then 1 else 0 end) promo - ,count(*) total_cnt -from catalog_sales -join inventory on (cs_item_sk = inv_item_sk) -join warehouse on (w_warehouse_sk=inv_warehouse_sk) -join item on (i_item_sk = cs_item_sk) -join customer_demographics on (cs_bill_cdemo_sk = cd_demo_sk) -join household_demographics on (cs_bill_hdemo_sk = hd_demo_sk) -join date_dim d1 on (cs_sold_date_sk = d1.d_date_sk) -join date_dim d2 on (inv_date_sk = d2.d_date_sk) -join date_dim d3 on (cs_ship_date_sk = d3.d_date_sk) -left outer join promotion on (cs_promo_sk=p_promo_sk) -left outer join catalog_returns on (cr_item_sk = cs_item_sk and cr_order_number = cs_order_number) -where d1.d_week_seq = d2.d_week_seq - and inv_quantity_on_hand < cs_quantity - and d3.d_date > d1.d_date + 5 - and hd_buy_potential = '1001-5000' - and d1.d_year = 1998 - and cd_marital_status = 'U' -group by i_item_desc,w_warehouse_name,d1.d_week_seq -order by total_cnt desc, i_item_desc, w_warehouse_name, d_week_seq -limit 100; - --- end template query72.tpl query 26 in stream 4 --- start template query6.tpl query 27 in stream 4 -select /* TPC-DS query6.tpl 0.58 */ a.ca_state state, count(*) cnt - from customer_address a - ,customer c - ,store_sales s - ,date_dim d - ,item i - where a.ca_address_sk = c.c_current_addr_sk - and c.c_customer_sk = s.ss_customer_sk - and s.ss_sold_date_sk = d.d_date_sk - and s.ss_item_sk = i.i_item_sk - and d.d_month_seq = - (select distinct (d_month_seq) - from date_dim - where d_year = 2000 - and d_moy = 1 ) - and i.i_current_price > 1.2 * - (select avg(j.i_current_price) - from item j - where j.i_category = i.i_category) - group by a.ca_state - having count(*) >= 10 - order by cnt, a.ca_state - limit 100; - --- end template query6.tpl query 27 in stream 4 --- start template query28.tpl query 28 in stream 4 -select /* TPC-DS query28.tpl 0.36 */ * -from (select avg(ss_list_price) B1_LP - ,count(ss_list_price) B1_CNT - ,count(distinct ss_list_price) B1_CNTD - from store_sales - where ss_quantity between 0 and 5 - and (ss_list_price between 107 and 107+10 - or ss_coupon_amt between 2845 and 2845+1000 - or ss_wholesale_cost between 53 and 53+20)) B1, - (select avg(ss_list_price) B2_LP - ,count(ss_list_price) B2_CNT - ,count(distinct ss_list_price) B2_CNTD - from store_sales - where ss_quantity between 6 and 10 - and (ss_list_price between 145 and 145+10 - or ss_coupon_amt between 9720 and 9720+1000 - or ss_wholesale_cost between 2 and 2+20)) B2, - (select avg(ss_list_price) B3_LP - ,count(ss_list_price) B3_CNT - ,count(distinct ss_list_price) B3_CNTD - from store_sales - where ss_quantity between 11 and 15 - and (ss_list_price between 167 and 167+10 - or ss_coupon_amt between 3926 and 3926+1000 - or ss_wholesale_cost between 20 and 20+20)) B3, - (select avg(ss_list_price) B4_LP - ,count(ss_list_price) B4_CNT - ,count(distinct ss_list_price) B4_CNTD - from store_sales - where ss_quantity between 16 and 20 - and (ss_list_price between 74 and 74+10 - or ss_coupon_amt between 6100 and 6100+1000 - or ss_wholesale_cost between 16 and 16+20)) B4, - (select avg(ss_list_price) B5_LP - ,count(ss_list_price) B5_CNT - ,count(distinct ss_list_price) B5_CNTD - from store_sales - where ss_quantity between 21 and 25 - and (ss_list_price between 47 and 47+10 - or ss_coupon_amt between 5459 and 5459+1000 - or ss_wholesale_cost between 45 and 45+20)) B5, - (select avg(ss_list_price) B6_LP - ,count(ss_list_price) B6_CNT - ,count(distinct ss_list_price) B6_CNTD - from store_sales - where ss_quantity between 26 and 30 - and (ss_list_price between 93 and 93+10 - or ss_coupon_amt between 9793 and 9793+1000 - or ss_wholesale_cost between 60 and 60+20)) B6 -limit 100; - --- end template query28.tpl query 28 in stream 4 --- start template query81.tpl query 29 in stream 4 -with /* TPC-DS query81.tpl 0.37 */ customer_total_return as - (select cr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(cr_return_amt_inc_tax) as ctr_total_return - from catalog_returns - ,date_dim - ,customer_address - where cr_returned_date_sk = d_date_sk - and d_year =1999 - and cr_returning_addr_sk = ca_address_sk - group by cr_returning_customer_sk - ,ca_state ) - select c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'KS' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - limit 100; - --- end template query81.tpl query 29 in stream 4 --- start template query44.tpl query 30 in stream 4 -select /* TPC-DS query44.tpl 0.4 */ asceding.rnk, i1.i_product_name best_performing, i2.i_product_name worst_performing -from(select * - from (select item_sk,rank() over (order by rank_col asc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 555 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 555 - and ss_addr_sk is null - group by ss_store_sk))V1)V11 - where rnk < 11) asceding, - (select * - from (select item_sk,rank() over (order by rank_col desc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 555 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 555 - and ss_addr_sk is null - group by ss_store_sk))V2)V21 - where rnk < 11) descending, -item i1, -item i2 -where asceding.rnk = descending.rnk - and i1.i_item_sk=asceding.item_sk - and i2.i_item_sk=descending.item_sk -order by asceding.rnk -limit 100; - --- end template query44.tpl query 30 in stream 4 --- start template query97.tpl query 31 in stream 4 -with /* TPC-DS query97.tpl 0.38 */ ssci as ( -select ss_customer_sk customer_sk - ,ss_item_sk item_sk -from store_sales,date_dim -where ss_sold_date_sk = d_date_sk - and d_month_seq between 1177 and 1177 + 11 -group by ss_customer_sk - ,ss_item_sk), -csci as( - select cs_bill_customer_sk customer_sk - ,cs_item_sk item_sk -from catalog_sales,date_dim -where cs_sold_date_sk = d_date_sk - and d_month_seq between 1177 and 1177 + 11 -group by cs_bill_customer_sk - ,cs_item_sk) - select sum(case when ssci.customer_sk is not null and csci.customer_sk is null then 1 else 0 end) store_only - ,sum(case when ssci.customer_sk is null and csci.customer_sk is not null then 1 else 0 end) catalog_only - ,sum(case when ssci.customer_sk is not null and csci.customer_sk is not null then 1 else 0 end) store_and_catalog -from ssci full outer join csci on (ssci.customer_sk=csci.customer_sk - and ssci.item_sk = csci.item_sk) -limit 100; - --- end template query97.tpl query 31 in stream 4 --- start template query88.tpl query 32 in stream 4 -select /* TPC-DS query88.tpl 0.66 */ * -from - (select count(*) h8_30_to_9 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s1, - (select count(*) h9_to_9_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s2, - (select count(*) h9_30_to_10 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s3, - (select count(*) h10_to_10_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s4, - (select count(*) h10_30_to_11 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s5, - (select count(*) h11_to_11_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s6, - (select count(*) h11_30_to_12 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s7, - (select count(*) h12_to_12_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 12 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s8 -; - --- end template query88.tpl query 32 in stream 4 --- start template query77a.tpl query 33 in stream 4 -with /* TPC-DS query77a.tpl 0.78 */ ss as - (select s_store_sk, - sum(ss_ext_sales_price) as sales, - sum(ss_net_profit) as profit - from store_sales, - date_dim, - store - where ss_sold_date_sk = d_date_sk - and d_date between cast('1998-08-20' as date) - and dateadd(day,30,cast('1998-08-20' as date)) - and ss_store_sk = s_store_sk - group by s_store_sk) - , - sr as - (select s_store_sk, - sum(sr_return_amt) as returns, - sum(sr_net_loss) as profit_loss - from store_returns, - date_dim, - store - where sr_returned_date_sk = d_date_sk - and d_date between cast('1998-08-20' as date) - and dateadd(day,30,cast('1998-08-20' as date)) - and sr_store_sk = s_store_sk - group by s_store_sk), - cs as - (select cs_call_center_sk, - sum(cs_ext_sales_price) as sales, - sum(cs_net_profit) as profit - from catalog_sales, - date_dim - where cs_sold_date_sk = d_date_sk - and d_date between cast('1998-08-20' as date) - and dateadd(day,30,cast('1998-08-20' as date)) - group by cs_call_center_sk - ), - cr as - (select cr_call_center_sk, - sum(cr_return_amount) as returns, - sum(cr_net_loss) as profit_loss - from catalog_returns, - date_dim - where cr_returned_date_sk = d_date_sk - and d_date between cast('1998-08-20' as date) - and dateadd(day,30,cast('1998-08-20' as date)) - group by cr_call_center_sk), - ws as - ( select wp_web_page_sk, - sum(ws_ext_sales_price) as sales, - sum(ws_net_profit) as profit - from web_sales, - date_dim, - web_page - where ws_sold_date_sk = d_date_sk - and d_date between cast('1998-08-20' as date) - and dateadd(day,30,cast('1998-08-20' as date)) - and ws_web_page_sk = wp_web_page_sk - group by wp_web_page_sk), - wr as - (select wp_web_page_sk, - sum(wr_return_amt) as returns, - sum(wr_net_loss) as profit_loss - from web_returns, - date_dim, - web_page - where wr_returned_date_sk = d_date_sk - and d_date between cast('1998-08-20' as date) - and dateadd(day,30,cast('1998-08-20' as date)) - and wr_web_page_sk = wp_web_page_sk - group by wp_web_page_sk) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , ss.s_store_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ss left join sr - on ss.s_store_sk = sr.s_store_sk - union all - select 'catalog channel' as channel - , cs_call_center_sk as id - , sales - , returns - , (profit - profit_loss) as profit - from cs - , cr - union all - select 'web channel' as channel - , ws.wp_web_page_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ws left join wr - on ws.wp_web_page_sk = wr.wp_web_page_sk - ) x - group by channel, id ) - - select * - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results -) foo -order by channel, id - limit 100; - --- end template query77a.tpl query 33 in stream 4 --- start template query95.tpl query 34 in stream 4 -with /* TPC-DS query95.tpl 0.43 */ ws_wh as -(select ws1.ws_order_number,ws1.ws_warehouse_sk wh1,ws2.ws_warehouse_sk wh2 - from web_sales ws1,web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) - select - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2002-4-01' and - dateadd(day,60,cast('2002-4-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'TX' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and ws1.ws_order_number in (select ws_order_number - from ws_wh) -and ws1.ws_order_number in (select wr_order_number - from web_returns,ws_wh - where wr_order_number = ws_wh.ws_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query95.tpl query 34 in stream 4 --- start template query33.tpl query 35 in stream 4 -with /* TPC-DS query33.tpl 0.22 */ ss as ( - select - i_manufact_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Books')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 4 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id), - cs as ( - select - i_manufact_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Books')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 4 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id), - ws as ( - select - i_manufact_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Books')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 4 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id) - select i_manufact_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_manufact_id - order by total_sales -limit 100; - --- end template query33.tpl query 35 in stream 4 --- start template query36a.tpl query 36 in stream 4 -with /* TPC-DS query36a.tpl 0.21 */ results as - (select - sum(ss_net_profit) as ss_net_profit, sum(ss_ext_sales_price) as ss_ext_sales_price, - sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin - ,i_category - ,i_class - ,0 as g_category, 0 as g_class - from - store_sales - ,date_dim d1 - ,item - ,store - where - d1.d_year = 2001 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and s_state in ('SC','LA','MN','CO', - 'PA','IL','MN','WV') - group by i_category,i_class) - , - results_rollup as - (select gross_margin ,i_category ,i_class,0 as t_category, 0 as t_class, 0 as lochierarchy from results - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - i_category, NULL AS i_class, 0 as t_category, 1 as t_class, 1 as lochierarchy from results group by i_category - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - NULL AS i_category ,NULL AS i_class, 1 as t_category, 1 as t_class, 2 as lochierarchy from results) - select - gross_margin ,i_category ,i_class, lochierarchy,rank() over ( - partition by lochierarchy, case when t_class = 0 then i_category end - order by gross_margin asc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then i_category end - ,rank_within_parent - limit 100; - --- end template query36a.tpl query 36 in stream 4 --- start template query61.tpl query 37 in stream 4 -select /* TPC-DS query61.tpl 0.97 */ promotions,total,cast(promotions as decimal(15,4))/cast(total as decimal(15,4))*100 -from - (select sum(ss_ext_sales_price) promotions - from store_sales - ,store - ,promotion - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_promo_sk = p_promo_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -6 - and i_category = 'Electronics' - and (p_channel_dmail = 'Y' or p_channel_email = 'Y' or p_channel_tv = 'Y') - and s_gmt_offset = -6 - and d_year = 2002 - and d_moy = 12) promotional_sales, - (select sum(ss_ext_sales_price) total - from store_sales - ,store - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -6 - and i_category = 'Electronics' - and s_gmt_offset = -6 - and d_year = 2002 - and d_moy = 12) all_sales -order by promotions, total -limit 100; - --- end template query61.tpl query 37 in stream 4 --- start template query35a.tpl query 38 in stream 4 -select /* TPC-DS query35a.tpl 0.47 */ - ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - count(*) cnt1, - min(cd_dep_count), - stddev_samp(cd_dep_count), - stddev_samp(cd_dep_count), - cd_dep_employed_count, - count(*) cnt2, - min(cd_dep_employed_count), - stddev_samp(cd_dep_employed_count), - stddev_samp(cd_dep_employed_count), - cd_dep_college_count, - count(*) cnt3, - min(cd_dep_college_count), - stddev_samp(cd_dep_college_count), - stddev_samp(cd_dep_college_count) - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2000 and - d_qoy < 4) and - exists (select * from - (select ws_bill_customer_sk customsk - from web_sales,date_dim - where - ws_sold_date_sk = d_date_sk and - d_year = 2000 and - d_qoy < 4 - union all - select cs_ship_customer_sk customsk - from catalog_sales,date_dim - where - cs_sold_date_sk = d_date_sk and - d_year = 2000 and - d_qoy < 4)x - where x.customsk = c.c_customer_sk) - group by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - limit 100; - --- end template query35a.tpl query 38 in stream 4 --- start template query60.tpl query 39 in stream 4 -with /* TPC-DS query60.tpl 0.29 */ ss as ( - select - i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Jewelry')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 8 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - cs as ( - select - i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Jewelry')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 8 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - ws as ( - select - i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Jewelry')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 8 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id) - select - i_item_id -,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by i_item_id - ,total_sales - limit 100; - --- end template query60.tpl query 39 in stream 4 --- start template query75.tpl query 40 in stream 4 -WITH /* TPC-DS query75.tpl 0.3 */ all_sales AS ( - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,SUM(sales_cnt) AS sales_cnt - ,SUM(sales_amt) AS sales_amt - FROM (SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,cs_quantity - COALESCE(cr_return_quantity,0) AS sales_cnt - ,cs_ext_sales_price - COALESCE(cr_return_amount,0.0) AS sales_amt - FROM catalog_sales JOIN item ON i_item_sk=cs_item_sk - JOIN date_dim ON d_date_sk=cs_sold_date_sk - LEFT JOIN catalog_returns ON (cs_order_number=cr_order_number - AND cs_item_sk=cr_item_sk) - WHERE i_category='Children' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ss_quantity - COALESCE(sr_return_quantity,0) AS sales_cnt - ,ss_ext_sales_price - COALESCE(sr_return_amt,0.0) AS sales_amt - FROM store_sales JOIN item ON i_item_sk=ss_item_sk - JOIN date_dim ON d_date_sk=ss_sold_date_sk - LEFT JOIN store_returns ON (ss_ticket_number=sr_ticket_number - AND ss_item_sk=sr_item_sk) - WHERE i_category='Children' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ws_quantity - COALESCE(wr_return_quantity,0) AS sales_cnt - ,ws_ext_sales_price - COALESCE(wr_return_amt,0.0) AS sales_amt - FROM web_sales JOIN item ON i_item_sk=ws_item_sk - JOIN date_dim ON d_date_sk=ws_sold_date_sk - LEFT JOIN web_returns ON (ws_order_number=wr_order_number - AND ws_item_sk=wr_item_sk) - WHERE i_category='Children') sales_detail - GROUP BY d_year, i_brand_id, i_class_id, i_category_id, i_manufact_id) - SELECT prev_yr.d_year AS prev_year - ,curr_yr.d_year AS year - ,curr_yr.i_brand_id - ,curr_yr.i_class_id - ,curr_yr.i_category_id - ,curr_yr.i_manufact_id - ,prev_yr.sales_cnt AS prev_yr_cnt - ,curr_yr.sales_cnt AS curr_yr_cnt - ,curr_yr.sales_cnt-prev_yr.sales_cnt AS sales_cnt_diff - ,curr_yr.sales_amt-prev_yr.sales_amt AS sales_amt_diff - FROM all_sales curr_yr, all_sales prev_yr - WHERE curr_yr.i_brand_id=prev_yr.i_brand_id - AND curr_yr.i_class_id=prev_yr.i_class_id - AND curr_yr.i_category_id=prev_yr.i_category_id - AND curr_yr.i_manufact_id=prev_yr.i_manufact_id - AND curr_yr.d_year=1999 - AND prev_yr.d_year=1999-1 - AND CAST(curr_yr.sales_cnt AS DECIMAL(17,2))/CAST(prev_yr.sales_cnt AS DECIMAL(17,2))<0.9 - ORDER BY sales_cnt_diff,sales_amt_diff - limit 100; - --- end template query75.tpl query 40 in stream 4 --- start template query74.tpl query 41 in stream 4 -with /* TPC-DS query74.tpl 0.76 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,max(ss_net_paid) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (2000,2000+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,max(ws_net_paid) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - and d_year in (2000,2000+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - ) - select - t_s_secyear.customer_id, t_s_secyear.customer_first_name, t_s_secyear.customer_last_name - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.year = 2000 - and t_s_secyear.year = 2000+1 - and t_w_firstyear.year = 2000 - and t_w_secyear.year = 2000+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - order by 1,3,2 -limit 100; - --- end template query74.tpl query 41 in stream 4 --- start template query55.tpl query 42 in stream 4 -select /* TPC-DS query55.tpl 0.82 */ i_brand_id brand_id, i_brand brand, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=75 - and d_moy=11 - and d_year=1999 - group by i_brand, i_brand_id - order by ext_price desc, i_brand_id -limit 100 ; - --- end template query55.tpl query 42 in stream 4 --- start template query51.tpl query 43 in stream 4 -WITH /* TPC-DS query51.tpl 0.46 */ web_v1 as ( -select - ws_item_sk item_sk, d_date, - sum(sum(ws_sales_price)) - over (partition by ws_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from web_sales - ,date_dim -where ws_sold_date_sk=d_date_sk - and d_month_seq between 1210 and 1210+11 - and ws_item_sk is not NULL -group by ws_item_sk, d_date), -store_v1 as ( -select - ss_item_sk item_sk, d_date, - sum(sum(ss_sales_price)) - over (partition by ss_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from store_sales - ,date_dim -where ss_sold_date_sk=d_date_sk - and d_month_seq between 1210 and 1210+11 - and ss_item_sk is not NULL -group by ss_item_sk, d_date) - select * -from (select item_sk - ,d_date - ,web_sales - ,store_sales - ,max(web_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) web_cumulative - ,max(store_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) store_cumulative - from (select case when web.item_sk is not null then web.item_sk else store.item_sk end item_sk - ,case when web.d_date is not null then web.d_date else store.d_date end d_date - ,web.cume_sales web_sales - ,store.cume_sales store_sales - from web_v1 web full outer join store_v1 store on (web.item_sk = store.item_sk - and web.d_date = store.d_date) - )x )y -where web_cumulative > store_cumulative -order by item_sk - ,d_date -limit 100; - --- end template query51.tpl query 43 in stream 4 --- start template query17.tpl query 44 in stream 4 -select /* TPC-DS query17.tpl 0.41 */ i_item_id - ,i_item_desc - ,s_state - ,count(ss_quantity) as store_sales_quantitycount - ,avg(ss_quantity) as store_sales_quantityave - ,stddev_samp(ss_quantity) as store_sales_quantitystdev - ,stddev_samp(ss_quantity)/avg(ss_quantity) as store_sales_quantitycov - ,count(sr_return_quantity) as store_returns_quantitycount - ,avg(sr_return_quantity) as store_returns_quantityave - ,stddev_samp(sr_return_quantity) as store_returns_quantitystdev - ,stddev_samp(sr_return_quantity)/avg(sr_return_quantity) as store_returns_quantitycov - ,count(cs_quantity) as catalog_sales_quantitycount ,avg(cs_quantity) as catalog_sales_quantityave - ,stddev_samp(cs_quantity) as catalog_sales_quantitystdev - ,stddev_samp(cs_quantity)/avg(cs_quantity) as catalog_sales_quantitycov - from store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where d1.d_quarter_name = '2001Q1' - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_quarter_name in ('2001Q1','2001Q2','2001Q3') - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_quarter_name in ('2001Q1','2001Q2','2001Q3') - group by i_item_id - ,i_item_desc - ,s_state - order by i_item_id - ,i_item_desc - ,s_state -limit 100; - --- end template query17.tpl query 44 in stream 4 --- start template query52.tpl query 45 in stream 4 -select /* TPC-DS query52.tpl 0.59 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_sales_price) ext_price - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=12 - and dt.d_year=2002 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,ext_price desc - ,brand_id -limit 100 ; - --- end template query52.tpl query 45 in stream 4 --- start template query90.tpl query 46 in stream 4 -select /* TPC-DS query90.tpl 0.40 */ cast(amc as decimal(15,4))/cast(pmc as decimal(15,4)) am_pm_ratio - from ( select count(*) amc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 12 and 12+1 - and household_demographics.hd_dep_count = 8 - and web_page.wp_char_count between 5000 and 5200) at, - ( select count(*) pmc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 15 and 15+1 - and household_demographics.hd_dep_count = 8 - and web_page.wp_char_count between 5000 and 5200) pt - order by am_pm_ratio - limit 100; - --- end template query90.tpl query 46 in stream 4 --- start template query22a.tpl query 47 in stream 4 -with /* TPC-DS query22a.tpl 0.55 */ results as -(select i_product_name - ,i_brand - ,i_class - ,i_category - ,avg(inv_quantity_on_hand) qoh - from inventory - ,date_dim - ,item --- ,warehouse - where inv_date_sk=d_date_sk - and inv_item_sk=i_item_sk --- and inv_warehouse_sk = w_warehouse_sk - and d_month_seq between 1217 and 1217 + 11 - group by i_product_name,i_brand,i_class,i_category), -results_rollup as -(select i_product_name, i_brand, i_class, i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class,i_category -union all -select i_product_name, i_brand, i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class -union all -select i_product_name, i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand -union all -select i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name -union all -select null i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results) - select i_product_name, i_brand, i_class, i_category,qoh - from results_rollup - order by qoh, i_product_name, i_brand, i_class, i_category -limit 100; - --- end template query22a.tpl query 47 in stream 4 --- start template query27a.tpl query 48 in stream 4 -with /* TPC-DS query27a.tpl 0.16 */ results as - (select i_item_id, - s_state, 0 as g_state, - ss_quantity agg1, - ss_list_price agg2, - ss_coupon_amt agg3, - ss_sales_price agg4 - from store_sales, customer_demographics, date_dim, store, item - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_store_sk = s_store_sk and - ss_cdemo_sk = cd_demo_sk and - cd_gender = 'F' and - cd_marital_status = 'S' and - cd_education_status = 'Primary' and - d_year = 1999 and - s_state in ('FL','NC', 'MN', 'CO', 'MI', 'SC') - ) - - select i_item_id, - s_state, g_state, agg1, agg2, agg3, agg4 - from ( - select i_item_id, s_state, 0 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4 from results - group by i_item_id, s_state - union all - select i_item_id, NULL AS s_state, 1 AS g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as s_state, 1 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - ) foo - order by i_item_id, s_state - limit 100; - --- end template query27a.tpl query 48 in stream 4 --- start template query63.tpl query 49 in stream 4 -select /* TPC-DS query63.tpl 0.27 */ * -from (select i_manager_id - ,sum(ss_sales_price) sum_sales - ,avg(sum(ss_sales_price)) over (partition by i_manager_id) avg_monthly_sales - from item - ,store_sales - ,date_dim - ,store - where ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and d_month_seq in (1201,1201+1,1201+2,1201+3,1201+4,1201+5,1201+6,1201+7,1201+8,1201+9,1201+10,1201+11) - and (( i_category in ('Books','Children','Electronics') - and i_class in ('personal','portable','reference','self-help') - and i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) - or( i_category in ('Women','Music','Men') - and i_class in ('accessories','classical','fragrances','pants') - and i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manager_id, d_moy) tmp1 -where case when avg_monthly_sales > 0 then abs (sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 -order by i_manager_id - ,avg_monthly_sales - ,sum_sales -limit 100; - --- end template query63.tpl query 49 in stream 4 --- start template query38.tpl query 50 in stream 4 -select /* TPC-DS query38.tpl 0.54 */ count(*) from ( - select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1223 and 1223 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1223 and 1223 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1223 and 1223 + 11 -) hot_cust -limit 100; - --- end template query38.tpl query 50 in stream 4 --- start template query18a.tpl query 51 in stream 4 -with /* TPC-DS query18a.tpl 0.90 */ results as - (select i_item_id, - ca_country, - ca_state, - ca_county, - cast(cs_quantity as decimal(12,2)) agg1, - cast(cs_list_price as decimal(12,2)) agg2, - cast(cs_coupon_amt as decimal(12,2)) agg3, - cast(cs_sales_price as decimal(12,2)) agg4, - cast(cs_net_profit as decimal(12,2)) agg5, - cast(c_birth_year as decimal(12,2)) agg6, - cast(cd1.cd_dep_count as decimal(12,2)) agg7 - from catalog_sales, customer_demographics cd1, customer_demographics cd2, customer, customer_address, date_dim, item - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd1.cd_demo_sk and - cs_bill_customer_sk = c_customer_sk and - cd1.cd_gender = 'F' and - cd1.cd_education_status = 'Advanced Degree' and - c_current_cdemo_sk = cd2.cd_demo_sk and - c_current_addr_sk = ca_address_sk and - c_birth_month in (5,9,7,10,11,6) and - d_year = 2000 and - ca_state in ('NE','NY','TX','MS','GA','KY','NH') - ) - select i_item_id, ca_country, ca_state, ca_county, agg1, agg2, agg3, agg4, agg5, agg6, agg7 - from ( - select i_item_id, ca_country, ca_state, ca_county, avg(agg1) agg1, - avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state, ca_county - union all - select i_item_id, ca_country, ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state - union all - select i_item_id, ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country - union all - select i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - ) foo - order by ca_country, ca_state, ca_county, i_item_id - limit 100; - --- end template query18a.tpl query 51 in stream 4 --- start template query24.tpl query 52 in stream 4 -with /* TPC-DS query24.tpl 0.92 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_net_paid_inc_tax) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip -and s_market_id=8 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'drab' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; -with /* TPC-DS query24.tpl 0.92 part2 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_net_paid_inc_tax) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip - and s_market_id = 8 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'lemon' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; - --- end template query24.tpl query 52 in stream 4 --- start template query37.tpl query 53 in stream 4 -select /* TPC-DS query37.tpl 0.31 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, catalog_sales - where i_current_price between 44 and 44 + 30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('2002-05-02' as date) and dateadd(day,60,cast('2002-05-02' as date)) - and i_manufact_id in (806,759,948,993) - and inv_quantity_on_hand between 100 and 500 - and cs_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query37.tpl query 53 in stream 4 --- start template query47.tpl query 54 in stream 4 -with /* TPC-DS query47.tpl 0.42 */ v1 as( - select i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, - s_store_name, s_company_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - s_store_name, s_company_name - order by d_year, d_moy) rn - from item, store_sales, date_dim, store - where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - ( - d_year = 2001 or - ( d_year = 2001-1 and d_moy =12) or - ( d_year = 2001+1 and d_moy =1) - ) - group by i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy), - v2 as( - select v1.s_company_name - ,v1.d_year, v1.d_moy - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1.s_store_name = v1_lag.s_store_name and - v1.s_store_name = v1_lead.s_store_name and - v1.s_company_name = v1_lag.s_company_name and - v1.s_company_name = v1_lead.s_company_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 2001 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, psum - limit 100; - --- end template query47.tpl query 54 in stream 4 --- start template query10.tpl query 55 in stream 4 -select /* TPC-DS query10.tpl 0.26 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3, - cd_dep_count, - count(*) cnt4, - cd_dep_employed_count, - count(*) cnt5, - cd_dep_college_count, - count(*) cnt6 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_county in ('Perry County','Allamakee County','Otsego County','Hand County','Garvin County') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 3 and 3+3) and - (exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 3 ANd 3+3) or - exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 3 and 3+3)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count -limit 100; - --- end template query10.tpl query 55 in stream 4 --- start template query70a.tpl query 56 in stream 4 -with /* TPC-DS query70a.tpl 0.34 */ results as -( select - sum(ss_net_profit) as total_sum ,s_state ,s_county, 0 as gstate, 0 as g_county - from - store_sales - ,date_dim d1 - ,store - where - d1.d_month_seq between 1200 and 1200 + 11 - and d1.d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - and s_state in - ( select s_state - from (select s_state as s_state, - rank() over ( partition by s_state order by sum(ss_net_profit) desc) as ranking - from store_sales, store, date_dim - where d_month_seq between 1200 and 1200 + 11 - and d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - group by s_state - ) tmp1 - where ranking <= 5) - group by s_state,s_county) , - results_rollup as -(select total_sum ,s_state ,s_county, 0 as g_state, 0 as g_county, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum,s_state, NULL as s_county, 0 as g_state, 1 as g_county, 1 as lochierarchy from results group by s_state - union - select sum(total_sum) as total_sum ,NULL as s_state ,NULL as s_county, 1 as g_state, 1 as g_county, 2 as lochierarchy from results) - select total_sum ,s_state ,s_county, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_county = 0 then s_state end - order by total_sum desc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then s_state end - ,rank_within_parent - limit 100; - --- end template query70a.tpl query 56 in stream 4 --- start template query23.tpl query 57 in stream 4 -with /* TPC-DS query23.tpl 0.68 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (2000,2000+1,2000+2,2000+3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (2000,2000+1,2000+2,2000+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * -from - max_store_sales)) - select sum(sales) - from (select cs_quantity*cs_list_price sales - from catalog_sales - ,date_dim - where d_year = 2000 - and d_moy = 7 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - union all - select ws_quantity*ws_list_price sales - from web_sales - ,date_dim - where d_year = 2000 - and d_moy = 7 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer)) - limit 100; -with /* TPC-DS query23.tpl 0.68 part2 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (2000,2000 + 1,2000 + 2,2000 + 3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (2000,2000+1,2000+2,2000+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * - from max_store_sales)) - select c_last_name,c_first_name,sales - from (select c_last_name,c_first_name,sum(cs_quantity*cs_list_price) sales - from catalog_sales - ,customer - ,date_dim - where d_year = 2000 - and d_moy = 7 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and cs_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name - union all - select c_last_name,c_first_name,sum(ws_quantity*ws_list_price) sales - from web_sales - ,customer - ,date_dim - where d_year = 2000 - and d_moy = 7 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and ws_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name) - order by c_last_name,c_first_name,sales - limit 100; - --- end template query23.tpl query 57 in stream 4 --- start template query7.tpl query 58 in stream 4 -select /* TPC-DS query7.tpl 0.2 */ i_item_id, - avg(ss_quantity) agg1, - avg(ss_list_price) agg2, - avg(ss_coupon_amt) agg3, - avg(ss_sales_price) agg4 - from store_sales, customer_demographics, date_dim, item, promotion - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_cdemo_sk = cd_demo_sk and - ss_promo_sk = p_promo_sk and - cd_gender = 'M' and - cd_marital_status = 'U' and - cd_education_status = 'Advanced Degree' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 1998 - group by i_item_id - order by i_item_id - limit 100; - --- end template query7.tpl query 58 in stream 4 --- start template query92.tpl query 59 in stream 4 -select /* TPC-DS query92.tpl 0.44 */ - sum(ws_ext_discount_amt) as "Excess Discount Amount" -from - web_sales - ,item - ,date_dim -where -i_manufact_id = 664 -and i_item_sk = ws_item_sk -and d_date between '2000-01-16' and - dateadd(day,90,cast('2000-01-16' as date)) -and d_date_sk = ws_sold_date_sk -and ws_ext_discount_amt - > ( - SELECT - 1.3 * avg(ws_ext_discount_amt) - FROM - web_sales - ,date_dim - WHERE - ws_item_sk = i_item_sk - and d_date between '2000-01-16' and - dateadd(day,90,cast('2000-01-16' as date)) - and d_date_sk = ws_sold_date_sk - ) -order by sum(ws_ext_discount_amt) -limit 100; - --- end template query92.tpl query 59 in stream 4 --- start template query54.tpl query 60 in stream 4 -with /* TPC-DS query54.tpl 0.81 */ my_customers as ( - select distinct c_customer_sk - , c_current_addr_sk - from - ( select cs_sold_date_sk sold_date_sk, - cs_bill_customer_sk customer_sk, - cs_item_sk item_sk - from catalog_sales - union all - select ws_sold_date_sk sold_date_sk, - ws_bill_customer_sk customer_sk, - ws_item_sk item_sk - from web_sales - ) cs_or_ws_sales, - item, - date_dim, - customer - where sold_date_sk = d_date_sk - and item_sk = i_item_sk - and i_category = 'Music' - and i_class = 'pop' - and c_customer_sk = cs_or_ws_sales.customer_sk - and d_moy = 3 - and d_year = 2001 - ) - , my_revenue as ( - select c_customer_sk, - sum(ss_ext_sales_price) as revenue - from my_customers, - store_sales, - customer_address, - store, - date_dim - where c_current_addr_sk = ca_address_sk - and ca_county = s_county - and ca_state = s_state - and ss_sold_date_sk = d_date_sk - and c_customer_sk = ss_customer_sk - and d_month_seq between (select distinct d_month_seq+1 - from date_dim where d_year = 2001 and d_moy = 3) - and (select distinct d_month_seq+3 - from date_dim where d_year = 2001 and d_moy = 3) - group by c_customer_sk - ) - , segments as - (select cast((revenue/50) as int) as segment - from my_revenue - ) - select segment, count(*) as num_customers, segment*50 as segment_base - from segments - group by segment - order by segment, num_customers - limit 100; - --- end template query54.tpl query 60 in stream 4 --- start template query82.tpl query 61 in stream 4 -select /* TPC-DS query82.tpl 0.67 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, store_sales - where i_current_price between 24 and 24+30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('2001-05-03' as date) and dateadd(day,60,cast('2001-05-03' as date)) - and i_manufact_id in (425,892,229,481) - and inv_quantity_on_hand between 100 and 500 - and ss_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query82.tpl query 61 in stream 4 --- start template query76.tpl query 62 in stream 4 -select /* TPC-DS query76.tpl 0.99 */ channel, col_name, d_year, d_qoy, i_category, COUNT(*) sales_cnt, SUM(ext_sales_price) sales_amt FROM ( - SELECT 'store' as channel, 'ss_store_sk' col_name, d_year, d_qoy, i_category, ss_ext_sales_price ext_sales_price - FROM store_sales, item, date_dim - WHERE ss_store_sk IS NULL - AND ss_sold_date_sk=d_date_sk - AND ss_item_sk=i_item_sk - UNION ALL - SELECT 'web' as channel, 'ws_bill_customer_sk' col_name, d_year, d_qoy, i_category, ws_ext_sales_price ext_sales_price - FROM web_sales, item, date_dim - WHERE ws_bill_customer_sk IS NULL - AND ws_sold_date_sk=d_date_sk - AND ws_item_sk=i_item_sk - UNION ALL - SELECT 'catalog' as channel, 'cs_ship_cdemo_sk' col_name, d_year, d_qoy, i_category, cs_ext_sales_price ext_sales_price - FROM catalog_sales, item, date_dim - WHERE cs_ship_cdemo_sk IS NULL - AND cs_sold_date_sk=d_date_sk - AND cs_item_sk=i_item_sk) foo -GROUP BY channel, col_name, d_year, d_qoy, i_category -ORDER BY channel, col_name, d_year, d_qoy, i_category -limit 100; - --- end template query76.tpl query 62 in stream 4 --- start template query80a.tpl query 63 in stream 4 -with /* TPC-DS query80a.tpl 0.6 */ ssr as - (select s_store_id as store_id, - sum(ss_ext_sales_price) as sales, - sum(coalesce(sr_return_amt, 0)) as returns, - sum(ss_net_profit - coalesce(sr_net_loss, 0)) as profit - from store_sales left outer join store_returns on - (ss_item_sk = sr_item_sk and ss_ticket_number = sr_ticket_number), - date_dim, - store, - item, - promotion - where ss_sold_date_sk = d_date_sk - and d_date between cast('1999-08-05' as date) - and dateadd(day,30,cast('1999-08-05' as date)) - and ss_store_sk = s_store_sk - and ss_item_sk = i_item_sk - and i_current_price > 50 - and ss_promo_sk = p_promo_sk - and p_channel_tv = 'N' - group by s_store_id) - , - csr as - (select cp_catalog_page_id as catalog_page_id, - sum(cs_ext_sales_price) as sales, - sum(coalesce(cr_return_amount, 0)) as returns, - sum(cs_net_profit - coalesce(cr_net_loss, 0)) as profit - from catalog_sales left outer join catalog_returns on - (cs_item_sk = cr_item_sk and cs_order_number = cr_order_number), - date_dim, - catalog_page, - item, - promotion - where cs_sold_date_sk = d_date_sk - and d_date between cast('1999-08-05' as date) - and dateadd(day,30,cast('1999-08-05' as date)) - and cs_catalog_page_sk = cp_catalog_page_sk - and cs_item_sk = i_item_sk - and i_current_price > 50 - and cs_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(ws_ext_sales_price) as sales, - sum(coalesce(wr_return_amt, 0)) as returns, - sum(ws_net_profit - coalesce(wr_net_loss, 0)) as profit - from web_sales left outer join web_returns on - (ws_item_sk = wr_item_sk and ws_order_number = wr_order_number), - date_dim, - web_site, - item, - promotion - where ws_sold_date_sk = d_date_sk - and d_date between cast('1999-08-05' as date) - and dateadd(day,30,cast('1999-08-05' as date)) - and ws_web_site_sk = web_site_sk - and ws_item_sk = i_item_sk - and i_current_price > 50 - and ws_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by web_site_id) -, -results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || store_id as id - , sales - , returns - , profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || catalog_page_id as id - , sales - , returns - , profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , profit - from wsr - ) x - group by channel, id) - - select channel - , id - , sales - , returns - , profit - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results - ) foo - order by channel, id - limit 100; - --- end template query80a.tpl query 63 in stream 4 --- start template query56.tpl query 64 in stream 4 -with /* TPC-DS query56.tpl 0.83 */ ss as ( - select i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where i_item_id in (select - i_item_id -from item -where i_color in ('lime','grey','navy')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 5 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - cs as ( - select i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('lime','grey','navy')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 5 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - ws as ( - select i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('lime','grey','navy')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 5 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id) - select i_item_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by total_sales, - i_item_id - limit 100; - --- end template query56.tpl query 64 in stream 4 --- start template query96.tpl query 65 in stream 4 -select /* TPC-DS query96.tpl 0.1 */ count(*) -from store_sales - ,household_demographics - ,time_dim, store -where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and household_demographics.hd_dep_count = 4 - and store.s_store_name = 'ese' -order by count(*) -limit 100; - --- end template query96.tpl query 65 in stream 4 --- start template query50.tpl query 66 in stream 4 -select /* TPC-DS query50.tpl 0.60 */ - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 30) and - (sr_returned_date_sk - ss_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 60) and - (sr_returned_date_sk - ss_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 90) and - (sr_returned_date_sk - ss_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - store_sales - ,store_returns - ,store - ,date_dim d1 - ,date_dim d2 -where - d2.d_year = 2002 -and d2.d_moy = 8 -and ss_ticket_number = sr_ticket_number -and ss_item_sk = sr_item_sk -and ss_sold_date_sk = d1.d_date_sk -and sr_returned_date_sk = d2.d_date_sk -and ss_customer_sk = sr_customer_sk -and ss_store_sk = s_store_sk -group by - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -order by s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -limit 100; - --- end template query50.tpl query 66 in stream 4 --- start template query85.tpl query 67 in stream 4 -select /* TPC-DS query85.tpl 0.33 */ substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) - from web_sales, web_returns, web_page, customer_demographics cd1, - customer_demographics cd2, customer_address, date_dim, reason - where ws_web_page_sk = wp_web_page_sk - and ws_item_sk = wr_item_sk - and ws_order_number = wr_order_number - and ws_sold_date_sk = d_date_sk and d_year = 2002 - and cd1.cd_demo_sk = wr_refunded_cdemo_sk - and cd2.cd_demo_sk = wr_returning_cdemo_sk - and ca_address_sk = wr_refunded_addr_sk - and r_reason_sk = wr_reason_sk - and - ( - ( - cd1.cd_marital_status = 'S' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'College' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 100.00 and 150.00 - ) - or - ( - cd1.cd_marital_status = 'U' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = '4 yr Degree' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 50.00 and 100.00 - ) - or - ( - cd1.cd_marital_status = 'W' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Unknown' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ca_country = 'United States' - and - ca_state in ('MI', 'OR', 'KY') - and ws_net_profit between 100 and 200 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('GA', 'MO', 'VA') - and ws_net_profit between 150 and 300 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('NE', 'MA', 'NC') - and ws_net_profit between 50 and 250 - ) - ) -group by r_reason_desc -order by substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) -limit 100; - --- end template query85.tpl query 67 in stream 4 --- start template query86a.tpl query 68 in stream 4 -with /* TPC-DS query86a.tpl 0.11 */ results as -( select sum(ws_net_paid) as total_sum, i_category, i_class, 0 as g_category, 0 as g_class - from - web_sales - ,date_dim d1 - ,item - where - d1.d_month_seq between 1211 and 1211+11 - and d1.d_date_sk = ws_sold_date_sk - and i_item_sk = ws_item_sk - group by i_category,i_class - ) , - - results_rollup as -( select total_sum ,i_category ,i_class, g_category, g_class, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum, i_category, NULL as i_class, 0 as g_category, 1 as g_class, 1 as lochierarchy from results group by i_category - union - select sum(total_sum) as total_sum, NULL as i_category, NULL as i_class, 1 as g_category, 1 as g_class, 2 as lochierarchy from results) - select - total_sum ,i_category ,i_class, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_class = 0 then i_category end - order by total_sum desc) as rank_within_parent - from - results_rollup - order by - lochierarchy desc, - case when lochierarchy = 0 then i_category end, - rank_within_parent - limit 100; - --- end template query86a.tpl query 68 in stream 4 --- start template query69.tpl query 69 in stream 4 -select /* TPC-DS query69.tpl 0.28 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_state in ('SD','UT','CO') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2003 and - d_moy between 2 and 2+2) and - (not exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2003 and - d_moy between 2 and 2+2) and - not exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2003 and - d_moy between 2 and 2+2)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - limit 100; - --- end template query69.tpl query 69 in stream 4 --- start template query68.tpl query 70 in stream 4 -select /* TPC-DS query68.tpl 0.95 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,extended_price - ,extended_tax - ,list_price - from (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_ext_sales_price) extended_price - ,sum(ss_ext_list_price) list_price - ,sum(ss_ext_tax) extended_tax - from store_sales - ,date_dim - ,store - ,household_demographics - ,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_dep_count = 2 or - household_demographics.hd_vehicle_count= -1) - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_city in ('Lakeside','Pleasant Valley') - group by ss_ticket_number - ,ss_customer_sk - ,ss_addr_sk,ca_city) dn - ,customer - ,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,ss_ticket_number - limit 100; - --- end template query68.tpl query 70 in stream 4 --- start template query1.tpl query 71 in stream 4 -with /* TPC-DS query1.tpl 0.12 */ customer_total_return as -(select sr_customer_sk as ctr_customer_sk -,sr_store_sk as ctr_store_sk -,sum(SR_STORE_CREDIT) as ctr_total_return -from store_returns -,date_dim -where sr_returned_date_sk = d_date_sk -and d_year =2000 -group by sr_customer_sk -,sr_store_sk) - select c_customer_id -from customer_total_return ctr1 -,store -,customer -where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 -from customer_total_return ctr2 -where ctr1.ctr_store_sk = ctr2.ctr_store_sk) -and s_store_sk = ctr1.ctr_store_sk -and s_state = 'NE' -and ctr1.ctr_customer_sk = c_customer_sk -order by c_customer_id -limit 100; - --- end template query1.tpl query 71 in stream 4 --- start template query12.tpl query 72 in stream 4 -select /* TPC-DS query12.tpl 0.64 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ws_ext_sales_price) as itemrevenue - ,sum(ws_ext_sales_price)*100/sum(sum(ws_ext_sales_price)) over - (partition by i_class) as revenueratio -from - web_sales - ,item - ,date_dim -where - ws_item_sk = i_item_sk - and i_category in ('Sports', 'Men', 'Home') - and ws_sold_date_sk = d_date_sk - and d_date between cast('2000-02-17' as date) - and dateadd(day,30,cast('2000-02-17' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query12.tpl query 72 in stream 4 --- start template query43.tpl query 73 in stream 4 -select /* TPC-DS query43.tpl 0.15 */ s_store_name, s_store_id, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from date_dim, store_sales, store - where d_date_sk = ss_sold_date_sk and - s_store_sk = ss_store_sk and - s_gmt_offset = -6 and - d_year = 2002 - group by s_store_name, s_store_id - order by s_store_name, s_store_id,sun_sales,mon_sales,tue_sales,wed_sales,thu_sales,fri_sales,sat_sales - limit 100; - --- end template query43.tpl query 73 in stream 4 --- start template query16.tpl query 74 in stream 4 -select /* TPC-DS query16.tpl 0.25 */ - count(distinct cs_order_number) as "order count" - ,sum(cs_ext_ship_cost) as "total shipping cost" - ,sum(cs_net_profit) as "total net profit" -from - catalog_sales cs1 - ,date_dim - ,customer_address - ,call_center -where - d_date between '2001-5-01' and - dateadd(day, 60, cast('2001-5-01' as date)) -and cs1.cs_ship_date_sk = d_date_sk -and cs1.cs_ship_addr_sk = ca_address_sk -and ca_state = 'NJ' -and cs1.cs_call_center_sk = cc_call_center_sk -and cc_county in ('Mobile County','Jefferson Davis Parish','Raleigh County','Jackson County', - 'Wadena County' -) -and exists (select * - from catalog_sales cs2 - where cs1.cs_order_number = cs2.cs_order_number - and cs1.cs_warehouse_sk <> cs2.cs_warehouse_sk) -and not exists(select * - from catalog_returns cr1 - where cs1.cs_order_number = cr1.cr_order_number) -order by count(distinct cs_order_number) -limit 100; - --- end template query16.tpl query 74 in stream 4 --- start template query4.tpl query 75 in stream 4 -with /* TPC-DS query4.tpl 0.93 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(((ss_ext_list_price-ss_ext_wholesale_cost-ss_ext_discount_amt)+ss_ext_sales_price)/2) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((cs_ext_list_price-cs_ext_wholesale_cost-cs_ext_discount_amt)+cs_ext_sales_price)/2) ) year_total - ,'c' sale_type - from customer - ,catalog_sales - ,date_dim - where c_customer_sk = cs_bill_customer_sk - and cs_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year -union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((ws_ext_list_price-ws_ext_wholesale_cost-ws_ext_discount_amt)+ws_ext_sales_price)/2) ) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_preferred_cust_flag - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_c_firstyear - ,year_total t_c_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_c_secyear.customer_id - and t_s_firstyear.customer_id = t_c_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_c_firstyear.sale_type = 'c' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_c_secyear.sale_type = 'c' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 2001 - and t_s_secyear.dyear = 2001+1 - and t_c_firstyear.dyear = 2001 - and t_c_secyear.dyear = 2001+1 - and t_w_firstyear.dyear = 2001 - and t_w_secyear.dyear = 2001+1 - and t_s_firstyear.year_total > 0 - and t_c_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_preferred_cust_flag -limit 100; - --- end template query4.tpl query 75 in stream 4 --- start template query25.tpl query 76 in stream 4 -select /* TPC-DS query25.tpl 0.9 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,avg(ss_net_profit) as store_sales_profit - ,avg(sr_net_loss) as store_returns_loss - ,avg(cs_net_profit) as catalog_sales_profit - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 1999 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 10 - and d2.d_year = 1999 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_moy between 4 and 10 - and d3.d_year = 1999 - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query25.tpl query 76 in stream 4 --- start template query20.tpl query 77 in stream 4 -select /* TPC-DS query20.tpl 0.65 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(cs_ext_sales_price) as itemrevenue - ,sum(cs_ext_sales_price)*100/sum(sum(cs_ext_sales_price)) over - (partition by i_class) as revenueratio - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and i_category in ('Electronics', 'Children', 'Home') - and cs_sold_date_sk = d_date_sk - and d_date between cast('2000-06-12' as date) - and dateadd(day,30,cast('2000-06-12' as date)) - group by i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - order by i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query20.tpl query 77 in stream 4 --- start template query65.tpl query 78 in stream 4 -select /* TPC-DS query65.tpl 0.71 */ - s_store_name, - i_item_desc, - sc.revenue, - i_current_price, - i_wholesale_cost, - i_brand - from store, item, - (select ss_store_sk, avg(revenue) as ave - from - (select ss_store_sk, ss_item_sk, - sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1200 and 1200+11 - group by ss_store_sk, ss_item_sk) sa - group by ss_store_sk) sb, - (select ss_store_sk, ss_item_sk, sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1200 and 1200+11 - group by ss_store_sk, ss_item_sk) sc - where sb.ss_store_sk = sc.ss_store_sk and - sc.revenue <= 0.1 * sb.ave and - s_store_sk = sc.ss_store_sk and - i_item_sk = sc.ss_item_sk - order by s_store_name, i_item_desc -limit 100; - --- end template query65.tpl query 78 in stream 4 --- start template query15.tpl query 79 in stream 4 -select /* TPC-DS query15.tpl 0.57 */ ca_zip - ,sum(cs_sales_price) - from catalog_sales - ,customer - ,customer_address - ,date_dim - where cs_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', - '85392', '85460', '80348', '81792') - or ca_state in ('CA','WA','GA') - or cs_sales_price > 500) - and cs_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 1998 - group by ca_zip - order by ca_zip - limit 100; - --- end template query15.tpl query 79 in stream 4 --- start template query98.tpl query 80 in stream 4 -select /* TPC-DS query98.tpl 0.32 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ss_ext_sales_price) as itemrevenue - ,sum(ss_ext_sales_price)*100/sum(sum(ss_ext_sales_price)) over - (partition by i_class) as revenueratio -from - store_sales - ,item - ,date_dim -where - ss_item_sk = i_item_sk - and i_category in ('Home', 'Sports', 'Jewelry') - and ss_sold_date_sk = d_date_sk - and d_date between cast('1998-03-06' as date) - and dateadd(day,30,cast('1998-03-06' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio; - --- end template query98.tpl query 80 in stream 4 --- start template query42.tpl query 81 in stream 4 -select /* TPC-DS query42.tpl 0.61 */ dt.d_year - ,item.i_category_id - ,item.i_category - ,sum(ss_ext_sales_price) - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=11 - and dt.d_year=2000 - group by dt.d_year - ,item.i_category_id - ,item.i_category - order by sum(ss_ext_sales_price) desc,dt.d_year - ,item.i_category_id - ,item.i_category -limit 100 ; - --- end template query42.tpl query 81 in stream 4 --- start template query26.tpl query 82 in stream 4 -select /* TPC-DS query26.tpl 0.85 */ i_item_id, - avg(cs_quantity) agg1, - avg(cs_list_price) agg2, - avg(cs_coupon_amt) agg3, - avg(cs_sales_price) agg4 - from catalog_sales, customer_demographics, date_dim, item, promotion - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd_demo_sk and - cs_promo_sk = p_promo_sk and - cd_gender = 'F' and - cd_marital_status = 'M' and - cd_education_status = 'Advanced Degree' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 2001 - group by i_item_id - order by i_item_id - limit 100; - --- end template query26.tpl query 82 in stream 4 --- start template query34.tpl query 83 in stream 4 -select /* TPC-DS query34.tpl 0.73 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (date_dim.d_dom between 1 and 3 or date_dim.d_dom between 25 and 28) - and (household_demographics.hd_buy_potential = '501-1000' or - household_demographics.hd_buy_potential = '0-500') - and household_demographics.hd_vehicle_count > 0 - and (case when household_demographics.hd_vehicle_count > 0 - then household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count - else null - end) > 1.2 - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_county in ('Bronx County','Mesa County','Salem County','Maverick County', - 'Harmon County','Luce County','Huron County','Terry County') - group by ss_ticket_number,ss_customer_sk) dn,customer - where ss_customer_sk = c_customer_sk - and cnt between 15 and 20 - order by c_last_name,c_first_name,c_salutation,c_preferred_cust_flag desc, ss_ticket_number; - --- end template query34.tpl query 83 in stream 4 --- start template query5a.tpl query 84 in stream 4 -with /* TPC-DS query5a.tpl 0.98 */ ssr as - (select s_store_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ss_store_sk as store_sk, - ss_sold_date_sk as date_sk, - ss_ext_sales_price as sales_price, - ss_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from store_sales - union all - select sr_store_sk as store_sk, - sr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - sr_return_amt as return_amt, - sr_net_loss as net_loss - from store_returns - ) salesreturns, - date_dim, - store - where date_sk = d_date_sk - and d_date between cast('1998-08-10' as date) - and dateadd(day,14,cast('1998-08-10' as date)) - and store_sk = s_store_sk - group by s_store_id) - , - csr as - (select cp_catalog_page_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select cs_catalog_page_sk as page_sk, - cs_sold_date_sk as date_sk, - cs_ext_sales_price as sales_price, - cs_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from catalog_sales - union all - select cr_catalog_page_sk as page_sk, - cr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - cr_return_amount as return_amt, - cr_net_loss as net_loss - from catalog_returns - ) salesreturns, - date_dim, - catalog_page - where date_sk = d_date_sk - and d_date between cast('1998-08-10' as date) - and dateadd(day,14,cast('1998-08-10' as date)) - and page_sk = cp_catalog_page_sk - group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ws_web_site_sk as wsr_web_site_sk, - ws_sold_date_sk as date_sk, - ws_ext_sales_price as sales_price, - ws_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from web_sales - union all - select ws_web_site_sk as wsr_web_site_sk, - wr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - wr_return_amt as return_amt, - wr_net_loss as net_loss - from web_returns left outer join web_sales on - ( wr_item_sk = ws_item_sk - and wr_order_number = ws_order_number) - ) salesreturns, - date_dim, - web_site - where date_sk = d_date_sk - and d_date between cast('1998-08-10' as date) - and dateadd(day,14,cast('1998-08-10' as date)) - and wsr_web_site_sk = web_site_sk - group by web_site_id) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || s_store_id as id - , sales - , returns - , (profit - profit_loss) as profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || cp_catalog_page_id as id - , sales - , returns - , (profit - profit_loss) as profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , (profit - profit_loss) as profit - from wsr - ) x - group by channel, id) - select channel, id, sales, returns, profit from ( - select channel, id, sales, returns, profit from results - union - select channel, null as id, sum(sales), sum(returns), sum(profit) from results group by channel - union - select null as channel, null as id, sum(sales), sum(returns), sum(profit) from results) foo -order by channel, id -limit 100; - --- end template query5a.tpl query 84 in stream 4 --- start template query87.tpl query 85 in stream 4 -select /* TPC-DS query87.tpl 0.77 */ count(*) -from ((select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1205 and 1205+11) - except - (select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1205 and 1205+11) - except - (select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1205 and 1205+11) -) cool_cust -; - --- end template query87.tpl query 85 in stream 4 --- start template query3.tpl query 86 in stream 4 -select /* TPC-DS query3.tpl 0.45 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_sales_price) sum_agg - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manufact_id = 556 - and dt.d_moy=12 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,sum_agg desc - ,brand_id - limit 100; - --- end template query3.tpl query 86 in stream 4 --- start template query64.tpl query 87 in stream 4 -with /* TPC-DS query64.tpl 0.20 */ cs_ui as - (select cs_item_sk - ,sum(cs_ext_list_price) as sale,sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit) as refund - from catalog_sales - ,catalog_returns - where cs_item_sk = cr_item_sk - and cs_order_number = cr_order_number - group by cs_item_sk - having sum(cs_ext_list_price)>2*sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit)), -cross_sales as - (select i_product_name product_name - ,i_item_sk item_sk - ,s_store_name store_name - ,s_zip store_zip - ,ad1.ca_street_number b_street_number - ,ad1.ca_street_name b_street_name - ,ad1.ca_city b_city - ,ad1.ca_zip b_zip - ,ad2.ca_street_number c_street_number - ,ad2.ca_street_name c_street_name - ,ad2.ca_city c_city - ,ad2.ca_zip c_zip - ,d1.d_year as syear - ,d2.d_year as fsyear - ,d3.d_year s2year - ,count(*) cnt - ,sum(ss_wholesale_cost) s1 - ,sum(ss_list_price) s2 - ,sum(ss_coupon_amt) s3 - FROM store_sales - ,store_returns - ,cs_ui - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,customer - ,customer_demographics cd1 - ,customer_demographics cd2 - ,promotion - ,household_demographics hd1 - ,household_demographics hd2 - ,customer_address ad1 - ,customer_address ad2 - ,income_band ib1 - ,income_band ib2 - ,item - WHERE ss_store_sk = s_store_sk AND - ss_sold_date_sk = d1.d_date_sk AND - ss_customer_sk = c_customer_sk AND - ss_cdemo_sk= cd1.cd_demo_sk AND - ss_hdemo_sk = hd1.hd_demo_sk AND - ss_addr_sk = ad1.ca_address_sk and - ss_item_sk = i_item_sk and - ss_item_sk = sr_item_sk and - ss_ticket_number = sr_ticket_number and - ss_item_sk = cs_ui.cs_item_sk and - c_current_cdemo_sk = cd2.cd_demo_sk AND - c_current_hdemo_sk = hd2.hd_demo_sk AND - c_current_addr_sk = ad2.ca_address_sk and - c_first_sales_date_sk = d2.d_date_sk and - c_first_shipto_date_sk = d3.d_date_sk and - ss_promo_sk = p_promo_sk and - hd1.hd_income_band_sk = ib1.ib_income_band_sk and - hd2.hd_income_band_sk = ib2.ib_income_band_sk and - cd1.cd_marital_status <> cd2.cd_marital_status and - i_color in ('blush','lemon','royal','chiffon','lace','lawn') and - i_current_price between 82 and 82 + 10 and - i_current_price between 82 + 1 and 82 + 15 -group by i_product_name - ,i_item_sk - ,s_store_name - ,s_zip - ,ad1.ca_street_number - ,ad1.ca_street_name - ,ad1.ca_city - ,ad1.ca_zip - ,ad2.ca_street_number - ,ad2.ca_street_name - ,ad2.ca_city - ,ad2.ca_zip - ,d1.d_year - ,d2.d_year - ,d3.d_year -) -select cs1.product_name - ,cs1.store_name - ,cs1.store_zip - ,cs1.b_street_number - ,cs1.b_street_name - ,cs1.b_city - ,cs1.b_zip - ,cs1.c_street_number - ,cs1.c_street_name - ,cs1.c_city - ,cs1.c_zip - ,cs1.syear - ,cs1.cnt - ,cs1.s1 as s11 - ,cs1.s2 as s21 - ,cs1.s3 as s31 - ,cs2.s1 as s12 - ,cs2.s2 as s22 - ,cs2.s3 as s32 - ,cs2.syear - ,cs2.cnt -from cross_sales cs1,cross_sales cs2 -where cs1.item_sk=cs2.item_sk and - cs1.syear = 2001 and - cs2.syear = 2001 + 1 and - cs2.cnt <= cs1.cnt and - cs1.store_name = cs2.store_name and - cs1.store_zip = cs2.store_zip -order by cs1.product_name - ,cs1.store_name - ,cs2.cnt - ,cs1.s1 - ,cs2.s1; - --- end template query64.tpl query 87 in stream 4 --- start template query31.tpl query 88 in stream 4 -with /* TPC-DS query31.tpl 0.50 */ ss as - (select ca_county,d_qoy, d_year,sum(ss_ext_sales_price) as store_sales - from store_sales,date_dim,customer_address - where ss_sold_date_sk = d_date_sk - and ss_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year), - ws as - (select ca_county,d_qoy, d_year,sum(ws_ext_sales_price) as web_sales - from web_sales,date_dim,customer_address - where ws_sold_date_sk = d_date_sk - and ws_bill_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year) - select - ss1.ca_county - ,ss1.d_year - ,ws2.web_sales/ws1.web_sales web_q1_q2_increase - ,ss2.store_sales/ss1.store_sales store_q1_q2_increase - ,ws3.web_sales/ws2.web_sales web_q2_q3_increase - ,ss3.store_sales/ss2.store_sales store_q2_q3_increase - from - ss ss1 - ,ss ss2 - ,ss ss3 - ,ws ws1 - ,ws ws2 - ,ws ws3 - where - ss1.d_qoy = 1 - and ss1.d_year = 2000 - and ss1.ca_county = ss2.ca_county - and ss2.d_qoy = 2 - and ss2.d_year = 2000 - and ss2.ca_county = ss3.ca_county - and ss3.d_qoy = 3 - and ss3.d_year = 2000 - and ss1.ca_county = ws1.ca_county - and ws1.d_qoy = 1 - and ws1.d_year = 2000 - and ws1.ca_county = ws2.ca_county - and ws2.d_qoy = 2 - and ws2.d_year = 2000 - and ws1.ca_county = ws3.ca_county - and ws3.d_qoy = 3 - and ws3.d_year =2000 - and case when ws1.web_sales > 0 then ws2.web_sales/ws1.web_sales else null end - > case when ss1.store_sales > 0 then ss2.store_sales/ss1.store_sales else null end - and case when ws2.web_sales > 0 then ws3.web_sales/ws2.web_sales else null end - > case when ss2.store_sales > 0 then ss3.store_sales/ss2.store_sales else null end - order by ss1.d_year; - --- end template query31.tpl query 88 in stream 4 --- start template query57.tpl query 89 in stream 4 -with /* TPC-DS query57.tpl 0.70 */ v1 as( - select i_category, i_brand, - cc_name, - d_year, d_moy, - sum(cs_sales_price) sum_sales, - avg(sum(cs_sales_price)) over - (partition by i_category, i_brand, - cc_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - cc_name - order by d_year, d_moy) rn - from item, catalog_sales, date_dim, call_center - where cs_item_sk = i_item_sk and - cs_sold_date_sk = d_date_sk and - cc_call_center_sk= cs_call_center_sk and - ( - d_year = 2000 or - ( d_year = 2000-1 and d_moy =12) or - ( d_year = 2000+1 and d_moy =1) - ) - group by i_category, i_brand, - cc_name , d_year, d_moy), - v2 as( - select v1.cc_name - ,v1.d_year - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1. cc_name = v1_lag. cc_name and - v1. cc_name = v1_lead. cc_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 2000 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, nsum - limit 100; - --- end template query57.tpl query 89 in stream 4 --- start template query30.tpl query 90 in stream 4 -with /* TPC-DS query30.tpl 0.75 */ customer_total_return as - (select wr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(wr_return_amt) as ctr_total_return - from web_returns - ,date_dim - ,customer_address - where wr_returned_date_sk = d_date_sk - and d_year =1999 - and wr_returning_addr_sk = ca_address_sk - group by wr_returning_customer_sk - ,ca_state) - select c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'CA' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return -limit 100; - --- end template query30.tpl query 90 in stream 4 --- start template query13.tpl query 91 in stream 4 -select /* TPC-DS query13.tpl 0.91 */ avg(ss_quantity) - ,avg(ss_ext_sales_price) - ,avg(ss_ext_wholesale_cost) - ,sum(ss_ext_wholesale_cost) - from store_sales - ,store - ,customer_demographics - ,household_demographics - ,customer_address - ,date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2001 - and((ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'W' - and cd_education_status = '2 yr Degree' - and ss_sales_price between 100.00 and 150.00 - and hd_dep_count = 3 - )or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'S' - and cd_education_status = 'Secondary' - and ss_sales_price between 50.00 and 100.00 - and hd_dep_count = 1 - ) or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'U' - and cd_education_status = 'Primary' - and ss_sales_price between 150.00 and 200.00 - and hd_dep_count = 1 - )) - and((ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('WI', 'MO', 'MN') - and ss_net_profit between 100 and 200 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('NV', 'HI', 'VA') - and ss_net_profit between 150 and 300 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('MT', 'OH', 'UT') - and ss_net_profit between 50 and 250 - )) -; - --- end template query13.tpl query 91 in stream 4 --- start template query94.tpl query 92 in stream 4 -select /* TPC-DS query94.tpl 0.17 */ - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2001-5-01' and - dateadd(day,60,cast('2001-5-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'WI' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and exists (select * - from web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) -and not exists(select * - from web_returns wr1 - where ws1.ws_order_number = wr1.wr_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query94.tpl query 92 in stream 4 --- start template query62.tpl query 93 in stream 4 -select /* TPC-DS query62.tpl 0.24 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 30) and - (ws_ship_date_sk - ws_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 60) and - (ws_ship_date_sk - ws_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 90) and - (ws_ship_date_sk - ws_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - web_sales - ,warehouse - ,ship_mode - ,web_site - ,date_dim -where - d_month_seq between 1177 and 1177 + 11 -and ws_ship_date_sk = d_date_sk -and ws_warehouse_sk = w_warehouse_sk -and ws_ship_mode_sk = sm_ship_mode_sk -and ws_web_site_sk = web_site_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -limit 100; - --- end template query62.tpl query 93 in stream 4 --- start template query49.tpl query 94 in stream 4 -select /* TPC-DS query49.tpl 0.48 */ channel, item, return_ratio, return_rank, currency_rank from - (select - 'web' as channel - ,web.item - ,web.return_ratio - ,web.return_rank - ,web.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select ws.ws_item_sk as item - ,(cast(sum(coalesce(wr.wr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(wr.wr_return_amt,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - web_sales ws left outer join web_returns wr - on (ws.ws_order_number = wr.wr_order_number and - ws.ws_item_sk = wr.wr_item_sk) - ,date_dim - where - wr.wr_return_amt > 10000 - and ws.ws_net_profit > 1 - and ws.ws_net_paid > 0 - and ws.ws_quantity > 0 - and ws_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 11 - group by ws.ws_item_sk - ) in_web - ) web - where - ( - web.return_rank <= 10 - or - web.currency_rank <= 10 - ) - union - select - 'catalog' as channel - ,catalog.item - ,catalog.return_ratio - ,catalog.return_rank - ,catalog.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select - cs.cs_item_sk as item - ,(cast(sum(coalesce(cr.cr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(cr.cr_return_amount,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - catalog_sales cs left outer join catalog_returns cr - on (cs.cs_order_number = cr.cr_order_number and - cs.cs_item_sk = cr.cr_item_sk) - ,date_dim - where - cr.cr_return_amount > 10000 - and cs.cs_net_profit > 1 - and cs.cs_net_paid > 0 - and cs.cs_quantity > 0 - and cs_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 11 - group by cs.cs_item_sk - ) in_cat - ) catalog - where - ( - catalog.return_rank <= 10 - or - catalog.currency_rank <=10 - ) - union - select - 'store' as channel - ,store.item - ,store.return_ratio - ,store.return_rank - ,store.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select sts.ss_item_sk as item - ,(cast(sum(coalesce(sr.sr_return_quantity,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(sr.sr_return_amt,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - store_sales sts left outer join store_returns sr - on (sts.ss_ticket_number = sr.sr_ticket_number and sts.ss_item_sk = sr.sr_item_sk) - ,date_dim - where - sr.sr_return_amt > 10000 - and sts.ss_net_profit > 1 - and sts.ss_net_paid > 0 - and sts.ss_quantity > 0 - and ss_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 11 - group by sts.ss_item_sk - ) in_store - ) store - where ( - store.return_rank <= 10 - or - store.currency_rank <= 10 - ) - ) - order by 1,4,5,2 - limit 100; - --- end template query49.tpl query 94 in stream 4 --- start template query11.tpl query 95 in stream 4 -with /* TPC-DS query11.tpl 0.51 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ss_ext_list_price-ss_ext_discount_amt) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ws_ext_list_price-ws_ext_discount_amt) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_birth_country - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 1998 - and t_s_secyear.dyear = 1998+1 - and t_w_firstyear.dyear = 1998 - and t_w_secyear.dyear = 1998+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else 0.0 end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else 0.0 end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_birth_country -limit 100; - --- end template query11.tpl query 95 in stream 4 --- start template query73.tpl query 96 in stream 4 -select /* TPC-DS query73.tpl 0.79 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_buy_potential = '>10000' or - household_demographics.hd_buy_potential = '0-500') - and household_demographics.hd_vehicle_count > 0 - and case when household_demographics.hd_vehicle_count > 0 then - household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count else null end > 1 - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_county in ('Harper County','Walker County','Kittitas County','Fairfield County') - group by ss_ticket_number,ss_customer_sk) dj,customer - where ss_customer_sk = c_customer_sk - and cnt between 1 and 5 - order by cnt desc, c_last_name asc; - --- end template query73.tpl query 96 in stream 4 --- start template query67a.tpl query 97 in stream 4 -with /* TPC-DS query67a.tpl 0.35 */ results as -( select i_category ,i_class ,i_brand ,i_product_name ,d_year ,d_qoy ,d_moy ,s_store_id - ,sum(coalesce(ss_sales_price*ss_quantity,0)) sumsales - from store_sales ,date_dim ,store ,item - where ss_sold_date_sk=d_date_sk - and ss_item_sk=i_item_sk - and ss_store_sk = s_store_sk - and d_month_seq between 1182 and 1182 + 11 - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy,s_store_id) - , - results_rollup as - (select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, s_store_id, sumsales - from results - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy - union all - select i_category, i_class, i_brand, i_product_name, d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year - union all - select i_category, i_class, i_brand, i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name - union all - select i_category, i_class, i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand - union all - select i_category, i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class - union all - select i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category - union all - select null i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results) - - select * -from (select i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rank() over (partition by i_category order by sumsales desc) rk - from results_rollup) dw2 -where rk <= 100 -order by i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rk -limit 100; - --- end template query67a.tpl query 97 in stream 4 --- start template query53.tpl query 98 in stream 4 -select /* TPC-DS query53.tpl 0.88 */ * from -(select i_manufact_id, -sum(ss_sales_price) sum_sales, -avg(sum(ss_sales_price)) over (partition by i_manufact_id) avg_quarterly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and -ss_sold_date_sk = d_date_sk and -ss_store_sk = s_store_sk and -d_month_seq in (1189,1189+1,1189+2,1189+3,1189+4,1189+5,1189+6,1189+7,1189+8,1189+9,1189+10,1189+11) and -((i_category in ('Books','Children','Electronics') and -i_class in ('personal','portable','reference','self-help') and -i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) -or(i_category in ('Women','Music','Men') and -i_class in ('accessories','classical','fragrances','pants') and -i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manufact_id, d_qoy ) tmp1 -where case when avg_quarterly_sales > 0 - then abs (sum_sales - avg_quarterly_sales)/ avg_quarterly_sales - else null end > 0.1 -order by avg_quarterly_sales, - sum_sales, - i_manufact_id -limit 100; - --- end template query53.tpl query 98 in stream 4 --- start template query9.tpl query 99 in stream 4 -select /* TPC-DS query9.tpl 0.49 */ case when (select count(*) - from store_sales - where ss_quantity between 1 and 20) > 63736023 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 1 and 20) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 1 and 20) end bucket1 , - case when (select count(*) - from store_sales - where ss_quantity between 21 and 40) > 118016562 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 21 and 40) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 21 and 40) end bucket2, - case when (select count(*) - from store_sales - where ss_quantity between 41 and 60) > 143037907 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 41 and 60) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 41 and 60) end bucket3, - case when (select count(*) - from store_sales - where ss_quantity between 61 and 80) > 64043924 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 61 and 80) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 61 and 80) end bucket4, - case when (select count(*) - from store_sales - where ss_quantity between 81 and 100) > 76593752 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 81 and 100) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 81 and 100) end bucket5 -from reason -where r_reason_sk = 1 -; - --- end template query9.tpl query 99 in stream 4 diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/3TB/queries/query_5.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/3TB/queries/query_5.sql deleted file mode 100644 index 99e7d844..00000000 --- a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/3TB/queries/query_5.sql +++ /dev/null @@ -1,5027 +0,0 @@ --- start template query73.tpl query 1 in stream 5 -select /* TPC-DS query73.tpl 0.79 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_buy_potential = '1001-5000' or - household_demographics.hd_buy_potential = 'Unknown') - and household_demographics.hd_vehicle_count > 0 - and case when household_demographics.hd_vehicle_count > 0 then - household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count else null end > 1 - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_county in ('Huron County','Essex County','San Miguel County','Wadena County') - group by ss_ticket_number,ss_customer_sk) dj,customer - where ss_customer_sk = c_customer_sk - and cnt between 1 and 5 - order by cnt desc, c_last_name asc; - --- end template query73.tpl query 1 in stream 5 --- start template query66.tpl query 2 in stream 5 -select /* TPC-DS query66.tpl 0.39 */ - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - ,sum(jan_sales) as jan_sales - ,sum(feb_sales) as feb_sales - ,sum(mar_sales) as mar_sales - ,sum(apr_sales) as apr_sales - ,sum(may_sales) as may_sales - ,sum(jun_sales) as jun_sales - ,sum(jul_sales) as jul_sales - ,sum(aug_sales) as aug_sales - ,sum(sep_sales) as sep_sales - ,sum(oct_sales) as oct_sales - ,sum(nov_sales) as nov_sales - ,sum(dec_sales) as dec_sales - ,sum(jan_sales/w_warehouse_sq_ft) as jan_sales_per_sq_foot - ,sum(feb_sales/w_warehouse_sq_ft) as feb_sales_per_sq_foot - ,sum(mar_sales/w_warehouse_sq_ft) as mar_sales_per_sq_foot - ,sum(apr_sales/w_warehouse_sq_ft) as apr_sales_per_sq_foot - ,sum(may_sales/w_warehouse_sq_ft) as may_sales_per_sq_foot - ,sum(jun_sales/w_warehouse_sq_ft) as jun_sales_per_sq_foot - ,sum(jul_sales/w_warehouse_sq_ft) as jul_sales_per_sq_foot - ,sum(aug_sales/w_warehouse_sq_ft) as aug_sales_per_sq_foot - ,sum(sep_sales/w_warehouse_sq_ft) as sep_sales_per_sq_foot - ,sum(oct_sales/w_warehouse_sq_ft) as oct_sales_per_sq_foot - ,sum(nov_sales/w_warehouse_sq_ft) as nov_sales_per_sq_foot - ,sum(dec_sales/w_warehouse_sq_ft) as dec_sales_per_sq_foot - ,sum(jan_net) as jan_net - ,sum(feb_net) as feb_net - ,sum(mar_net) as mar_net - ,sum(apr_net) as apr_net - ,sum(may_net) as may_net - ,sum(jun_net) as jun_net - ,sum(jul_net) as jul_net - ,sum(aug_net) as aug_net - ,sum(sep_net) as sep_net - ,sum(oct_net) as oct_net - ,sum(nov_net) as nov_net - ,sum(dec_net) as dec_net - from ( - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'FEDEX' || ',' || 'ZHOU' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then ws_ext_list_price* ws_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then ws_ext_list_price* ws_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then ws_ext_list_price* ws_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then ws_ext_list_price* ws_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then ws_ext_list_price* ws_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then ws_ext_list_price* ws_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then ws_ext_list_price* ws_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then ws_ext_list_price* ws_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then ws_ext_list_price* ws_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then ws_ext_list_price* ws_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then ws_ext_list_price* ws_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then ws_ext_list_price* ws_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then ws_net_paid * ws_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then ws_net_paid * ws_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then ws_net_paid * ws_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then ws_net_paid * ws_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then ws_net_paid * ws_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then ws_net_paid * ws_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then ws_net_paid * ws_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then ws_net_paid * ws_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then ws_net_paid * ws_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then ws_net_paid * ws_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then ws_net_paid * ws_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then ws_net_paid * ws_quantity else 0 end) as dec_net - from - web_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - ws_warehouse_sk = w_warehouse_sk - and ws_sold_date_sk = d_date_sk - and ws_sold_time_sk = t_time_sk - and ws_ship_mode_sk = sm_ship_mode_sk - and d_year = 1999 - and t_time between 47181 and 47181+28800 - and sm_carrier in ('FEDEX','ZHOU') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - union all - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'FEDEX' || ',' || 'ZHOU' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then cs_ext_list_price* cs_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then cs_ext_list_price* cs_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then cs_ext_list_price* cs_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then cs_ext_list_price* cs_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then cs_ext_list_price* cs_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then cs_ext_list_price* cs_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then cs_ext_list_price* cs_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then cs_ext_list_price* cs_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then cs_ext_list_price* cs_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then cs_ext_list_price* cs_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then cs_ext_list_price* cs_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then cs_ext_list_price* cs_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then cs_net_profit * cs_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then cs_net_profit * cs_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then cs_net_profit * cs_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then cs_net_profit * cs_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then cs_net_profit * cs_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then cs_net_profit * cs_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then cs_net_profit * cs_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then cs_net_profit * cs_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then cs_net_profit * cs_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then cs_net_profit * cs_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then cs_net_profit * cs_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then cs_net_profit * cs_quantity else 0 end) as dec_net - from - catalog_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and cs_sold_time_sk = t_time_sk - and cs_ship_mode_sk = sm_ship_mode_sk - and d_year = 1999 - and t_time between 47181 AND 47181+28800 - and sm_carrier in ('FEDEX','ZHOU') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - ) x - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - order by w_warehouse_name - limit 100; - --- end template query66.tpl query 2 in stream 5 --- start template query4.tpl query 3 in stream 5 -with /* TPC-DS query4.tpl 0.93 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(((ss_ext_list_price-ss_ext_wholesale_cost-ss_ext_discount_amt)+ss_ext_sales_price)/2) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((cs_ext_list_price-cs_ext_wholesale_cost-cs_ext_discount_amt)+cs_ext_sales_price)/2) ) year_total - ,'c' sale_type - from customer - ,catalog_sales - ,date_dim - where c_customer_sk = cs_bill_customer_sk - and cs_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year -union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((ws_ext_list_price-ws_ext_wholesale_cost-ws_ext_discount_amt)+ws_ext_sales_price)/2) ) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_login - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_c_firstyear - ,year_total t_c_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_c_secyear.customer_id - and t_s_firstyear.customer_id = t_c_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_c_firstyear.sale_type = 'c' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_c_secyear.sale_type = 'c' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 1998 - and t_s_secyear.dyear = 1998+1 - and t_c_firstyear.dyear = 1998 - and t_c_secyear.dyear = 1998+1 - and t_w_firstyear.dyear = 1998 - and t_w_secyear.dyear = 1998+1 - and t_s_firstyear.year_total > 0 - and t_c_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_login -limit 100; - --- end template query4.tpl query 3 in stream 5 --- start template query17.tpl query 4 in stream 5 -select /* TPC-DS query17.tpl 0.41 */ i_item_id - ,i_item_desc - ,s_state - ,count(ss_quantity) as store_sales_quantitycount - ,avg(ss_quantity) as store_sales_quantityave - ,stddev_samp(ss_quantity) as store_sales_quantitystdev - ,stddev_samp(ss_quantity)/avg(ss_quantity) as store_sales_quantitycov - ,count(sr_return_quantity) as store_returns_quantitycount - ,avg(sr_return_quantity) as store_returns_quantityave - ,stddev_samp(sr_return_quantity) as store_returns_quantitystdev - ,stddev_samp(sr_return_quantity)/avg(sr_return_quantity) as store_returns_quantitycov - ,count(cs_quantity) as catalog_sales_quantitycount ,avg(cs_quantity) as catalog_sales_quantityave - ,stddev_samp(cs_quantity) as catalog_sales_quantitystdev - ,stddev_samp(cs_quantity)/avg(cs_quantity) as catalog_sales_quantitycov - from store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where d1.d_quarter_name = '1998Q1' - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_quarter_name in ('1998Q1','1998Q2','1998Q3') - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_quarter_name in ('1998Q1','1998Q2','1998Q3') - group by i_item_id - ,i_item_desc - ,s_state - order by i_item_id - ,i_item_desc - ,s_state -limit 100; - --- end template query17.tpl query 4 in stream 5 --- start template query60.tpl query 5 in stream 5 -with /* TPC-DS query60.tpl 0.29 */ ss as ( - select - i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Men')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 10 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id), - cs as ( - select - i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Men')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 10 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id), - ws as ( - select - i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Men')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 10 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id) - select - i_item_id -,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by i_item_id - ,total_sales - limit 100; - --- end template query60.tpl query 5 in stream 5 --- start template query98.tpl query 6 in stream 5 -select /* TPC-DS query98.tpl 0.32 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ss_ext_sales_price) as itemrevenue - ,sum(ss_ext_sales_price)*100/sum(sum(ss_ext_sales_price)) over - (partition by i_class) as revenueratio -from - store_sales - ,item - ,date_dim -where - ss_item_sk = i_item_sk - and i_category in ('Home', 'Women', 'Shoes') - and ss_sold_date_sk = d_date_sk - and d_date between cast('2000-03-18' as date) - and dateadd(day,30,cast('2000-03-18' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio; - --- end template query98.tpl query 6 in stream 5 --- start template query88.tpl query 7 in stream 5 -select /* TPC-DS query88.tpl 0.66 */ * -from - (select count(*) h8_30_to_9 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2)) - and store.s_store_name = 'ese') s1, - (select count(*) h9_to_9_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2)) - and store.s_store_name = 'ese') s2, - (select count(*) h9_30_to_10 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2)) - and store.s_store_name = 'ese') s3, - (select count(*) h10_to_10_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2)) - and store.s_store_name = 'ese') s4, - (select count(*) h10_30_to_11 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2)) - and store.s_store_name = 'ese') s5, - (select count(*) h11_to_11_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2)) - and store.s_store_name = 'ese') s6, - (select count(*) h11_30_to_12 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2)) - and store.s_store_name = 'ese') s7, - (select count(*) h12_to_12_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 12 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2)) - and store.s_store_name = 'ese') s8 -; - --- end template query88.tpl query 7 in stream 5 --- start template query2.tpl query 8 in stream 5 -with /* TPC-DS query2.tpl 0.84 */ wscs as - (select sold_date_sk - ,sales_price - from (select ws_sold_date_sk sold_date_sk - ,ws_ext_sales_price sales_price - from web_sales - union all - select cs_sold_date_sk sold_date_sk - ,cs_ext_sales_price sales_price - from catalog_sales)), - wswscs as - (select d_week_seq, - sum(case when (d_day_name='Sunday') then sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then sales_price else null end) sat_sales - from wscs - ,date_dim - where d_date_sk = sold_date_sk - group by d_week_seq) - select d_week_seq1 - ,round(sun_sales1/sun_sales2,2) - ,round(mon_sales1/mon_sales2,2) - ,round(tue_sales1/tue_sales2,2) - ,round(wed_sales1/wed_sales2,2) - ,round(thu_sales1/thu_sales2,2) - ,round(fri_sales1/fri_sales2,2) - ,round(sat_sales1/sat_sales2,2) - from - (select wswscs.d_week_seq d_week_seq1 - ,sun_sales sun_sales1 - ,mon_sales mon_sales1 - ,tue_sales tue_sales1 - ,wed_sales wed_sales1 - ,thu_sales thu_sales1 - ,fri_sales fri_sales1 - ,sat_sales sat_sales1 - from wswscs,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 2001) y, - (select wswscs.d_week_seq d_week_seq2 - ,sun_sales sun_sales2 - ,mon_sales mon_sales2 - ,tue_sales tue_sales2 - ,wed_sales wed_sales2 - ,thu_sales thu_sales2 - ,fri_sales fri_sales2 - ,sat_sales sat_sales2 - from wswscs - ,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 2001+1) z - where d_week_seq1=d_week_seq2-53 - order by d_week_seq1; - --- end template query2.tpl query 8 in stream 5 --- start template query19.tpl query 9 in stream 5 -select /* TPC-DS query19.tpl 0.8 */ i_brand_id brand_id, i_brand brand, i_manufact_id, i_manufact, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item,customer,customer_address,store - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=44 - and d_moy=11 - and d_year=1998 - and ss_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and substring(ca_zip,1,5) <> substring(s_zip,1,5) - and ss_store_sk = s_store_sk - group by i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact - order by ext_price desc - ,i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact -limit 100 ; - --- end template query19.tpl query 9 in stream 5 --- start template query65.tpl query 10 in stream 5 -select /* TPC-DS query65.tpl 0.71 */ - s_store_name, - i_item_desc, - sc.revenue, - i_current_price, - i_wholesale_cost, - i_brand - from store, item, - (select ss_store_sk, avg(revenue) as ave - from - (select ss_store_sk, ss_item_sk, - sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1179 and 1179+11 - group by ss_store_sk, ss_item_sk) sa - group by ss_store_sk) sb, - (select ss_store_sk, ss_item_sk, sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1179 and 1179+11 - group by ss_store_sk, ss_item_sk) sc - where sb.ss_store_sk = sc.ss_store_sk and - sc.revenue <= 0.1 * sb.ave and - s_store_sk = sc.ss_store_sk and - i_item_sk = sc.ss_item_sk - order by s_store_name, i_item_desc -limit 100; - --- end template query65.tpl query 10 in stream 5 --- start template query3.tpl query 11 in stream 5 -select /* TPC-DS query3.tpl 0.45 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_net_profit) sum_agg - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manufact_id = 128 - and dt.d_moy=11 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,sum_agg desc - ,brand_id - limit 100; - --- end template query3.tpl query 11 in stream 5 --- start template query79.tpl query 12 in stream 5 -select /* TPC-DS query79.tpl 0.89 */ - c_last_name,c_first_name,substring(s_city,1,30),ss_ticket_number,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,store.s_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (household_demographics.hd_dep_count = 6 or household_demographics.hd_vehicle_count > -1) - and date_dim.d_dow = 1 - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_number_employees between 200 and 295 - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,store.s_city) ms,customer - where ss_customer_sk = c_customer_sk - order by c_last_name,c_first_name,substring(s_city,1,30), profit -limit 100; - --- end template query79.tpl query 12 in stream 5 --- start template query13.tpl query 13 in stream 5 -select /* TPC-DS query13.tpl 0.91 */ avg(ss_quantity) - ,avg(ss_ext_sales_price) - ,avg(ss_ext_wholesale_cost) - ,sum(ss_ext_wholesale_cost) - from store_sales - ,store - ,customer_demographics - ,household_demographics - ,customer_address - ,date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2001 - and((ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'D' - and cd_education_status = 'College' - and ss_sales_price between 100.00 and 150.00 - and hd_dep_count = 3 - )or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'U' - and cd_education_status = 'Unknown' - and ss_sales_price between 50.00 and 100.00 - and hd_dep_count = 1 - ) or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'M' - and cd_education_status = 'Advanced Degree' - and ss_sales_price between 150.00 and 200.00 - and hd_dep_count = 1 - )) - and((ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('PA', 'CO', 'GA') - and ss_net_profit between 100 and 200 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('MO', 'IL', 'AR') - and ss_net_profit between 150 and 300 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('KY', 'VA', 'OK') - and ss_net_profit between 50 and 250 - )) -; - --- end template query13.tpl query 13 in stream 5 --- start template query21.tpl query 14 in stream 5 -select /* TPC-DS query21.tpl 0.14 */ * - from(select w_warehouse_name - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('2001-05-12' as date)) - then inv_quantity_on_hand - else 0 end) as inv_before - ,sum(case when (cast(d_date as date) >= cast ('2001-05-12' as date)) - then inv_quantity_on_hand - else 0 end) as inv_after - from inventory - ,warehouse - ,item - ,date_dim - where i_current_price between 0.99 and 1.49 - and i_item_sk = inv_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('2001-05-12' as date)) - and dateadd(day,30,cast ('2001-05-12' as date)) - group by w_warehouse_name, i_item_id) x - where (case when inv_before > 0 - then inv_after / inv_before - else null - end) between 2.0/3.0 and 3.0/2.0 - order by w_warehouse_name - ,i_item_id - limit 100; - --- end template query21.tpl query 14 in stream 5 --- start template query51.tpl query 15 in stream 5 -WITH /* TPC-DS query51.tpl 0.46 */ web_v1 as ( -select - ws_item_sk item_sk, d_date, - sum(sum(ws_sales_price)) - over (partition by ws_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from web_sales - ,date_dim -where ws_sold_date_sk=d_date_sk - and d_month_seq between 1184 and 1184+11 - and ws_item_sk is not NULL -group by ws_item_sk, d_date), -store_v1 as ( -select - ss_item_sk item_sk, d_date, - sum(sum(ss_sales_price)) - over (partition by ss_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from store_sales - ,date_dim -where ss_sold_date_sk=d_date_sk - and d_month_seq between 1184 and 1184+11 - and ss_item_sk is not NULL -group by ss_item_sk, d_date) - select * -from (select item_sk - ,d_date - ,web_sales - ,store_sales - ,max(web_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) web_cumulative - ,max(store_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) store_cumulative - from (select case when web.item_sk is not null then web.item_sk else store.item_sk end item_sk - ,case when web.d_date is not null then web.d_date else store.d_date end d_date - ,web.cume_sales web_sales - ,store.cume_sales store_sales - from web_v1 web full outer join store_v1 store on (web.item_sk = store.item_sk - and web.d_date = store.d_date) - )x )y -where web_cumulative > store_cumulative -order by item_sk - ,d_date -limit 100; - --- end template query51.tpl query 15 in stream 5 --- start template query6.tpl query 16 in stream 5 -select /* TPC-DS query6.tpl 0.58 */ a.ca_state state, count(*) cnt - from customer_address a - ,customer c - ,store_sales s - ,date_dim d - ,item i - where a.ca_address_sk = c.c_current_addr_sk - and c.c_customer_sk = s.ss_customer_sk - and s.ss_sold_date_sk = d.d_date_sk - and s.ss_item_sk = i.i_item_sk - and d.d_month_seq = - (select distinct (d_month_seq) - from date_dim - where d_year = 2000 - and d_moy = 2 ) - and i.i_current_price > 1.2 * - (select avg(j.i_current_price) - from item j - where j.i_category = i.i_category) - group by a.ca_state - having count(*) >= 10 - order by cnt, a.ca_state - limit 100; - --- end template query6.tpl query 16 in stream 5 --- start template query49.tpl query 17 in stream 5 -select /* TPC-DS query49.tpl 0.48 */ channel, item, return_ratio, return_rank, currency_rank from - (select - 'web' as channel - ,web.item - ,web.return_ratio - ,web.return_rank - ,web.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select ws.ws_item_sk as item - ,(cast(sum(coalesce(wr.wr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(wr.wr_return_amt,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - web_sales ws left outer join web_returns wr - on (ws.ws_order_number = wr.wr_order_number and - ws.ws_item_sk = wr.wr_item_sk) - ,date_dim - where - wr.wr_return_amt > 10000 - and ws.ws_net_profit > 1 - and ws.ws_net_paid > 0 - and ws.ws_quantity > 0 - and ws_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 11 - group by ws.ws_item_sk - ) in_web - ) web - where - ( - web.return_rank <= 10 - or - web.currency_rank <= 10 - ) - union - select - 'catalog' as channel - ,catalog.item - ,catalog.return_ratio - ,catalog.return_rank - ,catalog.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select - cs.cs_item_sk as item - ,(cast(sum(coalesce(cr.cr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(cr.cr_return_amount,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - catalog_sales cs left outer join catalog_returns cr - on (cs.cs_order_number = cr.cr_order_number and - cs.cs_item_sk = cr.cr_item_sk) - ,date_dim - where - cr.cr_return_amount > 10000 - and cs.cs_net_profit > 1 - and cs.cs_net_paid > 0 - and cs.cs_quantity > 0 - and cs_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 11 - group by cs.cs_item_sk - ) in_cat - ) catalog - where - ( - catalog.return_rank <= 10 - or - catalog.currency_rank <=10 - ) - union - select - 'store' as channel - ,store.item - ,store.return_ratio - ,store.return_rank - ,store.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select sts.ss_item_sk as item - ,(cast(sum(coalesce(sr.sr_return_quantity,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(sr.sr_return_amt,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - store_sales sts left outer join store_returns sr - on (sts.ss_ticket_number = sr.sr_ticket_number and sts.ss_item_sk = sr.sr_item_sk) - ,date_dim - where - sr.sr_return_amt > 10000 - and sts.ss_net_profit > 1 - and sts.ss_net_paid > 0 - and sts.ss_quantity > 0 - and ss_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 11 - group by sts.ss_item_sk - ) in_store - ) store - where ( - store.return_rank <= 10 - or - store.currency_rank <= 10 - ) - ) - order by 1,4,5,2 - limit 100; - --- end template query49.tpl query 17 in stream 5 --- start template query52.tpl query 18 in stream 5 -select /* TPC-DS query52.tpl 0.59 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_sales_price) ext_price - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=11 - and dt.d_year=1999 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,ext_price desc - ,brand_id -limit 100 ; - --- end template query52.tpl query 18 in stream 5 --- start template query7.tpl query 19 in stream 5 -select /* TPC-DS query7.tpl 0.2 */ i_item_id, - avg(ss_quantity) agg1, - avg(ss_list_price) agg2, - avg(ss_coupon_amt) agg3, - avg(ss_sales_price) agg4 - from store_sales, customer_demographics, date_dim, item, promotion - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_cdemo_sk = cd_demo_sk and - ss_promo_sk = p_promo_sk and - cd_gender = 'F' and - cd_marital_status = 'M' and - cd_education_status = '4 yr Degree' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 1998 - group by i_item_id - order by i_item_id - limit 100; - --- end template query7.tpl query 19 in stream 5 --- start template query56.tpl query 20 in stream 5 -with /* TPC-DS query56.tpl 0.83 */ ss as ( - select i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where i_item_id in (select - i_item_id -from item -where i_color in ('dark','lavender','beige')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 1 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -7 - group by i_item_id), - cs as ( - select i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('dark','lavender','beige')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 1 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -7 - group by i_item_id), - ws as ( - select i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('dark','lavender','beige')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 1 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -7 - group by i_item_id) - select i_item_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by total_sales, - i_item_id - limit 100; - --- end template query56.tpl query 20 in stream 5 --- start template query36a.tpl query 21 in stream 5 -with /* TPC-DS query36a.tpl 0.21 */ results as - (select - sum(ss_net_profit) as ss_net_profit, sum(ss_ext_sales_price) as ss_ext_sales_price, - sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin - ,i_category - ,i_class - ,0 as g_category, 0 as g_class - from - store_sales - ,date_dim d1 - ,item - ,store - where - d1.d_year = 2000 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and s_state in ('SC','GA','MI','MI', - 'TN','IN','OH','NE') - group by i_category,i_class) - , - results_rollup as - (select gross_margin ,i_category ,i_class,0 as t_category, 0 as t_class, 0 as lochierarchy from results - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - i_category, NULL AS i_class, 0 as t_category, 1 as t_class, 1 as lochierarchy from results group by i_category - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - NULL AS i_category ,NULL AS i_class, 1 as t_category, 1 as t_class, 2 as lochierarchy from results) - select - gross_margin ,i_category ,i_class, lochierarchy,rank() over ( - partition by lochierarchy, case when t_class = 0 then i_category end - order by gross_margin asc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then i_category end - ,rank_within_parent - limit 100; - --- end template query36a.tpl query 21 in stream 5 --- start template query77a.tpl query 22 in stream 5 -with /* TPC-DS query77a.tpl 0.78 */ ss as - (select s_store_sk, - sum(ss_ext_sales_price) as sales, - sum(ss_net_profit) as profit - from store_sales, - date_dim, - store - where ss_sold_date_sk = d_date_sk - and d_date between cast('1998-08-26' as date) - and dateadd(day,30,cast('1998-08-26' as date)) - and ss_store_sk = s_store_sk - group by s_store_sk) - , - sr as - (select s_store_sk, - sum(sr_return_amt) as returns, - sum(sr_net_loss) as profit_loss - from store_returns, - date_dim, - store - where sr_returned_date_sk = d_date_sk - and d_date between cast('1998-08-26' as date) - and dateadd(day,30,cast('1998-08-26' as date)) - and sr_store_sk = s_store_sk - group by s_store_sk), - cs as - (select cs_call_center_sk, - sum(cs_ext_sales_price) as sales, - sum(cs_net_profit) as profit - from catalog_sales, - date_dim - where cs_sold_date_sk = d_date_sk - and d_date between cast('1998-08-26' as date) - and dateadd(day,30,cast('1998-08-26' as date)) - group by cs_call_center_sk - ), - cr as - (select cr_call_center_sk, - sum(cr_return_amount) as returns, - sum(cr_net_loss) as profit_loss - from catalog_returns, - date_dim - where cr_returned_date_sk = d_date_sk - and d_date between cast('1998-08-26' as date) - and dateadd(day,30,cast('1998-08-26' as date)) - group by cr_call_center_sk), - ws as - ( select wp_web_page_sk, - sum(ws_ext_sales_price) as sales, - sum(ws_net_profit) as profit - from web_sales, - date_dim, - web_page - where ws_sold_date_sk = d_date_sk - and d_date between cast('1998-08-26' as date) - and dateadd(day,30,cast('1998-08-26' as date)) - and ws_web_page_sk = wp_web_page_sk - group by wp_web_page_sk), - wr as - (select wp_web_page_sk, - sum(wr_return_amt) as returns, - sum(wr_net_loss) as profit_loss - from web_returns, - date_dim, - web_page - where wr_returned_date_sk = d_date_sk - and d_date between cast('1998-08-26' as date) - and dateadd(day,30,cast('1998-08-26' as date)) - and wr_web_page_sk = wp_web_page_sk - group by wp_web_page_sk) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , ss.s_store_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ss left join sr - on ss.s_store_sk = sr.s_store_sk - union all - select 'catalog channel' as channel - , cs_call_center_sk as id - , sales - , returns - , (profit - profit_loss) as profit - from cs - , cr - union all - select 'web channel' as channel - , ws.wp_web_page_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ws left join wr - on ws.wp_web_page_sk = wr.wp_web_page_sk - ) x - group by channel, id ) - - select * - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results -) foo -order by channel, id - limit 100; - --- end template query77a.tpl query 22 in stream 5 --- start template query90.tpl query 23 in stream 5 -select /* TPC-DS query90.tpl 0.40 */ cast(amc as decimal(15,4))/cast(pmc as decimal(15,4)) am_pm_ratio - from ( select count(*) amc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 9 and 9+1 - and household_demographics.hd_dep_count = 4 - and web_page.wp_char_count between 5000 and 5200) at, - ( select count(*) pmc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 14 and 14+1 - and household_demographics.hd_dep_count = 4 - and web_page.wp_char_count between 5000 and 5200) pt - order by am_pm_ratio - limit 100; - --- end template query90.tpl query 23 in stream 5 --- start template query76.tpl query 24 in stream 5 -select /* TPC-DS query76.tpl 0.99 */ channel, col_name, d_year, d_qoy, i_category, COUNT(*) sales_cnt, SUM(ext_sales_price) sales_amt FROM ( - SELECT 'store' as channel, 'ss_addr_sk' col_name, d_year, d_qoy, i_category, ss_ext_sales_price ext_sales_price - FROM store_sales, item, date_dim - WHERE ss_addr_sk IS NULL - AND ss_sold_date_sk=d_date_sk - AND ss_item_sk=i_item_sk - UNION ALL - SELECT 'web' as channel, 'ws_ship_mode_sk' col_name, d_year, d_qoy, i_category, ws_ext_sales_price ext_sales_price - FROM web_sales, item, date_dim - WHERE ws_ship_mode_sk IS NULL - AND ws_sold_date_sk=d_date_sk - AND ws_item_sk=i_item_sk - UNION ALL - SELECT 'catalog' as channel, 'cs_ship_addr_sk' col_name, d_year, d_qoy, i_category, cs_ext_sales_price ext_sales_price - FROM catalog_sales, item, date_dim - WHERE cs_ship_addr_sk IS NULL - AND cs_sold_date_sk=d_date_sk - AND cs_item_sk=i_item_sk) foo -GROUP BY channel, col_name, d_year, d_qoy, i_category -ORDER BY channel, col_name, d_year, d_qoy, i_category -limit 100; - --- end template query76.tpl query 24 in stream 5 --- start template query58.tpl query 25 in stream 5 -with /* TPC-DS query58.tpl 0.19 */ ss_items as - (select i_item_id item_id - ,sum(ss_ext_sales_price) ss_item_rev - from store_sales - ,item - ,date_dim - where ss_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '1998-03-18')) - and ss_sold_date_sk = d_date_sk - group by i_item_id), - cs_items as - (select i_item_id item_id - ,sum(cs_ext_sales_price) cs_item_rev - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '1998-03-18')) - and cs_sold_date_sk = d_date_sk - group by i_item_id), - ws_items as - (select i_item_id item_id - ,sum(ws_ext_sales_price) ws_item_rev - from web_sales - ,item - ,date_dim - where ws_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq =(select d_week_seq - from date_dim - where d_date = '1998-03-18')) - and ws_sold_date_sk = d_date_sk - group by i_item_id) - select ss_items.item_id - ,ss_item_rev - ,ss_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ss_dev - ,cs_item_rev - ,cs_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 cs_dev - ,ws_item_rev - ,ws_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ws_dev - ,(ss_item_rev+cs_item_rev+ws_item_rev)/3 average - from ss_items,cs_items,ws_items - where ss_items.item_id=cs_items.item_id - and ss_items.item_id=ws_items.item_id - and ss_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - and ss_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and cs_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and cs_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and ws_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and ws_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - order by item_id - ,ss_item_rev - limit 100; - --- end template query58.tpl query 25 in stream 5 --- start template query71.tpl query 26 in stream 5 -select /* TPC-DS query71.tpl 0.72 */ i_brand_id brand_id, i_brand brand,t_hour,t_minute, - sum(ext_price) ext_price - from item, (select ws_ext_sales_price as ext_price, - ws_sold_date_sk as sold_date_sk, - ws_item_sk as sold_item_sk, - ws_sold_time_sk as time_sk - from web_sales,date_dim - where d_date_sk = ws_sold_date_sk - and d_moy=12 - and d_year=1999 - union all - select cs_ext_sales_price as ext_price, - cs_sold_date_sk as sold_date_sk, - cs_item_sk as sold_item_sk, - cs_sold_time_sk as time_sk - from catalog_sales,date_dim - where d_date_sk = cs_sold_date_sk - and d_moy=12 - and d_year=1999 - union all - select ss_ext_sales_price as ext_price, - ss_sold_date_sk as sold_date_sk, - ss_item_sk as sold_item_sk, - ss_sold_time_sk as time_sk - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - and d_moy=12 - and d_year=1999 - ) tmp,time_dim - where - sold_item_sk = i_item_sk - and i_manager_id=1 - and time_sk = t_time_sk - and (t_meal_time = 'breakfast' or t_meal_time = 'dinner') - group by i_brand, i_brand_id,t_hour,t_minute - order by ext_price desc, i_brand_id - ; - --- end template query71.tpl query 26 in stream 5 --- start template query80a.tpl query 27 in stream 5 -with /* TPC-DS query80a.tpl 0.6 */ ssr as - (select s_store_id as store_id, - sum(ss_ext_sales_price) as sales, - sum(coalesce(sr_return_amt, 0)) as returns, - sum(ss_net_profit - coalesce(sr_net_loss, 0)) as profit - from store_sales left outer join store_returns on - (ss_item_sk = sr_item_sk and ss_ticket_number = sr_ticket_number), - date_dim, - store, - item, - promotion - where ss_sold_date_sk = d_date_sk - and d_date between cast('1999-08-03' as date) - and dateadd(day,30,cast('1999-08-03' as date)) - and ss_store_sk = s_store_sk - and ss_item_sk = i_item_sk - and i_current_price > 50 - and ss_promo_sk = p_promo_sk - and p_channel_tv = 'N' - group by s_store_id) - , - csr as - (select cp_catalog_page_id as catalog_page_id, - sum(cs_ext_sales_price) as sales, - sum(coalesce(cr_return_amount, 0)) as returns, - sum(cs_net_profit - coalesce(cr_net_loss, 0)) as profit - from catalog_sales left outer join catalog_returns on - (cs_item_sk = cr_item_sk and cs_order_number = cr_order_number), - date_dim, - catalog_page, - item, - promotion - where cs_sold_date_sk = d_date_sk - and d_date between cast('1999-08-03' as date) - and dateadd(day,30,cast('1999-08-03' as date)) - and cs_catalog_page_sk = cp_catalog_page_sk - and cs_item_sk = i_item_sk - and i_current_price > 50 - and cs_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(ws_ext_sales_price) as sales, - sum(coalesce(wr_return_amt, 0)) as returns, - sum(ws_net_profit - coalesce(wr_net_loss, 0)) as profit - from web_sales left outer join web_returns on - (ws_item_sk = wr_item_sk and ws_order_number = wr_order_number), - date_dim, - web_site, - item, - promotion - where ws_sold_date_sk = d_date_sk - and d_date between cast('1999-08-03' as date) - and dateadd(day,30,cast('1999-08-03' as date)) - and ws_web_site_sk = web_site_sk - and ws_item_sk = i_item_sk - and i_current_price > 50 - and ws_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by web_site_id) -, -results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || store_id as id - , sales - , returns - , profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || catalog_page_id as id - , sales - , returns - , profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , profit - from wsr - ) x - group by channel, id) - - select channel - , id - , sales - , returns - , profit - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results - ) foo - order by channel, id - limit 100; - --- end template query80a.tpl query 27 in stream 5 --- start template query69.tpl query 28 in stream 5 -select /* TPC-DS query69.tpl 0.28 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_state in ('ND','IN','VA') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2003 and - d_moy between 4 and 4+2) and - (not exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2003 and - d_moy between 4 and 4+2) and - not exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2003 and - d_moy between 4 and 4+2)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - limit 100; - --- end template query69.tpl query 28 in stream 5 --- start template query54.tpl query 29 in stream 5 -with /* TPC-DS query54.tpl 0.81 */ my_customers as ( - select distinct c_customer_sk - , c_current_addr_sk - from - ( select cs_sold_date_sk sold_date_sk, - cs_bill_customer_sk customer_sk, - cs_item_sk item_sk - from catalog_sales - union all - select ws_sold_date_sk sold_date_sk, - ws_bill_customer_sk customer_sk, - ws_item_sk item_sk - from web_sales - ) cs_or_ws_sales, - item, - date_dim, - customer - where sold_date_sk = d_date_sk - and item_sk = i_item_sk - and i_category = 'Sports' - and i_class = 'sailing' - and c_customer_sk = cs_or_ws_sales.customer_sk - and d_moy = 4 - and d_year = 2000 - ) - , my_revenue as ( - select c_customer_sk, - sum(ss_ext_sales_price) as revenue - from my_customers, - store_sales, - customer_address, - store, - date_dim - where c_current_addr_sk = ca_address_sk - and ca_county = s_county - and ca_state = s_state - and ss_sold_date_sk = d_date_sk - and c_customer_sk = ss_customer_sk - and d_month_seq between (select distinct d_month_seq+1 - from date_dim where d_year = 2000 and d_moy = 4) - and (select distinct d_month_seq+3 - from date_dim where d_year = 2000 and d_moy = 4) - group by c_customer_sk - ) - , segments as - (select cast((revenue/50) as int) as segment - from my_revenue - ) - select segment, count(*) as num_customers, segment*50 as segment_base - from segments - group by segment - order by segment, num_customers - limit 100; - --- end template query54.tpl query 29 in stream 5 --- start template query92.tpl query 30 in stream 5 -select /* TPC-DS query92.tpl 0.44 */ - sum(ws_ext_discount_amt) as "Excess Discount Amount" -from - web_sales - ,item - ,date_dim -where -i_manufact_id = 615 -and i_item_sk = ws_item_sk -and d_date between '1998-03-03' and - dateadd(day,90,cast('1998-03-03' as date)) -and d_date_sk = ws_sold_date_sk -and ws_ext_discount_amt - > ( - SELECT - 1.3 * avg(ws_ext_discount_amt) - FROM - web_sales - ,date_dim - WHERE - ws_item_sk = i_item_sk - and d_date between '1998-03-03' and - dateadd(day,90,cast('1998-03-03' as date)) - and d_date_sk = ws_sold_date_sk - ) -order by sum(ws_ext_discount_amt) -limit 100; - --- end template query92.tpl query 30 in stream 5 --- start template query61.tpl query 31 in stream 5 -select /* TPC-DS query61.tpl 0.97 */ promotions,total,cast(promotions as decimal(15,4))/cast(total as decimal(15,4))*100 -from - (select sum(ss_ext_sales_price) promotions - from store_sales - ,store - ,promotion - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_promo_sk = p_promo_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -7 - and i_category = 'Sports' - and (p_channel_dmail = 'Y' or p_channel_email = 'Y' or p_channel_tv = 'Y') - and s_gmt_offset = -7 - and d_year = 1999 - and d_moy = 12) promotional_sales, - (select sum(ss_ext_sales_price) total - from store_sales - ,store - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -7 - and i_category = 'Sports' - and s_gmt_offset = -7 - and d_year = 1999 - and d_moy = 12) all_sales -order by promotions, total -limit 100; - --- end template query61.tpl query 31 in stream 5 --- start template query53.tpl query 32 in stream 5 -select /* TPC-DS query53.tpl 0.88 */ * from -(select i_manufact_id, -sum(ss_sales_price) sum_sales, -avg(sum(ss_sales_price)) over (partition by i_manufact_id) avg_quarterly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and -ss_sold_date_sk = d_date_sk and -ss_store_sk = s_store_sk and -d_month_seq in (1209,1209+1,1209+2,1209+3,1209+4,1209+5,1209+6,1209+7,1209+8,1209+9,1209+10,1209+11) and -((i_category in ('Books','Children','Electronics') and -i_class in ('personal','portable','reference','self-help') and -i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) -or(i_category in ('Women','Music','Men') and -i_class in ('accessories','classical','fragrances','pants') and -i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manufact_id, d_qoy ) tmp1 -where case when avg_quarterly_sales > 0 - then abs (sum_sales - avg_quarterly_sales)/ avg_quarterly_sales - else null end > 0.1 -order by avg_quarterly_sales, - sum_sales, - i_manufact_id -limit 100; - --- end template query53.tpl query 32 in stream 5 --- start template query87.tpl query 33 in stream 5 -select /* TPC-DS query87.tpl 0.77 */ count(*) -from ((select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1220 and 1220+11) - except - (select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1220 and 1220+11) - except - (select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1220 and 1220+11) -) cool_cust -; - --- end template query87.tpl query 33 in stream 5 --- start template query68.tpl query 34 in stream 5 -select /* TPC-DS query68.tpl 0.95 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,extended_price - ,extended_tax - ,list_price - from (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_ext_sales_price) extended_price - ,sum(ss_ext_list_price) list_price - ,sum(ss_ext_tax) extended_tax - from store_sales - ,date_dim - ,store - ,household_demographics - ,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_dep_count = 4 or - household_demographics.hd_vehicle_count= 2) - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_city in ('Brownsville','Franklin') - group by ss_ticket_number - ,ss_customer_sk - ,ss_addr_sk,ca_city) dn - ,customer - ,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,ss_ticket_number - limit 100; - --- end template query68.tpl query 34 in stream 5 --- start template query85.tpl query 35 in stream 5 -select /* TPC-DS query85.tpl 0.33 */ substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) - from web_sales, web_returns, web_page, customer_demographics cd1, - customer_demographics cd2, customer_address, date_dim, reason - where ws_web_page_sk = wp_web_page_sk - and ws_item_sk = wr_item_sk - and ws_order_number = wr_order_number - and ws_sold_date_sk = d_date_sk and d_year = 1998 - and cd1.cd_demo_sk = wr_refunded_cdemo_sk - and cd2.cd_demo_sk = wr_returning_cdemo_sk - and ca_address_sk = wr_refunded_addr_sk - and r_reason_sk = wr_reason_sk - and - ( - ( - cd1.cd_marital_status = 'U' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Primary' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 100.00 and 150.00 - ) - or - ( - cd1.cd_marital_status = 'D' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Secondary' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 50.00 and 100.00 - ) - or - ( - cd1.cd_marital_status = 'S' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Advanced Degree' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ca_country = 'United States' - and - ca_state in ('KS', 'TX', 'FL') - and ws_net_profit between 100 and 200 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('SD', 'AZ', 'ID') - and ws_net_profit between 150 and 300 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('AL', 'IN', 'IA') - and ws_net_profit between 50 and 250 - ) - ) -group by r_reason_desc -order by substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) -limit 100; - --- end template query85.tpl query 35 in stream 5 --- start template query28.tpl query 36 in stream 5 -select /* TPC-DS query28.tpl 0.36 */ * -from (select avg(ss_list_price) B1_LP - ,count(ss_list_price) B1_CNT - ,count(distinct ss_list_price) B1_CNTD - from store_sales - where ss_quantity between 0 and 5 - and (ss_list_price between 131 and 131+10 - or ss_coupon_amt between 1482 and 1482+1000 - or ss_wholesale_cost between 33 and 33+20)) B1, - (select avg(ss_list_price) B2_LP - ,count(ss_list_price) B2_CNT - ,count(distinct ss_list_price) B2_CNTD - from store_sales - where ss_quantity between 6 and 10 - and (ss_list_price between 167 and 167+10 - or ss_coupon_amt between 131 and 131+1000 - or ss_wholesale_cost between 16 and 16+20)) B2, - (select avg(ss_list_price) B3_LP - ,count(ss_list_price) B3_CNT - ,count(distinct ss_list_price) B3_CNTD - from store_sales - where ss_quantity between 11 and 15 - and (ss_list_price between 137 and 137+10 - or ss_coupon_amt between 17163 and 17163+1000 - or ss_wholesale_cost between 55 and 55+20)) B3, - (select avg(ss_list_price) B4_LP - ,count(ss_list_price) B4_CNT - ,count(distinct ss_list_price) B4_CNTD - from store_sales - where ss_quantity between 16 and 20 - and (ss_list_price between 60 and 60+10 - or ss_coupon_amt between 17366 and 17366+1000 - or ss_wholesale_cost between 74 and 74+20)) B4, - (select avg(ss_list_price) B5_LP - ,count(ss_list_price) B5_CNT - ,count(distinct ss_list_price) B5_CNTD - from store_sales - where ss_quantity between 21 and 25 - and (ss_list_price between 127 and 127+10 - or ss_coupon_amt between 8344 and 8344+1000 - or ss_wholesale_cost between 79 and 79+20)) B5, - (select avg(ss_list_price) B6_LP - ,count(ss_list_price) B6_CNT - ,count(distinct ss_list_price) B6_CNTD - from store_sales - where ss_quantity between 26 and 30 - and (ss_list_price between 32 and 32+10 - or ss_coupon_amt between 6077 and 6077+1000 - or ss_wholesale_cost between 62 and 62+20)) B6 -limit 100; - --- end template query28.tpl query 36 in stream 5 --- start template query42.tpl query 37 in stream 5 -select /* TPC-DS query42.tpl 0.61 */ dt.d_year - ,item.i_category_id - ,item.i_category - ,sum(ss_ext_sales_price) - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=12 - and dt.d_year=2001 - group by dt.d_year - ,item.i_category_id - ,item.i_category - order by sum(ss_ext_sales_price) desc,dt.d_year - ,item.i_category_id - ,item.i_category -limit 100 ; - --- end template query42.tpl query 37 in stream 5 --- start template query67a.tpl query 38 in stream 5 -with /* TPC-DS query67a.tpl 0.35 */ results as -( select i_category ,i_class ,i_brand ,i_product_name ,d_year ,d_qoy ,d_moy ,s_store_id - ,sum(coalesce(ss_sales_price*ss_quantity,0)) sumsales - from store_sales ,date_dim ,store ,item - where ss_sold_date_sk=d_date_sk - and ss_item_sk=i_item_sk - and ss_store_sk = s_store_sk - and d_month_seq between 1193 and 1193 + 11 - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy,s_store_id) - , - results_rollup as - (select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, s_store_id, sumsales - from results - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy - union all - select i_category, i_class, i_brand, i_product_name, d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year - union all - select i_category, i_class, i_brand, i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name - union all - select i_category, i_class, i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand - union all - select i_category, i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class - union all - select i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category - union all - select null i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results) - - select * -from (select i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rank() over (partition by i_category order by sumsales desc) rk - from results_rollup) dw2 -where rk <= 100 -order by i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rk -limit 100; - --- end template query67a.tpl query 38 in stream 5 --- start template query50.tpl query 39 in stream 5 -select /* TPC-DS query50.tpl 0.60 */ - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 30) and - (sr_returned_date_sk - ss_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 60) and - (sr_returned_date_sk - ss_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 90) and - (sr_returned_date_sk - ss_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - store_sales - ,store_returns - ,store - ,date_dim d1 - ,date_dim d2 -where - d2.d_year = 2000 -and d2.d_moy = 8 -and ss_ticket_number = sr_ticket_number -and ss_item_sk = sr_item_sk -and ss_sold_date_sk = d1.d_date_sk -and sr_returned_date_sk = d2.d_date_sk -and ss_customer_sk = sr_customer_sk -and ss_store_sk = s_store_sk -group by - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -order by s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -limit 100; - --- end template query50.tpl query 39 in stream 5 --- start template query30.tpl query 40 in stream 5 -with /* TPC-DS query30.tpl 0.75 */ customer_total_return as - (select wr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(wr_return_amt) as ctr_total_return - from web_returns - ,date_dim - ,customer_address - where wr_returned_date_sk = d_date_sk - and d_year =2002 - and wr_returning_addr_sk = ca_address_sk - group by wr_returning_customer_sk - ,ca_state) - select c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'WI' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return -limit 100; - --- end template query30.tpl query 40 in stream 5 --- start template query48.tpl query 41 in stream 5 -select /* TPC-DS query48.tpl 0.74 */ sum (ss_quantity) - from store_sales, store, customer_demographics, customer_address, date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 1998 - and - ( - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'M' - and - cd_education_status = 'Primary' - and - ss_sales_price between 100.00 and 150.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'D' - and - cd_education_status = 'Unknown' - and - ss_sales_price between 50.00 and 100.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'S' - and - cd_education_status = 'Advanced Degree' - and - ss_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('NE', 'OK', 'KY') - and ss_net_profit between 0 and 2000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('GA', 'ID', 'CO') - and ss_net_profit between 150 and 3000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('MT', 'KS', 'PA') - and ss_net_profit between 50 and 25000 - ) - ) -; - --- end template query48.tpl query 41 in stream 5 --- start template query22a.tpl query 42 in stream 5 -with /* TPC-DS query22a.tpl 0.55 */ results as -(select i_product_name - ,i_brand - ,i_class - ,i_category - ,avg(inv_quantity_on_hand) qoh - from inventory - ,date_dim - ,item --- ,warehouse - where inv_date_sk=d_date_sk - and inv_item_sk=i_item_sk --- and inv_warehouse_sk = w_warehouse_sk - and d_month_seq between 1196 and 1196 + 11 - group by i_product_name,i_brand,i_class,i_category), -results_rollup as -(select i_product_name, i_brand, i_class, i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class,i_category -union all -select i_product_name, i_brand, i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class -union all -select i_product_name, i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand -union all -select i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name -union all -select null i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results) - select i_product_name, i_brand, i_class, i_category,qoh - from results_rollup - order by qoh, i_product_name, i_brand, i_class, i_category -limit 100; - --- end template query22a.tpl query 42 in stream 5 --- start template query11.tpl query 43 in stream 5 -with /* TPC-DS query11.tpl 0.51 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ss_ext_list_price-ss_ext_discount_amt) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ws_ext_list_price-ws_ext_discount_amt) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_login - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 1999 - and t_s_secyear.dyear = 1999+1 - and t_w_firstyear.dyear = 1999 - and t_w_secyear.dyear = 1999+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else 0.0 end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else 0.0 end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_login -limit 100; - --- end template query11.tpl query 43 in stream 5 --- start template query94.tpl query 44 in stream 5 -select /* TPC-DS query94.tpl 0.17 */ - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2002-5-01' and - dateadd(day,60,cast('2002-5-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'OH' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and exists (select * - from web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) -and not exists(select * - from web_returns wr1 - where ws1.ws_order_number = wr1.wr_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query94.tpl query 44 in stream 5 --- start template query93.tpl query 45 in stream 5 -select /* TPC-DS query93.tpl 0.52 */ ss_customer_sk - ,sum(act_sales) sumsales - from (select ss_item_sk - ,ss_ticket_number - ,ss_customer_sk - ,case when sr_return_quantity is not null then (ss_quantity-sr_return_quantity)*ss_sales_price - else (ss_quantity*ss_sales_price) end act_sales - from store_sales left outer join store_returns on (sr_item_sk = ss_item_sk - and sr_ticket_number = ss_ticket_number) - ,reason - where sr_reason_sk = r_reason_sk - and r_reason_desc = 'unauthoized purchase') t - group by ss_customer_sk - order by sumsales, ss_customer_sk -limit 100; - --- end template query93.tpl query 45 in stream 5 --- start template query18a.tpl query 46 in stream 5 -with /* TPC-DS query18a.tpl 0.90 */ results as - (select i_item_id, - ca_country, - ca_state, - ca_county, - cast(cs_quantity as decimal(12,2)) agg1, - cast(cs_list_price as decimal(12,2)) agg2, - cast(cs_coupon_amt as decimal(12,2)) agg3, - cast(cs_sales_price as decimal(12,2)) agg4, - cast(cs_net_profit as decimal(12,2)) agg5, - cast(c_birth_year as decimal(12,2)) agg6, - cast(cd1.cd_dep_count as decimal(12,2)) agg7 - from catalog_sales, customer_demographics cd1, customer_demographics cd2, customer, customer_address, date_dim, item - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd1.cd_demo_sk and - cs_bill_customer_sk = c_customer_sk and - cd1.cd_gender = 'M' and - cd1.cd_education_status = '4 yr Degree' and - c_current_cdemo_sk = cd2.cd_demo_sk and - c_current_addr_sk = ca_address_sk and - c_birth_month in (11,2,9,8,4,12) and - d_year = 2001 and - ca_state in ('PA','NC','ID','IL','TX','MI','MD') - ) - select i_item_id, ca_country, ca_state, ca_county, agg1, agg2, agg3, agg4, agg5, agg6, agg7 - from ( - select i_item_id, ca_country, ca_state, ca_county, avg(agg1) agg1, - avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state, ca_county - union all - select i_item_id, ca_country, ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state - union all - select i_item_id, ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country - union all - select i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - ) foo - order by ca_country, ca_state, ca_county, i_item_id - limit 100; - --- end template query18a.tpl query 46 in stream 5 --- start template query33.tpl query 47 in stream 5 -with /* TPC-DS query33.tpl 0.22 */ ss as ( - select - i_manufact_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Electronics')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 6 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id), - cs as ( - select - i_manufact_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Electronics')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 6 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id), - ws as ( - select - i_manufact_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Electronics')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 6 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id) - select i_manufact_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_manufact_id - order by total_sales -limit 100; - --- end template query33.tpl query 47 in stream 5 --- start template query63.tpl query 48 in stream 5 -select /* TPC-DS query63.tpl 0.27 */ * -from (select i_manager_id - ,sum(ss_sales_price) sum_sales - ,avg(sum(ss_sales_price)) over (partition by i_manager_id) avg_monthly_sales - from item - ,store_sales - ,date_dim - ,store - where ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and d_month_seq in (1222,1222+1,1222+2,1222+3,1222+4,1222+5,1222+6,1222+7,1222+8,1222+9,1222+10,1222+11) - and (( i_category in ('Books','Children','Electronics') - and i_class in ('personal','portable','reference','self-help') - and i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) - or( i_category in ('Women','Music','Men') - and i_class in ('accessories','classical','fragrances','pants') - and i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manager_id, d_moy) tmp1 -where case when avg_monthly_sales > 0 then abs (sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 -order by i_manager_id - ,avg_monthly_sales - ,sum_sales -limit 100; - --- end template query63.tpl query 48 in stream 5 --- start template query8.tpl query 49 in stream 5 -select /* TPC-DS query8.tpl 0.63 */ s_store_name - ,sum(ss_net_profit) - from store_sales - ,date_dim - ,store, - (select ca_zip - from ( - SELECT substring(ca_zip,1,5) ca_zip - FROM customer_address - WHERE substring(ca_zip,1,5) IN ( - '61874','30697','69490','90165','59409','76397', - '66501','51240','89992','37130','23298', - '54518','81448','36091','10579','79466', - '77093','71662','97159','47912','65620', - '49710','25578','25706','49768','13244', - '76716','68052','84481','66508','42132', - '28012','35544','42594','70511','70310', - '41923','62353','30316','25538','33794', - '49016','52395','93258','29895','37679', - '39289','53646','59734','72166','40196', - '34033','54843','96248','24243','85088', - '28719','72770','23061','29921','31641', - '42520','30484','37134','15243','84232', - '79183','95079','40355','25401','97202', - '18122','25526','97797','83822','50545', - '42304','33787','56335','77448','48310', - '29484','83469','26658','62386','19209', - '46798','83788','33548','24400','82702', - '38315','25469','53558','66548','46520', - '29845','26280','48443','61625','25191', - '13603','24521','34746','31843','73391', - '93706','47627','27673','84716','17293', - '79921','24571','24264','80365','39106', - '68362','27459','91279','93702','47278', - '69621','13880','88660','75642','42144', - '67475','59923','78509','93592','32638', - '27244','78483','12568','73846','76417', - '22141','88040','74100','88787','81475', - '53327','14355','28954','81191','61007', - '28638','64344','28084','83440','41911', - '51680','98490','77588','28637','97636', - '56466','56486','33702','83236','69847', - '70018','37111','93050','25955','41614', - '32208','94944','86239','26896','51053', - '96376','82094','26226','82967','80341', - '90575','43006','73150','62989','53401', - '26293','85632','24510','56307','33215', - '51884','90732','60468','57164','17476', - '25850','72876','48511','39834','78877', - '46886','16778','60404','47491','99008', - '37160','18812','17124','23778','70607', - '19230','85564','75759','60363','93526', - '51725','61486','39315','55794','22273', - '43622','18689','99640','67211','34424', - '87128','81944','29520','36292','41978', - '89239','67088','27915','53429','40445', - '17945','20567','14514','23914','45732', - '99838','22109','39132','87933','87498', - '78157','49318','81334','18235','95165', - '92253','40901','88690','54873','62816', - '95005','16973','80218','22842','39260', - '78571','16019','10851','47012','65698', - '46840','26356','66516','21204','44949', - '99454','96477','68796','88077','26228', - '44240','69678','19847','57087','85875', - '17882','86696','52554','77103','29733', - '51446','67775','18123','11787','83933', - '29361','32013','95324','53926','79662', - '50593','11742','18084','71922','16810', - '69137','51144','85312','70225','25302', - '89704','15248','14137','19857','62135', - '41017','62638','96206','41351','46071', - '86168','29409','95785','73760','73790', - '20461','89467','72581','50231','42722', - '30428','48879','25352','62887','98945', - '21898','15136','11234','87798','11469', - '83484','14679','26793','66649','40053', - '73125','85950','74393','66748','45883', - '21837','52819','33590','85094','57915', - '81738','80242','92321','97575','59114', - '68120','92833','47951','83132','72756', - '16338','15408','62485','69922','21854', - '12755','42306','57271','18267','43363', - '80197','29431','69895','58411','81882', - '44200','10545','60144','55687','24150', - '67380','83690','52210','64571','65051', - '24029','86934','42273','85026','15611', - '84495','93223','16909','40953','37506', - '52739','47613','49708','89248','77351', - '21191','65083','12506','92180') - intersect - select ca_zip - from (SELECT substring(ca_zip,1,5) ca_zip,count(*) cnt - FROM customer_address, customer - WHERE ca_address_sk = c_current_addr_sk and - c_preferred_cust_flag='Y' - group by ca_zip - having count(*) > 10)A1)A2) V1 - where ss_store_sk = s_store_sk - and ss_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 1999 - and (substring(s_zip,1,2) = substring(V1.ca_zip,1,2)) - group by s_store_name - order by s_store_name - limit 100; - --- end template query8.tpl query 49 in stream 5 --- start template query97.tpl query 50 in stream 5 -with /* TPC-DS query97.tpl 0.38 */ ssci as ( -select ss_customer_sk customer_sk - ,ss_item_sk item_sk -from store_sales,date_dim -where ss_sold_date_sk = d_date_sk - and d_month_seq between 1188 and 1188 + 11 -group by ss_customer_sk - ,ss_item_sk), -csci as( - select cs_bill_customer_sk customer_sk - ,cs_item_sk item_sk -from catalog_sales,date_dim -where cs_sold_date_sk = d_date_sk - and d_month_seq between 1188 and 1188 + 11 -group by cs_bill_customer_sk - ,cs_item_sk) - select sum(case when ssci.customer_sk is not null and csci.customer_sk is null then 1 else 0 end) store_only - ,sum(case when ssci.customer_sk is null and csci.customer_sk is not null then 1 else 0 end) catalog_only - ,sum(case when ssci.customer_sk is not null and csci.customer_sk is not null then 1 else 0 end) store_and_catalog -from ssci full outer join csci on (ssci.customer_sk=csci.customer_sk - and ssci.item_sk = csci.item_sk) -limit 100; - --- end template query97.tpl query 50 in stream 5 --- start template query45.tpl query 51 in stream 5 -select /* TPC-DS query45.tpl 0.18 */ ca_zip, ca_county, sum(ws_sales_price) - from web_sales, customer, customer_address, date_dim, item - where ws_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ws_item_sk = i_item_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', '85392', '85460', '80348', '81792') - or - i_item_id in (select i_item_id - from item - where i_item_sk in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29) - ) - ) - and ws_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 2002 - group by ca_zip, ca_county - order by ca_zip, ca_county - limit 100; - --- end template query45.tpl query 51 in stream 5 --- start template query62.tpl query 52 in stream 5 -select /* TPC-DS query62.tpl 0.24 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 30) and - (ws_ship_date_sk - ws_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 60) and - (ws_ship_date_sk - ws_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 90) and - (ws_ship_date_sk - ws_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - web_sales - ,warehouse - ,ship_mode - ,web_site - ,date_dim -where - d_month_seq between 1196 and 1196 + 11 -and ws_ship_date_sk = d_date_sk -and ws_warehouse_sk = w_warehouse_sk -and ws_ship_mode_sk = sm_ship_mode_sk -and ws_web_site_sk = web_site_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -limit 100; - --- end template query62.tpl query 52 in stream 5 --- start template query81.tpl query 53 in stream 5 -with /* TPC-DS query81.tpl 0.37 */ customer_total_return as - (select cr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(cr_return_amt_inc_tax) as ctr_total_return - from catalog_returns - ,date_dim - ,customer_address - where cr_returned_date_sk = d_date_sk - and d_year =2002 - and cr_returning_addr_sk = ca_address_sk - group by cr_returning_customer_sk - ,ca_state ) - select c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'MS' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - limit 100; - --- end template query81.tpl query 53 in stream 5 --- start template query35a.tpl query 54 in stream 5 -select /* TPC-DS query35a.tpl 0.47 */ - ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - count(*) cnt1, - sum(cd_dep_count), - stddev_samp(cd_dep_count), - avg(cd_dep_count), - cd_dep_employed_count, - count(*) cnt2, - sum(cd_dep_employed_count), - stddev_samp(cd_dep_employed_count), - avg(cd_dep_employed_count), - cd_dep_college_count, - count(*) cnt3, - sum(cd_dep_college_count), - stddev_samp(cd_dep_college_count), - avg(cd_dep_college_count) - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2000 and - d_qoy < 4) and - exists (select * from - (select ws_bill_customer_sk customsk - from web_sales,date_dim - where - ws_sold_date_sk = d_date_sk and - d_year = 2000 and - d_qoy < 4 - union all - select cs_ship_customer_sk customsk - from catalog_sales,date_dim - where - cs_sold_date_sk = d_date_sk and - d_year = 2000 and - d_qoy < 4)x - where x.customsk = c.c_customer_sk) - group by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - limit 100; - --- end template query35a.tpl query 54 in stream 5 --- start template query78.tpl query 55 in stream 5 -with /* TPC-DS query78.tpl 0.10 */ ws as - (select d_year AS ws_sold_year, ws_item_sk, - ws_bill_customer_sk ws_customer_sk, - sum(ws_quantity) ws_qty, - sum(ws_wholesale_cost) ws_wc, - sum(ws_sales_price) ws_sp - from web_sales - left join web_returns on wr_order_number=ws_order_number and ws_item_sk=wr_item_sk - join date_dim on ws_sold_date_sk = d_date_sk - where wr_order_number is null - group by d_year, ws_item_sk, ws_bill_customer_sk - ), -cs as - (select d_year AS cs_sold_year, cs_item_sk, - cs_bill_customer_sk cs_customer_sk, - sum(cs_quantity) cs_qty, - sum(cs_wholesale_cost) cs_wc, - sum(cs_sales_price) cs_sp - from catalog_sales - left join catalog_returns on cr_order_number=cs_order_number and cs_item_sk=cr_item_sk - join date_dim on cs_sold_date_sk = d_date_sk - where cr_order_number is null - group by d_year, cs_item_sk, cs_bill_customer_sk - ), -ss as - (select d_year AS ss_sold_year, ss_item_sk, - ss_customer_sk, - sum(ss_quantity) ss_qty, - sum(ss_wholesale_cost) ss_wc, - sum(ss_sales_price) ss_sp - from store_sales - left join store_returns on sr_ticket_number=ss_ticket_number and ss_item_sk=sr_item_sk - join date_dim on ss_sold_date_sk = d_date_sk - where sr_ticket_number is null - group by d_year, ss_item_sk, ss_customer_sk - ) - select -ss_item_sk, -round(ss_qty/(coalesce(ws_qty,0)+coalesce(cs_qty,0)),2) ratio, -ss_qty store_qty, ss_wc store_wholesale_cost, ss_sp store_sales_price, -coalesce(ws_qty,0)+coalesce(cs_qty,0) other_chan_qty, -coalesce(ws_wc,0)+coalesce(cs_wc,0) other_chan_wholesale_cost, -coalesce(ws_sp,0)+coalesce(cs_sp,0) other_chan_sales_price -from ss -left join ws on (ws_sold_year=ss_sold_year and ws_item_sk=ss_item_sk and ws_customer_sk=ss_customer_sk) -left join cs on (cs_sold_year=ss_sold_year and cs_item_sk=ss_item_sk and cs_customer_sk=ss_customer_sk) -where (coalesce(ws_qty,0)>0 or coalesce(cs_qty, 0)>0) and ss_sold_year=2002 -order by - ss_item_sk, - ss_qty desc, ss_wc desc, ss_sp desc, - other_chan_qty, - other_chan_wholesale_cost, - other_chan_sales_price, - ratio -limit 100; - --- end template query78.tpl query 55 in stream 5 --- start template query57.tpl query 56 in stream 5 -with /* TPC-DS query57.tpl 0.70 */ v1 as( - select i_category, i_brand, - cc_name, - d_year, d_moy, - sum(cs_sales_price) sum_sales, - avg(sum(cs_sales_price)) over - (partition by i_category, i_brand, - cc_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - cc_name - order by d_year, d_moy) rn - from item, catalog_sales, date_dim, call_center - where cs_item_sk = i_item_sk and - cs_sold_date_sk = d_date_sk and - cc_call_center_sk= cs_call_center_sk and - ( - d_year = 1999 or - ( d_year = 1999-1 and d_moy =12) or - ( d_year = 1999+1 and d_moy =1) - ) - group by i_category, i_brand, - cc_name , d_year, d_moy), - v2 as( - select v1.i_category, v1.i_brand - ,v1.d_year, v1.d_moy - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1. cc_name = v1_lag. cc_name and - v1. cc_name = v1_lead. cc_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 1999 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, avg_monthly_sales - limit 100; - --- end template query57.tpl query 56 in stream 5 --- start template query46.tpl query 57 in stream 5 -select /* TPC-DS query46.tpl 0.23 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and (household_demographics.hd_dep_count = 9 or - household_demographics.hd_vehicle_count= 3) - and date_dim.d_dow in (6,0) - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_city in ('Jamestown','Sulphur Springs','New Hope','Clinton','Oakwood') - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,ca_city) dn,customer,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - limit 100; - --- end template query46.tpl query 57 in stream 5 --- start template query32.tpl query 58 in stream 5 -select /* TPC-DS query32.tpl 0.7 */ sum(cs_ext_discount_amt) as "excess discount amount" -from - catalog_sales - ,item - ,date_dim -where -i_manufact_id = 503 -and i_item_sk = cs_item_sk -and d_date between '1998-03-28' and - dateadd(day,90,cast('1998-03-28' as date)) -and d_date_sk = cs_sold_date_sk -and cs_ext_discount_amt - > ( - select - 1.3 * avg(cs_ext_discount_amt) - from - catalog_sales - ,date_dim - where - cs_item_sk = i_item_sk - and d_date between '1998-03-28' and - dateadd(day,90,cast('1998-03-28' as date)) - and d_date_sk = cs_sold_date_sk - ) -limit 100; - --- end template query32.tpl query 58 in stream 5 --- start template query24.tpl query 59 in stream 5 -with /* TPC-DS query24.tpl 0.92 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_net_profit) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip -and s_market_id=8 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'maroon' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; -with /* TPC-DS query24.tpl 0.92 part2 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_net_profit) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip - and s_market_id = 8 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'slate' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; - --- end template query24.tpl query 59 in stream 5 --- start template query38.tpl query 60 in stream 5 -select /* TPC-DS query38.tpl 0.54 */ count(*) from ( - select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1221 and 1221 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1221 and 1221 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1221 and 1221 + 11 -) hot_cust -limit 100; - --- end template query38.tpl query 60 in stream 5 --- start template query55.tpl query 61 in stream 5 -select /* TPC-DS query55.tpl 0.82 */ i_brand_id brand_id, i_brand brand, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=93 - and d_moy=12 - and d_year=2001 - group by i_brand, i_brand_id - order by ext_price desc, i_brand_id -limit 100 ; - --- end template query55.tpl query 61 in stream 5 --- start template query74.tpl query 62 in stream 5 -with /* TPC-DS query74.tpl 0.76 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,sum(ss_net_paid) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (2001,2001+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,sum(ws_net_paid) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - and d_year in (2001,2001+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - ) - select - t_s_secyear.customer_id, t_s_secyear.customer_first_name, t_s_secyear.customer_last_name - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.year = 2001 - and t_s_secyear.year = 2001+1 - and t_w_firstyear.year = 2001 - and t_w_secyear.year = 2001+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - order by 1,2,3 -limit 100; - --- end template query74.tpl query 62 in stream 5 --- start template query84.tpl query 63 in stream 5 -select /* TPC-DS query84.tpl 0.80 */ c_customer_id as customer_id - , coalesce(c_last_name,'') || ', ' || coalesce(c_first_name,'') as customername - from customer - ,customer_address - ,customer_demographics - ,household_demographics - ,income_band - ,store_returns - where ca_city = 'Mountain View' - and c_current_addr_sk = ca_address_sk - and ib_lower_bound >= 46572 - and ib_upper_bound <= 46572 + 50000 - and ib_income_band_sk = hd_income_band_sk - and cd_demo_sk = c_current_cdemo_sk - and hd_demo_sk = c_current_hdemo_sk - and sr_cdemo_sk = cd_demo_sk - order by c_customer_id - limit 100; - --- end template query84.tpl query 63 in stream 5 --- start template query89.tpl query 64 in stream 5 -select /* TPC-DS query89.tpl 0.56 */ * -from( -select i_category, i_class, i_brand, - s_store_name, s_company_name, - d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, s_store_name, s_company_name) - avg_monthly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - d_year in (2000) and - ((i_category in ('Books','Children','Men') and - i_class in ('travel','infants','sports-apparel') - ) - or (i_category in ('Shoes','Electronics','Home') and - i_class in ('mens','musical','lighting') - )) -group by i_category, i_class, i_brand, - s_store_name, s_company_name, d_moy) tmp1 -where case when (avg_monthly_sales <> 0) then (abs(sum_sales - avg_monthly_sales) / avg_monthly_sales) else null end > 0.1 -order by sum_sales - avg_monthly_sales, s_store_name -limit 100; - --- end template query89.tpl query 64 in stream 5 --- start template query83.tpl query 65 in stream 5 -with /* TPC-DS query83.tpl 0.96 */ sr_items as - (select i_item_id item_id, - sum(sr_return_quantity) sr_item_qty - from store_returns, - item, - date_dim - where sr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2002-07-15','2002-08-07','2002-11-17'))) - and sr_returned_date_sk = d_date_sk - group by i_item_id), - cr_items as - (select i_item_id item_id, - sum(cr_return_quantity) cr_item_qty - from catalog_returns, - item, - date_dim - where cr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2002-07-15','2002-08-07','2002-11-17'))) - and cr_returned_date_sk = d_date_sk - group by i_item_id), - wr_items as - (select i_item_id item_id, - sum(wr_return_quantity) wr_item_qty - from web_returns, - item, - date_dim - where wr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2002-07-15','2002-08-07','2002-11-17'))) - and wr_returned_date_sk = d_date_sk - group by i_item_id) - select sr_items.item_id - ,sr_item_qty - ,sr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 sr_dev - ,cr_item_qty - ,cr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 cr_dev - ,wr_item_qty - ,wr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 wr_dev - ,(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 average - from sr_items - ,cr_items - ,wr_items - where sr_items.item_id=cr_items.item_id - and sr_items.item_id=wr_items.item_id - order by sr_items.item_id - ,sr_item_qty - limit 100; - --- end template query83.tpl query 65 in stream 5 --- start template query31.tpl query 66 in stream 5 -with /* TPC-DS query31.tpl 0.50 */ ss as - (select ca_county,d_qoy, d_year,sum(ss_ext_sales_price) as store_sales - from store_sales,date_dim,customer_address - where ss_sold_date_sk = d_date_sk - and ss_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year), - ws as - (select ca_county,d_qoy, d_year,sum(ws_ext_sales_price) as web_sales - from web_sales,date_dim,customer_address - where ws_sold_date_sk = d_date_sk - and ws_bill_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year) - select - ss1.ca_county - ,ss1.d_year - ,ws2.web_sales/ws1.web_sales web_q1_q2_increase - ,ss2.store_sales/ss1.store_sales store_q1_q2_increase - ,ws3.web_sales/ws2.web_sales web_q2_q3_increase - ,ss3.store_sales/ss2.store_sales store_q2_q3_increase - from - ss ss1 - ,ss ss2 - ,ss ss3 - ,ws ws1 - ,ws ws2 - ,ws ws3 - where - ss1.d_qoy = 1 - and ss1.d_year = 1999 - and ss1.ca_county = ss2.ca_county - and ss2.d_qoy = 2 - and ss2.d_year = 1999 - and ss2.ca_county = ss3.ca_county - and ss3.d_qoy = 3 - and ss3.d_year = 1999 - and ss1.ca_county = ws1.ca_county - and ws1.d_qoy = 1 - and ws1.d_year = 1999 - and ws1.ca_county = ws2.ca_county - and ws2.d_qoy = 2 - and ws2.d_year = 1999 - and ws1.ca_county = ws3.ca_county - and ws3.d_qoy = 3 - and ws3.d_year =1999 - and case when ws1.web_sales > 0 then ws2.web_sales/ws1.web_sales else null end - > case when ss1.store_sales > 0 then ss2.store_sales/ss1.store_sales else null end - and case when ws2.web_sales > 0 then ws3.web_sales/ws2.web_sales else null end - > case when ss2.store_sales > 0 then ss3.store_sales/ss2.store_sales else null end - order by web_q2_q3_increase; - --- end template query31.tpl query 66 in stream 5 --- start template query26.tpl query 67 in stream 5 -select /* TPC-DS query26.tpl 0.85 */ i_item_id, - avg(cs_quantity) agg1, - avg(cs_list_price) agg2, - avg(cs_coupon_amt) agg3, - avg(cs_sales_price) agg4 - from catalog_sales, customer_demographics, date_dim, item, promotion - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd_demo_sk and - cs_promo_sk = p_promo_sk and - cd_gender = 'F' and - cd_marital_status = 'M' and - cd_education_status = 'Primary' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 2002 - group by i_item_id - order by i_item_id - limit 100; - --- end template query26.tpl query 67 in stream 5 --- start template query40.tpl query 68 in stream 5 -select /* TPC-DS query40.tpl 0.86 */ - w_state - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('1998-05-20' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_before - ,sum(case when (cast(d_date as date) >= cast ('1998-05-20' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_after - from - catalog_sales left outer join catalog_returns on - (cs_order_number = cr_order_number - and cs_item_sk = cr_item_sk) - ,warehouse - ,item - ,date_dim - where - i_current_price between 0.99 and 1.49 - and i_item_sk = cs_item_sk - and cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('1998-05-20' as date)) - and dateadd(day,30,cast ('1998-05-20' as date)) - group by - w_state,i_item_id - order by w_state,i_item_id -limit 100; - --- end template query40.tpl query 68 in stream 5 --- start template query14a.tpl query 69 in stream 5 -with /* TPC-DS query14a.tpl 0.69 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1998 AND 1998 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1998 AND 1998 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1998 AND 1998 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as - (select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2) x) -, - results AS -(select channel, i_brand_id, i_class_id, i_category_id, sum(sales) sum_sales, sum(number_sales) number_sales - from ( - select 'store' channel, i_brand_id,i_class_id - ,i_category_id,sum(ss_quantity*ss_list_price) sales - , count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1998+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales) - union all - select 'catalog' channel, i_brand_id,i_class_id,i_category_id, sum(cs_quantity*cs_list_price) sales, count(*) number_sales - from catalog_sales - ,item - ,date_dim - where cs_item_sk in (select ss_item_sk from cross_items) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1998+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(cs_quantity*cs_list_price) > (select average_sales from avg_sales) - union all - select 'web' channel, i_brand_id,i_class_id,i_category_id, sum(ws_quantity*ws_list_price) sales , count(*) number_sales - from web_sales - ,item - ,date_dim - where ws_item_sk in (select ss_item_sk from cross_items) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1998+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ws_quantity*ws_list_price) > (select average_sales from avg_sales) - ) y - group by channel, i_brand_id,i_class_id,i_category_id) - - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales -from ( - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales from results - union - select channel, i_brand_id, i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id, i_class_id - union - select channel, i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id - union - select channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel - union - select null as channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results) z -order by channel, i_brand_id, i_class_id, i_category_id - limit 100; -with /* TPC-DS query14a.tpl 0.69 part2 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1998 AND 1998 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1998 AND 1998 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1998 AND 1998 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as -(select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2) x) - select this_year.channel ty_channel - ,this_year.i_brand_id ty_brand - ,this_year.i_class_id ty_class - ,this_year.i_category_id ty_category - ,this_year.sales ty_sales - ,this_year.number_sales ty_number_sales - ,last_year.channel ly_channel - ,last_year.i_brand_id ly_brand - ,last_year.i_class_id ly_class - ,last_year.i_category_id ly_category - ,last_year.sales ly_sales - ,last_year.number_sales ly_number_sales -from - (select 'store' channel, i_brand_id,i_class_id,i_category_id - ,sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1998 + 1 - and d_moy = 12 - and d_dom = 20) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) this_year, - (select 'store' channel, i_brand_id,i_class_id - ,i_category_id, sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1998 - and d_moy = 12 - and d_dom = 20) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) last_year - where this_year.i_brand_id= last_year.i_brand_id - and this_year.i_class_id = last_year.i_class_id - and this_year.i_category_id = last_year.i_category_id - order by this_year.channel, this_year.i_brand_id, this_year.i_class_id, this_year.i_category_id - limit 100; - --- end template query14a.tpl query 69 in stream 5 --- start template query23.tpl query 70 in stream 5 -with /* TPC-DS query23.tpl 0.68 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (1998,1998+1,1998+2,1998+3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1998,1998+1,1998+2,1998+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * -from - max_store_sales)) - select sum(sales) - from (select cs_quantity*cs_list_price sales - from catalog_sales - ,date_dim - where d_year = 1998 - and d_moy = 2 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - union all - select ws_quantity*ws_list_price sales - from web_sales - ,date_dim - where d_year = 1998 - and d_moy = 2 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer)) - limit 100; -with /* TPC-DS query23.tpl 0.68 part2 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (1998,1998 + 1,1998 + 2,1998 + 3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1998,1998+1,1998+2,1998+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * - from max_store_sales)) - select c_last_name,c_first_name,sales - from (select c_last_name,c_first_name,sum(cs_quantity*cs_list_price) sales - from catalog_sales - ,customer - ,date_dim - where d_year = 1998 - and d_moy = 2 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and cs_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name - union all - select c_last_name,c_first_name,sum(ws_quantity*ws_list_price) sales - from web_sales - ,customer - ,date_dim - where d_year = 1998 - and d_moy = 2 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and ws_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name) - order by c_last_name,c_first_name,sales - limit 100; - --- end template query23.tpl query 70 in stream 5 --- start template query96.tpl query 71 in stream 5 -select /* TPC-DS query96.tpl 0.1 */ count(*) -from store_sales - ,household_demographics - ,time_dim, store -where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and household_demographics.hd_dep_count = 2 - and store.s_store_name = 'ese' -order by count(*) -limit 100; - --- end template query96.tpl query 71 in stream 5 --- start template query1.tpl query 72 in stream 5 -with /* TPC-DS query1.tpl 0.12 */ customer_total_return as -(select sr_customer_sk as ctr_customer_sk -,sr_store_sk as ctr_store_sk -,sum(SR_FEE) as ctr_total_return -from store_returns -,date_dim -where sr_returned_date_sk = d_date_sk -and d_year =2001 -group by sr_customer_sk -,sr_store_sk) - select c_customer_id -from customer_total_return ctr1 -,store -,customer -where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 -from customer_total_return ctr2 -where ctr1.ctr_store_sk = ctr2.ctr_store_sk) -and s_store_sk = ctr1.ctr_store_sk -and s_state = 'TX' -and ctr1.ctr_customer_sk = c_customer_sk -order by c_customer_id -limit 100; - --- end template query1.tpl query 72 in stream 5 --- start template query95.tpl query 73 in stream 5 -with /* TPC-DS query95.tpl 0.43 */ ws_wh as -(select ws1.ws_order_number,ws1.ws_warehouse_sk wh1,ws2.ws_warehouse_sk wh2 - from web_sales ws1,web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) - select - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2001-4-01' and - dateadd(day,60,cast('2001-4-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'OH' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and ws1.ws_order_number in (select ws_order_number - from ws_wh) -and ws1.ws_order_number in (select wr_order_number - from web_returns,ws_wh - where wr_order_number = ws_wh.ws_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query95.tpl query 73 in stream 5 --- start template query27a.tpl query 74 in stream 5 -with /* TPC-DS query27a.tpl 0.16 */ results as - (select i_item_id, - s_state, 0 as g_state, - ss_quantity agg1, - ss_list_price agg2, - ss_coupon_amt agg3, - ss_sales_price agg4 - from store_sales, customer_demographics, date_dim, store, item - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_store_sk = s_store_sk and - ss_cdemo_sk = cd_demo_sk and - cd_gender = 'F' and - cd_marital_status = 'S' and - cd_education_status = 'Primary' and - d_year = 2000 and - s_state in ('MI','OH', 'SC', 'MN', 'PA', 'NC') - ) - - select i_item_id, - s_state, g_state, agg1, agg2, agg3, agg4 - from ( - select i_item_id, s_state, 0 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4 from results - group by i_item_id, s_state - union all - select i_item_id, NULL AS s_state, 1 AS g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as s_state, 1 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - ) foo - order by i_item_id, s_state - limit 100; - --- end template query27a.tpl query 74 in stream 5 --- start template query44.tpl query 75 in stream 5 -select /* TPC-DS query44.tpl 0.4 */ asceding.rnk, i1.i_product_name best_performing, i2.i_product_name worst_performing -from(select * - from (select item_sk,rank() over (order by rank_col asc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 78 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 78 - and ss_cdemo_sk is null - group by ss_store_sk))V1)V11 - where rnk < 11) asceding, - (select * - from (select item_sk,rank() over (order by rank_col desc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 78 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 78 - and ss_cdemo_sk is null - group by ss_store_sk))V2)V21 - where rnk < 11) descending, -item i1, -item i2 -where asceding.rnk = descending.rnk - and i1.i_item_sk=asceding.item_sk - and i2.i_item_sk=descending.item_sk -order by asceding.rnk -limit 100; - --- end template query44.tpl query 75 in stream 5 --- start template query16.tpl query 76 in stream 5 -select /* TPC-DS query16.tpl 0.25 */ - count(distinct cs_order_number) as "order count" - ,sum(cs_ext_ship_cost) as "total shipping cost" - ,sum(cs_net_profit) as "total net profit" -from - catalog_sales cs1 - ,date_dim - ,customer_address - ,call_center -where - d_date between '1999-2-01' and - dateadd(day, 60, cast('1999-2-01' as date)) -and cs1.cs_ship_date_sk = d_date_sk -and cs1.cs_ship_addr_sk = ca_address_sk -and ca_state = 'MN' -and cs1.cs_call_center_sk = cc_call_center_sk -and cc_county in ('Kittitas County','Mobile County','Walker County','Barrow County', - 'Marshall County' -) -and exists (select * - from catalog_sales cs2 - where cs1.cs_order_number = cs2.cs_order_number - and cs1.cs_warehouse_sk <> cs2.cs_warehouse_sk) -and not exists(select * - from catalog_returns cr1 - where cs1.cs_order_number = cr1.cr_order_number) -order by count(distinct cs_order_number) -limit 100; - --- end template query16.tpl query 76 in stream 5 --- start template query64.tpl query 77 in stream 5 -with /* TPC-DS query64.tpl 0.20 */ cs_ui as - (select cs_item_sk - ,sum(cs_ext_list_price) as sale,sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit) as refund - from catalog_sales - ,catalog_returns - where cs_item_sk = cr_item_sk - and cs_order_number = cr_order_number - group by cs_item_sk - having sum(cs_ext_list_price)>2*sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit)), -cross_sales as - (select i_product_name product_name - ,i_item_sk item_sk - ,s_store_name store_name - ,s_zip store_zip - ,ad1.ca_street_number b_street_number - ,ad1.ca_street_name b_street_name - ,ad1.ca_city b_city - ,ad1.ca_zip b_zip - ,ad2.ca_street_number c_street_number - ,ad2.ca_street_name c_street_name - ,ad2.ca_city c_city - ,ad2.ca_zip c_zip - ,d1.d_year as syear - ,d2.d_year as fsyear - ,d3.d_year s2year - ,count(*) cnt - ,sum(ss_wholesale_cost) s1 - ,sum(ss_list_price) s2 - ,sum(ss_coupon_amt) s3 - FROM store_sales - ,store_returns - ,cs_ui - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,customer - ,customer_demographics cd1 - ,customer_demographics cd2 - ,promotion - ,household_demographics hd1 - ,household_demographics hd2 - ,customer_address ad1 - ,customer_address ad2 - ,income_band ib1 - ,income_band ib2 - ,item - WHERE ss_store_sk = s_store_sk AND - ss_sold_date_sk = d1.d_date_sk AND - ss_customer_sk = c_customer_sk AND - ss_cdemo_sk= cd1.cd_demo_sk AND - ss_hdemo_sk = hd1.hd_demo_sk AND - ss_addr_sk = ad1.ca_address_sk and - ss_item_sk = i_item_sk and - ss_item_sk = sr_item_sk and - ss_ticket_number = sr_ticket_number and - ss_item_sk = cs_ui.cs_item_sk and - c_current_cdemo_sk = cd2.cd_demo_sk AND - c_current_hdemo_sk = hd2.hd_demo_sk AND - c_current_addr_sk = ad2.ca_address_sk and - c_first_sales_date_sk = d2.d_date_sk and - c_first_shipto_date_sk = d3.d_date_sk and - ss_promo_sk = p_promo_sk and - hd1.hd_income_band_sk = ib1.ib_income_band_sk and - hd2.hd_income_band_sk = ib2.ib_income_band_sk and - cd1.cd_marital_status <> cd2.cd_marital_status and - i_color in ('peru','chiffon','salmon','lace','purple','antique') and - i_current_price between 36 and 36 + 10 and - i_current_price between 36 + 1 and 36 + 15 -group by i_product_name - ,i_item_sk - ,s_store_name - ,s_zip - ,ad1.ca_street_number - ,ad1.ca_street_name - ,ad1.ca_city - ,ad1.ca_zip - ,ad2.ca_street_number - ,ad2.ca_street_name - ,ad2.ca_city - ,ad2.ca_zip - ,d1.d_year - ,d2.d_year - ,d3.d_year -) -select cs1.product_name - ,cs1.store_name - ,cs1.store_zip - ,cs1.b_street_number - ,cs1.b_street_name - ,cs1.b_city - ,cs1.b_zip - ,cs1.c_street_number - ,cs1.c_street_name - ,cs1.c_city - ,cs1.c_zip - ,cs1.syear - ,cs1.cnt - ,cs1.s1 as s11 - ,cs1.s2 as s21 - ,cs1.s3 as s31 - ,cs2.s1 as s12 - ,cs2.s2 as s22 - ,cs2.s3 as s32 - ,cs2.syear - ,cs2.cnt -from cross_sales cs1,cross_sales cs2 -where cs1.item_sk=cs2.item_sk and - cs1.syear = 2000 and - cs2.syear = 2000 + 1 and - cs2.cnt <= cs1.cnt and - cs1.store_name = cs2.store_name and - cs1.store_zip = cs2.store_zip -order by cs1.product_name - ,cs1.store_name - ,cs2.cnt - ,cs1.s1 - ,cs2.s1; - --- end template query64.tpl query 77 in stream 5 --- start template query20.tpl query 78 in stream 5 -select /* TPC-DS query20.tpl 0.65 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(cs_ext_sales_price) as itemrevenue - ,sum(cs_ext_sales_price)*100/sum(sum(cs_ext_sales_price)) over - (partition by i_class) as revenueratio - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and i_category in ('Women', 'Books', 'Home') - and cs_sold_date_sk = d_date_sk - and d_date between cast('2000-04-08' as date) - and dateadd(day,30,cast('2000-04-08' as date)) - group by i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - order by i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query20.tpl query 78 in stream 5 --- start template query43.tpl query 79 in stream 5 -select /* TPC-DS query43.tpl 0.15 */ s_store_name, s_store_id, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from date_dim, store_sales, store - where d_date_sk = ss_sold_date_sk and - s_store_sk = ss_store_sk and - s_gmt_offset = -5 and - d_year = 1998 - group by s_store_name, s_store_id - order by s_store_name, s_store_id,sun_sales,mon_sales,tue_sales,wed_sales,thu_sales,fri_sales,sat_sales - limit 100; - --- end template query43.tpl query 79 in stream 5 --- start template query5a.tpl query 80 in stream 5 -with /* TPC-DS query5a.tpl 0.98 */ ssr as - (select s_store_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ss_store_sk as store_sk, - ss_sold_date_sk as date_sk, - ss_ext_sales_price as sales_price, - ss_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from store_sales - union all - select sr_store_sk as store_sk, - sr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - sr_return_amt as return_amt, - sr_net_loss as net_loss - from store_returns - ) salesreturns, - date_dim, - store - where date_sk = d_date_sk - and d_date between cast('2002-08-12' as date) - and dateadd(day,14,cast('2002-08-12' as date)) - and store_sk = s_store_sk - group by s_store_id) - , - csr as - (select cp_catalog_page_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select cs_catalog_page_sk as page_sk, - cs_sold_date_sk as date_sk, - cs_ext_sales_price as sales_price, - cs_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from catalog_sales - union all - select cr_catalog_page_sk as page_sk, - cr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - cr_return_amount as return_amt, - cr_net_loss as net_loss - from catalog_returns - ) salesreturns, - date_dim, - catalog_page - where date_sk = d_date_sk - and d_date between cast('2002-08-12' as date) - and dateadd(day,14,cast('2002-08-12' as date)) - and page_sk = cp_catalog_page_sk - group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ws_web_site_sk as wsr_web_site_sk, - ws_sold_date_sk as date_sk, - ws_ext_sales_price as sales_price, - ws_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from web_sales - union all - select ws_web_site_sk as wsr_web_site_sk, - wr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - wr_return_amt as return_amt, - wr_net_loss as net_loss - from web_returns left outer join web_sales on - ( wr_item_sk = ws_item_sk - and wr_order_number = ws_order_number) - ) salesreturns, - date_dim, - web_site - where date_sk = d_date_sk - and d_date between cast('2002-08-12' as date) - and dateadd(day,14,cast('2002-08-12' as date)) - and wsr_web_site_sk = web_site_sk - group by web_site_id) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || s_store_id as id - , sales - , returns - , (profit - profit_loss) as profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || cp_catalog_page_id as id - , sales - , returns - , (profit - profit_loss) as profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , (profit - profit_loss) as profit - from wsr - ) x - group by channel, id) - select channel, id, sales, returns, profit from ( - select channel, id, sales, returns, profit from results - union - select channel, null as id, sum(sales), sum(returns), sum(profit) from results group by channel - union - select null as channel, null as id, sum(sales), sum(returns), sum(profit) from results) foo -order by channel, id -limit 100; - --- end template query5a.tpl query 80 in stream 5 --- start template query47.tpl query 81 in stream 5 -with /* TPC-DS query47.tpl 0.42 */ v1 as( - select i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, - s_store_name, s_company_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - s_store_name, s_company_name - order by d_year, d_moy) rn - from item, store_sales, date_dim, store - where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - ( - d_year = 2000 or - ( d_year = 2000-1 and d_moy =12) or - ( d_year = 2000+1 and d_moy =1) - ) - group by i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy), - v2 as( - select v1.s_store_name - ,v1.d_year - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1.s_store_name = v1_lag.s_store_name and - v1.s_store_name = v1_lead.s_store_name and - v1.s_company_name = v1_lag.s_company_name and - v1.s_company_name = v1_lead.s_company_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 2000 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, psum - limit 100; - --- end template query47.tpl query 81 in stream 5 --- start template query10.tpl query 82 in stream 5 -select /* TPC-DS query10.tpl 0.26 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3, - cd_dep_count, - count(*) cnt4, - cd_dep_employed_count, - count(*) cnt5, - cd_dep_college_count, - count(*) cnt6 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_county in ('Mineral County','Lake County','Taylor County','Warren County','Meigs County') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 1 and 1+3) and - (exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 1 ANd 1+3) or - exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 1 and 1+3)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count -limit 100; - --- end template query10.tpl query 82 in stream 5 --- start template query70a.tpl query 83 in stream 5 -with /* TPC-DS query70a.tpl 0.34 */ results as -( select - sum(ss_net_profit) as total_sum ,s_state ,s_county, 0 as gstate, 0 as g_county - from - store_sales - ,date_dim d1 - ,store - where - d1.d_month_seq between 1190 and 1190 + 11 - and d1.d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - and s_state in - ( select s_state - from (select s_state as s_state, - rank() over ( partition by s_state order by sum(ss_net_profit) desc) as ranking - from store_sales, store, date_dim - where d_month_seq between 1190 and 1190 + 11 - and d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - group by s_state - ) tmp1 - where ranking <= 5) - group by s_state,s_county) , - results_rollup as -(select total_sum ,s_state ,s_county, 0 as g_state, 0 as g_county, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum,s_state, NULL as s_county, 0 as g_state, 1 as g_county, 1 as lochierarchy from results group by s_state - union - select sum(total_sum) as total_sum ,NULL as s_state ,NULL as s_county, 1 as g_state, 1 as g_county, 2 as lochierarchy from results) - select total_sum ,s_state ,s_county, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_county = 0 then s_state end - order by total_sum desc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then s_state end - ,rank_within_parent - limit 100; - --- end template query70a.tpl query 83 in stream 5 --- start template query39.tpl query 84 in stream 5 -with /* TPC-DS query39.tpl 0.5 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =2000 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=2 - and inv2.d_moy=2+1 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; -with /* TPC-DS query39.tpl 0.5 part2 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =2000 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=2 - and inv2.d_moy=2+1 - and inv1.cov > 1.5 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; - --- end template query39.tpl query 84 in stream 5 --- start template query72.tpl query 85 in stream 5 -select /* TPC-DS query72.tpl 0.87 */ i_item_desc - ,w_warehouse_name - ,d1.d_week_seq - ,sum(case when p_promo_sk is null then 1 else 0 end) no_promo - ,sum(case when p_promo_sk is not null then 1 else 0 end) promo - ,count(*) total_cnt -from catalog_sales -join inventory on (cs_item_sk = inv_item_sk) -join warehouse on (w_warehouse_sk=inv_warehouse_sk) -join item on (i_item_sk = cs_item_sk) -join customer_demographics on (cs_bill_cdemo_sk = cd_demo_sk) -join household_demographics on (cs_bill_hdemo_sk = hd_demo_sk) -join date_dim d1 on (cs_sold_date_sk = d1.d_date_sk) -join date_dim d2 on (inv_date_sk = d2.d_date_sk) -join date_dim d3 on (cs_ship_date_sk = d3.d_date_sk) -left outer join promotion on (cs_promo_sk=p_promo_sk) -left outer join catalog_returns on (cr_item_sk = cs_item_sk and cr_order_number = cs_order_number) -where d1.d_week_seq = d2.d_week_seq - and inv_quantity_on_hand < cs_quantity - and d3.d_date > d1.d_date + 5 - and hd_buy_potential = '>10000' - and d1.d_year = 2000 - and cd_marital_status = 'M' -group by i_item_desc,w_warehouse_name,d1.d_week_seq -order by total_cnt desc, i_item_desc, w_warehouse_name, d_week_seq -limit 100; - --- end template query72.tpl query 85 in stream 5 --- start template query75.tpl query 86 in stream 5 -WITH /* TPC-DS query75.tpl 0.3 */ all_sales AS ( - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,SUM(sales_cnt) AS sales_cnt - ,SUM(sales_amt) AS sales_amt - FROM (SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,cs_quantity - COALESCE(cr_return_quantity,0) AS sales_cnt - ,cs_ext_sales_price - COALESCE(cr_return_amount,0.0) AS sales_amt - FROM catalog_sales JOIN item ON i_item_sk=cs_item_sk - JOIN date_dim ON d_date_sk=cs_sold_date_sk - LEFT JOIN catalog_returns ON (cs_order_number=cr_order_number - AND cs_item_sk=cr_item_sk) - WHERE i_category='Women' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ss_quantity - COALESCE(sr_return_quantity,0) AS sales_cnt - ,ss_ext_sales_price - COALESCE(sr_return_amt,0.0) AS sales_amt - FROM store_sales JOIN item ON i_item_sk=ss_item_sk - JOIN date_dim ON d_date_sk=ss_sold_date_sk - LEFT JOIN store_returns ON (ss_ticket_number=sr_ticket_number - AND ss_item_sk=sr_item_sk) - WHERE i_category='Women' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ws_quantity - COALESCE(wr_return_quantity,0) AS sales_cnt - ,ws_ext_sales_price - COALESCE(wr_return_amt,0.0) AS sales_amt - FROM web_sales JOIN item ON i_item_sk=ws_item_sk - JOIN date_dim ON d_date_sk=ws_sold_date_sk - LEFT JOIN web_returns ON (ws_order_number=wr_order_number - AND ws_item_sk=wr_item_sk) - WHERE i_category='Women') sales_detail - GROUP BY d_year, i_brand_id, i_class_id, i_category_id, i_manufact_id) - SELECT prev_yr.d_year AS prev_year - ,curr_yr.d_year AS year - ,curr_yr.i_brand_id - ,curr_yr.i_class_id - ,curr_yr.i_category_id - ,curr_yr.i_manufact_id - ,prev_yr.sales_cnt AS prev_yr_cnt - ,curr_yr.sales_cnt AS curr_yr_cnt - ,curr_yr.sales_cnt-prev_yr.sales_cnt AS sales_cnt_diff - ,curr_yr.sales_amt-prev_yr.sales_amt AS sales_amt_diff - FROM all_sales curr_yr, all_sales prev_yr - WHERE curr_yr.i_brand_id=prev_yr.i_brand_id - AND curr_yr.i_class_id=prev_yr.i_class_id - AND curr_yr.i_category_id=prev_yr.i_category_id - AND curr_yr.i_manufact_id=prev_yr.i_manufact_id - AND curr_yr.d_year=2002 - AND prev_yr.d_year=2002-1 - AND CAST(curr_yr.sales_cnt AS DECIMAL(17,2))/CAST(prev_yr.sales_cnt AS DECIMAL(17,2))<0.9 - ORDER BY sales_cnt_diff,sales_amt_diff - limit 100; - --- end template query75.tpl query 86 in stream 5 --- start template query12.tpl query 87 in stream 5 -select /* TPC-DS query12.tpl 0.64 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ws_ext_sales_price) as itemrevenue - ,sum(ws_ext_sales_price)*100/sum(sum(ws_ext_sales_price)) over - (partition by i_class) as revenueratio -from - web_sales - ,item - ,date_dim -where - ws_item_sk = i_item_sk - and i_category in ('Shoes', 'Children', 'Books') - and ws_sold_date_sk = d_date_sk - and d_date between cast('2001-02-04' as date) - and dateadd(day,30,cast('2001-02-04' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query12.tpl query 87 in stream 5 --- start template query37.tpl query 88 in stream 5 -select /* TPC-DS query37.tpl 0.31 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, catalog_sales - where i_current_price between 53 and 53 + 30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('1998-03-04' as date) and dateadd(day,60,cast('1998-03-04' as date)) - and i_manufact_id in (773,826,710,954) - and inv_quantity_on_hand between 100 and 500 - and cs_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query37.tpl query 88 in stream 5 --- start template query15.tpl query 89 in stream 5 -select /* TPC-DS query15.tpl 0.57 */ ca_zip - ,sum(cs_sales_price) - from catalog_sales - ,customer - ,customer_address - ,date_dim - where cs_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', - '85392', '85460', '80348', '81792') - or ca_state in ('CA','WA','GA') - or cs_sales_price > 500) - and cs_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 1999 - group by ca_zip - order by ca_zip - limit 100; - --- end template query15.tpl query 89 in stream 5 --- start template query59.tpl query 90 in stream 5 -with /* TPC-DS query59.tpl 0.30 */ wss as - (select d_week_seq, - ss_store_sk, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - group by d_week_seq,ss_store_sk - ) - select s_store_name1,s_store_id1,d_week_seq1 - ,sun_sales1/sun_sales2,mon_sales1/mon_sales2 - ,tue_sales1/tue_sales2,wed_sales1/wed_sales2,thu_sales1/thu_sales2 - ,fri_sales1/fri_sales2,sat_sales1/sat_sales2 - from - (select s_store_name s_store_name1,wss.d_week_seq d_week_seq1 - ,s_store_id s_store_id1,sun_sales sun_sales1 - ,mon_sales mon_sales1,tue_sales tue_sales1 - ,wed_sales wed_sales1,thu_sales thu_sales1 - ,fri_sales fri_sales1,sat_sales sat_sales1 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1194 and 1194 + 11) y, - (select s_store_name s_store_name2,wss.d_week_seq d_week_seq2 - ,s_store_id s_store_id2,sun_sales sun_sales2 - ,mon_sales mon_sales2,tue_sales tue_sales2 - ,wed_sales wed_sales2,thu_sales thu_sales2 - ,fri_sales fri_sales2,sat_sales sat_sales2 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1194+ 12 and 1194 + 23) x - where s_store_id1=s_store_id2 - and d_week_seq1=d_week_seq2-52 - order by s_store_name1,s_store_id1,d_week_seq1 -limit 100; - --- end template query59.tpl query 90 in stream 5 --- start template query91.tpl query 91 in stream 5 -select /* TPC-DS query91.tpl 0.13 */ - cc_call_center_id Call_Center, - cc_name Call_Center_Name, - cc_manager Manager, - sum(cr_net_loss) Returns_Loss -from - call_center, - catalog_returns, - date_dim, - customer, - customer_address, - customer_demographics, - household_demographics -where - cr_call_center_sk = cc_call_center_sk -and cr_returned_date_sk = d_date_sk -and cr_returning_customer_sk= c_customer_sk -and cd_demo_sk = c_current_cdemo_sk -and hd_demo_sk = c_current_hdemo_sk -and ca_address_sk = c_current_addr_sk -and d_year = 1998 -and d_moy = 12 -and ( (cd_marital_status = 'M' and cd_education_status = 'Unknown') - or(cd_marital_status = 'W' and cd_education_status = 'Advanced Degree')) -and hd_buy_potential like '0-500%' -and ca_gmt_offset = -6 -group by cc_call_center_id,cc_name,cc_manager,cd_marital_status,cd_education_status -order by sum(cr_net_loss) desc; - --- end template query91.tpl query 91 in stream 5 --- start template query99.tpl query 92 in stream 5 -select /* TPC-DS query99.tpl 0.94 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 30) and - (cs_ship_date_sk - cs_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 60) and - (cs_ship_date_sk - cs_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 90) and - (cs_ship_date_sk - cs_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - catalog_sales - ,warehouse - ,ship_mode - ,call_center - ,date_dim -where - d_month_seq between 1193 and 1193 + 11 -and cs_ship_date_sk = d_date_sk -and cs_warehouse_sk = w_warehouse_sk -and cs_ship_mode_sk = sm_ship_mode_sk -and cs_call_center_sk = cc_call_center_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -limit 100; - --- end template query99.tpl query 92 in stream 5 --- start template query41.tpl query 93 in stream 5 -select /* TPC-DS query41.tpl 0.62 */ distinct(i_product_name) - from item i1 - where i_manufact_id between 687 and 687+40 - and (select count(*) as item_cnt - from item - where (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'puff' or i_color = 'purple') and - (i_units = 'N/A' or i_units = 'Dram') and - (i_size = 'medium' or i_size = 'extra large') - ) or - (i_category = 'Women' and - (i_color = 'navy' or i_color = 'saddle') and - (i_units = 'Ton' or i_units = 'Pallet') and - (i_size = 'small' or i_size = 'large') - ) or - (i_category = 'Men' and - (i_color = 'yellow' or i_color = 'ivory') and - (i_units = 'Bunch' or i_units = 'Each') and - (i_size = 'N/A' or i_size = 'economy') - ) or - (i_category = 'Men' and - (i_color = 'blanched' or i_color = 'white') and - (i_units = 'Box' or i_units = 'Case') and - (i_size = 'medium' or i_size = 'extra large') - ))) or - (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'plum' or i_color = 'burlywood') and - (i_units = 'Carton' or i_units = 'Unknown') and - (i_size = 'medium' or i_size = 'extra large') - ) or - (i_category = 'Women' and - (i_color = 'smoke' or i_color = 'rose') and - (i_units = 'Oz' or i_units = 'Cup') and - (i_size = 'small' or i_size = 'large') - ) or - (i_category = 'Men' and - (i_color = 'linen' or i_color = 'aquamarine') and - (i_units = 'Gross' or i_units = 'Pound') and - (i_size = 'N/A' or i_size = 'economy') - ) or - (i_category = 'Men' and - (i_color = 'orchid' or i_color = 'lavender') and - (i_units = 'Lb' or i_units = 'Gram') and - (i_size = 'medium' or i_size = 'extra large') - )))) > 0 - order by i_product_name - limit 100; - --- end template query41.tpl query 93 in stream 5 --- start template query9.tpl query 94 in stream 5 -select /* TPC-DS query9.tpl 0.49 */ case when (select count(*) - from store_sales - where ss_quantity between 1 and 20) > 84676842 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 1 and 20) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 1 and 20) end bucket1 , - case when (select count(*) - from store_sales - where ss_quantity between 21 and 40) > 38436486 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 21 and 40) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 21 and 40) end bucket2, - case when (select count(*) - from store_sales - where ss_quantity between 41 and 60) > 27330240 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 41 and 60) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 41 and 60) end bucket3, - case when (select count(*) - from store_sales - where ss_quantity between 61 and 80) > 25343 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 61 and 80) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 61 and 80) end bucket4, - case when (select count(*) - from store_sales - where ss_quantity between 81 and 100) > 71846204 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 81 and 100) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 81 and 100) end bucket5 -from reason -where r_reason_sk = 1 -; - --- end template query9.tpl query 94 in stream 5 --- start template query86a.tpl query 95 in stream 5 -with /* TPC-DS query86a.tpl 0.11 */ results as -( select sum(ws_net_paid) as total_sum, i_category, i_class, 0 as g_category, 0 as g_class - from - web_sales - ,date_dim d1 - ,item - where - d1.d_month_seq between 1182 and 1182+11 - and d1.d_date_sk = ws_sold_date_sk - and i_item_sk = ws_item_sk - group by i_category,i_class - ) , - - results_rollup as -( select total_sum ,i_category ,i_class, g_category, g_class, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum, i_category, NULL as i_class, 0 as g_category, 1 as g_class, 1 as lochierarchy from results group by i_category - union - select sum(total_sum) as total_sum, NULL as i_category, NULL as i_class, 1 as g_category, 1 as g_class, 2 as lochierarchy from results) - select - total_sum ,i_category ,i_class, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_class = 0 then i_category end - order by total_sum desc) as rank_within_parent - from - results_rollup - order by - lochierarchy desc, - case when lochierarchy = 0 then i_category end, - rank_within_parent - limit 100; - --- end template query86a.tpl query 95 in stream 5 --- start template query34.tpl query 96 in stream 5 -select /* TPC-DS query34.tpl 0.73 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (date_dim.d_dom between 1 and 3 or date_dim.d_dom between 25 and 28) - and (household_demographics.hd_buy_potential = '501-1000' or - household_demographics.hd_buy_potential = 'Unknown') - and household_demographics.hd_vehicle_count > 0 - and (case when household_demographics.hd_vehicle_count > 0 - then household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count - else null - end) > 1.2 - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_county in ('Sierra County','Adams County','San Miguel County','Mesa County', - 'Appanoose County','Levy County','Wadena County','Fairfield County') - group by ss_ticket_number,ss_customer_sk) dn,customer - where ss_customer_sk = c_customer_sk - and cnt between 15 and 20 - order by c_last_name,c_first_name,c_salutation,c_preferred_cust_flag desc, ss_ticket_number; - --- end template query34.tpl query 96 in stream 5 --- start template query82.tpl query 97 in stream 5 -select /* TPC-DS query82.tpl 0.67 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, store_sales - where i_current_price between 29 and 29+30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('1998-03-17' as date) and dateadd(day,60,cast('1998-03-17' as date)) - and i_manufact_id in (28,183,805,309) - and inv_quantity_on_hand between 100 and 500 - and ss_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query82.tpl query 97 in stream 5 --- start template query29.tpl query 98 in stream 5 -select /* TPC-DS query29.tpl 0.53 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,min(ss_quantity) as store_sales_quantity - ,min(sr_return_quantity) as store_returns_quantity - ,min(cs_quantity) as catalog_sales_quantity - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 1999 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 4 + 3 - and d2.d_year = 1999 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_year in (1999,1999+1,1999+2) - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query29.tpl query 98 in stream 5 --- start template query25.tpl query 99 in stream 5 -select /* TPC-DS query25.tpl 0.9 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,sum(ss_net_profit) as store_sales_profit - ,sum(sr_net_loss) as store_returns_loss - ,sum(cs_net_profit) as catalog_sales_profit - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 2001 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 10 - and d2.d_year = 2001 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_moy between 4 and 10 - and d3.d_year = 2001 - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query25.tpl query 99 in stream 5 diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/3TB/queries/query_6.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/3TB/queries/query_6.sql deleted file mode 100644 index 6ec798a9..00000000 --- a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/3TB/queries/query_6.sql +++ /dev/null @@ -1,5027 +0,0 @@ --- start template query34.tpl query 1 in stream 6 -select /* TPC-DS query34.tpl 0.73 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (date_dim.d_dom between 1 and 3 or date_dim.d_dom between 25 and 28) - and (household_demographics.hd_buy_potential = '1001-5000' or - household_demographics.hd_buy_potential = '0-500') - and household_demographics.hd_vehicle_count > 0 - and (case when household_demographics.hd_vehicle_count > 0 - then household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count - else null - end) > 1.2 - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_county in ('Orange County','Jefferson Davis Parish','Coal County','Fairfield County', - 'Harper County','Dauphin County','Williamson County','Terrell County') - group by ss_ticket_number,ss_customer_sk) dn,customer - where ss_customer_sk = c_customer_sk - and cnt between 15 and 20 - order by c_last_name,c_first_name,c_salutation,c_preferred_cust_flag desc, ss_ticket_number; - --- end template query34.tpl query 1 in stream 6 --- start template query88.tpl query 2 in stream 6 -select /* TPC-DS query88.tpl 0.66 */ * -from - (select count(*) h8_30_to_9 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s1, - (select count(*) h9_to_9_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s2, - (select count(*) h9_30_to_10 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s3, - (select count(*) h10_to_10_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s4, - (select count(*) h10_30_to_11 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s5, - (select count(*) h11_to_11_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s6, - (select count(*) h11_30_to_12 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s7, - (select count(*) h12_to_12_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 12 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s8 -; - --- end template query88.tpl query 2 in stream 6 --- start template query44.tpl query 3 in stream 6 -select /* TPC-DS query44.tpl 0.4 */ asceding.rnk, i1.i_product_name best_performing, i2.i_product_name worst_performing -from(select * - from (select item_sk,rank() over (order by rank_col asc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 153 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 153 - and ss_customer_sk is null - group by ss_store_sk))V1)V11 - where rnk < 11) asceding, - (select * - from (select item_sk,rank() over (order by rank_col desc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 153 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 153 - and ss_customer_sk is null - group by ss_store_sk))V2)V21 - where rnk < 11) descending, -item i1, -item i2 -where asceding.rnk = descending.rnk - and i1.i_item_sk=asceding.item_sk - and i2.i_item_sk=descending.item_sk -order by asceding.rnk -limit 100; - --- end template query44.tpl query 3 in stream 6 --- start template query94.tpl query 4 in stream 6 -select /* TPC-DS query94.tpl 0.17 */ - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2000-4-01' and - dateadd(day,60,cast('2000-4-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'AR' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and exists (select * - from web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) -and not exists(select * - from web_returns wr1 - where ws1.ws_order_number = wr1.wr_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query94.tpl query 4 in stream 6 --- start template query50.tpl query 5 in stream 6 -select /* TPC-DS query50.tpl 0.60 */ - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 30) and - (sr_returned_date_sk - ss_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 60) and - (sr_returned_date_sk - ss_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 90) and - (sr_returned_date_sk - ss_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - store_sales - ,store_returns - ,store - ,date_dim d1 - ,date_dim d2 -where - d2.d_year = 2001 -and d2.d_moy = 9 -and ss_ticket_number = sr_ticket_number -and ss_item_sk = sr_item_sk -and ss_sold_date_sk = d1.d_date_sk -and sr_returned_date_sk = d2.d_date_sk -and ss_customer_sk = sr_customer_sk -and ss_store_sk = s_store_sk -group by - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -order by s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -limit 100; - --- end template query50.tpl query 5 in stream 6 --- start template query5a.tpl query 6 in stream 6 -with /* TPC-DS query5a.tpl 0.98 */ ssr as - (select s_store_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ss_store_sk as store_sk, - ss_sold_date_sk as date_sk, - ss_ext_sales_price as sales_price, - ss_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from store_sales - union all - select sr_store_sk as store_sk, - sr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - sr_return_amt as return_amt, - sr_net_loss as net_loss - from store_returns - ) salesreturns, - date_dim, - store - where date_sk = d_date_sk - and d_date between cast('1999-08-17' as date) - and dateadd(day,14,cast('1999-08-17' as date)) - and store_sk = s_store_sk - group by s_store_id) - , - csr as - (select cp_catalog_page_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select cs_catalog_page_sk as page_sk, - cs_sold_date_sk as date_sk, - cs_ext_sales_price as sales_price, - cs_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from catalog_sales - union all - select cr_catalog_page_sk as page_sk, - cr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - cr_return_amount as return_amt, - cr_net_loss as net_loss - from catalog_returns - ) salesreturns, - date_dim, - catalog_page - where date_sk = d_date_sk - and d_date between cast('1999-08-17' as date) - and dateadd(day,14,cast('1999-08-17' as date)) - and page_sk = cp_catalog_page_sk - group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ws_web_site_sk as wsr_web_site_sk, - ws_sold_date_sk as date_sk, - ws_ext_sales_price as sales_price, - ws_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from web_sales - union all - select ws_web_site_sk as wsr_web_site_sk, - wr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - wr_return_amt as return_amt, - wr_net_loss as net_loss - from web_returns left outer join web_sales on - ( wr_item_sk = ws_item_sk - and wr_order_number = ws_order_number) - ) salesreturns, - date_dim, - web_site - where date_sk = d_date_sk - and d_date between cast('1999-08-17' as date) - and dateadd(day,14,cast('1999-08-17' as date)) - and wsr_web_site_sk = web_site_sk - group by web_site_id) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || s_store_id as id - , sales - , returns - , (profit - profit_loss) as profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || cp_catalog_page_id as id - , sales - , returns - , (profit - profit_loss) as profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , (profit - profit_loss) as profit - from wsr - ) x - group by channel, id) - select channel, id, sales, returns, profit from ( - select channel, id, sales, returns, profit from results - union - select channel, null as id, sum(sales), sum(returns), sum(profit) from results group by channel - union - select null as channel, null as id, sum(sales), sum(returns), sum(profit) from results) foo -order by channel, id -limit 100; - --- end template query5a.tpl query 6 in stream 6 --- start template query53.tpl query 7 in stream 6 -select /* TPC-DS query53.tpl 0.88 */ * from -(select i_manufact_id, -sum(ss_sales_price) sum_sales, -avg(sum(ss_sales_price)) over (partition by i_manufact_id) avg_quarterly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and -ss_sold_date_sk = d_date_sk and -ss_store_sk = s_store_sk and -d_month_seq in (1211,1211+1,1211+2,1211+3,1211+4,1211+5,1211+6,1211+7,1211+8,1211+9,1211+10,1211+11) and -((i_category in ('Books','Children','Electronics') and -i_class in ('personal','portable','reference','self-help') and -i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) -or(i_category in ('Women','Music','Men') and -i_class in ('accessories','classical','fragrances','pants') and -i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manufact_id, d_qoy ) tmp1 -where case when avg_quarterly_sales > 0 - then abs (sum_sales - avg_quarterly_sales)/ avg_quarterly_sales - else null end > 0.1 -order by avg_quarterly_sales, - sum_sales, - i_manufact_id -limit 100; - --- end template query53.tpl query 7 in stream 6 --- start template query7.tpl query 8 in stream 6 -select /* TPC-DS query7.tpl 0.2 */ i_item_id, - avg(ss_quantity) agg1, - avg(ss_list_price) agg2, - avg(ss_coupon_amt) agg3, - avg(ss_sales_price) agg4 - from store_sales, customer_demographics, date_dim, item, promotion - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_cdemo_sk = cd_demo_sk and - ss_promo_sk = p_promo_sk and - cd_gender = 'M' and - cd_marital_status = 'W' and - cd_education_status = '4 yr Degree' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 1999 - group by i_item_id - order by i_item_id - limit 100; - --- end template query7.tpl query 8 in stream 6 --- start template query58.tpl query 9 in stream 6 -with /* TPC-DS query58.tpl 0.19 */ ss_items as - (select i_item_id item_id - ,sum(ss_ext_sales_price) ss_item_rev - from store_sales - ,item - ,date_dim - where ss_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '1998-03-24')) - and ss_sold_date_sk = d_date_sk - group by i_item_id), - cs_items as - (select i_item_id item_id - ,sum(cs_ext_sales_price) cs_item_rev - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '1998-03-24')) - and cs_sold_date_sk = d_date_sk - group by i_item_id), - ws_items as - (select i_item_id item_id - ,sum(ws_ext_sales_price) ws_item_rev - from web_sales - ,item - ,date_dim - where ws_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq =(select d_week_seq - from date_dim - where d_date = '1998-03-24')) - and ws_sold_date_sk = d_date_sk - group by i_item_id) - select ss_items.item_id - ,ss_item_rev - ,ss_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ss_dev - ,cs_item_rev - ,cs_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 cs_dev - ,ws_item_rev - ,ws_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ws_dev - ,(ss_item_rev+cs_item_rev+ws_item_rev)/3 average - from ss_items,cs_items,ws_items - where ss_items.item_id=cs_items.item_id - and ss_items.item_id=ws_items.item_id - and ss_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - and ss_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and cs_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and cs_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and ws_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and ws_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - order by item_id - ,ss_item_rev - limit 100; - --- end template query58.tpl query 9 in stream 6 --- start template query20.tpl query 10 in stream 6 -select /* TPC-DS query20.tpl 0.65 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(cs_ext_sales_price) as itemrevenue - ,sum(cs_ext_sales_price)*100/sum(sum(cs_ext_sales_price)) over - (partition by i_class) as revenueratio - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and i_category in ('Jewelry', 'Shoes', 'Children') - and cs_sold_date_sk = d_date_sk - and d_date between cast('1998-03-13' as date) - and dateadd(day,30,cast('1998-03-13' as date)) - group by i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - order by i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query20.tpl query 10 in stream 6 --- start template query75.tpl query 11 in stream 6 -WITH /* TPC-DS query75.tpl 0.3 */ all_sales AS ( - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,SUM(sales_cnt) AS sales_cnt - ,SUM(sales_amt) AS sales_amt - FROM (SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,cs_quantity - COALESCE(cr_return_quantity,0) AS sales_cnt - ,cs_ext_sales_price - COALESCE(cr_return_amount,0.0) AS sales_amt - FROM catalog_sales JOIN item ON i_item_sk=cs_item_sk - JOIN date_dim ON d_date_sk=cs_sold_date_sk - LEFT JOIN catalog_returns ON (cs_order_number=cr_order_number - AND cs_item_sk=cr_item_sk) - WHERE i_category='Men' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ss_quantity - COALESCE(sr_return_quantity,0) AS sales_cnt - ,ss_ext_sales_price - COALESCE(sr_return_amt,0.0) AS sales_amt - FROM store_sales JOIN item ON i_item_sk=ss_item_sk - JOIN date_dim ON d_date_sk=ss_sold_date_sk - LEFT JOIN store_returns ON (ss_ticket_number=sr_ticket_number - AND ss_item_sk=sr_item_sk) - WHERE i_category='Men' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ws_quantity - COALESCE(wr_return_quantity,0) AS sales_cnt - ,ws_ext_sales_price - COALESCE(wr_return_amt,0.0) AS sales_amt - FROM web_sales JOIN item ON i_item_sk=ws_item_sk - JOIN date_dim ON d_date_sk=ws_sold_date_sk - LEFT JOIN web_returns ON (ws_order_number=wr_order_number - AND ws_item_sk=wr_item_sk) - WHERE i_category='Men') sales_detail - GROUP BY d_year, i_brand_id, i_class_id, i_category_id, i_manufact_id) - SELECT prev_yr.d_year AS prev_year - ,curr_yr.d_year AS year - ,curr_yr.i_brand_id - ,curr_yr.i_class_id - ,curr_yr.i_category_id - ,curr_yr.i_manufact_id - ,prev_yr.sales_cnt AS prev_yr_cnt - ,curr_yr.sales_cnt AS curr_yr_cnt - ,curr_yr.sales_cnt-prev_yr.sales_cnt AS sales_cnt_diff - ,curr_yr.sales_amt-prev_yr.sales_amt AS sales_amt_diff - FROM all_sales curr_yr, all_sales prev_yr - WHERE curr_yr.i_brand_id=prev_yr.i_brand_id - AND curr_yr.i_class_id=prev_yr.i_class_id - AND curr_yr.i_category_id=prev_yr.i_category_id - AND curr_yr.i_manufact_id=prev_yr.i_manufact_id - AND curr_yr.d_year=1999 - AND prev_yr.d_year=1999-1 - AND CAST(curr_yr.sales_cnt AS DECIMAL(17,2))/CAST(prev_yr.sales_cnt AS DECIMAL(17,2))<0.9 - ORDER BY sales_cnt_diff,sales_amt_diff - limit 100; - --- end template query75.tpl query 11 in stream 6 --- start template query73.tpl query 12 in stream 6 -select /* TPC-DS query73.tpl 0.79 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_buy_potential = '1001-5000' or - household_demographics.hd_buy_potential = 'Unknown') - and household_demographics.hd_vehicle_count > 0 - and case when household_demographics.hd_vehicle_count > 0 then - household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count else null end > 1 - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_county in ('Mesa County','Richland County','Dauphin County','Jackson County') - group by ss_ticket_number,ss_customer_sk) dj,customer - where ss_customer_sk = c_customer_sk - and cnt between 1 and 5 - order by cnt desc, c_last_name asc; - --- end template query73.tpl query 12 in stream 6 --- start template query91.tpl query 13 in stream 6 -select /* TPC-DS query91.tpl 0.13 */ - cc_call_center_id Call_Center, - cc_name Call_Center_Name, - cc_manager Manager, - sum(cr_net_loss) Returns_Loss -from - call_center, - catalog_returns, - date_dim, - customer, - customer_address, - customer_demographics, - household_demographics -where - cr_call_center_sk = cc_call_center_sk -and cr_returned_date_sk = d_date_sk -and cr_returning_customer_sk= c_customer_sk -and cd_demo_sk = c_current_cdemo_sk -and hd_demo_sk = c_current_hdemo_sk -and ca_address_sk = c_current_addr_sk -and d_year = 2000 -and d_moy = 11 -and ( (cd_marital_status = 'M' and cd_education_status = 'Unknown') - or(cd_marital_status = 'W' and cd_education_status = 'Advanced Degree')) -and hd_buy_potential like '0-500%' -and ca_gmt_offset = -6 -group by cc_call_center_id,cc_name,cc_manager,cd_marital_status,cd_education_status -order by sum(cr_net_loss) desc; - --- end template query91.tpl query 13 in stream 6 --- start template query36a.tpl query 14 in stream 6 -with /* TPC-DS query36a.tpl 0.21 */ results as - (select - sum(ss_net_profit) as ss_net_profit, sum(ss_ext_sales_price) as ss_ext_sales_price, - sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin - ,i_category - ,i_class - ,0 as g_category, 0 as g_class - from - store_sales - ,date_dim d1 - ,item - ,store - where - d1.d_year = 1999 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and s_state in ('NE','TN','IN','MO', - 'WA','CO','WV','SC') - group by i_category,i_class) - , - results_rollup as - (select gross_margin ,i_category ,i_class,0 as t_category, 0 as t_class, 0 as lochierarchy from results - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - i_category, NULL AS i_class, 0 as t_category, 1 as t_class, 1 as lochierarchy from results group by i_category - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - NULL AS i_category ,NULL AS i_class, 1 as t_category, 1 as t_class, 2 as lochierarchy from results) - select - gross_margin ,i_category ,i_class, lochierarchy,rank() over ( - partition by lochierarchy, case when t_class = 0 then i_category end - order by gross_margin asc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then i_category end - ,rank_within_parent - limit 100; - --- end template query36a.tpl query 14 in stream 6 --- start template query11.tpl query 15 in stream 6 -with /* TPC-DS query11.tpl 0.51 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ss_ext_list_price-ss_ext_discount_amt) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ws_ext_list_price-ws_ext_discount_amt) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_login - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 1999 - and t_s_secyear.dyear = 1999+1 - and t_w_firstyear.dyear = 1999 - and t_w_secyear.dyear = 1999+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else 0.0 end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else 0.0 end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_login -limit 100; - --- end template query11.tpl query 15 in stream 6 --- start template query80a.tpl query 16 in stream 6 -with /* TPC-DS query80a.tpl 0.6 */ ssr as - (select s_store_id as store_id, - sum(ss_ext_sales_price) as sales, - sum(coalesce(sr_return_amt, 0)) as returns, - sum(ss_net_profit - coalesce(sr_net_loss, 0)) as profit - from store_sales left outer join store_returns on - (ss_item_sk = sr_item_sk and ss_ticket_number = sr_ticket_number), - date_dim, - store, - item, - promotion - where ss_sold_date_sk = d_date_sk - and d_date between cast('2001-08-08' as date) - and dateadd(day,30,cast('2001-08-08' as date)) - and ss_store_sk = s_store_sk - and ss_item_sk = i_item_sk - and i_current_price > 50 - and ss_promo_sk = p_promo_sk - and p_channel_tv = 'N' - group by s_store_id) - , - csr as - (select cp_catalog_page_id as catalog_page_id, - sum(cs_ext_sales_price) as sales, - sum(coalesce(cr_return_amount, 0)) as returns, - sum(cs_net_profit - coalesce(cr_net_loss, 0)) as profit - from catalog_sales left outer join catalog_returns on - (cs_item_sk = cr_item_sk and cs_order_number = cr_order_number), - date_dim, - catalog_page, - item, - promotion - where cs_sold_date_sk = d_date_sk - and d_date between cast('2001-08-08' as date) - and dateadd(day,30,cast('2001-08-08' as date)) - and cs_catalog_page_sk = cp_catalog_page_sk - and cs_item_sk = i_item_sk - and i_current_price > 50 - and cs_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(ws_ext_sales_price) as sales, - sum(coalesce(wr_return_amt, 0)) as returns, - sum(ws_net_profit - coalesce(wr_net_loss, 0)) as profit - from web_sales left outer join web_returns on - (ws_item_sk = wr_item_sk and ws_order_number = wr_order_number), - date_dim, - web_site, - item, - promotion - where ws_sold_date_sk = d_date_sk - and d_date between cast('2001-08-08' as date) - and dateadd(day,30,cast('2001-08-08' as date)) - and ws_web_site_sk = web_site_sk - and ws_item_sk = i_item_sk - and i_current_price > 50 - and ws_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by web_site_id) -, -results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || store_id as id - , sales - , returns - , profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || catalog_page_id as id - , sales - , returns - , profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , profit - from wsr - ) x - group by channel, id) - - select channel - , id - , sales - , returns - , profit - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results - ) foo - order by channel, id - limit 100; - --- end template query80a.tpl query 16 in stream 6 --- start template query9.tpl query 17 in stream 6 -select /* TPC-DS query9.tpl 0.49 */ case when (select count(*) - from store_sales - where ss_quantity between 1 and 20) > 107891285 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 1 and 20) - else (select avg(ss_net_profit) - from store_sales - where ss_quantity between 1 and 20) end bucket1 , - case when (select count(*) - from store_sales - where ss_quantity between 21 and 40) > 70534593 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 21 and 40) - else (select avg(ss_net_profit) - from store_sales - where ss_quantity between 21 and 40) end bucket2, - case when (select count(*) - from store_sales - where ss_quantity between 41 and 60) > 23070723 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 41 and 60) - else (select avg(ss_net_profit) - from store_sales - where ss_quantity between 41 and 60) end bucket3, - case when (select count(*) - from store_sales - where ss_quantity between 61 and 80) > 7558254 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 61 and 80) - else (select avg(ss_net_profit) - from store_sales - where ss_quantity between 61 and 80) end bucket4, - case when (select count(*) - from store_sales - where ss_quantity between 81 and 100) > 141263814 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 81 and 100) - else (select avg(ss_net_profit) - from store_sales - where ss_quantity between 81 and 100) end bucket5 -from reason -where r_reason_sk = 1 -; - --- end template query9.tpl query 17 in stream 6 --- start template query93.tpl query 18 in stream 6 -select /* TPC-DS query93.tpl 0.52 */ ss_customer_sk - ,sum(act_sales) sumsales - from (select ss_item_sk - ,ss_ticket_number - ,ss_customer_sk - ,case when sr_return_quantity is not null then (ss_quantity-sr_return_quantity)*ss_sales_price - else (ss_quantity*ss_sales_price) end act_sales - from store_sales left outer join store_returns on (sr_item_sk = ss_item_sk - and sr_ticket_number = ss_ticket_number) - ,reason - where sr_reason_sk = r_reason_sk - and r_reason_desc = 'reason 24') t - group by ss_customer_sk - order by sumsales, ss_customer_sk -limit 100; - --- end template query93.tpl query 18 in stream 6 --- start template query32.tpl query 19 in stream 6 -select /* TPC-DS query32.tpl 0.7 */ sum(cs_ext_discount_amt) as "excess discount amount" -from - catalog_sales - ,item - ,date_dim -where -i_manufact_id = 248 -and i_item_sk = cs_item_sk -and d_date between '2002-01-09' and - dateadd(day,90,cast('2002-01-09' as date)) -and d_date_sk = cs_sold_date_sk -and cs_ext_discount_amt - > ( - select - 1.3 * avg(cs_ext_discount_amt) - from - catalog_sales - ,date_dim - where - cs_item_sk = i_item_sk - and d_date between '2002-01-09' and - dateadd(day,90,cast('2002-01-09' as date)) - and d_date_sk = cs_sold_date_sk - ) -limit 100; - --- end template query32.tpl query 19 in stream 6 --- start template query89.tpl query 20 in stream 6 -select /* TPC-DS query89.tpl 0.56 */ * -from( -select i_category, i_class, i_brand, - s_store_name, s_company_name, - d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, s_store_name, s_company_name) - avg_monthly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - d_year in (2002) and - ((i_category in ('Books','Home','Electronics') and - i_class in ('computers','decor','disk drives') - ) - or (i_category in ('Music','Jewelry','Children') and - i_class in ('pop','bracelets','toddlers') - )) -group by i_category, i_class, i_brand, - s_store_name, s_company_name, d_moy) tmp1 -where case when (avg_monthly_sales <> 0) then (abs(sum_sales - avg_monthly_sales) / avg_monthly_sales) else null end > 0.1 -order by sum_sales - avg_monthly_sales, s_store_name -limit 100; - --- end template query89.tpl query 20 in stream 6 --- start template query28.tpl query 21 in stream 6 -select /* TPC-DS query28.tpl 0.36 */ * -from (select avg(ss_list_price) B1_LP - ,count(ss_list_price) B1_CNT - ,count(distinct ss_list_price) B1_CNTD - from store_sales - where ss_quantity between 0 and 5 - and (ss_list_price between 153 and 153+10 - or ss_coupon_amt between 4195 and 4195+1000 - or ss_wholesale_cost between 76 and 76+20)) B1, - (select avg(ss_list_price) B2_LP - ,count(ss_list_price) B2_CNT - ,count(distinct ss_list_price) B2_CNTD - from store_sales - where ss_quantity between 6 and 10 - and (ss_list_price between 15 and 15+10 - or ss_coupon_amt between 11023 and 11023+1000 - or ss_wholesale_cost between 69 and 69+20)) B2, - (select avg(ss_list_price) B3_LP - ,count(ss_list_price) B3_CNT - ,count(distinct ss_list_price) B3_CNTD - from store_sales - where ss_quantity between 11 and 15 - and (ss_list_price between 58 and 58+10 - or ss_coupon_amt between 3016 and 3016+1000 - or ss_wholesale_cost between 24 and 24+20)) B3, - (select avg(ss_list_price) B4_LP - ,count(ss_list_price) B4_CNT - ,count(distinct ss_list_price) B4_CNTD - from store_sales - where ss_quantity between 16 and 20 - and (ss_list_price between 175 and 175+10 - or ss_coupon_amt between 9132 and 9132+1000 - or ss_wholesale_cost between 1 and 1+20)) B4, - (select avg(ss_list_price) B5_LP - ,count(ss_list_price) B5_CNT - ,count(distinct ss_list_price) B5_CNTD - from store_sales - where ss_quantity between 21 and 25 - and (ss_list_price between 141 and 141+10 - or ss_coupon_amt between 4 and 4+1000 - or ss_wholesale_cost between 62 and 62+20)) B5, - (select avg(ss_list_price) B6_LP - ,count(ss_list_price) B6_CNT - ,count(distinct ss_list_price) B6_CNTD - from store_sales - where ss_quantity between 26 and 30 - and (ss_list_price between 181 and 181+10 - or ss_coupon_amt between 10 and 10+1000 - or ss_wholesale_cost between 13 and 13+20)) B6 -limit 100; - --- end template query28.tpl query 21 in stream 6 --- start template query87.tpl query 22 in stream 6 -select /* TPC-DS query87.tpl 0.77 */ count(*) -from ((select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1196 and 1196+11) - except - (select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1196 and 1196+11) - except - (select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1196 and 1196+11) -) cool_cust -; - --- end template query87.tpl query 22 in stream 6 --- start template query18a.tpl query 23 in stream 6 -with /* TPC-DS query18a.tpl 0.90 */ results as - (select i_item_id, - ca_country, - ca_state, - ca_county, - cast(cs_quantity as decimal(12,2)) agg1, - cast(cs_list_price as decimal(12,2)) agg2, - cast(cs_coupon_amt as decimal(12,2)) agg3, - cast(cs_sales_price as decimal(12,2)) agg4, - cast(cs_net_profit as decimal(12,2)) agg5, - cast(c_birth_year as decimal(12,2)) agg6, - cast(cd1.cd_dep_count as decimal(12,2)) agg7 - from catalog_sales, customer_demographics cd1, customer_demographics cd2, customer, customer_address, date_dim, item - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd1.cd_demo_sk and - cs_bill_customer_sk = c_customer_sk and - cd1.cd_gender = 'F' and - cd1.cd_education_status = 'Unknown' and - c_current_cdemo_sk = cd2.cd_demo_sk and - c_current_addr_sk = ca_address_sk and - c_birth_month in (11,8,12,4,2,10) and - d_year = 2002 and - ca_state in ('TX','NE','VA','HI','WI','VT','PA') - ) - select i_item_id, ca_country, ca_state, ca_county, agg1, agg2, agg3, agg4, agg5, agg6, agg7 - from ( - select i_item_id, ca_country, ca_state, ca_county, avg(agg1) agg1, - avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state, ca_county - union all - select i_item_id, ca_country, ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state - union all - select i_item_id, ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country - union all - select i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - ) foo - order by ca_country, ca_state, ca_county, i_item_id - limit 100; - --- end template query18a.tpl query 23 in stream 6 --- start template query74.tpl query 24 in stream 6 -with /* TPC-DS query74.tpl 0.76 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,max(ss_net_paid) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1998,1998+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,max(ws_net_paid) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - and d_year in (1998,1998+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - ) - select - t_s_secyear.customer_id, t_s_secyear.customer_first_name, t_s_secyear.customer_last_name - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.year = 1998 - and t_s_secyear.year = 1998+1 - and t_w_firstyear.year = 1998 - and t_w_secyear.year = 1998+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - order by 2,3,1 -limit 100; - --- end template query74.tpl query 24 in stream 6 --- start template query6.tpl query 25 in stream 6 -select /* TPC-DS query6.tpl 0.58 */ a.ca_state state, count(*) cnt - from customer_address a - ,customer c - ,store_sales s - ,date_dim d - ,item i - where a.ca_address_sk = c.c_current_addr_sk - and c.c_customer_sk = s.ss_customer_sk - and s.ss_sold_date_sk = d.d_date_sk - and s.ss_item_sk = i.i_item_sk - and d.d_month_seq = - (select distinct (d_month_seq) - from date_dim - where d_year = 1999 - and d_moy = 4 ) - and i.i_current_price > 1.2 * - (select avg(j.i_current_price) - from item j - where j.i_category = i.i_category) - group by a.ca_state - having count(*) >= 10 - order by cnt, a.ca_state - limit 100; - --- end template query6.tpl query 25 in stream 6 --- start template query65.tpl query 26 in stream 6 -select /* TPC-DS query65.tpl 0.71 */ - s_store_name, - i_item_desc, - sc.revenue, - i_current_price, - i_wholesale_cost, - i_brand - from store, item, - (select ss_store_sk, avg(revenue) as ave - from - (select ss_store_sk, ss_item_sk, - sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1180 and 1180+11 - group by ss_store_sk, ss_item_sk) sa - group by ss_store_sk) sb, - (select ss_store_sk, ss_item_sk, sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1180 and 1180+11 - group by ss_store_sk, ss_item_sk) sc - where sb.ss_store_sk = sc.ss_store_sk and - sc.revenue <= 0.1 * sb.ave and - s_store_sk = sc.ss_store_sk and - i_item_sk = sc.ss_item_sk - order by s_store_name, i_item_desc -limit 100; - --- end template query65.tpl query 26 in stream 6 --- start template query84.tpl query 27 in stream 6 -select /* TPC-DS query84.tpl 0.80 */ c_customer_id as customer_id - , coalesce(c_last_name,'') || ', ' || coalesce(c_first_name,'') as customername - from customer - ,customer_address - ,customer_demographics - ,household_demographics - ,income_band - ,store_returns - where ca_city = 'Riverside' - and c_current_addr_sk = ca_address_sk - and ib_lower_bound >= 849 - and ib_upper_bound <= 849 + 50000 - and ib_income_band_sk = hd_income_band_sk - and cd_demo_sk = c_current_cdemo_sk - and hd_demo_sk = c_current_hdemo_sk - and sr_cdemo_sk = cd_demo_sk - order by c_customer_id - limit 100; - --- end template query84.tpl query 27 in stream 6 --- start template query14a.tpl query 28 in stream 6 -with /* TPC-DS query14a.tpl 0.69 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 2000 AND 2000 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 2000 AND 2000 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 2000 AND 2000 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as - (select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2) x) -, - results AS -(select channel, i_brand_id, i_class_id, i_category_id, sum(sales) sum_sales, sum(number_sales) number_sales - from ( - select 'store' channel, i_brand_id,i_class_id - ,i_category_id,sum(ss_quantity*ss_list_price) sales - , count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2000+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales) - union all - select 'catalog' channel, i_brand_id,i_class_id,i_category_id, sum(cs_quantity*cs_list_price) sales, count(*) number_sales - from catalog_sales - ,item - ,date_dim - where cs_item_sk in (select ss_item_sk from cross_items) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2000+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(cs_quantity*cs_list_price) > (select average_sales from avg_sales) - union all - select 'web' channel, i_brand_id,i_class_id,i_category_id, sum(ws_quantity*ws_list_price) sales , count(*) number_sales - from web_sales - ,item - ,date_dim - where ws_item_sk in (select ss_item_sk from cross_items) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2000+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ws_quantity*ws_list_price) > (select average_sales from avg_sales) - ) y - group by channel, i_brand_id,i_class_id,i_category_id) - - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales -from ( - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales from results - union - select channel, i_brand_id, i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id, i_class_id - union - select channel, i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id - union - select channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel - union - select null as channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results) z -order by channel, i_brand_id, i_class_id, i_category_id - limit 100; -with /* TPC-DS query14a.tpl 0.69 part2 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 2000 AND 2000 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 2000 AND 2000 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 2000 AND 2000 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as -(select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2) x) - select this_year.channel ty_channel - ,this_year.i_brand_id ty_brand - ,this_year.i_class_id ty_class - ,this_year.i_category_id ty_category - ,this_year.sales ty_sales - ,this_year.number_sales ty_number_sales - ,last_year.channel ly_channel - ,last_year.i_brand_id ly_brand - ,last_year.i_class_id ly_class - ,last_year.i_category_id ly_category - ,last_year.sales ly_sales - ,last_year.number_sales ly_number_sales -from - (select 'store' channel, i_brand_id,i_class_id,i_category_id - ,sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 2000 + 1 - and d_moy = 12 - and d_dom = 10) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) this_year, - (select 'store' channel, i_brand_id,i_class_id - ,i_category_id, sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 2000 - and d_moy = 12 - and d_dom = 10) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) last_year - where this_year.i_brand_id= last_year.i_brand_id - and this_year.i_class_id = last_year.i_class_id - and this_year.i_category_id = last_year.i_category_id - order by this_year.channel, this_year.i_brand_id, this_year.i_class_id, this_year.i_category_id - limit 100; - --- end template query14a.tpl query 28 in stream 6 --- start template query38.tpl query 29 in stream 6 -select /* TPC-DS query38.tpl 0.54 */ count(*) from ( - select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1184 and 1184 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1184 and 1184 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1184 and 1184 + 11 -) hot_cust -limit 100; - --- end template query38.tpl query 29 in stream 6 --- start template query24.tpl query 30 in stream 6 -with /* TPC-DS query24.tpl 0.92 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_net_paid) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip -and s_market_id=8 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'royal' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; -with /* TPC-DS query24.tpl 0.92 part2 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_net_paid) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip - and s_market_id = 8 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'tomato' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; - --- end template query24.tpl query 30 in stream 6 --- start template query42.tpl query 31 in stream 6 -select /* TPC-DS query42.tpl 0.61 */ dt.d_year - ,item.i_category_id - ,item.i_category - ,sum(ss_ext_sales_price) - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=12 - and dt.d_year=1999 - group by dt.d_year - ,item.i_category_id - ,item.i_category - order by sum(ss_ext_sales_price) desc,dt.d_year - ,item.i_category_id - ,item.i_category -limit 100 ; - --- end template query42.tpl query 31 in stream 6 --- start template query29.tpl query 32 in stream 6 -select /* TPC-DS query29.tpl 0.53 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,max(ss_quantity) as store_sales_quantity - ,max(sr_return_quantity) as store_returns_quantity - ,max(cs_quantity) as catalog_sales_quantity - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 2000 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 4 + 3 - and d2.d_year = 2000 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_year in (2000,2000+1,2000+2) - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query29.tpl query 32 in stream 6 --- start template query72.tpl query 33 in stream 6 -select /* TPC-DS query72.tpl 0.87 */ i_item_desc - ,w_warehouse_name - ,d1.d_week_seq - ,sum(case when p_promo_sk is null then 1 else 0 end) no_promo - ,sum(case when p_promo_sk is not null then 1 else 0 end) promo - ,count(*) total_cnt -from catalog_sales -join inventory on (cs_item_sk = inv_item_sk) -join warehouse on (w_warehouse_sk=inv_warehouse_sk) -join item on (i_item_sk = cs_item_sk) -join customer_demographics on (cs_bill_cdemo_sk = cd_demo_sk) -join household_demographics on (cs_bill_hdemo_sk = hd_demo_sk) -join date_dim d1 on (cs_sold_date_sk = d1.d_date_sk) -join date_dim d2 on (inv_date_sk = d2.d_date_sk) -join date_dim d3 on (cs_ship_date_sk = d3.d_date_sk) -left outer join promotion on (cs_promo_sk=p_promo_sk) -left outer join catalog_returns on (cr_item_sk = cs_item_sk and cr_order_number = cs_order_number) -where d1.d_week_seq = d2.d_week_seq - and inv_quantity_on_hand < cs_quantity - and d3.d_date > d1.d_date + 5 - and hd_buy_potential = '501-1000' - and d1.d_year = 1998 - and cd_marital_status = 'M' -group by i_item_desc,w_warehouse_name,d1.d_week_seq -order by total_cnt desc, i_item_desc, w_warehouse_name, d_week_seq -limit 100; - --- end template query72.tpl query 33 in stream 6 --- start template query23.tpl query 34 in stream 6 -with /* TPC-DS query23.tpl 0.68 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (1999,1999+1,1999+2,1999+3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1999,1999+1,1999+2,1999+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * -from - max_store_sales)) - select sum(sales) - from (select cs_quantity*cs_list_price sales - from catalog_sales - ,date_dim - where d_year = 1999 - and d_moy = 7 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - union all - select ws_quantity*ws_list_price sales - from web_sales - ,date_dim - where d_year = 1999 - and d_moy = 7 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer)) - limit 100; -with /* TPC-DS query23.tpl 0.68 part2 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (1999,1999 + 1,1999 + 2,1999 + 3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1999,1999+1,1999+2,1999+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * - from max_store_sales)) - select c_last_name,c_first_name,sales - from (select c_last_name,c_first_name,sum(cs_quantity*cs_list_price) sales - from catalog_sales - ,customer - ,date_dim - where d_year = 1999 - and d_moy = 7 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and cs_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name - union all - select c_last_name,c_first_name,sum(ws_quantity*ws_list_price) sales - from web_sales - ,customer - ,date_dim - where d_year = 1999 - and d_moy = 7 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and ws_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name) - order by c_last_name,c_first_name,sales - limit 100; - --- end template query23.tpl query 34 in stream 6 --- start template query26.tpl query 35 in stream 6 -select /* TPC-DS query26.tpl 0.85 */ i_item_id, - avg(cs_quantity) agg1, - avg(cs_list_price) agg2, - avg(cs_coupon_amt) agg3, - avg(cs_sales_price) agg4 - from catalog_sales, customer_demographics, date_dim, item, promotion - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd_demo_sk and - cs_promo_sk = p_promo_sk and - cd_gender = 'M' and - cd_marital_status = 'U' and - cd_education_status = 'Unknown' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 1998 - group by i_item_id - order by i_item_id - limit 100; - --- end template query26.tpl query 35 in stream 6 --- start template query69.tpl query 36 in stream 6 -select /* TPC-DS query69.tpl 0.28 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_state in ('SC','MO','NE') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 1999 and - d_moy between 1 and 1+2) and - (not exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 1999 and - d_moy between 1 and 1+2) and - not exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 1999 and - d_moy between 1 and 1+2)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - limit 100; - --- end template query69.tpl query 36 in stream 6 --- start template query47.tpl query 37 in stream 6 -with /* TPC-DS query47.tpl 0.42 */ v1 as( - select i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, - s_store_name, s_company_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - s_store_name, s_company_name - order by d_year, d_moy) rn - from item, store_sales, date_dim, store - where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - ( - d_year = 2001 or - ( d_year = 2001-1 and d_moy =12) or - ( d_year = 2001+1 and d_moy =1) - ) - group by i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy), - v2 as( - select v1.s_company_name - ,v1.d_year, v1.d_moy - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1.s_store_name = v1_lag.s_store_name and - v1.s_store_name = v1_lead.s_store_name and - v1.s_company_name = v1_lag.s_company_name and - v1.s_company_name = v1_lead.s_company_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 2001 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, nsum - limit 100; - --- end template query47.tpl query 37 in stream 6 --- start template query82.tpl query 38 in stream 6 -select /* TPC-DS query82.tpl 0.67 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, store_sales - where i_current_price between 81 and 81+30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('1999-05-08' as date) and dateadd(day,60,cast('1999-05-08' as date)) - and i_manufact_id in (342,91,222,313) - and inv_quantity_on_hand between 100 and 500 - and ss_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query82.tpl query 38 in stream 6 --- start template query31.tpl query 39 in stream 6 -with /* TPC-DS query31.tpl 0.50 */ ss as - (select ca_county,d_qoy, d_year,sum(ss_ext_sales_price) as store_sales - from store_sales,date_dim,customer_address - where ss_sold_date_sk = d_date_sk - and ss_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year), - ws as - (select ca_county,d_qoy, d_year,sum(ws_ext_sales_price) as web_sales - from web_sales,date_dim,customer_address - where ws_sold_date_sk = d_date_sk - and ws_bill_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year) - select - ss1.ca_county - ,ss1.d_year - ,ws2.web_sales/ws1.web_sales web_q1_q2_increase - ,ss2.store_sales/ss1.store_sales store_q1_q2_increase - ,ws3.web_sales/ws2.web_sales web_q2_q3_increase - ,ss3.store_sales/ss2.store_sales store_q2_q3_increase - from - ss ss1 - ,ss ss2 - ,ss ss3 - ,ws ws1 - ,ws ws2 - ,ws ws3 - where - ss1.d_qoy = 1 - and ss1.d_year = 2002 - and ss1.ca_county = ss2.ca_county - and ss2.d_qoy = 2 - and ss2.d_year = 2002 - and ss2.ca_county = ss3.ca_county - and ss3.d_qoy = 3 - and ss3.d_year = 2002 - and ss1.ca_county = ws1.ca_county - and ws1.d_qoy = 1 - and ws1.d_year = 2002 - and ws1.ca_county = ws2.ca_county - and ws2.d_qoy = 2 - and ws2.d_year = 2002 - and ws1.ca_county = ws3.ca_county - and ws3.d_qoy = 3 - and ws3.d_year =2002 - and case when ws1.web_sales > 0 then ws2.web_sales/ws1.web_sales else null end - > case when ss1.store_sales > 0 then ss2.store_sales/ss1.store_sales else null end - and case when ws2.web_sales > 0 then ws3.web_sales/ws2.web_sales else null end - > case when ss2.store_sales > 0 then ss3.store_sales/ss2.store_sales else null end - order by store_q1_q2_increase; - --- end template query31.tpl query 39 in stream 6 --- start template query59.tpl query 40 in stream 6 -with /* TPC-DS query59.tpl 0.30 */ wss as - (select d_week_seq, - ss_store_sk, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - group by d_week_seq,ss_store_sk - ) - select s_store_name1,s_store_id1,d_week_seq1 - ,sun_sales1/sun_sales2,mon_sales1/mon_sales2 - ,tue_sales1/tue_sales2,wed_sales1/wed_sales2,thu_sales1/thu_sales2 - ,fri_sales1/fri_sales2,sat_sales1/sat_sales2 - from - (select s_store_name s_store_name1,wss.d_week_seq d_week_seq1 - ,s_store_id s_store_id1,sun_sales sun_sales1 - ,mon_sales mon_sales1,tue_sales tue_sales1 - ,wed_sales wed_sales1,thu_sales thu_sales1 - ,fri_sales fri_sales1,sat_sales sat_sales1 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1194 and 1194 + 11) y, - (select s_store_name s_store_name2,wss.d_week_seq d_week_seq2 - ,s_store_id s_store_id2,sun_sales sun_sales2 - ,mon_sales mon_sales2,tue_sales tue_sales2 - ,wed_sales wed_sales2,thu_sales thu_sales2 - ,fri_sales fri_sales2,sat_sales sat_sales2 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1194+ 12 and 1194 + 23) x - where s_store_id1=s_store_id2 - and d_week_seq1=d_week_seq2-52 - order by s_store_name1,s_store_id1,d_week_seq1 -limit 100; - --- end template query59.tpl query 40 in stream 6 --- start template query49.tpl query 41 in stream 6 -select /* TPC-DS query49.tpl 0.48 */ channel, item, return_ratio, return_rank, currency_rank from - (select - 'web' as channel - ,web.item - ,web.return_ratio - ,web.return_rank - ,web.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select ws.ws_item_sk as item - ,(cast(sum(coalesce(wr.wr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(wr.wr_return_amt,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - web_sales ws left outer join web_returns wr - on (ws.ws_order_number = wr.wr_order_number and - ws.ws_item_sk = wr.wr_item_sk) - ,date_dim - where - wr.wr_return_amt > 10000 - and ws.ws_net_profit > 1 - and ws.ws_net_paid > 0 - and ws.ws_quantity > 0 - and ws_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 12 - group by ws.ws_item_sk - ) in_web - ) web - where - ( - web.return_rank <= 10 - or - web.currency_rank <= 10 - ) - union - select - 'catalog' as channel - ,catalog.item - ,catalog.return_ratio - ,catalog.return_rank - ,catalog.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select - cs.cs_item_sk as item - ,(cast(sum(coalesce(cr.cr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(cr.cr_return_amount,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - catalog_sales cs left outer join catalog_returns cr - on (cs.cs_order_number = cr.cr_order_number and - cs.cs_item_sk = cr.cr_item_sk) - ,date_dim - where - cr.cr_return_amount > 10000 - and cs.cs_net_profit > 1 - and cs.cs_net_paid > 0 - and cs.cs_quantity > 0 - and cs_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 12 - group by cs.cs_item_sk - ) in_cat - ) catalog - where - ( - catalog.return_rank <= 10 - or - catalog.currency_rank <=10 - ) - union - select - 'store' as channel - ,store.item - ,store.return_ratio - ,store.return_rank - ,store.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select sts.ss_item_sk as item - ,(cast(sum(coalesce(sr.sr_return_quantity,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(sr.sr_return_amt,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - store_sales sts left outer join store_returns sr - on (sts.ss_ticket_number = sr.sr_ticket_number and sts.ss_item_sk = sr.sr_item_sk) - ,date_dim - where - sr.sr_return_amt > 10000 - and sts.ss_net_profit > 1 - and sts.ss_net_paid > 0 - and sts.ss_quantity > 0 - and ss_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 12 - group by sts.ss_item_sk - ) in_store - ) store - where ( - store.return_rank <= 10 - or - store.currency_rank <= 10 - ) - ) - order by 1,4,5,2 - limit 100; - --- end template query49.tpl query 41 in stream 6 --- start template query33.tpl query 42 in stream 6 -with /* TPC-DS query33.tpl 0.22 */ ss as ( - select - i_manufact_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Sports')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 6 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -7 - group by i_manufact_id), - cs as ( - select - i_manufact_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Sports')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 6 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -7 - group by i_manufact_id), - ws as ( - select - i_manufact_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Sports')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 6 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -7 - group by i_manufact_id) - select i_manufact_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_manufact_id - order by total_sales -limit 100; - --- end template query33.tpl query 42 in stream 6 --- start template query86a.tpl query 43 in stream 6 -with /* TPC-DS query86a.tpl 0.11 */ results as -( select sum(ws_net_paid) as total_sum, i_category, i_class, 0 as g_category, 0 as g_class - from - web_sales - ,date_dim d1 - ,item - where - d1.d_month_seq between 1222 and 1222+11 - and d1.d_date_sk = ws_sold_date_sk - and i_item_sk = ws_item_sk - group by i_category,i_class - ) , - - results_rollup as -( select total_sum ,i_category ,i_class, g_category, g_class, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum, i_category, NULL as i_class, 0 as g_category, 1 as g_class, 1 as lochierarchy from results group by i_category - union - select sum(total_sum) as total_sum, NULL as i_category, NULL as i_class, 1 as g_category, 1 as g_class, 2 as lochierarchy from results) - select - total_sum ,i_category ,i_class, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_class = 0 then i_category end - order by total_sum desc) as rank_within_parent - from - results_rollup - order by - lochierarchy desc, - case when lochierarchy = 0 then i_category end, - rank_within_parent - limit 100; - --- end template query86a.tpl query 43 in stream 6 --- start template query99.tpl query 44 in stream 6 -select /* TPC-DS query99.tpl 0.94 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 30) and - (cs_ship_date_sk - cs_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 60) and - (cs_ship_date_sk - cs_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 90) and - (cs_ship_date_sk - cs_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - catalog_sales - ,warehouse - ,ship_mode - ,call_center - ,date_dim -where - d_month_seq between 1201 and 1201 + 11 -and cs_ship_date_sk = d_date_sk -and cs_warehouse_sk = w_warehouse_sk -and cs_ship_mode_sk = sm_ship_mode_sk -and cs_call_center_sk = cc_call_center_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -limit 100; - --- end template query99.tpl query 44 in stream 6 --- start template query4.tpl query 45 in stream 6 -with /* TPC-DS query4.tpl 0.93 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(((ss_ext_list_price-ss_ext_wholesale_cost-ss_ext_discount_amt)+ss_ext_sales_price)/2) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((cs_ext_list_price-cs_ext_wholesale_cost-cs_ext_discount_amt)+cs_ext_sales_price)/2) ) year_total - ,'c' sale_type - from customer - ,catalog_sales - ,date_dim - where c_customer_sk = cs_bill_customer_sk - and cs_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year -union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((ws_ext_list_price-ws_ext_wholesale_cost-ws_ext_discount_amt)+ws_ext_sales_price)/2) ) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_login - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_c_firstyear - ,year_total t_c_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_c_secyear.customer_id - and t_s_firstyear.customer_id = t_c_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_c_firstyear.sale_type = 'c' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_c_secyear.sale_type = 'c' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 1998 - and t_s_secyear.dyear = 1998+1 - and t_c_firstyear.dyear = 1998 - and t_c_secyear.dyear = 1998+1 - and t_w_firstyear.dyear = 1998 - and t_w_secyear.dyear = 1998+1 - and t_s_firstyear.year_total > 0 - and t_c_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_login -limit 100; - --- end template query4.tpl query 45 in stream 6 --- start template query45.tpl query 46 in stream 6 -select /* TPC-DS query45.tpl 0.18 */ ca_zip, ca_county, sum(ws_sales_price) - from web_sales, customer, customer_address, date_dim, item - where ws_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ws_item_sk = i_item_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', '85392', '85460', '80348', '81792') - or - i_item_id in (select i_item_id - from item - where i_item_sk in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29) - ) - ) - and ws_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 2002 - group by ca_zip, ca_county - order by ca_zip, ca_county - limit 100; - --- end template query45.tpl query 46 in stream 6 --- start template query85.tpl query 47 in stream 6 -select /* TPC-DS query85.tpl 0.33 */ substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) - from web_sales, web_returns, web_page, customer_demographics cd1, - customer_demographics cd2, customer_address, date_dim, reason - where ws_web_page_sk = wp_web_page_sk - and ws_item_sk = wr_item_sk - and ws_order_number = wr_order_number - and ws_sold_date_sk = d_date_sk and d_year = 1999 - and cd1.cd_demo_sk = wr_refunded_cdemo_sk - and cd2.cd_demo_sk = wr_returning_cdemo_sk - and ca_address_sk = wr_refunded_addr_sk - and r_reason_sk = wr_reason_sk - and - ( - ( - cd1.cd_marital_status = 'W' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Secondary' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 100.00 and 150.00 - ) - or - ( - cd1.cd_marital_status = 'M' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = '4 yr Degree' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 50.00 and 100.00 - ) - or - ( - cd1.cd_marital_status = 'D' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = '2 yr Degree' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ca_country = 'United States' - and - ca_state in ('VA', 'IA', 'MN') - and ws_net_profit between 100 and 200 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('OR', 'WV', 'KS') - and ws_net_profit between 150 and 300 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('LA', 'MD', 'TN') - and ws_net_profit between 50 and 250 - ) - ) -group by r_reason_desc -order by substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) -limit 100; - --- end template query85.tpl query 47 in stream 6 --- start template query8.tpl query 48 in stream 6 -select /* TPC-DS query8.tpl 0.63 */ s_store_name - ,sum(ss_net_profit) - from store_sales - ,date_dim - ,store, - (select ca_zip - from ( - SELECT substring(ca_zip,1,5) ca_zip - FROM customer_address - WHERE substring(ca_zip,1,5) IN ( - '47792','57955','42788','78317','55713','39639', - '32424','15538','28514','69134','45217', - '61435','50147','62099','23908','16053', - '73173','84101','82884','90260','20750', - '97142','85617','80083','96286','27536', - '40549','11107','62812','75856','46523', - '55556','54307','18053','79308','93617', - '60989','19914','98651','10284','37539', - '66032','84857','14395','71795','77471', - '50367','62559','48526','47648','16271', - '47382','51597','11070','94634','87558', - '45410','53359','22859','47162','41319', - '86998','53235','15453','28847','30620', - '21485','61135','11845','92819','46157', - '97845','86575','81166','52005','38985', - '33975','84761','30048','37285','28409', - '23936','56017','17216','31535','18679', - '28298','44436','25186','58270','34316', - '17840','20297','39999','75278','98330', - '52468','81936','42792','56625','30729', - '99012','43727','86957','33571','60180', - '13582','46369','87122','24245','62962', - '94557','32621','55696','42728','12892', - '61292','90896','76751','78917','62536', - '38991','60525','88400','51632','55592', - '68789','63802','95305','92685','55155', - '53066','56347','42779','22128','46813', - '57061','59820','68385','35188','43913', - '63102','14263','80594','60675','22133', - '11456','88882','64007','34928','18795', - '79415','66112','63295','48049','95391', - '67867','64292','80661','61870','68662', - '22067','26983','45961','35365','45059', - '45332','53931','83271','48316','52820', - '81471','58518','74206','86776','19826', - '57005','65044','13276','57946','96675', - '23274','88779','87243','11706','43720', - '57112','42062','96771','90153','69138', - '83993','57532','94756','35434','28908', - '33423','97043','21150','33637','86828', - '62644','52540','23449','34297','31615', - '45384','63722','28985','50707','44426', - '98035','84687','71223','46274','42754', - '52289','81983','60442','30140','75551', - '55423','11363','64673','58740','83847', - '23752','67683','96966','48245','14920', - '79811','12876','22279','64595','41530', - '28665','92075','13128','40982','21189', - '17902','66960','46002','54695','87628', - '29652','49132','40798','39612','15360', - '94289','15781','12650','99737','97228', - '14151','55137','61878','50013','59932', - '52053','72299','52263','94003','39393', - '10398','55601','84223','23060','73925', - '61361','28858','77909','77495','51460', - '65769','16196','72201','25413','41465', - '39628','88740','62172','85568','78383', - '23122','24424','37113','31311','34453', - '77105','80857','46772','99718','32906', - '87491','73852','70361','36843','39034', - '15159','72821','92716','72620','23986', - '12030','11015','22064','36619','23416', - '35253','82403','66826','33294','41898', - '13074','46973','98415','47386','68828', - '14145','97463','83989','26168','26034', - '94104','23402','70142','52520','20303', - '31820','90078','86349','69409','10622', - '16753','89980','62146','45962','88845', - '97587','44220','43827','41515','72853', - '73583','77396','22438','62217','27011', - '11213','96999','25006','38595','68405', - '92253','29896','77598','82684','69356', - '43393','79497','79757','82229','49965', - '48528','48788','79434','34558','38662', - '60899','36019','43814','91936','23032', - '27040','57999','19790','73001','31506', - '59037','36323','39142','76521','90534', - '55316','63147','75477','33383','51157', - '59509','52128','64610','77024','22764', - '36913','13833','63263','25708') - intersect - select ca_zip - from (SELECT substring(ca_zip,1,5) ca_zip,count(*) cnt - FROM customer_address, customer - WHERE ca_address_sk = c_current_addr_sk and - c_preferred_cust_flag='Y' - group by ca_zip - having count(*) > 10)A1)A2) V1 - where ss_store_sk = s_store_sk - and ss_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 2002 - and (substring(s_zip,1,2) = substring(V1.ca_zip,1,2)) - group by s_store_name - order by s_store_name - limit 100; - --- end template query8.tpl query 48 in stream 6 --- start template query19.tpl query 49 in stream 6 -select /* TPC-DS query19.tpl 0.8 */ i_brand_id brand_id, i_brand brand, i_manufact_id, i_manufact, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item,customer,customer_address,store - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=17 - and d_moy=12 - and d_year=2002 - and ss_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and substring(ca_zip,1,5) <> substring(s_zip,1,5) - and ss_store_sk = s_store_sk - group by i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact - order by ext_price desc - ,i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact -limit 100 ; - --- end template query19.tpl query 49 in stream 6 --- start template query61.tpl query 50 in stream 6 -select /* TPC-DS query61.tpl 0.97 */ promotions,total,cast(promotions as decimal(15,4))/cast(total as decimal(15,4))*100 -from - (select sum(ss_ext_sales_price) promotions - from store_sales - ,store - ,promotion - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_promo_sk = p_promo_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -6 - and i_category = 'Sports' - and (p_channel_dmail = 'Y' or p_channel_email = 'Y' or p_channel_tv = 'Y') - and s_gmt_offset = -6 - and d_year = 1998 - and d_moy = 12) promotional_sales, - (select sum(ss_ext_sales_price) total - from store_sales - ,store - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -6 - and i_category = 'Sports' - and s_gmt_offset = -6 - and d_year = 1998 - and d_moy = 12) all_sales -order by promotions, total -limit 100; - --- end template query61.tpl query 50 in stream 6 --- start template query3.tpl query 51 in stream 6 -select /* TPC-DS query3.tpl 0.45 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_sales_price) sum_agg - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manufact_id = 313 - and dt.d_moy=11 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,sum_agg desc - ,brand_id - limit 100; - --- end template query3.tpl query 51 in stream 6 --- start template query41.tpl query 52 in stream 6 -select /* TPC-DS query41.tpl 0.62 */ distinct(i_product_name) - from item i1 - where i_manufact_id between 932 and 932+40 - and (select count(*) as item_cnt - from item - where (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'goldenrod' or i_color = 'turquoise') and - (i_units = 'Pallet' or i_units = 'Carton') and - (i_size = 'extra large' or i_size = 'medium') - ) or - (i_category = 'Women' and - (i_color = 'sky' or i_color = 'slate') and - (i_units = 'Tsp' or i_units = 'Box') and - (i_size = 'large' or i_size = 'economy') - ) or - (i_category = 'Men' and - (i_color = 'royal' or i_color = 'chocolate') and - (i_units = 'Unknown' or i_units = 'Tbl') and - (i_size = 'petite' or i_size = 'small') - ) or - (i_category = 'Men' and - (i_color = 'puff' or i_color = 'hot') and - (i_units = 'Cup' or i_units = 'Gross') and - (i_size = 'extra large' or i_size = 'medium') - ))) or - (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'olive' or i_color = 'wheat') and - (i_units = 'N/A' or i_units = 'Gram') and - (i_size = 'extra large' or i_size = 'medium') - ) or - (i_category = 'Women' and - (i_color = 'burlywood' or i_color = 'lawn') and - (i_units = 'Oz' or i_units = 'Bunch') and - (i_size = 'large' or i_size = 'economy') - ) or - (i_category = 'Men' and - (i_color = 'bisque' or i_color = 'forest') and - (i_units = 'Dram' or i_units = 'Ounce') and - (i_size = 'petite' or i_size = 'small') - ) or - (i_category = 'Men' and - (i_color = 'frosted' or i_color = 'indian') and - (i_units = 'Lb' or i_units = 'Dozen') and - (i_size = 'extra large' or i_size = 'medium') - )))) > 0 - order by i_product_name - limit 100; - --- end template query41.tpl query 52 in stream 6 --- start template query54.tpl query 53 in stream 6 -with /* TPC-DS query54.tpl 0.81 */ my_customers as ( - select distinct c_customer_sk - , c_current_addr_sk - from - ( select cs_sold_date_sk sold_date_sk, - cs_bill_customer_sk customer_sk, - cs_item_sk item_sk - from catalog_sales - union all - select ws_sold_date_sk sold_date_sk, - ws_bill_customer_sk customer_sk, - ws_item_sk item_sk - from web_sales - ) cs_or_ws_sales, - item, - date_dim, - customer - where sold_date_sk = d_date_sk - and item_sk = i_item_sk - and i_category = 'Children' - and i_class = 'infants' - and c_customer_sk = cs_or_ws_sales.customer_sk - and d_moy = 7 - and d_year = 1999 - ) - , my_revenue as ( - select c_customer_sk, - sum(ss_ext_sales_price) as revenue - from my_customers, - store_sales, - customer_address, - store, - date_dim - where c_current_addr_sk = ca_address_sk - and ca_county = s_county - and ca_state = s_state - and ss_sold_date_sk = d_date_sk - and c_customer_sk = ss_customer_sk - and d_month_seq between (select distinct d_month_seq+1 - from date_dim where d_year = 1999 and d_moy = 7) - and (select distinct d_month_seq+3 - from date_dim where d_year = 1999 and d_moy = 7) - group by c_customer_sk - ) - , segments as - (select cast((revenue/50) as int) as segment - from my_revenue - ) - select segment, count(*) as num_customers, segment*50 as segment_base - from segments - group by segment - order by segment, num_customers - limit 100; - --- end template query54.tpl query 53 in stream 6 --- start template query67a.tpl query 54 in stream 6 -with /* TPC-DS query67a.tpl 0.35 */ results as -( select i_category ,i_class ,i_brand ,i_product_name ,d_year ,d_qoy ,d_moy ,s_store_id - ,sum(coalesce(ss_sales_price*ss_quantity,0)) sumsales - from store_sales ,date_dim ,store ,item - where ss_sold_date_sk=d_date_sk - and ss_item_sk=i_item_sk - and ss_store_sk = s_store_sk - and d_month_seq between 1214 and 1214 + 11 - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy,s_store_id) - , - results_rollup as - (select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, s_store_id, sumsales - from results - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy - union all - select i_category, i_class, i_brand, i_product_name, d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year - union all - select i_category, i_class, i_brand, i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name - union all - select i_category, i_class, i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand - union all - select i_category, i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class - union all - select i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category - union all - select null i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results) - - select * -from (select i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rank() over (partition by i_category order by sumsales desc) rk - from results_rollup) dw2 -where rk <= 100 -order by i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rk -limit 100; - --- end template query67a.tpl query 54 in stream 6 --- start template query77a.tpl query 55 in stream 6 -with /* TPC-DS query77a.tpl 0.78 */ ss as - (select s_store_sk, - sum(ss_ext_sales_price) as sales, - sum(ss_net_profit) as profit - from store_sales, - date_dim, - store - where ss_sold_date_sk = d_date_sk - and d_date between cast('1999-08-24' as date) - and dateadd(day,30,cast('1999-08-24' as date)) - and ss_store_sk = s_store_sk - group by s_store_sk) - , - sr as - (select s_store_sk, - sum(sr_return_amt) as returns, - sum(sr_net_loss) as profit_loss - from store_returns, - date_dim, - store - where sr_returned_date_sk = d_date_sk - and d_date between cast('1999-08-24' as date) - and dateadd(day,30,cast('1999-08-24' as date)) - and sr_store_sk = s_store_sk - group by s_store_sk), - cs as - (select cs_call_center_sk, - sum(cs_ext_sales_price) as sales, - sum(cs_net_profit) as profit - from catalog_sales, - date_dim - where cs_sold_date_sk = d_date_sk - and d_date between cast('1999-08-24' as date) - and dateadd(day,30,cast('1999-08-24' as date)) - group by cs_call_center_sk - ), - cr as - (select cr_call_center_sk, - sum(cr_return_amount) as returns, - sum(cr_net_loss) as profit_loss - from catalog_returns, - date_dim - where cr_returned_date_sk = d_date_sk - and d_date between cast('1999-08-24' as date) - and dateadd(day,30,cast('1999-08-24' as date)) - group by cr_call_center_sk), - ws as - ( select wp_web_page_sk, - sum(ws_ext_sales_price) as sales, - sum(ws_net_profit) as profit - from web_sales, - date_dim, - web_page - where ws_sold_date_sk = d_date_sk - and d_date between cast('1999-08-24' as date) - and dateadd(day,30,cast('1999-08-24' as date)) - and ws_web_page_sk = wp_web_page_sk - group by wp_web_page_sk), - wr as - (select wp_web_page_sk, - sum(wr_return_amt) as returns, - sum(wr_net_loss) as profit_loss - from web_returns, - date_dim, - web_page - where wr_returned_date_sk = d_date_sk - and d_date between cast('1999-08-24' as date) - and dateadd(day,30,cast('1999-08-24' as date)) - and wr_web_page_sk = wp_web_page_sk - group by wp_web_page_sk) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , ss.s_store_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ss left join sr - on ss.s_store_sk = sr.s_store_sk - union all - select 'catalog channel' as channel - , cs_call_center_sk as id - , sales - , returns - , (profit - profit_loss) as profit - from cs - , cr - union all - select 'web channel' as channel - , ws.wp_web_page_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ws left join wr - on ws.wp_web_page_sk = wr.wp_web_page_sk - ) x - group by channel, id ) - - select * - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results -) foo -order by channel, id - limit 100; - --- end template query77a.tpl query 55 in stream 6 --- start template query15.tpl query 56 in stream 6 -select /* TPC-DS query15.tpl 0.57 */ ca_zip - ,sum(cs_sales_price) - from catalog_sales - ,customer - ,customer_address - ,date_dim - where cs_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', - '85392', '85460', '80348', '81792') - or ca_state in ('CA','WA','GA') - or cs_sales_price > 500) - and cs_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 1999 - group by ca_zip - order by ca_zip - limit 100; - --- end template query15.tpl query 56 in stream 6 --- start template query51.tpl query 57 in stream 6 -WITH /* TPC-DS query51.tpl 0.46 */ web_v1 as ( -select - ws_item_sk item_sk, d_date, - sum(sum(ws_sales_price)) - over (partition by ws_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from web_sales - ,date_dim -where ws_sold_date_sk=d_date_sk - and d_month_seq between 1205 and 1205+11 - and ws_item_sk is not NULL -group by ws_item_sk, d_date), -store_v1 as ( -select - ss_item_sk item_sk, d_date, - sum(sum(ss_sales_price)) - over (partition by ss_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from store_sales - ,date_dim -where ss_sold_date_sk=d_date_sk - and d_month_seq between 1205 and 1205+11 - and ss_item_sk is not NULL -group by ss_item_sk, d_date) - select * -from (select item_sk - ,d_date - ,web_sales - ,store_sales - ,max(web_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) web_cumulative - ,max(store_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) store_cumulative - from (select case when web.item_sk is not null then web.item_sk else store.item_sk end item_sk - ,case when web.d_date is not null then web.d_date else store.d_date end d_date - ,web.cume_sales web_sales - ,store.cume_sales store_sales - from web_v1 web full outer join store_v1 store on (web.item_sk = store.item_sk - and web.d_date = store.d_date) - )x )y -where web_cumulative > store_cumulative -order by item_sk - ,d_date -limit 100; - --- end template query51.tpl query 57 in stream 6 --- start template query98.tpl query 58 in stream 6 -select /* TPC-DS query98.tpl 0.32 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ss_ext_sales_price) as itemrevenue - ,sum(ss_ext_sales_price)*100/sum(sum(ss_ext_sales_price)) over - (partition by i_class) as revenueratio -from - store_sales - ,item - ,date_dim -where - ss_item_sk = i_item_sk - and i_category in ('Sports', 'Books', 'Electronics') - and ss_sold_date_sk = d_date_sk - and d_date between cast('2002-01-15' as date) - and dateadd(day,30,cast('2002-01-15' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio; - --- end template query98.tpl query 58 in stream 6 --- start template query62.tpl query 59 in stream 6 -select /* TPC-DS query62.tpl 0.24 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 30) and - (ws_ship_date_sk - ws_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 60) and - (ws_ship_date_sk - ws_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 90) and - (ws_ship_date_sk - ws_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - web_sales - ,warehouse - ,ship_mode - ,web_site - ,date_dim -where - d_month_seq between 1209 and 1209 + 11 -and ws_ship_date_sk = d_date_sk -and ws_warehouse_sk = w_warehouse_sk -and ws_ship_mode_sk = sm_ship_mode_sk -and ws_web_site_sk = web_site_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -limit 100; - --- end template query62.tpl query 59 in stream 6 --- start template query97.tpl query 60 in stream 6 -with /* TPC-DS query97.tpl 0.38 */ ssci as ( -select ss_customer_sk customer_sk - ,ss_item_sk item_sk -from store_sales,date_dim -where ss_sold_date_sk = d_date_sk - and d_month_seq between 1177 and 1177 + 11 -group by ss_customer_sk - ,ss_item_sk), -csci as( - select cs_bill_customer_sk customer_sk - ,cs_item_sk item_sk -from catalog_sales,date_dim -where cs_sold_date_sk = d_date_sk - and d_month_seq between 1177 and 1177 + 11 -group by cs_bill_customer_sk - ,cs_item_sk) - select sum(case when ssci.customer_sk is not null and csci.customer_sk is null then 1 else 0 end) store_only - ,sum(case when ssci.customer_sk is null and csci.customer_sk is not null then 1 else 0 end) catalog_only - ,sum(case when ssci.customer_sk is not null and csci.customer_sk is not null then 1 else 0 end) store_and_catalog -from ssci full outer join csci on (ssci.customer_sk=csci.customer_sk - and ssci.item_sk = csci.item_sk) -limit 100; - --- end template query97.tpl query 60 in stream 6 --- start template query22a.tpl query 61 in stream 6 -with /* TPC-DS query22a.tpl 0.55 */ results as -(select i_product_name - ,i_brand - ,i_class - ,i_category - ,avg(inv_quantity_on_hand) qoh - from inventory - ,date_dim - ,item --- ,warehouse - where inv_date_sk=d_date_sk - and inv_item_sk=i_item_sk --- and inv_warehouse_sk = w_warehouse_sk - and d_month_seq between 1200 and 1200 + 11 - group by i_product_name,i_brand,i_class,i_category), -results_rollup as -(select i_product_name, i_brand, i_class, i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class,i_category -union all -select i_product_name, i_brand, i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class -union all -select i_product_name, i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand -union all -select i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name -union all -select null i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results) - select i_product_name, i_brand, i_class, i_category,qoh - from results_rollup - order by qoh, i_product_name, i_brand, i_class, i_category -limit 100; - --- end template query22a.tpl query 61 in stream 6 --- start template query48.tpl query 62 in stream 6 -select /* TPC-DS query48.tpl 0.74 */ sum (ss_quantity) - from store_sales, store, customer_demographics, customer_address, date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2000 - and - ( - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'S' - and - cd_education_status = 'Primary' - and - ss_sales_price between 100.00 and 150.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'U' - and - cd_education_status = '4 yr Degree' - and - ss_sales_price between 50.00 and 100.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'D' - and - cd_education_status = '2 yr Degree' - and - ss_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('TN', 'TX', 'GA') - and ss_net_profit between 0 and 2000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('IN', 'MD', 'CO') - and ss_net_profit between 150 and 3000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('NH', 'AZ', 'NC') - and ss_net_profit between 50 and 25000 - ) - ) -; - --- end template query48.tpl query 62 in stream 6 --- start template query2.tpl query 63 in stream 6 -with /* TPC-DS query2.tpl 0.84 */ wscs as - (select sold_date_sk - ,sales_price - from (select ws_sold_date_sk sold_date_sk - ,ws_ext_sales_price sales_price - from web_sales - union all - select cs_sold_date_sk sold_date_sk - ,cs_ext_sales_price sales_price - from catalog_sales)), - wswscs as - (select d_week_seq, - sum(case when (d_day_name='Sunday') then sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then sales_price else null end) sat_sales - from wscs - ,date_dim - where d_date_sk = sold_date_sk - group by d_week_seq) - select d_week_seq1 - ,round(sun_sales1/sun_sales2,2) - ,round(mon_sales1/mon_sales2,2) - ,round(tue_sales1/tue_sales2,2) - ,round(wed_sales1/wed_sales2,2) - ,round(thu_sales1/thu_sales2,2) - ,round(fri_sales1/fri_sales2,2) - ,round(sat_sales1/sat_sales2,2) - from - (select wswscs.d_week_seq d_week_seq1 - ,sun_sales sun_sales1 - ,mon_sales mon_sales1 - ,tue_sales tue_sales1 - ,wed_sales wed_sales1 - ,thu_sales thu_sales1 - ,fri_sales fri_sales1 - ,sat_sales sat_sales1 - from wswscs,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 2001) y, - (select wswscs.d_week_seq d_week_seq2 - ,sun_sales sun_sales2 - ,mon_sales mon_sales2 - ,tue_sales tue_sales2 - ,wed_sales wed_sales2 - ,thu_sales thu_sales2 - ,fri_sales fri_sales2 - ,sat_sales sat_sales2 - from wswscs - ,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 2001+1) z - where d_week_seq1=d_week_seq2-53 - order by d_week_seq1; - --- end template query2.tpl query 63 in stream 6 --- start template query79.tpl query 64 in stream 6 -select /* TPC-DS query79.tpl 0.89 */ - c_last_name,c_first_name,substring(s_city,1,30),ss_ticket_number,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,store.s_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (household_demographics.hd_dep_count = 3 or household_demographics.hd_vehicle_count > 1) - and date_dim.d_dow = 1 - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_number_employees between 200 and 295 - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,store.s_city) ms,customer - where ss_customer_sk = c_customer_sk - order by c_last_name,c_first_name,substring(s_city,1,30), profit -limit 100; - --- end template query79.tpl query 64 in stream 6 --- start template query56.tpl query 65 in stream 6 -with /* TPC-DS query56.tpl 0.83 */ ss as ( - select i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where i_item_id in (select - i_item_id -from item -where i_color in ('powder','smoke','grey')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 4 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id), - cs as ( - select i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('powder','smoke','grey')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 4 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id), - ws as ( - select i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('powder','smoke','grey')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 4 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id) - select i_item_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by total_sales, - i_item_id - limit 100; - --- end template query56.tpl query 65 in stream 6 --- start template query37.tpl query 66 in stream 6 -select /* TPC-DS query37.tpl 0.31 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, catalog_sales - where i_current_price between 38 and 38 + 30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('2001-04-24' as date) and dateadd(day,60,cast('2001-04-24' as date)) - and i_manufact_id in (956,941,793,901) - and inv_quantity_on_hand between 100 and 500 - and cs_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query37.tpl query 66 in stream 6 --- start template query10.tpl query 67 in stream 6 -select /* TPC-DS query10.tpl 0.26 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3, - cd_dep_count, - count(*) cnt4, - cd_dep_employed_count, - count(*) cnt5, - cd_dep_college_count, - count(*) cnt6 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_county in ('Pulaski County','Dickey County','Benton County','Worcester County','Monroe County') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 3 and 3+3) and - (exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 3 ANd 3+3) or - exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 3 and 3+3)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count -limit 100; - --- end template query10.tpl query 67 in stream 6 --- start template query90.tpl query 68 in stream 6 -select /* TPC-DS query90.tpl 0.40 */ cast(amc as decimal(15,4))/cast(pmc as decimal(15,4)) am_pm_ratio - from ( select count(*) amc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 7 and 7+1 - and household_demographics.hd_dep_count = 5 - and web_page.wp_char_count between 5000 and 5200) at, - ( select count(*) pmc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 20 and 20+1 - and household_demographics.hd_dep_count = 5 - and web_page.wp_char_count between 5000 and 5200) pt - order by am_pm_ratio - limit 100; - --- end template query90.tpl query 68 in stream 6 --- start template query21.tpl query 69 in stream 6 -select /* TPC-DS query21.tpl 0.14 */ * - from(select w_warehouse_name - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('1999-06-20' as date)) - then inv_quantity_on_hand - else 0 end) as inv_before - ,sum(case when (cast(d_date as date) >= cast ('1999-06-20' as date)) - then inv_quantity_on_hand - else 0 end) as inv_after - from inventory - ,warehouse - ,item - ,date_dim - where i_current_price between 0.99 and 1.49 - and i_item_sk = inv_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('1999-06-20' as date)) - and dateadd(day,30,cast ('1999-06-20' as date)) - group by w_warehouse_name, i_item_id) x - where (case when inv_before > 0 - then inv_after / inv_before - else null - end) between 2.0/3.0 and 3.0/2.0 - order by w_warehouse_name - ,i_item_id - limit 100; - --- end template query21.tpl query 69 in stream 6 --- start template query46.tpl query 70 in stream 6 -select /* TPC-DS query46.tpl 0.23 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and (household_demographics.hd_dep_count = 5 or - household_demographics.hd_vehicle_count= 4) - and date_dim.d_dow in (6,0) - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_city in ('Oakland','Union','Spring Hill','Midway','Friendship') - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,ca_city) dn,customer,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - limit 100; - --- end template query46.tpl query 70 in stream 6 --- start template query83.tpl query 71 in stream 6 -with /* TPC-DS query83.tpl 0.96 */ sr_items as - (select i_item_id item_id, - sum(sr_return_quantity) sr_item_qty - from store_returns, - item, - date_dim - where sr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2001-04-29','2001-08-03','2001-11-11'))) - and sr_returned_date_sk = d_date_sk - group by i_item_id), - cr_items as - (select i_item_id item_id, - sum(cr_return_quantity) cr_item_qty - from catalog_returns, - item, - date_dim - where cr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2001-04-29','2001-08-03','2001-11-11'))) - and cr_returned_date_sk = d_date_sk - group by i_item_id), - wr_items as - (select i_item_id item_id, - sum(wr_return_quantity) wr_item_qty - from web_returns, - item, - date_dim - where wr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2001-04-29','2001-08-03','2001-11-11'))) - and wr_returned_date_sk = d_date_sk - group by i_item_id) - select sr_items.item_id - ,sr_item_qty - ,sr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 sr_dev - ,cr_item_qty - ,cr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 cr_dev - ,wr_item_qty - ,wr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 wr_dev - ,(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 average - from sr_items - ,cr_items - ,wr_items - where sr_items.item_id=cr_items.item_id - and sr_items.item_id=wr_items.item_id - order by sr_items.item_id - ,sr_item_qty - limit 100; - --- end template query83.tpl query 71 in stream 6 --- start template query96.tpl query 72 in stream 6 -select /* TPC-DS query96.tpl 0.1 */ count(*) -from store_sales - ,household_demographics - ,time_dim, store -where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 20 - and time_dim.t_minute >= 30 - and household_demographics.hd_dep_count = 0 - and store.s_store_name = 'ese' -order by count(*) -limit 100; - --- end template query96.tpl query 72 in stream 6 --- start template query68.tpl query 73 in stream 6 -select /* TPC-DS query68.tpl 0.95 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,extended_price - ,extended_tax - ,list_price - from (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_ext_sales_price) extended_price - ,sum(ss_ext_list_price) list_price - ,sum(ss_ext_tax) extended_tax - from store_sales - ,date_dim - ,store - ,household_demographics - ,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_dep_count = 2 or - household_demographics.hd_vehicle_count= 2) - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_city in ('Salem','Woodland') - group by ss_ticket_number - ,ss_customer_sk - ,ss_addr_sk,ca_city) dn - ,customer - ,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,ss_ticket_number - limit 100; - --- end template query68.tpl query 73 in stream 6 --- start template query63.tpl query 74 in stream 6 -select /* TPC-DS query63.tpl 0.27 */ * -from (select i_manager_id - ,sum(ss_sales_price) sum_sales - ,avg(sum(ss_sales_price)) over (partition by i_manager_id) avg_monthly_sales - from item - ,store_sales - ,date_dim - ,store - where ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and d_month_seq in (1178,1178+1,1178+2,1178+3,1178+4,1178+5,1178+6,1178+7,1178+8,1178+9,1178+10,1178+11) - and (( i_category in ('Books','Children','Electronics') - and i_class in ('personal','portable','reference','self-help') - and i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) - or( i_category in ('Women','Music','Men') - and i_class in ('accessories','classical','fragrances','pants') - and i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manager_id, d_moy) tmp1 -where case when avg_monthly_sales > 0 then abs (sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 -order by i_manager_id - ,avg_monthly_sales - ,sum_sales -limit 100; - --- end template query63.tpl query 74 in stream 6 --- start template query92.tpl query 75 in stream 6 -select /* TPC-DS query92.tpl 0.44 */ - sum(ws_ext_discount_amt) as "Excess Discount Amount" -from - web_sales - ,item - ,date_dim -where -i_manufact_id = 322 -and i_item_sk = ws_item_sk -and d_date between '2000-02-06' and - dateadd(day,90,cast('2000-02-06' as date)) -and d_date_sk = ws_sold_date_sk -and ws_ext_discount_amt - > ( - SELECT - 1.3 * avg(ws_ext_discount_amt) - FROM - web_sales - ,date_dim - WHERE - ws_item_sk = i_item_sk - and d_date between '2000-02-06' and - dateadd(day,90,cast('2000-02-06' as date)) - and d_date_sk = ws_sold_date_sk - ) -order by sum(ws_ext_discount_amt) -limit 100; - --- end template query92.tpl query 75 in stream 6 --- start template query27a.tpl query 76 in stream 6 -with /* TPC-DS query27a.tpl 0.16 */ results as - (select i_item_id, - s_state, 0 as g_state, - ss_quantity agg1, - ss_list_price agg2, - ss_coupon_amt agg3, - ss_sales_price agg4 - from store_sales, customer_demographics, date_dim, store, item - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_store_sk = s_store_sk and - ss_cdemo_sk = cd_demo_sk and - cd_gender = 'F' and - cd_marital_status = 'M' and - cd_education_status = 'Primary' and - d_year = 2001 and - s_state in ('NC','GA', 'MI', 'MI', 'NM', 'NE') - ) - - select i_item_id, - s_state, g_state, agg1, agg2, agg3, agg4 - from ( - select i_item_id, s_state, 0 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4 from results - group by i_item_id, s_state - union all - select i_item_id, NULL AS s_state, 1 AS g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as s_state, 1 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - ) foo - order by i_item_id, s_state - limit 100; - --- end template query27a.tpl query 76 in stream 6 --- start template query12.tpl query 77 in stream 6 -select /* TPC-DS query12.tpl 0.64 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ws_ext_sales_price) as itemrevenue - ,sum(ws_ext_sales_price)*100/sum(sum(ws_ext_sales_price)) over - (partition by i_class) as revenueratio -from - web_sales - ,item - ,date_dim -where - ws_item_sk = i_item_sk - and i_category in ('Shoes', 'Electronics', 'Sports') - and ws_sold_date_sk = d_date_sk - and d_date between cast('2000-03-13' as date) - and dateadd(day,30,cast('2000-03-13' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query12.tpl query 77 in stream 6 --- start template query64.tpl query 78 in stream 6 -with /* TPC-DS query64.tpl 0.20 */ cs_ui as - (select cs_item_sk - ,sum(cs_ext_list_price) as sale,sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit) as refund - from catalog_sales - ,catalog_returns - where cs_item_sk = cr_item_sk - and cs_order_number = cr_order_number - group by cs_item_sk - having sum(cs_ext_list_price)>2*sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit)), -cross_sales as - (select i_product_name product_name - ,i_item_sk item_sk - ,s_store_name store_name - ,s_zip store_zip - ,ad1.ca_street_number b_street_number - ,ad1.ca_street_name b_street_name - ,ad1.ca_city b_city - ,ad1.ca_zip b_zip - ,ad2.ca_street_number c_street_number - ,ad2.ca_street_name c_street_name - ,ad2.ca_city c_city - ,ad2.ca_zip c_zip - ,d1.d_year as syear - ,d2.d_year as fsyear - ,d3.d_year s2year - ,count(*) cnt - ,sum(ss_wholesale_cost) s1 - ,sum(ss_list_price) s2 - ,sum(ss_coupon_amt) s3 - FROM store_sales - ,store_returns - ,cs_ui - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,customer - ,customer_demographics cd1 - ,customer_demographics cd2 - ,promotion - ,household_demographics hd1 - ,household_demographics hd2 - ,customer_address ad1 - ,customer_address ad2 - ,income_band ib1 - ,income_band ib2 - ,item - WHERE ss_store_sk = s_store_sk AND - ss_sold_date_sk = d1.d_date_sk AND - ss_customer_sk = c_customer_sk AND - ss_cdemo_sk= cd1.cd_demo_sk AND - ss_hdemo_sk = hd1.hd_demo_sk AND - ss_addr_sk = ad1.ca_address_sk and - ss_item_sk = i_item_sk and - ss_item_sk = sr_item_sk and - ss_ticket_number = sr_ticket_number and - ss_item_sk = cs_ui.cs_item_sk and - c_current_cdemo_sk = cd2.cd_demo_sk AND - c_current_hdemo_sk = hd2.hd_demo_sk AND - c_current_addr_sk = ad2.ca_address_sk and - c_first_sales_date_sk = d2.d_date_sk and - c_first_shipto_date_sk = d3.d_date_sk and - ss_promo_sk = p_promo_sk and - hd1.hd_income_band_sk = ib1.ib_income_band_sk and - hd2.hd_income_band_sk = ib2.ib_income_band_sk and - cd1.cd_marital_status <> cd2.cd_marital_status and - i_color in ('beige','medium','ivory','powder','almond','papaya') and - i_current_price between 20 and 20 + 10 and - i_current_price between 20 + 1 and 20 + 15 -group by i_product_name - ,i_item_sk - ,s_store_name - ,s_zip - ,ad1.ca_street_number - ,ad1.ca_street_name - ,ad1.ca_city - ,ad1.ca_zip - ,ad2.ca_street_number - ,ad2.ca_street_name - ,ad2.ca_city - ,ad2.ca_zip - ,d1.d_year - ,d2.d_year - ,d3.d_year -) -select cs1.product_name - ,cs1.store_name - ,cs1.store_zip - ,cs1.b_street_number - ,cs1.b_street_name - ,cs1.b_city - ,cs1.b_zip - ,cs1.c_street_number - ,cs1.c_street_name - ,cs1.c_city - ,cs1.c_zip - ,cs1.syear - ,cs1.cnt - ,cs1.s1 as s11 - ,cs1.s2 as s21 - ,cs1.s3 as s31 - ,cs2.s1 as s12 - ,cs2.s2 as s22 - ,cs2.s3 as s32 - ,cs2.syear - ,cs2.cnt -from cross_sales cs1,cross_sales cs2 -where cs1.item_sk=cs2.item_sk and - cs1.syear = 2001 and - cs2.syear = 2001 + 1 and - cs2.cnt <= cs1.cnt and - cs1.store_name = cs2.store_name and - cs1.store_zip = cs2.store_zip -order by cs1.product_name - ,cs1.store_name - ,cs2.cnt - ,cs1.s1 - ,cs2.s1; - --- end template query64.tpl query 78 in stream 6 --- start template query95.tpl query 79 in stream 6 -with /* TPC-DS query95.tpl 0.43 */ ws_wh as -(select ws1.ws_order_number,ws1.ws_warehouse_sk wh1,ws2.ws_warehouse_sk wh2 - from web_sales ws1,web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) - select - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2002-3-01' and - dateadd(day,60,cast('2002-3-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'KS' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and ws1.ws_order_number in (select ws_order_number - from ws_wh) -and ws1.ws_order_number in (select wr_order_number - from web_returns,ws_wh - where wr_order_number = ws_wh.ws_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query95.tpl query 79 in stream 6 --- start template query39.tpl query 80 in stream 6 -with /* TPC-DS query39.tpl 0.5 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =2002 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=3 - and inv2.d_moy=3+1 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; -with /* TPC-DS query39.tpl 0.5 part2 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =2002 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=3 - and inv2.d_moy=3+1 - and inv1.cov > 1.5 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; - --- end template query39.tpl query 80 in stream 6 --- start template query35a.tpl query 81 in stream 6 -select /* TPC-DS query35a.tpl 0.47 */ - ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - count(*) cnt1, - stddev_samp(cd_dep_count), - stddev_samp(cd_dep_count), - max(cd_dep_count), - cd_dep_employed_count, - count(*) cnt2, - stddev_samp(cd_dep_employed_count), - stddev_samp(cd_dep_employed_count), - max(cd_dep_employed_count), - cd_dep_college_count, - count(*) cnt3, - stddev_samp(cd_dep_college_count), - stddev_samp(cd_dep_college_count), - max(cd_dep_college_count) - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2002 and - d_qoy < 4) and - exists (select * from - (select ws_bill_customer_sk customsk - from web_sales,date_dim - where - ws_sold_date_sk = d_date_sk and - d_year = 2002 and - d_qoy < 4 - union all - select cs_ship_customer_sk customsk - from catalog_sales,date_dim - where - cs_sold_date_sk = d_date_sk and - d_year = 2002 and - d_qoy < 4)x - where x.customsk = c.c_customer_sk) - group by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - limit 100; - --- end template query35a.tpl query 81 in stream 6 --- start template query78.tpl query 82 in stream 6 -with /* TPC-DS query78.tpl 0.10 */ ws as - (select d_year AS ws_sold_year, ws_item_sk, - ws_bill_customer_sk ws_customer_sk, - sum(ws_quantity) ws_qty, - sum(ws_wholesale_cost) ws_wc, - sum(ws_sales_price) ws_sp - from web_sales - left join web_returns on wr_order_number=ws_order_number and ws_item_sk=wr_item_sk - join date_dim on ws_sold_date_sk = d_date_sk - where wr_order_number is null - group by d_year, ws_item_sk, ws_bill_customer_sk - ), -cs as - (select d_year AS cs_sold_year, cs_item_sk, - cs_bill_customer_sk cs_customer_sk, - sum(cs_quantity) cs_qty, - sum(cs_wholesale_cost) cs_wc, - sum(cs_sales_price) cs_sp - from catalog_sales - left join catalog_returns on cr_order_number=cs_order_number and cs_item_sk=cr_item_sk - join date_dim on cs_sold_date_sk = d_date_sk - where cr_order_number is null - group by d_year, cs_item_sk, cs_bill_customer_sk - ), -ss as - (select d_year AS ss_sold_year, ss_item_sk, - ss_customer_sk, - sum(ss_quantity) ss_qty, - sum(ss_wholesale_cost) ss_wc, - sum(ss_sales_price) ss_sp - from store_sales - left join store_returns on sr_ticket_number=ss_ticket_number and ss_item_sk=sr_item_sk - join date_dim on ss_sold_date_sk = d_date_sk - where sr_ticket_number is null - group by d_year, ss_item_sk, ss_customer_sk - ) - select -ss_sold_year, ss_item_sk, ss_customer_sk, -round(ss_qty/(coalesce(ws_qty,0)+coalesce(cs_qty,0)),2) ratio, -ss_qty store_qty, ss_wc store_wholesale_cost, ss_sp store_sales_price, -coalesce(ws_qty,0)+coalesce(cs_qty,0) other_chan_qty, -coalesce(ws_wc,0)+coalesce(cs_wc,0) other_chan_wholesale_cost, -coalesce(ws_sp,0)+coalesce(cs_sp,0) other_chan_sales_price -from ss -left join ws on (ws_sold_year=ss_sold_year and ws_item_sk=ss_item_sk and ws_customer_sk=ss_customer_sk) -left join cs on (cs_sold_year=ss_sold_year and cs_item_sk=ss_item_sk and cs_customer_sk=ss_customer_sk) -where (coalesce(ws_qty,0)>0 or coalesce(cs_qty, 0)>0) and ss_sold_year=1998 -order by - ss_sold_year, ss_item_sk, ss_customer_sk, - ss_qty desc, ss_wc desc, ss_sp desc, - other_chan_qty, - other_chan_wholesale_cost, - other_chan_sales_price, - ratio -limit 100; - --- end template query78.tpl query 82 in stream 6 --- start template query57.tpl query 83 in stream 6 -with /* TPC-DS query57.tpl 0.70 */ v1 as( - select i_category, i_brand, - cc_name, - d_year, d_moy, - sum(cs_sales_price) sum_sales, - avg(sum(cs_sales_price)) over - (partition by i_category, i_brand, - cc_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - cc_name - order by d_year, d_moy) rn - from item, catalog_sales, date_dim, call_center - where cs_item_sk = i_item_sk and - cs_sold_date_sk = d_date_sk and - cc_call_center_sk= cs_call_center_sk and - ( - d_year = 1999 or - ( d_year = 1999-1 and d_moy =12) or - ( d_year = 1999+1 and d_moy =1) - ) - group by i_category, i_brand, - cc_name , d_year, d_moy), - v2 as( - select v1.i_category - ,v1.d_year, v1.d_moy - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1. cc_name = v1_lag. cc_name and - v1. cc_name = v1_lead. cc_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 1999 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, psum - limit 100; - --- end template query57.tpl query 83 in stream 6 --- start template query66.tpl query 84 in stream 6 -select /* TPC-DS query66.tpl 0.39 */ - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - ,sum(jan_sales) as jan_sales - ,sum(feb_sales) as feb_sales - ,sum(mar_sales) as mar_sales - ,sum(apr_sales) as apr_sales - ,sum(may_sales) as may_sales - ,sum(jun_sales) as jun_sales - ,sum(jul_sales) as jul_sales - ,sum(aug_sales) as aug_sales - ,sum(sep_sales) as sep_sales - ,sum(oct_sales) as oct_sales - ,sum(nov_sales) as nov_sales - ,sum(dec_sales) as dec_sales - ,sum(jan_sales/w_warehouse_sq_ft) as jan_sales_per_sq_foot - ,sum(feb_sales/w_warehouse_sq_ft) as feb_sales_per_sq_foot - ,sum(mar_sales/w_warehouse_sq_ft) as mar_sales_per_sq_foot - ,sum(apr_sales/w_warehouse_sq_ft) as apr_sales_per_sq_foot - ,sum(may_sales/w_warehouse_sq_ft) as may_sales_per_sq_foot - ,sum(jun_sales/w_warehouse_sq_ft) as jun_sales_per_sq_foot - ,sum(jul_sales/w_warehouse_sq_ft) as jul_sales_per_sq_foot - ,sum(aug_sales/w_warehouse_sq_ft) as aug_sales_per_sq_foot - ,sum(sep_sales/w_warehouse_sq_ft) as sep_sales_per_sq_foot - ,sum(oct_sales/w_warehouse_sq_ft) as oct_sales_per_sq_foot - ,sum(nov_sales/w_warehouse_sq_ft) as nov_sales_per_sq_foot - ,sum(dec_sales/w_warehouse_sq_ft) as dec_sales_per_sq_foot - ,sum(jan_net) as jan_net - ,sum(feb_net) as feb_net - ,sum(mar_net) as mar_net - ,sum(apr_net) as apr_net - ,sum(may_net) as may_net - ,sum(jun_net) as jun_net - ,sum(jul_net) as jul_net - ,sum(aug_net) as aug_net - ,sum(sep_net) as sep_net - ,sum(oct_net) as oct_net - ,sum(nov_net) as nov_net - ,sum(dec_net) as dec_net - from ( - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'AIRBORNE' || ',' || 'ALLIANCE' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then ws_ext_sales_price* ws_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then ws_ext_sales_price* ws_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then ws_ext_sales_price* ws_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then ws_ext_sales_price* ws_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then ws_ext_sales_price* ws_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then ws_ext_sales_price* ws_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then ws_ext_sales_price* ws_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then ws_ext_sales_price* ws_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then ws_ext_sales_price* ws_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then ws_ext_sales_price* ws_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then ws_ext_sales_price* ws_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then ws_ext_sales_price* ws_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as dec_net - from - web_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - ws_warehouse_sk = w_warehouse_sk - and ws_sold_date_sk = d_date_sk - and ws_sold_time_sk = t_time_sk - and ws_ship_mode_sk = sm_ship_mode_sk - and d_year = 2000 - and t_time between 26880 and 26880+28800 - and sm_carrier in ('AIRBORNE','ALLIANCE') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - union all - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'AIRBORNE' || ',' || 'ALLIANCE' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then cs_ext_list_price* cs_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then cs_ext_list_price* cs_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then cs_ext_list_price* cs_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then cs_ext_list_price* cs_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then cs_ext_list_price* cs_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then cs_ext_list_price* cs_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then cs_ext_list_price* cs_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then cs_ext_list_price* cs_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then cs_ext_list_price* cs_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then cs_ext_list_price* cs_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then cs_ext_list_price* cs_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then cs_ext_list_price* cs_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then cs_net_profit * cs_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then cs_net_profit * cs_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then cs_net_profit * cs_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then cs_net_profit * cs_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then cs_net_profit * cs_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then cs_net_profit * cs_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then cs_net_profit * cs_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then cs_net_profit * cs_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then cs_net_profit * cs_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then cs_net_profit * cs_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then cs_net_profit * cs_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then cs_net_profit * cs_quantity else 0 end) as dec_net - from - catalog_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and cs_sold_time_sk = t_time_sk - and cs_ship_mode_sk = sm_ship_mode_sk - and d_year = 2000 - and t_time between 26880 AND 26880+28800 - and sm_carrier in ('AIRBORNE','ALLIANCE') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - ) x - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - order by w_warehouse_name - limit 100; - --- end template query66.tpl query 84 in stream 6 --- start template query71.tpl query 85 in stream 6 -select /* TPC-DS query71.tpl 0.72 */ i_brand_id brand_id, i_brand brand,t_hour,t_minute, - sum(ext_price) ext_price - from item, (select ws_ext_sales_price as ext_price, - ws_sold_date_sk as sold_date_sk, - ws_item_sk as sold_item_sk, - ws_sold_time_sk as time_sk - from web_sales,date_dim - where d_date_sk = ws_sold_date_sk - and d_moy=11 - and d_year=2002 - union all - select cs_ext_sales_price as ext_price, - cs_sold_date_sk as sold_date_sk, - cs_item_sk as sold_item_sk, - cs_sold_time_sk as time_sk - from catalog_sales,date_dim - where d_date_sk = cs_sold_date_sk - and d_moy=11 - and d_year=2002 - union all - select ss_ext_sales_price as ext_price, - ss_sold_date_sk as sold_date_sk, - ss_item_sk as sold_item_sk, - ss_sold_time_sk as time_sk - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - and d_moy=11 - and d_year=2002 - ) tmp,time_dim - where - sold_item_sk = i_item_sk - and i_manager_id=1 - and time_sk = t_time_sk - and (t_meal_time = 'breakfast' or t_meal_time = 'dinner') - group by i_brand, i_brand_id,t_hour,t_minute - order by ext_price desc, i_brand_id - ; - --- end template query71.tpl query 85 in stream 6 --- start template query30.tpl query 86 in stream 6 -with /* TPC-DS query30.tpl 0.75 */ customer_total_return as - (select wr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(wr_return_amt) as ctr_total_return - from web_returns - ,date_dim - ,customer_address - where wr_returned_date_sk = d_date_sk - and d_year =1999 - and wr_returning_addr_sk = ca_address_sk - group by wr_returning_customer_sk - ,ca_state) - select c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'SD' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return -limit 100; - --- end template query30.tpl query 86 in stream 6 --- start template query1.tpl query 87 in stream 6 -with /* TPC-DS query1.tpl 0.12 */ customer_total_return as -(select sr_customer_sk as ctr_customer_sk -,sr_store_sk as ctr_store_sk -,sum(SR_FEE) as ctr_total_return -from store_returns -,date_dim -where sr_returned_date_sk = d_date_sk -and d_year =2000 -group by sr_customer_sk -,sr_store_sk) - select c_customer_id -from customer_total_return ctr1 -,store -,customer -where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 -from customer_total_return ctr2 -where ctr1.ctr_store_sk = ctr2.ctr_store_sk) -and s_store_sk = ctr1.ctr_store_sk -and s_state = 'IN' -and ctr1.ctr_customer_sk = c_customer_sk -order by c_customer_id -limit 100; - --- end template query1.tpl query 87 in stream 6 --- start template query81.tpl query 88 in stream 6 -with /* TPC-DS query81.tpl 0.37 */ customer_total_return as - (select cr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(cr_return_amt_inc_tax) as ctr_total_return - from catalog_returns - ,date_dim - ,customer_address - where cr_returned_date_sk = d_date_sk - and d_year =2000 - and cr_returning_addr_sk = ca_address_sk - group by cr_returning_customer_sk - ,ca_state ) - select c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'SC' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - limit 100; - --- end template query81.tpl query 88 in stream 6 --- start template query43.tpl query 89 in stream 6 -select /* TPC-DS query43.tpl 0.15 */ s_store_name, s_store_id, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from date_dim, store_sales, store - where d_date_sk = ss_sold_date_sk and - s_store_sk = ss_store_sk and - s_gmt_offset = -7 and - d_year = 2001 - group by s_store_name, s_store_id - order by s_store_name, s_store_id,sun_sales,mon_sales,tue_sales,wed_sales,thu_sales,fri_sales,sat_sales - limit 100; - --- end template query43.tpl query 89 in stream 6 --- start template query52.tpl query 90 in stream 6 -select /* TPC-DS query52.tpl 0.59 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_sales_price) ext_price - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=12 - and dt.d_year=1998 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,ext_price desc - ,brand_id -limit 100 ; - --- end template query52.tpl query 90 in stream 6 --- start template query13.tpl query 91 in stream 6 -select /* TPC-DS query13.tpl 0.91 */ avg(ss_quantity) - ,avg(ss_ext_sales_price) - ,avg(ss_ext_wholesale_cost) - ,sum(ss_ext_wholesale_cost) - from store_sales - ,store - ,customer_demographics - ,household_demographics - ,customer_address - ,date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2001 - and((ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'W' - and cd_education_status = 'Advanced Degree' - and ss_sales_price between 100.00 and 150.00 - and hd_dep_count = 3 - )or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'S' - and cd_education_status = '4 yr Degree' - and ss_sales_price between 50.00 and 100.00 - and hd_dep_count = 1 - ) or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'M' - and cd_education_status = 'Unknown' - and ss_sales_price between 150.00 and 200.00 - and hd_dep_count = 1 - )) - and((ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('MO', 'TX', 'GA') - and ss_net_profit between 100 and 200 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('MI', 'NY', 'SD') - and ss_net_profit between 150 and 300 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('WV', 'FL', 'VA') - and ss_net_profit between 50 and 250 - )) -; - --- end template query13.tpl query 91 in stream 6 --- start template query76.tpl query 92 in stream 6 -select /* TPC-DS query76.tpl 0.99 */ channel, col_name, d_year, d_qoy, i_category, COUNT(*) sales_cnt, SUM(ext_sales_price) sales_amt FROM ( - SELECT 'store' as channel, 'ss_addr_sk' col_name, d_year, d_qoy, i_category, ss_ext_sales_price ext_sales_price - FROM store_sales, item, date_dim - WHERE ss_addr_sk IS NULL - AND ss_sold_date_sk=d_date_sk - AND ss_item_sk=i_item_sk - UNION ALL - SELECT 'web' as channel, 'ws_ship_addr_sk' col_name, d_year, d_qoy, i_category, ws_ext_sales_price ext_sales_price - FROM web_sales, item, date_dim - WHERE ws_ship_addr_sk IS NULL - AND ws_sold_date_sk=d_date_sk - AND ws_item_sk=i_item_sk - UNION ALL - SELECT 'catalog' as channel, 'cs_ship_customer_sk' col_name, d_year, d_qoy, i_category, cs_ext_sales_price ext_sales_price - FROM catalog_sales, item, date_dim - WHERE cs_ship_customer_sk IS NULL - AND cs_sold_date_sk=d_date_sk - AND cs_item_sk=i_item_sk) foo -GROUP BY channel, col_name, d_year, d_qoy, i_category -ORDER BY channel, col_name, d_year, d_qoy, i_category -limit 100; - --- end template query76.tpl query 92 in stream 6 --- start template query17.tpl query 93 in stream 6 -select /* TPC-DS query17.tpl 0.41 */ i_item_id - ,i_item_desc - ,s_state - ,count(ss_quantity) as store_sales_quantitycount - ,avg(ss_quantity) as store_sales_quantityave - ,stddev_samp(ss_quantity) as store_sales_quantitystdev - ,stddev_samp(ss_quantity)/avg(ss_quantity) as store_sales_quantitycov - ,count(sr_return_quantity) as store_returns_quantitycount - ,avg(sr_return_quantity) as store_returns_quantityave - ,stddev_samp(sr_return_quantity) as store_returns_quantitystdev - ,stddev_samp(sr_return_quantity)/avg(sr_return_quantity) as store_returns_quantitycov - ,count(cs_quantity) as catalog_sales_quantitycount ,avg(cs_quantity) as catalog_sales_quantityave - ,stddev_samp(cs_quantity) as catalog_sales_quantitystdev - ,stddev_samp(cs_quantity)/avg(cs_quantity) as catalog_sales_quantitycov - from store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where d1.d_quarter_name = '2001Q1' - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_quarter_name in ('2001Q1','2001Q2','2001Q3') - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_quarter_name in ('2001Q1','2001Q2','2001Q3') - group by i_item_id - ,i_item_desc - ,s_state - order by i_item_id - ,i_item_desc - ,s_state -limit 100; - --- end template query17.tpl query 93 in stream 6 --- start template query25.tpl query 94 in stream 6 -select /* TPC-DS query25.tpl 0.9 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,sum(ss_net_profit) as store_sales_profit - ,sum(sr_net_loss) as store_returns_loss - ,sum(cs_net_profit) as catalog_sales_profit - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 2000 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 10 - and d2.d_year = 2000 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_moy between 4 and 10 - and d3.d_year = 2000 - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query25.tpl query 94 in stream 6 --- start template query40.tpl query 95 in stream 6 -select /* TPC-DS query40.tpl 0.86 */ - w_state - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('2000-05-18' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_before - ,sum(case when (cast(d_date as date) >= cast ('2000-05-18' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_after - from - catalog_sales left outer join catalog_returns on - (cs_order_number = cr_order_number - and cs_item_sk = cr_item_sk) - ,warehouse - ,item - ,date_dim - where - i_current_price between 0.99 and 1.49 - and i_item_sk = cs_item_sk - and cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('2000-05-18' as date)) - and dateadd(day,30,cast ('2000-05-18' as date)) - group by - w_state,i_item_id - order by w_state,i_item_id -limit 100; - --- end template query40.tpl query 95 in stream 6 --- start template query70a.tpl query 96 in stream 6 -with /* TPC-DS query70a.tpl 0.34 */ results as -( select - sum(ss_net_profit) as total_sum ,s_state ,s_county, 0 as gstate, 0 as g_county - from - store_sales - ,date_dim d1 - ,store - where - d1.d_month_seq between 1218 and 1218 + 11 - and d1.d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - and s_state in - ( select s_state - from (select s_state as s_state, - rank() over ( partition by s_state order by sum(ss_net_profit) desc) as ranking - from store_sales, store, date_dim - where d_month_seq between 1218 and 1218 + 11 - and d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - group by s_state - ) tmp1 - where ranking <= 5) - group by s_state,s_county) , - results_rollup as -(select total_sum ,s_state ,s_county, 0 as g_state, 0 as g_county, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum,s_state, NULL as s_county, 0 as g_state, 1 as g_county, 1 as lochierarchy from results group by s_state - union - select sum(total_sum) as total_sum ,NULL as s_state ,NULL as s_county, 1 as g_state, 1 as g_county, 2 as lochierarchy from results) - select total_sum ,s_state ,s_county, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_county = 0 then s_state end - order by total_sum desc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then s_state end - ,rank_within_parent - limit 100; - --- end template query70a.tpl query 96 in stream 6 --- start template query55.tpl query 97 in stream 6 -select /* TPC-DS query55.tpl 0.82 */ i_brand_id brand_id, i_brand brand, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=51 - and d_moy=11 - and d_year=2000 - group by i_brand, i_brand_id - order by ext_price desc, i_brand_id -limit 100 ; - --- end template query55.tpl query 97 in stream 6 --- start template query60.tpl query 98 in stream 6 -with /* TPC-DS query60.tpl 0.29 */ ss as ( - select - i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Children')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 10 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - cs as ( - select - i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Children')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 10 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - ws as ( - select - i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Children')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 10 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id) - select - i_item_id -,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by i_item_id - ,total_sales - limit 100; - --- end template query60.tpl query 98 in stream 6 --- start template query16.tpl query 99 in stream 6 -select /* TPC-DS query16.tpl 0.25 */ - count(distinct cs_order_number) as "order count" - ,sum(cs_ext_ship_cost) as "total shipping cost" - ,sum(cs_net_profit) as "total net profit" -from - catalog_sales cs1 - ,date_dim - ,customer_address - ,call_center -where - d_date between '2002-2-01' and - dateadd(day, 60, cast('2002-2-01' as date)) -and cs1.cs_ship_date_sk = d_date_sk -and cs1.cs_ship_addr_sk = ca_address_sk -and ca_state = 'MO' -and cs1.cs_call_center_sk = cc_call_center_sk -and cc_county in ('Walker County','Mobile County','Barrow County','Dauphin County', - 'Levy County' -) -and exists (select * - from catalog_sales cs2 - where cs1.cs_order_number = cs2.cs_order_number - and cs1.cs_warehouse_sk <> cs2.cs_warehouse_sk) -and not exists(select * - from catalog_returns cr1 - where cs1.cs_order_number = cr1.cr_order_number) -order by count(distinct cs_order_number) -limit 100; - --- end template query16.tpl query 99 in stream 6 diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/3TB/queries/query_7.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/3TB/queries/query_7.sql deleted file mode 100644 index 70bf794b..00000000 --- a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/3TB/queries/query_7.sql +++ /dev/null @@ -1,5027 +0,0 @@ --- start template query70a.tpl query 1 in stream 7 -with /* TPC-DS query70a.tpl 0.34 */ results as -( select - sum(ss_net_profit) as total_sum ,s_state ,s_county, 0 as gstate, 0 as g_county - from - store_sales - ,date_dim d1 - ,store - where - d1.d_month_seq between 1213 and 1213 + 11 - and d1.d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - and s_state in - ( select s_state - from (select s_state as s_state, - rank() over ( partition by s_state order by sum(ss_net_profit) desc) as ranking - from store_sales, store, date_dim - where d_month_seq between 1213 and 1213 + 11 - and d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - group by s_state - ) tmp1 - where ranking <= 5) - group by s_state,s_county) , - results_rollup as -(select total_sum ,s_state ,s_county, 0 as g_state, 0 as g_county, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum,s_state, NULL as s_county, 0 as g_state, 1 as g_county, 1 as lochierarchy from results group by s_state - union - select sum(total_sum) as total_sum ,NULL as s_state ,NULL as s_county, 1 as g_state, 1 as g_county, 2 as lochierarchy from results) - select total_sum ,s_state ,s_county, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_county = 0 then s_state end - order by total_sum desc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then s_state end - ,rank_within_parent - limit 100; - --- end template query70a.tpl query 1 in stream 7 --- start template query53.tpl query 2 in stream 7 -select /* TPC-DS query53.tpl 0.88 */ * from -(select i_manufact_id, -sum(ss_sales_price) sum_sales, -avg(sum(ss_sales_price)) over (partition by i_manufact_id) avg_quarterly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and -ss_sold_date_sk = d_date_sk and -ss_store_sk = s_store_sk and -d_month_seq in (1224,1224+1,1224+2,1224+3,1224+4,1224+5,1224+6,1224+7,1224+8,1224+9,1224+10,1224+11) and -((i_category in ('Books','Children','Electronics') and -i_class in ('personal','portable','reference','self-help') and -i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) -or(i_category in ('Women','Music','Men') and -i_class in ('accessories','classical','fragrances','pants') and -i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manufact_id, d_qoy ) tmp1 -where case when avg_quarterly_sales > 0 - then abs (sum_sales - avg_quarterly_sales)/ avg_quarterly_sales - else null end > 0.1 -order by avg_quarterly_sales, - sum_sales, - i_manufact_id -limit 100; - --- end template query53.tpl query 2 in stream 7 --- start template query92.tpl query 3 in stream 7 -select /* TPC-DS query92.tpl 0.44 */ - sum(ws_ext_discount_amt) as "Excess Discount Amount" -from - web_sales - ,item - ,date_dim -where -i_manufact_id = 749 -and i_item_sk = ws_item_sk -and d_date between '1999-03-07' and - dateadd(day,90,cast('1999-03-07' as date)) -and d_date_sk = ws_sold_date_sk -and ws_ext_discount_amt - > ( - SELECT - 1.3 * avg(ws_ext_discount_amt) - FROM - web_sales - ,date_dim - WHERE - ws_item_sk = i_item_sk - and d_date between '1999-03-07' and - dateadd(day,90,cast('1999-03-07' as date)) - and d_date_sk = ws_sold_date_sk - ) -order by sum(ws_ext_discount_amt) -limit 100; - --- end template query92.tpl query 3 in stream 7 --- start template query99.tpl query 4 in stream 7 -select /* TPC-DS query99.tpl 0.94 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 30) and - (cs_ship_date_sk - cs_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 60) and - (cs_ship_date_sk - cs_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 90) and - (cs_ship_date_sk - cs_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - catalog_sales - ,warehouse - ,ship_mode - ,call_center - ,date_dim -where - d_month_seq between 1217 and 1217 + 11 -and cs_ship_date_sk = d_date_sk -and cs_warehouse_sk = w_warehouse_sk -and cs_ship_mode_sk = sm_ship_mode_sk -and cs_call_center_sk = cc_call_center_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -limit 100; - --- end template query99.tpl query 4 in stream 7 --- start template query31.tpl query 5 in stream 7 -with /* TPC-DS query31.tpl 0.50 */ ss as - (select ca_county,d_qoy, d_year,sum(ss_ext_sales_price) as store_sales - from store_sales,date_dim,customer_address - where ss_sold_date_sk = d_date_sk - and ss_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year), - ws as - (select ca_county,d_qoy, d_year,sum(ws_ext_sales_price) as web_sales - from web_sales,date_dim,customer_address - where ws_sold_date_sk = d_date_sk - and ws_bill_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year) - select - ss1.ca_county - ,ss1.d_year - ,ws2.web_sales/ws1.web_sales web_q1_q2_increase - ,ss2.store_sales/ss1.store_sales store_q1_q2_increase - ,ws3.web_sales/ws2.web_sales web_q2_q3_increase - ,ss3.store_sales/ss2.store_sales store_q2_q3_increase - from - ss ss1 - ,ss ss2 - ,ss ss3 - ,ws ws1 - ,ws ws2 - ,ws ws3 - where - ss1.d_qoy = 1 - and ss1.d_year = 1998 - and ss1.ca_county = ss2.ca_county - and ss2.d_qoy = 2 - and ss2.d_year = 1998 - and ss2.ca_county = ss3.ca_county - and ss3.d_qoy = 3 - and ss3.d_year = 1998 - and ss1.ca_county = ws1.ca_county - and ws1.d_qoy = 1 - and ws1.d_year = 1998 - and ws1.ca_county = ws2.ca_county - and ws2.d_qoy = 2 - and ws2.d_year = 1998 - and ws1.ca_county = ws3.ca_county - and ws3.d_qoy = 3 - and ws3.d_year =1998 - and case when ws1.web_sales > 0 then ws2.web_sales/ws1.web_sales else null end - > case when ss1.store_sales > 0 then ss2.store_sales/ss1.store_sales else null end - and case when ws2.web_sales > 0 then ws3.web_sales/ws2.web_sales else null end - > case when ss2.store_sales > 0 then ss3.store_sales/ss2.store_sales else null end - order by store_q2_q3_increase; - --- end template query31.tpl query 5 in stream 7 --- start template query39.tpl query 6 in stream 7 -with /* TPC-DS query39.tpl 0.5 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =2002 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=3 - and inv2.d_moy=3+1 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; -with /* TPC-DS query39.tpl 0.5 part2 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =2002 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=3 - and inv2.d_moy=3+1 - and inv1.cov > 1.5 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; - --- end template query39.tpl query 6 in stream 7 --- start template query29.tpl query 7 in stream 7 -select /* TPC-DS query29.tpl 0.53 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,sum(ss_quantity) as store_sales_quantity - ,sum(sr_return_quantity) as store_returns_quantity - ,sum(cs_quantity) as catalog_sales_quantity - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 1999 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 4 + 3 - and d2.d_year = 1999 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_year in (1999,1999+1,1999+2) - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query29.tpl query 7 in stream 7 --- start template query32.tpl query 8 in stream 7 -select /* TPC-DS query32.tpl 0.7 */ sum(cs_ext_discount_amt) as "excess discount amount" -from - catalog_sales - ,item - ,date_dim -where -i_manufact_id = 64 -and i_item_sk = cs_item_sk -and d_date between '1999-03-13' and - dateadd(day,90,cast('1999-03-13' as date)) -and d_date_sk = cs_sold_date_sk -and cs_ext_discount_amt - > ( - select - 1.3 * avg(cs_ext_discount_amt) - from - catalog_sales - ,date_dim - where - cs_item_sk = i_item_sk - and d_date between '1999-03-13' and - dateadd(day,90,cast('1999-03-13' as date)) - and d_date_sk = cs_sold_date_sk - ) -limit 100; - --- end template query32.tpl query 8 in stream 7 --- start template query6.tpl query 9 in stream 7 -select /* TPC-DS query6.tpl 0.58 */ a.ca_state state, count(*) cnt - from customer_address a - ,customer c - ,store_sales s - ,date_dim d - ,item i - where a.ca_address_sk = c.c_current_addr_sk - and c.c_customer_sk = s.ss_customer_sk - and s.ss_sold_date_sk = d.d_date_sk - and s.ss_item_sk = i.i_item_sk - and d.d_month_seq = - (select distinct (d_month_seq) - from date_dim - where d_year = 2000 - and d_moy = 4 ) - and i.i_current_price > 1.2 * - (select avg(j.i_current_price) - from item j - where j.i_category = i.i_category) - group by a.ca_state - having count(*) >= 10 - order by cnt, a.ca_state - limit 100; - --- end template query6.tpl query 9 in stream 7 --- start template query64.tpl query 10 in stream 7 -with /* TPC-DS query64.tpl 0.20 */ cs_ui as - (select cs_item_sk - ,sum(cs_ext_list_price) as sale,sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit) as refund - from catalog_sales - ,catalog_returns - where cs_item_sk = cr_item_sk - and cs_order_number = cr_order_number - group by cs_item_sk - having sum(cs_ext_list_price)>2*sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit)), -cross_sales as - (select i_product_name product_name - ,i_item_sk item_sk - ,s_store_name store_name - ,s_zip store_zip - ,ad1.ca_street_number b_street_number - ,ad1.ca_street_name b_street_name - ,ad1.ca_city b_city - ,ad1.ca_zip b_zip - ,ad2.ca_street_number c_street_number - ,ad2.ca_street_name c_street_name - ,ad2.ca_city c_city - ,ad2.ca_zip c_zip - ,d1.d_year as syear - ,d2.d_year as fsyear - ,d3.d_year s2year - ,count(*) cnt - ,sum(ss_wholesale_cost) s1 - ,sum(ss_list_price) s2 - ,sum(ss_coupon_amt) s3 - FROM store_sales - ,store_returns - ,cs_ui - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,customer - ,customer_demographics cd1 - ,customer_demographics cd2 - ,promotion - ,household_demographics hd1 - ,household_demographics hd2 - ,customer_address ad1 - ,customer_address ad2 - ,income_band ib1 - ,income_band ib2 - ,item - WHERE ss_store_sk = s_store_sk AND - ss_sold_date_sk = d1.d_date_sk AND - ss_customer_sk = c_customer_sk AND - ss_cdemo_sk= cd1.cd_demo_sk AND - ss_hdemo_sk = hd1.hd_demo_sk AND - ss_addr_sk = ad1.ca_address_sk and - ss_item_sk = i_item_sk and - ss_item_sk = sr_item_sk and - ss_ticket_number = sr_ticket_number and - ss_item_sk = cs_ui.cs_item_sk and - c_current_cdemo_sk = cd2.cd_demo_sk AND - c_current_hdemo_sk = hd2.hd_demo_sk AND - c_current_addr_sk = ad2.ca_address_sk and - c_first_sales_date_sk = d2.d_date_sk and - c_first_shipto_date_sk = d3.d_date_sk and - ss_promo_sk = p_promo_sk and - hd1.hd_income_band_sk = ib1.ib_income_band_sk and - hd2.hd_income_band_sk = ib2.ib_income_band_sk and - cd1.cd_marital_status <> cd2.cd_marital_status and - i_color in ('khaki','floral','cornsilk','firebrick','orchid','chiffon') and - i_current_price between 68 and 68 + 10 and - i_current_price between 68 + 1 and 68 + 15 -group by i_product_name - ,i_item_sk - ,s_store_name - ,s_zip - ,ad1.ca_street_number - ,ad1.ca_street_name - ,ad1.ca_city - ,ad1.ca_zip - ,ad2.ca_street_number - ,ad2.ca_street_name - ,ad2.ca_city - ,ad2.ca_zip - ,d1.d_year - ,d2.d_year - ,d3.d_year -) -select cs1.product_name - ,cs1.store_name - ,cs1.store_zip - ,cs1.b_street_number - ,cs1.b_street_name - ,cs1.b_city - ,cs1.b_zip - ,cs1.c_street_number - ,cs1.c_street_name - ,cs1.c_city - ,cs1.c_zip - ,cs1.syear - ,cs1.cnt - ,cs1.s1 as s11 - ,cs1.s2 as s21 - ,cs1.s3 as s31 - ,cs2.s1 as s12 - ,cs2.s2 as s22 - ,cs2.s3 as s32 - ,cs2.syear - ,cs2.cnt -from cross_sales cs1,cross_sales cs2 -where cs1.item_sk=cs2.item_sk and - cs1.syear = 2000 and - cs2.syear = 2000 + 1 and - cs2.cnt <= cs1.cnt and - cs1.store_name = cs2.store_name and - cs1.store_zip = cs2.store_zip -order by cs1.product_name - ,cs1.store_name - ,cs2.cnt - ,cs1.s1 - ,cs2.s1; - --- end template query64.tpl query 10 in stream 7 --- start template query30.tpl query 11 in stream 7 -with /* TPC-DS query30.tpl 0.75 */ customer_total_return as - (select wr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(wr_return_amt) as ctr_total_return - from web_returns - ,date_dim - ,customer_address - where wr_returned_date_sk = d_date_sk - and d_year =1999 - and wr_returning_addr_sk = ca_address_sk - group by wr_returning_customer_sk - ,ca_state) - select c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'AR' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return -limit 100; - --- end template query30.tpl query 11 in stream 7 --- start template query34.tpl query 12 in stream 7 -select /* TPC-DS query34.tpl 0.73 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (date_dim.d_dom between 1 and 3 or date_dim.d_dom between 25 and 28) - and (household_demographics.hd_buy_potential = '1001-5000' or - household_demographics.hd_buy_potential = '0-500') - and household_demographics.hd_vehicle_count > 0 - and (case when household_demographics.hd_vehicle_count > 0 - then household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count - else null - end) > 1.2 - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_county in ('Salem County','Bronx County','Richland County','Arthur County', - 'Dauphin County','Levy County','Hubbard County','Gage County') - group by ss_ticket_number,ss_customer_sk) dn,customer - where ss_customer_sk = c_customer_sk - and cnt between 15 and 20 - order by c_last_name,c_first_name,c_salutation,c_preferred_cust_flag desc, ss_ticket_number; - --- end template query34.tpl query 12 in stream 7 --- start template query13.tpl query 13 in stream 7 -select /* TPC-DS query13.tpl 0.91 */ avg(ss_quantity) - ,avg(ss_ext_sales_price) - ,avg(ss_ext_wholesale_cost) - ,sum(ss_ext_wholesale_cost) - from store_sales - ,store - ,customer_demographics - ,household_demographics - ,customer_address - ,date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2001 - and((ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'S' - and cd_education_status = 'Unknown' - and ss_sales_price between 100.00 and 150.00 - and hd_dep_count = 3 - )or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'W' - and cd_education_status = 'College' - and ss_sales_price between 50.00 and 100.00 - and hd_dep_count = 1 - ) or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'U' - and cd_education_status = 'Advanced Degree' - and ss_sales_price between 150.00 and 200.00 - and hd_dep_count = 1 - )) - and((ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('TX', 'CO', 'GA') - and ss_net_profit between 100 and 200 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('WI', 'IA', 'WV') - and ss_net_profit between 150 and 300 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('OK', 'IL', 'CA') - and ss_net_profit between 50 and 250 - )) -; - --- end template query13.tpl query 13 in stream 7 --- start template query28.tpl query 14 in stream 7 -select /* TPC-DS query28.tpl 0.36 */ * -from (select avg(ss_list_price) B1_LP - ,count(ss_list_price) B1_CNT - ,count(distinct ss_list_price) B1_CNTD - from store_sales - where ss_quantity between 0 and 5 - and (ss_list_price between 186 and 186+10 - or ss_coupon_amt between 5420 and 5420+1000 - or ss_wholesale_cost between 71 and 71+20)) B1, - (select avg(ss_list_price) B2_LP - ,count(ss_list_price) B2_CNT - ,count(distinct ss_list_price) B2_CNTD - from store_sales - where ss_quantity between 6 and 10 - and (ss_list_price between 171 and 171+10 - or ss_coupon_amt between 4492 and 4492+1000 - or ss_wholesale_cost between 73 and 73+20)) B2, - (select avg(ss_list_price) B3_LP - ,count(ss_list_price) B3_CNT - ,count(distinct ss_list_price) B3_CNTD - from store_sales - where ss_quantity between 11 and 15 - and (ss_list_price between 34 and 34+10 - or ss_coupon_amt between 10339 and 10339+1000 - or ss_wholesale_cost between 10 and 10+20)) B3, - (select avg(ss_list_price) B4_LP - ,count(ss_list_price) B4_CNT - ,count(distinct ss_list_price) B4_CNTD - from store_sales - where ss_quantity between 16 and 20 - and (ss_list_price between 138 and 138+10 - or ss_coupon_amt between 8046 and 8046+1000 - or ss_wholesale_cost between 9 and 9+20)) B4, - (select avg(ss_list_price) B5_LP - ,count(ss_list_price) B5_CNT - ,count(distinct ss_list_price) B5_CNTD - from store_sales - where ss_quantity between 21 and 25 - and (ss_list_price between 6 and 6+10 - or ss_coupon_amt between 10036 and 10036+1000 - or ss_wholesale_cost between 33 and 33+20)) B5, - (select avg(ss_list_price) B6_LP - ,count(ss_list_price) B6_CNT - ,count(distinct ss_list_price) B6_CNTD - from store_sales - where ss_quantity between 26 and 30 - and (ss_list_price between 37 and 37+10 - or ss_coupon_amt between 12948 and 12948+1000 - or ss_wholesale_cost between 12 and 12+20)) B6 -limit 100; - --- end template query28.tpl query 14 in stream 7 --- start template query86a.tpl query 15 in stream 7 -with /* TPC-DS query86a.tpl 0.11 */ results as -( select sum(ws_net_paid) as total_sum, i_category, i_class, 0 as g_category, 0 as g_class - from - web_sales - ,date_dim d1 - ,item - where - d1.d_month_seq between 1206 and 1206+11 - and d1.d_date_sk = ws_sold_date_sk - and i_item_sk = ws_item_sk - group by i_category,i_class - ) , - - results_rollup as -( select total_sum ,i_category ,i_class, g_category, g_class, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum, i_category, NULL as i_class, 0 as g_category, 1 as g_class, 1 as lochierarchy from results group by i_category - union - select sum(total_sum) as total_sum, NULL as i_category, NULL as i_class, 1 as g_category, 1 as g_class, 2 as lochierarchy from results) - select - total_sum ,i_category ,i_class, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_class = 0 then i_category end - order by total_sum desc) as rank_within_parent - from - results_rollup - order by - lochierarchy desc, - case when lochierarchy = 0 then i_category end, - rank_within_parent - limit 100; - --- end template query86a.tpl query 15 in stream 7 --- start template query84.tpl query 16 in stream 7 -select /* TPC-DS query84.tpl 0.80 */ c_customer_id as customer_id - , coalesce(c_last_name,'') || ', ' || coalesce(c_first_name,'') as customername - from customer - ,customer_address - ,customer_demographics - ,household_demographics - ,income_band - ,store_returns - where ca_city = 'White Oak' - and c_current_addr_sk = ca_address_sk - and ib_lower_bound >= 14454 - and ib_upper_bound <= 14454 + 50000 - and ib_income_band_sk = hd_income_band_sk - and cd_demo_sk = c_current_cdemo_sk - and hd_demo_sk = c_current_hdemo_sk - and sr_cdemo_sk = cd_demo_sk - order by c_customer_id - limit 100; - --- end template query84.tpl query 16 in stream 7 --- start template query25.tpl query 17 in stream 7 -select /* TPC-DS query25.tpl 0.9 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,max(ss_net_profit) as store_sales_profit - ,max(sr_net_loss) as store_returns_loss - ,max(cs_net_profit) as catalog_sales_profit - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 1998 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 10 - and d2.d_year = 1998 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_moy between 4 and 10 - and d3.d_year = 1998 - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query25.tpl query 17 in stream 7 --- start template query4.tpl query 18 in stream 7 -with /* TPC-DS query4.tpl 0.93 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(((ss_ext_list_price-ss_ext_wholesale_cost-ss_ext_discount_amt)+ss_ext_sales_price)/2) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((cs_ext_list_price-cs_ext_wholesale_cost-cs_ext_discount_amt)+cs_ext_sales_price)/2) ) year_total - ,'c' sale_type - from customer - ,catalog_sales - ,date_dim - where c_customer_sk = cs_bill_customer_sk - and cs_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year -union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((ws_ext_list_price-ws_ext_wholesale_cost-ws_ext_discount_amt)+ws_ext_sales_price)/2) ) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_birth_country - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_c_firstyear - ,year_total t_c_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_c_secyear.customer_id - and t_s_firstyear.customer_id = t_c_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_c_firstyear.sale_type = 'c' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_c_secyear.sale_type = 'c' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 2000 - and t_s_secyear.dyear = 2000+1 - and t_c_firstyear.dyear = 2000 - and t_c_secyear.dyear = 2000+1 - and t_w_firstyear.dyear = 2000 - and t_w_secyear.dyear = 2000+1 - and t_s_firstyear.year_total > 0 - and t_c_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_birth_country -limit 100; - --- end template query4.tpl query 18 in stream 7 --- start template query98.tpl query 19 in stream 7 -select /* TPC-DS query98.tpl 0.32 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ss_ext_sales_price) as itemrevenue - ,sum(ss_ext_sales_price)*100/sum(sum(ss_ext_sales_price)) over - (partition by i_class) as revenueratio -from - store_sales - ,item - ,date_dim -where - ss_item_sk = i_item_sk - and i_category in ('Books', 'Music', 'Sports') - and ss_sold_date_sk = d_date_sk - and d_date between cast('2000-05-04' as date) - and dateadd(day,30,cast('2000-05-04' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio; - --- end template query98.tpl query 19 in stream 7 --- start template query79.tpl query 20 in stream 7 -select /* TPC-DS query79.tpl 0.89 */ - c_last_name,c_first_name,substring(s_city,1,30),ss_ticket_number,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,store.s_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (household_demographics.hd_dep_count = 4 or household_demographics.hd_vehicle_count > 2) - and date_dim.d_dow = 1 - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_number_employees between 200 and 295 - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,store.s_city) ms,customer - where ss_customer_sk = c_customer_sk - order by c_last_name,c_first_name,substring(s_city,1,30), profit -limit 100; - --- end template query79.tpl query 20 in stream 7 --- start template query69.tpl query 21 in stream 7 -select /* TPC-DS query69.tpl 0.28 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_state in ('MN','CO','TN') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 1999 and - d_moy between 2 and 2+2) and - (not exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 1999 and - d_moy between 2 and 2+2) and - not exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 1999 and - d_moy between 2 and 2+2)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - limit 100; - --- end template query69.tpl query 21 in stream 7 --- start template query72.tpl query 22 in stream 7 -select /* TPC-DS query72.tpl 0.87 */ i_item_desc - ,w_warehouse_name - ,d1.d_week_seq - ,sum(case when p_promo_sk is null then 1 else 0 end) no_promo - ,sum(case when p_promo_sk is not null then 1 else 0 end) promo - ,count(*) total_cnt -from catalog_sales -join inventory on (cs_item_sk = inv_item_sk) -join warehouse on (w_warehouse_sk=inv_warehouse_sk) -join item on (i_item_sk = cs_item_sk) -join customer_demographics on (cs_bill_cdemo_sk = cd_demo_sk) -join household_demographics on (cs_bill_hdemo_sk = hd_demo_sk) -join date_dim d1 on (cs_sold_date_sk = d1.d_date_sk) -join date_dim d2 on (inv_date_sk = d2.d_date_sk) -join date_dim d3 on (cs_ship_date_sk = d3.d_date_sk) -left outer join promotion on (cs_promo_sk=p_promo_sk) -left outer join catalog_returns on (cr_item_sk = cs_item_sk and cr_order_number = cs_order_number) -where d1.d_week_seq = d2.d_week_seq - and inv_quantity_on_hand < cs_quantity - and d3.d_date > d1.d_date + 5 - and hd_buy_potential = '>10000' - and d1.d_year = 2000 - and cd_marital_status = 'U' -group by i_item_desc,w_warehouse_name,d1.d_week_seq -order by total_cnt desc, i_item_desc, w_warehouse_name, d_week_seq -limit 100; - --- end template query72.tpl query 22 in stream 7 --- start template query45.tpl query 23 in stream 7 -select /* TPC-DS query45.tpl 0.18 */ ca_zip, ca_county, sum(ws_sales_price) - from web_sales, customer, customer_address, date_dim, item - where ws_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ws_item_sk = i_item_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', '85392', '85460', '80348', '81792') - or - i_item_id in (select i_item_id - from item - where i_item_sk in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29) - ) - ) - and ws_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 1999 - group by ca_zip, ca_county - order by ca_zip, ca_county - limit 100; - --- end template query45.tpl query 23 in stream 7 --- start template query48.tpl query 24 in stream 7 -select /* TPC-DS query48.tpl 0.74 */ sum (ss_quantity) - from store_sales, store, customer_demographics, customer_address, date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2002 - and - ( - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'D' - and - cd_education_status = '4 yr Degree' - and - ss_sales_price between 100.00 and 150.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'M' - and - cd_education_status = 'Advanced Degree' - and - ss_sales_price between 50.00 and 100.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'S' - and - cd_education_status = 'Unknown' - and - ss_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('KY', 'FL', 'SD') - and ss_net_profit between 0 and 2000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('MT', 'MI', 'NY') - and ss_net_profit between 150 and 3000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('KS', 'IL', 'WV') - and ss_net_profit between 50 and 25000 - ) - ) -; - --- end template query48.tpl query 24 in stream 7 --- start template query80a.tpl query 25 in stream 7 -with /* TPC-DS query80a.tpl 0.6 */ ssr as - (select s_store_id as store_id, - sum(ss_ext_sales_price) as sales, - sum(coalesce(sr_return_amt, 0)) as returns, - sum(ss_net_profit - coalesce(sr_net_loss, 0)) as profit - from store_sales left outer join store_returns on - (ss_item_sk = sr_item_sk and ss_ticket_number = sr_ticket_number), - date_dim, - store, - item, - promotion - where ss_sold_date_sk = d_date_sk - and d_date between cast('2002-08-08' as date) - and dateadd(day,30,cast('2002-08-08' as date)) - and ss_store_sk = s_store_sk - and ss_item_sk = i_item_sk - and i_current_price > 50 - and ss_promo_sk = p_promo_sk - and p_channel_tv = 'N' - group by s_store_id) - , - csr as - (select cp_catalog_page_id as catalog_page_id, - sum(cs_ext_sales_price) as sales, - sum(coalesce(cr_return_amount, 0)) as returns, - sum(cs_net_profit - coalesce(cr_net_loss, 0)) as profit - from catalog_sales left outer join catalog_returns on - (cs_item_sk = cr_item_sk and cs_order_number = cr_order_number), - date_dim, - catalog_page, - item, - promotion - where cs_sold_date_sk = d_date_sk - and d_date between cast('2002-08-08' as date) - and dateadd(day,30,cast('2002-08-08' as date)) - and cs_catalog_page_sk = cp_catalog_page_sk - and cs_item_sk = i_item_sk - and i_current_price > 50 - and cs_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(ws_ext_sales_price) as sales, - sum(coalesce(wr_return_amt, 0)) as returns, - sum(ws_net_profit - coalesce(wr_net_loss, 0)) as profit - from web_sales left outer join web_returns on - (ws_item_sk = wr_item_sk and ws_order_number = wr_order_number), - date_dim, - web_site, - item, - promotion - where ws_sold_date_sk = d_date_sk - and d_date between cast('2002-08-08' as date) - and dateadd(day,30,cast('2002-08-08' as date)) - and ws_web_site_sk = web_site_sk - and ws_item_sk = i_item_sk - and i_current_price > 50 - and ws_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by web_site_id) -, -results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || store_id as id - , sales - , returns - , profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || catalog_page_id as id - , sales - , returns - , profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , profit - from wsr - ) x - group by channel, id) - - select channel - , id - , sales - , returns - , profit - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results - ) foo - order by channel, id - limit 100; - --- end template query80a.tpl query 25 in stream 7 --- start template query20.tpl query 26 in stream 7 -select /* TPC-DS query20.tpl 0.65 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(cs_ext_sales_price) as itemrevenue - ,sum(cs_ext_sales_price)*100/sum(sum(cs_ext_sales_price)) over - (partition by i_class) as revenueratio - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and i_category in ('Books', 'Jewelry', 'Electronics') - and cs_sold_date_sk = d_date_sk - and d_date between cast('1999-04-18' as date) - and dateadd(day,30,cast('1999-04-18' as date)) - group by i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - order by i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query20.tpl query 26 in stream 7 --- start template query2.tpl query 27 in stream 7 -with /* TPC-DS query2.tpl 0.84 */ wscs as - (select sold_date_sk - ,sales_price - from (select ws_sold_date_sk sold_date_sk - ,ws_ext_sales_price sales_price - from web_sales - union all - select cs_sold_date_sk sold_date_sk - ,cs_ext_sales_price sales_price - from catalog_sales)), - wswscs as - (select d_week_seq, - sum(case when (d_day_name='Sunday') then sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then sales_price else null end) sat_sales - from wscs - ,date_dim - where d_date_sk = sold_date_sk - group by d_week_seq) - select d_week_seq1 - ,round(sun_sales1/sun_sales2,2) - ,round(mon_sales1/mon_sales2,2) - ,round(tue_sales1/tue_sales2,2) - ,round(wed_sales1/wed_sales2,2) - ,round(thu_sales1/thu_sales2,2) - ,round(fri_sales1/fri_sales2,2) - ,round(sat_sales1/sat_sales2,2) - from - (select wswscs.d_week_seq d_week_seq1 - ,sun_sales sun_sales1 - ,mon_sales mon_sales1 - ,tue_sales tue_sales1 - ,wed_sales wed_sales1 - ,thu_sales thu_sales1 - ,fri_sales fri_sales1 - ,sat_sales sat_sales1 - from wswscs,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 1999) y, - (select wswscs.d_week_seq d_week_seq2 - ,sun_sales sun_sales2 - ,mon_sales mon_sales2 - ,tue_sales tue_sales2 - ,wed_sales wed_sales2 - ,thu_sales thu_sales2 - ,fri_sales fri_sales2 - ,sat_sales sat_sales2 - from wswscs - ,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 1999+1) z - where d_week_seq1=d_week_seq2-53 - order by d_week_seq1; - --- end template query2.tpl query 27 in stream 7 --- start template query21.tpl query 28 in stream 7 -select /* TPC-DS query21.tpl 0.14 */ * - from(select w_warehouse_name - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('2001-02-26' as date)) - then inv_quantity_on_hand - else 0 end) as inv_before - ,sum(case when (cast(d_date as date) >= cast ('2001-02-26' as date)) - then inv_quantity_on_hand - else 0 end) as inv_after - from inventory - ,warehouse - ,item - ,date_dim - where i_current_price between 0.99 and 1.49 - and i_item_sk = inv_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('2001-02-26' as date)) - and dateadd(day,30,cast ('2001-02-26' as date)) - group by w_warehouse_name, i_item_id) x - where (case when inv_before > 0 - then inv_after / inv_before - else null - end) between 2.0/3.0 and 3.0/2.0 - order by w_warehouse_name - ,i_item_id - limit 100; - --- end template query21.tpl query 28 in stream 7 --- start template query97.tpl query 29 in stream 7 -with /* TPC-DS query97.tpl 0.38 */ ssci as ( -select ss_customer_sk customer_sk - ,ss_item_sk item_sk -from store_sales,date_dim -where ss_sold_date_sk = d_date_sk - and d_month_seq between 1194 and 1194 + 11 -group by ss_customer_sk - ,ss_item_sk), -csci as( - select cs_bill_customer_sk customer_sk - ,cs_item_sk item_sk -from catalog_sales,date_dim -where cs_sold_date_sk = d_date_sk - and d_month_seq between 1194 and 1194 + 11 -group by cs_bill_customer_sk - ,cs_item_sk) - select sum(case when ssci.customer_sk is not null and csci.customer_sk is null then 1 else 0 end) store_only - ,sum(case when ssci.customer_sk is null and csci.customer_sk is not null then 1 else 0 end) catalog_only - ,sum(case when ssci.customer_sk is not null and csci.customer_sk is not null then 1 else 0 end) store_and_catalog -from ssci full outer join csci on (ssci.customer_sk=csci.customer_sk - and ssci.item_sk = csci.item_sk) -limit 100; - --- end template query97.tpl query 29 in stream 7 --- start template query62.tpl query 30 in stream 7 -select /* TPC-DS query62.tpl 0.24 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 30) and - (ws_ship_date_sk - ws_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 60) and - (ws_ship_date_sk - ws_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 90) and - (ws_ship_date_sk - ws_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - web_sales - ,warehouse - ,ship_mode - ,web_site - ,date_dim -where - d_month_seq between 1201 and 1201 + 11 -and ws_ship_date_sk = d_date_sk -and ws_warehouse_sk = w_warehouse_sk -and ws_ship_mode_sk = sm_ship_mode_sk -and ws_web_site_sk = web_site_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -limit 100; - --- end template query62.tpl query 30 in stream 7 --- start template query47.tpl query 31 in stream 7 -with /* TPC-DS query47.tpl 0.42 */ v1 as( - select i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, - s_store_name, s_company_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - s_store_name, s_company_name - order by d_year, d_moy) rn - from item, store_sales, date_dim, store - where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - ( - d_year = 2001 or - ( d_year = 2001-1 and d_moy =12) or - ( d_year = 2001+1 and d_moy =1) - ) - group by i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy), - v2 as( - select v1.i_brand - ,v1.d_year - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1.s_store_name = v1_lag.s_store_name and - v1.s_store_name = v1_lead.s_store_name and - v1.s_company_name = v1_lag.s_company_name and - v1.s_company_name = v1_lead.s_company_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 2001 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, psum - limit 100; - --- end template query47.tpl query 31 in stream 7 --- start template query60.tpl query 32 in stream 7 -with /* TPC-DS query60.tpl 0.29 */ ss as ( - select - i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Jewelry')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 8 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - cs as ( - select - i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Jewelry')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 8 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - ws as ( - select - i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Jewelry')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 8 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id) - select - i_item_id -,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by i_item_id - ,total_sales - limit 100; - --- end template query60.tpl query 32 in stream 7 --- start template query71.tpl query 33 in stream 7 -select /* TPC-DS query71.tpl 0.72 */ i_brand_id brand_id, i_brand brand,t_hour,t_minute, - sum(ext_price) ext_price - from item, (select ws_ext_sales_price as ext_price, - ws_sold_date_sk as sold_date_sk, - ws_item_sk as sold_item_sk, - ws_sold_time_sk as time_sk - from web_sales,date_dim - where d_date_sk = ws_sold_date_sk - and d_moy=11 - and d_year=1998 - union all - select cs_ext_sales_price as ext_price, - cs_sold_date_sk as sold_date_sk, - cs_item_sk as sold_item_sk, - cs_sold_time_sk as time_sk - from catalog_sales,date_dim - where d_date_sk = cs_sold_date_sk - and d_moy=11 - and d_year=1998 - union all - select ss_ext_sales_price as ext_price, - ss_sold_date_sk as sold_date_sk, - ss_item_sk as sold_item_sk, - ss_sold_time_sk as time_sk - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - and d_moy=11 - and d_year=1998 - ) tmp,time_dim - where - sold_item_sk = i_item_sk - and i_manager_id=1 - and time_sk = t_time_sk - and (t_meal_time = 'breakfast' or t_meal_time = 'dinner') - group by i_brand, i_brand_id,t_hour,t_minute - order by ext_price desc, i_brand_id - ; - --- end template query71.tpl query 33 in stream 7 --- start template query46.tpl query 34 in stream 7 -select /* TPC-DS query46.tpl 0.23 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and (household_demographics.hd_dep_count = 0 or - household_demographics.hd_vehicle_count= -1) - and date_dim.d_dow in (6,0) - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_city in ('Pine Grove','Pleasant Grove','Pleasant Hill','Stringtown','Clinton') - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,ca_city) dn,customer,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - limit 100; - --- end template query46.tpl query 34 in stream 7 --- start template query10.tpl query 35 in stream 7 -select /* TPC-DS query10.tpl 0.26 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3, - cd_dep_count, - count(*) cnt4, - cd_dep_employed_count, - count(*) cnt5, - cd_dep_college_count, - count(*) cnt6 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_county in ('Walsh County','Logan County','Ross County','Freestone County','Pike County') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 1999 and - d_moy between 4 and 4+3) and - (exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 1999 and - d_moy between 4 ANd 4+3) or - exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 1999 and - d_moy between 4 and 4+3)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count -limit 100; - --- end template query10.tpl query 35 in stream 7 --- start template query14a.tpl query 36 in stream 7 -with /* TPC-DS query14a.tpl 0.69 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 2000 AND 2000 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 2000 AND 2000 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 2000 AND 2000 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as - (select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2) x) -, - results AS -(select channel, i_brand_id, i_class_id, i_category_id, sum(sales) sum_sales, sum(number_sales) number_sales - from ( - select 'store' channel, i_brand_id,i_class_id - ,i_category_id,sum(ss_quantity*ss_list_price) sales - , count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2000+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales) - union all - select 'catalog' channel, i_brand_id,i_class_id,i_category_id, sum(cs_quantity*cs_list_price) sales, count(*) number_sales - from catalog_sales - ,item - ,date_dim - where cs_item_sk in (select ss_item_sk from cross_items) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2000+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(cs_quantity*cs_list_price) > (select average_sales from avg_sales) - union all - select 'web' channel, i_brand_id,i_class_id,i_category_id, sum(ws_quantity*ws_list_price) sales , count(*) number_sales - from web_sales - ,item - ,date_dim - where ws_item_sk in (select ss_item_sk from cross_items) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2000+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ws_quantity*ws_list_price) > (select average_sales from avg_sales) - ) y - group by channel, i_brand_id,i_class_id,i_category_id) - - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales -from ( - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales from results - union - select channel, i_brand_id, i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id, i_class_id - union - select channel, i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id - union - select channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel - union - select null as channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results) z -order by channel, i_brand_id, i_class_id, i_category_id - limit 100; -with /* TPC-DS query14a.tpl 0.69 part2 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 2000 AND 2000 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 2000 AND 2000 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 2000 AND 2000 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as -(select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2) x) - select this_year.channel ty_channel - ,this_year.i_brand_id ty_brand - ,this_year.i_class_id ty_class - ,this_year.i_category_id ty_category - ,this_year.sales ty_sales - ,this_year.number_sales ty_number_sales - ,last_year.channel ly_channel - ,last_year.i_brand_id ly_brand - ,last_year.i_class_id ly_class - ,last_year.i_category_id ly_category - ,last_year.sales ly_sales - ,last_year.number_sales ly_number_sales -from - (select 'store' channel, i_brand_id,i_class_id,i_category_id - ,sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 2000 + 1 - and d_moy = 12 - and d_dom = 1) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) this_year, - (select 'store' channel, i_brand_id,i_class_id - ,i_category_id, sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 2000 - and d_moy = 12 - and d_dom = 1) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) last_year - where this_year.i_brand_id= last_year.i_brand_id - and this_year.i_class_id = last_year.i_class_id - and this_year.i_category_id = last_year.i_category_id - order by this_year.channel, this_year.i_brand_id, this_year.i_class_id, this_year.i_category_id - limit 100; - --- end template query14a.tpl query 36 in stream 7 --- start template query35a.tpl query 37 in stream 7 -select /* TPC-DS query35a.tpl 0.47 */ - ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - count(*) cnt1, - sum(cd_dep_count), - sum(cd_dep_count), - min(cd_dep_count), - cd_dep_employed_count, - count(*) cnt2, - sum(cd_dep_employed_count), - sum(cd_dep_employed_count), - min(cd_dep_employed_count), - cd_dep_college_count, - count(*) cnt3, - sum(cd_dep_college_count), - sum(cd_dep_college_count), - min(cd_dep_college_count) - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2000 and - d_qoy < 4) and - exists (select * from - (select ws_bill_customer_sk customsk - from web_sales,date_dim - where - ws_sold_date_sk = d_date_sk and - d_year = 2000 and - d_qoy < 4 - union all - select cs_ship_customer_sk customsk - from catalog_sales,date_dim - where - cs_sold_date_sk = d_date_sk and - d_year = 2000 and - d_qoy < 4)x - where x.customsk = c.c_customer_sk) - group by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - limit 100; - --- end template query35a.tpl query 37 in stream 7 --- start template query55.tpl query 38 in stream 7 -select /* TPC-DS query55.tpl 0.82 */ i_brand_id brand_id, i_brand brand, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=65 - and d_moy=11 - and d_year=1999 - group by i_brand, i_brand_id - order by ext_price desc, i_brand_id -limit 100 ; - --- end template query55.tpl query 38 in stream 7 --- start template query37.tpl query 39 in stream 7 -select /* TPC-DS query37.tpl 0.31 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, catalog_sales - where i_current_price between 48 and 48 + 30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('2001-01-03' as date) and dateadd(day,60,cast('2001-01-03' as date)) - and i_manufact_id in (781,934,761,803) - and inv_quantity_on_hand between 100 and 500 - and cs_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query37.tpl query 39 in stream 7 --- start template query52.tpl query 40 in stream 7 -select /* TPC-DS query52.tpl 0.59 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_sales_price) ext_price - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=11 - and dt.d_year=2001 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,ext_price desc - ,brand_id -limit 100 ; - --- end template query52.tpl query 40 in stream 7 --- start template query9.tpl query 41 in stream 7 -select /* TPC-DS query9.tpl 0.49 */ case when (select count(*) - from store_sales - where ss_quantity between 1 and 20) > 11059080 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 1 and 20) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 1 and 20) end bucket1 , - case when (select count(*) - from store_sales - where ss_quantity between 21 and 40) > 67713305 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 21 and 40) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 21 and 40) end bucket2, - case when (select count(*) - from store_sales - where ss_quantity between 41 and 60) > 110927476 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 41 and 60) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 41 and 60) end bucket3, - case when (select count(*) - from store_sales - where ss_quantity between 61 and 80) > 138660616 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 61 and 80) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 61 and 80) end bucket4, - case when (select count(*) - from store_sales - where ss_quantity between 81 and 100) > 35618279 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 81 and 100) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 81 and 100) end bucket5 -from reason -where r_reason_sk = 1 -; - --- end template query9.tpl query 41 in stream 7 --- start template query85.tpl query 42 in stream 7 -select /* TPC-DS query85.tpl 0.33 */ substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) - from web_sales, web_returns, web_page, customer_demographics cd1, - customer_demographics cd2, customer_address, date_dim, reason - where ws_web_page_sk = wp_web_page_sk - and ws_item_sk = wr_item_sk - and ws_order_number = wr_order_number - and ws_sold_date_sk = d_date_sk and d_year = 2001 - and cd1.cd_demo_sk = wr_refunded_cdemo_sk - and cd2.cd_demo_sk = wr_returning_cdemo_sk - and ca_address_sk = wr_refunded_addr_sk - and r_reason_sk = wr_reason_sk - and - ( - ( - cd1.cd_marital_status = 'S' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Advanced Degree' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 100.00 and 150.00 - ) - or - ( - cd1.cd_marital_status = 'U' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'College' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 50.00 and 100.00 - ) - or - ( - cd1.cd_marital_status = 'D' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Unknown' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ca_country = 'United States' - and - ca_state in ('MS', 'AK', 'KS') - and ws_net_profit between 100 and 200 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('TX', 'OH', 'PA') - and ws_net_profit between 150 and 300 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('MI', 'AR', 'IN') - and ws_net_profit between 50 and 250 - ) - ) -group by r_reason_desc -order by substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) -limit 100; - --- end template query85.tpl query 42 in stream 7 --- start template query40.tpl query 43 in stream 7 -select /* TPC-DS query40.tpl 0.86 */ - w_state - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('1999-04-16' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_before - ,sum(case when (cast(d_date as date) >= cast ('1999-04-16' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_after - from - catalog_sales left outer join catalog_returns on - (cs_order_number = cr_order_number - and cs_item_sk = cr_item_sk) - ,warehouse - ,item - ,date_dim - where - i_current_price between 0.99 and 1.49 - and i_item_sk = cs_item_sk - and cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('1999-04-16' as date)) - and dateadd(day,30,cast ('1999-04-16' as date)) - group by - w_state,i_item_id - order by w_state,i_item_id -limit 100; - --- end template query40.tpl query 43 in stream 7 --- start template query76.tpl query 44 in stream 7 -select /* TPC-DS query76.tpl 0.99 */ channel, col_name, d_year, d_qoy, i_category, COUNT(*) sales_cnt, SUM(ext_sales_price) sales_amt FROM ( - SELECT 'store' as channel, 'ss_customer_sk' col_name, d_year, d_qoy, i_category, ss_ext_sales_price ext_sales_price - FROM store_sales, item, date_dim - WHERE ss_customer_sk IS NULL - AND ss_sold_date_sk=d_date_sk - AND ss_item_sk=i_item_sk - UNION ALL - SELECT 'web' as channel, 'ws_warehouse_sk' col_name, d_year, d_qoy, i_category, ws_ext_sales_price ext_sales_price - FROM web_sales, item, date_dim - WHERE ws_warehouse_sk IS NULL - AND ws_sold_date_sk=d_date_sk - AND ws_item_sk=i_item_sk - UNION ALL - SELECT 'catalog' as channel, 'cs_warehouse_sk' col_name, d_year, d_qoy, i_category, cs_ext_sales_price ext_sales_price - FROM catalog_sales, item, date_dim - WHERE cs_warehouse_sk IS NULL - AND cs_sold_date_sk=d_date_sk - AND cs_item_sk=i_item_sk) foo -GROUP BY channel, col_name, d_year, d_qoy, i_category -ORDER BY channel, col_name, d_year, d_qoy, i_category -limit 100; - --- end template query76.tpl query 44 in stream 7 --- start template query44.tpl query 45 in stream 7 -select /* TPC-DS query44.tpl 0.4 */ asceding.rnk, i1.i_product_name best_performing, i2.i_product_name worst_performing -from(select * - from (select item_sk,rank() over (order by rank_col asc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 158 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 158 - and ss_customer_sk is null - group by ss_store_sk))V1)V11 - where rnk < 11) asceding, - (select * - from (select item_sk,rank() over (order by rank_col desc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 158 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 158 - and ss_customer_sk is null - group by ss_store_sk))V2)V21 - where rnk < 11) descending, -item i1, -item i2 -where asceding.rnk = descending.rnk - and i1.i_item_sk=asceding.item_sk - and i2.i_item_sk=descending.item_sk -order by asceding.rnk -limit 100; - --- end template query44.tpl query 45 in stream 7 --- start template query3.tpl query 46 in stream 7 -select /* TPC-DS query3.tpl 0.45 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_sales_price) sum_agg - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manufact_id = 57 - and dt.d_moy=12 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,sum_agg desc - ,brand_id - limit 100; - --- end template query3.tpl query 46 in stream 7 --- start template query26.tpl query 47 in stream 7 -select /* TPC-DS query26.tpl 0.85 */ i_item_id, - avg(cs_quantity) agg1, - avg(cs_list_price) agg2, - avg(cs_coupon_amt) agg3, - avg(cs_sales_price) agg4 - from catalog_sales, customer_demographics, date_dim, item, promotion - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd_demo_sk and - cs_promo_sk = p_promo_sk and - cd_gender = 'M' and - cd_marital_status = 'M' and - cd_education_status = 'Advanced Degree' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 2002 - group by i_item_id - order by i_item_id - limit 100; - --- end template query26.tpl query 47 in stream 7 --- start template query19.tpl query 48 in stream 7 -select /* TPC-DS query19.tpl 0.8 */ i_brand_id brand_id, i_brand brand, i_manufact_id, i_manufact, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item,customer,customer_address,store - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=51 - and d_moy=12 - and d_year=2001 - and ss_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and substring(ca_zip,1,5) <> substring(s_zip,1,5) - and ss_store_sk = s_store_sk - group by i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact - order by ext_price desc - ,i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact -limit 100 ; - --- end template query19.tpl query 48 in stream 7 --- start template query58.tpl query 49 in stream 7 -with /* TPC-DS query58.tpl 0.19 */ ss_items as - (select i_item_id item_id - ,sum(ss_ext_sales_price) ss_item_rev - from store_sales - ,item - ,date_dim - where ss_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '2002-04-13')) - and ss_sold_date_sk = d_date_sk - group by i_item_id), - cs_items as - (select i_item_id item_id - ,sum(cs_ext_sales_price) cs_item_rev - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '2002-04-13')) - and cs_sold_date_sk = d_date_sk - group by i_item_id), - ws_items as - (select i_item_id item_id - ,sum(ws_ext_sales_price) ws_item_rev - from web_sales - ,item - ,date_dim - where ws_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq =(select d_week_seq - from date_dim - where d_date = '2002-04-13')) - and ws_sold_date_sk = d_date_sk - group by i_item_id) - select ss_items.item_id - ,ss_item_rev - ,ss_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ss_dev - ,cs_item_rev - ,cs_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 cs_dev - ,ws_item_rev - ,ws_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ws_dev - ,(ss_item_rev+cs_item_rev+ws_item_rev)/3 average - from ss_items,cs_items,ws_items - where ss_items.item_id=cs_items.item_id - and ss_items.item_id=ws_items.item_id - and ss_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - and ss_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and cs_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and cs_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and ws_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and ws_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - order by item_id - ,ss_item_rev - limit 100; - --- end template query58.tpl query 49 in stream 7 --- start template query42.tpl query 50 in stream 7 -select /* TPC-DS query42.tpl 0.61 */ dt.d_year - ,item.i_category_id - ,item.i_category - ,sum(ss_ext_sales_price) - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=11 - and dt.d_year=2000 - group by dt.d_year - ,item.i_category_id - ,item.i_category - order by sum(ss_ext_sales_price) desc,dt.d_year - ,item.i_category_id - ,item.i_category -limit 100 ; - --- end template query42.tpl query 50 in stream 7 --- start template query75.tpl query 51 in stream 7 -WITH /* TPC-DS query75.tpl 0.3 */ all_sales AS ( - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,SUM(sales_cnt) AS sales_cnt - ,SUM(sales_amt) AS sales_amt - FROM (SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,cs_quantity - COALESCE(cr_return_quantity,0) AS sales_cnt - ,cs_ext_sales_price - COALESCE(cr_return_amount,0.0) AS sales_amt - FROM catalog_sales JOIN item ON i_item_sk=cs_item_sk - JOIN date_dim ON d_date_sk=cs_sold_date_sk - LEFT JOIN catalog_returns ON (cs_order_number=cr_order_number - AND cs_item_sk=cr_item_sk) - WHERE i_category='Sports' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ss_quantity - COALESCE(sr_return_quantity,0) AS sales_cnt - ,ss_ext_sales_price - COALESCE(sr_return_amt,0.0) AS sales_amt - FROM store_sales JOIN item ON i_item_sk=ss_item_sk - JOIN date_dim ON d_date_sk=ss_sold_date_sk - LEFT JOIN store_returns ON (ss_ticket_number=sr_ticket_number - AND ss_item_sk=sr_item_sk) - WHERE i_category='Sports' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ws_quantity - COALESCE(wr_return_quantity,0) AS sales_cnt - ,ws_ext_sales_price - COALESCE(wr_return_amt,0.0) AS sales_amt - FROM web_sales JOIN item ON i_item_sk=ws_item_sk - JOIN date_dim ON d_date_sk=ws_sold_date_sk - LEFT JOIN web_returns ON (ws_order_number=wr_order_number - AND ws_item_sk=wr_item_sk) - WHERE i_category='Sports') sales_detail - GROUP BY d_year, i_brand_id, i_class_id, i_category_id, i_manufact_id) - SELECT prev_yr.d_year AS prev_year - ,curr_yr.d_year AS year - ,curr_yr.i_brand_id - ,curr_yr.i_class_id - ,curr_yr.i_category_id - ,curr_yr.i_manufact_id - ,prev_yr.sales_cnt AS prev_yr_cnt - ,curr_yr.sales_cnt AS curr_yr_cnt - ,curr_yr.sales_cnt-prev_yr.sales_cnt AS sales_cnt_diff - ,curr_yr.sales_amt-prev_yr.sales_amt AS sales_amt_diff - FROM all_sales curr_yr, all_sales prev_yr - WHERE curr_yr.i_brand_id=prev_yr.i_brand_id - AND curr_yr.i_class_id=prev_yr.i_class_id - AND curr_yr.i_category_id=prev_yr.i_category_id - AND curr_yr.i_manufact_id=prev_yr.i_manufact_id - AND curr_yr.d_year=2000 - AND prev_yr.d_year=2000-1 - AND CAST(curr_yr.sales_cnt AS DECIMAL(17,2))/CAST(prev_yr.sales_cnt AS DECIMAL(17,2))<0.9 - ORDER BY sales_cnt_diff,sales_amt_diff - limit 100; - --- end template query75.tpl query 51 in stream 7 --- start template query17.tpl query 52 in stream 7 -select /* TPC-DS query17.tpl 0.41 */ i_item_id - ,i_item_desc - ,s_state - ,count(ss_quantity) as store_sales_quantitycount - ,avg(ss_quantity) as store_sales_quantityave - ,stddev_samp(ss_quantity) as store_sales_quantitystdev - ,stddev_samp(ss_quantity)/avg(ss_quantity) as store_sales_quantitycov - ,count(sr_return_quantity) as store_returns_quantitycount - ,avg(sr_return_quantity) as store_returns_quantityave - ,stddev_samp(sr_return_quantity) as store_returns_quantitystdev - ,stddev_samp(sr_return_quantity)/avg(sr_return_quantity) as store_returns_quantitycov - ,count(cs_quantity) as catalog_sales_quantitycount ,avg(cs_quantity) as catalog_sales_quantityave - ,stddev_samp(cs_quantity) as catalog_sales_quantitystdev - ,stddev_samp(cs_quantity)/avg(cs_quantity) as catalog_sales_quantitycov - from store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where d1.d_quarter_name = '1999Q1' - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_quarter_name in ('1999Q1','1999Q2','1999Q3') - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_quarter_name in ('1999Q1','1999Q2','1999Q3') - group by i_item_id - ,i_item_desc - ,s_state - order by i_item_id - ,i_item_desc - ,s_state -limit 100; - --- end template query17.tpl query 52 in stream 7 --- start template query38.tpl query 53 in stream 7 -select /* TPC-DS query38.tpl 0.54 */ count(*) from ( - select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1180 and 1180 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1180 and 1180 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1180 and 1180 + 11 -) hot_cust -limit 100; - --- end template query38.tpl query 53 in stream 7 --- start template query82.tpl query 54 in stream 7 -select /* TPC-DS query82.tpl 0.67 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, store_sales - where i_current_price between 61 and 61+30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('2002-03-16' as date) and dateadd(day,60,cast('2002-03-16' as date)) - and i_manufact_id in (62,714,617,604) - and inv_quantity_on_hand between 100 and 500 - and ss_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query82.tpl query 54 in stream 7 --- start template query87.tpl query 55 in stream 7 -select /* TPC-DS query87.tpl 0.77 */ count(*) -from ((select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1206 and 1206+11) - except - (select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1206 and 1206+11) - except - (select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1206 and 1206+11) -) cool_cust -; - --- end template query87.tpl query 55 in stream 7 --- start template query43.tpl query 56 in stream 7 -select /* TPC-DS query43.tpl 0.15 */ s_store_name, s_store_id, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from date_dim, store_sales, store - where d_date_sk = ss_sold_date_sk and - s_store_sk = ss_store_sk and - s_gmt_offset = -5 and - d_year = 2002 - group by s_store_name, s_store_id - order by s_store_name, s_store_id,sun_sales,mon_sales,tue_sales,wed_sales,thu_sales,fri_sales,sat_sales - limit 100; - --- end template query43.tpl query 56 in stream 7 --- start template query11.tpl query 57 in stream 7 -with /* TPC-DS query11.tpl 0.51 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ss_ext_list_price-ss_ext_discount_amt) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ws_ext_list_price-ws_ext_discount_amt) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_login - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 2001 - and t_s_secyear.dyear = 2001+1 - and t_w_firstyear.dyear = 2001 - and t_w_secyear.dyear = 2001+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else 0.0 end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else 0.0 end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_login -limit 100; - --- end template query11.tpl query 57 in stream 7 --- start template query5a.tpl query 58 in stream 7 -with /* TPC-DS query5a.tpl 0.98 */ ssr as - (select s_store_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ss_store_sk as store_sk, - ss_sold_date_sk as date_sk, - ss_ext_sales_price as sales_price, - ss_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from store_sales - union all - select sr_store_sk as store_sk, - sr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - sr_return_amt as return_amt, - sr_net_loss as net_loss - from store_returns - ) salesreturns, - date_dim, - store - where date_sk = d_date_sk - and d_date between cast('2002-08-12' as date) - and dateadd(day,14,cast('2002-08-12' as date)) - and store_sk = s_store_sk - group by s_store_id) - , - csr as - (select cp_catalog_page_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select cs_catalog_page_sk as page_sk, - cs_sold_date_sk as date_sk, - cs_ext_sales_price as sales_price, - cs_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from catalog_sales - union all - select cr_catalog_page_sk as page_sk, - cr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - cr_return_amount as return_amt, - cr_net_loss as net_loss - from catalog_returns - ) salesreturns, - date_dim, - catalog_page - where date_sk = d_date_sk - and d_date between cast('2002-08-12' as date) - and dateadd(day,14,cast('2002-08-12' as date)) - and page_sk = cp_catalog_page_sk - group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ws_web_site_sk as wsr_web_site_sk, - ws_sold_date_sk as date_sk, - ws_ext_sales_price as sales_price, - ws_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from web_sales - union all - select ws_web_site_sk as wsr_web_site_sk, - wr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - wr_return_amt as return_amt, - wr_net_loss as net_loss - from web_returns left outer join web_sales on - ( wr_item_sk = ws_item_sk - and wr_order_number = ws_order_number) - ) salesreturns, - date_dim, - web_site - where date_sk = d_date_sk - and d_date between cast('2002-08-12' as date) - and dateadd(day,14,cast('2002-08-12' as date)) - and wsr_web_site_sk = web_site_sk - group by web_site_id) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || s_store_id as id - , sales - , returns - , (profit - profit_loss) as profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || cp_catalog_page_id as id - , sales - , returns - , (profit - profit_loss) as profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , (profit - profit_loss) as profit - from wsr - ) x - group by channel, id) - select channel, id, sales, returns, profit from ( - select channel, id, sales, returns, profit from results - union - select channel, null as id, sum(sales), sum(returns), sum(profit) from results group by channel - union - select null as channel, null as id, sum(sales), sum(returns), sum(profit) from results) foo -order by channel, id -limit 100; - --- end template query5a.tpl query 58 in stream 7 --- start template query41.tpl query 59 in stream 7 -select /* TPC-DS query41.tpl 0.62 */ distinct(i_product_name) - from item i1 - where i_manufact_id between 696 and 696+40 - and (select count(*) as item_cnt - from item - where (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'yellow' or i_color = 'peru') and - (i_units = 'Dozen' or i_units = 'Carton') and - (i_size = 'extra large' or i_size = 'N/A') - ) or - (i_category = 'Women' and - (i_color = 'cornsilk' or i_color = 'metallic') and - (i_units = 'Lb' or i_units = 'Tsp') and - (i_size = 'small' or i_size = 'medium') - ) or - (i_category = 'Men' and - (i_color = 'dark' or i_color = 'plum') and - (i_units = 'Each' or i_units = 'Gram') and - (i_size = 'petite' or i_size = 'economy') - ) or - (i_category = 'Men' and - (i_color = 'linen' or i_color = 'thistle') and - (i_units = 'Cup' or i_units = 'Ounce') and - (i_size = 'extra large' or i_size = 'N/A') - ))) or - (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'frosted' or i_color = 'sienna') and - (i_units = 'Box' or i_units = 'Pound') and - (i_size = 'extra large' or i_size = 'N/A') - ) or - (i_category = 'Women' and - (i_color = 'cream' or i_color = 'moccasin') and - (i_units = 'Dram' or i_units = 'Bundle') and - (i_size = 'small' or i_size = 'medium') - ) or - (i_category = 'Men' and - (i_color = 'firebrick' or i_color = 'misty') and - (i_units = 'Pallet' or i_units = 'Tbl') and - (i_size = 'petite' or i_size = 'economy') - ) or - (i_category = 'Men' and - (i_color = 'olive' or i_color = 'deep') and - (i_units = 'Unknown' or i_units = 'Bunch') and - (i_size = 'extra large' or i_size = 'N/A') - )))) > 0 - order by i_product_name - limit 100; - --- end template query41.tpl query 59 in stream 7 --- start template query61.tpl query 60 in stream 7 -select /* TPC-DS query61.tpl 0.97 */ promotions,total,cast(promotions as decimal(15,4))/cast(total as decimal(15,4))*100 -from - (select sum(ss_ext_sales_price) promotions - from store_sales - ,store - ,promotion - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_promo_sk = p_promo_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -7 - and i_category = 'Electronics' - and (p_channel_dmail = 'Y' or p_channel_email = 'Y' or p_channel_tv = 'Y') - and s_gmt_offset = -7 - and d_year = 1999 - and d_moy = 11) promotional_sales, - (select sum(ss_ext_sales_price) total - from store_sales - ,store - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -7 - and i_category = 'Electronics' - and s_gmt_offset = -7 - and d_year = 1999 - and d_moy = 11) all_sales -order by promotions, total -limit 100; - --- end template query61.tpl query 60 in stream 7 --- start template query33.tpl query 61 in stream 7 -with /* TPC-DS query33.tpl 0.22 */ ss as ( - select - i_manufact_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Jewelry')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 7 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id), - cs as ( - select - i_manufact_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Jewelry')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 7 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id), - ws as ( - select - i_manufact_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Jewelry')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 7 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id) - select i_manufact_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_manufact_id - order by total_sales -limit 100; - --- end template query33.tpl query 61 in stream 7 --- start template query49.tpl query 62 in stream 7 -select /* TPC-DS query49.tpl 0.48 */ channel, item, return_ratio, return_rank, currency_rank from - (select - 'web' as channel - ,web.item - ,web.return_ratio - ,web.return_rank - ,web.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select ws.ws_item_sk as item - ,(cast(sum(coalesce(wr.wr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(wr.wr_return_amt,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - web_sales ws left outer join web_returns wr - on (ws.ws_order_number = wr.wr_order_number and - ws.ws_item_sk = wr.wr_item_sk) - ,date_dim - where - wr.wr_return_amt > 10000 - and ws.ws_net_profit > 1 - and ws.ws_net_paid > 0 - and ws.ws_quantity > 0 - and ws_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 12 - group by ws.ws_item_sk - ) in_web - ) web - where - ( - web.return_rank <= 10 - or - web.currency_rank <= 10 - ) - union - select - 'catalog' as channel - ,catalog.item - ,catalog.return_ratio - ,catalog.return_rank - ,catalog.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select - cs.cs_item_sk as item - ,(cast(sum(coalesce(cr.cr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(cr.cr_return_amount,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - catalog_sales cs left outer join catalog_returns cr - on (cs.cs_order_number = cr.cr_order_number and - cs.cs_item_sk = cr.cr_item_sk) - ,date_dim - where - cr.cr_return_amount > 10000 - and cs.cs_net_profit > 1 - and cs.cs_net_paid > 0 - and cs.cs_quantity > 0 - and cs_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 12 - group by cs.cs_item_sk - ) in_cat - ) catalog - where - ( - catalog.return_rank <= 10 - or - catalog.currency_rank <=10 - ) - union - select - 'store' as channel - ,store.item - ,store.return_ratio - ,store.return_rank - ,store.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select sts.ss_item_sk as item - ,(cast(sum(coalesce(sr.sr_return_quantity,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(sr.sr_return_amt,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - store_sales sts left outer join store_returns sr - on (sts.ss_ticket_number = sr.sr_ticket_number and sts.ss_item_sk = sr.sr_item_sk) - ,date_dim - where - sr.sr_return_amt > 10000 - and sts.ss_net_profit > 1 - and sts.ss_net_paid > 0 - and sts.ss_quantity > 0 - and ss_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 12 - group by sts.ss_item_sk - ) in_store - ) store - where ( - store.return_rank <= 10 - or - store.currency_rank <= 10 - ) - ) - order by 1,4,5,2 - limit 100; - --- end template query49.tpl query 62 in stream 7 --- start template query7.tpl query 63 in stream 7 -select /* TPC-DS query7.tpl 0.2 */ i_item_id, - avg(ss_quantity) agg1, - avg(ss_list_price) agg2, - avg(ss_coupon_amt) agg3, - avg(ss_sales_price) agg4 - from store_sales, customer_demographics, date_dim, item, promotion - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_cdemo_sk = cd_demo_sk and - ss_promo_sk = p_promo_sk and - cd_gender = 'M' and - cd_marital_status = 'U' and - cd_education_status = 'College' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 1998 - group by i_item_id - order by i_item_id - limit 100; - --- end template query7.tpl query 63 in stream 7 --- start template query73.tpl query 64 in stream 7 -select /* TPC-DS query73.tpl 0.79 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_buy_potential = '1001-5000' or - household_demographics.hd_buy_potential = 'Unknown') - and household_demographics.hd_vehicle_count > 0 - and case when household_demographics.hd_vehicle_count > 0 then - household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count else null end > 1 - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_county in ('Walker County','Ziebach County','Kittitas County','Gogebic County') - group by ss_ticket_number,ss_customer_sk) dj,customer - where ss_customer_sk = c_customer_sk - and cnt between 1 and 5 - order by cnt desc, c_last_name asc; - --- end template query73.tpl query 64 in stream 7 --- start template query89.tpl query 65 in stream 7 -select /* TPC-DS query89.tpl 0.56 */ * -from( -select i_category, i_class, i_brand, - s_store_name, s_company_name, - d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, s_store_name, s_company_name) - avg_monthly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - d_year in (2000) and - ((i_category in ('Books','Music','Electronics') and - i_class in ('parenting','classical','automotive') - ) - or (i_category in ('Children','Sports','Home') and - i_class in ('infants','outdoor','wallpaper') - )) -group by i_category, i_class, i_brand, - s_store_name, s_company_name, d_moy) tmp1 -where case when (avg_monthly_sales <> 0) then (abs(sum_sales - avg_monthly_sales) / avg_monthly_sales) else null end > 0.1 -order by sum_sales - avg_monthly_sales, s_store_name -limit 100; - --- end template query89.tpl query 65 in stream 7 --- start template query81.tpl query 66 in stream 7 -with /* TPC-DS query81.tpl 0.37 */ customer_total_return as - (select cr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(cr_return_amt_inc_tax) as ctr_total_return - from catalog_returns - ,date_dim - ,customer_address - where cr_returned_date_sk = d_date_sk - and d_year =2002 - and cr_returning_addr_sk = ca_address_sk - group by cr_returning_customer_sk - ,ca_state ) - select c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'NE' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - limit 100; - --- end template query81.tpl query 66 in stream 7 --- start template query78.tpl query 67 in stream 7 -with /* TPC-DS query78.tpl 0.10 */ ws as - (select d_year AS ws_sold_year, ws_item_sk, - ws_bill_customer_sk ws_customer_sk, - sum(ws_quantity) ws_qty, - sum(ws_wholesale_cost) ws_wc, - sum(ws_sales_price) ws_sp - from web_sales - left join web_returns on wr_order_number=ws_order_number and ws_item_sk=wr_item_sk - join date_dim on ws_sold_date_sk = d_date_sk - where wr_order_number is null - group by d_year, ws_item_sk, ws_bill_customer_sk - ), -cs as - (select d_year AS cs_sold_year, cs_item_sk, - cs_bill_customer_sk cs_customer_sk, - sum(cs_quantity) cs_qty, - sum(cs_wholesale_cost) cs_wc, - sum(cs_sales_price) cs_sp - from catalog_sales - left join catalog_returns on cr_order_number=cs_order_number and cs_item_sk=cr_item_sk - join date_dim on cs_sold_date_sk = d_date_sk - where cr_order_number is null - group by d_year, cs_item_sk, cs_bill_customer_sk - ), -ss as - (select d_year AS ss_sold_year, ss_item_sk, - ss_customer_sk, - sum(ss_quantity) ss_qty, - sum(ss_wholesale_cost) ss_wc, - sum(ss_sales_price) ss_sp - from store_sales - left join store_returns on sr_ticket_number=ss_ticket_number and ss_item_sk=sr_item_sk - join date_dim on ss_sold_date_sk = d_date_sk - where sr_ticket_number is null - group by d_year, ss_item_sk, ss_customer_sk - ) - select -ss_item_sk, -round(ss_qty/(coalesce(ws_qty,0)+coalesce(cs_qty,0)),2) ratio, -ss_qty store_qty, ss_wc store_wholesale_cost, ss_sp store_sales_price, -coalesce(ws_qty,0)+coalesce(cs_qty,0) other_chan_qty, -coalesce(ws_wc,0)+coalesce(cs_wc,0) other_chan_wholesale_cost, -coalesce(ws_sp,0)+coalesce(cs_sp,0) other_chan_sales_price -from ss -left join ws on (ws_sold_year=ss_sold_year and ws_item_sk=ss_item_sk and ws_customer_sk=ss_customer_sk) -left join cs on (cs_sold_year=ss_sold_year and cs_item_sk=ss_item_sk and cs_customer_sk=ss_customer_sk) -where (coalesce(ws_qty,0)>0 or coalesce(cs_qty, 0)>0) and ss_sold_year=1999 -order by - ss_item_sk, - ss_qty desc, ss_wc desc, ss_sp desc, - other_chan_qty, - other_chan_wholesale_cost, - other_chan_sales_price, - ratio -limit 100; - --- end template query78.tpl query 67 in stream 7 --- start template query18a.tpl query 68 in stream 7 -with /* TPC-DS query18a.tpl 0.90 */ results as - (select i_item_id, - ca_country, - ca_state, - ca_county, - cast(cs_quantity as decimal(12,2)) agg1, - cast(cs_list_price as decimal(12,2)) agg2, - cast(cs_coupon_amt as decimal(12,2)) agg3, - cast(cs_sales_price as decimal(12,2)) agg4, - cast(cs_net_profit as decimal(12,2)) agg5, - cast(c_birth_year as decimal(12,2)) agg6, - cast(cd1.cd_dep_count as decimal(12,2)) agg7 - from catalog_sales, customer_demographics cd1, customer_demographics cd2, customer, customer_address, date_dim, item - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd1.cd_demo_sk and - cs_bill_customer_sk = c_customer_sk and - cd1.cd_gender = 'F' and - cd1.cd_education_status = 'Unknown' and - c_current_cdemo_sk = cd2.cd_demo_sk and - c_current_addr_sk = ca_address_sk and - c_birth_month in (9,2,8,10,7,3) and - d_year = 2002 and - ca_state in ('TN','TX','NC','MT','CO','FL','AK') - ) - select i_item_id, ca_country, ca_state, ca_county, agg1, agg2, agg3, agg4, agg5, agg6, agg7 - from ( - select i_item_id, ca_country, ca_state, ca_county, avg(agg1) agg1, - avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state, ca_county - union all - select i_item_id, ca_country, ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state - union all - select i_item_id, ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country - union all - select i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - ) foo - order by ca_country, ca_state, ca_county, i_item_id - limit 100; - --- end template query18a.tpl query 68 in stream 7 --- start template query36a.tpl query 69 in stream 7 -with /* TPC-DS query36a.tpl 0.21 */ results as - (select - sum(ss_net_profit) as ss_net_profit, sum(ss_ext_sales_price) as ss_ext_sales_price, - sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin - ,i_category - ,i_class - ,0 as g_category, 0 as g_class - from - store_sales - ,date_dim d1 - ,item - ,store - where - d1.d_year = 2000 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and s_state in ('GA','TN','OH','NE', - 'AL','PA','NY','AL') - group by i_category,i_class) - , - results_rollup as - (select gross_margin ,i_category ,i_class,0 as t_category, 0 as t_class, 0 as lochierarchy from results - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - i_category, NULL AS i_class, 0 as t_category, 1 as t_class, 1 as lochierarchy from results group by i_category - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - NULL AS i_category ,NULL AS i_class, 1 as t_category, 1 as t_class, 2 as lochierarchy from results) - select - gross_margin ,i_category ,i_class, lochierarchy,rank() over ( - partition by lochierarchy, case when t_class = 0 then i_category end - order by gross_margin asc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then i_category end - ,rank_within_parent - limit 100; - --- end template query36a.tpl query 69 in stream 7 --- start template query51.tpl query 70 in stream 7 -WITH /* TPC-DS query51.tpl 0.46 */ web_v1 as ( -select - ws_item_sk item_sk, d_date, - sum(sum(ws_sales_price)) - over (partition by ws_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from web_sales - ,date_dim -where ws_sold_date_sk=d_date_sk - and d_month_seq between 1191 and 1191+11 - and ws_item_sk is not NULL -group by ws_item_sk, d_date), -store_v1 as ( -select - ss_item_sk item_sk, d_date, - sum(sum(ss_sales_price)) - over (partition by ss_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from store_sales - ,date_dim -where ss_sold_date_sk=d_date_sk - and d_month_seq between 1191 and 1191+11 - and ss_item_sk is not NULL -group by ss_item_sk, d_date) - select * -from (select item_sk - ,d_date - ,web_sales - ,store_sales - ,max(web_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) web_cumulative - ,max(store_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) store_cumulative - from (select case when web.item_sk is not null then web.item_sk else store.item_sk end item_sk - ,case when web.d_date is not null then web.d_date else store.d_date end d_date - ,web.cume_sales web_sales - ,store.cume_sales store_sales - from web_v1 web full outer join store_v1 store on (web.item_sk = store.item_sk - and web.d_date = store.d_date) - )x )y -where web_cumulative > store_cumulative -order by item_sk - ,d_date -limit 100; - --- end template query51.tpl query 70 in stream 7 --- start template query56.tpl query 71 in stream 7 -with /* TPC-DS query56.tpl 0.83 */ ss as ( - select i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where i_item_id in (select - i_item_id -from item -where i_color in ('purple','rose','deep')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 7 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - cs as ( - select i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('purple','rose','deep')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 7 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - ws as ( - select i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('purple','rose','deep')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 7 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id) - select i_item_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by total_sales, - i_item_id - limit 100; - --- end template query56.tpl query 71 in stream 7 --- start template query83.tpl query 72 in stream 7 -with /* TPC-DS query83.tpl 0.96 */ sr_items as - (select i_item_id item_id, - sum(sr_return_quantity) sr_item_qty - from store_returns, - item, - date_dim - where sr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('1999-07-23','1999-09-10','1999-11-09'))) - and sr_returned_date_sk = d_date_sk - group by i_item_id), - cr_items as - (select i_item_id item_id, - sum(cr_return_quantity) cr_item_qty - from catalog_returns, - item, - date_dim - where cr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('1999-07-23','1999-09-10','1999-11-09'))) - and cr_returned_date_sk = d_date_sk - group by i_item_id), - wr_items as - (select i_item_id item_id, - sum(wr_return_quantity) wr_item_qty - from web_returns, - item, - date_dim - where wr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('1999-07-23','1999-09-10','1999-11-09'))) - and wr_returned_date_sk = d_date_sk - group by i_item_id) - select sr_items.item_id - ,sr_item_qty - ,sr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 sr_dev - ,cr_item_qty - ,cr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 cr_dev - ,wr_item_qty - ,wr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 wr_dev - ,(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 average - from sr_items - ,cr_items - ,wr_items - where sr_items.item_id=cr_items.item_id - and sr_items.item_id=wr_items.item_id - order by sr_items.item_id - ,sr_item_qty - limit 100; - --- end template query83.tpl query 72 in stream 7 --- start template query23.tpl query 73 in stream 7 -with /* TPC-DS query23.tpl 0.68 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (1999,1999+1,1999+2,1999+3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1999,1999+1,1999+2,1999+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * -from - max_store_sales)) - select sum(sales) - from (select cs_quantity*cs_list_price sales - from catalog_sales - ,date_dim - where d_year = 1999 - and d_moy = 4 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - union all - select ws_quantity*ws_list_price sales - from web_sales - ,date_dim - where d_year = 1999 - and d_moy = 4 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer)) - limit 100; -with /* TPC-DS query23.tpl 0.68 part2 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (1999,1999 + 1,1999 + 2,1999 + 3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1999,1999+1,1999+2,1999+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * - from max_store_sales)) - select c_last_name,c_first_name,sales - from (select c_last_name,c_first_name,sum(cs_quantity*cs_list_price) sales - from catalog_sales - ,customer - ,date_dim - where d_year = 1999 - and d_moy = 4 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and cs_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name - union all - select c_last_name,c_first_name,sum(ws_quantity*ws_list_price) sales - from web_sales - ,customer - ,date_dim - where d_year = 1999 - and d_moy = 4 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and ws_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name) - order by c_last_name,c_first_name,sales - limit 100; - --- end template query23.tpl query 73 in stream 7 --- start template query8.tpl query 74 in stream 7 -select /* TPC-DS query8.tpl 0.63 */ s_store_name - ,sum(ss_net_profit) - from store_sales - ,date_dim - ,store, - (select ca_zip - from ( - SELECT substring(ca_zip,1,5) ca_zip - FROM customer_address - WHERE substring(ca_zip,1,5) IN ( - '84453','82541','17371','77534','66266','74556', - '27140','17954','39342','43846','18988', - '49625','41194','87375','22927','11307', - '75228','92814','18015','72626','44225', - '60432','43371','57357','14328','61786', - '52206','18566','64971','42948','13109', - '57056','71246','82389','16815','35246', - '77118','21986','75029','87698','71948', - '48916','59972','68899','78437','80847', - '37733','89975','20439','35161','47911', - '59870','15424','35604','15803','91825', - '31214','73105','83275','26109','20195', - '99375','60648','19023','51611','61166', - '37029','99873','20343','42965','96699', - '45289','40763','79790','25692','58032', - '68822','85440','85438','75825','75090', - '21902','42555','29884','86898','50763', - '82741','55607','38002','78908','81041', - '18305','73998','17034','29009','50497', - '35058','69988','14825','78700','24682', - '52512','45571','33536','64410','14454', - '88881','74540','88821','99110','38080', - '73684','86442','12805','79913','22729', - '13484','49550','88190','14960','71827', - '42410','38192','66842','13203','39715', - '82592','97745','68630','76113','12331', - '80817','76275','34180','60875','99764', - '46427','95637','22333','64890','72878', - '21900','86754','36391','21656','34075', - '83885','36443','50478','66053','87646', - '71609','70137','41048','48889','80960', - '26339','59772','48778','45424','21941', - '29289','36650','69800','94358','30854', - '79276','40670','19342','83571','75232', - '47651','10713','92805','86349','52250', - '51584','75508','82854','94114','29186', - '11230','65309','39614','55120','86136', - '33890','13231','40073','81825','45386', - '70024','48717','96895','96571','26505', - '21095','99095','78261','81506','97978', - '25319','88601','10151','88392','61064', - '36760','99496','41154','88834','38979', - '69729','79353','68299','84664','12880', - '88522','45653','97319','91215','93448', - '55996','38594','28593','47426','67450', - '92316','36953','18910','52437','98584', - '19153','84430','26534','46182','29897', - '73571','86279','21352','65423','41343', - '20734','46011','96518','25930','96131', - '30424','87786','22541','13759','41898', - '47001','94793','66371','80918','12512', - '16192','82650','53764','97678','75540', - '88894','47252','68429','89135','89112', - '96287','78472','35942','70392','92970', - '26565','77587','25003','54721','57386', - '57306','17527','21740','78365','82171', - '32559','96859','48546','61059','75411', - '10470','34935','57323','63601','18035', - '11362','95547','89132','54861','12841', - '12120','94789','40951','84930','85772', - '11658','71020','82903','93646','56340', - '27875','73667','60607','75608','18772', - '45530','61710','78338','88425','97584', - '60067','51433','65037','90991','66378', - '54734','17198','37976','24941','92190', - '29975','73237','62851','62569','30648', - '66353','48955','77510','54577','98202', - '45109','53200','28613','29077','74037', - '98101','90841','53366','76537','57514', - '17965','14319','99972','93170','20875', - '51539','56323','13373','58954','27938', - '24172','46552','22470','32001','26880', - '60768','38551','22695','53765','23713', - '78018','69623','71945','17355','99717', - '16299','48622','86486','86561','17137', - '15025','23872','29069','67881','33299', - '80468','94180','79959','79953','19139', - '51237','52466','31085','32023','94832', - '63632','50780','73425','56197','73465', - '91994','61173','85756','15369') - intersect - select ca_zip - from (SELECT substring(ca_zip,1,5) ca_zip,count(*) cnt - FROM customer_address, customer - WHERE ca_address_sk = c_current_addr_sk and - c_preferred_cust_flag='Y' - group by ca_zip - having count(*) > 10)A1)A2) V1 - where ss_store_sk = s_store_sk - and ss_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 2000 - and (substring(s_zip,1,2) = substring(V1.ca_zip,1,2)) - group by s_store_name - order by s_store_name - limit 100; - --- end template query8.tpl query 74 in stream 7 --- start template query24.tpl query 75 in stream 7 -with /* TPC-DS query24.tpl 0.92 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_net_paid) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip -and s_market_id=6 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'cream' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; -with /* TPC-DS query24.tpl 0.92 part2 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_net_paid) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip - and s_market_id = 6 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'metallic' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; - --- end template query24.tpl query 75 in stream 7 --- start template query63.tpl query 76 in stream 7 -select /* TPC-DS query63.tpl 0.27 */ * -from (select i_manager_id - ,sum(ss_sales_price) sum_sales - ,avg(sum(ss_sales_price)) over (partition by i_manager_id) avg_monthly_sales - from item - ,store_sales - ,date_dim - ,store - where ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and d_month_seq in (1200,1200+1,1200+2,1200+3,1200+4,1200+5,1200+6,1200+7,1200+8,1200+9,1200+10,1200+11) - and (( i_category in ('Books','Children','Electronics') - and i_class in ('personal','portable','reference','self-help') - and i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) - or( i_category in ('Women','Music','Men') - and i_class in ('accessories','classical','fragrances','pants') - and i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manager_id, d_moy) tmp1 -where case when avg_monthly_sales > 0 then abs (sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 -order by i_manager_id - ,avg_monthly_sales - ,sum_sales -limit 100; - --- end template query63.tpl query 76 in stream 7 --- start template query1.tpl query 77 in stream 7 -with /* TPC-DS query1.tpl 0.12 */ customer_total_return as -(select sr_customer_sk as ctr_customer_sk -,sr_store_sk as ctr_store_sk -,sum(SR_STORE_CREDIT) as ctr_total_return -from store_returns -,date_dim -where sr_returned_date_sk = d_date_sk -and d_year =2001 -group by sr_customer_sk -,sr_store_sk) - select c_customer_id -from customer_total_return ctr1 -,store -,customer -where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 -from customer_total_return ctr2 -where ctr1.ctr_store_sk = ctr2.ctr_store_sk) -and s_store_sk = ctr1.ctr_store_sk -and s_state = 'AL' -and ctr1.ctr_customer_sk = c_customer_sk -order by c_customer_id -limit 100; - --- end template query1.tpl query 77 in stream 7 --- start template query12.tpl query 78 in stream 7 -select /* TPC-DS query12.tpl 0.64 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ws_ext_sales_price) as itemrevenue - ,sum(ws_ext_sales_price)*100/sum(sum(ws_ext_sales_price)) over - (partition by i_class) as revenueratio -from - web_sales - ,item - ,date_dim -where - ws_item_sk = i_item_sk - and i_category in ('Children', 'Sports', 'Men') - and ws_sold_date_sk = d_date_sk - and d_date between cast('2001-05-06' as date) - and dateadd(day,30,cast('2001-05-06' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query12.tpl query 78 in stream 7 --- start template query68.tpl query 79 in stream 7 -select /* TPC-DS query68.tpl 0.95 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,extended_price - ,extended_tax - ,list_price - from (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_ext_sales_price) extended_price - ,sum(ss_ext_list_price) list_price - ,sum(ss_ext_tax) extended_tax - from store_sales - ,date_dim - ,store - ,household_demographics - ,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_dep_count = 1 or - household_demographics.hd_vehicle_count= 3) - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_city in ('Farmington','Oakwood') - group by ss_ticket_number - ,ss_customer_sk - ,ss_addr_sk,ca_city) dn - ,customer - ,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,ss_ticket_number - limit 100; - --- end template query68.tpl query 79 in stream 7 --- start template query66.tpl query 80 in stream 7 -select /* TPC-DS query66.tpl 0.39 */ - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - ,sum(jan_sales) as jan_sales - ,sum(feb_sales) as feb_sales - ,sum(mar_sales) as mar_sales - ,sum(apr_sales) as apr_sales - ,sum(may_sales) as may_sales - ,sum(jun_sales) as jun_sales - ,sum(jul_sales) as jul_sales - ,sum(aug_sales) as aug_sales - ,sum(sep_sales) as sep_sales - ,sum(oct_sales) as oct_sales - ,sum(nov_sales) as nov_sales - ,sum(dec_sales) as dec_sales - ,sum(jan_sales/w_warehouse_sq_ft) as jan_sales_per_sq_foot - ,sum(feb_sales/w_warehouse_sq_ft) as feb_sales_per_sq_foot - ,sum(mar_sales/w_warehouse_sq_ft) as mar_sales_per_sq_foot - ,sum(apr_sales/w_warehouse_sq_ft) as apr_sales_per_sq_foot - ,sum(may_sales/w_warehouse_sq_ft) as may_sales_per_sq_foot - ,sum(jun_sales/w_warehouse_sq_ft) as jun_sales_per_sq_foot - ,sum(jul_sales/w_warehouse_sq_ft) as jul_sales_per_sq_foot - ,sum(aug_sales/w_warehouse_sq_ft) as aug_sales_per_sq_foot - ,sum(sep_sales/w_warehouse_sq_ft) as sep_sales_per_sq_foot - ,sum(oct_sales/w_warehouse_sq_ft) as oct_sales_per_sq_foot - ,sum(nov_sales/w_warehouse_sq_ft) as nov_sales_per_sq_foot - ,sum(dec_sales/w_warehouse_sq_ft) as dec_sales_per_sq_foot - ,sum(jan_net) as jan_net - ,sum(feb_net) as feb_net - ,sum(mar_net) as mar_net - ,sum(apr_net) as apr_net - ,sum(may_net) as may_net - ,sum(jun_net) as jun_net - ,sum(jul_net) as jul_net - ,sum(aug_net) as aug_net - ,sum(sep_net) as sep_net - ,sum(oct_net) as oct_net - ,sum(nov_net) as nov_net - ,sum(dec_net) as dec_net - from ( - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'LATVIAN' || ',' || 'GREAT EASTERN' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then ws_ext_list_price* ws_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then ws_ext_list_price* ws_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then ws_ext_list_price* ws_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then ws_ext_list_price* ws_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then ws_ext_list_price* ws_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then ws_ext_list_price* ws_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then ws_ext_list_price* ws_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then ws_ext_list_price* ws_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then ws_ext_list_price* ws_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then ws_ext_list_price* ws_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then ws_ext_list_price* ws_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then ws_ext_list_price* ws_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as dec_net - from - web_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - ws_warehouse_sk = w_warehouse_sk - and ws_sold_date_sk = d_date_sk - and ws_sold_time_sk = t_time_sk - and ws_ship_mode_sk = sm_ship_mode_sk - and d_year = 1998 - and t_time between 47504 and 47504+28800 - and sm_carrier in ('LATVIAN','GREAT EASTERN') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - union all - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'LATVIAN' || ',' || 'GREAT EASTERN' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then cs_ext_list_price* cs_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then cs_ext_list_price* cs_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then cs_ext_list_price* cs_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then cs_ext_list_price* cs_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then cs_ext_list_price* cs_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then cs_ext_list_price* cs_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then cs_ext_list_price* cs_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then cs_ext_list_price* cs_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then cs_ext_list_price* cs_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then cs_ext_list_price* cs_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then cs_ext_list_price* cs_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then cs_ext_list_price* cs_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then cs_net_profit * cs_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then cs_net_profit * cs_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then cs_net_profit * cs_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then cs_net_profit * cs_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then cs_net_profit * cs_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then cs_net_profit * cs_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then cs_net_profit * cs_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then cs_net_profit * cs_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then cs_net_profit * cs_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then cs_net_profit * cs_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then cs_net_profit * cs_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then cs_net_profit * cs_quantity else 0 end) as dec_net - from - catalog_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and cs_sold_time_sk = t_time_sk - and cs_ship_mode_sk = sm_ship_mode_sk - and d_year = 1998 - and t_time between 47504 AND 47504+28800 - and sm_carrier in ('LATVIAN','GREAT EASTERN') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - ) x - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - order by w_warehouse_name - limit 100; - --- end template query66.tpl query 80 in stream 7 --- start template query67a.tpl query 81 in stream 7 -with /* TPC-DS query67a.tpl 0.35 */ results as -( select i_category ,i_class ,i_brand ,i_product_name ,d_year ,d_qoy ,d_moy ,s_store_id - ,sum(coalesce(ss_sales_price*ss_quantity,0)) sumsales - from store_sales ,date_dim ,store ,item - where ss_sold_date_sk=d_date_sk - and ss_item_sk=i_item_sk - and ss_store_sk = s_store_sk - and d_month_seq between 1200 and 1200 + 11 - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy,s_store_id) - , - results_rollup as - (select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, s_store_id, sumsales - from results - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy - union all - select i_category, i_class, i_brand, i_product_name, d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year - union all - select i_category, i_class, i_brand, i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name - union all - select i_category, i_class, i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand - union all - select i_category, i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class - union all - select i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category - union all - select null i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results) - - select * -from (select i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rank() over (partition by i_category order by sumsales desc) rk - from results_rollup) dw2 -where rk <= 100 -order by i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rk -limit 100; - --- end template query67a.tpl query 81 in stream 7 --- start template query77a.tpl query 82 in stream 7 -with /* TPC-DS query77a.tpl 0.78 */ ss as - (select s_store_sk, - sum(ss_ext_sales_price) as sales, - sum(ss_net_profit) as profit - from store_sales, - date_dim, - store - where ss_sold_date_sk = d_date_sk - and d_date between cast('2001-08-19' as date) - and dateadd(day,30,cast('2001-08-19' as date)) - and ss_store_sk = s_store_sk - group by s_store_sk) - , - sr as - (select s_store_sk, - sum(sr_return_amt) as returns, - sum(sr_net_loss) as profit_loss - from store_returns, - date_dim, - store - where sr_returned_date_sk = d_date_sk - and d_date between cast('2001-08-19' as date) - and dateadd(day,30,cast('2001-08-19' as date)) - and sr_store_sk = s_store_sk - group by s_store_sk), - cs as - (select cs_call_center_sk, - sum(cs_ext_sales_price) as sales, - sum(cs_net_profit) as profit - from catalog_sales, - date_dim - where cs_sold_date_sk = d_date_sk - and d_date between cast('2001-08-19' as date) - and dateadd(day,30,cast('2001-08-19' as date)) - group by cs_call_center_sk - ), - cr as - (select cr_call_center_sk, - sum(cr_return_amount) as returns, - sum(cr_net_loss) as profit_loss - from catalog_returns, - date_dim - where cr_returned_date_sk = d_date_sk - and d_date between cast('2001-08-19' as date) - and dateadd(day,30,cast('2001-08-19' as date)) - group by cr_call_center_sk), - ws as - ( select wp_web_page_sk, - sum(ws_ext_sales_price) as sales, - sum(ws_net_profit) as profit - from web_sales, - date_dim, - web_page - where ws_sold_date_sk = d_date_sk - and d_date between cast('2001-08-19' as date) - and dateadd(day,30,cast('2001-08-19' as date)) - and ws_web_page_sk = wp_web_page_sk - group by wp_web_page_sk), - wr as - (select wp_web_page_sk, - sum(wr_return_amt) as returns, - sum(wr_net_loss) as profit_loss - from web_returns, - date_dim, - web_page - where wr_returned_date_sk = d_date_sk - and d_date between cast('2001-08-19' as date) - and dateadd(day,30,cast('2001-08-19' as date)) - and wr_web_page_sk = wp_web_page_sk - group by wp_web_page_sk) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , ss.s_store_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ss left join sr - on ss.s_store_sk = sr.s_store_sk - union all - select 'catalog channel' as channel - , cs_call_center_sk as id - , sales - , returns - , (profit - profit_loss) as profit - from cs - , cr - union all - select 'web channel' as channel - , ws.wp_web_page_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ws left join wr - on ws.wp_web_page_sk = wr.wp_web_page_sk - ) x - group by channel, id ) - - select * - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results -) foo -order by channel, id - limit 100; - --- end template query77a.tpl query 82 in stream 7 --- start template query15.tpl query 83 in stream 7 -select /* TPC-DS query15.tpl 0.57 */ ca_zip - ,sum(cs_sales_price) - from catalog_sales - ,customer - ,customer_address - ,date_dim - where cs_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', - '85392', '85460', '80348', '81792') - or ca_state in ('CA','WA','GA') - or cs_sales_price > 500) - and cs_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 1999 - group by ca_zip - order by ca_zip - limit 100; - --- end template query15.tpl query 83 in stream 7 --- start template query88.tpl query 84 in stream 7 -select /* TPC-DS query88.tpl 0.66 */ * -from - (select count(*) h8_30_to_9 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s1, - (select count(*) h9_to_9_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s2, - (select count(*) h9_30_to_10 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s3, - (select count(*) h10_to_10_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s4, - (select count(*) h10_30_to_11 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s5, - (select count(*) h11_to_11_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s6, - (select count(*) h11_30_to_12 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s7, - (select count(*) h12_to_12_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 12 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s8 -; - --- end template query88.tpl query 84 in stream 7 --- start template query65.tpl query 85 in stream 7 -select /* TPC-DS query65.tpl 0.71 */ - s_store_name, - i_item_desc, - sc.revenue, - i_current_price, - i_wholesale_cost, - i_brand - from store, item, - (select ss_store_sk, avg(revenue) as ave - from - (select ss_store_sk, ss_item_sk, - sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1177 and 1177+11 - group by ss_store_sk, ss_item_sk) sa - group by ss_store_sk) sb, - (select ss_store_sk, ss_item_sk, sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1177 and 1177+11 - group by ss_store_sk, ss_item_sk) sc - where sb.ss_store_sk = sc.ss_store_sk and - sc.revenue <= 0.1 * sb.ave and - s_store_sk = sc.ss_store_sk and - i_item_sk = sc.ss_item_sk - order by s_store_name, i_item_desc -limit 100; - --- end template query65.tpl query 85 in stream 7 --- start template query59.tpl query 86 in stream 7 -with /* TPC-DS query59.tpl 0.30 */ wss as - (select d_week_seq, - ss_store_sk, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - group by d_week_seq,ss_store_sk - ) - select s_store_name1,s_store_id1,d_week_seq1 - ,sun_sales1/sun_sales2,mon_sales1/mon_sales2 - ,tue_sales1/tue_sales2,wed_sales1/wed_sales2,thu_sales1/thu_sales2 - ,fri_sales1/fri_sales2,sat_sales1/sat_sales2 - from - (select s_store_name s_store_name1,wss.d_week_seq d_week_seq1 - ,s_store_id s_store_id1,sun_sales sun_sales1 - ,mon_sales mon_sales1,tue_sales tue_sales1 - ,wed_sales wed_sales1,thu_sales thu_sales1 - ,fri_sales fri_sales1,sat_sales sat_sales1 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1196 and 1196 + 11) y, - (select s_store_name s_store_name2,wss.d_week_seq d_week_seq2 - ,s_store_id s_store_id2,sun_sales sun_sales2 - ,mon_sales mon_sales2,tue_sales tue_sales2 - ,wed_sales wed_sales2,thu_sales thu_sales2 - ,fri_sales fri_sales2,sat_sales sat_sales2 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1196+ 12 and 1196 + 23) x - where s_store_id1=s_store_id2 - and d_week_seq1=d_week_seq2-52 - order by s_store_name1,s_store_id1,d_week_seq1 -limit 100; - --- end template query59.tpl query 86 in stream 7 --- start template query96.tpl query 87 in stream 7 -select /* TPC-DS query96.tpl 0.1 */ count(*) -from store_sales - ,household_demographics - ,time_dim, store -where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and household_demographics.hd_dep_count = 3 - and store.s_store_name = 'ese' -order by count(*) -limit 100; - --- end template query96.tpl query 87 in stream 7 --- start template query54.tpl query 88 in stream 7 -with /* TPC-DS query54.tpl 0.81 */ my_customers as ( - select distinct c_customer_sk - , c_current_addr_sk - from - ( select cs_sold_date_sk sold_date_sk, - cs_bill_customer_sk customer_sk, - cs_item_sk item_sk - from catalog_sales - union all - select ws_sold_date_sk sold_date_sk, - ws_bill_customer_sk customer_sk, - ws_item_sk item_sk - from web_sales - ) cs_or_ws_sales, - item, - date_dim, - customer - where sold_date_sk = d_date_sk - and item_sk = i_item_sk - and i_category = 'Electronics' - and i_class = 'memory' - and c_customer_sk = cs_or_ws_sales.customer_sk - and d_moy = 1 - and d_year = 2000 - ) - , my_revenue as ( - select c_customer_sk, - sum(ss_ext_sales_price) as revenue - from my_customers, - store_sales, - customer_address, - store, - date_dim - where c_current_addr_sk = ca_address_sk - and ca_county = s_county - and ca_state = s_state - and ss_sold_date_sk = d_date_sk - and c_customer_sk = ss_customer_sk - and d_month_seq between (select distinct d_month_seq+1 - from date_dim where d_year = 2000 and d_moy = 1) - and (select distinct d_month_seq+3 - from date_dim where d_year = 2000 and d_moy = 1) - group by c_customer_sk - ) - , segments as - (select cast((revenue/50) as int) as segment - from my_revenue - ) - select segment, count(*) as num_customers, segment*50 as segment_base - from segments - group by segment - order by segment, num_customers - limit 100; - --- end template query54.tpl query 88 in stream 7 --- start template query95.tpl query 89 in stream 7 -with /* TPC-DS query95.tpl 0.43 */ ws_wh as -(select ws1.ws_order_number,ws1.ws_warehouse_sk wh1,ws2.ws_warehouse_sk wh2 - from web_sales ws1,web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) - select - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2000-3-01' and - dateadd(day,60,cast('2000-3-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'LA' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and ws1.ws_order_number in (select ws_order_number - from ws_wh) -and ws1.ws_order_number in (select wr_order_number - from web_returns,ws_wh - where wr_order_number = ws_wh.ws_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query95.tpl query 89 in stream 7 --- start template query93.tpl query 90 in stream 7 -select /* TPC-DS query93.tpl 0.52 */ ss_customer_sk - ,sum(act_sales) sumsales - from (select ss_item_sk - ,ss_ticket_number - ,ss_customer_sk - ,case when sr_return_quantity is not null then (ss_quantity-sr_return_quantity)*ss_sales_price - else (ss_quantity*ss_sales_price) end act_sales - from store_sales left outer join store_returns on (sr_item_sk = ss_item_sk - and sr_ticket_number = ss_ticket_number) - ,reason - where sr_reason_sk = r_reason_sk - and r_reason_desc = 'reason 71') t - group by ss_customer_sk - order by sumsales, ss_customer_sk -limit 100; - --- end template query93.tpl query 90 in stream 7 --- start template query91.tpl query 91 in stream 7 -select /* TPC-DS query91.tpl 0.13 */ - cc_call_center_id Call_Center, - cc_name Call_Center_Name, - cc_manager Manager, - sum(cr_net_loss) Returns_Loss -from - call_center, - catalog_returns, - date_dim, - customer, - customer_address, - customer_demographics, - household_demographics -where - cr_call_center_sk = cc_call_center_sk -and cr_returned_date_sk = d_date_sk -and cr_returning_customer_sk= c_customer_sk -and cd_demo_sk = c_current_cdemo_sk -and hd_demo_sk = c_current_hdemo_sk -and ca_address_sk = c_current_addr_sk -and d_year = 1998 -and d_moy = 12 -and ( (cd_marital_status = 'M' and cd_education_status = 'Unknown') - or(cd_marital_status = 'W' and cd_education_status = 'Advanced Degree')) -and hd_buy_potential like 'Unknown%' -and ca_gmt_offset = -7 -group by cc_call_center_id,cc_name,cc_manager,cd_marital_status,cd_education_status -order by sum(cr_net_loss) desc; - --- end template query91.tpl query 91 in stream 7 --- start template query74.tpl query 92 in stream 7 -with /* TPC-DS query74.tpl 0.76 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,max(ss_net_paid) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (2001,2001+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,max(ws_net_paid) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - and d_year in (2001,2001+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - ) - select - t_s_secyear.customer_id, t_s_secyear.customer_first_name, t_s_secyear.customer_last_name - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.year = 2001 - and t_s_secyear.year = 2001+1 - and t_w_firstyear.year = 2001 - and t_w_secyear.year = 2001+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - order by 2,3,1 -limit 100; - --- end template query74.tpl query 92 in stream 7 --- start template query94.tpl query 93 in stream 7 -select /* TPC-DS query94.tpl 0.17 */ - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2002-5-01' and - dateadd(day,60,cast('2002-5-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'AL' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and exists (select * - from web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) -and not exists(select * - from web_returns wr1 - where ws1.ws_order_number = wr1.wr_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query94.tpl query 93 in stream 7 --- start template query16.tpl query 94 in stream 7 -select /* TPC-DS query16.tpl 0.25 */ - count(distinct cs_order_number) as "order count" - ,sum(cs_ext_ship_cost) as "total shipping cost" - ,sum(cs_net_profit) as "total net profit" -from - catalog_sales cs1 - ,date_dim - ,customer_address - ,call_center -where - d_date between '2001-4-01' and - dateadd(day, 60, cast('2001-4-01' as date)) -and cs1.cs_ship_date_sk = d_date_sk -and cs1.cs_ship_addr_sk = ca_address_sk -and ca_state = 'OK' -and cs1.cs_call_center_sk = cc_call_center_sk -and cc_county in ('Wadena County','Richland County','Dauphin County','San Miguel County', - 'Daviess County' -) -and exists (select * - from catalog_sales cs2 - where cs1.cs_order_number = cs2.cs_order_number - and cs1.cs_warehouse_sk <> cs2.cs_warehouse_sk) -and not exists(select * - from catalog_returns cr1 - where cs1.cs_order_number = cr1.cr_order_number) -order by count(distinct cs_order_number) -limit 100; - --- end template query16.tpl query 94 in stream 7 --- start template query90.tpl query 95 in stream 7 -select /* TPC-DS query90.tpl 0.40 */ cast(amc as decimal(15,4))/cast(pmc as decimal(15,4)) am_pm_ratio - from ( select count(*) amc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 7 and 7+1 - and household_demographics.hd_dep_count = 7 - and web_page.wp_char_count between 5000 and 5200) at, - ( select count(*) pmc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 13 and 13+1 - and household_demographics.hd_dep_count = 7 - and web_page.wp_char_count between 5000 and 5200) pt - order by am_pm_ratio - limit 100; - --- end template query90.tpl query 95 in stream 7 --- start template query57.tpl query 96 in stream 7 -with /* TPC-DS query57.tpl 0.70 */ v1 as( - select i_category, i_brand, - cc_name, - d_year, d_moy, - sum(cs_sales_price) sum_sales, - avg(sum(cs_sales_price)) over - (partition by i_category, i_brand, - cc_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - cc_name - order by d_year, d_moy) rn - from item, catalog_sales, date_dim, call_center - where cs_item_sk = i_item_sk and - cs_sold_date_sk = d_date_sk and - cc_call_center_sk= cs_call_center_sk and - ( - d_year = 2000 or - ( d_year = 2000-1 and d_moy =12) or - ( d_year = 2000+1 and d_moy =1) - ) - group by i_category, i_brand, - cc_name , d_year, d_moy), - v2 as( - select v1.i_category, v1.i_brand - ,v1.d_year, v1.d_moy - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1. cc_name = v1_lag. cc_name and - v1. cc_name = v1_lead. cc_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 2000 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, avg_monthly_sales - limit 100; - --- end template query57.tpl query 96 in stream 7 --- start template query22a.tpl query 97 in stream 7 -with /* TPC-DS query22a.tpl 0.55 */ results as -(select i_product_name - ,i_brand - ,i_class - ,i_category - ,avg(inv_quantity_on_hand) qoh - from inventory - ,date_dim - ,item --- ,warehouse - where inv_date_sk=d_date_sk - and inv_item_sk=i_item_sk --- and inv_warehouse_sk = w_warehouse_sk - and d_month_seq between 1221 and 1221 + 11 - group by i_product_name,i_brand,i_class,i_category), -results_rollup as -(select i_product_name, i_brand, i_class, i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class,i_category -union all -select i_product_name, i_brand, i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class -union all -select i_product_name, i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand -union all -select i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name -union all -select null i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results) - select i_product_name, i_brand, i_class, i_category,qoh - from results_rollup - order by qoh, i_product_name, i_brand, i_class, i_category -limit 100; - --- end template query22a.tpl query 97 in stream 7 --- start template query50.tpl query 98 in stream 7 -select /* TPC-DS query50.tpl 0.60 */ - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 30) and - (sr_returned_date_sk - ss_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 60) and - (sr_returned_date_sk - ss_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 90) and - (sr_returned_date_sk - ss_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - store_sales - ,store_returns - ,store - ,date_dim d1 - ,date_dim d2 -where - d2.d_year = 1999 -and d2.d_moy = 10 -and ss_ticket_number = sr_ticket_number -and ss_item_sk = sr_item_sk -and ss_sold_date_sk = d1.d_date_sk -and sr_returned_date_sk = d2.d_date_sk -and ss_customer_sk = sr_customer_sk -and ss_store_sk = s_store_sk -group by - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -order by s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -limit 100; - --- end template query50.tpl query 98 in stream 7 --- start template query27a.tpl query 99 in stream 7 -with /* TPC-DS query27a.tpl 0.16 */ results as - (select i_item_id, - s_state, 0 as g_state, - ss_quantity agg1, - ss_list_price agg2, - ss_coupon_amt agg3, - ss_sales_price agg4 - from store_sales, customer_demographics, date_dim, store, item - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_store_sk = s_store_sk and - ss_cdemo_sk = cd_demo_sk and - cd_gender = 'F' and - cd_marital_status = 'M' and - cd_education_status = '2 yr Degree' and - d_year = 1998 and - s_state in ('MO','FL', 'MN', 'LA', 'AL', 'NM') - ) - - select i_item_id, - s_state, g_state, agg1, agg2, agg3, agg4 - from ( - select i_item_id, s_state, 0 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4 from results - group by i_item_id, s_state - union all - select i_item_id, NULL AS s_state, 1 AS g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as s_state, 1 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - ) foo - order by i_item_id, s_state - limit 100; - --- end template query27a.tpl query 99 in stream 7 diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/3TB/queries/query_8.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/3TB/queries/query_8.sql deleted file mode 100644 index 0c77c09a..00000000 --- a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/3TB/queries/query_8.sql +++ /dev/null @@ -1,5027 +0,0 @@ --- start template query57.tpl query 1 in stream 8 -with /* TPC-DS query57.tpl 0.70 */ v1 as( - select i_category, i_brand, - cc_name, - d_year, d_moy, - sum(cs_sales_price) sum_sales, - avg(sum(cs_sales_price)) over - (partition by i_category, i_brand, - cc_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - cc_name - order by d_year, d_moy) rn - from item, catalog_sales, date_dim, call_center - where cs_item_sk = i_item_sk and - cs_sold_date_sk = d_date_sk and - cc_call_center_sk= cs_call_center_sk and - ( - d_year = 2000 or - ( d_year = 2000-1 and d_moy =12) or - ( d_year = 2000+1 and d_moy =1) - ) - group by i_category, i_brand, - cc_name , d_year, d_moy), - v2 as( - select v1.cc_name - ,v1.d_year, v1.d_moy - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1. cc_name = v1_lag. cc_name and - v1. cc_name = v1_lead. cc_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 2000 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, nsum - limit 100; - --- end template query57.tpl query 1 in stream 8 --- start template query29.tpl query 2 in stream 8 -select /* TPC-DS query29.tpl 0.53 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,sum(ss_quantity) as store_sales_quantity - ,sum(sr_return_quantity) as store_returns_quantity - ,sum(cs_quantity) as catalog_sales_quantity - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 1998 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 4 + 3 - and d2.d_year = 1998 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_year in (1998,1998+1,1998+2) - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query29.tpl query 2 in stream 8 --- start template query24.tpl query 3 in stream 8 -with /* TPC-DS query24.tpl 0.92 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_ext_sales_price) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip -and s_market_id=10 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'salmon' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; -with /* TPC-DS query24.tpl 0.92 part2 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_ext_sales_price) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip - and s_market_id = 10 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'goldenrod' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; - --- end template query24.tpl query 3 in stream 8 --- start template query76.tpl query 4 in stream 8 -select /* TPC-DS query76.tpl 0.99 */ channel, col_name, d_year, d_qoy, i_category, COUNT(*) sales_cnt, SUM(ext_sales_price) sales_amt FROM ( - SELECT 'store' as channel, 'ss_addr_sk' col_name, d_year, d_qoy, i_category, ss_ext_sales_price ext_sales_price - FROM store_sales, item, date_dim - WHERE ss_addr_sk IS NULL - AND ss_sold_date_sk=d_date_sk - AND ss_item_sk=i_item_sk - UNION ALL - SELECT 'web' as channel, 'ws_bill_customer_sk' col_name, d_year, d_qoy, i_category, ws_ext_sales_price ext_sales_price - FROM web_sales, item, date_dim - WHERE ws_bill_customer_sk IS NULL - AND ws_sold_date_sk=d_date_sk - AND ws_item_sk=i_item_sk - UNION ALL - SELECT 'catalog' as channel, 'cs_bill_addr_sk' col_name, d_year, d_qoy, i_category, cs_ext_sales_price ext_sales_price - FROM catalog_sales, item, date_dim - WHERE cs_bill_addr_sk IS NULL - AND cs_sold_date_sk=d_date_sk - AND cs_item_sk=i_item_sk) foo -GROUP BY channel, col_name, d_year, d_qoy, i_category -ORDER BY channel, col_name, d_year, d_qoy, i_category -limit 100; - --- end template query76.tpl query 4 in stream 8 --- start template query37.tpl query 5 in stream 8 -select /* TPC-DS query37.tpl 0.31 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, catalog_sales - where i_current_price between 37 and 37 + 30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('1998-02-14' as date) and dateadd(day,60,cast('1998-02-14' as date)) - and i_manufact_id in (767,894,861,948) - and inv_quantity_on_hand between 100 and 500 - and cs_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query37.tpl query 5 in stream 8 --- start template query66.tpl query 6 in stream 8 -select /* TPC-DS query66.tpl 0.39 */ - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - ,sum(jan_sales) as jan_sales - ,sum(feb_sales) as feb_sales - ,sum(mar_sales) as mar_sales - ,sum(apr_sales) as apr_sales - ,sum(may_sales) as may_sales - ,sum(jun_sales) as jun_sales - ,sum(jul_sales) as jul_sales - ,sum(aug_sales) as aug_sales - ,sum(sep_sales) as sep_sales - ,sum(oct_sales) as oct_sales - ,sum(nov_sales) as nov_sales - ,sum(dec_sales) as dec_sales - ,sum(jan_sales/w_warehouse_sq_ft) as jan_sales_per_sq_foot - ,sum(feb_sales/w_warehouse_sq_ft) as feb_sales_per_sq_foot - ,sum(mar_sales/w_warehouse_sq_ft) as mar_sales_per_sq_foot - ,sum(apr_sales/w_warehouse_sq_ft) as apr_sales_per_sq_foot - ,sum(may_sales/w_warehouse_sq_ft) as may_sales_per_sq_foot - ,sum(jun_sales/w_warehouse_sq_ft) as jun_sales_per_sq_foot - ,sum(jul_sales/w_warehouse_sq_ft) as jul_sales_per_sq_foot - ,sum(aug_sales/w_warehouse_sq_ft) as aug_sales_per_sq_foot - ,sum(sep_sales/w_warehouse_sq_ft) as sep_sales_per_sq_foot - ,sum(oct_sales/w_warehouse_sq_ft) as oct_sales_per_sq_foot - ,sum(nov_sales/w_warehouse_sq_ft) as nov_sales_per_sq_foot - ,sum(dec_sales/w_warehouse_sq_ft) as dec_sales_per_sq_foot - ,sum(jan_net) as jan_net - ,sum(feb_net) as feb_net - ,sum(mar_net) as mar_net - ,sum(apr_net) as apr_net - ,sum(may_net) as may_net - ,sum(jun_net) as jun_net - ,sum(jul_net) as jul_net - ,sum(aug_net) as aug_net - ,sum(sep_net) as sep_net - ,sum(oct_net) as oct_net - ,sum(nov_net) as nov_net - ,sum(dec_net) as dec_net - from ( - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'DIAMOND' || ',' || 'TBS' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then ws_ext_list_price* ws_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then ws_ext_list_price* ws_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then ws_ext_list_price* ws_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then ws_ext_list_price* ws_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then ws_ext_list_price* ws_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then ws_ext_list_price* ws_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then ws_ext_list_price* ws_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then ws_ext_list_price* ws_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then ws_ext_list_price* ws_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then ws_ext_list_price* ws_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then ws_ext_list_price* ws_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then ws_ext_list_price* ws_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as dec_net - from - web_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - ws_warehouse_sk = w_warehouse_sk - and ws_sold_date_sk = d_date_sk - and ws_sold_time_sk = t_time_sk - and ws_ship_mode_sk = sm_ship_mode_sk - and d_year = 2001 - and t_time between 51000 and 51000+28800 - and sm_carrier in ('DIAMOND','TBS') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - union all - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'DIAMOND' || ',' || 'TBS' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then cs_ext_sales_price* cs_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then cs_ext_sales_price* cs_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then cs_ext_sales_price* cs_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then cs_ext_sales_price* cs_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then cs_ext_sales_price* cs_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then cs_ext_sales_price* cs_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then cs_ext_sales_price* cs_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then cs_ext_sales_price* cs_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then cs_ext_sales_price* cs_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then cs_ext_sales_price* cs_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then cs_ext_sales_price* cs_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then cs_ext_sales_price* cs_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as dec_net - from - catalog_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and cs_sold_time_sk = t_time_sk - and cs_ship_mode_sk = sm_ship_mode_sk - and d_year = 2001 - and t_time between 51000 AND 51000+28800 - and sm_carrier in ('DIAMOND','TBS') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - ) x - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - order by w_warehouse_name - limit 100; - --- end template query66.tpl query 6 in stream 8 --- start template query60.tpl query 7 in stream 8 -with /* TPC-DS query60.tpl 0.29 */ ss as ( - select - i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Jewelry')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 10 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - cs as ( - select - i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Jewelry')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 10 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - ws as ( - select - i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Jewelry')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 10 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id) - select - i_item_id -,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by i_item_id - ,total_sales - limit 100; - --- end template query60.tpl query 7 in stream 8 --- start template query98.tpl query 8 in stream 8 -select /* TPC-DS query98.tpl 0.32 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ss_ext_sales_price) as itemrevenue - ,sum(ss_ext_sales_price)*100/sum(sum(ss_ext_sales_price)) over - (partition by i_class) as revenueratio -from - store_sales - ,item - ,date_dim -where - ss_item_sk = i_item_sk - and i_category in ('Sports', 'Music', 'Men') - and ss_sold_date_sk = d_date_sk - and d_date between cast('2000-04-19' as date) - and dateadd(day,30,cast('2000-04-19' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio; - --- end template query98.tpl query 8 in stream 8 --- start template query80a.tpl query 9 in stream 8 -with /* TPC-DS query80a.tpl 0.6 */ ssr as - (select s_store_id as store_id, - sum(ss_ext_sales_price) as sales, - sum(coalesce(sr_return_amt, 0)) as returns, - sum(ss_net_profit - coalesce(sr_net_loss, 0)) as profit - from store_sales left outer join store_returns on - (ss_item_sk = sr_item_sk and ss_ticket_number = sr_ticket_number), - date_dim, - store, - item, - promotion - where ss_sold_date_sk = d_date_sk - and d_date between cast('1999-08-19' as date) - and dateadd(day,30,cast('1999-08-19' as date)) - and ss_store_sk = s_store_sk - and ss_item_sk = i_item_sk - and i_current_price > 50 - and ss_promo_sk = p_promo_sk - and p_channel_tv = 'N' - group by s_store_id) - , - csr as - (select cp_catalog_page_id as catalog_page_id, - sum(cs_ext_sales_price) as sales, - sum(coalesce(cr_return_amount, 0)) as returns, - sum(cs_net_profit - coalesce(cr_net_loss, 0)) as profit - from catalog_sales left outer join catalog_returns on - (cs_item_sk = cr_item_sk and cs_order_number = cr_order_number), - date_dim, - catalog_page, - item, - promotion - where cs_sold_date_sk = d_date_sk - and d_date between cast('1999-08-19' as date) - and dateadd(day,30,cast('1999-08-19' as date)) - and cs_catalog_page_sk = cp_catalog_page_sk - and cs_item_sk = i_item_sk - and i_current_price > 50 - and cs_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(ws_ext_sales_price) as sales, - sum(coalesce(wr_return_amt, 0)) as returns, - sum(ws_net_profit - coalesce(wr_net_loss, 0)) as profit - from web_sales left outer join web_returns on - (ws_item_sk = wr_item_sk and ws_order_number = wr_order_number), - date_dim, - web_site, - item, - promotion - where ws_sold_date_sk = d_date_sk - and d_date between cast('1999-08-19' as date) - and dateadd(day,30,cast('1999-08-19' as date)) - and ws_web_site_sk = web_site_sk - and ws_item_sk = i_item_sk - and i_current_price > 50 - and ws_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by web_site_id) -, -results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || store_id as id - , sales - , returns - , profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || catalog_page_id as id - , sales - , returns - , profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , profit - from wsr - ) x - group by channel, id) - - select channel - , id - , sales - , returns - , profit - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results - ) foo - order by channel, id - limit 100; - --- end template query80a.tpl query 9 in stream 8 --- start template query12.tpl query 10 in stream 8 -select /* TPC-DS query12.tpl 0.64 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ws_ext_sales_price) as itemrevenue - ,sum(ws_ext_sales_price)*100/sum(sum(ws_ext_sales_price)) over - (partition by i_class) as revenueratio -from - web_sales - ,item - ,date_dim -where - ws_item_sk = i_item_sk - and i_category in ('Women', 'Sports', 'Children') - and ws_sold_date_sk = d_date_sk - and d_date between cast('1999-06-25' as date) - and dateadd(day,30,cast('1999-06-25' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query12.tpl query 10 in stream 8 --- start template query59.tpl query 11 in stream 8 -with /* TPC-DS query59.tpl 0.30 */ wss as - (select d_week_seq, - ss_store_sk, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - group by d_week_seq,ss_store_sk - ) - select s_store_name1,s_store_id1,d_week_seq1 - ,sun_sales1/sun_sales2,mon_sales1/mon_sales2 - ,tue_sales1/tue_sales2,wed_sales1/wed_sales2,thu_sales1/thu_sales2 - ,fri_sales1/fri_sales2,sat_sales1/sat_sales2 - from - (select s_store_name s_store_name1,wss.d_week_seq d_week_seq1 - ,s_store_id s_store_id1,sun_sales sun_sales1 - ,mon_sales mon_sales1,tue_sales tue_sales1 - ,wed_sales wed_sales1,thu_sales thu_sales1 - ,fri_sales fri_sales1,sat_sales sat_sales1 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1211 and 1211 + 11) y, - (select s_store_name s_store_name2,wss.d_week_seq d_week_seq2 - ,s_store_id s_store_id2,sun_sales sun_sales2 - ,mon_sales mon_sales2,tue_sales tue_sales2 - ,wed_sales wed_sales2,thu_sales thu_sales2 - ,fri_sales fri_sales2,sat_sales sat_sales2 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1211+ 12 and 1211 + 23) x - where s_store_id1=s_store_id2 - and d_week_seq1=d_week_seq2-52 - order by s_store_name1,s_store_id1,d_week_seq1 -limit 100; - --- end template query59.tpl query 11 in stream 8 --- start template query70a.tpl query 12 in stream 8 -with /* TPC-DS query70a.tpl 0.34 */ results as -( select - sum(ss_net_profit) as total_sum ,s_state ,s_county, 0 as gstate, 0 as g_county - from - store_sales - ,date_dim d1 - ,store - where - d1.d_month_seq between 1179 and 1179 + 11 - and d1.d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - and s_state in - ( select s_state - from (select s_state as s_state, - rank() over ( partition by s_state order by sum(ss_net_profit) desc) as ranking - from store_sales, store, date_dim - where d_month_seq between 1179 and 1179 + 11 - and d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - group by s_state - ) tmp1 - where ranking <= 5) - group by s_state,s_county) , - results_rollup as -(select total_sum ,s_state ,s_county, 0 as g_state, 0 as g_county, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum,s_state, NULL as s_county, 0 as g_state, 1 as g_county, 1 as lochierarchy from results group by s_state - union - select sum(total_sum) as total_sum ,NULL as s_state ,NULL as s_county, 1 as g_state, 1 as g_county, 2 as lochierarchy from results) - select total_sum ,s_state ,s_county, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_county = 0 then s_state end - order by total_sum desc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then s_state end - ,rank_within_parent - limit 100; - --- end template query70a.tpl query 12 in stream 8 --- start template query91.tpl query 13 in stream 8 -select /* TPC-DS query91.tpl 0.13 */ - cc_call_center_id Call_Center, - cc_name Call_Center_Name, - cc_manager Manager, - sum(cr_net_loss) Returns_Loss -from - call_center, - catalog_returns, - date_dim, - customer, - customer_address, - customer_demographics, - household_demographics -where - cr_call_center_sk = cc_call_center_sk -and cr_returned_date_sk = d_date_sk -and cr_returning_customer_sk= c_customer_sk -and cd_demo_sk = c_current_cdemo_sk -and hd_demo_sk = c_current_hdemo_sk -and ca_address_sk = c_current_addr_sk -and d_year = 2002 -and d_moy = 11 -and ( (cd_marital_status = 'M' and cd_education_status = 'Unknown') - or(cd_marital_status = 'W' and cd_education_status = 'Advanced Degree')) -and hd_buy_potential like 'Unknown%' -and ca_gmt_offset = -6 -group by cc_call_center_id,cc_name,cc_manager,cd_marital_status,cd_education_status -order by sum(cr_net_loss) desc; - --- end template query91.tpl query 13 in stream 8 --- start template query69.tpl query 14 in stream 8 -select /* TPC-DS query69.tpl 0.28 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_state in ('KY','WY','VA') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2001 and - d_moy between 2 and 2+2) and - (not exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2001 and - d_moy between 2 and 2+2) and - not exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2001 and - d_moy between 2 and 2+2)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - limit 100; - --- end template query69.tpl query 14 in stream 8 --- start template query40.tpl query 15 in stream 8 -select /* TPC-DS query40.tpl 0.86 */ - w_state - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('2000-03-21' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_before - ,sum(case when (cast(d_date as date) >= cast ('2000-03-21' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_after - from - catalog_sales left outer join catalog_returns on - (cs_order_number = cr_order_number - and cs_item_sk = cr_item_sk) - ,warehouse - ,item - ,date_dim - where - i_current_price between 0.99 and 1.49 - and i_item_sk = cs_item_sk - and cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('2000-03-21' as date)) - and dateadd(day,30,cast ('2000-03-21' as date)) - group by - w_state,i_item_id - order by w_state,i_item_id -limit 100; - --- end template query40.tpl query 15 in stream 8 --- start template query2.tpl query 16 in stream 8 -with /* TPC-DS query2.tpl 0.84 */ wscs as - (select sold_date_sk - ,sales_price - from (select ws_sold_date_sk sold_date_sk - ,ws_ext_sales_price sales_price - from web_sales - union all - select cs_sold_date_sk sold_date_sk - ,cs_ext_sales_price sales_price - from catalog_sales)), - wswscs as - (select d_week_seq, - sum(case when (d_day_name='Sunday') then sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then sales_price else null end) sat_sales - from wscs - ,date_dim - where d_date_sk = sold_date_sk - group by d_week_seq) - select d_week_seq1 - ,round(sun_sales1/sun_sales2,2) - ,round(mon_sales1/mon_sales2,2) - ,round(tue_sales1/tue_sales2,2) - ,round(wed_sales1/wed_sales2,2) - ,round(thu_sales1/thu_sales2,2) - ,round(fri_sales1/fri_sales2,2) - ,round(sat_sales1/sat_sales2,2) - from - (select wswscs.d_week_seq d_week_seq1 - ,sun_sales sun_sales1 - ,mon_sales mon_sales1 - ,tue_sales tue_sales1 - ,wed_sales wed_sales1 - ,thu_sales thu_sales1 - ,fri_sales fri_sales1 - ,sat_sales sat_sales1 - from wswscs,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 2001) y, - (select wswscs.d_week_seq d_week_seq2 - ,sun_sales sun_sales2 - ,mon_sales mon_sales2 - ,tue_sales tue_sales2 - ,wed_sales wed_sales2 - ,thu_sales thu_sales2 - ,fri_sales fri_sales2 - ,sat_sales sat_sales2 - from wswscs - ,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 2001+1) z - where d_week_seq1=d_week_seq2-53 - order by d_week_seq1; - --- end template query2.tpl query 16 in stream 8 --- start template query16.tpl query 17 in stream 8 -select /* TPC-DS query16.tpl 0.25 */ - count(distinct cs_order_number) as "order count" - ,sum(cs_ext_ship_cost) as "total shipping cost" - ,sum(cs_net_profit) as "total net profit" -from - catalog_sales cs1 - ,date_dim - ,customer_address - ,call_center -where - d_date between '1999-2-01' and - dateadd(day, 60, cast('1999-2-01' as date)) -and cs1.cs_ship_date_sk = d_date_sk -and cs1.cs_ship_addr_sk = ca_address_sk -and ca_state = 'GA' -and cs1.cs_call_center_sk = cc_call_center_sk -and cc_county in ('Franklin Parish','Pennington County','Daviess County','Barrow County', - 'Kittitas County' -) -and exists (select * - from catalog_sales cs2 - where cs1.cs_order_number = cs2.cs_order_number - and cs1.cs_warehouse_sk <> cs2.cs_warehouse_sk) -and not exists(select * - from catalog_returns cr1 - where cs1.cs_order_number = cr1.cr_order_number) -order by count(distinct cs_order_number) -limit 100; - --- end template query16.tpl query 17 in stream 8 --- start template query44.tpl query 18 in stream 8 -select /* TPC-DS query44.tpl 0.4 */ asceding.rnk, i1.i_product_name best_performing, i2.i_product_name worst_performing -from(select * - from (select item_sk,rank() over (order by rank_col asc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 333 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 333 - and ss_promo_sk is null - group by ss_store_sk))V1)V11 - where rnk < 11) asceding, - (select * - from (select item_sk,rank() over (order by rank_col desc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 333 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 333 - and ss_promo_sk is null - group by ss_store_sk))V2)V21 - where rnk < 11) descending, -item i1, -item i2 -where asceding.rnk = descending.rnk - and i1.i_item_sk=asceding.item_sk - and i2.i_item_sk=descending.item_sk -order by asceding.rnk -limit 100; - --- end template query44.tpl query 18 in stream 8 --- start template query5a.tpl query 19 in stream 8 -with /* TPC-DS query5a.tpl 0.98 */ ssr as - (select s_store_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ss_store_sk as store_sk, - ss_sold_date_sk as date_sk, - ss_ext_sales_price as sales_price, - ss_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from store_sales - union all - select sr_store_sk as store_sk, - sr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - sr_return_amt as return_amt, - sr_net_loss as net_loss - from store_returns - ) salesreturns, - date_dim, - store - where date_sk = d_date_sk - and d_date between cast('1999-08-29' as date) - and dateadd(day,14,cast('1999-08-29' as date)) - and store_sk = s_store_sk - group by s_store_id) - , - csr as - (select cp_catalog_page_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select cs_catalog_page_sk as page_sk, - cs_sold_date_sk as date_sk, - cs_ext_sales_price as sales_price, - cs_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from catalog_sales - union all - select cr_catalog_page_sk as page_sk, - cr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - cr_return_amount as return_amt, - cr_net_loss as net_loss - from catalog_returns - ) salesreturns, - date_dim, - catalog_page - where date_sk = d_date_sk - and d_date between cast('1999-08-29' as date) - and dateadd(day,14,cast('1999-08-29' as date)) - and page_sk = cp_catalog_page_sk - group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ws_web_site_sk as wsr_web_site_sk, - ws_sold_date_sk as date_sk, - ws_ext_sales_price as sales_price, - ws_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from web_sales - union all - select ws_web_site_sk as wsr_web_site_sk, - wr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - wr_return_amt as return_amt, - wr_net_loss as net_loss - from web_returns left outer join web_sales on - ( wr_item_sk = ws_item_sk - and wr_order_number = ws_order_number) - ) salesreturns, - date_dim, - web_site - where date_sk = d_date_sk - and d_date between cast('1999-08-29' as date) - and dateadd(day,14,cast('1999-08-29' as date)) - and wsr_web_site_sk = web_site_sk - group by web_site_id) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || s_store_id as id - , sales - , returns - , (profit - profit_loss) as profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || cp_catalog_page_id as id - , sales - , returns - , (profit - profit_loss) as profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , (profit - profit_loss) as profit - from wsr - ) x - group by channel, id) - select channel, id, sales, returns, profit from ( - select channel, id, sales, returns, profit from results - union - select channel, null as id, sum(sales), sum(returns), sum(profit) from results group by channel - union - select null as channel, null as id, sum(sales), sum(returns), sum(profit) from results) foo -order by channel, id -limit 100; - --- end template query5a.tpl query 19 in stream 8 --- start template query73.tpl query 20 in stream 8 -select /* TPC-DS query73.tpl 0.79 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_buy_potential = '501-1000' or - household_demographics.hd_buy_potential = '0-500') - and household_demographics.hd_vehicle_count > 0 - and case when household_demographics.hd_vehicle_count > 0 then - household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count else null end > 1 - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_county in ('Perry County','Anderson County','Huron County','Oglethorpe County') - group by ss_ticket_number,ss_customer_sk) dj,customer - where ss_customer_sk = c_customer_sk - and cnt between 1 and 5 - order by cnt desc, c_last_name asc; - --- end template query73.tpl query 20 in stream 8 --- start template query14a.tpl query 21 in stream 8 -with /* TPC-DS query14a.tpl 0.69 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 2000 AND 2000 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 2000 AND 2000 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 2000 AND 2000 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as - (select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2) x) -, - results AS -(select channel, i_brand_id, i_class_id, i_category_id, sum(sales) sum_sales, sum(number_sales) number_sales - from ( - select 'store' channel, i_brand_id,i_class_id - ,i_category_id,sum(ss_quantity*ss_list_price) sales - , count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2000+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales) - union all - select 'catalog' channel, i_brand_id,i_class_id,i_category_id, sum(cs_quantity*cs_list_price) sales, count(*) number_sales - from catalog_sales - ,item - ,date_dim - where cs_item_sk in (select ss_item_sk from cross_items) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2000+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(cs_quantity*cs_list_price) > (select average_sales from avg_sales) - union all - select 'web' channel, i_brand_id,i_class_id,i_category_id, sum(ws_quantity*ws_list_price) sales , count(*) number_sales - from web_sales - ,item - ,date_dim - where ws_item_sk in (select ss_item_sk from cross_items) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2000+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ws_quantity*ws_list_price) > (select average_sales from avg_sales) - ) y - group by channel, i_brand_id,i_class_id,i_category_id) - - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales -from ( - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales from results - union - select channel, i_brand_id, i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id, i_class_id - union - select channel, i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id - union - select channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel - union - select null as channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results) z -order by channel, i_brand_id, i_class_id, i_category_id - limit 100; -with /* TPC-DS query14a.tpl 0.69 part2 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 2000 AND 2000 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 2000 AND 2000 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 2000 AND 2000 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as -(select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2) x) - select this_year.channel ty_channel - ,this_year.i_brand_id ty_brand - ,this_year.i_class_id ty_class - ,this_year.i_category_id ty_category - ,this_year.sales ty_sales - ,this_year.number_sales ty_number_sales - ,last_year.channel ly_channel - ,last_year.i_brand_id ly_brand - ,last_year.i_class_id ly_class - ,last_year.i_category_id ly_category - ,last_year.sales ly_sales - ,last_year.number_sales ly_number_sales -from - (select 'store' channel, i_brand_id,i_class_id,i_category_id - ,sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 2000 + 1 - and d_moy = 12 - and d_dom = 15) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) this_year, - (select 'store' channel, i_brand_id,i_class_id - ,i_category_id, sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 2000 - and d_moy = 12 - and d_dom = 15) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) last_year - where this_year.i_brand_id= last_year.i_brand_id - and this_year.i_class_id = last_year.i_class_id - and this_year.i_category_id = last_year.i_category_id - order by this_year.channel, this_year.i_brand_id, this_year.i_class_id, this_year.i_category_id - limit 100; - --- end template query14a.tpl query 21 in stream 8 --- start template query71.tpl query 22 in stream 8 -select /* TPC-DS query71.tpl 0.72 */ i_brand_id brand_id, i_brand brand,t_hour,t_minute, - sum(ext_price) ext_price - from item, (select ws_ext_sales_price as ext_price, - ws_sold_date_sk as sold_date_sk, - ws_item_sk as sold_item_sk, - ws_sold_time_sk as time_sk - from web_sales,date_dim - where d_date_sk = ws_sold_date_sk - and d_moy=11 - and d_year=2000 - union all - select cs_ext_sales_price as ext_price, - cs_sold_date_sk as sold_date_sk, - cs_item_sk as sold_item_sk, - cs_sold_time_sk as time_sk - from catalog_sales,date_dim - where d_date_sk = cs_sold_date_sk - and d_moy=11 - and d_year=2000 - union all - select ss_ext_sales_price as ext_price, - ss_sold_date_sk as sold_date_sk, - ss_item_sk as sold_item_sk, - ss_sold_time_sk as time_sk - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - and d_moy=11 - and d_year=2000 - ) tmp,time_dim - where - sold_item_sk = i_item_sk - and i_manager_id=1 - and time_sk = t_time_sk - and (t_meal_time = 'breakfast' or t_meal_time = 'dinner') - group by i_brand, i_brand_id,t_hour,t_minute - order by ext_price desc, i_brand_id - ; - --- end template query71.tpl query 22 in stream 8 --- start template query3.tpl query 23 in stream 8 -select /* TPC-DS query3.tpl 0.45 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_net_profit) sum_agg - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manufact_id = 409 - and dt.d_moy=12 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,sum_agg desc - ,brand_id - limit 100; - --- end template query3.tpl query 23 in stream 8 --- start template query49.tpl query 24 in stream 8 -select /* TPC-DS query49.tpl 0.48 */ channel, item, return_ratio, return_rank, currency_rank from - (select - 'web' as channel - ,web.item - ,web.return_ratio - ,web.return_rank - ,web.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select ws.ws_item_sk as item - ,(cast(sum(coalesce(wr.wr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(wr.wr_return_amt,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - web_sales ws left outer join web_returns wr - on (ws.ws_order_number = wr.wr_order_number and - ws.ws_item_sk = wr.wr_item_sk) - ,date_dim - where - wr.wr_return_amt > 10000 - and ws.ws_net_profit > 1 - and ws.ws_net_paid > 0 - and ws.ws_quantity > 0 - and ws_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 12 - group by ws.ws_item_sk - ) in_web - ) web - where - ( - web.return_rank <= 10 - or - web.currency_rank <= 10 - ) - union - select - 'catalog' as channel - ,catalog.item - ,catalog.return_ratio - ,catalog.return_rank - ,catalog.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select - cs.cs_item_sk as item - ,(cast(sum(coalesce(cr.cr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(cr.cr_return_amount,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - catalog_sales cs left outer join catalog_returns cr - on (cs.cs_order_number = cr.cr_order_number and - cs.cs_item_sk = cr.cr_item_sk) - ,date_dim - where - cr.cr_return_amount > 10000 - and cs.cs_net_profit > 1 - and cs.cs_net_paid > 0 - and cs.cs_quantity > 0 - and cs_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 12 - group by cs.cs_item_sk - ) in_cat - ) catalog - where - ( - catalog.return_rank <= 10 - or - catalog.currency_rank <=10 - ) - union - select - 'store' as channel - ,store.item - ,store.return_ratio - ,store.return_rank - ,store.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select sts.ss_item_sk as item - ,(cast(sum(coalesce(sr.sr_return_quantity,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(sr.sr_return_amt,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - store_sales sts left outer join store_returns sr - on (sts.ss_ticket_number = sr.sr_ticket_number and sts.ss_item_sk = sr.sr_item_sk) - ,date_dim - where - sr.sr_return_amt > 10000 - and sts.ss_net_profit > 1 - and sts.ss_net_paid > 0 - and sts.ss_quantity > 0 - and ss_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 12 - group by sts.ss_item_sk - ) in_store - ) store - where ( - store.return_rank <= 10 - or - store.currency_rank <= 10 - ) - ) - order by 1,4,5,2 - limit 100; - --- end template query49.tpl query 24 in stream 8 --- start template query84.tpl query 25 in stream 8 -select /* TPC-DS query84.tpl 0.80 */ c_customer_id as customer_id - , coalesce(c_last_name,'') || ', ' || coalesce(c_first_name,'') as customername - from customer - ,customer_address - ,customer_demographics - ,household_demographics - ,income_band - ,store_returns - where ca_city = 'Pine Grove' - and c_current_addr_sk = ca_address_sk - and ib_lower_bound >= 65534 - and ib_upper_bound <= 65534 + 50000 - and ib_income_band_sk = hd_income_band_sk - and cd_demo_sk = c_current_cdemo_sk - and hd_demo_sk = c_current_hdemo_sk - and sr_cdemo_sk = cd_demo_sk - order by c_customer_id - limit 100; - --- end template query84.tpl query 25 in stream 8 --- start template query64.tpl query 26 in stream 8 -with /* TPC-DS query64.tpl 0.20 */ cs_ui as - (select cs_item_sk - ,sum(cs_ext_list_price) as sale,sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit) as refund - from catalog_sales - ,catalog_returns - where cs_item_sk = cr_item_sk - and cs_order_number = cr_order_number - group by cs_item_sk - having sum(cs_ext_list_price)>2*sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit)), -cross_sales as - (select i_product_name product_name - ,i_item_sk item_sk - ,s_store_name store_name - ,s_zip store_zip - ,ad1.ca_street_number b_street_number - ,ad1.ca_street_name b_street_name - ,ad1.ca_city b_city - ,ad1.ca_zip b_zip - ,ad2.ca_street_number c_street_number - ,ad2.ca_street_name c_street_name - ,ad2.ca_city c_city - ,ad2.ca_zip c_zip - ,d1.d_year as syear - ,d2.d_year as fsyear - ,d3.d_year s2year - ,count(*) cnt - ,sum(ss_wholesale_cost) s1 - ,sum(ss_list_price) s2 - ,sum(ss_coupon_amt) s3 - FROM store_sales - ,store_returns - ,cs_ui - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,customer - ,customer_demographics cd1 - ,customer_demographics cd2 - ,promotion - ,household_demographics hd1 - ,household_demographics hd2 - ,customer_address ad1 - ,customer_address ad2 - ,income_band ib1 - ,income_band ib2 - ,item - WHERE ss_store_sk = s_store_sk AND - ss_sold_date_sk = d1.d_date_sk AND - ss_customer_sk = c_customer_sk AND - ss_cdemo_sk= cd1.cd_demo_sk AND - ss_hdemo_sk = hd1.hd_demo_sk AND - ss_addr_sk = ad1.ca_address_sk and - ss_item_sk = i_item_sk and - ss_item_sk = sr_item_sk and - ss_ticket_number = sr_ticket_number and - ss_item_sk = cs_ui.cs_item_sk and - c_current_cdemo_sk = cd2.cd_demo_sk AND - c_current_hdemo_sk = hd2.hd_demo_sk AND - c_current_addr_sk = ad2.ca_address_sk and - c_first_sales_date_sk = d2.d_date_sk and - c_first_shipto_date_sk = d3.d_date_sk and - ss_promo_sk = p_promo_sk and - hd1.hd_income_band_sk = ib1.ib_income_band_sk and - hd2.hd_income_band_sk = ib2.ib_income_band_sk and - cd1.cd_marital_status <> cd2.cd_marital_status and - i_color in ('sienna','royal','chiffon','cream','chocolate','maroon') and - i_current_price between 52 and 52 + 10 and - i_current_price between 52 + 1 and 52 + 15 -group by i_product_name - ,i_item_sk - ,s_store_name - ,s_zip - ,ad1.ca_street_number - ,ad1.ca_street_name - ,ad1.ca_city - ,ad1.ca_zip - ,ad2.ca_street_number - ,ad2.ca_street_name - ,ad2.ca_city - ,ad2.ca_zip - ,d1.d_year - ,d2.d_year - ,d3.d_year -) -select cs1.product_name - ,cs1.store_name - ,cs1.store_zip - ,cs1.b_street_number - ,cs1.b_street_name - ,cs1.b_city - ,cs1.b_zip - ,cs1.c_street_number - ,cs1.c_street_name - ,cs1.c_city - ,cs1.c_zip - ,cs1.syear - ,cs1.cnt - ,cs1.s1 as s11 - ,cs1.s2 as s21 - ,cs1.s3 as s31 - ,cs2.s1 as s12 - ,cs2.s2 as s22 - ,cs2.s3 as s32 - ,cs2.syear - ,cs2.cnt -from cross_sales cs1,cross_sales cs2 -where cs1.item_sk=cs2.item_sk and - cs1.syear = 2000 and - cs2.syear = 2000 + 1 and - cs2.cnt <= cs1.cnt and - cs1.store_name = cs2.store_name and - cs1.store_zip = cs2.store_zip -order by cs1.product_name - ,cs1.store_name - ,cs2.cnt - ,cs1.s1 - ,cs2.s1; - --- end template query64.tpl query 26 in stream 8 --- start template query7.tpl query 27 in stream 8 -select /* TPC-DS query7.tpl 0.2 */ i_item_id, - avg(ss_quantity) agg1, - avg(ss_list_price) agg2, - avg(ss_coupon_amt) agg3, - avg(ss_sales_price) agg4 - from store_sales, customer_demographics, date_dim, item, promotion - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_cdemo_sk = cd_demo_sk and - ss_promo_sk = p_promo_sk and - cd_gender = 'F' and - cd_marital_status = 'W' and - cd_education_status = '2 yr Degree' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 2000 - group by i_item_id - order by i_item_id - limit 100; - --- end template query7.tpl query 27 in stream 8 --- start template query36a.tpl query 28 in stream 8 -with /* TPC-DS query36a.tpl 0.21 */ results as - (select - sum(ss_net_profit) as ss_net_profit, sum(ss_ext_sales_price) as ss_ext_sales_price, - sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin - ,i_category - ,i_class - ,0 as g_category, 0 as g_class - from - store_sales - ,date_dim d1 - ,item - ,store - where - d1.d_year = 1998 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and s_state in ('NY','PA','OH','WV', - 'SC','LA','WA','CO') - group by i_category,i_class) - , - results_rollup as - (select gross_margin ,i_category ,i_class,0 as t_category, 0 as t_class, 0 as lochierarchy from results - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - i_category, NULL AS i_class, 0 as t_category, 1 as t_class, 1 as lochierarchy from results group by i_category - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - NULL AS i_category ,NULL AS i_class, 1 as t_category, 1 as t_class, 2 as lochierarchy from results) - select - gross_margin ,i_category ,i_class, lochierarchy,rank() over ( - partition by lochierarchy, case when t_class = 0 then i_category end - order by gross_margin asc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then i_category end - ,rank_within_parent - limit 100; - --- end template query36a.tpl query 28 in stream 8 --- start template query61.tpl query 29 in stream 8 -select /* TPC-DS query61.tpl 0.97 */ promotions,total,cast(promotions as decimal(15,4))/cast(total as decimal(15,4))*100 -from - (select sum(ss_ext_sales_price) promotions - from store_sales - ,store - ,promotion - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_promo_sk = p_promo_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -7 - and i_category = 'Home' - and (p_channel_dmail = 'Y' or p_channel_email = 'Y' or p_channel_tv = 'Y') - and s_gmt_offset = -7 - and d_year = 1999 - and d_moy = 11) promotional_sales, - (select sum(ss_ext_sales_price) total - from store_sales - ,store - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -7 - and i_category = 'Home' - and s_gmt_offset = -7 - and d_year = 1999 - and d_moy = 11) all_sales -order by promotions, total -limit 100; - --- end template query61.tpl query 29 in stream 8 --- start template query41.tpl query 30 in stream 8 -select /* TPC-DS query41.tpl 0.62 */ distinct(i_product_name) - from item i1 - where i_manufact_id between 767 and 767+40 - and (select count(*) as item_cnt - from item - where (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'puff' or i_color = 'burnished') and - (i_units = 'Each' or i_units = 'Cup') and - (i_size = 'small' or i_size = 'large') - ) or - (i_category = 'Women' and - (i_color = 'cyan' or i_color = 'bisque') and - (i_units = 'Bundle' or i_units = 'Bunch') and - (i_size = 'extra large' or i_size = 'medium') - ) or - (i_category = 'Men' and - (i_color = 'white' or i_color = 'yellow') and - (i_units = 'Unknown' or i_units = 'Oz') and - (i_size = 'N/A' or i_size = 'economy') - ) or - (i_category = 'Men' and - (i_color = 'beige' or i_color = 'dodger') and - (i_units = 'Box' or i_units = 'Case') and - (i_size = 'small' or i_size = 'large') - ))) or - (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'deep' or i_color = 'olive') and - (i_units = 'Dram' or i_units = 'N/A') and - (i_size = 'small' or i_size = 'large') - ) or - (i_category = 'Women' and - (i_color = 'honeydew' or i_color = 'midnight') and - (i_units = 'Pallet' or i_units = 'Ounce') and - (i_size = 'extra large' or i_size = 'medium') - ) or - (i_category = 'Men' and - (i_color = 'maroon' or i_color = 'papaya') and - (i_units = 'Ton' or i_units = 'Gross') and - (i_size = 'N/A' or i_size = 'economy') - ) or - (i_category = 'Men' and - (i_color = 'orange' or i_color = 'moccasin') and - (i_units = 'Lb' or i_units = 'Pound') and - (i_size = 'small' or i_size = 'large') - )))) > 0 - order by i_product_name - limit 100; - --- end template query41.tpl query 30 in stream 8 --- start template query35a.tpl query 31 in stream 8 -select /* TPC-DS query35a.tpl 0.47 */ - ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - count(*) cnt1, - min(cd_dep_count), - max(cd_dep_count), - sum(cd_dep_count), - cd_dep_employed_count, - count(*) cnt2, - min(cd_dep_employed_count), - max(cd_dep_employed_count), - sum(cd_dep_employed_count), - cd_dep_college_count, - count(*) cnt3, - min(cd_dep_college_count), - max(cd_dep_college_count), - sum(cd_dep_college_count) - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 1999 and - d_qoy < 4) and - exists (select * from - (select ws_bill_customer_sk customsk - from web_sales,date_dim - where - ws_sold_date_sk = d_date_sk and - d_year = 1999 and - d_qoy < 4 - union all - select cs_ship_customer_sk customsk - from catalog_sales,date_dim - where - cs_sold_date_sk = d_date_sk and - d_year = 1999 and - d_qoy < 4)x - where x.customsk = c.c_customer_sk) - group by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - limit 100; - --- end template query35a.tpl query 31 in stream 8 --- start template query50.tpl query 32 in stream 8 -select /* TPC-DS query50.tpl 0.60 */ - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 30) and - (sr_returned_date_sk - ss_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 60) and - (sr_returned_date_sk - ss_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 90) and - (sr_returned_date_sk - ss_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - store_sales - ,store_returns - ,store - ,date_dim d1 - ,date_dim d2 -where - d2.d_year = 2000 -and d2.d_moy = 10 -and ss_ticket_number = sr_ticket_number -and ss_item_sk = sr_item_sk -and ss_sold_date_sk = d1.d_date_sk -and sr_returned_date_sk = d2.d_date_sk -and ss_customer_sk = sr_customer_sk -and ss_store_sk = s_store_sk -group by - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -order by s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -limit 100; - --- end template query50.tpl query 32 in stream 8 --- start template query65.tpl query 33 in stream 8 -select /* TPC-DS query65.tpl 0.71 */ - s_store_name, - i_item_desc, - sc.revenue, - i_current_price, - i_wholesale_cost, - i_brand - from store, item, - (select ss_store_sk, avg(revenue) as ave - from - (select ss_store_sk, ss_item_sk, - sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1203 and 1203+11 - group by ss_store_sk, ss_item_sk) sa - group by ss_store_sk) sb, - (select ss_store_sk, ss_item_sk, sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1203 and 1203+11 - group by ss_store_sk, ss_item_sk) sc - where sb.ss_store_sk = sc.ss_store_sk and - sc.revenue <= 0.1 * sb.ave and - s_store_sk = sc.ss_store_sk and - i_item_sk = sc.ss_item_sk - order by s_store_name, i_item_desc -limit 100; - --- end template query65.tpl query 33 in stream 8 --- start template query51.tpl query 34 in stream 8 -WITH /* TPC-DS query51.tpl 0.46 */ web_v1 as ( -select - ws_item_sk item_sk, d_date, - sum(sum(ws_sales_price)) - over (partition by ws_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from web_sales - ,date_dim -where ws_sold_date_sk=d_date_sk - and d_month_seq between 1206 and 1206+11 - and ws_item_sk is not NULL -group by ws_item_sk, d_date), -store_v1 as ( -select - ss_item_sk item_sk, d_date, - sum(sum(ss_sales_price)) - over (partition by ss_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from store_sales - ,date_dim -where ss_sold_date_sk=d_date_sk - and d_month_seq between 1206 and 1206+11 - and ss_item_sk is not NULL -group by ss_item_sk, d_date) - select * -from (select item_sk - ,d_date - ,web_sales - ,store_sales - ,max(web_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) web_cumulative - ,max(store_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) store_cumulative - from (select case when web.item_sk is not null then web.item_sk else store.item_sk end item_sk - ,case when web.d_date is not null then web.d_date else store.d_date end d_date - ,web.cume_sales web_sales - ,store.cume_sales store_sales - from web_v1 web full outer join store_v1 store on (web.item_sk = store.item_sk - and web.d_date = store.d_date) - )x )y -where web_cumulative > store_cumulative -order by item_sk - ,d_date -limit 100; - --- end template query51.tpl query 34 in stream 8 --- start template query78.tpl query 35 in stream 8 -with /* TPC-DS query78.tpl 0.10 */ ws as - (select d_year AS ws_sold_year, ws_item_sk, - ws_bill_customer_sk ws_customer_sk, - sum(ws_quantity) ws_qty, - sum(ws_wholesale_cost) ws_wc, - sum(ws_sales_price) ws_sp - from web_sales - left join web_returns on wr_order_number=ws_order_number and ws_item_sk=wr_item_sk - join date_dim on ws_sold_date_sk = d_date_sk - where wr_order_number is null - group by d_year, ws_item_sk, ws_bill_customer_sk - ), -cs as - (select d_year AS cs_sold_year, cs_item_sk, - cs_bill_customer_sk cs_customer_sk, - sum(cs_quantity) cs_qty, - sum(cs_wholesale_cost) cs_wc, - sum(cs_sales_price) cs_sp - from catalog_sales - left join catalog_returns on cr_order_number=cs_order_number and cs_item_sk=cr_item_sk - join date_dim on cs_sold_date_sk = d_date_sk - where cr_order_number is null - group by d_year, cs_item_sk, cs_bill_customer_sk - ), -ss as - (select d_year AS ss_sold_year, ss_item_sk, - ss_customer_sk, - sum(ss_quantity) ss_qty, - sum(ss_wholesale_cost) ss_wc, - sum(ss_sales_price) ss_sp - from store_sales - left join store_returns on sr_ticket_number=ss_ticket_number and ss_item_sk=sr_item_sk - join date_dim on ss_sold_date_sk = d_date_sk - where sr_ticket_number is null - group by d_year, ss_item_sk, ss_customer_sk - ) - select -ss_sold_year, ss_item_sk, ss_customer_sk, -round(ss_qty/(coalesce(ws_qty,0)+coalesce(cs_qty,0)),2) ratio, -ss_qty store_qty, ss_wc store_wholesale_cost, ss_sp store_sales_price, -coalesce(ws_qty,0)+coalesce(cs_qty,0) other_chan_qty, -coalesce(ws_wc,0)+coalesce(cs_wc,0) other_chan_wholesale_cost, -coalesce(ws_sp,0)+coalesce(cs_sp,0) other_chan_sales_price -from ss -left join ws on (ws_sold_year=ss_sold_year and ws_item_sk=ss_item_sk and ws_customer_sk=ss_customer_sk) -left join cs on (cs_sold_year=ss_sold_year and cs_item_sk=ss_item_sk and cs_customer_sk=ss_customer_sk) -where (coalesce(ws_qty,0)>0 or coalesce(cs_qty, 0)>0) and ss_sold_year=1999 -order by - ss_sold_year, ss_item_sk, ss_customer_sk, - ss_qty desc, ss_wc desc, ss_sp desc, - other_chan_qty, - other_chan_wholesale_cost, - other_chan_sales_price, - ratio -limit 100; - --- end template query78.tpl query 35 in stream 8 --- start template query21.tpl query 36 in stream 8 -select /* TPC-DS query21.tpl 0.14 */ * - from(select w_warehouse_name - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('2001-05-15' as date)) - then inv_quantity_on_hand - else 0 end) as inv_before - ,sum(case when (cast(d_date as date) >= cast ('2001-05-15' as date)) - then inv_quantity_on_hand - else 0 end) as inv_after - from inventory - ,warehouse - ,item - ,date_dim - where i_current_price between 0.99 and 1.49 - and i_item_sk = inv_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('2001-05-15' as date)) - and dateadd(day,30,cast ('2001-05-15' as date)) - group by w_warehouse_name, i_item_id) x - where (case when inv_before > 0 - then inv_after / inv_before - else null - end) between 2.0/3.0 and 3.0/2.0 - order by w_warehouse_name - ,i_item_id - limit 100; - --- end template query21.tpl query 36 in stream 8 --- start template query67a.tpl query 37 in stream 8 -with /* TPC-DS query67a.tpl 0.35 */ results as -( select i_category ,i_class ,i_brand ,i_product_name ,d_year ,d_qoy ,d_moy ,s_store_id - ,sum(coalesce(ss_sales_price*ss_quantity,0)) sumsales - from store_sales ,date_dim ,store ,item - where ss_sold_date_sk=d_date_sk - and ss_item_sk=i_item_sk - and ss_store_sk = s_store_sk - and d_month_seq between 1183 and 1183 + 11 - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy,s_store_id) - , - results_rollup as - (select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, s_store_id, sumsales - from results - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy - union all - select i_category, i_class, i_brand, i_product_name, d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year - union all - select i_category, i_class, i_brand, i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name - union all - select i_category, i_class, i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand - union all - select i_category, i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class - union all - select i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category - union all - select null i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results) - - select * -from (select i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rank() over (partition by i_category order by sumsales desc) rk - from results_rollup) dw2 -where rk <= 100 -order by i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rk -limit 100; - --- end template query67a.tpl query 37 in stream 8 --- start template query22a.tpl query 38 in stream 8 -with /* TPC-DS query22a.tpl 0.55 */ results as -(select i_product_name - ,i_brand - ,i_class - ,i_category - ,avg(inv_quantity_on_hand) qoh - from inventory - ,date_dim - ,item --- ,warehouse - where inv_date_sk=d_date_sk - and inv_item_sk=i_item_sk --- and inv_warehouse_sk = w_warehouse_sk - and d_month_seq between 1197 and 1197 + 11 - group by i_product_name,i_brand,i_class,i_category), -results_rollup as -(select i_product_name, i_brand, i_class, i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class,i_category -union all -select i_product_name, i_brand, i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class -union all -select i_product_name, i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand -union all -select i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name -union all -select null i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results) - select i_product_name, i_brand, i_class, i_category,qoh - from results_rollup - order by qoh, i_product_name, i_brand, i_class, i_category -limit 100; - --- end template query22a.tpl query 38 in stream 8 --- start template query81.tpl query 39 in stream 8 -with /* TPC-DS query81.tpl 0.37 */ customer_total_return as - (select cr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(cr_return_amt_inc_tax) as ctr_total_return - from catalog_returns - ,date_dim - ,customer_address - where cr_returned_date_sk = d_date_sk - and d_year =2002 - and cr_returning_addr_sk = ca_address_sk - group by cr_returning_customer_sk - ,ca_state ) - select c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'AL' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - limit 100; - --- end template query81.tpl query 39 in stream 8 --- start template query93.tpl query 40 in stream 8 -select /* TPC-DS query93.tpl 0.52 */ ss_customer_sk - ,sum(act_sales) sumsales - from (select ss_item_sk - ,ss_ticket_number - ,ss_customer_sk - ,case when sr_return_quantity is not null then (ss_quantity-sr_return_quantity)*ss_sales_price - else (ss_quantity*ss_sales_price) end act_sales - from store_sales left outer join store_returns on (sr_item_sk = ss_item_sk - and sr_ticket_number = ss_ticket_number) - ,reason - where sr_reason_sk = r_reason_sk - and r_reason_desc = 'reason 50') t - group by ss_customer_sk - order by sumsales, ss_customer_sk -limit 100; - --- end template query93.tpl query 40 in stream 8 --- start template query25.tpl query 41 in stream 8 -select /* TPC-DS query25.tpl 0.9 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,min(ss_net_profit) as store_sales_profit - ,min(sr_net_loss) as store_returns_loss - ,min(cs_net_profit) as catalog_sales_profit - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 1999 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 10 - and d2.d_year = 1999 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_moy between 4 and 10 - and d3.d_year = 1999 - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query25.tpl query 41 in stream 8 --- start template query26.tpl query 42 in stream 8 -select /* TPC-DS query26.tpl 0.85 */ i_item_id, - avg(cs_quantity) agg1, - avg(cs_list_price) agg2, - avg(cs_coupon_amt) agg3, - avg(cs_sales_price) agg4 - from catalog_sales, customer_demographics, date_dim, item, promotion - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd_demo_sk and - cs_promo_sk = p_promo_sk and - cd_gender = 'F' and - cd_marital_status = 'D' and - cd_education_status = 'Secondary' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 2002 - group by i_item_id - order by i_item_id - limit 100; - --- end template query26.tpl query 42 in stream 8 --- start template query90.tpl query 43 in stream 8 -select /* TPC-DS query90.tpl 0.40 */ cast(amc as decimal(15,4))/cast(pmc as decimal(15,4)) am_pm_ratio - from ( select count(*) amc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 11 and 11+1 - and household_demographics.hd_dep_count = 9 - and web_page.wp_char_count between 5000 and 5200) at, - ( select count(*) pmc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 20 and 20+1 - and household_demographics.hd_dep_count = 9 - and web_page.wp_char_count between 5000 and 5200) pt - order by am_pm_ratio - limit 100; - --- end template query90.tpl query 43 in stream 8 --- start template query74.tpl query 44 in stream 8 -with /* TPC-DS query74.tpl 0.76 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,min(ss_net_paid) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1998,1998+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,min(ws_net_paid) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - and d_year in (1998,1998+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - ) - select - t_s_secyear.customer_id, t_s_secyear.customer_first_name, t_s_secyear.customer_last_name - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.year = 1998 - and t_s_secyear.year = 1998+1 - and t_w_firstyear.year = 1998 - and t_w_secyear.year = 1998+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - order by 2,3,1 -limit 100; - --- end template query74.tpl query 44 in stream 8 --- start template query92.tpl query 45 in stream 8 -select /* TPC-DS query92.tpl 0.44 */ - sum(ws_ext_discount_amt) as "Excess Discount Amount" -from - web_sales - ,item - ,date_dim -where -i_manufact_id = 393 -and i_item_sk = ws_item_sk -and d_date between '2002-02-03' and - dateadd(day,90,cast('2002-02-03' as date)) -and d_date_sk = ws_sold_date_sk -and ws_ext_discount_amt - > ( - SELECT - 1.3 * avg(ws_ext_discount_amt) - FROM - web_sales - ,date_dim - WHERE - ws_item_sk = i_item_sk - and d_date between '2002-02-03' and - dateadd(day,90,cast('2002-02-03' as date)) - and d_date_sk = ws_sold_date_sk - ) -order by sum(ws_ext_discount_amt) -limit 100; - --- end template query92.tpl query 45 in stream 8 --- start template query75.tpl query 46 in stream 8 -WITH /* TPC-DS query75.tpl 0.3 */ all_sales AS ( - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,SUM(sales_cnt) AS sales_cnt - ,SUM(sales_amt) AS sales_amt - FROM (SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,cs_quantity - COALESCE(cr_return_quantity,0) AS sales_cnt - ,cs_ext_sales_price - COALESCE(cr_return_amount,0.0) AS sales_amt - FROM catalog_sales JOIN item ON i_item_sk=cs_item_sk - JOIN date_dim ON d_date_sk=cs_sold_date_sk - LEFT JOIN catalog_returns ON (cs_order_number=cr_order_number - AND cs_item_sk=cr_item_sk) - WHERE i_category='Jewelry' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ss_quantity - COALESCE(sr_return_quantity,0) AS sales_cnt - ,ss_ext_sales_price - COALESCE(sr_return_amt,0.0) AS sales_amt - FROM store_sales JOIN item ON i_item_sk=ss_item_sk - JOIN date_dim ON d_date_sk=ss_sold_date_sk - LEFT JOIN store_returns ON (ss_ticket_number=sr_ticket_number - AND ss_item_sk=sr_item_sk) - WHERE i_category='Jewelry' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ws_quantity - COALESCE(wr_return_quantity,0) AS sales_cnt - ,ws_ext_sales_price - COALESCE(wr_return_amt,0.0) AS sales_amt - FROM web_sales JOIN item ON i_item_sk=ws_item_sk - JOIN date_dim ON d_date_sk=ws_sold_date_sk - LEFT JOIN web_returns ON (ws_order_number=wr_order_number - AND ws_item_sk=wr_item_sk) - WHERE i_category='Jewelry') sales_detail - GROUP BY d_year, i_brand_id, i_class_id, i_category_id, i_manufact_id) - SELECT prev_yr.d_year AS prev_year - ,curr_yr.d_year AS year - ,curr_yr.i_brand_id - ,curr_yr.i_class_id - ,curr_yr.i_category_id - ,curr_yr.i_manufact_id - ,prev_yr.sales_cnt AS prev_yr_cnt - ,curr_yr.sales_cnt AS curr_yr_cnt - ,curr_yr.sales_cnt-prev_yr.sales_cnt AS sales_cnt_diff - ,curr_yr.sales_amt-prev_yr.sales_amt AS sales_amt_diff - FROM all_sales curr_yr, all_sales prev_yr - WHERE curr_yr.i_brand_id=prev_yr.i_brand_id - AND curr_yr.i_class_id=prev_yr.i_class_id - AND curr_yr.i_category_id=prev_yr.i_category_id - AND curr_yr.i_manufact_id=prev_yr.i_manufact_id - AND curr_yr.d_year=1999 - AND prev_yr.d_year=1999-1 - AND CAST(curr_yr.sales_cnt AS DECIMAL(17,2))/CAST(prev_yr.sales_cnt AS DECIMAL(17,2))<0.9 - ORDER BY sales_cnt_diff,sales_amt_diff - limit 100; - --- end template query75.tpl query 46 in stream 8 --- start template query10.tpl query 47 in stream 8 -select /* TPC-DS query10.tpl 0.26 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3, - cd_dep_count, - count(*) cnt4, - cd_dep_employed_count, - count(*) cnt5, - cd_dep_college_count, - count(*) cnt6 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_county in ('Ottawa County','Wayne County','Dearborn County','Fall River County','Edwards County') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 4 and 4+3) and - (exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 4 ANd 4+3) or - exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 4 and 4+3)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count -limit 100; - --- end template query10.tpl query 47 in stream 8 --- start template query58.tpl query 48 in stream 8 -with /* TPC-DS query58.tpl 0.19 */ ss_items as - (select i_item_id item_id - ,sum(ss_ext_sales_price) ss_item_rev - from store_sales - ,item - ,date_dim - where ss_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '1998-04-26')) - and ss_sold_date_sk = d_date_sk - group by i_item_id), - cs_items as - (select i_item_id item_id - ,sum(cs_ext_sales_price) cs_item_rev - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '1998-04-26')) - and cs_sold_date_sk = d_date_sk - group by i_item_id), - ws_items as - (select i_item_id item_id - ,sum(ws_ext_sales_price) ws_item_rev - from web_sales - ,item - ,date_dim - where ws_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq =(select d_week_seq - from date_dim - where d_date = '1998-04-26')) - and ws_sold_date_sk = d_date_sk - group by i_item_id) - select ss_items.item_id - ,ss_item_rev - ,ss_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ss_dev - ,cs_item_rev - ,cs_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 cs_dev - ,ws_item_rev - ,ws_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ws_dev - ,(ss_item_rev+cs_item_rev+ws_item_rev)/3 average - from ss_items,cs_items,ws_items - where ss_items.item_id=cs_items.item_id - and ss_items.item_id=ws_items.item_id - and ss_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - and ss_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and cs_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and cs_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and ws_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and ws_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - order by item_id - ,ss_item_rev - limit 100; - --- end template query58.tpl query 48 in stream 8 --- start template query6.tpl query 49 in stream 8 -select /* TPC-DS query6.tpl 0.58 */ a.ca_state state, count(*) cnt - from customer_address a - ,customer c - ,store_sales s - ,date_dim d - ,item i - where a.ca_address_sk = c.c_current_addr_sk - and c.c_customer_sk = s.ss_customer_sk - and s.ss_sold_date_sk = d.d_date_sk - and s.ss_item_sk = i.i_item_sk - and d.d_month_seq = - (select distinct (d_month_seq) - from date_dim - where d_year = 2001 - and d_moy = 6 ) - and i.i_current_price > 1.2 * - (select avg(j.i_current_price) - from item j - where j.i_category = i.i_category) - group by a.ca_state - having count(*) >= 10 - order by cnt, a.ca_state - limit 100; - --- end template query6.tpl query 49 in stream 8 --- start template query47.tpl query 50 in stream 8 -with /* TPC-DS query47.tpl 0.42 */ v1 as( - select i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, - s_store_name, s_company_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - s_store_name, s_company_name - order by d_year, d_moy) rn - from item, store_sales, date_dim, store - where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - ( - d_year = 1999 or - ( d_year = 1999-1 and d_moy =12) or - ( d_year = 1999+1 and d_moy =1) - ) - group by i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy), - v2 as( - select v1.s_company_name - ,v1.d_year, v1.d_moy - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1.s_store_name = v1_lag.s_store_name and - v1.s_store_name = v1_lead.s_store_name and - v1.s_company_name = v1_lag.s_company_name and - v1.s_company_name = v1_lead.s_company_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 1999 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, sum_sales - limit 100; - --- end template query47.tpl query 50 in stream 8 --- start template query30.tpl query 51 in stream 8 -with /* TPC-DS query30.tpl 0.75 */ customer_total_return as - (select wr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(wr_return_amt) as ctr_total_return - from web_returns - ,date_dim - ,customer_address - where wr_returned_date_sk = d_date_sk - and d_year =2001 - and wr_returning_addr_sk = ca_address_sk - group by wr_returning_customer_sk - ,ca_state) - select c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'CA' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return -limit 100; - --- end template query30.tpl query 51 in stream 8 --- start template query94.tpl query 52 in stream 8 -select /* TPC-DS query94.tpl 0.17 */ - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2001-4-01' and - dateadd(day,60,cast('2001-4-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'CO' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and exists (select * - from web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) -and not exists(select * - from web_returns wr1 - where ws1.ws_order_number = wr1.wr_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query94.tpl query 52 in stream 8 --- start template query97.tpl query 53 in stream 8 -with /* TPC-DS query97.tpl 0.38 */ ssci as ( -select ss_customer_sk customer_sk - ,ss_item_sk item_sk -from store_sales,date_dim -where ss_sold_date_sk = d_date_sk - and d_month_seq between 1201 and 1201 + 11 -group by ss_customer_sk - ,ss_item_sk), -csci as( - select cs_bill_customer_sk customer_sk - ,cs_item_sk item_sk -from catalog_sales,date_dim -where cs_sold_date_sk = d_date_sk - and d_month_seq between 1201 and 1201 + 11 -group by cs_bill_customer_sk - ,cs_item_sk) - select sum(case when ssci.customer_sk is not null and csci.customer_sk is null then 1 else 0 end) store_only - ,sum(case when ssci.customer_sk is null and csci.customer_sk is not null then 1 else 0 end) catalog_only - ,sum(case when ssci.customer_sk is not null and csci.customer_sk is not null then 1 else 0 end) store_and_catalog -from ssci full outer join csci on (ssci.customer_sk=csci.customer_sk - and ssci.item_sk = csci.item_sk) -limit 100; - --- end template query97.tpl query 53 in stream 8 --- start template query55.tpl query 54 in stream 8 -select /* TPC-DS query55.tpl 0.82 */ i_brand_id brand_id, i_brand brand, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=61 - and d_moy=11 - and d_year=2001 - group by i_brand, i_brand_id - order by ext_price desc, i_brand_id -limit 100 ; - --- end template query55.tpl query 54 in stream 8 --- start template query72.tpl query 55 in stream 8 -select /* TPC-DS query72.tpl 0.87 */ i_item_desc - ,w_warehouse_name - ,d1.d_week_seq - ,sum(case when p_promo_sk is null then 1 else 0 end) no_promo - ,sum(case when p_promo_sk is not null then 1 else 0 end) promo - ,count(*) total_cnt -from catalog_sales -join inventory on (cs_item_sk = inv_item_sk) -join warehouse on (w_warehouse_sk=inv_warehouse_sk) -join item on (i_item_sk = cs_item_sk) -join customer_demographics on (cs_bill_cdemo_sk = cd_demo_sk) -join household_demographics on (cs_bill_hdemo_sk = hd_demo_sk) -join date_dim d1 on (cs_sold_date_sk = d1.d_date_sk) -join date_dim d2 on (inv_date_sk = d2.d_date_sk) -join date_dim d3 on (cs_ship_date_sk = d3.d_date_sk) -left outer join promotion on (cs_promo_sk=p_promo_sk) -left outer join catalog_returns on (cr_item_sk = cs_item_sk and cr_order_number = cs_order_number) -where d1.d_week_seq = d2.d_week_seq - and inv_quantity_on_hand < cs_quantity - and d3.d_date > d1.d_date + 5 - and hd_buy_potential = '>10000' - and d1.d_year = 1999 - and cd_marital_status = 'U' -group by i_item_desc,w_warehouse_name,d1.d_week_seq -order by total_cnt desc, i_item_desc, w_warehouse_name, d_week_seq -limit 100; - --- end template query72.tpl query 55 in stream 8 --- start template query95.tpl query 56 in stream 8 -with /* TPC-DS query95.tpl 0.43 */ ws_wh as -(select ws1.ws_order_number,ws1.ws_warehouse_sk wh1,ws2.ws_warehouse_sk wh2 - from web_sales ws1,web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) - select - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '1999-2-01' and - dateadd(day,60,cast('1999-2-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'VA' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and ws1.ws_order_number in (select ws_order_number - from ws_wh) -and ws1.ws_order_number in (select wr_order_number - from web_returns,ws_wh - where wr_order_number = ws_wh.ws_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query95.tpl query 56 in stream 8 --- start template query86a.tpl query 57 in stream 8 -with /* TPC-DS query86a.tpl 0.11 */ results as -( select sum(ws_net_paid) as total_sum, i_category, i_class, 0 as g_category, 0 as g_class - from - web_sales - ,date_dim d1 - ,item - where - d1.d_month_seq between 1222 and 1222+11 - and d1.d_date_sk = ws_sold_date_sk - and i_item_sk = ws_item_sk - group by i_category,i_class - ) , - - results_rollup as -( select total_sum ,i_category ,i_class, g_category, g_class, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum, i_category, NULL as i_class, 0 as g_category, 1 as g_class, 1 as lochierarchy from results group by i_category - union - select sum(total_sum) as total_sum, NULL as i_category, NULL as i_class, 1 as g_category, 1 as g_class, 2 as lochierarchy from results) - select - total_sum ,i_category ,i_class, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_class = 0 then i_category end - order by total_sum desc) as rank_within_parent - from - results_rollup - order by - lochierarchy desc, - case when lochierarchy = 0 then i_category end, - rank_within_parent - limit 100; - --- end template query86a.tpl query 57 in stream 8 --- start template query39.tpl query 58 in stream 8 -with /* TPC-DS query39.tpl 0.5 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =1999 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=3 - and inv2.d_moy=3+1 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; -with /* TPC-DS query39.tpl 0.5 part2 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =1999 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=3 - and inv2.d_moy=3+1 - and inv1.cov > 1.5 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; - --- end template query39.tpl query 58 in stream 8 --- start template query17.tpl query 59 in stream 8 -select /* TPC-DS query17.tpl 0.41 */ i_item_id - ,i_item_desc - ,s_state - ,count(ss_quantity) as store_sales_quantitycount - ,avg(ss_quantity) as store_sales_quantityave - ,stddev_samp(ss_quantity) as store_sales_quantitystdev - ,stddev_samp(ss_quantity)/avg(ss_quantity) as store_sales_quantitycov - ,count(sr_return_quantity) as store_returns_quantitycount - ,avg(sr_return_quantity) as store_returns_quantityave - ,stddev_samp(sr_return_quantity) as store_returns_quantitystdev - ,stddev_samp(sr_return_quantity)/avg(sr_return_quantity) as store_returns_quantitycov - ,count(cs_quantity) as catalog_sales_quantitycount ,avg(cs_quantity) as catalog_sales_quantityave - ,stddev_samp(cs_quantity) as catalog_sales_quantitystdev - ,stddev_samp(cs_quantity)/avg(cs_quantity) as catalog_sales_quantitycov - from store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where d1.d_quarter_name = '1999Q1' - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_quarter_name in ('1999Q1','1999Q2','1999Q3') - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_quarter_name in ('1999Q1','1999Q2','1999Q3') - group by i_item_id - ,i_item_desc - ,s_state - order by i_item_id - ,i_item_desc - ,s_state -limit 100; - --- end template query17.tpl query 59 in stream 8 --- start template query42.tpl query 60 in stream 8 -select /* TPC-DS query42.tpl 0.61 */ dt.d_year - ,item.i_category_id - ,item.i_category - ,sum(ss_ext_sales_price) - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=12 - and dt.d_year=2000 - group by dt.d_year - ,item.i_category_id - ,item.i_category - order by sum(ss_ext_sales_price) desc,dt.d_year - ,item.i_category_id - ,item.i_category -limit 100 ; - --- end template query42.tpl query 60 in stream 8 --- start template query85.tpl query 61 in stream 8 -select /* TPC-DS query85.tpl 0.33 */ substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) - from web_sales, web_returns, web_page, customer_demographics cd1, - customer_demographics cd2, customer_address, date_dim, reason - where ws_web_page_sk = wp_web_page_sk - and ws_item_sk = wr_item_sk - and ws_order_number = wr_order_number - and ws_sold_date_sk = d_date_sk and d_year = 1998 - and cd1.cd_demo_sk = wr_refunded_cdemo_sk - and cd2.cd_demo_sk = wr_returning_cdemo_sk - and ca_address_sk = wr_refunded_addr_sk - and r_reason_sk = wr_reason_sk - and - ( - ( - cd1.cd_marital_status = 'U' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Primary' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 100.00 and 150.00 - ) - or - ( - cd1.cd_marital_status = 'M' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = '4 yr Degree' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 50.00 and 100.00 - ) - or - ( - cd1.cd_marital_status = 'W' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Secondary' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ca_country = 'United States' - and - ca_state in ('AR', 'NY', 'CT') - and ws_net_profit between 100 and 200 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('SD', 'VA', 'MS') - and ws_net_profit between 150 and 300 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('IL', 'WV', 'AL') - and ws_net_profit between 50 and 250 - ) - ) -group by r_reason_desc -order by substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) -limit 100; - --- end template query85.tpl query 61 in stream 8 --- start template query9.tpl query 62 in stream 8 -select /* TPC-DS query9.tpl 0.49 */ case when (select count(*) - from store_sales - where ss_quantity between 1 and 20) > 15256314 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 1 and 20) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 1 and 20) end bucket1 , - case when (select count(*) - from store_sales - where ss_quantity between 21 and 40) > 96142604 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 21 and 40) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 21 and 40) end bucket2, - case when (select count(*) - from store_sales - where ss_quantity between 41 and 60) > 64752420 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 41 and 60) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 41 and 60) end bucket3, - case when (select count(*) - from store_sales - where ss_quantity between 61 and 80) > 97828692 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 61 and 80) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 61 and 80) end bucket4, - case when (select count(*) - from store_sales - where ss_quantity between 81 and 100) > 110058222 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 81 and 100) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 81 and 100) end bucket5 -from reason -where r_reason_sk = 1 -; - --- end template query9.tpl query 62 in stream 8 --- start template query32.tpl query 63 in stream 8 -select /* TPC-DS query32.tpl 0.7 */ sum(cs_ext_discount_amt) as "excess discount amount" -from - catalog_sales - ,item - ,date_dim -where -i_manufact_id = 944 -and i_item_sk = cs_item_sk -and d_date between '2002-03-27' and - dateadd(day,90,cast('2002-03-27' as date)) -and d_date_sk = cs_sold_date_sk -and cs_ext_discount_amt - > ( - select - 1.3 * avg(cs_ext_discount_amt) - from - catalog_sales - ,date_dim - where - cs_item_sk = i_item_sk - and d_date between '2002-03-27' and - dateadd(day,90,cast('2002-03-27' as date)) - and d_date_sk = cs_sold_date_sk - ) -limit 100; - --- end template query32.tpl query 63 in stream 8 --- start template query34.tpl query 64 in stream 8 -select /* TPC-DS query34.tpl 0.73 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (date_dim.d_dom between 1 and 3 or date_dim.d_dom between 25 and 28) - and (household_demographics.hd_buy_potential = '501-1000' or - household_demographics.hd_buy_potential = '0-500') - and household_demographics.hd_vehicle_count > 0 - and (case when household_demographics.hd_vehicle_count > 0 - then household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count - else null - end) > 1.2 - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_county in ('Perry County','Essex County','Williamson County','Arthur County', - 'Contra Costa County','Walker County','Daviess County','Kittitas County') - group by ss_ticket_number,ss_customer_sk) dn,customer - where ss_customer_sk = c_customer_sk - and cnt between 15 and 20 - order by c_last_name,c_first_name,c_salutation,c_preferred_cust_flag desc, ss_ticket_number; - --- end template query34.tpl query 64 in stream 8 --- start template query79.tpl query 65 in stream 8 -select /* TPC-DS query79.tpl 0.89 */ - c_last_name,c_first_name,substring(s_city,1,30),ss_ticket_number,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,store.s_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (household_demographics.hd_dep_count = 2 or household_demographics.hd_vehicle_count > 2) - and date_dim.d_dow = 1 - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_number_employees between 200 and 295 - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,store.s_city) ms,customer - where ss_customer_sk = c_customer_sk - order by c_last_name,c_first_name,substring(s_city,1,30), profit -limit 100; - --- end template query79.tpl query 65 in stream 8 --- start template query54.tpl query 66 in stream 8 -with /* TPC-DS query54.tpl 0.81 */ my_customers as ( - select distinct c_customer_sk - , c_current_addr_sk - from - ( select cs_sold_date_sk sold_date_sk, - cs_bill_customer_sk customer_sk, - cs_item_sk item_sk - from catalog_sales - union all - select ws_sold_date_sk sold_date_sk, - ws_bill_customer_sk customer_sk, - ws_item_sk item_sk - from web_sales - ) cs_or_ws_sales, - item, - date_dim, - customer - where sold_date_sk = d_date_sk - and item_sk = i_item_sk - and i_category = 'Sports' - and i_class = 'sailing' - and c_customer_sk = cs_or_ws_sales.customer_sk - and d_moy = 5 - and d_year = 1999 - ) - , my_revenue as ( - select c_customer_sk, - sum(ss_ext_sales_price) as revenue - from my_customers, - store_sales, - customer_address, - store, - date_dim - where c_current_addr_sk = ca_address_sk - and ca_county = s_county - and ca_state = s_state - and ss_sold_date_sk = d_date_sk - and c_customer_sk = ss_customer_sk - and d_month_seq between (select distinct d_month_seq+1 - from date_dim where d_year = 1999 and d_moy = 5) - and (select distinct d_month_seq+3 - from date_dim where d_year = 1999 and d_moy = 5) - group by c_customer_sk - ) - , segments as - (select cast((revenue/50) as int) as segment - from my_revenue - ) - select segment, count(*) as num_customers, segment*50 as segment_base - from segments - group by segment - order by segment, num_customers - limit 100; - --- end template query54.tpl query 66 in stream 8 --- start template query77a.tpl query 67 in stream 8 -with /* TPC-DS query77a.tpl 0.78 */ ss as - (select s_store_sk, - sum(ss_ext_sales_price) as sales, - sum(ss_net_profit) as profit - from store_sales, - date_dim, - store - where ss_sold_date_sk = d_date_sk - and d_date between cast('1999-08-19' as date) - and dateadd(day,30,cast('1999-08-19' as date)) - and ss_store_sk = s_store_sk - group by s_store_sk) - , - sr as - (select s_store_sk, - sum(sr_return_amt) as returns, - sum(sr_net_loss) as profit_loss - from store_returns, - date_dim, - store - where sr_returned_date_sk = d_date_sk - and d_date between cast('1999-08-19' as date) - and dateadd(day,30,cast('1999-08-19' as date)) - and sr_store_sk = s_store_sk - group by s_store_sk), - cs as - (select cs_call_center_sk, - sum(cs_ext_sales_price) as sales, - sum(cs_net_profit) as profit - from catalog_sales, - date_dim - where cs_sold_date_sk = d_date_sk - and d_date between cast('1999-08-19' as date) - and dateadd(day,30,cast('1999-08-19' as date)) - group by cs_call_center_sk - ), - cr as - (select cr_call_center_sk, - sum(cr_return_amount) as returns, - sum(cr_net_loss) as profit_loss - from catalog_returns, - date_dim - where cr_returned_date_sk = d_date_sk - and d_date between cast('1999-08-19' as date) - and dateadd(day,30,cast('1999-08-19' as date)) - group by cr_call_center_sk), - ws as - ( select wp_web_page_sk, - sum(ws_ext_sales_price) as sales, - sum(ws_net_profit) as profit - from web_sales, - date_dim, - web_page - where ws_sold_date_sk = d_date_sk - and d_date between cast('1999-08-19' as date) - and dateadd(day,30,cast('1999-08-19' as date)) - and ws_web_page_sk = wp_web_page_sk - group by wp_web_page_sk), - wr as - (select wp_web_page_sk, - sum(wr_return_amt) as returns, - sum(wr_net_loss) as profit_loss - from web_returns, - date_dim, - web_page - where wr_returned_date_sk = d_date_sk - and d_date between cast('1999-08-19' as date) - and dateadd(day,30,cast('1999-08-19' as date)) - and wr_web_page_sk = wp_web_page_sk - group by wp_web_page_sk) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , ss.s_store_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ss left join sr - on ss.s_store_sk = sr.s_store_sk - union all - select 'catalog channel' as channel - , cs_call_center_sk as id - , sales - , returns - , (profit - profit_loss) as profit - from cs - , cr - union all - select 'web channel' as channel - , ws.wp_web_page_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ws left join wr - on ws.wp_web_page_sk = wr.wp_web_page_sk - ) x - group by channel, id ) - - select * - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results -) foo -order by channel, id - limit 100; - --- end template query77a.tpl query 67 in stream 8 --- start template query45.tpl query 68 in stream 8 -select /* TPC-DS query45.tpl 0.18 */ ca_zip, ca_city, sum(ws_sales_price) - from web_sales, customer, customer_address, date_dim, item - where ws_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ws_item_sk = i_item_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', '85392', '85460', '80348', '81792') - or - i_item_id in (select i_item_id - from item - where i_item_sk in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29) - ) - ) - and ws_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 2002 - group by ca_zip, ca_city - order by ca_zip, ca_city - limit 100; - --- end template query45.tpl query 68 in stream 8 --- start template query28.tpl query 69 in stream 8 -select /* TPC-DS query28.tpl 0.36 */ * -from (select avg(ss_list_price) B1_LP - ,count(ss_list_price) B1_CNT - ,count(distinct ss_list_price) B1_CNTD - from store_sales - where ss_quantity between 0 and 5 - and (ss_list_price between 31 and 31+10 - or ss_coupon_amt between 13026 and 13026+1000 - or ss_wholesale_cost between 8 and 8+20)) B1, - (select avg(ss_list_price) B2_LP - ,count(ss_list_price) B2_CNT - ,count(distinct ss_list_price) B2_CNTD - from store_sales - where ss_quantity between 6 and 10 - and (ss_list_price between 72 and 72+10 - or ss_coupon_amt between 17504 and 17504+1000 - or ss_wholesale_cost between 67 and 67+20)) B2, - (select avg(ss_list_price) B3_LP - ,count(ss_list_price) B3_CNT - ,count(distinct ss_list_price) B3_CNTD - from store_sales - where ss_quantity between 11 and 15 - and (ss_list_price between 110 and 110+10 - or ss_coupon_amt between 9026 and 9026+1000 - or ss_wholesale_cost between 47 and 47+20)) B3, - (select avg(ss_list_price) B4_LP - ,count(ss_list_price) B4_CNT - ,count(distinct ss_list_price) B4_CNTD - from store_sales - where ss_quantity between 16 and 20 - and (ss_list_price between 68 and 68+10 - or ss_coupon_amt between 3865 and 3865+1000 - or ss_wholesale_cost between 72 and 72+20)) B4, - (select avg(ss_list_price) B5_LP - ,count(ss_list_price) B5_CNT - ,count(distinct ss_list_price) B5_CNTD - from store_sales - where ss_quantity between 21 and 25 - and (ss_list_price between 24 and 24+10 - or ss_coupon_amt between 4926 and 4926+1000 - or ss_wholesale_cost between 35 and 35+20)) B5, - (select avg(ss_list_price) B6_LP - ,count(ss_list_price) B6_CNT - ,count(distinct ss_list_price) B6_CNTD - from store_sales - where ss_quantity between 26 and 30 - and (ss_list_price between 27 and 27+10 - or ss_coupon_amt between 13868 and 13868+1000 - or ss_wholesale_cost between 80 and 80+20)) B6 -limit 100; - --- end template query28.tpl query 69 in stream 8 --- start template query11.tpl query 70 in stream 8 -with /* TPC-DS query11.tpl 0.51 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ss_ext_list_price-ss_ext_discount_amt) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ws_ext_list_price-ws_ext_discount_amt) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_preferred_cust_flag - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 2001 - and t_s_secyear.dyear = 2001+1 - and t_w_firstyear.dyear = 2001 - and t_w_secyear.dyear = 2001+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else 0.0 end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else 0.0 end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_preferred_cust_flag -limit 100; - --- end template query11.tpl query 70 in stream 8 --- start template query89.tpl query 71 in stream 8 -select /* TPC-DS query89.tpl 0.56 */ * -from( -select i_category, i_class, i_brand, - s_store_name, s_company_name, - d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, s_store_name, s_company_name) - avg_monthly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - d_year in (1998) and - ((i_category in ('Shoes','Music','Home') and - i_class in ('athletic','country','blinds/shades') - ) - or (i_category in ('Children','Men','Jewelry') and - i_class in ('newborn','accessories','birdal') - )) -group by i_category, i_class, i_brand, - s_store_name, s_company_name, d_moy) tmp1 -where case when (avg_monthly_sales <> 0) then (abs(sum_sales - avg_monthly_sales) / avg_monthly_sales) else null end > 0.1 -order by sum_sales - avg_monthly_sales, s_store_name -limit 100; - --- end template query89.tpl query 71 in stream 8 --- start template query56.tpl query 72 in stream 8 -with /* TPC-DS query56.tpl 0.83 */ ss as ( - select i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where i_item_id in (select - i_item_id -from item -where i_color in ('violet','dodger','orchid')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 6 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - cs as ( - select i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('violet','dodger','orchid')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 6 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - ws as ( - select i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('violet','dodger','orchid')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 6 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id) - select i_item_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by total_sales, - i_item_id - limit 100; - --- end template query56.tpl query 72 in stream 8 --- start template query46.tpl query 73 in stream 8 -select /* TPC-DS query46.tpl 0.23 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and (household_demographics.hd_dep_count = 9 or - household_demographics.hd_vehicle_count= 0) - and date_dim.d_dow in (6,0) - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_city in ('New Hope','Mount Pleasant','Lebanon','Sulphur Springs','Springfield') - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,ca_city) dn,customer,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - limit 100; - --- end template query46.tpl query 73 in stream 8 --- start template query19.tpl query 74 in stream 8 -select /* TPC-DS query19.tpl 0.8 */ i_brand_id brand_id, i_brand brand, i_manufact_id, i_manufact, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item,customer,customer_address,store - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=47 - and d_moy=11 - and d_year=2000 - and ss_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and substring(ca_zip,1,5) <> substring(s_zip,1,5) - and ss_store_sk = s_store_sk - group by i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact - order by ext_price desc - ,i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact -limit 100 ; - --- end template query19.tpl query 74 in stream 8 --- start template query62.tpl query 75 in stream 8 -select /* TPC-DS query62.tpl 0.24 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 30) and - (ws_ship_date_sk - ws_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 60) and - (ws_ship_date_sk - ws_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 90) and - (ws_ship_date_sk - ws_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - web_sales - ,warehouse - ,ship_mode - ,web_site - ,date_dim -where - d_month_seq between 1224 and 1224 + 11 -and ws_ship_date_sk = d_date_sk -and ws_warehouse_sk = w_warehouse_sk -and ws_ship_mode_sk = sm_ship_mode_sk -and ws_web_site_sk = web_site_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -limit 100; - --- end template query62.tpl query 75 in stream 8 --- start template query8.tpl query 76 in stream 8 -select /* TPC-DS query8.tpl 0.63 */ s_store_name - ,sum(ss_net_profit) - from store_sales - ,date_dim - ,store, - (select ca_zip - from ( - SELECT substring(ca_zip,1,5) ca_zip - FROM customer_address - WHERE substring(ca_zip,1,5) IN ( - '13716','26981','47813','11334','23406','84891', - '45157','29831','19642','79801','59935', - '47470','67096','35893','72818','79501', - '90702','15272','60303','23529','14424', - '41378','84952','53862','53606','28784', - '86638','45817','66574','44301','23734', - '85926','76384','65928','40812','77510', - '46369','54152','59743','90230','25299', - '25714','49696','39211','54678','43800', - '63578','20562','88099','66530','12421', - '12073','33923','95024','22299','84062', - '95186','37755','26758','55500','46802', - '14343','65378','83493','74980','59031', - '75838','69910','14946','29196','38664', - '58717','91219','24714','75237','98535', - '76684','43693','32958','63873','18189', - '65508','39425','36728','97813','69256', - '91192','49531','18050','99795','14811', - '30719','91348','31092','88089','80628', - '78307','51492','20949','61882','97538', - '38351','18809','98302','93095','18326', - '10279','95446','41373','99708','32661', - '28333','66333','67786','17984','58358', - '56525','57593','36460','19170','76994', - '71920','82571','76858','50047','82056', - '55026','56031','58330','73247','23065', - '40019','13866','75551','53155','58751', - '40846','34484','27239','20659','69206', - '78836','72226','99196','85574','26979', - '87451','73770','67822','51289','55955', - '90312','93146','43465','61210','89775', - '31716','64380','17685','78488','93459', - '86419','37298','51357','12165','44816', - '45670','38285','66744','91620','25658', - '57105','85735','95617','43990','53964', - '79550','58010','45934','37848','81278', - '44445','47352','28641','71990','14592', - '60760','29411','42759','26802','48296', - '40199','84076','24027','39491','36142', - '21589','81115','99799','71028','18873', - '84105','62010','63608','36918','22829', - '23666','41214','11358','43862','87823', - '14405','98329','59278','75417','81635', - '74834','41649','27467','19949','70003', - '23367','61963','63333','73125','60028', - '88228','50840','86534','90746','74320', - '57565','17721','36112','79380','14441', - '49814','65536','61157','11059','49676', - '98598','16685','19366','55151','60694', - '46861','97716','26811','89883','14013', - '82866','29225','81783','19340','64880', - '29031','69820','11709','25922','12131', - '45798','62769','46975','84914','97070', - '53822','35460','11421','32062','68918', - '69956','31684','53465','64832','75342', - '90813','49029','57592','33391','69716', - '41533','62502','50026','55435','90377', - '72943','29904','62333','69086','91574', - '57810','64154','40172','75235','17962', - '70683','93729','37498','37997','42839', - '82735','35067','89822','63214','53474', - '97196','61862','25633','23805','21415', - '30005','86716','16208','57996','91968', - '83385','42976','46583','86044','97271', - '79862','54417','82502','72935','36284', - '41037','83318','23324','89430','55413', - '19786','67291','42060','48080','84473', - '25678','14055','38506','13001','19552', - '61612','47104','90500','77742','23546', - '10518','53565','56137','47471','13880', - '40921','97854','82204','31383','41605', - '43633','23762','18736','13631','39580', - '25225','82336','58794','85863','98209', - '20884','18532','64752','79921','51745', - '34012','37476','61724','51951','13156', - '99937','25725','73257','80551','17785', - '72893','62610','57730','30290','21976', - '97910','34302','48773','43812','99069', - '34834','47091','81522','12329','24305', - '19989','35176','69601','44246') - intersect - select ca_zip - from (SELECT substring(ca_zip,1,5) ca_zip,count(*) cnt - FROM customer_address, customer - WHERE ca_address_sk = c_current_addr_sk and - c_preferred_cust_flag='Y' - group by ca_zip - having count(*) > 10)A1)A2) V1 - where ss_store_sk = s_store_sk - and ss_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 2001 - and (substring(s_zip,1,2) = substring(V1.ca_zip,1,2)) - group by s_store_name - order by s_store_name - limit 100; - --- end template query8.tpl query 76 in stream 8 --- start template query96.tpl query 77 in stream 8 -select /* TPC-DS query96.tpl 0.1 */ count(*) -from store_sales - ,household_demographics - ,time_dim, store -where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 15 - and time_dim.t_minute >= 30 - and household_demographics.hd_dep_count = 2 - and store.s_store_name = 'ese' -order by count(*) -limit 100; - --- end template query96.tpl query 77 in stream 8 --- start template query1.tpl query 78 in stream 8 -with /* TPC-DS query1.tpl 0.12 */ customer_total_return as -(select sr_customer_sk as ctr_customer_sk -,sr_store_sk as ctr_store_sk -,sum(SR_REVERSED_CHARGE) as ctr_total_return -from store_returns -,date_dim -where sr_returned_date_sk = d_date_sk -and d_year =2000 -group by sr_customer_sk -,sr_store_sk) - select c_customer_id -from customer_total_return ctr1 -,store -,customer -where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 -from customer_total_return ctr2 -where ctr1.ctr_store_sk = ctr2.ctr_store_sk) -and s_store_sk = ctr1.ctr_store_sk -and s_state = 'PA' -and ctr1.ctr_customer_sk = c_customer_sk -order by c_customer_id -limit 100; - --- end template query1.tpl query 78 in stream 8 --- start template query23.tpl query 79 in stream 8 -with /* TPC-DS query23.tpl 0.68 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (2000,2000+1,2000+2,2000+3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (2000,2000+1,2000+2,2000+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * -from - max_store_sales)) - select sum(sales) - from (select cs_quantity*cs_list_price sales - from catalog_sales - ,date_dim - where d_year = 2000 - and d_moy = 2 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - union all - select ws_quantity*ws_list_price sales - from web_sales - ,date_dim - where d_year = 2000 - and d_moy = 2 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer)) - limit 100; -with /* TPC-DS query23.tpl 0.68 part2 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (2000,2000 + 1,2000 + 2,2000 + 3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (2000,2000+1,2000+2,2000+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * - from max_store_sales)) - select c_last_name,c_first_name,sales - from (select c_last_name,c_first_name,sum(cs_quantity*cs_list_price) sales - from catalog_sales - ,customer - ,date_dim - where d_year = 2000 - and d_moy = 2 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and cs_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name - union all - select c_last_name,c_first_name,sum(ws_quantity*ws_list_price) sales - from web_sales - ,customer - ,date_dim - where d_year = 2000 - and d_moy = 2 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and ws_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name) - order by c_last_name,c_first_name,sales - limit 100; - --- end template query23.tpl query 79 in stream 8 --- start template query88.tpl query 80 in stream 8 -select /* TPC-DS query88.tpl 0.66 */ * -from - (select count(*) h8_30_to_9 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2)) - and store.s_store_name = 'ese') s1, - (select count(*) h9_to_9_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2)) - and store.s_store_name = 'ese') s2, - (select count(*) h9_30_to_10 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2)) - and store.s_store_name = 'ese') s3, - (select count(*) h10_to_10_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2)) - and store.s_store_name = 'ese') s4, - (select count(*) h10_30_to_11 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2)) - and store.s_store_name = 'ese') s5, - (select count(*) h11_to_11_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2)) - and store.s_store_name = 'ese') s6, - (select count(*) h11_30_to_12 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2)) - and store.s_store_name = 'ese') s7, - (select count(*) h12_to_12_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 12 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2)) - and store.s_store_name = 'ese') s8 -; - --- end template query88.tpl query 80 in stream 8 --- start template query82.tpl query 81 in stream 8 -select /* TPC-DS query82.tpl 0.67 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, store_sales - where i_current_price between 67 and 67+30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('2000-03-21' as date) and dateadd(day,60,cast('2000-03-21' as date)) - and i_manufact_id in (509,410,487,347) - and inv_quantity_on_hand between 100 and 500 - and ss_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query82.tpl query 81 in stream 8 --- start template query87.tpl query 82 in stream 8 -select /* TPC-DS query87.tpl 0.77 */ count(*) -from ((select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1200 and 1200+11) - except - (select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1200 and 1200+11) - except - (select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1200 and 1200+11) -) cool_cust -; - --- end template query87.tpl query 82 in stream 8 --- start template query43.tpl query 83 in stream 8 -select /* TPC-DS query43.tpl 0.15 */ s_store_name, s_store_id, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from date_dim, store_sales, store - where d_date_sk = ss_sold_date_sk and - s_store_sk = ss_store_sk and - s_gmt_offset = -6 and - d_year = 1998 - group by s_store_name, s_store_id - order by s_store_name, s_store_id,sun_sales,mon_sales,tue_sales,wed_sales,thu_sales,fri_sales,sat_sales - limit 100; - --- end template query43.tpl query 83 in stream 8 --- start template query53.tpl query 84 in stream 8 -select /* TPC-DS query53.tpl 0.88 */ * from -(select i_manufact_id, -sum(ss_sales_price) sum_sales, -avg(sum(ss_sales_price)) over (partition by i_manufact_id) avg_quarterly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and -ss_sold_date_sk = d_date_sk and -ss_store_sk = s_store_sk and -d_month_seq in (1221,1221+1,1221+2,1221+3,1221+4,1221+5,1221+6,1221+7,1221+8,1221+9,1221+10,1221+11) and -((i_category in ('Books','Children','Electronics') and -i_class in ('personal','portable','reference','self-help') and -i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) -or(i_category in ('Women','Music','Men') and -i_class in ('accessories','classical','fragrances','pants') and -i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manufact_id, d_qoy ) tmp1 -where case when avg_quarterly_sales > 0 - then abs (sum_sales - avg_quarterly_sales)/ avg_quarterly_sales - else null end > 0.1 -order by avg_quarterly_sales, - sum_sales, - i_manufact_id -limit 100; - --- end template query53.tpl query 84 in stream 8 --- start template query20.tpl query 85 in stream 8 -select /* TPC-DS query20.tpl 0.65 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(cs_ext_sales_price) as itemrevenue - ,sum(cs_ext_sales_price)*100/sum(sum(cs_ext_sales_price)) over - (partition by i_class) as revenueratio - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and i_category in ('Books', 'Electronics', 'Home') - and cs_sold_date_sk = d_date_sk - and d_date between cast('2002-01-22' as date) - and dateadd(day,30,cast('2002-01-22' as date)) - group by i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - order by i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query20.tpl query 85 in stream 8 --- start template query52.tpl query 86 in stream 8 -select /* TPC-DS query52.tpl 0.59 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_sales_price) ext_price - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=11 - and dt.d_year=1998 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,ext_price desc - ,brand_id -limit 100 ; - --- end template query52.tpl query 86 in stream 8 --- start template query83.tpl query 87 in stream 8 -with /* TPC-DS query83.tpl 0.96 */ sr_items as - (select i_item_id item_id, - sum(sr_return_quantity) sr_item_qty - from store_returns, - item, - date_dim - where sr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2002-02-01','2002-09-03','2002-11-17'))) - and sr_returned_date_sk = d_date_sk - group by i_item_id), - cr_items as - (select i_item_id item_id, - sum(cr_return_quantity) cr_item_qty - from catalog_returns, - item, - date_dim - where cr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2002-02-01','2002-09-03','2002-11-17'))) - and cr_returned_date_sk = d_date_sk - group by i_item_id), - wr_items as - (select i_item_id item_id, - sum(wr_return_quantity) wr_item_qty - from web_returns, - item, - date_dim - where wr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2002-02-01','2002-09-03','2002-11-17'))) - and wr_returned_date_sk = d_date_sk - group by i_item_id) - select sr_items.item_id - ,sr_item_qty - ,sr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 sr_dev - ,cr_item_qty - ,cr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 cr_dev - ,wr_item_qty - ,wr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 wr_dev - ,(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 average - from sr_items - ,cr_items - ,wr_items - where sr_items.item_id=cr_items.item_id - and sr_items.item_id=wr_items.item_id - order by sr_items.item_id - ,sr_item_qty - limit 100; - --- end template query83.tpl query 87 in stream 8 --- start template query38.tpl query 88 in stream 8 -select /* TPC-DS query38.tpl 0.54 */ count(*) from ( - select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1214 and 1214 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1214 and 1214 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1214 and 1214 + 11 -) hot_cust -limit 100; - --- end template query38.tpl query 88 in stream 8 --- start template query68.tpl query 89 in stream 8 -select /* TPC-DS query68.tpl 0.95 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,extended_price - ,extended_tax - ,list_price - from (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_ext_sales_price) extended_price - ,sum(ss_ext_list_price) list_price - ,sum(ss_ext_tax) extended_tax - from store_sales - ,date_dim - ,store - ,household_demographics - ,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_dep_count = 2 or - household_demographics.hd_vehicle_count= -1) - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_city in ('Walnut Grove','Springfield') - group by ss_ticket_number - ,ss_customer_sk - ,ss_addr_sk,ca_city) dn - ,customer - ,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,ss_ticket_number - limit 100; - --- end template query68.tpl query 89 in stream 8 --- start template query4.tpl query 90 in stream 8 -with /* TPC-DS query4.tpl 0.93 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(((ss_ext_list_price-ss_ext_wholesale_cost-ss_ext_discount_amt)+ss_ext_sales_price)/2) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((cs_ext_list_price-cs_ext_wholesale_cost-cs_ext_discount_amt)+cs_ext_sales_price)/2) ) year_total - ,'c' sale_type - from customer - ,catalog_sales - ,date_dim - where c_customer_sk = cs_bill_customer_sk - and cs_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year -union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((ws_ext_list_price-ws_ext_wholesale_cost-ws_ext_discount_amt)+ws_ext_sales_price)/2) ) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_login - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_c_firstyear - ,year_total t_c_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_c_secyear.customer_id - and t_s_firstyear.customer_id = t_c_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_c_firstyear.sale_type = 'c' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_c_secyear.sale_type = 'c' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 1999 - and t_s_secyear.dyear = 1999+1 - and t_c_firstyear.dyear = 1999 - and t_c_secyear.dyear = 1999+1 - and t_w_firstyear.dyear = 1999 - and t_w_secyear.dyear = 1999+1 - and t_s_firstyear.year_total > 0 - and t_c_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_login -limit 100; - --- end template query4.tpl query 90 in stream 8 --- start template query13.tpl query 91 in stream 8 -select /* TPC-DS query13.tpl 0.91 */ avg(ss_quantity) - ,avg(ss_ext_sales_price) - ,avg(ss_ext_wholesale_cost) - ,sum(ss_ext_wholesale_cost) - from store_sales - ,store - ,customer_demographics - ,household_demographics - ,customer_address - ,date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2001 - and((ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'D' - and cd_education_status = 'Advanced Degree' - and ss_sales_price between 100.00 and 150.00 - and hd_dep_count = 3 - )or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'W' - and cd_education_status = 'Unknown' - and ss_sales_price between 50.00 and 100.00 - and hd_dep_count = 1 - ) or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'M' - and cd_education_status = 'College' - and ss_sales_price between 150.00 and 200.00 - and hd_dep_count = 1 - )) - and((ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('VA', 'CO', 'KS') - and ss_net_profit between 100 and 200 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('PA', 'WI', 'AK') - and ss_net_profit between 150 and 300 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('TN', 'ID', 'SD') - and ss_net_profit between 50 and 250 - )) -; - --- end template query13.tpl query 91 in stream 8 --- start template query48.tpl query 92 in stream 8 -select /* TPC-DS query48.tpl 0.74 */ sum (ss_quantity) - from store_sales, store, customer_demographics, customer_address, date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2001 - and - ( - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'M' - and - cd_education_status = 'Secondary' - and - ss_sales_price between 100.00 and 150.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'S' - and - cd_education_status = 'Unknown' - and - ss_sales_price between 50.00 and 100.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'D' - and - cd_education_status = 'College' - and - ss_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('SC', 'CO', 'TX') - and ss_net_profit between 0 and 2000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('SD', 'KY', 'WI') - and ss_net_profit between 150 and 3000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('AL', 'VA', 'ND') - and ss_net_profit between 50 and 25000 - ) - ) -; - --- end template query48.tpl query 92 in stream 8 --- start template query99.tpl query 93 in stream 8 -select /* TPC-DS query99.tpl 0.94 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 30) and - (cs_ship_date_sk - cs_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 60) and - (cs_ship_date_sk - cs_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 90) and - (cs_ship_date_sk - cs_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - catalog_sales - ,warehouse - ,ship_mode - ,call_center - ,date_dim -where - d_month_seq between 1190 and 1190 + 11 -and cs_ship_date_sk = d_date_sk -and cs_warehouse_sk = w_warehouse_sk -and cs_ship_mode_sk = sm_ship_mode_sk -and cs_call_center_sk = cc_call_center_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -limit 100; - --- end template query99.tpl query 93 in stream 8 --- start template query27a.tpl query 94 in stream 8 -with /* TPC-DS query27a.tpl 0.16 */ results as - (select i_item_id, - s_state, 0 as g_state, - ss_quantity agg1, - ss_list_price agg2, - ss_coupon_amt agg3, - ss_sales_price agg4 - from store_sales, customer_demographics, date_dim, store, item - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_store_sk = s_store_sk and - ss_cdemo_sk = cd_demo_sk and - cd_gender = 'M' and - cd_marital_status = 'M' and - cd_education_status = '2 yr Degree' and - d_year = 1999 and - s_state in ('MO','NY', 'WV', 'LA', 'AL', 'NM') - ) - - select i_item_id, - s_state, g_state, agg1, agg2, agg3, agg4 - from ( - select i_item_id, s_state, 0 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4 from results - group by i_item_id, s_state - union all - select i_item_id, NULL AS s_state, 1 AS g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as s_state, 1 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - ) foo - order by i_item_id, s_state - limit 100; - --- end template query27a.tpl query 94 in stream 8 --- start template query18a.tpl query 95 in stream 8 -with /* TPC-DS query18a.tpl 0.90 */ results as - (select i_item_id, - ca_country, - ca_state, - ca_county, - cast(cs_quantity as decimal(12,2)) agg1, - cast(cs_list_price as decimal(12,2)) agg2, - cast(cs_coupon_amt as decimal(12,2)) agg3, - cast(cs_sales_price as decimal(12,2)) agg4, - cast(cs_net_profit as decimal(12,2)) agg5, - cast(c_birth_year as decimal(12,2)) agg6, - cast(cd1.cd_dep_count as decimal(12,2)) agg7 - from catalog_sales, customer_demographics cd1, customer_demographics cd2, customer, customer_address, date_dim, item - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd1.cd_demo_sk and - cs_bill_customer_sk = c_customer_sk and - cd1.cd_gender = 'F' and - cd1.cd_education_status = '4 yr Degree' and - c_current_cdemo_sk = cd2.cd_demo_sk and - c_current_addr_sk = ca_address_sk and - c_birth_month in (12,5,7,1,6,2) and - d_year = 1998 and - ca_state in ('VA','NC','IA','NV','KY','MI','MO') - ) - select i_item_id, ca_country, ca_state, ca_county, agg1, agg2, agg3, agg4, agg5, agg6, agg7 - from ( - select i_item_id, ca_country, ca_state, ca_county, avg(agg1) agg1, - avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state, ca_county - union all - select i_item_id, ca_country, ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state - union all - select i_item_id, ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country - union all - select i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - ) foo - order by ca_country, ca_state, ca_county, i_item_id - limit 100; - --- end template query18a.tpl query 95 in stream 8 --- start template query15.tpl query 96 in stream 8 -select /* TPC-DS query15.tpl 0.57 */ ca_zip - ,sum(cs_sales_price) - from catalog_sales - ,customer - ,customer_address - ,date_dim - where cs_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', - '85392', '85460', '80348', '81792') - or ca_state in ('CA','WA','GA') - or cs_sales_price > 500) - and cs_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 1998 - group by ca_zip - order by ca_zip - limit 100; - --- end template query15.tpl query 96 in stream 8 --- start template query33.tpl query 97 in stream 8 -with /* TPC-DS query33.tpl 0.22 */ ss as ( - select - i_manufact_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Sports')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 5 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id), - cs as ( - select - i_manufact_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Sports')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 5 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id), - ws as ( - select - i_manufact_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Sports')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 5 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id) - select i_manufact_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_manufact_id - order by total_sales -limit 100; - --- end template query33.tpl query 97 in stream 8 --- start template query31.tpl query 98 in stream 8 -with /* TPC-DS query31.tpl 0.50 */ ss as - (select ca_county,d_qoy, d_year,sum(ss_ext_sales_price) as store_sales - from store_sales,date_dim,customer_address - where ss_sold_date_sk = d_date_sk - and ss_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year), - ws as - (select ca_county,d_qoy, d_year,sum(ws_ext_sales_price) as web_sales - from web_sales,date_dim,customer_address - where ws_sold_date_sk = d_date_sk - and ws_bill_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year) - select - ss1.ca_county - ,ss1.d_year - ,ws2.web_sales/ws1.web_sales web_q1_q2_increase - ,ss2.store_sales/ss1.store_sales store_q1_q2_increase - ,ws3.web_sales/ws2.web_sales web_q2_q3_increase - ,ss3.store_sales/ss2.store_sales store_q2_q3_increase - from - ss ss1 - ,ss ss2 - ,ss ss3 - ,ws ws1 - ,ws ws2 - ,ws ws3 - where - ss1.d_qoy = 1 - and ss1.d_year = 1999 - and ss1.ca_county = ss2.ca_county - and ss2.d_qoy = 2 - and ss2.d_year = 1999 - and ss2.ca_county = ss3.ca_county - and ss3.d_qoy = 3 - and ss3.d_year = 1999 - and ss1.ca_county = ws1.ca_county - and ws1.d_qoy = 1 - and ws1.d_year = 1999 - and ws1.ca_county = ws2.ca_county - and ws2.d_qoy = 2 - and ws2.d_year = 1999 - and ws1.ca_county = ws3.ca_county - and ws3.d_qoy = 3 - and ws3.d_year =1999 - and case when ws1.web_sales > 0 then ws2.web_sales/ws1.web_sales else null end - > case when ss1.store_sales > 0 then ss2.store_sales/ss1.store_sales else null end - and case when ws2.web_sales > 0 then ws3.web_sales/ws2.web_sales else null end - > case when ss2.store_sales > 0 then ss3.store_sales/ss2.store_sales else null end - order by ss1.d_year; - --- end template query31.tpl query 98 in stream 8 --- start template query63.tpl query 99 in stream 8 -select /* TPC-DS query63.tpl 0.27 */ * -from (select i_manager_id - ,sum(ss_sales_price) sum_sales - ,avg(sum(ss_sales_price)) over (partition by i_manager_id) avg_monthly_sales - from item - ,store_sales - ,date_dim - ,store - where ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and d_month_seq in (1184,1184+1,1184+2,1184+3,1184+4,1184+5,1184+6,1184+7,1184+8,1184+9,1184+10,1184+11) - and (( i_category in ('Books','Children','Electronics') - and i_class in ('personal','portable','reference','self-help') - and i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) - or( i_category in ('Women','Music','Men') - and i_class in ('accessories','classical','fragrances','pants') - and i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manager_id, d_moy) tmp1 -where case when avg_monthly_sales > 0 then abs (sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 -order by i_manager_id - ,avg_monthly_sales - ,sum_sales -limit 100; - --- end template query63.tpl query 99 in stream 8 diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/3TB/queries/query_9.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/3TB/queries/query_9.sql deleted file mode 100644 index f179f07a..00000000 --- a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/3TB/queries/query_9.sql +++ /dev/null @@ -1,5027 +0,0 @@ --- start template query15.tpl query 1 in stream 9 -select /* TPC-DS query15.tpl 0.57 */ ca_zip - ,sum(cs_sales_price) - from catalog_sales - ,customer - ,customer_address - ,date_dim - where cs_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', - '85392', '85460', '80348', '81792') - or ca_state in ('CA','WA','GA') - or cs_sales_price > 500) - and cs_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 2000 - group by ca_zip - order by ca_zip - limit 100; - --- end template query15.tpl query 1 in stream 9 --- start template query60.tpl query 2 in stream 9 -with /* TPC-DS query60.tpl 0.29 */ ss as ( - select - i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Music')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 10 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - cs as ( - select - i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Music')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 10 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - ws as ( - select - i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Music')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 10 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id) - select - i_item_id -,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by i_item_id - ,total_sales - limit 100; - --- end template query60.tpl query 2 in stream 9 --- start template query62.tpl query 3 in stream 9 -select /* TPC-DS query62.tpl 0.24 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 30) and - (ws_ship_date_sk - ws_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 60) and - (ws_ship_date_sk - ws_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 90) and - (ws_ship_date_sk - ws_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - web_sales - ,warehouse - ,ship_mode - ,web_site - ,date_dim -where - d_month_seq between 1215 and 1215 + 11 -and ws_ship_date_sk = d_date_sk -and ws_warehouse_sk = w_warehouse_sk -and ws_ship_mode_sk = sm_ship_mode_sk -and ws_web_site_sk = web_site_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -limit 100; - --- end template query62.tpl query 3 in stream 9 --- start template query74.tpl query 4 in stream 9 -with /* TPC-DS query74.tpl 0.76 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,avg(ss_net_paid) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (2000,2000+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,avg(ws_net_paid) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - and d_year in (2000,2000+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - ) - select - t_s_secyear.customer_id, t_s_secyear.customer_first_name, t_s_secyear.customer_last_name - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.year = 2000 - and t_s_secyear.year = 2000+1 - and t_w_firstyear.year = 2000 - and t_w_secyear.year = 2000+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - order by 2,3,1 -limit 100; - --- end template query74.tpl query 4 in stream 9 --- start template query81.tpl query 5 in stream 9 -with /* TPC-DS query81.tpl 0.37 */ customer_total_return as - (select cr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(cr_return_amt_inc_tax) as ctr_total_return - from catalog_returns - ,date_dim - ,customer_address - where cr_returned_date_sk = d_date_sk - and d_year =2001 - and cr_returning_addr_sk = ca_address_sk - group by cr_returning_customer_sk - ,ca_state ) - select c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'KY' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - limit 100; - --- end template query81.tpl query 5 in stream 9 --- start template query88.tpl query 6 in stream 9 -select /* TPC-DS query88.tpl 0.66 */ * -from - (select count(*) h8_30_to_9 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s1, - (select count(*) h9_to_9_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s2, - (select count(*) h9_30_to_10 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s3, - (select count(*) h10_to_10_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s4, - (select count(*) h10_30_to_11 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s5, - (select count(*) h11_to_11_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s6, - (select count(*) h11_30_to_12 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s7, - (select count(*) h12_to_12_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 12 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s8 -; - --- end template query88.tpl query 6 in stream 9 --- start template query50.tpl query 7 in stream 9 -select /* TPC-DS query50.tpl 0.60 */ - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 30) and - (sr_returned_date_sk - ss_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 60) and - (sr_returned_date_sk - ss_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 90) and - (sr_returned_date_sk - ss_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - store_sales - ,store_returns - ,store - ,date_dim d1 - ,date_dim d2 -where - d2.d_year = 2001 -and d2.d_moy = 10 -and ss_ticket_number = sr_ticket_number -and ss_item_sk = sr_item_sk -and ss_sold_date_sk = d1.d_date_sk -and sr_returned_date_sk = d2.d_date_sk -and ss_customer_sk = sr_customer_sk -and ss_store_sk = s_store_sk -group by - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -order by s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -limit 100; - --- end template query50.tpl query 7 in stream 9 --- start template query5a.tpl query 8 in stream 9 -with /* TPC-DS query5a.tpl 0.98 */ ssr as - (select s_store_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ss_store_sk as store_sk, - ss_sold_date_sk as date_sk, - ss_ext_sales_price as sales_price, - ss_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from store_sales - union all - select sr_store_sk as store_sk, - sr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - sr_return_amt as return_amt, - sr_net_loss as net_loss - from store_returns - ) salesreturns, - date_dim, - store - where date_sk = d_date_sk - and d_date between cast('2001-08-22' as date) - and dateadd(day,14,cast('2001-08-22' as date)) - and store_sk = s_store_sk - group by s_store_id) - , - csr as - (select cp_catalog_page_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select cs_catalog_page_sk as page_sk, - cs_sold_date_sk as date_sk, - cs_ext_sales_price as sales_price, - cs_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from catalog_sales - union all - select cr_catalog_page_sk as page_sk, - cr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - cr_return_amount as return_amt, - cr_net_loss as net_loss - from catalog_returns - ) salesreturns, - date_dim, - catalog_page - where date_sk = d_date_sk - and d_date between cast('2001-08-22' as date) - and dateadd(day,14,cast('2001-08-22' as date)) - and page_sk = cp_catalog_page_sk - group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ws_web_site_sk as wsr_web_site_sk, - ws_sold_date_sk as date_sk, - ws_ext_sales_price as sales_price, - ws_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from web_sales - union all - select ws_web_site_sk as wsr_web_site_sk, - wr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - wr_return_amt as return_amt, - wr_net_loss as net_loss - from web_returns left outer join web_sales on - ( wr_item_sk = ws_item_sk - and wr_order_number = ws_order_number) - ) salesreturns, - date_dim, - web_site - where date_sk = d_date_sk - and d_date between cast('2001-08-22' as date) - and dateadd(day,14,cast('2001-08-22' as date)) - and wsr_web_site_sk = web_site_sk - group by web_site_id) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || s_store_id as id - , sales - , returns - , (profit - profit_loss) as profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || cp_catalog_page_id as id - , sales - , returns - , (profit - profit_loss) as profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , (profit - profit_loss) as profit - from wsr - ) x - group by channel, id) - select channel, id, sales, returns, profit from ( - select channel, id, sales, returns, profit from results - union - select channel, null as id, sum(sales), sum(returns), sum(profit) from results group by channel - union - select null as channel, null as id, sum(sales), sum(returns), sum(profit) from results) foo -order by channel, id -limit 100; - --- end template query5a.tpl query 8 in stream 9 --- start template query84.tpl query 9 in stream 9 -select /* TPC-DS query84.tpl 0.80 */ c_customer_id as customer_id - , coalesce(c_last_name,'') || ', ' || coalesce(c_first_name,'') as customername - from customer - ,customer_address - ,customer_demographics - ,household_demographics - ,income_band - ,store_returns - where ca_city = 'Bridgeport' - and c_current_addr_sk = ca_address_sk - and ib_lower_bound >= 24624 - and ib_upper_bound <= 24624 + 50000 - and ib_income_band_sk = hd_income_band_sk - and cd_demo_sk = c_current_cdemo_sk - and hd_demo_sk = c_current_hdemo_sk - and sr_cdemo_sk = cd_demo_sk - order by c_customer_id - limit 100; - --- end template query84.tpl query 9 in stream 9 --- start template query1.tpl query 10 in stream 9 -with /* TPC-DS query1.tpl 0.12 */ customer_total_return as -(select sr_customer_sk as ctr_customer_sk -,sr_store_sk as ctr_store_sk -,sum(SR_FEE) as ctr_total_return -from store_returns -,date_dim -where sr_returned_date_sk = d_date_sk -and d_year =1999 -group by sr_customer_sk -,sr_store_sk) - select c_customer_id -from customer_total_return ctr1 -,store -,customer -where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 -from customer_total_return ctr2 -where ctr1.ctr_store_sk = ctr2.ctr_store_sk) -and s_store_sk = ctr1.ctr_store_sk -and s_state = 'AL' -and ctr1.ctr_customer_sk = c_customer_sk -order by c_customer_id -limit 100; - --- end template query1.tpl query 10 in stream 9 --- start template query52.tpl query 11 in stream 9 -select /* TPC-DS query52.tpl 0.59 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_sales_price) ext_price - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=12 - and dt.d_year=2001 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,ext_price desc - ,brand_id -limit 100 ; - --- end template query52.tpl query 11 in stream 9 --- start template query57.tpl query 12 in stream 9 -with /* TPC-DS query57.tpl 0.70 */ v1 as( - select i_category, i_brand, - cc_name, - d_year, d_moy, - sum(cs_sales_price) sum_sales, - avg(sum(cs_sales_price)) over - (partition by i_category, i_brand, - cc_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - cc_name - order by d_year, d_moy) rn - from item, catalog_sales, date_dim, call_center - where cs_item_sk = i_item_sk and - cs_sold_date_sk = d_date_sk and - cc_call_center_sk= cs_call_center_sk and - ( - d_year = 2001 or - ( d_year = 2001-1 and d_moy =12) or - ( d_year = 2001+1 and d_moy =1) - ) - group by i_category, i_brand, - cc_name , d_year, d_moy), - v2 as( - select v1.cc_name - ,v1.d_year - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1. cc_name = v1_lag. cc_name and - v1. cc_name = v1_lead. cc_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 2001 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, sum_sales - limit 100; - --- end template query57.tpl query 12 in stream 9 --- start template query13.tpl query 13 in stream 9 -select /* TPC-DS query13.tpl 0.91 */ avg(ss_quantity) - ,avg(ss_ext_sales_price) - ,avg(ss_ext_wholesale_cost) - ,sum(ss_ext_wholesale_cost) - from store_sales - ,store - ,customer_demographics - ,household_demographics - ,customer_address - ,date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2001 - and((ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'W' - and cd_education_status = 'College' - and ss_sales_price between 100.00 and 150.00 - and hd_dep_count = 3 - )or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'M' - and cd_education_status = '4 yr Degree' - and ss_sales_price between 50.00 and 100.00 - and hd_dep_count = 1 - ) or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'S' - and cd_education_status = 'Advanced Degree' - and ss_sales_price between 150.00 and 200.00 - and hd_dep_count = 1 - )) - and((ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('MI', 'IA', 'VT') - and ss_net_profit between 100 and 200 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('KY', 'OH', 'NE') - and ss_net_profit between 150 and 300 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('SC', 'OR', 'MO') - and ss_net_profit between 50 and 250 - )) -; - --- end template query13.tpl query 13 in stream 9 --- start template query14a.tpl query 14 in stream 9 -with /* TPC-DS query14a.tpl 0.69 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1998 AND 1998 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1998 AND 1998 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1998 AND 1998 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as - (select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2) x) -, - results AS -(select channel, i_brand_id, i_class_id, i_category_id, sum(sales) sum_sales, sum(number_sales) number_sales - from ( - select 'store' channel, i_brand_id,i_class_id - ,i_category_id,sum(ss_quantity*ss_list_price) sales - , count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1998+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales) - union all - select 'catalog' channel, i_brand_id,i_class_id,i_category_id, sum(cs_quantity*cs_list_price) sales, count(*) number_sales - from catalog_sales - ,item - ,date_dim - where cs_item_sk in (select ss_item_sk from cross_items) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1998+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(cs_quantity*cs_list_price) > (select average_sales from avg_sales) - union all - select 'web' channel, i_brand_id,i_class_id,i_category_id, sum(ws_quantity*ws_list_price) sales , count(*) number_sales - from web_sales - ,item - ,date_dim - where ws_item_sk in (select ss_item_sk from cross_items) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1998+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ws_quantity*ws_list_price) > (select average_sales from avg_sales) - ) y - group by channel, i_brand_id,i_class_id,i_category_id) - - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales -from ( - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales from results - union - select channel, i_brand_id, i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id, i_class_id - union - select channel, i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id - union - select channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel - union - select null as channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results) z -order by channel, i_brand_id, i_class_id, i_category_id - limit 100; -with /* TPC-DS query14a.tpl 0.69 part2 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1998 AND 1998 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1998 AND 1998 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1998 AND 1998 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as -(select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2) x) - select this_year.channel ty_channel - ,this_year.i_brand_id ty_brand - ,this_year.i_class_id ty_class - ,this_year.i_category_id ty_category - ,this_year.sales ty_sales - ,this_year.number_sales ty_number_sales - ,last_year.channel ly_channel - ,last_year.i_brand_id ly_brand - ,last_year.i_class_id ly_class - ,last_year.i_category_id ly_category - ,last_year.sales ly_sales - ,last_year.number_sales ly_number_sales -from - (select 'store' channel, i_brand_id,i_class_id,i_category_id - ,sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1998 + 1 - and d_moy = 12 - and d_dom = 16) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) this_year, - (select 'store' channel, i_brand_id,i_class_id - ,i_category_id, sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1998 - and d_moy = 12 - and d_dom = 16) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) last_year - where this_year.i_brand_id= last_year.i_brand_id - and this_year.i_class_id = last_year.i_class_id - and this_year.i_category_id = last_year.i_category_id - order by this_year.channel, this_year.i_brand_id, this_year.i_class_id, this_year.i_category_id - limit 100; - --- end template query14a.tpl query 14 in stream 9 --- start template query90.tpl query 15 in stream 9 -select /* TPC-DS query90.tpl 0.40 */ cast(amc as decimal(15,4))/cast(pmc as decimal(15,4)) am_pm_ratio - from ( select count(*) amc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 7 and 7+1 - and household_demographics.hd_dep_count = 6 - and web_page.wp_char_count between 5000 and 5200) at, - ( select count(*) pmc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 16 and 16+1 - and household_demographics.hd_dep_count = 6 - and web_page.wp_char_count between 5000 and 5200) pt - order by am_pm_ratio - limit 100; - --- end template query90.tpl query 15 in stream 9 --- start template query7.tpl query 16 in stream 9 -select /* TPC-DS query7.tpl 0.2 */ i_item_id, - avg(ss_quantity) agg1, - avg(ss_list_price) agg2, - avg(ss_coupon_amt) agg3, - avg(ss_sales_price) agg4 - from store_sales, customer_demographics, date_dim, item, promotion - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_cdemo_sk = cd_demo_sk and - ss_promo_sk = p_promo_sk and - cd_gender = 'M' and - cd_marital_status = 'S' and - cd_education_status = 'Secondary' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 2001 - group by i_item_id - order by i_item_id - limit 100; - --- end template query7.tpl query 16 in stream 9 --- start template query27a.tpl query 17 in stream 9 -with /* TPC-DS query27a.tpl 0.16 */ results as - (select i_item_id, - s_state, 0 as g_state, - ss_quantity agg1, - ss_list_price agg2, - ss_coupon_amt agg3, - ss_sales_price agg4 - from store_sales, customer_demographics, date_dim, store, item - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_store_sk = s_store_sk and - ss_cdemo_sk = cd_demo_sk and - cd_gender = 'M' and - cd_marital_status = 'W' and - cd_education_status = 'College' and - d_year = 2000 and - s_state in ('NY','WA', 'MI', 'TN', 'NM', 'LA') - ) - - select i_item_id, - s_state, g_state, agg1, agg2, agg3, agg4 - from ( - select i_item_id, s_state, 0 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4 from results - group by i_item_id, s_state - union all - select i_item_id, NULL AS s_state, 1 AS g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as s_state, 1 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - ) foo - order by i_item_id, s_state - limit 100; - --- end template query27a.tpl query 17 in stream 9 --- start template query92.tpl query 18 in stream 9 -select /* TPC-DS query92.tpl 0.44 */ - sum(ws_ext_discount_amt) as "Excess Discount Amount" -from - web_sales - ,item - ,date_dim -where -i_manufact_id = 892 -and i_item_sk = ws_item_sk -and d_date between '1999-03-20' and - dateadd(day,90,cast('1999-03-20' as date)) -and d_date_sk = ws_sold_date_sk -and ws_ext_discount_amt - > ( - SELECT - 1.3 * avg(ws_ext_discount_amt) - FROM - web_sales - ,date_dim - WHERE - ws_item_sk = i_item_sk - and d_date between '1999-03-20' and - dateadd(day,90,cast('1999-03-20' as date)) - and d_date_sk = ws_sold_date_sk - ) -order by sum(ws_ext_discount_amt) -limit 100; - --- end template query92.tpl query 18 in stream 9 --- start template query39.tpl query 19 in stream 9 -with /* TPC-DS query39.tpl 0.5 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =1998 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=3 - and inv2.d_moy=3+1 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; -with /* TPC-DS query39.tpl 0.5 part2 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =1998 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=3 - and inv2.d_moy=3+1 - and inv1.cov > 1.5 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; - --- end template query39.tpl query 19 in stream 9 --- start template query34.tpl query 20 in stream 9 -select /* TPC-DS query34.tpl 0.73 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (date_dim.d_dom between 1 and 3 or date_dim.d_dom between 25 and 28) - and (household_demographics.hd_buy_potential = '501-1000' or - household_demographics.hd_buy_potential = 'Unknown') - and household_demographics.hd_vehicle_count > 0 - and (case when household_demographics.hd_vehicle_count > 0 - then household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count - else null - end) > 1.2 - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_county in ('Terry County','Franklin Parish','Fairfield County','Kittitas County', - 'Gage County','Harmon County','Sumner County','Raleigh County') - group by ss_ticket_number,ss_customer_sk) dn,customer - where ss_customer_sk = c_customer_sk - and cnt between 15 and 20 - order by c_last_name,c_first_name,c_salutation,c_preferred_cust_flag desc, ss_ticket_number; - --- end template query34.tpl query 20 in stream 9 --- start template query21.tpl query 21 in stream 9 -select /* TPC-DS query21.tpl 0.14 */ * - from(select w_warehouse_name - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('1998-03-15' as date)) - then inv_quantity_on_hand - else 0 end) as inv_before - ,sum(case when (cast(d_date as date) >= cast ('1998-03-15' as date)) - then inv_quantity_on_hand - else 0 end) as inv_after - from inventory - ,warehouse - ,item - ,date_dim - where i_current_price between 0.99 and 1.49 - and i_item_sk = inv_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('1998-03-15' as date)) - and dateadd(day,30,cast ('1998-03-15' as date)) - group by w_warehouse_name, i_item_id) x - where (case when inv_before > 0 - then inv_after / inv_before - else null - end) between 2.0/3.0 and 3.0/2.0 - order by w_warehouse_name - ,i_item_id - limit 100; - --- end template query21.tpl query 21 in stream 9 --- start template query65.tpl query 22 in stream 9 -select /* TPC-DS query65.tpl 0.71 */ - s_store_name, - i_item_desc, - sc.revenue, - i_current_price, - i_wholesale_cost, - i_brand - from store, item, - (select ss_store_sk, avg(revenue) as ave - from - (select ss_store_sk, ss_item_sk, - sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1196 and 1196+11 - group by ss_store_sk, ss_item_sk) sa - group by ss_store_sk) sb, - (select ss_store_sk, ss_item_sk, sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1196 and 1196+11 - group by ss_store_sk, ss_item_sk) sc - where sb.ss_store_sk = sc.ss_store_sk and - sc.revenue <= 0.1 * sb.ave and - s_store_sk = sc.ss_store_sk and - i_item_sk = sc.ss_item_sk - order by s_store_name, i_item_desc -limit 100; - --- end template query65.tpl query 22 in stream 9 --- start template query75.tpl query 23 in stream 9 -WITH /* TPC-DS query75.tpl 0.3 */ all_sales AS ( - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,SUM(sales_cnt) AS sales_cnt - ,SUM(sales_amt) AS sales_amt - FROM (SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,cs_quantity - COALESCE(cr_return_quantity,0) AS sales_cnt - ,cs_ext_sales_price - COALESCE(cr_return_amount,0.0) AS sales_amt - FROM catalog_sales JOIN item ON i_item_sk=cs_item_sk - JOIN date_dim ON d_date_sk=cs_sold_date_sk - LEFT JOIN catalog_returns ON (cs_order_number=cr_order_number - AND cs_item_sk=cr_item_sk) - WHERE i_category='Men' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ss_quantity - COALESCE(sr_return_quantity,0) AS sales_cnt - ,ss_ext_sales_price - COALESCE(sr_return_amt,0.0) AS sales_amt - FROM store_sales JOIN item ON i_item_sk=ss_item_sk - JOIN date_dim ON d_date_sk=ss_sold_date_sk - LEFT JOIN store_returns ON (ss_ticket_number=sr_ticket_number - AND ss_item_sk=sr_item_sk) - WHERE i_category='Men' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ws_quantity - COALESCE(wr_return_quantity,0) AS sales_cnt - ,ws_ext_sales_price - COALESCE(wr_return_amt,0.0) AS sales_amt - FROM web_sales JOIN item ON i_item_sk=ws_item_sk - JOIN date_dim ON d_date_sk=ws_sold_date_sk - LEFT JOIN web_returns ON (ws_order_number=wr_order_number - AND ws_item_sk=wr_item_sk) - WHERE i_category='Men') sales_detail - GROUP BY d_year, i_brand_id, i_class_id, i_category_id, i_manufact_id) - SELECT prev_yr.d_year AS prev_year - ,curr_yr.d_year AS year - ,curr_yr.i_brand_id - ,curr_yr.i_class_id - ,curr_yr.i_category_id - ,curr_yr.i_manufact_id - ,prev_yr.sales_cnt AS prev_yr_cnt - ,curr_yr.sales_cnt AS curr_yr_cnt - ,curr_yr.sales_cnt-prev_yr.sales_cnt AS sales_cnt_diff - ,curr_yr.sales_amt-prev_yr.sales_amt AS sales_amt_diff - FROM all_sales curr_yr, all_sales prev_yr - WHERE curr_yr.i_brand_id=prev_yr.i_brand_id - AND curr_yr.i_class_id=prev_yr.i_class_id - AND curr_yr.i_category_id=prev_yr.i_category_id - AND curr_yr.i_manufact_id=prev_yr.i_manufact_id - AND curr_yr.d_year=1999 - AND prev_yr.d_year=1999-1 - AND CAST(curr_yr.sales_cnt AS DECIMAL(17,2))/CAST(prev_yr.sales_cnt AS DECIMAL(17,2))<0.9 - ORDER BY sales_cnt_diff,sales_amt_diff - limit 100; - --- end template query75.tpl query 23 in stream 9 --- start template query9.tpl query 24 in stream 9 -select /* TPC-DS query9.tpl 0.49 */ case when (select count(*) - from store_sales - where ss_quantity between 1 and 20) > 75780808 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 1 and 20) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 1 and 20) end bucket1 , - case when (select count(*) - from store_sales - where ss_quantity between 21 and 40) > 131643214 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 21 and 40) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 21 and 40) end bucket2, - case when (select count(*) - from store_sales - where ss_quantity between 41 and 60) > 116201008 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 41 and 60) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 41 and 60) end bucket3, - case when (select count(*) - from store_sales - where ss_quantity between 61 and 80) > 84450646 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 61 and 80) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 61 and 80) end bucket4, - case when (select count(*) - from store_sales - where ss_quantity between 81 and 100) > 62714526 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 81 and 100) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 81 and 100) end bucket5 -from reason -where r_reason_sk = 1 -; - --- end template query9.tpl query 24 in stream 9 --- start template query2.tpl query 25 in stream 9 -with /* TPC-DS query2.tpl 0.84 */ wscs as - (select sold_date_sk - ,sales_price - from (select ws_sold_date_sk sold_date_sk - ,ws_ext_sales_price sales_price - from web_sales - union all - select cs_sold_date_sk sold_date_sk - ,cs_ext_sales_price sales_price - from catalog_sales)), - wswscs as - (select d_week_seq, - sum(case when (d_day_name='Sunday') then sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then sales_price else null end) sat_sales - from wscs - ,date_dim - where d_date_sk = sold_date_sk - group by d_week_seq) - select d_week_seq1 - ,round(sun_sales1/sun_sales2,2) - ,round(mon_sales1/mon_sales2,2) - ,round(tue_sales1/tue_sales2,2) - ,round(wed_sales1/wed_sales2,2) - ,round(thu_sales1/thu_sales2,2) - ,round(fri_sales1/fri_sales2,2) - ,round(sat_sales1/sat_sales2,2) - from - (select wswscs.d_week_seq d_week_seq1 - ,sun_sales sun_sales1 - ,mon_sales mon_sales1 - ,tue_sales tue_sales1 - ,wed_sales wed_sales1 - ,thu_sales thu_sales1 - ,fri_sales fri_sales1 - ,sat_sales sat_sales1 - from wswscs,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 1999) y, - (select wswscs.d_week_seq d_week_seq2 - ,sun_sales sun_sales2 - ,mon_sales mon_sales2 - ,tue_sales tue_sales2 - ,wed_sales wed_sales2 - ,thu_sales thu_sales2 - ,fri_sales fri_sales2 - ,sat_sales sat_sales2 - from wswscs - ,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 1999+1) z - where d_week_seq1=d_week_seq2-53 - order by d_week_seq1; - --- end template query2.tpl query 25 in stream 9 --- start template query12.tpl query 26 in stream 9 -select /* TPC-DS query12.tpl 0.64 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ws_ext_sales_price) as itemrevenue - ,sum(ws_ext_sales_price)*100/sum(sum(ws_ext_sales_price)) over - (partition by i_class) as revenueratio -from - web_sales - ,item - ,date_dim -where - ws_item_sk = i_item_sk - and i_category in ('Music', 'Children', 'Men') - and ws_sold_date_sk = d_date_sk - and d_date between cast('2001-03-27' as date) - and dateadd(day,30,cast('2001-03-27' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query12.tpl query 26 in stream 9 --- start template query32.tpl query 27 in stream 9 -select /* TPC-DS query32.tpl 0.7 */ sum(cs_ext_discount_amt) as "excess discount amount" -from - catalog_sales - ,item - ,date_dim -where -i_manufact_id = 523 -and i_item_sk = cs_item_sk -and d_date between '2000-03-20' and - dateadd(day,90,cast('2000-03-20' as date)) -and d_date_sk = cs_sold_date_sk -and cs_ext_discount_amt - > ( - select - 1.3 * avg(cs_ext_discount_amt) - from - catalog_sales - ,date_dim - where - cs_item_sk = i_item_sk - and d_date between '2000-03-20' and - dateadd(day,90,cast('2000-03-20' as date)) - and d_date_sk = cs_sold_date_sk - ) -limit 100; - --- end template query32.tpl query 27 in stream 9 --- start template query28.tpl query 28 in stream 9 -select /* TPC-DS query28.tpl 0.36 */ * -from (select avg(ss_list_price) B1_LP - ,count(ss_list_price) B1_CNT - ,count(distinct ss_list_price) B1_CNTD - from store_sales - where ss_quantity between 0 and 5 - and (ss_list_price between 64 and 64+10 - or ss_coupon_amt between 14078 and 14078+1000 - or ss_wholesale_cost between 52 and 52+20)) B1, - (select avg(ss_list_price) B2_LP - ,count(ss_list_price) B2_CNT - ,count(distinct ss_list_price) B2_CNTD - from store_sales - where ss_quantity between 6 and 10 - and (ss_list_price between 37 and 37+10 - or ss_coupon_amt between 10126 and 10126+1000 - or ss_wholesale_cost between 22 and 22+20)) B2, - (select avg(ss_list_price) B3_LP - ,count(ss_list_price) B3_CNT - ,count(distinct ss_list_price) B3_CNTD - from store_sales - where ss_quantity between 11 and 15 - and (ss_list_price between 179 and 179+10 - or ss_coupon_amt between 10159 and 10159+1000 - or ss_wholesale_cost between 0 and 0+20)) B3, - (select avg(ss_list_price) B4_LP - ,count(ss_list_price) B4_CNT - ,count(distinct ss_list_price) B4_CNTD - from store_sales - where ss_quantity between 16 and 20 - and (ss_list_price between 67 and 67+10 - or ss_coupon_amt between 9737 and 9737+1000 - or ss_wholesale_cost between 60 and 60+20)) B4, - (select avg(ss_list_price) B5_LP - ,count(ss_list_price) B5_CNT - ,count(distinct ss_list_price) B5_CNTD - from store_sales - where ss_quantity between 21 and 25 - and (ss_list_price between 17 and 17+10 - or ss_coupon_amt between 10238 and 10238+1000 - or ss_wholesale_cost between 77 and 77+20)) B5, - (select avg(ss_list_price) B6_LP - ,count(ss_list_price) B6_CNT - ,count(distinct ss_list_price) B6_CNTD - from store_sales - where ss_quantity between 26 and 30 - and (ss_list_price between 155 and 155+10 - or ss_coupon_amt between 6021 and 6021+1000 - or ss_wholesale_cost between 30 and 30+20)) B6 -limit 100; - --- end template query28.tpl query 28 in stream 9 --- start template query42.tpl query 29 in stream 9 -select /* TPC-DS query42.tpl 0.61 */ dt.d_year - ,item.i_category_id - ,item.i_category - ,sum(ss_ext_sales_price) - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=11 - and dt.d_year=1998 - group by dt.d_year - ,item.i_category_id - ,item.i_category - order by sum(ss_ext_sales_price) desc,dt.d_year - ,item.i_category_id - ,item.i_category -limit 100 ; - --- end template query42.tpl query 29 in stream 9 --- start template query17.tpl query 30 in stream 9 -select /* TPC-DS query17.tpl 0.41 */ i_item_id - ,i_item_desc - ,s_state - ,count(ss_quantity) as store_sales_quantitycount - ,avg(ss_quantity) as store_sales_quantityave - ,stddev_samp(ss_quantity) as store_sales_quantitystdev - ,stddev_samp(ss_quantity)/avg(ss_quantity) as store_sales_quantitycov - ,count(sr_return_quantity) as store_returns_quantitycount - ,avg(sr_return_quantity) as store_returns_quantityave - ,stddev_samp(sr_return_quantity) as store_returns_quantitystdev - ,stddev_samp(sr_return_quantity)/avg(sr_return_quantity) as store_returns_quantitycov - ,count(cs_quantity) as catalog_sales_quantitycount ,avg(cs_quantity) as catalog_sales_quantityave - ,stddev_samp(cs_quantity) as catalog_sales_quantitystdev - ,stddev_samp(cs_quantity)/avg(cs_quantity) as catalog_sales_quantitycov - from store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where d1.d_quarter_name = '2000Q1' - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_quarter_name in ('2000Q1','2000Q2','2000Q3') - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_quarter_name in ('2000Q1','2000Q2','2000Q3') - group by i_item_id - ,i_item_desc - ,s_state - order by i_item_id - ,i_item_desc - ,s_state -limit 100; - --- end template query17.tpl query 30 in stream 9 --- start template query67a.tpl query 31 in stream 9 -with /* TPC-DS query67a.tpl 0.35 */ results as -( select i_category ,i_class ,i_brand ,i_product_name ,d_year ,d_qoy ,d_moy ,s_store_id - ,sum(coalesce(ss_sales_price*ss_quantity,0)) sumsales - from store_sales ,date_dim ,store ,item - where ss_sold_date_sk=d_date_sk - and ss_item_sk=i_item_sk - and ss_store_sk = s_store_sk - and d_month_seq between 1180 and 1180 + 11 - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy,s_store_id) - , - results_rollup as - (select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, s_store_id, sumsales - from results - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy - union all - select i_category, i_class, i_brand, i_product_name, d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year - union all - select i_category, i_class, i_brand, i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name - union all - select i_category, i_class, i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand - union all - select i_category, i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class - union all - select i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category - union all - select null i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results) - - select * -from (select i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rank() over (partition by i_category order by sumsales desc) rk - from results_rollup) dw2 -where rk <= 100 -order by i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rk -limit 100; - --- end template query67a.tpl query 31 in stream 9 --- start template query31.tpl query 32 in stream 9 -with /* TPC-DS query31.tpl 0.50 */ ss as - (select ca_county,d_qoy, d_year,sum(ss_ext_sales_price) as store_sales - from store_sales,date_dim,customer_address - where ss_sold_date_sk = d_date_sk - and ss_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year), - ws as - (select ca_county,d_qoy, d_year,sum(ws_ext_sales_price) as web_sales - from web_sales,date_dim,customer_address - where ws_sold_date_sk = d_date_sk - and ws_bill_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year) - select - ss1.ca_county - ,ss1.d_year - ,ws2.web_sales/ws1.web_sales web_q1_q2_increase - ,ss2.store_sales/ss1.store_sales store_q1_q2_increase - ,ws3.web_sales/ws2.web_sales web_q2_q3_increase - ,ss3.store_sales/ss2.store_sales store_q2_q3_increase - from - ss ss1 - ,ss ss2 - ,ss ss3 - ,ws ws1 - ,ws ws2 - ,ws ws3 - where - ss1.d_qoy = 1 - and ss1.d_year = 2002 - and ss1.ca_county = ss2.ca_county - and ss2.d_qoy = 2 - and ss2.d_year = 2002 - and ss2.ca_county = ss3.ca_county - and ss3.d_qoy = 3 - and ss3.d_year = 2002 - and ss1.ca_county = ws1.ca_county - and ws1.d_qoy = 1 - and ws1.d_year = 2002 - and ws1.ca_county = ws2.ca_county - and ws2.d_qoy = 2 - and ws2.d_year = 2002 - and ws1.ca_county = ws3.ca_county - and ws3.d_qoy = 3 - and ws3.d_year =2002 - and case when ws1.web_sales > 0 then ws2.web_sales/ws1.web_sales else null end - > case when ss1.store_sales > 0 then ss2.store_sales/ss1.store_sales else null end - and case when ws2.web_sales > 0 then ws3.web_sales/ws2.web_sales else null end - > case when ss2.store_sales > 0 then ss3.store_sales/ss2.store_sales else null end - order by ss1.d_year; - --- end template query31.tpl query 32 in stream 9 --- start template query20.tpl query 33 in stream 9 -select /* TPC-DS query20.tpl 0.65 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(cs_ext_sales_price) as itemrevenue - ,sum(cs_ext_sales_price)*100/sum(sum(cs_ext_sales_price)) over - (partition by i_class) as revenueratio - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and i_category in ('Jewelry', 'Music', 'Electronics') - and cs_sold_date_sk = d_date_sk - and d_date between cast('1999-05-31' as date) - and dateadd(day,30,cast('1999-05-31' as date)) - group by i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - order by i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query20.tpl query 33 in stream 9 --- start template query11.tpl query 34 in stream 9 -with /* TPC-DS query11.tpl 0.51 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ss_ext_list_price-ss_ext_discount_amt) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ws_ext_list_price-ws_ext_discount_amt) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_email_address - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 1999 - and t_s_secyear.dyear = 1999+1 - and t_w_firstyear.dyear = 1999 - and t_w_secyear.dyear = 1999+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else 0.0 end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else 0.0 end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_email_address -limit 100; - --- end template query11.tpl query 34 in stream 9 --- start template query77a.tpl query 35 in stream 9 -with /* TPC-DS query77a.tpl 0.78 */ ss as - (select s_store_sk, - sum(ss_ext_sales_price) as sales, - sum(ss_net_profit) as profit - from store_sales, - date_dim, - store - where ss_sold_date_sk = d_date_sk - and d_date between cast('2001-08-19' as date) - and dateadd(day,30,cast('2001-08-19' as date)) - and ss_store_sk = s_store_sk - group by s_store_sk) - , - sr as - (select s_store_sk, - sum(sr_return_amt) as returns, - sum(sr_net_loss) as profit_loss - from store_returns, - date_dim, - store - where sr_returned_date_sk = d_date_sk - and d_date between cast('2001-08-19' as date) - and dateadd(day,30,cast('2001-08-19' as date)) - and sr_store_sk = s_store_sk - group by s_store_sk), - cs as - (select cs_call_center_sk, - sum(cs_ext_sales_price) as sales, - sum(cs_net_profit) as profit - from catalog_sales, - date_dim - where cs_sold_date_sk = d_date_sk - and d_date between cast('2001-08-19' as date) - and dateadd(day,30,cast('2001-08-19' as date)) - group by cs_call_center_sk - ), - cr as - (select cr_call_center_sk, - sum(cr_return_amount) as returns, - sum(cr_net_loss) as profit_loss - from catalog_returns, - date_dim - where cr_returned_date_sk = d_date_sk - and d_date between cast('2001-08-19' as date) - and dateadd(day,30,cast('2001-08-19' as date)) - group by cr_call_center_sk), - ws as - ( select wp_web_page_sk, - sum(ws_ext_sales_price) as sales, - sum(ws_net_profit) as profit - from web_sales, - date_dim, - web_page - where ws_sold_date_sk = d_date_sk - and d_date between cast('2001-08-19' as date) - and dateadd(day,30,cast('2001-08-19' as date)) - and ws_web_page_sk = wp_web_page_sk - group by wp_web_page_sk), - wr as - (select wp_web_page_sk, - sum(wr_return_amt) as returns, - sum(wr_net_loss) as profit_loss - from web_returns, - date_dim, - web_page - where wr_returned_date_sk = d_date_sk - and d_date between cast('2001-08-19' as date) - and dateadd(day,30,cast('2001-08-19' as date)) - and wr_web_page_sk = wp_web_page_sk - group by wp_web_page_sk) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , ss.s_store_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ss left join sr - on ss.s_store_sk = sr.s_store_sk - union all - select 'catalog channel' as channel - , cs_call_center_sk as id - , sales - , returns - , (profit - profit_loss) as profit - from cs - , cr - union all - select 'web channel' as channel - , ws.wp_web_page_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ws left join wr - on ws.wp_web_page_sk = wr.wp_web_page_sk - ) x - group by channel, id ) - - select * - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results -) foo -order by channel, id - limit 100; - --- end template query77a.tpl query 35 in stream 9 --- start template query36a.tpl query 36 in stream 9 -with /* TPC-DS query36a.tpl 0.21 */ results as - (select - sum(ss_net_profit) as ss_net_profit, sum(ss_ext_sales_price) as ss_ext_sales_price, - sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin - ,i_category - ,i_class - ,0 as g_category, 0 as g_class - from - store_sales - ,date_dim d1 - ,item - ,store - where - d1.d_year = 1998 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and s_state in ('AL','MN','SC','GA', - 'MO','LA','MI','AL') - group by i_category,i_class) - , - results_rollup as - (select gross_margin ,i_category ,i_class,0 as t_category, 0 as t_class, 0 as lochierarchy from results - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - i_category, NULL AS i_class, 0 as t_category, 1 as t_class, 1 as lochierarchy from results group by i_category - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - NULL AS i_category ,NULL AS i_class, 1 as t_category, 1 as t_class, 2 as lochierarchy from results) - select - gross_margin ,i_category ,i_class, lochierarchy,rank() over ( - partition by lochierarchy, case when t_class = 0 then i_category end - order by gross_margin asc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then i_category end - ,rank_within_parent - limit 100; - --- end template query36a.tpl query 36 in stream 9 --- start template query82.tpl query 37 in stream 9 -select /* TPC-DS query82.tpl 0.67 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, store_sales - where i_current_price between 56 and 56+30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('1998-07-04' as date) and dateadd(day,60,cast('1998-07-04' as date)) - and i_manufact_id in (689,650,803,591) - and inv_quantity_on_hand between 100 and 500 - and ss_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query82.tpl query 37 in stream 9 --- start template query33.tpl query 38 in stream 9 -with /* TPC-DS query33.tpl 0.22 */ ss as ( - select - i_manufact_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Jewelry')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 4 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id), - cs as ( - select - i_manufact_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Jewelry')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 4 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id), - ws as ( - select - i_manufact_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Jewelry')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 4 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id) - select i_manufact_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_manufact_id - order by total_sales -limit 100; - --- end template query33.tpl query 38 in stream 9 --- start template query54.tpl query 39 in stream 9 -with /* TPC-DS query54.tpl 0.81 */ my_customers as ( - select distinct c_customer_sk - , c_current_addr_sk - from - ( select cs_sold_date_sk sold_date_sk, - cs_bill_customer_sk customer_sk, - cs_item_sk item_sk - from catalog_sales - union all - select ws_sold_date_sk sold_date_sk, - ws_bill_customer_sk customer_sk, - ws_item_sk item_sk - from web_sales - ) cs_or_ws_sales, - item, - date_dim, - customer - where sold_date_sk = d_date_sk - and item_sk = i_item_sk - and i_category = 'Home' - and i_class = 'mattresses' - and c_customer_sk = cs_or_ws_sales.customer_sk - and d_moy = 1 - and d_year = 2002 - ) - , my_revenue as ( - select c_customer_sk, - sum(ss_ext_sales_price) as revenue - from my_customers, - store_sales, - customer_address, - store, - date_dim - where c_current_addr_sk = ca_address_sk - and ca_county = s_county - and ca_state = s_state - and ss_sold_date_sk = d_date_sk - and c_customer_sk = ss_customer_sk - and d_month_seq between (select distinct d_month_seq+1 - from date_dim where d_year = 2002 and d_moy = 1) - and (select distinct d_month_seq+3 - from date_dim where d_year = 2002 and d_moy = 1) - group by c_customer_sk - ) - , segments as - (select cast((revenue/50) as int) as segment - from my_revenue - ) - select segment, count(*) as num_customers, segment*50 as segment_base - from segments - group by segment - order by segment, num_customers - limit 100; - --- end template query54.tpl query 39 in stream 9 --- start template query4.tpl query 40 in stream 9 -with /* TPC-DS query4.tpl 0.93 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(((ss_ext_list_price-ss_ext_wholesale_cost-ss_ext_discount_amt)+ss_ext_sales_price)/2) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((cs_ext_list_price-cs_ext_wholesale_cost-cs_ext_discount_amt)+cs_ext_sales_price)/2) ) year_total - ,'c' sale_type - from customer - ,catalog_sales - ,date_dim - where c_customer_sk = cs_bill_customer_sk - and cs_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year -union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((ws_ext_list_price-ws_ext_wholesale_cost-ws_ext_discount_amt)+ws_ext_sales_price)/2) ) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_preferred_cust_flag - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_c_firstyear - ,year_total t_c_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_c_secyear.customer_id - and t_s_firstyear.customer_id = t_c_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_c_firstyear.sale_type = 'c' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_c_secyear.sale_type = 'c' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 1998 - and t_s_secyear.dyear = 1998+1 - and t_c_firstyear.dyear = 1998 - and t_c_secyear.dyear = 1998+1 - and t_w_firstyear.dyear = 1998 - and t_w_secyear.dyear = 1998+1 - and t_s_firstyear.year_total > 0 - and t_c_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_preferred_cust_flag -limit 100; - --- end template query4.tpl query 40 in stream 9 --- start template query16.tpl query 41 in stream 9 -select /* TPC-DS query16.tpl 0.25 */ - count(distinct cs_order_number) as "order count" - ,sum(cs_ext_ship_cost) as "total shipping cost" - ,sum(cs_net_profit) as "total net profit" -from - catalog_sales cs1 - ,date_dim - ,customer_address - ,call_center -where - d_date between '2002-4-01' and - dateadd(day, 60, cast('2002-4-01' as date)) -and cs1.cs_ship_date_sk = d_date_sk -and cs1.cs_ship_addr_sk = ca_address_sk -and ca_state = 'CA' -and cs1.cs_call_center_sk = cc_call_center_sk -and cc_county in ('Pennington County','Levy County','Richland County','Walker County', - 'Mesa County' -) -and exists (select * - from catalog_sales cs2 - where cs1.cs_order_number = cs2.cs_order_number - and cs1.cs_warehouse_sk <> cs2.cs_warehouse_sk) -and not exists(select * - from catalog_returns cr1 - where cs1.cs_order_number = cr1.cr_order_number) -order by count(distinct cs_order_number) -limit 100; - --- end template query16.tpl query 41 in stream 9 --- start template query10.tpl query 42 in stream 9 -select /* TPC-DS query10.tpl 0.26 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3, - cd_dep_count, - count(*) cnt4, - cd_dep_employed_count, - count(*) cnt5, - cd_dep_college_count, - count(*) cnt6 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_county in ('Webster County','Los Angeles County','Floyd County','Early County','Gray County') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 4 and 4+3) and - (exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 4 ANd 4+3) or - exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 4 and 4+3)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count -limit 100; - --- end template query10.tpl query 42 in stream 9 --- start template query18a.tpl query 43 in stream 9 -with /* TPC-DS query18a.tpl 0.90 */ results as - (select i_item_id, - ca_country, - ca_state, - ca_county, - cast(cs_quantity as decimal(12,2)) agg1, - cast(cs_list_price as decimal(12,2)) agg2, - cast(cs_coupon_amt as decimal(12,2)) agg3, - cast(cs_sales_price as decimal(12,2)) agg4, - cast(cs_net_profit as decimal(12,2)) agg5, - cast(c_birth_year as decimal(12,2)) agg6, - cast(cd1.cd_dep_count as decimal(12,2)) agg7 - from catalog_sales, customer_demographics cd1, customer_demographics cd2, customer, customer_address, date_dim, item - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd1.cd_demo_sk and - cs_bill_customer_sk = c_customer_sk and - cd1.cd_gender = 'M' and - cd1.cd_education_status = 'Primary' and - c_current_cdemo_sk = cd2.cd_demo_sk and - c_current_addr_sk = ca_address_sk and - c_birth_month in (5,3,2,8,12,10) and - d_year = 2002 and - ca_state in ('KS','MS','NJ','IN','OK','TX','UT') - ) - select i_item_id, ca_country, ca_state, ca_county, agg1, agg2, agg3, agg4, agg5, agg6, agg7 - from ( - select i_item_id, ca_country, ca_state, ca_county, avg(agg1) agg1, - avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state, ca_county - union all - select i_item_id, ca_country, ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state - union all - select i_item_id, ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country - union all - select i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - ) foo - order by ca_country, ca_state, ca_county, i_item_id - limit 100; - --- end template query18a.tpl query 43 in stream 9 --- start template query48.tpl query 44 in stream 9 -select /* TPC-DS query48.tpl 0.74 */ sum (ss_quantity) - from store_sales, store, customer_demographics, customer_address, date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2001 - and - ( - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'W' - and - cd_education_status = 'College' - and - ss_sales_price between 100.00 and 150.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'U' - and - cd_education_status = 'Secondary' - and - ss_sales_price between 50.00 and 100.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'S' - and - cd_education_status = '2 yr Degree' - and - ss_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('GA', 'VA', 'TN') - and ss_net_profit between 0 and 2000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('FL', 'CT', 'PA') - and ss_net_profit between 150 and 3000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('MI', 'TX', 'IA') - and ss_net_profit between 50 and 25000 - ) - ) -; - --- end template query48.tpl query 44 in stream 9 --- start template query24.tpl query 45 in stream 9 -with /* TPC-DS query24.tpl 0.92 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_ext_sales_price) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip -and s_market_id=7 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'puff' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; -with /* TPC-DS query24.tpl 0.92 part2 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_ext_sales_price) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip - and s_market_id = 7 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'khaki' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; - --- end template query24.tpl query 45 in stream 9 --- start template query30.tpl query 46 in stream 9 -with /* TPC-DS query30.tpl 0.75 */ customer_total_return as - (select wr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(wr_return_amt) as ctr_total_return - from web_returns - ,date_dim - ,customer_address - where wr_returned_date_sk = d_date_sk - and d_year =2000 - and wr_returning_addr_sk = ca_address_sk - group by wr_returning_customer_sk - ,ca_state) - select c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'CA' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return -limit 100; - --- end template query30.tpl query 46 in stream 9 --- start template query78.tpl query 47 in stream 9 -with /* TPC-DS query78.tpl 0.10 */ ws as - (select d_year AS ws_sold_year, ws_item_sk, - ws_bill_customer_sk ws_customer_sk, - sum(ws_quantity) ws_qty, - sum(ws_wholesale_cost) ws_wc, - sum(ws_sales_price) ws_sp - from web_sales - left join web_returns on wr_order_number=ws_order_number and ws_item_sk=wr_item_sk - join date_dim on ws_sold_date_sk = d_date_sk - where wr_order_number is null - group by d_year, ws_item_sk, ws_bill_customer_sk - ), -cs as - (select d_year AS cs_sold_year, cs_item_sk, - cs_bill_customer_sk cs_customer_sk, - sum(cs_quantity) cs_qty, - sum(cs_wholesale_cost) cs_wc, - sum(cs_sales_price) cs_sp - from catalog_sales - left join catalog_returns on cr_order_number=cs_order_number and cs_item_sk=cr_item_sk - join date_dim on cs_sold_date_sk = d_date_sk - where cr_order_number is null - group by d_year, cs_item_sk, cs_bill_customer_sk - ), -ss as - (select d_year AS ss_sold_year, ss_item_sk, - ss_customer_sk, - sum(ss_quantity) ss_qty, - sum(ss_wholesale_cost) ss_wc, - sum(ss_sales_price) ss_sp - from store_sales - left join store_returns on sr_ticket_number=ss_ticket_number and ss_item_sk=sr_item_sk - join date_dim on ss_sold_date_sk = d_date_sk - where sr_ticket_number is null - group by d_year, ss_item_sk, ss_customer_sk - ) - select -ss_sold_year, -round(ss_qty/(coalesce(ws_qty,0)+coalesce(cs_qty,0)),2) ratio, -ss_qty store_qty, ss_wc store_wholesale_cost, ss_sp store_sales_price, -coalesce(ws_qty,0)+coalesce(cs_qty,0) other_chan_qty, -coalesce(ws_wc,0)+coalesce(cs_wc,0) other_chan_wholesale_cost, -coalesce(ws_sp,0)+coalesce(cs_sp,0) other_chan_sales_price -from ss -left join ws on (ws_sold_year=ss_sold_year and ws_item_sk=ss_item_sk and ws_customer_sk=ss_customer_sk) -left join cs on (cs_sold_year=ss_sold_year and cs_item_sk=ss_item_sk and cs_customer_sk=ss_customer_sk) -where (coalesce(ws_qty,0)>0 or coalesce(cs_qty, 0)>0) and ss_sold_year=2000 -order by - ss_sold_year, - ss_qty desc, ss_wc desc, ss_sp desc, - other_chan_qty, - other_chan_wholesale_cost, - other_chan_sales_price, - ratio -limit 100; - --- end template query78.tpl query 47 in stream 9 --- start template query6.tpl query 48 in stream 9 -select /* TPC-DS query6.tpl 0.58 */ a.ca_state state, count(*) cnt - from customer_address a - ,customer c - ,store_sales s - ,date_dim d - ,item i - where a.ca_address_sk = c.c_current_addr_sk - and c.c_customer_sk = s.ss_customer_sk - and s.ss_sold_date_sk = d.d_date_sk - and s.ss_item_sk = i.i_item_sk - and d.d_month_seq = - (select distinct (d_month_seq) - from date_dim - where d_year = 1998 - and d_moy = 3 ) - and i.i_current_price > 1.2 * - (select avg(j.i_current_price) - from item j - where j.i_category = i.i_category) - group by a.ca_state - having count(*) >= 10 - order by cnt, a.ca_state - limit 100; - --- end template query6.tpl query 48 in stream 9 --- start template query80a.tpl query 49 in stream 9 -with /* TPC-DS query80a.tpl 0.6 */ ssr as - (select s_store_id as store_id, - sum(ss_ext_sales_price) as sales, - sum(coalesce(sr_return_amt, 0)) as returns, - sum(ss_net_profit - coalesce(sr_net_loss, 0)) as profit - from store_sales left outer join store_returns on - (ss_item_sk = sr_item_sk and ss_ticket_number = sr_ticket_number), - date_dim, - store, - item, - promotion - where ss_sold_date_sk = d_date_sk - and d_date between cast('1999-08-29' as date) - and dateadd(day,30,cast('1999-08-29' as date)) - and ss_store_sk = s_store_sk - and ss_item_sk = i_item_sk - and i_current_price > 50 - and ss_promo_sk = p_promo_sk - and p_channel_tv = 'N' - group by s_store_id) - , - csr as - (select cp_catalog_page_id as catalog_page_id, - sum(cs_ext_sales_price) as sales, - sum(coalesce(cr_return_amount, 0)) as returns, - sum(cs_net_profit - coalesce(cr_net_loss, 0)) as profit - from catalog_sales left outer join catalog_returns on - (cs_item_sk = cr_item_sk and cs_order_number = cr_order_number), - date_dim, - catalog_page, - item, - promotion - where cs_sold_date_sk = d_date_sk - and d_date between cast('1999-08-29' as date) - and dateadd(day,30,cast('1999-08-29' as date)) - and cs_catalog_page_sk = cp_catalog_page_sk - and cs_item_sk = i_item_sk - and i_current_price > 50 - and cs_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(ws_ext_sales_price) as sales, - sum(coalesce(wr_return_amt, 0)) as returns, - sum(ws_net_profit - coalesce(wr_net_loss, 0)) as profit - from web_sales left outer join web_returns on - (ws_item_sk = wr_item_sk and ws_order_number = wr_order_number), - date_dim, - web_site, - item, - promotion - where ws_sold_date_sk = d_date_sk - and d_date between cast('1999-08-29' as date) - and dateadd(day,30,cast('1999-08-29' as date)) - and ws_web_site_sk = web_site_sk - and ws_item_sk = i_item_sk - and i_current_price > 50 - and ws_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by web_site_id) -, -results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || store_id as id - , sales - , returns - , profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || catalog_page_id as id - , sales - , returns - , profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , profit - from wsr - ) x - group by channel, id) - - select channel - , id - , sales - , returns - , profit - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results - ) foo - order by channel, id - limit 100; - --- end template query80a.tpl query 49 in stream 9 --- start template query35a.tpl query 50 in stream 9 -select /* TPC-DS query35a.tpl 0.47 */ - ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - count(*) cnt1, - avg(cd_dep_count), - avg(cd_dep_count), - max(cd_dep_count), - cd_dep_employed_count, - count(*) cnt2, - avg(cd_dep_employed_count), - avg(cd_dep_employed_count), - max(cd_dep_employed_count), - cd_dep_college_count, - count(*) cnt3, - avg(cd_dep_college_count), - avg(cd_dep_college_count), - max(cd_dep_college_count) - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2000 and - d_qoy < 4) and - exists (select * from - (select ws_bill_customer_sk customsk - from web_sales,date_dim - where - ws_sold_date_sk = d_date_sk and - d_year = 2000 and - d_qoy < 4 - union all - select cs_ship_customer_sk customsk - from catalog_sales,date_dim - where - cs_sold_date_sk = d_date_sk and - d_year = 2000 and - d_qoy < 4)x - where x.customsk = c.c_customer_sk) - group by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - limit 100; - --- end template query35a.tpl query 50 in stream 9 --- start template query59.tpl query 51 in stream 9 -with /* TPC-DS query59.tpl 0.30 */ wss as - (select d_week_seq, - ss_store_sk, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - group by d_week_seq,ss_store_sk - ) - select s_store_name1,s_store_id1,d_week_seq1 - ,sun_sales1/sun_sales2,mon_sales1/mon_sales2 - ,tue_sales1/tue_sales2,wed_sales1/wed_sales2,thu_sales1/thu_sales2 - ,fri_sales1/fri_sales2,sat_sales1/sat_sales2 - from - (select s_store_name s_store_name1,wss.d_week_seq d_week_seq1 - ,s_store_id s_store_id1,sun_sales sun_sales1 - ,mon_sales mon_sales1,tue_sales tue_sales1 - ,wed_sales wed_sales1,thu_sales thu_sales1 - ,fri_sales fri_sales1,sat_sales sat_sales1 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1201 and 1201 + 11) y, - (select s_store_name s_store_name2,wss.d_week_seq d_week_seq2 - ,s_store_id s_store_id2,sun_sales sun_sales2 - ,mon_sales mon_sales2,tue_sales tue_sales2 - ,wed_sales wed_sales2,thu_sales thu_sales2 - ,fri_sales fri_sales2,sat_sales sat_sales2 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1201+ 12 and 1201 + 23) x - where s_store_id1=s_store_id2 - and d_week_seq1=d_week_seq2-52 - order by s_store_name1,s_store_id1,d_week_seq1 -limit 100; - --- end template query59.tpl query 51 in stream 9 --- start template query99.tpl query 52 in stream 9 -select /* TPC-DS query99.tpl 0.94 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 30) and - (cs_ship_date_sk - cs_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 60) and - (cs_ship_date_sk - cs_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 90) and - (cs_ship_date_sk - cs_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - catalog_sales - ,warehouse - ,ship_mode - ,call_center - ,date_dim -where - d_month_seq between 1186 and 1186 + 11 -and cs_ship_date_sk = d_date_sk -and cs_warehouse_sk = w_warehouse_sk -and cs_ship_mode_sk = sm_ship_mode_sk -and cs_call_center_sk = cc_call_center_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -limit 100; - --- end template query99.tpl query 52 in stream 9 --- start template query61.tpl query 53 in stream 9 -select /* TPC-DS query61.tpl 0.97 */ promotions,total,cast(promotions as decimal(15,4))/cast(total as decimal(15,4))*100 -from - (select sum(ss_ext_sales_price) promotions - from store_sales - ,store - ,promotion - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_promo_sk = p_promo_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -6 - and i_category = 'Jewelry' - and (p_channel_dmail = 'Y' or p_channel_email = 'Y' or p_channel_tv = 'Y') - and s_gmt_offset = -6 - and d_year = 1998 - and d_moy = 12) promotional_sales, - (select sum(ss_ext_sales_price) total - from store_sales - ,store - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -6 - and i_category = 'Jewelry' - and s_gmt_offset = -6 - and d_year = 1998 - and d_moy = 12) all_sales -order by promotions, total -limit 100; - --- end template query61.tpl query 53 in stream 9 --- start template query22a.tpl query 54 in stream 9 -with /* TPC-DS query22a.tpl 0.55 */ results as -(select i_product_name - ,i_brand - ,i_class - ,i_category - ,avg(inv_quantity_on_hand) qoh - from inventory - ,date_dim - ,item --- ,warehouse - where inv_date_sk=d_date_sk - and inv_item_sk=i_item_sk --- and inv_warehouse_sk = w_warehouse_sk - and d_month_seq between 1202 and 1202 + 11 - group by i_product_name,i_brand,i_class,i_category), -results_rollup as -(select i_product_name, i_brand, i_class, i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class,i_category -union all -select i_product_name, i_brand, i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class -union all -select i_product_name, i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand -union all -select i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name -union all -select null i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results) - select i_product_name, i_brand, i_class, i_category,qoh - from results_rollup - order by qoh, i_product_name, i_brand, i_class, i_category -limit 100; - --- end template query22a.tpl query 54 in stream 9 --- start template query71.tpl query 55 in stream 9 -select /* TPC-DS query71.tpl 0.72 */ i_brand_id brand_id, i_brand brand,t_hour,t_minute, - sum(ext_price) ext_price - from item, (select ws_ext_sales_price as ext_price, - ws_sold_date_sk as sold_date_sk, - ws_item_sk as sold_item_sk, - ws_sold_time_sk as time_sk - from web_sales,date_dim - where d_date_sk = ws_sold_date_sk - and d_moy=11 - and d_year=2000 - union all - select cs_ext_sales_price as ext_price, - cs_sold_date_sk as sold_date_sk, - cs_item_sk as sold_item_sk, - cs_sold_time_sk as time_sk - from catalog_sales,date_dim - where d_date_sk = cs_sold_date_sk - and d_moy=11 - and d_year=2000 - union all - select ss_ext_sales_price as ext_price, - ss_sold_date_sk as sold_date_sk, - ss_item_sk as sold_item_sk, - ss_sold_time_sk as time_sk - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - and d_moy=11 - and d_year=2000 - ) tmp,time_dim - where - sold_item_sk = i_item_sk - and i_manager_id=1 - and time_sk = t_time_sk - and (t_meal_time = 'breakfast' or t_meal_time = 'dinner') - group by i_brand, i_brand_id,t_hour,t_minute - order by ext_price desc, i_brand_id - ; - --- end template query71.tpl query 55 in stream 9 --- start template query68.tpl query 56 in stream 9 -select /* TPC-DS query68.tpl 0.95 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,extended_price - ,extended_tax - ,list_price - from (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_ext_sales_price) extended_price - ,sum(ss_ext_list_price) list_price - ,sum(ss_ext_tax) extended_tax - from store_sales - ,date_dim - ,store - ,household_demographics - ,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_dep_count = 7 or - household_demographics.hd_vehicle_count= 0) - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_city in ('Springfield','Lincoln') - group by ss_ticket_number - ,ss_customer_sk - ,ss_addr_sk,ca_city) dn - ,customer - ,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,ss_ticket_number - limit 100; - --- end template query68.tpl query 56 in stream 9 --- start template query40.tpl query 57 in stream 9 -select /* TPC-DS query40.tpl 0.86 */ - w_state - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('2000-03-07' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_before - ,sum(case when (cast(d_date as date) >= cast ('2000-03-07' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_after - from - catalog_sales left outer join catalog_returns on - (cs_order_number = cr_order_number - and cs_item_sk = cr_item_sk) - ,warehouse - ,item - ,date_dim - where - i_current_price between 0.99 and 1.49 - and i_item_sk = cs_item_sk - and cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('2000-03-07' as date)) - and dateadd(day,30,cast ('2000-03-07' as date)) - group by - w_state,i_item_id - order by w_state,i_item_id -limit 100; - --- end template query40.tpl query 57 in stream 9 --- start template query66.tpl query 58 in stream 9 -select /* TPC-DS query66.tpl 0.39 */ - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - ,sum(jan_sales) as jan_sales - ,sum(feb_sales) as feb_sales - ,sum(mar_sales) as mar_sales - ,sum(apr_sales) as apr_sales - ,sum(may_sales) as may_sales - ,sum(jun_sales) as jun_sales - ,sum(jul_sales) as jul_sales - ,sum(aug_sales) as aug_sales - ,sum(sep_sales) as sep_sales - ,sum(oct_sales) as oct_sales - ,sum(nov_sales) as nov_sales - ,sum(dec_sales) as dec_sales - ,sum(jan_sales/w_warehouse_sq_ft) as jan_sales_per_sq_foot - ,sum(feb_sales/w_warehouse_sq_ft) as feb_sales_per_sq_foot - ,sum(mar_sales/w_warehouse_sq_ft) as mar_sales_per_sq_foot - ,sum(apr_sales/w_warehouse_sq_ft) as apr_sales_per_sq_foot - ,sum(may_sales/w_warehouse_sq_ft) as may_sales_per_sq_foot - ,sum(jun_sales/w_warehouse_sq_ft) as jun_sales_per_sq_foot - ,sum(jul_sales/w_warehouse_sq_ft) as jul_sales_per_sq_foot - ,sum(aug_sales/w_warehouse_sq_ft) as aug_sales_per_sq_foot - ,sum(sep_sales/w_warehouse_sq_ft) as sep_sales_per_sq_foot - ,sum(oct_sales/w_warehouse_sq_ft) as oct_sales_per_sq_foot - ,sum(nov_sales/w_warehouse_sq_ft) as nov_sales_per_sq_foot - ,sum(dec_sales/w_warehouse_sq_ft) as dec_sales_per_sq_foot - ,sum(jan_net) as jan_net - ,sum(feb_net) as feb_net - ,sum(mar_net) as mar_net - ,sum(apr_net) as apr_net - ,sum(may_net) as may_net - ,sum(jun_net) as jun_net - ,sum(jul_net) as jul_net - ,sum(aug_net) as aug_net - ,sum(sep_net) as sep_net - ,sum(oct_net) as oct_net - ,sum(nov_net) as nov_net - ,sum(dec_net) as dec_net - from ( - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'HARMSTORF' || ',' || 'UPS' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then ws_ext_list_price* ws_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then ws_ext_list_price* ws_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then ws_ext_list_price* ws_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then ws_ext_list_price* ws_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then ws_ext_list_price* ws_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then ws_ext_list_price* ws_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then ws_ext_list_price* ws_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then ws_ext_list_price* ws_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then ws_ext_list_price* ws_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then ws_ext_list_price* ws_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then ws_ext_list_price* ws_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then ws_ext_list_price* ws_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as dec_net - from - web_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - ws_warehouse_sk = w_warehouse_sk - and ws_sold_date_sk = d_date_sk - and ws_sold_time_sk = t_time_sk - and ws_ship_mode_sk = sm_ship_mode_sk - and d_year = 1999 - and t_time between 54112 and 54112+28800 - and sm_carrier in ('HARMSTORF','UPS') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - union all - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'HARMSTORF' || ',' || 'UPS' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then cs_ext_sales_price* cs_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then cs_ext_sales_price* cs_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then cs_ext_sales_price* cs_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then cs_ext_sales_price* cs_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then cs_ext_sales_price* cs_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then cs_ext_sales_price* cs_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then cs_ext_sales_price* cs_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then cs_ext_sales_price* cs_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then cs_ext_sales_price* cs_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then cs_ext_sales_price* cs_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then cs_ext_sales_price* cs_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then cs_ext_sales_price* cs_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as dec_net - from - catalog_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and cs_sold_time_sk = t_time_sk - and cs_ship_mode_sk = sm_ship_mode_sk - and d_year = 1999 - and t_time between 54112 AND 54112+28800 - and sm_carrier in ('HARMSTORF','UPS') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - ) x - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - order by w_warehouse_name - limit 100; - --- end template query66.tpl query 58 in stream 9 --- start template query94.tpl query 59 in stream 9 -select /* TPC-DS query94.tpl 0.17 */ - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2001-2-01' and - dateadd(day,60,cast('2001-2-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'VA' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and exists (select * - from web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) -and not exists(select * - from web_returns wr1 - where ws1.ws_order_number = wr1.wr_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query94.tpl query 59 in stream 9 --- start template query47.tpl query 60 in stream 9 -with /* TPC-DS query47.tpl 0.42 */ v1 as( - select i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, - s_store_name, s_company_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - s_store_name, s_company_name - order by d_year, d_moy) rn - from item, store_sales, date_dim, store - where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - ( - d_year = 2000 or - ( d_year = 2000-1 and d_moy =12) or - ( d_year = 2000+1 and d_moy =1) - ) - group by i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy), - v2 as( - select v1.i_brand - ,v1.d_year - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1.s_store_name = v1_lag.s_store_name and - v1.s_store_name = v1_lead.s_store_name and - v1.s_company_name = v1_lag.s_company_name and - v1.s_company_name = v1_lead.s_company_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 2000 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, avg_monthly_sales - limit 100; - --- end template query47.tpl query 60 in stream 9 --- start template query26.tpl query 61 in stream 9 -select /* TPC-DS query26.tpl 0.85 */ i_item_id, - avg(cs_quantity) agg1, - avg(cs_list_price) agg2, - avg(cs_coupon_amt) agg3, - avg(cs_sales_price) agg4 - from catalog_sales, customer_demographics, date_dim, item, promotion - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd_demo_sk and - cs_promo_sk = p_promo_sk and - cd_gender = 'M' and - cd_marital_status = 'S' and - cd_education_status = 'Unknown' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 2000 - group by i_item_id - order by i_item_id - limit 100; - --- end template query26.tpl query 61 in stream 9 --- start template query25.tpl query 62 in stream 9 -select /* TPC-DS query25.tpl 0.9 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,stddev_samp(ss_net_profit) as store_sales_profit - ,stddev_samp(sr_net_loss) as store_returns_loss - ,stddev_samp(cs_net_profit) as catalog_sales_profit - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 1998 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 10 - and d2.d_year = 1998 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_moy between 4 and 10 - and d3.d_year = 1998 - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query25.tpl query 62 in stream 9 --- start template query98.tpl query 63 in stream 9 -select /* TPC-DS query98.tpl 0.32 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ss_ext_sales_price) as itemrevenue - ,sum(ss_ext_sales_price)*100/sum(sum(ss_ext_sales_price)) over - (partition by i_class) as revenueratio -from - store_sales - ,item - ,date_dim -where - ss_item_sk = i_item_sk - and i_category in ('Jewelry', 'Sports', 'Women') - and ss_sold_date_sk = d_date_sk - and d_date between cast('2000-02-12' as date) - and dateadd(day,30,cast('2000-02-12' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio; - --- end template query98.tpl query 63 in stream 9 --- start template query70a.tpl query 64 in stream 9 -with /* TPC-DS query70a.tpl 0.34 */ results as -( select - sum(ss_net_profit) as total_sum ,s_state ,s_county, 0 as gstate, 0 as g_county - from - store_sales - ,date_dim d1 - ,store - where - d1.d_month_seq between 1212 and 1212 + 11 - and d1.d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - and s_state in - ( select s_state - from (select s_state as s_state, - rank() over ( partition by s_state order by sum(ss_net_profit) desc) as ranking - from store_sales, store, date_dim - where d_month_seq between 1212 and 1212 + 11 - and d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - group by s_state - ) tmp1 - where ranking <= 5) - group by s_state,s_county) , - results_rollup as -(select total_sum ,s_state ,s_county, 0 as g_state, 0 as g_county, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum,s_state, NULL as s_county, 0 as g_state, 1 as g_county, 1 as lochierarchy from results group by s_state - union - select sum(total_sum) as total_sum ,NULL as s_state ,NULL as s_county, 1 as g_state, 1 as g_county, 2 as lochierarchy from results) - select total_sum ,s_state ,s_county, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_county = 0 then s_state end - order by total_sum desc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then s_state end - ,rank_within_parent - limit 100; - --- end template query70a.tpl query 64 in stream 9 --- start template query73.tpl query 65 in stream 9 -select /* TPC-DS query73.tpl 0.79 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_buy_potential = '501-1000' or - household_demographics.hd_buy_potential = '0-500') - and household_demographics.hd_vehicle_count > 0 - and case when household_demographics.hd_vehicle_count > 0 then - household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count else null end > 1 - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_county in ('Fairfield County','Walker County','Arthur County','San Miguel County') - group by ss_ticket_number,ss_customer_sk) dj,customer - where ss_customer_sk = c_customer_sk - and cnt between 1 and 5 - order by cnt desc, c_last_name asc; - --- end template query73.tpl query 65 in stream 9 --- start template query38.tpl query 66 in stream 9 -select /* TPC-DS query38.tpl 0.54 */ count(*) from ( - select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1205 and 1205 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1205 and 1205 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1205 and 1205 + 11 -) hot_cust -limit 100; - --- end template query38.tpl query 66 in stream 9 --- start template query87.tpl query 67 in stream 9 -select /* TPC-DS query87.tpl 0.77 */ count(*) -from ((select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1203 and 1203+11) - except - (select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1203 and 1203+11) - except - (select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1203 and 1203+11) -) cool_cust -; - --- end template query87.tpl query 67 in stream 9 --- start template query3.tpl query 68 in stream 9 -select /* TPC-DS query3.tpl 0.45 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_net_profit) sum_agg - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manufact_id = 526 - and dt.d_moy=11 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,sum_agg desc - ,brand_id - limit 100; - --- end template query3.tpl query 68 in stream 9 --- start template query69.tpl query 69 in stream 9 -select /* TPC-DS query69.tpl 0.28 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_state in ('NE','GA','OH') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2001 and - d_moy between 3 and 3+2) and - (not exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2001 and - d_moy between 3 and 3+2) and - not exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2001 and - d_moy between 3 and 3+2)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - limit 100; - --- end template query69.tpl query 69 in stream 9 --- start template query86a.tpl query 70 in stream 9 -with /* TPC-DS query86a.tpl 0.11 */ results as -( select sum(ws_net_paid) as total_sum, i_category, i_class, 0 as g_category, 0 as g_class - from - web_sales - ,date_dim d1 - ,item - where - d1.d_month_seq between 1184 and 1184+11 - and d1.d_date_sk = ws_sold_date_sk - and i_item_sk = ws_item_sk - group by i_category,i_class - ) , - - results_rollup as -( select total_sum ,i_category ,i_class, g_category, g_class, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum, i_category, NULL as i_class, 0 as g_category, 1 as g_class, 1 as lochierarchy from results group by i_category - union - select sum(total_sum) as total_sum, NULL as i_category, NULL as i_class, 1 as g_category, 1 as g_class, 2 as lochierarchy from results) - select - total_sum ,i_category ,i_class, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_class = 0 then i_category end - order by total_sum desc) as rank_within_parent - from - results_rollup - order by - lochierarchy desc, - case when lochierarchy = 0 then i_category end, - rank_within_parent - limit 100; - --- end template query86a.tpl query 70 in stream 9 --- start template query79.tpl query 71 in stream 9 -select /* TPC-DS query79.tpl 0.89 */ - c_last_name,c_first_name,substring(s_city,1,30),ss_ticket_number,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,store.s_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (household_demographics.hd_dep_count = 1 or household_demographics.hd_vehicle_count > 3) - and date_dim.d_dow = 1 - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_number_employees between 200 and 295 - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,store.s_city) ms,customer - where ss_customer_sk = c_customer_sk - order by c_last_name,c_first_name,substring(s_city,1,30), profit -limit 100; - --- end template query79.tpl query 71 in stream 9 --- start template query89.tpl query 72 in stream 9 -select /* TPC-DS query89.tpl 0.56 */ * -from( -select i_category, i_class, i_brand, - s_store_name, s_company_name, - d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, s_store_name, s_company_name) - avg_monthly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - d_year in (2001) and - ((i_category in ('Sports','Home','Jewelry') and - i_class in ('basketball','kids','custom') - ) - or (i_category in ('Women','Music','Electronics') and - i_class in ('fragrances','country','stereo') - )) -group by i_category, i_class, i_brand, - s_store_name, s_company_name, d_moy) tmp1 -where case when (avg_monthly_sales <> 0) then (abs(sum_sales - avg_monthly_sales) / avg_monthly_sales) else null end > 0.1 -order by sum_sales - avg_monthly_sales, s_store_name -limit 100; - --- end template query89.tpl query 72 in stream 9 --- start template query51.tpl query 73 in stream 9 -WITH /* TPC-DS query51.tpl 0.46 */ web_v1 as ( -select - ws_item_sk item_sk, d_date, - sum(sum(ws_sales_price)) - over (partition by ws_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from web_sales - ,date_dim -where ws_sold_date_sk=d_date_sk - and d_month_seq between 1189 and 1189+11 - and ws_item_sk is not NULL -group by ws_item_sk, d_date), -store_v1 as ( -select - ss_item_sk item_sk, d_date, - sum(sum(ss_sales_price)) - over (partition by ss_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from store_sales - ,date_dim -where ss_sold_date_sk=d_date_sk - and d_month_seq between 1189 and 1189+11 - and ss_item_sk is not NULL -group by ss_item_sk, d_date) - select * -from (select item_sk - ,d_date - ,web_sales - ,store_sales - ,max(web_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) web_cumulative - ,max(store_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) store_cumulative - from (select case when web.item_sk is not null then web.item_sk else store.item_sk end item_sk - ,case when web.d_date is not null then web.d_date else store.d_date end d_date - ,web.cume_sales web_sales - ,store.cume_sales store_sales - from web_v1 web full outer join store_v1 store on (web.item_sk = store.item_sk - and web.d_date = store.d_date) - )x )y -where web_cumulative > store_cumulative -order by item_sk - ,d_date -limit 100; - --- end template query51.tpl query 73 in stream 9 --- start template query58.tpl query 74 in stream 9 -with /* TPC-DS query58.tpl 0.19 */ ss_items as - (select i_item_id item_id - ,sum(ss_ext_sales_price) ss_item_rev - from store_sales - ,item - ,date_dim - where ss_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '1999-07-04')) - and ss_sold_date_sk = d_date_sk - group by i_item_id), - cs_items as - (select i_item_id item_id - ,sum(cs_ext_sales_price) cs_item_rev - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '1999-07-04')) - and cs_sold_date_sk = d_date_sk - group by i_item_id), - ws_items as - (select i_item_id item_id - ,sum(ws_ext_sales_price) ws_item_rev - from web_sales - ,item - ,date_dim - where ws_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq =(select d_week_seq - from date_dim - where d_date = '1999-07-04')) - and ws_sold_date_sk = d_date_sk - group by i_item_id) - select ss_items.item_id - ,ss_item_rev - ,ss_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ss_dev - ,cs_item_rev - ,cs_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 cs_dev - ,ws_item_rev - ,ws_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ws_dev - ,(ss_item_rev+cs_item_rev+ws_item_rev)/3 average - from ss_items,cs_items,ws_items - where ss_items.item_id=cs_items.item_id - and ss_items.item_id=ws_items.item_id - and ss_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - and ss_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and cs_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and cs_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and ws_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and ws_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - order by item_id - ,ss_item_rev - limit 100; - --- end template query58.tpl query 74 in stream 9 --- start template query41.tpl query 75 in stream 9 -select /* TPC-DS query41.tpl 0.62 */ distinct(i_product_name) - from item i1 - where i_manufact_id between 671 and 671+40 - and (select count(*) as item_cnt - from item - where (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'peru' or i_color = 'blush') and - (i_units = 'Each' or i_units = 'Lb') and - (i_size = 'extra large' or i_size = 'small') - ) or - (i_category = 'Women' and - (i_color = 'lace' or i_color = 'burnished') and - (i_units = 'Case' or i_units = 'Bunch') and - (i_size = 'petite' or i_size = 'economy') - ) or - (i_category = 'Men' and - (i_color = 'turquoise' or i_color = 'snow') and - (i_units = 'Box' or i_units = 'Oz') and - (i_size = 'large' or i_size = 'N/A') - ) or - (i_category = 'Men' and - (i_color = 'dodger' or i_color = 'spring') and - (i_units = 'N/A' or i_units = 'Dram') and - (i_size = 'extra large' or i_size = 'small') - ))) or - (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'plum' or i_color = 'orange') and - (i_units = 'Bundle' or i_units = 'Cup') and - (i_size = 'extra large' or i_size = 'small') - ) or - (i_category = 'Women' and - (i_color = 'dark' or i_color = 'ghost') and - (i_units = 'Gram' or i_units = 'Pound') and - (i_size = 'petite' or i_size = 'economy') - ) or - (i_category = 'Men' and - (i_color = 'cyan' or i_color = 'dim') and - (i_units = 'Tsp' or i_units = 'Pallet') and - (i_size = 'large' or i_size = 'N/A') - ) or - (i_category = 'Men' and - (i_color = 'chartreuse' or i_color = 'deep') and - (i_units = 'Dozen' or i_units = 'Carton') and - (i_size = 'extra large' or i_size = 'small') - )))) > 0 - order by i_product_name - limit 100; - --- end template query41.tpl query 75 in stream 9 --- start template query19.tpl query 76 in stream 9 -select /* TPC-DS query19.tpl 0.8 */ i_brand_id brand_id, i_brand brand, i_manufact_id, i_manufact, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item,customer,customer_address,store - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=14 - and d_moy=11 - and d_year=1998 - and ss_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and substring(ca_zip,1,5) <> substring(s_zip,1,5) - and ss_store_sk = s_store_sk - group by i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact - order by ext_price desc - ,i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact -limit 100 ; - --- end template query19.tpl query 76 in stream 9 --- start template query83.tpl query 77 in stream 9 -with /* TPC-DS query83.tpl 0.96 */ sr_items as - (select i_item_id item_id, - sum(sr_return_quantity) sr_item_qty - from store_returns, - item, - date_dim - where sr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2000-02-07','2000-09-27','2000-11-20'))) - and sr_returned_date_sk = d_date_sk - group by i_item_id), - cr_items as - (select i_item_id item_id, - sum(cr_return_quantity) cr_item_qty - from catalog_returns, - item, - date_dim - where cr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2000-02-07','2000-09-27','2000-11-20'))) - and cr_returned_date_sk = d_date_sk - group by i_item_id), - wr_items as - (select i_item_id item_id, - sum(wr_return_quantity) wr_item_qty - from web_returns, - item, - date_dim - where wr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2000-02-07','2000-09-27','2000-11-20'))) - and wr_returned_date_sk = d_date_sk - group by i_item_id) - select sr_items.item_id - ,sr_item_qty - ,sr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 sr_dev - ,cr_item_qty - ,cr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 cr_dev - ,wr_item_qty - ,wr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 wr_dev - ,(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 average - from sr_items - ,cr_items - ,wr_items - where sr_items.item_id=cr_items.item_id - and sr_items.item_id=wr_items.item_id - order by sr_items.item_id - ,sr_item_qty - limit 100; - --- end template query83.tpl query 77 in stream 9 --- start template query96.tpl query 78 in stream 9 -select /* TPC-DS query96.tpl 0.1 */ count(*) -from store_sales - ,household_demographics - ,time_dim, store -where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 16 - and time_dim.t_minute >= 30 - and household_demographics.hd_dep_count = 9 - and store.s_store_name = 'ese' -order by count(*) -limit 100; - --- end template query96.tpl query 78 in stream 9 --- start template query46.tpl query 79 in stream 9 -select /* TPC-DS query46.tpl 0.23 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and (household_demographics.hd_dep_count = 6 or - household_demographics.hd_vehicle_count= 2) - and date_dim.d_dow in (6,0) - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_city in ('Crossroads','Oakland','Lakeview','Mount Vernon','Edgewood') - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,ca_city) dn,customer,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - limit 100; - --- end template query46.tpl query 79 in stream 9 --- start template query53.tpl query 80 in stream 9 -select /* TPC-DS query53.tpl 0.88 */ * from -(select i_manufact_id, -sum(ss_sales_price) sum_sales, -avg(sum(ss_sales_price)) over (partition by i_manufact_id) avg_quarterly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and -ss_sold_date_sk = d_date_sk and -ss_store_sk = s_store_sk and -d_month_seq in (1185,1185+1,1185+2,1185+3,1185+4,1185+5,1185+6,1185+7,1185+8,1185+9,1185+10,1185+11) and -((i_category in ('Books','Children','Electronics') and -i_class in ('personal','portable','reference','self-help') and -i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) -or(i_category in ('Women','Music','Men') and -i_class in ('accessories','classical','fragrances','pants') and -i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manufact_id, d_qoy ) tmp1 -where case when avg_quarterly_sales > 0 - then abs (sum_sales - avg_quarterly_sales)/ avg_quarterly_sales - else null end > 0.1 -order by avg_quarterly_sales, - sum_sales, - i_manufact_id -limit 100; - --- end template query53.tpl query 80 in stream 9 --- start template query55.tpl query 81 in stream 9 -select /* TPC-DS query55.tpl 0.82 */ i_brand_id brand_id, i_brand brand, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=3 - and d_moy=12 - and d_year=1999 - group by i_brand, i_brand_id - order by ext_price desc, i_brand_id -limit 100 ; - --- end template query55.tpl query 81 in stream 9 --- start template query72.tpl query 82 in stream 9 -select /* TPC-DS query72.tpl 0.87 */ i_item_desc - ,w_warehouse_name - ,d1.d_week_seq - ,sum(case when p_promo_sk is null then 1 else 0 end) no_promo - ,sum(case when p_promo_sk is not null then 1 else 0 end) promo - ,count(*) total_cnt -from catalog_sales -join inventory on (cs_item_sk = inv_item_sk) -join warehouse on (w_warehouse_sk=inv_warehouse_sk) -join item on (i_item_sk = cs_item_sk) -join customer_demographics on (cs_bill_cdemo_sk = cd_demo_sk) -join household_demographics on (cs_bill_hdemo_sk = hd_demo_sk) -join date_dim d1 on (cs_sold_date_sk = d1.d_date_sk) -join date_dim d2 on (inv_date_sk = d2.d_date_sk) -join date_dim d3 on (cs_ship_date_sk = d3.d_date_sk) -left outer join promotion on (cs_promo_sk=p_promo_sk) -left outer join catalog_returns on (cr_item_sk = cs_item_sk and cr_order_number = cs_order_number) -where d1.d_week_seq = d2.d_week_seq - and inv_quantity_on_hand < cs_quantity - and d3.d_date > d1.d_date + 5 - and hd_buy_potential = '1001-5000' - and d1.d_year = 1998 - and cd_marital_status = 'S' -group by i_item_desc,w_warehouse_name,d1.d_week_seq -order by total_cnt desc, i_item_desc, w_warehouse_name, d_week_seq -limit 100; - --- end template query72.tpl query 82 in stream 9 --- start template query95.tpl query 83 in stream 9 -with /* TPC-DS query95.tpl 0.43 */ ws_wh as -(select ws1.ws_order_number,ws1.ws_warehouse_sk wh1,ws2.ws_warehouse_sk wh2 - from web_sales ws1,web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) - select - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '1999-2-01' and - dateadd(day,60,cast('1999-2-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'TN' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and ws1.ws_order_number in (select ws_order_number - from ws_wh) -and ws1.ws_order_number in (select wr_order_number - from web_returns,ws_wh - where wr_order_number = ws_wh.ws_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query95.tpl query 83 in stream 9 --- start template query29.tpl query 84 in stream 9 -select /* TPC-DS query29.tpl 0.53 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,stddev_samp(ss_quantity) as store_sales_quantity - ,stddev_samp(sr_return_quantity) as store_returns_quantity - ,stddev_samp(cs_quantity) as catalog_sales_quantity - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 1998 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 4 + 3 - and d2.d_year = 1998 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_year in (1998,1998+1,1998+2) - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query29.tpl query 84 in stream 9 --- start template query64.tpl query 85 in stream 9 -with /* TPC-DS query64.tpl 0.20 */ cs_ui as - (select cs_item_sk - ,sum(cs_ext_list_price) as sale,sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit) as refund - from catalog_sales - ,catalog_returns - where cs_item_sk = cr_item_sk - and cs_order_number = cr_order_number - group by cs_item_sk - having sum(cs_ext_list_price)>2*sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit)), -cross_sales as - (select i_product_name product_name - ,i_item_sk item_sk - ,s_store_name store_name - ,s_zip store_zip - ,ad1.ca_street_number b_street_number - ,ad1.ca_street_name b_street_name - ,ad1.ca_city b_city - ,ad1.ca_zip b_zip - ,ad2.ca_street_number c_street_number - ,ad2.ca_street_name c_street_name - ,ad2.ca_city c_city - ,ad2.ca_zip c_zip - ,d1.d_year as syear - ,d2.d_year as fsyear - ,d3.d_year s2year - ,count(*) cnt - ,sum(ss_wholesale_cost) s1 - ,sum(ss_list_price) s2 - ,sum(ss_coupon_amt) s3 - FROM store_sales - ,store_returns - ,cs_ui - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,customer - ,customer_demographics cd1 - ,customer_demographics cd2 - ,promotion - ,household_demographics hd1 - ,household_demographics hd2 - ,customer_address ad1 - ,customer_address ad2 - ,income_band ib1 - ,income_band ib2 - ,item - WHERE ss_store_sk = s_store_sk AND - ss_sold_date_sk = d1.d_date_sk AND - ss_customer_sk = c_customer_sk AND - ss_cdemo_sk= cd1.cd_demo_sk AND - ss_hdemo_sk = hd1.hd_demo_sk AND - ss_addr_sk = ad1.ca_address_sk and - ss_item_sk = i_item_sk and - ss_item_sk = sr_item_sk and - ss_ticket_number = sr_ticket_number and - ss_item_sk = cs_ui.cs_item_sk and - c_current_cdemo_sk = cd2.cd_demo_sk AND - c_current_hdemo_sk = hd2.hd_demo_sk AND - c_current_addr_sk = ad2.ca_address_sk and - c_first_sales_date_sk = d2.d_date_sk and - c_first_shipto_date_sk = d3.d_date_sk and - ss_promo_sk = p_promo_sk and - hd1.hd_income_band_sk = ib1.ib_income_band_sk and - hd2.hd_income_band_sk = ib2.ib_income_band_sk and - cd1.cd_marital_status <> cd2.cd_marital_status and - i_color in ('sandy','seashell','black','peru','misty','spring') and - i_current_price between 6 and 6 + 10 and - i_current_price between 6 + 1 and 6 + 15 -group by i_product_name - ,i_item_sk - ,s_store_name - ,s_zip - ,ad1.ca_street_number - ,ad1.ca_street_name - ,ad1.ca_city - ,ad1.ca_zip - ,ad2.ca_street_number - ,ad2.ca_street_name - ,ad2.ca_city - ,ad2.ca_zip - ,d1.d_year - ,d2.d_year - ,d3.d_year -) -select cs1.product_name - ,cs1.store_name - ,cs1.store_zip - ,cs1.b_street_number - ,cs1.b_street_name - ,cs1.b_city - ,cs1.b_zip - ,cs1.c_street_number - ,cs1.c_street_name - ,cs1.c_city - ,cs1.c_zip - ,cs1.syear - ,cs1.cnt - ,cs1.s1 as s11 - ,cs1.s2 as s21 - ,cs1.s3 as s31 - ,cs2.s1 as s12 - ,cs2.s2 as s22 - ,cs2.s3 as s32 - ,cs2.syear - ,cs2.cnt -from cross_sales cs1,cross_sales cs2 -where cs1.item_sk=cs2.item_sk and - cs1.syear = 2001 and - cs2.syear = 2001 + 1 and - cs2.cnt <= cs1.cnt and - cs1.store_name = cs2.store_name and - cs1.store_zip = cs2.store_zip -order by cs1.product_name - ,cs1.store_name - ,cs2.cnt - ,cs1.s1 - ,cs2.s1; - --- end template query64.tpl query 85 in stream 9 --- start template query93.tpl query 86 in stream 9 -select /* TPC-DS query93.tpl 0.52 */ ss_customer_sk - ,sum(act_sales) sumsales - from (select ss_item_sk - ,ss_ticket_number - ,ss_customer_sk - ,case when sr_return_quantity is not null then (ss_quantity-sr_return_quantity)*ss_sales_price - else (ss_quantity*ss_sales_price) end act_sales - from store_sales left outer join store_returns on (sr_item_sk = ss_item_sk - and sr_ticket_number = ss_ticket_number) - ,reason - where sr_reason_sk = r_reason_sk - and r_reason_desc = 'reason 31') t - group by ss_customer_sk - order by sumsales, ss_customer_sk -limit 100; - --- end template query93.tpl query 86 in stream 9 --- start template query56.tpl query 87 in stream 9 -with /* TPC-DS query56.tpl 0.83 */ ss as ( - select i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where i_item_id in (select - i_item_id -from item -where i_color in ('azure','cornsilk','orchid')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 1 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - cs as ( - select i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('azure','cornsilk','orchid')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 1 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - ws as ( - select i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('azure','cornsilk','orchid')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 1 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id) - select i_item_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by total_sales, - i_item_id - limit 100; - --- end template query56.tpl query 87 in stream 9 --- start template query97.tpl query 88 in stream 9 -with /* TPC-DS query97.tpl 0.38 */ ssci as ( -select ss_customer_sk customer_sk - ,ss_item_sk item_sk -from store_sales,date_dim -where ss_sold_date_sk = d_date_sk - and d_month_seq between 1217 and 1217 + 11 -group by ss_customer_sk - ,ss_item_sk), -csci as( - select cs_bill_customer_sk customer_sk - ,cs_item_sk item_sk -from catalog_sales,date_dim -where cs_sold_date_sk = d_date_sk - and d_month_seq between 1217 and 1217 + 11 -group by cs_bill_customer_sk - ,cs_item_sk) - select sum(case when ssci.customer_sk is not null and csci.customer_sk is null then 1 else 0 end) store_only - ,sum(case when ssci.customer_sk is null and csci.customer_sk is not null then 1 else 0 end) catalog_only - ,sum(case when ssci.customer_sk is not null and csci.customer_sk is not null then 1 else 0 end) store_and_catalog -from ssci full outer join csci on (ssci.customer_sk=csci.customer_sk - and ssci.item_sk = csci.item_sk) -limit 100; - --- end template query97.tpl query 88 in stream 9 --- start template query23.tpl query 89 in stream 9 -with /* TPC-DS query23.tpl 0.68 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (1999,1999+1,1999+2,1999+3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1999,1999+1,1999+2,1999+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * -from - max_store_sales)) - select sum(sales) - from (select cs_quantity*cs_list_price sales - from catalog_sales - ,date_dim - where d_year = 1999 - and d_moy = 2 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - union all - select ws_quantity*ws_list_price sales - from web_sales - ,date_dim - where d_year = 1999 - and d_moy = 2 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer)) - limit 100; -with /* TPC-DS query23.tpl 0.68 part2 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (1999,1999 + 1,1999 + 2,1999 + 3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1999,1999+1,1999+2,1999+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * - from max_store_sales)) - select c_last_name,c_first_name,sales - from (select c_last_name,c_first_name,sum(cs_quantity*cs_list_price) sales - from catalog_sales - ,customer - ,date_dim - where d_year = 1999 - and d_moy = 2 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and cs_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name - union all - select c_last_name,c_first_name,sum(ws_quantity*ws_list_price) sales - from web_sales - ,customer - ,date_dim - where d_year = 1999 - and d_moy = 2 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and ws_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name) - order by c_last_name,c_first_name,sales - limit 100; - --- end template query23.tpl query 89 in stream 9 --- start template query44.tpl query 90 in stream 9 -select /* TPC-DS query44.tpl 0.4 */ asceding.rnk, i1.i_product_name best_performing, i2.i_product_name worst_performing -from(select * - from (select item_sk,rank() over (order by rank_col asc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 42 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 42 - and ss_addr_sk is null - group by ss_store_sk))V1)V11 - where rnk < 11) asceding, - (select * - from (select item_sk,rank() over (order by rank_col desc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 42 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 42 - and ss_addr_sk is null - group by ss_store_sk))V2)V21 - where rnk < 11) descending, -item i1, -item i2 -where asceding.rnk = descending.rnk - and i1.i_item_sk=asceding.item_sk - and i2.i_item_sk=descending.item_sk -order by asceding.rnk -limit 100; - --- end template query44.tpl query 90 in stream 9 --- start template query91.tpl query 91 in stream 9 -select /* TPC-DS query91.tpl 0.13 */ - cc_call_center_id Call_Center, - cc_name Call_Center_Name, - cc_manager Manager, - sum(cr_net_loss) Returns_Loss -from - call_center, - catalog_returns, - date_dim, - customer, - customer_address, - customer_demographics, - household_demographics -where - cr_call_center_sk = cc_call_center_sk -and cr_returned_date_sk = d_date_sk -and cr_returning_customer_sk= c_customer_sk -and cd_demo_sk = c_current_cdemo_sk -and hd_demo_sk = c_current_hdemo_sk -and ca_address_sk = c_current_addr_sk -and d_year = 1998 -and d_moy = 12 -and ( (cd_marital_status = 'M' and cd_education_status = 'Unknown') - or(cd_marital_status = 'W' and cd_education_status = 'Advanced Degree')) -and hd_buy_potential like '>10000%' -and ca_gmt_offset = -7 -group by cc_call_center_id,cc_name,cc_manager,cd_marital_status,cd_education_status -order by sum(cr_net_loss) desc; - --- end template query91.tpl query 91 in stream 9 --- start template query49.tpl query 92 in stream 9 -select /* TPC-DS query49.tpl 0.48 */ channel, item, return_ratio, return_rank, currency_rank from - (select - 'web' as channel - ,web.item - ,web.return_ratio - ,web.return_rank - ,web.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select ws.ws_item_sk as item - ,(cast(sum(coalesce(wr.wr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(wr.wr_return_amt,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - web_sales ws left outer join web_returns wr - on (ws.ws_order_number = wr.wr_order_number and - ws.ws_item_sk = wr.wr_item_sk) - ,date_dim - where - wr.wr_return_amt > 10000 - and ws.ws_net_profit > 1 - and ws.ws_net_paid > 0 - and ws.ws_quantity > 0 - and ws_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 12 - group by ws.ws_item_sk - ) in_web - ) web - where - ( - web.return_rank <= 10 - or - web.currency_rank <= 10 - ) - union - select - 'catalog' as channel - ,catalog.item - ,catalog.return_ratio - ,catalog.return_rank - ,catalog.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select - cs.cs_item_sk as item - ,(cast(sum(coalesce(cr.cr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(cr.cr_return_amount,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - catalog_sales cs left outer join catalog_returns cr - on (cs.cs_order_number = cr.cr_order_number and - cs.cs_item_sk = cr.cr_item_sk) - ,date_dim - where - cr.cr_return_amount > 10000 - and cs.cs_net_profit > 1 - and cs.cs_net_paid > 0 - and cs.cs_quantity > 0 - and cs_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 12 - group by cs.cs_item_sk - ) in_cat - ) catalog - where - ( - catalog.return_rank <= 10 - or - catalog.currency_rank <=10 - ) - union - select - 'store' as channel - ,store.item - ,store.return_ratio - ,store.return_rank - ,store.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select sts.ss_item_sk as item - ,(cast(sum(coalesce(sr.sr_return_quantity,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(sr.sr_return_amt,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - store_sales sts left outer join store_returns sr - on (sts.ss_ticket_number = sr.sr_ticket_number and sts.ss_item_sk = sr.sr_item_sk) - ,date_dim - where - sr.sr_return_amt > 10000 - and sts.ss_net_profit > 1 - and sts.ss_net_paid > 0 - and sts.ss_quantity > 0 - and ss_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 12 - group by sts.ss_item_sk - ) in_store - ) store - where ( - store.return_rank <= 10 - or - store.currency_rank <= 10 - ) - ) - order by 1,4,5,2 - limit 100; - --- end template query49.tpl query 92 in stream 9 --- start template query76.tpl query 93 in stream 9 -select /* TPC-DS query76.tpl 0.99 */ channel, col_name, d_year, d_qoy, i_category, COUNT(*) sales_cnt, SUM(ext_sales_price) sales_amt FROM ( - SELECT 'store' as channel, 'ss_hdemo_sk' col_name, d_year, d_qoy, i_category, ss_ext_sales_price ext_sales_price - FROM store_sales, item, date_dim - WHERE ss_hdemo_sk IS NULL - AND ss_sold_date_sk=d_date_sk - AND ss_item_sk=i_item_sk - UNION ALL - SELECT 'web' as channel, 'ws_warehouse_sk' col_name, d_year, d_qoy, i_category, ws_ext_sales_price ext_sales_price - FROM web_sales, item, date_dim - WHERE ws_warehouse_sk IS NULL - AND ws_sold_date_sk=d_date_sk - AND ws_item_sk=i_item_sk - UNION ALL - SELECT 'catalog' as channel, 'cs_promo_sk' col_name, d_year, d_qoy, i_category, cs_ext_sales_price ext_sales_price - FROM catalog_sales, item, date_dim - WHERE cs_promo_sk IS NULL - AND cs_sold_date_sk=d_date_sk - AND cs_item_sk=i_item_sk) foo -GROUP BY channel, col_name, d_year, d_qoy, i_category -ORDER BY channel, col_name, d_year, d_qoy, i_category -limit 100; - --- end template query76.tpl query 93 in stream 9 --- start template query63.tpl query 94 in stream 9 -select /* TPC-DS query63.tpl 0.27 */ * -from (select i_manager_id - ,sum(ss_sales_price) sum_sales - ,avg(sum(ss_sales_price)) over (partition by i_manager_id) avg_monthly_sales - from item - ,store_sales - ,date_dim - ,store - where ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and d_month_seq in (1214,1214+1,1214+2,1214+3,1214+4,1214+5,1214+6,1214+7,1214+8,1214+9,1214+10,1214+11) - and (( i_category in ('Books','Children','Electronics') - and i_class in ('personal','portable','reference','self-help') - and i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) - or( i_category in ('Women','Music','Men') - and i_class in ('accessories','classical','fragrances','pants') - and i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manager_id, d_moy) tmp1 -where case when avg_monthly_sales > 0 then abs (sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 -order by i_manager_id - ,avg_monthly_sales - ,sum_sales -limit 100; - --- end template query63.tpl query 94 in stream 9 --- start template query45.tpl query 95 in stream 9 -select /* TPC-DS query45.tpl 0.18 */ ca_zip, ca_state, sum(ws_sales_price) - from web_sales, customer, customer_address, date_dim, item - where ws_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ws_item_sk = i_item_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', '85392', '85460', '80348', '81792') - or - i_item_id in (select i_item_id - from item - where i_item_sk in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29) - ) - ) - and ws_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 1999 - group by ca_zip, ca_state - order by ca_zip, ca_state - limit 100; - --- end template query45.tpl query 95 in stream 9 --- start template query43.tpl query 96 in stream 9 -select /* TPC-DS query43.tpl 0.15 */ s_store_name, s_store_id, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from date_dim, store_sales, store - where d_date_sk = ss_sold_date_sk and - s_store_sk = ss_store_sk and - s_gmt_offset = -6 and - d_year = 1998 - group by s_store_name, s_store_id - order by s_store_name, s_store_id,sun_sales,mon_sales,tue_sales,wed_sales,thu_sales,fri_sales,sat_sales - limit 100; - --- end template query43.tpl query 96 in stream 9 --- start template query85.tpl query 97 in stream 9 -select /* TPC-DS query85.tpl 0.33 */ substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) - from web_sales, web_returns, web_page, customer_demographics cd1, - customer_demographics cd2, customer_address, date_dim, reason - where ws_web_page_sk = wp_web_page_sk - and ws_item_sk = wr_item_sk - and ws_order_number = wr_order_number - and ws_sold_date_sk = d_date_sk and d_year = 1998 - and cd1.cd_demo_sk = wr_refunded_cdemo_sk - and cd2.cd_demo_sk = wr_returning_cdemo_sk - and ca_address_sk = wr_refunded_addr_sk - and r_reason_sk = wr_reason_sk - and - ( - ( - cd1.cd_marital_status = 'D' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Primary' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 100.00 and 150.00 - ) - or - ( - cd1.cd_marital_status = 'U' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Unknown' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 50.00 and 100.00 - ) - or - ( - cd1.cd_marital_status = 'S' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'College' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ca_country = 'United States' - and - ca_state in ('IN', 'GA', 'ND') - and ws_net_profit between 100 and 200 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('NC', 'MI', 'AR') - and ws_net_profit between 150 and 300 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('MS', 'MT', 'CO') - and ws_net_profit between 50 and 250 - ) - ) -group by r_reason_desc -order by substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) -limit 100; - --- end template query85.tpl query 97 in stream 9 --- start template query37.tpl query 98 in stream 9 -select /* TPC-DS query37.tpl 0.31 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, catalog_sales - where i_current_price between 32 and 32 + 30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('2002-03-30' as date) and dateadd(day,60,cast('2002-03-30' as date)) - and i_manufact_id in (839,730,801,892) - and inv_quantity_on_hand between 100 and 500 - and cs_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query37.tpl query 98 in stream 9 --- start template query8.tpl query 99 in stream 9 -select /* TPC-DS query8.tpl 0.63 */ s_store_name - ,sum(ss_net_profit) - from store_sales - ,date_dim - ,store, - (select ca_zip - from ( - SELECT substring(ca_zip,1,5) ca_zip - FROM customer_address - WHERE substring(ca_zip,1,5) IN ( - '62046','89526','85296','21879','11716','99602', - '37453','68232','69551','26076','61061', - '42848','26745','11744','49061','64110', - '24130','69073','11561','58328','37732', - '23084','35956','40810','36647','83788', - '58704','93116','58595','23718','55377', - '81570','63830','56636','43016','55653', - '21707','13294','53407','96700','86667', - '25958','47023','25933','78868','57341', - '88874','67465','52947','20999','56855', - '74939','49091','11510','52773','20787', - '33779','40713','73768','11836','13848', - '67141','75046','61290','72146','85721', - '44891','21818','74932','11053','47771', - '10587','75500','18155','67274','15559', - '77862','41647','70013','51783','82437', - '79590','86463','24137','98275','77642', - '21508','50459','40605','90023','16621', - '41918','78990','85875','36888','81469', - '79572','49563','24923','71978','90232', - '68486','75833','73207','26780','38957', - '27743','50709','62451','59746','37248', - '25638','18498','52829','66662','49383', - '38051','60441','20278','91681','94786', - '83261','20169','93868','38861','60456', - '79430','48408','71880','42448','22915', - '93839','33158','74139','75252','20541', - '13631','99592','84860','71434','70100', - '73083','25346','39806','45935','15298', - '51337','85342','88531','50284','66976', - '13197','85080','64664','90660','84299', - '40019','59000','32645','62839','38903', - '90589','19990','82111','65907','12774', - '50234','51447','28651','49411','52696', - '50734','94926','73742','51326','27376', - '59120','75257','34848','80036','61388', - '48053','56231','81987','88140','41584', - '17186','48647','93045','51467','97560', - '71519','75139','42525','62112','65703', - '11232','27070','76524','90036','82172', - '64596','78729','30497','68208','85995', - '54660','90003','30706','56765','11170', - '16270','71208','51606','23309','72486', - '65384','29220','93707','68058','32531', - '24743','24373','81069','72861','68681', - '37867','78339','38557','97810','32927', - '99337','34076','25307','73572','39778', - '65862','85233','23225','99581','79234', - '92427','40228','24894','50906','57962', - '37871','57331','40561','51699','83441', - '75294','94413','47349','40619','99529', - '47243','89221','91652','17917','99877', - '25816','34147','20044','59643','66850', - '58046','75772','94378','45323','48195', - '94518','73073','72377','13773','86191', - '76733','78289','69195','99596','71363', - '83215','15816','70440','56838','53161', - '82189','50545','31368','57994','60439', - '99127','47817','50820','23776','17481', - '86283','16638','41559','39055','84928', - '79560','18978','35593','45299','18960', - '73504','23397','61838','86617','59290', - '28639','45814','60120','57745','45386', - '93664','64771','50974','62158','40964', - '88837','24705','73895','12359','45218', - '84035','87454','89227','45930','58764', - '91012','35744','10976','80398','31960', - '77346','79640','81015','69520','37315', - '33250','99629','21592','64683','27318', - '59463','35256','92250','63183','56540', - '86540','88933','55140','54730','37171', - '88109','62087','25092','32186','26993', - '92835','76650','79319','14925','96321', - '12834','87512','94362','92674','32840', - '73425','11068','47346','97338','22698', - '28267','65786','67514','62956','92984', - '56762','51277','69986','81634','67402', - '31378','55783','63994','35274','51306', - '85205','85303','66517','44871','11684', - '51693','64213','23679','23073') - intersect - select ca_zip - from (SELECT substring(ca_zip,1,5) ca_zip,count(*) cnt - FROM customer_address, customer - WHERE ca_address_sk = c_current_addr_sk and - c_preferred_cust_flag='Y' - group by ca_zip - having count(*) > 10)A1)A2) V1 - where ss_store_sk = s_store_sk - and ss_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 2001 - and (substring(s_zip,1,2) = substring(V1.ca_zip,1,2)) - group by s_store_name - order by s_store_name - limit 100; - --- end template query8.tpl query 99 in stream 9 diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/README.md b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/README.md index 64607816..864bf629 100644 --- a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/README.md +++ b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/README.md @@ -14,8 +14,6 @@ In order to address the enormous range of query types and user behaviors encount The Cloud DW benchmark consists of the 99 queries from TPC-DS. These have a wide variation of complexity, amount of data scanned, answer set size and elapsed time. Each query asks a business question and includes the corresponding query to answer the question. We have generated TPC-DS datasets and corresponding queries using the official TPC-DS kit from tpc.org. We have also provided sample DDL for each of the tables in the Cloud DW benchmark. This gives you an easy and complete way of setting up your own Cloud DW benchmark on Redshift and running the same queries that we use in our own testing. While the queries we provide use the default random seed as provided by TPC-DS, you can use the tools in the TPC-DS Benchmark Kit to generate different versions of these queries that have different parameter values. -TPC-DS also permits the use of and provides official query variants for several queries. As Amazon Redshift does not currently support the ROLLUP or GROUPING operators, this benchmark uses the approved SQL variants provided by TPC-DS for queries 5, 14, 18, 22, 27, 35, 36, 67, 70, 77, 80, and 86. - ## Repository Structure This repository contains a directory for each data scale that we have generated. For example, the `3TB` directory includes the queries, table definitions, and load SQL for the 3 Terabyte TPC-DS dataset. The data itself is stored in Amazon S3. @@ -23,7 +21,6 @@ This repository contains a directory for each data scale that we have generated. The files in each data scale directory are as follows: * `ddl.sql`: This SQL file creates the TPC-DS tables and then loads the data via COPY from S3. Prior to executing, you will need to replace the strings `` and `` with any valid S3 credentials. The file also executes `SELECT COUNT(*)` against all tables at the end to show that all data was loaded. * `queries/query_0.sql`: This file contains the 99 queries that are part of the TPC-DS "Power Run". The "Power Run" is a single-concurrency execution of the official TPC-DS queries. Note that 4 of the TPC-DS "queries" have 2 parts, so executing the file will result in 103 SQL queries being executed. -* `queries/query_1.sql` through `queries/query_10.sql`: These files contain the same 99 queries, but each in a different random order. The random order is defined by the TPC-DS specification. These files are used for the TPC-DS "Throughput Run". The "Throughput Run" is a multi-concurrency execution. So for example, to execute a 5-user Throughput Run, the files `query_1.sql` through `query_5.sql` should be executed at the same time against the database. ## Instructions For Use @@ -37,12 +34,6 @@ To execute the TPC-DS Power Run at a particular data scale (e.g. 3TB), perform t 3. `ddl.sql` will execute `SELECT COUNT(*)` at the end against each table. Verify that the resulting counts match the values at the end of `ddl.sql`. -4. Execute `query_0.sql` several times sequentially (e.g. five times) and record the run time of each execution. +4. Execute `query_0.sql` three times and record the best run time. Note that the S3 data is located in US-EAST-1 so you may get faster load times if your test cluster is located in that region. - -### Throughput Run - -Once you have the data loaded and have executed the Power Run, you can then execute the Throughput Run using the same data: - -5. Simultaneously execute the query files that correspond to the number of concurrent streams you want. For example, to execute 2 concurrent streams, simultaneously execute `query_1.sql` and `query_2.sql`. To execute 5 concurrent streams simultaneously execute `query_1.sql` through `query_5.sql`. The Throughput Run time will be the time elapsed from the start of the first query for the streams to the end of the last query of any stream. diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/README.md b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/README.md index 607bc2df..1eb04b42 100644 --- a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/README.md +++ b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/README.md @@ -36,7 +36,7 @@ To execute the TPC-H Power Run at a particular data scale (e.g. 3TB), perform th 2. Connect to the database you created and execute `ddl.sql`. This may take several hours, depending on the data scale and data warehouse size. -3. Execute `query_0.sql` several times sequentially (e.g. five times) and record the run time of each execution. +3. Execute `query_0.sql` three times and record the best run time. Note that the S3 data is located in US-EAST-1 so you may get faster load times if your test cluster is located in that region. From 6f1081a88c83206e5f332b55120412e3b180ea5a Mon Sep 17 00:00:00 2001 From: Devanathan Sabapathy <123671658+DevanathanSabapathy1@users.noreply.github.com> Date: Fri, 3 Nov 2023 14:09:51 -0700 Subject: [PATCH 28/49] correct a mistake in the quote which makes it a code block only for the desired words. (#706) --- src/MetadataTransfer/readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MetadataTransfer/readme.md b/src/MetadataTransfer/readme.md index cbe03fdb..3b375e22 100644 --- a/src/MetadataTransfer/readme.md +++ b/src/MetadataTransfer/readme.md @@ -4,7 +4,7 @@ This utility enables the end user to automate the transfer of metadata from one The utility requries the [`redshift_connector`](https://pypi.org/project/redshift-connector) and [`boto3`](https://pypi.org/project/boto3) Python3 libraries. Additionally, the utility requires that you configure the [default region](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-quickstart.html#cli-configure-quickstart-region) for `boto3` to successfully send requests. -The utility has two scripts. The `metadatacopy.py' script creates objects such as tables, schemas, users, and profiles. The `userprivs.py` script only migrates the privileges and does not create the database/schema/user objects. +The utility has two scripts. The `metadatacopy.py` script creates objects such as tables, schemas, users, and profiles. The `userprivs.py` script only migrates the privileges and does not create the database/schema/user objects. The objects which are migrated when executing each script are: From 8085eeb48036ad236325adfe40c63425dd3cf2f1 Mon Sep 17 00:00:00 2001 From: sgromoll Date: Mon, 12 Feb 2024 11:39:32 -0500 Subject: [PATCH 29/49] Update queries with latest (#713) --- .../Cloud-DWB-Derived-from-TPCDS/10TB/ddl.sql | 624 -- .../10TB/queries/query_0.sql | 5027 ----------------- .../10TB/queries/query_1.sql | 5027 ----------------- .../10TB/queries/query_10.sql | 5027 ----------------- .../10TB/queries/query_2.sql | 5027 ----------------- .../10TB/queries/query_3.sql | 5027 ----------------- .../10TB/queries/query_4.sql | 5027 ----------------- .../10TB/queries/query_5.sql | 5027 ----------------- .../10TB/queries/query_6.sql | 5027 ----------------- .../10TB/queries/query_7.sql | 5027 ----------------- .../10TB/queries/query_8.sql | 5027 ----------------- .../10TB/queries/query_9.sql | 5027 ----------------- .../1TB/queries/query_0.sql | 495 +- .../1TB/queries/query_1.sql | 5027 ----------------- .../1TB/queries/query_10.sql | 5027 ----------------- .../1TB/queries/query_2.sql | 5027 ----------------- .../1TB/queries/query_3.sql | 5027 ----------------- .../1TB/queries/query_4.sql | 5027 ----------------- .../1TB/queries/query_5.sql | 5027 ----------------- .../1TB/queries/query_6.sql | 5027 ----------------- .../1TB/queries/query_7.sql | 5027 ----------------- .../1TB/queries/query_8.sql | 5027 ----------------- .../1TB/queries/query_9.sql | 5027 ----------------- 23 files changed, 167 insertions(+), 106519 deletions(-) delete mode 100644 src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/10TB/ddl.sql delete mode 100644 src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/10TB/queries/query_0.sql delete mode 100644 src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/10TB/queries/query_1.sql delete mode 100644 src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/10TB/queries/query_10.sql delete mode 100644 src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/10TB/queries/query_2.sql delete mode 100644 src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/10TB/queries/query_3.sql delete mode 100644 src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/10TB/queries/query_4.sql delete mode 100644 src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/10TB/queries/query_5.sql delete mode 100644 src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/10TB/queries/query_6.sql delete mode 100644 src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/10TB/queries/query_7.sql delete mode 100644 src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/10TB/queries/query_8.sql delete mode 100644 src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/10TB/queries/query_9.sql delete mode 100644 src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/1TB/queries/query_1.sql delete mode 100644 src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/1TB/queries/query_10.sql delete mode 100644 src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/1TB/queries/query_2.sql delete mode 100644 src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/1TB/queries/query_3.sql delete mode 100644 src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/1TB/queries/query_4.sql delete mode 100644 src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/1TB/queries/query_5.sql delete mode 100644 src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/1TB/queries/query_6.sql delete mode 100644 src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/1TB/queries/query_7.sql delete mode 100644 src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/1TB/queries/query_8.sql delete mode 100644 src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/1TB/queries/query_9.sql diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/10TB/ddl.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/10TB/ddl.sql deleted file mode 100644 index 10ccb1f4..00000000 --- a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/10TB/ddl.sql +++ /dev/null @@ -1,624 +0,0 @@ -create table dbgen_version -( - dv_version varchar(32), - dv_create_date date , - dv_create_time timestamp, - dv_cmdline_args varchar(200) -); - -create table customer_address -( - ca_address_sk int4 not null , - ca_address_id char(16) not null , - ca_street_number char(10) , - ca_street_name varchar(60) , - ca_street_type char(15) , - ca_suite_number char(10) , - ca_city varchar(60) , - ca_county varchar(30) , - ca_state char(2) , - ca_zip char(10) , - ca_country varchar(20) , - ca_gmt_offset numeric(5,2) , - ca_location_type char(20) - ,primary key (ca_address_sk) -) distkey(ca_address_sk); - -create table customer_demographics -( - cd_demo_sk int4 not null , - cd_gender char(1) , - cd_marital_status char(1) , - cd_education_status char(20) , - cd_purchase_estimate int4 , - cd_credit_rating char(10) , - cd_dep_count int4 , - cd_dep_employed_count int4 , - cd_dep_college_count int4 - ,primary key (cd_demo_sk) -)distkey (cd_demo_sk); - -create table date_dim -( - d_date_sk integer not null, - d_date_id char(16) not null, - d_date date, - d_month_seq integer , - d_week_seq integer , - d_quarter_seq integer , - d_year integer , - d_dow integer , - d_moy integer , - d_dom integer , - d_qoy integer , - d_fy_year integer , - d_fy_quarter_seq integer , - d_fy_week_seq integer , - d_day_name char(9) , - d_quarter_name char(6) , - d_holiday char(1) , - d_weekend char(1) , - d_following_holiday char(1) , - d_first_dom integer , - d_last_dom integer , - d_same_day_ly integer , - d_same_day_lq integer , - d_current_day char(1) , - d_current_week char(1) , - d_current_month char(1) , - d_current_quarter char(1) , - d_current_year char(1) , - primary key (d_date_sk) -) diststyle all; - -create table warehouse -( - w_warehouse_sk integer not null, - w_warehouse_id char(16) not null, - w_warehouse_name varchar(20) , - w_warehouse_sq_ft integer , - w_street_number char(10) , - w_street_name varchar(60) , - w_street_type char(15) , - w_suite_number char(10) , - w_city varchar(60) , - w_county varchar(30) , - w_state char(2) , - w_zip char(10) , - w_country varchar(20) , - w_gmt_offset decimal(5,2) , - primary key (w_warehouse_sk) -) diststyle all; - -create table ship_mode -( - sm_ship_mode_sk integer not null, - sm_ship_mode_id char(16) not null, - sm_type char(30) , - sm_code char(10) , - sm_carrier char(20) , - sm_contract char(20) , - primary key (sm_ship_mode_sk) -) diststyle all; - -create table time_dim -( - t_time_sk integer not null, - t_time_id char(16) not null, - t_time integer , - t_hour integer , - t_minute integer , - t_second integer , - t_am_pm char(2) , - t_shift char(20) , - t_sub_shift char(20) , - t_meal_time char(20) , - primary key (t_time_sk) -) diststyle all; - -create table reason -( - r_reason_sk integer not null, - r_reason_id char(16) not null, - r_reason_desc char(100) , - primary key (r_reason_sk) -) diststyle all ; - -create table income_band -( - ib_income_band_sk integer not null, - ib_lower_bound integer , - ib_upper_bound integer , - primary key (ib_income_band_sk) -) diststyle all; - -create table item -( -i_item_sk int4 not null, - i_item_id char(16) not null , - i_rec_start_date date, - i_rec_end_date date, - i_item_desc varchar(200) , - i_current_price numeric(7,2), - i_wholesale_cost numeric(7,2), - i_brand_id int4, - i_brand char(50) , - i_class_id int4, - i_class char(50) , - i_category_id int4, - i_category char(50) , - i_manufact_id int4, - i_manufact char(50) , - i_size char(20) , - i_formulation char(20) , - i_color char(20) , - i_units char(10), - i_container char(10), - i_manager_id int4, - i_product_name char(50) - ,primary key (i_item_sk) -) distkey(i_item_sk) sortkey(i_category); - -create table store -( - s_store_sk integer not null, - s_store_id char(16) not null, - s_rec_start_date date, - s_rec_end_date date, - s_closed_date_sk integer , - s_store_name varchar(50) , - s_number_employees integer , - s_floor_space integer , - s_hours char(20) , - s_manager varchar(40) , - s_market_id integer , - s_geography_class varchar(100) , - s_market_desc varchar(100) , - s_market_manager varchar(40) , - s_division_id integer , - s_division_name varchar(50) , - s_company_id integer , - s_company_name varchar(50) , - s_street_number varchar(10) , - s_street_name varchar(60) , - s_street_type char(15) , - s_suite_number char(10) , - s_city varchar(60) , - s_county varchar(30) , - s_state char(2) , - s_zip char(10) , - s_country varchar(20) , - s_gmt_offset decimal(5,2) , - s_tax_precentage decimal(5,2) , - primary key (s_store_sk) -) diststyle all; - -create table call_center -( - cc_call_center_sk integer not null, - cc_call_center_id char(16) not null, - cc_rec_start_date date, - cc_rec_end_date date, - cc_closed_date_sk integer , - cc_open_date_sk integer , - cc_name varchar(50) , - cc_class varchar(50) , - cc_employees integer , - cc_sq_ft integer , - cc_hours char(20) , - cc_manager varchar(40) , - cc_mkt_id integer , - cc_mkt_class char(50) , - cc_mkt_desc varchar(100) , - cc_market_manager varchar(40) , - cc_division integer , - cc_division_name varchar(50) , - cc_company integer , - cc_company_name char(50) , - cc_street_number char(10) , - cc_street_name varchar(60) , - cc_street_type char(15) , - cc_suite_number char(10) , - cc_city varchar(60) , - cc_county varchar(30) , - cc_state char(2) , - cc_zip char(10) , - cc_country varchar(20) , - cc_gmt_offset decimal(5,2) , - cc_tax_percentage decimal(5,2) , - primary key (cc_call_center_sk) -) diststyle all; - -create table customer -( - c_customer_sk int4 not null , - c_customer_id char(16) not null , - c_current_cdemo_sk int4 , - c_current_hdemo_sk int4 , - c_current_addr_sk int4 , - c_first_shipto_date_sk int4 , - c_first_sales_date_sk int4 , - c_salutation char(10) , - c_first_name char(20) , - c_last_name char(30) , - c_preferred_cust_flag char(1) , - c_birth_day int4 , - c_birth_month int4 , - c_birth_year int4 , - c_birth_country varchar(20) , - c_login char(13) , - c_email_address char(50) , - c_last_review_date_sk int4 , - primary key (c_customer_sk) -) distkey(c_customer_sk); - -create table web_site -( - web_site_sk integer not null, - web_site_id char(16) not null, - web_rec_start_date date, - web_rec_end_date date, - web_name varchar(50) , - web_open_date_sk integer , - web_close_date_sk integer , - web_class varchar(50) , - web_manager varchar(40) , - web_mkt_id integer , - web_mkt_class varchar(50) , - web_mkt_desc varchar(100) , - web_market_manager varchar(40) , - web_company_id integer , - web_company_name char(50) , - web_street_number char(10) , - web_street_name varchar(60) , - web_street_type char(15) , - web_suite_number char(10) , - web_city varchar(60) , - web_county varchar(30) , - web_state char(2) , - web_zip char(10) , - web_country varchar(20) , - web_gmt_offset decimal(5,2) , - web_tax_percentage decimal(5,2) , - primary key (web_site_sk) -) diststyle all; - -create table store_returns -( -sr_returned_date_sk int4 , - sr_return_time_sk int4 , - sr_item_sk int4 not null , - sr_customer_sk int4 , - sr_cdemo_sk int4 , - sr_hdemo_sk int4 , - sr_addr_sk int4 , - sr_store_sk int4 , - sr_reason_sk int4 , - sr_ticket_number int8 not null, - sr_return_quantity int4 , - sr_return_amt numeric(7,2) , - sr_return_tax numeric(7,2) , - sr_return_amt_inc_tax numeric(7,2) , - sr_fee numeric(7,2) , - sr_return_ship_cost numeric(7,2) , - sr_refunded_cash numeric(7,2) , - sr_reversed_charge numeric(7,2) , - sr_store_credit numeric(7,2) , - sr_net_loss numeric(7,2) - ,primary key (sr_item_sk, sr_ticket_number) -) distkey(sr_item_sk) sortkey(sr_returned_date_sk); - -create table household_demographics -( - hd_demo_sk integer not null, - hd_income_band_sk integer , - hd_buy_potential char(15) , - hd_dep_count integer , - hd_vehicle_count integer , - primary key (hd_demo_sk) -) diststyle all; - -create table web_page -( - wp_web_page_sk integer not null, - wp_web_page_id char(16) not null, - wp_rec_start_date date, - wp_rec_end_date date, - wp_creation_date_sk integer , - wp_access_date_sk integer , - wp_autogen_flag char(1) , - wp_customer_sk integer , - wp_url varchar(100) , - wp_type char(50) , - wp_char_count integer , - wp_link_count integer , - wp_image_count integer , - wp_max_ad_count integer , - primary key (wp_web_page_sk) -) diststyle all; - -create table promotion -( - p_promo_sk integer not null, - p_promo_id char(16) not null, - p_start_date_sk integer , - p_end_date_sk integer , - p_item_sk integer , - p_cost decimal(15,2) , - p_response_target integer , - p_promo_name char(50) , - p_channel_dmail char(1) , - p_channel_email char(1) , - p_channel_catalog char(1) , - p_channel_tv char(1) , - p_channel_radio char(1) , - p_channel_press char(1) , - p_channel_event char(1) , - p_channel_demo char(1) , - p_channel_details varchar(100) , - p_purpose char(15) , - p_discount_active char(1) , - primary key (p_promo_sk) -) diststyle all; - -create table catalog_page -( - cp_catalog_page_sk integer not null, - cp_catalog_page_id char(16) not null, - cp_start_date_sk integer , - cp_end_date_sk integer , - cp_department varchar(50) , - cp_catalog_number integer , - cp_catalog_page_number integer , - cp_description varchar(100) , - cp_type varchar(100) , - primary key (cp_catalog_page_sk) -) diststyle all; - -create table inventory -( - inv_date_sk int4 not null , - inv_item_sk int4 not null , - inv_warehouse_sk int4 not null , - inv_quantity_on_hand int4 - ,primary key (inv_date_sk, inv_item_sk, inv_warehouse_sk) -) distkey(inv_item_sk) sortkey(inv_date_sk); - -create table catalog_returns -( - cr_returned_date_sk int4 , - cr_returned_time_sk int4 , - cr_item_sk int4 not null , - cr_refunded_customer_sk int4 , - cr_refunded_cdemo_sk int4 , - cr_refunded_hdemo_sk int4 , - cr_refunded_addr_sk int4 , - cr_returning_customer_sk int4 , - cr_returning_cdemo_sk int4 , - cr_returning_hdemo_sk int4 , - cr_returning_addr_sk int4 , - cr_call_center_sk int4 , - cr_catalog_page_sk int4 , - cr_ship_mode_sk int4 , - cr_warehouse_sk int4 , - cr_reason_sk int4 , - cr_order_number int8 not null, - cr_return_quantity int4 , - cr_return_amount numeric(7,2) , - cr_return_tax numeric(7,2) , - cr_return_amt_inc_tax numeric(7,2) , - cr_fee numeric(7,2) , - cr_return_ship_cost numeric(7,2) , - cr_refunded_cash numeric(7,2) , - cr_reversed_charge numeric(7,2) , - cr_store_credit numeric(7,2) , - cr_net_loss numeric(7,2) - ,primary key (cr_item_sk, cr_order_number) -) distkey(cr_item_sk) sortkey(cr_returned_date_sk); - -create table web_returns -( -wr_returned_date_sk int4 , - wr_returned_time_sk int4 , - wr_item_sk int4 not null , - wr_refunded_customer_sk int4 , - wr_refunded_cdemo_sk int4 , - wr_refunded_hdemo_sk int4 , - wr_refunded_addr_sk int4 , - wr_returning_customer_sk int4 , - wr_returning_cdemo_sk int4 , - wr_returning_hdemo_sk int4 , - wr_returning_addr_sk int4 , - wr_web_page_sk int4 , - wr_reason_sk int4 , - wr_order_number int8 not null, - wr_return_quantity int4 , - wr_return_amt numeric(7,2) , - wr_return_tax numeric(7,2) , - wr_return_amt_inc_tax numeric(7,2) , - wr_fee numeric(7,2) , - wr_return_ship_cost numeric(7,2) , - wr_refunded_cash numeric(7,2) , - wr_reversed_charge numeric(7,2) , - wr_account_credit numeric(7,2) , - wr_net_loss numeric(7,2) - ,primary key (wr_item_sk, wr_order_number) -) distkey(wr_order_number) sortkey(wr_returned_date_sk); - -create table web_sales -( - ws_sold_date_sk int4 , - ws_sold_time_sk int4 , - ws_ship_date_sk int4 , - ws_item_sk int4 not null , - ws_bill_customer_sk int4 , - ws_bill_cdemo_sk int4 , - ws_bill_hdemo_sk int4 , - ws_bill_addr_sk int4 , - ws_ship_customer_sk int4 , - ws_ship_cdemo_sk int4 , - ws_ship_hdemo_sk int4 , - ws_ship_addr_sk int4 , - ws_web_page_sk int4 , - ws_web_site_sk int4 , - ws_ship_mode_sk int4 , - ws_warehouse_sk int4 , - ws_promo_sk int4 , - ws_order_number int8 not null, - ws_quantity int4 , - ws_wholesale_cost numeric(7,2) , - ws_list_price numeric(7,2) , - ws_sales_price numeric(7,2) , - ws_ext_discount_amt numeric(7,2) , - ws_ext_sales_price numeric(7,2) , - ws_ext_wholesale_cost numeric(7,2) , - ws_ext_list_price numeric(7,2) , - ws_ext_tax numeric(7,2) , - ws_coupon_amt numeric(7,2) , - ws_ext_ship_cost numeric(7,2) , - ws_net_paid numeric(7,2) , - ws_net_paid_inc_tax numeric(7,2) , - ws_net_paid_inc_ship numeric(7,2) , - ws_net_paid_inc_ship_tax numeric(7,2) , - ws_net_profit numeric(7,2) - ,primary key (ws_item_sk, ws_order_number) -) distkey(ws_order_number) sortkey(ws_sold_date_sk); - -create table catalog_sales -( - cs_sold_date_sk int4 , - cs_sold_time_sk int4 , - cs_ship_date_sk int4 , - cs_bill_customer_sk int4 , - cs_bill_cdemo_sk int4 , - cs_bill_hdemo_sk int4 , - cs_bill_addr_sk int4 , - cs_ship_customer_sk int4 , - cs_ship_cdemo_sk int4 , - cs_ship_hdemo_sk int4 , - cs_ship_addr_sk int4 , - cs_call_center_sk int4 , - cs_catalog_page_sk int4 , - cs_ship_mode_sk int4 , - cs_warehouse_sk int4 , - cs_item_sk int4 not null , - cs_promo_sk int4 , - cs_order_number int8 not null , - cs_quantity int4 , - cs_wholesale_cost numeric(7,2) , - cs_list_price numeric(7,2) , - cs_sales_price numeric(7,2) , - cs_ext_discount_amt numeric(7,2) , - cs_ext_sales_price numeric(7,2) , - cs_ext_wholesale_cost numeric(7,2) , - cs_ext_list_price numeric(7,2) , - cs_ext_tax numeric(7,2) , - cs_coupon_amt numeric(7,2) , - cs_ext_ship_cost numeric(7,2) , - cs_net_paid numeric(7,2) , - cs_net_paid_inc_tax numeric(7,2) , - cs_net_paid_inc_ship numeric(7,2) , - cs_net_paid_inc_ship_tax numeric(7,2) , - cs_net_profit numeric(7,2) - ,primary key (cs_item_sk, cs_order_number) -) distkey(cs_item_sk) sortkey(cs_sold_date_sk); - -create table store_sales -( -ss_sold_date_sk int4 , - ss_sold_time_sk int4 , - ss_item_sk int4 not null , - ss_customer_sk int4 , - ss_cdemo_sk int4 , - ss_hdemo_sk int4 , - ss_addr_sk int4 , - ss_store_sk int4 , - ss_promo_sk int4 , - ss_ticket_number int8 not null, - ss_quantity int4 , - ss_wholesale_cost numeric(7,2) , - ss_list_price numeric(7,2) , - ss_sales_price numeric(7,2) , - ss_ext_discount_amt numeric(7,2) , - ss_ext_sales_price numeric(7,2) , - ss_ext_wholesale_cost numeric(7,2) , - ss_ext_list_price numeric(7,2) , - ss_ext_tax numeric(7,2) , - ss_coupon_amt numeric(7,2) , - ss_net_paid numeric(7,2) , - ss_net_paid_inc_tax numeric(7,2) , - ss_net_profit numeric(7,2) - ,primary key (ss_item_sk, ss_ticket_number) -) distkey(ss_item_sk) sortkey(ss_sold_date_sk); - -/* - - - Text files needed to load test data under s3://redshift-downloads/TPC-DS/2.13/10TB are publicly available. - - To load the sample data, you must provide authentication for your cluster to access Amazon S3 on your behalf. - - You can provide authentication by referencing an IAM role that you have created. You can set an IAM_Role as the default for your cluster or you can directly provide the ARN of an IAM_Role. - For more information https://docs.aws.amazon.com/redshift/latest/mgmt/authorizing-redshift-service.html - - The COPY commands include a placeholder for IAM_Role, in this code IAM_Role clause is set to use the default IAM_Role. If your cluster does not have a IAM_Role set as default then please follow the instructions provided here: - - https://docs.aws.amazon.com/redshift/latest/mgmt/default-iam-role.html - - For more information check samples in https://docs.aws.amazon.com/redshift/latest/gsg/rs-gsg-create-sample-db.html - - **Note** another option to provide IAM_Role is to provide IAM_Role ARN in IAM_Role clause. For example - copy call_center from 's3://redshift-downloads/TPC-DS/2.13/10TB/call_center/' IAM_Role 'Replace text inside the quotes with Redshift cluster IAM_Role ARN' gzip delimiter '|' EMPTYASNULL region 'us-east-1'; - -*/ - -copy call_center from 's3://redshift-downloads/TPC-DS/2.13/10TB/call_center/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1' ; -copy catalog_page from 's3://redshift-downloads/TPC-DS/2.13/10TB/catalog_page/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1' ; -copy catalog_returns from 's3://redshift-downloads/TPC-DS/2.13/10TB/catalog_returns/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1' ; -copy catalog_sales from 's3://redshift-downloads/TPC-DS/2.13/10TB/catalog_sales/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1' ; -copy customer_address from 's3://redshift-downloads/TPC-DS/2.13/10TB/customer_address/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1' ; -copy customer_demographics from 's3://redshift-downloads/TPC-DS/2.13/10TB/customer_demographics/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1' ; -copy customer from 's3://redshift-downloads/TPC-DS/2.13/10TB/customer/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1' ; -copy date_dim from 's3://redshift-downloads/TPC-DS/2.13/10TB/date_dim/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1' ; -copy household_demographics from 's3://redshift-downloads/TPC-DS/2.13/10TB/household_demographics/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1' ; -copy income_band from 's3://redshift-downloads/TPC-DS/2.13/10TB/income_band/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1' ; -copy inventory from 's3://redshift-downloads/TPC-DS/2.13/10TB/inventory/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1' ; -copy item from 's3://redshift-downloads/TPC-DS/2.13/10TB/item/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1' ; -copy promotion from 's3://redshift-downloads/TPC-DS/2.13/10TB/promotion/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1' ; -copy reason from 's3://redshift-downloads/TPC-DS/2.13/10TB/reason/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1' ; -copy ship_mode from 's3://redshift-downloads/TPC-DS/2.13/10TB/ship_mode/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1' ; -copy store from 's3://redshift-downloads/TPC-DS/2.13/10TB/store/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1' ; -copy store_returns from 's3://redshift-downloads/TPC-DS/2.13/10TB/store_returns/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1' ; -copy store_sales from 's3://redshift-downloads/TPC-DS/2.13/10TB/store_sales/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1'; -copy time_dim from 's3://redshift-downloads/TPC-DS/2.13/10TB/time_dim/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1' ; -copy warehouse from 's3://redshift-downloads/TPC-DS/2.13/10TB/warehouse/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1' ; -copy web_page from 's3://redshift-downloads/TPC-DS/2.13/10TB/web_page/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1' ; -copy web_returns from 's3://redshift-downloads/TPC-DS/2.13/10TB/web_returns/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1' ; -copy web_sales from 's3://redshift-downloads/TPC-DS/2.13/10TB/web_sales/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1' ; -copy web_site from 's3://redshift-downloads/TPC-DS/2.13/10TB/web_site/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1' ; - - -select count(*) from call_center; -- 54 -select count(*) from catalog_page; -- 40000 -select count(*) from catalog_returns; -- 1440033112 -select count(*) from catalog_sales; -- 14399964710 -select count(*) from customer; -- 65000000 -select count(*) from customer_address; -- 32500000 -select count(*) from customer_demographics; -- 1920800 -select count(*) from date_dim; -- 73049 -select count(*) from household_demographics; -- 7200 -select count(*) from income_band; -- 20 -select count(*) from inventory; -- 1311525000 -select count(*) from item; -- 402000 -select count(*) from promotion; -- 2000 -select count(*) from reason; -- 70 -select count(*) from ship_mode; -- 20 -select count(*) from store; -- 1500 -select count(*) from store_returns; -- 2879356097 -select count(*) from store_sales; -- 28801286459 -select count(*) from time_dim; -- 86400 -select count(*) from warehouse; -- 25 -select count(*) from web_page; -- 4002 -select count(*) from web_returns; -- 720020485 -select count(*) from web_sales; -- 7199963324 -select count(*) from web_site; -- 78 diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/10TB/queries/query_0.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/10TB/queries/query_0.sql deleted file mode 100644 index 7757eddc..00000000 --- a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/10TB/queries/query_0.sql +++ /dev/null @@ -1,5027 +0,0 @@ --- start template query96.tpl query 1 in stream 0 -select /* TPC-DS query96.tpl 0.1 */ count(*) -from store_sales - ,household_demographics - ,time_dim, store -where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and household_demographics.hd_dep_count = 5 - and store.s_store_name = 'ese' -order by count(*) -limit 100; - --- end template query96.tpl query 1 in stream 0 --- start template query7.tpl query 2 in stream 0 -select /* TPC-DS query7.tpl 0.2 */ i_item_id, - avg(ss_quantity) agg1, - avg(ss_list_price) agg2, - avg(ss_coupon_amt) agg3, - avg(ss_sales_price) agg4 - from store_sales, customer_demographics, date_dim, item, promotion - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_cdemo_sk = cd_demo_sk and - ss_promo_sk = p_promo_sk and - cd_gender = 'M' and - cd_marital_status = 'M' and - cd_education_status = '4 yr Degree' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 2001 - group by i_item_id - order by i_item_id - limit 100; - --- end template query7.tpl query 2 in stream 0 --- start template query75.tpl query 3 in stream 0 -WITH /* TPC-DS query75.tpl 0.3 */ all_sales AS ( - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,SUM(sales_cnt) AS sales_cnt - ,SUM(sales_amt) AS sales_amt - FROM (SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,cs_quantity - COALESCE(cr_return_quantity,0) AS sales_cnt - ,cs_ext_sales_price - COALESCE(cr_return_amount,0.0) AS sales_amt - FROM catalog_sales JOIN item ON i_item_sk=cs_item_sk - JOIN date_dim ON d_date_sk=cs_sold_date_sk - LEFT JOIN catalog_returns ON (cs_order_number=cr_order_number - AND cs_item_sk=cr_item_sk) - WHERE i_category='Shoes' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ss_quantity - COALESCE(sr_return_quantity,0) AS sales_cnt - ,ss_ext_sales_price - COALESCE(sr_return_amt,0.0) AS sales_amt - FROM store_sales JOIN item ON i_item_sk=ss_item_sk - JOIN date_dim ON d_date_sk=ss_sold_date_sk - LEFT JOIN store_returns ON (ss_ticket_number=sr_ticket_number - AND ss_item_sk=sr_item_sk) - WHERE i_category='Shoes' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ws_quantity - COALESCE(wr_return_quantity,0) AS sales_cnt - ,ws_ext_sales_price - COALESCE(wr_return_amt,0.0) AS sales_amt - FROM web_sales JOIN item ON i_item_sk=ws_item_sk - JOIN date_dim ON d_date_sk=ws_sold_date_sk - LEFT JOIN web_returns ON (ws_order_number=wr_order_number - AND ws_item_sk=wr_item_sk) - WHERE i_category='Shoes') sales_detail - GROUP BY d_year, i_brand_id, i_class_id, i_category_id, i_manufact_id) - SELECT prev_yr.d_year AS prev_year - ,curr_yr.d_year AS year - ,curr_yr.i_brand_id - ,curr_yr.i_class_id - ,curr_yr.i_category_id - ,curr_yr.i_manufact_id - ,prev_yr.sales_cnt AS prev_yr_cnt - ,curr_yr.sales_cnt AS curr_yr_cnt - ,curr_yr.sales_cnt-prev_yr.sales_cnt AS sales_cnt_diff - ,curr_yr.sales_amt-prev_yr.sales_amt AS sales_amt_diff - FROM all_sales curr_yr, all_sales prev_yr - WHERE curr_yr.i_brand_id=prev_yr.i_brand_id - AND curr_yr.i_class_id=prev_yr.i_class_id - AND curr_yr.i_category_id=prev_yr.i_category_id - AND curr_yr.i_manufact_id=prev_yr.i_manufact_id - AND curr_yr.d_year=2000 - AND prev_yr.d_year=2000-1 - AND CAST(curr_yr.sales_cnt AS DECIMAL(17,2))/CAST(prev_yr.sales_cnt AS DECIMAL(17,2))<0.9 - ORDER BY sales_cnt_diff,sales_amt_diff - limit 100; - --- end template query75.tpl query 3 in stream 0 --- start template query44.tpl query 4 in stream 0 -select /* TPC-DS query44.tpl 0.4 */ asceding.rnk, i1.i_product_name best_performing, i2.i_product_name worst_performing -from(select * - from (select item_sk,rank() over (order by rank_col asc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 639 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 639 - and ss_hdemo_sk is null - group by ss_store_sk))V1)V11 - where rnk < 11) asceding, - (select * - from (select item_sk,rank() over (order by rank_col desc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 639 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 639 - and ss_hdemo_sk is null - group by ss_store_sk))V2)V21 - where rnk < 11) descending, -item i1, -item i2 -where asceding.rnk = descending.rnk - and i1.i_item_sk=asceding.item_sk - and i2.i_item_sk=descending.item_sk -order by asceding.rnk -limit 100; - --- end template query44.tpl query 4 in stream 0 --- start template query39.tpl query 5 in stream 0 -with /* TPC-DS query39.tpl 0.5 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =2001 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=1 - and inv2.d_moy=1+1 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; -with /* TPC-DS query39.tpl 0.5 part2 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =2001 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=1 - and inv2.d_moy=1+1 - and inv1.cov > 1.5 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; - --- end template query39.tpl query 5 in stream 0 --- start template query80a.tpl query 6 in stream 0 -with /* TPC-DS query80a.tpl 0.6 */ ssr as - (select s_store_id as store_id, - sum(ss_ext_sales_price) as sales, - sum(coalesce(sr_return_amt, 0)) as returns, - sum(ss_net_profit - coalesce(sr_net_loss, 0)) as profit - from store_sales left outer join store_returns on - (ss_item_sk = sr_item_sk and ss_ticket_number = sr_ticket_number), - date_dim, - store, - item, - promotion - where ss_sold_date_sk = d_date_sk - and d_date between cast('2002-08-04' as date) - and dateadd(day,30,cast('2002-08-04' as date)) - and ss_store_sk = s_store_sk - and ss_item_sk = i_item_sk - and i_current_price > 50 - and ss_promo_sk = p_promo_sk - and p_channel_tv = 'N' - group by s_store_id) - , - csr as - (select cp_catalog_page_id as catalog_page_id, - sum(cs_ext_sales_price) as sales, - sum(coalesce(cr_return_amount, 0)) as returns, - sum(cs_net_profit - coalesce(cr_net_loss, 0)) as profit - from catalog_sales left outer join catalog_returns on - (cs_item_sk = cr_item_sk and cs_order_number = cr_order_number), - date_dim, - catalog_page, - item, - promotion - where cs_sold_date_sk = d_date_sk - and d_date between cast('2002-08-04' as date) - and dateadd(day,30,cast('2002-08-04' as date)) - and cs_catalog_page_sk = cp_catalog_page_sk - and cs_item_sk = i_item_sk - and i_current_price > 50 - and cs_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(ws_ext_sales_price) as sales, - sum(coalesce(wr_return_amt, 0)) as returns, - sum(ws_net_profit - coalesce(wr_net_loss, 0)) as profit - from web_sales left outer join web_returns on - (ws_item_sk = wr_item_sk and ws_order_number = wr_order_number), - date_dim, - web_site, - item, - promotion - where ws_sold_date_sk = d_date_sk - and d_date between cast('2002-08-04' as date) - and dateadd(day,30,cast('2002-08-04' as date)) - and ws_web_site_sk = web_site_sk - and ws_item_sk = i_item_sk - and i_current_price > 50 - and ws_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by web_site_id) -, -results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || store_id as id - , sales - , returns - , profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || catalog_page_id as id - , sales - , returns - , profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , profit - from wsr - ) x - group by channel, id) - - select channel - , id - , sales - , returns - , profit - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results - ) foo - order by channel, id - limit 100; - --- end template query80a.tpl query 6 in stream 0 --- start template query32.tpl query 7 in stream 0 -select /* TPC-DS query32.tpl 0.7 */ sum(cs_ext_discount_amt) as "excess discount amount" -from - catalog_sales - ,item - ,date_dim -where -i_manufact_id = 283 -and i_item_sk = cs_item_sk -and d_date between '1999-02-22' and - dateadd(day,90,cast('1999-02-22' as date)) -and d_date_sk = cs_sold_date_sk -and cs_ext_discount_amt - > ( - select - 1.3 * avg(cs_ext_discount_amt) - from - catalog_sales - ,date_dim - where - cs_item_sk = i_item_sk - and d_date between '1999-02-22' and - dateadd(day,90,cast('1999-02-22' as date)) - and d_date_sk = cs_sold_date_sk - ) -limit 100; - --- end template query32.tpl query 7 in stream 0 --- start template query19.tpl query 8 in stream 0 -select /* TPC-DS query19.tpl 0.8 */ i_brand_id brand_id, i_brand brand, i_manufact_id, i_manufact, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item,customer,customer_address,store - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=8 - and d_moy=11 - and d_year=1999 - and ss_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and substring(ca_zip,1,5) <> substring(s_zip,1,5) - and ss_store_sk = s_store_sk - group by i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact - order by ext_price desc - ,i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact -limit 100 ; - --- end template query19.tpl query 8 in stream 0 --- start template query25.tpl query 9 in stream 0 -select /* TPC-DS query25.tpl 0.9 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,min(ss_net_profit) as store_sales_profit - ,min(sr_net_loss) as store_returns_loss - ,min(cs_net_profit) as catalog_sales_profit - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 2002 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 10 - and d2.d_year = 2002 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_moy between 4 and 10 - and d3.d_year = 2002 - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query25.tpl query 9 in stream 0 --- start template query78.tpl query 10 in stream 0 -with /* TPC-DS query78.tpl 0.10 */ ws as - (select d_year AS ws_sold_year, ws_item_sk, - ws_bill_customer_sk ws_customer_sk, - sum(ws_quantity) ws_qty, - sum(ws_wholesale_cost) ws_wc, - sum(ws_sales_price) ws_sp - from web_sales - left join web_returns on wr_order_number=ws_order_number and ws_item_sk=wr_item_sk - join date_dim on ws_sold_date_sk = d_date_sk - where wr_order_number is null - group by d_year, ws_item_sk, ws_bill_customer_sk - ), -cs as - (select d_year AS cs_sold_year, cs_item_sk, - cs_bill_customer_sk cs_customer_sk, - sum(cs_quantity) cs_qty, - sum(cs_wholesale_cost) cs_wc, - sum(cs_sales_price) cs_sp - from catalog_sales - left join catalog_returns on cr_order_number=cs_order_number and cs_item_sk=cr_item_sk - join date_dim on cs_sold_date_sk = d_date_sk - where cr_order_number is null - group by d_year, cs_item_sk, cs_bill_customer_sk - ), -ss as - (select d_year AS ss_sold_year, ss_item_sk, - ss_customer_sk, - sum(ss_quantity) ss_qty, - sum(ss_wholesale_cost) ss_wc, - sum(ss_sales_price) ss_sp - from store_sales - left join store_returns on sr_ticket_number=ss_ticket_number and ss_item_sk=sr_item_sk - join date_dim on ss_sold_date_sk = d_date_sk - where sr_ticket_number is null - group by d_year, ss_item_sk, ss_customer_sk - ) - select -ss_customer_sk, -round(ss_qty/(coalesce(ws_qty,0)+coalesce(cs_qty,0)),2) ratio, -ss_qty store_qty, ss_wc store_wholesale_cost, ss_sp store_sales_price, -coalesce(ws_qty,0)+coalesce(cs_qty,0) other_chan_qty, -coalesce(ws_wc,0)+coalesce(cs_wc,0) other_chan_wholesale_cost, -coalesce(ws_sp,0)+coalesce(cs_sp,0) other_chan_sales_price -from ss -left join ws on (ws_sold_year=ss_sold_year and ws_item_sk=ss_item_sk and ws_customer_sk=ss_customer_sk) -left join cs on (cs_sold_year=ss_sold_year and cs_item_sk=ss_item_sk and cs_customer_sk=ss_customer_sk) -where (coalesce(ws_qty,0)>0 or coalesce(cs_qty, 0)>0) and ss_sold_year=2001 -order by - ss_customer_sk, - ss_qty desc, ss_wc desc, ss_sp desc, - other_chan_qty, - other_chan_wholesale_cost, - other_chan_sales_price, - ratio -limit 100; - --- end template query78.tpl query 10 in stream 0 --- start template query86a.tpl query 11 in stream 0 -with /* TPC-DS query86a.tpl 0.11 */ results as -( select sum(ws_net_paid) as total_sum, i_category, i_class, 0 as g_category, 0 as g_class - from - web_sales - ,date_dim d1 - ,item - where - d1.d_month_seq between 1205 and 1205+11 - and d1.d_date_sk = ws_sold_date_sk - and i_item_sk = ws_item_sk - group by i_category,i_class - ) , - - results_rollup as -( select total_sum ,i_category ,i_class, g_category, g_class, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum, i_category, NULL as i_class, 0 as g_category, 1 as g_class, 1 as lochierarchy from results group by i_category - union - select sum(total_sum) as total_sum, NULL as i_category, NULL as i_class, 1 as g_category, 1 as g_class, 2 as lochierarchy from results) - select - total_sum ,i_category ,i_class, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_class = 0 then i_category end - order by total_sum desc) as rank_within_parent - from - results_rollup - order by - lochierarchy desc, - case when lochierarchy = 0 then i_category end, - rank_within_parent - limit 100; - --- end template query86a.tpl query 11 in stream 0 --- start template query1.tpl query 12 in stream 0 -with /* TPC-DS query1.tpl 0.12 */ customer_total_return as -(select sr_customer_sk as ctr_customer_sk -,sr_store_sk as ctr_store_sk -,sum(SR_RETURN_AMT_INC_TAX) as ctr_total_return -from store_returns -,date_dim -where sr_returned_date_sk = d_date_sk -and d_year =1999 -group by sr_customer_sk -,sr_store_sk) - select c_customer_id -from customer_total_return ctr1 -,store -,customer -where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 -from customer_total_return ctr2 -where ctr1.ctr_store_sk = ctr2.ctr_store_sk) -and s_store_sk = ctr1.ctr_store_sk -and s_state = 'VT' -and ctr1.ctr_customer_sk = c_customer_sk -order by c_customer_id -limit 100; - --- end template query1.tpl query 12 in stream 0 --- start template query91.tpl query 13 in stream 0 -select /* TPC-DS query91.tpl 0.13 */ - cc_call_center_id Call_Center, - cc_name Call_Center_Name, - cc_manager Manager, - sum(cr_net_loss) Returns_Loss -from - call_center, - catalog_returns, - date_dim, - customer, - customer_address, - customer_demographics, - household_demographics -where - cr_call_center_sk = cc_call_center_sk -and cr_returned_date_sk = d_date_sk -and cr_returning_customer_sk= c_customer_sk -and cd_demo_sk = c_current_cdemo_sk -and hd_demo_sk = c_current_hdemo_sk -and ca_address_sk = c_current_addr_sk -and d_year = 2002 -and d_moy = 11 -and ( (cd_marital_status = 'M' and cd_education_status = 'Unknown') - or(cd_marital_status = 'W' and cd_education_status = 'Advanced Degree')) -and hd_buy_potential like 'Unknown%' -and ca_gmt_offset = -6 -group by cc_call_center_id,cc_name,cc_manager,cd_marital_status,cd_education_status -order by sum(cr_net_loss) desc; - --- end template query91.tpl query 13 in stream 0 --- start template query21.tpl query 14 in stream 0 -select /* TPC-DS query21.tpl 0.14 */ * - from(select w_warehouse_name - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('2000-05-19' as date)) - then inv_quantity_on_hand - else 0 end) as inv_before - ,sum(case when (cast(d_date as date) >= cast ('2000-05-19' as date)) - then inv_quantity_on_hand - else 0 end) as inv_after - from inventory - ,warehouse - ,item - ,date_dim - where i_current_price between 0.99 and 1.49 - and i_item_sk = inv_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('2000-05-19' as date)) - and dateadd(day,30,cast ('2000-05-19' as date)) - group by w_warehouse_name, i_item_id) x - where (case when inv_before > 0 - then inv_after / inv_before - else null - end) between 2.0/3.0 and 3.0/2.0 - order by w_warehouse_name - ,i_item_id - limit 100; - --- end template query21.tpl query 14 in stream 0 --- start template query43.tpl query 15 in stream 0 -select /* TPC-DS query43.tpl 0.15 */ s_store_name, s_store_id, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from date_dim, store_sales, store - where d_date_sk = ss_sold_date_sk and - s_store_sk = ss_store_sk and - s_gmt_offset = -5 and - d_year = 2000 - group by s_store_name, s_store_id - order by s_store_name, s_store_id,sun_sales,mon_sales,tue_sales,wed_sales,thu_sales,fri_sales,sat_sales - limit 100; - --- end template query43.tpl query 15 in stream 0 --- start template query27a.tpl query 16 in stream 0 -with /* TPC-DS query27a.tpl 0.16 */ results as - (select i_item_id, - s_state, 0 as g_state, - ss_quantity agg1, - ss_list_price agg2, - ss_coupon_amt agg3, - ss_sales_price agg4 - from store_sales, customer_demographics, date_dim, store, item - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_store_sk = s_store_sk and - ss_cdemo_sk = cd_demo_sk and - cd_gender = 'F' and - cd_marital_status = 'S' and - cd_education_status = 'Advanced Degree' and - d_year = 1999 and - s_state in ('TX','MI', 'IL', 'MN', 'NM', 'SD') - ) - - select i_item_id, - s_state, g_state, agg1, agg2, agg3, agg4 - from ( - select i_item_id, s_state, 0 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4 from results - group by i_item_id, s_state - union all - select i_item_id, NULL AS s_state, 1 AS g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as s_state, 1 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - ) foo - order by i_item_id, s_state - limit 100; - --- end template query27a.tpl query 16 in stream 0 --- start template query94.tpl query 17 in stream 0 -select /* TPC-DS query94.tpl 0.17 */ - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2000-4-01' and - dateadd(day,60,cast('2000-4-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'ND' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and exists (select * - from web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) -and not exists(select * - from web_returns wr1 - where ws1.ws_order_number = wr1.wr_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query94.tpl query 17 in stream 0 --- start template query45.tpl query 18 in stream 0 -select /* TPC-DS query45.tpl 0.18 */ ca_zip, ca_state, sum(ws_sales_price) - from web_sales, customer, customer_address, date_dim, item - where ws_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ws_item_sk = i_item_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', '85392', '85460', '80348', '81792') - or - i_item_id in (select i_item_id - from item - where i_item_sk in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29) - ) - ) - and ws_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 2000 - group by ca_zip, ca_state - order by ca_zip, ca_state - limit 100; - --- end template query45.tpl query 18 in stream 0 --- start template query58.tpl query 19 in stream 0 -with /* TPC-DS query58.tpl 0.19 */ ss_items as - (select i_item_id item_id - ,sum(ss_ext_sales_price) ss_item_rev - from store_sales - ,item - ,date_dim - where ss_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '1998-04-13')) - and ss_sold_date_sk = d_date_sk - group by i_item_id), - cs_items as - (select i_item_id item_id - ,sum(cs_ext_sales_price) cs_item_rev - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '1998-04-13')) - and cs_sold_date_sk = d_date_sk - group by i_item_id), - ws_items as - (select i_item_id item_id - ,sum(ws_ext_sales_price) ws_item_rev - from web_sales - ,item - ,date_dim - where ws_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq =(select d_week_seq - from date_dim - where d_date = '1998-04-13')) - and ws_sold_date_sk = d_date_sk - group by i_item_id) - select ss_items.item_id - ,ss_item_rev - ,ss_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ss_dev - ,cs_item_rev - ,cs_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 cs_dev - ,ws_item_rev - ,ws_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ws_dev - ,(ss_item_rev+cs_item_rev+ws_item_rev)/3 average - from ss_items,cs_items,ws_items - where ss_items.item_id=cs_items.item_id - and ss_items.item_id=ws_items.item_id - and ss_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - and ss_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and cs_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and cs_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and ws_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and ws_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - order by item_id - ,ss_item_rev - limit 100; - --- end template query58.tpl query 19 in stream 0 --- start template query64.tpl query 20 in stream 0 -with /* TPC-DS query64.tpl 0.20 */ cs_ui as - (select cs_item_sk - ,sum(cs_ext_list_price) as sale,sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit) as refund - from catalog_sales - ,catalog_returns - where cs_item_sk = cr_item_sk - and cs_order_number = cr_order_number - group by cs_item_sk - having sum(cs_ext_list_price)>2*sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit)), -cross_sales as - (select i_product_name product_name - ,i_item_sk item_sk - ,s_store_name store_name - ,s_zip store_zip - ,ad1.ca_street_number b_street_number - ,ad1.ca_street_name b_street_name - ,ad1.ca_city b_city - ,ad1.ca_zip b_zip - ,ad2.ca_street_number c_street_number - ,ad2.ca_street_name c_street_name - ,ad2.ca_city c_city - ,ad2.ca_zip c_zip - ,d1.d_year as syear - ,d2.d_year as fsyear - ,d3.d_year s2year - ,count(*) cnt - ,sum(ss_wholesale_cost) s1 - ,sum(ss_list_price) s2 - ,sum(ss_coupon_amt) s3 - FROM store_sales - ,store_returns - ,cs_ui - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,customer - ,customer_demographics cd1 - ,customer_demographics cd2 - ,promotion - ,household_demographics hd1 - ,household_demographics hd2 - ,customer_address ad1 - ,customer_address ad2 - ,income_band ib1 - ,income_band ib2 - ,item - WHERE ss_store_sk = s_store_sk AND - ss_sold_date_sk = d1.d_date_sk AND - ss_customer_sk = c_customer_sk AND - ss_cdemo_sk= cd1.cd_demo_sk AND - ss_hdemo_sk = hd1.hd_demo_sk AND - ss_addr_sk = ad1.ca_address_sk and - ss_item_sk = i_item_sk and - ss_item_sk = sr_item_sk and - ss_ticket_number = sr_ticket_number and - ss_item_sk = cs_ui.cs_item_sk and - c_current_cdemo_sk = cd2.cd_demo_sk AND - c_current_hdemo_sk = hd2.hd_demo_sk AND - c_current_addr_sk = ad2.ca_address_sk and - c_first_sales_date_sk = d2.d_date_sk and - c_first_shipto_date_sk = d3.d_date_sk and - ss_promo_sk = p_promo_sk and - hd1.hd_income_band_sk = ib1.ib_income_band_sk and - hd2.hd_income_band_sk = ib2.ib_income_band_sk and - cd1.cd_marital_status <> cd2.cd_marital_status and - i_color in ('coral','drab','orchid','bisque','antique','snow') and - i_current_price between 68 and 68 + 10 and - i_current_price between 68 + 1 and 68 + 15 -group by i_product_name - ,i_item_sk - ,s_store_name - ,s_zip - ,ad1.ca_street_number - ,ad1.ca_street_name - ,ad1.ca_city - ,ad1.ca_zip - ,ad2.ca_street_number - ,ad2.ca_street_name - ,ad2.ca_city - ,ad2.ca_zip - ,d1.d_year - ,d2.d_year - ,d3.d_year -) -select cs1.product_name - ,cs1.store_name - ,cs1.store_zip - ,cs1.b_street_number - ,cs1.b_street_name - ,cs1.b_city - ,cs1.b_zip - ,cs1.c_street_number - ,cs1.c_street_name - ,cs1.c_city - ,cs1.c_zip - ,cs1.syear - ,cs1.cnt - ,cs1.s1 as s11 - ,cs1.s2 as s21 - ,cs1.s3 as s31 - ,cs2.s1 as s12 - ,cs2.s2 as s22 - ,cs2.s3 as s32 - ,cs2.syear - ,cs2.cnt -from cross_sales cs1,cross_sales cs2 -where cs1.item_sk=cs2.item_sk and - cs1.syear = 2000 and - cs2.syear = 2000 + 1 and - cs2.cnt <= cs1.cnt and - cs1.store_name = cs2.store_name and - cs1.store_zip = cs2.store_zip -order by cs1.product_name - ,cs1.store_name - ,cs2.cnt - ,cs1.s1 - ,cs2.s1; - --- end template query64.tpl query 20 in stream 0 --- start template query36a.tpl query 21 in stream 0 -with /* TPC-DS query36a.tpl 0.21 */ results as - (select - sum(ss_net_profit) as ss_net_profit, sum(ss_ext_sales_price) as ss_ext_sales_price, - sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin - ,i_category - ,i_class - ,0 as g_category, 0 as g_class - from - store_sales - ,date_dim d1 - ,item - ,store - where - d1.d_year = 2002 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and s_state in ('MN','TN','MI','WV', - 'NC','GA','TN','OH') - group by i_category,i_class) - , - results_rollup as - (select gross_margin ,i_category ,i_class,0 as t_category, 0 as t_class, 0 as lochierarchy from results - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - i_category, NULL AS i_class, 0 as t_category, 1 as t_class, 1 as lochierarchy from results group by i_category - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - NULL AS i_category ,NULL AS i_class, 1 as t_category, 1 as t_class, 2 as lochierarchy from results) - select - gross_margin ,i_category ,i_class, lochierarchy,rank() over ( - partition by lochierarchy, case when t_class = 0 then i_category end - order by gross_margin asc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then i_category end - ,rank_within_parent - limit 100; - --- end template query36a.tpl query 21 in stream 0 --- start template query33.tpl query 22 in stream 0 -with /* TPC-DS query33.tpl 0.22 */ ss as ( - select - i_manufact_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Jewelry')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 3 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_manufact_id), - cs as ( - select - i_manufact_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Jewelry')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 3 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_manufact_id), - ws as ( - select - i_manufact_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Jewelry')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 3 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_manufact_id) - select i_manufact_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_manufact_id - order by total_sales -limit 100; - --- end template query33.tpl query 22 in stream 0 --- start template query46.tpl query 23 in stream 0 -select /* TPC-DS query46.tpl 0.23 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and (household_demographics.hd_dep_count = 9 or - household_demographics.hd_vehicle_count= 1) - and date_dim.d_dow in (6,0) - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_city in ('New Hope','Hamilton','Georgetown','Hillcrest','Walnut Grove') - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,ca_city) dn,customer,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - limit 100; - --- end template query46.tpl query 23 in stream 0 --- start template query62.tpl query 24 in stream 0 -select /* TPC-DS query62.tpl 0.24 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 30) and - (ws_ship_date_sk - ws_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 60) and - (ws_ship_date_sk - ws_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 90) and - (ws_ship_date_sk - ws_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - web_sales - ,warehouse - ,ship_mode - ,web_site - ,date_dim -where - d_month_seq between 1185 and 1185 + 11 -and ws_ship_date_sk = d_date_sk -and ws_warehouse_sk = w_warehouse_sk -and ws_ship_mode_sk = sm_ship_mode_sk -and ws_web_site_sk = web_site_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -limit 100; - --- end template query62.tpl query 24 in stream 0 --- start template query16.tpl query 25 in stream 0 -select /* TPC-DS query16.tpl 0.25 */ - count(distinct cs_order_number) as "order count" - ,sum(cs_ext_ship_cost) as "total shipping cost" - ,sum(cs_net_profit) as "total net profit" -from - catalog_sales cs1 - ,date_dim - ,customer_address - ,call_center -where - d_date between '2000-2-01' and - dateadd(day, 60, cast('2000-2-01' as date)) -and cs1.cs_ship_date_sk = d_date_sk -and cs1.cs_ship_addr_sk = ca_address_sk -and ca_state = 'AL' -and cs1.cs_call_center_sk = cc_call_center_sk -and cc_county in ('Dauphin County','Levy County','Luce County','Jackson County', - 'Daviess County' -) -and exists (select * - from catalog_sales cs2 - where cs1.cs_order_number = cs2.cs_order_number - and cs1.cs_warehouse_sk <> cs2.cs_warehouse_sk) -and not exists(select * - from catalog_returns cr1 - where cs1.cs_order_number = cr1.cr_order_number) -order by count(distinct cs_order_number) -limit 100; - --- end template query16.tpl query 25 in stream 0 --- start template query10.tpl query 26 in stream 0 -select /* TPC-DS query10.tpl 0.26 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3, - cd_dep_count, - count(*) cnt4, - cd_dep_employed_count, - count(*) cnt5, - cd_dep_college_count, - count(*) cnt6 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_county in ('Chautauqua County','Cherokee County','Bell County','Washington County','Clarke County') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 2 and 2+3) and - (exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 2 ANd 2+3) or - exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 2 and 2+3)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count -limit 100; - --- end template query10.tpl query 26 in stream 0 --- start template query63.tpl query 27 in stream 0 -select /* TPC-DS query63.tpl 0.27 */ * -from (select i_manager_id - ,sum(ss_sales_price) sum_sales - ,avg(sum(ss_sales_price)) over (partition by i_manager_id) avg_monthly_sales - from item - ,store_sales - ,date_dim - ,store - where ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and d_month_seq in (1223,1223+1,1223+2,1223+3,1223+4,1223+5,1223+6,1223+7,1223+8,1223+9,1223+10,1223+11) - and (( i_category in ('Books','Children','Electronics') - and i_class in ('personal','portable','reference','self-help') - and i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) - or( i_category in ('Women','Music','Men') - and i_class in ('accessories','classical','fragrances','pants') - and i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manager_id, d_moy) tmp1 -where case when avg_monthly_sales > 0 then abs (sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 -order by i_manager_id - ,avg_monthly_sales - ,sum_sales -limit 100; - --- end template query63.tpl query 27 in stream 0 --- start template query69.tpl query 28 in stream 0 -select /* TPC-DS query69.tpl 0.28 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_state in ('CO','SD','TX') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 1 and 1+2) and - (not exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 1 and 1+2) and - not exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 1 and 1+2)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - limit 100; - --- end template query69.tpl query 28 in stream 0 --- start template query60.tpl query 29 in stream 0 -with /* TPC-DS query60.tpl 0.29 */ ss as ( - select - i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Music')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 8 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id), - cs as ( - select - i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Music')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 8 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id), - ws as ( - select - i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Music')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 8 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id) - select - i_item_id -,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by i_item_id - ,total_sales - limit 100; - --- end template query60.tpl query 29 in stream 0 --- start template query59.tpl query 30 in stream 0 -with /* TPC-DS query59.tpl 0.30 */ wss as - (select d_week_seq, - ss_store_sk, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - group by d_week_seq,ss_store_sk - ) - select s_store_name1,s_store_id1,d_week_seq1 - ,sun_sales1/sun_sales2,mon_sales1/mon_sales2 - ,tue_sales1/tue_sales2,wed_sales1/wed_sales2,thu_sales1/thu_sales2 - ,fri_sales1/fri_sales2,sat_sales1/sat_sales2 - from - (select s_store_name s_store_name1,wss.d_week_seq d_week_seq1 - ,s_store_id s_store_id1,sun_sales sun_sales1 - ,mon_sales mon_sales1,tue_sales tue_sales1 - ,wed_sales wed_sales1,thu_sales thu_sales1 - ,fri_sales fri_sales1,sat_sales sat_sales1 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1182 and 1182 + 11) y, - (select s_store_name s_store_name2,wss.d_week_seq d_week_seq2 - ,s_store_id s_store_id2,sun_sales sun_sales2 - ,mon_sales mon_sales2,tue_sales tue_sales2 - ,wed_sales wed_sales2,thu_sales thu_sales2 - ,fri_sales fri_sales2,sat_sales sat_sales2 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1182+ 12 and 1182 + 23) x - where s_store_id1=s_store_id2 - and d_week_seq1=d_week_seq2-52 - order by s_store_name1,s_store_id1,d_week_seq1 -limit 100; - --- end template query59.tpl query 30 in stream 0 --- start template query37.tpl query 31 in stream 0 -select /* TPC-DS query37.tpl 0.31 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, catalog_sales - where i_current_price between 24 and 24 + 30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('2002-06-22' as date) and dateadd(day,60,cast('2002-06-22' as date)) - and i_manufact_id in (951,717,692,953) - and inv_quantity_on_hand between 100 and 500 - and cs_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query37.tpl query 31 in stream 0 --- start template query98.tpl query 32 in stream 0 -select /* TPC-DS query98.tpl 0.32 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ss_ext_sales_price) as itemrevenue - ,sum(ss_ext_sales_price)*100/sum(sum(ss_ext_sales_price)) over - (partition by i_class) as revenueratio -from - store_sales - ,item - ,date_dim -where - ss_item_sk = i_item_sk - and i_category in ('Men', 'Music', 'Shoes') - and ss_sold_date_sk = d_date_sk - and d_date between cast('2001-03-17' as date) - and dateadd(day,30,cast('2001-03-17' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio; - --- end template query98.tpl query 32 in stream 0 --- start template query85.tpl query 33 in stream 0 -select /* TPC-DS query85.tpl 0.33 */ substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) - from web_sales, web_returns, web_page, customer_demographics cd1, - customer_demographics cd2, customer_address, date_dim, reason - where ws_web_page_sk = wp_web_page_sk - and ws_item_sk = wr_item_sk - and ws_order_number = wr_order_number - and ws_sold_date_sk = d_date_sk and d_year = 2000 - and cd1.cd_demo_sk = wr_refunded_cdemo_sk - and cd2.cd_demo_sk = wr_returning_cdemo_sk - and ca_address_sk = wr_refunded_addr_sk - and r_reason_sk = wr_reason_sk - and - ( - ( - cd1.cd_marital_status = 'S' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Secondary' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 100.00 and 150.00 - ) - or - ( - cd1.cd_marital_status = 'U' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Advanced Degree' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 50.00 and 100.00 - ) - or - ( - cd1.cd_marital_status = 'W' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = '4 yr Degree' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ca_country = 'United States' - and - ca_state in ('VA', 'MI', 'ID') - and ws_net_profit between 100 and 200 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('TX', 'LA', 'KS') - and ws_net_profit between 150 and 300 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('IA', 'NY', 'NM') - and ws_net_profit between 50 and 250 - ) - ) -group by r_reason_desc -order by substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) -limit 100; - --- end template query85.tpl query 33 in stream 0 --- start template query70a.tpl query 34 in stream 0 -with /* TPC-DS query70a.tpl 0.34 */ results as -( select - sum(ss_net_profit) as total_sum ,s_state ,s_county, 0 as gstate, 0 as g_county - from - store_sales - ,date_dim d1 - ,store - where - d1.d_month_seq between 1188 and 1188 + 11 - and d1.d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - and s_state in - ( select s_state - from (select s_state as s_state, - rank() over ( partition by s_state order by sum(ss_net_profit) desc) as ranking - from store_sales, store, date_dim - where d_month_seq between 1188 and 1188 + 11 - and d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - group by s_state - ) tmp1 - where ranking <= 5) - group by s_state,s_county) , - results_rollup as -(select total_sum ,s_state ,s_county, 0 as g_state, 0 as g_county, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum,s_state, NULL as s_county, 0 as g_state, 1 as g_county, 1 as lochierarchy from results group by s_state - union - select sum(total_sum) as total_sum ,NULL as s_state ,NULL as s_county, 1 as g_state, 1 as g_county, 2 as lochierarchy from results) - select total_sum ,s_state ,s_county, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_county = 0 then s_state end - order by total_sum desc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then s_state end - ,rank_within_parent - limit 100; - --- end template query70a.tpl query 34 in stream 0 --- start template query67a.tpl query 35 in stream 0 -with /* TPC-DS query67a.tpl 0.35 */ results as -( select i_category ,i_class ,i_brand ,i_product_name ,d_year ,d_qoy ,d_moy ,s_store_id - ,sum(coalesce(ss_sales_price*ss_quantity,0)) sumsales - from store_sales ,date_dim ,store ,item - where ss_sold_date_sk=d_date_sk - and ss_item_sk=i_item_sk - and ss_store_sk = s_store_sk - and d_month_seq between 1219 and 1219 + 11 - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy,s_store_id) - , - results_rollup as - (select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, s_store_id, sumsales - from results - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy - union all - select i_category, i_class, i_brand, i_product_name, d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year - union all - select i_category, i_class, i_brand, i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name - union all - select i_category, i_class, i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand - union all - select i_category, i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class - union all - select i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category - union all - select null i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results) - - select * -from (select i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rank() over (partition by i_category order by sumsales desc) rk - from results_rollup) dw2 -where rk <= 100 -order by i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rk -limit 100; - --- end template query67a.tpl query 35 in stream 0 --- start template query28.tpl query 36 in stream 0 -select /* TPC-DS query28.tpl 0.36 */ * -from (select avg(ss_list_price) B1_LP - ,count(ss_list_price) B1_CNT - ,count(distinct ss_list_price) B1_CNTD - from store_sales - where ss_quantity between 0 and 5 - and (ss_list_price between 85 and 85+10 - or ss_coupon_amt between 725 and 725+1000 - or ss_wholesale_cost between 18 and 18+20)) B1, - (select avg(ss_list_price) B2_LP - ,count(ss_list_price) B2_CNT - ,count(distinct ss_list_price) B2_CNTD - from store_sales - where ss_quantity between 6 and 10 - and (ss_list_price between 6 and 6+10 - or ss_coupon_amt between 11704 and 11704+1000 - or ss_wholesale_cost between 15 and 15+20)) B2, - (select avg(ss_list_price) B3_LP - ,count(ss_list_price) B3_CNT - ,count(distinct ss_list_price) B3_CNTD - from store_sales - where ss_quantity between 11 and 15 - and (ss_list_price between 72 and 72+10 - or ss_coupon_amt between 5172 and 5172+1000 - or ss_wholesale_cost between 27 and 27+20)) B3, - (select avg(ss_list_price) B4_LP - ,count(ss_list_price) B4_CNT - ,count(distinct ss_list_price) B4_CNTD - from store_sales - where ss_quantity between 16 and 20 - and (ss_list_price between 104 and 104+10 - or ss_coupon_amt between 2440 and 2440+1000 - or ss_wholesale_cost between 65 and 65+20)) B4, - (select avg(ss_list_price) B5_LP - ,count(ss_list_price) B5_CNT - ,count(distinct ss_list_price) B5_CNTD - from store_sales - where ss_quantity between 21 and 25 - and (ss_list_price between 153 and 153+10 - or ss_coupon_amt between 1350 and 1350+1000 - or ss_wholesale_cost between 3 and 3+20)) B5, - (select avg(ss_list_price) B6_LP - ,count(ss_list_price) B6_CNT - ,count(distinct ss_list_price) B6_CNTD - from store_sales - where ss_quantity between 26 and 30 - and (ss_list_price between 64 and 64+10 - or ss_coupon_amt between 2991 and 2991+1000 - or ss_wholesale_cost between 7 and 7+20)) B6 -limit 100; - --- end template query28.tpl query 36 in stream 0 --- start template query81.tpl query 37 in stream 0 -with /* TPC-DS query81.tpl 0.37 */ customer_total_return as - (select cr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(cr_return_amt_inc_tax) as ctr_total_return - from catalog_returns - ,date_dim - ,customer_address - where cr_returned_date_sk = d_date_sk - and d_year =1999 - and cr_returning_addr_sk = ca_address_sk - group by cr_returning_customer_sk - ,ca_state ) - select c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'TN' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - limit 100; - --- end template query81.tpl query 37 in stream 0 --- start template query97.tpl query 38 in stream 0 -with /* TPC-DS query97.tpl 0.38 */ ssci as ( -select ss_customer_sk customer_sk - ,ss_item_sk item_sk -from store_sales,date_dim -where ss_sold_date_sk = d_date_sk - and d_month_seq between 1180 and 1180 + 11 -group by ss_customer_sk - ,ss_item_sk), -csci as( - select cs_bill_customer_sk customer_sk - ,cs_item_sk item_sk -from catalog_sales,date_dim -where cs_sold_date_sk = d_date_sk - and d_month_seq between 1180 and 1180 + 11 -group by cs_bill_customer_sk - ,cs_item_sk) - select sum(case when ssci.customer_sk is not null and csci.customer_sk is null then 1 else 0 end) store_only - ,sum(case when ssci.customer_sk is null and csci.customer_sk is not null then 1 else 0 end) catalog_only - ,sum(case when ssci.customer_sk is not null and csci.customer_sk is not null then 1 else 0 end) store_and_catalog -from ssci full outer join csci on (ssci.customer_sk=csci.customer_sk - and ssci.item_sk = csci.item_sk) -limit 100; - --- end template query97.tpl query 38 in stream 0 --- start template query66.tpl query 39 in stream 0 -select /* TPC-DS query66.tpl 0.39 */ - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - ,sum(jan_sales) as jan_sales - ,sum(feb_sales) as feb_sales - ,sum(mar_sales) as mar_sales - ,sum(apr_sales) as apr_sales - ,sum(may_sales) as may_sales - ,sum(jun_sales) as jun_sales - ,sum(jul_sales) as jul_sales - ,sum(aug_sales) as aug_sales - ,sum(sep_sales) as sep_sales - ,sum(oct_sales) as oct_sales - ,sum(nov_sales) as nov_sales - ,sum(dec_sales) as dec_sales - ,sum(jan_sales/w_warehouse_sq_ft) as jan_sales_per_sq_foot - ,sum(feb_sales/w_warehouse_sq_ft) as feb_sales_per_sq_foot - ,sum(mar_sales/w_warehouse_sq_ft) as mar_sales_per_sq_foot - ,sum(apr_sales/w_warehouse_sq_ft) as apr_sales_per_sq_foot - ,sum(may_sales/w_warehouse_sq_ft) as may_sales_per_sq_foot - ,sum(jun_sales/w_warehouse_sq_ft) as jun_sales_per_sq_foot - ,sum(jul_sales/w_warehouse_sq_ft) as jul_sales_per_sq_foot - ,sum(aug_sales/w_warehouse_sq_ft) as aug_sales_per_sq_foot - ,sum(sep_sales/w_warehouse_sq_ft) as sep_sales_per_sq_foot - ,sum(oct_sales/w_warehouse_sq_ft) as oct_sales_per_sq_foot - ,sum(nov_sales/w_warehouse_sq_ft) as nov_sales_per_sq_foot - ,sum(dec_sales/w_warehouse_sq_ft) as dec_sales_per_sq_foot - ,sum(jan_net) as jan_net - ,sum(feb_net) as feb_net - ,sum(mar_net) as mar_net - ,sum(apr_net) as apr_net - ,sum(may_net) as may_net - ,sum(jun_net) as jun_net - ,sum(jul_net) as jul_net - ,sum(aug_net) as aug_net - ,sum(sep_net) as sep_net - ,sum(oct_net) as oct_net - ,sum(nov_net) as nov_net - ,sum(dec_net) as dec_net - from ( - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'BARIAN' || ',' || 'FEDEX' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then ws_ext_sales_price* ws_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then ws_ext_sales_price* ws_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then ws_ext_sales_price* ws_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then ws_ext_sales_price* ws_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then ws_ext_sales_price* ws_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then ws_ext_sales_price* ws_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then ws_ext_sales_price* ws_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then ws_ext_sales_price* ws_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then ws_ext_sales_price* ws_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then ws_ext_sales_price* ws_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then ws_ext_sales_price* ws_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then ws_ext_sales_price* ws_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as dec_net - from - web_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - ws_warehouse_sk = w_warehouse_sk - and ws_sold_date_sk = d_date_sk - and ws_sold_time_sk = t_time_sk - and ws_ship_mode_sk = sm_ship_mode_sk - and d_year = 2001 - and t_time between 2298 and 2298+28800 - and sm_carrier in ('BARIAN','FEDEX') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - union all - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'BARIAN' || ',' || 'FEDEX' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then cs_ext_sales_price* cs_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then cs_ext_sales_price* cs_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then cs_ext_sales_price* cs_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then cs_ext_sales_price* cs_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then cs_ext_sales_price* cs_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then cs_ext_sales_price* cs_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then cs_ext_sales_price* cs_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then cs_ext_sales_price* cs_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then cs_ext_sales_price* cs_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then cs_ext_sales_price* cs_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then cs_ext_sales_price* cs_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then cs_ext_sales_price* cs_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as dec_net - from - catalog_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and cs_sold_time_sk = t_time_sk - and cs_ship_mode_sk = sm_ship_mode_sk - and d_year = 2001 - and t_time between 2298 AND 2298+28800 - and sm_carrier in ('BARIAN','FEDEX') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - ) x - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - order by w_warehouse_name - limit 100; - --- end template query66.tpl query 39 in stream 0 --- start template query90.tpl query 40 in stream 0 -select /* TPC-DS query90.tpl 0.40 */ cast(amc as decimal(15,4))/cast(pmc as decimal(15,4)) am_pm_ratio - from ( select count(*) amc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 7 and 7+1 - and household_demographics.hd_dep_count = 9 - and web_page.wp_char_count between 5000 and 5200) at, - ( select count(*) pmc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 18 and 18+1 - and household_demographics.hd_dep_count = 9 - and web_page.wp_char_count between 5000 and 5200) pt - order by am_pm_ratio - limit 100; - --- end template query90.tpl query 40 in stream 0 --- start template query17.tpl query 41 in stream 0 -select /* TPC-DS query17.tpl 0.41 */ i_item_id - ,i_item_desc - ,s_state - ,count(ss_quantity) as store_sales_quantitycount - ,avg(ss_quantity) as store_sales_quantityave - ,stddev_samp(ss_quantity) as store_sales_quantitystdev - ,stddev_samp(ss_quantity)/avg(ss_quantity) as store_sales_quantitycov - ,count(sr_return_quantity) as store_returns_quantitycount - ,avg(sr_return_quantity) as store_returns_quantityave - ,stddev_samp(sr_return_quantity) as store_returns_quantitystdev - ,stddev_samp(sr_return_quantity)/avg(sr_return_quantity) as store_returns_quantitycov - ,count(cs_quantity) as catalog_sales_quantitycount ,avg(cs_quantity) as catalog_sales_quantityave - ,stddev_samp(cs_quantity) as catalog_sales_quantitystdev - ,stddev_samp(cs_quantity)/avg(cs_quantity) as catalog_sales_quantitycov - from store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where d1.d_quarter_name = '1998Q1' - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_quarter_name in ('1998Q1','1998Q2','1998Q3') - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_quarter_name in ('1998Q1','1998Q2','1998Q3') - group by i_item_id - ,i_item_desc - ,s_state - order by i_item_id - ,i_item_desc - ,s_state -limit 100; - --- end template query17.tpl query 41 in stream 0 --- start template query47.tpl query 42 in stream 0 -with /* TPC-DS query47.tpl 0.42 */ v1 as( - select i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, - s_store_name, s_company_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - s_store_name, s_company_name - order by d_year, d_moy) rn - from item, store_sales, date_dim, store - where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - ( - d_year = 2001 or - ( d_year = 2001-1 and d_moy =12) or - ( d_year = 2001+1 and d_moy =1) - ) - group by i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy), - v2 as( - select v1.s_store_name - ,v1.d_year, v1.d_moy - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1.s_store_name = v1_lag.s_store_name and - v1.s_store_name = v1_lead.s_store_name and - v1.s_company_name = v1_lag.s_company_name and - v1.s_company_name = v1_lead.s_company_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 2001 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, sum_sales - limit 100; - --- end template query47.tpl query 42 in stream 0 --- start template query95.tpl query 43 in stream 0 -with /* TPC-DS query95.tpl 0.43 */ ws_wh as -(select ws1.ws_order_number,ws1.ws_warehouse_sk wh1,ws2.ws_warehouse_sk wh2 - from web_sales ws1,web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) - select - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2002-3-01' and - dateadd(day,60,cast('2002-3-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'IA' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and ws1.ws_order_number in (select ws_order_number - from ws_wh) -and ws1.ws_order_number in (select wr_order_number - from web_returns,ws_wh - where wr_order_number = ws_wh.ws_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query95.tpl query 43 in stream 0 --- start template query92.tpl query 44 in stream 0 -select /* TPC-DS query92.tpl 0.44 */ - sum(ws_ext_discount_amt) as "Excess Discount Amount" -from - web_sales - ,item - ,date_dim -where -i_manufact_id = 992 -and i_item_sk = ws_item_sk -and d_date between '1998-02-02' and - dateadd(day,90,cast('1998-02-02' as date)) -and d_date_sk = ws_sold_date_sk -and ws_ext_discount_amt - > ( - SELECT - 1.3 * avg(ws_ext_discount_amt) - FROM - web_sales - ,date_dim - WHERE - ws_item_sk = i_item_sk - and d_date between '1998-02-02' and - dateadd(day,90,cast('1998-02-02' as date)) - and d_date_sk = ws_sold_date_sk - ) -order by sum(ws_ext_discount_amt) -limit 100; - --- end template query92.tpl query 44 in stream 0 --- start template query3.tpl query 45 in stream 0 -select /* TPC-DS query3.tpl 0.45 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_sales_price) sum_agg - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manufact_id = 810 - and dt.d_moy=11 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,sum_agg desc - ,brand_id - limit 100; - --- end template query3.tpl query 45 in stream 0 --- start template query51.tpl query 46 in stream 0 -WITH /* TPC-DS query51.tpl 0.46 */ web_v1 as ( -select - ws_item_sk item_sk, d_date, - sum(sum(ws_sales_price)) - over (partition by ws_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from web_sales - ,date_dim -where ws_sold_date_sk=d_date_sk - and d_month_seq between 1181 and 1181+11 - and ws_item_sk is not NULL -group by ws_item_sk, d_date), -store_v1 as ( -select - ss_item_sk item_sk, d_date, - sum(sum(ss_sales_price)) - over (partition by ss_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from store_sales - ,date_dim -where ss_sold_date_sk=d_date_sk - and d_month_seq between 1181 and 1181+11 - and ss_item_sk is not NULL -group by ss_item_sk, d_date) - select * -from (select item_sk - ,d_date - ,web_sales - ,store_sales - ,max(web_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) web_cumulative - ,max(store_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) store_cumulative - from (select case when web.item_sk is not null then web.item_sk else store.item_sk end item_sk - ,case when web.d_date is not null then web.d_date else store.d_date end d_date - ,web.cume_sales web_sales - ,store.cume_sales store_sales - from web_v1 web full outer join store_v1 store on (web.item_sk = store.item_sk - and web.d_date = store.d_date) - )x )y -where web_cumulative > store_cumulative -order by item_sk - ,d_date -limit 100; - --- end template query51.tpl query 46 in stream 0 --- start template query35a.tpl query 47 in stream 0 -select /* TPC-DS query35a.tpl 0.47 */ - ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - count(*) cnt1, - max(cd_dep_count), - min(cd_dep_count), - max(cd_dep_count), - cd_dep_employed_count, - count(*) cnt2, - max(cd_dep_employed_count), - min(cd_dep_employed_count), - max(cd_dep_employed_count), - cd_dep_college_count, - count(*) cnt3, - max(cd_dep_college_count), - min(cd_dep_college_count), - max(cd_dep_college_count) - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 1999 and - d_qoy < 4) and - exists (select * from - (select ws_bill_customer_sk customsk - from web_sales,date_dim - where - ws_sold_date_sk = d_date_sk and - d_year = 1999 and - d_qoy < 4 - union all - select cs_ship_customer_sk customsk - from catalog_sales,date_dim - where - cs_sold_date_sk = d_date_sk and - d_year = 1999 and - d_qoy < 4)x - where x.customsk = c.c_customer_sk) - group by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - limit 100; - --- end template query35a.tpl query 47 in stream 0 --- start template query49.tpl query 48 in stream 0 -select /* TPC-DS query49.tpl 0.48 */ channel, item, return_ratio, return_rank, currency_rank from - (select - 'web' as channel - ,web.item - ,web.return_ratio - ,web.return_rank - ,web.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select ws.ws_item_sk as item - ,(cast(sum(coalesce(wr.wr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(wr.wr_return_amt,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - web_sales ws left outer join web_returns wr - on (ws.ws_order_number = wr.wr_order_number and - ws.ws_item_sk = wr.wr_item_sk) - ,date_dim - where - wr.wr_return_amt > 10000 - and ws.ws_net_profit > 1 - and ws.ws_net_paid > 0 - and ws.ws_quantity > 0 - and ws_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 11 - group by ws.ws_item_sk - ) in_web - ) web - where - ( - web.return_rank <= 10 - or - web.currency_rank <= 10 - ) - union - select - 'catalog' as channel - ,catalog.item - ,catalog.return_ratio - ,catalog.return_rank - ,catalog.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select - cs.cs_item_sk as item - ,(cast(sum(coalesce(cr.cr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(cr.cr_return_amount,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - catalog_sales cs left outer join catalog_returns cr - on (cs.cs_order_number = cr.cr_order_number and - cs.cs_item_sk = cr.cr_item_sk) - ,date_dim - where - cr.cr_return_amount > 10000 - and cs.cs_net_profit > 1 - and cs.cs_net_paid > 0 - and cs.cs_quantity > 0 - and cs_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 11 - group by cs.cs_item_sk - ) in_cat - ) catalog - where - ( - catalog.return_rank <= 10 - or - catalog.currency_rank <=10 - ) - union - select - 'store' as channel - ,store.item - ,store.return_ratio - ,store.return_rank - ,store.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select sts.ss_item_sk as item - ,(cast(sum(coalesce(sr.sr_return_quantity,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(sr.sr_return_amt,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - store_sales sts left outer join store_returns sr - on (sts.ss_ticket_number = sr.sr_ticket_number and sts.ss_item_sk = sr.sr_item_sk) - ,date_dim - where - sr.sr_return_amt > 10000 - and sts.ss_net_profit > 1 - and sts.ss_net_paid > 0 - and sts.ss_quantity > 0 - and ss_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 11 - group by sts.ss_item_sk - ) in_store - ) store - where ( - store.return_rank <= 10 - or - store.currency_rank <= 10 - ) - ) - order by 1,4,5,2 - limit 100; - --- end template query49.tpl query 48 in stream 0 --- start template query9.tpl query 49 in stream 0 -select /* TPC-DS query9.tpl 0.49 */ case when (select count(*) - from store_sales - where ss_quantity between 1 and 20) > 12171089 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 1 and 20) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 1 and 20) end bucket1 , - case when (select count(*) - from store_sales - where ss_quantity between 21 and 40) > 111772806 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 21 and 40) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 21 and 40) end bucket2, - case when (select count(*) - from store_sales - where ss_quantity between 41 and 60) > 23211533 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 41 and 60) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 41 and 60) end bucket3, - case when (select count(*) - from store_sales - where ss_quantity between 61 and 80) > 56475617 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 61 and 80) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 61 and 80) end bucket4, - case when (select count(*) - from store_sales - where ss_quantity between 81 and 100) > 43543186 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 81 and 100) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 81 and 100) end bucket5 -from reason -where r_reason_sk = 1 -; - --- end template query9.tpl query 49 in stream 0 --- start template query31.tpl query 50 in stream 0 -with /* TPC-DS query31.tpl 0.50 */ ss as - (select ca_county,d_qoy, d_year,sum(ss_ext_sales_price) as store_sales - from store_sales,date_dim,customer_address - where ss_sold_date_sk = d_date_sk - and ss_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year), - ws as - (select ca_county,d_qoy, d_year,sum(ws_ext_sales_price) as web_sales - from web_sales,date_dim,customer_address - where ws_sold_date_sk = d_date_sk - and ws_bill_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year) - select - ss1.ca_county - ,ss1.d_year - ,ws2.web_sales/ws1.web_sales web_q1_q2_increase - ,ss2.store_sales/ss1.store_sales store_q1_q2_increase - ,ws3.web_sales/ws2.web_sales web_q2_q3_increase - ,ss3.store_sales/ss2.store_sales store_q2_q3_increase - from - ss ss1 - ,ss ss2 - ,ss ss3 - ,ws ws1 - ,ws ws2 - ,ws ws3 - where - ss1.d_qoy = 1 - and ss1.d_year = 1998 - and ss1.ca_county = ss2.ca_county - and ss2.d_qoy = 2 - and ss2.d_year = 1998 - and ss2.ca_county = ss3.ca_county - and ss3.d_qoy = 3 - and ss3.d_year = 1998 - and ss1.ca_county = ws1.ca_county - and ws1.d_qoy = 1 - and ws1.d_year = 1998 - and ws1.ca_county = ws2.ca_county - and ws2.d_qoy = 2 - and ws2.d_year = 1998 - and ws1.ca_county = ws3.ca_county - and ws3.d_qoy = 3 - and ws3.d_year =1998 - and case when ws1.web_sales > 0 then ws2.web_sales/ws1.web_sales else null end - > case when ss1.store_sales > 0 then ss2.store_sales/ss1.store_sales else null end - and case when ws2.web_sales > 0 then ws3.web_sales/ws2.web_sales else null end - > case when ss2.store_sales > 0 then ss3.store_sales/ss2.store_sales else null end - order by web_q1_q2_increase; - --- end template query31.tpl query 50 in stream 0 --- start template query11.tpl query 51 in stream 0 -with /* TPC-DS query11.tpl 0.51 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ss_ext_list_price-ss_ext_discount_amt) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ws_ext_list_price-ws_ext_discount_amt) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_email_address - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 1998 - and t_s_secyear.dyear = 1998+1 - and t_w_firstyear.dyear = 1998 - and t_w_secyear.dyear = 1998+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else 0.0 end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else 0.0 end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_email_address -limit 100; - --- end template query11.tpl query 51 in stream 0 --- start template query93.tpl query 52 in stream 0 -select /* TPC-DS query93.tpl 0.52 */ ss_customer_sk - ,sum(act_sales) sumsales - from (select ss_item_sk - ,ss_ticket_number - ,ss_customer_sk - ,case when sr_return_quantity is not null then (ss_quantity-sr_return_quantity)*ss_sales_price - else (ss_quantity*ss_sales_price) end act_sales - from store_sales left outer join store_returns on (sr_item_sk = ss_item_sk - and sr_ticket_number = ss_ticket_number) - ,reason - where sr_reason_sk = r_reason_sk - and r_reason_desc = 'No service location in my area') t - group by ss_customer_sk - order by sumsales, ss_customer_sk -limit 100; - --- end template query93.tpl query 52 in stream 0 --- start template query29.tpl query 53 in stream 0 -select /* TPC-DS query29.tpl 0.53 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,min(ss_quantity) as store_sales_quantity - ,min(sr_return_quantity) as store_returns_quantity - ,min(cs_quantity) as catalog_sales_quantity - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 1998 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 4 + 3 - and d2.d_year = 1998 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_year in (1998,1998+1,1998+2) - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query29.tpl query 53 in stream 0 --- start template query38.tpl query 54 in stream 0 -select /* TPC-DS query38.tpl 0.54 */ count(*) from ( - select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1190 and 1190 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1190 and 1190 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1190 and 1190 + 11 -) hot_cust -limit 100; - --- end template query38.tpl query 54 in stream 0 --- start template query22a.tpl query 55 in stream 0 -with /* TPC-DS query22a.tpl 0.55 */ results as -(select i_product_name - ,i_brand - ,i_class - ,i_category - ,avg(inv_quantity_on_hand) qoh - from inventory - ,date_dim - ,item --- ,warehouse - where inv_date_sk=d_date_sk - and inv_item_sk=i_item_sk --- and inv_warehouse_sk = w_warehouse_sk - and d_month_seq between 1183 and 1183 + 11 - group by i_product_name,i_brand,i_class,i_category), -results_rollup as -(select i_product_name, i_brand, i_class, i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class,i_category -union all -select i_product_name, i_brand, i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class -union all -select i_product_name, i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand -union all -select i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name -union all -select null i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results) - select i_product_name, i_brand, i_class, i_category,qoh - from results_rollup - order by qoh, i_product_name, i_brand, i_class, i_category -limit 100; - --- end template query22a.tpl query 55 in stream 0 --- start template query89.tpl query 56 in stream 0 -select /* TPC-DS query89.tpl 0.56 */ * -from( -select i_category, i_class, i_brand, - s_store_name, s_company_name, - d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, s_store_name, s_company_name) - avg_monthly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - d_year in (1999) and - ((i_category in ('Shoes','Men','Music') and - i_class in ('kids','sports-apparel','classical') - ) - or (i_category in ('Electronics','Women','Jewelry') and - i_class in ('portable','fragrances','diamonds') - )) -group by i_category, i_class, i_brand, - s_store_name, s_company_name, d_moy) tmp1 -where case when (avg_monthly_sales <> 0) then (abs(sum_sales - avg_monthly_sales) / avg_monthly_sales) else null end > 0.1 -order by sum_sales - avg_monthly_sales, s_store_name -limit 100; - --- end template query89.tpl query 56 in stream 0 --- start template query15.tpl query 57 in stream 0 -select /* TPC-DS query15.tpl 0.57 */ ca_zip - ,sum(cs_sales_price) - from catalog_sales - ,customer - ,customer_address - ,date_dim - where cs_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', - '85392', '85460', '80348', '81792') - or ca_state in ('CA','WA','GA') - or cs_sales_price > 500) - and cs_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 2002 - group by ca_zip - order by ca_zip - limit 100; - --- end template query15.tpl query 57 in stream 0 --- start template query6.tpl query 58 in stream 0 -select /* TPC-DS query6.tpl 0.58 */ a.ca_state state, count(*) cnt - from customer_address a - ,customer c - ,store_sales s - ,date_dim d - ,item i - where a.ca_address_sk = c.c_current_addr_sk - and c.c_customer_sk = s.ss_customer_sk - and s.ss_sold_date_sk = d.d_date_sk - and s.ss_item_sk = i.i_item_sk - and d.d_month_seq = - (select distinct (d_month_seq) - from date_dim - where d_year = 2000 - and d_moy = 6 ) - and i.i_current_price > 1.2 * - (select avg(j.i_current_price) - from item j - where j.i_category = i.i_category) - group by a.ca_state - having count(*) >= 10 - order by cnt, a.ca_state - limit 100; - --- end template query6.tpl query 58 in stream 0 --- start template query52.tpl query 59 in stream 0 -select /* TPC-DS query52.tpl 0.59 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_sales_price) ext_price - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=12 - and dt.d_year=2002 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,ext_price desc - ,brand_id -limit 100 ; - --- end template query52.tpl query 59 in stream 0 --- start template query50.tpl query 60 in stream 0 -select /* TPC-DS query50.tpl 0.60 */ - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 30) and - (sr_returned_date_sk - ss_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 60) and - (sr_returned_date_sk - ss_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 90) and - (sr_returned_date_sk - ss_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - store_sales - ,store_returns - ,store - ,date_dim d1 - ,date_dim d2 -where - d2.d_year = 2000 -and d2.d_moy = 8 -and ss_ticket_number = sr_ticket_number -and ss_item_sk = sr_item_sk -and ss_sold_date_sk = d1.d_date_sk -and sr_returned_date_sk = d2.d_date_sk -and ss_customer_sk = sr_customer_sk -and ss_store_sk = s_store_sk -group by - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -order by s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -limit 100; - --- end template query50.tpl query 60 in stream 0 --- start template query42.tpl query 61 in stream 0 -select /* TPC-DS query42.tpl 0.61 */ dt.d_year - ,item.i_category_id - ,item.i_category - ,sum(ss_ext_sales_price) - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=11 - and dt.d_year=2002 - group by dt.d_year - ,item.i_category_id - ,item.i_category - order by sum(ss_ext_sales_price) desc,dt.d_year - ,item.i_category_id - ,item.i_category -limit 100 ; - --- end template query42.tpl query 61 in stream 0 --- start template query41.tpl query 62 in stream 0 -select /* TPC-DS query41.tpl 0.62 */ distinct(i_product_name) - from item i1 - where i_manufact_id between 744 and 744+40 - and (select count(*) as item_cnt - from item - where (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'light' or i_color = 'yellow') and - (i_units = 'Pallet' or i_units = 'Box') and - (i_size = 'large' or i_size = 'medium') - ) or - (i_category = 'Women' and - (i_color = 'firebrick' or i_color = 'cream') and - (i_units = 'Oz' or i_units = 'Carton') and - (i_size = 'petite' or i_size = 'extra large') - ) or - (i_category = 'Men' and - (i_color = 'magenta' or i_color = 'sandy') and - (i_units = 'Ounce' or i_units = 'Cup') and - (i_size = 'economy' or i_size = 'N/A') - ) or - (i_category = 'Men' and - (i_color = 'frosted' or i_color = 'plum') and - (i_units = 'Tsp' or i_units = 'Bundle') and - (i_size = 'large' or i_size = 'medium') - ))) or - (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'orchid' or i_color = 'chocolate') and - (i_units = 'Pound' or i_units = 'Lb') and - (i_size = 'large' or i_size = 'medium') - ) or - (i_category = 'Women' and - (i_color = 'slate' or i_color = 'linen') and - (i_units = 'Gross' or i_units = 'Unknown') and - (i_size = 'petite' or i_size = 'extra large') - ) or - (i_category = 'Men' and - (i_color = 'gainsboro' or i_color = 'dim') and - (i_units = 'Ton' or i_units = 'Dozen') and - (i_size = 'economy' or i_size = 'N/A') - ) or - (i_category = 'Men' and - (i_color = 'ivory' or i_color = 'navy') and - (i_units = 'Tbl' or i_units = 'Bunch') and - (i_size = 'large' or i_size = 'medium') - )))) > 0 - order by i_product_name - limit 100; - --- end template query41.tpl query 62 in stream 0 --- start template query8.tpl query 63 in stream 0 -select /* TPC-DS query8.tpl 0.63 */ s_store_name - ,sum(ss_net_profit) - from store_sales - ,date_dim - ,store, - (select ca_zip - from ( - SELECT substring(ca_zip,1,5) ca_zip - FROM customer_address - WHERE substring(ca_zip,1,5) IN ( - '26556','82112','24494','73691','98508','18363', - '41721','46255','78664','37879','34631', - '17403','95906','94421','28597','65967', - '69188','51636','36103','45863','80231', - '79103','41954','15519','61556','60058', - '48509','37205','10650','59740','59298', - '13874','56012','65512','52264','54461', - '59470','14637','10372','67783','97087', - '62039','40518','60351','38632','19606', - '80070','59580','86492','55927','64327', - '53882','67474','12458','82078','46252', - '49165','13401','18594','65541','68465', - '97735','24310','68631','48690','39042', - '90155','82017','47883','11086','82378', - '10370','28527','29801','15250','41710', - '61843','72074','86421','46740','53095', - '66122','49141','72860','76856','42354', - '73478','23432','38411','68186','22463', - '79797','33813','43372','13791','10809', - '65618','12450','76873','49396','85237', - '26488','57775','31180','18716','81011', - '83681','66000','11771','73015','33835', - '46817','76701','31547','83457','75436', - '56571','43139','10402','12697','97655', - '26816','48020','51327','66247','19638', - '27924','56952','98110','32832','45822', - '40701','42224','61006','84718','56193', - '73599','16391','58743','57732','91680', - '30943','32250','66700','43635','31814', - '36844','31473','65152','57290','95503', - '19135','24537','31616','76138','25098', - '61834','25575','17242','42476','14038', - '45935','46640','32629','78679','15184', - '58733','29653','35033','91955','55438', - '59385','51260','94033','93405','35163', - '88445','43583','25436','26866','21031', - '92837','35145','24525','23420','88229', - '76177','44450','13151','36177','55985', - '79267','48952','82431','47695','40498', - '25822','58483','45280','28927','56469', - '83913','68230','10239','68388','29779', - '43154','19312','61069','87600','10954', - '13819','48918','58684','47648','91715', - '22597','37040','68547','84107','79889', - '88543','60666','58974','19022','48431', - '22189','86395','37827','56350','86895', - '99043','68580','65360','27802','80243', - '76348','45282','10256','17332','60662', - '69071','73700','17112','31443','50184', - '77431','19501','57676','73777','46583', - '20964','25007','73595','68097','47714', - '88677','65600','26205','34419','86714', - '48988','62918','69497','68714','81334', - '73065','13377','74375','90645','65230', - '89804','83041','47768','74883','64661', - '81274','71543','34286','71187','67840', - '33566','14169','72824','91239','32800', - '96800','11912','20618','65860','21770', - '10639','54057','27720','41069','23249', - '26538','35337','49769','25421','56853', - '21054','63991','91130','54032','72754', - '18837','88940','40610','96229','72583', - '91490','85543','58228','19319','79825', - '42284','38667','42295','50270','77379', - '34373','48957','61684','99140','72081', - '23102','93733','48243','94248','73453', - '29850','81312','37403','62464','22310', - '72204','66646','28100','21010','25273', - '31969','65294','77042','51049','68577', - '20466','19183','14641','52685','86569', - '88149','40016','67759','82318','23271', - '17105','20084','19551','32376','57892', - '24874','64449','15345','76044','93800', - '79979','97579','20209','64988','12896', - '31940','21327','67892','72990','56774', - '68787','52096','74943','18423','78791', - '75359','73805','24386','33058','79698', - '35405','44431','94433','17701','93876', - '16520','91611','95666','50200','13262', - '25443','51576','29248','29727') - intersect - select ca_zip - from (SELECT substring(ca_zip,1,5) ca_zip,count(*) cnt - FROM customer_address, customer - WHERE ca_address_sk = c_current_addr_sk and - c_preferred_cust_flag='Y' - group by ca_zip - having count(*) > 10)A1)A2) V1 - where ss_store_sk = s_store_sk - and ss_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 2000 - and (substring(s_zip,1,2) = substring(V1.ca_zip,1,2)) - group by s_store_name - order by s_store_name - limit 100; - --- end template query8.tpl query 63 in stream 0 --- start template query12.tpl query 64 in stream 0 -select /* TPC-DS query12.tpl 0.64 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ws_ext_sales_price) as itemrevenue - ,sum(ws_ext_sales_price)*100/sum(sum(ws_ext_sales_price)) over - (partition by i_class) as revenueratio -from - web_sales - ,item - ,date_dim -where - ws_item_sk = i_item_sk - and i_category in ('Electronics', 'Shoes', 'Jewelry') - and ws_sold_date_sk = d_date_sk - and d_date between cast('2001-06-29' as date) - and dateadd(day,30,cast('2001-06-29' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query12.tpl query 64 in stream 0 --- start template query20.tpl query 65 in stream 0 -select /* TPC-DS query20.tpl 0.65 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(cs_ext_sales_price) as itemrevenue - ,sum(cs_ext_sales_price)*100/sum(sum(cs_ext_sales_price)) over - (partition by i_class) as revenueratio - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and i_category in ('Shoes', 'Sports', 'Electronics') - and cs_sold_date_sk = d_date_sk - and d_date between cast('1998-05-13' as date) - and dateadd(day,30,cast('1998-05-13' as date)) - group by i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - order by i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query20.tpl query 65 in stream 0 --- start template query88.tpl query 66 in stream 0 -select /* TPC-DS query88.tpl 0.66 */ * -from - (select count(*) h8_30_to_9 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s1, - (select count(*) h9_to_9_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s2, - (select count(*) h9_30_to_10 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s3, - (select count(*) h10_to_10_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s4, - (select count(*) h10_30_to_11 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s5, - (select count(*) h11_to_11_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s6, - (select count(*) h11_30_to_12 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s7, - (select count(*) h12_to_12_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 12 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s8 -; - --- end template query88.tpl query 66 in stream 0 --- start template query82.tpl query 67 in stream 0 -select /* TPC-DS query82.tpl 0.67 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, store_sales - where i_current_price between 12 and 12+30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('2002-04-05' as date) and dateadd(day,60,cast('2002-04-05' as date)) - and i_manufact_id in (400,448,910,149) - and inv_quantity_on_hand between 100 and 500 - and ss_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query82.tpl query 67 in stream 0 --- start template query23.tpl query 68 in stream 0 -with /* TPC-DS query23.tpl 0.68 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (1998,1998+1,1998+2,1998+3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1998,1998+1,1998+2,1998+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * -from - max_store_sales)) - select sum(sales) - from (select cs_quantity*cs_list_price sales - from catalog_sales - ,date_dim - where d_year = 1998 - and d_moy = 4 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - union all - select ws_quantity*ws_list_price sales - from web_sales - ,date_dim - where d_year = 1998 - and d_moy = 4 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer)) - limit 100; -with /* TPC-DS query23.tpl 0.68 part2 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (1998,1998 + 1,1998 + 2,1998 + 3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1998,1998+1,1998+2,1998+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * - from max_store_sales)) - select c_last_name,c_first_name,sales - from (select c_last_name,c_first_name,sum(cs_quantity*cs_list_price) sales - from catalog_sales - ,customer - ,date_dim - where d_year = 1998 - and d_moy = 4 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and cs_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name - union all - select c_last_name,c_first_name,sum(ws_quantity*ws_list_price) sales - from web_sales - ,customer - ,date_dim - where d_year = 1998 - and d_moy = 4 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and ws_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name) - order by c_last_name,c_first_name,sales - limit 100; - --- end template query23.tpl query 68 in stream 0 --- start template query14a.tpl query 69 in stream 0 -with /* TPC-DS query14a.tpl 0.69 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1999 AND 1999 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1999 AND 1999 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1999 AND 1999 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as - (select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2) x) -, - results AS -(select channel, i_brand_id, i_class_id, i_category_id, sum(sales) sum_sales, sum(number_sales) number_sales - from ( - select 'store' channel, i_brand_id,i_class_id - ,i_category_id,sum(ss_quantity*ss_list_price) sales - , count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1999+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales) - union all - select 'catalog' channel, i_brand_id,i_class_id,i_category_id, sum(cs_quantity*cs_list_price) sales, count(*) number_sales - from catalog_sales - ,item - ,date_dim - where cs_item_sk in (select ss_item_sk from cross_items) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1999+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(cs_quantity*cs_list_price) > (select average_sales from avg_sales) - union all - select 'web' channel, i_brand_id,i_class_id,i_category_id, sum(ws_quantity*ws_list_price) sales , count(*) number_sales - from web_sales - ,item - ,date_dim - where ws_item_sk in (select ss_item_sk from cross_items) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1999+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ws_quantity*ws_list_price) > (select average_sales from avg_sales) - ) y - group by channel, i_brand_id,i_class_id,i_category_id) - - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales -from ( - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales from results - union - select channel, i_brand_id, i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id, i_class_id - union - select channel, i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id - union - select channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel - union - select null as channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results) z -order by channel, i_brand_id, i_class_id, i_category_id - limit 100; -with /* TPC-DS query14a.tpl 0.69 part2 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1999 AND 1999 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1999 AND 1999 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1999 AND 1999 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as -(select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2) x) - select this_year.channel ty_channel - ,this_year.i_brand_id ty_brand - ,this_year.i_class_id ty_class - ,this_year.i_category_id ty_category - ,this_year.sales ty_sales - ,this_year.number_sales ty_number_sales - ,last_year.channel ly_channel - ,last_year.i_brand_id ly_brand - ,last_year.i_class_id ly_class - ,last_year.i_category_id ly_category - ,last_year.sales ly_sales - ,last_year.number_sales ly_number_sales -from - (select 'store' channel, i_brand_id,i_class_id,i_category_id - ,sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1999 + 1 - and d_moy = 12 - and d_dom = 17) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) this_year, - (select 'store' channel, i_brand_id,i_class_id - ,i_category_id, sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1999 - and d_moy = 12 - and d_dom = 17) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) last_year - where this_year.i_brand_id= last_year.i_brand_id - and this_year.i_class_id = last_year.i_class_id - and this_year.i_category_id = last_year.i_category_id - order by this_year.channel, this_year.i_brand_id, this_year.i_class_id, this_year.i_category_id - limit 100; - --- end template query14a.tpl query 69 in stream 0 --- start template query57.tpl query 70 in stream 0 -with /* TPC-DS query57.tpl 0.70 */ v1 as( - select i_category, i_brand, - cc_name, - d_year, d_moy, - sum(cs_sales_price) sum_sales, - avg(sum(cs_sales_price)) over - (partition by i_category, i_brand, - cc_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - cc_name - order by d_year, d_moy) rn - from item, catalog_sales, date_dim, call_center - where cs_item_sk = i_item_sk and - cs_sold_date_sk = d_date_sk and - cc_call_center_sk= cs_call_center_sk and - ( - d_year = 2001 or - ( d_year = 2001-1 and d_moy =12) or - ( d_year = 2001+1 and d_moy =1) - ) - group by i_category, i_brand, - cc_name , d_year, d_moy), - v2 as( - select v1.cc_name - ,v1.d_year, v1.d_moy - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1. cc_name = v1_lag. cc_name and - v1. cc_name = v1_lead. cc_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 2001 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, psum - limit 100; - --- end template query57.tpl query 70 in stream 0 --- start template query65.tpl query 71 in stream 0 -select /* TPC-DS query65.tpl 0.71 */ - s_store_name, - i_item_desc, - sc.revenue, - i_current_price, - i_wholesale_cost, - i_brand - from store, item, - (select ss_store_sk, avg(revenue) as ave - from - (select ss_store_sk, ss_item_sk, - sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1217 and 1217+11 - group by ss_store_sk, ss_item_sk) sa - group by ss_store_sk) sb, - (select ss_store_sk, ss_item_sk, sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1217 and 1217+11 - group by ss_store_sk, ss_item_sk) sc - where sb.ss_store_sk = sc.ss_store_sk and - sc.revenue <= 0.1 * sb.ave and - s_store_sk = sc.ss_store_sk and - i_item_sk = sc.ss_item_sk - order by s_store_name, i_item_desc -limit 100; - --- end template query65.tpl query 71 in stream 0 --- start template query71.tpl query 72 in stream 0 -select /* TPC-DS query71.tpl 0.72 */ i_brand_id brand_id, i_brand brand,t_hour,t_minute, - sum(ext_price) ext_price - from item, (select ws_ext_sales_price as ext_price, - ws_sold_date_sk as sold_date_sk, - ws_item_sk as sold_item_sk, - ws_sold_time_sk as time_sk - from web_sales,date_dim - where d_date_sk = ws_sold_date_sk - and d_moy=12 - and d_year=2001 - union all - select cs_ext_sales_price as ext_price, - cs_sold_date_sk as sold_date_sk, - cs_item_sk as sold_item_sk, - cs_sold_time_sk as time_sk - from catalog_sales,date_dim - where d_date_sk = cs_sold_date_sk - and d_moy=12 - and d_year=2001 - union all - select ss_ext_sales_price as ext_price, - ss_sold_date_sk as sold_date_sk, - ss_item_sk as sold_item_sk, - ss_sold_time_sk as time_sk - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - and d_moy=12 - and d_year=2001 - ) tmp,time_dim - where - sold_item_sk = i_item_sk - and i_manager_id=1 - and time_sk = t_time_sk - and (t_meal_time = 'breakfast' or t_meal_time = 'dinner') - group by i_brand, i_brand_id,t_hour,t_minute - order by ext_price desc, i_brand_id - ; - --- end template query71.tpl query 72 in stream 0 --- start template query34.tpl query 73 in stream 0 -select /* TPC-DS query34.tpl 0.73 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (date_dim.d_dom between 1 and 3 or date_dim.d_dom between 25 and 28) - and (household_demographics.hd_buy_potential = '501-1000' or - household_demographics.hd_buy_potential = '5001-10000') - and household_demographics.hd_vehicle_count > 0 - and (case when household_demographics.hd_vehicle_count > 0 - then household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count - else null - end) > 1.2 - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_county in ('Sumner County','Gage County','Bronx County','Salem County', - 'Perry County','San Miguel County','Hubbard County','Pennington County') - group by ss_ticket_number,ss_customer_sk) dn,customer - where ss_customer_sk = c_customer_sk - and cnt between 15 and 20 - order by c_last_name,c_first_name,c_salutation,c_preferred_cust_flag desc, ss_ticket_number; - --- end template query34.tpl query 73 in stream 0 --- start template query48.tpl query 74 in stream 0 -select /* TPC-DS query48.tpl 0.74 */ sum (ss_quantity) - from store_sales, store, customer_demographics, customer_address, date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 1999 - and - ( - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'D' - and - cd_education_status = 'Secondary' - and - ss_sales_price between 100.00 and 150.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'M' - and - cd_education_status = '2 yr Degree' - and - ss_sales_price between 50.00 and 100.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'W' - and - cd_education_status = '4 yr Degree' - and - ss_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('IN', 'WV', 'VA') - and ss_net_profit between 0 and 2000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('TX', 'ND', 'MN') - and ss_net_profit between 150 and 3000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('SD', 'GA', 'CO') - and ss_net_profit between 50 and 25000 - ) - ) -; - --- end template query48.tpl query 74 in stream 0 --- start template query30.tpl query 75 in stream 0 -with /* TPC-DS query30.tpl 0.75 */ customer_total_return as - (select wr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(wr_return_amt) as ctr_total_return - from web_returns - ,date_dim - ,customer_address - where wr_returned_date_sk = d_date_sk - and d_year =2000 - and wr_returning_addr_sk = ca_address_sk - group by wr_returning_customer_sk - ,ca_state) - select c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'TX' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return -limit 100; - --- end template query30.tpl query 75 in stream 0 --- start template query74.tpl query 76 in stream 0 -with /* TPC-DS query74.tpl 0.76 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,max(ss_net_paid) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1998,1998+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,max(ws_net_paid) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - and d_year in (1998,1998+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - ) - select - t_s_secyear.customer_id, t_s_secyear.customer_first_name, t_s_secyear.customer_last_name - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.year = 1998 - and t_s_secyear.year = 1998+1 - and t_w_firstyear.year = 1998 - and t_w_secyear.year = 1998+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - order by 2,3,1 -limit 100; - --- end template query74.tpl query 76 in stream 0 --- start template query87.tpl query 77 in stream 0 -select /* TPC-DS query87.tpl 0.77 */ count(*) -from ((select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1217 and 1217+11) - except - (select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1217 and 1217+11) - except - (select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1217 and 1217+11) -) cool_cust -; - --- end template query87.tpl query 77 in stream 0 --- start template query77a.tpl query 78 in stream 0 -with /* TPC-DS query77a.tpl 0.78 */ ss as - (select s_store_sk, - sum(ss_ext_sales_price) as sales, - sum(ss_net_profit) as profit - from store_sales, - date_dim, - store - where ss_sold_date_sk = d_date_sk - and d_date between cast('2000-08-02' as date) - and dateadd(day,30,cast('2000-08-02' as date)) - and ss_store_sk = s_store_sk - group by s_store_sk) - , - sr as - (select s_store_sk, - sum(sr_return_amt) as returns, - sum(sr_net_loss) as profit_loss - from store_returns, - date_dim, - store - where sr_returned_date_sk = d_date_sk - and d_date between cast('2000-08-02' as date) - and dateadd(day,30,cast('2000-08-02' as date)) - and sr_store_sk = s_store_sk - group by s_store_sk), - cs as - (select cs_call_center_sk, - sum(cs_ext_sales_price) as sales, - sum(cs_net_profit) as profit - from catalog_sales, - date_dim - where cs_sold_date_sk = d_date_sk - and d_date between cast('2000-08-02' as date) - and dateadd(day,30,cast('2000-08-02' as date)) - group by cs_call_center_sk - ), - cr as - (select cr_call_center_sk, - sum(cr_return_amount) as returns, - sum(cr_net_loss) as profit_loss - from catalog_returns, - date_dim - where cr_returned_date_sk = d_date_sk - and d_date between cast('2000-08-02' as date) - and dateadd(day,30,cast('2000-08-02' as date)) - group by cr_call_center_sk), - ws as - ( select wp_web_page_sk, - sum(ws_ext_sales_price) as sales, - sum(ws_net_profit) as profit - from web_sales, - date_dim, - web_page - where ws_sold_date_sk = d_date_sk - and d_date between cast('2000-08-02' as date) - and dateadd(day,30,cast('2000-08-02' as date)) - and ws_web_page_sk = wp_web_page_sk - group by wp_web_page_sk), - wr as - (select wp_web_page_sk, - sum(wr_return_amt) as returns, - sum(wr_net_loss) as profit_loss - from web_returns, - date_dim, - web_page - where wr_returned_date_sk = d_date_sk - and d_date between cast('2000-08-02' as date) - and dateadd(day,30,cast('2000-08-02' as date)) - and wr_web_page_sk = wp_web_page_sk - group by wp_web_page_sk) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , ss.s_store_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ss left join sr - on ss.s_store_sk = sr.s_store_sk - union all - select 'catalog channel' as channel - , cs_call_center_sk as id - , sales - , returns - , (profit - profit_loss) as profit - from cs - , cr - union all - select 'web channel' as channel - , ws.wp_web_page_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ws left join wr - on ws.wp_web_page_sk = wr.wp_web_page_sk - ) x - group by channel, id ) - - select * - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results -) foo -order by channel, id - limit 100; - --- end template query77a.tpl query 78 in stream 0 --- start template query73.tpl query 79 in stream 0 -select /* TPC-DS query73.tpl 0.79 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_buy_potential = '501-1000' or - household_demographics.hd_buy_potential = '5001-10000') - and household_demographics.hd_vehicle_count > 0 - and case when household_demographics.hd_vehicle_count > 0 then - household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count else null end > 1 - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_county in ('Richland County','Wadena County','Terrell County','Huron County') - group by ss_ticket_number,ss_customer_sk) dj,customer - where ss_customer_sk = c_customer_sk - and cnt between 1 and 5 - order by cnt desc, c_last_name asc; - --- end template query73.tpl query 79 in stream 0 --- start template query84.tpl query 80 in stream 0 -select /* TPC-DS query84.tpl 0.80 */ c_customer_id as customer_id - , coalesce(c_last_name,'') || ', ' || coalesce(c_first_name,'') as customername - from customer - ,customer_address - ,customer_demographics - ,household_demographics - ,income_band - ,store_returns - where ca_city = 'Greenville' - and c_current_addr_sk = ca_address_sk - and ib_lower_bound >= 36218 - and ib_upper_bound <= 36218 + 50000 - and ib_income_band_sk = hd_income_band_sk - and cd_demo_sk = c_current_cdemo_sk - and hd_demo_sk = c_current_hdemo_sk - and sr_cdemo_sk = cd_demo_sk - order by c_customer_id - limit 100; - --- end template query84.tpl query 80 in stream 0 --- start template query54.tpl query 81 in stream 0 -with /* TPC-DS query54.tpl 0.81 */ my_customers as ( - select distinct c_customer_sk - , c_current_addr_sk - from - ( select cs_sold_date_sk sold_date_sk, - cs_bill_customer_sk customer_sk, - cs_item_sk item_sk - from catalog_sales - union all - select ws_sold_date_sk sold_date_sk, - ws_bill_customer_sk customer_sk, - ws_item_sk item_sk - from web_sales - ) cs_or_ws_sales, - item, - date_dim, - customer - where sold_date_sk = d_date_sk - and item_sk = i_item_sk - and i_category = 'Jewelry' - and i_class = 'rings' - and c_customer_sk = cs_or_ws_sales.customer_sk - and d_moy = 6 - and d_year = 1998 - ) - , my_revenue as ( - select c_customer_sk, - sum(ss_ext_sales_price) as revenue - from my_customers, - store_sales, - customer_address, - store, - date_dim - where c_current_addr_sk = ca_address_sk - and ca_county = s_county - and ca_state = s_state - and ss_sold_date_sk = d_date_sk - and c_customer_sk = ss_customer_sk - and d_month_seq between (select distinct d_month_seq+1 - from date_dim where d_year = 1998 and d_moy = 6) - and (select distinct d_month_seq+3 - from date_dim where d_year = 1998 and d_moy = 6) - group by c_customer_sk - ) - , segments as - (select cast((revenue/50) as int) as segment - from my_revenue - ) - select segment, count(*) as num_customers, segment*50 as segment_base - from segments - group by segment - order by segment, num_customers - limit 100; - --- end template query54.tpl query 81 in stream 0 --- start template query55.tpl query 82 in stream 0 -select /* TPC-DS query55.tpl 0.82 */ i_brand_id brand_id, i_brand brand, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=83 - and d_moy=12 - and d_year=2002 - group by i_brand, i_brand_id - order by ext_price desc, i_brand_id -limit 100 ; - --- end template query55.tpl query 82 in stream 0 --- start template query56.tpl query 83 in stream 0 -with /* TPC-DS query56.tpl 0.83 */ ss as ( - select i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where i_item_id in (select - i_item_id -from item -where i_color in ('lavender','rose','beige')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 4 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - cs as ( - select i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('lavender','rose','beige')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 4 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - ws as ( - select i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('lavender','rose','beige')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 4 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id) - select i_item_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by total_sales, - i_item_id - limit 100; - --- end template query56.tpl query 83 in stream 0 --- start template query2.tpl query 84 in stream 0 -with /* TPC-DS query2.tpl 0.84 */ wscs as - (select sold_date_sk - ,sales_price - from (select ws_sold_date_sk sold_date_sk - ,ws_ext_sales_price sales_price - from web_sales - union all - select cs_sold_date_sk sold_date_sk - ,cs_ext_sales_price sales_price - from catalog_sales)), - wswscs as - (select d_week_seq, - sum(case when (d_day_name='Sunday') then sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then sales_price else null end) sat_sales - from wscs - ,date_dim - where d_date_sk = sold_date_sk - group by d_week_seq) - select d_week_seq1 - ,round(sun_sales1/sun_sales2,2) - ,round(mon_sales1/mon_sales2,2) - ,round(tue_sales1/tue_sales2,2) - ,round(wed_sales1/wed_sales2,2) - ,round(thu_sales1/thu_sales2,2) - ,round(fri_sales1/fri_sales2,2) - ,round(sat_sales1/sat_sales2,2) - from - (select wswscs.d_week_seq d_week_seq1 - ,sun_sales sun_sales1 - ,mon_sales mon_sales1 - ,tue_sales tue_sales1 - ,wed_sales wed_sales1 - ,thu_sales thu_sales1 - ,fri_sales fri_sales1 - ,sat_sales sat_sales1 - from wswscs,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 2001) y, - (select wswscs.d_week_seq d_week_seq2 - ,sun_sales sun_sales2 - ,mon_sales mon_sales2 - ,tue_sales tue_sales2 - ,wed_sales wed_sales2 - ,thu_sales thu_sales2 - ,fri_sales fri_sales2 - ,sat_sales sat_sales2 - from wswscs - ,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 2001+1) z - where d_week_seq1=d_week_seq2-53 - order by d_week_seq1; - --- end template query2.tpl query 84 in stream 0 --- start template query26.tpl query 85 in stream 0 -select /* TPC-DS query26.tpl 0.85 */ i_item_id, - avg(cs_quantity) agg1, - avg(cs_list_price) agg2, - avg(cs_coupon_amt) agg3, - avg(cs_sales_price) agg4 - from catalog_sales, customer_demographics, date_dim, item, promotion - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd_demo_sk and - cs_promo_sk = p_promo_sk and - cd_gender = 'M' and - cd_marital_status = 'S' and - cd_education_status = 'Primary' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 1999 - group by i_item_id - order by i_item_id - limit 100; - --- end template query26.tpl query 85 in stream 0 --- start template query40.tpl query 86 in stream 0 -select /* TPC-DS query40.tpl 0.86 */ - w_state - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('2001-03-21' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_before - ,sum(case when (cast(d_date as date) >= cast ('2001-03-21' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_after - from - catalog_sales left outer join catalog_returns on - (cs_order_number = cr_order_number - and cs_item_sk = cr_item_sk) - ,warehouse - ,item - ,date_dim - where - i_current_price between 0.99 and 1.49 - and i_item_sk = cs_item_sk - and cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('2001-03-21' as date)) - and dateadd(day,30,cast ('2001-03-21' as date)) - group by - w_state,i_item_id - order by w_state,i_item_id -limit 100; - --- end template query40.tpl query 86 in stream 0 --- start template query72.tpl query 87 in stream 0 -select /* TPC-DS query72.tpl 0.87 */ i_item_desc - ,w_warehouse_name - ,d1.d_week_seq - ,sum(case when p_promo_sk is null then 1 else 0 end) no_promo - ,sum(case when p_promo_sk is not null then 1 else 0 end) promo - ,count(*) total_cnt -from catalog_sales -join inventory on (cs_item_sk = inv_item_sk) -join warehouse on (w_warehouse_sk=inv_warehouse_sk) -join item on (i_item_sk = cs_item_sk) -join customer_demographics on (cs_bill_cdemo_sk = cd_demo_sk) -join household_demographics on (cs_bill_hdemo_sk = hd_demo_sk) -join date_dim d1 on (cs_sold_date_sk = d1.d_date_sk) -join date_dim d2 on (inv_date_sk = d2.d_date_sk) -join date_dim d3 on (cs_ship_date_sk = d3.d_date_sk) -left outer join promotion on (cs_promo_sk=p_promo_sk) -left outer join catalog_returns on (cr_item_sk = cs_item_sk and cr_order_number = cs_order_number) -where d1.d_week_seq = d2.d_week_seq - and inv_quantity_on_hand < cs_quantity - and d3.d_date > d1.d_date + 5 - and hd_buy_potential = '1001-5000' - and d1.d_year = 2000 - and cd_marital_status = 'D' -group by i_item_desc,w_warehouse_name,d1.d_week_seq -order by total_cnt desc, i_item_desc, w_warehouse_name, d_week_seq -limit 100; - --- end template query72.tpl query 87 in stream 0 --- start template query53.tpl query 88 in stream 0 -select /* TPC-DS query53.tpl 0.88 */ * from -(select i_manufact_id, -sum(ss_sales_price) sum_sales, -avg(sum(ss_sales_price)) over (partition by i_manufact_id) avg_quarterly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and -ss_sold_date_sk = d_date_sk and -ss_store_sk = s_store_sk and -d_month_seq in (1212,1212+1,1212+2,1212+3,1212+4,1212+5,1212+6,1212+7,1212+8,1212+9,1212+10,1212+11) and -((i_category in ('Books','Children','Electronics') and -i_class in ('personal','portable','reference','self-help') and -i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) -or(i_category in ('Women','Music','Men') and -i_class in ('accessories','classical','fragrances','pants') and -i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manufact_id, d_qoy ) tmp1 -where case when avg_quarterly_sales > 0 - then abs (sum_sales - avg_quarterly_sales)/ avg_quarterly_sales - else null end > 0.1 -order by avg_quarterly_sales, - sum_sales, - i_manufact_id -limit 100; - --- end template query53.tpl query 88 in stream 0 --- start template query79.tpl query 89 in stream 0 -select /* TPC-DS query79.tpl 0.89 */ - c_last_name,c_first_name,substring(s_city,1,30),ss_ticket_number,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,store.s_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (household_demographics.hd_dep_count = 0 or household_demographics.hd_vehicle_count > 2) - and date_dim.d_dow = 1 - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_number_employees between 200 and 295 - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,store.s_city) ms,customer - where ss_customer_sk = c_customer_sk - order by c_last_name,c_first_name,substring(s_city,1,30), profit -limit 100; - --- end template query79.tpl query 89 in stream 0 --- start template query18a.tpl query 90 in stream 0 -with /* TPC-DS query18a.tpl 0.90 */ results as - (select i_item_id, - ca_country, - ca_state, - ca_county, - cast(cs_quantity as decimal(12,2)) agg1, - cast(cs_list_price as decimal(12,2)) agg2, - cast(cs_coupon_amt as decimal(12,2)) agg3, - cast(cs_sales_price as decimal(12,2)) agg4, - cast(cs_net_profit as decimal(12,2)) agg5, - cast(c_birth_year as decimal(12,2)) agg6, - cast(cd1.cd_dep_count as decimal(12,2)) agg7 - from catalog_sales, customer_demographics cd1, customer_demographics cd2, customer, customer_address, date_dim, item - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd1.cd_demo_sk and - cs_bill_customer_sk = c_customer_sk and - cd1.cd_gender = 'M' and - cd1.cd_education_status = 'Primary' and - c_current_cdemo_sk = cd2.cd_demo_sk and - c_current_addr_sk = ca_address_sk and - c_birth_month in (9,5,1,2,3,8) and - d_year = 1999 and - ca_state in ('NV','AL','CA','WI','SD','OK','KY') - ) - select i_item_id, ca_country, ca_state, ca_county, agg1, agg2, agg3, agg4, agg5, agg6, agg7 - from ( - select i_item_id, ca_country, ca_state, ca_county, avg(agg1) agg1, - avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state, ca_county - union all - select i_item_id, ca_country, ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state - union all - select i_item_id, ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country - union all - select i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - ) foo - order by ca_country, ca_state, ca_county, i_item_id - limit 100; - --- end template query18a.tpl query 90 in stream 0 --- start template query13.tpl query 91 in stream 0 -select /* TPC-DS query13.tpl 0.91 */ avg(ss_quantity) - ,avg(ss_ext_sales_price) - ,avg(ss_ext_wholesale_cost) - ,sum(ss_ext_wholesale_cost) - from store_sales - ,store - ,customer_demographics - ,household_demographics - ,customer_address - ,date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2001 - and((ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'M' - and cd_education_status = 'Unknown' - and ss_sales_price between 100.00 and 150.00 - and hd_dep_count = 3 - )or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'D' - and cd_education_status = '4 yr Degree' - and ss_sales_price between 50.00 and 100.00 - and hd_dep_count = 1 - ) or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'W' - and cd_education_status = 'Primary' - and ss_sales_price between 150.00 and 200.00 - and hd_dep_count = 1 - )) - and((ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('TX', 'NC', 'NE') - and ss_net_profit between 100 and 200 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('DE', 'CO', 'MN') - and ss_net_profit between 150 and 300 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('OH', 'AL', 'ND') - and ss_net_profit between 50 and 250 - )) -; - --- end template query13.tpl query 91 in stream 0 --- start template query24.tpl query 92 in stream 0 -with /* TPC-DS query24.tpl 0.92 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_sales_price) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip -and s_market_id=5 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'gainsboro' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; -with /* TPC-DS query24.tpl 0.92 part2 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_sales_price) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip - and s_market_id = 5 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'light' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; - --- end template query24.tpl query 92 in stream 0 --- start template query4.tpl query 93 in stream 0 -with /* TPC-DS query4.tpl 0.93 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(((ss_ext_list_price-ss_ext_wholesale_cost-ss_ext_discount_amt)+ss_ext_sales_price)/2) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((cs_ext_list_price-cs_ext_wholesale_cost-cs_ext_discount_amt)+cs_ext_sales_price)/2) ) year_total - ,'c' sale_type - from customer - ,catalog_sales - ,date_dim - where c_customer_sk = cs_bill_customer_sk - and cs_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year -union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((ws_ext_list_price-ws_ext_wholesale_cost-ws_ext_discount_amt)+ws_ext_sales_price)/2) ) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_email_address - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_c_firstyear - ,year_total t_c_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_c_secyear.customer_id - and t_s_firstyear.customer_id = t_c_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_c_firstyear.sale_type = 'c' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_c_secyear.sale_type = 'c' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 1998 - and t_s_secyear.dyear = 1998+1 - and t_c_firstyear.dyear = 1998 - and t_c_secyear.dyear = 1998+1 - and t_w_firstyear.dyear = 1998 - and t_w_secyear.dyear = 1998+1 - and t_s_firstyear.year_total > 0 - and t_c_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_email_address -limit 100; - --- end template query4.tpl query 93 in stream 0 --- start template query99.tpl query 94 in stream 0 -select /* TPC-DS query99.tpl 0.94 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 30) and - (cs_ship_date_sk - cs_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 60) and - (cs_ship_date_sk - cs_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 90) and - (cs_ship_date_sk - cs_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - catalog_sales - ,warehouse - ,ship_mode - ,call_center - ,date_dim -where - d_month_seq between 1206 and 1206 + 11 -and cs_ship_date_sk = d_date_sk -and cs_warehouse_sk = w_warehouse_sk -and cs_ship_mode_sk = sm_ship_mode_sk -and cs_call_center_sk = cc_call_center_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -limit 100; - --- end template query99.tpl query 94 in stream 0 --- start template query68.tpl query 95 in stream 0 -select /* TPC-DS query68.tpl 0.95 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,extended_price - ,extended_tax - ,list_price - from (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_ext_sales_price) extended_price - ,sum(ss_ext_list_price) list_price - ,sum(ss_ext_tax) extended_tax - from store_sales - ,date_dim - ,store - ,household_demographics - ,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_dep_count = 6 or - household_demographics.hd_vehicle_count= 1) - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_city in ('Mount Zion','Springfield') - group by ss_ticket_number - ,ss_customer_sk - ,ss_addr_sk,ca_city) dn - ,customer - ,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,ss_ticket_number - limit 100; - --- end template query68.tpl query 95 in stream 0 --- start template query83.tpl query 96 in stream 0 -with /* TPC-DS query83.tpl 0.96 */ sr_items as - (select i_item_id item_id, - sum(sr_return_quantity) sr_item_qty - from store_returns, - item, - date_dim - where sr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('1998-06-09','1998-08-05','1998-11-11'))) - and sr_returned_date_sk = d_date_sk - group by i_item_id), - cr_items as - (select i_item_id item_id, - sum(cr_return_quantity) cr_item_qty - from catalog_returns, - item, - date_dim - where cr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('1998-06-09','1998-08-05','1998-11-11'))) - and cr_returned_date_sk = d_date_sk - group by i_item_id), - wr_items as - (select i_item_id item_id, - sum(wr_return_quantity) wr_item_qty - from web_returns, - item, - date_dim - where wr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('1998-06-09','1998-08-05','1998-11-11'))) - and wr_returned_date_sk = d_date_sk - group by i_item_id) - select sr_items.item_id - ,sr_item_qty - ,sr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 sr_dev - ,cr_item_qty - ,cr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 cr_dev - ,wr_item_qty - ,wr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 wr_dev - ,(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 average - from sr_items - ,cr_items - ,wr_items - where sr_items.item_id=cr_items.item_id - and sr_items.item_id=wr_items.item_id - order by sr_items.item_id - ,sr_item_qty - limit 100; - --- end template query83.tpl query 96 in stream 0 --- start template query61.tpl query 97 in stream 0 -select /* TPC-DS query61.tpl 0.97 */ promotions,total,cast(promotions as decimal(15,4))/cast(total as decimal(15,4))*100 -from - (select sum(ss_ext_sales_price) promotions - from store_sales - ,store - ,promotion - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_promo_sk = p_promo_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -6 - and i_category = 'Books' - and (p_channel_dmail = 'Y' or p_channel_email = 'Y' or p_channel_tv = 'Y') - and s_gmt_offset = -6 - and d_year = 2000 - and d_moy = 11) promotional_sales, - (select sum(ss_ext_sales_price) total - from store_sales - ,store - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -6 - and i_category = 'Books' - and s_gmt_offset = -6 - and d_year = 2000 - and d_moy = 11) all_sales -order by promotions, total -limit 100; - --- end template query61.tpl query 97 in stream 0 --- start template query5a.tpl query 98 in stream 0 -with /* TPC-DS query5a.tpl 0.98 */ ssr as - (select s_store_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ss_store_sk as store_sk, - ss_sold_date_sk as date_sk, - ss_ext_sales_price as sales_price, - ss_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from store_sales - union all - select sr_store_sk as store_sk, - sr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - sr_return_amt as return_amt, - sr_net_loss as net_loss - from store_returns - ) salesreturns, - date_dim, - store - where date_sk = d_date_sk - and d_date between cast('1998-08-11' as date) - and dateadd(day,14,cast('1998-08-11' as date)) - and store_sk = s_store_sk - group by s_store_id) - , - csr as - (select cp_catalog_page_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select cs_catalog_page_sk as page_sk, - cs_sold_date_sk as date_sk, - cs_ext_sales_price as sales_price, - cs_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from catalog_sales - union all - select cr_catalog_page_sk as page_sk, - cr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - cr_return_amount as return_amt, - cr_net_loss as net_loss - from catalog_returns - ) salesreturns, - date_dim, - catalog_page - where date_sk = d_date_sk - and d_date between cast('1998-08-11' as date) - and dateadd(day,14,cast('1998-08-11' as date)) - and page_sk = cp_catalog_page_sk - group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ws_web_site_sk as wsr_web_site_sk, - ws_sold_date_sk as date_sk, - ws_ext_sales_price as sales_price, - ws_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from web_sales - union all - select ws_web_site_sk as wsr_web_site_sk, - wr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - wr_return_amt as return_amt, - wr_net_loss as net_loss - from web_returns left outer join web_sales on - ( wr_item_sk = ws_item_sk - and wr_order_number = ws_order_number) - ) salesreturns, - date_dim, - web_site - where date_sk = d_date_sk - and d_date between cast('1998-08-11' as date) - and dateadd(day,14,cast('1998-08-11' as date)) - and wsr_web_site_sk = web_site_sk - group by web_site_id) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || s_store_id as id - , sales - , returns - , (profit - profit_loss) as profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || cp_catalog_page_id as id - , sales - , returns - , (profit - profit_loss) as profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , (profit - profit_loss) as profit - from wsr - ) x - group by channel, id) - select channel, id, sales, returns, profit from ( - select channel, id, sales, returns, profit from results - union - select channel, null as id, sum(sales), sum(returns), sum(profit) from results group by channel - union - select null as channel, null as id, sum(sales), sum(returns), sum(profit) from results) foo -order by channel, id -limit 100; - --- end template query5a.tpl query 98 in stream 0 --- start template query76.tpl query 99 in stream 0 -select /* TPC-DS query76.tpl 0.99 */ channel, col_name, d_year, d_qoy, i_category, COUNT(*) sales_cnt, SUM(ext_sales_price) sales_amt FROM ( - SELECT 'store' as channel, 'ss_addr_sk' col_name, d_year, d_qoy, i_category, ss_ext_sales_price ext_sales_price - FROM store_sales, item, date_dim - WHERE ss_addr_sk IS NULL - AND ss_sold_date_sk=d_date_sk - AND ss_item_sk=i_item_sk - UNION ALL - SELECT 'web' as channel, 'ws_ship_cdemo_sk' col_name, d_year, d_qoy, i_category, ws_ext_sales_price ext_sales_price - FROM web_sales, item, date_dim - WHERE ws_ship_cdemo_sk IS NULL - AND ws_sold_date_sk=d_date_sk - AND ws_item_sk=i_item_sk - UNION ALL - SELECT 'catalog' as channel, 'cs_bill_customer_sk' col_name, d_year, d_qoy, i_category, cs_ext_sales_price ext_sales_price - FROM catalog_sales, item, date_dim - WHERE cs_bill_customer_sk IS NULL - AND cs_sold_date_sk=d_date_sk - AND cs_item_sk=i_item_sk) foo -GROUP BY channel, col_name, d_year, d_qoy, i_category -ORDER BY channel, col_name, d_year, d_qoy, i_category -limit 100; - --- end template query76.tpl query 99 in stream 0 diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/10TB/queries/query_1.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/10TB/queries/query_1.sql deleted file mode 100644 index a99f745c..00000000 --- a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/10TB/queries/query_1.sql +++ /dev/null @@ -1,5027 +0,0 @@ --- start template query83.tpl query 1 in stream 1 -with /* TPC-DS query83.tpl 0.96 */ sr_items as - (select i_item_id item_id, - sum(sr_return_quantity) sr_item_qty - from store_returns, - item, - date_dim - where sr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2002-02-24','2002-08-27','2002-11-17'))) - and sr_returned_date_sk = d_date_sk - group by i_item_id), - cr_items as - (select i_item_id item_id, - sum(cr_return_quantity) cr_item_qty - from catalog_returns, - item, - date_dim - where cr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2002-02-24','2002-08-27','2002-11-17'))) - and cr_returned_date_sk = d_date_sk - group by i_item_id), - wr_items as - (select i_item_id item_id, - sum(wr_return_quantity) wr_item_qty - from web_returns, - item, - date_dim - where wr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2002-02-24','2002-08-27','2002-11-17'))) - and wr_returned_date_sk = d_date_sk - group by i_item_id) - select sr_items.item_id - ,sr_item_qty - ,sr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 sr_dev - ,cr_item_qty - ,cr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 cr_dev - ,wr_item_qty - ,wr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 wr_dev - ,(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 average - from sr_items - ,cr_items - ,wr_items - where sr_items.item_id=cr_items.item_id - and sr_items.item_id=wr_items.item_id - order by sr_items.item_id - ,sr_item_qty - limit 100; - --- end template query83.tpl query 1 in stream 1 --- start template query32.tpl query 2 in stream 1 -select /* TPC-DS query32.tpl 0.7 */ sum(cs_ext_discount_amt) as "excess discount amount" -from - catalog_sales - ,item - ,date_dim -where -i_manufact_id = 661 -and i_item_sk = cs_item_sk -and d_date between '2001-02-17' and - dateadd(day,90,cast('2001-02-17' as date)) -and d_date_sk = cs_sold_date_sk -and cs_ext_discount_amt - > ( - select - 1.3 * avg(cs_ext_discount_amt) - from - catalog_sales - ,date_dim - where - cs_item_sk = i_item_sk - and d_date between '2001-02-17' and - dateadd(day,90,cast('2001-02-17' as date)) - and d_date_sk = cs_sold_date_sk - ) -limit 100; - --- end template query32.tpl query 2 in stream 1 --- start template query30.tpl query 3 in stream 1 -with /* TPC-DS query30.tpl 0.75 */ customer_total_return as - (select wr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(wr_return_amt) as ctr_total_return - from web_returns - ,date_dim - ,customer_address - where wr_returned_date_sk = d_date_sk - and d_year =2002 - and wr_returning_addr_sk = ca_address_sk - group by wr_returning_customer_sk - ,ca_state) - select c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'OH' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return -limit 100; - --- end template query30.tpl query 3 in stream 1 --- start template query92.tpl query 4 in stream 1 -select /* TPC-DS query92.tpl 0.44 */ - sum(ws_ext_discount_amt) as "Excess Discount Amount" -from - web_sales - ,item - ,date_dim -where -i_manufact_id = 690 -and i_item_sk = ws_item_sk -and d_date between '1998-02-01' and - dateadd(day,90,cast('1998-02-01' as date)) -and d_date_sk = ws_sold_date_sk -and ws_ext_discount_amt - > ( - SELECT - 1.3 * avg(ws_ext_discount_amt) - FROM - web_sales - ,date_dim - WHERE - ws_item_sk = i_item_sk - and d_date between '1998-02-01' and - dateadd(day,90,cast('1998-02-01' as date)) - and d_date_sk = ws_sold_date_sk - ) -order by sum(ws_ext_discount_amt) -limit 100; - --- end template query92.tpl query 4 in stream 1 --- start template query66.tpl query 5 in stream 1 -select /* TPC-DS query66.tpl 0.39 */ - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - ,sum(jan_sales) as jan_sales - ,sum(feb_sales) as feb_sales - ,sum(mar_sales) as mar_sales - ,sum(apr_sales) as apr_sales - ,sum(may_sales) as may_sales - ,sum(jun_sales) as jun_sales - ,sum(jul_sales) as jul_sales - ,sum(aug_sales) as aug_sales - ,sum(sep_sales) as sep_sales - ,sum(oct_sales) as oct_sales - ,sum(nov_sales) as nov_sales - ,sum(dec_sales) as dec_sales - ,sum(jan_sales/w_warehouse_sq_ft) as jan_sales_per_sq_foot - ,sum(feb_sales/w_warehouse_sq_ft) as feb_sales_per_sq_foot - ,sum(mar_sales/w_warehouse_sq_ft) as mar_sales_per_sq_foot - ,sum(apr_sales/w_warehouse_sq_ft) as apr_sales_per_sq_foot - ,sum(may_sales/w_warehouse_sq_ft) as may_sales_per_sq_foot - ,sum(jun_sales/w_warehouse_sq_ft) as jun_sales_per_sq_foot - ,sum(jul_sales/w_warehouse_sq_ft) as jul_sales_per_sq_foot - ,sum(aug_sales/w_warehouse_sq_ft) as aug_sales_per_sq_foot - ,sum(sep_sales/w_warehouse_sq_ft) as sep_sales_per_sq_foot - ,sum(oct_sales/w_warehouse_sq_ft) as oct_sales_per_sq_foot - ,sum(nov_sales/w_warehouse_sq_ft) as nov_sales_per_sq_foot - ,sum(dec_sales/w_warehouse_sq_ft) as dec_sales_per_sq_foot - ,sum(jan_net) as jan_net - ,sum(feb_net) as feb_net - ,sum(mar_net) as mar_net - ,sum(apr_net) as apr_net - ,sum(may_net) as may_net - ,sum(jun_net) as jun_net - ,sum(jul_net) as jul_net - ,sum(aug_net) as aug_net - ,sum(sep_net) as sep_net - ,sum(oct_net) as oct_net - ,sum(nov_net) as nov_net - ,sum(dec_net) as dec_net - from ( - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'AIRBORNE' || ',' || 'MSC' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then ws_sales_price* ws_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then ws_sales_price* ws_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then ws_sales_price* ws_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then ws_sales_price* ws_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then ws_sales_price* ws_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then ws_sales_price* ws_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then ws_sales_price* ws_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then ws_sales_price* ws_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then ws_sales_price* ws_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then ws_sales_price* ws_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then ws_sales_price* ws_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then ws_sales_price* ws_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then ws_net_profit * ws_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then ws_net_profit * ws_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then ws_net_profit * ws_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then ws_net_profit * ws_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then ws_net_profit * ws_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then ws_net_profit * ws_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then ws_net_profit * ws_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then ws_net_profit * ws_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then ws_net_profit * ws_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then ws_net_profit * ws_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then ws_net_profit * ws_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then ws_net_profit * ws_quantity else 0 end) as dec_net - from - web_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - ws_warehouse_sk = w_warehouse_sk - and ws_sold_date_sk = d_date_sk - and ws_sold_time_sk = t_time_sk - and ws_ship_mode_sk = sm_ship_mode_sk - and d_year = 2001 - and t_time between 6152 and 6152+28800 - and sm_carrier in ('AIRBORNE','MSC') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - union all - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'AIRBORNE' || ',' || 'MSC' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then cs_sales_price* cs_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then cs_sales_price* cs_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then cs_sales_price* cs_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then cs_sales_price* cs_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then cs_sales_price* cs_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then cs_sales_price* cs_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then cs_sales_price* cs_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then cs_sales_price* cs_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then cs_sales_price* cs_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then cs_sales_price* cs_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then cs_sales_price* cs_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then cs_sales_price* cs_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as dec_net - from - catalog_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and cs_sold_time_sk = t_time_sk - and cs_ship_mode_sk = sm_ship_mode_sk - and d_year = 2001 - and t_time between 6152 AND 6152+28800 - and sm_carrier in ('AIRBORNE','MSC') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - ) x - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - order by w_warehouse_name - limit 100; - --- end template query66.tpl query 5 in stream 1 --- start template query84.tpl query 6 in stream 1 -select /* TPC-DS query84.tpl 0.80 */ c_customer_id as customer_id - , coalesce(c_last_name,'') || ', ' || coalesce(c_first_name,'') as customername - from customer - ,customer_address - ,customer_demographics - ,household_demographics - ,income_band - ,store_returns - where ca_city = 'Sunnyside' - and c_current_addr_sk = ca_address_sk - and ib_lower_bound >= 23067 - and ib_upper_bound <= 23067 + 50000 - and ib_income_band_sk = hd_income_band_sk - and cd_demo_sk = c_current_cdemo_sk - and hd_demo_sk = c_current_hdemo_sk - and sr_cdemo_sk = cd_demo_sk - order by c_customer_id - limit 100; - --- end template query84.tpl query 6 in stream 1 --- start template query98.tpl query 7 in stream 1 -select /* TPC-DS query98.tpl 0.32 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ss_ext_sales_price) as itemrevenue - ,sum(ss_ext_sales_price)*100/sum(sum(ss_ext_sales_price)) over - (partition by i_class) as revenueratio -from - store_sales - ,item - ,date_dim -where - ss_item_sk = i_item_sk - and i_category in ('Women', 'Home', 'Music') - and ss_sold_date_sk = d_date_sk - and d_date between cast('2000-06-25' as date) - and dateadd(day,30,cast('2000-06-25' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio; - --- end template query98.tpl query 7 in stream 1 --- start template query58.tpl query 8 in stream 1 -with /* TPC-DS query58.tpl 0.19 */ ss_items as - (select i_item_id item_id - ,sum(ss_ext_sales_price) ss_item_rev - from store_sales - ,item - ,date_dim - where ss_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '1999-05-29')) - and ss_sold_date_sk = d_date_sk - group by i_item_id), - cs_items as - (select i_item_id item_id - ,sum(cs_ext_sales_price) cs_item_rev - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '1999-05-29')) - and cs_sold_date_sk = d_date_sk - group by i_item_id), - ws_items as - (select i_item_id item_id - ,sum(ws_ext_sales_price) ws_item_rev - from web_sales - ,item - ,date_dim - where ws_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq =(select d_week_seq - from date_dim - where d_date = '1999-05-29')) - and ws_sold_date_sk = d_date_sk - group by i_item_id) - select ss_items.item_id - ,ss_item_rev - ,ss_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ss_dev - ,cs_item_rev - ,cs_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 cs_dev - ,ws_item_rev - ,ws_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ws_dev - ,(ss_item_rev+cs_item_rev+ws_item_rev)/3 average - from ss_items,cs_items,ws_items - where ss_items.item_id=cs_items.item_id - and ss_items.item_id=ws_items.item_id - and ss_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - and ss_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and cs_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and cs_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and ws_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and ws_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - order by item_id - ,ss_item_rev - limit 100; - --- end template query58.tpl query 8 in stream 1 --- start template query16.tpl query 9 in stream 1 -select /* TPC-DS query16.tpl 0.25 */ - count(distinct cs_order_number) as "order count" - ,sum(cs_ext_ship_cost) as "total shipping cost" - ,sum(cs_net_profit) as "total net profit" -from - catalog_sales cs1 - ,date_dim - ,customer_address - ,call_center -where - d_date between '2002-3-01' and - dateadd(day, 60, cast('2002-3-01' as date)) -and cs1.cs_ship_date_sk = d_date_sk -and cs1.cs_ship_addr_sk = ca_address_sk -and ca_state = 'MN' -and cs1.cs_call_center_sk = cc_call_center_sk -and cc_county in ('Jackson County','Marshall County','San Miguel County','Oglethorpe County', - 'Huron County' -) -and exists (select * - from catalog_sales cs2 - where cs1.cs_order_number = cs2.cs_order_number - and cs1.cs_warehouse_sk <> cs2.cs_warehouse_sk) -and not exists(select * - from catalog_returns cr1 - where cs1.cs_order_number = cr1.cr_order_number) -order by count(distinct cs_order_number) -limit 100; - --- end template query16.tpl query 9 in stream 1 --- start template query77a.tpl query 10 in stream 1 -with /* TPC-DS query77a.tpl 0.78 */ ss as - (select s_store_sk, - sum(ss_ext_sales_price) as sales, - sum(ss_net_profit) as profit - from store_sales, - date_dim, - store - where ss_sold_date_sk = d_date_sk - and d_date between cast('2002-08-17' as date) - and dateadd(day,30,cast('2002-08-17' as date)) - and ss_store_sk = s_store_sk - group by s_store_sk) - , - sr as - (select s_store_sk, - sum(sr_return_amt) as returns, - sum(sr_net_loss) as profit_loss - from store_returns, - date_dim, - store - where sr_returned_date_sk = d_date_sk - and d_date between cast('2002-08-17' as date) - and dateadd(day,30,cast('2002-08-17' as date)) - and sr_store_sk = s_store_sk - group by s_store_sk), - cs as - (select cs_call_center_sk, - sum(cs_ext_sales_price) as sales, - sum(cs_net_profit) as profit - from catalog_sales, - date_dim - where cs_sold_date_sk = d_date_sk - and d_date between cast('2002-08-17' as date) - and dateadd(day,30,cast('2002-08-17' as date)) - group by cs_call_center_sk - ), - cr as - (select cr_call_center_sk, - sum(cr_return_amount) as returns, - sum(cr_net_loss) as profit_loss - from catalog_returns, - date_dim - where cr_returned_date_sk = d_date_sk - and d_date between cast('2002-08-17' as date) - and dateadd(day,30,cast('2002-08-17' as date)) - group by cr_call_center_sk), - ws as - ( select wp_web_page_sk, - sum(ws_ext_sales_price) as sales, - sum(ws_net_profit) as profit - from web_sales, - date_dim, - web_page - where ws_sold_date_sk = d_date_sk - and d_date between cast('2002-08-17' as date) - and dateadd(day,30,cast('2002-08-17' as date)) - and ws_web_page_sk = wp_web_page_sk - group by wp_web_page_sk), - wr as - (select wp_web_page_sk, - sum(wr_return_amt) as returns, - sum(wr_net_loss) as profit_loss - from web_returns, - date_dim, - web_page - where wr_returned_date_sk = d_date_sk - and d_date between cast('2002-08-17' as date) - and dateadd(day,30,cast('2002-08-17' as date)) - and wr_web_page_sk = wp_web_page_sk - group by wp_web_page_sk) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , ss.s_store_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ss left join sr - on ss.s_store_sk = sr.s_store_sk - union all - select 'catalog channel' as channel - , cs_call_center_sk as id - , sales - , returns - , (profit - profit_loss) as profit - from cs - , cr - union all - select 'web channel' as channel - , ws.wp_web_page_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ws left join wr - on ws.wp_web_page_sk = wr.wp_web_page_sk - ) x - group by channel, id ) - - select * - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results -) foo -order by channel, id - limit 100; - --- end template query77a.tpl query 10 in stream 1 --- start template query40.tpl query 11 in stream 1 -select /* TPC-DS query40.tpl 0.86 */ - w_state - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('1998-05-07' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_before - ,sum(case when (cast(d_date as date) >= cast ('1998-05-07' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_after - from - catalog_sales left outer join catalog_returns on - (cs_order_number = cr_order_number - and cs_item_sk = cr_item_sk) - ,warehouse - ,item - ,date_dim - where - i_current_price between 0.99 and 1.49 - and i_item_sk = cs_item_sk - and cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('1998-05-07' as date)) - and dateadd(day,30,cast ('1998-05-07' as date)) - group by - w_state,i_item_id - order by w_state,i_item_id -limit 100; - --- end template query40.tpl query 11 in stream 1 --- start template query96.tpl query 12 in stream 1 -select /* TPC-DS query96.tpl 0.1 */ count(*) -from store_sales - ,household_demographics - ,time_dim, store -where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 16 - and time_dim.t_minute >= 30 - and household_demographics.hd_dep_count = 7 - and store.s_store_name = 'ese' -order by count(*) -limit 100; - --- end template query96.tpl query 12 in stream 1 --- start template query13.tpl query 13 in stream 1 -select /* TPC-DS query13.tpl 0.91 */ avg(ss_quantity) - ,avg(ss_ext_sales_price) - ,avg(ss_ext_wholesale_cost) - ,sum(ss_ext_wholesale_cost) - from store_sales - ,store - ,customer_demographics - ,household_demographics - ,customer_address - ,date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2001 - and((ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'D' - and cd_education_status = 'Unknown' - and ss_sales_price between 100.00 and 150.00 - and hd_dep_count = 3 - )or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'S' - and cd_education_status = 'Advanced Degree' - and ss_sales_price between 50.00 and 100.00 - and hd_dep_count = 1 - ) or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'W' - and cd_education_status = 'College' - and ss_sales_price between 150.00 and 200.00 - and hd_dep_count = 1 - )) - and((ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('LA', 'IN', 'VA') - and ss_net_profit between 100 and 200 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('MS', 'SD', 'ND') - and ss_net_profit between 150 and 300 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('IA', 'OH', 'MN') - and ss_net_profit between 50 and 250 - )) -; - --- end template query13.tpl query 13 in stream 1 --- start template query36a.tpl query 14 in stream 1 -with /* TPC-DS query36a.tpl 0.21 */ results as - (select - sum(ss_net_profit) as ss_net_profit, sum(ss_ext_sales_price) as ss_ext_sales_price, - sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin - ,i_category - ,i_class - ,0 as g_category, 0 as g_class - from - store_sales - ,date_dim d1 - ,item - ,store - where - d1.d_year = 1998 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and s_state in ('PA','GA','MI','MI', - 'MO','NY','TN','AL') - group by i_category,i_class) - , - results_rollup as - (select gross_margin ,i_category ,i_class,0 as t_category, 0 as t_class, 0 as lochierarchy from results - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - i_category, NULL AS i_class, 0 as t_category, 1 as t_class, 1 as lochierarchy from results group by i_category - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - NULL AS i_category ,NULL AS i_class, 1 as t_category, 1 as t_class, 2 as lochierarchy from results) - select - gross_margin ,i_category ,i_class, lochierarchy,rank() over ( - partition by lochierarchy, case when t_class = 0 then i_category end - order by gross_margin asc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then i_category end - ,rank_within_parent - limit 100; - --- end template query36a.tpl query 14 in stream 1 --- start template query95.tpl query 15 in stream 1 -with /* TPC-DS query95.tpl 0.43 */ ws_wh as -(select ws1.ws_order_number,ws1.ws_warehouse_sk wh1,ws2.ws_warehouse_sk wh2 - from web_sales ws1,web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) - select - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2002-3-01' and - dateadd(day,60,cast('2002-3-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'VA' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and ws1.ws_order_number in (select ws_order_number - from ws_wh) -and ws1.ws_order_number in (select wr_order_number - from web_returns,ws_wh - where wr_order_number = ws_wh.ws_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query95.tpl query 15 in stream 1 --- start template query63.tpl query 16 in stream 1 -select /* TPC-DS query63.tpl 0.27 */ * -from (select i_manager_id - ,sum(ss_sales_price) sum_sales - ,avg(sum(ss_sales_price)) over (partition by i_manager_id) avg_monthly_sales - from item - ,store_sales - ,date_dim - ,store - where ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and d_month_seq in (1202,1202+1,1202+2,1202+3,1202+4,1202+5,1202+6,1202+7,1202+8,1202+9,1202+10,1202+11) - and (( i_category in ('Books','Children','Electronics') - and i_class in ('personal','portable','reference','self-help') - and i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) - or( i_category in ('Women','Music','Men') - and i_class in ('accessories','classical','fragrances','pants') - and i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manager_id, d_moy) tmp1 -where case when avg_monthly_sales > 0 then abs (sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 -order by i_manager_id - ,avg_monthly_sales - ,sum_sales -limit 100; - --- end template query63.tpl query 16 in stream 1 --- start template query99.tpl query 17 in stream 1 -select /* TPC-DS query99.tpl 0.94 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 30) and - (cs_ship_date_sk - cs_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 60) and - (cs_ship_date_sk - cs_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 90) and - (cs_ship_date_sk - cs_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - catalog_sales - ,warehouse - ,ship_mode - ,call_center - ,date_dim -where - d_month_seq between 1218 and 1218 + 11 -and cs_ship_date_sk = d_date_sk -and cs_warehouse_sk = w_warehouse_sk -and cs_ship_mode_sk = sm_ship_mode_sk -and cs_call_center_sk = cc_call_center_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -limit 100; - --- end template query99.tpl query 17 in stream 1 --- start template query3.tpl query 18 in stream 1 -select /* TPC-DS query3.tpl 0.45 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_net_profit) sum_agg - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manufact_id = 826 - and dt.d_moy=12 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,sum_agg desc - ,brand_id - limit 100; - --- end template query3.tpl query 18 in stream 1 --- start template query6.tpl query 19 in stream 1 -select /* TPC-DS query6.tpl 0.58 */ a.ca_state state, count(*) cnt - from customer_address a - ,customer c - ,store_sales s - ,date_dim d - ,item i - where a.ca_address_sk = c.c_current_addr_sk - and c.c_customer_sk = s.ss_customer_sk - and s.ss_sold_date_sk = d.d_date_sk - and s.ss_item_sk = i.i_item_sk - and d.d_month_seq = - (select distinct (d_month_seq) - from date_dim - where d_year = 1999 - and d_moy = 4 ) - and i.i_current_price > 1.2 * - (select avg(j.i_current_price) - from item j - where j.i_category = i.i_category) - group by a.ca_state - having count(*) >= 10 - order by cnt, a.ca_state - limit 100; - --- end template query6.tpl query 19 in stream 1 --- start template query12.tpl query 20 in stream 1 -select /* TPC-DS query12.tpl 0.64 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ws_ext_sales_price) as itemrevenue - ,sum(ws_ext_sales_price)*100/sum(sum(ws_ext_sales_price)) over - (partition by i_class) as revenueratio -from - web_sales - ,item - ,date_dim -where - ws_item_sk = i_item_sk - and i_category in ('Men', 'Jewelry', 'Women') - and ws_sold_date_sk = d_date_sk - and d_date between cast('2000-01-21' as date) - and dateadd(day,30,cast('2000-01-21' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query12.tpl query 20 in stream 1 --- start template query28.tpl query 21 in stream 1 -select /* TPC-DS query28.tpl 0.36 */ * -from (select avg(ss_list_price) B1_LP - ,count(ss_list_price) B1_CNT - ,count(distinct ss_list_price) B1_CNTD - from store_sales - where ss_quantity between 0 and 5 - and (ss_list_price between 2 and 2+10 - or ss_coupon_amt between 4869 and 4869+1000 - or ss_wholesale_cost between 15 and 15+20)) B1, - (select avg(ss_list_price) B2_LP - ,count(ss_list_price) B2_CNT - ,count(distinct ss_list_price) B2_CNTD - from store_sales - where ss_quantity between 6 and 10 - and (ss_list_price between 28 and 28+10 - or ss_coupon_amt between 13932 and 13932+1000 - or ss_wholesale_cost between 17 and 17+20)) B2, - (select avg(ss_list_price) B3_LP - ,count(ss_list_price) B3_CNT - ,count(distinct ss_list_price) B3_CNTD - from store_sales - where ss_quantity between 11 and 15 - and (ss_list_price between 131 and 131+10 - or ss_coupon_amt between 6064 and 6064+1000 - or ss_wholesale_cost between 73 and 73+20)) B3, - (select avg(ss_list_price) B4_LP - ,count(ss_list_price) B4_CNT - ,count(distinct ss_list_price) B4_CNTD - from store_sales - where ss_quantity between 16 and 20 - and (ss_list_price between 147 and 147+10 - or ss_coupon_amt between 15739 and 15739+1000 - or ss_wholesale_cost between 60 and 60+20)) B4, - (select avg(ss_list_price) B5_LP - ,count(ss_list_price) B5_CNT - ,count(distinct ss_list_price) B5_CNTD - from store_sales - where ss_quantity between 21 and 25 - and (ss_list_price between 146 and 146+10 - or ss_coupon_amt between 2128 and 2128+1000 - or ss_wholesale_cost between 51 and 51+20)) B5, - (select avg(ss_list_price) B6_LP - ,count(ss_list_price) B6_CNT - ,count(distinct ss_list_price) B6_CNTD - from store_sales - where ss_quantity between 26 and 30 - and (ss_list_price between 41 and 41+10 - or ss_coupon_amt between 4345 and 4345+1000 - or ss_wholesale_cost between 48 and 48+20)) B6 -limit 100; - --- end template query28.tpl query 21 in stream 1 --- start template query85.tpl query 22 in stream 1 -select /* TPC-DS query85.tpl 0.33 */ substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) - from web_sales, web_returns, web_page, customer_demographics cd1, - customer_demographics cd2, customer_address, date_dim, reason - where ws_web_page_sk = wp_web_page_sk - and ws_item_sk = wr_item_sk - and ws_order_number = wr_order_number - and ws_sold_date_sk = d_date_sk and d_year = 2002 - and cd1.cd_demo_sk = wr_refunded_cdemo_sk - and cd2.cd_demo_sk = wr_returning_cdemo_sk - and ca_address_sk = wr_refunded_addr_sk - and r_reason_sk = wr_reason_sk - and - ( - ( - cd1.cd_marital_status = 'W' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Advanced Degree' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 100.00 and 150.00 - ) - or - ( - cd1.cd_marital_status = 'S' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Primary' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 50.00 and 100.00 - ) - or - ( - cd1.cd_marital_status = 'U' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Unknown' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ca_country = 'United States' - and - ca_state in ('OH', 'MI', 'PA') - and ws_net_profit between 100 and 200 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('NY', 'IN', 'FL') - and ws_net_profit between 150 and 300 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('IA', 'TN', 'OK') - and ws_net_profit between 50 and 250 - ) - ) -group by r_reason_desc -order by substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) -limit 100; - --- end template query85.tpl query 22 in stream 1 --- start template query51.tpl query 23 in stream 1 -WITH /* TPC-DS query51.tpl 0.46 */ web_v1 as ( -select - ws_item_sk item_sk, d_date, - sum(sum(ws_sales_price)) - over (partition by ws_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from web_sales - ,date_dim -where ws_sold_date_sk=d_date_sk - and d_month_seq between 1198 and 1198+11 - and ws_item_sk is not NULL -group by ws_item_sk, d_date), -store_v1 as ( -select - ss_item_sk item_sk, d_date, - sum(sum(ss_sales_price)) - over (partition by ss_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from store_sales - ,date_dim -where ss_sold_date_sk=d_date_sk - and d_month_seq between 1198 and 1198+11 - and ss_item_sk is not NULL -group by ss_item_sk, d_date) - select * -from (select item_sk - ,d_date - ,web_sales - ,store_sales - ,max(web_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) web_cumulative - ,max(store_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) store_cumulative - from (select case when web.item_sk is not null then web.item_sk else store.item_sk end item_sk - ,case when web.d_date is not null then web.d_date else store.d_date end d_date - ,web.cume_sales web_sales - ,store.cume_sales store_sales - from web_v1 web full outer join store_v1 store on (web.item_sk = store.item_sk - and web.d_date = store.d_date) - )x )y -where web_cumulative > store_cumulative -order by item_sk - ,d_date -limit 100; - --- end template query51.tpl query 23 in stream 1 --- start template query41.tpl query 24 in stream 1 -select /* TPC-DS query41.tpl 0.62 */ distinct(i_product_name) - from item i1 - where i_manufact_id between 985 and 985+40 - and (select count(*) as item_cnt - from item - where (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'peach' or i_color = 'cyan') and - (i_units = 'N/A' or i_units = 'Pallet') and - (i_size = 'N/A' or i_size = 'small') - ) or - (i_category = 'Women' and - (i_color = 'deep' or i_color = 'orchid') and - (i_units = 'Gross' or i_units = 'Bunch') and - (i_size = 'extra large' or i_size = 'economy') - ) or - (i_category = 'Men' and - (i_color = 'khaki' or i_color = 'goldenrod') and - (i_units = 'Gram' or i_units = 'Tsp') and - (i_size = 'petite' or i_size = 'large') - ) or - (i_category = 'Men' and - (i_color = 'midnight' or i_color = 'wheat') and - (i_units = 'Ton' or i_units = 'Dozen') and - (i_size = 'N/A' or i_size = 'small') - ))) or - (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'violet' or i_color = 'ivory') and - (i_units = 'Case' or i_units = 'Carton') and - (i_size = 'N/A' or i_size = 'small') - ) or - (i_category = 'Women' and - (i_color = 'sky' or i_color = 'lavender') and - (i_units = 'Cup' or i_units = 'Dram') and - (i_size = 'extra large' or i_size = 'economy') - ) or - (i_category = 'Men' and - (i_color = 'puff' or i_color = 'rosy') and - (i_units = 'Each' or i_units = 'Ounce') and - (i_size = 'petite' or i_size = 'large') - ) or - (i_category = 'Men' and - (i_color = 'rose' or i_color = 'olive') and - (i_units = 'Oz' or i_units = 'Pound') and - (i_size = 'N/A' or i_size = 'small') - )))) > 0 - order by i_product_name - limit 100; - --- end template query41.tpl query 24 in stream 1 --- start template query27a.tpl query 25 in stream 1 -with /* TPC-DS query27a.tpl 0.16 */ results as - (select i_item_id, - s_state, 0 as g_state, - ss_quantity agg1, - ss_list_price agg2, - ss_coupon_amt agg3, - ss_sales_price agg4 - from store_sales, customer_demographics, date_dim, store, item - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_store_sk = s_store_sk and - ss_cdemo_sk = cd_demo_sk and - cd_gender = 'M' and - cd_marital_status = 'D' and - cd_education_status = 'College' and - d_year = 1999 and - s_state in ('NM','PA', 'WA', 'TX', 'AL', 'MO') - ) - - select i_item_id, - s_state, g_state, agg1, agg2, agg3, agg4 - from ( - select i_item_id, s_state, 0 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4 from results - group by i_item_id, s_state - union all - select i_item_id, NULL AS s_state, 1 AS g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as s_state, 1 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - ) foo - order by i_item_id, s_state - limit 100; - --- end template query27a.tpl query 25 in stream 1 --- start template query78.tpl query 26 in stream 1 -with /* TPC-DS query78.tpl 0.10 */ ws as - (select d_year AS ws_sold_year, ws_item_sk, - ws_bill_customer_sk ws_customer_sk, - sum(ws_quantity) ws_qty, - sum(ws_wholesale_cost) ws_wc, - sum(ws_sales_price) ws_sp - from web_sales - left join web_returns on wr_order_number=ws_order_number and ws_item_sk=wr_item_sk - join date_dim on ws_sold_date_sk = d_date_sk - where wr_order_number is null - group by d_year, ws_item_sk, ws_bill_customer_sk - ), -cs as - (select d_year AS cs_sold_year, cs_item_sk, - cs_bill_customer_sk cs_customer_sk, - sum(cs_quantity) cs_qty, - sum(cs_wholesale_cost) cs_wc, - sum(cs_sales_price) cs_sp - from catalog_sales - left join catalog_returns on cr_order_number=cs_order_number and cs_item_sk=cr_item_sk - join date_dim on cs_sold_date_sk = d_date_sk - where cr_order_number is null - group by d_year, cs_item_sk, cs_bill_customer_sk - ), -ss as - (select d_year AS ss_sold_year, ss_item_sk, - ss_customer_sk, - sum(ss_quantity) ss_qty, - sum(ss_wholesale_cost) ss_wc, - sum(ss_sales_price) ss_sp - from store_sales - left join store_returns on sr_ticket_number=ss_ticket_number and ss_item_sk=sr_item_sk - join date_dim on ss_sold_date_sk = d_date_sk - where sr_ticket_number is null - group by d_year, ss_item_sk, ss_customer_sk - ) - select -ss_sold_year, ss_item_sk, ss_customer_sk, -round(ss_qty/(coalesce(ws_qty,0)+coalesce(cs_qty,0)),2) ratio, -ss_qty store_qty, ss_wc store_wholesale_cost, ss_sp store_sales_price, -coalesce(ws_qty,0)+coalesce(cs_qty,0) other_chan_qty, -coalesce(ws_wc,0)+coalesce(cs_wc,0) other_chan_wholesale_cost, -coalesce(ws_sp,0)+coalesce(cs_sp,0) other_chan_sales_price -from ss -left join ws on (ws_sold_year=ss_sold_year and ws_item_sk=ss_item_sk and ws_customer_sk=ss_customer_sk) -left join cs on (cs_sold_year=ss_sold_year and cs_item_sk=ss_item_sk and cs_customer_sk=ss_customer_sk) -where (coalesce(ws_qty,0)>0 or coalesce(cs_qty, 0)>0) and ss_sold_year=2002 -order by - ss_sold_year, ss_item_sk, ss_customer_sk, - ss_qty desc, ss_wc desc, ss_sp desc, - other_chan_qty, - other_chan_wholesale_cost, - other_chan_sales_price, - ratio -limit 100; - --- end template query78.tpl query 26 in stream 1 --- start template query8.tpl query 27 in stream 1 -select /* TPC-DS query8.tpl 0.63 */ s_store_name - ,sum(ss_net_profit) - from store_sales - ,date_dim - ,store, - (select ca_zip - from ( - SELECT substring(ca_zip,1,5) ca_zip - FROM customer_address - WHERE substring(ca_zip,1,5) IN ( - '31269','62978','24771','75908','26633','58807', - '91823','46238','46217','30888','82296', - '15031','61670','59715','98486','53342', - '35183','73499','58660','16750','46584', - '49175','17240','73061','40114','52140', - '41731','21764','26217','22312','40718', - '27875','26621','67481','19205','66059', - '56942','60701','98608','80016','68865', - '82808','57915','95643','47035','44491', - '78926','15630','46264','70791','41486', - '48014','20084','25385','40531','21011', - '91104','29457','20842','10447','40637', - '35745','41195','24747','97386','54687', - '25476','61167','57566','65744','34121', - '54959','86192','63258','80664','20951', - '10813','41908','76419','47735','80990', - '92768','27935','63216','91444','35227', - '52389','87666','25920','72443','53615', - '32332','70064','43058','75022','39293', - '11398','79515','94539','95825','54591', - '41684','20429','65088','16558','94163', - '63673','30818','92386','87118','87601', - '38203','19047','44848','68948','42477', - '79734','98424','93565','81591','16200', - '65720','56494','38236','27711','18651', - '68920','69560','62567','61847','23900', - '77840','10540','98865','71716','36214', - '56403','41470','37409','24517','99038', - '12449','40682','38379','20090','41321', - '24534','63217','48584','66954','76196', - '20435','14513','88692','59058','50177', - '97620','43525','10563','27604','33815', - '80134','19911','19558','63626','66867', - '56643','79911','95326','92834','86481', - '47209','31274','45962','36409','12235', - '24887','98953','31123','92823','55662', - '23220','91799','10234','59327','10778', - '38878','50756','19340','96761','61794', - '19200','91732','86726','49274','95286', - '70120','10774','16362','19629','84302', - '55826','64497','81089','69969','86323', - '16203','70828','37735','84782','26226', - '25155','15054','24459','30254','96473', - '53553','62496','83336','68111','69856', - '19907','97815','13523','65881','46711', - '16620','95053','59072','53685','69865', - '13471','87339','82731','93521','49294', - '57454','83098','95213','70967','30424', - '43636','74877','27332','74396','54115', - '83816','92832','31942','92178','66192', - '25450','47951','65618','37587','57300', - '50936','18439','55603','73435','67730', - '79136','48046','42288','51727','93138', - '73315','28088','40487','34271','42118', - '78187','49747','57559','73675','39639', - '12395','18415','85347','52779','37364', - '88177','89232','92678','15721','29855', - '67332','11422','71634','95807','41451', - '60932','70205','95133','88461','14545', - '69194','38064','34275','90543','98442', - '43466','26349','87807','84040','57546', - '59693','60294','16669','74794','64728', - '14831','44796','29661','87115','93843', - '49261','10707','79281','84707','82761', - '79865','55364','88944','65426','92184', - '45993','73346','88551','14660','37541', - '42738','99844','74207','92947','30767', - '58667','57172','11787','51089','94496', - '88984','26912','28399','62632','24871', - '49485','50402','79324','63338','34202', - '37653','70307','45036','68885','69648', - '65231','28814','66838','29933','45684', - '83782','93023','72602','14311','95487', - '47057','77739','33708','71129','18050', - '91362','29764','68930','16213','14355', - '79995','67095','23389','69788','58036', - '17182','69533','91913','84814','32039', - '82983','61327','17017','68776','22961', - '55006','91792','81722','37087','26060', - '56454','90011','26724','24746') - intersect - select ca_zip - from (SELECT substring(ca_zip,1,5) ca_zip,count(*) cnt - FROM customer_address, customer - WHERE ca_address_sk = c_current_addr_sk and - c_preferred_cust_flag='Y' - group by ca_zip - having count(*) > 10)A1)A2) V1 - where ss_store_sk = s_store_sk - and ss_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 2000 - and (substring(s_zip,1,2) = substring(V1.ca_zip,1,2)) - group by s_store_name - order by s_store_name - limit 100; - --- end template query8.tpl query 27 in stream 1 --- start template query14a.tpl query 28 in stream 1 -with /* TPC-DS query14a.tpl 0.69 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1998 AND 1998 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1998 AND 1998 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1998 AND 1998 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as - (select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2) x) -, - results AS -(select channel, i_brand_id, i_class_id, i_category_id, sum(sales) sum_sales, sum(number_sales) number_sales - from ( - select 'store' channel, i_brand_id,i_class_id - ,i_category_id,sum(ss_quantity*ss_list_price) sales - , count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1998+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales) - union all - select 'catalog' channel, i_brand_id,i_class_id,i_category_id, sum(cs_quantity*cs_list_price) sales, count(*) number_sales - from catalog_sales - ,item - ,date_dim - where cs_item_sk in (select ss_item_sk from cross_items) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1998+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(cs_quantity*cs_list_price) > (select average_sales from avg_sales) - union all - select 'web' channel, i_brand_id,i_class_id,i_category_id, sum(ws_quantity*ws_list_price) sales , count(*) number_sales - from web_sales - ,item - ,date_dim - where ws_item_sk in (select ss_item_sk from cross_items) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1998+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ws_quantity*ws_list_price) > (select average_sales from avg_sales) - ) y - group by channel, i_brand_id,i_class_id,i_category_id) - - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales -from ( - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales from results - union - select channel, i_brand_id, i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id, i_class_id - union - select channel, i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id - union - select channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel - union - select null as channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results) z -order by channel, i_brand_id, i_class_id, i_category_id - limit 100; -with /* TPC-DS query14a.tpl 0.69 part2 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1998 AND 1998 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1998 AND 1998 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1998 AND 1998 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as -(select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2) x) - select this_year.channel ty_channel - ,this_year.i_brand_id ty_brand - ,this_year.i_class_id ty_class - ,this_year.i_category_id ty_category - ,this_year.sales ty_sales - ,this_year.number_sales ty_number_sales - ,last_year.channel ly_channel - ,last_year.i_brand_id ly_brand - ,last_year.i_class_id ly_class - ,last_year.i_category_id ly_category - ,last_year.sales ly_sales - ,last_year.number_sales ly_number_sales -from - (select 'store' channel, i_brand_id,i_class_id,i_category_id - ,sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1998 + 1 - and d_moy = 12 - and d_dom = 4) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) this_year, - (select 'store' channel, i_brand_id,i_class_id - ,i_category_id, sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1998 - and d_moy = 12 - and d_dom = 4) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) last_year - where this_year.i_brand_id= last_year.i_brand_id - and this_year.i_class_id = last_year.i_class_id - and this_year.i_category_id = last_year.i_category_id - order by this_year.channel, this_year.i_brand_id, this_year.i_class_id, this_year.i_category_id - limit 100; - --- end template query14a.tpl query 28 in stream 1 --- start template query50.tpl query 29 in stream 1 -select /* TPC-DS query50.tpl 0.60 */ - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 30) and - (sr_returned_date_sk - ss_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 60) and - (sr_returned_date_sk - ss_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 90) and - (sr_returned_date_sk - ss_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - store_sales - ,store_returns - ,store - ,date_dim d1 - ,date_dim d2 -where - d2.d_year = 2001 -and d2.d_moy = 8 -and ss_ticket_number = sr_ticket_number -and ss_item_sk = sr_item_sk -and ss_sold_date_sk = d1.d_date_sk -and sr_returned_date_sk = d2.d_date_sk -and ss_customer_sk = sr_customer_sk -and ss_store_sk = s_store_sk -group by - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -order by s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -limit 100; - --- end template query50.tpl query 29 in stream 1 --- start template query52.tpl query 30 in stream 1 -select /* TPC-DS query52.tpl 0.59 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_sales_price) ext_price - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=12 - and dt.d_year=2002 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,ext_price desc - ,brand_id -limit 100 ; - --- end template query52.tpl query 30 in stream 1 --- start template query81.tpl query 31 in stream 1 -with /* TPC-DS query81.tpl 0.37 */ customer_total_return as - (select cr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(cr_return_amt_inc_tax) as ctr_total_return - from catalog_returns - ,date_dim - ,customer_address - where cr_returned_date_sk = d_date_sk - and d_year =2002 - and cr_returning_addr_sk = ca_address_sk - group by cr_returning_customer_sk - ,ca_state ) - select c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'CT' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - limit 100; - --- end template query81.tpl query 31 in stream 1 --- start template query5a.tpl query 32 in stream 1 -with /* TPC-DS query5a.tpl 0.98 */ ssr as - (select s_store_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ss_store_sk as store_sk, - ss_sold_date_sk as date_sk, - ss_ext_sales_price as sales_price, - ss_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from store_sales - union all - select sr_store_sk as store_sk, - sr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - sr_return_amt as return_amt, - sr_net_loss as net_loss - from store_returns - ) salesreturns, - date_dim, - store - where date_sk = d_date_sk - and d_date between cast('2001-08-11' as date) - and dateadd(day,14,cast('2001-08-11' as date)) - and store_sk = s_store_sk - group by s_store_id) - , - csr as - (select cp_catalog_page_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select cs_catalog_page_sk as page_sk, - cs_sold_date_sk as date_sk, - cs_ext_sales_price as sales_price, - cs_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from catalog_sales - union all - select cr_catalog_page_sk as page_sk, - cr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - cr_return_amount as return_amt, - cr_net_loss as net_loss - from catalog_returns - ) salesreturns, - date_dim, - catalog_page - where date_sk = d_date_sk - and d_date between cast('2001-08-11' as date) - and dateadd(day,14,cast('2001-08-11' as date)) - and page_sk = cp_catalog_page_sk - group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ws_web_site_sk as wsr_web_site_sk, - ws_sold_date_sk as date_sk, - ws_ext_sales_price as sales_price, - ws_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from web_sales - union all - select ws_web_site_sk as wsr_web_site_sk, - wr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - wr_return_amt as return_amt, - wr_net_loss as net_loss - from web_returns left outer join web_sales on - ( wr_item_sk = ws_item_sk - and wr_order_number = ws_order_number) - ) salesreturns, - date_dim, - web_site - where date_sk = d_date_sk - and d_date between cast('2001-08-11' as date) - and dateadd(day,14,cast('2001-08-11' as date)) - and wsr_web_site_sk = web_site_sk - group by web_site_id) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || s_store_id as id - , sales - , returns - , (profit - profit_loss) as profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || cp_catalog_page_id as id - , sales - , returns - , (profit - profit_loss) as profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , (profit - profit_loss) as profit - from wsr - ) x - group by channel, id) - select channel, id, sales, returns, profit from ( - select channel, id, sales, returns, profit from results - union - select channel, null as id, sum(sales), sum(returns), sum(profit) from results group by channel - union - select null as channel, null as id, sum(sales), sum(returns), sum(profit) from results) foo -order by channel, id -limit 100; - --- end template query5a.tpl query 32 in stream 1 --- start template query26.tpl query 33 in stream 1 -select /* TPC-DS query26.tpl 0.85 */ i_item_id, - avg(cs_quantity) agg1, - avg(cs_list_price) agg2, - avg(cs_coupon_amt) agg3, - avg(cs_sales_price) agg4 - from catalog_sales, customer_demographics, date_dim, item, promotion - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd_demo_sk and - cs_promo_sk = p_promo_sk and - cd_gender = 'F' and - cd_marital_status = 'D' and - cd_education_status = 'Secondary' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 1999 - group by i_item_id - order by i_item_id - limit 100; - --- end template query26.tpl query 33 in stream 1 --- start template query57.tpl query 34 in stream 1 -with /* TPC-DS query57.tpl 0.70 */ v1 as( - select i_category, i_brand, - cc_name, - d_year, d_moy, - sum(cs_sales_price) sum_sales, - avg(sum(cs_sales_price)) over - (partition by i_category, i_brand, - cc_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - cc_name - order by d_year, d_moy) rn - from item, catalog_sales, date_dim, call_center - where cs_item_sk = i_item_sk and - cs_sold_date_sk = d_date_sk and - cc_call_center_sk= cs_call_center_sk and - ( - d_year = 1999 or - ( d_year = 1999-1 and d_moy =12) or - ( d_year = 1999+1 and d_moy =1) - ) - group by i_category, i_brand, - cc_name , d_year, d_moy), - v2 as( - select v1.cc_name - ,v1.d_year, v1.d_moy - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1. cc_name = v1_lag. cc_name and - v1. cc_name = v1_lead. cc_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 1999 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, psum - limit 100; - --- end template query57.tpl query 34 in stream 1 --- start template query82.tpl query 35 in stream 1 -select /* TPC-DS query82.tpl 0.67 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, store_sales - where i_current_price between 26 and 26+30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('2002-06-26' as date) and dateadd(day,60,cast('2002-06-26' as date)) - and i_manufact_id in (889,568,806,360) - and inv_quantity_on_hand between 100 and 500 - and ss_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query82.tpl query 35 in stream 1 --- start template query69.tpl query 36 in stream 1 -select /* TPC-DS query69.tpl 0.28 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_state in ('TX','OH','VA') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 4 and 4+2) and - (not exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 4 and 4+2) and - not exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 4 and 4+2)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - limit 100; - --- end template query69.tpl query 36 in stream 1 --- start template query54.tpl query 37 in stream 1 -with /* TPC-DS query54.tpl 0.81 */ my_customers as ( - select distinct c_customer_sk - , c_current_addr_sk - from - ( select cs_sold_date_sk sold_date_sk, - cs_bill_customer_sk customer_sk, - cs_item_sk item_sk - from catalog_sales - union all - select ws_sold_date_sk sold_date_sk, - ws_bill_customer_sk customer_sk, - ws_item_sk item_sk - from web_sales - ) cs_or_ws_sales, - item, - date_dim, - customer - where sold_date_sk = d_date_sk - and item_sk = i_item_sk - and i_category = 'Electronics' - and i_class = 'automotive' - and c_customer_sk = cs_or_ws_sales.customer_sk - and d_moy = 3 - and d_year = 2002 - ) - , my_revenue as ( - select c_customer_sk, - sum(ss_ext_sales_price) as revenue - from my_customers, - store_sales, - customer_address, - store, - date_dim - where c_current_addr_sk = ca_address_sk - and ca_county = s_county - and ca_state = s_state - and ss_sold_date_sk = d_date_sk - and c_customer_sk = ss_customer_sk - and d_month_seq between (select distinct d_month_seq+1 - from date_dim where d_year = 2002 and d_moy = 3) - and (select distinct d_month_seq+3 - from date_dim where d_year = 2002 and d_moy = 3) - group by c_customer_sk - ) - , segments as - (select cast((revenue/50) as int) as segment - from my_revenue - ) - select segment, count(*) as num_customers, segment*50 as segment_base - from segments - group by segment - order by segment, num_customers - limit 100; - --- end template query54.tpl query 37 in stream 1 --- start template query61.tpl query 38 in stream 1 -select /* TPC-DS query61.tpl 0.97 */ promotions,total,cast(promotions as decimal(15,4))/cast(total as decimal(15,4))*100 -from - (select sum(ss_ext_sales_price) promotions - from store_sales - ,store - ,promotion - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_promo_sk = p_promo_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -7 - and i_category = 'Sports' - and (p_channel_dmail = 'Y' or p_channel_email = 'Y' or p_channel_tv = 'Y') - and s_gmt_offset = -7 - and d_year = 2000 - and d_moy = 11) promotional_sales, - (select sum(ss_ext_sales_price) total - from store_sales - ,store - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -7 - and i_category = 'Sports' - and s_gmt_offset = -7 - and d_year = 2000 - and d_moy = 11) all_sales -order by promotions, total -limit 100; - --- end template query61.tpl query 38 in stream 1 --- start template query88.tpl query 39 in stream 1 -select /* TPC-DS query88.tpl 0.66 */ * -from - (select count(*) h8_30_to_9 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s1, - (select count(*) h9_to_9_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s2, - (select count(*) h9_30_to_10 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s3, - (select count(*) h10_to_10_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s4, - (select count(*) h10_30_to_11 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s5, - (select count(*) h11_to_11_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s6, - (select count(*) h11_30_to_12 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s7, - (select count(*) h12_to_12_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 12 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s8 -; - --- end template query88.tpl query 39 in stream 1 --- start template query18a.tpl query 40 in stream 1 -with /* TPC-DS query18a.tpl 0.90 */ results as - (select i_item_id, - ca_country, - ca_state, - ca_county, - cast(cs_quantity as decimal(12,2)) agg1, - cast(cs_list_price as decimal(12,2)) agg2, - cast(cs_coupon_amt as decimal(12,2)) agg3, - cast(cs_sales_price as decimal(12,2)) agg4, - cast(cs_net_profit as decimal(12,2)) agg5, - cast(c_birth_year as decimal(12,2)) agg6, - cast(cd1.cd_dep_count as decimal(12,2)) agg7 - from catalog_sales, customer_demographics cd1, customer_demographics cd2, customer, customer_address, date_dim, item - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd1.cd_demo_sk and - cs_bill_customer_sk = c_customer_sk and - cd1.cd_gender = 'F' and - cd1.cd_education_status = 'Unknown' and - c_current_cdemo_sk = cd2.cd_demo_sk and - c_current_addr_sk = ca_address_sk and - c_birth_month in (12,10,4,9,7,8) and - d_year = 2002 and - ca_state in ('WV','NC','MI','GA','AR','LA','KS') - ) - select i_item_id, ca_country, ca_state, ca_county, agg1, agg2, agg3, agg4, agg5, agg6, agg7 - from ( - select i_item_id, ca_country, ca_state, ca_county, avg(agg1) agg1, - avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state, ca_county - union all - select i_item_id, ca_country, ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state - union all - select i_item_id, ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country - union all - select i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - ) foo - order by ca_country, ca_state, ca_county, i_item_id - limit 100; - --- end template query18a.tpl query 40 in stream 1 --- start template query94.tpl query 41 in stream 1 -select /* TPC-DS query94.tpl 0.17 */ - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2001-2-01' and - dateadd(day,60,cast('2001-2-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'TX' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and exists (select * - from web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) -and not exists(select * - from web_returns wr1 - where ws1.ws_order_number = wr1.wr_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query94.tpl query 41 in stream 1 --- start template query35a.tpl query 42 in stream 1 -select /* TPC-DS query35a.tpl 0.47 */ - ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - count(*) cnt1, - max(cd_dep_count), - max(cd_dep_count), - avg(cd_dep_count), - cd_dep_employed_count, - count(*) cnt2, - max(cd_dep_employed_count), - max(cd_dep_employed_count), - avg(cd_dep_employed_count), - cd_dep_college_count, - count(*) cnt3, - max(cd_dep_college_count), - max(cd_dep_college_count), - avg(cd_dep_college_count) - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2000 and - d_qoy < 4) and - exists (select * from - (select ws_bill_customer_sk customsk - from web_sales,date_dim - where - ws_sold_date_sk = d_date_sk and - d_year = 2000 and - d_qoy < 4 - union all - select cs_ship_customer_sk customsk - from catalog_sales,date_dim - where - cs_sold_date_sk = d_date_sk and - d_year = 2000 and - d_qoy < 4)x - where x.customsk = c.c_customer_sk) - group by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - limit 100; - --- end template query35a.tpl query 42 in stream 1 --- start template query68.tpl query 43 in stream 1 -select /* TPC-DS query68.tpl 0.95 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,extended_price - ,extended_tax - ,list_price - from (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_ext_sales_price) extended_price - ,sum(ss_ext_list_price) list_price - ,sum(ss_ext_tax) extended_tax - from store_sales - ,date_dim - ,store - ,household_demographics - ,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_dep_count = 4 or - household_demographics.hd_vehicle_count= 3) - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_city in ('Concord','Hopewell') - group by ss_ticket_number - ,ss_customer_sk - ,ss_addr_sk,ca_city) dn - ,customer - ,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,ss_ticket_number - limit 100; - --- end template query68.tpl query 43 in stream 1 --- start template query24.tpl query 44 in stream 1 -with /* TPC-DS query24.tpl 0.92 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_ext_sales_price) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip -and s_market_id=10 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'moccasin' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; -with /* TPC-DS query24.tpl 0.92 part2 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_ext_sales_price) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip - and s_market_id = 10 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'lime' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; - --- end template query24.tpl query 44 in stream 1 --- start template query75.tpl query 45 in stream 1 -WITH /* TPC-DS query75.tpl 0.3 */ all_sales AS ( - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,SUM(sales_cnt) AS sales_cnt - ,SUM(sales_amt) AS sales_amt - FROM (SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,cs_quantity - COALESCE(cr_return_quantity,0) AS sales_cnt - ,cs_ext_sales_price - COALESCE(cr_return_amount,0.0) AS sales_amt - FROM catalog_sales JOIN item ON i_item_sk=cs_item_sk - JOIN date_dim ON d_date_sk=cs_sold_date_sk - LEFT JOIN catalog_returns ON (cs_order_number=cr_order_number - AND cs_item_sk=cr_item_sk) - WHERE i_category='Home' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ss_quantity - COALESCE(sr_return_quantity,0) AS sales_cnt - ,ss_ext_sales_price - COALESCE(sr_return_amt,0.0) AS sales_amt - FROM store_sales JOIN item ON i_item_sk=ss_item_sk - JOIN date_dim ON d_date_sk=ss_sold_date_sk - LEFT JOIN store_returns ON (ss_ticket_number=sr_ticket_number - AND ss_item_sk=sr_item_sk) - WHERE i_category='Home' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ws_quantity - COALESCE(wr_return_quantity,0) AS sales_cnt - ,ws_ext_sales_price - COALESCE(wr_return_amt,0.0) AS sales_amt - FROM web_sales JOIN item ON i_item_sk=ws_item_sk - JOIN date_dim ON d_date_sk=ws_sold_date_sk - LEFT JOIN web_returns ON (ws_order_number=wr_order_number - AND ws_item_sk=wr_item_sk) - WHERE i_category='Home') sales_detail - GROUP BY d_year, i_brand_id, i_class_id, i_category_id, i_manufact_id) - SELECT prev_yr.d_year AS prev_year - ,curr_yr.d_year AS year - ,curr_yr.i_brand_id - ,curr_yr.i_class_id - ,curr_yr.i_category_id - ,curr_yr.i_manufact_id - ,prev_yr.sales_cnt AS prev_yr_cnt - ,curr_yr.sales_cnt AS curr_yr_cnt - ,curr_yr.sales_cnt-prev_yr.sales_cnt AS sales_cnt_diff - ,curr_yr.sales_amt-prev_yr.sales_amt AS sales_amt_diff - FROM all_sales curr_yr, all_sales prev_yr - WHERE curr_yr.i_brand_id=prev_yr.i_brand_id - AND curr_yr.i_class_id=prev_yr.i_class_id - AND curr_yr.i_category_id=prev_yr.i_category_id - AND curr_yr.i_manufact_id=prev_yr.i_manufact_id - AND curr_yr.d_year=2000 - AND prev_yr.d_year=2000-1 - AND CAST(curr_yr.sales_cnt AS DECIMAL(17,2))/CAST(prev_yr.sales_cnt AS DECIMAL(17,2))<0.9 - ORDER BY sales_cnt_diff,sales_amt_diff - limit 100; - --- end template query75.tpl query 45 in stream 1 --- start template query11.tpl query 46 in stream 1 -with /* TPC-DS query11.tpl 0.51 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ss_ext_list_price-ss_ext_discount_amt) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ws_ext_list_price-ws_ext_discount_amt) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_preferred_cust_flag - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 2001 - and t_s_secyear.dyear = 2001+1 - and t_w_firstyear.dyear = 2001 - and t_w_secyear.dyear = 2001+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else 0.0 end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else 0.0 end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_preferred_cust_flag -limit 100; - --- end template query11.tpl query 46 in stream 1 --- start template query67a.tpl query 47 in stream 1 -with /* TPC-DS query67a.tpl 0.35 */ results as -( select i_category ,i_class ,i_brand ,i_product_name ,d_year ,d_qoy ,d_moy ,s_store_id - ,sum(coalesce(ss_sales_price*ss_quantity,0)) sumsales - from store_sales ,date_dim ,store ,item - where ss_sold_date_sk=d_date_sk - and ss_item_sk=i_item_sk - and ss_store_sk = s_store_sk - and d_month_seq between 1200 and 1200 + 11 - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy,s_store_id) - , - results_rollup as - (select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, s_store_id, sumsales - from results - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy - union all - select i_category, i_class, i_brand, i_product_name, d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year - union all - select i_category, i_class, i_brand, i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name - union all - select i_category, i_class, i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand - union all - select i_category, i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class - union all - select i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category - union all - select null i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results) - - select * -from (select i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rank() over (partition by i_category order by sumsales desc) rk - from results_rollup) dw2 -where rk <= 100 -order by i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rk -limit 100; - --- end template query67a.tpl query 47 in stream 1 --- start template query9.tpl query 48 in stream 1 -select /* TPC-DS query9.tpl 0.49 */ case when (select count(*) - from store_sales - where ss_quantity between 1 and 20) > 109221918 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 1 and 20) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 1 and 20) end bucket1 , - case when (select count(*) - from store_sales - where ss_quantity between 21 and 40) > 97086998 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 21 and 40) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 21 and 40) end bucket2, - case when (select count(*) - from store_sales - where ss_quantity between 41 and 60) > 91922583 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 41 and 60) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 41 and 60) end bucket3, - case when (select count(*) - from store_sales - where ss_quantity between 61 and 80) > 19390379 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 61 and 80) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 61 and 80) end bucket4, - case when (select count(*) - from store_sales - where ss_quantity between 81 and 100) > 91543850 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 81 and 100) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 81 and 100) end bucket5 -from reason -where r_reason_sk = 1 -; - --- end template query9.tpl query 48 in stream 1 --- start template query25.tpl query 49 in stream 1 -select /* TPC-DS query25.tpl 0.9 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,max(ss_net_profit) as store_sales_profit - ,max(sr_net_loss) as store_returns_loss - ,max(cs_net_profit) as catalog_sales_profit - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 1998 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 10 - and d2.d_year = 1998 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_moy between 4 and 10 - and d3.d_year = 1998 - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query25.tpl query 49 in stream 1 --- start template query37.tpl query 50 in stream 1 -select /* TPC-DS query37.tpl 0.31 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, catalog_sales - where i_current_price between 70 and 70 + 30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('2001-01-18' as date) and dateadd(day,60,cast('2001-01-18' as date)) - and i_manufact_id in (678,902,874,801) - and inv_quantity_on_hand between 100 and 500 - and cs_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query37.tpl query 50 in stream 1 --- start template query86a.tpl query 51 in stream 1 -with /* TPC-DS query86a.tpl 0.11 */ results as -( select sum(ws_net_paid) as total_sum, i_category, i_class, 0 as g_category, 0 as g_class - from - web_sales - ,date_dim d1 - ,item - where - d1.d_month_seq between 1208 and 1208+11 - and d1.d_date_sk = ws_sold_date_sk - and i_item_sk = ws_item_sk - group by i_category,i_class - ) , - - results_rollup as -( select total_sum ,i_category ,i_class, g_category, g_class, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum, i_category, NULL as i_class, 0 as g_category, 1 as g_class, 1 as lochierarchy from results group by i_category - union - select sum(total_sum) as total_sum, NULL as i_category, NULL as i_class, 1 as g_category, 1 as g_class, 2 as lochierarchy from results) - select - total_sum ,i_category ,i_class, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_class = 0 then i_category end - order by total_sum desc) as rank_within_parent - from - results_rollup - order by - lochierarchy desc, - case when lochierarchy = 0 then i_category end, - rank_within_parent - limit 100; - --- end template query86a.tpl query 51 in stream 1 --- start template query4.tpl query 52 in stream 1 -with /* TPC-DS query4.tpl 0.93 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(((ss_ext_list_price-ss_ext_wholesale_cost-ss_ext_discount_amt)+ss_ext_sales_price)/2) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((cs_ext_list_price-cs_ext_wholesale_cost-cs_ext_discount_amt)+cs_ext_sales_price)/2) ) year_total - ,'c' sale_type - from customer - ,catalog_sales - ,date_dim - where c_customer_sk = cs_bill_customer_sk - and cs_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year -union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((ws_ext_list_price-ws_ext_wholesale_cost-ws_ext_discount_amt)+ws_ext_sales_price)/2) ) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_preferred_cust_flag - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_c_firstyear - ,year_total t_c_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_c_secyear.customer_id - and t_s_firstyear.customer_id = t_c_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_c_firstyear.sale_type = 'c' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_c_secyear.sale_type = 'c' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 2001 - and t_s_secyear.dyear = 2001+1 - and t_c_firstyear.dyear = 2001 - and t_c_secyear.dyear = 2001+1 - and t_w_firstyear.dyear = 2001 - and t_w_secyear.dyear = 2001+1 - and t_s_firstyear.year_total > 0 - and t_c_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_preferred_cust_flag -limit 100; - --- end template query4.tpl query 52 in stream 1 --- start template query60.tpl query 53 in stream 1 -with /* TPC-DS query60.tpl 0.29 */ ss as ( - select - i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Shoes')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 10 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id), - cs as ( - select - i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Shoes')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 10 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id), - ws as ( - select - i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Shoes')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 10 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id) - select - i_item_id -,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by i_item_id - ,total_sales - limit 100; - --- end template query60.tpl query 53 in stream 1 --- start template query97.tpl query 54 in stream 1 -with /* TPC-DS query97.tpl 0.38 */ ssci as ( -select ss_customer_sk customer_sk - ,ss_item_sk item_sk -from store_sales,date_dim -where ss_sold_date_sk = d_date_sk - and d_month_seq between 1201 and 1201 + 11 -group by ss_customer_sk - ,ss_item_sk), -csci as( - select cs_bill_customer_sk customer_sk - ,cs_item_sk item_sk -from catalog_sales,date_dim -where cs_sold_date_sk = d_date_sk - and d_month_seq between 1201 and 1201 + 11 -group by cs_bill_customer_sk - ,cs_item_sk) - select sum(case when ssci.customer_sk is not null and csci.customer_sk is null then 1 else 0 end) store_only - ,sum(case when ssci.customer_sk is null and csci.customer_sk is not null then 1 else 0 end) catalog_only - ,sum(case when ssci.customer_sk is not null and csci.customer_sk is not null then 1 else 0 end) store_and_catalog -from ssci full outer join csci on (ssci.customer_sk=csci.customer_sk - and ssci.item_sk = csci.item_sk) -limit 100; - --- end template query97.tpl query 54 in stream 1 --- start template query33.tpl query 55 in stream 1 -with /* TPC-DS query33.tpl 0.22 */ ss as ( - select - i_manufact_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Electronics')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 2 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id), - cs as ( - select - i_manufact_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Electronics')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 2 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id), - ws as ( - select - i_manufact_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Electronics')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 2 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id) - select i_manufact_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_manufact_id - order by total_sales -limit 100; - --- end template query33.tpl query 55 in stream 1 --- start template query79.tpl query 56 in stream 1 -select /* TPC-DS query79.tpl 0.89 */ - c_last_name,c_first_name,substring(s_city,1,30),ss_ticket_number,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,store.s_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (household_demographics.hd_dep_count = 4 or household_demographics.hd_vehicle_count > 1) - and date_dim.d_dow = 1 - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_number_employees between 200 and 295 - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,store.s_city) ms,customer - where ss_customer_sk = c_customer_sk - order by c_last_name,c_first_name,substring(s_city,1,30), profit -limit 100; - --- end template query79.tpl query 56 in stream 1 --- start template query43.tpl query 57 in stream 1 -select /* TPC-DS query43.tpl 0.15 */ s_store_name, s_store_id, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from date_dim, store_sales, store - where d_date_sk = ss_sold_date_sk and - s_store_sk = ss_store_sk and - s_gmt_offset = -5 and - d_year = 2002 - group by s_store_name, s_store_id - order by s_store_name, s_store_id,sun_sales,mon_sales,tue_sales,wed_sales,thu_sales,fri_sales,sat_sales - limit 100; - --- end template query43.tpl query 57 in stream 1 --- start template query80a.tpl query 58 in stream 1 -with /* TPC-DS query80a.tpl 0.6 */ ssr as - (select s_store_id as store_id, - sum(ss_ext_sales_price) as sales, - sum(coalesce(sr_return_amt, 0)) as returns, - sum(ss_net_profit - coalesce(sr_net_loss, 0)) as profit - from store_sales left outer join store_returns on - (ss_item_sk = sr_item_sk and ss_ticket_number = sr_ticket_number), - date_dim, - store, - item, - promotion - where ss_sold_date_sk = d_date_sk - and d_date between cast('1998-08-23' as date) - and dateadd(day,30,cast('1998-08-23' as date)) - and ss_store_sk = s_store_sk - and ss_item_sk = i_item_sk - and i_current_price > 50 - and ss_promo_sk = p_promo_sk - and p_channel_tv = 'N' - group by s_store_id) - , - csr as - (select cp_catalog_page_id as catalog_page_id, - sum(cs_ext_sales_price) as sales, - sum(coalesce(cr_return_amount, 0)) as returns, - sum(cs_net_profit - coalesce(cr_net_loss, 0)) as profit - from catalog_sales left outer join catalog_returns on - (cs_item_sk = cr_item_sk and cs_order_number = cr_order_number), - date_dim, - catalog_page, - item, - promotion - where cs_sold_date_sk = d_date_sk - and d_date between cast('1998-08-23' as date) - and dateadd(day,30,cast('1998-08-23' as date)) - and cs_catalog_page_sk = cp_catalog_page_sk - and cs_item_sk = i_item_sk - and i_current_price > 50 - and cs_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(ws_ext_sales_price) as sales, - sum(coalesce(wr_return_amt, 0)) as returns, - sum(ws_net_profit - coalesce(wr_net_loss, 0)) as profit - from web_sales left outer join web_returns on - (ws_item_sk = wr_item_sk and ws_order_number = wr_order_number), - date_dim, - web_site, - item, - promotion - where ws_sold_date_sk = d_date_sk - and d_date between cast('1998-08-23' as date) - and dateadd(day,30,cast('1998-08-23' as date)) - and ws_web_site_sk = web_site_sk - and ws_item_sk = i_item_sk - and i_current_price > 50 - and ws_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by web_site_id) -, -results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || store_id as id - , sales - , returns - , profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || catalog_page_id as id - , sales - , returns - , profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , profit - from wsr - ) x - group by channel, id) - - select channel - , id - , sales - , returns - , profit - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results - ) foo - order by channel, id - limit 100; - --- end template query80a.tpl query 58 in stream 1 --- start template query93.tpl query 59 in stream 1 -select /* TPC-DS query93.tpl 0.52 */ ss_customer_sk - ,sum(act_sales) sumsales - from (select ss_item_sk - ,ss_ticket_number - ,ss_customer_sk - ,case when sr_return_quantity is not null then (ss_quantity-sr_return_quantity)*ss_sales_price - else (ss_quantity*ss_sales_price) end act_sales - from store_sales left outer join store_returns on (sr_item_sk = ss_item_sk - and sr_ticket_number = ss_ticket_number) - ,reason - where sr_reason_sk = r_reason_sk - and r_reason_desc = 'reason 47') t - group by ss_customer_sk - order by sumsales, ss_customer_sk -limit 100; - --- end template query93.tpl query 59 in stream 1 --- start template query31.tpl query 60 in stream 1 -with /* TPC-DS query31.tpl 0.50 */ ss as - (select ca_county,d_qoy, d_year,sum(ss_ext_sales_price) as store_sales - from store_sales,date_dim,customer_address - where ss_sold_date_sk = d_date_sk - and ss_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year), - ws as - (select ca_county,d_qoy, d_year,sum(ws_ext_sales_price) as web_sales - from web_sales,date_dim,customer_address - where ws_sold_date_sk = d_date_sk - and ws_bill_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year) - select - ss1.ca_county - ,ss1.d_year - ,ws2.web_sales/ws1.web_sales web_q1_q2_increase - ,ss2.store_sales/ss1.store_sales store_q1_q2_increase - ,ws3.web_sales/ws2.web_sales web_q2_q3_increase - ,ss3.store_sales/ss2.store_sales store_q2_q3_increase - from - ss ss1 - ,ss ss2 - ,ss ss3 - ,ws ws1 - ,ws ws2 - ,ws ws3 - where - ss1.d_qoy = 1 - and ss1.d_year = 2000 - and ss1.ca_county = ss2.ca_county - and ss2.d_qoy = 2 - and ss2.d_year = 2000 - and ss2.ca_county = ss3.ca_county - and ss3.d_qoy = 3 - and ss3.d_year = 2000 - and ss1.ca_county = ws1.ca_county - and ws1.d_qoy = 1 - and ws1.d_year = 2000 - and ws1.ca_county = ws2.ca_county - and ws2.d_qoy = 2 - and ws2.d_year = 2000 - and ws1.ca_county = ws3.ca_county - and ws3.d_qoy = 3 - and ws3.d_year =2000 - and case when ws1.web_sales > 0 then ws2.web_sales/ws1.web_sales else null end - > case when ss1.store_sales > 0 then ss2.store_sales/ss1.store_sales else null end - and case when ws2.web_sales > 0 then ws3.web_sales/ws2.web_sales else null end - > case when ss2.store_sales > 0 then ss3.store_sales/ss2.store_sales else null end - order by web_q1_q2_increase; - --- end template query31.tpl query 60 in stream 1 --- start template query47.tpl query 61 in stream 1 -with /* TPC-DS query47.tpl 0.42 */ v1 as( - select i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, - s_store_name, s_company_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - s_store_name, s_company_name - order by d_year, d_moy) rn - from item, store_sales, date_dim, store - where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - ( - d_year = 1999 or - ( d_year = 1999-1 and d_moy =12) or - ( d_year = 1999+1 and d_moy =1) - ) - group by i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy), - v2 as( - select v1.i_category, v1.i_brand - ,v1.d_year - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1.s_store_name = v1_lag.s_store_name and - v1.s_store_name = v1_lead.s_store_name and - v1.s_company_name = v1_lag.s_company_name and - v1.s_company_name = v1_lead.s_company_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 1999 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, sum_sales - limit 100; - --- end template query47.tpl query 61 in stream 1 --- start template query17.tpl query 62 in stream 1 -select /* TPC-DS query17.tpl 0.41 */ i_item_id - ,i_item_desc - ,s_state - ,count(ss_quantity) as store_sales_quantitycount - ,avg(ss_quantity) as store_sales_quantityave - ,stddev_samp(ss_quantity) as store_sales_quantitystdev - ,stddev_samp(ss_quantity)/avg(ss_quantity) as store_sales_quantitycov - ,count(sr_return_quantity) as store_returns_quantitycount - ,avg(sr_return_quantity) as store_returns_quantityave - ,stddev_samp(sr_return_quantity) as store_returns_quantitystdev - ,stddev_samp(sr_return_quantity)/avg(sr_return_quantity) as store_returns_quantitycov - ,count(cs_quantity) as catalog_sales_quantitycount ,avg(cs_quantity) as catalog_sales_quantityave - ,stddev_samp(cs_quantity) as catalog_sales_quantitystdev - ,stddev_samp(cs_quantity)/avg(cs_quantity) as catalog_sales_quantitycov - from store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where d1.d_quarter_name = '1999Q1' - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_quarter_name in ('1999Q1','1999Q2','1999Q3') - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_quarter_name in ('1999Q1','1999Q2','1999Q3') - group by i_item_id - ,i_item_desc - ,s_state - order by i_item_id - ,i_item_desc - ,s_state -limit 100; - --- end template query17.tpl query 62 in stream 1 --- start template query19.tpl query 63 in stream 1 -select /* TPC-DS query19.tpl 0.8 */ i_brand_id brand_id, i_brand brand, i_manufact_id, i_manufact, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item,customer,customer_address,store - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=1 - and d_moy=12 - and d_year=1999 - and ss_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and substring(ca_zip,1,5) <> substring(s_zip,1,5) - and ss_store_sk = s_store_sk - group by i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact - order by ext_price desc - ,i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact -limit 100 ; - --- end template query19.tpl query 63 in stream 1 --- start template query1.tpl query 64 in stream 1 -with /* TPC-DS query1.tpl 0.12 */ customer_total_return as -(select sr_customer_sk as ctr_customer_sk -,sr_store_sk as ctr_store_sk -,sum(SR_RETURN_AMT_INC_TAX) as ctr_total_return -from store_returns -,date_dim -where sr_returned_date_sk = d_date_sk -and d_year =1998 -group by sr_customer_sk -,sr_store_sk) - select c_customer_id -from customer_total_return ctr1 -,store -,customer -where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 -from customer_total_return ctr2 -where ctr1.ctr_store_sk = ctr2.ctr_store_sk) -and s_store_sk = ctr1.ctr_store_sk -and s_state = 'OK' -and ctr1.ctr_customer_sk = c_customer_sk -order by c_customer_id -limit 100; - --- end template query1.tpl query 64 in stream 1 --- start template query64.tpl query 65 in stream 1 -with /* TPC-DS query64.tpl 0.20 */ cs_ui as - (select cs_item_sk - ,sum(cs_ext_list_price) as sale,sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit) as refund - from catalog_sales - ,catalog_returns - where cs_item_sk = cr_item_sk - and cs_order_number = cr_order_number - group by cs_item_sk - having sum(cs_ext_list_price)>2*sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit)), -cross_sales as - (select i_product_name product_name - ,i_item_sk item_sk - ,s_store_name store_name - ,s_zip store_zip - ,ad1.ca_street_number b_street_number - ,ad1.ca_street_name b_street_name - ,ad1.ca_city b_city - ,ad1.ca_zip b_zip - ,ad2.ca_street_number c_street_number - ,ad2.ca_street_name c_street_name - ,ad2.ca_city c_city - ,ad2.ca_zip c_zip - ,d1.d_year as syear - ,d2.d_year as fsyear - ,d3.d_year s2year - ,count(*) cnt - ,sum(ss_wholesale_cost) s1 - ,sum(ss_list_price) s2 - ,sum(ss_coupon_amt) s3 - FROM store_sales - ,store_returns - ,cs_ui - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,customer - ,customer_demographics cd1 - ,customer_demographics cd2 - ,promotion - ,household_demographics hd1 - ,household_demographics hd2 - ,customer_address ad1 - ,customer_address ad2 - ,income_band ib1 - ,income_band ib2 - ,item - WHERE ss_store_sk = s_store_sk AND - ss_sold_date_sk = d1.d_date_sk AND - ss_customer_sk = c_customer_sk AND - ss_cdemo_sk= cd1.cd_demo_sk AND - ss_hdemo_sk = hd1.hd_demo_sk AND - ss_addr_sk = ad1.ca_address_sk and - ss_item_sk = i_item_sk and - ss_item_sk = sr_item_sk and - ss_ticket_number = sr_ticket_number and - ss_item_sk = cs_ui.cs_item_sk and - c_current_cdemo_sk = cd2.cd_demo_sk AND - c_current_hdemo_sk = hd2.hd_demo_sk AND - c_current_addr_sk = ad2.ca_address_sk and - c_first_sales_date_sk = d2.d_date_sk and - c_first_shipto_date_sk = d3.d_date_sk and - ss_promo_sk = p_promo_sk and - hd1.hd_income_band_sk = ib1.ib_income_band_sk and - hd2.hd_income_band_sk = ib2.ib_income_band_sk and - cd1.cd_marital_status <> cd2.cd_marital_status and - i_color in ('snow','midnight','azure','antique','ghost','slate') and - i_current_price between 47 and 47 + 10 and - i_current_price between 47 + 1 and 47 + 15 -group by i_product_name - ,i_item_sk - ,s_store_name - ,s_zip - ,ad1.ca_street_number - ,ad1.ca_street_name - ,ad1.ca_city - ,ad1.ca_zip - ,ad2.ca_street_number - ,ad2.ca_street_name - ,ad2.ca_city - ,ad2.ca_zip - ,d1.d_year - ,d2.d_year - ,d3.d_year -) -select cs1.product_name - ,cs1.store_name - ,cs1.store_zip - ,cs1.b_street_number - ,cs1.b_street_name - ,cs1.b_city - ,cs1.b_zip - ,cs1.c_street_number - ,cs1.c_street_name - ,cs1.c_city - ,cs1.c_zip - ,cs1.syear - ,cs1.cnt - ,cs1.s1 as s11 - ,cs1.s2 as s21 - ,cs1.s3 as s31 - ,cs2.s1 as s12 - ,cs2.s2 as s22 - ,cs2.s3 as s32 - ,cs2.syear - ,cs2.cnt -from cross_sales cs1,cross_sales cs2 -where cs1.item_sk=cs2.item_sk and - cs1.syear = 2001 and - cs2.syear = 2001 + 1 and - cs2.cnt <= cs1.cnt and - cs1.store_name = cs2.store_name and - cs1.store_zip = cs2.store_zip -order by cs1.product_name - ,cs1.store_name - ,cs2.cnt - ,cs1.s1 - ,cs2.s1; - --- end template query64.tpl query 65 in stream 1 --- start template query53.tpl query 66 in stream 1 -select /* TPC-DS query53.tpl 0.88 */ * from -(select i_manufact_id, -sum(ss_sales_price) sum_sales, -avg(sum(ss_sales_price)) over (partition by i_manufact_id) avg_quarterly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and -ss_sold_date_sk = d_date_sk and -ss_store_sk = s_store_sk and -d_month_seq in (1177,1177+1,1177+2,1177+3,1177+4,1177+5,1177+6,1177+7,1177+8,1177+9,1177+10,1177+11) and -((i_category in ('Books','Children','Electronics') and -i_class in ('personal','portable','reference','self-help') and -i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) -or(i_category in ('Women','Music','Men') and -i_class in ('accessories','classical','fragrances','pants') and -i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manufact_id, d_qoy ) tmp1 -where case when avg_quarterly_sales > 0 - then abs (sum_sales - avg_quarterly_sales)/ avg_quarterly_sales - else null end > 0.1 -order by avg_quarterly_sales, - sum_sales, - i_manufact_id -limit 100; - --- end template query53.tpl query 66 in stream 1 --- start template query55.tpl query 67 in stream 1 -select /* TPC-DS query55.tpl 0.82 */ i_brand_id brand_id, i_brand brand, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=57 - and d_moy=12 - and d_year=1999 - group by i_brand, i_brand_id - order by ext_price desc, i_brand_id -limit 100 ; - --- end template query55.tpl query 67 in stream 1 --- start template query46.tpl query 68 in stream 1 -select /* TPC-DS query46.tpl 0.23 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and (household_demographics.hd_dep_count = 6 or - household_demographics.hd_vehicle_count= 2) - and date_dim.d_dow in (6,0) - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_city in ('Oak Grove','Brownsville','Greenwood','Harmony','Newtown') - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,ca_city) dn,customer,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - limit 100; - --- end template query46.tpl query 68 in stream 1 --- start template query21.tpl query 69 in stream 1 -select /* TPC-DS query21.tpl 0.14 */ * - from(select w_warehouse_name - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('1999-05-21' as date)) - then inv_quantity_on_hand - else 0 end) as inv_before - ,sum(case when (cast(d_date as date) >= cast ('1999-05-21' as date)) - then inv_quantity_on_hand - else 0 end) as inv_after - from inventory - ,warehouse - ,item - ,date_dim - where i_current_price between 0.99 and 1.49 - and i_item_sk = inv_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('1999-05-21' as date)) - and dateadd(day,30,cast ('1999-05-21' as date)) - group by w_warehouse_name, i_item_id) x - where (case when inv_before > 0 - then inv_after / inv_before - else null - end) between 2.0/3.0 and 3.0/2.0 - order by w_warehouse_name - ,i_item_id - limit 100; - --- end template query21.tpl query 69 in stream 1 --- start template query15.tpl query 70 in stream 1 -select /* TPC-DS query15.tpl 0.57 */ ca_zip - ,sum(cs_sales_price) - from catalog_sales - ,customer - ,customer_address - ,date_dim - where cs_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', - '85392', '85460', '80348', '81792') - or ca_state in ('CA','WA','GA') - or cs_sales_price > 500) - and cs_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 2002 - group by ca_zip - order by ca_zip - limit 100; - --- end template query15.tpl query 70 in stream 1 --- start template query20.tpl query 71 in stream 1 -select /* TPC-DS query20.tpl 0.65 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(cs_ext_sales_price) as itemrevenue - ,sum(cs_ext_sales_price)*100/sum(sum(cs_ext_sales_price)) over - (partition by i_class) as revenueratio - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and i_category in ('Jewelry', 'Women', 'Men') - and cs_sold_date_sk = d_date_sk - and d_date between cast('1999-02-23' as date) - and dateadd(day,30,cast('1999-02-23' as date)) - group by i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - order by i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query20.tpl query 71 in stream 1 --- start template query65.tpl query 72 in stream 1 -select /* TPC-DS query65.tpl 0.71 */ - s_store_name, - i_item_desc, - sc.revenue, - i_current_price, - i_wholesale_cost, - i_brand - from store, item, - (select ss_store_sk, avg(revenue) as ave - from - (select ss_store_sk, ss_item_sk, - sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1214 and 1214+11 - group by ss_store_sk, ss_item_sk) sa - group by ss_store_sk) sb, - (select ss_store_sk, ss_item_sk, sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1214 and 1214+11 - group by ss_store_sk, ss_item_sk) sc - where sb.ss_store_sk = sc.ss_store_sk and - sc.revenue <= 0.1 * sb.ave and - s_store_sk = sc.ss_store_sk and - i_item_sk = sc.ss_item_sk - order by s_store_name, i_item_desc -limit 100; - --- end template query65.tpl query 72 in stream 1 --- start template query70a.tpl query 73 in stream 1 -with /* TPC-DS query70a.tpl 0.34 */ results as -( select - sum(ss_net_profit) as total_sum ,s_state ,s_county, 0 as gstate, 0 as g_county - from - store_sales - ,date_dim d1 - ,store - where - d1.d_month_seq between 1214 and 1214 + 11 - and d1.d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - and s_state in - ( select s_state - from (select s_state as s_state, - rank() over ( partition by s_state order by sum(ss_net_profit) desc) as ranking - from store_sales, store, date_dim - where d_month_seq between 1214 and 1214 + 11 - and d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - group by s_state - ) tmp1 - where ranking <= 5) - group by s_state,s_county) , - results_rollup as -(select total_sum ,s_state ,s_county, 0 as g_state, 0 as g_county, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum,s_state, NULL as s_county, 0 as g_state, 1 as g_county, 1 as lochierarchy from results group by s_state - union - select sum(total_sum) as total_sum ,NULL as s_state ,NULL as s_county, 1 as g_state, 1 as g_county, 2 as lochierarchy from results) - select total_sum ,s_state ,s_county, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_county = 0 then s_state end - order by total_sum desc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then s_state end - ,rank_within_parent - limit 100; - --- end template query70a.tpl query 73 in stream 1 --- start template query49.tpl query 74 in stream 1 -select /* TPC-DS query49.tpl 0.48 */ channel, item, return_ratio, return_rank, currency_rank from - (select - 'web' as channel - ,web.item - ,web.return_ratio - ,web.return_rank - ,web.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select ws.ws_item_sk as item - ,(cast(sum(coalesce(wr.wr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(wr.wr_return_amt,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - web_sales ws left outer join web_returns wr - on (ws.ws_order_number = wr.wr_order_number and - ws.ws_item_sk = wr.wr_item_sk) - ,date_dim - where - wr.wr_return_amt > 10000 - and ws.ws_net_profit > 1 - and ws.ws_net_paid > 0 - and ws.ws_quantity > 0 - and ws_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 12 - group by ws.ws_item_sk - ) in_web - ) web - where - ( - web.return_rank <= 10 - or - web.currency_rank <= 10 - ) - union - select - 'catalog' as channel - ,catalog.item - ,catalog.return_ratio - ,catalog.return_rank - ,catalog.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select - cs.cs_item_sk as item - ,(cast(sum(coalesce(cr.cr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(cr.cr_return_amount,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - catalog_sales cs left outer join catalog_returns cr - on (cs.cs_order_number = cr.cr_order_number and - cs.cs_item_sk = cr.cr_item_sk) - ,date_dim - where - cr.cr_return_amount > 10000 - and cs.cs_net_profit > 1 - and cs.cs_net_paid > 0 - and cs.cs_quantity > 0 - and cs_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 12 - group by cs.cs_item_sk - ) in_cat - ) catalog - where - ( - catalog.return_rank <= 10 - or - catalog.currency_rank <=10 - ) - union - select - 'store' as channel - ,store.item - ,store.return_ratio - ,store.return_rank - ,store.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select sts.ss_item_sk as item - ,(cast(sum(coalesce(sr.sr_return_quantity,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(sr.sr_return_amt,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - store_sales sts left outer join store_returns sr - on (sts.ss_ticket_number = sr.sr_ticket_number and sts.ss_item_sk = sr.sr_item_sk) - ,date_dim - where - sr.sr_return_amt > 10000 - and sts.ss_net_profit > 1 - and sts.ss_net_paid > 0 - and sts.ss_quantity > 0 - and ss_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 12 - group by sts.ss_item_sk - ) in_store - ) store - where ( - store.return_rank <= 10 - or - store.currency_rank <= 10 - ) - ) - order by 1,4,5,2 - limit 100; - --- end template query49.tpl query 74 in stream 1 --- start template query59.tpl query 75 in stream 1 -with /* TPC-DS query59.tpl 0.30 */ wss as - (select d_week_seq, - ss_store_sk, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - group by d_week_seq,ss_store_sk - ) - select s_store_name1,s_store_id1,d_week_seq1 - ,sun_sales1/sun_sales2,mon_sales1/mon_sales2 - ,tue_sales1/tue_sales2,wed_sales1/wed_sales2,thu_sales1/thu_sales2 - ,fri_sales1/fri_sales2,sat_sales1/sat_sales2 - from - (select s_store_name s_store_name1,wss.d_week_seq d_week_seq1 - ,s_store_id s_store_id1,sun_sales sun_sales1 - ,mon_sales mon_sales1,tue_sales tue_sales1 - ,wed_sales wed_sales1,thu_sales thu_sales1 - ,fri_sales fri_sales1,sat_sales sat_sales1 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1212 and 1212 + 11) y, - (select s_store_name s_store_name2,wss.d_week_seq d_week_seq2 - ,s_store_id s_store_id2,sun_sales sun_sales2 - ,mon_sales mon_sales2,tue_sales tue_sales2 - ,wed_sales wed_sales2,thu_sales thu_sales2 - ,fri_sales fri_sales2,sat_sales sat_sales2 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1212+ 12 and 1212 + 23) x - where s_store_id1=s_store_id2 - and d_week_seq1=d_week_seq2-52 - order by s_store_name1,s_store_id1,d_week_seq1 -limit 100; - --- end template query59.tpl query 75 in stream 1 --- start template query48.tpl query 76 in stream 1 -select /* TPC-DS query48.tpl 0.74 */ sum (ss_quantity) - from store_sales, store, customer_demographics, customer_address, date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2001 - and - ( - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'D' - and - cd_education_status = 'Unknown' - and - ss_sales_price between 100.00 and 150.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'S' - and - cd_education_status = 'Advanced Degree' - and - ss_sales_price between 50.00 and 100.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'U' - and - cd_education_status = '4 yr Degree' - and - ss_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('TN', 'CA', 'MS') - and ss_net_profit between 0 and 2000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('AR', 'TX', 'MO') - and ss_net_profit between 150 and 3000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('NJ', 'NM', 'OH') - and ss_net_profit between 50 and 25000 - ) - ) -; - --- end template query48.tpl query 76 in stream 1 --- start template query72.tpl query 77 in stream 1 -select /* TPC-DS query72.tpl 0.87 */ i_item_desc - ,w_warehouse_name - ,d1.d_week_seq - ,sum(case when p_promo_sk is null then 1 else 0 end) no_promo - ,sum(case when p_promo_sk is not null then 1 else 0 end) promo - ,count(*) total_cnt -from catalog_sales -join inventory on (cs_item_sk = inv_item_sk) -join warehouse on (w_warehouse_sk=inv_warehouse_sk) -join item on (i_item_sk = cs_item_sk) -join customer_demographics on (cs_bill_cdemo_sk = cd_demo_sk) -join household_demographics on (cs_bill_hdemo_sk = hd_demo_sk) -join date_dim d1 on (cs_sold_date_sk = d1.d_date_sk) -join date_dim d2 on (inv_date_sk = d2.d_date_sk) -join date_dim d3 on (cs_ship_date_sk = d3.d_date_sk) -left outer join promotion on (cs_promo_sk=p_promo_sk) -left outer join catalog_returns on (cr_item_sk = cs_item_sk and cr_order_number = cs_order_number) -where d1.d_week_seq = d2.d_week_seq - and inv_quantity_on_hand < cs_quantity - and d3.d_date > d1.d_date + 5 - and hd_buy_potential = '1001-5000' - and d1.d_year = 2000 - and cd_marital_status = 'M' -group by i_item_desc,w_warehouse_name,d1.d_week_seq -order by total_cnt desc, i_item_desc, w_warehouse_name, d_week_seq -limit 100; - --- end template query72.tpl query 77 in stream 1 --- start template query87.tpl query 78 in stream 1 -select /* TPC-DS query87.tpl 0.77 */ count(*) -from ((select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1189 and 1189+11) - except - (select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1189 and 1189+11) - except - (select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1189 and 1189+11) -) cool_cust -; - --- end template query87.tpl query 78 in stream 1 --- start template query34.tpl query 79 in stream 1 -select /* TPC-DS query34.tpl 0.73 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (date_dim.d_dom between 1 and 3 or date_dim.d_dom between 25 and 28) - and (household_demographics.hd_buy_potential = '501-1000' or - household_demographics.hd_buy_potential = 'Unknown') - and household_demographics.hd_vehicle_count > 0 - and (case when household_demographics.hd_vehicle_count > 0 - then household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count - else null - end) > 1.2 - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_county in ('Sumner County','Gage County','Bronx County','Essex County', - 'Arthur County','Mobile County','Oglethorpe County','Maverick County') - group by ss_ticket_number,ss_customer_sk) dn,customer - where ss_customer_sk = c_customer_sk - and cnt between 15 and 20 - order by c_last_name,c_first_name,c_salutation,c_preferred_cust_flag desc, ss_ticket_number; - --- end template query34.tpl query 79 in stream 1 --- start template query2.tpl query 80 in stream 1 -with /* TPC-DS query2.tpl 0.84 */ wscs as - (select sold_date_sk - ,sales_price - from (select ws_sold_date_sk sold_date_sk - ,ws_ext_sales_price sales_price - from web_sales - union all - select cs_sold_date_sk sold_date_sk - ,cs_ext_sales_price sales_price - from catalog_sales)), - wswscs as - (select d_week_seq, - sum(case when (d_day_name='Sunday') then sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then sales_price else null end) sat_sales - from wscs - ,date_dim - where d_date_sk = sold_date_sk - group by d_week_seq) - select d_week_seq1 - ,round(sun_sales1/sun_sales2,2) - ,round(mon_sales1/mon_sales2,2) - ,round(tue_sales1/tue_sales2,2) - ,round(wed_sales1/wed_sales2,2) - ,round(thu_sales1/thu_sales2,2) - ,round(fri_sales1/fri_sales2,2) - ,round(sat_sales1/sat_sales2,2) - from - (select wswscs.d_week_seq d_week_seq1 - ,sun_sales sun_sales1 - ,mon_sales mon_sales1 - ,tue_sales tue_sales1 - ,wed_sales wed_sales1 - ,thu_sales thu_sales1 - ,fri_sales fri_sales1 - ,sat_sales sat_sales1 - from wswscs,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 2001) y, - (select wswscs.d_week_seq d_week_seq2 - ,sun_sales sun_sales2 - ,mon_sales mon_sales2 - ,tue_sales tue_sales2 - ,wed_sales wed_sales2 - ,thu_sales thu_sales2 - ,fri_sales fri_sales2 - ,sat_sales sat_sales2 - from wswscs - ,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 2001+1) z - where d_week_seq1=d_week_seq2-53 - order by d_week_seq1; - --- end template query2.tpl query 80 in stream 1 --- start template query38.tpl query 81 in stream 1 -select /* TPC-DS query38.tpl 0.54 */ count(*) from ( - select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1207 and 1207 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1207 and 1207 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1207 and 1207 + 11 -) hot_cust -limit 100; - --- end template query38.tpl query 81 in stream 1 --- start template query22a.tpl query 82 in stream 1 -with /* TPC-DS query22a.tpl 0.55 */ results as -(select i_product_name - ,i_brand - ,i_class - ,i_category - ,avg(inv_quantity_on_hand) qoh - from inventory - ,date_dim - ,item --- ,warehouse - where inv_date_sk=d_date_sk - and inv_item_sk=i_item_sk --- and inv_warehouse_sk = w_warehouse_sk - and d_month_seq between 1188 and 1188 + 11 - group by i_product_name,i_brand,i_class,i_category), -results_rollup as -(select i_product_name, i_brand, i_class, i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class,i_category -union all -select i_product_name, i_brand, i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class -union all -select i_product_name, i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand -union all -select i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name -union all -select null i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results) - select i_product_name, i_brand, i_class, i_category,qoh - from results_rollup - order by qoh, i_product_name, i_brand, i_class, i_category -limit 100; - --- end template query22a.tpl query 82 in stream 1 --- start template query89.tpl query 83 in stream 1 -select /* TPC-DS query89.tpl 0.56 */ * -from( -select i_category, i_class, i_brand, - s_store_name, s_company_name, - d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, s_store_name, s_company_name) - avg_monthly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - d_year in (1998) and - ((i_category in ('Men','Electronics','Music') and - i_class in ('sports-apparel','musical','country') - ) - or (i_category in ('Sports','Children','Books') and - i_class in ('baseball','toddlers','science') - )) -group by i_category, i_class, i_brand, - s_store_name, s_company_name, d_moy) tmp1 -where case when (avg_monthly_sales <> 0) then (abs(sum_sales - avg_monthly_sales) / avg_monthly_sales) else null end > 0.1 -order by sum_sales - avg_monthly_sales, s_store_name -limit 100; - --- end template query89.tpl query 83 in stream 1 --- start template query7.tpl query 84 in stream 1 -select /* TPC-DS query7.tpl 0.2 */ i_item_id, - avg(ss_quantity) agg1, - avg(ss_list_price) agg2, - avg(ss_coupon_amt) agg3, - avg(ss_sales_price) agg4 - from store_sales, customer_demographics, date_dim, item, promotion - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_cdemo_sk = cd_demo_sk and - ss_promo_sk = p_promo_sk and - cd_gender = 'M' and - cd_marital_status = 'S' and - cd_education_status = 'Primary' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 2002 - group by i_item_id - order by i_item_id - limit 100; - --- end template query7.tpl query 84 in stream 1 --- start template query10.tpl query 85 in stream 1 -select /* TPC-DS query10.tpl 0.26 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3, - cd_dep_count, - count(*) cnt4, - cd_dep_employed_count, - count(*) cnt5, - cd_dep_college_count, - count(*) cnt6 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_county in ('Lincoln County','Spotsylvania County','Dunklin County','Jones County','Gosper County') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 1999 and - d_moy between 4 and 4+3) and - (exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 1999 and - d_moy between 4 ANd 4+3) or - exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 1999 and - d_moy between 4 and 4+3)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count -limit 100; - --- end template query10.tpl query 85 in stream 1 --- start template query90.tpl query 86 in stream 1 -select /* TPC-DS query90.tpl 0.40 */ cast(amc as decimal(15,4))/cast(pmc as decimal(15,4)) am_pm_ratio - from ( select count(*) amc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 7 and 7+1 - and household_demographics.hd_dep_count = 4 - and web_page.wp_char_count between 5000 and 5200) at, - ( select count(*) pmc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 14 and 14+1 - and household_demographics.hd_dep_count = 4 - and web_page.wp_char_count between 5000 and 5200) pt - order by am_pm_ratio - limit 100; - --- end template query90.tpl query 86 in stream 1 --- start template query71.tpl query 87 in stream 1 -select /* TPC-DS query71.tpl 0.72 */ i_brand_id brand_id, i_brand brand,t_hour,t_minute, - sum(ext_price) ext_price - from item, (select ws_ext_sales_price as ext_price, - ws_sold_date_sk as sold_date_sk, - ws_item_sk as sold_item_sk, - ws_sold_time_sk as time_sk - from web_sales,date_dim - where d_date_sk = ws_sold_date_sk - and d_moy=11 - and d_year=1998 - union all - select cs_ext_sales_price as ext_price, - cs_sold_date_sk as sold_date_sk, - cs_item_sk as sold_item_sk, - cs_sold_time_sk as time_sk - from catalog_sales,date_dim - where d_date_sk = cs_sold_date_sk - and d_moy=11 - and d_year=1998 - union all - select ss_ext_sales_price as ext_price, - ss_sold_date_sk as sold_date_sk, - ss_item_sk as sold_item_sk, - ss_sold_time_sk as time_sk - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - and d_moy=11 - and d_year=1998 - ) tmp,time_dim - where - sold_item_sk = i_item_sk - and i_manager_id=1 - and time_sk = t_time_sk - and (t_meal_time = 'breakfast' or t_meal_time = 'dinner') - group by i_brand, i_brand_id,t_hour,t_minute - order by ext_price desc, i_brand_id - ; - --- end template query71.tpl query 87 in stream 1 --- start template query29.tpl query 88 in stream 1 -select /* TPC-DS query29.tpl 0.53 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,avg(ss_quantity) as store_sales_quantity - ,avg(sr_return_quantity) as store_returns_quantity - ,avg(cs_quantity) as catalog_sales_quantity - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 1998 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 4 + 3 - and d2.d_year = 1998 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_year in (1998,1998+1,1998+2) - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query29.tpl query 88 in stream 1 --- start template query73.tpl query 89 in stream 1 -select /* TPC-DS query73.tpl 0.79 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_buy_potential = '501-1000' or - household_demographics.hd_buy_potential = '0-500') - and household_demographics.hd_vehicle_count > 0 - and case when household_demographics.hd_vehicle_count > 0 then - household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count else null end > 1 - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_county in ('Essex County','Mesa County','Terry County','Sierra County') - group by ss_ticket_number,ss_customer_sk) dj,customer - where ss_customer_sk = c_customer_sk - and cnt between 1 and 5 - order by cnt desc, c_last_name asc; - --- end template query73.tpl query 89 in stream 1 --- start template query45.tpl query 90 in stream 1 -select /* TPC-DS query45.tpl 0.18 */ ca_zip, ca_state, sum(ws_sales_price) - from web_sales, customer, customer_address, date_dim, item - where ws_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ws_item_sk = i_item_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', '85392', '85460', '80348', '81792') - or - i_item_id in (select i_item_id - from item - where i_item_sk in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29) - ) - ) - and ws_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 1998 - group by ca_zip, ca_state - order by ca_zip, ca_state - limit 100; - --- end template query45.tpl query 90 in stream 1 --- start template query91.tpl query 91 in stream 1 -select /* TPC-DS query91.tpl 0.13 */ - cc_call_center_id Call_Center, - cc_name Call_Center_Name, - cc_manager Manager, - sum(cr_net_loss) Returns_Loss -from - call_center, - catalog_returns, - date_dim, - customer, - customer_address, - customer_demographics, - household_demographics -where - cr_call_center_sk = cc_call_center_sk -and cr_returned_date_sk = d_date_sk -and cr_returning_customer_sk= c_customer_sk -and cd_demo_sk = c_current_cdemo_sk -and hd_demo_sk = c_current_hdemo_sk -and ca_address_sk = c_current_addr_sk -and d_year = 1999 -and d_moy = 12 -and ( (cd_marital_status = 'M' and cd_education_status = 'Unknown') - or(cd_marital_status = 'W' and cd_education_status = 'Advanced Degree')) -and hd_buy_potential like 'Unknown%' -and ca_gmt_offset = -7 -group by cc_call_center_id,cc_name,cc_manager,cd_marital_status,cd_education_status -order by sum(cr_net_loss) desc; - --- end template query91.tpl query 91 in stream 1 --- start template query62.tpl query 92 in stream 1 -select /* TPC-DS query62.tpl 0.24 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 30) and - (ws_ship_date_sk - ws_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 60) and - (ws_ship_date_sk - ws_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 90) and - (ws_ship_date_sk - ws_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - web_sales - ,warehouse - ,ship_mode - ,web_site - ,date_dim -where - d_month_seq between 1195 and 1195 + 11 -and ws_ship_date_sk = d_date_sk -and ws_warehouse_sk = w_warehouse_sk -and ws_ship_mode_sk = sm_ship_mode_sk -and ws_web_site_sk = web_site_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -limit 100; - --- end template query62.tpl query 92 in stream 1 --- start template query44.tpl query 93 in stream 1 -select /* TPC-DS query44.tpl 0.4 */ asceding.rnk, i1.i_product_name best_performing, i2.i_product_name worst_performing -from(select * - from (select item_sk,rank() over (order by rank_col asc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 92 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 92 - and ss_customer_sk is null - group by ss_store_sk))V1)V11 - where rnk < 11) asceding, - (select * - from (select item_sk,rank() over (order by rank_col desc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 92 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 92 - and ss_customer_sk is null - group by ss_store_sk))V2)V21 - where rnk < 11) descending, -item i1, -item i2 -where asceding.rnk = descending.rnk - and i1.i_item_sk=asceding.item_sk - and i2.i_item_sk=descending.item_sk -order by asceding.rnk -limit 100; - --- end template query44.tpl query 93 in stream 1 --- start template query76.tpl query 94 in stream 1 -select /* TPC-DS query76.tpl 0.99 */ channel, col_name, d_year, d_qoy, i_category, COUNT(*) sales_cnt, SUM(ext_sales_price) sales_amt FROM ( - SELECT 'store' as channel, 'ss_promo_sk' col_name, d_year, d_qoy, i_category, ss_ext_sales_price ext_sales_price - FROM store_sales, item, date_dim - WHERE ss_promo_sk IS NULL - AND ss_sold_date_sk=d_date_sk - AND ss_item_sk=i_item_sk - UNION ALL - SELECT 'web' as channel, 'ws_warehouse_sk' col_name, d_year, d_qoy, i_category, ws_ext_sales_price ext_sales_price - FROM web_sales, item, date_dim - WHERE ws_warehouse_sk IS NULL - AND ws_sold_date_sk=d_date_sk - AND ws_item_sk=i_item_sk - UNION ALL - SELECT 'catalog' as channel, 'cs_ship_hdemo_sk' col_name, d_year, d_qoy, i_category, cs_ext_sales_price ext_sales_price - FROM catalog_sales, item, date_dim - WHERE cs_ship_hdemo_sk IS NULL - AND cs_sold_date_sk=d_date_sk - AND cs_item_sk=i_item_sk) foo -GROUP BY channel, col_name, d_year, d_qoy, i_category -ORDER BY channel, col_name, d_year, d_qoy, i_category -limit 100; - --- end template query76.tpl query 94 in stream 1 --- start template query23.tpl query 95 in stream 1 -with /* TPC-DS query23.tpl 0.68 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (1998,1998+1,1998+2,1998+3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1998,1998+1,1998+2,1998+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * -from - max_store_sales)) - select sum(sales) - from (select cs_quantity*cs_list_price sales - from catalog_sales - ,date_dim - where d_year = 1998 - and d_moy = 1 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - union all - select ws_quantity*ws_list_price sales - from web_sales - ,date_dim - where d_year = 1998 - and d_moy = 1 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer)) - limit 100; -with /* TPC-DS query23.tpl 0.68 part2 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (1998,1998 + 1,1998 + 2,1998 + 3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1998,1998+1,1998+2,1998+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * - from max_store_sales)) - select c_last_name,c_first_name,sales - from (select c_last_name,c_first_name,sum(cs_quantity*cs_list_price) sales - from catalog_sales - ,customer - ,date_dim - where d_year = 1998 - and d_moy = 1 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and cs_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name - union all - select c_last_name,c_first_name,sum(ws_quantity*ws_list_price) sales - from web_sales - ,customer - ,date_dim - where d_year = 1998 - and d_moy = 1 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and ws_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name) - order by c_last_name,c_first_name,sales - limit 100; - --- end template query23.tpl query 95 in stream 1 --- start template query56.tpl query 96 in stream 1 -with /* TPC-DS query56.tpl 0.83 */ ss as ( - select i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where i_item_id in (select - i_item_id -from item -where i_color in ('salmon','orchid','purple')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 1 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id), - cs as ( - select i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('salmon','orchid','purple')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 1 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id), - ws as ( - select i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('salmon','orchid','purple')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 1 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id) - select i_item_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by total_sales, - i_item_id - limit 100; - --- end template query56.tpl query 96 in stream 1 --- start template query42.tpl query 97 in stream 1 -select /* TPC-DS query42.tpl 0.61 */ dt.d_year - ,item.i_category_id - ,item.i_category - ,sum(ss_ext_sales_price) - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=12 - and dt.d_year=1999 - group by dt.d_year - ,item.i_category_id - ,item.i_category - order by sum(ss_ext_sales_price) desc,dt.d_year - ,item.i_category_id - ,item.i_category -limit 100 ; - --- end template query42.tpl query 97 in stream 1 --- start template query39.tpl query 98 in stream 1 -with /* TPC-DS query39.tpl 0.5 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =1999 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=1 - and inv2.d_moy=1+1 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; -with /* TPC-DS query39.tpl 0.5 part2 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =1999 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=1 - and inv2.d_moy=1+1 - and inv1.cov > 1.5 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; - --- end template query39.tpl query 98 in stream 1 --- start template query74.tpl query 99 in stream 1 -with /* TPC-DS query74.tpl 0.76 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,avg(ss_net_paid) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1999,1999+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,avg(ws_net_paid) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - and d_year in (1999,1999+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - ) - select - t_s_secyear.customer_id, t_s_secyear.customer_first_name, t_s_secyear.customer_last_name - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.year = 1999 - and t_s_secyear.year = 1999+1 - and t_w_firstyear.year = 1999 - and t_w_secyear.year = 1999+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - order by 3,1,2 -limit 100; - --- end template query74.tpl query 99 in stream 1 diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/10TB/queries/query_10.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/10TB/queries/query_10.sql deleted file mode 100644 index efda975d..00000000 --- a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/10TB/queries/query_10.sql +++ /dev/null @@ -1,5027 +0,0 @@ --- start template query43.tpl query 1 in stream 10 -select /* TPC-DS query43.tpl 0.15 */ s_store_name, s_store_id, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from date_dim, store_sales, store - where d_date_sk = ss_sold_date_sk and - s_store_sk = ss_store_sk and - s_gmt_offset = -6 and - d_year = 1998 - group by s_store_name, s_store_id - order by s_store_name, s_store_id,sun_sales,mon_sales,tue_sales,wed_sales,thu_sales,fri_sales,sat_sales - limit 100; - --- end template query43.tpl query 1 in stream 10 --- start template query50.tpl query 2 in stream 10 -select /* TPC-DS query50.tpl 0.60 */ - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 30) and - (sr_returned_date_sk - ss_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 60) and - (sr_returned_date_sk - ss_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 90) and - (sr_returned_date_sk - ss_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - store_sales - ,store_returns - ,store - ,date_dim d1 - ,date_dim d2 -where - d2.d_year = 1999 -and d2.d_moy = 9 -and ss_ticket_number = sr_ticket_number -and ss_item_sk = sr_item_sk -and ss_sold_date_sk = d1.d_date_sk -and sr_returned_date_sk = d2.d_date_sk -and ss_customer_sk = sr_customer_sk -and ss_store_sk = s_store_sk -group by - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -order by s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -limit 100; - --- end template query50.tpl query 2 in stream 10 --- start template query41.tpl query 3 in stream 10 -select /* TPC-DS query41.tpl 0.62 */ distinct(i_product_name) - from item i1 - where i_manufact_id between 964 and 964+40 - and (select count(*) as item_cnt - from item - where (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'hot' or i_color = 'chartreuse') and - (i_units = 'Bunch' or i_units = 'Case') and - (i_size = 'medium' or i_size = 'economy') - ) or - (i_category = 'Women' and - (i_color = 'honeydew' or i_color = 'dark') and - (i_units = 'Ounce' or i_units = 'Bundle') and - (i_size = 'N/A' or i_size = 'extra large') - ) or - (i_category = 'Men' and - (i_color = 'tomato' or i_color = 'snow') and - (i_units = 'Pallet' or i_units = 'Pound') and - (i_size = 'petite' or i_size = 'small') - ) or - (i_category = 'Men' and - (i_color = 'goldenrod' or i_color = 'lavender') and - (i_units = 'Lb' or i_units = 'N/A') and - (i_size = 'medium' or i_size = 'economy') - ))) or - (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'white' or i_color = 'burlywood') and - (i_units = 'Gram' or i_units = 'Gross') and - (i_size = 'medium' or i_size = 'economy') - ) or - (i_category = 'Women' and - (i_color = 'black' or i_color = 'saddle') and - (i_units = 'Oz' or i_units = 'Tbl') and - (i_size = 'N/A' or i_size = 'extra large') - ) or - (i_category = 'Men' and - (i_color = 'lawn' or i_color = 'pale') and - (i_units = 'Ton' or i_units = 'Dozen') and - (i_size = 'petite' or i_size = 'small') - ) or - (i_category = 'Men' and - (i_color = 'indian' or i_color = 'brown') and - (i_units = 'Dram' or i_units = 'Each') and - (i_size = 'medium' or i_size = 'economy') - )))) > 0 - order by i_product_name - limit 100; - --- end template query41.tpl query 3 in stream 10 --- start template query48.tpl query 4 in stream 10 -select /* TPC-DS query48.tpl 0.74 */ sum (ss_quantity) - from store_sales, store, customer_demographics, customer_address, date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 1998 - and - ( - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'D' - and - cd_education_status = 'Primary' - and - ss_sales_price between 100.00 and 150.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'U' - and - cd_education_status = 'College' - and - ss_sales_price between 50.00 and 100.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'S' - and - cd_education_status = '2 yr Degree' - and - ss_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('CO', 'TX', 'IL') - and ss_net_profit between 0 and 2000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('IN', 'MO', 'VA') - and ss_net_profit between 150 and 3000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('IA', 'AR', 'KY') - and ss_net_profit between 50 and 25000 - ) - ) -; - --- end template query48.tpl query 4 in stream 10 --- start template query54.tpl query 5 in stream 10 -with /* TPC-DS query54.tpl 0.81 */ my_customers as ( - select distinct c_customer_sk - , c_current_addr_sk - from - ( select cs_sold_date_sk sold_date_sk, - cs_bill_customer_sk customer_sk, - cs_item_sk item_sk - from catalog_sales - union all - select ws_sold_date_sk sold_date_sk, - ws_bill_customer_sk customer_sk, - ws_item_sk item_sk - from web_sales - ) cs_or_ws_sales, - item, - date_dim, - customer - where sold_date_sk = d_date_sk - and item_sk = i_item_sk - and i_category = 'Jewelry' - and i_class = 'custom' - and c_customer_sk = cs_or_ws_sales.customer_sk - and d_moy = 6 - and d_year = 2000 - ) - , my_revenue as ( - select c_customer_sk, - sum(ss_ext_sales_price) as revenue - from my_customers, - store_sales, - customer_address, - store, - date_dim - where c_current_addr_sk = ca_address_sk - and ca_county = s_county - and ca_state = s_state - and ss_sold_date_sk = d_date_sk - and c_customer_sk = ss_customer_sk - and d_month_seq between (select distinct d_month_seq+1 - from date_dim where d_year = 2000 and d_moy = 6) - and (select distinct d_month_seq+3 - from date_dim where d_year = 2000 and d_moy = 6) - group by c_customer_sk - ) - , segments as - (select cast((revenue/50) as int) as segment - from my_revenue - ) - select segment, count(*) as num_customers, segment*50 as segment_base - from segments - group by segment - order by segment, num_customers - limit 100; - --- end template query54.tpl query 5 in stream 10 --- start template query53.tpl query 6 in stream 10 -select /* TPC-DS query53.tpl 0.88 */ * from -(select i_manufact_id, -sum(ss_sales_price) sum_sales, -avg(sum(ss_sales_price)) over (partition by i_manufact_id) avg_quarterly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and -ss_sold_date_sk = d_date_sk and -ss_store_sk = s_store_sk and -d_month_seq in (1180,1180+1,1180+2,1180+3,1180+4,1180+5,1180+6,1180+7,1180+8,1180+9,1180+10,1180+11) and -((i_category in ('Books','Children','Electronics') and -i_class in ('personal','portable','reference','self-help') and -i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) -or(i_category in ('Women','Music','Men') and -i_class in ('accessories','classical','fragrances','pants') and -i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manufact_id, d_qoy ) tmp1 -where case when avg_quarterly_sales > 0 - then abs (sum_sales - avg_quarterly_sales)/ avg_quarterly_sales - else null end > 0.1 -order by avg_quarterly_sales, - sum_sales, - i_manufact_id -limit 100; - --- end template query53.tpl query 6 in stream 10 --- start template query31.tpl query 7 in stream 10 -with /* TPC-DS query31.tpl 0.50 */ ss as - (select ca_county,d_qoy, d_year,sum(ss_ext_sales_price) as store_sales - from store_sales,date_dim,customer_address - where ss_sold_date_sk = d_date_sk - and ss_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year), - ws as - (select ca_county,d_qoy, d_year,sum(ws_ext_sales_price) as web_sales - from web_sales,date_dim,customer_address - where ws_sold_date_sk = d_date_sk - and ws_bill_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year) - select - ss1.ca_county - ,ss1.d_year - ,ws2.web_sales/ws1.web_sales web_q1_q2_increase - ,ss2.store_sales/ss1.store_sales store_q1_q2_increase - ,ws3.web_sales/ws2.web_sales web_q2_q3_increase - ,ss3.store_sales/ss2.store_sales store_q2_q3_increase - from - ss ss1 - ,ss ss2 - ,ss ss3 - ,ws ws1 - ,ws ws2 - ,ws ws3 - where - ss1.d_qoy = 1 - and ss1.d_year = 1998 - and ss1.ca_county = ss2.ca_county - and ss2.d_qoy = 2 - and ss2.d_year = 1998 - and ss2.ca_county = ss3.ca_county - and ss3.d_qoy = 3 - and ss3.d_year = 1998 - and ss1.ca_county = ws1.ca_county - and ws1.d_qoy = 1 - and ws1.d_year = 1998 - and ws1.ca_county = ws2.ca_county - and ws2.d_qoy = 2 - and ws2.d_year = 1998 - and ws1.ca_county = ws3.ca_county - and ws3.d_qoy = 3 - and ws3.d_year =1998 - and case when ws1.web_sales > 0 then ws2.web_sales/ws1.web_sales else null end - > case when ss1.store_sales > 0 then ss2.store_sales/ss1.store_sales else null end - and case when ws2.web_sales > 0 then ws3.web_sales/ws2.web_sales else null end - > case when ss2.store_sales > 0 then ss3.store_sales/ss2.store_sales else null end - order by web_q2_q3_increase; - --- end template query31.tpl query 7 in stream 10 --- start template query39.tpl query 8 in stream 10 -with /* TPC-DS query39.tpl 0.5 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =2000 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=4 - and inv2.d_moy=4+1 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; -with /* TPC-DS query39.tpl 0.5 part2 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =2000 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=4 - and inv2.d_moy=4+1 - and inv1.cov > 1.5 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; - --- end template query39.tpl query 8 in stream 10 --- start template query2.tpl query 9 in stream 10 -with /* TPC-DS query2.tpl 0.84 */ wscs as - (select sold_date_sk - ,sales_price - from (select ws_sold_date_sk sold_date_sk - ,ws_ext_sales_price sales_price - from web_sales - union all - select cs_sold_date_sk sold_date_sk - ,cs_ext_sales_price sales_price - from catalog_sales)), - wswscs as - (select d_week_seq, - sum(case when (d_day_name='Sunday') then sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then sales_price else null end) sat_sales - from wscs - ,date_dim - where d_date_sk = sold_date_sk - group by d_week_seq) - select d_week_seq1 - ,round(sun_sales1/sun_sales2,2) - ,round(mon_sales1/mon_sales2,2) - ,round(tue_sales1/tue_sales2,2) - ,round(wed_sales1/wed_sales2,2) - ,round(thu_sales1/thu_sales2,2) - ,round(fri_sales1/fri_sales2,2) - ,round(sat_sales1/sat_sales2,2) - from - (select wswscs.d_week_seq d_week_seq1 - ,sun_sales sun_sales1 - ,mon_sales mon_sales1 - ,tue_sales tue_sales1 - ,wed_sales wed_sales1 - ,thu_sales thu_sales1 - ,fri_sales fri_sales1 - ,sat_sales sat_sales1 - from wswscs,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 1999) y, - (select wswscs.d_week_seq d_week_seq2 - ,sun_sales sun_sales2 - ,mon_sales mon_sales2 - ,tue_sales tue_sales2 - ,wed_sales wed_sales2 - ,thu_sales thu_sales2 - ,fri_sales fri_sales2 - ,sat_sales sat_sales2 - from wswscs - ,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 1999+1) z - where d_week_seq1=d_week_seq2-53 - order by d_week_seq1; - --- end template query2.tpl query 9 in stream 10 --- start template query96.tpl query 10 in stream 10 -select /* TPC-DS query96.tpl 0.1 */ count(*) -from store_sales - ,household_demographics - ,time_dim, store -where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and household_demographics.hd_dep_count = 3 - and store.s_store_name = 'ese' -order by count(*) -limit 100; - --- end template query96.tpl query 10 in stream 10 --- start template query93.tpl query 11 in stream 10 -select /* TPC-DS query93.tpl 0.52 */ ss_customer_sk - ,sum(act_sales) sumsales - from (select ss_item_sk - ,ss_ticket_number - ,ss_customer_sk - ,case when sr_return_quantity is not null then (ss_quantity-sr_return_quantity)*ss_sales_price - else (ss_quantity*ss_sales_price) end act_sales - from store_sales left outer join store_returns on (sr_item_sk = ss_item_sk - and sr_ticket_number = ss_ticket_number) - ,reason - where sr_reason_sk = r_reason_sk - and r_reason_desc = 'reason 54') t - group by ss_customer_sk - order by sumsales, ss_customer_sk -limit 100; - --- end template query93.tpl query 11 in stream 10 --- start template query15.tpl query 12 in stream 10 -select /* TPC-DS query15.tpl 0.57 */ ca_zip - ,sum(cs_sales_price) - from catalog_sales - ,customer - ,customer_address - ,date_dim - where cs_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', - '85392', '85460', '80348', '81792') - or ca_state in ('CA','WA','GA') - or cs_sales_price > 500) - and cs_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 2000 - group by ca_zip - order by ca_zip - limit 100; - --- end template query15.tpl query 12 in stream 10 --- start template query91.tpl query 13 in stream 10 -select /* TPC-DS query91.tpl 0.13 */ - cc_call_center_id Call_Center, - cc_name Call_Center_Name, - cc_manager Manager, - sum(cr_net_loss) Returns_Loss -from - call_center, - catalog_returns, - date_dim, - customer, - customer_address, - customer_demographics, - household_demographics -where - cr_call_center_sk = cc_call_center_sk -and cr_returned_date_sk = d_date_sk -and cr_returning_customer_sk= c_customer_sk -and cd_demo_sk = c_current_cdemo_sk -and hd_demo_sk = c_current_hdemo_sk -and ca_address_sk = c_current_addr_sk -and d_year = 1998 -and d_moy = 11 -and ( (cd_marital_status = 'M' and cd_education_status = 'Unknown') - or(cd_marital_status = 'W' and cd_education_status = 'Advanced Degree')) -and hd_buy_potential like 'Unknown%' -and ca_gmt_offset = -7 -group by cc_call_center_id,cc_name,cc_manager,cd_marital_status,cd_education_status -order by sum(cr_net_loss) desc; - --- end template query91.tpl query 13 in stream 10 --- start template query21.tpl query 14 in stream 10 -select /* TPC-DS query21.tpl 0.14 */ * - from(select w_warehouse_name - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('1999-06-06' as date)) - then inv_quantity_on_hand - else 0 end) as inv_before - ,sum(case when (cast(d_date as date) >= cast ('1999-06-06' as date)) - then inv_quantity_on_hand - else 0 end) as inv_after - from inventory - ,warehouse - ,item - ,date_dim - where i_current_price between 0.99 and 1.49 - and i_item_sk = inv_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('1999-06-06' as date)) - and dateadd(day,30,cast ('1999-06-06' as date)) - group by w_warehouse_name, i_item_id) x - where (case when inv_before > 0 - then inv_after / inv_before - else null - end) between 2.0/3.0 and 3.0/2.0 - order by w_warehouse_name - ,i_item_id - limit 100; - --- end template query21.tpl query 14 in stream 10 --- start template query18a.tpl query 15 in stream 10 -with /* TPC-DS query18a.tpl 0.90 */ results as - (select i_item_id, - ca_country, - ca_state, - ca_county, - cast(cs_quantity as decimal(12,2)) agg1, - cast(cs_list_price as decimal(12,2)) agg2, - cast(cs_coupon_amt as decimal(12,2)) agg3, - cast(cs_sales_price as decimal(12,2)) agg4, - cast(cs_net_profit as decimal(12,2)) agg5, - cast(c_birth_year as decimal(12,2)) agg6, - cast(cd1.cd_dep_count as decimal(12,2)) agg7 - from catalog_sales, customer_demographics cd1, customer_demographics cd2, customer, customer_address, date_dim, item - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd1.cd_demo_sk and - cs_bill_customer_sk = c_customer_sk and - cd1.cd_gender = 'M' and - cd1.cd_education_status = 'Advanced Degree' and - c_current_cdemo_sk = cd2.cd_demo_sk and - c_current_addr_sk = ca_address_sk and - c_birth_month in (7,5,11,3,8,10) and - d_year = 1999 and - ca_state in ('GA','OK','KY','LA','TX','NH','WV') - ) - select i_item_id, ca_country, ca_state, ca_county, agg1, agg2, agg3, agg4, agg5, agg6, agg7 - from ( - select i_item_id, ca_country, ca_state, ca_county, avg(agg1) agg1, - avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state, ca_county - union all - select i_item_id, ca_country, ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state - union all - select i_item_id, ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country - union all - select i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - ) foo - order by ca_country, ca_state, ca_county, i_item_id - limit 100; - --- end template query18a.tpl query 15 in stream 10 --- start template query32.tpl query 16 in stream 10 -select /* TPC-DS query32.tpl 0.7 */ sum(cs_ext_discount_amt) as "excess discount amount" -from - catalog_sales - ,item - ,date_dim -where -i_manufact_id = 27 -and i_item_sk = cs_item_sk -and d_date between '2001-02-23' and - dateadd(day,90,cast('2001-02-23' as date)) -and d_date_sk = cs_sold_date_sk -and cs_ext_discount_amt - > ( - select - 1.3 * avg(cs_ext_discount_amt) - from - catalog_sales - ,date_dim - where - cs_item_sk = i_item_sk - and d_date between '2001-02-23' and - dateadd(day,90,cast('2001-02-23' as date)) - and d_date_sk = cs_sold_date_sk - ) -limit 100; - --- end template query32.tpl query 16 in stream 10 --- start template query63.tpl query 17 in stream 10 -select /* TPC-DS query63.tpl 0.27 */ * -from (select i_manager_id - ,sum(ss_sales_price) sum_sales - ,avg(sum(ss_sales_price)) over (partition by i_manager_id) avg_monthly_sales - from item - ,store_sales - ,date_dim - ,store - where ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and d_month_seq in (1186,1186+1,1186+2,1186+3,1186+4,1186+5,1186+6,1186+7,1186+8,1186+9,1186+10,1186+11) - and (( i_category in ('Books','Children','Electronics') - and i_class in ('personal','portable','reference','self-help') - and i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) - or( i_category in ('Women','Music','Men') - and i_class in ('accessories','classical','fragrances','pants') - and i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manager_id, d_moy) tmp1 -where case when avg_monthly_sales > 0 then abs (sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 -order by i_manager_id - ,avg_monthly_sales - ,sum_sales -limit 100; - --- end template query63.tpl query 17 in stream 10 --- start template query24.tpl query 18 in stream 10 -with /* TPC-DS query24.tpl 0.92 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_net_paid) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip -and s_market_id=5 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'burnished' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; -with /* TPC-DS query24.tpl 0.92 part2 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_net_paid) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip - and s_market_id = 5 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'navajo' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; - --- end template query24.tpl query 18 in stream 10 --- start template query66.tpl query 19 in stream 10 -select /* TPC-DS query66.tpl 0.39 */ - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - ,sum(jan_sales) as jan_sales - ,sum(feb_sales) as feb_sales - ,sum(mar_sales) as mar_sales - ,sum(apr_sales) as apr_sales - ,sum(may_sales) as may_sales - ,sum(jun_sales) as jun_sales - ,sum(jul_sales) as jul_sales - ,sum(aug_sales) as aug_sales - ,sum(sep_sales) as sep_sales - ,sum(oct_sales) as oct_sales - ,sum(nov_sales) as nov_sales - ,sum(dec_sales) as dec_sales - ,sum(jan_sales/w_warehouse_sq_ft) as jan_sales_per_sq_foot - ,sum(feb_sales/w_warehouse_sq_ft) as feb_sales_per_sq_foot - ,sum(mar_sales/w_warehouse_sq_ft) as mar_sales_per_sq_foot - ,sum(apr_sales/w_warehouse_sq_ft) as apr_sales_per_sq_foot - ,sum(may_sales/w_warehouse_sq_ft) as may_sales_per_sq_foot - ,sum(jun_sales/w_warehouse_sq_ft) as jun_sales_per_sq_foot - ,sum(jul_sales/w_warehouse_sq_ft) as jul_sales_per_sq_foot - ,sum(aug_sales/w_warehouse_sq_ft) as aug_sales_per_sq_foot - ,sum(sep_sales/w_warehouse_sq_ft) as sep_sales_per_sq_foot - ,sum(oct_sales/w_warehouse_sq_ft) as oct_sales_per_sq_foot - ,sum(nov_sales/w_warehouse_sq_ft) as nov_sales_per_sq_foot - ,sum(dec_sales/w_warehouse_sq_ft) as dec_sales_per_sq_foot - ,sum(jan_net) as jan_net - ,sum(feb_net) as feb_net - ,sum(mar_net) as mar_net - ,sum(apr_net) as apr_net - ,sum(may_net) as may_net - ,sum(jun_net) as jun_net - ,sum(jul_net) as jul_net - ,sum(aug_net) as aug_net - ,sum(sep_net) as sep_net - ,sum(oct_net) as oct_net - ,sum(nov_net) as nov_net - ,sum(dec_net) as dec_net - from ( - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'HARMSTORF' || ',' || 'DIAMOND' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then ws_ext_list_price* ws_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then ws_ext_list_price* ws_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then ws_ext_list_price* ws_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then ws_ext_list_price* ws_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then ws_ext_list_price* ws_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then ws_ext_list_price* ws_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then ws_ext_list_price* ws_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then ws_ext_list_price* ws_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then ws_ext_list_price* ws_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then ws_ext_list_price* ws_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then ws_ext_list_price* ws_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then ws_ext_list_price* ws_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as dec_net - from - web_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - ws_warehouse_sk = w_warehouse_sk - and ws_sold_date_sk = d_date_sk - and ws_sold_time_sk = t_time_sk - and ws_ship_mode_sk = sm_ship_mode_sk - and d_year = 1998 - and t_time between 18403 and 18403+28800 - and sm_carrier in ('HARMSTORF','DIAMOND') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - union all - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'HARMSTORF' || ',' || 'DIAMOND' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then cs_sales_price* cs_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then cs_sales_price* cs_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then cs_sales_price* cs_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then cs_sales_price* cs_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then cs_sales_price* cs_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then cs_sales_price* cs_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then cs_sales_price* cs_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then cs_sales_price* cs_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then cs_sales_price* cs_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then cs_sales_price* cs_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then cs_sales_price* cs_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then cs_sales_price* cs_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as dec_net - from - catalog_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and cs_sold_time_sk = t_time_sk - and cs_ship_mode_sk = sm_ship_mode_sk - and d_year = 1998 - and t_time between 18403 AND 18403+28800 - and sm_carrier in ('HARMSTORF','DIAMOND') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - ) x - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - order by w_warehouse_name - limit 100; - --- end template query66.tpl query 19 in stream 10 --- start template query70a.tpl query 20 in stream 10 -with /* TPC-DS query70a.tpl 0.34 */ results as -( select - sum(ss_net_profit) as total_sum ,s_state ,s_county, 0 as gstate, 0 as g_county - from - store_sales - ,date_dim d1 - ,store - where - d1.d_month_seq between 1205 and 1205 + 11 - and d1.d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - and s_state in - ( select s_state - from (select s_state as s_state, - rank() over ( partition by s_state order by sum(ss_net_profit) desc) as ranking - from store_sales, store, date_dim - where d_month_seq between 1205 and 1205 + 11 - and d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - group by s_state - ) tmp1 - where ranking <= 5) - group by s_state,s_county) , - results_rollup as -(select total_sum ,s_state ,s_county, 0 as g_state, 0 as g_county, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum,s_state, NULL as s_county, 0 as g_state, 1 as g_county, 1 as lochierarchy from results group by s_state - union - select sum(total_sum) as total_sum ,NULL as s_state ,NULL as s_county, 1 as g_state, 1 as g_county, 2 as lochierarchy from results) - select total_sum ,s_state ,s_county, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_county = 0 then s_state end - order by total_sum desc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then s_state end - ,rank_within_parent - limit 100; - --- end template query70a.tpl query 20 in stream 10 --- start template query36a.tpl query 21 in stream 10 -with /* TPC-DS query36a.tpl 0.21 */ results as - (select - sum(ss_net_profit) as ss_net_profit, sum(ss_ext_sales_price) as ss_ext_sales_price, - sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin - ,i_category - ,i_class - ,0 as g_category, 0 as g_class - from - store_sales - ,date_dim d1 - ,item - ,store - where - d1.d_year = 1999 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and s_state in ('IL','CO','MN','MI', - 'NM','PA','TN','TX') - group by i_category,i_class) - , - results_rollup as - (select gross_margin ,i_category ,i_class,0 as t_category, 0 as t_class, 0 as lochierarchy from results - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - i_category, NULL AS i_class, 0 as t_category, 1 as t_class, 1 as lochierarchy from results group by i_category - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - NULL AS i_category ,NULL AS i_class, 1 as t_category, 1 as t_class, 2 as lochierarchy from results) - select - gross_margin ,i_category ,i_class, lochierarchy,rank() over ( - partition by lochierarchy, case when t_class = 0 then i_category end - order by gross_margin asc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then i_category end - ,rank_within_parent - limit 100; - --- end template query36a.tpl query 21 in stream 10 --- start template query20.tpl query 22 in stream 10 -select /* TPC-DS query20.tpl 0.65 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(cs_ext_sales_price) as itemrevenue - ,sum(cs_ext_sales_price)*100/sum(sum(cs_ext_sales_price)) over - (partition by i_class) as revenueratio - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and i_category in ('Books', 'Sports', 'Home') - and cs_sold_date_sk = d_date_sk - and d_date between cast('1998-05-28' as date) - and dateadd(day,30,cast('1998-05-28' as date)) - group by i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - order by i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query20.tpl query 22 in stream 10 --- start template query30.tpl query 23 in stream 10 -with /* TPC-DS query30.tpl 0.75 */ customer_total_return as - (select wr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(wr_return_amt) as ctr_total_return - from web_returns - ,date_dim - ,customer_address - where wr_returned_date_sk = d_date_sk - and d_year =2001 - and wr_returning_addr_sk = ca_address_sk - group by wr_returning_customer_sk - ,ca_state) - select c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'MO' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return -limit 100; - --- end template query30.tpl query 23 in stream 10 --- start template query25.tpl query 24 in stream 10 -select /* TPC-DS query25.tpl 0.9 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,max(ss_net_profit) as store_sales_profit - ,max(sr_net_loss) as store_returns_loss - ,max(cs_net_profit) as catalog_sales_profit - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 2000 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 10 - and d2.d_year = 2000 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_moy between 4 and 10 - and d3.d_year = 2000 - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query25.tpl query 24 in stream 10 --- start template query7.tpl query 25 in stream 10 -select /* TPC-DS query7.tpl 0.2 */ i_item_id, - avg(ss_quantity) agg1, - avg(ss_list_price) agg2, - avg(ss_coupon_amt) agg3, - avg(ss_sales_price) agg4 - from store_sales, customer_demographics, date_dim, item, promotion - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_cdemo_sk = cd_demo_sk and - ss_promo_sk = p_promo_sk and - cd_gender = 'M' and - cd_marital_status = 'D' and - cd_education_status = 'Primary' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 1999 - group by i_item_id - order by i_item_id - limit 100; - --- end template query7.tpl query 25 in stream 10 --- start template query1.tpl query 26 in stream 10 -with /* TPC-DS query1.tpl 0.12 */ customer_total_return as -(select sr_customer_sk as ctr_customer_sk -,sr_store_sk as ctr_store_sk -,sum(SR_REFUNDED_CASH) as ctr_total_return -from store_returns -,date_dim -where sr_returned_date_sk = d_date_sk -and d_year =1998 -group by sr_customer_sk -,sr_store_sk) - select c_customer_id -from customer_total_return ctr1 -,store -,customer -where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 -from customer_total_return ctr2 -where ctr1.ctr_store_sk = ctr2.ctr_store_sk) -and s_store_sk = ctr1.ctr_store_sk -and s_state = 'GA' -and ctr1.ctr_customer_sk = c_customer_sk -order by c_customer_id -limit 100; - --- end template query1.tpl query 26 in stream 10 --- start template query98.tpl query 27 in stream 10 -select /* TPC-DS query98.tpl 0.32 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ss_ext_sales_price) as itemrevenue - ,sum(ss_ext_sales_price)*100/sum(sum(ss_ext_sales_price)) over - (partition by i_class) as revenueratio -from - store_sales - ,item - ,date_dim -where - ss_item_sk = i_item_sk - and i_category in ('Children', 'Sports', 'Music') - and ss_sold_date_sk = d_date_sk - and d_date between cast('2001-04-26' as date) - and dateadd(day,30,cast('2001-04-26' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio; - --- end template query98.tpl query 27 in stream 10 --- start template query69.tpl query 28 in stream 10 -select /* TPC-DS query69.tpl 0.28 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_state in ('IL','KY','MT') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 4 and 4+2) and - (not exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 4 and 4+2) and - not exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 4 and 4+2)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - limit 100; - --- end template query69.tpl query 28 in stream 10 --- start template query47.tpl query 29 in stream 10 -with /* TPC-DS query47.tpl 0.42 */ v1 as( - select i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, - s_store_name, s_company_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - s_store_name, s_company_name - order by d_year, d_moy) rn - from item, store_sales, date_dim, store - where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - ( - d_year = 1999 or - ( d_year = 1999-1 and d_moy =12) or - ( d_year = 1999+1 and d_moy =1) - ) - group by i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy), - v2 as( - select v1.i_brand - ,v1.d_year - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1.s_store_name = v1_lag.s_store_name and - v1.s_store_name = v1_lead.s_store_name and - v1.s_company_name = v1_lag.s_company_name and - v1.s_company_name = v1_lead.s_company_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 1999 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, avg_monthly_sales - limit 100; - --- end template query47.tpl query 29 in stream 10 --- start template query94.tpl query 30 in stream 10 -select /* TPC-DS query94.tpl 0.17 */ - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '1999-2-01' and - dateadd(day,60,cast('1999-2-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'KS' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and exists (select * - from web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) -and not exists(select * - from web_returns wr1 - where ws1.ws_order_number = wr1.wr_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query94.tpl query 30 in stream 10 --- start template query82.tpl query 31 in stream 10 -select /* TPC-DS query82.tpl 0.67 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, store_sales - where i_current_price between 55 and 55+30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('2002-04-27' as date) and dateadd(day,60,cast('2002-04-27' as date)) - and i_manufact_id in (592,492,400,480) - and inv_quantity_on_hand between 100 and 500 - and ss_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query82.tpl query 31 in stream 10 --- start template query37.tpl query 32 in stream 10 -select /* TPC-DS query37.tpl 0.31 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, catalog_sales - where i_current_price between 33 and 33 + 30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('2002-05-01' as date) and dateadd(day,60,cast('2002-05-01' as date)) - and i_manufact_id in (712,948,979,675) - and inv_quantity_on_hand between 100 and 500 - and cs_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query37.tpl query 32 in stream 10 --- start template query64.tpl query 33 in stream 10 -with /* TPC-DS query64.tpl 0.20 */ cs_ui as - (select cs_item_sk - ,sum(cs_ext_list_price) as sale,sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit) as refund - from catalog_sales - ,catalog_returns - where cs_item_sk = cr_item_sk - and cs_order_number = cr_order_number - group by cs_item_sk - having sum(cs_ext_list_price)>2*sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit)), -cross_sales as - (select i_product_name product_name - ,i_item_sk item_sk - ,s_store_name store_name - ,s_zip store_zip - ,ad1.ca_street_number b_street_number - ,ad1.ca_street_name b_street_name - ,ad1.ca_city b_city - ,ad1.ca_zip b_zip - ,ad2.ca_street_number c_street_number - ,ad2.ca_street_name c_street_name - ,ad2.ca_city c_city - ,ad2.ca_zip c_zip - ,d1.d_year as syear - ,d2.d_year as fsyear - ,d3.d_year s2year - ,count(*) cnt - ,sum(ss_wholesale_cost) s1 - ,sum(ss_list_price) s2 - ,sum(ss_coupon_amt) s3 - FROM store_sales - ,store_returns - ,cs_ui - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,customer - ,customer_demographics cd1 - ,customer_demographics cd2 - ,promotion - ,household_demographics hd1 - ,household_demographics hd2 - ,customer_address ad1 - ,customer_address ad2 - ,income_band ib1 - ,income_band ib2 - ,item - WHERE ss_store_sk = s_store_sk AND - ss_sold_date_sk = d1.d_date_sk AND - ss_customer_sk = c_customer_sk AND - ss_cdemo_sk= cd1.cd_demo_sk AND - ss_hdemo_sk = hd1.hd_demo_sk AND - ss_addr_sk = ad1.ca_address_sk and - ss_item_sk = i_item_sk and - ss_item_sk = sr_item_sk and - ss_ticket_number = sr_ticket_number and - ss_item_sk = cs_ui.cs_item_sk and - c_current_cdemo_sk = cd2.cd_demo_sk AND - c_current_hdemo_sk = hd2.hd_demo_sk AND - c_current_addr_sk = ad2.ca_address_sk and - c_first_sales_date_sk = d2.d_date_sk and - c_first_shipto_date_sk = d3.d_date_sk and - ss_promo_sk = p_promo_sk and - hd1.hd_income_band_sk = ib1.ib_income_band_sk and - hd2.hd_income_band_sk = ib2.ib_income_band_sk and - cd1.cd_marital_status <> cd2.cd_marital_status and - i_color in ('lawn','lavender','royal','blue','cyan','spring') and - i_current_price between 58 and 58 + 10 and - i_current_price between 58 + 1 and 58 + 15 -group by i_product_name - ,i_item_sk - ,s_store_name - ,s_zip - ,ad1.ca_street_number - ,ad1.ca_street_name - ,ad1.ca_city - ,ad1.ca_zip - ,ad2.ca_street_number - ,ad2.ca_street_name - ,ad2.ca_city - ,ad2.ca_zip - ,d1.d_year - ,d2.d_year - ,d3.d_year -) -select cs1.product_name - ,cs1.store_name - ,cs1.store_zip - ,cs1.b_street_number - ,cs1.b_street_name - ,cs1.b_city - ,cs1.b_zip - ,cs1.c_street_number - ,cs1.c_street_name - ,cs1.c_city - ,cs1.c_zip - ,cs1.syear - ,cs1.cnt - ,cs1.s1 as s11 - ,cs1.s2 as s21 - ,cs1.s3 as s31 - ,cs2.s1 as s12 - ,cs2.s2 as s22 - ,cs2.s3 as s32 - ,cs2.syear - ,cs2.cnt -from cross_sales cs1,cross_sales cs2 -where cs1.item_sk=cs2.item_sk and - cs1.syear = 2000 and - cs2.syear = 2000 + 1 and - cs2.cnt <= cs1.cnt and - cs1.store_name = cs2.store_name and - cs1.store_zip = cs2.store_zip -order by cs1.product_name - ,cs1.store_name - ,cs2.cnt - ,cs1.s1 - ,cs2.s1; - --- end template query64.tpl query 33 in stream 10 --- start template query86a.tpl query 34 in stream 10 -with /* TPC-DS query86a.tpl 0.11 */ results as -( select sum(ws_net_paid) as total_sum, i_category, i_class, 0 as g_category, 0 as g_class - from - web_sales - ,date_dim d1 - ,item - where - d1.d_month_seq between 1210 and 1210+11 - and d1.d_date_sk = ws_sold_date_sk - and i_item_sk = ws_item_sk - group by i_category,i_class - ) , - - results_rollup as -( select total_sum ,i_category ,i_class, g_category, g_class, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum, i_category, NULL as i_class, 0 as g_category, 1 as g_class, 1 as lochierarchy from results group by i_category - union - select sum(total_sum) as total_sum, NULL as i_category, NULL as i_class, 1 as g_category, 1 as g_class, 2 as lochierarchy from results) - select - total_sum ,i_category ,i_class, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_class = 0 then i_category end - order by total_sum desc) as rank_within_parent - from - results_rollup - order by - lochierarchy desc, - case when lochierarchy = 0 then i_category end, - rank_within_parent - limit 100; - --- end template query86a.tpl query 34 in stream 10 --- start template query87.tpl query 35 in stream 10 -select /* TPC-DS query87.tpl 0.77 */ count(*) -from ((select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1206 and 1206+11) - except - (select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1206 and 1206+11) - except - (select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1206 and 1206+11) -) cool_cust -; - --- end template query87.tpl query 35 in stream 10 --- start template query28.tpl query 36 in stream 10 -select /* TPC-DS query28.tpl 0.36 */ * -from (select avg(ss_list_price) B1_LP - ,count(ss_list_price) B1_CNT - ,count(distinct ss_list_price) B1_CNTD - from store_sales - where ss_quantity between 0 and 5 - and (ss_list_price between 124 and 124+10 - or ss_coupon_amt between 6195 and 6195+1000 - or ss_wholesale_cost between 4 and 4+20)) B1, - (select avg(ss_list_price) B2_LP - ,count(ss_list_price) B2_CNT - ,count(distinct ss_list_price) B2_CNTD - from store_sales - where ss_quantity between 6 and 10 - and (ss_list_price between 69 and 69+10 - or ss_coupon_amt between 10056 and 10056+1000 - or ss_wholesale_cost between 23 and 23+20)) B2, - (select avg(ss_list_price) B3_LP - ,count(ss_list_price) B3_CNT - ,count(distinct ss_list_price) B3_CNTD - from store_sales - where ss_quantity between 11 and 15 - and (ss_list_price between 80 and 80+10 - or ss_coupon_amt between 17668 and 17668+1000 - or ss_wholesale_cost between 6 and 6+20)) B3, - (select avg(ss_list_price) B4_LP - ,count(ss_list_price) B4_CNT - ,count(distinct ss_list_price) B4_CNTD - from store_sales - where ss_quantity between 16 and 20 - and (ss_list_price between 13 and 13+10 - or ss_coupon_amt between 12799 and 12799+1000 - or ss_wholesale_cost between 72 and 72+20)) B4, - (select avg(ss_list_price) B5_LP - ,count(ss_list_price) B5_CNT - ,count(distinct ss_list_price) B5_CNTD - from store_sales - where ss_quantity between 21 and 25 - and (ss_list_price between 135 and 135+10 - or ss_coupon_amt between 11976 and 11976+1000 - or ss_wholesale_cost between 33 and 33+20)) B5, - (select avg(ss_list_price) B6_LP - ,count(ss_list_price) B6_CNT - ,count(distinct ss_list_price) B6_CNTD - from store_sales - where ss_quantity between 26 and 30 - and (ss_list_price between 103 and 103+10 - or ss_coupon_amt between 1405 and 1405+1000 - or ss_wholesale_cost between 0 and 0+20)) B6 -limit 100; - --- end template query28.tpl query 36 in stream 10 --- start template query55.tpl query 37 in stream 10 -select /* TPC-DS query55.tpl 0.82 */ i_brand_id brand_id, i_brand brand, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=34 - and d_moy=11 - and d_year=2002 - group by i_brand, i_brand_id - order by ext_price desc, i_brand_id -limit 100 ; - --- end template query55.tpl query 37 in stream 10 --- start template query85.tpl query 38 in stream 10 -select /* TPC-DS query85.tpl 0.33 */ substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) - from web_sales, web_returns, web_page, customer_demographics cd1, - customer_demographics cd2, customer_address, date_dim, reason - where ws_web_page_sk = wp_web_page_sk - and ws_item_sk = wr_item_sk - and ws_order_number = wr_order_number - and ws_sold_date_sk = d_date_sk and d_year = 2001 - and cd1.cd_demo_sk = wr_refunded_cdemo_sk - and cd2.cd_demo_sk = wr_returning_cdemo_sk - and ca_address_sk = wr_refunded_addr_sk - and r_reason_sk = wr_reason_sk - and - ( - ( - cd1.cd_marital_status = 'S' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = '4 yr Degree' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 100.00 and 150.00 - ) - or - ( - cd1.cd_marital_status = 'W' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Unknown' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 50.00 and 100.00 - ) - or - ( - cd1.cd_marital_status = 'M' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Primary' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ca_country = 'United States' - and - ca_state in ('AZ', 'NY', 'OH') - and ws_net_profit between 100 and 200 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('AL', 'GA', 'KS') - and ws_net_profit between 150 and 300 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('IL', 'MN', 'SC') - and ws_net_profit between 50 and 250 - ) - ) -group by r_reason_desc -order by substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) -limit 100; - --- end template query85.tpl query 38 in stream 10 --- start template query38.tpl query 39 in stream 10 -select /* TPC-DS query38.tpl 0.54 */ count(*) from ( - select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1199 and 1199 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1199 and 1199 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1199 and 1199 + 11 -) hot_cust -limit 100; - --- end template query38.tpl query 39 in stream 10 --- start template query44.tpl query 40 in stream 10 -select /* TPC-DS query44.tpl 0.4 */ asceding.rnk, i1.i_product_name best_performing, i2.i_product_name worst_performing -from(select * - from (select item_sk,rank() over (order by rank_col asc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 362 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 362 - and ss_cdemo_sk is null - group by ss_store_sk))V1)V11 - where rnk < 11) asceding, - (select * - from (select item_sk,rank() over (order by rank_col desc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 362 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 362 - and ss_cdemo_sk is null - group by ss_store_sk))V2)V21 - where rnk < 11) descending, -item i1, -item i2 -where asceding.rnk = descending.rnk - and i1.i_item_sk=asceding.item_sk - and i2.i_item_sk=descending.item_sk -order by asceding.rnk -limit 100; - --- end template query44.tpl query 40 in stream 10 --- start template query27a.tpl query 41 in stream 10 -with /* TPC-DS query27a.tpl 0.16 */ results as - (select i_item_id, - s_state, 0 as g_state, - ss_quantity agg1, - ss_list_price agg2, - ss_coupon_amt agg3, - ss_sales_price agg4 - from store_sales, customer_demographics, date_dim, store, item - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_store_sk = s_store_sk and - ss_cdemo_sk = cd_demo_sk and - cd_gender = 'M' and - cd_marital_status = 'M' and - cd_education_status = 'Unknown' and - d_year = 2000 and - s_state in ('LA','CO', 'FL', 'TN', 'MI', 'IN') - ) - - select i_item_id, - s_state, g_state, agg1, agg2, agg3, agg4 - from ( - select i_item_id, s_state, 0 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4 from results - group by i_item_id, s_state - union all - select i_item_id, NULL AS s_state, 1 AS g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as s_state, 1 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - ) foo - order by i_item_id, s_state - limit 100; - --- end template query27a.tpl query 41 in stream 10 --- start template query78.tpl query 42 in stream 10 -with /* TPC-DS query78.tpl 0.10 */ ws as - (select d_year AS ws_sold_year, ws_item_sk, - ws_bill_customer_sk ws_customer_sk, - sum(ws_quantity) ws_qty, - sum(ws_wholesale_cost) ws_wc, - sum(ws_sales_price) ws_sp - from web_sales - left join web_returns on wr_order_number=ws_order_number and ws_item_sk=wr_item_sk - join date_dim on ws_sold_date_sk = d_date_sk - where wr_order_number is null - group by d_year, ws_item_sk, ws_bill_customer_sk - ), -cs as - (select d_year AS cs_sold_year, cs_item_sk, - cs_bill_customer_sk cs_customer_sk, - sum(cs_quantity) cs_qty, - sum(cs_wholesale_cost) cs_wc, - sum(cs_sales_price) cs_sp - from catalog_sales - left join catalog_returns on cr_order_number=cs_order_number and cs_item_sk=cr_item_sk - join date_dim on cs_sold_date_sk = d_date_sk - where cr_order_number is null - group by d_year, cs_item_sk, cs_bill_customer_sk - ), -ss as - (select d_year AS ss_sold_year, ss_item_sk, - ss_customer_sk, - sum(ss_quantity) ss_qty, - sum(ss_wholesale_cost) ss_wc, - sum(ss_sales_price) ss_sp - from store_sales - left join store_returns on sr_ticket_number=ss_ticket_number and ss_item_sk=sr_item_sk - join date_dim on ss_sold_date_sk = d_date_sk - where sr_ticket_number is null - group by d_year, ss_item_sk, ss_customer_sk - ) - select -ss_sold_year, -round(ss_qty/(coalesce(ws_qty,0)+coalesce(cs_qty,0)),2) ratio, -ss_qty store_qty, ss_wc store_wholesale_cost, ss_sp store_sales_price, -coalesce(ws_qty,0)+coalesce(cs_qty,0) other_chan_qty, -coalesce(ws_wc,0)+coalesce(cs_wc,0) other_chan_wholesale_cost, -coalesce(ws_sp,0)+coalesce(cs_sp,0) other_chan_sales_price -from ss -left join ws on (ws_sold_year=ss_sold_year and ws_item_sk=ss_item_sk and ws_customer_sk=ss_customer_sk) -left join cs on (cs_sold_year=ss_sold_year and cs_item_sk=ss_item_sk and cs_customer_sk=ss_customer_sk) -where (coalesce(ws_qty,0)>0 or coalesce(cs_qty, 0)>0) and ss_sold_year=2001 -order by - ss_sold_year, - ss_qty desc, ss_wc desc, ss_sp desc, - other_chan_qty, - other_chan_wholesale_cost, - other_chan_sales_price, - ratio -limit 100; - --- end template query78.tpl query 42 in stream 10 --- start template query45.tpl query 43 in stream 10 -select /* TPC-DS query45.tpl 0.18 */ ca_zip, ca_county, sum(ws_sales_price) - from web_sales, customer, customer_address, date_dim, item - where ws_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ws_item_sk = i_item_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', '85392', '85460', '80348', '81792') - or - i_item_id in (select i_item_id - from item - where i_item_sk in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29) - ) - ) - and ws_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 2000 - group by ca_zip, ca_county - order by ca_zip, ca_county - limit 100; - --- end template query45.tpl query 43 in stream 10 --- start template query49.tpl query 44 in stream 10 -select /* TPC-DS query49.tpl 0.48 */ channel, item, return_ratio, return_rank, currency_rank from - (select - 'web' as channel - ,web.item - ,web.return_ratio - ,web.return_rank - ,web.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select ws.ws_item_sk as item - ,(cast(sum(coalesce(wr.wr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(wr.wr_return_amt,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - web_sales ws left outer join web_returns wr - on (ws.ws_order_number = wr.wr_order_number and - ws.ws_item_sk = wr.wr_item_sk) - ,date_dim - where - wr.wr_return_amt > 10000 - and ws.ws_net_profit > 1 - and ws.ws_net_paid > 0 - and ws.ws_quantity > 0 - and ws_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 11 - group by ws.ws_item_sk - ) in_web - ) web - where - ( - web.return_rank <= 10 - or - web.currency_rank <= 10 - ) - union - select - 'catalog' as channel - ,catalog.item - ,catalog.return_ratio - ,catalog.return_rank - ,catalog.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select - cs.cs_item_sk as item - ,(cast(sum(coalesce(cr.cr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(cr.cr_return_amount,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - catalog_sales cs left outer join catalog_returns cr - on (cs.cs_order_number = cr.cr_order_number and - cs.cs_item_sk = cr.cr_item_sk) - ,date_dim - where - cr.cr_return_amount > 10000 - and cs.cs_net_profit > 1 - and cs.cs_net_paid > 0 - and cs.cs_quantity > 0 - and cs_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 11 - group by cs.cs_item_sk - ) in_cat - ) catalog - where - ( - catalog.return_rank <= 10 - or - catalog.currency_rank <=10 - ) - union - select - 'store' as channel - ,store.item - ,store.return_ratio - ,store.return_rank - ,store.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select sts.ss_item_sk as item - ,(cast(sum(coalesce(sr.sr_return_quantity,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(sr.sr_return_amt,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - store_sales sts left outer join store_returns sr - on (sts.ss_ticket_number = sr.sr_ticket_number and sts.ss_item_sk = sr.sr_item_sk) - ,date_dim - where - sr.sr_return_amt > 10000 - and sts.ss_net_profit > 1 - and sts.ss_net_paid > 0 - and sts.ss_quantity > 0 - and ss_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 11 - group by sts.ss_item_sk - ) in_store - ) store - where ( - store.return_rank <= 10 - or - store.currency_rank <= 10 - ) - ) - order by 1,4,5,2 - limit 100; - --- end template query49.tpl query 44 in stream 10 --- start template query62.tpl query 45 in stream 10 -select /* TPC-DS query62.tpl 0.24 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 30) and - (ws_ship_date_sk - ws_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 60) and - (ws_ship_date_sk - ws_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 90) and - (ws_ship_date_sk - ws_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - web_sales - ,warehouse - ,ship_mode - ,web_site - ,date_dim -where - d_month_seq between 1202 and 1202 + 11 -and ws_ship_date_sk = d_date_sk -and ws_warehouse_sk = w_warehouse_sk -and ws_ship_mode_sk = sm_ship_mode_sk -and ws_web_site_sk = web_site_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -limit 100; - --- end template query62.tpl query 45 in stream 10 --- start template query59.tpl query 46 in stream 10 -with /* TPC-DS query59.tpl 0.30 */ wss as - (select d_week_seq, - ss_store_sk, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - group by d_week_seq,ss_store_sk - ) - select s_store_name1,s_store_id1,d_week_seq1 - ,sun_sales1/sun_sales2,mon_sales1/mon_sales2 - ,tue_sales1/tue_sales2,wed_sales1/wed_sales2,thu_sales1/thu_sales2 - ,fri_sales1/fri_sales2,sat_sales1/sat_sales2 - from - (select s_store_name s_store_name1,wss.d_week_seq d_week_seq1 - ,s_store_id s_store_id1,sun_sales sun_sales1 - ,mon_sales mon_sales1,tue_sales tue_sales1 - ,wed_sales wed_sales1,thu_sales thu_sales1 - ,fri_sales fri_sales1,sat_sales sat_sales1 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1187 and 1187 + 11) y, - (select s_store_name s_store_name2,wss.d_week_seq d_week_seq2 - ,s_store_id s_store_id2,sun_sales sun_sales2 - ,mon_sales mon_sales2,tue_sales tue_sales2 - ,wed_sales wed_sales2,thu_sales thu_sales2 - ,fri_sales fri_sales2,sat_sales sat_sales2 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1187+ 12 and 1187 + 23) x - where s_store_id1=s_store_id2 - and d_week_seq1=d_week_seq2-52 - order by s_store_name1,s_store_id1,d_week_seq1 -limit 100; - --- end template query59.tpl query 46 in stream 10 --- start template query77a.tpl query 47 in stream 10 -with /* TPC-DS query77a.tpl 0.78 */ ss as - (select s_store_sk, - sum(ss_ext_sales_price) as sales, - sum(ss_net_profit) as profit - from store_sales, - date_dim, - store - where ss_sold_date_sk = d_date_sk - and d_date between cast('2000-08-03' as date) - and dateadd(day,30,cast('2000-08-03' as date)) - and ss_store_sk = s_store_sk - group by s_store_sk) - , - sr as - (select s_store_sk, - sum(sr_return_amt) as returns, - sum(sr_net_loss) as profit_loss - from store_returns, - date_dim, - store - where sr_returned_date_sk = d_date_sk - and d_date between cast('2000-08-03' as date) - and dateadd(day,30,cast('2000-08-03' as date)) - and sr_store_sk = s_store_sk - group by s_store_sk), - cs as - (select cs_call_center_sk, - sum(cs_ext_sales_price) as sales, - sum(cs_net_profit) as profit - from catalog_sales, - date_dim - where cs_sold_date_sk = d_date_sk - and d_date between cast('2000-08-03' as date) - and dateadd(day,30,cast('2000-08-03' as date)) - group by cs_call_center_sk - ), - cr as - (select cr_call_center_sk, - sum(cr_return_amount) as returns, - sum(cr_net_loss) as profit_loss - from catalog_returns, - date_dim - where cr_returned_date_sk = d_date_sk - and d_date between cast('2000-08-03' as date) - and dateadd(day,30,cast('2000-08-03' as date)) - group by cr_call_center_sk), - ws as - ( select wp_web_page_sk, - sum(ws_ext_sales_price) as sales, - sum(ws_net_profit) as profit - from web_sales, - date_dim, - web_page - where ws_sold_date_sk = d_date_sk - and d_date between cast('2000-08-03' as date) - and dateadd(day,30,cast('2000-08-03' as date)) - and ws_web_page_sk = wp_web_page_sk - group by wp_web_page_sk), - wr as - (select wp_web_page_sk, - sum(wr_return_amt) as returns, - sum(wr_net_loss) as profit_loss - from web_returns, - date_dim, - web_page - where wr_returned_date_sk = d_date_sk - and d_date between cast('2000-08-03' as date) - and dateadd(day,30,cast('2000-08-03' as date)) - and wr_web_page_sk = wp_web_page_sk - group by wp_web_page_sk) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , ss.s_store_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ss left join sr - on ss.s_store_sk = sr.s_store_sk - union all - select 'catalog channel' as channel - , cs_call_center_sk as id - , sales - , returns - , (profit - profit_loss) as profit - from cs - , cr - union all - select 'web channel' as channel - , ws.wp_web_page_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ws left join wr - on ws.wp_web_page_sk = wr.wp_web_page_sk - ) x - group by channel, id ) - - select * - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results -) foo -order by channel, id - limit 100; - --- end template query77a.tpl query 47 in stream 10 --- start template query80a.tpl query 48 in stream 10 -with /* TPC-DS query80a.tpl 0.6 */ ssr as - (select s_store_id as store_id, - sum(ss_ext_sales_price) as sales, - sum(coalesce(sr_return_amt, 0)) as returns, - sum(ss_net_profit - coalesce(sr_net_loss, 0)) as profit - from store_sales left outer join store_returns on - (ss_item_sk = sr_item_sk and ss_ticket_number = sr_ticket_number), - date_dim, - store, - item, - promotion - where ss_sold_date_sk = d_date_sk - and d_date between cast('2002-08-15' as date) - and dateadd(day,30,cast('2002-08-15' as date)) - and ss_store_sk = s_store_sk - and ss_item_sk = i_item_sk - and i_current_price > 50 - and ss_promo_sk = p_promo_sk - and p_channel_tv = 'N' - group by s_store_id) - , - csr as - (select cp_catalog_page_id as catalog_page_id, - sum(cs_ext_sales_price) as sales, - sum(coalesce(cr_return_amount, 0)) as returns, - sum(cs_net_profit - coalesce(cr_net_loss, 0)) as profit - from catalog_sales left outer join catalog_returns on - (cs_item_sk = cr_item_sk and cs_order_number = cr_order_number), - date_dim, - catalog_page, - item, - promotion - where cs_sold_date_sk = d_date_sk - and d_date between cast('2002-08-15' as date) - and dateadd(day,30,cast('2002-08-15' as date)) - and cs_catalog_page_sk = cp_catalog_page_sk - and cs_item_sk = i_item_sk - and i_current_price > 50 - and cs_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(ws_ext_sales_price) as sales, - sum(coalesce(wr_return_amt, 0)) as returns, - sum(ws_net_profit - coalesce(wr_net_loss, 0)) as profit - from web_sales left outer join web_returns on - (ws_item_sk = wr_item_sk and ws_order_number = wr_order_number), - date_dim, - web_site, - item, - promotion - where ws_sold_date_sk = d_date_sk - and d_date between cast('2002-08-15' as date) - and dateadd(day,30,cast('2002-08-15' as date)) - and ws_web_site_sk = web_site_sk - and ws_item_sk = i_item_sk - and i_current_price > 50 - and ws_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by web_site_id) -, -results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || store_id as id - , sales - , returns - , profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || catalog_page_id as id - , sales - , returns - , profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , profit - from wsr - ) x - group by channel, id) - - select channel - , id - , sales - , returns - , profit - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results - ) foo - order by channel, id - limit 100; - --- end template query80a.tpl query 48 in stream 10 --- start template query84.tpl query 49 in stream 10 -select /* TPC-DS query84.tpl 0.80 */ c_customer_id as customer_id - , coalesce(c_last_name,'') || ', ' || coalesce(c_first_name,'') as customername - from customer - ,customer_address - ,customer_demographics - ,household_demographics - ,income_band - ,store_returns - where ca_city = 'Buena Vista' - and c_current_addr_sk = ca_address_sk - and ib_lower_bound >= 40429 - and ib_upper_bound <= 40429 + 50000 - and ib_income_band_sk = hd_income_band_sk - and cd_demo_sk = c_current_cdemo_sk - and hd_demo_sk = c_current_hdemo_sk - and sr_cdemo_sk = cd_demo_sk - order by c_customer_id - limit 100; - --- end template query84.tpl query 49 in stream 10 --- start template query67a.tpl query 50 in stream 10 -with /* TPC-DS query67a.tpl 0.35 */ results as -( select i_category ,i_class ,i_brand ,i_product_name ,d_year ,d_qoy ,d_moy ,s_store_id - ,sum(coalesce(ss_sales_price*ss_quantity,0)) sumsales - from store_sales ,date_dim ,store ,item - where ss_sold_date_sk=d_date_sk - and ss_item_sk=i_item_sk - and ss_store_sk = s_store_sk - and d_month_seq between 1187 and 1187 + 11 - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy,s_store_id) - , - results_rollup as - (select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, s_store_id, sumsales - from results - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy - union all - select i_category, i_class, i_brand, i_product_name, d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year - union all - select i_category, i_class, i_brand, i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name - union all - select i_category, i_class, i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand - union all - select i_category, i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class - union all - select i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category - union all - select null i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results) - - select * -from (select i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rank() over (partition by i_category order by sumsales desc) rk - from results_rollup) dw2 -where rk <= 100 -order by i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rk -limit 100; - --- end template query67a.tpl query 50 in stream 10 --- start template query52.tpl query 51 in stream 10 -select /* TPC-DS query52.tpl 0.59 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_sales_price) ext_price - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=12 - and dt.d_year=2001 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,ext_price desc - ,brand_id -limit 100 ; - --- end template query52.tpl query 51 in stream 10 --- start template query76.tpl query 52 in stream 10 -select /* TPC-DS query76.tpl 0.99 */ channel, col_name, d_year, d_qoy, i_category, COUNT(*) sales_cnt, SUM(ext_sales_price) sales_amt FROM ( - SELECT 'store' as channel, 'ss_customer_sk' col_name, d_year, d_qoy, i_category, ss_ext_sales_price ext_sales_price - FROM store_sales, item, date_dim - WHERE ss_customer_sk IS NULL - AND ss_sold_date_sk=d_date_sk - AND ss_item_sk=i_item_sk - UNION ALL - SELECT 'web' as channel, 'ws_ship_addr_sk' col_name, d_year, d_qoy, i_category, ws_ext_sales_price ext_sales_price - FROM web_sales, item, date_dim - WHERE ws_ship_addr_sk IS NULL - AND ws_sold_date_sk=d_date_sk - AND ws_item_sk=i_item_sk - UNION ALL - SELECT 'catalog' as channel, 'cs_ship_addr_sk' col_name, d_year, d_qoy, i_category, cs_ext_sales_price ext_sales_price - FROM catalog_sales, item, date_dim - WHERE cs_ship_addr_sk IS NULL - AND cs_sold_date_sk=d_date_sk - AND cs_item_sk=i_item_sk) foo -GROUP BY channel, col_name, d_year, d_qoy, i_category -ORDER BY channel, col_name, d_year, d_qoy, i_category -limit 100; - --- end template query76.tpl query 52 in stream 10 --- start template query42.tpl query 53 in stream 10 -select /* TPC-DS query42.tpl 0.61 */ dt.d_year - ,item.i_category_id - ,item.i_category - ,sum(ss_ext_sales_price) - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=11 - and dt.d_year=1998 - group by dt.d_year - ,item.i_category_id - ,item.i_category - order by sum(ss_ext_sales_price) desc,dt.d_year - ,item.i_category_id - ,item.i_category -limit 100 ; - --- end template query42.tpl query 53 in stream 10 --- start template query33.tpl query 54 in stream 10 -with /* TPC-DS query33.tpl 0.22 */ ss as ( - select - i_manufact_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Home')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 6 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id), - cs as ( - select - i_manufact_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Home')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 6 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id), - ws as ( - select - i_manufact_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Home')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 6 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id) - select i_manufact_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_manufact_id - order by total_sales -limit 100; - --- end template query33.tpl query 54 in stream 10 --- start template query65.tpl query 55 in stream 10 -select /* TPC-DS query65.tpl 0.71 */ - s_store_name, - i_item_desc, - sc.revenue, - i_current_price, - i_wholesale_cost, - i_brand - from store, item, - (select ss_store_sk, avg(revenue) as ave - from - (select ss_store_sk, ss_item_sk, - sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1196 and 1196+11 - group by ss_store_sk, ss_item_sk) sa - group by ss_store_sk) sb, - (select ss_store_sk, ss_item_sk, sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1196 and 1196+11 - group by ss_store_sk, ss_item_sk) sc - where sb.ss_store_sk = sc.ss_store_sk and - sc.revenue <= 0.1 * sb.ave and - s_store_sk = sc.ss_store_sk and - i_item_sk = sc.ss_item_sk - order by s_store_name, i_item_desc -limit 100; - --- end template query65.tpl query 55 in stream 10 --- start template query23.tpl query 56 in stream 10 -with /* TPC-DS query23.tpl 0.68 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (1998,1998+1,1998+2,1998+3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1998,1998+1,1998+2,1998+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * -from - max_store_sales)) - select sum(sales) - from (select cs_quantity*cs_list_price sales - from catalog_sales - ,date_dim - where d_year = 1998 - and d_moy = 7 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - union all - select ws_quantity*ws_list_price sales - from web_sales - ,date_dim - where d_year = 1998 - and d_moy = 7 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer)) - limit 100; -with /* TPC-DS query23.tpl 0.68 part2 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (1998,1998 + 1,1998 + 2,1998 + 3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1998,1998+1,1998+2,1998+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * - from max_store_sales)) - select c_last_name,c_first_name,sales - from (select c_last_name,c_first_name,sum(cs_quantity*cs_list_price) sales - from catalog_sales - ,customer - ,date_dim - where d_year = 1998 - and d_moy = 7 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and cs_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name - union all - select c_last_name,c_first_name,sum(ws_quantity*ws_list_price) sales - from web_sales - ,customer - ,date_dim - where d_year = 1998 - and d_moy = 7 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and ws_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name) - order by c_last_name,c_first_name,sales - limit 100; - --- end template query23.tpl query 56 in stream 10 --- start template query90.tpl query 57 in stream 10 -select /* TPC-DS query90.tpl 0.40 */ cast(amc as decimal(15,4))/cast(pmc as decimal(15,4)) am_pm_ratio - from ( select count(*) amc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 6 and 6+1 - and household_demographics.hd_dep_count = 9 - and web_page.wp_char_count between 5000 and 5200) at, - ( select count(*) pmc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 20 and 20+1 - and household_demographics.hd_dep_count = 9 - and web_page.wp_char_count between 5000 and 5200) pt - order by am_pm_ratio - limit 100; - --- end template query90.tpl query 57 in stream 10 --- start template query88.tpl query 58 in stream 10 -select /* TPC-DS query88.tpl 0.66 */ * -from - (select count(*) h8_30_to_9 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s1, - (select count(*) h9_to_9_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s2, - (select count(*) h9_30_to_10 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s3, - (select count(*) h10_to_10_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s4, - (select count(*) h10_30_to_11 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s5, - (select count(*) h11_to_11_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s6, - (select count(*) h11_30_to_12 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s7, - (select count(*) h12_to_12_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 12 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s8 -; - --- end template query88.tpl query 58 in stream 10 --- start template query99.tpl query 59 in stream 10 -select /* TPC-DS query99.tpl 0.94 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 30) and - (cs_ship_date_sk - cs_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 60) and - (cs_ship_date_sk - cs_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 90) and - (cs_ship_date_sk - cs_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - catalog_sales - ,warehouse - ,ship_mode - ,call_center - ,date_dim -where - d_month_seq between 1190 and 1190 + 11 -and cs_ship_date_sk = d_date_sk -and cs_warehouse_sk = w_warehouse_sk -and cs_ship_mode_sk = sm_ship_mode_sk -and cs_call_center_sk = cc_call_center_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -limit 100; - --- end template query99.tpl query 59 in stream 10 --- start template query35a.tpl query 60 in stream 10 -select /* TPC-DS query35a.tpl 0.47 */ - ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - count(*) cnt1, - max(cd_dep_count), - min(cd_dep_count), - stddev_samp(cd_dep_count), - cd_dep_employed_count, - count(*) cnt2, - max(cd_dep_employed_count), - min(cd_dep_employed_count), - stddev_samp(cd_dep_employed_count), - cd_dep_college_count, - count(*) cnt3, - max(cd_dep_college_count), - min(cd_dep_college_count), - stddev_samp(cd_dep_college_count) - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2002 and - d_qoy < 4) and - exists (select * from - (select ws_bill_customer_sk customsk - from web_sales,date_dim - where - ws_sold_date_sk = d_date_sk and - d_year = 2002 and - d_qoy < 4 - union all - select cs_ship_customer_sk customsk - from catalog_sales,date_dim - where - cs_sold_date_sk = d_date_sk and - d_year = 2002 and - d_qoy < 4)x - where x.customsk = c.c_customer_sk) - group by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - limit 100; - --- end template query35a.tpl query 60 in stream 10 --- start template query10.tpl query 61 in stream 10 -select /* TPC-DS query10.tpl 0.26 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3, - cd_dep_count, - count(*) cnt4, - cd_dep_employed_count, - count(*) cnt5, - cd_dep_college_count, - count(*) cnt6 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_county in ('Wayne County','Tazewell County','King County','Geneva County','Marion County') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 1999 and - d_moy between 3 and 3+3) and - (exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 1999 and - d_moy between 3 ANd 3+3) or - exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 1999 and - d_moy between 3 and 3+3)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count -limit 100; - --- end template query10.tpl query 61 in stream 10 --- start template query16.tpl query 62 in stream 10 -select /* TPC-DS query16.tpl 0.25 */ - count(distinct cs_order_number) as "order count" - ,sum(cs_ext_ship_cost) as "total shipping cost" - ,sum(cs_net_profit) as "total net profit" -from - catalog_sales cs1 - ,date_dim - ,customer_address - ,call_center -where - d_date between '2001-3-01' and - dateadd(day, 60, cast('2001-3-01' as date)) -and cs1.cs_ship_date_sk = d_date_sk -and cs1.cs_ship_addr_sk = ca_address_sk -and ca_state = 'TX' -and cs1.cs_call_center_sk = cc_call_center_sk -and cc_county in ('Franklin Parish','Kittitas County','Jefferson Davis Parish','Walker County', - 'Huron County' -) -and exists (select * - from catalog_sales cs2 - where cs1.cs_order_number = cs2.cs_order_number - and cs1.cs_warehouse_sk <> cs2.cs_warehouse_sk) -and not exists(select * - from catalog_returns cr1 - where cs1.cs_order_number = cr1.cr_order_number) -order by count(distinct cs_order_number) -limit 100; - --- end template query16.tpl query 62 in stream 10 --- start template query5a.tpl query 63 in stream 10 -with /* TPC-DS query5a.tpl 0.98 */ ssr as - (select s_store_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ss_store_sk as store_sk, - ss_sold_date_sk as date_sk, - ss_ext_sales_price as sales_price, - ss_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from store_sales - union all - select sr_store_sk as store_sk, - sr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - sr_return_amt as return_amt, - sr_net_loss as net_loss - from store_returns - ) salesreturns, - date_dim, - store - where date_sk = d_date_sk - and d_date between cast('2001-08-19' as date) - and dateadd(day,14,cast('2001-08-19' as date)) - and store_sk = s_store_sk - group by s_store_id) - , - csr as - (select cp_catalog_page_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select cs_catalog_page_sk as page_sk, - cs_sold_date_sk as date_sk, - cs_ext_sales_price as sales_price, - cs_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from catalog_sales - union all - select cr_catalog_page_sk as page_sk, - cr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - cr_return_amount as return_amt, - cr_net_loss as net_loss - from catalog_returns - ) salesreturns, - date_dim, - catalog_page - where date_sk = d_date_sk - and d_date between cast('2001-08-19' as date) - and dateadd(day,14,cast('2001-08-19' as date)) - and page_sk = cp_catalog_page_sk - group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ws_web_site_sk as wsr_web_site_sk, - ws_sold_date_sk as date_sk, - ws_ext_sales_price as sales_price, - ws_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from web_sales - union all - select ws_web_site_sk as wsr_web_site_sk, - wr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - wr_return_amt as return_amt, - wr_net_loss as net_loss - from web_returns left outer join web_sales on - ( wr_item_sk = ws_item_sk - and wr_order_number = ws_order_number) - ) salesreturns, - date_dim, - web_site - where date_sk = d_date_sk - and d_date between cast('2001-08-19' as date) - and dateadd(day,14,cast('2001-08-19' as date)) - and wsr_web_site_sk = web_site_sk - group by web_site_id) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || s_store_id as id - , sales - , returns - , (profit - profit_loss) as profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || cp_catalog_page_id as id - , sales - , returns - , (profit - profit_loss) as profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , (profit - profit_loss) as profit - from wsr - ) x - group by channel, id) - select channel, id, sales, returns, profit from ( - select channel, id, sales, returns, profit from results - union - select channel, null as id, sum(sales), sum(returns), sum(profit) from results group by channel - union - select null as channel, null as id, sum(sales), sum(returns), sum(profit) from results) foo -order by channel, id -limit 100; - --- end template query5a.tpl query 63 in stream 10 --- start template query57.tpl query 64 in stream 10 -with /* TPC-DS query57.tpl 0.70 */ v1 as( - select i_category, i_brand, - cc_name, - d_year, d_moy, - sum(cs_sales_price) sum_sales, - avg(sum(cs_sales_price)) over - (partition by i_category, i_brand, - cc_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - cc_name - order by d_year, d_moy) rn - from item, catalog_sales, date_dim, call_center - where cs_item_sk = i_item_sk and - cs_sold_date_sk = d_date_sk and - cc_call_center_sk= cs_call_center_sk and - ( - d_year = 2000 or - ( d_year = 2000-1 and d_moy =12) or - ( d_year = 2000+1 and d_moy =1) - ) - group by i_category, i_brand, - cc_name , d_year, d_moy), - v2 as( - select v1.i_brand - ,v1.d_year - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1. cc_name = v1_lag. cc_name and - v1. cc_name = v1_lead. cc_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 2000 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, nsum - limit 100; - --- end template query57.tpl query 64 in stream 10 --- start template query34.tpl query 65 in stream 10 -select /* TPC-DS query34.tpl 0.73 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (date_dim.d_dom between 1 and 3 or date_dim.d_dom between 25 and 28) - and (household_demographics.hd_buy_potential = '>10000' or - household_demographics.hd_buy_potential = '0-500') - and household_demographics.hd_vehicle_count > 0 - and (case when household_demographics.hd_vehicle_count > 0 - then household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count - else null - end) > 1.2 - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_county in ('Harmon County','Saginaw County','Walker County','Wadena County', - 'Mesa County','Essex County','Richland County','Sierra County') - group by ss_ticket_number,ss_customer_sk) dn,customer - where ss_customer_sk = c_customer_sk - and cnt between 15 and 20 - order by c_last_name,c_first_name,c_salutation,c_preferred_cust_flag desc, ss_ticket_number; - --- end template query34.tpl query 65 in stream 10 --- start template query97.tpl query 66 in stream 10 -with /* TPC-DS query97.tpl 0.38 */ ssci as ( -select ss_customer_sk customer_sk - ,ss_item_sk item_sk -from store_sales,date_dim -where ss_sold_date_sk = d_date_sk - and d_month_seq between 1208 and 1208 + 11 -group by ss_customer_sk - ,ss_item_sk), -csci as( - select cs_bill_customer_sk customer_sk - ,cs_item_sk item_sk -from catalog_sales,date_dim -where cs_sold_date_sk = d_date_sk - and d_month_seq between 1208 and 1208 + 11 -group by cs_bill_customer_sk - ,cs_item_sk) - select sum(case when ssci.customer_sk is not null and csci.customer_sk is null then 1 else 0 end) store_only - ,sum(case when ssci.customer_sk is null and csci.customer_sk is not null then 1 else 0 end) catalog_only - ,sum(case when ssci.customer_sk is not null and csci.customer_sk is not null then 1 else 0 end) store_and_catalog -from ssci full outer join csci on (ssci.customer_sk=csci.customer_sk - and ssci.item_sk = csci.item_sk) -limit 100; - --- end template query97.tpl query 66 in stream 10 --- start template query72.tpl query 67 in stream 10 -select /* TPC-DS query72.tpl 0.87 */ i_item_desc - ,w_warehouse_name - ,d1.d_week_seq - ,sum(case when p_promo_sk is null then 1 else 0 end) no_promo - ,sum(case when p_promo_sk is not null then 1 else 0 end) promo - ,count(*) total_cnt -from catalog_sales -join inventory on (cs_item_sk = inv_item_sk) -join warehouse on (w_warehouse_sk=inv_warehouse_sk) -join item on (i_item_sk = cs_item_sk) -join customer_demographics on (cs_bill_cdemo_sk = cd_demo_sk) -join household_demographics on (cs_bill_hdemo_sk = hd_demo_sk) -join date_dim d1 on (cs_sold_date_sk = d1.d_date_sk) -join date_dim d2 on (inv_date_sk = d2.d_date_sk) -join date_dim d3 on (cs_ship_date_sk = d3.d_date_sk) -left outer join promotion on (cs_promo_sk=p_promo_sk) -left outer join catalog_returns on (cr_item_sk = cs_item_sk and cr_order_number = cs_order_number) -where d1.d_week_seq = d2.d_week_seq - and inv_quantity_on_hand < cs_quantity - and d3.d_date > d1.d_date + 5 - and hd_buy_potential = '501-1000' - and d1.d_year = 1999 - and cd_marital_status = 'U' -group by i_item_desc,w_warehouse_name,d1.d_week_seq -order by total_cnt desc, i_item_desc, w_warehouse_name, d_week_seq -limit 100; - --- end template query72.tpl query 67 in stream 10 --- start template query75.tpl query 68 in stream 10 -WITH /* TPC-DS query75.tpl 0.3 */ all_sales AS ( - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,SUM(sales_cnt) AS sales_cnt - ,SUM(sales_amt) AS sales_amt - FROM (SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,cs_quantity - COALESCE(cr_return_quantity,0) AS sales_cnt - ,cs_ext_sales_price - COALESCE(cr_return_amount,0.0) AS sales_amt - FROM catalog_sales JOIN item ON i_item_sk=cs_item_sk - JOIN date_dim ON d_date_sk=cs_sold_date_sk - LEFT JOIN catalog_returns ON (cs_order_number=cr_order_number - AND cs_item_sk=cr_item_sk) - WHERE i_category='Women' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ss_quantity - COALESCE(sr_return_quantity,0) AS sales_cnt - ,ss_ext_sales_price - COALESCE(sr_return_amt,0.0) AS sales_amt - FROM store_sales JOIN item ON i_item_sk=ss_item_sk - JOIN date_dim ON d_date_sk=ss_sold_date_sk - LEFT JOIN store_returns ON (ss_ticket_number=sr_ticket_number - AND ss_item_sk=sr_item_sk) - WHERE i_category='Women' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ws_quantity - COALESCE(wr_return_quantity,0) AS sales_cnt - ,ws_ext_sales_price - COALESCE(wr_return_amt,0.0) AS sales_amt - FROM web_sales JOIN item ON i_item_sk=ws_item_sk - JOIN date_dim ON d_date_sk=ws_sold_date_sk - LEFT JOIN web_returns ON (ws_order_number=wr_order_number - AND ws_item_sk=wr_item_sk) - WHERE i_category='Women') sales_detail - GROUP BY d_year, i_brand_id, i_class_id, i_category_id, i_manufact_id) - SELECT prev_yr.d_year AS prev_year - ,curr_yr.d_year AS year - ,curr_yr.i_brand_id - ,curr_yr.i_class_id - ,curr_yr.i_category_id - ,curr_yr.i_manufact_id - ,prev_yr.sales_cnt AS prev_yr_cnt - ,curr_yr.sales_cnt AS curr_yr_cnt - ,curr_yr.sales_cnt-prev_yr.sales_cnt AS sales_cnt_diff - ,curr_yr.sales_amt-prev_yr.sales_amt AS sales_amt_diff - FROM all_sales curr_yr, all_sales prev_yr - WHERE curr_yr.i_brand_id=prev_yr.i_brand_id - AND curr_yr.i_class_id=prev_yr.i_class_id - AND curr_yr.i_category_id=prev_yr.i_category_id - AND curr_yr.i_manufact_id=prev_yr.i_manufact_id - AND curr_yr.d_year=2001 - AND prev_yr.d_year=2001-1 - AND CAST(curr_yr.sales_cnt AS DECIMAL(17,2))/CAST(prev_yr.sales_cnt AS DECIMAL(17,2))<0.9 - ORDER BY sales_cnt_diff,sales_amt_diff - limit 100; - --- end template query75.tpl query 68 in stream 10 --- start template query14a.tpl query 69 in stream 10 -with /* TPC-DS query14a.tpl 0.69 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1998 AND 1998 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1998 AND 1998 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1998 AND 1998 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as - (select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2) x) -, - results AS -(select channel, i_brand_id, i_class_id, i_category_id, sum(sales) sum_sales, sum(number_sales) number_sales - from ( - select 'store' channel, i_brand_id,i_class_id - ,i_category_id,sum(ss_quantity*ss_list_price) sales - , count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1998+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales) - union all - select 'catalog' channel, i_brand_id,i_class_id,i_category_id, sum(cs_quantity*cs_list_price) sales, count(*) number_sales - from catalog_sales - ,item - ,date_dim - where cs_item_sk in (select ss_item_sk from cross_items) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1998+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(cs_quantity*cs_list_price) > (select average_sales from avg_sales) - union all - select 'web' channel, i_brand_id,i_class_id,i_category_id, sum(ws_quantity*ws_list_price) sales , count(*) number_sales - from web_sales - ,item - ,date_dim - where ws_item_sk in (select ss_item_sk from cross_items) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1998+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ws_quantity*ws_list_price) > (select average_sales from avg_sales) - ) y - group by channel, i_brand_id,i_class_id,i_category_id) - - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales -from ( - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales from results - union - select channel, i_brand_id, i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id, i_class_id - union - select channel, i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id - union - select channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel - union - select null as channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results) z -order by channel, i_brand_id, i_class_id, i_category_id - limit 100; -with /* TPC-DS query14a.tpl 0.69 part2 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1998 AND 1998 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1998 AND 1998 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1998 AND 1998 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as -(select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2) x) - select this_year.channel ty_channel - ,this_year.i_brand_id ty_brand - ,this_year.i_class_id ty_class - ,this_year.i_category_id ty_category - ,this_year.sales ty_sales - ,this_year.number_sales ty_number_sales - ,last_year.channel ly_channel - ,last_year.i_brand_id ly_brand - ,last_year.i_class_id ly_class - ,last_year.i_category_id ly_category - ,last_year.sales ly_sales - ,last_year.number_sales ly_number_sales -from - (select 'store' channel, i_brand_id,i_class_id,i_category_id - ,sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1998 + 1 - and d_moy = 12 - and d_dom = 1) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) this_year, - (select 'store' channel, i_brand_id,i_class_id - ,i_category_id, sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1998 - and d_moy = 12 - and d_dom = 1) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) last_year - where this_year.i_brand_id= last_year.i_brand_id - and this_year.i_class_id = last_year.i_class_id - and this_year.i_category_id = last_year.i_category_id - order by this_year.channel, this_year.i_brand_id, this_year.i_class_id, this_year.i_category_id - limit 100; - --- end template query14a.tpl query 69 in stream 10 --- start template query40.tpl query 70 in stream 10 -select /* TPC-DS query40.tpl 0.86 */ - w_state - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('1999-02-02' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_before - ,sum(case when (cast(d_date as date) >= cast ('1999-02-02' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_after - from - catalog_sales left outer join catalog_returns on - (cs_order_number = cr_order_number - and cs_item_sk = cr_item_sk) - ,warehouse - ,item - ,date_dim - where - i_current_price between 0.99 and 1.49 - and i_item_sk = cs_item_sk - and cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('1999-02-02' as date)) - and dateadd(day,30,cast ('1999-02-02' as date)) - group by - w_state,i_item_id - order by w_state,i_item_id -limit 100; - --- end template query40.tpl query 70 in stream 10 --- start template query73.tpl query 71 in stream 10 -select /* TPC-DS query73.tpl 0.79 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_buy_potential = '501-1000' or - household_demographics.hd_buy_potential = '5001-10000') - and household_demographics.hd_vehicle_count > 0 - and case when household_demographics.hd_vehicle_count > 0 then - household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count else null end > 1 - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_county in ('Marshall County','Levy County','Kittitas County','Sumner County') - group by ss_ticket_number,ss_customer_sk) dj,customer - where ss_customer_sk = c_customer_sk - and cnt between 1 and 5 - order by cnt desc, c_last_name asc; - --- end template query73.tpl query 71 in stream 10 --- start template query79.tpl query 72 in stream 10 -select /* TPC-DS query79.tpl 0.89 */ - c_last_name,c_first_name,substring(s_city,1,30),ss_ticket_number,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,store.s_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (household_demographics.hd_dep_count = 4 or household_demographics.hd_vehicle_count > 4) - and date_dim.d_dow = 1 - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_number_employees between 200 and 295 - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,store.s_city) ms,customer - where ss_customer_sk = c_customer_sk - order by c_last_name,c_first_name,substring(s_city,1,30), profit -limit 100; - --- end template query79.tpl query 72 in stream 10 --- start template query11.tpl query 73 in stream 10 -with /* TPC-DS query11.tpl 0.51 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ss_ext_list_price-ss_ext_discount_amt) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ws_ext_list_price-ws_ext_discount_amt) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_birth_country - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 1999 - and t_s_secyear.dyear = 1999+1 - and t_w_firstyear.dyear = 1999 - and t_w_secyear.dyear = 1999+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else 0.0 end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else 0.0 end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_birth_country -limit 100; - --- end template query11.tpl query 73 in stream 10 --- start template query6.tpl query 74 in stream 10 -select /* TPC-DS query6.tpl 0.58 */ a.ca_state state, count(*) cnt - from customer_address a - ,customer c - ,store_sales s - ,date_dim d - ,item i - where a.ca_address_sk = c.c_current_addr_sk - and c.c_customer_sk = s.ss_customer_sk - and s.ss_sold_date_sk = d.d_date_sk - and s.ss_item_sk = i.i_item_sk - and d.d_month_seq = - (select distinct (d_month_seq) - from date_dim - where d_year = 1998 - and d_moy = 4 ) - and i.i_current_price > 1.2 * - (select avg(j.i_current_price) - from item j - where j.i_category = i.i_category) - group by a.ca_state - having count(*) >= 10 - order by cnt, a.ca_state - limit 100; - --- end template query6.tpl query 74 in stream 10 --- start template query17.tpl query 75 in stream 10 -select /* TPC-DS query17.tpl 0.41 */ i_item_id - ,i_item_desc - ,s_state - ,count(ss_quantity) as store_sales_quantitycount - ,avg(ss_quantity) as store_sales_quantityave - ,stddev_samp(ss_quantity) as store_sales_quantitystdev - ,stddev_samp(ss_quantity)/avg(ss_quantity) as store_sales_quantitycov - ,count(sr_return_quantity) as store_returns_quantitycount - ,avg(sr_return_quantity) as store_returns_quantityave - ,stddev_samp(sr_return_quantity) as store_returns_quantitystdev - ,stddev_samp(sr_return_quantity)/avg(sr_return_quantity) as store_returns_quantitycov - ,count(cs_quantity) as catalog_sales_quantitycount ,avg(cs_quantity) as catalog_sales_quantityave - ,stddev_samp(cs_quantity) as catalog_sales_quantitystdev - ,stddev_samp(cs_quantity)/avg(cs_quantity) as catalog_sales_quantitycov - from store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where d1.d_quarter_name = '2002Q1' - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_quarter_name in ('2002Q1','2002Q2','2002Q3') - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_quarter_name in ('2002Q1','2002Q2','2002Q3') - group by i_item_id - ,i_item_desc - ,s_state - order by i_item_id - ,i_item_desc - ,s_state -limit 100; - --- end template query17.tpl query 75 in stream 10 --- start template query58.tpl query 76 in stream 10 -with /* TPC-DS query58.tpl 0.19 */ ss_items as - (select i_item_id item_id - ,sum(ss_ext_sales_price) ss_item_rev - from store_sales - ,item - ,date_dim - where ss_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '2002-05-24')) - and ss_sold_date_sk = d_date_sk - group by i_item_id), - cs_items as - (select i_item_id item_id - ,sum(cs_ext_sales_price) cs_item_rev - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '2002-05-24')) - and cs_sold_date_sk = d_date_sk - group by i_item_id), - ws_items as - (select i_item_id item_id - ,sum(ws_ext_sales_price) ws_item_rev - from web_sales - ,item - ,date_dim - where ws_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq =(select d_week_seq - from date_dim - where d_date = '2002-05-24')) - and ws_sold_date_sk = d_date_sk - group by i_item_id) - select ss_items.item_id - ,ss_item_rev - ,ss_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ss_dev - ,cs_item_rev - ,cs_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 cs_dev - ,ws_item_rev - ,ws_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ws_dev - ,(ss_item_rev+cs_item_rev+ws_item_rev)/3 average - from ss_items,cs_items,ws_items - where ss_items.item_id=cs_items.item_id - and ss_items.item_id=ws_items.item_id - and ss_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - and ss_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and cs_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and cs_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and ws_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and ws_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - order by item_id - ,ss_item_rev - limit 100; - --- end template query58.tpl query 76 in stream 10 --- start template query56.tpl query 77 in stream 10 -with /* TPC-DS query56.tpl 0.83 */ ss as ( - select i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where i_item_id in (select - i_item_id -from item -where i_color in ('salmon','coral','burlywood')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 4 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - cs as ( - select i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('salmon','coral','burlywood')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 4 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - ws as ( - select i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('salmon','coral','burlywood')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 4 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id) - select i_item_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by total_sales, - i_item_id - limit 100; - --- end template query56.tpl query 77 in stream 10 --- start template query83.tpl query 78 in stream 10 -with /* TPC-DS query83.tpl 0.96 */ sr_items as - (select i_item_id item_id, - sum(sr_return_quantity) sr_item_qty - from store_returns, - item, - date_dim - where sr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2002-06-12','2002-08-15','2002-11-05'))) - and sr_returned_date_sk = d_date_sk - group by i_item_id), - cr_items as - (select i_item_id item_id, - sum(cr_return_quantity) cr_item_qty - from catalog_returns, - item, - date_dim - where cr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2002-06-12','2002-08-15','2002-11-05'))) - and cr_returned_date_sk = d_date_sk - group by i_item_id), - wr_items as - (select i_item_id item_id, - sum(wr_return_quantity) wr_item_qty - from web_returns, - item, - date_dim - where wr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2002-06-12','2002-08-15','2002-11-05'))) - and wr_returned_date_sk = d_date_sk - group by i_item_id) - select sr_items.item_id - ,sr_item_qty - ,sr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 sr_dev - ,cr_item_qty - ,cr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 cr_dev - ,wr_item_qty - ,wr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 wr_dev - ,(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 average - from sr_items - ,cr_items - ,wr_items - where sr_items.item_id=cr_items.item_id - and sr_items.item_id=wr_items.item_id - order by sr_items.item_id - ,sr_item_qty - limit 100; - --- end template query83.tpl query 78 in stream 10 --- start template query51.tpl query 79 in stream 10 -WITH /* TPC-DS query51.tpl 0.46 */ web_v1 as ( -select - ws_item_sk item_sk, d_date, - sum(sum(ws_sales_price)) - over (partition by ws_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from web_sales - ,date_dim -where ws_sold_date_sk=d_date_sk - and d_month_seq between 1202 and 1202+11 - and ws_item_sk is not NULL -group by ws_item_sk, d_date), -store_v1 as ( -select - ss_item_sk item_sk, d_date, - sum(sum(ss_sales_price)) - over (partition by ss_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from store_sales - ,date_dim -where ss_sold_date_sk=d_date_sk - and d_month_seq between 1202 and 1202+11 - and ss_item_sk is not NULL -group by ss_item_sk, d_date) - select * -from (select item_sk - ,d_date - ,web_sales - ,store_sales - ,max(web_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) web_cumulative - ,max(store_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) store_cumulative - from (select case when web.item_sk is not null then web.item_sk else store.item_sk end item_sk - ,case when web.d_date is not null then web.d_date else store.d_date end d_date - ,web.cume_sales web_sales - ,store.cume_sales store_sales - from web_v1 web full outer join store_v1 store on (web.item_sk = store.item_sk - and web.d_date = store.d_date) - )x )y -where web_cumulative > store_cumulative -order by item_sk - ,d_date -limit 100; - --- end template query51.tpl query 79 in stream 10 --- start template query29.tpl query 80 in stream 10 -select /* TPC-DS query29.tpl 0.53 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,avg(ss_quantity) as store_sales_quantity - ,avg(sr_return_quantity) as store_returns_quantity - ,avg(cs_quantity) as catalog_sales_quantity - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 1998 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 4 + 3 - and d2.d_year = 1998 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_year in (1998,1998+1,1998+2) - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query29.tpl query 80 in stream 10 --- start template query22a.tpl query 81 in stream 10 -with /* TPC-DS query22a.tpl 0.55 */ results as -(select i_product_name - ,i_brand - ,i_class - ,i_category - ,avg(inv_quantity_on_hand) qoh - from inventory - ,date_dim - ,item --- ,warehouse - where inv_date_sk=d_date_sk - and inv_item_sk=i_item_sk --- and inv_warehouse_sk = w_warehouse_sk - and d_month_seq between 1201 and 1201 + 11 - group by i_product_name,i_brand,i_class,i_category), -results_rollup as -(select i_product_name, i_brand, i_class, i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class,i_category -union all -select i_product_name, i_brand, i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class -union all -select i_product_name, i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand -union all -select i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name -union all -select null i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results) - select i_product_name, i_brand, i_class, i_category,qoh - from results_rollup - order by qoh, i_product_name, i_brand, i_class, i_category -limit 100; - --- end template query22a.tpl query 81 in stream 10 --- start template query71.tpl query 82 in stream 10 -select /* TPC-DS query71.tpl 0.72 */ i_brand_id brand_id, i_brand brand,t_hour,t_minute, - sum(ext_price) ext_price - from item, (select ws_ext_sales_price as ext_price, - ws_sold_date_sk as sold_date_sk, - ws_item_sk as sold_item_sk, - ws_sold_time_sk as time_sk - from web_sales,date_dim - where d_date_sk = ws_sold_date_sk - and d_moy=12 - and d_year=1998 - union all - select cs_ext_sales_price as ext_price, - cs_sold_date_sk as sold_date_sk, - cs_item_sk as sold_item_sk, - cs_sold_time_sk as time_sk - from catalog_sales,date_dim - where d_date_sk = cs_sold_date_sk - and d_moy=12 - and d_year=1998 - union all - select ss_ext_sales_price as ext_price, - ss_sold_date_sk as sold_date_sk, - ss_item_sk as sold_item_sk, - ss_sold_time_sk as time_sk - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - and d_moy=12 - and d_year=1998 - ) tmp,time_dim - where - sold_item_sk = i_item_sk - and i_manager_id=1 - and time_sk = t_time_sk - and (t_meal_time = 'breakfast' or t_meal_time = 'dinner') - group by i_brand, i_brand_id,t_hour,t_minute - order by ext_price desc, i_brand_id - ; - --- end template query71.tpl query 82 in stream 10 --- start template query68.tpl query 83 in stream 10 -select /* TPC-DS query68.tpl 0.95 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,extended_price - ,extended_tax - ,list_price - from (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_ext_sales_price) extended_price - ,sum(ss_ext_list_price) list_price - ,sum(ss_ext_tax) extended_tax - from store_sales - ,date_dim - ,store - ,household_demographics - ,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_dep_count = 1 or - household_demographics.hd_vehicle_count= -1) - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_city in ('Shady Grove','Oak Ridge') - group by ss_ticket_number - ,ss_customer_sk - ,ss_addr_sk,ca_city) dn - ,customer - ,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,ss_ticket_number - limit 100; - --- end template query68.tpl query 83 in stream 10 --- start template query60.tpl query 84 in stream 10 -with /* TPC-DS query60.tpl 0.29 */ ss as ( - select - i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Music')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 8 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id), - cs as ( - select - i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Music')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 8 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id), - ws as ( - select - i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Music')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 8 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id) - select - i_item_id -,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by i_item_id - ,total_sales - limit 100; - --- end template query60.tpl query 84 in stream 10 --- start template query12.tpl query 85 in stream 10 -select /* TPC-DS query12.tpl 0.64 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ws_ext_sales_price) as itemrevenue - ,sum(ws_ext_sales_price)*100/sum(sum(ws_ext_sales_price)) over - (partition by i_class) as revenueratio -from - web_sales - ,item - ,date_dim -where - ws_item_sk = i_item_sk - and i_category in ('Shoes', 'Women', 'Sports') - and ws_sold_date_sk = d_date_sk - and d_date between cast('2001-05-24' as date) - and dateadd(day,30,cast('2001-05-24' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query12.tpl query 85 in stream 10 --- start template query4.tpl query 86 in stream 10 -with /* TPC-DS query4.tpl 0.93 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(((ss_ext_list_price-ss_ext_wholesale_cost-ss_ext_discount_amt)+ss_ext_sales_price)/2) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((cs_ext_list_price-cs_ext_wholesale_cost-cs_ext_discount_amt)+cs_ext_sales_price)/2) ) year_total - ,'c' sale_type - from customer - ,catalog_sales - ,date_dim - where c_customer_sk = cs_bill_customer_sk - and cs_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year -union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((ws_ext_list_price-ws_ext_wholesale_cost-ws_ext_discount_amt)+ws_ext_sales_price)/2) ) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_email_address - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_c_firstyear - ,year_total t_c_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_c_secyear.customer_id - and t_s_firstyear.customer_id = t_c_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_c_firstyear.sale_type = 'c' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_c_secyear.sale_type = 'c' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 1999 - and t_s_secyear.dyear = 1999+1 - and t_c_firstyear.dyear = 1999 - and t_c_secyear.dyear = 1999+1 - and t_w_firstyear.dyear = 1999 - and t_w_secyear.dyear = 1999+1 - and t_s_firstyear.year_total > 0 - and t_c_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_email_address -limit 100; - --- end template query4.tpl query 86 in stream 10 --- start template query89.tpl query 87 in stream 10 -select /* TPC-DS query89.tpl 0.56 */ * -from( -select i_category, i_class, i_brand, - s_store_name, s_company_name, - d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, s_store_name, s_company_name) - avg_monthly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - d_year in (1999) and - ((i_category in ('Music','Men','Electronics') and - i_class in ('rock','shirts','monitors') - ) - or (i_category in ('Children','Sports','Shoes') and - i_class in ('toddlers','pools','mens') - )) -group by i_category, i_class, i_brand, - s_store_name, s_company_name, d_moy) tmp1 -where case when (avg_monthly_sales <> 0) then (abs(sum_sales - avg_monthly_sales) / avg_monthly_sales) else null end > 0.1 -order by sum_sales - avg_monthly_sales, s_store_name -limit 100; - --- end template query89.tpl query 87 in stream 10 --- start template query61.tpl query 88 in stream 10 -select /* TPC-DS query61.tpl 0.97 */ promotions,total,cast(promotions as decimal(15,4))/cast(total as decimal(15,4))*100 -from - (select sum(ss_ext_sales_price) promotions - from store_sales - ,store - ,promotion - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_promo_sk = p_promo_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -7 - and i_category = 'Jewelry' - and (p_channel_dmail = 'Y' or p_channel_email = 'Y' or p_channel_tv = 'Y') - and s_gmt_offset = -7 - and d_year = 1998 - and d_moy = 12) promotional_sales, - (select sum(ss_ext_sales_price) total - from store_sales - ,store - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -7 - and i_category = 'Jewelry' - and s_gmt_offset = -7 - and d_year = 1998 - and d_moy = 12) all_sales -order by promotions, total -limit 100; - --- end template query61.tpl query 88 in stream 10 --- start template query46.tpl query 89 in stream 10 -select /* TPC-DS query46.tpl 0.23 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and (household_demographics.hd_dep_count = 7 or - household_demographics.hd_vehicle_count= 0) - and date_dim.d_dow in (6,0) - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_city in ('Clifton','Riverview','Stringtown','Woodville','Mount Vernon') - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,ca_city) dn,customer,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - limit 100; - --- end template query46.tpl query 89 in stream 10 --- start template query92.tpl query 90 in stream 10 -select /* TPC-DS query92.tpl 0.44 */ - sum(ws_ext_discount_amt) as "Excess Discount Amount" -from - web_sales - ,item - ,date_dim -where -i_manufact_id = 643 -and i_item_sk = ws_item_sk -and d_date between '1999-03-12' and - dateadd(day,90,cast('1999-03-12' as date)) -and d_date_sk = ws_sold_date_sk -and ws_ext_discount_amt - > ( - SELECT - 1.3 * avg(ws_ext_discount_amt) - FROM - web_sales - ,date_dim - WHERE - ws_item_sk = i_item_sk - and d_date between '1999-03-12' and - dateadd(day,90,cast('1999-03-12' as date)) - and d_date_sk = ws_sold_date_sk - ) -order by sum(ws_ext_discount_amt) -limit 100; - --- end template query92.tpl query 90 in stream 10 --- start template query13.tpl query 91 in stream 10 -select /* TPC-DS query13.tpl 0.91 */ avg(ss_quantity) - ,avg(ss_ext_sales_price) - ,avg(ss_ext_wholesale_cost) - ,sum(ss_ext_wholesale_cost) - from store_sales - ,store - ,customer_demographics - ,household_demographics - ,customer_address - ,date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2001 - and((ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'S' - and cd_education_status = '4 yr Degree' - and ss_sales_price between 100.00 and 150.00 - and hd_dep_count = 3 - )or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'W' - and cd_education_status = 'Secondary' - and ss_sales_price between 50.00 and 100.00 - and hd_dep_count = 1 - ) or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'D' - and cd_education_status = 'Advanced Degree' - and ss_sales_price between 150.00 and 200.00 - and hd_dep_count = 1 - )) - and((ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('KS', 'OH', 'CA') - and ss_net_profit between 100 and 200 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('IA', 'IL', 'WI') - and ss_net_profit between 150 and 300 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('PA', 'TX', 'NJ') - and ss_net_profit between 50 and 250 - )) -; - --- end template query13.tpl query 91 in stream 10 --- start template query9.tpl query 92 in stream 10 -select /* TPC-DS query9.tpl 0.49 */ case when (select count(*) - from store_sales - where ss_quantity between 1 and 20) > 54286959 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 1 and 20) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 1 and 20) end bucket1 , - case when (select count(*) - from store_sales - where ss_quantity between 21 and 40) > 128172808 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 21 and 40) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 21 and 40) end bucket2, - case when (select count(*) - from store_sales - where ss_quantity between 41 and 60) > 15948959 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 41 and 60) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 41 and 60) end bucket3, - case when (select count(*) - from store_sales - where ss_quantity between 61 and 80) > 7664642 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 61 and 80) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 61 and 80) end bucket4, - case when (select count(*) - from store_sales - where ss_quantity between 81 and 100) > 30700090 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 81 and 100) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 81 and 100) end bucket5 -from reason -where r_reason_sk = 1 -; - --- end template query9.tpl query 92 in stream 10 --- start template query74.tpl query 93 in stream 10 -with /* TPC-DS query74.tpl 0.76 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,min(ss_net_paid) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (2000,2000+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,min(ws_net_paid) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - and d_year in (2000,2000+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - ) - select - t_s_secyear.customer_id, t_s_secyear.customer_first_name, t_s_secyear.customer_last_name - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.year = 2000 - and t_s_secyear.year = 2000+1 - and t_w_firstyear.year = 2000 - and t_w_secyear.year = 2000+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - order by 3,1,2 -limit 100; - --- end template query74.tpl query 93 in stream 10 --- start template query8.tpl query 94 in stream 10 -select /* TPC-DS query8.tpl 0.63 */ s_store_name - ,sum(ss_net_profit) - from store_sales - ,date_dim - ,store, - (select ca_zip - from ( - SELECT substring(ca_zip,1,5) ca_zip - FROM customer_address - WHERE substring(ca_zip,1,5) IN ( - '55450','90516','81277','70764','17234','41349', - '95067','28262','74462','95913','84854', - '60972','95597','35589','56554','35346', - '23514','38334','11919','35908','35353', - '35434','14326','32198','58559','88017', - '64397','76301','99560','85481','66733', - '92758','20993','26222','45543','73029', - '99719','44400','77543','83616','76641', - '94342','88834','94818','65770','48314', - '82084','49404','43470','61534','74626', - '71361','12279','44531','53223','31346', - '24545','52587','22250','40221','64819', - '86063','29059','98980','95439','92571', - '67324','68918','64065','62539','10155', - '32556','86818','27272','29675','59359', - '82324','59936','61136','10904','12463', - '21204','31445','33279','84515','80802', - '37229','48593','10428','21358','69697', - '67373','77506','24532','23244','88161', - '83775','81714','44444','51181','62005', - '25197','47185','59301','10750','92663', - '67578','84199','86089','54082','71251', - '98235','58947','69311','55083','62360', - '24911','10543','87501','81044','92879', - '19586','68063','81721','88712','72769', - '20799','44911','58016','46070','78729', - '62221','45952','29418','74664','71172', - '37889','81943','13616','37823','94684', - '94244','53234','82280','19210','79460', - '11820','64499','86547','72145','45904', - '96972','11792','72997','62144','33012', - '43403','86785','11817','98357','40801', - '41087','67539','38940','91012','84379', - '35226','13936','85945','49641','10658', - '83360','74443','94021','65796','82984', - '16210','50069','18052','72519','42170', - '73727','13460','48986','73794','54939', - '34245','21373','57817','96154','65699', - '75098','59078','97143','36108','90272', - '27466','51075','91034','49463','68627', - '97202','67213','26841','19255','33825', - '19588','28422','65378','57737','20855', - '68159','39130','20120','88282','74163', - '94773','17987','41375','48068','97405', - '65685','13428','88584','75122','11249', - '16065','92361','38576','33573','21891', - '28164','60504','75558','76901','82091', - '17700','38328','29126','46344','93429', - '33926','30575','53925','84706','46506', - '37564','29506','99596','50471','98091', - '61371','97119','66179','70749','67094', - '71837','32564','49005','66531','87958', - '26558','42985','29450','21875','40367', - '19639','45002','90766','57463','11383', - '83514','13921','75067','39842','13343', - '71199','20952','11797','24334','89837', - '21641','86931','80518','71144','83367', - '94849','32896','96636','48400','82595', - '56813','84704','57959','60758','34285', - '37929','73127','17691','22778','18438', - '65441','87706','39171','82488','67786', - '47591','65591','14287','88340','26673', - '80626','10012','16978','21845','71569', - '25463','34443','24797','22252','93498', - '94304','61495','70119','98548','31005', - '60067','29606','17427','83889','45365', - '56231','28753','83825','96337','53893', - '95221','24308','81797','13898','53782', - '91319','45335','81675','43071','56892', - '71961','89321','92661','14715','51669', - '30767','40863','72373','36321','89451', - '52498','35303','10449','26715','60142', - '20180','45873','71372','20334','97638', - '98237','45614','89517','93468','86284', - '56119','54328','18249','75229','88157', - '54376','19676','86934','99653','75729', - '57076','62264','65637','56464','24214', - '23028','72100','79438','64628','52988', - '34129','52373','37013','23803','67789', - '27591','81464','26887','40759') - intersect - select ca_zip - from (SELECT substring(ca_zip,1,5) ca_zip,count(*) cnt - FROM customer_address, customer - WHERE ca_address_sk = c_current_addr_sk and - c_preferred_cust_flag='Y' - group by ca_zip - having count(*) > 10)A1)A2) V1 - where ss_store_sk = s_store_sk - and ss_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 2001 - and (substring(s_zip,1,2) = substring(V1.ca_zip,1,2)) - group by s_store_name - order by s_store_name - limit 100; - --- end template query8.tpl query 94 in stream 10 --- start template query3.tpl query 95 in stream 10 -select /* TPC-DS query3.tpl 0.45 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_discount_amt) sum_agg - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manufact_id = 400 - and dt.d_moy=11 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,sum_agg desc - ,brand_id - limit 100; - --- end template query3.tpl query 95 in stream 10 --- start template query95.tpl query 96 in stream 10 -with /* TPC-DS query95.tpl 0.43 */ ws_wh as -(select ws1.ws_order_number,ws1.ws_warehouse_sk wh1,ws2.ws_warehouse_sk wh2 - from web_sales ws1,web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) - select - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2000-2-01' and - dateadd(day,60,cast('2000-2-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'NC' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and ws1.ws_order_number in (select ws_order_number - from ws_wh) -and ws1.ws_order_number in (select wr_order_number - from web_returns,ws_wh - where wr_order_number = ws_wh.ws_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query95.tpl query 96 in stream 10 --- start template query26.tpl query 97 in stream 10 -select /* TPC-DS query26.tpl 0.85 */ i_item_id, - avg(cs_quantity) agg1, - avg(cs_list_price) agg2, - avg(cs_coupon_amt) agg3, - avg(cs_sales_price) agg4 - from catalog_sales, customer_demographics, date_dim, item, promotion - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd_demo_sk and - cs_promo_sk = p_promo_sk and - cd_gender = 'M' and - cd_marital_status = 'U' and - cd_education_status = 'Unknown' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 2001 - group by i_item_id - order by i_item_id - limit 100; - --- end template query26.tpl query 97 in stream 10 --- start template query81.tpl query 98 in stream 10 -with /* TPC-DS query81.tpl 0.37 */ customer_total_return as - (select cr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(cr_return_amt_inc_tax) as ctr_total_return - from catalog_returns - ,date_dim - ,customer_address - where cr_returned_date_sk = d_date_sk - and d_year =2000 - and cr_returning_addr_sk = ca_address_sk - group by cr_returning_customer_sk - ,ca_state ) - select c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'IA' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - limit 100; - --- end template query81.tpl query 98 in stream 10 --- start template query19.tpl query 99 in stream 10 -select /* TPC-DS query19.tpl 0.8 */ i_brand_id brand_id, i_brand brand, i_manufact_id, i_manufact, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item,customer,customer_address,store - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=14 - and d_moy=11 - and d_year=2000 - and ss_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and substring(ca_zip,1,5) <> substring(s_zip,1,5) - and ss_store_sk = s_store_sk - group by i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact - order by ext_price desc - ,i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact -limit 100 ; - --- end template query19.tpl query 99 in stream 10 diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/10TB/queries/query_2.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/10TB/queries/query_2.sql deleted file mode 100644 index 66abac20..00000000 --- a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/10TB/queries/query_2.sql +++ /dev/null @@ -1,5027 +0,0 @@ --- start template query56.tpl query 1 in stream 2 -with /* TPC-DS query56.tpl 0.83 */ ss as ( - select i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where i_item_id in (select - i_item_id -from item -where i_color in ('antique','orchid','beige')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 3 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - cs as ( - select i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('antique','orchid','beige')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 3 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - ws as ( - select i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('antique','orchid','beige')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 3 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id) - select i_item_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by total_sales, - i_item_id - limit 100; - --- end template query56.tpl query 1 in stream 2 --- start template query98.tpl query 2 in stream 2 -select /* TPC-DS query98.tpl 0.32 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ss_ext_sales_price) as itemrevenue - ,sum(ss_ext_sales_price)*100/sum(sum(ss_ext_sales_price)) over - (partition by i_class) as revenueratio -from - store_sales - ,item - ,date_dim -where - ss_item_sk = i_item_sk - and i_category in ('Music', 'Electronics', 'Books') - and ss_sold_date_sk = d_date_sk - and d_date between cast('1999-02-26' as date) - and dateadd(day,30,cast('1999-02-26' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio; - --- end template query98.tpl query 2 in stream 2 --- start template query59.tpl query 3 in stream 2 -with /* TPC-DS query59.tpl 0.30 */ wss as - (select d_week_seq, - ss_store_sk, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - group by d_week_seq,ss_store_sk - ) - select s_store_name1,s_store_id1,d_week_seq1 - ,sun_sales1/sun_sales2,mon_sales1/mon_sales2 - ,tue_sales1/tue_sales2,wed_sales1/wed_sales2,thu_sales1/thu_sales2 - ,fri_sales1/fri_sales2,sat_sales1/sat_sales2 - from - (select s_store_name s_store_name1,wss.d_week_seq d_week_seq1 - ,s_store_id s_store_id1,sun_sales sun_sales1 - ,mon_sales mon_sales1,tue_sales tue_sales1 - ,wed_sales wed_sales1,thu_sales thu_sales1 - ,fri_sales fri_sales1,sat_sales sat_sales1 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1203 and 1203 + 11) y, - (select s_store_name s_store_name2,wss.d_week_seq d_week_seq2 - ,s_store_id s_store_id2,sun_sales sun_sales2 - ,mon_sales mon_sales2,tue_sales tue_sales2 - ,wed_sales wed_sales2,thu_sales thu_sales2 - ,fri_sales fri_sales2,sat_sales sat_sales2 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1203+ 12 and 1203 + 23) x - where s_store_id1=s_store_id2 - and d_week_seq1=d_week_seq2-52 - order by s_store_name1,s_store_id1,d_week_seq1 -limit 100; - --- end template query59.tpl query 3 in stream 2 --- start template query24.tpl query 4 in stream 2 -with /* TPC-DS query24.tpl 0.92 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_net_profit) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip -and s_market_id=6 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'cyan' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; -with /* TPC-DS query24.tpl 0.92 part2 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_net_profit) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip - and s_market_id = 6 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'grey' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; - --- end template query24.tpl query 4 in stream 2 --- start template query88.tpl query 5 in stream 2 -select /* TPC-DS query88.tpl 0.66 */ * -from - (select count(*) h8_30_to_9 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s1, - (select count(*) h9_to_9_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s2, - (select count(*) h9_30_to_10 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s3, - (select count(*) h10_to_10_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s4, - (select count(*) h10_30_to_11 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s5, - (select count(*) h11_to_11_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s6, - (select count(*) h11_30_to_12 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s7, - (select count(*) h12_to_12_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 12 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s8 -; - --- end template query88.tpl query 5 in stream 2 --- start template query2.tpl query 6 in stream 2 -with /* TPC-DS query2.tpl 0.84 */ wscs as - (select sold_date_sk - ,sales_price - from (select ws_sold_date_sk sold_date_sk - ,ws_ext_sales_price sales_price - from web_sales - union all - select cs_sold_date_sk sold_date_sk - ,cs_ext_sales_price sales_price - from catalog_sales)), - wswscs as - (select d_week_seq, - sum(case when (d_day_name='Sunday') then sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then sales_price else null end) sat_sales - from wscs - ,date_dim - where d_date_sk = sold_date_sk - group by d_week_seq) - select d_week_seq1 - ,round(sun_sales1/sun_sales2,2) - ,round(mon_sales1/mon_sales2,2) - ,round(tue_sales1/tue_sales2,2) - ,round(wed_sales1/wed_sales2,2) - ,round(thu_sales1/thu_sales2,2) - ,round(fri_sales1/fri_sales2,2) - ,round(sat_sales1/sat_sales2,2) - from - (select wswscs.d_week_seq d_week_seq1 - ,sun_sales sun_sales1 - ,mon_sales mon_sales1 - ,tue_sales tue_sales1 - ,wed_sales wed_sales1 - ,thu_sales thu_sales1 - ,fri_sales fri_sales1 - ,sat_sales sat_sales1 - from wswscs,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 2001) y, - (select wswscs.d_week_seq d_week_seq2 - ,sun_sales sun_sales2 - ,mon_sales mon_sales2 - ,tue_sales tue_sales2 - ,wed_sales wed_sales2 - ,thu_sales thu_sales2 - ,fri_sales fri_sales2 - ,sat_sales sat_sales2 - from wswscs - ,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 2001+1) z - where d_week_seq1=d_week_seq2-53 - order by d_week_seq1; - --- end template query2.tpl query 6 in stream 2 --- start template query5a.tpl query 7 in stream 2 -with /* TPC-DS query5a.tpl 0.98 */ ssr as - (select s_store_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ss_store_sk as store_sk, - ss_sold_date_sk as date_sk, - ss_ext_sales_price as sales_price, - ss_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from store_sales - union all - select sr_store_sk as store_sk, - sr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - sr_return_amt as return_amt, - sr_net_loss as net_loss - from store_returns - ) salesreturns, - date_dim, - store - where date_sk = d_date_sk - and d_date between cast('2001-08-15' as date) - and dateadd(day,14,cast('2001-08-15' as date)) - and store_sk = s_store_sk - group by s_store_id) - , - csr as - (select cp_catalog_page_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select cs_catalog_page_sk as page_sk, - cs_sold_date_sk as date_sk, - cs_ext_sales_price as sales_price, - cs_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from catalog_sales - union all - select cr_catalog_page_sk as page_sk, - cr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - cr_return_amount as return_amt, - cr_net_loss as net_loss - from catalog_returns - ) salesreturns, - date_dim, - catalog_page - where date_sk = d_date_sk - and d_date between cast('2001-08-15' as date) - and dateadd(day,14,cast('2001-08-15' as date)) - and page_sk = cp_catalog_page_sk - group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ws_web_site_sk as wsr_web_site_sk, - ws_sold_date_sk as date_sk, - ws_ext_sales_price as sales_price, - ws_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from web_sales - union all - select ws_web_site_sk as wsr_web_site_sk, - wr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - wr_return_amt as return_amt, - wr_net_loss as net_loss - from web_returns left outer join web_sales on - ( wr_item_sk = ws_item_sk - and wr_order_number = ws_order_number) - ) salesreturns, - date_dim, - web_site - where date_sk = d_date_sk - and d_date between cast('2001-08-15' as date) - and dateadd(day,14,cast('2001-08-15' as date)) - and wsr_web_site_sk = web_site_sk - group by web_site_id) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || s_store_id as id - , sales - , returns - , (profit - profit_loss) as profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || cp_catalog_page_id as id - , sales - , returns - , (profit - profit_loss) as profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , (profit - profit_loss) as profit - from wsr - ) x - group by channel, id) - select channel, id, sales, returns, profit from ( - select channel, id, sales, returns, profit from results - union - select channel, null as id, sum(sales), sum(returns), sum(profit) from results group by channel - union - select null as channel, null as id, sum(sales), sum(returns), sum(profit) from results) foo -order by channel, id -limit 100; - --- end template query5a.tpl query 7 in stream 2 --- start template query6.tpl query 8 in stream 2 -select /* TPC-DS query6.tpl 0.58 */ a.ca_state state, count(*) cnt - from customer_address a - ,customer c - ,store_sales s - ,date_dim d - ,item i - where a.ca_address_sk = c.c_current_addr_sk - and c.c_customer_sk = s.ss_customer_sk - and s.ss_sold_date_sk = d.d_date_sk - and s.ss_item_sk = i.i_item_sk - and d.d_month_seq = - (select distinct (d_month_seq) - from date_dim - where d_year = 2002 - and d_moy = 7 ) - and i.i_current_price > 1.2 * - (select avg(j.i_current_price) - from item j - where j.i_category = i.i_category) - group by a.ca_state - having count(*) >= 10 - order by cnt, a.ca_state - limit 100; - --- end template query6.tpl query 8 in stream 2 --- start template query27a.tpl query 9 in stream 2 -with /* TPC-DS query27a.tpl 0.16 */ results as - (select i_item_id, - s_state, 0 as g_state, - ss_quantity agg1, - ss_list_price agg2, - ss_coupon_amt agg3, - ss_sales_price agg4 - from store_sales, customer_demographics, date_dim, store, item - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_store_sk = s_store_sk and - ss_cdemo_sk = cd_demo_sk and - cd_gender = 'M' and - cd_marital_status = 'S' and - cd_education_status = 'College' and - d_year = 2001 and - s_state in ('NY','AL', 'MN', 'WV', 'NC', 'GA') - ) - - select i_item_id, - s_state, g_state, agg1, agg2, agg3, agg4 - from ( - select i_item_id, s_state, 0 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4 from results - group by i_item_id, s_state - union all - select i_item_id, NULL AS s_state, 1 AS g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as s_state, 1 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - ) foo - order by i_item_id, s_state - limit 100; - --- end template query27a.tpl query 9 in stream 2 --- start template query87.tpl query 10 in stream 2 -select /* TPC-DS query87.tpl 0.77 */ count(*) -from ((select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1197 and 1197+11) - except - (select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1197 and 1197+11) - except - (select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1197 and 1197+11) -) cool_cust -; - --- end template query87.tpl query 10 in stream 2 --- start template query90.tpl query 11 in stream 2 -select /* TPC-DS query90.tpl 0.40 */ cast(amc as decimal(15,4))/cast(pmc as decimal(15,4)) am_pm_ratio - from ( select count(*) amc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 8 and 8+1 - and household_demographics.hd_dep_count = 1 - and web_page.wp_char_count between 5000 and 5200) at, - ( select count(*) pmc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 21 and 21+1 - and household_demographics.hd_dep_count = 1 - and web_page.wp_char_count between 5000 and 5200) pt - order by am_pm_ratio - limit 100; - --- end template query90.tpl query 11 in stream 2 --- start template query83.tpl query 12 in stream 2 -with /* TPC-DS query83.tpl 0.96 */ sr_items as - (select i_item_id item_id, - sum(sr_return_quantity) sr_item_qty - from store_returns, - item, - date_dim - where sr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2002-06-29','2002-09-09','2002-11-10'))) - and sr_returned_date_sk = d_date_sk - group by i_item_id), - cr_items as - (select i_item_id item_id, - sum(cr_return_quantity) cr_item_qty - from catalog_returns, - item, - date_dim - where cr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2002-06-29','2002-09-09','2002-11-10'))) - and cr_returned_date_sk = d_date_sk - group by i_item_id), - wr_items as - (select i_item_id item_id, - sum(wr_return_quantity) wr_item_qty - from web_returns, - item, - date_dim - where wr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2002-06-29','2002-09-09','2002-11-10'))) - and wr_returned_date_sk = d_date_sk - group by i_item_id) - select sr_items.item_id - ,sr_item_qty - ,sr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 sr_dev - ,cr_item_qty - ,cr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 cr_dev - ,wr_item_qty - ,wr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 wr_dev - ,(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 average - from sr_items - ,cr_items - ,wr_items - where sr_items.item_id=cr_items.item_id - and sr_items.item_id=wr_items.item_id - order by sr_items.item_id - ,sr_item_qty - limit 100; - --- end template query83.tpl query 12 in stream 2 --- start template query91.tpl query 13 in stream 2 -select /* TPC-DS query91.tpl 0.13 */ - cc_call_center_id Call_Center, - cc_name Call_Center_Name, - cc_manager Manager, - sum(cr_net_loss) Returns_Loss -from - call_center, - catalog_returns, - date_dim, - customer, - customer_address, - customer_demographics, - household_demographics -where - cr_call_center_sk = cc_call_center_sk -and cr_returned_date_sk = d_date_sk -and cr_returning_customer_sk= c_customer_sk -and cd_demo_sk = c_current_cdemo_sk -and hd_demo_sk = c_current_hdemo_sk -and ca_address_sk = c_current_addr_sk -and d_year = 1999 -and d_moy = 11 -and ( (cd_marital_status = 'M' and cd_education_status = 'Unknown') - or(cd_marital_status = 'W' and cd_education_status = 'Advanced Degree')) -and hd_buy_potential like '501-1000%' -and ca_gmt_offset = -6 -group by cc_call_center_id,cc_name,cc_manager,cd_marital_status,cd_education_status -order by sum(cr_net_loss) desc; - --- end template query91.tpl query 13 in stream 2 --- start template query28.tpl query 14 in stream 2 -select /* TPC-DS query28.tpl 0.36 */ * -from (select avg(ss_list_price) B1_LP - ,count(ss_list_price) B1_CNT - ,count(distinct ss_list_price) B1_CNTD - from store_sales - where ss_quantity between 0 and 5 - and (ss_list_price between 100 and 100+10 - or ss_coupon_amt between 7313 and 7313+1000 - or ss_wholesale_cost between 71 and 71+20)) B1, - (select avg(ss_list_price) B2_LP - ,count(ss_list_price) B2_CNT - ,count(distinct ss_list_price) B2_CNTD - from store_sales - where ss_quantity between 6 and 10 - and (ss_list_price between 187 and 187+10 - or ss_coupon_amt between 2738 and 2738+1000 - or ss_wholesale_cost between 49 and 49+20)) B2, - (select avg(ss_list_price) B3_LP - ,count(ss_list_price) B3_CNT - ,count(distinct ss_list_price) B3_CNTD - from store_sales - where ss_quantity between 11 and 15 - and (ss_list_price between 133 and 133+10 - or ss_coupon_amt between 4856 and 4856+1000 - or ss_wholesale_cost between 51 and 51+20)) B3, - (select avg(ss_list_price) B4_LP - ,count(ss_list_price) B4_CNT - ,count(distinct ss_list_price) B4_CNTD - from store_sales - where ss_quantity between 16 and 20 - and (ss_list_price between 28 and 28+10 - or ss_coupon_amt between 14150 and 14150+1000 - or ss_wholesale_cost between 22 and 22+20)) B4, - (select avg(ss_list_price) B5_LP - ,count(ss_list_price) B5_CNT - ,count(distinct ss_list_price) B5_CNTD - from store_sales - where ss_quantity between 21 and 25 - and (ss_list_price between 45 and 45+10 - or ss_coupon_amt between 15100 and 15100+1000 - or ss_wholesale_cost between 60 and 60+20)) B5, - (select avg(ss_list_price) B6_LP - ,count(ss_list_price) B6_CNT - ,count(distinct ss_list_price) B6_CNTD - from store_sales - where ss_quantity between 26 and 30 - and (ss_list_price between 57 and 57+10 - or ss_coupon_amt between 10201 and 10201+1000 - or ss_wholesale_cost between 40 and 40+20)) B6 -limit 100; - --- end template query28.tpl query 14 in stream 2 --- start template query68.tpl query 15 in stream 2 -select /* TPC-DS query68.tpl 0.95 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,extended_price - ,extended_tax - ,list_price - from (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_ext_sales_price) extended_price - ,sum(ss_ext_list_price) list_price - ,sum(ss_ext_tax) extended_tax - from store_sales - ,date_dim - ,store - ,household_demographics - ,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_dep_count = 2 or - household_demographics.hd_vehicle_count= 3) - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_city in ('Greenville','Woodland') - group by ss_ticket_number - ,ss_customer_sk - ,ss_addr_sk,ca_city) dn - ,customer - ,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,ss_ticket_number - limit 100; - --- end template query68.tpl query 15 in stream 2 --- start template query8.tpl query 16 in stream 2 -select /* TPC-DS query8.tpl 0.63 */ s_store_name - ,sum(ss_net_profit) - from store_sales - ,date_dim - ,store, - (select ca_zip - from ( - SELECT substring(ca_zip,1,5) ca_zip - FROM customer_address - WHERE substring(ca_zip,1,5) IN ( - '97227','57646','63537','49508','82778','21291', - '91710','24128','76063','58775','18777', - '61264','75764','39055','51840','34692', - '22165','78129','76783','50126','78322', - '27320','96606','71001','22721','15020', - '72641','41670','16239','39591','25328', - '64810','11337','29043','69600','59064', - '70615','50995','98908','21696','76474', - '83845','53410','81652','31543','47757', - '58590','80368','84577','28208','48023', - '76174','35762','24399','16942','24377', - '74498','52149','37686','55512','77050', - '74138','83021','47835','44846','46138', - '44823','15340','16533','50061','54042', - '84736','70642','63077','29144','84604', - '56386','90287','48651','12092','83709', - '21251','96744','40916','22215','70685', - '25325','79798','32778','77230','27033', - '31920','56375','25356','10061','14868', - '23702','36581','48360','86298','36997', - '67961','97211','44504','19917','44007', - '26699','10569','10389','33713','38623', - '96580','62288','51153','49824','93603', - '60498','33437','11533','37436','24375', - '63864','86231','67381','76680','85653', - '14440','95191','54206','42928','78108', - '22857','40400','84650','64456','54331', - '42367','53134','30214','62399','97679', - '61808','79008','51930','24060','64203', - '61200','33279','43462','56326','74061', - '63272','50455','99677','10238','55304', - '44225','62495','94805','88842','40461', - '88068','51666','96160','13428','13402', - '93249','83010','64855','69688','78523', - '51614','42841','30055','34320','85949', - '67914','65974','56289','49547','87986', - '51306','12056','49421','32238','21665', - '29796','90196','41320','83210','54911', - '42523','98954','14647','40555','11069', - '70565','59650','87464','57483','16119', - '61484','22098','49912','82942','87590', - '55856','18844','12334','64875','77264', - '69117','77917','55972','96707','18872', - '34815','58704','79430','51261','13532', - '48258','53322','47314','59699','58430', - '64988','44160','93990','80205','99720', - '89322','57193','81384','56419','81326', - '30970','14880','11026','94383','46959', - '72943','10433','64389','18213','45832', - '67945','51736','20378','44911','34498', - '69375','58066','69624','35627','65616', - '90096','44413','87619','57721','20011', - '42059','59502','68567','42887','72658', - '12818','71422','89707','87218','86363', - '36001','65140','66026','39306','87755', - '64809','22660','94039','60193','24675', - '29345','72959','23978','13106','81307', - '44979','69441','84948','10092','38312', - '60289','33249','75696','46569','42165', - '33825','41632','67273','76716','56327', - '58540','91270','61492','99690','10981', - '20282','53422','51822','72411','65250', - '65550','65239','41731','88723','73994', - '87156','12044','20389','92235','96233', - '89382','21396','62951','13829','26681', - '32736','43016','53491','24435','96148', - '43272','14576','30919','52819','87364', - '77439','84184','79309','15334','26794', - '67848','86448','32837','60146','94880', - '38975','39474','94173','11020','34504', - '48781','91477','69996','25896','52842', - '75563','40408','67967','89903','15846', - '62161','37454','28997','37851','42766', - '52910','38961','92344','74156','46673', - '39399','98752','15613','44332','82192', - '17329','45965','54808','76219','46512', - '51279','70084','82155','20917','59092', - '60529','61002','79957','23954','56549', - '73687','14545','47974','73695','18119', - '23623','12964','32154','59768') - intersect - select ca_zip - from (SELECT substring(ca_zip,1,5) ca_zip,count(*) cnt - FROM customer_address, customer - WHERE ca_address_sk = c_current_addr_sk and - c_preferred_cust_flag='Y' - group by ca_zip - having count(*) > 10)A1)A2) V1 - where ss_store_sk = s_store_sk - and ss_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 2001 - and (substring(s_zip,1,2) = substring(V1.ca_zip,1,2)) - group by s_store_name - order by s_store_name - limit 100; - --- end template query8.tpl query 16 in stream 2 --- start template query76.tpl query 17 in stream 2 -select /* TPC-DS query76.tpl 0.99 */ channel, col_name, d_year, d_qoy, i_category, COUNT(*) sales_cnt, SUM(ext_sales_price) sales_amt FROM ( - SELECT 'store' as channel, 'ss_customer_sk' col_name, d_year, d_qoy, i_category, ss_ext_sales_price ext_sales_price - FROM store_sales, item, date_dim - WHERE ss_customer_sk IS NULL - AND ss_sold_date_sk=d_date_sk - AND ss_item_sk=i_item_sk - UNION ALL - SELECT 'web' as channel, 'ws_bill_addr_sk' col_name, d_year, d_qoy, i_category, ws_ext_sales_price ext_sales_price - FROM web_sales, item, date_dim - WHERE ws_bill_addr_sk IS NULL - AND ws_sold_date_sk=d_date_sk - AND ws_item_sk=i_item_sk - UNION ALL - SELECT 'catalog' as channel, 'cs_bill_addr_sk' col_name, d_year, d_qoy, i_category, cs_ext_sales_price ext_sales_price - FROM catalog_sales, item, date_dim - WHERE cs_bill_addr_sk IS NULL - AND cs_sold_date_sk=d_date_sk - AND cs_item_sk=i_item_sk) foo -GROUP BY channel, col_name, d_year, d_qoy, i_category -ORDER BY channel, col_name, d_year, d_qoy, i_category -limit 100; - --- end template query76.tpl query 17 in stream 2 --- start template query75.tpl query 18 in stream 2 -WITH /* TPC-DS query75.tpl 0.3 */ all_sales AS ( - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,SUM(sales_cnt) AS sales_cnt - ,SUM(sales_amt) AS sales_amt - FROM (SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,cs_quantity - COALESCE(cr_return_quantity,0) AS sales_cnt - ,cs_ext_sales_price - COALESCE(cr_return_amount,0.0) AS sales_amt - FROM catalog_sales JOIN item ON i_item_sk=cs_item_sk - JOIN date_dim ON d_date_sk=cs_sold_date_sk - LEFT JOIN catalog_returns ON (cs_order_number=cr_order_number - AND cs_item_sk=cr_item_sk) - WHERE i_category='Electronics' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ss_quantity - COALESCE(sr_return_quantity,0) AS sales_cnt - ,ss_ext_sales_price - COALESCE(sr_return_amt,0.0) AS sales_amt - FROM store_sales JOIN item ON i_item_sk=ss_item_sk - JOIN date_dim ON d_date_sk=ss_sold_date_sk - LEFT JOIN store_returns ON (ss_ticket_number=sr_ticket_number - AND ss_item_sk=sr_item_sk) - WHERE i_category='Electronics' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ws_quantity - COALESCE(wr_return_quantity,0) AS sales_cnt - ,ws_ext_sales_price - COALESCE(wr_return_amt,0.0) AS sales_amt - FROM web_sales JOIN item ON i_item_sk=ws_item_sk - JOIN date_dim ON d_date_sk=ws_sold_date_sk - LEFT JOIN web_returns ON (ws_order_number=wr_order_number - AND ws_item_sk=wr_item_sk) - WHERE i_category='Electronics') sales_detail - GROUP BY d_year, i_brand_id, i_class_id, i_category_id, i_manufact_id) - SELECT prev_yr.d_year AS prev_year - ,curr_yr.d_year AS year - ,curr_yr.i_brand_id - ,curr_yr.i_class_id - ,curr_yr.i_category_id - ,curr_yr.i_manufact_id - ,prev_yr.sales_cnt AS prev_yr_cnt - ,curr_yr.sales_cnt AS curr_yr_cnt - ,curr_yr.sales_cnt-prev_yr.sales_cnt AS sales_cnt_diff - ,curr_yr.sales_amt-prev_yr.sales_amt AS sales_amt_diff - FROM all_sales curr_yr, all_sales prev_yr - WHERE curr_yr.i_brand_id=prev_yr.i_brand_id - AND curr_yr.i_class_id=prev_yr.i_class_id - AND curr_yr.i_category_id=prev_yr.i_category_id - AND curr_yr.i_manufact_id=prev_yr.i_manufact_id - AND curr_yr.d_year=2002 - AND prev_yr.d_year=2002-1 - AND CAST(curr_yr.sales_cnt AS DECIMAL(17,2))/CAST(prev_yr.sales_cnt AS DECIMAL(17,2))<0.9 - ORDER BY sales_cnt_diff,sales_amt_diff - limit 100; - --- end template query75.tpl query 18 in stream 2 --- start template query80a.tpl query 19 in stream 2 -with /* TPC-DS query80a.tpl 0.6 */ ssr as - (select s_store_id as store_id, - sum(ss_ext_sales_price) as sales, - sum(coalesce(sr_return_amt, 0)) as returns, - sum(ss_net_profit - coalesce(sr_net_loss, 0)) as profit - from store_sales left outer join store_returns on - (ss_item_sk = sr_item_sk and ss_ticket_number = sr_ticket_number), - date_dim, - store, - item, - promotion - where ss_sold_date_sk = d_date_sk - and d_date between cast('2002-08-16' as date) - and dateadd(day,30,cast('2002-08-16' as date)) - and ss_store_sk = s_store_sk - and ss_item_sk = i_item_sk - and i_current_price > 50 - and ss_promo_sk = p_promo_sk - and p_channel_tv = 'N' - group by s_store_id) - , - csr as - (select cp_catalog_page_id as catalog_page_id, - sum(cs_ext_sales_price) as sales, - sum(coalesce(cr_return_amount, 0)) as returns, - sum(cs_net_profit - coalesce(cr_net_loss, 0)) as profit - from catalog_sales left outer join catalog_returns on - (cs_item_sk = cr_item_sk and cs_order_number = cr_order_number), - date_dim, - catalog_page, - item, - promotion - where cs_sold_date_sk = d_date_sk - and d_date between cast('2002-08-16' as date) - and dateadd(day,30,cast('2002-08-16' as date)) - and cs_catalog_page_sk = cp_catalog_page_sk - and cs_item_sk = i_item_sk - and i_current_price > 50 - and cs_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(ws_ext_sales_price) as sales, - sum(coalesce(wr_return_amt, 0)) as returns, - sum(ws_net_profit - coalesce(wr_net_loss, 0)) as profit - from web_sales left outer join web_returns on - (ws_item_sk = wr_item_sk and ws_order_number = wr_order_number), - date_dim, - web_site, - item, - promotion - where ws_sold_date_sk = d_date_sk - and d_date between cast('2002-08-16' as date) - and dateadd(day,30,cast('2002-08-16' as date)) - and ws_web_site_sk = web_site_sk - and ws_item_sk = i_item_sk - and i_current_price > 50 - and ws_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by web_site_id) -, -results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || store_id as id - , sales - , returns - , profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || catalog_page_id as id - , sales - , returns - , profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , profit - from wsr - ) x - group by channel, id) - - select channel - , id - , sales - , returns - , profit - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results - ) foo - order by channel, id - limit 100; - --- end template query80a.tpl query 19 in stream 2 --- start template query1.tpl query 20 in stream 2 -with /* TPC-DS query1.tpl 0.12 */ customer_total_return as -(select sr_customer_sk as ctr_customer_sk -,sr_store_sk as ctr_store_sk -,sum(SR_RETURN_AMT) as ctr_total_return -from store_returns -,date_dim -where sr_returned_date_sk = d_date_sk -and d_year =2001 -group by sr_customer_sk -,sr_store_sk) - select c_customer_id -from customer_total_return ctr1 -,store -,customer -where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 -from customer_total_return ctr2 -where ctr1.ctr_store_sk = ctr2.ctr_store_sk) -and s_store_sk = ctr1.ctr_store_sk -and s_state = 'FL' -and ctr1.ctr_customer_sk = c_customer_sk -order by c_customer_id -limit 100; - --- end template query1.tpl query 20 in stream 2 --- start template query69.tpl query 21 in stream 2 -select /* TPC-DS query69.tpl 0.28 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_state in ('NV','OK','NY') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 2 and 2+2) and - (not exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 2 and 2+2) and - not exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 2 and 2+2)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - limit 100; - --- end template query69.tpl query 21 in stream 2 --- start template query26.tpl query 22 in stream 2 -select /* TPC-DS query26.tpl 0.85 */ i_item_id, - avg(cs_quantity) agg1, - avg(cs_list_price) agg2, - avg(cs_coupon_amt) agg3, - avg(cs_sales_price) agg4 - from catalog_sales, customer_demographics, date_dim, item, promotion - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd_demo_sk and - cs_promo_sk = p_promo_sk and - cd_gender = 'M' and - cd_marital_status = 'M' and - cd_education_status = 'College' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 2000 - group by i_item_id - order by i_item_id - limit 100; - --- end template query26.tpl query 22 in stream 2 --- start template query11.tpl query 23 in stream 2 -with /* TPC-DS query11.tpl 0.51 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ss_ext_list_price-ss_ext_discount_amt) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ws_ext_list_price-ws_ext_discount_amt) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_login - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 1998 - and t_s_secyear.dyear = 1998+1 - and t_w_firstyear.dyear = 1998 - and t_w_secyear.dyear = 1998+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else 0.0 end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else 0.0 end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_login -limit 100; - --- end template query11.tpl query 23 in stream 2 --- start template query17.tpl query 24 in stream 2 -select /* TPC-DS query17.tpl 0.41 */ i_item_id - ,i_item_desc - ,s_state - ,count(ss_quantity) as store_sales_quantitycount - ,avg(ss_quantity) as store_sales_quantityave - ,stddev_samp(ss_quantity) as store_sales_quantitystdev - ,stddev_samp(ss_quantity)/avg(ss_quantity) as store_sales_quantitycov - ,count(sr_return_quantity) as store_returns_quantitycount - ,avg(sr_return_quantity) as store_returns_quantityave - ,stddev_samp(sr_return_quantity) as store_returns_quantitystdev - ,stddev_samp(sr_return_quantity)/avg(sr_return_quantity) as store_returns_quantitycov - ,count(cs_quantity) as catalog_sales_quantitycount ,avg(cs_quantity) as catalog_sales_quantityave - ,stddev_samp(cs_quantity) as catalog_sales_quantitystdev - ,stddev_samp(cs_quantity)/avg(cs_quantity) as catalog_sales_quantitycov - from store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where d1.d_quarter_name = '2002Q1' - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_quarter_name in ('2002Q1','2002Q2','2002Q3') - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_quarter_name in ('2002Q1','2002Q2','2002Q3') - group by i_item_id - ,i_item_desc - ,s_state - order by i_item_id - ,i_item_desc - ,s_state -limit 100; - --- end template query17.tpl query 24 in stream 2 --- start template query63.tpl query 25 in stream 2 -select /* TPC-DS query63.tpl 0.27 */ * -from (select i_manager_id - ,sum(ss_sales_price) sum_sales - ,avg(sum(ss_sales_price)) over (partition by i_manager_id) avg_monthly_sales - from item - ,store_sales - ,date_dim - ,store - where ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and d_month_seq in (1209,1209+1,1209+2,1209+3,1209+4,1209+5,1209+6,1209+7,1209+8,1209+9,1209+10,1209+11) - and (( i_category in ('Books','Children','Electronics') - and i_class in ('personal','portable','reference','self-help') - and i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) - or( i_category in ('Women','Music','Men') - and i_class in ('accessories','classical','fragrances','pants') - and i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manager_id, d_moy) tmp1 -where case when avg_monthly_sales > 0 then abs (sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 -order by i_manager_id - ,avg_monthly_sales - ,sum_sales -limit 100; - --- end template query63.tpl query 25 in stream 2 --- start template query77a.tpl query 26 in stream 2 -with /* TPC-DS query77a.tpl 0.78 */ ss as - (select s_store_sk, - sum(ss_ext_sales_price) as sales, - sum(ss_net_profit) as profit - from store_sales, - date_dim, - store - where ss_sold_date_sk = d_date_sk - and d_date between cast('1998-08-28' as date) - and dateadd(day,30,cast('1998-08-28' as date)) - and ss_store_sk = s_store_sk - group by s_store_sk) - , - sr as - (select s_store_sk, - sum(sr_return_amt) as returns, - sum(sr_net_loss) as profit_loss - from store_returns, - date_dim, - store - where sr_returned_date_sk = d_date_sk - and d_date between cast('1998-08-28' as date) - and dateadd(day,30,cast('1998-08-28' as date)) - and sr_store_sk = s_store_sk - group by s_store_sk), - cs as - (select cs_call_center_sk, - sum(cs_ext_sales_price) as sales, - sum(cs_net_profit) as profit - from catalog_sales, - date_dim - where cs_sold_date_sk = d_date_sk - and d_date between cast('1998-08-28' as date) - and dateadd(day,30,cast('1998-08-28' as date)) - group by cs_call_center_sk - ), - cr as - (select cr_call_center_sk, - sum(cr_return_amount) as returns, - sum(cr_net_loss) as profit_loss - from catalog_returns, - date_dim - where cr_returned_date_sk = d_date_sk - and d_date between cast('1998-08-28' as date) - and dateadd(day,30,cast('1998-08-28' as date)) - group by cr_call_center_sk), - ws as - ( select wp_web_page_sk, - sum(ws_ext_sales_price) as sales, - sum(ws_net_profit) as profit - from web_sales, - date_dim, - web_page - where ws_sold_date_sk = d_date_sk - and d_date between cast('1998-08-28' as date) - and dateadd(day,30,cast('1998-08-28' as date)) - and ws_web_page_sk = wp_web_page_sk - group by wp_web_page_sk), - wr as - (select wp_web_page_sk, - sum(wr_return_amt) as returns, - sum(wr_net_loss) as profit_loss - from web_returns, - date_dim, - web_page - where wr_returned_date_sk = d_date_sk - and d_date between cast('1998-08-28' as date) - and dateadd(day,30,cast('1998-08-28' as date)) - and wr_web_page_sk = wp_web_page_sk - group by wp_web_page_sk) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , ss.s_store_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ss left join sr - on ss.s_store_sk = sr.s_store_sk - union all - select 'catalog channel' as channel - , cs_call_center_sk as id - , sales - , returns - , (profit - profit_loss) as profit - from cs - , cr - union all - select 'web channel' as channel - , ws.wp_web_page_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ws left join wr - on ws.wp_web_page_sk = wr.wp_web_page_sk - ) x - group by channel, id ) - - select * - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results -) foo -order by channel, id - limit 100; - --- end template query77a.tpl query 26 in stream 2 --- start template query19.tpl query 27 in stream 2 -select /* TPC-DS query19.tpl 0.8 */ i_brand_id brand_id, i_brand brand, i_manufact_id, i_manufact, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item,customer,customer_address,store - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=6 - and d_moy=12 - and d_year=2002 - and ss_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and substring(ca_zip,1,5) <> substring(s_zip,1,5) - and ss_store_sk = s_store_sk - group by i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact - order by ext_price desc - ,i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact -limit 100 ; - --- end template query19.tpl query 27 in stream 2 --- start template query21.tpl query 28 in stream 2 -select /* TPC-DS query21.tpl 0.14 */ * - from(select w_warehouse_name - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('2001-03-16' as date)) - then inv_quantity_on_hand - else 0 end) as inv_before - ,sum(case when (cast(d_date as date) >= cast ('2001-03-16' as date)) - then inv_quantity_on_hand - else 0 end) as inv_after - from inventory - ,warehouse - ,item - ,date_dim - where i_current_price between 0.99 and 1.49 - and i_item_sk = inv_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('2001-03-16' as date)) - and dateadd(day,30,cast ('2001-03-16' as date)) - group by w_warehouse_name, i_item_id) x - where (case when inv_before > 0 - then inv_after / inv_before - else null - end) between 2.0/3.0 and 3.0/2.0 - order by w_warehouse_name - ,i_item_id - limit 100; - --- end template query21.tpl query 28 in stream 2 --- start template query31.tpl query 29 in stream 2 -with /* TPC-DS query31.tpl 0.50 */ ss as - (select ca_county,d_qoy, d_year,sum(ss_ext_sales_price) as store_sales - from store_sales,date_dim,customer_address - where ss_sold_date_sk = d_date_sk - and ss_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year), - ws as - (select ca_county,d_qoy, d_year,sum(ws_ext_sales_price) as web_sales - from web_sales,date_dim,customer_address - where ws_sold_date_sk = d_date_sk - and ws_bill_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year) - select - ss1.ca_county - ,ss1.d_year - ,ws2.web_sales/ws1.web_sales web_q1_q2_increase - ,ss2.store_sales/ss1.store_sales store_q1_q2_increase - ,ws3.web_sales/ws2.web_sales web_q2_q3_increase - ,ss3.store_sales/ss2.store_sales store_q2_q3_increase - from - ss ss1 - ,ss ss2 - ,ss ss3 - ,ws ws1 - ,ws ws2 - ,ws ws3 - where - ss1.d_qoy = 1 - and ss1.d_year = 2001 - and ss1.ca_county = ss2.ca_county - and ss2.d_qoy = 2 - and ss2.d_year = 2001 - and ss2.ca_county = ss3.ca_county - and ss3.d_qoy = 3 - and ss3.d_year = 2001 - and ss1.ca_county = ws1.ca_county - and ws1.d_qoy = 1 - and ws1.d_year = 2001 - and ws1.ca_county = ws2.ca_county - and ws2.d_qoy = 2 - and ws2.d_year = 2001 - and ws1.ca_county = ws3.ca_county - and ws3.d_qoy = 3 - and ws3.d_year =2001 - and case when ws1.web_sales > 0 then ws2.web_sales/ws1.web_sales else null end - > case when ss1.store_sales > 0 then ss2.store_sales/ss1.store_sales else null end - and case when ws2.web_sales > 0 then ws3.web_sales/ws2.web_sales else null end - > case when ss2.store_sales > 0 then ss3.store_sales/ss2.store_sales else null end - order by store_q1_q2_increase; - --- end template query31.tpl query 29 in stream 2 --- start template query93.tpl query 30 in stream 2 -select /* TPC-DS query93.tpl 0.52 */ ss_customer_sk - ,sum(act_sales) sumsales - from (select ss_item_sk - ,ss_ticket_number - ,ss_customer_sk - ,case when sr_return_quantity is not null then (ss_quantity-sr_return_quantity)*ss_sales_price - else (ss_quantity*ss_sales_price) end act_sales - from store_sales left outer join store_returns on (sr_item_sk = ss_item_sk - and sr_ticket_number = ss_ticket_number) - ,reason - where sr_reason_sk = r_reason_sk - and r_reason_desc = 'reason 41') t - group by ss_customer_sk - order by sumsales, ss_customer_sk -limit 100; - --- end template query93.tpl query 30 in stream 2 --- start template query54.tpl query 31 in stream 2 -with /* TPC-DS query54.tpl 0.81 */ my_customers as ( - select distinct c_customer_sk - , c_current_addr_sk - from - ( select cs_sold_date_sk sold_date_sk, - cs_bill_customer_sk customer_sk, - cs_item_sk item_sk - from catalog_sales - union all - select ws_sold_date_sk sold_date_sk, - ws_bill_customer_sk customer_sk, - ws_item_sk item_sk - from web_sales - ) cs_or_ws_sales, - item, - date_dim, - customer - where sold_date_sk = d_date_sk - and item_sk = i_item_sk - and i_category = 'Jewelry' - and i_class = 'mens watch' - and c_customer_sk = cs_or_ws_sales.customer_sk - and d_moy = 6 - and d_year = 1999 - ) - , my_revenue as ( - select c_customer_sk, - sum(ss_ext_sales_price) as revenue - from my_customers, - store_sales, - customer_address, - store, - date_dim - where c_current_addr_sk = ca_address_sk - and ca_county = s_county - and ca_state = s_state - and ss_sold_date_sk = d_date_sk - and c_customer_sk = ss_customer_sk - and d_month_seq between (select distinct d_month_seq+1 - from date_dim where d_year = 1999 and d_moy = 6) - and (select distinct d_month_seq+3 - from date_dim where d_year = 1999 and d_moy = 6) - group by c_customer_sk - ) - , segments as - (select cast((revenue/50) as int) as segment - from my_revenue - ) - select segment, count(*) as num_customers, segment*50 as segment_base - from segments - group by segment - order by segment, num_customers - limit 100; - --- end template query54.tpl query 31 in stream 2 --- start template query39.tpl query 32 in stream 2 -with /* TPC-DS query39.tpl 0.5 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =1999 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=4 - and inv2.d_moy=4+1 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; -with /* TPC-DS query39.tpl 0.5 part2 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =1999 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=4 - and inv2.d_moy=4+1 - and inv1.cov > 1.5 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; - --- end template query39.tpl query 32 in stream 2 --- start template query10.tpl query 33 in stream 2 -select /* TPC-DS query10.tpl 0.26 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3, - cd_dep_count, - count(*) cnt4, - cd_dep_employed_count, - count(*) cnt5, - cd_dep_college_count, - count(*) cnt6 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_county in ('Fayette County','Niagara County','Pike County','Morgan County','Union County') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 4 and 4+3) and - (exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 4 ANd 4+3) or - exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 4 and 4+3)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count -limit 100; - --- end template query10.tpl query 33 in stream 2 --- start template query15.tpl query 34 in stream 2 -select /* TPC-DS query15.tpl 0.57 */ ca_zip - ,sum(cs_sales_price) - from catalog_sales - ,customer - ,customer_address - ,date_dim - where cs_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', - '85392', '85460', '80348', '81792') - or ca_state in ('CA','WA','GA') - or cs_sales_price > 500) - and cs_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 2002 - group by ca_zip - order by ca_zip - limit 100; - --- end template query15.tpl query 34 in stream 2 --- start template query55.tpl query 35 in stream 2 -select /* TPC-DS query55.tpl 0.82 */ i_brand_id brand_id, i_brand brand, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=31 - and d_moy=11 - and d_year=1999 - group by i_brand, i_brand_id - order by ext_price desc, i_brand_id -limit 100 ; - --- end template query55.tpl query 35 in stream 2 --- start template query14a.tpl query 36 in stream 2 -with /* TPC-DS query14a.tpl 0.69 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1999 AND 1999 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1999 AND 1999 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1999 AND 1999 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as - (select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2) x) -, - results AS -(select channel, i_brand_id, i_class_id, i_category_id, sum(sales) sum_sales, sum(number_sales) number_sales - from ( - select 'store' channel, i_brand_id,i_class_id - ,i_category_id,sum(ss_quantity*ss_list_price) sales - , count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1999+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales) - union all - select 'catalog' channel, i_brand_id,i_class_id,i_category_id, sum(cs_quantity*cs_list_price) sales, count(*) number_sales - from catalog_sales - ,item - ,date_dim - where cs_item_sk in (select ss_item_sk from cross_items) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1999+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(cs_quantity*cs_list_price) > (select average_sales from avg_sales) - union all - select 'web' channel, i_brand_id,i_class_id,i_category_id, sum(ws_quantity*ws_list_price) sales , count(*) number_sales - from web_sales - ,item - ,date_dim - where ws_item_sk in (select ss_item_sk from cross_items) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1999+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ws_quantity*ws_list_price) > (select average_sales from avg_sales) - ) y - group by channel, i_brand_id,i_class_id,i_category_id) - - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales -from ( - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales from results - union - select channel, i_brand_id, i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id, i_class_id - union - select channel, i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id - union - select channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel - union - select null as channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results) z -order by channel, i_brand_id, i_class_id, i_category_id - limit 100; -with /* TPC-DS query14a.tpl 0.69 part2 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1999 AND 1999 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1999 AND 1999 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1999 AND 1999 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as -(select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2) x) - select this_year.channel ty_channel - ,this_year.i_brand_id ty_brand - ,this_year.i_class_id ty_class - ,this_year.i_category_id ty_category - ,this_year.sales ty_sales - ,this_year.number_sales ty_number_sales - ,last_year.channel ly_channel - ,last_year.i_brand_id ly_brand - ,last_year.i_class_id ly_class - ,last_year.i_category_id ly_category - ,last_year.sales ly_sales - ,last_year.number_sales ly_number_sales -from - (select 'store' channel, i_brand_id,i_class_id,i_category_id - ,sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1999 + 1 - and d_moy = 12 - and d_dom = 15) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) this_year, - (select 'store' channel, i_brand_id,i_class_id - ,i_category_id, sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1999 - and d_moy = 12 - and d_dom = 15) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) last_year - where this_year.i_brand_id= last_year.i_brand_id - and this_year.i_class_id = last_year.i_class_id - and this_year.i_category_id = last_year.i_category_id - order by this_year.channel, this_year.i_brand_id, this_year.i_class_id, this_year.i_category_id - limit 100; - --- end template query14a.tpl query 36 in stream 2 --- start template query38.tpl query 37 in stream 2 -select /* TPC-DS query38.tpl 0.54 */ count(*) from ( - select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1180 and 1180 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1180 and 1180 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1180 and 1180 + 11 -) hot_cust -limit 100; - --- end template query38.tpl query 37 in stream 2 --- start template query42.tpl query 38 in stream 2 -select /* TPC-DS query42.tpl 0.61 */ dt.d_year - ,item.i_category_id - ,item.i_category - ,sum(ss_ext_sales_price) - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=12 - and dt.d_year=2001 - group by dt.d_year - ,item.i_category_id - ,item.i_category - order by sum(ss_ext_sales_price) desc,dt.d_year - ,item.i_category_id - ,item.i_category -limit 100 ; - --- end template query42.tpl query 38 in stream 2 --- start template query53.tpl query 39 in stream 2 -select /* TPC-DS query53.tpl 0.88 */ * from -(select i_manufact_id, -sum(ss_sales_price) sum_sales, -avg(sum(ss_sales_price)) over (partition by i_manufact_id) avg_quarterly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and -ss_sold_date_sk = d_date_sk and -ss_store_sk = s_store_sk and -d_month_seq in (1218,1218+1,1218+2,1218+3,1218+4,1218+5,1218+6,1218+7,1218+8,1218+9,1218+10,1218+11) and -((i_category in ('Books','Children','Electronics') and -i_class in ('personal','portable','reference','self-help') and -i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) -or(i_category in ('Women','Music','Men') and -i_class in ('accessories','classical','fragrances','pants') and -i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manufact_id, d_qoy ) tmp1 -where case when avg_quarterly_sales > 0 - then abs (sum_sales - avg_quarterly_sales)/ avg_quarterly_sales - else null end > 0.1 -order by avg_quarterly_sales, - sum_sales, - i_manufact_id -limit 100; - --- end template query53.tpl query 39 in stream 2 --- start template query45.tpl query 40 in stream 2 -select /* TPC-DS query45.tpl 0.18 */ ca_zip, ca_county, sum(ws_sales_price) - from web_sales, customer, customer_address, date_dim, item - where ws_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ws_item_sk = i_item_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', '85392', '85460', '80348', '81792') - or - i_item_id in (select i_item_id - from item - where i_item_sk in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29) - ) - ) - and ws_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 2002 - group by ca_zip, ca_county - order by ca_zip, ca_county - limit 100; - --- end template query45.tpl query 40 in stream 2 --- start template query99.tpl query 41 in stream 2 -select /* TPC-DS query99.tpl 0.94 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 30) and - (cs_ship_date_sk - cs_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 60) and - (cs_ship_date_sk - cs_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 90) and - (cs_ship_date_sk - cs_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - catalog_sales - ,warehouse - ,ship_mode - ,call_center - ,date_dim -where - d_month_seq between 1194 and 1194 + 11 -and cs_ship_date_sk = d_date_sk -and cs_warehouse_sk = w_warehouse_sk -and cs_ship_mode_sk = sm_ship_mode_sk -and cs_call_center_sk = cc_call_center_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -limit 100; - --- end template query99.tpl query 41 in stream 2 --- start template query67a.tpl query 42 in stream 2 -with /* TPC-DS query67a.tpl 0.35 */ results as -( select i_category ,i_class ,i_brand ,i_product_name ,d_year ,d_qoy ,d_moy ,s_store_id - ,sum(coalesce(ss_sales_price*ss_quantity,0)) sumsales - from store_sales ,date_dim ,store ,item - where ss_sold_date_sk=d_date_sk - and ss_item_sk=i_item_sk - and ss_store_sk = s_store_sk - and d_month_seq between 1184 and 1184 + 11 - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy,s_store_id) - , - results_rollup as - (select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, s_store_id, sumsales - from results - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy - union all - select i_category, i_class, i_brand, i_product_name, d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year - union all - select i_category, i_class, i_brand, i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name - union all - select i_category, i_class, i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand - union all - select i_category, i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class - union all - select i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category - union all - select null i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results) - - select * -from (select i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rank() over (partition by i_category order by sumsales desc) rk - from results_rollup) dw2 -where rk <= 100 -order by i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rk -limit 100; - --- end template query67a.tpl query 42 in stream 2 --- start template query23.tpl query 43 in stream 2 -with /* TPC-DS query23.tpl 0.68 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (2000,2000+1,2000+2,2000+3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (2000,2000+1,2000+2,2000+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * -from - max_store_sales)) - select sum(sales) - from (select cs_quantity*cs_list_price sales - from catalog_sales - ,date_dim - where d_year = 2000 - and d_moy = 3 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - union all - select ws_quantity*ws_list_price sales - from web_sales - ,date_dim - where d_year = 2000 - and d_moy = 3 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer)) - limit 100; -with /* TPC-DS query23.tpl 0.68 part2 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (2000,2000 + 1,2000 + 2,2000 + 3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (2000,2000+1,2000+2,2000+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * - from max_store_sales)) - select c_last_name,c_first_name,sales - from (select c_last_name,c_first_name,sum(cs_quantity*cs_list_price) sales - from catalog_sales - ,customer - ,date_dim - where d_year = 2000 - and d_moy = 3 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and cs_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name - union all - select c_last_name,c_first_name,sum(ws_quantity*ws_list_price) sales - from web_sales - ,customer - ,date_dim - where d_year = 2000 - and d_moy = 3 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and ws_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name) - order by c_last_name,c_first_name,sales - limit 100; - --- end template query23.tpl query 43 in stream 2 --- start template query62.tpl query 44 in stream 2 -select /* TPC-DS query62.tpl 0.24 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 30) and - (ws_ship_date_sk - ws_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 60) and - (ws_ship_date_sk - ws_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 90) and - (ws_ship_date_sk - ws_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - web_sales - ,warehouse - ,ship_mode - ,web_site - ,date_dim -where - d_month_seq between 1207 and 1207 + 11 -and ws_ship_date_sk = d_date_sk -and ws_warehouse_sk = w_warehouse_sk -and ws_ship_mode_sk = sm_ship_mode_sk -and ws_web_site_sk = web_site_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -limit 100; - --- end template query62.tpl query 44 in stream 2 --- start template query30.tpl query 45 in stream 2 -with /* TPC-DS query30.tpl 0.75 */ customer_total_return as - (select wr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(wr_return_amt) as ctr_total_return - from web_returns - ,date_dim - ,customer_address - where wr_returned_date_sk = d_date_sk - and d_year =2002 - and wr_returning_addr_sk = ca_address_sk - group by wr_returning_customer_sk - ,ca_state) - select c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'MS' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return -limit 100; - --- end template query30.tpl query 45 in stream 2 --- start template query86a.tpl query 46 in stream 2 -with /* TPC-DS query86a.tpl 0.11 */ results as -( select sum(ws_net_paid) as total_sum, i_category, i_class, 0 as g_category, 0 as g_class - from - web_sales - ,date_dim d1 - ,item - where - d1.d_month_seq between 1187 and 1187+11 - and d1.d_date_sk = ws_sold_date_sk - and i_item_sk = ws_item_sk - group by i_category,i_class - ) , - - results_rollup as -( select total_sum ,i_category ,i_class, g_category, g_class, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum, i_category, NULL as i_class, 0 as g_category, 1 as g_class, 1 as lochierarchy from results group by i_category - union - select sum(total_sum) as total_sum, NULL as i_category, NULL as i_class, 1 as g_category, 1 as g_class, 2 as lochierarchy from results) - select - total_sum ,i_category ,i_class, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_class = 0 then i_category end - order by total_sum desc) as rank_within_parent - from - results_rollup - order by - lochierarchy desc, - case when lochierarchy = 0 then i_category end, - rank_within_parent - limit 100; - --- end template query86a.tpl query 46 in stream 2 --- start template query82.tpl query 47 in stream 2 -select /* TPC-DS query82.tpl 0.67 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, store_sales - where i_current_price between 21 and 21+30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('1998-05-12' as date) and dateadd(day,60,cast('1998-05-12' as date)) - and i_manufact_id in (76,979,308,402) - and inv_quantity_on_hand between 100 and 500 - and ss_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query82.tpl query 47 in stream 2 --- start template query25.tpl query 48 in stream 2 -select /* TPC-DS query25.tpl 0.9 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,min(ss_net_profit) as store_sales_profit - ,min(sr_net_loss) as store_returns_loss - ,min(cs_net_profit) as catalog_sales_profit - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 1999 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 10 - and d2.d_year = 1999 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_moy between 4 and 10 - and d3.d_year = 1999 - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query25.tpl query 48 in stream 2 --- start template query16.tpl query 49 in stream 2 -select /* TPC-DS query16.tpl 0.25 */ - count(distinct cs_order_number) as "order count" - ,sum(cs_ext_ship_cost) as "total shipping cost" - ,sum(cs_net_profit) as "total net profit" -from - catalog_sales cs1 - ,date_dim - ,customer_address - ,call_center -where - d_date between '1999-2-01' and - dateadd(day, 60, cast('1999-2-01' as date)) -and cs1.cs_ship_date_sk = d_date_sk -and cs1.cs_ship_addr_sk = ca_address_sk -and ca_state = 'WI' -and cs1.cs_call_center_sk = cc_call_center_sk -and cc_county in ('Barrow County','Williamson County','Jackson County','Dauphin County', - 'Pennington County' -) -and exists (select * - from catalog_sales cs2 - where cs1.cs_order_number = cs2.cs_order_number - and cs1.cs_warehouse_sk <> cs2.cs_warehouse_sk) -and not exists(select * - from catalog_returns cr1 - where cs1.cs_order_number = cr1.cr_order_number) -order by count(distinct cs_order_number) -limit 100; - --- end template query16.tpl query 49 in stream 2 --- start template query81.tpl query 50 in stream 2 -with /* TPC-DS query81.tpl 0.37 */ customer_total_return as - (select cr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(cr_return_amt_inc_tax) as ctr_total_return - from catalog_returns - ,date_dim - ,customer_address - where cr_returned_date_sk = d_date_sk - and d_year =2000 - and cr_returning_addr_sk = ca_address_sk - group by cr_returning_customer_sk - ,ca_state ) - select c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'FL' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - limit 100; - --- end template query81.tpl query 50 in stream 2 --- start template query40.tpl query 51 in stream 2 -select /* TPC-DS query40.tpl 0.86 */ - w_state - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('1999-03-06' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_before - ,sum(case when (cast(d_date as date) >= cast ('1999-03-06' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_after - from - catalog_sales left outer join catalog_returns on - (cs_order_number = cr_order_number - and cs_item_sk = cr_item_sk) - ,warehouse - ,item - ,date_dim - where - i_current_price between 0.99 and 1.49 - and i_item_sk = cs_item_sk - and cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('1999-03-06' as date)) - and dateadd(day,30,cast ('1999-03-06' as date)) - group by - w_state,i_item_id - order by w_state,i_item_id -limit 100; - --- end template query40.tpl query 51 in stream 2 --- start template query44.tpl query 52 in stream 2 -select /* TPC-DS query44.tpl 0.4 */ asceding.rnk, i1.i_product_name best_performing, i2.i_product_name worst_performing -from(select * - from (select item_sk,rank() over (order by rank_col asc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 451 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 451 - and ss_hdemo_sk is null - group by ss_store_sk))V1)V11 - where rnk < 11) asceding, - (select * - from (select item_sk,rank() over (order by rank_col desc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 451 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 451 - and ss_hdemo_sk is null - group by ss_store_sk))V2)V21 - where rnk < 11) descending, -item i1, -item i2 -where asceding.rnk = descending.rnk - and i1.i_item_sk=asceding.item_sk - and i2.i_item_sk=descending.item_sk -order by asceding.rnk -limit 100; - --- end template query44.tpl query 52 in stream 2 --- start template query50.tpl query 53 in stream 2 -select /* TPC-DS query50.tpl 0.60 */ - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 30) and - (sr_returned_date_sk - ss_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 60) and - (sr_returned_date_sk - ss_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 90) and - (sr_returned_date_sk - ss_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - store_sales - ,store_returns - ,store - ,date_dim d1 - ,date_dim d2 -where - d2.d_year = 2001 -and d2.d_moy = 9 -and ss_ticket_number = sr_ticket_number -and ss_item_sk = sr_item_sk -and ss_sold_date_sk = d1.d_date_sk -and sr_returned_date_sk = d2.d_date_sk -and ss_customer_sk = sr_customer_sk -and ss_store_sk = s_store_sk -group by - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -order by s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -limit 100; - --- end template query50.tpl query 53 in stream 2 --- start template query61.tpl query 54 in stream 2 -select /* TPC-DS query61.tpl 0.97 */ promotions,total,cast(promotions as decimal(15,4))/cast(total as decimal(15,4))*100 -from - (select sum(ss_ext_sales_price) promotions - from store_sales - ,store - ,promotion - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_promo_sk = p_promo_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -6 - and i_category = 'Sports' - and (p_channel_dmail = 'Y' or p_channel_email = 'Y' or p_channel_tv = 'Y') - and s_gmt_offset = -6 - and d_year = 1998 - and d_moy = 11) promotional_sales, - (select sum(ss_ext_sales_price) total - from store_sales - ,store - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -6 - and i_category = 'Sports' - and s_gmt_offset = -6 - and d_year = 1998 - and d_moy = 11) all_sales -order by promotions, total -limit 100; - --- end template query61.tpl query 54 in stream 2 --- start template query85.tpl query 55 in stream 2 -select /* TPC-DS query85.tpl 0.33 */ substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) - from web_sales, web_returns, web_page, customer_demographics cd1, - customer_demographics cd2, customer_address, date_dim, reason - where ws_web_page_sk = wp_web_page_sk - and ws_item_sk = wr_item_sk - and ws_order_number = wr_order_number - and ws_sold_date_sk = d_date_sk and d_year = 2001 - and cd1.cd_demo_sk = wr_refunded_cdemo_sk - and cd2.cd_demo_sk = wr_returning_cdemo_sk - and ca_address_sk = wr_refunded_addr_sk - and r_reason_sk = wr_reason_sk - and - ( - ( - cd1.cd_marital_status = 'U' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Advanced Degree' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 100.00 and 150.00 - ) - or - ( - cd1.cd_marital_status = 'M' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = '4 yr Degree' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 50.00 and 100.00 - ) - or - ( - cd1.cd_marital_status = 'S' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'College' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ca_country = 'United States' - and - ca_state in ('KY', 'PA', 'SC') - and ws_net_profit between 100 and 200 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('VT', 'NE', 'VA') - and ws_net_profit between 150 and 300 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('ME', 'GA', 'NY') - and ws_net_profit between 50 and 250 - ) - ) -group by r_reason_desc -order by substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) -limit 100; - --- end template query85.tpl query 55 in stream 2 --- start template query73.tpl query 56 in stream 2 -select /* TPC-DS query73.tpl 0.79 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_buy_potential = '>10000' or - household_demographics.hd_buy_potential = '0-500') - and household_demographics.hd_vehicle_count > 0 - and case when household_demographics.hd_vehicle_count > 0 then - household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count else null end > 1 - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_county in ('Jackson County','Wadena County','Terrell County','San Miguel County') - group by ss_ticket_number,ss_customer_sk) dj,customer - where ss_customer_sk = c_customer_sk - and cnt between 1 and 5 - order by cnt desc, c_last_name asc; - --- end template query73.tpl query 56 in stream 2 --- start template query95.tpl query 57 in stream 2 -with /* TPC-DS query95.tpl 0.43 */ ws_wh as -(select ws1.ws_order_number,ws1.ws_warehouse_sk wh1,ws2.ws_warehouse_sk wh2 - from web_sales ws1,web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) - select - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2002-2-01' and - dateadd(day,60,cast('2002-2-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'CO' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and ws1.ws_order_number in (select ws_order_number - from ws_wh) -and ws1.ws_order_number in (select wr_order_number - from web_returns,ws_wh - where wr_order_number = ws_wh.ws_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query95.tpl query 57 in stream 2 --- start template query84.tpl query 58 in stream 2 -select /* TPC-DS query84.tpl 0.80 */ c_customer_id as customer_id - , coalesce(c_last_name,'') || ', ' || coalesce(c_first_name,'') as customername - from customer - ,customer_address - ,customer_demographics - ,household_demographics - ,income_band - ,store_returns - where ca_city = 'Cedar Grove' - and c_current_addr_sk = ca_address_sk - and ib_lower_bound >= 32432 - and ib_upper_bound <= 32432 + 50000 - and ib_income_band_sk = hd_income_band_sk - and cd_demo_sk = c_current_cdemo_sk - and hd_demo_sk = c_current_hdemo_sk - and sr_cdemo_sk = cd_demo_sk - order by c_customer_id - limit 100; - --- end template query84.tpl query 58 in stream 2 --- start template query4.tpl query 59 in stream 2 -with /* TPC-DS query4.tpl 0.93 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(((ss_ext_list_price-ss_ext_wholesale_cost-ss_ext_discount_amt)+ss_ext_sales_price)/2) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((cs_ext_list_price-cs_ext_wholesale_cost-cs_ext_discount_amt)+cs_ext_sales_price)/2) ) year_total - ,'c' sale_type - from customer - ,catalog_sales - ,date_dim - where c_customer_sk = cs_bill_customer_sk - and cs_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year -union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((ws_ext_list_price-ws_ext_wholesale_cost-ws_ext_discount_amt)+ws_ext_sales_price)/2) ) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_birth_country - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_c_firstyear - ,year_total t_c_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_c_secyear.customer_id - and t_s_firstyear.customer_id = t_c_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_c_firstyear.sale_type = 'c' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_c_secyear.sale_type = 'c' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 1998 - and t_s_secyear.dyear = 1998+1 - and t_c_firstyear.dyear = 1998 - and t_c_secyear.dyear = 1998+1 - and t_w_firstyear.dyear = 1998 - and t_w_secyear.dyear = 1998+1 - and t_s_firstyear.year_total > 0 - and t_c_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_birth_country -limit 100; - --- end template query4.tpl query 59 in stream 2 --- start template query37.tpl query 60 in stream 2 -select /* TPC-DS query37.tpl 0.31 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, catalog_sales - where i_current_price between 26 and 26 + 30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('2002-05-20' as date) and dateadd(day,60,cast('2002-05-20' as date)) - and i_manufact_id in (754,855,932,911) - and inv_quantity_on_hand between 100 and 500 - and cs_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query37.tpl query 60 in stream 2 --- start template query35a.tpl query 61 in stream 2 -select /* TPC-DS query35a.tpl 0.47 */ - ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - count(*) cnt1, - avg(cd_dep_count), - max(cd_dep_count), - max(cd_dep_count), - cd_dep_employed_count, - count(*) cnt2, - avg(cd_dep_employed_count), - max(cd_dep_employed_count), - max(cd_dep_employed_count), - cd_dep_college_count, - count(*) cnt3, - avg(cd_dep_college_count), - max(cd_dep_college_count), - max(cd_dep_college_count) - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2000 and - d_qoy < 4) and - exists (select * from - (select ws_bill_customer_sk customsk - from web_sales,date_dim - where - ws_sold_date_sk = d_date_sk and - d_year = 2000 and - d_qoy < 4 - union all - select cs_ship_customer_sk customsk - from catalog_sales,date_dim - where - cs_sold_date_sk = d_date_sk and - d_year = 2000 and - d_qoy < 4)x - where x.customsk = c.c_customer_sk) - group by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - limit 100; - --- end template query35a.tpl query 61 in stream 2 --- start template query94.tpl query 62 in stream 2 -select /* TPC-DS query94.tpl 0.17 */ - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '1999-2-01' and - dateadd(day,60,cast('1999-2-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'VA' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and exists (select * - from web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) -and not exists(select * - from web_returns wr1 - where ws1.ws_order_number = wr1.wr_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query94.tpl query 62 in stream 2 --- start template query58.tpl query 63 in stream 2 -with /* TPC-DS query58.tpl 0.19 */ ss_items as - (select i_item_id item_id - ,sum(ss_ext_sales_price) ss_item_rev - from store_sales - ,item - ,date_dim - where ss_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '2001-06-28')) - and ss_sold_date_sk = d_date_sk - group by i_item_id), - cs_items as - (select i_item_id item_id - ,sum(cs_ext_sales_price) cs_item_rev - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '2001-06-28')) - and cs_sold_date_sk = d_date_sk - group by i_item_id), - ws_items as - (select i_item_id item_id - ,sum(ws_ext_sales_price) ws_item_rev - from web_sales - ,item - ,date_dim - where ws_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq =(select d_week_seq - from date_dim - where d_date = '2001-06-28')) - and ws_sold_date_sk = d_date_sk - group by i_item_id) - select ss_items.item_id - ,ss_item_rev - ,ss_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ss_dev - ,cs_item_rev - ,cs_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 cs_dev - ,ws_item_rev - ,ws_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ws_dev - ,(ss_item_rev+cs_item_rev+ws_item_rev)/3 average - from ss_items,cs_items,ws_items - where ss_items.item_id=cs_items.item_id - and ss_items.item_id=ws_items.item_id - and ss_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - and ss_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and cs_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and cs_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and ws_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and ws_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - order by item_id - ,ss_item_rev - limit 100; - --- end template query58.tpl query 63 in stream 2 --- start template query96.tpl query 64 in stream 2 -select /* TPC-DS query96.tpl 0.1 */ count(*) -from store_sales - ,household_demographics - ,time_dim, store -where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 15 - and time_dim.t_minute >= 30 - and household_demographics.hd_dep_count = 0 - and store.s_store_name = 'ese' -order by count(*) -limit 100; - --- end template query96.tpl query 64 in stream 2 --- start template query12.tpl query 65 in stream 2 -select /* TPC-DS query12.tpl 0.64 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ws_ext_sales_price) as itemrevenue - ,sum(ws_ext_sales_price)*100/sum(sum(ws_ext_sales_price)) over - (partition by i_class) as revenueratio -from - web_sales - ,item - ,date_dim -where - ws_item_sk = i_item_sk - and i_category in ('Women', 'Shoes', 'Electronics') - and ws_sold_date_sk = d_date_sk - and d_date between cast('2000-06-15' as date) - and dateadd(day,30,cast('2000-06-15' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query12.tpl query 65 in stream 2 --- start template query29.tpl query 66 in stream 2 -select /* TPC-DS query29.tpl 0.53 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,max(ss_quantity) as store_sales_quantity - ,max(sr_return_quantity) as store_returns_quantity - ,max(cs_quantity) as catalog_sales_quantity - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 1999 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 4 + 3 - and d2.d_year = 1999 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_year in (1999,1999+1,1999+2) - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query29.tpl query 66 in stream 2 --- start template query22a.tpl query 67 in stream 2 -with /* TPC-DS query22a.tpl 0.55 */ results as -(select i_product_name - ,i_brand - ,i_class - ,i_category - ,avg(inv_quantity_on_hand) qoh - from inventory - ,date_dim - ,item --- ,warehouse - where inv_date_sk=d_date_sk - and inv_item_sk=i_item_sk --- and inv_warehouse_sk = w_warehouse_sk - and d_month_seq between 1218 and 1218 + 11 - group by i_product_name,i_brand,i_class,i_category), -results_rollup as -(select i_product_name, i_brand, i_class, i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class,i_category -union all -select i_product_name, i_brand, i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class -union all -select i_product_name, i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand -union all -select i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name -union all -select null i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results) - select i_product_name, i_brand, i_class, i_category,qoh - from results_rollup - order by qoh, i_product_name, i_brand, i_class, i_category -limit 100; - --- end template query22a.tpl query 67 in stream 2 --- start template query51.tpl query 68 in stream 2 -WITH /* TPC-DS query51.tpl 0.46 */ web_v1 as ( -select - ws_item_sk item_sk, d_date, - sum(sum(ws_sales_price)) - over (partition by ws_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from web_sales - ,date_dim -where ws_sold_date_sk=d_date_sk - and d_month_seq between 1190 and 1190+11 - and ws_item_sk is not NULL -group by ws_item_sk, d_date), -store_v1 as ( -select - ss_item_sk item_sk, d_date, - sum(sum(ss_sales_price)) - over (partition by ss_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from store_sales - ,date_dim -where ss_sold_date_sk=d_date_sk - and d_month_seq between 1190 and 1190+11 - and ss_item_sk is not NULL -group by ss_item_sk, d_date) - select * -from (select item_sk - ,d_date - ,web_sales - ,store_sales - ,max(web_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) web_cumulative - ,max(store_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) store_cumulative - from (select case when web.item_sk is not null then web.item_sk else store.item_sk end item_sk - ,case when web.d_date is not null then web.d_date else store.d_date end d_date - ,web.cume_sales web_sales - ,store.cume_sales store_sales - from web_v1 web full outer join store_v1 store on (web.item_sk = store.item_sk - and web.d_date = store.d_date) - )x )y -where web_cumulative > store_cumulative -order by item_sk - ,d_date -limit 100; - --- end template query51.tpl query 68 in stream 2 --- start template query36a.tpl query 69 in stream 2 -with /* TPC-DS query36a.tpl 0.21 */ results as - (select - sum(ss_net_profit) as ss_net_profit, sum(ss_ext_sales_price) as ss_ext_sales_price, - sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin - ,i_category - ,i_class - ,0 as g_category, 0 as g_class - from - store_sales - ,date_dim d1 - ,item - ,store - where - d1.d_year = 2002 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and s_state in ('WV','NE','MN','OH', - 'SD','IN','MI','AL') - group by i_category,i_class) - , - results_rollup as - (select gross_margin ,i_category ,i_class,0 as t_category, 0 as t_class, 0 as lochierarchy from results - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - i_category, NULL AS i_class, 0 as t_category, 1 as t_class, 1 as lochierarchy from results group by i_category - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - NULL AS i_category ,NULL AS i_class, 1 as t_category, 1 as t_class, 2 as lochierarchy from results) - select - gross_margin ,i_category ,i_class, lochierarchy,rank() over ( - partition by lochierarchy, case when t_class = 0 then i_category end - order by gross_margin asc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then i_category end - ,rank_within_parent - limit 100; - --- end template query36a.tpl query 69 in stream 2 --- start template query43.tpl query 70 in stream 2 -select /* TPC-DS query43.tpl 0.15 */ s_store_name, s_store_id, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from date_dim, store_sales, store - where d_date_sk = ss_sold_date_sk and - s_store_sk = ss_store_sk and - s_gmt_offset = -5 and - d_year = 2000 - group by s_store_name, s_store_id - order by s_store_name, s_store_id,sun_sales,mon_sales,tue_sales,wed_sales,thu_sales,fri_sales,sat_sales - limit 100; - --- end template query43.tpl query 70 in stream 2 --- start template query64.tpl query 71 in stream 2 -with /* TPC-DS query64.tpl 0.20 */ cs_ui as - (select cs_item_sk - ,sum(cs_ext_list_price) as sale,sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit) as refund - from catalog_sales - ,catalog_returns - where cs_item_sk = cr_item_sk - and cs_order_number = cr_order_number - group by cs_item_sk - having sum(cs_ext_list_price)>2*sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit)), -cross_sales as - (select i_product_name product_name - ,i_item_sk item_sk - ,s_store_name store_name - ,s_zip store_zip - ,ad1.ca_street_number b_street_number - ,ad1.ca_street_name b_street_name - ,ad1.ca_city b_city - ,ad1.ca_zip b_zip - ,ad2.ca_street_number c_street_number - ,ad2.ca_street_name c_street_name - ,ad2.ca_city c_city - ,ad2.ca_zip c_zip - ,d1.d_year as syear - ,d2.d_year as fsyear - ,d3.d_year s2year - ,count(*) cnt - ,sum(ss_wholesale_cost) s1 - ,sum(ss_list_price) s2 - ,sum(ss_coupon_amt) s3 - FROM store_sales - ,store_returns - ,cs_ui - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,customer - ,customer_demographics cd1 - ,customer_demographics cd2 - ,promotion - ,household_demographics hd1 - ,household_demographics hd2 - ,customer_address ad1 - ,customer_address ad2 - ,income_band ib1 - ,income_band ib2 - ,item - WHERE ss_store_sk = s_store_sk AND - ss_sold_date_sk = d1.d_date_sk AND - ss_customer_sk = c_customer_sk AND - ss_cdemo_sk= cd1.cd_demo_sk AND - ss_hdemo_sk = hd1.hd_demo_sk AND - ss_addr_sk = ad1.ca_address_sk and - ss_item_sk = i_item_sk and - ss_item_sk = sr_item_sk and - ss_ticket_number = sr_ticket_number and - ss_item_sk = cs_ui.cs_item_sk and - c_current_cdemo_sk = cd2.cd_demo_sk AND - c_current_hdemo_sk = hd2.hd_demo_sk AND - c_current_addr_sk = ad2.ca_address_sk and - c_first_sales_date_sk = d2.d_date_sk and - c_first_shipto_date_sk = d3.d_date_sk and - ss_promo_sk = p_promo_sk and - hd1.hd_income_band_sk = ib1.ib_income_band_sk and - hd2.hd_income_band_sk = ib2.ib_income_band_sk and - cd1.cd_marital_status <> cd2.cd_marital_status and - i_color in ('drab','puff','olive','chartreuse','sky','maroon') and - i_current_price between 1 and 1 + 10 and - i_current_price between 1 + 1 and 1 + 15 -group by i_product_name - ,i_item_sk - ,s_store_name - ,s_zip - ,ad1.ca_street_number - ,ad1.ca_street_name - ,ad1.ca_city - ,ad1.ca_zip - ,ad2.ca_street_number - ,ad2.ca_street_name - ,ad2.ca_city - ,ad2.ca_zip - ,d1.d_year - ,d2.d_year - ,d3.d_year -) -select cs1.product_name - ,cs1.store_name - ,cs1.store_zip - ,cs1.b_street_number - ,cs1.b_street_name - ,cs1.b_city - ,cs1.b_zip - ,cs1.c_street_number - ,cs1.c_street_name - ,cs1.c_city - ,cs1.c_zip - ,cs1.syear - ,cs1.cnt - ,cs1.s1 as s11 - ,cs1.s2 as s21 - ,cs1.s3 as s31 - ,cs2.s1 as s12 - ,cs2.s2 as s22 - ,cs2.s3 as s32 - ,cs2.syear - ,cs2.cnt -from cross_sales cs1,cross_sales cs2 -where cs1.item_sk=cs2.item_sk and - cs1.syear = 1999 and - cs2.syear = 1999 + 1 and - cs2.cnt <= cs1.cnt and - cs1.store_name = cs2.store_name and - cs1.store_zip = cs2.store_zip -order by cs1.product_name - ,cs1.store_name - ,cs2.cnt - ,cs1.s1 - ,cs2.s1; - --- end template query64.tpl query 71 in stream 2 --- start template query20.tpl query 72 in stream 2 -select /* TPC-DS query20.tpl 0.65 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(cs_ext_sales_price) as itemrevenue - ,sum(cs_ext_sales_price)*100/sum(sum(cs_ext_sales_price)) over - (partition by i_class) as revenueratio - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and i_category in ('Electronics', 'Sports', 'Shoes') - and cs_sold_date_sk = d_date_sk - and d_date between cast('1999-05-22' as date) - and dateadd(day,30,cast('1999-05-22' as date)) - group by i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - order by i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query20.tpl query 72 in stream 2 --- start template query57.tpl query 73 in stream 2 -with /* TPC-DS query57.tpl 0.70 */ v1 as( - select i_category, i_brand, - cc_name, - d_year, d_moy, - sum(cs_sales_price) sum_sales, - avg(sum(cs_sales_price)) over - (partition by i_category, i_brand, - cc_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - cc_name - order by d_year, d_moy) rn - from item, catalog_sales, date_dim, call_center - where cs_item_sk = i_item_sk and - cs_sold_date_sk = d_date_sk and - cc_call_center_sk= cs_call_center_sk and - ( - d_year = 2001 or - ( d_year = 2001-1 and d_moy =12) or - ( d_year = 2001+1 and d_moy =1) - ) - group by i_category, i_brand, - cc_name , d_year, d_moy), - v2 as( - select v1.i_brand - ,v1.d_year, v1.d_moy - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1. cc_name = v1_lag. cc_name and - v1. cc_name = v1_lead. cc_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 2001 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, nsum - limit 100; - --- end template query57.tpl query 73 in stream 2 --- start template query9.tpl query 74 in stream 2 -select /* TPC-DS query9.tpl 0.49 */ case when (select count(*) - from store_sales - where ss_quantity between 1 and 20) > 138306382 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 1 and 20) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 1 and 20) end bucket1 , - case when (select count(*) - from store_sales - where ss_quantity between 21 and 40) > 15599360 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 21 and 40) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 21 and 40) end bucket2, - case when (select count(*) - from store_sales - where ss_quantity between 41 and 60) > 47846449 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 41 and 60) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 41 and 60) end bucket3, - case when (select count(*) - from store_sales - where ss_quantity between 61 and 80) > 37509033 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 61 and 80) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 61 and 80) end bucket4, - case when (select count(*) - from store_sales - where ss_quantity between 81 and 100) > 128429629 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 81 and 100) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 81 and 100) end bucket5 -from reason -where r_reason_sk = 1 -; - --- end template query9.tpl query 74 in stream 2 --- start template query52.tpl query 75 in stream 2 -select /* TPC-DS query52.tpl 0.59 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_sales_price) ext_price - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=12 - and dt.d_year=2001 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,ext_price desc - ,brand_id -limit 100 ; - --- end template query52.tpl query 75 in stream 2 --- start template query49.tpl query 76 in stream 2 -select /* TPC-DS query49.tpl 0.48 */ channel, item, return_ratio, return_rank, currency_rank from - (select - 'web' as channel - ,web.item - ,web.return_ratio - ,web.return_rank - ,web.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select ws.ws_item_sk as item - ,(cast(sum(coalesce(wr.wr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(wr.wr_return_amt,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - web_sales ws left outer join web_returns wr - on (ws.ws_order_number = wr.wr_order_number and - ws.ws_item_sk = wr.wr_item_sk) - ,date_dim - where - wr.wr_return_amt > 10000 - and ws.ws_net_profit > 1 - and ws.ws_net_paid > 0 - and ws.ws_quantity > 0 - and ws_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 11 - group by ws.ws_item_sk - ) in_web - ) web - where - ( - web.return_rank <= 10 - or - web.currency_rank <= 10 - ) - union - select - 'catalog' as channel - ,catalog.item - ,catalog.return_ratio - ,catalog.return_rank - ,catalog.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select - cs.cs_item_sk as item - ,(cast(sum(coalesce(cr.cr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(cr.cr_return_amount,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - catalog_sales cs left outer join catalog_returns cr - on (cs.cs_order_number = cr.cr_order_number and - cs.cs_item_sk = cr.cr_item_sk) - ,date_dim - where - cr.cr_return_amount > 10000 - and cs.cs_net_profit > 1 - and cs.cs_net_paid > 0 - and cs.cs_quantity > 0 - and cs_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 11 - group by cs.cs_item_sk - ) in_cat - ) catalog - where - ( - catalog.return_rank <= 10 - or - catalog.currency_rank <=10 - ) - union - select - 'store' as channel - ,store.item - ,store.return_ratio - ,store.return_rank - ,store.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select sts.ss_item_sk as item - ,(cast(sum(coalesce(sr.sr_return_quantity,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(sr.sr_return_amt,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - store_sales sts left outer join store_returns sr - on (sts.ss_ticket_number = sr.sr_ticket_number and sts.ss_item_sk = sr.sr_item_sk) - ,date_dim - where - sr.sr_return_amt > 10000 - and sts.ss_net_profit > 1 - and sts.ss_net_paid > 0 - and sts.ss_quantity > 0 - and ss_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 11 - group by sts.ss_item_sk - ) in_store - ) store - where ( - store.return_rank <= 10 - or - store.currency_rank <= 10 - ) - ) - order by 1,4,5,2 - limit 100; - --- end template query49.tpl query 76 in stream 2 --- start template query71.tpl query 77 in stream 2 -select /* TPC-DS query71.tpl 0.72 */ i_brand_id brand_id, i_brand brand,t_hour,t_minute, - sum(ext_price) ext_price - from item, (select ws_ext_sales_price as ext_price, - ws_sold_date_sk as sold_date_sk, - ws_item_sk as sold_item_sk, - ws_sold_time_sk as time_sk - from web_sales,date_dim - where d_date_sk = ws_sold_date_sk - and d_moy=11 - and d_year=1998 - union all - select cs_ext_sales_price as ext_price, - cs_sold_date_sk as sold_date_sk, - cs_item_sk as sold_item_sk, - cs_sold_time_sk as time_sk - from catalog_sales,date_dim - where d_date_sk = cs_sold_date_sk - and d_moy=11 - and d_year=1998 - union all - select ss_ext_sales_price as ext_price, - ss_sold_date_sk as sold_date_sk, - ss_item_sk as sold_item_sk, - ss_sold_time_sk as time_sk - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - and d_moy=11 - and d_year=1998 - ) tmp,time_dim - where - sold_item_sk = i_item_sk - and i_manager_id=1 - and time_sk = t_time_sk - and (t_meal_time = 'breakfast' or t_meal_time = 'dinner') - group by i_brand, i_brand_id,t_hour,t_minute - order by ext_price desc, i_brand_id - ; - --- end template query71.tpl query 77 in stream 2 --- start template query72.tpl query 78 in stream 2 -select /* TPC-DS query72.tpl 0.87 */ i_item_desc - ,w_warehouse_name - ,d1.d_week_seq - ,sum(case when p_promo_sk is null then 1 else 0 end) no_promo - ,sum(case when p_promo_sk is not null then 1 else 0 end) promo - ,count(*) total_cnt -from catalog_sales -join inventory on (cs_item_sk = inv_item_sk) -join warehouse on (w_warehouse_sk=inv_warehouse_sk) -join item on (i_item_sk = cs_item_sk) -join customer_demographics on (cs_bill_cdemo_sk = cd_demo_sk) -join household_demographics on (cs_bill_hdemo_sk = hd_demo_sk) -join date_dim d1 on (cs_sold_date_sk = d1.d_date_sk) -join date_dim d2 on (inv_date_sk = d2.d_date_sk) -join date_dim d3 on (cs_ship_date_sk = d3.d_date_sk) -left outer join promotion on (cs_promo_sk=p_promo_sk) -left outer join catalog_returns on (cr_item_sk = cs_item_sk and cr_order_number = cs_order_number) -where d1.d_week_seq = d2.d_week_seq - and inv_quantity_on_hand < cs_quantity - and d3.d_date > d1.d_date + 5 - and hd_buy_potential = '1001-5000' - and d1.d_year = 1999 - and cd_marital_status = 'M' -group by i_item_desc,w_warehouse_name,d1.d_week_seq -order by total_cnt desc, i_item_desc, w_warehouse_name, d_week_seq -limit 100; - --- end template query72.tpl query 78 in stream 2 --- start template query70a.tpl query 79 in stream 2 -with /* TPC-DS query70a.tpl 0.34 */ results as -( select - sum(ss_net_profit) as total_sum ,s_state ,s_county, 0 as gstate, 0 as g_county - from - store_sales - ,date_dim d1 - ,store - where - d1.d_month_seq between 1222 and 1222 + 11 - and d1.d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - and s_state in - ( select s_state - from (select s_state as s_state, - rank() over ( partition by s_state order by sum(ss_net_profit) desc) as ranking - from store_sales, store, date_dim - where d_month_seq between 1222 and 1222 + 11 - and d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - group by s_state - ) tmp1 - where ranking <= 5) - group by s_state,s_county) , - results_rollup as -(select total_sum ,s_state ,s_county, 0 as g_state, 0 as g_county, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum,s_state, NULL as s_county, 0 as g_state, 1 as g_county, 1 as lochierarchy from results group by s_state - union - select sum(total_sum) as total_sum ,NULL as s_state ,NULL as s_county, 1 as g_state, 1 as g_county, 2 as lochierarchy from results) - select total_sum ,s_state ,s_county, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_county = 0 then s_state end - order by total_sum desc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then s_state end - ,rank_within_parent - limit 100; - --- end template query70a.tpl query 79 in stream 2 --- start template query7.tpl query 80 in stream 2 -select /* TPC-DS query7.tpl 0.2 */ i_item_id, - avg(ss_quantity) agg1, - avg(ss_list_price) agg2, - avg(ss_coupon_amt) agg3, - avg(ss_sales_price) agg4 - from store_sales, customer_demographics, date_dim, item, promotion - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_cdemo_sk = cd_demo_sk and - ss_promo_sk = p_promo_sk and - cd_gender = 'F' and - cd_marital_status = 'U' and - cd_education_status = 'College' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 2001 - group by i_item_id - order by i_item_id - limit 100; - --- end template query7.tpl query 80 in stream 2 --- start template query97.tpl query 81 in stream 2 -with /* TPC-DS query97.tpl 0.38 */ ssci as ( -select ss_customer_sk customer_sk - ,ss_item_sk item_sk -from store_sales,date_dim -where ss_sold_date_sk = d_date_sk - and d_month_seq between 1184 and 1184 + 11 -group by ss_customer_sk - ,ss_item_sk), -csci as( - select cs_bill_customer_sk customer_sk - ,cs_item_sk item_sk -from catalog_sales,date_dim -where cs_sold_date_sk = d_date_sk - and d_month_seq between 1184 and 1184 + 11 -group by cs_bill_customer_sk - ,cs_item_sk) - select sum(case when ssci.customer_sk is not null and csci.customer_sk is null then 1 else 0 end) store_only - ,sum(case when ssci.customer_sk is null and csci.customer_sk is not null then 1 else 0 end) catalog_only - ,sum(case when ssci.customer_sk is not null and csci.customer_sk is not null then 1 else 0 end) store_and_catalog -from ssci full outer join csci on (ssci.customer_sk=csci.customer_sk - and ssci.item_sk = csci.item_sk) -limit 100; - --- end template query97.tpl query 81 in stream 2 --- start template query33.tpl query 82 in stream 2 -with /* TPC-DS query33.tpl 0.22 */ ss as ( - select - i_manufact_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Books')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 7 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id), - cs as ( - select - i_manufact_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Books')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 7 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id), - ws as ( - select - i_manufact_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Books')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 7 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id) - select i_manufact_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_manufact_id - order by total_sales -limit 100; - --- end template query33.tpl query 82 in stream 2 --- start template query79.tpl query 83 in stream 2 -select /* TPC-DS query79.tpl 0.89 */ - c_last_name,c_first_name,substring(s_city,1,30),ss_ticket_number,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,store.s_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (household_demographics.hd_dep_count = 0 or household_demographics.hd_vehicle_count > 2) - and date_dim.d_dow = 1 - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_number_employees between 200 and 295 - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,store.s_city) ms,customer - where ss_customer_sk = c_customer_sk - order by c_last_name,c_first_name,substring(s_city,1,30), profit -limit 100; - --- end template query79.tpl query 83 in stream 2 --- start template query32.tpl query 84 in stream 2 -select /* TPC-DS query32.tpl 0.7 */ sum(cs_ext_discount_amt) as "excess discount amount" -from - catalog_sales - ,item - ,date_dim -where -i_manufact_id = 457 -and i_item_sk = cs_item_sk -and d_date between '1998-01-11' and - dateadd(day,90,cast('1998-01-11' as date)) -and d_date_sk = cs_sold_date_sk -and cs_ext_discount_amt - > ( - select - 1.3 * avg(cs_ext_discount_amt) - from - catalog_sales - ,date_dim - where - cs_item_sk = i_item_sk - and d_date between '1998-01-11' and - dateadd(day,90,cast('1998-01-11' as date)) - and d_date_sk = cs_sold_date_sk - ) -limit 100; - --- end template query32.tpl query 84 in stream 2 --- start template query78.tpl query 85 in stream 2 -with /* TPC-DS query78.tpl 0.10 */ ws as - (select d_year AS ws_sold_year, ws_item_sk, - ws_bill_customer_sk ws_customer_sk, - sum(ws_quantity) ws_qty, - sum(ws_wholesale_cost) ws_wc, - sum(ws_sales_price) ws_sp - from web_sales - left join web_returns on wr_order_number=ws_order_number and ws_item_sk=wr_item_sk - join date_dim on ws_sold_date_sk = d_date_sk - where wr_order_number is null - group by d_year, ws_item_sk, ws_bill_customer_sk - ), -cs as - (select d_year AS cs_sold_year, cs_item_sk, - cs_bill_customer_sk cs_customer_sk, - sum(cs_quantity) cs_qty, - sum(cs_wholesale_cost) cs_wc, - sum(cs_sales_price) cs_sp - from catalog_sales - left join catalog_returns on cr_order_number=cs_order_number and cs_item_sk=cr_item_sk - join date_dim on cs_sold_date_sk = d_date_sk - where cr_order_number is null - group by d_year, cs_item_sk, cs_bill_customer_sk - ), -ss as - (select d_year AS ss_sold_year, ss_item_sk, - ss_customer_sk, - sum(ss_quantity) ss_qty, - sum(ss_wholesale_cost) ss_wc, - sum(ss_sales_price) ss_sp - from store_sales - left join store_returns on sr_ticket_number=ss_ticket_number and ss_item_sk=sr_item_sk - join date_dim on ss_sold_date_sk = d_date_sk - where sr_ticket_number is null - group by d_year, ss_item_sk, ss_customer_sk - ) - select -ss_sold_year, ss_item_sk, ss_customer_sk, -round(ss_qty/(coalesce(ws_qty,0)+coalesce(cs_qty,0)),2) ratio, -ss_qty store_qty, ss_wc store_wholesale_cost, ss_sp store_sales_price, -coalesce(ws_qty,0)+coalesce(cs_qty,0) other_chan_qty, -coalesce(ws_wc,0)+coalesce(cs_wc,0) other_chan_wholesale_cost, -coalesce(ws_sp,0)+coalesce(cs_sp,0) other_chan_sales_price -from ss -left join ws on (ws_sold_year=ss_sold_year and ws_item_sk=ss_item_sk and ws_customer_sk=ss_customer_sk) -left join cs on (cs_sold_year=ss_sold_year and cs_item_sk=ss_item_sk and cs_customer_sk=ss_customer_sk) -where (coalesce(ws_qty,0)>0 or coalesce(cs_qty, 0)>0) and ss_sold_year=2000 -order by - ss_sold_year, ss_item_sk, ss_customer_sk, - ss_qty desc, ss_wc desc, ss_sp desc, - other_chan_qty, - other_chan_wholesale_cost, - other_chan_sales_price, - ratio -limit 100; - --- end template query78.tpl query 85 in stream 2 --- start template query18a.tpl query 86 in stream 2 -with /* TPC-DS query18a.tpl 0.90 */ results as - (select i_item_id, - ca_country, - ca_state, - ca_county, - cast(cs_quantity as decimal(12,2)) agg1, - cast(cs_list_price as decimal(12,2)) agg2, - cast(cs_coupon_amt as decimal(12,2)) agg3, - cast(cs_sales_price as decimal(12,2)) agg4, - cast(cs_net_profit as decimal(12,2)) agg5, - cast(c_birth_year as decimal(12,2)) agg6, - cast(cd1.cd_dep_count as decimal(12,2)) agg7 - from catalog_sales, customer_demographics cd1, customer_demographics cd2, customer, customer_address, date_dim, item - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd1.cd_demo_sk and - cs_bill_customer_sk = c_customer_sk and - cd1.cd_gender = 'M' and - cd1.cd_education_status = 'Unknown' and - c_current_cdemo_sk = cd2.cd_demo_sk and - c_current_addr_sk = ca_address_sk and - c_birth_month in (12,10,2,11,3,9) and - d_year = 2002 and - ca_state in ('AL','FL','NC','OH','SC','NY','MS') - ) - select i_item_id, ca_country, ca_state, ca_county, agg1, agg2, agg3, agg4, agg5, agg6, agg7 - from ( - select i_item_id, ca_country, ca_state, ca_county, avg(agg1) agg1, - avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state, ca_county - union all - select i_item_id, ca_country, ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state - union all - select i_item_id, ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country - union all - select i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - ) foo - order by ca_country, ca_state, ca_county, i_item_id - limit 100; - --- end template query18a.tpl query 86 in stream 2 --- start template query65.tpl query 87 in stream 2 -select /* TPC-DS query65.tpl 0.71 */ - s_store_name, - i_item_desc, - sc.revenue, - i_current_price, - i_wholesale_cost, - i_brand - from store, item, - (select ss_store_sk, avg(revenue) as ave - from - (select ss_store_sk, ss_item_sk, - sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1209 and 1209+11 - group by ss_store_sk, ss_item_sk) sa - group by ss_store_sk) sb, - (select ss_store_sk, ss_item_sk, sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1209 and 1209+11 - group by ss_store_sk, ss_item_sk) sc - where sb.ss_store_sk = sc.ss_store_sk and - sc.revenue <= 0.1 * sb.ave and - s_store_sk = sc.ss_store_sk and - i_item_sk = sc.ss_item_sk - order by s_store_name, i_item_desc -limit 100; - --- end template query65.tpl query 87 in stream 2 --- start template query60.tpl query 88 in stream 2 -with /* TPC-DS query60.tpl 0.29 */ ss as ( - select - i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Jewelry')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 8 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -7 - group by i_item_id), - cs as ( - select - i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Jewelry')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 8 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -7 - group by i_item_id), - ws as ( - select - i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Jewelry')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 8 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -7 - group by i_item_id) - select - i_item_id -,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by i_item_id - ,total_sales - limit 100; - --- end template query60.tpl query 88 in stream 2 --- start template query34.tpl query 89 in stream 2 -select /* TPC-DS query34.tpl 0.73 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (date_dim.d_dom between 1 and 3 or date_dim.d_dom between 25 and 28) - and (household_demographics.hd_buy_potential = '1001-5000' or - household_demographics.hd_buy_potential = 'Unknown') - and household_demographics.hd_vehicle_count > 0 - and (case when household_demographics.hd_vehicle_count > 0 - then household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count - else null - end) > 1.2 - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_county in ('Daviess County','Huron County','Mobile County','Pennington County', - 'Williamson County','Coal County','Marshall County','Sumner County') - group by ss_ticket_number,ss_customer_sk) dn,customer - where ss_customer_sk = c_customer_sk - and cnt between 15 and 20 - order by c_last_name,c_first_name,c_salutation,c_preferred_cust_flag desc, ss_ticket_number; - --- end template query34.tpl query 89 in stream 2 --- start template query3.tpl query 90 in stream 2 -select /* TPC-DS query3.tpl 0.45 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_discount_amt) sum_agg - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manufact_id = 568 - and dt.d_moy=11 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,sum_agg desc - ,brand_id - limit 100; - --- end template query3.tpl query 90 in stream 2 --- start template query13.tpl query 91 in stream 2 -select /* TPC-DS query13.tpl 0.91 */ avg(ss_quantity) - ,avg(ss_ext_sales_price) - ,avg(ss_ext_wholesale_cost) - ,sum(ss_ext_wholesale_cost) - from store_sales - ,store - ,customer_demographics - ,household_demographics - ,customer_address - ,date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2001 - and((ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'W' - and cd_education_status = '2 yr Degree' - and ss_sales_price between 100.00 and 150.00 - and hd_dep_count = 3 - )or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'D' - and cd_education_status = 'Secondary' - and ss_sales_price between 50.00 and 100.00 - and hd_dep_count = 1 - ) or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'M' - and cd_education_status = 'Advanced Degree' - and ss_sales_price between 150.00 and 200.00 - and hd_dep_count = 1 - )) - and((ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('IN', 'MI', 'WV') - and ss_net_profit between 100 and 200 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('KY', 'GA', 'SD') - and ss_net_profit between 150 and 300 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('CO', 'IL', 'ND') - and ss_net_profit between 50 and 250 - )) -; - --- end template query13.tpl query 91 in stream 2 --- start template query41.tpl query 92 in stream 2 -select /* TPC-DS query41.tpl 0.62 */ distinct(i_product_name) - from item i1 - where i_manufact_id between 966 and 966+40 - and (select count(*) as item_cnt - from item - where (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'sky' or i_color = 'lemon') and - (i_units = 'Pound' or i_units = 'Gross') and - (i_size = 'medium' or i_size = 'small') - ) or - (i_category = 'Women' and - (i_color = 'wheat' or i_color = 'thistle') and - (i_units = 'Ton' or i_units = 'Bundle') and - (i_size = 'N/A' or i_size = 'economy') - ) or - (i_category = 'Men' and - (i_color = 'steel' or i_color = 'seashell') and - (i_units = 'Bunch' or i_units = 'Unknown') and - (i_size = 'large' or i_size = 'extra large') - ) or - (i_category = 'Men' and - (i_color = 'khaki' or i_color = 'cyan') and - (i_units = 'Lb' or i_units = 'Tsp') and - (i_size = 'medium' or i_size = 'small') - ))) or - (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'pale' or i_color = 'cornflower') and - (i_units = 'Tbl' or i_units = 'Box') and - (i_size = 'medium' or i_size = 'small') - ) or - (i_category = 'Women' and - (i_color = 'forest' or i_color = 'blush') and - (i_units = 'Gram' or i_units = 'Ounce') and - (i_size = 'N/A' or i_size = 'economy') - ) or - (i_category = 'Men' and - (i_color = 'dim' or i_color = 'royal') and - (i_units = 'Oz' or i_units = 'Pallet') and - (i_size = 'large' or i_size = 'extra large') - ) or - (i_category = 'Men' and - (i_color = 'lime' or i_color = 'chiffon') and - (i_units = 'Each' or i_units = 'Cup') and - (i_size = 'medium' or i_size = 'small') - )))) > 0 - order by i_product_name - limit 100; - --- end template query41.tpl query 92 in stream 2 --- start template query92.tpl query 93 in stream 2 -select /* TPC-DS query92.tpl 0.44 */ - sum(ws_ext_discount_amt) as "Excess Discount Amount" -from - web_sales - ,item - ,date_dim -where -i_manufact_id = 483 -and i_item_sk = ws_item_sk -and d_date between '2002-03-25' and - dateadd(day,90,cast('2002-03-25' as date)) -and d_date_sk = ws_sold_date_sk -and ws_ext_discount_amt - > ( - SELECT - 1.3 * avg(ws_ext_discount_amt) - FROM - web_sales - ,date_dim - WHERE - ws_item_sk = i_item_sk - and d_date between '2002-03-25' and - dateadd(day,90,cast('2002-03-25' as date)) - and d_date_sk = ws_sold_date_sk - ) -order by sum(ws_ext_discount_amt) -limit 100; - --- end template query92.tpl query 93 in stream 2 --- start template query74.tpl query 94 in stream 2 -with /* TPC-DS query74.tpl 0.76 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,max(ss_net_paid) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1999,1999+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,max(ws_net_paid) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - and d_year in (1999,1999+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - ) - select - t_s_secyear.customer_id, t_s_secyear.customer_first_name, t_s_secyear.customer_last_name - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.year = 1999 - and t_s_secyear.year = 1999+1 - and t_w_firstyear.year = 1999 - and t_w_secyear.year = 1999+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - order by 3,1,2 -limit 100; - --- end template query74.tpl query 94 in stream 2 --- start template query46.tpl query 95 in stream 2 -select /* TPC-DS query46.tpl 0.23 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and (household_demographics.hd_dep_count = 9 or - household_demographics.hd_vehicle_count= -1) - and date_dim.d_dow in (6,0) - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_city in ('Centerville','Highland','Woodville','Pleasant Hill','Woodlawn') - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,ca_city) dn,customer,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - limit 100; - --- end template query46.tpl query 95 in stream 2 --- start template query89.tpl query 96 in stream 2 -select /* TPC-DS query89.tpl 0.56 */ * -from( -select i_category, i_class, i_brand, - s_store_name, s_company_name, - d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, s_store_name, s_company_name) - avg_monthly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - d_year in (1999) and - ((i_category in ('Music','Men','Books') and - i_class in ('country','sports-apparel','sports') - ) - or (i_category in ('Shoes','Children','Women') and - i_class in ('mens','newborn','fragrances') - )) -group by i_category, i_class, i_brand, - s_store_name, s_company_name, d_moy) tmp1 -where case when (avg_monthly_sales <> 0) then (abs(sum_sales - avg_monthly_sales) / avg_monthly_sales) else null end > 0.1 -order by sum_sales - avg_monthly_sales, s_store_name -limit 100; - --- end template query89.tpl query 96 in stream 2 --- start template query47.tpl query 97 in stream 2 -with /* TPC-DS query47.tpl 0.42 */ v1 as( - select i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, - s_store_name, s_company_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - s_store_name, s_company_name - order by d_year, d_moy) rn - from item, store_sales, date_dim, store - where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - ( - d_year = 2000 or - ( d_year = 2000-1 and d_moy =12) or - ( d_year = 2000+1 and d_moy =1) - ) - group by i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy), - v2 as( - select v1.s_company_name - ,v1.d_year, v1.d_moy - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1.s_store_name = v1_lag.s_store_name and - v1.s_store_name = v1_lead.s_store_name and - v1.s_company_name = v1_lag.s_company_name and - v1.s_company_name = v1_lead.s_company_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 2000 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, sum_sales - limit 100; - --- end template query47.tpl query 97 in stream 2 --- start template query66.tpl query 98 in stream 2 -select /* TPC-DS query66.tpl 0.39 */ - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - ,sum(jan_sales) as jan_sales - ,sum(feb_sales) as feb_sales - ,sum(mar_sales) as mar_sales - ,sum(apr_sales) as apr_sales - ,sum(may_sales) as may_sales - ,sum(jun_sales) as jun_sales - ,sum(jul_sales) as jul_sales - ,sum(aug_sales) as aug_sales - ,sum(sep_sales) as sep_sales - ,sum(oct_sales) as oct_sales - ,sum(nov_sales) as nov_sales - ,sum(dec_sales) as dec_sales - ,sum(jan_sales/w_warehouse_sq_ft) as jan_sales_per_sq_foot - ,sum(feb_sales/w_warehouse_sq_ft) as feb_sales_per_sq_foot - ,sum(mar_sales/w_warehouse_sq_ft) as mar_sales_per_sq_foot - ,sum(apr_sales/w_warehouse_sq_ft) as apr_sales_per_sq_foot - ,sum(may_sales/w_warehouse_sq_ft) as may_sales_per_sq_foot - ,sum(jun_sales/w_warehouse_sq_ft) as jun_sales_per_sq_foot - ,sum(jul_sales/w_warehouse_sq_ft) as jul_sales_per_sq_foot - ,sum(aug_sales/w_warehouse_sq_ft) as aug_sales_per_sq_foot - ,sum(sep_sales/w_warehouse_sq_ft) as sep_sales_per_sq_foot - ,sum(oct_sales/w_warehouse_sq_ft) as oct_sales_per_sq_foot - ,sum(nov_sales/w_warehouse_sq_ft) as nov_sales_per_sq_foot - ,sum(dec_sales/w_warehouse_sq_ft) as dec_sales_per_sq_foot - ,sum(jan_net) as jan_net - ,sum(feb_net) as feb_net - ,sum(mar_net) as mar_net - ,sum(apr_net) as apr_net - ,sum(may_net) as may_net - ,sum(jun_net) as jun_net - ,sum(jul_net) as jul_net - ,sum(aug_net) as aug_net - ,sum(sep_net) as sep_net - ,sum(oct_net) as oct_net - ,sum(nov_net) as nov_net - ,sum(dec_net) as dec_net - from ( - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'BARIAN' || ',' || 'DHL' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then ws_ext_sales_price* ws_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then ws_ext_sales_price* ws_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then ws_ext_sales_price* ws_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then ws_ext_sales_price* ws_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then ws_ext_sales_price* ws_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then ws_ext_sales_price* ws_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then ws_ext_sales_price* ws_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then ws_ext_sales_price* ws_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then ws_ext_sales_price* ws_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then ws_ext_sales_price* ws_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then ws_ext_sales_price* ws_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then ws_ext_sales_price* ws_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as dec_net - from - web_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - ws_warehouse_sk = w_warehouse_sk - and ws_sold_date_sk = d_date_sk - and ws_sold_time_sk = t_time_sk - and ws_ship_mode_sk = sm_ship_mode_sk - and d_year = 2000 - and t_time between 4524 and 4524+28800 - and sm_carrier in ('BARIAN','DHL') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - union all - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'BARIAN' || ',' || 'DHL' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then cs_sales_price* cs_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then cs_sales_price* cs_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then cs_sales_price* cs_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then cs_sales_price* cs_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then cs_sales_price* cs_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then cs_sales_price* cs_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then cs_sales_price* cs_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then cs_sales_price* cs_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then cs_sales_price* cs_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then cs_sales_price* cs_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then cs_sales_price* cs_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then cs_sales_price* cs_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then cs_net_paid * cs_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then cs_net_paid * cs_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then cs_net_paid * cs_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then cs_net_paid * cs_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then cs_net_paid * cs_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then cs_net_paid * cs_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then cs_net_paid * cs_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then cs_net_paid * cs_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then cs_net_paid * cs_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then cs_net_paid * cs_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then cs_net_paid * cs_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then cs_net_paid * cs_quantity else 0 end) as dec_net - from - catalog_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and cs_sold_time_sk = t_time_sk - and cs_ship_mode_sk = sm_ship_mode_sk - and d_year = 2000 - and t_time between 4524 AND 4524+28800 - and sm_carrier in ('BARIAN','DHL') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - ) x - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - order by w_warehouse_name - limit 100; - --- end template query66.tpl query 98 in stream 2 --- start template query48.tpl query 99 in stream 2 -select /* TPC-DS query48.tpl 0.74 */ sum (ss_quantity) - from store_sales, store, customer_demographics, customer_address, date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2002 - and - ( - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'D' - and - cd_education_status = '2 yr Degree' - and - ss_sales_price between 100.00 and 150.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'W' - and - cd_education_status = 'Secondary' - and - ss_sales_price between 50.00 and 100.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'M' - and - cd_education_status = '4 yr Degree' - and - ss_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('NC', 'SC', 'CA') - and ss_net_profit between 0 and 2000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('NE', 'GA', 'IL') - and ss_net_profit between 150 and 3000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('KY', 'AK', 'OR') - and ss_net_profit between 50 and 25000 - ) - ) -; - --- end template query48.tpl query 99 in stream 2 diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/10TB/queries/query_3.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/10TB/queries/query_3.sql deleted file mode 100644 index 3f679b19..00000000 --- a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/10TB/queries/query_3.sql +++ /dev/null @@ -1,5027 +0,0 @@ --- start template query89.tpl query 1 in stream 3 -select /* TPC-DS query89.tpl 0.56 */ * -from( -select i_category, i_class, i_brand, - s_store_name, s_company_name, - d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, s_store_name, s_company_name) - avg_monthly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - d_year in (2002) and - ((i_category in ('Books','Men','Music') and - i_class in ('mystery','shirts','country') - ) - or (i_category in ('Women','Children','Sports') and - i_class in ('fragrances','infants','sailing') - )) -group by i_category, i_class, i_brand, - s_store_name, s_company_name, d_moy) tmp1 -where case when (avg_monthly_sales <> 0) then (abs(sum_sales - avg_monthly_sales) / avg_monthly_sales) else null end > 0.1 -order by sum_sales - avg_monthly_sales, s_store_name -limit 100; - --- end template query89.tpl query 1 in stream 3 --- start template query5a.tpl query 2 in stream 3 -with /* TPC-DS query5a.tpl 0.98 */ ssr as - (select s_store_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ss_store_sk as store_sk, - ss_sold_date_sk as date_sk, - ss_ext_sales_price as sales_price, - ss_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from store_sales - union all - select sr_store_sk as store_sk, - sr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - sr_return_amt as return_amt, - sr_net_loss as net_loss - from store_returns - ) salesreturns, - date_dim, - store - where date_sk = d_date_sk - and d_date between cast('2000-08-23' as date) - and dateadd(day,14,cast('2000-08-23' as date)) - and store_sk = s_store_sk - group by s_store_id) - , - csr as - (select cp_catalog_page_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select cs_catalog_page_sk as page_sk, - cs_sold_date_sk as date_sk, - cs_ext_sales_price as sales_price, - cs_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from catalog_sales - union all - select cr_catalog_page_sk as page_sk, - cr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - cr_return_amount as return_amt, - cr_net_loss as net_loss - from catalog_returns - ) salesreturns, - date_dim, - catalog_page - where date_sk = d_date_sk - and d_date between cast('2000-08-23' as date) - and dateadd(day,14,cast('2000-08-23' as date)) - and page_sk = cp_catalog_page_sk - group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ws_web_site_sk as wsr_web_site_sk, - ws_sold_date_sk as date_sk, - ws_ext_sales_price as sales_price, - ws_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from web_sales - union all - select ws_web_site_sk as wsr_web_site_sk, - wr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - wr_return_amt as return_amt, - wr_net_loss as net_loss - from web_returns left outer join web_sales on - ( wr_item_sk = ws_item_sk - and wr_order_number = ws_order_number) - ) salesreturns, - date_dim, - web_site - where date_sk = d_date_sk - and d_date between cast('2000-08-23' as date) - and dateadd(day,14,cast('2000-08-23' as date)) - and wsr_web_site_sk = web_site_sk - group by web_site_id) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || s_store_id as id - , sales - , returns - , (profit - profit_loss) as profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || cp_catalog_page_id as id - , sales - , returns - , (profit - profit_loss) as profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , (profit - profit_loss) as profit - from wsr - ) x - group by channel, id) - select channel, id, sales, returns, profit from ( - select channel, id, sales, returns, profit from results - union - select channel, null as id, sum(sales), sum(returns), sum(profit) from results group by channel - union - select null as channel, null as id, sum(sales), sum(returns), sum(profit) from results) foo -order by channel, id -limit 100; - --- end template query5a.tpl query 2 in stream 3 --- start template query52.tpl query 3 in stream 3 -select /* TPC-DS query52.tpl 0.59 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_sales_price) ext_price - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=11 - and dt.d_year=1998 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,ext_price desc - ,brand_id -limit 100 ; - --- end template query52.tpl query 3 in stream 3 --- start template query62.tpl query 4 in stream 3 -select /* TPC-DS query62.tpl 0.24 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 30) and - (ws_ship_date_sk - ws_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 60) and - (ws_ship_date_sk - ws_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 90) and - (ws_ship_date_sk - ws_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - web_sales - ,warehouse - ,ship_mode - ,web_site - ,date_dim -where - d_month_seq between 1203 and 1203 + 11 -and ws_ship_date_sk = d_date_sk -and ws_warehouse_sk = w_warehouse_sk -and ws_ship_mode_sk = sm_ship_mode_sk -and ws_web_site_sk = web_site_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -limit 100; - --- end template query62.tpl query 4 in stream 3 --- start template query53.tpl query 5 in stream 3 -select /* TPC-DS query53.tpl 0.88 */ * from -(select i_manufact_id, -sum(ss_sales_price) sum_sales, -avg(sum(ss_sales_price)) over (partition by i_manufact_id) avg_quarterly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and -ss_sold_date_sk = d_date_sk and -ss_store_sk = s_store_sk and -d_month_seq in (1222,1222+1,1222+2,1222+3,1222+4,1222+5,1222+6,1222+7,1222+8,1222+9,1222+10,1222+11) and -((i_category in ('Books','Children','Electronics') and -i_class in ('personal','portable','reference','self-help') and -i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) -or(i_category in ('Women','Music','Men') and -i_class in ('accessories','classical','fragrances','pants') and -i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manufact_id, d_qoy ) tmp1 -where case when avg_quarterly_sales > 0 - then abs (sum_sales - avg_quarterly_sales)/ avg_quarterly_sales - else null end > 0.1 -order by avg_quarterly_sales, - sum_sales, - i_manufact_id -limit 100; - --- end template query53.tpl query 5 in stream 3 --- start template query7.tpl query 6 in stream 3 -select /* TPC-DS query7.tpl 0.2 */ i_item_id, - avg(ss_quantity) agg1, - avg(ss_list_price) agg2, - avg(ss_coupon_amt) agg3, - avg(ss_sales_price) agg4 - from store_sales, customer_demographics, date_dim, item, promotion - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_cdemo_sk = cd_demo_sk and - ss_promo_sk = p_promo_sk and - cd_gender = 'F' and - cd_marital_status = 'U' and - cd_education_status = '2 yr Degree' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 2001 - group by i_item_id - order by i_item_id - limit 100; - --- end template query7.tpl query 6 in stream 3 --- start template query39.tpl query 7 in stream 3 -with /* TPC-DS query39.tpl 0.5 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =1998 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=3 - and inv2.d_moy=3+1 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; -with /* TPC-DS query39.tpl 0.5 part2 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =1998 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=3 - and inv2.d_moy=3+1 - and inv1.cov > 1.5 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; - --- end template query39.tpl query 7 in stream 3 --- start template query80a.tpl query 8 in stream 3 -with /* TPC-DS query80a.tpl 0.6 */ ssr as - (select s_store_id as store_id, - sum(ss_ext_sales_price) as sales, - sum(coalesce(sr_return_amt, 0)) as returns, - sum(ss_net_profit - coalesce(sr_net_loss, 0)) as profit - from store_sales left outer join store_returns on - (ss_item_sk = sr_item_sk and ss_ticket_number = sr_ticket_number), - date_dim, - store, - item, - promotion - where ss_sold_date_sk = d_date_sk - and d_date between cast('1999-08-05' as date) - and dateadd(day,30,cast('1999-08-05' as date)) - and ss_store_sk = s_store_sk - and ss_item_sk = i_item_sk - and i_current_price > 50 - and ss_promo_sk = p_promo_sk - and p_channel_tv = 'N' - group by s_store_id) - , - csr as - (select cp_catalog_page_id as catalog_page_id, - sum(cs_ext_sales_price) as sales, - sum(coalesce(cr_return_amount, 0)) as returns, - sum(cs_net_profit - coalesce(cr_net_loss, 0)) as profit - from catalog_sales left outer join catalog_returns on - (cs_item_sk = cr_item_sk and cs_order_number = cr_order_number), - date_dim, - catalog_page, - item, - promotion - where cs_sold_date_sk = d_date_sk - and d_date between cast('1999-08-05' as date) - and dateadd(day,30,cast('1999-08-05' as date)) - and cs_catalog_page_sk = cp_catalog_page_sk - and cs_item_sk = i_item_sk - and i_current_price > 50 - and cs_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(ws_ext_sales_price) as sales, - sum(coalesce(wr_return_amt, 0)) as returns, - sum(ws_net_profit - coalesce(wr_net_loss, 0)) as profit - from web_sales left outer join web_returns on - (ws_item_sk = wr_item_sk and ws_order_number = wr_order_number), - date_dim, - web_site, - item, - promotion - where ws_sold_date_sk = d_date_sk - and d_date between cast('1999-08-05' as date) - and dateadd(day,30,cast('1999-08-05' as date)) - and ws_web_site_sk = web_site_sk - and ws_item_sk = i_item_sk - and i_current_price > 50 - and ws_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by web_site_id) -, -results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || store_id as id - , sales - , returns - , profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || catalog_page_id as id - , sales - , returns - , profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , profit - from wsr - ) x - group by channel, id) - - select channel - , id - , sales - , returns - , profit - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results - ) foo - order by channel, id - limit 100; - --- end template query80a.tpl query 8 in stream 3 --- start template query63.tpl query 9 in stream 3 -select /* TPC-DS query63.tpl 0.27 */ * -from (select i_manager_id - ,sum(ss_sales_price) sum_sales - ,avg(sum(ss_sales_price)) over (partition by i_manager_id) avg_monthly_sales - from item - ,store_sales - ,date_dim - ,store - where ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and d_month_seq in (1182,1182+1,1182+2,1182+3,1182+4,1182+5,1182+6,1182+7,1182+8,1182+9,1182+10,1182+11) - and (( i_category in ('Books','Children','Electronics') - and i_class in ('personal','portable','reference','self-help') - and i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) - or( i_category in ('Women','Music','Men') - and i_class in ('accessories','classical','fragrances','pants') - and i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manager_id, d_moy) tmp1 -where case when avg_monthly_sales > 0 then abs (sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 -order by i_manager_id - ,avg_monthly_sales - ,sum_sales -limit 100; - --- end template query63.tpl query 9 in stream 3 --- start template query72.tpl query 10 in stream 3 -select /* TPC-DS query72.tpl 0.87 */ i_item_desc - ,w_warehouse_name - ,d1.d_week_seq - ,sum(case when p_promo_sk is null then 1 else 0 end) no_promo - ,sum(case when p_promo_sk is not null then 1 else 0 end) promo - ,count(*) total_cnt -from catalog_sales -join inventory on (cs_item_sk = inv_item_sk) -join warehouse on (w_warehouse_sk=inv_warehouse_sk) -join item on (i_item_sk = cs_item_sk) -join customer_demographics on (cs_bill_cdemo_sk = cd_demo_sk) -join household_demographics on (cs_bill_hdemo_sk = hd_demo_sk) -join date_dim d1 on (cs_sold_date_sk = d1.d_date_sk) -join date_dim d2 on (inv_date_sk = d2.d_date_sk) -join date_dim d3 on (cs_ship_date_sk = d3.d_date_sk) -left outer join promotion on (cs_promo_sk=p_promo_sk) -left outer join catalog_returns on (cr_item_sk = cs_item_sk and cr_order_number = cs_order_number) -where d1.d_week_seq = d2.d_week_seq - and inv_quantity_on_hand < cs_quantity - and d3.d_date > d1.d_date + 5 - and hd_buy_potential = '501-1000' - and d1.d_year = 2001 - and cd_marital_status = 'M' -group by i_item_desc,w_warehouse_name,d1.d_week_seq -order by total_cnt desc, i_item_desc, w_warehouse_name, d_week_seq -limit 100; - --- end template query72.tpl query 10 in stream 3 --- start template query18a.tpl query 11 in stream 3 -with /* TPC-DS query18a.tpl 0.90 */ results as - (select i_item_id, - ca_country, - ca_state, - ca_county, - cast(cs_quantity as decimal(12,2)) agg1, - cast(cs_list_price as decimal(12,2)) agg2, - cast(cs_coupon_amt as decimal(12,2)) agg3, - cast(cs_sales_price as decimal(12,2)) agg4, - cast(cs_net_profit as decimal(12,2)) agg5, - cast(c_birth_year as decimal(12,2)) agg6, - cast(cd1.cd_dep_count as decimal(12,2)) agg7 - from catalog_sales, customer_demographics cd1, customer_demographics cd2, customer, customer_address, date_dim, item - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd1.cd_demo_sk and - cs_bill_customer_sk = c_customer_sk and - cd1.cd_gender = 'M' and - cd1.cd_education_status = 'Advanced Degree' and - c_current_cdemo_sk = cd2.cd_demo_sk and - c_current_addr_sk = ca_address_sk and - c_birth_month in (7,9,6,2,4,1) and - d_year = 2000 and - ca_state in ('KY','IN','MO','MN','GA','ND','CO') - ) - select i_item_id, ca_country, ca_state, ca_county, agg1, agg2, agg3, agg4, agg5, agg6, agg7 - from ( - select i_item_id, ca_country, ca_state, ca_county, avg(agg1) agg1, - avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state, ca_county - union all - select i_item_id, ca_country, ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state - union all - select i_item_id, ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country - union all - select i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - ) foo - order by ca_country, ca_state, ca_county, i_item_id - limit 100; - --- end template query18a.tpl query 11 in stream 3 --- start template query56.tpl query 12 in stream 3 -with /* TPC-DS query56.tpl 0.83 */ ss as ( - select i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where i_item_id in (select - i_item_id -from item -where i_color in ('green','misty','chocolate')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 6 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - cs as ( - select i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('green','misty','chocolate')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 6 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - ws as ( - select i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('green','misty','chocolate')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 6 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id) - select i_item_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by total_sales, - i_item_id - limit 100; - --- end template query56.tpl query 12 in stream 3 --- start template query13.tpl query 13 in stream 3 -select /* TPC-DS query13.tpl 0.91 */ avg(ss_quantity) - ,avg(ss_ext_sales_price) - ,avg(ss_ext_wholesale_cost) - ,sum(ss_ext_wholesale_cost) - from store_sales - ,store - ,customer_demographics - ,household_demographics - ,customer_address - ,date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2001 - and((ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'M' - and cd_education_status = 'Secondary' - and ss_sales_price between 100.00 and 150.00 - and hd_dep_count = 3 - )or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'U' - and cd_education_status = 'Unknown' - and ss_sales_price between 50.00 and 100.00 - and hd_dep_count = 1 - ) or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'S' - and cd_education_status = '2 yr Degree' - and ss_sales_price between 150.00 and 200.00 - and hd_dep_count = 1 - )) - and((ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('TX', 'WA', 'MN') - and ss_net_profit between 100 and 200 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('ND', 'KY', 'IA') - and ss_net_profit between 150 and 300 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('SC', 'AK', 'IL') - and ss_net_profit between 50 and 250 - )) -; - --- end template query13.tpl query 13 in stream 3 --- start template query69.tpl query 14 in stream 3 -select /* TPC-DS query69.tpl 0.28 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_state in ('NE','KY','UT') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2001 and - d_moy between 4 and 4+2) and - (not exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2001 and - d_moy between 4 and 4+2) and - not exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2001 and - d_moy between 4 and 4+2)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - limit 100; - --- end template query69.tpl query 14 in stream 3 --- start template query23.tpl query 15 in stream 3 -with /* TPC-DS query23.tpl 0.68 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (1999,1999+1,1999+2,1999+3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1999,1999+1,1999+2,1999+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * -from - max_store_sales)) - select sum(sales) - from (select cs_quantity*cs_list_price sales - from catalog_sales - ,date_dim - where d_year = 1999 - and d_moy = 1 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - union all - select ws_quantity*ws_list_price sales - from web_sales - ,date_dim - where d_year = 1999 - and d_moy = 1 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer)) - limit 100; -with /* TPC-DS query23.tpl 0.68 part2 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (1999,1999 + 1,1999 + 2,1999 + 3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1999,1999+1,1999+2,1999+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * - from max_store_sales)) - select c_last_name,c_first_name,sales - from (select c_last_name,c_first_name,sum(cs_quantity*cs_list_price) sales - from catalog_sales - ,customer - ,date_dim - where d_year = 1999 - and d_moy = 1 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and cs_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name - union all - select c_last_name,c_first_name,sum(ws_quantity*ws_list_price) sales - from web_sales - ,customer - ,date_dim - where d_year = 1999 - and d_moy = 1 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and ws_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name) - order by c_last_name,c_first_name,sales - limit 100; - --- end template query23.tpl query 15 in stream 3 --- start template query19.tpl query 16 in stream 3 -select /* TPC-DS query19.tpl 0.8 */ i_brand_id brand_id, i_brand brand, i_manufact_id, i_manufact, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item,customer,customer_address,store - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=5 - and d_moy=12 - and d_year=1999 - and ss_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and substring(ca_zip,1,5) <> substring(s_zip,1,5) - and ss_store_sk = s_store_sk - group by i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact - order by ext_price desc - ,i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact -limit 100 ; - --- end template query19.tpl query 16 in stream 3 --- start template query74.tpl query 17 in stream 3 -with /* TPC-DS query74.tpl 0.76 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,sum(ss_net_paid) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (2001,2001+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,sum(ws_net_paid) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - and d_year in (2001,2001+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - ) - select - t_s_secyear.customer_id, t_s_secyear.customer_first_name, t_s_secyear.customer_last_name - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.year = 2001 - and t_s_secyear.year = 2001+1 - and t_w_firstyear.year = 2001 - and t_w_secyear.year = 2001+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - order by 3,2,1 -limit 100; - --- end template query74.tpl query 17 in stream 3 --- start template query30.tpl query 18 in stream 3 -with /* TPC-DS query30.tpl 0.75 */ customer_total_return as - (select wr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(wr_return_amt) as ctr_total_return - from web_returns - ,date_dim - ,customer_address - where wr_returned_date_sk = d_date_sk - and d_year =2002 - and wr_returning_addr_sk = ca_address_sk - group by wr_returning_customer_sk - ,ca_state) - select c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'KS' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return -limit 100; - --- end template query30.tpl query 18 in stream 3 --- start template query84.tpl query 19 in stream 3 -select /* TPC-DS query84.tpl 0.80 */ c_customer_id as customer_id - , coalesce(c_last_name,'') || ', ' || coalesce(c_first_name,'') as customername - from customer - ,customer_address - ,customer_demographics - ,household_demographics - ,income_band - ,store_returns - where ca_city = 'Belmont' - and c_current_addr_sk = ca_address_sk - and ib_lower_bound >= 22617 - and ib_upper_bound <= 22617 + 50000 - and ib_income_band_sk = hd_income_band_sk - and cd_demo_sk = c_current_cdemo_sk - and hd_demo_sk = c_current_hdemo_sk - and sr_cdemo_sk = cd_demo_sk - order by c_customer_id - limit 100; - --- end template query84.tpl query 19 in stream 3 --- start template query96.tpl query 20 in stream 3 -select /* TPC-DS query96.tpl 0.1 */ count(*) -from store_sales - ,household_demographics - ,time_dim, store -where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 20 - and time_dim.t_minute >= 30 - and household_demographics.hd_dep_count = 7 - and store.s_store_name = 'ese' -order by count(*) -limit 100; - --- end template query96.tpl query 20 in stream 3 --- start template query14a.tpl query 21 in stream 3 -with /* TPC-DS query14a.tpl 0.69 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1999 AND 1999 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1999 AND 1999 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1999 AND 1999 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as - (select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2) x) -, - results AS -(select channel, i_brand_id, i_class_id, i_category_id, sum(sales) sum_sales, sum(number_sales) number_sales - from ( - select 'store' channel, i_brand_id,i_class_id - ,i_category_id,sum(ss_quantity*ss_list_price) sales - , count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1999+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales) - union all - select 'catalog' channel, i_brand_id,i_class_id,i_category_id, sum(cs_quantity*cs_list_price) sales, count(*) number_sales - from catalog_sales - ,item - ,date_dim - where cs_item_sk in (select ss_item_sk from cross_items) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1999+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(cs_quantity*cs_list_price) > (select average_sales from avg_sales) - union all - select 'web' channel, i_brand_id,i_class_id,i_category_id, sum(ws_quantity*ws_list_price) sales , count(*) number_sales - from web_sales - ,item - ,date_dim - where ws_item_sk in (select ss_item_sk from cross_items) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1999+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ws_quantity*ws_list_price) > (select average_sales from avg_sales) - ) y - group by channel, i_brand_id,i_class_id,i_category_id) - - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales -from ( - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales from results - union - select channel, i_brand_id, i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id, i_class_id - union - select channel, i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id - union - select channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel - union - select null as channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results) z -order by channel, i_brand_id, i_class_id, i_category_id - limit 100; -with /* TPC-DS query14a.tpl 0.69 part2 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1999 AND 1999 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1999 AND 1999 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1999 AND 1999 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as -(select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2) x) - select this_year.channel ty_channel - ,this_year.i_brand_id ty_brand - ,this_year.i_class_id ty_class - ,this_year.i_category_id ty_category - ,this_year.sales ty_sales - ,this_year.number_sales ty_number_sales - ,last_year.channel ly_channel - ,last_year.i_brand_id ly_brand - ,last_year.i_class_id ly_class - ,last_year.i_category_id ly_category - ,last_year.sales ly_sales - ,last_year.number_sales ly_number_sales -from - (select 'store' channel, i_brand_id,i_class_id,i_category_id - ,sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1999 + 1 - and d_moy = 12 - and d_dom = 7) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) this_year, - (select 'store' channel, i_brand_id,i_class_id - ,i_category_id, sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1999 - and d_moy = 12 - and d_dom = 7) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) last_year - where this_year.i_brand_id= last_year.i_brand_id - and this_year.i_class_id = last_year.i_class_id - and this_year.i_category_id = last_year.i_category_id - order by this_year.channel, this_year.i_brand_id, this_year.i_class_id, this_year.i_category_id - limit 100; - --- end template query14a.tpl query 21 in stream 3 --- start template query10.tpl query 22 in stream 3 -select /* TPC-DS query10.tpl 0.26 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3, - cd_dep_count, - count(*) cnt4, - cd_dep_employed_count, - count(*) cnt5, - cd_dep_college_count, - count(*) cnt6 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_county in ('Bleckley County','Lancaster County','Aroostook County','Marion County','Jefferson County') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2001 and - d_moy between 2 and 2+3) and - (exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2001 and - d_moy between 2 ANd 2+3) or - exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2001 and - d_moy between 2 and 2+3)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count -limit 100; - --- end template query10.tpl query 22 in stream 3 --- start template query86a.tpl query 23 in stream 3 -with /* TPC-DS query86a.tpl 0.11 */ results as -( select sum(ws_net_paid) as total_sum, i_category, i_class, 0 as g_category, 0 as g_class - from - web_sales - ,date_dim d1 - ,item - where - d1.d_month_seq between 1215 and 1215+11 - and d1.d_date_sk = ws_sold_date_sk - and i_item_sk = ws_item_sk - group by i_category,i_class - ) , - - results_rollup as -( select total_sum ,i_category ,i_class, g_category, g_class, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum, i_category, NULL as i_class, 0 as g_category, 1 as g_class, 1 as lochierarchy from results group by i_category - union - select sum(total_sum) as total_sum, NULL as i_category, NULL as i_class, 1 as g_category, 1 as g_class, 2 as lochierarchy from results) - select - total_sum ,i_category ,i_class, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_class = 0 then i_category end - order by total_sum desc) as rank_within_parent - from - results_rollup - order by - lochierarchy desc, - case when lochierarchy = 0 then i_category end, - rank_within_parent - limit 100; - --- end template query86a.tpl query 23 in stream 3 --- start template query94.tpl query 24 in stream 3 -select /* TPC-DS query94.tpl 0.17 */ - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '1999-4-01' and - dateadd(day,60,cast('1999-4-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'OH' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and exists (select * - from web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) -and not exists(select * - from web_returns wr1 - where ws1.ws_order_number = wr1.wr_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query94.tpl query 24 in stream 3 --- start template query8.tpl query 25 in stream 3 -select /* TPC-DS query8.tpl 0.63 */ s_store_name - ,sum(ss_net_profit) - from store_sales - ,date_dim - ,store, - (select ca_zip - from ( - SELECT substring(ca_zip,1,5) ca_zip - FROM customer_address - WHERE substring(ca_zip,1,5) IN ( - '84361','78842','59990','32122','60171','67842', - '37239','93338','65118','34995','53752', - '54823','86526','87442','43885','24133', - '34072','86647','86602','73543','53406', - '80729','83339','87237','54003','41917', - '41978','55168','88304','23984','88548', - '86328','73913','32336','56452','55568', - '48804','83811','11901','90870','10053', - '73537','72057','39045','66837','15093', - '51226','72962','53193','73746','93822', - '19940','47337','41644','13498','91706', - '35419','38328','60298','45011','64561', - '21190','35500','79781','94944','77135', - '48660','55382','14565','11895','85085', - '63977','55332','40791','99461','95716', - '61925','90851','24705','98920','47297', - '60899','60826','52548','66244','30319', - '49512','27254','77188','82445','42854', - '62067','37149','91888','59020','33334', - '61276','30954','47499','43917','94835', - '88978','94795','21525','80172','83247', - '61681','22762','33212','46417','29480', - '82656','38202','82330','20843','19900', - '84313','39598','45673','99280','56203', - '82225','80384','93889','89360','80438', - '48150','72353','17512','12643','28035', - '44737','99217','71663','91707','87044', - '68754','44213','74706','34858','76573', - '80770','99404','85607','29837','41899', - '31972','51095','49027','78196','31227', - '43647','10416','26000','48860','49728', - '12532','22398','99510','96055','49582', - '82392','10749','29425','79041','85314', - '74292','10758','21558','73839','99284', - '35135','84226','43518','99532','96365', - '43928','60880','97073','32436','55405', - '19667','33519','27211','60510','59270', - '60976','20813','17214','99302','92106', - '43471','58967','84214','51897','93139', - '57871','52859','65153','63841','55530', - '23655','27177','58981','45533','27640', - '99744','49655','18012','43980','78098', - '66011','61837','82932','76116','20065', - '65979','22059','26901','74636','39654', - '14151','45764','73721','83894','43356', - '61278','34443','66247','28709','93966', - '22337','22999','62719','34691','39405', - '17596','25613','80697','30505','43307', - '12481','24624','83531','75227','97810', - '28813','69851','36427','15967','35032', - '49979','43388','20919','95638','33921', - '79045','51982','42201','93197','68933', - '83909','64123','59613','15994','65766', - '62645','41691','22744','27304','33747', - '41568','33851','11370','93377','70718', - '16123','52293','66430','93005','50428', - '60778','65392','22931','52897','58668', - '56175','88815','11898','17590','25895', - '60221','48473','10675','44926','41376', - '61701','98151','29169','54112','72889', - '94965','77943','30307','82406','92019', - '87382','96003','69821','82690','87701', - '76127','77788','44453','47027','33124', - '70744','52714','85649','47942','24797', - '37316','40634','23448','18749','55718', - '54651','87619','32349','25912','17921', - '12971','69066','85461','91732','51831', - '17130','33698','23817','55882','33231', - '33955','23425','88859','17897','69976', - '63466','66686','47310','99038','17754', - '32994','62178','88950','99166','59604', - '84432','89582','20307','46854','84058', - '21570','63947','25570','66769','23960', - '51472','67047','13635','13428','95169', - '50744','63644','36229','16636','79406', - '76656','62098','38648','48931','84093', - '93801','73135','18298','53037','13245', - '47599','18148','27769','67499','25192', - '32376','36432','22729','59494','90043', - '94509','16765','97937','63331') - intersect - select ca_zip - from (SELECT substring(ca_zip,1,5) ca_zip,count(*) cnt - FROM customer_address, customer - WHERE ca_address_sk = c_current_addr_sk and - c_preferred_cust_flag='Y' - group by ca_zip - having count(*) > 10)A1)A2) V1 - where ss_store_sk = s_store_sk - and ss_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 2001 - and (substring(s_zip,1,2) = substring(V1.ca_zip,1,2)) - group by s_store_name - order by s_store_name - limit 100; - --- end template query8.tpl query 25 in stream 3 --- start template query87.tpl query 26 in stream 3 -select /* TPC-DS query87.tpl 0.77 */ count(*) -from ((select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1217 and 1217+11) - except - (select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1217 and 1217+11) - except - (select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1217 and 1217+11) -) cool_cust -; - --- end template query87.tpl query 26 in stream 3 --- start template query58.tpl query 27 in stream 3 -with /* TPC-DS query58.tpl 0.19 */ ss_items as - (select i_item_id item_id - ,sum(ss_ext_sales_price) ss_item_rev - from store_sales - ,item - ,date_dim - where ss_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '2000-06-07')) - and ss_sold_date_sk = d_date_sk - group by i_item_id), - cs_items as - (select i_item_id item_id - ,sum(cs_ext_sales_price) cs_item_rev - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '2000-06-07')) - and cs_sold_date_sk = d_date_sk - group by i_item_id), - ws_items as - (select i_item_id item_id - ,sum(ws_ext_sales_price) ws_item_rev - from web_sales - ,item - ,date_dim - where ws_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq =(select d_week_seq - from date_dim - where d_date = '2000-06-07')) - and ws_sold_date_sk = d_date_sk - group by i_item_id) - select ss_items.item_id - ,ss_item_rev - ,ss_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ss_dev - ,cs_item_rev - ,cs_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 cs_dev - ,ws_item_rev - ,ws_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ws_dev - ,(ss_item_rev+cs_item_rev+ws_item_rev)/3 average - from ss_items,cs_items,ws_items - where ss_items.item_id=cs_items.item_id - and ss_items.item_id=ws_items.item_id - and ss_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - and ss_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and cs_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and cs_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and ws_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and ws_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - order by item_id - ,ss_item_rev - limit 100; - --- end template query58.tpl query 27 in stream 3 --- start template query36a.tpl query 28 in stream 3 -with /* TPC-DS query36a.tpl 0.21 */ results as - (select - sum(ss_net_profit) as ss_net_profit, sum(ss_ext_sales_price) as ss_ext_sales_price, - sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin - ,i_category - ,i_class - ,0 as g_category, 0 as g_class - from - store_sales - ,date_dim d1 - ,item - ,store - where - d1.d_year = 1998 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and s_state in ('MO','TX','LA','OH', - 'NM','TN','TN','AL') - group by i_category,i_class) - , - results_rollup as - (select gross_margin ,i_category ,i_class,0 as t_category, 0 as t_class, 0 as lochierarchy from results - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - i_category, NULL AS i_class, 0 as t_category, 1 as t_class, 1 as lochierarchy from results group by i_category - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - NULL AS i_category ,NULL AS i_class, 1 as t_category, 1 as t_class, 2 as lochierarchy from results) - select - gross_margin ,i_category ,i_class, lochierarchy,rank() over ( - partition by lochierarchy, case when t_class = 0 then i_category end - order by gross_margin asc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then i_category end - ,rank_within_parent - limit 100; - --- end template query36a.tpl query 28 in stream 3 --- start template query37.tpl query 29 in stream 3 -select /* TPC-DS query37.tpl 0.31 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, catalog_sales - where i_current_price between 25 and 25 + 30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('1998-03-14' as date) and dateadd(day,60,cast('1998-03-14' as date)) - and i_manufact_id in (816,791,815,882) - and inv_quantity_on_hand between 100 and 500 - and cs_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query37.tpl query 29 in stream 3 --- start template query4.tpl query 30 in stream 3 -with /* TPC-DS query4.tpl 0.93 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(((ss_ext_list_price-ss_ext_wholesale_cost-ss_ext_discount_amt)+ss_ext_sales_price)/2) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((cs_ext_list_price-cs_ext_wholesale_cost-cs_ext_discount_amt)+cs_ext_sales_price)/2) ) year_total - ,'c' sale_type - from customer - ,catalog_sales - ,date_dim - where c_customer_sk = cs_bill_customer_sk - and cs_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year -union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((ws_ext_list_price-ws_ext_wholesale_cost-ws_ext_discount_amt)+ws_ext_sales_price)/2) ) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_email_address - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_c_firstyear - ,year_total t_c_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_c_secyear.customer_id - and t_s_firstyear.customer_id = t_c_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_c_firstyear.sale_type = 'c' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_c_secyear.sale_type = 'c' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 2001 - and t_s_secyear.dyear = 2001+1 - and t_c_firstyear.dyear = 2001 - and t_c_secyear.dyear = 2001+1 - and t_w_firstyear.dyear = 2001 - and t_w_secyear.dyear = 2001+1 - and t_s_firstyear.year_total > 0 - and t_c_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_email_address -limit 100; - --- end template query4.tpl query 30 in stream 3 --- start template query38.tpl query 31 in stream 3 -select /* TPC-DS query38.tpl 0.54 */ count(*) from ( - select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1203 and 1203 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1203 and 1203 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1203 and 1203 + 11 -) hot_cust -limit 100; - --- end template query38.tpl query 31 in stream 3 --- start template query66.tpl query 32 in stream 3 -select /* TPC-DS query66.tpl 0.39 */ - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - ,sum(jan_sales) as jan_sales - ,sum(feb_sales) as feb_sales - ,sum(mar_sales) as mar_sales - ,sum(apr_sales) as apr_sales - ,sum(may_sales) as may_sales - ,sum(jun_sales) as jun_sales - ,sum(jul_sales) as jul_sales - ,sum(aug_sales) as aug_sales - ,sum(sep_sales) as sep_sales - ,sum(oct_sales) as oct_sales - ,sum(nov_sales) as nov_sales - ,sum(dec_sales) as dec_sales - ,sum(jan_sales/w_warehouse_sq_ft) as jan_sales_per_sq_foot - ,sum(feb_sales/w_warehouse_sq_ft) as feb_sales_per_sq_foot - ,sum(mar_sales/w_warehouse_sq_ft) as mar_sales_per_sq_foot - ,sum(apr_sales/w_warehouse_sq_ft) as apr_sales_per_sq_foot - ,sum(may_sales/w_warehouse_sq_ft) as may_sales_per_sq_foot - ,sum(jun_sales/w_warehouse_sq_ft) as jun_sales_per_sq_foot - ,sum(jul_sales/w_warehouse_sq_ft) as jul_sales_per_sq_foot - ,sum(aug_sales/w_warehouse_sq_ft) as aug_sales_per_sq_foot - ,sum(sep_sales/w_warehouse_sq_ft) as sep_sales_per_sq_foot - ,sum(oct_sales/w_warehouse_sq_ft) as oct_sales_per_sq_foot - ,sum(nov_sales/w_warehouse_sq_ft) as nov_sales_per_sq_foot - ,sum(dec_sales/w_warehouse_sq_ft) as dec_sales_per_sq_foot - ,sum(jan_net) as jan_net - ,sum(feb_net) as feb_net - ,sum(mar_net) as mar_net - ,sum(apr_net) as apr_net - ,sum(may_net) as may_net - ,sum(jun_net) as jun_net - ,sum(jul_net) as jul_net - ,sum(aug_net) as aug_net - ,sum(sep_net) as sep_net - ,sum(oct_net) as oct_net - ,sum(nov_net) as nov_net - ,sum(dec_net) as dec_net - from ( - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'FEDEX' || ',' || 'TBS' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then ws_ext_list_price* ws_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then ws_ext_list_price* ws_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then ws_ext_list_price* ws_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then ws_ext_list_price* ws_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then ws_ext_list_price* ws_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then ws_ext_list_price* ws_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then ws_ext_list_price* ws_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then ws_ext_list_price* ws_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then ws_ext_list_price* ws_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then ws_ext_list_price* ws_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then ws_ext_list_price* ws_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then ws_ext_list_price* ws_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as dec_net - from - web_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - ws_warehouse_sk = w_warehouse_sk - and ws_sold_date_sk = d_date_sk - and ws_sold_time_sk = t_time_sk - and ws_ship_mode_sk = sm_ship_mode_sk - and d_year = 1998 - and t_time between 20417 and 20417+28800 - and sm_carrier in ('FEDEX','TBS') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - union all - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'FEDEX' || ',' || 'TBS' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then cs_sales_price* cs_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then cs_sales_price* cs_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then cs_sales_price* cs_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then cs_sales_price* cs_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then cs_sales_price* cs_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then cs_sales_price* cs_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then cs_sales_price* cs_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then cs_sales_price* cs_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then cs_sales_price* cs_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then cs_sales_price* cs_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then cs_sales_price* cs_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then cs_sales_price* cs_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as dec_net - from - catalog_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and cs_sold_time_sk = t_time_sk - and cs_ship_mode_sk = sm_ship_mode_sk - and d_year = 1998 - and t_time between 20417 AND 20417+28800 - and sm_carrier in ('FEDEX','TBS') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - ) x - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - order by w_warehouse_name - limit 100; - --- end template query66.tpl query 32 in stream 3 --- start template query78.tpl query 33 in stream 3 -with /* TPC-DS query78.tpl 0.10 */ ws as - (select d_year AS ws_sold_year, ws_item_sk, - ws_bill_customer_sk ws_customer_sk, - sum(ws_quantity) ws_qty, - sum(ws_wholesale_cost) ws_wc, - sum(ws_sales_price) ws_sp - from web_sales - left join web_returns on wr_order_number=ws_order_number and ws_item_sk=wr_item_sk - join date_dim on ws_sold_date_sk = d_date_sk - where wr_order_number is null - group by d_year, ws_item_sk, ws_bill_customer_sk - ), -cs as - (select d_year AS cs_sold_year, cs_item_sk, - cs_bill_customer_sk cs_customer_sk, - sum(cs_quantity) cs_qty, - sum(cs_wholesale_cost) cs_wc, - sum(cs_sales_price) cs_sp - from catalog_sales - left join catalog_returns on cr_order_number=cs_order_number and cs_item_sk=cr_item_sk - join date_dim on cs_sold_date_sk = d_date_sk - where cr_order_number is null - group by d_year, cs_item_sk, cs_bill_customer_sk - ), -ss as - (select d_year AS ss_sold_year, ss_item_sk, - ss_customer_sk, - sum(ss_quantity) ss_qty, - sum(ss_wholesale_cost) ss_wc, - sum(ss_sales_price) ss_sp - from store_sales - left join store_returns on sr_ticket_number=ss_ticket_number and ss_item_sk=sr_item_sk - join date_dim on ss_sold_date_sk = d_date_sk - where sr_ticket_number is null - group by d_year, ss_item_sk, ss_customer_sk - ) - select -ss_item_sk, -round(ss_qty/(coalesce(ws_qty,0)+coalesce(cs_qty,0)),2) ratio, -ss_qty store_qty, ss_wc store_wholesale_cost, ss_sp store_sales_price, -coalesce(ws_qty,0)+coalesce(cs_qty,0) other_chan_qty, -coalesce(ws_wc,0)+coalesce(cs_wc,0) other_chan_wholesale_cost, -coalesce(ws_sp,0)+coalesce(cs_sp,0) other_chan_sales_price -from ss -left join ws on (ws_sold_year=ss_sold_year and ws_item_sk=ss_item_sk and ws_customer_sk=ss_customer_sk) -left join cs on (cs_sold_year=ss_sold_year and cs_item_sk=ss_item_sk and cs_customer_sk=ss_customer_sk) -where (coalesce(ws_qty,0)>0 or coalesce(cs_qty, 0)>0) and ss_sold_year=1999 -order by - ss_item_sk, - ss_qty desc, ss_wc desc, ss_sp desc, - other_chan_qty, - other_chan_wholesale_cost, - other_chan_sales_price, - ratio -limit 100; - --- end template query78.tpl query 33 in stream 3 --- start template query43.tpl query 34 in stream 3 -select /* TPC-DS query43.tpl 0.15 */ s_store_name, s_store_id, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from date_dim, store_sales, store - where d_date_sk = ss_sold_date_sk and - s_store_sk = ss_store_sk and - s_gmt_offset = -7 and - d_year = 2000 - group by s_store_name, s_store_id - order by s_store_name, s_store_id,sun_sales,mon_sales,tue_sales,wed_sales,thu_sales,fri_sales,sat_sales - limit 100; - --- end template query43.tpl query 34 in stream 3 --- start template query22a.tpl query 35 in stream 3 -with /* TPC-DS query22a.tpl 0.55 */ results as -(select i_product_name - ,i_brand - ,i_class - ,i_category - ,avg(inv_quantity_on_hand) qoh - from inventory - ,date_dim - ,item --- ,warehouse - where inv_date_sk=d_date_sk - and inv_item_sk=i_item_sk --- and inv_warehouse_sk = w_warehouse_sk - and d_month_seq between 1188 and 1188 + 11 - group by i_product_name,i_brand,i_class,i_category), -results_rollup as -(select i_product_name, i_brand, i_class, i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class,i_category -union all -select i_product_name, i_brand, i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class -union all -select i_product_name, i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand -union all -select i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name -union all -select null i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results) - select i_product_name, i_brand, i_class, i_category,qoh - from results_rollup - order by qoh, i_product_name, i_brand, i_class, i_category -limit 100; - --- end template query22a.tpl query 35 in stream 3 --- start template query21.tpl query 36 in stream 3 -select /* TPC-DS query21.tpl 0.14 */ * - from(select w_warehouse_name - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('2001-03-01' as date)) - then inv_quantity_on_hand - else 0 end) as inv_before - ,sum(case when (cast(d_date as date) >= cast ('2001-03-01' as date)) - then inv_quantity_on_hand - else 0 end) as inv_after - from inventory - ,warehouse - ,item - ,date_dim - where i_current_price between 0.99 and 1.49 - and i_item_sk = inv_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('2001-03-01' as date)) - and dateadd(day,30,cast ('2001-03-01' as date)) - group by w_warehouse_name, i_item_id) x - where (case when inv_before > 0 - then inv_after / inv_before - else null - end) between 2.0/3.0 and 3.0/2.0 - order by w_warehouse_name - ,i_item_id - limit 100; - --- end template query21.tpl query 36 in stream 3 --- start template query97.tpl query 37 in stream 3 -with /* TPC-DS query97.tpl 0.38 */ ssci as ( -select ss_customer_sk customer_sk - ,ss_item_sk item_sk -from store_sales,date_dim -where ss_sold_date_sk = d_date_sk - and d_month_seq between 1212 and 1212 + 11 -group by ss_customer_sk - ,ss_item_sk), -csci as( - select cs_bill_customer_sk customer_sk - ,cs_item_sk item_sk -from catalog_sales,date_dim -where cs_sold_date_sk = d_date_sk - and d_month_seq between 1212 and 1212 + 11 -group by cs_bill_customer_sk - ,cs_item_sk) - select sum(case when ssci.customer_sk is not null and csci.customer_sk is null then 1 else 0 end) store_only - ,sum(case when ssci.customer_sk is null and csci.customer_sk is not null then 1 else 0 end) catalog_only - ,sum(case when ssci.customer_sk is not null and csci.customer_sk is not null then 1 else 0 end) store_and_catalog -from ssci full outer join csci on (ssci.customer_sk=csci.customer_sk - and ssci.item_sk = csci.item_sk) -limit 100; - --- end template query97.tpl query 37 in stream 3 --- start template query47.tpl query 38 in stream 3 -with /* TPC-DS query47.tpl 0.42 */ v1 as( - select i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, - s_store_name, s_company_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - s_store_name, s_company_name - order by d_year, d_moy) rn - from item, store_sales, date_dim, store - where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - ( - d_year = 2000 or - ( d_year = 2000-1 and d_moy =12) or - ( d_year = 2000+1 and d_moy =1) - ) - group by i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy), - v2 as( - select v1.s_company_name - ,v1.d_year, v1.d_moy - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1.s_store_name = v1_lag.s_store_name and - v1.s_store_name = v1_lead.s_store_name and - v1.s_company_name = v1_lag.s_company_name and - v1.s_company_name = v1_lead.s_company_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 2000 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, nsum - limit 100; - --- end template query47.tpl query 38 in stream 3 --- start template query29.tpl query 39 in stream 3 -select /* TPC-DS query29.tpl 0.53 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,stddev_samp(ss_quantity) as store_sales_quantity - ,stddev_samp(sr_return_quantity) as store_returns_quantity - ,stddev_samp(cs_quantity) as catalog_sales_quantity - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 1999 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 4 + 3 - and d2.d_year = 1999 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_year in (1999,1999+1,1999+2) - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query29.tpl query 39 in stream 3 --- start template query3.tpl query 40 in stream 3 -select /* TPC-DS query3.tpl 0.45 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_sales_price) sum_agg - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manufact_id = 819 - and dt.d_moy=12 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,sum_agg desc - ,brand_id - limit 100; - --- end template query3.tpl query 40 in stream 3 --- start template query76.tpl query 41 in stream 3 -select /* TPC-DS query76.tpl 0.99 */ channel, col_name, d_year, d_qoy, i_category, COUNT(*) sales_cnt, SUM(ext_sales_price) sales_amt FROM ( - SELECT 'store' as channel, 'ss_store_sk' col_name, d_year, d_qoy, i_category, ss_ext_sales_price ext_sales_price - FROM store_sales, item, date_dim - WHERE ss_store_sk IS NULL - AND ss_sold_date_sk=d_date_sk - AND ss_item_sk=i_item_sk - UNION ALL - SELECT 'web' as channel, 'ws_promo_sk' col_name, d_year, d_qoy, i_category, ws_ext_sales_price ext_sales_price - FROM web_sales, item, date_dim - WHERE ws_promo_sk IS NULL - AND ws_sold_date_sk=d_date_sk - AND ws_item_sk=i_item_sk - UNION ALL - SELECT 'catalog' as channel, 'cs_bill_addr_sk' col_name, d_year, d_qoy, i_category, cs_ext_sales_price ext_sales_price - FROM catalog_sales, item, date_dim - WHERE cs_bill_addr_sk IS NULL - AND cs_sold_date_sk=d_date_sk - AND cs_item_sk=i_item_sk) foo -GROUP BY channel, col_name, d_year, d_qoy, i_category -ORDER BY channel, col_name, d_year, d_qoy, i_category -limit 100; - --- end template query76.tpl query 41 in stream 3 --- start template query82.tpl query 42 in stream 3 -select /* TPC-DS query82.tpl 0.67 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, store_sales - where i_current_price between 56 and 56+30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('1999-04-15' as date) and dateadd(day,60,cast('1999-04-15' as date)) - and i_manufact_id in (812,479,428,661) - and inv_quantity_on_hand between 100 and 500 - and ss_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query82.tpl query 42 in stream 3 --- start template query46.tpl query 43 in stream 3 -select /* TPC-DS query46.tpl 0.23 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and (household_demographics.hd_dep_count = 7 or - household_demographics.hd_vehicle_count= -1) - and date_dim.d_dow in (6,0) - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_city in ('Edgewood','Oakdale','Unionville','Summit','Hamilton') - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,ca_city) dn,customer,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - limit 100; - --- end template query46.tpl query 43 in stream 3 --- start template query41.tpl query 44 in stream 3 -select /* TPC-DS query41.tpl 0.62 */ distinct(i_product_name) - from item i1 - where i_manufact_id between 736 and 736+40 - and (select count(*) as item_cnt - from item - where (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'floral' or i_color = 'lime') and - (i_units = 'Tsp' or i_units = 'Each') and - (i_size = 'medium' or i_size = 'petite') - ) or - (i_category = 'Women' and - (i_color = 'rose' or i_color = 'cyan') and - (i_units = 'N/A' or i_units = 'Tbl') and - (i_size = 'economy' or i_size = 'N/A') - ) or - (i_category = 'Men' and - (i_color = 'magenta' or i_color = 'plum') and - (i_units = 'Dram' or i_units = 'Lb') and - (i_size = 'extra large' or i_size = 'small') - ) or - (i_category = 'Men' and - (i_color = 'midnight' or i_color = 'seashell') and - (i_units = 'Carton' or i_units = 'Pallet') and - (i_size = 'medium' or i_size = 'petite') - ))) or - (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'metallic' or i_color = 'steel') and - (i_units = 'Box' or i_units = 'Gross') and - (i_size = 'medium' or i_size = 'petite') - ) or - (i_category = 'Women' and - (i_color = 'cornsilk' or i_color = 'white') and - (i_units = 'Cup' or i_units = 'Case') and - (i_size = 'economy' or i_size = 'N/A') - ) or - (i_category = 'Men' and - (i_color = 'hot' or i_color = 'blanched') and - (i_units = 'Bunch' or i_units = 'Dozen') and - (i_size = 'extra large' or i_size = 'small') - ) or - (i_category = 'Men' and - (i_color = 'sienna' or i_color = 'lavender') and - (i_units = 'Oz' or i_units = 'Pound') and - (i_size = 'medium' or i_size = 'petite') - )))) > 0 - order by i_product_name - limit 100; - --- end template query41.tpl query 44 in stream 3 --- start template query59.tpl query 45 in stream 3 -with /* TPC-DS query59.tpl 0.30 */ wss as - (select d_week_seq, - ss_store_sk, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - group by d_week_seq,ss_store_sk - ) - select s_store_name1,s_store_id1,d_week_seq1 - ,sun_sales1/sun_sales2,mon_sales1/mon_sales2 - ,tue_sales1/tue_sales2,wed_sales1/wed_sales2,thu_sales1/thu_sales2 - ,fri_sales1/fri_sales2,sat_sales1/sat_sales2 - from - (select s_store_name s_store_name1,wss.d_week_seq d_week_seq1 - ,s_store_id s_store_id1,sun_sales sun_sales1 - ,mon_sales mon_sales1,tue_sales tue_sales1 - ,wed_sales wed_sales1,thu_sales thu_sales1 - ,fri_sales fri_sales1,sat_sales sat_sales1 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1206 and 1206 + 11) y, - (select s_store_name s_store_name2,wss.d_week_seq d_week_seq2 - ,s_store_id s_store_id2,sun_sales sun_sales2 - ,mon_sales mon_sales2,tue_sales tue_sales2 - ,wed_sales wed_sales2,thu_sales thu_sales2 - ,fri_sales fri_sales2,sat_sales sat_sales2 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1206+ 12 and 1206 + 23) x - where s_store_id1=s_store_id2 - and d_week_seq1=d_week_seq2-52 - order by s_store_name1,s_store_id1,d_week_seq1 -limit 100; - --- end template query59.tpl query 45 in stream 3 --- start template query40.tpl query 46 in stream 3 -select /* TPC-DS query40.tpl 0.86 */ - w_state - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('2001-04-04' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_before - ,sum(case when (cast(d_date as date) >= cast ('2001-04-04' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_after - from - catalog_sales left outer join catalog_returns on - (cs_order_number = cr_order_number - and cs_item_sk = cr_item_sk) - ,warehouse - ,item - ,date_dim - where - i_current_price between 0.99 and 1.49 - and i_item_sk = cs_item_sk - and cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('2001-04-04' as date)) - and dateadd(day,30,cast ('2001-04-04' as date)) - group by - w_state,i_item_id - order by w_state,i_item_id -limit 100; - --- end template query40.tpl query 46 in stream 3 --- start template query55.tpl query 47 in stream 3 -select /* TPC-DS query55.tpl 0.82 */ i_brand_id brand_id, i_brand brand, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=16 - and d_moy=12 - and d_year=2000 - group by i_brand, i_brand_id - order by ext_price desc, i_brand_id -limit 100 ; - --- end template query55.tpl query 47 in stream 3 --- start template query16.tpl query 48 in stream 3 -select /* TPC-DS query16.tpl 0.25 */ - count(distinct cs_order_number) as "order count" - ,sum(cs_ext_ship_cost) as "total shipping cost" - ,sum(cs_net_profit) as "total net profit" -from - catalog_sales cs1 - ,date_dim - ,customer_address - ,call_center -where - d_date between '2002-5-01' and - dateadd(day, 60, cast('2002-5-01' as date)) -and cs1.cs_ship_date_sk = d_date_sk -and cs1.cs_ship_addr_sk = ca_address_sk -and ca_state = 'WV' -and cs1.cs_call_center_sk = cc_call_center_sk -and cc_county in ('Daviess County','Jefferson Davis Parish','Luce County','San Miguel County', - 'Williamson County' -) -and exists (select * - from catalog_sales cs2 - where cs1.cs_order_number = cs2.cs_order_number - and cs1.cs_warehouse_sk <> cs2.cs_warehouse_sk) -and not exists(select * - from catalog_returns cr1 - where cs1.cs_order_number = cr1.cr_order_number) -order by count(distinct cs_order_number) -limit 100; - --- end template query16.tpl query 48 in stream 3 --- start template query27a.tpl query 49 in stream 3 -with /* TPC-DS query27a.tpl 0.16 */ results as - (select i_item_id, - s_state, 0 as g_state, - ss_quantity agg1, - ss_list_price agg2, - ss_coupon_amt agg3, - ss_sales_price agg4 - from store_sales, customer_demographics, date_dim, store, item - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_store_sk = s_store_sk and - ss_cdemo_sk = cd_demo_sk and - cd_gender = 'F' and - cd_marital_status = 'M' and - cd_education_status = 'College' and - d_year = 2000 and - s_state in ('MI','GA', 'MI', 'AL', 'NC', 'FL') - ) - - select i_item_id, - s_state, g_state, agg1, agg2, agg3, agg4 - from ( - select i_item_id, s_state, 0 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4 from results - group by i_item_id, s_state - union all - select i_item_id, NULL AS s_state, 1 AS g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as s_state, 1 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - ) foo - order by i_item_id, s_state - limit 100; - --- end template query27a.tpl query 49 in stream 3 --- start template query54.tpl query 50 in stream 3 -with /* TPC-DS query54.tpl 0.81 */ my_customers as ( - select distinct c_customer_sk - , c_current_addr_sk - from - ( select cs_sold_date_sk sold_date_sk, - cs_bill_customer_sk customer_sk, - cs_item_sk item_sk - from catalog_sales - union all - select ws_sold_date_sk sold_date_sk, - ws_bill_customer_sk customer_sk, - ws_item_sk item_sk - from web_sales - ) cs_or_ws_sales, - item, - date_dim, - customer - where sold_date_sk = d_date_sk - and item_sk = i_item_sk - and i_category = 'Home' - and i_class = 'wallpaper' - and c_customer_sk = cs_or_ws_sales.customer_sk - and d_moy = 6 - and d_year = 1998 - ) - , my_revenue as ( - select c_customer_sk, - sum(ss_ext_sales_price) as revenue - from my_customers, - store_sales, - customer_address, - store, - date_dim - where c_current_addr_sk = ca_address_sk - and ca_county = s_county - and ca_state = s_state - and ss_sold_date_sk = d_date_sk - and c_customer_sk = ss_customer_sk - and d_month_seq between (select distinct d_month_seq+1 - from date_dim where d_year = 1998 and d_moy = 6) - and (select distinct d_month_seq+3 - from date_dim where d_year = 1998 and d_moy = 6) - group by c_customer_sk - ) - , segments as - (select cast((revenue/50) as int) as segment - from my_revenue - ) - select segment, count(*) as num_customers, segment*50 as segment_base - from segments - group by segment - order by segment, num_customers - limit 100; - --- end template query54.tpl query 50 in stream 3 --- start template query90.tpl query 51 in stream 3 -select /* TPC-DS query90.tpl 0.40 */ cast(amc as decimal(15,4))/cast(pmc as decimal(15,4)) am_pm_ratio - from ( select count(*) amc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 10 and 10+1 - and household_demographics.hd_dep_count = 8 - and web_page.wp_char_count between 5000 and 5200) at, - ( select count(*) pmc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 15 and 15+1 - and household_demographics.hd_dep_count = 8 - and web_page.wp_char_count between 5000 and 5200) pt - order by am_pm_ratio - limit 100; - --- end template query90.tpl query 51 in stream 3 --- start template query92.tpl query 52 in stream 3 -select /* TPC-DS query92.tpl 0.44 */ - sum(ws_ext_discount_amt) as "Excess Discount Amount" -from - web_sales - ,item - ,date_dim -where -i_manufact_id = 84 -and i_item_sk = ws_item_sk -and d_date between '1998-01-09' and - dateadd(day,90,cast('1998-01-09' as date)) -and d_date_sk = ws_sold_date_sk -and ws_ext_discount_amt - > ( - SELECT - 1.3 * avg(ws_ext_discount_amt) - FROM - web_sales - ,date_dim - WHERE - ws_item_sk = i_item_sk - and d_date between '1998-01-09' and - dateadd(day,90,cast('1998-01-09' as date)) - and d_date_sk = ws_sold_date_sk - ) -order by sum(ws_ext_discount_amt) -limit 100; - --- end template query92.tpl query 52 in stream 3 --- start template query31.tpl query 53 in stream 3 -with /* TPC-DS query31.tpl 0.50 */ ss as - (select ca_county,d_qoy, d_year,sum(ss_ext_sales_price) as store_sales - from store_sales,date_dim,customer_address - where ss_sold_date_sk = d_date_sk - and ss_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year), - ws as - (select ca_county,d_qoy, d_year,sum(ws_ext_sales_price) as web_sales - from web_sales,date_dim,customer_address - where ws_sold_date_sk = d_date_sk - and ws_bill_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year) - select - ss1.ca_county - ,ss1.d_year - ,ws2.web_sales/ws1.web_sales web_q1_q2_increase - ,ss2.store_sales/ss1.store_sales store_q1_q2_increase - ,ws3.web_sales/ws2.web_sales web_q2_q3_increase - ,ss3.store_sales/ss2.store_sales store_q2_q3_increase - from - ss ss1 - ,ss ss2 - ,ss ss3 - ,ws ws1 - ,ws ws2 - ,ws ws3 - where - ss1.d_qoy = 1 - and ss1.d_year = 2002 - and ss1.ca_county = ss2.ca_county - and ss2.d_qoy = 2 - and ss2.d_year = 2002 - and ss2.ca_county = ss3.ca_county - and ss3.d_qoy = 3 - and ss3.d_year = 2002 - and ss1.ca_county = ws1.ca_county - and ws1.d_qoy = 1 - and ws1.d_year = 2002 - and ws1.ca_county = ws2.ca_county - and ws2.d_qoy = 2 - and ws2.d_year = 2002 - and ws1.ca_county = ws3.ca_county - and ws3.d_qoy = 3 - and ws3.d_year =2002 - and case when ws1.web_sales > 0 then ws2.web_sales/ws1.web_sales else null end - > case when ss1.store_sales > 0 then ss2.store_sales/ss1.store_sales else null end - and case when ws2.web_sales > 0 then ws3.web_sales/ws2.web_sales else null end - > case when ss2.store_sales > 0 then ss3.store_sales/ss2.store_sales else null end - order by ss1.d_year; - --- end template query31.tpl query 53 in stream 3 --- start template query42.tpl query 54 in stream 3 -select /* TPC-DS query42.tpl 0.61 */ dt.d_year - ,item.i_category_id - ,item.i_category - ,sum(ss_ext_sales_price) - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=12 - and dt.d_year=1998 - group by dt.d_year - ,item.i_category_id - ,item.i_category - order by sum(ss_ext_sales_price) desc,dt.d_year - ,item.i_category_id - ,item.i_category -limit 100 ; - --- end template query42.tpl query 54 in stream 3 --- start template query26.tpl query 55 in stream 3 -select /* TPC-DS query26.tpl 0.85 */ i_item_id, - avg(cs_quantity) agg1, - avg(cs_list_price) agg2, - avg(cs_coupon_amt) agg3, - avg(cs_sales_price) agg4 - from catalog_sales, customer_demographics, date_dim, item, promotion - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd_demo_sk and - cs_promo_sk = p_promo_sk and - cd_gender = 'M' and - cd_marital_status = 'D' and - cd_education_status = 'Advanced Degree' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 2001 - group by i_item_id - order by i_item_id - limit 100; - --- end template query26.tpl query 55 in stream 3 --- start template query34.tpl query 56 in stream 3 -select /* TPC-DS query34.tpl 0.73 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (date_dim.d_dom between 1 and 3 or date_dim.d_dom between 25 and 28) - and (household_demographics.hd_buy_potential = '>10000' or - household_demographics.hd_buy_potential = '0-500') - and household_demographics.hd_vehicle_count > 0 - and (case when household_demographics.hd_vehicle_count > 0 - then household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count - else null - end) > 1.2 - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_county in ('Mobile County','Franklin Parish','Pennington County','Wadena County', - 'Ziebach County','Adams County','Anderson County','Maverick County') - group by ss_ticket_number,ss_customer_sk) dn,customer - where ss_customer_sk = c_customer_sk - and cnt between 15 and 20 - order by c_last_name,c_first_name,c_salutation,c_preferred_cust_flag desc, ss_ticket_number; - --- end template query34.tpl query 56 in stream 3 --- start template query68.tpl query 57 in stream 3 -select /* TPC-DS query68.tpl 0.95 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,extended_price - ,extended_tax - ,list_price - from (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_ext_sales_price) extended_price - ,sum(ss_ext_list_price) list_price - ,sum(ss_ext_tax) extended_tax - from store_sales - ,date_dim - ,store - ,household_demographics - ,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_dep_count = 1 or - household_demographics.hd_vehicle_count= 1) - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_city in ('Pleasant Valley','Sunnyside') - group by ss_ticket_number - ,ss_customer_sk - ,ss_addr_sk,ca_city) dn - ,customer - ,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,ss_ticket_number - limit 100; - --- end template query68.tpl query 57 in stream 3 --- start template query2.tpl query 58 in stream 3 -with /* TPC-DS query2.tpl 0.84 */ wscs as - (select sold_date_sk - ,sales_price - from (select ws_sold_date_sk sold_date_sk - ,ws_ext_sales_price sales_price - from web_sales - union all - select cs_sold_date_sk sold_date_sk - ,cs_ext_sales_price sales_price - from catalog_sales)), - wswscs as - (select d_week_seq, - sum(case when (d_day_name='Sunday') then sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then sales_price else null end) sat_sales - from wscs - ,date_dim - where d_date_sk = sold_date_sk - group by d_week_seq) - select d_week_seq1 - ,round(sun_sales1/sun_sales2,2) - ,round(mon_sales1/mon_sales2,2) - ,round(tue_sales1/tue_sales2,2) - ,round(wed_sales1/wed_sales2,2) - ,round(thu_sales1/thu_sales2,2) - ,round(fri_sales1/fri_sales2,2) - ,round(sat_sales1/sat_sales2,2) - from - (select wswscs.d_week_seq d_week_seq1 - ,sun_sales sun_sales1 - ,mon_sales mon_sales1 - ,tue_sales tue_sales1 - ,wed_sales wed_sales1 - ,thu_sales thu_sales1 - ,fri_sales fri_sales1 - ,sat_sales sat_sales1 - from wswscs,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 2000) y, - (select wswscs.d_week_seq d_week_seq2 - ,sun_sales sun_sales2 - ,mon_sales mon_sales2 - ,tue_sales tue_sales2 - ,wed_sales wed_sales2 - ,thu_sales thu_sales2 - ,fri_sales fri_sales2 - ,sat_sales sat_sales2 - from wswscs - ,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 2000+1) z - where d_week_seq1=d_week_seq2-53 - order by d_week_seq1; - --- end template query2.tpl query 58 in stream 3 --- start template query44.tpl query 59 in stream 3 -select /* TPC-DS query44.tpl 0.4 */ asceding.rnk, i1.i_product_name best_performing, i2.i_product_name worst_performing -from(select * - from (select item_sk,rank() over (order by rank_col asc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 491 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 491 - and ss_hdemo_sk is null - group by ss_store_sk))V1)V11 - where rnk < 11) asceding, - (select * - from (select item_sk,rank() over (order by rank_col desc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 491 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 491 - and ss_hdemo_sk is null - group by ss_store_sk))V2)V21 - where rnk < 11) descending, -item i1, -item i2 -where asceding.rnk = descending.rnk - and i1.i_item_sk=asceding.item_sk - and i2.i_item_sk=descending.item_sk -order by asceding.rnk -limit 100; - --- end template query44.tpl query 59 in stream 3 --- start template query81.tpl query 60 in stream 3 -with /* TPC-DS query81.tpl 0.37 */ customer_total_return as - (select cr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(cr_return_amt_inc_tax) as ctr_total_return - from catalog_returns - ,date_dim - ,customer_address - where cr_returned_date_sk = d_date_sk - and d_year =2002 - and cr_returning_addr_sk = ca_address_sk - group by cr_returning_customer_sk - ,ca_state ) - select c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'KY' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - limit 100; - --- end template query81.tpl query 60 in stream 3 --- start template query67a.tpl query 61 in stream 3 -with /* TPC-DS query67a.tpl 0.35 */ results as -( select i_category ,i_class ,i_brand ,i_product_name ,d_year ,d_qoy ,d_moy ,s_store_id - ,sum(coalesce(ss_sales_price*ss_quantity,0)) sumsales - from store_sales ,date_dim ,store ,item - where ss_sold_date_sk=d_date_sk - and ss_item_sk=i_item_sk - and ss_store_sk = s_store_sk - and d_month_seq between 1179 and 1179 + 11 - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy,s_store_id) - , - results_rollup as - (select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, s_store_id, sumsales - from results - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy - union all - select i_category, i_class, i_brand, i_product_name, d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year - union all - select i_category, i_class, i_brand, i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name - union all - select i_category, i_class, i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand - union all - select i_category, i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class - union all - select i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category - union all - select null i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results) - - select * -from (select i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rank() over (partition by i_category order by sumsales desc) rk - from results_rollup) dw2 -where rk <= 100 -order by i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rk -limit 100; - --- end template query67a.tpl query 61 in stream 3 --- start template query99.tpl query 62 in stream 3 -select /* TPC-DS query99.tpl 0.94 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 30) and - (cs_ship_date_sk - cs_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 60) and - (cs_ship_date_sk - cs_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 90) and - (cs_ship_date_sk - cs_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - catalog_sales - ,warehouse - ,ship_mode - ,call_center - ,date_dim -where - d_month_seq between 1208 and 1208 + 11 -and cs_ship_date_sk = d_date_sk -and cs_warehouse_sk = w_warehouse_sk -and cs_ship_mode_sk = sm_ship_mode_sk -and cs_call_center_sk = cc_call_center_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -limit 100; - --- end template query99.tpl query 62 in stream 3 --- start template query6.tpl query 63 in stream 3 -select /* TPC-DS query6.tpl 0.58 */ a.ca_state state, count(*) cnt - from customer_address a - ,customer c - ,store_sales s - ,date_dim d - ,item i - where a.ca_address_sk = c.c_current_addr_sk - and c.c_customer_sk = s.ss_customer_sk - and s.ss_sold_date_sk = d.d_date_sk - and s.ss_item_sk = i.i_item_sk - and d.d_month_seq = - (select distinct (d_month_seq) - from date_dim - where d_year = 2000 - and d_moy = 4 ) - and i.i_current_price > 1.2 * - (select avg(j.i_current_price) - from item j - where j.i_category = i.i_category) - group by a.ca_state - having count(*) >= 10 - order by cnt, a.ca_state - limit 100; - --- end template query6.tpl query 63 in stream 3 --- start template query83.tpl query 64 in stream 3 -with /* TPC-DS query83.tpl 0.96 */ sr_items as - (select i_item_id item_id, - sum(sr_return_quantity) sr_item_qty - from store_returns, - item, - date_dim - where sr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2001-02-11','2001-09-22','2001-11-16'))) - and sr_returned_date_sk = d_date_sk - group by i_item_id), - cr_items as - (select i_item_id item_id, - sum(cr_return_quantity) cr_item_qty - from catalog_returns, - item, - date_dim - where cr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2001-02-11','2001-09-22','2001-11-16'))) - and cr_returned_date_sk = d_date_sk - group by i_item_id), - wr_items as - (select i_item_id item_id, - sum(wr_return_quantity) wr_item_qty - from web_returns, - item, - date_dim - where wr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2001-02-11','2001-09-22','2001-11-16'))) - and wr_returned_date_sk = d_date_sk - group by i_item_id) - select sr_items.item_id - ,sr_item_qty - ,sr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 sr_dev - ,cr_item_qty - ,cr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 cr_dev - ,wr_item_qty - ,wr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 wr_dev - ,(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 average - from sr_items - ,cr_items - ,wr_items - where sr_items.item_id=cr_items.item_id - and sr_items.item_id=wr_items.item_id - order by sr_items.item_id - ,sr_item_qty - limit 100; - --- end template query83.tpl query 64 in stream 3 --- start template query1.tpl query 65 in stream 3 -with /* TPC-DS query1.tpl 0.12 */ customer_total_return as -(select sr_customer_sk as ctr_customer_sk -,sr_store_sk as ctr_store_sk -,sum(SR_FEE) as ctr_total_return -from store_returns -,date_dim -where sr_returned_date_sk = d_date_sk -and d_year =2000 -group by sr_customer_sk -,sr_store_sk) - select c_customer_id -from customer_total_return ctr1 -,store -,customer -where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 -from customer_total_return ctr2 -where ctr1.ctr_store_sk = ctr2.ctr_store_sk) -and s_store_sk = ctr1.ctr_store_sk -and s_state = 'VT' -and ctr1.ctr_customer_sk = c_customer_sk -order by c_customer_id -limit 100; - --- end template query1.tpl query 65 in stream 3 --- start template query60.tpl query 66 in stream 3 -with /* TPC-DS query60.tpl 0.29 */ ss as ( - select - i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Shoes')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 10 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -8 - group by i_item_id), - cs as ( - select - i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Shoes')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 10 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -8 - group by i_item_id), - ws as ( - select - i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Shoes')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 10 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -8 - group by i_item_id) - select - i_item_id -,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by i_item_id - ,total_sales - limit 100; - --- end template query60.tpl query 66 in stream 3 --- start template query33.tpl query 67 in stream 3 -with /* TPC-DS query33.tpl 0.22 */ ss as ( - select - i_manufact_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Jewelry')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 7 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id), - cs as ( - select - i_manufact_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Jewelry')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 7 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id), - ws as ( - select - i_manufact_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Jewelry')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 7 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id) - select i_manufact_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_manufact_id - order by total_sales -limit 100; - --- end template query33.tpl query 67 in stream 3 --- start template query11.tpl query 68 in stream 3 -with /* TPC-DS query11.tpl 0.51 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ss_ext_list_price-ss_ext_discount_amt) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ws_ext_list_price-ws_ext_discount_amt) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_birth_country - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 1999 - and t_s_secyear.dyear = 1999+1 - and t_w_firstyear.dyear = 1999 - and t_w_secyear.dyear = 1999+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else 0.0 end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else 0.0 end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_birth_country -limit 100; - --- end template query11.tpl query 68 in stream 3 --- start template query28.tpl query 69 in stream 3 -select /* TPC-DS query28.tpl 0.36 */ * -from (select avg(ss_list_price) B1_LP - ,count(ss_list_price) B1_CNT - ,count(distinct ss_list_price) B1_CNTD - from store_sales - where ss_quantity between 0 and 5 - and (ss_list_price between 84 and 84+10 - or ss_coupon_amt between 5544 and 5544+1000 - or ss_wholesale_cost between 14 and 14+20)) B1, - (select avg(ss_list_price) B2_LP - ,count(ss_list_price) B2_CNT - ,count(distinct ss_list_price) B2_CNTD - from store_sales - where ss_quantity between 6 and 10 - and (ss_list_price between 66 and 66+10 - or ss_coupon_amt between 12933 and 12933+1000 - or ss_wholesale_cost between 6 and 6+20)) B2, - (select avg(ss_list_price) B3_LP - ,count(ss_list_price) B3_CNT - ,count(distinct ss_list_price) B3_CNTD - from store_sales - where ss_quantity between 11 and 15 - and (ss_list_price between 170 and 170+10 - or ss_coupon_amt between 16576 and 16576+1000 - or ss_wholesale_cost between 2 and 2+20)) B3, - (select avg(ss_list_price) B4_LP - ,count(ss_list_price) B4_CNT - ,count(distinct ss_list_price) B4_CNTD - from store_sales - where ss_quantity between 16 and 20 - and (ss_list_price between 160 and 160+10 - or ss_coupon_amt between 787 and 787+1000 - or ss_wholesale_cost between 69 and 69+20)) B4, - (select avg(ss_list_price) B5_LP - ,count(ss_list_price) B5_CNT - ,count(distinct ss_list_price) B5_CNTD - from store_sales - where ss_quantity between 21 and 25 - and (ss_list_price between 45 and 45+10 - or ss_coupon_amt between 8822 and 8822+1000 - or ss_wholesale_cost between 50 and 50+20)) B5, - (select avg(ss_list_price) B6_LP - ,count(ss_list_price) B6_CNT - ,count(distinct ss_list_price) B6_CNTD - from store_sales - where ss_quantity between 26 and 30 - and (ss_list_price between 159 and 159+10 - or ss_coupon_amt between 11804 and 11804+1000 - or ss_wholesale_cost between 62 and 62+20)) B6 -limit 100; - --- end template query28.tpl query 69 in stream 3 --- start template query95.tpl query 70 in stream 3 -with /* TPC-DS query95.tpl 0.43 */ ws_wh as -(select ws1.ws_order_number,ws1.ws_warehouse_sk wh1,ws2.ws_warehouse_sk wh2 - from web_sales ws1,web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) - select - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2000-4-01' and - dateadd(day,60,cast('2000-4-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'MT' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and ws1.ws_order_number in (select ws_order_number - from ws_wh) -and ws1.ws_order_number in (select wr_order_number - from web_returns,ws_wh - where wr_order_number = ws_wh.ws_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query95.tpl query 70 in stream 3 --- start template query12.tpl query 71 in stream 3 -select /* TPC-DS query12.tpl 0.64 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ws_ext_sales_price) as itemrevenue - ,sum(ws_ext_sales_price)*100/sum(sum(ws_ext_sales_price)) over - (partition by i_class) as revenueratio -from - web_sales - ,item - ,date_dim -where - ws_item_sk = i_item_sk - and i_category in ('Men', 'Books', 'Women') - and ws_sold_date_sk = d_date_sk - and d_date between cast('1999-03-18' as date) - and dateadd(day,30,cast('1999-03-18' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query12.tpl query 71 in stream 3 --- start template query64.tpl query 72 in stream 3 -with /* TPC-DS query64.tpl 0.20 */ cs_ui as - (select cs_item_sk - ,sum(cs_ext_list_price) as sale,sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit) as refund - from catalog_sales - ,catalog_returns - where cs_item_sk = cr_item_sk - and cs_order_number = cr_order_number - group by cs_item_sk - having sum(cs_ext_list_price)>2*sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit)), -cross_sales as - (select i_product_name product_name - ,i_item_sk item_sk - ,s_store_name store_name - ,s_zip store_zip - ,ad1.ca_street_number b_street_number - ,ad1.ca_street_name b_street_name - ,ad1.ca_city b_city - ,ad1.ca_zip b_zip - ,ad2.ca_street_number c_street_number - ,ad2.ca_street_name c_street_name - ,ad2.ca_city c_city - ,ad2.ca_zip c_zip - ,d1.d_year as syear - ,d2.d_year as fsyear - ,d3.d_year s2year - ,count(*) cnt - ,sum(ss_wholesale_cost) s1 - ,sum(ss_list_price) s2 - ,sum(ss_coupon_amt) s3 - FROM store_sales - ,store_returns - ,cs_ui - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,customer - ,customer_demographics cd1 - ,customer_demographics cd2 - ,promotion - ,household_demographics hd1 - ,household_demographics hd2 - ,customer_address ad1 - ,customer_address ad2 - ,income_band ib1 - ,income_band ib2 - ,item - WHERE ss_store_sk = s_store_sk AND - ss_sold_date_sk = d1.d_date_sk AND - ss_customer_sk = c_customer_sk AND - ss_cdemo_sk= cd1.cd_demo_sk AND - ss_hdemo_sk = hd1.hd_demo_sk AND - ss_addr_sk = ad1.ca_address_sk and - ss_item_sk = i_item_sk and - ss_item_sk = sr_item_sk and - ss_ticket_number = sr_ticket_number and - ss_item_sk = cs_ui.cs_item_sk and - c_current_cdemo_sk = cd2.cd_demo_sk AND - c_current_hdemo_sk = hd2.hd_demo_sk AND - c_current_addr_sk = ad2.ca_address_sk and - c_first_sales_date_sk = d2.d_date_sk and - c_first_shipto_date_sk = d3.d_date_sk and - ss_promo_sk = p_promo_sk and - hd1.hd_income_band_sk = ib1.ib_income_band_sk and - hd2.hd_income_band_sk = ib2.ib_income_band_sk and - cd1.cd_marital_status <> cd2.cd_marital_status and - i_color in ('dim','brown','magenta','lavender','midnight','rosy') and - i_current_price between 18 and 18 + 10 and - i_current_price between 18 + 1 and 18 + 15 -group by i_product_name - ,i_item_sk - ,s_store_name - ,s_zip - ,ad1.ca_street_number - ,ad1.ca_street_name - ,ad1.ca_city - ,ad1.ca_zip - ,ad2.ca_street_number - ,ad2.ca_street_name - ,ad2.ca_city - ,ad2.ca_zip - ,d1.d_year - ,d2.d_year - ,d3.d_year -) -select cs1.product_name - ,cs1.store_name - ,cs1.store_zip - ,cs1.b_street_number - ,cs1.b_street_name - ,cs1.b_city - ,cs1.b_zip - ,cs1.c_street_number - ,cs1.c_street_name - ,cs1.c_city - ,cs1.c_zip - ,cs1.syear - ,cs1.cnt - ,cs1.s1 as s11 - ,cs1.s2 as s21 - ,cs1.s3 as s31 - ,cs2.s1 as s12 - ,cs2.s2 as s22 - ,cs2.s3 as s32 - ,cs2.syear - ,cs2.cnt -from cross_sales cs1,cross_sales cs2 -where cs1.item_sk=cs2.item_sk and - cs1.syear = 2001 and - cs2.syear = 2001 + 1 and - cs2.cnt <= cs1.cnt and - cs1.store_name = cs2.store_name and - cs1.store_zip = cs2.store_zip -order by cs1.product_name - ,cs1.store_name - ,cs2.cnt - ,cs1.s1 - ,cs2.s1; - --- end template query64.tpl query 72 in stream 3 --- start template query15.tpl query 73 in stream 3 -select /* TPC-DS query15.tpl 0.57 */ ca_zip - ,sum(cs_sales_price) - from catalog_sales - ,customer - ,customer_address - ,date_dim - where cs_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', - '85392', '85460', '80348', '81792') - or ca_state in ('CA','WA','GA') - or cs_sales_price > 500) - and cs_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 2001 - group by ca_zip - order by ca_zip - limit 100; - --- end template query15.tpl query 73 in stream 3 --- start template query25.tpl query 74 in stream 3 -select /* TPC-DS query25.tpl 0.9 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,avg(ss_net_profit) as store_sales_profit - ,avg(sr_net_loss) as store_returns_loss - ,avg(cs_net_profit) as catalog_sales_profit - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 1999 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 10 - and d2.d_year = 1999 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_moy between 4 and 10 - and d3.d_year = 1999 - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query25.tpl query 74 in stream 3 --- start template query93.tpl query 75 in stream 3 -select /* TPC-DS query93.tpl 0.52 */ ss_customer_sk - ,sum(act_sales) sumsales - from (select ss_item_sk - ,ss_ticket_number - ,ss_customer_sk - ,case when sr_return_quantity is not null then (ss_quantity-sr_return_quantity)*ss_sales_price - else (ss_quantity*ss_sales_price) end act_sales - from store_sales left outer join store_returns on (sr_item_sk = ss_item_sk - and sr_ticket_number = ss_ticket_number) - ,reason - where sr_reason_sk = r_reason_sk - and r_reason_desc = 'reason 66') t - group by ss_customer_sk - order by sumsales, ss_customer_sk -limit 100; - --- end template query93.tpl query 75 in stream 3 --- start template query9.tpl query 76 in stream 3 -select /* TPC-DS query9.tpl 0.49 */ case when (select count(*) - from store_sales - where ss_quantity between 1 and 20) > 78028047 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 1 and 20) - else (select avg(ss_net_profit) - from store_sales - where ss_quantity between 1 and 20) end bucket1 , - case when (select count(*) - from store_sales - where ss_quantity between 21 and 40) > 50389503 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 21 and 40) - else (select avg(ss_net_profit) - from store_sales - where ss_quantity between 21 and 40) end bucket2, - case when (select count(*) - from store_sales - where ss_quantity between 41 and 60) > 79367181 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 41 and 60) - else (select avg(ss_net_profit) - from store_sales - where ss_quantity between 41 and 60) end bucket3, - case when (select count(*) - from store_sales - where ss_quantity between 61 and 80) > 119906456 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 61 and 80) - else (select avg(ss_net_profit) - from store_sales - where ss_quantity between 61 and 80) end bucket4, - case when (select count(*) - from store_sales - where ss_quantity between 81 and 100) > 128467526 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 81 and 100) - else (select avg(ss_net_profit) - from store_sales - where ss_quantity between 81 and 100) end bucket5 -from reason -where r_reason_sk = 1 -; - --- end template query9.tpl query 76 in stream 3 --- start template query65.tpl query 77 in stream 3 -select /* TPC-DS query65.tpl 0.71 */ - s_store_name, - i_item_desc, - sc.revenue, - i_current_price, - i_wholesale_cost, - i_brand - from store, item, - (select ss_store_sk, avg(revenue) as ave - from - (select ss_store_sk, ss_item_sk, - sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1209 and 1209+11 - group by ss_store_sk, ss_item_sk) sa - group by ss_store_sk) sb, - (select ss_store_sk, ss_item_sk, sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1209 and 1209+11 - group by ss_store_sk, ss_item_sk) sc - where sb.ss_store_sk = sc.ss_store_sk and - sc.revenue <= 0.1 * sb.ave and - s_store_sk = sc.ss_store_sk and - i_item_sk = sc.ss_item_sk - order by s_store_name, i_item_desc -limit 100; - --- end template query65.tpl query 77 in stream 3 --- start template query71.tpl query 78 in stream 3 -select /* TPC-DS query71.tpl 0.72 */ i_brand_id brand_id, i_brand brand,t_hour,t_minute, - sum(ext_price) ext_price - from item, (select ws_ext_sales_price as ext_price, - ws_sold_date_sk as sold_date_sk, - ws_item_sk as sold_item_sk, - ws_sold_time_sk as time_sk - from web_sales,date_dim - where d_date_sk = ws_sold_date_sk - and d_moy=11 - and d_year=1999 - union all - select cs_ext_sales_price as ext_price, - cs_sold_date_sk as sold_date_sk, - cs_item_sk as sold_item_sk, - cs_sold_time_sk as time_sk - from catalog_sales,date_dim - where d_date_sk = cs_sold_date_sk - and d_moy=11 - and d_year=1999 - union all - select ss_ext_sales_price as ext_price, - ss_sold_date_sk as sold_date_sk, - ss_item_sk as sold_item_sk, - ss_sold_time_sk as time_sk - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - and d_moy=11 - and d_year=1999 - ) tmp,time_dim - where - sold_item_sk = i_item_sk - and i_manager_id=1 - and time_sk = t_time_sk - and (t_meal_time = 'breakfast' or t_meal_time = 'dinner') - group by i_brand, i_brand_id,t_hour,t_minute - order by ext_price desc, i_brand_id - ; - --- end template query71.tpl query 78 in stream 3 --- start template query57.tpl query 79 in stream 3 -with /* TPC-DS query57.tpl 0.70 */ v1 as( - select i_category, i_brand, - cc_name, - d_year, d_moy, - sum(cs_sales_price) sum_sales, - avg(sum(cs_sales_price)) over - (partition by i_category, i_brand, - cc_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - cc_name - order by d_year, d_moy) rn - from item, catalog_sales, date_dim, call_center - where cs_item_sk = i_item_sk and - cs_sold_date_sk = d_date_sk and - cc_call_center_sk= cs_call_center_sk and - ( - d_year = 1999 or - ( d_year = 1999-1 and d_moy =12) or - ( d_year = 1999+1 and d_moy =1) - ) - group by i_category, i_brand, - cc_name , d_year, d_moy), - v2 as( - select v1.i_category, v1.i_brand - ,v1.d_year, v1.d_moy - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1. cc_name = v1_lag. cc_name and - v1. cc_name = v1_lead. cc_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 1999 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, sum_sales - limit 100; - --- end template query57.tpl query 79 in stream 3 --- start template query32.tpl query 80 in stream 3 -select /* TPC-DS query32.tpl 0.7 */ sum(cs_ext_discount_amt) as "excess discount amount" -from - catalog_sales - ,item - ,date_dim -where -i_manufact_id = 369 -and i_item_sk = cs_item_sk -and d_date between '1998-03-10' and - dateadd(day,90,cast('1998-03-10' as date)) -and d_date_sk = cs_sold_date_sk -and cs_ext_discount_amt - > ( - select - 1.3 * avg(cs_ext_discount_amt) - from - catalog_sales - ,date_dim - where - cs_item_sk = i_item_sk - and d_date between '1998-03-10' and - dateadd(day,90,cast('1998-03-10' as date)) - and d_date_sk = cs_sold_date_sk - ) -limit 100; - --- end template query32.tpl query 80 in stream 3 --- start template query61.tpl query 81 in stream 3 -select /* TPC-DS query61.tpl 0.97 */ promotions,total,cast(promotions as decimal(15,4))/cast(total as decimal(15,4))*100 -from - (select sum(ss_ext_sales_price) promotions - from store_sales - ,store - ,promotion - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_promo_sk = p_promo_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -6 - and i_category = 'Books' - and (p_channel_dmail = 'Y' or p_channel_email = 'Y' or p_channel_tv = 'Y') - and s_gmt_offset = -6 - and d_year = 2002 - and d_moy = 12) promotional_sales, - (select sum(ss_ext_sales_price) total - from store_sales - ,store - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -6 - and i_category = 'Books' - and s_gmt_offset = -6 - and d_year = 2002 - and d_moy = 12) all_sales -order by promotions, total -limit 100; - --- end template query61.tpl query 81 in stream 3 --- start template query85.tpl query 82 in stream 3 -select /* TPC-DS query85.tpl 0.33 */ substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) - from web_sales, web_returns, web_page, customer_demographics cd1, - customer_demographics cd2, customer_address, date_dim, reason - where ws_web_page_sk = wp_web_page_sk - and ws_item_sk = wr_item_sk - and ws_order_number = wr_order_number - and ws_sold_date_sk = d_date_sk and d_year = 1999 - and cd1.cd_demo_sk = wr_refunded_cdemo_sk - and cd2.cd_demo_sk = wr_returning_cdemo_sk - and ca_address_sk = wr_refunded_addr_sk - and r_reason_sk = wr_reason_sk - and - ( - ( - cd1.cd_marital_status = 'U' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Primary' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 100.00 and 150.00 - ) - or - ( - cd1.cd_marital_status = 'W' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'College' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 50.00 and 100.00 - ) - or - ( - cd1.cd_marital_status = 'D' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = '2 yr Degree' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ca_country = 'United States' - and - ca_state in ('OK', 'OH', 'IN') - and ws_net_profit between 100 and 200 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('SD', 'MI', 'MO') - and ws_net_profit between 150 and 300 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('GA', 'VA', 'CO') - and ws_net_profit between 50 and 250 - ) - ) -group by r_reason_desc -order by substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) -limit 100; - --- end template query85.tpl query 82 in stream 3 --- start template query73.tpl query 83 in stream 3 -select /* TPC-DS query73.tpl 0.79 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_buy_potential = '1001-5000' or - household_demographics.hd_buy_potential = '5001-10000') - and household_demographics.hd_vehicle_count > 0 - and case when household_demographics.hd_vehicle_count > 0 then - household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count else null end > 1 - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_county in ('Anderson County','Huron County','Arthur County','Luce County') - group by ss_ticket_number,ss_customer_sk) dj,customer - where ss_customer_sk = c_customer_sk - and cnt between 1 and 5 - order by cnt desc, c_last_name asc; - --- end template query73.tpl query 83 in stream 3 --- start template query98.tpl query 84 in stream 3 -select /* TPC-DS query98.tpl 0.32 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ss_ext_sales_price) as itemrevenue - ,sum(ss_ext_sales_price)*100/sum(sum(ss_ext_sales_price)) over - (partition by i_class) as revenueratio -from - store_sales - ,item - ,date_dim -where - ss_item_sk = i_item_sk - and i_category in ('Sports', 'Music', 'Electronics') - and ss_sold_date_sk = d_date_sk - and d_date between cast('1999-06-22' as date) - and dateadd(day,30,cast('1999-06-22' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio; - --- end template query98.tpl query 84 in stream 3 --- start template query77a.tpl query 85 in stream 3 -with /* TPC-DS query77a.tpl 0.78 */ ss as - (select s_store_sk, - sum(ss_ext_sales_price) as sales, - sum(ss_net_profit) as profit - from store_sales, - date_dim, - store - where ss_sold_date_sk = d_date_sk - and d_date between cast('1999-08-13' as date) - and dateadd(day,30,cast('1999-08-13' as date)) - and ss_store_sk = s_store_sk - group by s_store_sk) - , - sr as - (select s_store_sk, - sum(sr_return_amt) as returns, - sum(sr_net_loss) as profit_loss - from store_returns, - date_dim, - store - where sr_returned_date_sk = d_date_sk - and d_date between cast('1999-08-13' as date) - and dateadd(day,30,cast('1999-08-13' as date)) - and sr_store_sk = s_store_sk - group by s_store_sk), - cs as - (select cs_call_center_sk, - sum(cs_ext_sales_price) as sales, - sum(cs_net_profit) as profit - from catalog_sales, - date_dim - where cs_sold_date_sk = d_date_sk - and d_date between cast('1999-08-13' as date) - and dateadd(day,30,cast('1999-08-13' as date)) - group by cs_call_center_sk - ), - cr as - (select cr_call_center_sk, - sum(cr_return_amount) as returns, - sum(cr_net_loss) as profit_loss - from catalog_returns, - date_dim - where cr_returned_date_sk = d_date_sk - and d_date between cast('1999-08-13' as date) - and dateadd(day,30,cast('1999-08-13' as date)) - group by cr_call_center_sk), - ws as - ( select wp_web_page_sk, - sum(ws_ext_sales_price) as sales, - sum(ws_net_profit) as profit - from web_sales, - date_dim, - web_page - where ws_sold_date_sk = d_date_sk - and d_date between cast('1999-08-13' as date) - and dateadd(day,30,cast('1999-08-13' as date)) - and ws_web_page_sk = wp_web_page_sk - group by wp_web_page_sk), - wr as - (select wp_web_page_sk, - sum(wr_return_amt) as returns, - sum(wr_net_loss) as profit_loss - from web_returns, - date_dim, - web_page - where wr_returned_date_sk = d_date_sk - and d_date between cast('1999-08-13' as date) - and dateadd(day,30,cast('1999-08-13' as date)) - and wr_web_page_sk = wp_web_page_sk - group by wp_web_page_sk) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , ss.s_store_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ss left join sr - on ss.s_store_sk = sr.s_store_sk - union all - select 'catalog channel' as channel - , cs_call_center_sk as id - , sales - , returns - , (profit - profit_loss) as profit - from cs - , cr - union all - select 'web channel' as channel - , ws.wp_web_page_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ws left join wr - on ws.wp_web_page_sk = wr.wp_web_page_sk - ) x - group by channel, id ) - - select * - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results -) foo -order by channel, id - limit 100; - --- end template query77a.tpl query 85 in stream 3 --- start template query45.tpl query 86 in stream 3 -select /* TPC-DS query45.tpl 0.18 */ ca_zip, ca_county, sum(ws_sales_price) - from web_sales, customer, customer_address, date_dim, item - where ws_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ws_item_sk = i_item_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', '85392', '85460', '80348', '81792') - or - i_item_id in (select i_item_id - from item - where i_item_sk in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29) - ) - ) - and ws_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 2001 - group by ca_zip, ca_county - order by ca_zip, ca_county - limit 100; - --- end template query45.tpl query 86 in stream 3 --- start template query20.tpl query 87 in stream 3 -select /* TPC-DS query20.tpl 0.65 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(cs_ext_sales_price) as itemrevenue - ,sum(cs_ext_sales_price)*100/sum(sum(cs_ext_sales_price)) over - (partition by i_class) as revenueratio - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and i_category in ('Electronics', 'Music', 'Women') - and cs_sold_date_sk = d_date_sk - and d_date between cast('1999-01-30' as date) - and dateadd(day,30,cast('1999-01-30' as date)) - group by i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - order by i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query20.tpl query 87 in stream 3 --- start template query50.tpl query 88 in stream 3 -select /* TPC-DS query50.tpl 0.60 */ - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 30) and - (sr_returned_date_sk - ss_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 60) and - (sr_returned_date_sk - ss_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 90) and - (sr_returned_date_sk - ss_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - store_sales - ,store_returns - ,store - ,date_dim d1 - ,date_dim d2 -where - d2.d_year = 1998 -and d2.d_moy = 9 -and ss_ticket_number = sr_ticket_number -and ss_item_sk = sr_item_sk -and ss_sold_date_sk = d1.d_date_sk -and sr_returned_date_sk = d2.d_date_sk -and ss_customer_sk = sr_customer_sk -and ss_store_sk = s_store_sk -group by - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -order by s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -limit 100; - --- end template query50.tpl query 88 in stream 3 --- start template query70a.tpl query 89 in stream 3 -with /* TPC-DS query70a.tpl 0.34 */ results as -( select - sum(ss_net_profit) as total_sum ,s_state ,s_county, 0 as gstate, 0 as g_county - from - store_sales - ,date_dim d1 - ,store - where - d1.d_month_seq between 1210 and 1210 + 11 - and d1.d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - and s_state in - ( select s_state - from (select s_state as s_state, - rank() over ( partition by s_state order by sum(ss_net_profit) desc) as ranking - from store_sales, store, date_dim - where d_month_seq between 1210 and 1210 + 11 - and d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - group by s_state - ) tmp1 - where ranking <= 5) - group by s_state,s_county) , - results_rollup as -(select total_sum ,s_state ,s_county, 0 as g_state, 0 as g_county, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum,s_state, NULL as s_county, 0 as g_state, 1 as g_county, 1 as lochierarchy from results group by s_state - union - select sum(total_sum) as total_sum ,NULL as s_state ,NULL as s_county, 1 as g_state, 1 as g_county, 2 as lochierarchy from results) - select total_sum ,s_state ,s_county, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_county = 0 then s_state end - order by total_sum desc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then s_state end - ,rank_within_parent - limit 100; - --- end template query70a.tpl query 89 in stream 3 --- start template query75.tpl query 90 in stream 3 -WITH /* TPC-DS query75.tpl 0.3 */ all_sales AS ( - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,SUM(sales_cnt) AS sales_cnt - ,SUM(sales_amt) AS sales_amt - FROM (SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,cs_quantity - COALESCE(cr_return_quantity,0) AS sales_cnt - ,cs_ext_sales_price - COALESCE(cr_return_amount,0.0) AS sales_amt - FROM catalog_sales JOIN item ON i_item_sk=cs_item_sk - JOIN date_dim ON d_date_sk=cs_sold_date_sk - LEFT JOIN catalog_returns ON (cs_order_number=cr_order_number - AND cs_item_sk=cr_item_sk) - WHERE i_category='Electronics' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ss_quantity - COALESCE(sr_return_quantity,0) AS sales_cnt - ,ss_ext_sales_price - COALESCE(sr_return_amt,0.0) AS sales_amt - FROM store_sales JOIN item ON i_item_sk=ss_item_sk - JOIN date_dim ON d_date_sk=ss_sold_date_sk - LEFT JOIN store_returns ON (ss_ticket_number=sr_ticket_number - AND ss_item_sk=sr_item_sk) - WHERE i_category='Electronics' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ws_quantity - COALESCE(wr_return_quantity,0) AS sales_cnt - ,ws_ext_sales_price - COALESCE(wr_return_amt,0.0) AS sales_amt - FROM web_sales JOIN item ON i_item_sk=ws_item_sk - JOIN date_dim ON d_date_sk=ws_sold_date_sk - LEFT JOIN web_returns ON (ws_order_number=wr_order_number - AND ws_item_sk=wr_item_sk) - WHERE i_category='Electronics') sales_detail - GROUP BY d_year, i_brand_id, i_class_id, i_category_id, i_manufact_id) - SELECT prev_yr.d_year AS prev_year - ,curr_yr.d_year AS year - ,curr_yr.i_brand_id - ,curr_yr.i_class_id - ,curr_yr.i_category_id - ,curr_yr.i_manufact_id - ,prev_yr.sales_cnt AS prev_yr_cnt - ,curr_yr.sales_cnt AS curr_yr_cnt - ,curr_yr.sales_cnt-prev_yr.sales_cnt AS sales_cnt_diff - ,curr_yr.sales_amt-prev_yr.sales_amt AS sales_amt_diff - FROM all_sales curr_yr, all_sales prev_yr - WHERE curr_yr.i_brand_id=prev_yr.i_brand_id - AND curr_yr.i_class_id=prev_yr.i_class_id - AND curr_yr.i_category_id=prev_yr.i_category_id - AND curr_yr.i_manufact_id=prev_yr.i_manufact_id - AND curr_yr.d_year=2001 - AND prev_yr.d_year=2001-1 - AND CAST(curr_yr.sales_cnt AS DECIMAL(17,2))/CAST(prev_yr.sales_cnt AS DECIMAL(17,2))<0.9 - ORDER BY sales_cnt_diff,sales_amt_diff - limit 100; - --- end template query75.tpl query 90 in stream 3 --- start template query91.tpl query 91 in stream 3 -select /* TPC-DS query91.tpl 0.13 */ - cc_call_center_id Call_Center, - cc_name Call_Center_Name, - cc_manager Manager, - sum(cr_net_loss) Returns_Loss -from - call_center, - catalog_returns, - date_dim, - customer, - customer_address, - customer_demographics, - household_demographics -where - cr_call_center_sk = cc_call_center_sk -and cr_returned_date_sk = d_date_sk -and cr_returning_customer_sk= c_customer_sk -and cd_demo_sk = c_current_cdemo_sk -and hd_demo_sk = c_current_hdemo_sk -and ca_address_sk = c_current_addr_sk -and d_year = 1999 -and d_moy = 11 -and ( (cd_marital_status = 'M' and cd_education_status = 'Unknown') - or(cd_marital_status = 'W' and cd_education_status = 'Advanced Degree')) -and hd_buy_potential like '1001-5000%' -and ca_gmt_offset = -6 -group by cc_call_center_id,cc_name,cc_manager,cd_marital_status,cd_education_status -order by sum(cr_net_loss) desc; - --- end template query91.tpl query 91 in stream 3 --- start template query17.tpl query 92 in stream 3 -select /* TPC-DS query17.tpl 0.41 */ i_item_id - ,i_item_desc - ,s_state - ,count(ss_quantity) as store_sales_quantitycount - ,avg(ss_quantity) as store_sales_quantityave - ,stddev_samp(ss_quantity) as store_sales_quantitystdev - ,stddev_samp(ss_quantity)/avg(ss_quantity) as store_sales_quantitycov - ,count(sr_return_quantity) as store_returns_quantitycount - ,avg(sr_return_quantity) as store_returns_quantityave - ,stddev_samp(sr_return_quantity) as store_returns_quantitystdev - ,stddev_samp(sr_return_quantity)/avg(sr_return_quantity) as store_returns_quantitycov - ,count(cs_quantity) as catalog_sales_quantitycount ,avg(cs_quantity) as catalog_sales_quantityave - ,stddev_samp(cs_quantity) as catalog_sales_quantitystdev - ,stddev_samp(cs_quantity)/avg(cs_quantity) as catalog_sales_quantitycov - from store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where d1.d_quarter_name = '2001Q1' - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_quarter_name in ('2001Q1','2001Q2','2001Q3') - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_quarter_name in ('2001Q1','2001Q2','2001Q3') - group by i_item_id - ,i_item_desc - ,s_state - order by i_item_id - ,i_item_desc - ,s_state -limit 100; - --- end template query17.tpl query 92 in stream 3 --- start template query24.tpl query 93 in stream 3 -with /* TPC-DS query24.tpl 0.92 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_sales_price) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip -and s_market_id=8 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'navajo' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; -with /* TPC-DS query24.tpl 0.92 part2 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_sales_price) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip - and s_market_id = 8 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'bisque' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; - --- end template query24.tpl query 93 in stream 3 --- start template query48.tpl query 94 in stream 3 -select /* TPC-DS query48.tpl 0.74 */ sum (ss_quantity) - from store_sales, store, customer_demographics, customer_address, date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2001 - and - ( - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'U' - and - cd_education_status = '2 yr Degree' - and - ss_sales_price between 100.00 and 150.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'D' - and - cd_education_status = 'Primary' - and - ss_sales_price between 50.00 and 100.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'S' - and - cd_education_status = 'Advanced Degree' - and - ss_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('TX', 'IA', 'ID') - and ss_net_profit between 0 and 2000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('NY', 'MA', 'GA') - and ss_net_profit between 150 and 3000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('IN', 'AK', 'MS') - and ss_net_profit between 50 and 25000 - ) - ) -; - --- end template query48.tpl query 94 in stream 3 --- start template query51.tpl query 95 in stream 3 -WITH /* TPC-DS query51.tpl 0.46 */ web_v1 as ( -select - ws_item_sk item_sk, d_date, - sum(sum(ws_sales_price)) - over (partition by ws_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from web_sales - ,date_dim -where ws_sold_date_sk=d_date_sk - and d_month_seq between 1205 and 1205+11 - and ws_item_sk is not NULL -group by ws_item_sk, d_date), -store_v1 as ( -select - ss_item_sk item_sk, d_date, - sum(sum(ss_sales_price)) - over (partition by ss_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from store_sales - ,date_dim -where ss_sold_date_sk=d_date_sk - and d_month_seq between 1205 and 1205+11 - and ss_item_sk is not NULL -group by ss_item_sk, d_date) - select * -from (select item_sk - ,d_date - ,web_sales - ,store_sales - ,max(web_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) web_cumulative - ,max(store_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) store_cumulative - from (select case when web.item_sk is not null then web.item_sk else store.item_sk end item_sk - ,case when web.d_date is not null then web.d_date else store.d_date end d_date - ,web.cume_sales web_sales - ,store.cume_sales store_sales - from web_v1 web full outer join store_v1 store on (web.item_sk = store.item_sk - and web.d_date = store.d_date) - )x )y -where web_cumulative > store_cumulative -order by item_sk - ,d_date -limit 100; - --- end template query51.tpl query 95 in stream 3 --- start template query79.tpl query 96 in stream 3 -select /* TPC-DS query79.tpl 0.89 */ - c_last_name,c_first_name,substring(s_city,1,30),ss_ticket_number,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,store.s_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (household_demographics.hd_dep_count = 2 or household_demographics.hd_vehicle_count > -1) - and date_dim.d_dow = 1 - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_number_employees between 200 and 295 - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,store.s_city) ms,customer - where ss_customer_sk = c_customer_sk - order by c_last_name,c_first_name,substring(s_city,1,30), profit -limit 100; - --- end template query79.tpl query 96 in stream 3 --- start template query35a.tpl query 97 in stream 3 -select /* TPC-DS query35a.tpl 0.47 */ - ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - count(*) cnt1, - stddev_samp(cd_dep_count), - max(cd_dep_count), - avg(cd_dep_count), - cd_dep_employed_count, - count(*) cnt2, - stddev_samp(cd_dep_employed_count), - max(cd_dep_employed_count), - avg(cd_dep_employed_count), - cd_dep_college_count, - count(*) cnt3, - stddev_samp(cd_dep_college_count), - max(cd_dep_college_count), - avg(cd_dep_college_count) - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2000 and - d_qoy < 4) and - exists (select * from - (select ws_bill_customer_sk customsk - from web_sales,date_dim - where - ws_sold_date_sk = d_date_sk and - d_year = 2000 and - d_qoy < 4 - union all - select cs_ship_customer_sk customsk - from catalog_sales,date_dim - where - cs_sold_date_sk = d_date_sk and - d_year = 2000 and - d_qoy < 4)x - where x.customsk = c.c_customer_sk) - group by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - limit 100; - --- end template query35a.tpl query 97 in stream 3 --- start template query88.tpl query 98 in stream 3 -select /* TPC-DS query88.tpl 0.66 */ * -from - (select count(*) h8_30_to_9 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s1, - (select count(*) h9_to_9_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s2, - (select count(*) h9_30_to_10 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s3, - (select count(*) h10_to_10_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s4, - (select count(*) h10_30_to_11 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s5, - (select count(*) h11_to_11_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s6, - (select count(*) h11_30_to_12 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s7, - (select count(*) h12_to_12_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 12 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s8 -; - --- end template query88.tpl query 98 in stream 3 --- start template query49.tpl query 99 in stream 3 -select /* TPC-DS query49.tpl 0.48 */ channel, item, return_ratio, return_rank, currency_rank from - (select - 'web' as channel - ,web.item - ,web.return_ratio - ,web.return_rank - ,web.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select ws.ws_item_sk as item - ,(cast(sum(coalesce(wr.wr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(wr.wr_return_amt,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - web_sales ws left outer join web_returns wr - on (ws.ws_order_number = wr.wr_order_number and - ws.ws_item_sk = wr.wr_item_sk) - ,date_dim - where - wr.wr_return_amt > 10000 - and ws.ws_net_profit > 1 - and ws.ws_net_paid > 0 - and ws.ws_quantity > 0 - and ws_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 11 - group by ws.ws_item_sk - ) in_web - ) web - where - ( - web.return_rank <= 10 - or - web.currency_rank <= 10 - ) - union - select - 'catalog' as channel - ,catalog.item - ,catalog.return_ratio - ,catalog.return_rank - ,catalog.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select - cs.cs_item_sk as item - ,(cast(sum(coalesce(cr.cr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(cr.cr_return_amount,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - catalog_sales cs left outer join catalog_returns cr - on (cs.cs_order_number = cr.cr_order_number and - cs.cs_item_sk = cr.cr_item_sk) - ,date_dim - where - cr.cr_return_amount > 10000 - and cs.cs_net_profit > 1 - and cs.cs_net_paid > 0 - and cs.cs_quantity > 0 - and cs_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 11 - group by cs.cs_item_sk - ) in_cat - ) catalog - where - ( - catalog.return_rank <= 10 - or - catalog.currency_rank <=10 - ) - union - select - 'store' as channel - ,store.item - ,store.return_ratio - ,store.return_rank - ,store.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select sts.ss_item_sk as item - ,(cast(sum(coalesce(sr.sr_return_quantity,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(sr.sr_return_amt,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - store_sales sts left outer join store_returns sr - on (sts.ss_ticket_number = sr.sr_ticket_number and sts.ss_item_sk = sr.sr_item_sk) - ,date_dim - where - sr.sr_return_amt > 10000 - and sts.ss_net_profit > 1 - and sts.ss_net_paid > 0 - and sts.ss_quantity > 0 - and ss_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 11 - group by sts.ss_item_sk - ) in_store - ) store - where ( - store.return_rank <= 10 - or - store.currency_rank <= 10 - ) - ) - order by 1,4,5,2 - limit 100; - --- end template query49.tpl query 99 in stream 3 diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/10TB/queries/query_4.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/10TB/queries/query_4.sql deleted file mode 100644 index 9eb02e79..00000000 --- a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/10TB/queries/query_4.sql +++ /dev/null @@ -1,5027 +0,0 @@ --- start template query79.tpl query 1 in stream 4 -select /* TPC-DS query79.tpl 0.89 */ - c_last_name,c_first_name,substring(s_city,1,30),ss_ticket_number,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,store.s_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (household_demographics.hd_dep_count = 5 or household_demographics.hd_vehicle_count > 3) - and date_dim.d_dow = 1 - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_number_employees between 200 and 295 - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,store.s_city) ms,customer - where ss_customer_sk = c_customer_sk - order by c_last_name,c_first_name,substring(s_city,1,30), profit -limit 100; - --- end template query79.tpl query 1 in stream 4 --- start template query39.tpl query 2 in stream 4 -with /* TPC-DS query39.tpl 0.5 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =1998 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=1 - and inv2.d_moy=1+1 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; -with /* TPC-DS query39.tpl 0.5 part2 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =1998 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=1 - and inv2.d_moy=1+1 - and inv1.cov > 1.5 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; - --- end template query39.tpl query 2 in stream 4 --- start template query93.tpl query 3 in stream 4 -select /* TPC-DS query93.tpl 0.52 */ ss_customer_sk - ,sum(act_sales) sumsales - from (select ss_item_sk - ,ss_ticket_number - ,ss_customer_sk - ,case when sr_return_quantity is not null then (ss_quantity-sr_return_quantity)*ss_sales_price - else (ss_quantity*ss_sales_price) end act_sales - from store_sales left outer join store_returns on (sr_item_sk = ss_item_sk - and sr_ticket_number = ss_ticket_number) - ,reason - where sr_reason_sk = r_reason_sk - and r_reason_desc = 'reason 40') t - group by ss_customer_sk - order by sumsales, ss_customer_sk -limit 100; - --- end template query93.tpl query 3 in stream 4 --- start template query41.tpl query 4 in stream 4 -select /* TPC-DS query41.tpl 0.62 */ distinct(i_product_name) - from item i1 - where i_manufact_id between 989 and 989+40 - and (select count(*) as item_cnt - from item - where (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'blush' or i_color = 'brown') and - (i_units = 'Ton' or i_units = 'Dram') and - (i_size = 'small' or i_size = 'economy') - ) or - (i_category = 'Women' and - (i_color = 'smoke' or i_color = 'bisque') and - (i_units = 'Box' or i_units = 'Tsp') and - (i_size = 'N/A' or i_size = 'extra large') - ) or - (i_category = 'Men' and - (i_color = 'almond' or i_color = 'beige') and - (i_units = 'Dozen' or i_units = 'Gross') and - (i_size = 'large' or i_size = 'medium') - ) or - (i_category = 'Men' and - (i_color = 'chiffon' or i_color = 'rose') and - (i_units = 'N/A' or i_units = 'Gram') and - (i_size = 'small' or i_size = 'economy') - ))) or - (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'lace' or i_color = 'honeydew') and - (i_units = 'Carton' or i_units = 'Bunch') and - (i_size = 'small' or i_size = 'economy') - ) or - (i_category = 'Women' and - (i_color = 'saddle' or i_color = 'goldenrod') and - (i_units = 'Case' or i_units = 'Pound') and - (i_size = 'N/A' or i_size = 'extra large') - ) or - (i_category = 'Men' and - (i_color = 'midnight' or i_color = 'ivory') and - (i_units = 'Ounce' or i_units = 'Bundle') and - (i_size = 'large' or i_size = 'medium') - ) or - (i_category = 'Men' and - (i_color = 'snow' or i_color = 'sienna') and - (i_units = 'Oz' or i_units = 'Lb') and - (i_size = 'small' or i_size = 'economy') - )))) > 0 - order by i_product_name - limit 100; - --- end template query41.tpl query 4 in stream 4 --- start template query29.tpl query 5 in stream 4 -select /* TPC-DS query29.tpl 0.53 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,avg(ss_quantity) as store_sales_quantity - ,avg(sr_return_quantity) as store_returns_quantity - ,avg(cs_quantity) as catalog_sales_quantity - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 2000 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 4 + 3 - and d2.d_year = 2000 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_year in (2000,2000+1,2000+2) - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query29.tpl query 5 in stream 4 --- start template query32.tpl query 6 in stream 4 -select /* TPC-DS query32.tpl 0.7 */ sum(cs_ext_discount_amt) as "excess discount amount" -from - catalog_sales - ,item - ,date_dim -where -i_manufact_id = 48 -and i_item_sk = cs_item_sk -and d_date between '2001-01-18' and - dateadd(day,90,cast('2001-01-18' as date)) -and d_date_sk = cs_sold_date_sk -and cs_ext_discount_amt - > ( - select - 1.3 * avg(cs_ext_discount_amt) - from - catalog_sales - ,date_dim - where - cs_item_sk = i_item_sk - and d_date between '2001-01-18' and - dateadd(day,90,cast('2001-01-18' as date)) - and d_date_sk = cs_sold_date_sk - ) -limit 100; - --- end template query32.tpl query 6 in stream 4 --- start template query66.tpl query 7 in stream 4 -select /* TPC-DS query66.tpl 0.39 */ - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - ,sum(jan_sales) as jan_sales - ,sum(feb_sales) as feb_sales - ,sum(mar_sales) as mar_sales - ,sum(apr_sales) as apr_sales - ,sum(may_sales) as may_sales - ,sum(jun_sales) as jun_sales - ,sum(jul_sales) as jul_sales - ,sum(aug_sales) as aug_sales - ,sum(sep_sales) as sep_sales - ,sum(oct_sales) as oct_sales - ,sum(nov_sales) as nov_sales - ,sum(dec_sales) as dec_sales - ,sum(jan_sales/w_warehouse_sq_ft) as jan_sales_per_sq_foot - ,sum(feb_sales/w_warehouse_sq_ft) as feb_sales_per_sq_foot - ,sum(mar_sales/w_warehouse_sq_ft) as mar_sales_per_sq_foot - ,sum(apr_sales/w_warehouse_sq_ft) as apr_sales_per_sq_foot - ,sum(may_sales/w_warehouse_sq_ft) as may_sales_per_sq_foot - ,sum(jun_sales/w_warehouse_sq_ft) as jun_sales_per_sq_foot - ,sum(jul_sales/w_warehouse_sq_ft) as jul_sales_per_sq_foot - ,sum(aug_sales/w_warehouse_sq_ft) as aug_sales_per_sq_foot - ,sum(sep_sales/w_warehouse_sq_ft) as sep_sales_per_sq_foot - ,sum(oct_sales/w_warehouse_sq_ft) as oct_sales_per_sq_foot - ,sum(nov_sales/w_warehouse_sq_ft) as nov_sales_per_sq_foot - ,sum(dec_sales/w_warehouse_sq_ft) as dec_sales_per_sq_foot - ,sum(jan_net) as jan_net - ,sum(feb_net) as feb_net - ,sum(mar_net) as mar_net - ,sum(apr_net) as apr_net - ,sum(may_net) as may_net - ,sum(jun_net) as jun_net - ,sum(jul_net) as jul_net - ,sum(aug_net) as aug_net - ,sum(sep_net) as sep_net - ,sum(oct_net) as oct_net - ,sum(nov_net) as nov_net - ,sum(dec_net) as dec_net - from ( - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'BOXBUNDLES' || ',' || 'DHL' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then ws_sales_price* ws_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then ws_sales_price* ws_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then ws_sales_price* ws_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then ws_sales_price* ws_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then ws_sales_price* ws_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then ws_sales_price* ws_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then ws_sales_price* ws_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then ws_sales_price* ws_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then ws_sales_price* ws_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then ws_sales_price* ws_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then ws_sales_price* ws_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then ws_sales_price* ws_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as dec_net - from - web_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - ws_warehouse_sk = w_warehouse_sk - and ws_sold_date_sk = d_date_sk - and ws_sold_time_sk = t_time_sk - and ws_ship_mode_sk = sm_ship_mode_sk - and d_year = 2001 - and t_time between 6623 and 6623+28800 - and sm_carrier in ('BOXBUNDLES','DHL') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - union all - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'BOXBUNDLES' || ',' || 'DHL' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then cs_ext_sales_price* cs_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then cs_ext_sales_price* cs_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then cs_ext_sales_price* cs_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then cs_ext_sales_price* cs_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then cs_ext_sales_price* cs_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then cs_ext_sales_price* cs_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then cs_ext_sales_price* cs_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then cs_ext_sales_price* cs_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then cs_ext_sales_price* cs_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then cs_ext_sales_price* cs_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then cs_ext_sales_price* cs_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then cs_ext_sales_price* cs_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as dec_net - from - catalog_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and cs_sold_time_sk = t_time_sk - and cs_ship_mode_sk = sm_ship_mode_sk - and d_year = 2001 - and t_time between 6623 AND 6623+28800 - and sm_carrier in ('BOXBUNDLES','DHL') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - ) x - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - order by w_warehouse_name - limit 100; - --- end template query66.tpl query 7 in stream 4 --- start template query84.tpl query 8 in stream 4 -select /* TPC-DS query84.tpl 0.80 */ c_customer_id as customer_id - , coalesce(c_last_name,'') || ', ' || coalesce(c_first_name,'') as customername - from customer - ,customer_address - ,customer_demographics - ,household_demographics - ,income_band - ,store_returns - where ca_city = 'Fairfield' - and c_current_addr_sk = ca_address_sk - and ib_lower_bound >= 25899 - and ib_upper_bound <= 25899 + 50000 - and ib_income_band_sk = hd_income_band_sk - and cd_demo_sk = c_current_cdemo_sk - and hd_demo_sk = c_current_hdemo_sk - and sr_cdemo_sk = cd_demo_sk - order by c_customer_id - limit 100; - --- end template query84.tpl query 8 in stream 4 --- start template query8.tpl query 9 in stream 4 -select /* TPC-DS query8.tpl 0.63 */ s_store_name - ,sum(ss_net_profit) - from store_sales - ,date_dim - ,store, - (select ca_zip - from ( - SELECT substring(ca_zip,1,5) ca_zip - FROM customer_address - WHERE substring(ca_zip,1,5) IN ( - '58255','36652','11086','80037','52737','48814', - '36037','94098','79272','35919','23140', - '81735','11761','41499','67168','22978', - '18088','27714','14448','76557','82730', - '65344','62745','61147','79665','86460', - '66958','47606','60141','31776','91174', - '17420','79444','14591','72012','98988', - '40195','81960','93484','58932','57002', - '82477','78187','87612','96252','94046', - '30395','32364','62142','39046','86931', - '27382','80612','63362','94312','33451', - '12196','56335','79422','34776','23654', - '39290','53034','61946','11921','93465', - '80288','90248','47558','73995','82000', - '55356','69037','64767','15415','72545', - '57354','28045','16264','52804','40420', - '76527','11807','34105','90927','17685', - '15641','12539','39360','98519','22249', - '28834','47487','78549','88956','18192', - '43649','47034','61205','11246','34316', - '62534','11602','49331','61466','99701', - '82545','25856','62468','58319','41472', - '82891','62027','62065','18624','94296', - '88041','79582','95536','23543','18289', - '34151','51520','87895','87987','57447', - '51112','41301','59644','98515','73524', - '18986','68062','48773','24015','88722', - '21751','61820','11787','52971','41523', - '30614','93103','25393','55871','22128', - '82072','86719','99070','13274','37677', - '51825','42712','42128','36034','70023', - '91418','18034','76105','45508','67292', - '75957','62554','93257','98512','28447', - '65503','15829','84801','83242','28660', - '99074','54555','71998','68282','67335', - '43646','90835','20867','29164','20382', - '14750','18080','96199','73142','37226', - '63358','35562','39799','43266','47608', - '50028','33797','41792','45030','57573', - '98580','60170','92420','17218','73741', - '67305','68832','56619','54247','86129', - '61140','31730','31219','65339','51141', - '32788','41208','45439','64877','83337', - '85084','14763','28075','90489','76473', - '79135','35674','89186','63091','92371', - '84601','97249','21321','58530','65770', - '83768','25806','95313','52542','51660', - '17293','70783','95147','37986','69732', - '14040','23990','32209','11931','12897', - '26016','73066','49653','99192','45704', - '20245','35150','11262','11701','74353', - '13383','50341','39254','86847','95843', - '58849','74262','50448','68668','24990', - '11261','16594','61180','91842','21594', - '66811','20412','68741','60083','30717', - '69465','18475','49303','92239','52395', - '31472','77147','97779','15496','41498', - '88204','56729','86621','39843','15548', - '47796','86285','12347','67584','34637', - '17692','62178','61923','77211','70579', - '15516','80119','98143','16423','93724', - '37024','67557','64828','48147','52580', - '65317','11793','58734','78343','31273', - '42177','20509','59168','77283','72741', - '59509','20121','64387','48629','91371', - '97911','85210','41334','92673','26937', - '46145','40070','97780','23416','74098', - '86046','63603','62055','79750','85789', - '78470','32994','48581','17103','37745', - '74274','82348','74327','29689','60124', - '74850','12748','72704','89603','91341', - '13851','48726','57790','99337','25712', - '52745','89466','37555','51955','67473', - '25562','54558','58879','88501','21019', - '73668','18196','19314','23028','56743', - '41475','54237','80619','13940','75353', - '38216','40371','18248','22689','38730', - '39542','25531','32676','18380','28573', - '58078','14829','17126','36217','98936', - '49390','24467','25274','25878') - intersect - select ca_zip - from (SELECT substring(ca_zip,1,5) ca_zip,count(*) cnt - FROM customer_address, customer - WHERE ca_address_sk = c_current_addr_sk and - c_preferred_cust_flag='Y' - group by ca_zip - having count(*) > 10)A1)A2) V1 - where ss_store_sk = s_store_sk - and ss_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 2001 - and (substring(s_zip,1,2) = substring(V1.ca_zip,1,2)) - group by s_store_name - order by s_store_name - limit 100; - --- end template query8.tpl query 9 in stream 4 --- start template query71.tpl query 10 in stream 4 -select /* TPC-DS query71.tpl 0.72 */ i_brand_id brand_id, i_brand brand,t_hour,t_minute, - sum(ext_price) ext_price - from item, (select ws_ext_sales_price as ext_price, - ws_sold_date_sk as sold_date_sk, - ws_item_sk as sold_item_sk, - ws_sold_time_sk as time_sk - from web_sales,date_dim - where d_date_sk = ws_sold_date_sk - and d_moy=11 - and d_year=2002 - union all - select cs_ext_sales_price as ext_price, - cs_sold_date_sk as sold_date_sk, - cs_item_sk as sold_item_sk, - cs_sold_time_sk as time_sk - from catalog_sales,date_dim - where d_date_sk = cs_sold_date_sk - and d_moy=11 - and d_year=2002 - union all - select ss_ext_sales_price as ext_price, - ss_sold_date_sk as sold_date_sk, - ss_item_sk as sold_item_sk, - ss_sold_time_sk as time_sk - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - and d_moy=11 - and d_year=2002 - ) tmp,time_dim - where - sold_item_sk = i_item_sk - and i_manager_id=1 - and time_sk = t_time_sk - and (t_meal_time = 'breakfast' or t_meal_time = 'dinner') - group by i_brand, i_brand_id,t_hour,t_minute - order by ext_price desc, i_brand_id - ; - --- end template query71.tpl query 10 in stream 4 --- start template query45.tpl query 11 in stream 4 -select /* TPC-DS query45.tpl 0.18 */ ca_zip, ca_city, sum(ws_sales_price) - from web_sales, customer, customer_address, date_dim, item - where ws_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ws_item_sk = i_item_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', '85392', '85460', '80348', '81792') - or - i_item_id in (select i_item_id - from item - where i_item_sk in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29) - ) - ) - and ws_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 2001 - group by ca_zip, ca_city - order by ca_zip, ca_city - limit 100; - --- end template query45.tpl query 11 in stream 4 --- start template query89.tpl query 12 in stream 4 -select /* TPC-DS query89.tpl 0.56 */ * -from( -select i_category, i_class, i_brand, - s_store_name, s_company_name, - d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, s_store_name, s_company_name) - avg_monthly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - d_year in (2002) and - ((i_category in ('Jewelry','Music','Electronics') and - i_class in ('diamonds','rock','memory') - ) - or (i_category in ('Men','Home','Books') and - i_class in ('pants','glassware','history') - )) -group by i_category, i_class, i_brand, - s_store_name, s_company_name, d_moy) tmp1 -where case when (avg_monthly_sales <> 0) then (abs(sum_sales - avg_monthly_sales) / avg_monthly_sales) else null end > 0.1 -order by sum_sales - avg_monthly_sales, s_store_name -limit 100; - --- end template query89.tpl query 12 in stream 4 --- start template query91.tpl query 13 in stream 4 -select /* TPC-DS query91.tpl 0.13 */ - cc_call_center_id Call_Center, - cc_name Call_Center_Name, - cc_manager Manager, - sum(cr_net_loss) Returns_Loss -from - call_center, - catalog_returns, - date_dim, - customer, - customer_address, - customer_demographics, - household_demographics -where - cr_call_center_sk = cc_call_center_sk -and cr_returned_date_sk = d_date_sk -and cr_returning_customer_sk= c_customer_sk -and cd_demo_sk = c_current_cdemo_sk -and hd_demo_sk = c_current_hdemo_sk -and ca_address_sk = c_current_addr_sk -and d_year = 2001 -and d_moy = 11 -and ( (cd_marital_status = 'M' and cd_education_status = 'Unknown') - or(cd_marital_status = 'W' and cd_education_status = 'Advanced Degree')) -and hd_buy_potential like '501-1000%' -and ca_gmt_offset = -6 -group by cc_call_center_id,cc_name,cc_manager,cd_marital_status,cd_education_status -order by sum(cr_net_loss) desc; - --- end template query91.tpl query 13 in stream 4 --- start template query14a.tpl query 14 in stream 4 -with /* TPC-DS query14a.tpl 0.69 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1999 AND 1999 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1999 AND 1999 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1999 AND 1999 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as - (select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2) x) -, - results AS -(select channel, i_brand_id, i_class_id, i_category_id, sum(sales) sum_sales, sum(number_sales) number_sales - from ( - select 'store' channel, i_brand_id,i_class_id - ,i_category_id,sum(ss_quantity*ss_list_price) sales - , count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1999+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales) - union all - select 'catalog' channel, i_brand_id,i_class_id,i_category_id, sum(cs_quantity*cs_list_price) sales, count(*) number_sales - from catalog_sales - ,item - ,date_dim - where cs_item_sk in (select ss_item_sk from cross_items) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1999+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(cs_quantity*cs_list_price) > (select average_sales from avg_sales) - union all - select 'web' channel, i_brand_id,i_class_id,i_category_id, sum(ws_quantity*ws_list_price) sales , count(*) number_sales - from web_sales - ,item - ,date_dim - where ws_item_sk in (select ss_item_sk from cross_items) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1999+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ws_quantity*ws_list_price) > (select average_sales from avg_sales) - ) y - group by channel, i_brand_id,i_class_id,i_category_id) - - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales -from ( - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales from results - union - select channel, i_brand_id, i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id, i_class_id - union - select channel, i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id - union - select channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel - union - select null as channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results) z -order by channel, i_brand_id, i_class_id, i_category_id - limit 100; -with /* TPC-DS query14a.tpl 0.69 part2 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1999 AND 1999 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1999 AND 1999 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1999 AND 1999 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as -(select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2) x) - select this_year.channel ty_channel - ,this_year.i_brand_id ty_brand - ,this_year.i_class_id ty_class - ,this_year.i_category_id ty_category - ,this_year.sales ty_sales - ,this_year.number_sales ty_number_sales - ,last_year.channel ly_channel - ,last_year.i_brand_id ly_brand - ,last_year.i_class_id ly_class - ,last_year.i_category_id ly_category - ,last_year.sales ly_sales - ,last_year.number_sales ly_number_sales -from - (select 'store' channel, i_brand_id,i_class_id,i_category_id - ,sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1999 + 1 - and d_moy = 12 - and d_dom = 5) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) this_year, - (select 'store' channel, i_brand_id,i_class_id - ,i_category_id, sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1999 - and d_moy = 12 - and d_dom = 5) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) last_year - where this_year.i_brand_id= last_year.i_brand_id - and this_year.i_class_id = last_year.i_class_id - and this_year.i_category_id = last_year.i_category_id - order by this_year.channel, this_year.i_brand_id, this_year.i_class_id, this_year.i_category_id - limit 100; - --- end template query14a.tpl query 14 in stream 4 --- start template query46.tpl query 15 in stream 4 -select /* TPC-DS query46.tpl 0.23 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and (household_demographics.hd_dep_count = 4 or - household_demographics.hd_vehicle_count= 4) - and date_dim.d_dow in (6,0) - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_city in ('Red Hill','Harmony','Jamestown','Forest Hills','Wildwood') - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,ca_city) dn,customer,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - limit 100; - --- end template query46.tpl query 15 in stream 4 --- start template query58.tpl query 16 in stream 4 -with /* TPC-DS query58.tpl 0.19 */ ss_items as - (select i_item_id item_id - ,sum(ss_ext_sales_price) ss_item_rev - from store_sales - ,item - ,date_dim - where ss_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '2002-07-02')) - and ss_sold_date_sk = d_date_sk - group by i_item_id), - cs_items as - (select i_item_id item_id - ,sum(cs_ext_sales_price) cs_item_rev - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '2002-07-02')) - and cs_sold_date_sk = d_date_sk - group by i_item_id), - ws_items as - (select i_item_id item_id - ,sum(ws_ext_sales_price) ws_item_rev - from web_sales - ,item - ,date_dim - where ws_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq =(select d_week_seq - from date_dim - where d_date = '2002-07-02')) - and ws_sold_date_sk = d_date_sk - group by i_item_id) - select ss_items.item_id - ,ss_item_rev - ,ss_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ss_dev - ,cs_item_rev - ,cs_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 cs_dev - ,ws_item_rev - ,ws_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ws_dev - ,(ss_item_rev+cs_item_rev+ws_item_rev)/3 average - from ss_items,cs_items,ws_items - where ss_items.item_id=cs_items.item_id - and ss_items.item_id=ws_items.item_id - and ss_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - and ss_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and cs_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and cs_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and ws_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and ws_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - order by item_id - ,ss_item_rev - limit 100; - --- end template query58.tpl query 16 in stream 4 --- start template query48.tpl query 17 in stream 4 -select /* TPC-DS query48.tpl 0.74 */ sum (ss_quantity) - from store_sales, store, customer_demographics, customer_address, date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2002 - and - ( - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'W' - and - cd_education_status = 'Secondary' - and - ss_sales_price between 100.00 and 150.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'U' - and - cd_education_status = 'Unknown' - and - ss_sales_price between 50.00 and 100.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'S' - and - cd_education_status = '4 yr Degree' - and - ss_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('NC', 'CO', 'PA') - and ss_net_profit between 0 and 2000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('WA', 'NV', 'IA') - and ss_net_profit between 150 and 3000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('OR', 'SD', 'NE') - and ss_net_profit between 50 and 25000 - ) - ) -; - --- end template query48.tpl query 17 in stream 4 --- start template query59.tpl query 18 in stream 4 -with /* TPC-DS query59.tpl 0.30 */ wss as - (select d_week_seq, - ss_store_sk, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - group by d_week_seq,ss_store_sk - ) - select s_store_name1,s_store_id1,d_week_seq1 - ,sun_sales1/sun_sales2,mon_sales1/mon_sales2 - ,tue_sales1/tue_sales2,wed_sales1/wed_sales2,thu_sales1/thu_sales2 - ,fri_sales1/fri_sales2,sat_sales1/sat_sales2 - from - (select s_store_name s_store_name1,wss.d_week_seq d_week_seq1 - ,s_store_id s_store_id1,sun_sales sun_sales1 - ,mon_sales mon_sales1,tue_sales tue_sales1 - ,wed_sales wed_sales1,thu_sales thu_sales1 - ,fri_sales fri_sales1,sat_sales sat_sales1 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1193 and 1193 + 11) y, - (select s_store_name s_store_name2,wss.d_week_seq d_week_seq2 - ,s_store_id s_store_id2,sun_sales sun_sales2 - ,mon_sales mon_sales2,tue_sales tue_sales2 - ,wed_sales wed_sales2,thu_sales thu_sales2 - ,fri_sales fri_sales2,sat_sales sat_sales2 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1193+ 12 and 1193 + 23) x - where s_store_id1=s_store_id2 - and d_week_seq1=d_week_seq2-52 - order by s_store_name1,s_store_id1,d_week_seq1 -limit 100; - --- end template query59.tpl query 18 in stream 4 --- start template query2.tpl query 19 in stream 4 -with /* TPC-DS query2.tpl 0.84 */ wscs as - (select sold_date_sk - ,sales_price - from (select ws_sold_date_sk sold_date_sk - ,ws_ext_sales_price sales_price - from web_sales - union all - select cs_sold_date_sk sold_date_sk - ,cs_ext_sales_price sales_price - from catalog_sales)), - wswscs as - (select d_week_seq, - sum(case when (d_day_name='Sunday') then sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then sales_price else null end) sat_sales - from wscs - ,date_dim - where d_date_sk = sold_date_sk - group by d_week_seq) - select d_week_seq1 - ,round(sun_sales1/sun_sales2,2) - ,round(mon_sales1/mon_sales2,2) - ,round(tue_sales1/tue_sales2,2) - ,round(wed_sales1/wed_sales2,2) - ,round(thu_sales1/thu_sales2,2) - ,round(fri_sales1/fri_sales2,2) - ,round(sat_sales1/sat_sales2,2) - from - (select wswscs.d_week_seq d_week_seq1 - ,sun_sales sun_sales1 - ,mon_sales mon_sales1 - ,tue_sales tue_sales1 - ,wed_sales wed_sales1 - ,thu_sales thu_sales1 - ,fri_sales fri_sales1 - ,sat_sales sat_sales1 - from wswscs,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 1999) y, - (select wswscs.d_week_seq d_week_seq2 - ,sun_sales sun_sales2 - ,mon_sales mon_sales2 - ,tue_sales tue_sales2 - ,wed_sales wed_sales2 - ,thu_sales thu_sales2 - ,fri_sales fri_sales2 - ,sat_sales sat_sales2 - from wswscs - ,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 1999+1) z - where d_week_seq1=d_week_seq2-53 - order by d_week_seq1; - --- end template query2.tpl query 19 in stream 4 --- start template query83.tpl query 20 in stream 4 -with /* TPC-DS query83.tpl 0.96 */ sr_items as - (select i_item_id item_id, - sum(sr_return_quantity) sr_item_qty - from store_returns, - item, - date_dim - where sr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2001-04-06','2001-08-19','2001-11-16'))) - and sr_returned_date_sk = d_date_sk - group by i_item_id), - cr_items as - (select i_item_id item_id, - sum(cr_return_quantity) cr_item_qty - from catalog_returns, - item, - date_dim - where cr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2001-04-06','2001-08-19','2001-11-16'))) - and cr_returned_date_sk = d_date_sk - group by i_item_id), - wr_items as - (select i_item_id item_id, - sum(wr_return_quantity) wr_item_qty - from web_returns, - item, - date_dim - where wr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2001-04-06','2001-08-19','2001-11-16'))) - and wr_returned_date_sk = d_date_sk - group by i_item_id) - select sr_items.item_id - ,sr_item_qty - ,sr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 sr_dev - ,cr_item_qty - ,cr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 cr_dev - ,wr_item_qty - ,wr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 wr_dev - ,(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 average - from sr_items - ,cr_items - ,wr_items - where sr_items.item_id=cr_items.item_id - and sr_items.item_id=wr_items.item_id - order by sr_items.item_id - ,sr_item_qty - limit 100; - --- end template query83.tpl query 20 in stream 4 --- start template query21.tpl query 21 in stream 4 -select /* TPC-DS query21.tpl 0.14 */ * - from(select w_warehouse_name - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('1998-06-01' as date)) - then inv_quantity_on_hand - else 0 end) as inv_before - ,sum(case when (cast(d_date as date) >= cast ('1998-06-01' as date)) - then inv_quantity_on_hand - else 0 end) as inv_after - from inventory - ,warehouse - ,item - ,date_dim - where i_current_price between 0.99 and 1.49 - and i_item_sk = inv_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('1998-06-01' as date)) - and dateadd(day,30,cast ('1998-06-01' as date)) - group by w_warehouse_name, i_item_id) x - where (case when inv_before > 0 - then inv_after / inv_before - else null - end) between 2.0/3.0 and 3.0/2.0 - order by w_warehouse_name - ,i_item_id - limit 100; - --- end template query21.tpl query 21 in stream 4 --- start template query78.tpl query 22 in stream 4 -with /* TPC-DS query78.tpl 0.10 */ ws as - (select d_year AS ws_sold_year, ws_item_sk, - ws_bill_customer_sk ws_customer_sk, - sum(ws_quantity) ws_qty, - sum(ws_wholesale_cost) ws_wc, - sum(ws_sales_price) ws_sp - from web_sales - left join web_returns on wr_order_number=ws_order_number and ws_item_sk=wr_item_sk - join date_dim on ws_sold_date_sk = d_date_sk - where wr_order_number is null - group by d_year, ws_item_sk, ws_bill_customer_sk - ), -cs as - (select d_year AS cs_sold_year, cs_item_sk, - cs_bill_customer_sk cs_customer_sk, - sum(cs_quantity) cs_qty, - sum(cs_wholesale_cost) cs_wc, - sum(cs_sales_price) cs_sp - from catalog_sales - left join catalog_returns on cr_order_number=cs_order_number and cs_item_sk=cr_item_sk - join date_dim on cs_sold_date_sk = d_date_sk - where cr_order_number is null - group by d_year, cs_item_sk, cs_bill_customer_sk - ), -ss as - (select d_year AS ss_sold_year, ss_item_sk, - ss_customer_sk, - sum(ss_quantity) ss_qty, - sum(ss_wholesale_cost) ss_wc, - sum(ss_sales_price) ss_sp - from store_sales - left join store_returns on sr_ticket_number=ss_ticket_number and ss_item_sk=sr_item_sk - join date_dim on ss_sold_date_sk = d_date_sk - where sr_ticket_number is null - group by d_year, ss_item_sk, ss_customer_sk - ) - select -ss_item_sk, -round(ss_qty/(coalesce(ws_qty,0)+coalesce(cs_qty,0)),2) ratio, -ss_qty store_qty, ss_wc store_wholesale_cost, ss_sp store_sales_price, -coalesce(ws_qty,0)+coalesce(cs_qty,0) other_chan_qty, -coalesce(ws_wc,0)+coalesce(cs_wc,0) other_chan_wholesale_cost, -coalesce(ws_sp,0)+coalesce(cs_sp,0) other_chan_sales_price -from ss -left join ws on (ws_sold_year=ss_sold_year and ws_item_sk=ss_item_sk and ws_customer_sk=ss_customer_sk) -left join cs on (cs_sold_year=ss_sold_year and cs_item_sk=ss_item_sk and cs_customer_sk=ss_customer_sk) -where (coalesce(ws_qty,0)>0 or coalesce(cs_qty, 0)>0) and ss_sold_year=1999 -order by - ss_item_sk, - ss_qty desc, ss_wc desc, ss_sp desc, - other_chan_qty, - other_chan_wholesale_cost, - other_chan_sales_price, - ratio -limit 100; - --- end template query78.tpl query 22 in stream 4 --- start template query40.tpl query 23 in stream 4 -select /* TPC-DS query40.tpl 0.86 */ - w_state - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('1999-02-05' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_before - ,sum(case when (cast(d_date as date) >= cast ('1999-02-05' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_after - from - catalog_sales left outer join catalog_returns on - (cs_order_number = cr_order_number - and cs_item_sk = cr_item_sk) - ,warehouse - ,item - ,date_dim - where - i_current_price between 0.99 and 1.49 - and i_item_sk = cs_item_sk - and cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('1999-02-05' as date)) - and dateadd(day,30,cast ('1999-02-05' as date)) - group by - w_state,i_item_id - order by w_state,i_item_id -limit 100; - --- end template query40.tpl query 23 in stream 4 --- start template query99.tpl query 24 in stream 4 -select /* TPC-DS query99.tpl 0.94 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 30) and - (cs_ship_date_sk - cs_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 60) and - (cs_ship_date_sk - cs_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 90) and - (cs_ship_date_sk - cs_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - catalog_sales - ,warehouse - ,ship_mode - ,call_center - ,date_dim -where - d_month_seq between 1188 and 1188 + 11 -and cs_ship_date_sk = d_date_sk -and cs_warehouse_sk = w_warehouse_sk -and cs_ship_mode_sk = sm_ship_mode_sk -and cs_call_center_sk = cc_call_center_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -limit 100; - --- end template query99.tpl query 24 in stream 4 --- start template query19.tpl query 25 in stream 4 -select /* TPC-DS query19.tpl 0.8 */ i_brand_id brand_id, i_brand brand, i_manufact_id, i_manufact, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item,customer,customer_address,store - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=7 - and d_moy=11 - and d_year=2001 - and ss_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and substring(ca_zip,1,5) <> substring(s_zip,1,5) - and ss_store_sk = s_store_sk - group by i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact - order by ext_price desc - ,i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact -limit 100 ; - --- end template query19.tpl query 25 in stream 4 --- start template query72.tpl query 26 in stream 4 -select /* TPC-DS query72.tpl 0.87 */ i_item_desc - ,w_warehouse_name - ,d1.d_week_seq - ,sum(case when p_promo_sk is null then 1 else 0 end) no_promo - ,sum(case when p_promo_sk is not null then 1 else 0 end) promo - ,count(*) total_cnt -from catalog_sales -join inventory on (cs_item_sk = inv_item_sk) -join warehouse on (w_warehouse_sk=inv_warehouse_sk) -join item on (i_item_sk = cs_item_sk) -join customer_demographics on (cs_bill_cdemo_sk = cd_demo_sk) -join household_demographics on (cs_bill_hdemo_sk = hd_demo_sk) -join date_dim d1 on (cs_sold_date_sk = d1.d_date_sk) -join date_dim d2 on (inv_date_sk = d2.d_date_sk) -join date_dim d3 on (cs_ship_date_sk = d3.d_date_sk) -left outer join promotion on (cs_promo_sk=p_promo_sk) -left outer join catalog_returns on (cr_item_sk = cs_item_sk and cr_order_number = cs_order_number) -where d1.d_week_seq = d2.d_week_seq - and inv_quantity_on_hand < cs_quantity - and d3.d_date > d1.d_date + 5 - and hd_buy_potential = '1001-5000' - and d1.d_year = 1998 - and cd_marital_status = 'U' -group by i_item_desc,w_warehouse_name,d1.d_week_seq -order by total_cnt desc, i_item_desc, w_warehouse_name, d_week_seq -limit 100; - --- end template query72.tpl query 26 in stream 4 --- start template query6.tpl query 27 in stream 4 -select /* TPC-DS query6.tpl 0.58 */ a.ca_state state, count(*) cnt - from customer_address a - ,customer c - ,store_sales s - ,date_dim d - ,item i - where a.ca_address_sk = c.c_current_addr_sk - and c.c_customer_sk = s.ss_customer_sk - and s.ss_sold_date_sk = d.d_date_sk - and s.ss_item_sk = i.i_item_sk - and d.d_month_seq = - (select distinct (d_month_seq) - from date_dim - where d_year = 2000 - and d_moy = 1 ) - and i.i_current_price > 1.2 * - (select avg(j.i_current_price) - from item j - where j.i_category = i.i_category) - group by a.ca_state - having count(*) >= 10 - order by cnt, a.ca_state - limit 100; - --- end template query6.tpl query 27 in stream 4 --- start template query28.tpl query 28 in stream 4 -select /* TPC-DS query28.tpl 0.36 */ * -from (select avg(ss_list_price) B1_LP - ,count(ss_list_price) B1_CNT - ,count(distinct ss_list_price) B1_CNTD - from store_sales - where ss_quantity between 0 and 5 - and (ss_list_price between 107 and 107+10 - or ss_coupon_amt between 2845 and 2845+1000 - or ss_wholesale_cost between 53 and 53+20)) B1, - (select avg(ss_list_price) B2_LP - ,count(ss_list_price) B2_CNT - ,count(distinct ss_list_price) B2_CNTD - from store_sales - where ss_quantity between 6 and 10 - and (ss_list_price between 145 and 145+10 - or ss_coupon_amt between 9720 and 9720+1000 - or ss_wholesale_cost between 2 and 2+20)) B2, - (select avg(ss_list_price) B3_LP - ,count(ss_list_price) B3_CNT - ,count(distinct ss_list_price) B3_CNTD - from store_sales - where ss_quantity between 11 and 15 - and (ss_list_price between 167 and 167+10 - or ss_coupon_amt between 3926 and 3926+1000 - or ss_wholesale_cost between 20 and 20+20)) B3, - (select avg(ss_list_price) B4_LP - ,count(ss_list_price) B4_CNT - ,count(distinct ss_list_price) B4_CNTD - from store_sales - where ss_quantity between 16 and 20 - and (ss_list_price between 74 and 74+10 - or ss_coupon_amt between 6100 and 6100+1000 - or ss_wholesale_cost between 16 and 16+20)) B4, - (select avg(ss_list_price) B5_LP - ,count(ss_list_price) B5_CNT - ,count(distinct ss_list_price) B5_CNTD - from store_sales - where ss_quantity between 21 and 25 - and (ss_list_price between 47 and 47+10 - or ss_coupon_amt between 5459 and 5459+1000 - or ss_wholesale_cost between 45 and 45+20)) B5, - (select avg(ss_list_price) B6_LP - ,count(ss_list_price) B6_CNT - ,count(distinct ss_list_price) B6_CNTD - from store_sales - where ss_quantity between 26 and 30 - and (ss_list_price between 93 and 93+10 - or ss_coupon_amt between 9793 and 9793+1000 - or ss_wholesale_cost between 60 and 60+20)) B6 -limit 100; - --- end template query28.tpl query 28 in stream 4 --- start template query81.tpl query 29 in stream 4 -with /* TPC-DS query81.tpl 0.37 */ customer_total_return as - (select cr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(cr_return_amt_inc_tax) as ctr_total_return - from catalog_returns - ,date_dim - ,customer_address - where cr_returned_date_sk = d_date_sk - and d_year =1999 - and cr_returning_addr_sk = ca_address_sk - group by cr_returning_customer_sk - ,ca_state ) - select c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'KS' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - limit 100; - --- end template query81.tpl query 29 in stream 4 --- start template query44.tpl query 30 in stream 4 -select /* TPC-DS query44.tpl 0.4 */ asceding.rnk, i1.i_product_name best_performing, i2.i_product_name worst_performing -from(select * - from (select item_sk,rank() over (order by rank_col asc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 555 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 555 - and ss_addr_sk is null - group by ss_store_sk))V1)V11 - where rnk < 11) asceding, - (select * - from (select item_sk,rank() over (order by rank_col desc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 555 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 555 - and ss_addr_sk is null - group by ss_store_sk))V2)V21 - where rnk < 11) descending, -item i1, -item i2 -where asceding.rnk = descending.rnk - and i1.i_item_sk=asceding.item_sk - and i2.i_item_sk=descending.item_sk -order by asceding.rnk -limit 100; - --- end template query44.tpl query 30 in stream 4 --- start template query97.tpl query 31 in stream 4 -with /* TPC-DS query97.tpl 0.38 */ ssci as ( -select ss_customer_sk customer_sk - ,ss_item_sk item_sk -from store_sales,date_dim -where ss_sold_date_sk = d_date_sk - and d_month_seq between 1177 and 1177 + 11 -group by ss_customer_sk - ,ss_item_sk), -csci as( - select cs_bill_customer_sk customer_sk - ,cs_item_sk item_sk -from catalog_sales,date_dim -where cs_sold_date_sk = d_date_sk - and d_month_seq between 1177 and 1177 + 11 -group by cs_bill_customer_sk - ,cs_item_sk) - select sum(case when ssci.customer_sk is not null and csci.customer_sk is null then 1 else 0 end) store_only - ,sum(case when ssci.customer_sk is null and csci.customer_sk is not null then 1 else 0 end) catalog_only - ,sum(case when ssci.customer_sk is not null and csci.customer_sk is not null then 1 else 0 end) store_and_catalog -from ssci full outer join csci on (ssci.customer_sk=csci.customer_sk - and ssci.item_sk = csci.item_sk) -limit 100; - --- end template query97.tpl query 31 in stream 4 --- start template query88.tpl query 32 in stream 4 -select /* TPC-DS query88.tpl 0.66 */ * -from - (select count(*) h8_30_to_9 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s1, - (select count(*) h9_to_9_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s2, - (select count(*) h9_30_to_10 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s3, - (select count(*) h10_to_10_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s4, - (select count(*) h10_30_to_11 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s5, - (select count(*) h11_to_11_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s6, - (select count(*) h11_30_to_12 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s7, - (select count(*) h12_to_12_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 12 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s8 -; - --- end template query88.tpl query 32 in stream 4 --- start template query77a.tpl query 33 in stream 4 -with /* TPC-DS query77a.tpl 0.78 */ ss as - (select s_store_sk, - sum(ss_ext_sales_price) as sales, - sum(ss_net_profit) as profit - from store_sales, - date_dim, - store - where ss_sold_date_sk = d_date_sk - and d_date between cast('1998-08-20' as date) - and dateadd(day,30,cast('1998-08-20' as date)) - and ss_store_sk = s_store_sk - group by s_store_sk) - , - sr as - (select s_store_sk, - sum(sr_return_amt) as returns, - sum(sr_net_loss) as profit_loss - from store_returns, - date_dim, - store - where sr_returned_date_sk = d_date_sk - and d_date between cast('1998-08-20' as date) - and dateadd(day,30,cast('1998-08-20' as date)) - and sr_store_sk = s_store_sk - group by s_store_sk), - cs as - (select cs_call_center_sk, - sum(cs_ext_sales_price) as sales, - sum(cs_net_profit) as profit - from catalog_sales, - date_dim - where cs_sold_date_sk = d_date_sk - and d_date between cast('1998-08-20' as date) - and dateadd(day,30,cast('1998-08-20' as date)) - group by cs_call_center_sk - ), - cr as - (select cr_call_center_sk, - sum(cr_return_amount) as returns, - sum(cr_net_loss) as profit_loss - from catalog_returns, - date_dim - where cr_returned_date_sk = d_date_sk - and d_date between cast('1998-08-20' as date) - and dateadd(day,30,cast('1998-08-20' as date)) - group by cr_call_center_sk), - ws as - ( select wp_web_page_sk, - sum(ws_ext_sales_price) as sales, - sum(ws_net_profit) as profit - from web_sales, - date_dim, - web_page - where ws_sold_date_sk = d_date_sk - and d_date between cast('1998-08-20' as date) - and dateadd(day,30,cast('1998-08-20' as date)) - and ws_web_page_sk = wp_web_page_sk - group by wp_web_page_sk), - wr as - (select wp_web_page_sk, - sum(wr_return_amt) as returns, - sum(wr_net_loss) as profit_loss - from web_returns, - date_dim, - web_page - where wr_returned_date_sk = d_date_sk - and d_date between cast('1998-08-20' as date) - and dateadd(day,30,cast('1998-08-20' as date)) - and wr_web_page_sk = wp_web_page_sk - group by wp_web_page_sk) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , ss.s_store_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ss left join sr - on ss.s_store_sk = sr.s_store_sk - union all - select 'catalog channel' as channel - , cs_call_center_sk as id - , sales - , returns - , (profit - profit_loss) as profit - from cs - , cr - union all - select 'web channel' as channel - , ws.wp_web_page_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ws left join wr - on ws.wp_web_page_sk = wr.wp_web_page_sk - ) x - group by channel, id ) - - select * - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results -) foo -order by channel, id - limit 100; - --- end template query77a.tpl query 33 in stream 4 --- start template query95.tpl query 34 in stream 4 -with /* TPC-DS query95.tpl 0.43 */ ws_wh as -(select ws1.ws_order_number,ws1.ws_warehouse_sk wh1,ws2.ws_warehouse_sk wh2 - from web_sales ws1,web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) - select - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2002-4-01' and - dateadd(day,60,cast('2002-4-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'TX' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and ws1.ws_order_number in (select ws_order_number - from ws_wh) -and ws1.ws_order_number in (select wr_order_number - from web_returns,ws_wh - where wr_order_number = ws_wh.ws_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query95.tpl query 34 in stream 4 --- start template query33.tpl query 35 in stream 4 -with /* TPC-DS query33.tpl 0.22 */ ss as ( - select - i_manufact_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Books')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 4 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id), - cs as ( - select - i_manufact_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Books')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 4 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id), - ws as ( - select - i_manufact_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Books')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 4 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id) - select i_manufact_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_manufact_id - order by total_sales -limit 100; - --- end template query33.tpl query 35 in stream 4 --- start template query36a.tpl query 36 in stream 4 -with /* TPC-DS query36a.tpl 0.21 */ results as - (select - sum(ss_net_profit) as ss_net_profit, sum(ss_ext_sales_price) as ss_ext_sales_price, - sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin - ,i_category - ,i_class - ,0 as g_category, 0 as g_class - from - store_sales - ,date_dim d1 - ,item - ,store - where - d1.d_year = 2001 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and s_state in ('SC','LA','MN','CO', - 'PA','IL','MN','WV') - group by i_category,i_class) - , - results_rollup as - (select gross_margin ,i_category ,i_class,0 as t_category, 0 as t_class, 0 as lochierarchy from results - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - i_category, NULL AS i_class, 0 as t_category, 1 as t_class, 1 as lochierarchy from results group by i_category - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - NULL AS i_category ,NULL AS i_class, 1 as t_category, 1 as t_class, 2 as lochierarchy from results) - select - gross_margin ,i_category ,i_class, lochierarchy,rank() over ( - partition by lochierarchy, case when t_class = 0 then i_category end - order by gross_margin asc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then i_category end - ,rank_within_parent - limit 100; - --- end template query36a.tpl query 36 in stream 4 --- start template query61.tpl query 37 in stream 4 -select /* TPC-DS query61.tpl 0.97 */ promotions,total,cast(promotions as decimal(15,4))/cast(total as decimal(15,4))*100 -from - (select sum(ss_ext_sales_price) promotions - from store_sales - ,store - ,promotion - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_promo_sk = p_promo_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -6 - and i_category = 'Electronics' - and (p_channel_dmail = 'Y' or p_channel_email = 'Y' or p_channel_tv = 'Y') - and s_gmt_offset = -6 - and d_year = 2002 - and d_moy = 12) promotional_sales, - (select sum(ss_ext_sales_price) total - from store_sales - ,store - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -6 - and i_category = 'Electronics' - and s_gmt_offset = -6 - and d_year = 2002 - and d_moy = 12) all_sales -order by promotions, total -limit 100; - --- end template query61.tpl query 37 in stream 4 --- start template query35a.tpl query 38 in stream 4 -select /* TPC-DS query35a.tpl 0.47 */ - ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - count(*) cnt1, - min(cd_dep_count), - stddev_samp(cd_dep_count), - stddev_samp(cd_dep_count), - cd_dep_employed_count, - count(*) cnt2, - min(cd_dep_employed_count), - stddev_samp(cd_dep_employed_count), - stddev_samp(cd_dep_employed_count), - cd_dep_college_count, - count(*) cnt3, - min(cd_dep_college_count), - stddev_samp(cd_dep_college_count), - stddev_samp(cd_dep_college_count) - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2000 and - d_qoy < 4) and - exists (select * from - (select ws_bill_customer_sk customsk - from web_sales,date_dim - where - ws_sold_date_sk = d_date_sk and - d_year = 2000 and - d_qoy < 4 - union all - select cs_ship_customer_sk customsk - from catalog_sales,date_dim - where - cs_sold_date_sk = d_date_sk and - d_year = 2000 and - d_qoy < 4)x - where x.customsk = c.c_customer_sk) - group by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - limit 100; - --- end template query35a.tpl query 38 in stream 4 --- start template query60.tpl query 39 in stream 4 -with /* TPC-DS query60.tpl 0.29 */ ss as ( - select - i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Jewelry')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 8 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - cs as ( - select - i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Jewelry')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 8 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - ws as ( - select - i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Jewelry')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 8 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id) - select - i_item_id -,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by i_item_id - ,total_sales - limit 100; - --- end template query60.tpl query 39 in stream 4 --- start template query75.tpl query 40 in stream 4 -WITH /* TPC-DS query75.tpl 0.3 */ all_sales AS ( - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,SUM(sales_cnt) AS sales_cnt - ,SUM(sales_amt) AS sales_amt - FROM (SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,cs_quantity - COALESCE(cr_return_quantity,0) AS sales_cnt - ,cs_ext_sales_price - COALESCE(cr_return_amount,0.0) AS sales_amt - FROM catalog_sales JOIN item ON i_item_sk=cs_item_sk - JOIN date_dim ON d_date_sk=cs_sold_date_sk - LEFT JOIN catalog_returns ON (cs_order_number=cr_order_number - AND cs_item_sk=cr_item_sk) - WHERE i_category='Children' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ss_quantity - COALESCE(sr_return_quantity,0) AS sales_cnt - ,ss_ext_sales_price - COALESCE(sr_return_amt,0.0) AS sales_amt - FROM store_sales JOIN item ON i_item_sk=ss_item_sk - JOIN date_dim ON d_date_sk=ss_sold_date_sk - LEFT JOIN store_returns ON (ss_ticket_number=sr_ticket_number - AND ss_item_sk=sr_item_sk) - WHERE i_category='Children' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ws_quantity - COALESCE(wr_return_quantity,0) AS sales_cnt - ,ws_ext_sales_price - COALESCE(wr_return_amt,0.0) AS sales_amt - FROM web_sales JOIN item ON i_item_sk=ws_item_sk - JOIN date_dim ON d_date_sk=ws_sold_date_sk - LEFT JOIN web_returns ON (ws_order_number=wr_order_number - AND ws_item_sk=wr_item_sk) - WHERE i_category='Children') sales_detail - GROUP BY d_year, i_brand_id, i_class_id, i_category_id, i_manufact_id) - SELECT prev_yr.d_year AS prev_year - ,curr_yr.d_year AS year - ,curr_yr.i_brand_id - ,curr_yr.i_class_id - ,curr_yr.i_category_id - ,curr_yr.i_manufact_id - ,prev_yr.sales_cnt AS prev_yr_cnt - ,curr_yr.sales_cnt AS curr_yr_cnt - ,curr_yr.sales_cnt-prev_yr.sales_cnt AS sales_cnt_diff - ,curr_yr.sales_amt-prev_yr.sales_amt AS sales_amt_diff - FROM all_sales curr_yr, all_sales prev_yr - WHERE curr_yr.i_brand_id=prev_yr.i_brand_id - AND curr_yr.i_class_id=prev_yr.i_class_id - AND curr_yr.i_category_id=prev_yr.i_category_id - AND curr_yr.i_manufact_id=prev_yr.i_manufact_id - AND curr_yr.d_year=1999 - AND prev_yr.d_year=1999-1 - AND CAST(curr_yr.sales_cnt AS DECIMAL(17,2))/CAST(prev_yr.sales_cnt AS DECIMAL(17,2))<0.9 - ORDER BY sales_cnt_diff,sales_amt_diff - limit 100; - --- end template query75.tpl query 40 in stream 4 --- start template query74.tpl query 41 in stream 4 -with /* TPC-DS query74.tpl 0.76 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,max(ss_net_paid) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (2000,2000+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,max(ws_net_paid) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - and d_year in (2000,2000+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - ) - select - t_s_secyear.customer_id, t_s_secyear.customer_first_name, t_s_secyear.customer_last_name - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.year = 2000 - and t_s_secyear.year = 2000+1 - and t_w_firstyear.year = 2000 - and t_w_secyear.year = 2000+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - order by 1,3,2 -limit 100; - --- end template query74.tpl query 41 in stream 4 --- start template query55.tpl query 42 in stream 4 -select /* TPC-DS query55.tpl 0.82 */ i_brand_id brand_id, i_brand brand, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=75 - and d_moy=11 - and d_year=1999 - group by i_brand, i_brand_id - order by ext_price desc, i_brand_id -limit 100 ; - --- end template query55.tpl query 42 in stream 4 --- start template query51.tpl query 43 in stream 4 -WITH /* TPC-DS query51.tpl 0.46 */ web_v1 as ( -select - ws_item_sk item_sk, d_date, - sum(sum(ws_sales_price)) - over (partition by ws_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from web_sales - ,date_dim -where ws_sold_date_sk=d_date_sk - and d_month_seq between 1210 and 1210+11 - and ws_item_sk is not NULL -group by ws_item_sk, d_date), -store_v1 as ( -select - ss_item_sk item_sk, d_date, - sum(sum(ss_sales_price)) - over (partition by ss_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from store_sales - ,date_dim -where ss_sold_date_sk=d_date_sk - and d_month_seq between 1210 and 1210+11 - and ss_item_sk is not NULL -group by ss_item_sk, d_date) - select * -from (select item_sk - ,d_date - ,web_sales - ,store_sales - ,max(web_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) web_cumulative - ,max(store_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) store_cumulative - from (select case when web.item_sk is not null then web.item_sk else store.item_sk end item_sk - ,case when web.d_date is not null then web.d_date else store.d_date end d_date - ,web.cume_sales web_sales - ,store.cume_sales store_sales - from web_v1 web full outer join store_v1 store on (web.item_sk = store.item_sk - and web.d_date = store.d_date) - )x )y -where web_cumulative > store_cumulative -order by item_sk - ,d_date -limit 100; - --- end template query51.tpl query 43 in stream 4 --- start template query17.tpl query 44 in stream 4 -select /* TPC-DS query17.tpl 0.41 */ i_item_id - ,i_item_desc - ,s_state - ,count(ss_quantity) as store_sales_quantitycount - ,avg(ss_quantity) as store_sales_quantityave - ,stddev_samp(ss_quantity) as store_sales_quantitystdev - ,stddev_samp(ss_quantity)/avg(ss_quantity) as store_sales_quantitycov - ,count(sr_return_quantity) as store_returns_quantitycount - ,avg(sr_return_quantity) as store_returns_quantityave - ,stddev_samp(sr_return_quantity) as store_returns_quantitystdev - ,stddev_samp(sr_return_quantity)/avg(sr_return_quantity) as store_returns_quantitycov - ,count(cs_quantity) as catalog_sales_quantitycount ,avg(cs_quantity) as catalog_sales_quantityave - ,stddev_samp(cs_quantity) as catalog_sales_quantitystdev - ,stddev_samp(cs_quantity)/avg(cs_quantity) as catalog_sales_quantitycov - from store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where d1.d_quarter_name = '2001Q1' - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_quarter_name in ('2001Q1','2001Q2','2001Q3') - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_quarter_name in ('2001Q1','2001Q2','2001Q3') - group by i_item_id - ,i_item_desc - ,s_state - order by i_item_id - ,i_item_desc - ,s_state -limit 100; - --- end template query17.tpl query 44 in stream 4 --- start template query52.tpl query 45 in stream 4 -select /* TPC-DS query52.tpl 0.59 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_sales_price) ext_price - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=12 - and dt.d_year=2002 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,ext_price desc - ,brand_id -limit 100 ; - --- end template query52.tpl query 45 in stream 4 --- start template query90.tpl query 46 in stream 4 -select /* TPC-DS query90.tpl 0.40 */ cast(amc as decimal(15,4))/cast(pmc as decimal(15,4)) am_pm_ratio - from ( select count(*) amc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 12 and 12+1 - and household_demographics.hd_dep_count = 8 - and web_page.wp_char_count between 5000 and 5200) at, - ( select count(*) pmc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 15 and 15+1 - and household_demographics.hd_dep_count = 8 - and web_page.wp_char_count between 5000 and 5200) pt - order by am_pm_ratio - limit 100; - --- end template query90.tpl query 46 in stream 4 --- start template query22a.tpl query 47 in stream 4 -with /* TPC-DS query22a.tpl 0.55 */ results as -(select i_product_name - ,i_brand - ,i_class - ,i_category - ,avg(inv_quantity_on_hand) qoh - from inventory - ,date_dim - ,item --- ,warehouse - where inv_date_sk=d_date_sk - and inv_item_sk=i_item_sk --- and inv_warehouse_sk = w_warehouse_sk - and d_month_seq between 1217 and 1217 + 11 - group by i_product_name,i_brand,i_class,i_category), -results_rollup as -(select i_product_name, i_brand, i_class, i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class,i_category -union all -select i_product_name, i_brand, i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class -union all -select i_product_name, i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand -union all -select i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name -union all -select null i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results) - select i_product_name, i_brand, i_class, i_category,qoh - from results_rollup - order by qoh, i_product_name, i_brand, i_class, i_category -limit 100; - --- end template query22a.tpl query 47 in stream 4 --- start template query27a.tpl query 48 in stream 4 -with /* TPC-DS query27a.tpl 0.16 */ results as - (select i_item_id, - s_state, 0 as g_state, - ss_quantity agg1, - ss_list_price agg2, - ss_coupon_amt agg3, - ss_sales_price agg4 - from store_sales, customer_demographics, date_dim, store, item - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_store_sk = s_store_sk and - ss_cdemo_sk = cd_demo_sk and - cd_gender = 'F' and - cd_marital_status = 'S' and - cd_education_status = 'Primary' and - d_year = 1999 and - s_state in ('FL','NC', 'MN', 'CO', 'MI', 'SC') - ) - - select i_item_id, - s_state, g_state, agg1, agg2, agg3, agg4 - from ( - select i_item_id, s_state, 0 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4 from results - group by i_item_id, s_state - union all - select i_item_id, NULL AS s_state, 1 AS g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as s_state, 1 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - ) foo - order by i_item_id, s_state - limit 100; - --- end template query27a.tpl query 48 in stream 4 --- start template query63.tpl query 49 in stream 4 -select /* TPC-DS query63.tpl 0.27 */ * -from (select i_manager_id - ,sum(ss_sales_price) sum_sales - ,avg(sum(ss_sales_price)) over (partition by i_manager_id) avg_monthly_sales - from item - ,store_sales - ,date_dim - ,store - where ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and d_month_seq in (1201,1201+1,1201+2,1201+3,1201+4,1201+5,1201+6,1201+7,1201+8,1201+9,1201+10,1201+11) - and (( i_category in ('Books','Children','Electronics') - and i_class in ('personal','portable','reference','self-help') - and i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) - or( i_category in ('Women','Music','Men') - and i_class in ('accessories','classical','fragrances','pants') - and i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manager_id, d_moy) tmp1 -where case when avg_monthly_sales > 0 then abs (sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 -order by i_manager_id - ,avg_monthly_sales - ,sum_sales -limit 100; - --- end template query63.tpl query 49 in stream 4 --- start template query38.tpl query 50 in stream 4 -select /* TPC-DS query38.tpl 0.54 */ count(*) from ( - select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1223 and 1223 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1223 and 1223 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1223 and 1223 + 11 -) hot_cust -limit 100; - --- end template query38.tpl query 50 in stream 4 --- start template query18a.tpl query 51 in stream 4 -with /* TPC-DS query18a.tpl 0.90 */ results as - (select i_item_id, - ca_country, - ca_state, - ca_county, - cast(cs_quantity as decimal(12,2)) agg1, - cast(cs_list_price as decimal(12,2)) agg2, - cast(cs_coupon_amt as decimal(12,2)) agg3, - cast(cs_sales_price as decimal(12,2)) agg4, - cast(cs_net_profit as decimal(12,2)) agg5, - cast(c_birth_year as decimal(12,2)) agg6, - cast(cd1.cd_dep_count as decimal(12,2)) agg7 - from catalog_sales, customer_demographics cd1, customer_demographics cd2, customer, customer_address, date_dim, item - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd1.cd_demo_sk and - cs_bill_customer_sk = c_customer_sk and - cd1.cd_gender = 'F' and - cd1.cd_education_status = 'Advanced Degree' and - c_current_cdemo_sk = cd2.cd_demo_sk and - c_current_addr_sk = ca_address_sk and - c_birth_month in (5,9,7,10,11,6) and - d_year = 2000 and - ca_state in ('NE','NY','TX','MS','GA','KY','NH') - ) - select i_item_id, ca_country, ca_state, ca_county, agg1, agg2, agg3, agg4, agg5, agg6, agg7 - from ( - select i_item_id, ca_country, ca_state, ca_county, avg(agg1) agg1, - avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state, ca_county - union all - select i_item_id, ca_country, ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state - union all - select i_item_id, ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country - union all - select i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - ) foo - order by ca_country, ca_state, ca_county, i_item_id - limit 100; - --- end template query18a.tpl query 51 in stream 4 --- start template query24.tpl query 52 in stream 4 -with /* TPC-DS query24.tpl 0.92 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_net_paid_inc_tax) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip -and s_market_id=8 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'drab' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; -with /* TPC-DS query24.tpl 0.92 part2 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_net_paid_inc_tax) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip - and s_market_id = 8 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'lemon' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; - --- end template query24.tpl query 52 in stream 4 --- start template query37.tpl query 53 in stream 4 -select /* TPC-DS query37.tpl 0.31 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, catalog_sales - where i_current_price between 44 and 44 + 30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('2002-05-02' as date) and dateadd(day,60,cast('2002-05-02' as date)) - and i_manufact_id in (806,759,948,993) - and inv_quantity_on_hand between 100 and 500 - and cs_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query37.tpl query 53 in stream 4 --- start template query47.tpl query 54 in stream 4 -with /* TPC-DS query47.tpl 0.42 */ v1 as( - select i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, - s_store_name, s_company_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - s_store_name, s_company_name - order by d_year, d_moy) rn - from item, store_sales, date_dim, store - where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - ( - d_year = 2001 or - ( d_year = 2001-1 and d_moy =12) or - ( d_year = 2001+1 and d_moy =1) - ) - group by i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy), - v2 as( - select v1.s_company_name - ,v1.d_year, v1.d_moy - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1.s_store_name = v1_lag.s_store_name and - v1.s_store_name = v1_lead.s_store_name and - v1.s_company_name = v1_lag.s_company_name and - v1.s_company_name = v1_lead.s_company_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 2001 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, psum - limit 100; - --- end template query47.tpl query 54 in stream 4 --- start template query10.tpl query 55 in stream 4 -select /* TPC-DS query10.tpl 0.26 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3, - cd_dep_count, - count(*) cnt4, - cd_dep_employed_count, - count(*) cnt5, - cd_dep_college_count, - count(*) cnt6 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_county in ('Perry County','Allamakee County','Otsego County','Hand County','Garvin County') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 3 and 3+3) and - (exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 3 ANd 3+3) or - exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 3 and 3+3)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count -limit 100; - --- end template query10.tpl query 55 in stream 4 --- start template query70a.tpl query 56 in stream 4 -with /* TPC-DS query70a.tpl 0.34 */ results as -( select - sum(ss_net_profit) as total_sum ,s_state ,s_county, 0 as gstate, 0 as g_county - from - store_sales - ,date_dim d1 - ,store - where - d1.d_month_seq between 1200 and 1200 + 11 - and d1.d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - and s_state in - ( select s_state - from (select s_state as s_state, - rank() over ( partition by s_state order by sum(ss_net_profit) desc) as ranking - from store_sales, store, date_dim - where d_month_seq between 1200 and 1200 + 11 - and d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - group by s_state - ) tmp1 - where ranking <= 5) - group by s_state,s_county) , - results_rollup as -(select total_sum ,s_state ,s_county, 0 as g_state, 0 as g_county, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum,s_state, NULL as s_county, 0 as g_state, 1 as g_county, 1 as lochierarchy from results group by s_state - union - select sum(total_sum) as total_sum ,NULL as s_state ,NULL as s_county, 1 as g_state, 1 as g_county, 2 as lochierarchy from results) - select total_sum ,s_state ,s_county, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_county = 0 then s_state end - order by total_sum desc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then s_state end - ,rank_within_parent - limit 100; - --- end template query70a.tpl query 56 in stream 4 --- start template query23.tpl query 57 in stream 4 -with /* TPC-DS query23.tpl 0.68 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (2000,2000+1,2000+2,2000+3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (2000,2000+1,2000+2,2000+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * -from - max_store_sales)) - select sum(sales) - from (select cs_quantity*cs_list_price sales - from catalog_sales - ,date_dim - where d_year = 2000 - and d_moy = 7 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - union all - select ws_quantity*ws_list_price sales - from web_sales - ,date_dim - where d_year = 2000 - and d_moy = 7 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer)) - limit 100; -with /* TPC-DS query23.tpl 0.68 part2 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (2000,2000 + 1,2000 + 2,2000 + 3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (2000,2000+1,2000+2,2000+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * - from max_store_sales)) - select c_last_name,c_first_name,sales - from (select c_last_name,c_first_name,sum(cs_quantity*cs_list_price) sales - from catalog_sales - ,customer - ,date_dim - where d_year = 2000 - and d_moy = 7 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and cs_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name - union all - select c_last_name,c_first_name,sum(ws_quantity*ws_list_price) sales - from web_sales - ,customer - ,date_dim - where d_year = 2000 - and d_moy = 7 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and ws_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name) - order by c_last_name,c_first_name,sales - limit 100; - --- end template query23.tpl query 57 in stream 4 --- start template query7.tpl query 58 in stream 4 -select /* TPC-DS query7.tpl 0.2 */ i_item_id, - avg(ss_quantity) agg1, - avg(ss_list_price) agg2, - avg(ss_coupon_amt) agg3, - avg(ss_sales_price) agg4 - from store_sales, customer_demographics, date_dim, item, promotion - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_cdemo_sk = cd_demo_sk and - ss_promo_sk = p_promo_sk and - cd_gender = 'M' and - cd_marital_status = 'U' and - cd_education_status = 'Advanced Degree' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 1998 - group by i_item_id - order by i_item_id - limit 100; - --- end template query7.tpl query 58 in stream 4 --- start template query92.tpl query 59 in stream 4 -select /* TPC-DS query92.tpl 0.44 */ - sum(ws_ext_discount_amt) as "Excess Discount Amount" -from - web_sales - ,item - ,date_dim -where -i_manufact_id = 664 -and i_item_sk = ws_item_sk -and d_date between '2000-01-16' and - dateadd(day,90,cast('2000-01-16' as date)) -and d_date_sk = ws_sold_date_sk -and ws_ext_discount_amt - > ( - SELECT - 1.3 * avg(ws_ext_discount_amt) - FROM - web_sales - ,date_dim - WHERE - ws_item_sk = i_item_sk - and d_date between '2000-01-16' and - dateadd(day,90,cast('2000-01-16' as date)) - and d_date_sk = ws_sold_date_sk - ) -order by sum(ws_ext_discount_amt) -limit 100; - --- end template query92.tpl query 59 in stream 4 --- start template query54.tpl query 60 in stream 4 -with /* TPC-DS query54.tpl 0.81 */ my_customers as ( - select distinct c_customer_sk - , c_current_addr_sk - from - ( select cs_sold_date_sk sold_date_sk, - cs_bill_customer_sk customer_sk, - cs_item_sk item_sk - from catalog_sales - union all - select ws_sold_date_sk sold_date_sk, - ws_bill_customer_sk customer_sk, - ws_item_sk item_sk - from web_sales - ) cs_or_ws_sales, - item, - date_dim, - customer - where sold_date_sk = d_date_sk - and item_sk = i_item_sk - and i_category = 'Music' - and i_class = 'pop' - and c_customer_sk = cs_or_ws_sales.customer_sk - and d_moy = 3 - and d_year = 2001 - ) - , my_revenue as ( - select c_customer_sk, - sum(ss_ext_sales_price) as revenue - from my_customers, - store_sales, - customer_address, - store, - date_dim - where c_current_addr_sk = ca_address_sk - and ca_county = s_county - and ca_state = s_state - and ss_sold_date_sk = d_date_sk - and c_customer_sk = ss_customer_sk - and d_month_seq between (select distinct d_month_seq+1 - from date_dim where d_year = 2001 and d_moy = 3) - and (select distinct d_month_seq+3 - from date_dim where d_year = 2001 and d_moy = 3) - group by c_customer_sk - ) - , segments as - (select cast((revenue/50) as int) as segment - from my_revenue - ) - select segment, count(*) as num_customers, segment*50 as segment_base - from segments - group by segment - order by segment, num_customers - limit 100; - --- end template query54.tpl query 60 in stream 4 --- start template query82.tpl query 61 in stream 4 -select /* TPC-DS query82.tpl 0.67 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, store_sales - where i_current_price between 24 and 24+30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('2001-05-03' as date) and dateadd(day,60,cast('2001-05-03' as date)) - and i_manufact_id in (425,892,229,481) - and inv_quantity_on_hand between 100 and 500 - and ss_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query82.tpl query 61 in stream 4 --- start template query76.tpl query 62 in stream 4 -select /* TPC-DS query76.tpl 0.99 */ channel, col_name, d_year, d_qoy, i_category, COUNT(*) sales_cnt, SUM(ext_sales_price) sales_amt FROM ( - SELECT 'store' as channel, 'ss_store_sk' col_name, d_year, d_qoy, i_category, ss_ext_sales_price ext_sales_price - FROM store_sales, item, date_dim - WHERE ss_store_sk IS NULL - AND ss_sold_date_sk=d_date_sk - AND ss_item_sk=i_item_sk - UNION ALL - SELECT 'web' as channel, 'ws_bill_customer_sk' col_name, d_year, d_qoy, i_category, ws_ext_sales_price ext_sales_price - FROM web_sales, item, date_dim - WHERE ws_bill_customer_sk IS NULL - AND ws_sold_date_sk=d_date_sk - AND ws_item_sk=i_item_sk - UNION ALL - SELECT 'catalog' as channel, 'cs_ship_cdemo_sk' col_name, d_year, d_qoy, i_category, cs_ext_sales_price ext_sales_price - FROM catalog_sales, item, date_dim - WHERE cs_ship_cdemo_sk IS NULL - AND cs_sold_date_sk=d_date_sk - AND cs_item_sk=i_item_sk) foo -GROUP BY channel, col_name, d_year, d_qoy, i_category -ORDER BY channel, col_name, d_year, d_qoy, i_category -limit 100; - --- end template query76.tpl query 62 in stream 4 --- start template query80a.tpl query 63 in stream 4 -with /* TPC-DS query80a.tpl 0.6 */ ssr as - (select s_store_id as store_id, - sum(ss_ext_sales_price) as sales, - sum(coalesce(sr_return_amt, 0)) as returns, - sum(ss_net_profit - coalesce(sr_net_loss, 0)) as profit - from store_sales left outer join store_returns on - (ss_item_sk = sr_item_sk and ss_ticket_number = sr_ticket_number), - date_dim, - store, - item, - promotion - where ss_sold_date_sk = d_date_sk - and d_date between cast('1999-08-05' as date) - and dateadd(day,30,cast('1999-08-05' as date)) - and ss_store_sk = s_store_sk - and ss_item_sk = i_item_sk - and i_current_price > 50 - and ss_promo_sk = p_promo_sk - and p_channel_tv = 'N' - group by s_store_id) - , - csr as - (select cp_catalog_page_id as catalog_page_id, - sum(cs_ext_sales_price) as sales, - sum(coalesce(cr_return_amount, 0)) as returns, - sum(cs_net_profit - coalesce(cr_net_loss, 0)) as profit - from catalog_sales left outer join catalog_returns on - (cs_item_sk = cr_item_sk and cs_order_number = cr_order_number), - date_dim, - catalog_page, - item, - promotion - where cs_sold_date_sk = d_date_sk - and d_date between cast('1999-08-05' as date) - and dateadd(day,30,cast('1999-08-05' as date)) - and cs_catalog_page_sk = cp_catalog_page_sk - and cs_item_sk = i_item_sk - and i_current_price > 50 - and cs_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(ws_ext_sales_price) as sales, - sum(coalesce(wr_return_amt, 0)) as returns, - sum(ws_net_profit - coalesce(wr_net_loss, 0)) as profit - from web_sales left outer join web_returns on - (ws_item_sk = wr_item_sk and ws_order_number = wr_order_number), - date_dim, - web_site, - item, - promotion - where ws_sold_date_sk = d_date_sk - and d_date between cast('1999-08-05' as date) - and dateadd(day,30,cast('1999-08-05' as date)) - and ws_web_site_sk = web_site_sk - and ws_item_sk = i_item_sk - and i_current_price > 50 - and ws_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by web_site_id) -, -results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || store_id as id - , sales - , returns - , profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || catalog_page_id as id - , sales - , returns - , profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , profit - from wsr - ) x - group by channel, id) - - select channel - , id - , sales - , returns - , profit - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results - ) foo - order by channel, id - limit 100; - --- end template query80a.tpl query 63 in stream 4 --- start template query56.tpl query 64 in stream 4 -with /* TPC-DS query56.tpl 0.83 */ ss as ( - select i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where i_item_id in (select - i_item_id -from item -where i_color in ('lime','grey','navy')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 5 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - cs as ( - select i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('lime','grey','navy')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 5 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - ws as ( - select i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('lime','grey','navy')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 5 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id) - select i_item_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by total_sales, - i_item_id - limit 100; - --- end template query56.tpl query 64 in stream 4 --- start template query96.tpl query 65 in stream 4 -select /* TPC-DS query96.tpl 0.1 */ count(*) -from store_sales - ,household_demographics - ,time_dim, store -where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and household_demographics.hd_dep_count = 4 - and store.s_store_name = 'ese' -order by count(*) -limit 100; - --- end template query96.tpl query 65 in stream 4 --- start template query50.tpl query 66 in stream 4 -select /* TPC-DS query50.tpl 0.60 */ - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 30) and - (sr_returned_date_sk - ss_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 60) and - (sr_returned_date_sk - ss_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 90) and - (sr_returned_date_sk - ss_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - store_sales - ,store_returns - ,store - ,date_dim d1 - ,date_dim d2 -where - d2.d_year = 2002 -and d2.d_moy = 8 -and ss_ticket_number = sr_ticket_number -and ss_item_sk = sr_item_sk -and ss_sold_date_sk = d1.d_date_sk -and sr_returned_date_sk = d2.d_date_sk -and ss_customer_sk = sr_customer_sk -and ss_store_sk = s_store_sk -group by - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -order by s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -limit 100; - --- end template query50.tpl query 66 in stream 4 --- start template query85.tpl query 67 in stream 4 -select /* TPC-DS query85.tpl 0.33 */ substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) - from web_sales, web_returns, web_page, customer_demographics cd1, - customer_demographics cd2, customer_address, date_dim, reason - where ws_web_page_sk = wp_web_page_sk - and ws_item_sk = wr_item_sk - and ws_order_number = wr_order_number - and ws_sold_date_sk = d_date_sk and d_year = 2002 - and cd1.cd_demo_sk = wr_refunded_cdemo_sk - and cd2.cd_demo_sk = wr_returning_cdemo_sk - and ca_address_sk = wr_refunded_addr_sk - and r_reason_sk = wr_reason_sk - and - ( - ( - cd1.cd_marital_status = 'S' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'College' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 100.00 and 150.00 - ) - or - ( - cd1.cd_marital_status = 'U' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = '4 yr Degree' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 50.00 and 100.00 - ) - or - ( - cd1.cd_marital_status = 'W' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Unknown' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ca_country = 'United States' - and - ca_state in ('MI', 'OR', 'KY') - and ws_net_profit between 100 and 200 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('GA', 'MO', 'VA') - and ws_net_profit between 150 and 300 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('NE', 'MA', 'NC') - and ws_net_profit between 50 and 250 - ) - ) -group by r_reason_desc -order by substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) -limit 100; - --- end template query85.tpl query 67 in stream 4 --- start template query86a.tpl query 68 in stream 4 -with /* TPC-DS query86a.tpl 0.11 */ results as -( select sum(ws_net_paid) as total_sum, i_category, i_class, 0 as g_category, 0 as g_class - from - web_sales - ,date_dim d1 - ,item - where - d1.d_month_seq between 1211 and 1211+11 - and d1.d_date_sk = ws_sold_date_sk - and i_item_sk = ws_item_sk - group by i_category,i_class - ) , - - results_rollup as -( select total_sum ,i_category ,i_class, g_category, g_class, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum, i_category, NULL as i_class, 0 as g_category, 1 as g_class, 1 as lochierarchy from results group by i_category - union - select sum(total_sum) as total_sum, NULL as i_category, NULL as i_class, 1 as g_category, 1 as g_class, 2 as lochierarchy from results) - select - total_sum ,i_category ,i_class, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_class = 0 then i_category end - order by total_sum desc) as rank_within_parent - from - results_rollup - order by - lochierarchy desc, - case when lochierarchy = 0 then i_category end, - rank_within_parent - limit 100; - --- end template query86a.tpl query 68 in stream 4 --- start template query69.tpl query 69 in stream 4 -select /* TPC-DS query69.tpl 0.28 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_state in ('SD','UT','CO') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2003 and - d_moy between 2 and 2+2) and - (not exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2003 and - d_moy between 2 and 2+2) and - not exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2003 and - d_moy between 2 and 2+2)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - limit 100; - --- end template query69.tpl query 69 in stream 4 --- start template query68.tpl query 70 in stream 4 -select /* TPC-DS query68.tpl 0.95 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,extended_price - ,extended_tax - ,list_price - from (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_ext_sales_price) extended_price - ,sum(ss_ext_list_price) list_price - ,sum(ss_ext_tax) extended_tax - from store_sales - ,date_dim - ,store - ,household_demographics - ,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_dep_count = 2 or - household_demographics.hd_vehicle_count= -1) - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_city in ('Lakeside','Pleasant Valley') - group by ss_ticket_number - ,ss_customer_sk - ,ss_addr_sk,ca_city) dn - ,customer - ,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,ss_ticket_number - limit 100; - --- end template query68.tpl query 70 in stream 4 --- start template query1.tpl query 71 in stream 4 -with /* TPC-DS query1.tpl 0.12 */ customer_total_return as -(select sr_customer_sk as ctr_customer_sk -,sr_store_sk as ctr_store_sk -,sum(SR_STORE_CREDIT) as ctr_total_return -from store_returns -,date_dim -where sr_returned_date_sk = d_date_sk -and d_year =2000 -group by sr_customer_sk -,sr_store_sk) - select c_customer_id -from customer_total_return ctr1 -,store -,customer -where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 -from customer_total_return ctr2 -where ctr1.ctr_store_sk = ctr2.ctr_store_sk) -and s_store_sk = ctr1.ctr_store_sk -and s_state = 'NE' -and ctr1.ctr_customer_sk = c_customer_sk -order by c_customer_id -limit 100; - --- end template query1.tpl query 71 in stream 4 --- start template query12.tpl query 72 in stream 4 -select /* TPC-DS query12.tpl 0.64 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ws_ext_sales_price) as itemrevenue - ,sum(ws_ext_sales_price)*100/sum(sum(ws_ext_sales_price)) over - (partition by i_class) as revenueratio -from - web_sales - ,item - ,date_dim -where - ws_item_sk = i_item_sk - and i_category in ('Sports', 'Men', 'Home') - and ws_sold_date_sk = d_date_sk - and d_date between cast('2000-02-17' as date) - and dateadd(day,30,cast('2000-02-17' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query12.tpl query 72 in stream 4 --- start template query43.tpl query 73 in stream 4 -select /* TPC-DS query43.tpl 0.15 */ s_store_name, s_store_id, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from date_dim, store_sales, store - where d_date_sk = ss_sold_date_sk and - s_store_sk = ss_store_sk and - s_gmt_offset = -6 and - d_year = 2002 - group by s_store_name, s_store_id - order by s_store_name, s_store_id,sun_sales,mon_sales,tue_sales,wed_sales,thu_sales,fri_sales,sat_sales - limit 100; - --- end template query43.tpl query 73 in stream 4 --- start template query16.tpl query 74 in stream 4 -select /* TPC-DS query16.tpl 0.25 */ - count(distinct cs_order_number) as "order count" - ,sum(cs_ext_ship_cost) as "total shipping cost" - ,sum(cs_net_profit) as "total net profit" -from - catalog_sales cs1 - ,date_dim - ,customer_address - ,call_center -where - d_date between '2001-5-01' and - dateadd(day, 60, cast('2001-5-01' as date)) -and cs1.cs_ship_date_sk = d_date_sk -and cs1.cs_ship_addr_sk = ca_address_sk -and ca_state = 'NJ' -and cs1.cs_call_center_sk = cc_call_center_sk -and cc_county in ('Mobile County','Jefferson Davis Parish','Raleigh County','Jackson County', - 'Wadena County' -) -and exists (select * - from catalog_sales cs2 - where cs1.cs_order_number = cs2.cs_order_number - and cs1.cs_warehouse_sk <> cs2.cs_warehouse_sk) -and not exists(select * - from catalog_returns cr1 - where cs1.cs_order_number = cr1.cr_order_number) -order by count(distinct cs_order_number) -limit 100; - --- end template query16.tpl query 74 in stream 4 --- start template query4.tpl query 75 in stream 4 -with /* TPC-DS query4.tpl 0.93 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(((ss_ext_list_price-ss_ext_wholesale_cost-ss_ext_discount_amt)+ss_ext_sales_price)/2) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((cs_ext_list_price-cs_ext_wholesale_cost-cs_ext_discount_amt)+cs_ext_sales_price)/2) ) year_total - ,'c' sale_type - from customer - ,catalog_sales - ,date_dim - where c_customer_sk = cs_bill_customer_sk - and cs_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year -union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((ws_ext_list_price-ws_ext_wholesale_cost-ws_ext_discount_amt)+ws_ext_sales_price)/2) ) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_preferred_cust_flag - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_c_firstyear - ,year_total t_c_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_c_secyear.customer_id - and t_s_firstyear.customer_id = t_c_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_c_firstyear.sale_type = 'c' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_c_secyear.sale_type = 'c' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 2001 - and t_s_secyear.dyear = 2001+1 - and t_c_firstyear.dyear = 2001 - and t_c_secyear.dyear = 2001+1 - and t_w_firstyear.dyear = 2001 - and t_w_secyear.dyear = 2001+1 - and t_s_firstyear.year_total > 0 - and t_c_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_preferred_cust_flag -limit 100; - --- end template query4.tpl query 75 in stream 4 --- start template query25.tpl query 76 in stream 4 -select /* TPC-DS query25.tpl 0.9 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,avg(ss_net_profit) as store_sales_profit - ,avg(sr_net_loss) as store_returns_loss - ,avg(cs_net_profit) as catalog_sales_profit - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 1999 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 10 - and d2.d_year = 1999 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_moy between 4 and 10 - and d3.d_year = 1999 - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query25.tpl query 76 in stream 4 --- start template query20.tpl query 77 in stream 4 -select /* TPC-DS query20.tpl 0.65 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(cs_ext_sales_price) as itemrevenue - ,sum(cs_ext_sales_price)*100/sum(sum(cs_ext_sales_price)) over - (partition by i_class) as revenueratio - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and i_category in ('Electronics', 'Children', 'Home') - and cs_sold_date_sk = d_date_sk - and d_date between cast('2000-06-12' as date) - and dateadd(day,30,cast('2000-06-12' as date)) - group by i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - order by i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query20.tpl query 77 in stream 4 --- start template query65.tpl query 78 in stream 4 -select /* TPC-DS query65.tpl 0.71 */ - s_store_name, - i_item_desc, - sc.revenue, - i_current_price, - i_wholesale_cost, - i_brand - from store, item, - (select ss_store_sk, avg(revenue) as ave - from - (select ss_store_sk, ss_item_sk, - sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1200 and 1200+11 - group by ss_store_sk, ss_item_sk) sa - group by ss_store_sk) sb, - (select ss_store_sk, ss_item_sk, sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1200 and 1200+11 - group by ss_store_sk, ss_item_sk) sc - where sb.ss_store_sk = sc.ss_store_sk and - sc.revenue <= 0.1 * sb.ave and - s_store_sk = sc.ss_store_sk and - i_item_sk = sc.ss_item_sk - order by s_store_name, i_item_desc -limit 100; - --- end template query65.tpl query 78 in stream 4 --- start template query15.tpl query 79 in stream 4 -select /* TPC-DS query15.tpl 0.57 */ ca_zip - ,sum(cs_sales_price) - from catalog_sales - ,customer - ,customer_address - ,date_dim - where cs_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', - '85392', '85460', '80348', '81792') - or ca_state in ('CA','WA','GA') - or cs_sales_price > 500) - and cs_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 1998 - group by ca_zip - order by ca_zip - limit 100; - --- end template query15.tpl query 79 in stream 4 --- start template query98.tpl query 80 in stream 4 -select /* TPC-DS query98.tpl 0.32 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ss_ext_sales_price) as itemrevenue - ,sum(ss_ext_sales_price)*100/sum(sum(ss_ext_sales_price)) over - (partition by i_class) as revenueratio -from - store_sales - ,item - ,date_dim -where - ss_item_sk = i_item_sk - and i_category in ('Home', 'Sports', 'Jewelry') - and ss_sold_date_sk = d_date_sk - and d_date between cast('1998-03-06' as date) - and dateadd(day,30,cast('1998-03-06' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio; - --- end template query98.tpl query 80 in stream 4 --- start template query42.tpl query 81 in stream 4 -select /* TPC-DS query42.tpl 0.61 */ dt.d_year - ,item.i_category_id - ,item.i_category - ,sum(ss_ext_sales_price) - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=11 - and dt.d_year=2000 - group by dt.d_year - ,item.i_category_id - ,item.i_category - order by sum(ss_ext_sales_price) desc,dt.d_year - ,item.i_category_id - ,item.i_category -limit 100 ; - --- end template query42.tpl query 81 in stream 4 --- start template query26.tpl query 82 in stream 4 -select /* TPC-DS query26.tpl 0.85 */ i_item_id, - avg(cs_quantity) agg1, - avg(cs_list_price) agg2, - avg(cs_coupon_amt) agg3, - avg(cs_sales_price) agg4 - from catalog_sales, customer_demographics, date_dim, item, promotion - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd_demo_sk and - cs_promo_sk = p_promo_sk and - cd_gender = 'F' and - cd_marital_status = 'M' and - cd_education_status = 'Advanced Degree' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 2001 - group by i_item_id - order by i_item_id - limit 100; - --- end template query26.tpl query 82 in stream 4 --- start template query34.tpl query 83 in stream 4 -select /* TPC-DS query34.tpl 0.73 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (date_dim.d_dom between 1 and 3 or date_dim.d_dom between 25 and 28) - and (household_demographics.hd_buy_potential = '501-1000' or - household_demographics.hd_buy_potential = '0-500') - and household_demographics.hd_vehicle_count > 0 - and (case when household_demographics.hd_vehicle_count > 0 - then household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count - else null - end) > 1.2 - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_county in ('Bronx County','Mesa County','Salem County','Maverick County', - 'Harmon County','Luce County','Huron County','Terry County') - group by ss_ticket_number,ss_customer_sk) dn,customer - where ss_customer_sk = c_customer_sk - and cnt between 15 and 20 - order by c_last_name,c_first_name,c_salutation,c_preferred_cust_flag desc, ss_ticket_number; - --- end template query34.tpl query 83 in stream 4 --- start template query5a.tpl query 84 in stream 4 -with /* TPC-DS query5a.tpl 0.98 */ ssr as - (select s_store_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ss_store_sk as store_sk, - ss_sold_date_sk as date_sk, - ss_ext_sales_price as sales_price, - ss_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from store_sales - union all - select sr_store_sk as store_sk, - sr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - sr_return_amt as return_amt, - sr_net_loss as net_loss - from store_returns - ) salesreturns, - date_dim, - store - where date_sk = d_date_sk - and d_date between cast('1998-08-10' as date) - and dateadd(day,14,cast('1998-08-10' as date)) - and store_sk = s_store_sk - group by s_store_id) - , - csr as - (select cp_catalog_page_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select cs_catalog_page_sk as page_sk, - cs_sold_date_sk as date_sk, - cs_ext_sales_price as sales_price, - cs_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from catalog_sales - union all - select cr_catalog_page_sk as page_sk, - cr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - cr_return_amount as return_amt, - cr_net_loss as net_loss - from catalog_returns - ) salesreturns, - date_dim, - catalog_page - where date_sk = d_date_sk - and d_date between cast('1998-08-10' as date) - and dateadd(day,14,cast('1998-08-10' as date)) - and page_sk = cp_catalog_page_sk - group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ws_web_site_sk as wsr_web_site_sk, - ws_sold_date_sk as date_sk, - ws_ext_sales_price as sales_price, - ws_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from web_sales - union all - select ws_web_site_sk as wsr_web_site_sk, - wr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - wr_return_amt as return_amt, - wr_net_loss as net_loss - from web_returns left outer join web_sales on - ( wr_item_sk = ws_item_sk - and wr_order_number = ws_order_number) - ) salesreturns, - date_dim, - web_site - where date_sk = d_date_sk - and d_date between cast('1998-08-10' as date) - and dateadd(day,14,cast('1998-08-10' as date)) - and wsr_web_site_sk = web_site_sk - group by web_site_id) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || s_store_id as id - , sales - , returns - , (profit - profit_loss) as profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || cp_catalog_page_id as id - , sales - , returns - , (profit - profit_loss) as profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , (profit - profit_loss) as profit - from wsr - ) x - group by channel, id) - select channel, id, sales, returns, profit from ( - select channel, id, sales, returns, profit from results - union - select channel, null as id, sum(sales), sum(returns), sum(profit) from results group by channel - union - select null as channel, null as id, sum(sales), sum(returns), sum(profit) from results) foo -order by channel, id -limit 100; - --- end template query5a.tpl query 84 in stream 4 --- start template query87.tpl query 85 in stream 4 -select /* TPC-DS query87.tpl 0.77 */ count(*) -from ((select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1205 and 1205+11) - except - (select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1205 and 1205+11) - except - (select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1205 and 1205+11) -) cool_cust -; - --- end template query87.tpl query 85 in stream 4 --- start template query3.tpl query 86 in stream 4 -select /* TPC-DS query3.tpl 0.45 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_sales_price) sum_agg - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manufact_id = 556 - and dt.d_moy=12 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,sum_agg desc - ,brand_id - limit 100; - --- end template query3.tpl query 86 in stream 4 --- start template query64.tpl query 87 in stream 4 -with /* TPC-DS query64.tpl 0.20 */ cs_ui as - (select cs_item_sk - ,sum(cs_ext_list_price) as sale,sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit) as refund - from catalog_sales - ,catalog_returns - where cs_item_sk = cr_item_sk - and cs_order_number = cr_order_number - group by cs_item_sk - having sum(cs_ext_list_price)>2*sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit)), -cross_sales as - (select i_product_name product_name - ,i_item_sk item_sk - ,s_store_name store_name - ,s_zip store_zip - ,ad1.ca_street_number b_street_number - ,ad1.ca_street_name b_street_name - ,ad1.ca_city b_city - ,ad1.ca_zip b_zip - ,ad2.ca_street_number c_street_number - ,ad2.ca_street_name c_street_name - ,ad2.ca_city c_city - ,ad2.ca_zip c_zip - ,d1.d_year as syear - ,d2.d_year as fsyear - ,d3.d_year s2year - ,count(*) cnt - ,sum(ss_wholesale_cost) s1 - ,sum(ss_list_price) s2 - ,sum(ss_coupon_amt) s3 - FROM store_sales - ,store_returns - ,cs_ui - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,customer - ,customer_demographics cd1 - ,customer_demographics cd2 - ,promotion - ,household_demographics hd1 - ,household_demographics hd2 - ,customer_address ad1 - ,customer_address ad2 - ,income_band ib1 - ,income_band ib2 - ,item - WHERE ss_store_sk = s_store_sk AND - ss_sold_date_sk = d1.d_date_sk AND - ss_customer_sk = c_customer_sk AND - ss_cdemo_sk= cd1.cd_demo_sk AND - ss_hdemo_sk = hd1.hd_demo_sk AND - ss_addr_sk = ad1.ca_address_sk and - ss_item_sk = i_item_sk and - ss_item_sk = sr_item_sk and - ss_ticket_number = sr_ticket_number and - ss_item_sk = cs_ui.cs_item_sk and - c_current_cdemo_sk = cd2.cd_demo_sk AND - c_current_hdemo_sk = hd2.hd_demo_sk AND - c_current_addr_sk = ad2.ca_address_sk and - c_first_sales_date_sk = d2.d_date_sk and - c_first_shipto_date_sk = d3.d_date_sk and - ss_promo_sk = p_promo_sk and - hd1.hd_income_band_sk = ib1.ib_income_band_sk and - hd2.hd_income_band_sk = ib2.ib_income_band_sk and - cd1.cd_marital_status <> cd2.cd_marital_status and - i_color in ('blush','lemon','royal','chiffon','lace','lawn') and - i_current_price between 82 and 82 + 10 and - i_current_price between 82 + 1 and 82 + 15 -group by i_product_name - ,i_item_sk - ,s_store_name - ,s_zip - ,ad1.ca_street_number - ,ad1.ca_street_name - ,ad1.ca_city - ,ad1.ca_zip - ,ad2.ca_street_number - ,ad2.ca_street_name - ,ad2.ca_city - ,ad2.ca_zip - ,d1.d_year - ,d2.d_year - ,d3.d_year -) -select cs1.product_name - ,cs1.store_name - ,cs1.store_zip - ,cs1.b_street_number - ,cs1.b_street_name - ,cs1.b_city - ,cs1.b_zip - ,cs1.c_street_number - ,cs1.c_street_name - ,cs1.c_city - ,cs1.c_zip - ,cs1.syear - ,cs1.cnt - ,cs1.s1 as s11 - ,cs1.s2 as s21 - ,cs1.s3 as s31 - ,cs2.s1 as s12 - ,cs2.s2 as s22 - ,cs2.s3 as s32 - ,cs2.syear - ,cs2.cnt -from cross_sales cs1,cross_sales cs2 -where cs1.item_sk=cs2.item_sk and - cs1.syear = 2001 and - cs2.syear = 2001 + 1 and - cs2.cnt <= cs1.cnt and - cs1.store_name = cs2.store_name and - cs1.store_zip = cs2.store_zip -order by cs1.product_name - ,cs1.store_name - ,cs2.cnt - ,cs1.s1 - ,cs2.s1; - --- end template query64.tpl query 87 in stream 4 --- start template query31.tpl query 88 in stream 4 -with /* TPC-DS query31.tpl 0.50 */ ss as - (select ca_county,d_qoy, d_year,sum(ss_ext_sales_price) as store_sales - from store_sales,date_dim,customer_address - where ss_sold_date_sk = d_date_sk - and ss_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year), - ws as - (select ca_county,d_qoy, d_year,sum(ws_ext_sales_price) as web_sales - from web_sales,date_dim,customer_address - where ws_sold_date_sk = d_date_sk - and ws_bill_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year) - select - ss1.ca_county - ,ss1.d_year - ,ws2.web_sales/ws1.web_sales web_q1_q2_increase - ,ss2.store_sales/ss1.store_sales store_q1_q2_increase - ,ws3.web_sales/ws2.web_sales web_q2_q3_increase - ,ss3.store_sales/ss2.store_sales store_q2_q3_increase - from - ss ss1 - ,ss ss2 - ,ss ss3 - ,ws ws1 - ,ws ws2 - ,ws ws3 - where - ss1.d_qoy = 1 - and ss1.d_year = 2000 - and ss1.ca_county = ss2.ca_county - and ss2.d_qoy = 2 - and ss2.d_year = 2000 - and ss2.ca_county = ss3.ca_county - and ss3.d_qoy = 3 - and ss3.d_year = 2000 - and ss1.ca_county = ws1.ca_county - and ws1.d_qoy = 1 - and ws1.d_year = 2000 - and ws1.ca_county = ws2.ca_county - and ws2.d_qoy = 2 - and ws2.d_year = 2000 - and ws1.ca_county = ws3.ca_county - and ws3.d_qoy = 3 - and ws3.d_year =2000 - and case when ws1.web_sales > 0 then ws2.web_sales/ws1.web_sales else null end - > case when ss1.store_sales > 0 then ss2.store_sales/ss1.store_sales else null end - and case when ws2.web_sales > 0 then ws3.web_sales/ws2.web_sales else null end - > case when ss2.store_sales > 0 then ss3.store_sales/ss2.store_sales else null end - order by ss1.d_year; - --- end template query31.tpl query 88 in stream 4 --- start template query57.tpl query 89 in stream 4 -with /* TPC-DS query57.tpl 0.70 */ v1 as( - select i_category, i_brand, - cc_name, - d_year, d_moy, - sum(cs_sales_price) sum_sales, - avg(sum(cs_sales_price)) over - (partition by i_category, i_brand, - cc_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - cc_name - order by d_year, d_moy) rn - from item, catalog_sales, date_dim, call_center - where cs_item_sk = i_item_sk and - cs_sold_date_sk = d_date_sk and - cc_call_center_sk= cs_call_center_sk and - ( - d_year = 2000 or - ( d_year = 2000-1 and d_moy =12) or - ( d_year = 2000+1 and d_moy =1) - ) - group by i_category, i_brand, - cc_name , d_year, d_moy), - v2 as( - select v1.cc_name - ,v1.d_year - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1. cc_name = v1_lag. cc_name and - v1. cc_name = v1_lead. cc_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 2000 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, nsum - limit 100; - --- end template query57.tpl query 89 in stream 4 --- start template query30.tpl query 90 in stream 4 -with /* TPC-DS query30.tpl 0.75 */ customer_total_return as - (select wr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(wr_return_amt) as ctr_total_return - from web_returns - ,date_dim - ,customer_address - where wr_returned_date_sk = d_date_sk - and d_year =1999 - and wr_returning_addr_sk = ca_address_sk - group by wr_returning_customer_sk - ,ca_state) - select c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'CA' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return -limit 100; - --- end template query30.tpl query 90 in stream 4 --- start template query13.tpl query 91 in stream 4 -select /* TPC-DS query13.tpl 0.91 */ avg(ss_quantity) - ,avg(ss_ext_sales_price) - ,avg(ss_ext_wholesale_cost) - ,sum(ss_ext_wholesale_cost) - from store_sales - ,store - ,customer_demographics - ,household_demographics - ,customer_address - ,date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2001 - and((ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'W' - and cd_education_status = '2 yr Degree' - and ss_sales_price between 100.00 and 150.00 - and hd_dep_count = 3 - )or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'S' - and cd_education_status = 'Secondary' - and ss_sales_price between 50.00 and 100.00 - and hd_dep_count = 1 - ) or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'U' - and cd_education_status = 'Primary' - and ss_sales_price between 150.00 and 200.00 - and hd_dep_count = 1 - )) - and((ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('WI', 'MO', 'MN') - and ss_net_profit between 100 and 200 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('NV', 'HI', 'VA') - and ss_net_profit between 150 and 300 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('MT', 'OH', 'UT') - and ss_net_profit between 50 and 250 - )) -; - --- end template query13.tpl query 91 in stream 4 --- start template query94.tpl query 92 in stream 4 -select /* TPC-DS query94.tpl 0.17 */ - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2001-5-01' and - dateadd(day,60,cast('2001-5-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'WI' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and exists (select * - from web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) -and not exists(select * - from web_returns wr1 - where ws1.ws_order_number = wr1.wr_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query94.tpl query 92 in stream 4 --- start template query62.tpl query 93 in stream 4 -select /* TPC-DS query62.tpl 0.24 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 30) and - (ws_ship_date_sk - ws_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 60) and - (ws_ship_date_sk - ws_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 90) and - (ws_ship_date_sk - ws_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - web_sales - ,warehouse - ,ship_mode - ,web_site - ,date_dim -where - d_month_seq between 1177 and 1177 + 11 -and ws_ship_date_sk = d_date_sk -and ws_warehouse_sk = w_warehouse_sk -and ws_ship_mode_sk = sm_ship_mode_sk -and ws_web_site_sk = web_site_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -limit 100; - --- end template query62.tpl query 93 in stream 4 --- start template query49.tpl query 94 in stream 4 -select /* TPC-DS query49.tpl 0.48 */ channel, item, return_ratio, return_rank, currency_rank from - (select - 'web' as channel - ,web.item - ,web.return_ratio - ,web.return_rank - ,web.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select ws.ws_item_sk as item - ,(cast(sum(coalesce(wr.wr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(wr.wr_return_amt,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - web_sales ws left outer join web_returns wr - on (ws.ws_order_number = wr.wr_order_number and - ws.ws_item_sk = wr.wr_item_sk) - ,date_dim - where - wr.wr_return_amt > 10000 - and ws.ws_net_profit > 1 - and ws.ws_net_paid > 0 - and ws.ws_quantity > 0 - and ws_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 11 - group by ws.ws_item_sk - ) in_web - ) web - where - ( - web.return_rank <= 10 - or - web.currency_rank <= 10 - ) - union - select - 'catalog' as channel - ,catalog.item - ,catalog.return_ratio - ,catalog.return_rank - ,catalog.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select - cs.cs_item_sk as item - ,(cast(sum(coalesce(cr.cr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(cr.cr_return_amount,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - catalog_sales cs left outer join catalog_returns cr - on (cs.cs_order_number = cr.cr_order_number and - cs.cs_item_sk = cr.cr_item_sk) - ,date_dim - where - cr.cr_return_amount > 10000 - and cs.cs_net_profit > 1 - and cs.cs_net_paid > 0 - and cs.cs_quantity > 0 - and cs_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 11 - group by cs.cs_item_sk - ) in_cat - ) catalog - where - ( - catalog.return_rank <= 10 - or - catalog.currency_rank <=10 - ) - union - select - 'store' as channel - ,store.item - ,store.return_ratio - ,store.return_rank - ,store.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select sts.ss_item_sk as item - ,(cast(sum(coalesce(sr.sr_return_quantity,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(sr.sr_return_amt,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - store_sales sts left outer join store_returns sr - on (sts.ss_ticket_number = sr.sr_ticket_number and sts.ss_item_sk = sr.sr_item_sk) - ,date_dim - where - sr.sr_return_amt > 10000 - and sts.ss_net_profit > 1 - and sts.ss_net_paid > 0 - and sts.ss_quantity > 0 - and ss_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 11 - group by sts.ss_item_sk - ) in_store - ) store - where ( - store.return_rank <= 10 - or - store.currency_rank <= 10 - ) - ) - order by 1,4,5,2 - limit 100; - --- end template query49.tpl query 94 in stream 4 --- start template query11.tpl query 95 in stream 4 -with /* TPC-DS query11.tpl 0.51 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ss_ext_list_price-ss_ext_discount_amt) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ws_ext_list_price-ws_ext_discount_amt) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_birth_country - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 1998 - and t_s_secyear.dyear = 1998+1 - and t_w_firstyear.dyear = 1998 - and t_w_secyear.dyear = 1998+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else 0.0 end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else 0.0 end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_birth_country -limit 100; - --- end template query11.tpl query 95 in stream 4 --- start template query73.tpl query 96 in stream 4 -select /* TPC-DS query73.tpl 0.79 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_buy_potential = '>10000' or - household_demographics.hd_buy_potential = '0-500') - and household_demographics.hd_vehicle_count > 0 - and case when household_demographics.hd_vehicle_count > 0 then - household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count else null end > 1 - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_county in ('Harper County','Walker County','Kittitas County','Fairfield County') - group by ss_ticket_number,ss_customer_sk) dj,customer - where ss_customer_sk = c_customer_sk - and cnt between 1 and 5 - order by cnt desc, c_last_name asc; - --- end template query73.tpl query 96 in stream 4 --- start template query67a.tpl query 97 in stream 4 -with /* TPC-DS query67a.tpl 0.35 */ results as -( select i_category ,i_class ,i_brand ,i_product_name ,d_year ,d_qoy ,d_moy ,s_store_id - ,sum(coalesce(ss_sales_price*ss_quantity,0)) sumsales - from store_sales ,date_dim ,store ,item - where ss_sold_date_sk=d_date_sk - and ss_item_sk=i_item_sk - and ss_store_sk = s_store_sk - and d_month_seq between 1182 and 1182 + 11 - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy,s_store_id) - , - results_rollup as - (select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, s_store_id, sumsales - from results - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy - union all - select i_category, i_class, i_brand, i_product_name, d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year - union all - select i_category, i_class, i_brand, i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name - union all - select i_category, i_class, i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand - union all - select i_category, i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class - union all - select i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category - union all - select null i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results) - - select * -from (select i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rank() over (partition by i_category order by sumsales desc) rk - from results_rollup) dw2 -where rk <= 100 -order by i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rk -limit 100; - --- end template query67a.tpl query 97 in stream 4 --- start template query53.tpl query 98 in stream 4 -select /* TPC-DS query53.tpl 0.88 */ * from -(select i_manufact_id, -sum(ss_sales_price) sum_sales, -avg(sum(ss_sales_price)) over (partition by i_manufact_id) avg_quarterly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and -ss_sold_date_sk = d_date_sk and -ss_store_sk = s_store_sk and -d_month_seq in (1189,1189+1,1189+2,1189+3,1189+4,1189+5,1189+6,1189+7,1189+8,1189+9,1189+10,1189+11) and -((i_category in ('Books','Children','Electronics') and -i_class in ('personal','portable','reference','self-help') and -i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) -or(i_category in ('Women','Music','Men') and -i_class in ('accessories','classical','fragrances','pants') and -i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manufact_id, d_qoy ) tmp1 -where case when avg_quarterly_sales > 0 - then abs (sum_sales - avg_quarterly_sales)/ avg_quarterly_sales - else null end > 0.1 -order by avg_quarterly_sales, - sum_sales, - i_manufact_id -limit 100; - --- end template query53.tpl query 98 in stream 4 --- start template query9.tpl query 99 in stream 4 -select /* TPC-DS query9.tpl 0.49 */ case when (select count(*) - from store_sales - where ss_quantity between 1 and 20) > 63736023 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 1 and 20) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 1 and 20) end bucket1 , - case when (select count(*) - from store_sales - where ss_quantity between 21 and 40) > 118016562 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 21 and 40) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 21 and 40) end bucket2, - case when (select count(*) - from store_sales - where ss_quantity between 41 and 60) > 143037907 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 41 and 60) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 41 and 60) end bucket3, - case when (select count(*) - from store_sales - where ss_quantity between 61 and 80) > 64043924 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 61 and 80) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 61 and 80) end bucket4, - case when (select count(*) - from store_sales - where ss_quantity between 81 and 100) > 76593752 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 81 and 100) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 81 and 100) end bucket5 -from reason -where r_reason_sk = 1 -; - --- end template query9.tpl query 99 in stream 4 diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/10TB/queries/query_5.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/10TB/queries/query_5.sql deleted file mode 100644 index 99e7d844..00000000 --- a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/10TB/queries/query_5.sql +++ /dev/null @@ -1,5027 +0,0 @@ --- start template query73.tpl query 1 in stream 5 -select /* TPC-DS query73.tpl 0.79 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_buy_potential = '1001-5000' or - household_demographics.hd_buy_potential = 'Unknown') - and household_demographics.hd_vehicle_count > 0 - and case when household_demographics.hd_vehicle_count > 0 then - household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count else null end > 1 - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_county in ('Huron County','Essex County','San Miguel County','Wadena County') - group by ss_ticket_number,ss_customer_sk) dj,customer - where ss_customer_sk = c_customer_sk - and cnt between 1 and 5 - order by cnt desc, c_last_name asc; - --- end template query73.tpl query 1 in stream 5 --- start template query66.tpl query 2 in stream 5 -select /* TPC-DS query66.tpl 0.39 */ - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - ,sum(jan_sales) as jan_sales - ,sum(feb_sales) as feb_sales - ,sum(mar_sales) as mar_sales - ,sum(apr_sales) as apr_sales - ,sum(may_sales) as may_sales - ,sum(jun_sales) as jun_sales - ,sum(jul_sales) as jul_sales - ,sum(aug_sales) as aug_sales - ,sum(sep_sales) as sep_sales - ,sum(oct_sales) as oct_sales - ,sum(nov_sales) as nov_sales - ,sum(dec_sales) as dec_sales - ,sum(jan_sales/w_warehouse_sq_ft) as jan_sales_per_sq_foot - ,sum(feb_sales/w_warehouse_sq_ft) as feb_sales_per_sq_foot - ,sum(mar_sales/w_warehouse_sq_ft) as mar_sales_per_sq_foot - ,sum(apr_sales/w_warehouse_sq_ft) as apr_sales_per_sq_foot - ,sum(may_sales/w_warehouse_sq_ft) as may_sales_per_sq_foot - ,sum(jun_sales/w_warehouse_sq_ft) as jun_sales_per_sq_foot - ,sum(jul_sales/w_warehouse_sq_ft) as jul_sales_per_sq_foot - ,sum(aug_sales/w_warehouse_sq_ft) as aug_sales_per_sq_foot - ,sum(sep_sales/w_warehouse_sq_ft) as sep_sales_per_sq_foot - ,sum(oct_sales/w_warehouse_sq_ft) as oct_sales_per_sq_foot - ,sum(nov_sales/w_warehouse_sq_ft) as nov_sales_per_sq_foot - ,sum(dec_sales/w_warehouse_sq_ft) as dec_sales_per_sq_foot - ,sum(jan_net) as jan_net - ,sum(feb_net) as feb_net - ,sum(mar_net) as mar_net - ,sum(apr_net) as apr_net - ,sum(may_net) as may_net - ,sum(jun_net) as jun_net - ,sum(jul_net) as jul_net - ,sum(aug_net) as aug_net - ,sum(sep_net) as sep_net - ,sum(oct_net) as oct_net - ,sum(nov_net) as nov_net - ,sum(dec_net) as dec_net - from ( - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'FEDEX' || ',' || 'ZHOU' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then ws_ext_list_price* ws_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then ws_ext_list_price* ws_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then ws_ext_list_price* ws_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then ws_ext_list_price* ws_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then ws_ext_list_price* ws_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then ws_ext_list_price* ws_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then ws_ext_list_price* ws_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then ws_ext_list_price* ws_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then ws_ext_list_price* ws_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then ws_ext_list_price* ws_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then ws_ext_list_price* ws_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then ws_ext_list_price* ws_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then ws_net_paid * ws_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then ws_net_paid * ws_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then ws_net_paid * ws_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then ws_net_paid * ws_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then ws_net_paid * ws_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then ws_net_paid * ws_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then ws_net_paid * ws_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then ws_net_paid * ws_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then ws_net_paid * ws_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then ws_net_paid * ws_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then ws_net_paid * ws_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then ws_net_paid * ws_quantity else 0 end) as dec_net - from - web_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - ws_warehouse_sk = w_warehouse_sk - and ws_sold_date_sk = d_date_sk - and ws_sold_time_sk = t_time_sk - and ws_ship_mode_sk = sm_ship_mode_sk - and d_year = 1999 - and t_time between 47181 and 47181+28800 - and sm_carrier in ('FEDEX','ZHOU') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - union all - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'FEDEX' || ',' || 'ZHOU' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then cs_ext_list_price* cs_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then cs_ext_list_price* cs_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then cs_ext_list_price* cs_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then cs_ext_list_price* cs_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then cs_ext_list_price* cs_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then cs_ext_list_price* cs_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then cs_ext_list_price* cs_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then cs_ext_list_price* cs_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then cs_ext_list_price* cs_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then cs_ext_list_price* cs_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then cs_ext_list_price* cs_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then cs_ext_list_price* cs_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then cs_net_profit * cs_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then cs_net_profit * cs_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then cs_net_profit * cs_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then cs_net_profit * cs_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then cs_net_profit * cs_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then cs_net_profit * cs_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then cs_net_profit * cs_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then cs_net_profit * cs_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then cs_net_profit * cs_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then cs_net_profit * cs_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then cs_net_profit * cs_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then cs_net_profit * cs_quantity else 0 end) as dec_net - from - catalog_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and cs_sold_time_sk = t_time_sk - and cs_ship_mode_sk = sm_ship_mode_sk - and d_year = 1999 - and t_time between 47181 AND 47181+28800 - and sm_carrier in ('FEDEX','ZHOU') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - ) x - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - order by w_warehouse_name - limit 100; - --- end template query66.tpl query 2 in stream 5 --- start template query4.tpl query 3 in stream 5 -with /* TPC-DS query4.tpl 0.93 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(((ss_ext_list_price-ss_ext_wholesale_cost-ss_ext_discount_amt)+ss_ext_sales_price)/2) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((cs_ext_list_price-cs_ext_wholesale_cost-cs_ext_discount_amt)+cs_ext_sales_price)/2) ) year_total - ,'c' sale_type - from customer - ,catalog_sales - ,date_dim - where c_customer_sk = cs_bill_customer_sk - and cs_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year -union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((ws_ext_list_price-ws_ext_wholesale_cost-ws_ext_discount_amt)+ws_ext_sales_price)/2) ) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_login - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_c_firstyear - ,year_total t_c_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_c_secyear.customer_id - and t_s_firstyear.customer_id = t_c_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_c_firstyear.sale_type = 'c' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_c_secyear.sale_type = 'c' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 1998 - and t_s_secyear.dyear = 1998+1 - and t_c_firstyear.dyear = 1998 - and t_c_secyear.dyear = 1998+1 - and t_w_firstyear.dyear = 1998 - and t_w_secyear.dyear = 1998+1 - and t_s_firstyear.year_total > 0 - and t_c_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_login -limit 100; - --- end template query4.tpl query 3 in stream 5 --- start template query17.tpl query 4 in stream 5 -select /* TPC-DS query17.tpl 0.41 */ i_item_id - ,i_item_desc - ,s_state - ,count(ss_quantity) as store_sales_quantitycount - ,avg(ss_quantity) as store_sales_quantityave - ,stddev_samp(ss_quantity) as store_sales_quantitystdev - ,stddev_samp(ss_quantity)/avg(ss_quantity) as store_sales_quantitycov - ,count(sr_return_quantity) as store_returns_quantitycount - ,avg(sr_return_quantity) as store_returns_quantityave - ,stddev_samp(sr_return_quantity) as store_returns_quantitystdev - ,stddev_samp(sr_return_quantity)/avg(sr_return_quantity) as store_returns_quantitycov - ,count(cs_quantity) as catalog_sales_quantitycount ,avg(cs_quantity) as catalog_sales_quantityave - ,stddev_samp(cs_quantity) as catalog_sales_quantitystdev - ,stddev_samp(cs_quantity)/avg(cs_quantity) as catalog_sales_quantitycov - from store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where d1.d_quarter_name = '1998Q1' - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_quarter_name in ('1998Q1','1998Q2','1998Q3') - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_quarter_name in ('1998Q1','1998Q2','1998Q3') - group by i_item_id - ,i_item_desc - ,s_state - order by i_item_id - ,i_item_desc - ,s_state -limit 100; - --- end template query17.tpl query 4 in stream 5 --- start template query60.tpl query 5 in stream 5 -with /* TPC-DS query60.tpl 0.29 */ ss as ( - select - i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Men')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 10 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id), - cs as ( - select - i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Men')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 10 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id), - ws as ( - select - i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Men')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 10 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id) - select - i_item_id -,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by i_item_id - ,total_sales - limit 100; - --- end template query60.tpl query 5 in stream 5 --- start template query98.tpl query 6 in stream 5 -select /* TPC-DS query98.tpl 0.32 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ss_ext_sales_price) as itemrevenue - ,sum(ss_ext_sales_price)*100/sum(sum(ss_ext_sales_price)) over - (partition by i_class) as revenueratio -from - store_sales - ,item - ,date_dim -where - ss_item_sk = i_item_sk - and i_category in ('Home', 'Women', 'Shoes') - and ss_sold_date_sk = d_date_sk - and d_date between cast('2000-03-18' as date) - and dateadd(day,30,cast('2000-03-18' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio; - --- end template query98.tpl query 6 in stream 5 --- start template query88.tpl query 7 in stream 5 -select /* TPC-DS query88.tpl 0.66 */ * -from - (select count(*) h8_30_to_9 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2)) - and store.s_store_name = 'ese') s1, - (select count(*) h9_to_9_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2)) - and store.s_store_name = 'ese') s2, - (select count(*) h9_30_to_10 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2)) - and store.s_store_name = 'ese') s3, - (select count(*) h10_to_10_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2)) - and store.s_store_name = 'ese') s4, - (select count(*) h10_30_to_11 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2)) - and store.s_store_name = 'ese') s5, - (select count(*) h11_to_11_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2)) - and store.s_store_name = 'ese') s6, - (select count(*) h11_30_to_12 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2)) - and store.s_store_name = 'ese') s7, - (select count(*) h12_to_12_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 12 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2)) - and store.s_store_name = 'ese') s8 -; - --- end template query88.tpl query 7 in stream 5 --- start template query2.tpl query 8 in stream 5 -with /* TPC-DS query2.tpl 0.84 */ wscs as - (select sold_date_sk - ,sales_price - from (select ws_sold_date_sk sold_date_sk - ,ws_ext_sales_price sales_price - from web_sales - union all - select cs_sold_date_sk sold_date_sk - ,cs_ext_sales_price sales_price - from catalog_sales)), - wswscs as - (select d_week_seq, - sum(case when (d_day_name='Sunday') then sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then sales_price else null end) sat_sales - from wscs - ,date_dim - where d_date_sk = sold_date_sk - group by d_week_seq) - select d_week_seq1 - ,round(sun_sales1/sun_sales2,2) - ,round(mon_sales1/mon_sales2,2) - ,round(tue_sales1/tue_sales2,2) - ,round(wed_sales1/wed_sales2,2) - ,round(thu_sales1/thu_sales2,2) - ,round(fri_sales1/fri_sales2,2) - ,round(sat_sales1/sat_sales2,2) - from - (select wswscs.d_week_seq d_week_seq1 - ,sun_sales sun_sales1 - ,mon_sales mon_sales1 - ,tue_sales tue_sales1 - ,wed_sales wed_sales1 - ,thu_sales thu_sales1 - ,fri_sales fri_sales1 - ,sat_sales sat_sales1 - from wswscs,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 2001) y, - (select wswscs.d_week_seq d_week_seq2 - ,sun_sales sun_sales2 - ,mon_sales mon_sales2 - ,tue_sales tue_sales2 - ,wed_sales wed_sales2 - ,thu_sales thu_sales2 - ,fri_sales fri_sales2 - ,sat_sales sat_sales2 - from wswscs - ,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 2001+1) z - where d_week_seq1=d_week_seq2-53 - order by d_week_seq1; - --- end template query2.tpl query 8 in stream 5 --- start template query19.tpl query 9 in stream 5 -select /* TPC-DS query19.tpl 0.8 */ i_brand_id brand_id, i_brand brand, i_manufact_id, i_manufact, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item,customer,customer_address,store - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=44 - and d_moy=11 - and d_year=1998 - and ss_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and substring(ca_zip,1,5) <> substring(s_zip,1,5) - and ss_store_sk = s_store_sk - group by i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact - order by ext_price desc - ,i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact -limit 100 ; - --- end template query19.tpl query 9 in stream 5 --- start template query65.tpl query 10 in stream 5 -select /* TPC-DS query65.tpl 0.71 */ - s_store_name, - i_item_desc, - sc.revenue, - i_current_price, - i_wholesale_cost, - i_brand - from store, item, - (select ss_store_sk, avg(revenue) as ave - from - (select ss_store_sk, ss_item_sk, - sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1179 and 1179+11 - group by ss_store_sk, ss_item_sk) sa - group by ss_store_sk) sb, - (select ss_store_sk, ss_item_sk, sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1179 and 1179+11 - group by ss_store_sk, ss_item_sk) sc - where sb.ss_store_sk = sc.ss_store_sk and - sc.revenue <= 0.1 * sb.ave and - s_store_sk = sc.ss_store_sk and - i_item_sk = sc.ss_item_sk - order by s_store_name, i_item_desc -limit 100; - --- end template query65.tpl query 10 in stream 5 --- start template query3.tpl query 11 in stream 5 -select /* TPC-DS query3.tpl 0.45 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_net_profit) sum_agg - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manufact_id = 128 - and dt.d_moy=11 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,sum_agg desc - ,brand_id - limit 100; - --- end template query3.tpl query 11 in stream 5 --- start template query79.tpl query 12 in stream 5 -select /* TPC-DS query79.tpl 0.89 */ - c_last_name,c_first_name,substring(s_city,1,30),ss_ticket_number,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,store.s_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (household_demographics.hd_dep_count = 6 or household_demographics.hd_vehicle_count > -1) - and date_dim.d_dow = 1 - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_number_employees between 200 and 295 - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,store.s_city) ms,customer - where ss_customer_sk = c_customer_sk - order by c_last_name,c_first_name,substring(s_city,1,30), profit -limit 100; - --- end template query79.tpl query 12 in stream 5 --- start template query13.tpl query 13 in stream 5 -select /* TPC-DS query13.tpl 0.91 */ avg(ss_quantity) - ,avg(ss_ext_sales_price) - ,avg(ss_ext_wholesale_cost) - ,sum(ss_ext_wholesale_cost) - from store_sales - ,store - ,customer_demographics - ,household_demographics - ,customer_address - ,date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2001 - and((ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'D' - and cd_education_status = 'College' - and ss_sales_price between 100.00 and 150.00 - and hd_dep_count = 3 - )or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'U' - and cd_education_status = 'Unknown' - and ss_sales_price between 50.00 and 100.00 - and hd_dep_count = 1 - ) or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'M' - and cd_education_status = 'Advanced Degree' - and ss_sales_price between 150.00 and 200.00 - and hd_dep_count = 1 - )) - and((ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('PA', 'CO', 'GA') - and ss_net_profit between 100 and 200 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('MO', 'IL', 'AR') - and ss_net_profit between 150 and 300 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('KY', 'VA', 'OK') - and ss_net_profit between 50 and 250 - )) -; - --- end template query13.tpl query 13 in stream 5 --- start template query21.tpl query 14 in stream 5 -select /* TPC-DS query21.tpl 0.14 */ * - from(select w_warehouse_name - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('2001-05-12' as date)) - then inv_quantity_on_hand - else 0 end) as inv_before - ,sum(case when (cast(d_date as date) >= cast ('2001-05-12' as date)) - then inv_quantity_on_hand - else 0 end) as inv_after - from inventory - ,warehouse - ,item - ,date_dim - where i_current_price between 0.99 and 1.49 - and i_item_sk = inv_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('2001-05-12' as date)) - and dateadd(day,30,cast ('2001-05-12' as date)) - group by w_warehouse_name, i_item_id) x - where (case when inv_before > 0 - then inv_after / inv_before - else null - end) between 2.0/3.0 and 3.0/2.0 - order by w_warehouse_name - ,i_item_id - limit 100; - --- end template query21.tpl query 14 in stream 5 --- start template query51.tpl query 15 in stream 5 -WITH /* TPC-DS query51.tpl 0.46 */ web_v1 as ( -select - ws_item_sk item_sk, d_date, - sum(sum(ws_sales_price)) - over (partition by ws_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from web_sales - ,date_dim -where ws_sold_date_sk=d_date_sk - and d_month_seq between 1184 and 1184+11 - and ws_item_sk is not NULL -group by ws_item_sk, d_date), -store_v1 as ( -select - ss_item_sk item_sk, d_date, - sum(sum(ss_sales_price)) - over (partition by ss_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from store_sales - ,date_dim -where ss_sold_date_sk=d_date_sk - and d_month_seq between 1184 and 1184+11 - and ss_item_sk is not NULL -group by ss_item_sk, d_date) - select * -from (select item_sk - ,d_date - ,web_sales - ,store_sales - ,max(web_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) web_cumulative - ,max(store_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) store_cumulative - from (select case when web.item_sk is not null then web.item_sk else store.item_sk end item_sk - ,case when web.d_date is not null then web.d_date else store.d_date end d_date - ,web.cume_sales web_sales - ,store.cume_sales store_sales - from web_v1 web full outer join store_v1 store on (web.item_sk = store.item_sk - and web.d_date = store.d_date) - )x )y -where web_cumulative > store_cumulative -order by item_sk - ,d_date -limit 100; - --- end template query51.tpl query 15 in stream 5 --- start template query6.tpl query 16 in stream 5 -select /* TPC-DS query6.tpl 0.58 */ a.ca_state state, count(*) cnt - from customer_address a - ,customer c - ,store_sales s - ,date_dim d - ,item i - where a.ca_address_sk = c.c_current_addr_sk - and c.c_customer_sk = s.ss_customer_sk - and s.ss_sold_date_sk = d.d_date_sk - and s.ss_item_sk = i.i_item_sk - and d.d_month_seq = - (select distinct (d_month_seq) - from date_dim - where d_year = 2000 - and d_moy = 2 ) - and i.i_current_price > 1.2 * - (select avg(j.i_current_price) - from item j - where j.i_category = i.i_category) - group by a.ca_state - having count(*) >= 10 - order by cnt, a.ca_state - limit 100; - --- end template query6.tpl query 16 in stream 5 --- start template query49.tpl query 17 in stream 5 -select /* TPC-DS query49.tpl 0.48 */ channel, item, return_ratio, return_rank, currency_rank from - (select - 'web' as channel - ,web.item - ,web.return_ratio - ,web.return_rank - ,web.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select ws.ws_item_sk as item - ,(cast(sum(coalesce(wr.wr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(wr.wr_return_amt,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - web_sales ws left outer join web_returns wr - on (ws.ws_order_number = wr.wr_order_number and - ws.ws_item_sk = wr.wr_item_sk) - ,date_dim - where - wr.wr_return_amt > 10000 - and ws.ws_net_profit > 1 - and ws.ws_net_paid > 0 - and ws.ws_quantity > 0 - and ws_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 11 - group by ws.ws_item_sk - ) in_web - ) web - where - ( - web.return_rank <= 10 - or - web.currency_rank <= 10 - ) - union - select - 'catalog' as channel - ,catalog.item - ,catalog.return_ratio - ,catalog.return_rank - ,catalog.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select - cs.cs_item_sk as item - ,(cast(sum(coalesce(cr.cr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(cr.cr_return_amount,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - catalog_sales cs left outer join catalog_returns cr - on (cs.cs_order_number = cr.cr_order_number and - cs.cs_item_sk = cr.cr_item_sk) - ,date_dim - where - cr.cr_return_amount > 10000 - and cs.cs_net_profit > 1 - and cs.cs_net_paid > 0 - and cs.cs_quantity > 0 - and cs_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 11 - group by cs.cs_item_sk - ) in_cat - ) catalog - where - ( - catalog.return_rank <= 10 - or - catalog.currency_rank <=10 - ) - union - select - 'store' as channel - ,store.item - ,store.return_ratio - ,store.return_rank - ,store.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select sts.ss_item_sk as item - ,(cast(sum(coalesce(sr.sr_return_quantity,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(sr.sr_return_amt,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - store_sales sts left outer join store_returns sr - on (sts.ss_ticket_number = sr.sr_ticket_number and sts.ss_item_sk = sr.sr_item_sk) - ,date_dim - where - sr.sr_return_amt > 10000 - and sts.ss_net_profit > 1 - and sts.ss_net_paid > 0 - and sts.ss_quantity > 0 - and ss_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 11 - group by sts.ss_item_sk - ) in_store - ) store - where ( - store.return_rank <= 10 - or - store.currency_rank <= 10 - ) - ) - order by 1,4,5,2 - limit 100; - --- end template query49.tpl query 17 in stream 5 --- start template query52.tpl query 18 in stream 5 -select /* TPC-DS query52.tpl 0.59 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_sales_price) ext_price - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=11 - and dt.d_year=1999 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,ext_price desc - ,brand_id -limit 100 ; - --- end template query52.tpl query 18 in stream 5 --- start template query7.tpl query 19 in stream 5 -select /* TPC-DS query7.tpl 0.2 */ i_item_id, - avg(ss_quantity) agg1, - avg(ss_list_price) agg2, - avg(ss_coupon_amt) agg3, - avg(ss_sales_price) agg4 - from store_sales, customer_demographics, date_dim, item, promotion - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_cdemo_sk = cd_demo_sk and - ss_promo_sk = p_promo_sk and - cd_gender = 'F' and - cd_marital_status = 'M' and - cd_education_status = '4 yr Degree' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 1998 - group by i_item_id - order by i_item_id - limit 100; - --- end template query7.tpl query 19 in stream 5 --- start template query56.tpl query 20 in stream 5 -with /* TPC-DS query56.tpl 0.83 */ ss as ( - select i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where i_item_id in (select - i_item_id -from item -where i_color in ('dark','lavender','beige')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 1 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -7 - group by i_item_id), - cs as ( - select i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('dark','lavender','beige')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 1 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -7 - group by i_item_id), - ws as ( - select i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('dark','lavender','beige')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 1 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -7 - group by i_item_id) - select i_item_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by total_sales, - i_item_id - limit 100; - --- end template query56.tpl query 20 in stream 5 --- start template query36a.tpl query 21 in stream 5 -with /* TPC-DS query36a.tpl 0.21 */ results as - (select - sum(ss_net_profit) as ss_net_profit, sum(ss_ext_sales_price) as ss_ext_sales_price, - sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin - ,i_category - ,i_class - ,0 as g_category, 0 as g_class - from - store_sales - ,date_dim d1 - ,item - ,store - where - d1.d_year = 2000 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and s_state in ('SC','GA','MI','MI', - 'TN','IN','OH','NE') - group by i_category,i_class) - , - results_rollup as - (select gross_margin ,i_category ,i_class,0 as t_category, 0 as t_class, 0 as lochierarchy from results - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - i_category, NULL AS i_class, 0 as t_category, 1 as t_class, 1 as lochierarchy from results group by i_category - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - NULL AS i_category ,NULL AS i_class, 1 as t_category, 1 as t_class, 2 as lochierarchy from results) - select - gross_margin ,i_category ,i_class, lochierarchy,rank() over ( - partition by lochierarchy, case when t_class = 0 then i_category end - order by gross_margin asc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then i_category end - ,rank_within_parent - limit 100; - --- end template query36a.tpl query 21 in stream 5 --- start template query77a.tpl query 22 in stream 5 -with /* TPC-DS query77a.tpl 0.78 */ ss as - (select s_store_sk, - sum(ss_ext_sales_price) as sales, - sum(ss_net_profit) as profit - from store_sales, - date_dim, - store - where ss_sold_date_sk = d_date_sk - and d_date between cast('1998-08-26' as date) - and dateadd(day,30,cast('1998-08-26' as date)) - and ss_store_sk = s_store_sk - group by s_store_sk) - , - sr as - (select s_store_sk, - sum(sr_return_amt) as returns, - sum(sr_net_loss) as profit_loss - from store_returns, - date_dim, - store - where sr_returned_date_sk = d_date_sk - and d_date between cast('1998-08-26' as date) - and dateadd(day,30,cast('1998-08-26' as date)) - and sr_store_sk = s_store_sk - group by s_store_sk), - cs as - (select cs_call_center_sk, - sum(cs_ext_sales_price) as sales, - sum(cs_net_profit) as profit - from catalog_sales, - date_dim - where cs_sold_date_sk = d_date_sk - and d_date between cast('1998-08-26' as date) - and dateadd(day,30,cast('1998-08-26' as date)) - group by cs_call_center_sk - ), - cr as - (select cr_call_center_sk, - sum(cr_return_amount) as returns, - sum(cr_net_loss) as profit_loss - from catalog_returns, - date_dim - where cr_returned_date_sk = d_date_sk - and d_date between cast('1998-08-26' as date) - and dateadd(day,30,cast('1998-08-26' as date)) - group by cr_call_center_sk), - ws as - ( select wp_web_page_sk, - sum(ws_ext_sales_price) as sales, - sum(ws_net_profit) as profit - from web_sales, - date_dim, - web_page - where ws_sold_date_sk = d_date_sk - and d_date between cast('1998-08-26' as date) - and dateadd(day,30,cast('1998-08-26' as date)) - and ws_web_page_sk = wp_web_page_sk - group by wp_web_page_sk), - wr as - (select wp_web_page_sk, - sum(wr_return_amt) as returns, - sum(wr_net_loss) as profit_loss - from web_returns, - date_dim, - web_page - where wr_returned_date_sk = d_date_sk - and d_date between cast('1998-08-26' as date) - and dateadd(day,30,cast('1998-08-26' as date)) - and wr_web_page_sk = wp_web_page_sk - group by wp_web_page_sk) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , ss.s_store_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ss left join sr - on ss.s_store_sk = sr.s_store_sk - union all - select 'catalog channel' as channel - , cs_call_center_sk as id - , sales - , returns - , (profit - profit_loss) as profit - from cs - , cr - union all - select 'web channel' as channel - , ws.wp_web_page_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ws left join wr - on ws.wp_web_page_sk = wr.wp_web_page_sk - ) x - group by channel, id ) - - select * - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results -) foo -order by channel, id - limit 100; - --- end template query77a.tpl query 22 in stream 5 --- start template query90.tpl query 23 in stream 5 -select /* TPC-DS query90.tpl 0.40 */ cast(amc as decimal(15,4))/cast(pmc as decimal(15,4)) am_pm_ratio - from ( select count(*) amc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 9 and 9+1 - and household_demographics.hd_dep_count = 4 - and web_page.wp_char_count between 5000 and 5200) at, - ( select count(*) pmc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 14 and 14+1 - and household_demographics.hd_dep_count = 4 - and web_page.wp_char_count between 5000 and 5200) pt - order by am_pm_ratio - limit 100; - --- end template query90.tpl query 23 in stream 5 --- start template query76.tpl query 24 in stream 5 -select /* TPC-DS query76.tpl 0.99 */ channel, col_name, d_year, d_qoy, i_category, COUNT(*) sales_cnt, SUM(ext_sales_price) sales_amt FROM ( - SELECT 'store' as channel, 'ss_addr_sk' col_name, d_year, d_qoy, i_category, ss_ext_sales_price ext_sales_price - FROM store_sales, item, date_dim - WHERE ss_addr_sk IS NULL - AND ss_sold_date_sk=d_date_sk - AND ss_item_sk=i_item_sk - UNION ALL - SELECT 'web' as channel, 'ws_ship_mode_sk' col_name, d_year, d_qoy, i_category, ws_ext_sales_price ext_sales_price - FROM web_sales, item, date_dim - WHERE ws_ship_mode_sk IS NULL - AND ws_sold_date_sk=d_date_sk - AND ws_item_sk=i_item_sk - UNION ALL - SELECT 'catalog' as channel, 'cs_ship_addr_sk' col_name, d_year, d_qoy, i_category, cs_ext_sales_price ext_sales_price - FROM catalog_sales, item, date_dim - WHERE cs_ship_addr_sk IS NULL - AND cs_sold_date_sk=d_date_sk - AND cs_item_sk=i_item_sk) foo -GROUP BY channel, col_name, d_year, d_qoy, i_category -ORDER BY channel, col_name, d_year, d_qoy, i_category -limit 100; - --- end template query76.tpl query 24 in stream 5 --- start template query58.tpl query 25 in stream 5 -with /* TPC-DS query58.tpl 0.19 */ ss_items as - (select i_item_id item_id - ,sum(ss_ext_sales_price) ss_item_rev - from store_sales - ,item - ,date_dim - where ss_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '1998-03-18')) - and ss_sold_date_sk = d_date_sk - group by i_item_id), - cs_items as - (select i_item_id item_id - ,sum(cs_ext_sales_price) cs_item_rev - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '1998-03-18')) - and cs_sold_date_sk = d_date_sk - group by i_item_id), - ws_items as - (select i_item_id item_id - ,sum(ws_ext_sales_price) ws_item_rev - from web_sales - ,item - ,date_dim - where ws_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq =(select d_week_seq - from date_dim - where d_date = '1998-03-18')) - and ws_sold_date_sk = d_date_sk - group by i_item_id) - select ss_items.item_id - ,ss_item_rev - ,ss_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ss_dev - ,cs_item_rev - ,cs_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 cs_dev - ,ws_item_rev - ,ws_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ws_dev - ,(ss_item_rev+cs_item_rev+ws_item_rev)/3 average - from ss_items,cs_items,ws_items - where ss_items.item_id=cs_items.item_id - and ss_items.item_id=ws_items.item_id - and ss_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - and ss_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and cs_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and cs_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and ws_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and ws_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - order by item_id - ,ss_item_rev - limit 100; - --- end template query58.tpl query 25 in stream 5 --- start template query71.tpl query 26 in stream 5 -select /* TPC-DS query71.tpl 0.72 */ i_brand_id brand_id, i_brand brand,t_hour,t_minute, - sum(ext_price) ext_price - from item, (select ws_ext_sales_price as ext_price, - ws_sold_date_sk as sold_date_sk, - ws_item_sk as sold_item_sk, - ws_sold_time_sk as time_sk - from web_sales,date_dim - where d_date_sk = ws_sold_date_sk - and d_moy=12 - and d_year=1999 - union all - select cs_ext_sales_price as ext_price, - cs_sold_date_sk as sold_date_sk, - cs_item_sk as sold_item_sk, - cs_sold_time_sk as time_sk - from catalog_sales,date_dim - where d_date_sk = cs_sold_date_sk - and d_moy=12 - and d_year=1999 - union all - select ss_ext_sales_price as ext_price, - ss_sold_date_sk as sold_date_sk, - ss_item_sk as sold_item_sk, - ss_sold_time_sk as time_sk - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - and d_moy=12 - and d_year=1999 - ) tmp,time_dim - where - sold_item_sk = i_item_sk - and i_manager_id=1 - and time_sk = t_time_sk - and (t_meal_time = 'breakfast' or t_meal_time = 'dinner') - group by i_brand, i_brand_id,t_hour,t_minute - order by ext_price desc, i_brand_id - ; - --- end template query71.tpl query 26 in stream 5 --- start template query80a.tpl query 27 in stream 5 -with /* TPC-DS query80a.tpl 0.6 */ ssr as - (select s_store_id as store_id, - sum(ss_ext_sales_price) as sales, - sum(coalesce(sr_return_amt, 0)) as returns, - sum(ss_net_profit - coalesce(sr_net_loss, 0)) as profit - from store_sales left outer join store_returns on - (ss_item_sk = sr_item_sk and ss_ticket_number = sr_ticket_number), - date_dim, - store, - item, - promotion - where ss_sold_date_sk = d_date_sk - and d_date between cast('1999-08-03' as date) - and dateadd(day,30,cast('1999-08-03' as date)) - and ss_store_sk = s_store_sk - and ss_item_sk = i_item_sk - and i_current_price > 50 - and ss_promo_sk = p_promo_sk - and p_channel_tv = 'N' - group by s_store_id) - , - csr as - (select cp_catalog_page_id as catalog_page_id, - sum(cs_ext_sales_price) as sales, - sum(coalesce(cr_return_amount, 0)) as returns, - sum(cs_net_profit - coalesce(cr_net_loss, 0)) as profit - from catalog_sales left outer join catalog_returns on - (cs_item_sk = cr_item_sk and cs_order_number = cr_order_number), - date_dim, - catalog_page, - item, - promotion - where cs_sold_date_sk = d_date_sk - and d_date between cast('1999-08-03' as date) - and dateadd(day,30,cast('1999-08-03' as date)) - and cs_catalog_page_sk = cp_catalog_page_sk - and cs_item_sk = i_item_sk - and i_current_price > 50 - and cs_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(ws_ext_sales_price) as sales, - sum(coalesce(wr_return_amt, 0)) as returns, - sum(ws_net_profit - coalesce(wr_net_loss, 0)) as profit - from web_sales left outer join web_returns on - (ws_item_sk = wr_item_sk and ws_order_number = wr_order_number), - date_dim, - web_site, - item, - promotion - where ws_sold_date_sk = d_date_sk - and d_date between cast('1999-08-03' as date) - and dateadd(day,30,cast('1999-08-03' as date)) - and ws_web_site_sk = web_site_sk - and ws_item_sk = i_item_sk - and i_current_price > 50 - and ws_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by web_site_id) -, -results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || store_id as id - , sales - , returns - , profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || catalog_page_id as id - , sales - , returns - , profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , profit - from wsr - ) x - group by channel, id) - - select channel - , id - , sales - , returns - , profit - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results - ) foo - order by channel, id - limit 100; - --- end template query80a.tpl query 27 in stream 5 --- start template query69.tpl query 28 in stream 5 -select /* TPC-DS query69.tpl 0.28 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_state in ('ND','IN','VA') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2003 and - d_moy between 4 and 4+2) and - (not exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2003 and - d_moy between 4 and 4+2) and - not exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2003 and - d_moy between 4 and 4+2)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - limit 100; - --- end template query69.tpl query 28 in stream 5 --- start template query54.tpl query 29 in stream 5 -with /* TPC-DS query54.tpl 0.81 */ my_customers as ( - select distinct c_customer_sk - , c_current_addr_sk - from - ( select cs_sold_date_sk sold_date_sk, - cs_bill_customer_sk customer_sk, - cs_item_sk item_sk - from catalog_sales - union all - select ws_sold_date_sk sold_date_sk, - ws_bill_customer_sk customer_sk, - ws_item_sk item_sk - from web_sales - ) cs_or_ws_sales, - item, - date_dim, - customer - where sold_date_sk = d_date_sk - and item_sk = i_item_sk - and i_category = 'Sports' - and i_class = 'sailing' - and c_customer_sk = cs_or_ws_sales.customer_sk - and d_moy = 4 - and d_year = 2000 - ) - , my_revenue as ( - select c_customer_sk, - sum(ss_ext_sales_price) as revenue - from my_customers, - store_sales, - customer_address, - store, - date_dim - where c_current_addr_sk = ca_address_sk - and ca_county = s_county - and ca_state = s_state - and ss_sold_date_sk = d_date_sk - and c_customer_sk = ss_customer_sk - and d_month_seq between (select distinct d_month_seq+1 - from date_dim where d_year = 2000 and d_moy = 4) - and (select distinct d_month_seq+3 - from date_dim where d_year = 2000 and d_moy = 4) - group by c_customer_sk - ) - , segments as - (select cast((revenue/50) as int) as segment - from my_revenue - ) - select segment, count(*) as num_customers, segment*50 as segment_base - from segments - group by segment - order by segment, num_customers - limit 100; - --- end template query54.tpl query 29 in stream 5 --- start template query92.tpl query 30 in stream 5 -select /* TPC-DS query92.tpl 0.44 */ - sum(ws_ext_discount_amt) as "Excess Discount Amount" -from - web_sales - ,item - ,date_dim -where -i_manufact_id = 615 -and i_item_sk = ws_item_sk -and d_date between '1998-03-03' and - dateadd(day,90,cast('1998-03-03' as date)) -and d_date_sk = ws_sold_date_sk -and ws_ext_discount_amt - > ( - SELECT - 1.3 * avg(ws_ext_discount_amt) - FROM - web_sales - ,date_dim - WHERE - ws_item_sk = i_item_sk - and d_date between '1998-03-03' and - dateadd(day,90,cast('1998-03-03' as date)) - and d_date_sk = ws_sold_date_sk - ) -order by sum(ws_ext_discount_amt) -limit 100; - --- end template query92.tpl query 30 in stream 5 --- start template query61.tpl query 31 in stream 5 -select /* TPC-DS query61.tpl 0.97 */ promotions,total,cast(promotions as decimal(15,4))/cast(total as decimal(15,4))*100 -from - (select sum(ss_ext_sales_price) promotions - from store_sales - ,store - ,promotion - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_promo_sk = p_promo_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -7 - and i_category = 'Sports' - and (p_channel_dmail = 'Y' or p_channel_email = 'Y' or p_channel_tv = 'Y') - and s_gmt_offset = -7 - and d_year = 1999 - and d_moy = 12) promotional_sales, - (select sum(ss_ext_sales_price) total - from store_sales - ,store - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -7 - and i_category = 'Sports' - and s_gmt_offset = -7 - and d_year = 1999 - and d_moy = 12) all_sales -order by promotions, total -limit 100; - --- end template query61.tpl query 31 in stream 5 --- start template query53.tpl query 32 in stream 5 -select /* TPC-DS query53.tpl 0.88 */ * from -(select i_manufact_id, -sum(ss_sales_price) sum_sales, -avg(sum(ss_sales_price)) over (partition by i_manufact_id) avg_quarterly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and -ss_sold_date_sk = d_date_sk and -ss_store_sk = s_store_sk and -d_month_seq in (1209,1209+1,1209+2,1209+3,1209+4,1209+5,1209+6,1209+7,1209+8,1209+9,1209+10,1209+11) and -((i_category in ('Books','Children','Electronics') and -i_class in ('personal','portable','reference','self-help') and -i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) -or(i_category in ('Women','Music','Men') and -i_class in ('accessories','classical','fragrances','pants') and -i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manufact_id, d_qoy ) tmp1 -where case when avg_quarterly_sales > 0 - then abs (sum_sales - avg_quarterly_sales)/ avg_quarterly_sales - else null end > 0.1 -order by avg_quarterly_sales, - sum_sales, - i_manufact_id -limit 100; - --- end template query53.tpl query 32 in stream 5 --- start template query87.tpl query 33 in stream 5 -select /* TPC-DS query87.tpl 0.77 */ count(*) -from ((select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1220 and 1220+11) - except - (select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1220 and 1220+11) - except - (select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1220 and 1220+11) -) cool_cust -; - --- end template query87.tpl query 33 in stream 5 --- start template query68.tpl query 34 in stream 5 -select /* TPC-DS query68.tpl 0.95 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,extended_price - ,extended_tax - ,list_price - from (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_ext_sales_price) extended_price - ,sum(ss_ext_list_price) list_price - ,sum(ss_ext_tax) extended_tax - from store_sales - ,date_dim - ,store - ,household_demographics - ,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_dep_count = 4 or - household_demographics.hd_vehicle_count= 2) - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_city in ('Brownsville','Franklin') - group by ss_ticket_number - ,ss_customer_sk - ,ss_addr_sk,ca_city) dn - ,customer - ,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,ss_ticket_number - limit 100; - --- end template query68.tpl query 34 in stream 5 --- start template query85.tpl query 35 in stream 5 -select /* TPC-DS query85.tpl 0.33 */ substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) - from web_sales, web_returns, web_page, customer_demographics cd1, - customer_demographics cd2, customer_address, date_dim, reason - where ws_web_page_sk = wp_web_page_sk - and ws_item_sk = wr_item_sk - and ws_order_number = wr_order_number - and ws_sold_date_sk = d_date_sk and d_year = 1998 - and cd1.cd_demo_sk = wr_refunded_cdemo_sk - and cd2.cd_demo_sk = wr_returning_cdemo_sk - and ca_address_sk = wr_refunded_addr_sk - and r_reason_sk = wr_reason_sk - and - ( - ( - cd1.cd_marital_status = 'U' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Primary' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 100.00 and 150.00 - ) - or - ( - cd1.cd_marital_status = 'D' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Secondary' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 50.00 and 100.00 - ) - or - ( - cd1.cd_marital_status = 'S' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Advanced Degree' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ca_country = 'United States' - and - ca_state in ('KS', 'TX', 'FL') - and ws_net_profit between 100 and 200 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('SD', 'AZ', 'ID') - and ws_net_profit between 150 and 300 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('AL', 'IN', 'IA') - and ws_net_profit between 50 and 250 - ) - ) -group by r_reason_desc -order by substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) -limit 100; - --- end template query85.tpl query 35 in stream 5 --- start template query28.tpl query 36 in stream 5 -select /* TPC-DS query28.tpl 0.36 */ * -from (select avg(ss_list_price) B1_LP - ,count(ss_list_price) B1_CNT - ,count(distinct ss_list_price) B1_CNTD - from store_sales - where ss_quantity between 0 and 5 - and (ss_list_price between 131 and 131+10 - or ss_coupon_amt between 1482 and 1482+1000 - or ss_wholesale_cost between 33 and 33+20)) B1, - (select avg(ss_list_price) B2_LP - ,count(ss_list_price) B2_CNT - ,count(distinct ss_list_price) B2_CNTD - from store_sales - where ss_quantity between 6 and 10 - and (ss_list_price between 167 and 167+10 - or ss_coupon_amt between 131 and 131+1000 - or ss_wholesale_cost between 16 and 16+20)) B2, - (select avg(ss_list_price) B3_LP - ,count(ss_list_price) B3_CNT - ,count(distinct ss_list_price) B3_CNTD - from store_sales - where ss_quantity between 11 and 15 - and (ss_list_price between 137 and 137+10 - or ss_coupon_amt between 17163 and 17163+1000 - or ss_wholesale_cost between 55 and 55+20)) B3, - (select avg(ss_list_price) B4_LP - ,count(ss_list_price) B4_CNT - ,count(distinct ss_list_price) B4_CNTD - from store_sales - where ss_quantity between 16 and 20 - and (ss_list_price between 60 and 60+10 - or ss_coupon_amt between 17366 and 17366+1000 - or ss_wholesale_cost between 74 and 74+20)) B4, - (select avg(ss_list_price) B5_LP - ,count(ss_list_price) B5_CNT - ,count(distinct ss_list_price) B5_CNTD - from store_sales - where ss_quantity between 21 and 25 - and (ss_list_price between 127 and 127+10 - or ss_coupon_amt between 8344 and 8344+1000 - or ss_wholesale_cost between 79 and 79+20)) B5, - (select avg(ss_list_price) B6_LP - ,count(ss_list_price) B6_CNT - ,count(distinct ss_list_price) B6_CNTD - from store_sales - where ss_quantity between 26 and 30 - and (ss_list_price between 32 and 32+10 - or ss_coupon_amt between 6077 and 6077+1000 - or ss_wholesale_cost between 62 and 62+20)) B6 -limit 100; - --- end template query28.tpl query 36 in stream 5 --- start template query42.tpl query 37 in stream 5 -select /* TPC-DS query42.tpl 0.61 */ dt.d_year - ,item.i_category_id - ,item.i_category - ,sum(ss_ext_sales_price) - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=12 - and dt.d_year=2001 - group by dt.d_year - ,item.i_category_id - ,item.i_category - order by sum(ss_ext_sales_price) desc,dt.d_year - ,item.i_category_id - ,item.i_category -limit 100 ; - --- end template query42.tpl query 37 in stream 5 --- start template query67a.tpl query 38 in stream 5 -with /* TPC-DS query67a.tpl 0.35 */ results as -( select i_category ,i_class ,i_brand ,i_product_name ,d_year ,d_qoy ,d_moy ,s_store_id - ,sum(coalesce(ss_sales_price*ss_quantity,0)) sumsales - from store_sales ,date_dim ,store ,item - where ss_sold_date_sk=d_date_sk - and ss_item_sk=i_item_sk - and ss_store_sk = s_store_sk - and d_month_seq between 1193 and 1193 + 11 - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy,s_store_id) - , - results_rollup as - (select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, s_store_id, sumsales - from results - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy - union all - select i_category, i_class, i_brand, i_product_name, d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year - union all - select i_category, i_class, i_brand, i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name - union all - select i_category, i_class, i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand - union all - select i_category, i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class - union all - select i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category - union all - select null i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results) - - select * -from (select i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rank() over (partition by i_category order by sumsales desc) rk - from results_rollup) dw2 -where rk <= 100 -order by i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rk -limit 100; - --- end template query67a.tpl query 38 in stream 5 --- start template query50.tpl query 39 in stream 5 -select /* TPC-DS query50.tpl 0.60 */ - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 30) and - (sr_returned_date_sk - ss_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 60) and - (sr_returned_date_sk - ss_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 90) and - (sr_returned_date_sk - ss_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - store_sales - ,store_returns - ,store - ,date_dim d1 - ,date_dim d2 -where - d2.d_year = 2000 -and d2.d_moy = 8 -and ss_ticket_number = sr_ticket_number -and ss_item_sk = sr_item_sk -and ss_sold_date_sk = d1.d_date_sk -and sr_returned_date_sk = d2.d_date_sk -and ss_customer_sk = sr_customer_sk -and ss_store_sk = s_store_sk -group by - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -order by s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -limit 100; - --- end template query50.tpl query 39 in stream 5 --- start template query30.tpl query 40 in stream 5 -with /* TPC-DS query30.tpl 0.75 */ customer_total_return as - (select wr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(wr_return_amt) as ctr_total_return - from web_returns - ,date_dim - ,customer_address - where wr_returned_date_sk = d_date_sk - and d_year =2002 - and wr_returning_addr_sk = ca_address_sk - group by wr_returning_customer_sk - ,ca_state) - select c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'WI' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return -limit 100; - --- end template query30.tpl query 40 in stream 5 --- start template query48.tpl query 41 in stream 5 -select /* TPC-DS query48.tpl 0.74 */ sum (ss_quantity) - from store_sales, store, customer_demographics, customer_address, date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 1998 - and - ( - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'M' - and - cd_education_status = 'Primary' - and - ss_sales_price between 100.00 and 150.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'D' - and - cd_education_status = 'Unknown' - and - ss_sales_price between 50.00 and 100.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'S' - and - cd_education_status = 'Advanced Degree' - and - ss_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('NE', 'OK', 'KY') - and ss_net_profit between 0 and 2000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('GA', 'ID', 'CO') - and ss_net_profit between 150 and 3000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('MT', 'KS', 'PA') - and ss_net_profit between 50 and 25000 - ) - ) -; - --- end template query48.tpl query 41 in stream 5 --- start template query22a.tpl query 42 in stream 5 -with /* TPC-DS query22a.tpl 0.55 */ results as -(select i_product_name - ,i_brand - ,i_class - ,i_category - ,avg(inv_quantity_on_hand) qoh - from inventory - ,date_dim - ,item --- ,warehouse - where inv_date_sk=d_date_sk - and inv_item_sk=i_item_sk --- and inv_warehouse_sk = w_warehouse_sk - and d_month_seq between 1196 and 1196 + 11 - group by i_product_name,i_brand,i_class,i_category), -results_rollup as -(select i_product_name, i_brand, i_class, i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class,i_category -union all -select i_product_name, i_brand, i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class -union all -select i_product_name, i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand -union all -select i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name -union all -select null i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results) - select i_product_name, i_brand, i_class, i_category,qoh - from results_rollup - order by qoh, i_product_name, i_brand, i_class, i_category -limit 100; - --- end template query22a.tpl query 42 in stream 5 --- start template query11.tpl query 43 in stream 5 -with /* TPC-DS query11.tpl 0.51 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ss_ext_list_price-ss_ext_discount_amt) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ws_ext_list_price-ws_ext_discount_amt) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_login - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 1999 - and t_s_secyear.dyear = 1999+1 - and t_w_firstyear.dyear = 1999 - and t_w_secyear.dyear = 1999+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else 0.0 end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else 0.0 end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_login -limit 100; - --- end template query11.tpl query 43 in stream 5 --- start template query94.tpl query 44 in stream 5 -select /* TPC-DS query94.tpl 0.17 */ - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2002-5-01' and - dateadd(day,60,cast('2002-5-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'OH' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and exists (select * - from web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) -and not exists(select * - from web_returns wr1 - where ws1.ws_order_number = wr1.wr_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query94.tpl query 44 in stream 5 --- start template query93.tpl query 45 in stream 5 -select /* TPC-DS query93.tpl 0.52 */ ss_customer_sk - ,sum(act_sales) sumsales - from (select ss_item_sk - ,ss_ticket_number - ,ss_customer_sk - ,case when sr_return_quantity is not null then (ss_quantity-sr_return_quantity)*ss_sales_price - else (ss_quantity*ss_sales_price) end act_sales - from store_sales left outer join store_returns on (sr_item_sk = ss_item_sk - and sr_ticket_number = ss_ticket_number) - ,reason - where sr_reason_sk = r_reason_sk - and r_reason_desc = 'unauthoized purchase') t - group by ss_customer_sk - order by sumsales, ss_customer_sk -limit 100; - --- end template query93.tpl query 45 in stream 5 --- start template query18a.tpl query 46 in stream 5 -with /* TPC-DS query18a.tpl 0.90 */ results as - (select i_item_id, - ca_country, - ca_state, - ca_county, - cast(cs_quantity as decimal(12,2)) agg1, - cast(cs_list_price as decimal(12,2)) agg2, - cast(cs_coupon_amt as decimal(12,2)) agg3, - cast(cs_sales_price as decimal(12,2)) agg4, - cast(cs_net_profit as decimal(12,2)) agg5, - cast(c_birth_year as decimal(12,2)) agg6, - cast(cd1.cd_dep_count as decimal(12,2)) agg7 - from catalog_sales, customer_demographics cd1, customer_demographics cd2, customer, customer_address, date_dim, item - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd1.cd_demo_sk and - cs_bill_customer_sk = c_customer_sk and - cd1.cd_gender = 'M' and - cd1.cd_education_status = '4 yr Degree' and - c_current_cdemo_sk = cd2.cd_demo_sk and - c_current_addr_sk = ca_address_sk and - c_birth_month in (11,2,9,8,4,12) and - d_year = 2001 and - ca_state in ('PA','NC','ID','IL','TX','MI','MD') - ) - select i_item_id, ca_country, ca_state, ca_county, agg1, agg2, agg3, agg4, agg5, agg6, agg7 - from ( - select i_item_id, ca_country, ca_state, ca_county, avg(agg1) agg1, - avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state, ca_county - union all - select i_item_id, ca_country, ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state - union all - select i_item_id, ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country - union all - select i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - ) foo - order by ca_country, ca_state, ca_county, i_item_id - limit 100; - --- end template query18a.tpl query 46 in stream 5 --- start template query33.tpl query 47 in stream 5 -with /* TPC-DS query33.tpl 0.22 */ ss as ( - select - i_manufact_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Electronics')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 6 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id), - cs as ( - select - i_manufact_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Electronics')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 6 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id), - ws as ( - select - i_manufact_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Electronics')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 6 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id) - select i_manufact_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_manufact_id - order by total_sales -limit 100; - --- end template query33.tpl query 47 in stream 5 --- start template query63.tpl query 48 in stream 5 -select /* TPC-DS query63.tpl 0.27 */ * -from (select i_manager_id - ,sum(ss_sales_price) sum_sales - ,avg(sum(ss_sales_price)) over (partition by i_manager_id) avg_monthly_sales - from item - ,store_sales - ,date_dim - ,store - where ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and d_month_seq in (1222,1222+1,1222+2,1222+3,1222+4,1222+5,1222+6,1222+7,1222+8,1222+9,1222+10,1222+11) - and (( i_category in ('Books','Children','Electronics') - and i_class in ('personal','portable','reference','self-help') - and i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) - or( i_category in ('Women','Music','Men') - and i_class in ('accessories','classical','fragrances','pants') - and i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manager_id, d_moy) tmp1 -where case when avg_monthly_sales > 0 then abs (sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 -order by i_manager_id - ,avg_monthly_sales - ,sum_sales -limit 100; - --- end template query63.tpl query 48 in stream 5 --- start template query8.tpl query 49 in stream 5 -select /* TPC-DS query8.tpl 0.63 */ s_store_name - ,sum(ss_net_profit) - from store_sales - ,date_dim - ,store, - (select ca_zip - from ( - SELECT substring(ca_zip,1,5) ca_zip - FROM customer_address - WHERE substring(ca_zip,1,5) IN ( - '61874','30697','69490','90165','59409','76397', - '66501','51240','89992','37130','23298', - '54518','81448','36091','10579','79466', - '77093','71662','97159','47912','65620', - '49710','25578','25706','49768','13244', - '76716','68052','84481','66508','42132', - '28012','35544','42594','70511','70310', - '41923','62353','30316','25538','33794', - '49016','52395','93258','29895','37679', - '39289','53646','59734','72166','40196', - '34033','54843','96248','24243','85088', - '28719','72770','23061','29921','31641', - '42520','30484','37134','15243','84232', - '79183','95079','40355','25401','97202', - '18122','25526','97797','83822','50545', - '42304','33787','56335','77448','48310', - '29484','83469','26658','62386','19209', - '46798','83788','33548','24400','82702', - '38315','25469','53558','66548','46520', - '29845','26280','48443','61625','25191', - '13603','24521','34746','31843','73391', - '93706','47627','27673','84716','17293', - '79921','24571','24264','80365','39106', - '68362','27459','91279','93702','47278', - '69621','13880','88660','75642','42144', - '67475','59923','78509','93592','32638', - '27244','78483','12568','73846','76417', - '22141','88040','74100','88787','81475', - '53327','14355','28954','81191','61007', - '28638','64344','28084','83440','41911', - '51680','98490','77588','28637','97636', - '56466','56486','33702','83236','69847', - '70018','37111','93050','25955','41614', - '32208','94944','86239','26896','51053', - '96376','82094','26226','82967','80341', - '90575','43006','73150','62989','53401', - '26293','85632','24510','56307','33215', - '51884','90732','60468','57164','17476', - '25850','72876','48511','39834','78877', - '46886','16778','60404','47491','99008', - '37160','18812','17124','23778','70607', - '19230','85564','75759','60363','93526', - '51725','61486','39315','55794','22273', - '43622','18689','99640','67211','34424', - '87128','81944','29520','36292','41978', - '89239','67088','27915','53429','40445', - '17945','20567','14514','23914','45732', - '99838','22109','39132','87933','87498', - '78157','49318','81334','18235','95165', - '92253','40901','88690','54873','62816', - '95005','16973','80218','22842','39260', - '78571','16019','10851','47012','65698', - '46840','26356','66516','21204','44949', - '99454','96477','68796','88077','26228', - '44240','69678','19847','57087','85875', - '17882','86696','52554','77103','29733', - '51446','67775','18123','11787','83933', - '29361','32013','95324','53926','79662', - '50593','11742','18084','71922','16810', - '69137','51144','85312','70225','25302', - '89704','15248','14137','19857','62135', - '41017','62638','96206','41351','46071', - '86168','29409','95785','73760','73790', - '20461','89467','72581','50231','42722', - '30428','48879','25352','62887','98945', - '21898','15136','11234','87798','11469', - '83484','14679','26793','66649','40053', - '73125','85950','74393','66748','45883', - '21837','52819','33590','85094','57915', - '81738','80242','92321','97575','59114', - '68120','92833','47951','83132','72756', - '16338','15408','62485','69922','21854', - '12755','42306','57271','18267','43363', - '80197','29431','69895','58411','81882', - '44200','10545','60144','55687','24150', - '67380','83690','52210','64571','65051', - '24029','86934','42273','85026','15611', - '84495','93223','16909','40953','37506', - '52739','47613','49708','89248','77351', - '21191','65083','12506','92180') - intersect - select ca_zip - from (SELECT substring(ca_zip,1,5) ca_zip,count(*) cnt - FROM customer_address, customer - WHERE ca_address_sk = c_current_addr_sk and - c_preferred_cust_flag='Y' - group by ca_zip - having count(*) > 10)A1)A2) V1 - where ss_store_sk = s_store_sk - and ss_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 1999 - and (substring(s_zip,1,2) = substring(V1.ca_zip,1,2)) - group by s_store_name - order by s_store_name - limit 100; - --- end template query8.tpl query 49 in stream 5 --- start template query97.tpl query 50 in stream 5 -with /* TPC-DS query97.tpl 0.38 */ ssci as ( -select ss_customer_sk customer_sk - ,ss_item_sk item_sk -from store_sales,date_dim -where ss_sold_date_sk = d_date_sk - and d_month_seq between 1188 and 1188 + 11 -group by ss_customer_sk - ,ss_item_sk), -csci as( - select cs_bill_customer_sk customer_sk - ,cs_item_sk item_sk -from catalog_sales,date_dim -where cs_sold_date_sk = d_date_sk - and d_month_seq between 1188 and 1188 + 11 -group by cs_bill_customer_sk - ,cs_item_sk) - select sum(case when ssci.customer_sk is not null and csci.customer_sk is null then 1 else 0 end) store_only - ,sum(case when ssci.customer_sk is null and csci.customer_sk is not null then 1 else 0 end) catalog_only - ,sum(case when ssci.customer_sk is not null and csci.customer_sk is not null then 1 else 0 end) store_and_catalog -from ssci full outer join csci on (ssci.customer_sk=csci.customer_sk - and ssci.item_sk = csci.item_sk) -limit 100; - --- end template query97.tpl query 50 in stream 5 --- start template query45.tpl query 51 in stream 5 -select /* TPC-DS query45.tpl 0.18 */ ca_zip, ca_county, sum(ws_sales_price) - from web_sales, customer, customer_address, date_dim, item - where ws_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ws_item_sk = i_item_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', '85392', '85460', '80348', '81792') - or - i_item_id in (select i_item_id - from item - where i_item_sk in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29) - ) - ) - and ws_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 2002 - group by ca_zip, ca_county - order by ca_zip, ca_county - limit 100; - --- end template query45.tpl query 51 in stream 5 --- start template query62.tpl query 52 in stream 5 -select /* TPC-DS query62.tpl 0.24 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 30) and - (ws_ship_date_sk - ws_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 60) and - (ws_ship_date_sk - ws_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 90) and - (ws_ship_date_sk - ws_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - web_sales - ,warehouse - ,ship_mode - ,web_site - ,date_dim -where - d_month_seq between 1196 and 1196 + 11 -and ws_ship_date_sk = d_date_sk -and ws_warehouse_sk = w_warehouse_sk -and ws_ship_mode_sk = sm_ship_mode_sk -and ws_web_site_sk = web_site_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -limit 100; - --- end template query62.tpl query 52 in stream 5 --- start template query81.tpl query 53 in stream 5 -with /* TPC-DS query81.tpl 0.37 */ customer_total_return as - (select cr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(cr_return_amt_inc_tax) as ctr_total_return - from catalog_returns - ,date_dim - ,customer_address - where cr_returned_date_sk = d_date_sk - and d_year =2002 - and cr_returning_addr_sk = ca_address_sk - group by cr_returning_customer_sk - ,ca_state ) - select c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'MS' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - limit 100; - --- end template query81.tpl query 53 in stream 5 --- start template query35a.tpl query 54 in stream 5 -select /* TPC-DS query35a.tpl 0.47 */ - ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - count(*) cnt1, - sum(cd_dep_count), - stddev_samp(cd_dep_count), - avg(cd_dep_count), - cd_dep_employed_count, - count(*) cnt2, - sum(cd_dep_employed_count), - stddev_samp(cd_dep_employed_count), - avg(cd_dep_employed_count), - cd_dep_college_count, - count(*) cnt3, - sum(cd_dep_college_count), - stddev_samp(cd_dep_college_count), - avg(cd_dep_college_count) - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2000 and - d_qoy < 4) and - exists (select * from - (select ws_bill_customer_sk customsk - from web_sales,date_dim - where - ws_sold_date_sk = d_date_sk and - d_year = 2000 and - d_qoy < 4 - union all - select cs_ship_customer_sk customsk - from catalog_sales,date_dim - where - cs_sold_date_sk = d_date_sk and - d_year = 2000 and - d_qoy < 4)x - where x.customsk = c.c_customer_sk) - group by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - limit 100; - --- end template query35a.tpl query 54 in stream 5 --- start template query78.tpl query 55 in stream 5 -with /* TPC-DS query78.tpl 0.10 */ ws as - (select d_year AS ws_sold_year, ws_item_sk, - ws_bill_customer_sk ws_customer_sk, - sum(ws_quantity) ws_qty, - sum(ws_wholesale_cost) ws_wc, - sum(ws_sales_price) ws_sp - from web_sales - left join web_returns on wr_order_number=ws_order_number and ws_item_sk=wr_item_sk - join date_dim on ws_sold_date_sk = d_date_sk - where wr_order_number is null - group by d_year, ws_item_sk, ws_bill_customer_sk - ), -cs as - (select d_year AS cs_sold_year, cs_item_sk, - cs_bill_customer_sk cs_customer_sk, - sum(cs_quantity) cs_qty, - sum(cs_wholesale_cost) cs_wc, - sum(cs_sales_price) cs_sp - from catalog_sales - left join catalog_returns on cr_order_number=cs_order_number and cs_item_sk=cr_item_sk - join date_dim on cs_sold_date_sk = d_date_sk - where cr_order_number is null - group by d_year, cs_item_sk, cs_bill_customer_sk - ), -ss as - (select d_year AS ss_sold_year, ss_item_sk, - ss_customer_sk, - sum(ss_quantity) ss_qty, - sum(ss_wholesale_cost) ss_wc, - sum(ss_sales_price) ss_sp - from store_sales - left join store_returns on sr_ticket_number=ss_ticket_number and ss_item_sk=sr_item_sk - join date_dim on ss_sold_date_sk = d_date_sk - where sr_ticket_number is null - group by d_year, ss_item_sk, ss_customer_sk - ) - select -ss_item_sk, -round(ss_qty/(coalesce(ws_qty,0)+coalesce(cs_qty,0)),2) ratio, -ss_qty store_qty, ss_wc store_wholesale_cost, ss_sp store_sales_price, -coalesce(ws_qty,0)+coalesce(cs_qty,0) other_chan_qty, -coalesce(ws_wc,0)+coalesce(cs_wc,0) other_chan_wholesale_cost, -coalesce(ws_sp,0)+coalesce(cs_sp,0) other_chan_sales_price -from ss -left join ws on (ws_sold_year=ss_sold_year and ws_item_sk=ss_item_sk and ws_customer_sk=ss_customer_sk) -left join cs on (cs_sold_year=ss_sold_year and cs_item_sk=ss_item_sk and cs_customer_sk=ss_customer_sk) -where (coalesce(ws_qty,0)>0 or coalesce(cs_qty, 0)>0) and ss_sold_year=2002 -order by - ss_item_sk, - ss_qty desc, ss_wc desc, ss_sp desc, - other_chan_qty, - other_chan_wholesale_cost, - other_chan_sales_price, - ratio -limit 100; - --- end template query78.tpl query 55 in stream 5 --- start template query57.tpl query 56 in stream 5 -with /* TPC-DS query57.tpl 0.70 */ v1 as( - select i_category, i_brand, - cc_name, - d_year, d_moy, - sum(cs_sales_price) sum_sales, - avg(sum(cs_sales_price)) over - (partition by i_category, i_brand, - cc_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - cc_name - order by d_year, d_moy) rn - from item, catalog_sales, date_dim, call_center - where cs_item_sk = i_item_sk and - cs_sold_date_sk = d_date_sk and - cc_call_center_sk= cs_call_center_sk and - ( - d_year = 1999 or - ( d_year = 1999-1 and d_moy =12) or - ( d_year = 1999+1 and d_moy =1) - ) - group by i_category, i_brand, - cc_name , d_year, d_moy), - v2 as( - select v1.i_category, v1.i_brand - ,v1.d_year, v1.d_moy - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1. cc_name = v1_lag. cc_name and - v1. cc_name = v1_lead. cc_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 1999 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, avg_monthly_sales - limit 100; - --- end template query57.tpl query 56 in stream 5 --- start template query46.tpl query 57 in stream 5 -select /* TPC-DS query46.tpl 0.23 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and (household_demographics.hd_dep_count = 9 or - household_demographics.hd_vehicle_count= 3) - and date_dim.d_dow in (6,0) - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_city in ('Jamestown','Sulphur Springs','New Hope','Clinton','Oakwood') - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,ca_city) dn,customer,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - limit 100; - --- end template query46.tpl query 57 in stream 5 --- start template query32.tpl query 58 in stream 5 -select /* TPC-DS query32.tpl 0.7 */ sum(cs_ext_discount_amt) as "excess discount amount" -from - catalog_sales - ,item - ,date_dim -where -i_manufact_id = 503 -and i_item_sk = cs_item_sk -and d_date between '1998-03-28' and - dateadd(day,90,cast('1998-03-28' as date)) -and d_date_sk = cs_sold_date_sk -and cs_ext_discount_amt - > ( - select - 1.3 * avg(cs_ext_discount_amt) - from - catalog_sales - ,date_dim - where - cs_item_sk = i_item_sk - and d_date between '1998-03-28' and - dateadd(day,90,cast('1998-03-28' as date)) - and d_date_sk = cs_sold_date_sk - ) -limit 100; - --- end template query32.tpl query 58 in stream 5 --- start template query24.tpl query 59 in stream 5 -with /* TPC-DS query24.tpl 0.92 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_net_profit) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip -and s_market_id=8 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'maroon' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; -with /* TPC-DS query24.tpl 0.92 part2 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_net_profit) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip - and s_market_id = 8 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'slate' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; - --- end template query24.tpl query 59 in stream 5 --- start template query38.tpl query 60 in stream 5 -select /* TPC-DS query38.tpl 0.54 */ count(*) from ( - select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1221 and 1221 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1221 and 1221 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1221 and 1221 + 11 -) hot_cust -limit 100; - --- end template query38.tpl query 60 in stream 5 --- start template query55.tpl query 61 in stream 5 -select /* TPC-DS query55.tpl 0.82 */ i_brand_id brand_id, i_brand brand, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=93 - and d_moy=12 - and d_year=2001 - group by i_brand, i_brand_id - order by ext_price desc, i_brand_id -limit 100 ; - --- end template query55.tpl query 61 in stream 5 --- start template query74.tpl query 62 in stream 5 -with /* TPC-DS query74.tpl 0.76 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,sum(ss_net_paid) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (2001,2001+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,sum(ws_net_paid) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - and d_year in (2001,2001+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - ) - select - t_s_secyear.customer_id, t_s_secyear.customer_first_name, t_s_secyear.customer_last_name - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.year = 2001 - and t_s_secyear.year = 2001+1 - and t_w_firstyear.year = 2001 - and t_w_secyear.year = 2001+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - order by 1,2,3 -limit 100; - --- end template query74.tpl query 62 in stream 5 --- start template query84.tpl query 63 in stream 5 -select /* TPC-DS query84.tpl 0.80 */ c_customer_id as customer_id - , coalesce(c_last_name,'') || ', ' || coalesce(c_first_name,'') as customername - from customer - ,customer_address - ,customer_demographics - ,household_demographics - ,income_band - ,store_returns - where ca_city = 'Mountain View' - and c_current_addr_sk = ca_address_sk - and ib_lower_bound >= 46572 - and ib_upper_bound <= 46572 + 50000 - and ib_income_band_sk = hd_income_band_sk - and cd_demo_sk = c_current_cdemo_sk - and hd_demo_sk = c_current_hdemo_sk - and sr_cdemo_sk = cd_demo_sk - order by c_customer_id - limit 100; - --- end template query84.tpl query 63 in stream 5 --- start template query89.tpl query 64 in stream 5 -select /* TPC-DS query89.tpl 0.56 */ * -from( -select i_category, i_class, i_brand, - s_store_name, s_company_name, - d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, s_store_name, s_company_name) - avg_monthly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - d_year in (2000) and - ((i_category in ('Books','Children','Men') and - i_class in ('travel','infants','sports-apparel') - ) - or (i_category in ('Shoes','Electronics','Home') and - i_class in ('mens','musical','lighting') - )) -group by i_category, i_class, i_brand, - s_store_name, s_company_name, d_moy) tmp1 -where case when (avg_monthly_sales <> 0) then (abs(sum_sales - avg_monthly_sales) / avg_monthly_sales) else null end > 0.1 -order by sum_sales - avg_monthly_sales, s_store_name -limit 100; - --- end template query89.tpl query 64 in stream 5 --- start template query83.tpl query 65 in stream 5 -with /* TPC-DS query83.tpl 0.96 */ sr_items as - (select i_item_id item_id, - sum(sr_return_quantity) sr_item_qty - from store_returns, - item, - date_dim - where sr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2002-07-15','2002-08-07','2002-11-17'))) - and sr_returned_date_sk = d_date_sk - group by i_item_id), - cr_items as - (select i_item_id item_id, - sum(cr_return_quantity) cr_item_qty - from catalog_returns, - item, - date_dim - where cr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2002-07-15','2002-08-07','2002-11-17'))) - and cr_returned_date_sk = d_date_sk - group by i_item_id), - wr_items as - (select i_item_id item_id, - sum(wr_return_quantity) wr_item_qty - from web_returns, - item, - date_dim - where wr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2002-07-15','2002-08-07','2002-11-17'))) - and wr_returned_date_sk = d_date_sk - group by i_item_id) - select sr_items.item_id - ,sr_item_qty - ,sr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 sr_dev - ,cr_item_qty - ,cr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 cr_dev - ,wr_item_qty - ,wr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 wr_dev - ,(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 average - from sr_items - ,cr_items - ,wr_items - where sr_items.item_id=cr_items.item_id - and sr_items.item_id=wr_items.item_id - order by sr_items.item_id - ,sr_item_qty - limit 100; - --- end template query83.tpl query 65 in stream 5 --- start template query31.tpl query 66 in stream 5 -with /* TPC-DS query31.tpl 0.50 */ ss as - (select ca_county,d_qoy, d_year,sum(ss_ext_sales_price) as store_sales - from store_sales,date_dim,customer_address - where ss_sold_date_sk = d_date_sk - and ss_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year), - ws as - (select ca_county,d_qoy, d_year,sum(ws_ext_sales_price) as web_sales - from web_sales,date_dim,customer_address - where ws_sold_date_sk = d_date_sk - and ws_bill_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year) - select - ss1.ca_county - ,ss1.d_year - ,ws2.web_sales/ws1.web_sales web_q1_q2_increase - ,ss2.store_sales/ss1.store_sales store_q1_q2_increase - ,ws3.web_sales/ws2.web_sales web_q2_q3_increase - ,ss3.store_sales/ss2.store_sales store_q2_q3_increase - from - ss ss1 - ,ss ss2 - ,ss ss3 - ,ws ws1 - ,ws ws2 - ,ws ws3 - where - ss1.d_qoy = 1 - and ss1.d_year = 1999 - and ss1.ca_county = ss2.ca_county - and ss2.d_qoy = 2 - and ss2.d_year = 1999 - and ss2.ca_county = ss3.ca_county - and ss3.d_qoy = 3 - and ss3.d_year = 1999 - and ss1.ca_county = ws1.ca_county - and ws1.d_qoy = 1 - and ws1.d_year = 1999 - and ws1.ca_county = ws2.ca_county - and ws2.d_qoy = 2 - and ws2.d_year = 1999 - and ws1.ca_county = ws3.ca_county - and ws3.d_qoy = 3 - and ws3.d_year =1999 - and case when ws1.web_sales > 0 then ws2.web_sales/ws1.web_sales else null end - > case when ss1.store_sales > 0 then ss2.store_sales/ss1.store_sales else null end - and case when ws2.web_sales > 0 then ws3.web_sales/ws2.web_sales else null end - > case when ss2.store_sales > 0 then ss3.store_sales/ss2.store_sales else null end - order by web_q2_q3_increase; - --- end template query31.tpl query 66 in stream 5 --- start template query26.tpl query 67 in stream 5 -select /* TPC-DS query26.tpl 0.85 */ i_item_id, - avg(cs_quantity) agg1, - avg(cs_list_price) agg2, - avg(cs_coupon_amt) agg3, - avg(cs_sales_price) agg4 - from catalog_sales, customer_demographics, date_dim, item, promotion - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd_demo_sk and - cs_promo_sk = p_promo_sk and - cd_gender = 'F' and - cd_marital_status = 'M' and - cd_education_status = 'Primary' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 2002 - group by i_item_id - order by i_item_id - limit 100; - --- end template query26.tpl query 67 in stream 5 --- start template query40.tpl query 68 in stream 5 -select /* TPC-DS query40.tpl 0.86 */ - w_state - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('1998-05-20' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_before - ,sum(case when (cast(d_date as date) >= cast ('1998-05-20' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_after - from - catalog_sales left outer join catalog_returns on - (cs_order_number = cr_order_number - and cs_item_sk = cr_item_sk) - ,warehouse - ,item - ,date_dim - where - i_current_price between 0.99 and 1.49 - and i_item_sk = cs_item_sk - and cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('1998-05-20' as date)) - and dateadd(day,30,cast ('1998-05-20' as date)) - group by - w_state,i_item_id - order by w_state,i_item_id -limit 100; - --- end template query40.tpl query 68 in stream 5 --- start template query14a.tpl query 69 in stream 5 -with /* TPC-DS query14a.tpl 0.69 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1998 AND 1998 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1998 AND 1998 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1998 AND 1998 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as - (select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2) x) -, - results AS -(select channel, i_brand_id, i_class_id, i_category_id, sum(sales) sum_sales, sum(number_sales) number_sales - from ( - select 'store' channel, i_brand_id,i_class_id - ,i_category_id,sum(ss_quantity*ss_list_price) sales - , count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1998+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales) - union all - select 'catalog' channel, i_brand_id,i_class_id,i_category_id, sum(cs_quantity*cs_list_price) sales, count(*) number_sales - from catalog_sales - ,item - ,date_dim - where cs_item_sk in (select ss_item_sk from cross_items) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1998+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(cs_quantity*cs_list_price) > (select average_sales from avg_sales) - union all - select 'web' channel, i_brand_id,i_class_id,i_category_id, sum(ws_quantity*ws_list_price) sales , count(*) number_sales - from web_sales - ,item - ,date_dim - where ws_item_sk in (select ss_item_sk from cross_items) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1998+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ws_quantity*ws_list_price) > (select average_sales from avg_sales) - ) y - group by channel, i_brand_id,i_class_id,i_category_id) - - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales -from ( - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales from results - union - select channel, i_brand_id, i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id, i_class_id - union - select channel, i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id - union - select channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel - union - select null as channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results) z -order by channel, i_brand_id, i_class_id, i_category_id - limit 100; -with /* TPC-DS query14a.tpl 0.69 part2 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1998 AND 1998 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1998 AND 1998 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1998 AND 1998 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as -(select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2) x) - select this_year.channel ty_channel - ,this_year.i_brand_id ty_brand - ,this_year.i_class_id ty_class - ,this_year.i_category_id ty_category - ,this_year.sales ty_sales - ,this_year.number_sales ty_number_sales - ,last_year.channel ly_channel - ,last_year.i_brand_id ly_brand - ,last_year.i_class_id ly_class - ,last_year.i_category_id ly_category - ,last_year.sales ly_sales - ,last_year.number_sales ly_number_sales -from - (select 'store' channel, i_brand_id,i_class_id,i_category_id - ,sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1998 + 1 - and d_moy = 12 - and d_dom = 20) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) this_year, - (select 'store' channel, i_brand_id,i_class_id - ,i_category_id, sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1998 - and d_moy = 12 - and d_dom = 20) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) last_year - where this_year.i_brand_id= last_year.i_brand_id - and this_year.i_class_id = last_year.i_class_id - and this_year.i_category_id = last_year.i_category_id - order by this_year.channel, this_year.i_brand_id, this_year.i_class_id, this_year.i_category_id - limit 100; - --- end template query14a.tpl query 69 in stream 5 --- start template query23.tpl query 70 in stream 5 -with /* TPC-DS query23.tpl 0.68 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (1998,1998+1,1998+2,1998+3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1998,1998+1,1998+2,1998+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * -from - max_store_sales)) - select sum(sales) - from (select cs_quantity*cs_list_price sales - from catalog_sales - ,date_dim - where d_year = 1998 - and d_moy = 2 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - union all - select ws_quantity*ws_list_price sales - from web_sales - ,date_dim - where d_year = 1998 - and d_moy = 2 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer)) - limit 100; -with /* TPC-DS query23.tpl 0.68 part2 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (1998,1998 + 1,1998 + 2,1998 + 3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1998,1998+1,1998+2,1998+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * - from max_store_sales)) - select c_last_name,c_first_name,sales - from (select c_last_name,c_first_name,sum(cs_quantity*cs_list_price) sales - from catalog_sales - ,customer - ,date_dim - where d_year = 1998 - and d_moy = 2 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and cs_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name - union all - select c_last_name,c_first_name,sum(ws_quantity*ws_list_price) sales - from web_sales - ,customer - ,date_dim - where d_year = 1998 - and d_moy = 2 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and ws_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name) - order by c_last_name,c_first_name,sales - limit 100; - --- end template query23.tpl query 70 in stream 5 --- start template query96.tpl query 71 in stream 5 -select /* TPC-DS query96.tpl 0.1 */ count(*) -from store_sales - ,household_demographics - ,time_dim, store -where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and household_demographics.hd_dep_count = 2 - and store.s_store_name = 'ese' -order by count(*) -limit 100; - --- end template query96.tpl query 71 in stream 5 --- start template query1.tpl query 72 in stream 5 -with /* TPC-DS query1.tpl 0.12 */ customer_total_return as -(select sr_customer_sk as ctr_customer_sk -,sr_store_sk as ctr_store_sk -,sum(SR_FEE) as ctr_total_return -from store_returns -,date_dim -where sr_returned_date_sk = d_date_sk -and d_year =2001 -group by sr_customer_sk -,sr_store_sk) - select c_customer_id -from customer_total_return ctr1 -,store -,customer -where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 -from customer_total_return ctr2 -where ctr1.ctr_store_sk = ctr2.ctr_store_sk) -and s_store_sk = ctr1.ctr_store_sk -and s_state = 'TX' -and ctr1.ctr_customer_sk = c_customer_sk -order by c_customer_id -limit 100; - --- end template query1.tpl query 72 in stream 5 --- start template query95.tpl query 73 in stream 5 -with /* TPC-DS query95.tpl 0.43 */ ws_wh as -(select ws1.ws_order_number,ws1.ws_warehouse_sk wh1,ws2.ws_warehouse_sk wh2 - from web_sales ws1,web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) - select - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2001-4-01' and - dateadd(day,60,cast('2001-4-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'OH' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and ws1.ws_order_number in (select ws_order_number - from ws_wh) -and ws1.ws_order_number in (select wr_order_number - from web_returns,ws_wh - where wr_order_number = ws_wh.ws_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query95.tpl query 73 in stream 5 --- start template query27a.tpl query 74 in stream 5 -with /* TPC-DS query27a.tpl 0.16 */ results as - (select i_item_id, - s_state, 0 as g_state, - ss_quantity agg1, - ss_list_price agg2, - ss_coupon_amt agg3, - ss_sales_price agg4 - from store_sales, customer_demographics, date_dim, store, item - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_store_sk = s_store_sk and - ss_cdemo_sk = cd_demo_sk and - cd_gender = 'F' and - cd_marital_status = 'S' and - cd_education_status = 'Primary' and - d_year = 2000 and - s_state in ('MI','OH', 'SC', 'MN', 'PA', 'NC') - ) - - select i_item_id, - s_state, g_state, agg1, agg2, agg3, agg4 - from ( - select i_item_id, s_state, 0 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4 from results - group by i_item_id, s_state - union all - select i_item_id, NULL AS s_state, 1 AS g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as s_state, 1 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - ) foo - order by i_item_id, s_state - limit 100; - --- end template query27a.tpl query 74 in stream 5 --- start template query44.tpl query 75 in stream 5 -select /* TPC-DS query44.tpl 0.4 */ asceding.rnk, i1.i_product_name best_performing, i2.i_product_name worst_performing -from(select * - from (select item_sk,rank() over (order by rank_col asc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 78 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 78 - and ss_cdemo_sk is null - group by ss_store_sk))V1)V11 - where rnk < 11) asceding, - (select * - from (select item_sk,rank() over (order by rank_col desc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 78 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 78 - and ss_cdemo_sk is null - group by ss_store_sk))V2)V21 - where rnk < 11) descending, -item i1, -item i2 -where asceding.rnk = descending.rnk - and i1.i_item_sk=asceding.item_sk - and i2.i_item_sk=descending.item_sk -order by asceding.rnk -limit 100; - --- end template query44.tpl query 75 in stream 5 --- start template query16.tpl query 76 in stream 5 -select /* TPC-DS query16.tpl 0.25 */ - count(distinct cs_order_number) as "order count" - ,sum(cs_ext_ship_cost) as "total shipping cost" - ,sum(cs_net_profit) as "total net profit" -from - catalog_sales cs1 - ,date_dim - ,customer_address - ,call_center -where - d_date between '1999-2-01' and - dateadd(day, 60, cast('1999-2-01' as date)) -and cs1.cs_ship_date_sk = d_date_sk -and cs1.cs_ship_addr_sk = ca_address_sk -and ca_state = 'MN' -and cs1.cs_call_center_sk = cc_call_center_sk -and cc_county in ('Kittitas County','Mobile County','Walker County','Barrow County', - 'Marshall County' -) -and exists (select * - from catalog_sales cs2 - where cs1.cs_order_number = cs2.cs_order_number - and cs1.cs_warehouse_sk <> cs2.cs_warehouse_sk) -and not exists(select * - from catalog_returns cr1 - where cs1.cs_order_number = cr1.cr_order_number) -order by count(distinct cs_order_number) -limit 100; - --- end template query16.tpl query 76 in stream 5 --- start template query64.tpl query 77 in stream 5 -with /* TPC-DS query64.tpl 0.20 */ cs_ui as - (select cs_item_sk - ,sum(cs_ext_list_price) as sale,sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit) as refund - from catalog_sales - ,catalog_returns - where cs_item_sk = cr_item_sk - and cs_order_number = cr_order_number - group by cs_item_sk - having sum(cs_ext_list_price)>2*sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit)), -cross_sales as - (select i_product_name product_name - ,i_item_sk item_sk - ,s_store_name store_name - ,s_zip store_zip - ,ad1.ca_street_number b_street_number - ,ad1.ca_street_name b_street_name - ,ad1.ca_city b_city - ,ad1.ca_zip b_zip - ,ad2.ca_street_number c_street_number - ,ad2.ca_street_name c_street_name - ,ad2.ca_city c_city - ,ad2.ca_zip c_zip - ,d1.d_year as syear - ,d2.d_year as fsyear - ,d3.d_year s2year - ,count(*) cnt - ,sum(ss_wholesale_cost) s1 - ,sum(ss_list_price) s2 - ,sum(ss_coupon_amt) s3 - FROM store_sales - ,store_returns - ,cs_ui - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,customer - ,customer_demographics cd1 - ,customer_demographics cd2 - ,promotion - ,household_demographics hd1 - ,household_demographics hd2 - ,customer_address ad1 - ,customer_address ad2 - ,income_band ib1 - ,income_band ib2 - ,item - WHERE ss_store_sk = s_store_sk AND - ss_sold_date_sk = d1.d_date_sk AND - ss_customer_sk = c_customer_sk AND - ss_cdemo_sk= cd1.cd_demo_sk AND - ss_hdemo_sk = hd1.hd_demo_sk AND - ss_addr_sk = ad1.ca_address_sk and - ss_item_sk = i_item_sk and - ss_item_sk = sr_item_sk and - ss_ticket_number = sr_ticket_number and - ss_item_sk = cs_ui.cs_item_sk and - c_current_cdemo_sk = cd2.cd_demo_sk AND - c_current_hdemo_sk = hd2.hd_demo_sk AND - c_current_addr_sk = ad2.ca_address_sk and - c_first_sales_date_sk = d2.d_date_sk and - c_first_shipto_date_sk = d3.d_date_sk and - ss_promo_sk = p_promo_sk and - hd1.hd_income_band_sk = ib1.ib_income_band_sk and - hd2.hd_income_band_sk = ib2.ib_income_band_sk and - cd1.cd_marital_status <> cd2.cd_marital_status and - i_color in ('peru','chiffon','salmon','lace','purple','antique') and - i_current_price between 36 and 36 + 10 and - i_current_price between 36 + 1 and 36 + 15 -group by i_product_name - ,i_item_sk - ,s_store_name - ,s_zip - ,ad1.ca_street_number - ,ad1.ca_street_name - ,ad1.ca_city - ,ad1.ca_zip - ,ad2.ca_street_number - ,ad2.ca_street_name - ,ad2.ca_city - ,ad2.ca_zip - ,d1.d_year - ,d2.d_year - ,d3.d_year -) -select cs1.product_name - ,cs1.store_name - ,cs1.store_zip - ,cs1.b_street_number - ,cs1.b_street_name - ,cs1.b_city - ,cs1.b_zip - ,cs1.c_street_number - ,cs1.c_street_name - ,cs1.c_city - ,cs1.c_zip - ,cs1.syear - ,cs1.cnt - ,cs1.s1 as s11 - ,cs1.s2 as s21 - ,cs1.s3 as s31 - ,cs2.s1 as s12 - ,cs2.s2 as s22 - ,cs2.s3 as s32 - ,cs2.syear - ,cs2.cnt -from cross_sales cs1,cross_sales cs2 -where cs1.item_sk=cs2.item_sk and - cs1.syear = 2000 and - cs2.syear = 2000 + 1 and - cs2.cnt <= cs1.cnt and - cs1.store_name = cs2.store_name and - cs1.store_zip = cs2.store_zip -order by cs1.product_name - ,cs1.store_name - ,cs2.cnt - ,cs1.s1 - ,cs2.s1; - --- end template query64.tpl query 77 in stream 5 --- start template query20.tpl query 78 in stream 5 -select /* TPC-DS query20.tpl 0.65 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(cs_ext_sales_price) as itemrevenue - ,sum(cs_ext_sales_price)*100/sum(sum(cs_ext_sales_price)) over - (partition by i_class) as revenueratio - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and i_category in ('Women', 'Books', 'Home') - and cs_sold_date_sk = d_date_sk - and d_date between cast('2000-04-08' as date) - and dateadd(day,30,cast('2000-04-08' as date)) - group by i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - order by i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query20.tpl query 78 in stream 5 --- start template query43.tpl query 79 in stream 5 -select /* TPC-DS query43.tpl 0.15 */ s_store_name, s_store_id, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from date_dim, store_sales, store - where d_date_sk = ss_sold_date_sk and - s_store_sk = ss_store_sk and - s_gmt_offset = -5 and - d_year = 1998 - group by s_store_name, s_store_id - order by s_store_name, s_store_id,sun_sales,mon_sales,tue_sales,wed_sales,thu_sales,fri_sales,sat_sales - limit 100; - --- end template query43.tpl query 79 in stream 5 --- start template query5a.tpl query 80 in stream 5 -with /* TPC-DS query5a.tpl 0.98 */ ssr as - (select s_store_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ss_store_sk as store_sk, - ss_sold_date_sk as date_sk, - ss_ext_sales_price as sales_price, - ss_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from store_sales - union all - select sr_store_sk as store_sk, - sr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - sr_return_amt as return_amt, - sr_net_loss as net_loss - from store_returns - ) salesreturns, - date_dim, - store - where date_sk = d_date_sk - and d_date between cast('2002-08-12' as date) - and dateadd(day,14,cast('2002-08-12' as date)) - and store_sk = s_store_sk - group by s_store_id) - , - csr as - (select cp_catalog_page_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select cs_catalog_page_sk as page_sk, - cs_sold_date_sk as date_sk, - cs_ext_sales_price as sales_price, - cs_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from catalog_sales - union all - select cr_catalog_page_sk as page_sk, - cr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - cr_return_amount as return_amt, - cr_net_loss as net_loss - from catalog_returns - ) salesreturns, - date_dim, - catalog_page - where date_sk = d_date_sk - and d_date between cast('2002-08-12' as date) - and dateadd(day,14,cast('2002-08-12' as date)) - and page_sk = cp_catalog_page_sk - group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ws_web_site_sk as wsr_web_site_sk, - ws_sold_date_sk as date_sk, - ws_ext_sales_price as sales_price, - ws_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from web_sales - union all - select ws_web_site_sk as wsr_web_site_sk, - wr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - wr_return_amt as return_amt, - wr_net_loss as net_loss - from web_returns left outer join web_sales on - ( wr_item_sk = ws_item_sk - and wr_order_number = ws_order_number) - ) salesreturns, - date_dim, - web_site - where date_sk = d_date_sk - and d_date between cast('2002-08-12' as date) - and dateadd(day,14,cast('2002-08-12' as date)) - and wsr_web_site_sk = web_site_sk - group by web_site_id) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || s_store_id as id - , sales - , returns - , (profit - profit_loss) as profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || cp_catalog_page_id as id - , sales - , returns - , (profit - profit_loss) as profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , (profit - profit_loss) as profit - from wsr - ) x - group by channel, id) - select channel, id, sales, returns, profit from ( - select channel, id, sales, returns, profit from results - union - select channel, null as id, sum(sales), sum(returns), sum(profit) from results group by channel - union - select null as channel, null as id, sum(sales), sum(returns), sum(profit) from results) foo -order by channel, id -limit 100; - --- end template query5a.tpl query 80 in stream 5 --- start template query47.tpl query 81 in stream 5 -with /* TPC-DS query47.tpl 0.42 */ v1 as( - select i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, - s_store_name, s_company_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - s_store_name, s_company_name - order by d_year, d_moy) rn - from item, store_sales, date_dim, store - where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - ( - d_year = 2000 or - ( d_year = 2000-1 and d_moy =12) or - ( d_year = 2000+1 and d_moy =1) - ) - group by i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy), - v2 as( - select v1.s_store_name - ,v1.d_year - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1.s_store_name = v1_lag.s_store_name and - v1.s_store_name = v1_lead.s_store_name and - v1.s_company_name = v1_lag.s_company_name and - v1.s_company_name = v1_lead.s_company_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 2000 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, psum - limit 100; - --- end template query47.tpl query 81 in stream 5 --- start template query10.tpl query 82 in stream 5 -select /* TPC-DS query10.tpl 0.26 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3, - cd_dep_count, - count(*) cnt4, - cd_dep_employed_count, - count(*) cnt5, - cd_dep_college_count, - count(*) cnt6 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_county in ('Mineral County','Lake County','Taylor County','Warren County','Meigs County') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 1 and 1+3) and - (exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 1 ANd 1+3) or - exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 1 and 1+3)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count -limit 100; - --- end template query10.tpl query 82 in stream 5 --- start template query70a.tpl query 83 in stream 5 -with /* TPC-DS query70a.tpl 0.34 */ results as -( select - sum(ss_net_profit) as total_sum ,s_state ,s_county, 0 as gstate, 0 as g_county - from - store_sales - ,date_dim d1 - ,store - where - d1.d_month_seq between 1190 and 1190 + 11 - and d1.d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - and s_state in - ( select s_state - from (select s_state as s_state, - rank() over ( partition by s_state order by sum(ss_net_profit) desc) as ranking - from store_sales, store, date_dim - where d_month_seq between 1190 and 1190 + 11 - and d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - group by s_state - ) tmp1 - where ranking <= 5) - group by s_state,s_county) , - results_rollup as -(select total_sum ,s_state ,s_county, 0 as g_state, 0 as g_county, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum,s_state, NULL as s_county, 0 as g_state, 1 as g_county, 1 as lochierarchy from results group by s_state - union - select sum(total_sum) as total_sum ,NULL as s_state ,NULL as s_county, 1 as g_state, 1 as g_county, 2 as lochierarchy from results) - select total_sum ,s_state ,s_county, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_county = 0 then s_state end - order by total_sum desc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then s_state end - ,rank_within_parent - limit 100; - --- end template query70a.tpl query 83 in stream 5 --- start template query39.tpl query 84 in stream 5 -with /* TPC-DS query39.tpl 0.5 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =2000 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=2 - and inv2.d_moy=2+1 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; -with /* TPC-DS query39.tpl 0.5 part2 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =2000 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=2 - and inv2.d_moy=2+1 - and inv1.cov > 1.5 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; - --- end template query39.tpl query 84 in stream 5 --- start template query72.tpl query 85 in stream 5 -select /* TPC-DS query72.tpl 0.87 */ i_item_desc - ,w_warehouse_name - ,d1.d_week_seq - ,sum(case when p_promo_sk is null then 1 else 0 end) no_promo - ,sum(case when p_promo_sk is not null then 1 else 0 end) promo - ,count(*) total_cnt -from catalog_sales -join inventory on (cs_item_sk = inv_item_sk) -join warehouse on (w_warehouse_sk=inv_warehouse_sk) -join item on (i_item_sk = cs_item_sk) -join customer_demographics on (cs_bill_cdemo_sk = cd_demo_sk) -join household_demographics on (cs_bill_hdemo_sk = hd_demo_sk) -join date_dim d1 on (cs_sold_date_sk = d1.d_date_sk) -join date_dim d2 on (inv_date_sk = d2.d_date_sk) -join date_dim d3 on (cs_ship_date_sk = d3.d_date_sk) -left outer join promotion on (cs_promo_sk=p_promo_sk) -left outer join catalog_returns on (cr_item_sk = cs_item_sk and cr_order_number = cs_order_number) -where d1.d_week_seq = d2.d_week_seq - and inv_quantity_on_hand < cs_quantity - and d3.d_date > d1.d_date + 5 - and hd_buy_potential = '>10000' - and d1.d_year = 2000 - and cd_marital_status = 'M' -group by i_item_desc,w_warehouse_name,d1.d_week_seq -order by total_cnt desc, i_item_desc, w_warehouse_name, d_week_seq -limit 100; - --- end template query72.tpl query 85 in stream 5 --- start template query75.tpl query 86 in stream 5 -WITH /* TPC-DS query75.tpl 0.3 */ all_sales AS ( - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,SUM(sales_cnt) AS sales_cnt - ,SUM(sales_amt) AS sales_amt - FROM (SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,cs_quantity - COALESCE(cr_return_quantity,0) AS sales_cnt - ,cs_ext_sales_price - COALESCE(cr_return_amount,0.0) AS sales_amt - FROM catalog_sales JOIN item ON i_item_sk=cs_item_sk - JOIN date_dim ON d_date_sk=cs_sold_date_sk - LEFT JOIN catalog_returns ON (cs_order_number=cr_order_number - AND cs_item_sk=cr_item_sk) - WHERE i_category='Women' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ss_quantity - COALESCE(sr_return_quantity,0) AS sales_cnt - ,ss_ext_sales_price - COALESCE(sr_return_amt,0.0) AS sales_amt - FROM store_sales JOIN item ON i_item_sk=ss_item_sk - JOIN date_dim ON d_date_sk=ss_sold_date_sk - LEFT JOIN store_returns ON (ss_ticket_number=sr_ticket_number - AND ss_item_sk=sr_item_sk) - WHERE i_category='Women' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ws_quantity - COALESCE(wr_return_quantity,0) AS sales_cnt - ,ws_ext_sales_price - COALESCE(wr_return_amt,0.0) AS sales_amt - FROM web_sales JOIN item ON i_item_sk=ws_item_sk - JOIN date_dim ON d_date_sk=ws_sold_date_sk - LEFT JOIN web_returns ON (ws_order_number=wr_order_number - AND ws_item_sk=wr_item_sk) - WHERE i_category='Women') sales_detail - GROUP BY d_year, i_brand_id, i_class_id, i_category_id, i_manufact_id) - SELECT prev_yr.d_year AS prev_year - ,curr_yr.d_year AS year - ,curr_yr.i_brand_id - ,curr_yr.i_class_id - ,curr_yr.i_category_id - ,curr_yr.i_manufact_id - ,prev_yr.sales_cnt AS prev_yr_cnt - ,curr_yr.sales_cnt AS curr_yr_cnt - ,curr_yr.sales_cnt-prev_yr.sales_cnt AS sales_cnt_diff - ,curr_yr.sales_amt-prev_yr.sales_amt AS sales_amt_diff - FROM all_sales curr_yr, all_sales prev_yr - WHERE curr_yr.i_brand_id=prev_yr.i_brand_id - AND curr_yr.i_class_id=prev_yr.i_class_id - AND curr_yr.i_category_id=prev_yr.i_category_id - AND curr_yr.i_manufact_id=prev_yr.i_manufact_id - AND curr_yr.d_year=2002 - AND prev_yr.d_year=2002-1 - AND CAST(curr_yr.sales_cnt AS DECIMAL(17,2))/CAST(prev_yr.sales_cnt AS DECIMAL(17,2))<0.9 - ORDER BY sales_cnt_diff,sales_amt_diff - limit 100; - --- end template query75.tpl query 86 in stream 5 --- start template query12.tpl query 87 in stream 5 -select /* TPC-DS query12.tpl 0.64 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ws_ext_sales_price) as itemrevenue - ,sum(ws_ext_sales_price)*100/sum(sum(ws_ext_sales_price)) over - (partition by i_class) as revenueratio -from - web_sales - ,item - ,date_dim -where - ws_item_sk = i_item_sk - and i_category in ('Shoes', 'Children', 'Books') - and ws_sold_date_sk = d_date_sk - and d_date between cast('2001-02-04' as date) - and dateadd(day,30,cast('2001-02-04' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query12.tpl query 87 in stream 5 --- start template query37.tpl query 88 in stream 5 -select /* TPC-DS query37.tpl 0.31 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, catalog_sales - where i_current_price between 53 and 53 + 30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('1998-03-04' as date) and dateadd(day,60,cast('1998-03-04' as date)) - and i_manufact_id in (773,826,710,954) - and inv_quantity_on_hand between 100 and 500 - and cs_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query37.tpl query 88 in stream 5 --- start template query15.tpl query 89 in stream 5 -select /* TPC-DS query15.tpl 0.57 */ ca_zip - ,sum(cs_sales_price) - from catalog_sales - ,customer - ,customer_address - ,date_dim - where cs_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', - '85392', '85460', '80348', '81792') - or ca_state in ('CA','WA','GA') - or cs_sales_price > 500) - and cs_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 1999 - group by ca_zip - order by ca_zip - limit 100; - --- end template query15.tpl query 89 in stream 5 --- start template query59.tpl query 90 in stream 5 -with /* TPC-DS query59.tpl 0.30 */ wss as - (select d_week_seq, - ss_store_sk, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - group by d_week_seq,ss_store_sk - ) - select s_store_name1,s_store_id1,d_week_seq1 - ,sun_sales1/sun_sales2,mon_sales1/mon_sales2 - ,tue_sales1/tue_sales2,wed_sales1/wed_sales2,thu_sales1/thu_sales2 - ,fri_sales1/fri_sales2,sat_sales1/sat_sales2 - from - (select s_store_name s_store_name1,wss.d_week_seq d_week_seq1 - ,s_store_id s_store_id1,sun_sales sun_sales1 - ,mon_sales mon_sales1,tue_sales tue_sales1 - ,wed_sales wed_sales1,thu_sales thu_sales1 - ,fri_sales fri_sales1,sat_sales sat_sales1 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1194 and 1194 + 11) y, - (select s_store_name s_store_name2,wss.d_week_seq d_week_seq2 - ,s_store_id s_store_id2,sun_sales sun_sales2 - ,mon_sales mon_sales2,tue_sales tue_sales2 - ,wed_sales wed_sales2,thu_sales thu_sales2 - ,fri_sales fri_sales2,sat_sales sat_sales2 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1194+ 12 and 1194 + 23) x - where s_store_id1=s_store_id2 - and d_week_seq1=d_week_seq2-52 - order by s_store_name1,s_store_id1,d_week_seq1 -limit 100; - --- end template query59.tpl query 90 in stream 5 --- start template query91.tpl query 91 in stream 5 -select /* TPC-DS query91.tpl 0.13 */ - cc_call_center_id Call_Center, - cc_name Call_Center_Name, - cc_manager Manager, - sum(cr_net_loss) Returns_Loss -from - call_center, - catalog_returns, - date_dim, - customer, - customer_address, - customer_demographics, - household_demographics -where - cr_call_center_sk = cc_call_center_sk -and cr_returned_date_sk = d_date_sk -and cr_returning_customer_sk= c_customer_sk -and cd_demo_sk = c_current_cdemo_sk -and hd_demo_sk = c_current_hdemo_sk -and ca_address_sk = c_current_addr_sk -and d_year = 1998 -and d_moy = 12 -and ( (cd_marital_status = 'M' and cd_education_status = 'Unknown') - or(cd_marital_status = 'W' and cd_education_status = 'Advanced Degree')) -and hd_buy_potential like '0-500%' -and ca_gmt_offset = -6 -group by cc_call_center_id,cc_name,cc_manager,cd_marital_status,cd_education_status -order by sum(cr_net_loss) desc; - --- end template query91.tpl query 91 in stream 5 --- start template query99.tpl query 92 in stream 5 -select /* TPC-DS query99.tpl 0.94 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 30) and - (cs_ship_date_sk - cs_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 60) and - (cs_ship_date_sk - cs_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 90) and - (cs_ship_date_sk - cs_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - catalog_sales - ,warehouse - ,ship_mode - ,call_center - ,date_dim -where - d_month_seq between 1193 and 1193 + 11 -and cs_ship_date_sk = d_date_sk -and cs_warehouse_sk = w_warehouse_sk -and cs_ship_mode_sk = sm_ship_mode_sk -and cs_call_center_sk = cc_call_center_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -limit 100; - --- end template query99.tpl query 92 in stream 5 --- start template query41.tpl query 93 in stream 5 -select /* TPC-DS query41.tpl 0.62 */ distinct(i_product_name) - from item i1 - where i_manufact_id between 687 and 687+40 - and (select count(*) as item_cnt - from item - where (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'puff' or i_color = 'purple') and - (i_units = 'N/A' or i_units = 'Dram') and - (i_size = 'medium' or i_size = 'extra large') - ) or - (i_category = 'Women' and - (i_color = 'navy' or i_color = 'saddle') and - (i_units = 'Ton' or i_units = 'Pallet') and - (i_size = 'small' or i_size = 'large') - ) or - (i_category = 'Men' and - (i_color = 'yellow' or i_color = 'ivory') and - (i_units = 'Bunch' or i_units = 'Each') and - (i_size = 'N/A' or i_size = 'economy') - ) or - (i_category = 'Men' and - (i_color = 'blanched' or i_color = 'white') and - (i_units = 'Box' or i_units = 'Case') and - (i_size = 'medium' or i_size = 'extra large') - ))) or - (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'plum' or i_color = 'burlywood') and - (i_units = 'Carton' or i_units = 'Unknown') and - (i_size = 'medium' or i_size = 'extra large') - ) or - (i_category = 'Women' and - (i_color = 'smoke' or i_color = 'rose') and - (i_units = 'Oz' or i_units = 'Cup') and - (i_size = 'small' or i_size = 'large') - ) or - (i_category = 'Men' and - (i_color = 'linen' or i_color = 'aquamarine') and - (i_units = 'Gross' or i_units = 'Pound') and - (i_size = 'N/A' or i_size = 'economy') - ) or - (i_category = 'Men' and - (i_color = 'orchid' or i_color = 'lavender') and - (i_units = 'Lb' or i_units = 'Gram') and - (i_size = 'medium' or i_size = 'extra large') - )))) > 0 - order by i_product_name - limit 100; - --- end template query41.tpl query 93 in stream 5 --- start template query9.tpl query 94 in stream 5 -select /* TPC-DS query9.tpl 0.49 */ case when (select count(*) - from store_sales - where ss_quantity between 1 and 20) > 84676842 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 1 and 20) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 1 and 20) end bucket1 , - case when (select count(*) - from store_sales - where ss_quantity between 21 and 40) > 38436486 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 21 and 40) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 21 and 40) end bucket2, - case when (select count(*) - from store_sales - where ss_quantity between 41 and 60) > 27330240 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 41 and 60) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 41 and 60) end bucket3, - case when (select count(*) - from store_sales - where ss_quantity between 61 and 80) > 25343 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 61 and 80) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 61 and 80) end bucket4, - case when (select count(*) - from store_sales - where ss_quantity between 81 and 100) > 71846204 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 81 and 100) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 81 and 100) end bucket5 -from reason -where r_reason_sk = 1 -; - --- end template query9.tpl query 94 in stream 5 --- start template query86a.tpl query 95 in stream 5 -with /* TPC-DS query86a.tpl 0.11 */ results as -( select sum(ws_net_paid) as total_sum, i_category, i_class, 0 as g_category, 0 as g_class - from - web_sales - ,date_dim d1 - ,item - where - d1.d_month_seq between 1182 and 1182+11 - and d1.d_date_sk = ws_sold_date_sk - and i_item_sk = ws_item_sk - group by i_category,i_class - ) , - - results_rollup as -( select total_sum ,i_category ,i_class, g_category, g_class, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum, i_category, NULL as i_class, 0 as g_category, 1 as g_class, 1 as lochierarchy from results group by i_category - union - select sum(total_sum) as total_sum, NULL as i_category, NULL as i_class, 1 as g_category, 1 as g_class, 2 as lochierarchy from results) - select - total_sum ,i_category ,i_class, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_class = 0 then i_category end - order by total_sum desc) as rank_within_parent - from - results_rollup - order by - lochierarchy desc, - case when lochierarchy = 0 then i_category end, - rank_within_parent - limit 100; - --- end template query86a.tpl query 95 in stream 5 --- start template query34.tpl query 96 in stream 5 -select /* TPC-DS query34.tpl 0.73 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (date_dim.d_dom between 1 and 3 or date_dim.d_dom between 25 and 28) - and (household_demographics.hd_buy_potential = '501-1000' or - household_demographics.hd_buy_potential = 'Unknown') - and household_demographics.hd_vehicle_count > 0 - and (case when household_demographics.hd_vehicle_count > 0 - then household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count - else null - end) > 1.2 - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_county in ('Sierra County','Adams County','San Miguel County','Mesa County', - 'Appanoose County','Levy County','Wadena County','Fairfield County') - group by ss_ticket_number,ss_customer_sk) dn,customer - where ss_customer_sk = c_customer_sk - and cnt between 15 and 20 - order by c_last_name,c_first_name,c_salutation,c_preferred_cust_flag desc, ss_ticket_number; - --- end template query34.tpl query 96 in stream 5 --- start template query82.tpl query 97 in stream 5 -select /* TPC-DS query82.tpl 0.67 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, store_sales - where i_current_price between 29 and 29+30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('1998-03-17' as date) and dateadd(day,60,cast('1998-03-17' as date)) - and i_manufact_id in (28,183,805,309) - and inv_quantity_on_hand between 100 and 500 - and ss_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query82.tpl query 97 in stream 5 --- start template query29.tpl query 98 in stream 5 -select /* TPC-DS query29.tpl 0.53 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,min(ss_quantity) as store_sales_quantity - ,min(sr_return_quantity) as store_returns_quantity - ,min(cs_quantity) as catalog_sales_quantity - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 1999 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 4 + 3 - and d2.d_year = 1999 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_year in (1999,1999+1,1999+2) - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query29.tpl query 98 in stream 5 --- start template query25.tpl query 99 in stream 5 -select /* TPC-DS query25.tpl 0.9 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,sum(ss_net_profit) as store_sales_profit - ,sum(sr_net_loss) as store_returns_loss - ,sum(cs_net_profit) as catalog_sales_profit - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 2001 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 10 - and d2.d_year = 2001 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_moy between 4 and 10 - and d3.d_year = 2001 - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query25.tpl query 99 in stream 5 diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/10TB/queries/query_6.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/10TB/queries/query_6.sql deleted file mode 100644 index 6ec798a9..00000000 --- a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/10TB/queries/query_6.sql +++ /dev/null @@ -1,5027 +0,0 @@ --- start template query34.tpl query 1 in stream 6 -select /* TPC-DS query34.tpl 0.73 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (date_dim.d_dom between 1 and 3 or date_dim.d_dom between 25 and 28) - and (household_demographics.hd_buy_potential = '1001-5000' or - household_demographics.hd_buy_potential = '0-500') - and household_demographics.hd_vehicle_count > 0 - and (case when household_demographics.hd_vehicle_count > 0 - then household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count - else null - end) > 1.2 - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_county in ('Orange County','Jefferson Davis Parish','Coal County','Fairfield County', - 'Harper County','Dauphin County','Williamson County','Terrell County') - group by ss_ticket_number,ss_customer_sk) dn,customer - where ss_customer_sk = c_customer_sk - and cnt between 15 and 20 - order by c_last_name,c_first_name,c_salutation,c_preferred_cust_flag desc, ss_ticket_number; - --- end template query34.tpl query 1 in stream 6 --- start template query88.tpl query 2 in stream 6 -select /* TPC-DS query88.tpl 0.66 */ * -from - (select count(*) h8_30_to_9 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s1, - (select count(*) h9_to_9_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s2, - (select count(*) h9_30_to_10 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s3, - (select count(*) h10_to_10_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s4, - (select count(*) h10_30_to_11 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s5, - (select count(*) h11_to_11_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s6, - (select count(*) h11_30_to_12 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s7, - (select count(*) h12_to_12_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 12 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s8 -; - --- end template query88.tpl query 2 in stream 6 --- start template query44.tpl query 3 in stream 6 -select /* TPC-DS query44.tpl 0.4 */ asceding.rnk, i1.i_product_name best_performing, i2.i_product_name worst_performing -from(select * - from (select item_sk,rank() over (order by rank_col asc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 153 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 153 - and ss_customer_sk is null - group by ss_store_sk))V1)V11 - where rnk < 11) asceding, - (select * - from (select item_sk,rank() over (order by rank_col desc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 153 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 153 - and ss_customer_sk is null - group by ss_store_sk))V2)V21 - where rnk < 11) descending, -item i1, -item i2 -where asceding.rnk = descending.rnk - and i1.i_item_sk=asceding.item_sk - and i2.i_item_sk=descending.item_sk -order by asceding.rnk -limit 100; - --- end template query44.tpl query 3 in stream 6 --- start template query94.tpl query 4 in stream 6 -select /* TPC-DS query94.tpl 0.17 */ - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2000-4-01' and - dateadd(day,60,cast('2000-4-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'AR' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and exists (select * - from web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) -and not exists(select * - from web_returns wr1 - where ws1.ws_order_number = wr1.wr_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query94.tpl query 4 in stream 6 --- start template query50.tpl query 5 in stream 6 -select /* TPC-DS query50.tpl 0.60 */ - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 30) and - (sr_returned_date_sk - ss_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 60) and - (sr_returned_date_sk - ss_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 90) and - (sr_returned_date_sk - ss_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - store_sales - ,store_returns - ,store - ,date_dim d1 - ,date_dim d2 -where - d2.d_year = 2001 -and d2.d_moy = 9 -and ss_ticket_number = sr_ticket_number -and ss_item_sk = sr_item_sk -and ss_sold_date_sk = d1.d_date_sk -and sr_returned_date_sk = d2.d_date_sk -and ss_customer_sk = sr_customer_sk -and ss_store_sk = s_store_sk -group by - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -order by s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -limit 100; - --- end template query50.tpl query 5 in stream 6 --- start template query5a.tpl query 6 in stream 6 -with /* TPC-DS query5a.tpl 0.98 */ ssr as - (select s_store_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ss_store_sk as store_sk, - ss_sold_date_sk as date_sk, - ss_ext_sales_price as sales_price, - ss_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from store_sales - union all - select sr_store_sk as store_sk, - sr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - sr_return_amt as return_amt, - sr_net_loss as net_loss - from store_returns - ) salesreturns, - date_dim, - store - where date_sk = d_date_sk - and d_date between cast('1999-08-17' as date) - and dateadd(day,14,cast('1999-08-17' as date)) - and store_sk = s_store_sk - group by s_store_id) - , - csr as - (select cp_catalog_page_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select cs_catalog_page_sk as page_sk, - cs_sold_date_sk as date_sk, - cs_ext_sales_price as sales_price, - cs_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from catalog_sales - union all - select cr_catalog_page_sk as page_sk, - cr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - cr_return_amount as return_amt, - cr_net_loss as net_loss - from catalog_returns - ) salesreturns, - date_dim, - catalog_page - where date_sk = d_date_sk - and d_date between cast('1999-08-17' as date) - and dateadd(day,14,cast('1999-08-17' as date)) - and page_sk = cp_catalog_page_sk - group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ws_web_site_sk as wsr_web_site_sk, - ws_sold_date_sk as date_sk, - ws_ext_sales_price as sales_price, - ws_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from web_sales - union all - select ws_web_site_sk as wsr_web_site_sk, - wr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - wr_return_amt as return_amt, - wr_net_loss as net_loss - from web_returns left outer join web_sales on - ( wr_item_sk = ws_item_sk - and wr_order_number = ws_order_number) - ) salesreturns, - date_dim, - web_site - where date_sk = d_date_sk - and d_date between cast('1999-08-17' as date) - and dateadd(day,14,cast('1999-08-17' as date)) - and wsr_web_site_sk = web_site_sk - group by web_site_id) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || s_store_id as id - , sales - , returns - , (profit - profit_loss) as profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || cp_catalog_page_id as id - , sales - , returns - , (profit - profit_loss) as profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , (profit - profit_loss) as profit - from wsr - ) x - group by channel, id) - select channel, id, sales, returns, profit from ( - select channel, id, sales, returns, profit from results - union - select channel, null as id, sum(sales), sum(returns), sum(profit) from results group by channel - union - select null as channel, null as id, sum(sales), sum(returns), sum(profit) from results) foo -order by channel, id -limit 100; - --- end template query5a.tpl query 6 in stream 6 --- start template query53.tpl query 7 in stream 6 -select /* TPC-DS query53.tpl 0.88 */ * from -(select i_manufact_id, -sum(ss_sales_price) sum_sales, -avg(sum(ss_sales_price)) over (partition by i_manufact_id) avg_quarterly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and -ss_sold_date_sk = d_date_sk and -ss_store_sk = s_store_sk and -d_month_seq in (1211,1211+1,1211+2,1211+3,1211+4,1211+5,1211+6,1211+7,1211+8,1211+9,1211+10,1211+11) and -((i_category in ('Books','Children','Electronics') and -i_class in ('personal','portable','reference','self-help') and -i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) -or(i_category in ('Women','Music','Men') and -i_class in ('accessories','classical','fragrances','pants') and -i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manufact_id, d_qoy ) tmp1 -where case when avg_quarterly_sales > 0 - then abs (sum_sales - avg_quarterly_sales)/ avg_quarterly_sales - else null end > 0.1 -order by avg_quarterly_sales, - sum_sales, - i_manufact_id -limit 100; - --- end template query53.tpl query 7 in stream 6 --- start template query7.tpl query 8 in stream 6 -select /* TPC-DS query7.tpl 0.2 */ i_item_id, - avg(ss_quantity) agg1, - avg(ss_list_price) agg2, - avg(ss_coupon_amt) agg3, - avg(ss_sales_price) agg4 - from store_sales, customer_demographics, date_dim, item, promotion - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_cdemo_sk = cd_demo_sk and - ss_promo_sk = p_promo_sk and - cd_gender = 'M' and - cd_marital_status = 'W' and - cd_education_status = '4 yr Degree' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 1999 - group by i_item_id - order by i_item_id - limit 100; - --- end template query7.tpl query 8 in stream 6 --- start template query58.tpl query 9 in stream 6 -with /* TPC-DS query58.tpl 0.19 */ ss_items as - (select i_item_id item_id - ,sum(ss_ext_sales_price) ss_item_rev - from store_sales - ,item - ,date_dim - where ss_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '1998-03-24')) - and ss_sold_date_sk = d_date_sk - group by i_item_id), - cs_items as - (select i_item_id item_id - ,sum(cs_ext_sales_price) cs_item_rev - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '1998-03-24')) - and cs_sold_date_sk = d_date_sk - group by i_item_id), - ws_items as - (select i_item_id item_id - ,sum(ws_ext_sales_price) ws_item_rev - from web_sales - ,item - ,date_dim - where ws_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq =(select d_week_seq - from date_dim - where d_date = '1998-03-24')) - and ws_sold_date_sk = d_date_sk - group by i_item_id) - select ss_items.item_id - ,ss_item_rev - ,ss_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ss_dev - ,cs_item_rev - ,cs_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 cs_dev - ,ws_item_rev - ,ws_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ws_dev - ,(ss_item_rev+cs_item_rev+ws_item_rev)/3 average - from ss_items,cs_items,ws_items - where ss_items.item_id=cs_items.item_id - and ss_items.item_id=ws_items.item_id - and ss_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - and ss_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and cs_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and cs_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and ws_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and ws_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - order by item_id - ,ss_item_rev - limit 100; - --- end template query58.tpl query 9 in stream 6 --- start template query20.tpl query 10 in stream 6 -select /* TPC-DS query20.tpl 0.65 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(cs_ext_sales_price) as itemrevenue - ,sum(cs_ext_sales_price)*100/sum(sum(cs_ext_sales_price)) over - (partition by i_class) as revenueratio - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and i_category in ('Jewelry', 'Shoes', 'Children') - and cs_sold_date_sk = d_date_sk - and d_date between cast('1998-03-13' as date) - and dateadd(day,30,cast('1998-03-13' as date)) - group by i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - order by i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query20.tpl query 10 in stream 6 --- start template query75.tpl query 11 in stream 6 -WITH /* TPC-DS query75.tpl 0.3 */ all_sales AS ( - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,SUM(sales_cnt) AS sales_cnt - ,SUM(sales_amt) AS sales_amt - FROM (SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,cs_quantity - COALESCE(cr_return_quantity,0) AS sales_cnt - ,cs_ext_sales_price - COALESCE(cr_return_amount,0.0) AS sales_amt - FROM catalog_sales JOIN item ON i_item_sk=cs_item_sk - JOIN date_dim ON d_date_sk=cs_sold_date_sk - LEFT JOIN catalog_returns ON (cs_order_number=cr_order_number - AND cs_item_sk=cr_item_sk) - WHERE i_category='Men' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ss_quantity - COALESCE(sr_return_quantity,0) AS sales_cnt - ,ss_ext_sales_price - COALESCE(sr_return_amt,0.0) AS sales_amt - FROM store_sales JOIN item ON i_item_sk=ss_item_sk - JOIN date_dim ON d_date_sk=ss_sold_date_sk - LEFT JOIN store_returns ON (ss_ticket_number=sr_ticket_number - AND ss_item_sk=sr_item_sk) - WHERE i_category='Men' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ws_quantity - COALESCE(wr_return_quantity,0) AS sales_cnt - ,ws_ext_sales_price - COALESCE(wr_return_amt,0.0) AS sales_amt - FROM web_sales JOIN item ON i_item_sk=ws_item_sk - JOIN date_dim ON d_date_sk=ws_sold_date_sk - LEFT JOIN web_returns ON (ws_order_number=wr_order_number - AND ws_item_sk=wr_item_sk) - WHERE i_category='Men') sales_detail - GROUP BY d_year, i_brand_id, i_class_id, i_category_id, i_manufact_id) - SELECT prev_yr.d_year AS prev_year - ,curr_yr.d_year AS year - ,curr_yr.i_brand_id - ,curr_yr.i_class_id - ,curr_yr.i_category_id - ,curr_yr.i_manufact_id - ,prev_yr.sales_cnt AS prev_yr_cnt - ,curr_yr.sales_cnt AS curr_yr_cnt - ,curr_yr.sales_cnt-prev_yr.sales_cnt AS sales_cnt_diff - ,curr_yr.sales_amt-prev_yr.sales_amt AS sales_amt_diff - FROM all_sales curr_yr, all_sales prev_yr - WHERE curr_yr.i_brand_id=prev_yr.i_brand_id - AND curr_yr.i_class_id=prev_yr.i_class_id - AND curr_yr.i_category_id=prev_yr.i_category_id - AND curr_yr.i_manufact_id=prev_yr.i_manufact_id - AND curr_yr.d_year=1999 - AND prev_yr.d_year=1999-1 - AND CAST(curr_yr.sales_cnt AS DECIMAL(17,2))/CAST(prev_yr.sales_cnt AS DECIMAL(17,2))<0.9 - ORDER BY sales_cnt_diff,sales_amt_diff - limit 100; - --- end template query75.tpl query 11 in stream 6 --- start template query73.tpl query 12 in stream 6 -select /* TPC-DS query73.tpl 0.79 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_buy_potential = '1001-5000' or - household_demographics.hd_buy_potential = 'Unknown') - and household_demographics.hd_vehicle_count > 0 - and case when household_demographics.hd_vehicle_count > 0 then - household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count else null end > 1 - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_county in ('Mesa County','Richland County','Dauphin County','Jackson County') - group by ss_ticket_number,ss_customer_sk) dj,customer - where ss_customer_sk = c_customer_sk - and cnt between 1 and 5 - order by cnt desc, c_last_name asc; - --- end template query73.tpl query 12 in stream 6 --- start template query91.tpl query 13 in stream 6 -select /* TPC-DS query91.tpl 0.13 */ - cc_call_center_id Call_Center, - cc_name Call_Center_Name, - cc_manager Manager, - sum(cr_net_loss) Returns_Loss -from - call_center, - catalog_returns, - date_dim, - customer, - customer_address, - customer_demographics, - household_demographics -where - cr_call_center_sk = cc_call_center_sk -and cr_returned_date_sk = d_date_sk -and cr_returning_customer_sk= c_customer_sk -and cd_demo_sk = c_current_cdemo_sk -and hd_demo_sk = c_current_hdemo_sk -and ca_address_sk = c_current_addr_sk -and d_year = 2000 -and d_moy = 11 -and ( (cd_marital_status = 'M' and cd_education_status = 'Unknown') - or(cd_marital_status = 'W' and cd_education_status = 'Advanced Degree')) -and hd_buy_potential like '0-500%' -and ca_gmt_offset = -6 -group by cc_call_center_id,cc_name,cc_manager,cd_marital_status,cd_education_status -order by sum(cr_net_loss) desc; - --- end template query91.tpl query 13 in stream 6 --- start template query36a.tpl query 14 in stream 6 -with /* TPC-DS query36a.tpl 0.21 */ results as - (select - sum(ss_net_profit) as ss_net_profit, sum(ss_ext_sales_price) as ss_ext_sales_price, - sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin - ,i_category - ,i_class - ,0 as g_category, 0 as g_class - from - store_sales - ,date_dim d1 - ,item - ,store - where - d1.d_year = 1999 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and s_state in ('NE','TN','IN','MO', - 'WA','CO','WV','SC') - group by i_category,i_class) - , - results_rollup as - (select gross_margin ,i_category ,i_class,0 as t_category, 0 as t_class, 0 as lochierarchy from results - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - i_category, NULL AS i_class, 0 as t_category, 1 as t_class, 1 as lochierarchy from results group by i_category - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - NULL AS i_category ,NULL AS i_class, 1 as t_category, 1 as t_class, 2 as lochierarchy from results) - select - gross_margin ,i_category ,i_class, lochierarchy,rank() over ( - partition by lochierarchy, case when t_class = 0 then i_category end - order by gross_margin asc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then i_category end - ,rank_within_parent - limit 100; - --- end template query36a.tpl query 14 in stream 6 --- start template query11.tpl query 15 in stream 6 -with /* TPC-DS query11.tpl 0.51 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ss_ext_list_price-ss_ext_discount_amt) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ws_ext_list_price-ws_ext_discount_amt) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_login - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 1999 - and t_s_secyear.dyear = 1999+1 - and t_w_firstyear.dyear = 1999 - and t_w_secyear.dyear = 1999+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else 0.0 end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else 0.0 end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_login -limit 100; - --- end template query11.tpl query 15 in stream 6 --- start template query80a.tpl query 16 in stream 6 -with /* TPC-DS query80a.tpl 0.6 */ ssr as - (select s_store_id as store_id, - sum(ss_ext_sales_price) as sales, - sum(coalesce(sr_return_amt, 0)) as returns, - sum(ss_net_profit - coalesce(sr_net_loss, 0)) as profit - from store_sales left outer join store_returns on - (ss_item_sk = sr_item_sk and ss_ticket_number = sr_ticket_number), - date_dim, - store, - item, - promotion - where ss_sold_date_sk = d_date_sk - and d_date between cast('2001-08-08' as date) - and dateadd(day,30,cast('2001-08-08' as date)) - and ss_store_sk = s_store_sk - and ss_item_sk = i_item_sk - and i_current_price > 50 - and ss_promo_sk = p_promo_sk - and p_channel_tv = 'N' - group by s_store_id) - , - csr as - (select cp_catalog_page_id as catalog_page_id, - sum(cs_ext_sales_price) as sales, - sum(coalesce(cr_return_amount, 0)) as returns, - sum(cs_net_profit - coalesce(cr_net_loss, 0)) as profit - from catalog_sales left outer join catalog_returns on - (cs_item_sk = cr_item_sk and cs_order_number = cr_order_number), - date_dim, - catalog_page, - item, - promotion - where cs_sold_date_sk = d_date_sk - and d_date between cast('2001-08-08' as date) - and dateadd(day,30,cast('2001-08-08' as date)) - and cs_catalog_page_sk = cp_catalog_page_sk - and cs_item_sk = i_item_sk - and i_current_price > 50 - and cs_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(ws_ext_sales_price) as sales, - sum(coalesce(wr_return_amt, 0)) as returns, - sum(ws_net_profit - coalesce(wr_net_loss, 0)) as profit - from web_sales left outer join web_returns on - (ws_item_sk = wr_item_sk and ws_order_number = wr_order_number), - date_dim, - web_site, - item, - promotion - where ws_sold_date_sk = d_date_sk - and d_date between cast('2001-08-08' as date) - and dateadd(day,30,cast('2001-08-08' as date)) - and ws_web_site_sk = web_site_sk - and ws_item_sk = i_item_sk - and i_current_price > 50 - and ws_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by web_site_id) -, -results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || store_id as id - , sales - , returns - , profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || catalog_page_id as id - , sales - , returns - , profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , profit - from wsr - ) x - group by channel, id) - - select channel - , id - , sales - , returns - , profit - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results - ) foo - order by channel, id - limit 100; - --- end template query80a.tpl query 16 in stream 6 --- start template query9.tpl query 17 in stream 6 -select /* TPC-DS query9.tpl 0.49 */ case when (select count(*) - from store_sales - where ss_quantity between 1 and 20) > 107891285 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 1 and 20) - else (select avg(ss_net_profit) - from store_sales - where ss_quantity between 1 and 20) end bucket1 , - case when (select count(*) - from store_sales - where ss_quantity between 21 and 40) > 70534593 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 21 and 40) - else (select avg(ss_net_profit) - from store_sales - where ss_quantity between 21 and 40) end bucket2, - case when (select count(*) - from store_sales - where ss_quantity between 41 and 60) > 23070723 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 41 and 60) - else (select avg(ss_net_profit) - from store_sales - where ss_quantity between 41 and 60) end bucket3, - case when (select count(*) - from store_sales - where ss_quantity between 61 and 80) > 7558254 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 61 and 80) - else (select avg(ss_net_profit) - from store_sales - where ss_quantity between 61 and 80) end bucket4, - case when (select count(*) - from store_sales - where ss_quantity between 81 and 100) > 141263814 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 81 and 100) - else (select avg(ss_net_profit) - from store_sales - where ss_quantity between 81 and 100) end bucket5 -from reason -where r_reason_sk = 1 -; - --- end template query9.tpl query 17 in stream 6 --- start template query93.tpl query 18 in stream 6 -select /* TPC-DS query93.tpl 0.52 */ ss_customer_sk - ,sum(act_sales) sumsales - from (select ss_item_sk - ,ss_ticket_number - ,ss_customer_sk - ,case when sr_return_quantity is not null then (ss_quantity-sr_return_quantity)*ss_sales_price - else (ss_quantity*ss_sales_price) end act_sales - from store_sales left outer join store_returns on (sr_item_sk = ss_item_sk - and sr_ticket_number = ss_ticket_number) - ,reason - where sr_reason_sk = r_reason_sk - and r_reason_desc = 'reason 24') t - group by ss_customer_sk - order by sumsales, ss_customer_sk -limit 100; - --- end template query93.tpl query 18 in stream 6 --- start template query32.tpl query 19 in stream 6 -select /* TPC-DS query32.tpl 0.7 */ sum(cs_ext_discount_amt) as "excess discount amount" -from - catalog_sales - ,item - ,date_dim -where -i_manufact_id = 248 -and i_item_sk = cs_item_sk -and d_date between '2002-01-09' and - dateadd(day,90,cast('2002-01-09' as date)) -and d_date_sk = cs_sold_date_sk -and cs_ext_discount_amt - > ( - select - 1.3 * avg(cs_ext_discount_amt) - from - catalog_sales - ,date_dim - where - cs_item_sk = i_item_sk - and d_date between '2002-01-09' and - dateadd(day,90,cast('2002-01-09' as date)) - and d_date_sk = cs_sold_date_sk - ) -limit 100; - --- end template query32.tpl query 19 in stream 6 --- start template query89.tpl query 20 in stream 6 -select /* TPC-DS query89.tpl 0.56 */ * -from( -select i_category, i_class, i_brand, - s_store_name, s_company_name, - d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, s_store_name, s_company_name) - avg_monthly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - d_year in (2002) and - ((i_category in ('Books','Home','Electronics') and - i_class in ('computers','decor','disk drives') - ) - or (i_category in ('Music','Jewelry','Children') and - i_class in ('pop','bracelets','toddlers') - )) -group by i_category, i_class, i_brand, - s_store_name, s_company_name, d_moy) tmp1 -where case when (avg_monthly_sales <> 0) then (abs(sum_sales - avg_monthly_sales) / avg_monthly_sales) else null end > 0.1 -order by sum_sales - avg_monthly_sales, s_store_name -limit 100; - --- end template query89.tpl query 20 in stream 6 --- start template query28.tpl query 21 in stream 6 -select /* TPC-DS query28.tpl 0.36 */ * -from (select avg(ss_list_price) B1_LP - ,count(ss_list_price) B1_CNT - ,count(distinct ss_list_price) B1_CNTD - from store_sales - where ss_quantity between 0 and 5 - and (ss_list_price between 153 and 153+10 - or ss_coupon_amt between 4195 and 4195+1000 - or ss_wholesale_cost between 76 and 76+20)) B1, - (select avg(ss_list_price) B2_LP - ,count(ss_list_price) B2_CNT - ,count(distinct ss_list_price) B2_CNTD - from store_sales - where ss_quantity between 6 and 10 - and (ss_list_price between 15 and 15+10 - or ss_coupon_amt between 11023 and 11023+1000 - or ss_wholesale_cost between 69 and 69+20)) B2, - (select avg(ss_list_price) B3_LP - ,count(ss_list_price) B3_CNT - ,count(distinct ss_list_price) B3_CNTD - from store_sales - where ss_quantity between 11 and 15 - and (ss_list_price between 58 and 58+10 - or ss_coupon_amt between 3016 and 3016+1000 - or ss_wholesale_cost between 24 and 24+20)) B3, - (select avg(ss_list_price) B4_LP - ,count(ss_list_price) B4_CNT - ,count(distinct ss_list_price) B4_CNTD - from store_sales - where ss_quantity between 16 and 20 - and (ss_list_price between 175 and 175+10 - or ss_coupon_amt between 9132 and 9132+1000 - or ss_wholesale_cost between 1 and 1+20)) B4, - (select avg(ss_list_price) B5_LP - ,count(ss_list_price) B5_CNT - ,count(distinct ss_list_price) B5_CNTD - from store_sales - where ss_quantity between 21 and 25 - and (ss_list_price between 141 and 141+10 - or ss_coupon_amt between 4 and 4+1000 - or ss_wholesale_cost between 62 and 62+20)) B5, - (select avg(ss_list_price) B6_LP - ,count(ss_list_price) B6_CNT - ,count(distinct ss_list_price) B6_CNTD - from store_sales - where ss_quantity between 26 and 30 - and (ss_list_price between 181 and 181+10 - or ss_coupon_amt between 10 and 10+1000 - or ss_wholesale_cost between 13 and 13+20)) B6 -limit 100; - --- end template query28.tpl query 21 in stream 6 --- start template query87.tpl query 22 in stream 6 -select /* TPC-DS query87.tpl 0.77 */ count(*) -from ((select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1196 and 1196+11) - except - (select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1196 and 1196+11) - except - (select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1196 and 1196+11) -) cool_cust -; - --- end template query87.tpl query 22 in stream 6 --- start template query18a.tpl query 23 in stream 6 -with /* TPC-DS query18a.tpl 0.90 */ results as - (select i_item_id, - ca_country, - ca_state, - ca_county, - cast(cs_quantity as decimal(12,2)) agg1, - cast(cs_list_price as decimal(12,2)) agg2, - cast(cs_coupon_amt as decimal(12,2)) agg3, - cast(cs_sales_price as decimal(12,2)) agg4, - cast(cs_net_profit as decimal(12,2)) agg5, - cast(c_birth_year as decimal(12,2)) agg6, - cast(cd1.cd_dep_count as decimal(12,2)) agg7 - from catalog_sales, customer_demographics cd1, customer_demographics cd2, customer, customer_address, date_dim, item - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd1.cd_demo_sk and - cs_bill_customer_sk = c_customer_sk and - cd1.cd_gender = 'F' and - cd1.cd_education_status = 'Unknown' and - c_current_cdemo_sk = cd2.cd_demo_sk and - c_current_addr_sk = ca_address_sk and - c_birth_month in (11,8,12,4,2,10) and - d_year = 2002 and - ca_state in ('TX','NE','VA','HI','WI','VT','PA') - ) - select i_item_id, ca_country, ca_state, ca_county, agg1, agg2, agg3, agg4, agg5, agg6, agg7 - from ( - select i_item_id, ca_country, ca_state, ca_county, avg(agg1) agg1, - avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state, ca_county - union all - select i_item_id, ca_country, ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state - union all - select i_item_id, ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country - union all - select i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - ) foo - order by ca_country, ca_state, ca_county, i_item_id - limit 100; - --- end template query18a.tpl query 23 in stream 6 --- start template query74.tpl query 24 in stream 6 -with /* TPC-DS query74.tpl 0.76 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,max(ss_net_paid) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1998,1998+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,max(ws_net_paid) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - and d_year in (1998,1998+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - ) - select - t_s_secyear.customer_id, t_s_secyear.customer_first_name, t_s_secyear.customer_last_name - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.year = 1998 - and t_s_secyear.year = 1998+1 - and t_w_firstyear.year = 1998 - and t_w_secyear.year = 1998+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - order by 2,3,1 -limit 100; - --- end template query74.tpl query 24 in stream 6 --- start template query6.tpl query 25 in stream 6 -select /* TPC-DS query6.tpl 0.58 */ a.ca_state state, count(*) cnt - from customer_address a - ,customer c - ,store_sales s - ,date_dim d - ,item i - where a.ca_address_sk = c.c_current_addr_sk - and c.c_customer_sk = s.ss_customer_sk - and s.ss_sold_date_sk = d.d_date_sk - and s.ss_item_sk = i.i_item_sk - and d.d_month_seq = - (select distinct (d_month_seq) - from date_dim - where d_year = 1999 - and d_moy = 4 ) - and i.i_current_price > 1.2 * - (select avg(j.i_current_price) - from item j - where j.i_category = i.i_category) - group by a.ca_state - having count(*) >= 10 - order by cnt, a.ca_state - limit 100; - --- end template query6.tpl query 25 in stream 6 --- start template query65.tpl query 26 in stream 6 -select /* TPC-DS query65.tpl 0.71 */ - s_store_name, - i_item_desc, - sc.revenue, - i_current_price, - i_wholesale_cost, - i_brand - from store, item, - (select ss_store_sk, avg(revenue) as ave - from - (select ss_store_sk, ss_item_sk, - sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1180 and 1180+11 - group by ss_store_sk, ss_item_sk) sa - group by ss_store_sk) sb, - (select ss_store_sk, ss_item_sk, sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1180 and 1180+11 - group by ss_store_sk, ss_item_sk) sc - where sb.ss_store_sk = sc.ss_store_sk and - sc.revenue <= 0.1 * sb.ave and - s_store_sk = sc.ss_store_sk and - i_item_sk = sc.ss_item_sk - order by s_store_name, i_item_desc -limit 100; - --- end template query65.tpl query 26 in stream 6 --- start template query84.tpl query 27 in stream 6 -select /* TPC-DS query84.tpl 0.80 */ c_customer_id as customer_id - , coalesce(c_last_name,'') || ', ' || coalesce(c_first_name,'') as customername - from customer - ,customer_address - ,customer_demographics - ,household_demographics - ,income_band - ,store_returns - where ca_city = 'Riverside' - and c_current_addr_sk = ca_address_sk - and ib_lower_bound >= 849 - and ib_upper_bound <= 849 + 50000 - and ib_income_band_sk = hd_income_band_sk - and cd_demo_sk = c_current_cdemo_sk - and hd_demo_sk = c_current_hdemo_sk - and sr_cdemo_sk = cd_demo_sk - order by c_customer_id - limit 100; - --- end template query84.tpl query 27 in stream 6 --- start template query14a.tpl query 28 in stream 6 -with /* TPC-DS query14a.tpl 0.69 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 2000 AND 2000 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 2000 AND 2000 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 2000 AND 2000 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as - (select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2) x) -, - results AS -(select channel, i_brand_id, i_class_id, i_category_id, sum(sales) sum_sales, sum(number_sales) number_sales - from ( - select 'store' channel, i_brand_id,i_class_id - ,i_category_id,sum(ss_quantity*ss_list_price) sales - , count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2000+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales) - union all - select 'catalog' channel, i_brand_id,i_class_id,i_category_id, sum(cs_quantity*cs_list_price) sales, count(*) number_sales - from catalog_sales - ,item - ,date_dim - where cs_item_sk in (select ss_item_sk from cross_items) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2000+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(cs_quantity*cs_list_price) > (select average_sales from avg_sales) - union all - select 'web' channel, i_brand_id,i_class_id,i_category_id, sum(ws_quantity*ws_list_price) sales , count(*) number_sales - from web_sales - ,item - ,date_dim - where ws_item_sk in (select ss_item_sk from cross_items) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2000+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ws_quantity*ws_list_price) > (select average_sales from avg_sales) - ) y - group by channel, i_brand_id,i_class_id,i_category_id) - - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales -from ( - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales from results - union - select channel, i_brand_id, i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id, i_class_id - union - select channel, i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id - union - select channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel - union - select null as channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results) z -order by channel, i_brand_id, i_class_id, i_category_id - limit 100; -with /* TPC-DS query14a.tpl 0.69 part2 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 2000 AND 2000 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 2000 AND 2000 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 2000 AND 2000 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as -(select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2) x) - select this_year.channel ty_channel - ,this_year.i_brand_id ty_brand - ,this_year.i_class_id ty_class - ,this_year.i_category_id ty_category - ,this_year.sales ty_sales - ,this_year.number_sales ty_number_sales - ,last_year.channel ly_channel - ,last_year.i_brand_id ly_brand - ,last_year.i_class_id ly_class - ,last_year.i_category_id ly_category - ,last_year.sales ly_sales - ,last_year.number_sales ly_number_sales -from - (select 'store' channel, i_brand_id,i_class_id,i_category_id - ,sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 2000 + 1 - and d_moy = 12 - and d_dom = 10) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) this_year, - (select 'store' channel, i_brand_id,i_class_id - ,i_category_id, sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 2000 - and d_moy = 12 - and d_dom = 10) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) last_year - where this_year.i_brand_id= last_year.i_brand_id - and this_year.i_class_id = last_year.i_class_id - and this_year.i_category_id = last_year.i_category_id - order by this_year.channel, this_year.i_brand_id, this_year.i_class_id, this_year.i_category_id - limit 100; - --- end template query14a.tpl query 28 in stream 6 --- start template query38.tpl query 29 in stream 6 -select /* TPC-DS query38.tpl 0.54 */ count(*) from ( - select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1184 and 1184 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1184 and 1184 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1184 and 1184 + 11 -) hot_cust -limit 100; - --- end template query38.tpl query 29 in stream 6 --- start template query24.tpl query 30 in stream 6 -with /* TPC-DS query24.tpl 0.92 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_net_paid) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip -and s_market_id=8 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'royal' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; -with /* TPC-DS query24.tpl 0.92 part2 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_net_paid) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip - and s_market_id = 8 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'tomato' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; - --- end template query24.tpl query 30 in stream 6 --- start template query42.tpl query 31 in stream 6 -select /* TPC-DS query42.tpl 0.61 */ dt.d_year - ,item.i_category_id - ,item.i_category - ,sum(ss_ext_sales_price) - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=12 - and dt.d_year=1999 - group by dt.d_year - ,item.i_category_id - ,item.i_category - order by sum(ss_ext_sales_price) desc,dt.d_year - ,item.i_category_id - ,item.i_category -limit 100 ; - --- end template query42.tpl query 31 in stream 6 --- start template query29.tpl query 32 in stream 6 -select /* TPC-DS query29.tpl 0.53 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,max(ss_quantity) as store_sales_quantity - ,max(sr_return_quantity) as store_returns_quantity - ,max(cs_quantity) as catalog_sales_quantity - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 2000 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 4 + 3 - and d2.d_year = 2000 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_year in (2000,2000+1,2000+2) - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query29.tpl query 32 in stream 6 --- start template query72.tpl query 33 in stream 6 -select /* TPC-DS query72.tpl 0.87 */ i_item_desc - ,w_warehouse_name - ,d1.d_week_seq - ,sum(case when p_promo_sk is null then 1 else 0 end) no_promo - ,sum(case when p_promo_sk is not null then 1 else 0 end) promo - ,count(*) total_cnt -from catalog_sales -join inventory on (cs_item_sk = inv_item_sk) -join warehouse on (w_warehouse_sk=inv_warehouse_sk) -join item on (i_item_sk = cs_item_sk) -join customer_demographics on (cs_bill_cdemo_sk = cd_demo_sk) -join household_demographics on (cs_bill_hdemo_sk = hd_demo_sk) -join date_dim d1 on (cs_sold_date_sk = d1.d_date_sk) -join date_dim d2 on (inv_date_sk = d2.d_date_sk) -join date_dim d3 on (cs_ship_date_sk = d3.d_date_sk) -left outer join promotion on (cs_promo_sk=p_promo_sk) -left outer join catalog_returns on (cr_item_sk = cs_item_sk and cr_order_number = cs_order_number) -where d1.d_week_seq = d2.d_week_seq - and inv_quantity_on_hand < cs_quantity - and d3.d_date > d1.d_date + 5 - and hd_buy_potential = '501-1000' - and d1.d_year = 1998 - and cd_marital_status = 'M' -group by i_item_desc,w_warehouse_name,d1.d_week_seq -order by total_cnt desc, i_item_desc, w_warehouse_name, d_week_seq -limit 100; - --- end template query72.tpl query 33 in stream 6 --- start template query23.tpl query 34 in stream 6 -with /* TPC-DS query23.tpl 0.68 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (1999,1999+1,1999+2,1999+3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1999,1999+1,1999+2,1999+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * -from - max_store_sales)) - select sum(sales) - from (select cs_quantity*cs_list_price sales - from catalog_sales - ,date_dim - where d_year = 1999 - and d_moy = 7 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - union all - select ws_quantity*ws_list_price sales - from web_sales - ,date_dim - where d_year = 1999 - and d_moy = 7 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer)) - limit 100; -with /* TPC-DS query23.tpl 0.68 part2 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (1999,1999 + 1,1999 + 2,1999 + 3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1999,1999+1,1999+2,1999+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * - from max_store_sales)) - select c_last_name,c_first_name,sales - from (select c_last_name,c_first_name,sum(cs_quantity*cs_list_price) sales - from catalog_sales - ,customer - ,date_dim - where d_year = 1999 - and d_moy = 7 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and cs_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name - union all - select c_last_name,c_first_name,sum(ws_quantity*ws_list_price) sales - from web_sales - ,customer - ,date_dim - where d_year = 1999 - and d_moy = 7 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and ws_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name) - order by c_last_name,c_first_name,sales - limit 100; - --- end template query23.tpl query 34 in stream 6 --- start template query26.tpl query 35 in stream 6 -select /* TPC-DS query26.tpl 0.85 */ i_item_id, - avg(cs_quantity) agg1, - avg(cs_list_price) agg2, - avg(cs_coupon_amt) agg3, - avg(cs_sales_price) agg4 - from catalog_sales, customer_demographics, date_dim, item, promotion - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd_demo_sk and - cs_promo_sk = p_promo_sk and - cd_gender = 'M' and - cd_marital_status = 'U' and - cd_education_status = 'Unknown' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 1998 - group by i_item_id - order by i_item_id - limit 100; - --- end template query26.tpl query 35 in stream 6 --- start template query69.tpl query 36 in stream 6 -select /* TPC-DS query69.tpl 0.28 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_state in ('SC','MO','NE') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 1999 and - d_moy between 1 and 1+2) and - (not exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 1999 and - d_moy between 1 and 1+2) and - not exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 1999 and - d_moy between 1 and 1+2)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - limit 100; - --- end template query69.tpl query 36 in stream 6 --- start template query47.tpl query 37 in stream 6 -with /* TPC-DS query47.tpl 0.42 */ v1 as( - select i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, - s_store_name, s_company_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - s_store_name, s_company_name - order by d_year, d_moy) rn - from item, store_sales, date_dim, store - where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - ( - d_year = 2001 or - ( d_year = 2001-1 and d_moy =12) or - ( d_year = 2001+1 and d_moy =1) - ) - group by i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy), - v2 as( - select v1.s_company_name - ,v1.d_year, v1.d_moy - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1.s_store_name = v1_lag.s_store_name and - v1.s_store_name = v1_lead.s_store_name and - v1.s_company_name = v1_lag.s_company_name and - v1.s_company_name = v1_lead.s_company_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 2001 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, nsum - limit 100; - --- end template query47.tpl query 37 in stream 6 --- start template query82.tpl query 38 in stream 6 -select /* TPC-DS query82.tpl 0.67 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, store_sales - where i_current_price between 81 and 81+30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('1999-05-08' as date) and dateadd(day,60,cast('1999-05-08' as date)) - and i_manufact_id in (342,91,222,313) - and inv_quantity_on_hand between 100 and 500 - and ss_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query82.tpl query 38 in stream 6 --- start template query31.tpl query 39 in stream 6 -with /* TPC-DS query31.tpl 0.50 */ ss as - (select ca_county,d_qoy, d_year,sum(ss_ext_sales_price) as store_sales - from store_sales,date_dim,customer_address - where ss_sold_date_sk = d_date_sk - and ss_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year), - ws as - (select ca_county,d_qoy, d_year,sum(ws_ext_sales_price) as web_sales - from web_sales,date_dim,customer_address - where ws_sold_date_sk = d_date_sk - and ws_bill_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year) - select - ss1.ca_county - ,ss1.d_year - ,ws2.web_sales/ws1.web_sales web_q1_q2_increase - ,ss2.store_sales/ss1.store_sales store_q1_q2_increase - ,ws3.web_sales/ws2.web_sales web_q2_q3_increase - ,ss3.store_sales/ss2.store_sales store_q2_q3_increase - from - ss ss1 - ,ss ss2 - ,ss ss3 - ,ws ws1 - ,ws ws2 - ,ws ws3 - where - ss1.d_qoy = 1 - and ss1.d_year = 2002 - and ss1.ca_county = ss2.ca_county - and ss2.d_qoy = 2 - and ss2.d_year = 2002 - and ss2.ca_county = ss3.ca_county - and ss3.d_qoy = 3 - and ss3.d_year = 2002 - and ss1.ca_county = ws1.ca_county - and ws1.d_qoy = 1 - and ws1.d_year = 2002 - and ws1.ca_county = ws2.ca_county - and ws2.d_qoy = 2 - and ws2.d_year = 2002 - and ws1.ca_county = ws3.ca_county - and ws3.d_qoy = 3 - and ws3.d_year =2002 - and case when ws1.web_sales > 0 then ws2.web_sales/ws1.web_sales else null end - > case when ss1.store_sales > 0 then ss2.store_sales/ss1.store_sales else null end - and case when ws2.web_sales > 0 then ws3.web_sales/ws2.web_sales else null end - > case when ss2.store_sales > 0 then ss3.store_sales/ss2.store_sales else null end - order by store_q1_q2_increase; - --- end template query31.tpl query 39 in stream 6 --- start template query59.tpl query 40 in stream 6 -with /* TPC-DS query59.tpl 0.30 */ wss as - (select d_week_seq, - ss_store_sk, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - group by d_week_seq,ss_store_sk - ) - select s_store_name1,s_store_id1,d_week_seq1 - ,sun_sales1/sun_sales2,mon_sales1/mon_sales2 - ,tue_sales1/tue_sales2,wed_sales1/wed_sales2,thu_sales1/thu_sales2 - ,fri_sales1/fri_sales2,sat_sales1/sat_sales2 - from - (select s_store_name s_store_name1,wss.d_week_seq d_week_seq1 - ,s_store_id s_store_id1,sun_sales sun_sales1 - ,mon_sales mon_sales1,tue_sales tue_sales1 - ,wed_sales wed_sales1,thu_sales thu_sales1 - ,fri_sales fri_sales1,sat_sales sat_sales1 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1194 and 1194 + 11) y, - (select s_store_name s_store_name2,wss.d_week_seq d_week_seq2 - ,s_store_id s_store_id2,sun_sales sun_sales2 - ,mon_sales mon_sales2,tue_sales tue_sales2 - ,wed_sales wed_sales2,thu_sales thu_sales2 - ,fri_sales fri_sales2,sat_sales sat_sales2 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1194+ 12 and 1194 + 23) x - where s_store_id1=s_store_id2 - and d_week_seq1=d_week_seq2-52 - order by s_store_name1,s_store_id1,d_week_seq1 -limit 100; - --- end template query59.tpl query 40 in stream 6 --- start template query49.tpl query 41 in stream 6 -select /* TPC-DS query49.tpl 0.48 */ channel, item, return_ratio, return_rank, currency_rank from - (select - 'web' as channel - ,web.item - ,web.return_ratio - ,web.return_rank - ,web.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select ws.ws_item_sk as item - ,(cast(sum(coalesce(wr.wr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(wr.wr_return_amt,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - web_sales ws left outer join web_returns wr - on (ws.ws_order_number = wr.wr_order_number and - ws.ws_item_sk = wr.wr_item_sk) - ,date_dim - where - wr.wr_return_amt > 10000 - and ws.ws_net_profit > 1 - and ws.ws_net_paid > 0 - and ws.ws_quantity > 0 - and ws_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 12 - group by ws.ws_item_sk - ) in_web - ) web - where - ( - web.return_rank <= 10 - or - web.currency_rank <= 10 - ) - union - select - 'catalog' as channel - ,catalog.item - ,catalog.return_ratio - ,catalog.return_rank - ,catalog.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select - cs.cs_item_sk as item - ,(cast(sum(coalesce(cr.cr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(cr.cr_return_amount,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - catalog_sales cs left outer join catalog_returns cr - on (cs.cs_order_number = cr.cr_order_number and - cs.cs_item_sk = cr.cr_item_sk) - ,date_dim - where - cr.cr_return_amount > 10000 - and cs.cs_net_profit > 1 - and cs.cs_net_paid > 0 - and cs.cs_quantity > 0 - and cs_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 12 - group by cs.cs_item_sk - ) in_cat - ) catalog - where - ( - catalog.return_rank <= 10 - or - catalog.currency_rank <=10 - ) - union - select - 'store' as channel - ,store.item - ,store.return_ratio - ,store.return_rank - ,store.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select sts.ss_item_sk as item - ,(cast(sum(coalesce(sr.sr_return_quantity,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(sr.sr_return_amt,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - store_sales sts left outer join store_returns sr - on (sts.ss_ticket_number = sr.sr_ticket_number and sts.ss_item_sk = sr.sr_item_sk) - ,date_dim - where - sr.sr_return_amt > 10000 - and sts.ss_net_profit > 1 - and sts.ss_net_paid > 0 - and sts.ss_quantity > 0 - and ss_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 12 - group by sts.ss_item_sk - ) in_store - ) store - where ( - store.return_rank <= 10 - or - store.currency_rank <= 10 - ) - ) - order by 1,4,5,2 - limit 100; - --- end template query49.tpl query 41 in stream 6 --- start template query33.tpl query 42 in stream 6 -with /* TPC-DS query33.tpl 0.22 */ ss as ( - select - i_manufact_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Sports')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 6 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -7 - group by i_manufact_id), - cs as ( - select - i_manufact_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Sports')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 6 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -7 - group by i_manufact_id), - ws as ( - select - i_manufact_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Sports')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 6 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -7 - group by i_manufact_id) - select i_manufact_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_manufact_id - order by total_sales -limit 100; - --- end template query33.tpl query 42 in stream 6 --- start template query86a.tpl query 43 in stream 6 -with /* TPC-DS query86a.tpl 0.11 */ results as -( select sum(ws_net_paid) as total_sum, i_category, i_class, 0 as g_category, 0 as g_class - from - web_sales - ,date_dim d1 - ,item - where - d1.d_month_seq between 1222 and 1222+11 - and d1.d_date_sk = ws_sold_date_sk - and i_item_sk = ws_item_sk - group by i_category,i_class - ) , - - results_rollup as -( select total_sum ,i_category ,i_class, g_category, g_class, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum, i_category, NULL as i_class, 0 as g_category, 1 as g_class, 1 as lochierarchy from results group by i_category - union - select sum(total_sum) as total_sum, NULL as i_category, NULL as i_class, 1 as g_category, 1 as g_class, 2 as lochierarchy from results) - select - total_sum ,i_category ,i_class, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_class = 0 then i_category end - order by total_sum desc) as rank_within_parent - from - results_rollup - order by - lochierarchy desc, - case when lochierarchy = 0 then i_category end, - rank_within_parent - limit 100; - --- end template query86a.tpl query 43 in stream 6 --- start template query99.tpl query 44 in stream 6 -select /* TPC-DS query99.tpl 0.94 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 30) and - (cs_ship_date_sk - cs_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 60) and - (cs_ship_date_sk - cs_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 90) and - (cs_ship_date_sk - cs_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - catalog_sales - ,warehouse - ,ship_mode - ,call_center - ,date_dim -where - d_month_seq between 1201 and 1201 + 11 -and cs_ship_date_sk = d_date_sk -and cs_warehouse_sk = w_warehouse_sk -and cs_ship_mode_sk = sm_ship_mode_sk -and cs_call_center_sk = cc_call_center_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -limit 100; - --- end template query99.tpl query 44 in stream 6 --- start template query4.tpl query 45 in stream 6 -with /* TPC-DS query4.tpl 0.93 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(((ss_ext_list_price-ss_ext_wholesale_cost-ss_ext_discount_amt)+ss_ext_sales_price)/2) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((cs_ext_list_price-cs_ext_wholesale_cost-cs_ext_discount_amt)+cs_ext_sales_price)/2) ) year_total - ,'c' sale_type - from customer - ,catalog_sales - ,date_dim - where c_customer_sk = cs_bill_customer_sk - and cs_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year -union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((ws_ext_list_price-ws_ext_wholesale_cost-ws_ext_discount_amt)+ws_ext_sales_price)/2) ) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_login - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_c_firstyear - ,year_total t_c_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_c_secyear.customer_id - and t_s_firstyear.customer_id = t_c_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_c_firstyear.sale_type = 'c' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_c_secyear.sale_type = 'c' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 1998 - and t_s_secyear.dyear = 1998+1 - and t_c_firstyear.dyear = 1998 - and t_c_secyear.dyear = 1998+1 - and t_w_firstyear.dyear = 1998 - and t_w_secyear.dyear = 1998+1 - and t_s_firstyear.year_total > 0 - and t_c_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_login -limit 100; - --- end template query4.tpl query 45 in stream 6 --- start template query45.tpl query 46 in stream 6 -select /* TPC-DS query45.tpl 0.18 */ ca_zip, ca_county, sum(ws_sales_price) - from web_sales, customer, customer_address, date_dim, item - where ws_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ws_item_sk = i_item_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', '85392', '85460', '80348', '81792') - or - i_item_id in (select i_item_id - from item - where i_item_sk in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29) - ) - ) - and ws_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 2002 - group by ca_zip, ca_county - order by ca_zip, ca_county - limit 100; - --- end template query45.tpl query 46 in stream 6 --- start template query85.tpl query 47 in stream 6 -select /* TPC-DS query85.tpl 0.33 */ substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) - from web_sales, web_returns, web_page, customer_demographics cd1, - customer_demographics cd2, customer_address, date_dim, reason - where ws_web_page_sk = wp_web_page_sk - and ws_item_sk = wr_item_sk - and ws_order_number = wr_order_number - and ws_sold_date_sk = d_date_sk and d_year = 1999 - and cd1.cd_demo_sk = wr_refunded_cdemo_sk - and cd2.cd_demo_sk = wr_returning_cdemo_sk - and ca_address_sk = wr_refunded_addr_sk - and r_reason_sk = wr_reason_sk - and - ( - ( - cd1.cd_marital_status = 'W' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Secondary' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 100.00 and 150.00 - ) - or - ( - cd1.cd_marital_status = 'M' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = '4 yr Degree' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 50.00 and 100.00 - ) - or - ( - cd1.cd_marital_status = 'D' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = '2 yr Degree' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ca_country = 'United States' - and - ca_state in ('VA', 'IA', 'MN') - and ws_net_profit between 100 and 200 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('OR', 'WV', 'KS') - and ws_net_profit between 150 and 300 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('LA', 'MD', 'TN') - and ws_net_profit between 50 and 250 - ) - ) -group by r_reason_desc -order by substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) -limit 100; - --- end template query85.tpl query 47 in stream 6 --- start template query8.tpl query 48 in stream 6 -select /* TPC-DS query8.tpl 0.63 */ s_store_name - ,sum(ss_net_profit) - from store_sales - ,date_dim - ,store, - (select ca_zip - from ( - SELECT substring(ca_zip,1,5) ca_zip - FROM customer_address - WHERE substring(ca_zip,1,5) IN ( - '47792','57955','42788','78317','55713','39639', - '32424','15538','28514','69134','45217', - '61435','50147','62099','23908','16053', - '73173','84101','82884','90260','20750', - '97142','85617','80083','96286','27536', - '40549','11107','62812','75856','46523', - '55556','54307','18053','79308','93617', - '60989','19914','98651','10284','37539', - '66032','84857','14395','71795','77471', - '50367','62559','48526','47648','16271', - '47382','51597','11070','94634','87558', - '45410','53359','22859','47162','41319', - '86998','53235','15453','28847','30620', - '21485','61135','11845','92819','46157', - '97845','86575','81166','52005','38985', - '33975','84761','30048','37285','28409', - '23936','56017','17216','31535','18679', - '28298','44436','25186','58270','34316', - '17840','20297','39999','75278','98330', - '52468','81936','42792','56625','30729', - '99012','43727','86957','33571','60180', - '13582','46369','87122','24245','62962', - '94557','32621','55696','42728','12892', - '61292','90896','76751','78917','62536', - '38991','60525','88400','51632','55592', - '68789','63802','95305','92685','55155', - '53066','56347','42779','22128','46813', - '57061','59820','68385','35188','43913', - '63102','14263','80594','60675','22133', - '11456','88882','64007','34928','18795', - '79415','66112','63295','48049','95391', - '67867','64292','80661','61870','68662', - '22067','26983','45961','35365','45059', - '45332','53931','83271','48316','52820', - '81471','58518','74206','86776','19826', - '57005','65044','13276','57946','96675', - '23274','88779','87243','11706','43720', - '57112','42062','96771','90153','69138', - '83993','57532','94756','35434','28908', - '33423','97043','21150','33637','86828', - '62644','52540','23449','34297','31615', - '45384','63722','28985','50707','44426', - '98035','84687','71223','46274','42754', - '52289','81983','60442','30140','75551', - '55423','11363','64673','58740','83847', - '23752','67683','96966','48245','14920', - '79811','12876','22279','64595','41530', - '28665','92075','13128','40982','21189', - '17902','66960','46002','54695','87628', - '29652','49132','40798','39612','15360', - '94289','15781','12650','99737','97228', - '14151','55137','61878','50013','59932', - '52053','72299','52263','94003','39393', - '10398','55601','84223','23060','73925', - '61361','28858','77909','77495','51460', - '65769','16196','72201','25413','41465', - '39628','88740','62172','85568','78383', - '23122','24424','37113','31311','34453', - '77105','80857','46772','99718','32906', - '87491','73852','70361','36843','39034', - '15159','72821','92716','72620','23986', - '12030','11015','22064','36619','23416', - '35253','82403','66826','33294','41898', - '13074','46973','98415','47386','68828', - '14145','97463','83989','26168','26034', - '94104','23402','70142','52520','20303', - '31820','90078','86349','69409','10622', - '16753','89980','62146','45962','88845', - '97587','44220','43827','41515','72853', - '73583','77396','22438','62217','27011', - '11213','96999','25006','38595','68405', - '92253','29896','77598','82684','69356', - '43393','79497','79757','82229','49965', - '48528','48788','79434','34558','38662', - '60899','36019','43814','91936','23032', - '27040','57999','19790','73001','31506', - '59037','36323','39142','76521','90534', - '55316','63147','75477','33383','51157', - '59509','52128','64610','77024','22764', - '36913','13833','63263','25708') - intersect - select ca_zip - from (SELECT substring(ca_zip,1,5) ca_zip,count(*) cnt - FROM customer_address, customer - WHERE ca_address_sk = c_current_addr_sk and - c_preferred_cust_flag='Y' - group by ca_zip - having count(*) > 10)A1)A2) V1 - where ss_store_sk = s_store_sk - and ss_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 2002 - and (substring(s_zip,1,2) = substring(V1.ca_zip,1,2)) - group by s_store_name - order by s_store_name - limit 100; - --- end template query8.tpl query 48 in stream 6 --- start template query19.tpl query 49 in stream 6 -select /* TPC-DS query19.tpl 0.8 */ i_brand_id brand_id, i_brand brand, i_manufact_id, i_manufact, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item,customer,customer_address,store - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=17 - and d_moy=12 - and d_year=2002 - and ss_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and substring(ca_zip,1,5) <> substring(s_zip,1,5) - and ss_store_sk = s_store_sk - group by i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact - order by ext_price desc - ,i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact -limit 100 ; - --- end template query19.tpl query 49 in stream 6 --- start template query61.tpl query 50 in stream 6 -select /* TPC-DS query61.tpl 0.97 */ promotions,total,cast(promotions as decimal(15,4))/cast(total as decimal(15,4))*100 -from - (select sum(ss_ext_sales_price) promotions - from store_sales - ,store - ,promotion - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_promo_sk = p_promo_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -6 - and i_category = 'Sports' - and (p_channel_dmail = 'Y' or p_channel_email = 'Y' or p_channel_tv = 'Y') - and s_gmt_offset = -6 - and d_year = 1998 - and d_moy = 12) promotional_sales, - (select sum(ss_ext_sales_price) total - from store_sales - ,store - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -6 - and i_category = 'Sports' - and s_gmt_offset = -6 - and d_year = 1998 - and d_moy = 12) all_sales -order by promotions, total -limit 100; - --- end template query61.tpl query 50 in stream 6 --- start template query3.tpl query 51 in stream 6 -select /* TPC-DS query3.tpl 0.45 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_sales_price) sum_agg - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manufact_id = 313 - and dt.d_moy=11 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,sum_agg desc - ,brand_id - limit 100; - --- end template query3.tpl query 51 in stream 6 --- start template query41.tpl query 52 in stream 6 -select /* TPC-DS query41.tpl 0.62 */ distinct(i_product_name) - from item i1 - where i_manufact_id between 932 and 932+40 - and (select count(*) as item_cnt - from item - where (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'goldenrod' or i_color = 'turquoise') and - (i_units = 'Pallet' or i_units = 'Carton') and - (i_size = 'extra large' or i_size = 'medium') - ) or - (i_category = 'Women' and - (i_color = 'sky' or i_color = 'slate') and - (i_units = 'Tsp' or i_units = 'Box') and - (i_size = 'large' or i_size = 'economy') - ) or - (i_category = 'Men' and - (i_color = 'royal' or i_color = 'chocolate') and - (i_units = 'Unknown' or i_units = 'Tbl') and - (i_size = 'petite' or i_size = 'small') - ) or - (i_category = 'Men' and - (i_color = 'puff' or i_color = 'hot') and - (i_units = 'Cup' or i_units = 'Gross') and - (i_size = 'extra large' or i_size = 'medium') - ))) or - (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'olive' or i_color = 'wheat') and - (i_units = 'N/A' or i_units = 'Gram') and - (i_size = 'extra large' or i_size = 'medium') - ) or - (i_category = 'Women' and - (i_color = 'burlywood' or i_color = 'lawn') and - (i_units = 'Oz' or i_units = 'Bunch') and - (i_size = 'large' or i_size = 'economy') - ) or - (i_category = 'Men' and - (i_color = 'bisque' or i_color = 'forest') and - (i_units = 'Dram' or i_units = 'Ounce') and - (i_size = 'petite' or i_size = 'small') - ) or - (i_category = 'Men' and - (i_color = 'frosted' or i_color = 'indian') and - (i_units = 'Lb' or i_units = 'Dozen') and - (i_size = 'extra large' or i_size = 'medium') - )))) > 0 - order by i_product_name - limit 100; - --- end template query41.tpl query 52 in stream 6 --- start template query54.tpl query 53 in stream 6 -with /* TPC-DS query54.tpl 0.81 */ my_customers as ( - select distinct c_customer_sk - , c_current_addr_sk - from - ( select cs_sold_date_sk sold_date_sk, - cs_bill_customer_sk customer_sk, - cs_item_sk item_sk - from catalog_sales - union all - select ws_sold_date_sk sold_date_sk, - ws_bill_customer_sk customer_sk, - ws_item_sk item_sk - from web_sales - ) cs_or_ws_sales, - item, - date_dim, - customer - where sold_date_sk = d_date_sk - and item_sk = i_item_sk - and i_category = 'Children' - and i_class = 'infants' - and c_customer_sk = cs_or_ws_sales.customer_sk - and d_moy = 7 - and d_year = 1999 - ) - , my_revenue as ( - select c_customer_sk, - sum(ss_ext_sales_price) as revenue - from my_customers, - store_sales, - customer_address, - store, - date_dim - where c_current_addr_sk = ca_address_sk - and ca_county = s_county - and ca_state = s_state - and ss_sold_date_sk = d_date_sk - and c_customer_sk = ss_customer_sk - and d_month_seq between (select distinct d_month_seq+1 - from date_dim where d_year = 1999 and d_moy = 7) - and (select distinct d_month_seq+3 - from date_dim where d_year = 1999 and d_moy = 7) - group by c_customer_sk - ) - , segments as - (select cast((revenue/50) as int) as segment - from my_revenue - ) - select segment, count(*) as num_customers, segment*50 as segment_base - from segments - group by segment - order by segment, num_customers - limit 100; - --- end template query54.tpl query 53 in stream 6 --- start template query67a.tpl query 54 in stream 6 -with /* TPC-DS query67a.tpl 0.35 */ results as -( select i_category ,i_class ,i_brand ,i_product_name ,d_year ,d_qoy ,d_moy ,s_store_id - ,sum(coalesce(ss_sales_price*ss_quantity,0)) sumsales - from store_sales ,date_dim ,store ,item - where ss_sold_date_sk=d_date_sk - and ss_item_sk=i_item_sk - and ss_store_sk = s_store_sk - and d_month_seq between 1214 and 1214 + 11 - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy,s_store_id) - , - results_rollup as - (select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, s_store_id, sumsales - from results - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy - union all - select i_category, i_class, i_brand, i_product_name, d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year - union all - select i_category, i_class, i_brand, i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name - union all - select i_category, i_class, i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand - union all - select i_category, i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class - union all - select i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category - union all - select null i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results) - - select * -from (select i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rank() over (partition by i_category order by sumsales desc) rk - from results_rollup) dw2 -where rk <= 100 -order by i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rk -limit 100; - --- end template query67a.tpl query 54 in stream 6 --- start template query77a.tpl query 55 in stream 6 -with /* TPC-DS query77a.tpl 0.78 */ ss as - (select s_store_sk, - sum(ss_ext_sales_price) as sales, - sum(ss_net_profit) as profit - from store_sales, - date_dim, - store - where ss_sold_date_sk = d_date_sk - and d_date between cast('1999-08-24' as date) - and dateadd(day,30,cast('1999-08-24' as date)) - and ss_store_sk = s_store_sk - group by s_store_sk) - , - sr as - (select s_store_sk, - sum(sr_return_amt) as returns, - sum(sr_net_loss) as profit_loss - from store_returns, - date_dim, - store - where sr_returned_date_sk = d_date_sk - and d_date between cast('1999-08-24' as date) - and dateadd(day,30,cast('1999-08-24' as date)) - and sr_store_sk = s_store_sk - group by s_store_sk), - cs as - (select cs_call_center_sk, - sum(cs_ext_sales_price) as sales, - sum(cs_net_profit) as profit - from catalog_sales, - date_dim - where cs_sold_date_sk = d_date_sk - and d_date between cast('1999-08-24' as date) - and dateadd(day,30,cast('1999-08-24' as date)) - group by cs_call_center_sk - ), - cr as - (select cr_call_center_sk, - sum(cr_return_amount) as returns, - sum(cr_net_loss) as profit_loss - from catalog_returns, - date_dim - where cr_returned_date_sk = d_date_sk - and d_date between cast('1999-08-24' as date) - and dateadd(day,30,cast('1999-08-24' as date)) - group by cr_call_center_sk), - ws as - ( select wp_web_page_sk, - sum(ws_ext_sales_price) as sales, - sum(ws_net_profit) as profit - from web_sales, - date_dim, - web_page - where ws_sold_date_sk = d_date_sk - and d_date between cast('1999-08-24' as date) - and dateadd(day,30,cast('1999-08-24' as date)) - and ws_web_page_sk = wp_web_page_sk - group by wp_web_page_sk), - wr as - (select wp_web_page_sk, - sum(wr_return_amt) as returns, - sum(wr_net_loss) as profit_loss - from web_returns, - date_dim, - web_page - where wr_returned_date_sk = d_date_sk - and d_date between cast('1999-08-24' as date) - and dateadd(day,30,cast('1999-08-24' as date)) - and wr_web_page_sk = wp_web_page_sk - group by wp_web_page_sk) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , ss.s_store_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ss left join sr - on ss.s_store_sk = sr.s_store_sk - union all - select 'catalog channel' as channel - , cs_call_center_sk as id - , sales - , returns - , (profit - profit_loss) as profit - from cs - , cr - union all - select 'web channel' as channel - , ws.wp_web_page_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ws left join wr - on ws.wp_web_page_sk = wr.wp_web_page_sk - ) x - group by channel, id ) - - select * - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results -) foo -order by channel, id - limit 100; - --- end template query77a.tpl query 55 in stream 6 --- start template query15.tpl query 56 in stream 6 -select /* TPC-DS query15.tpl 0.57 */ ca_zip - ,sum(cs_sales_price) - from catalog_sales - ,customer - ,customer_address - ,date_dim - where cs_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', - '85392', '85460', '80348', '81792') - or ca_state in ('CA','WA','GA') - or cs_sales_price > 500) - and cs_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 1999 - group by ca_zip - order by ca_zip - limit 100; - --- end template query15.tpl query 56 in stream 6 --- start template query51.tpl query 57 in stream 6 -WITH /* TPC-DS query51.tpl 0.46 */ web_v1 as ( -select - ws_item_sk item_sk, d_date, - sum(sum(ws_sales_price)) - over (partition by ws_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from web_sales - ,date_dim -where ws_sold_date_sk=d_date_sk - and d_month_seq between 1205 and 1205+11 - and ws_item_sk is not NULL -group by ws_item_sk, d_date), -store_v1 as ( -select - ss_item_sk item_sk, d_date, - sum(sum(ss_sales_price)) - over (partition by ss_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from store_sales - ,date_dim -where ss_sold_date_sk=d_date_sk - and d_month_seq between 1205 and 1205+11 - and ss_item_sk is not NULL -group by ss_item_sk, d_date) - select * -from (select item_sk - ,d_date - ,web_sales - ,store_sales - ,max(web_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) web_cumulative - ,max(store_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) store_cumulative - from (select case when web.item_sk is not null then web.item_sk else store.item_sk end item_sk - ,case when web.d_date is not null then web.d_date else store.d_date end d_date - ,web.cume_sales web_sales - ,store.cume_sales store_sales - from web_v1 web full outer join store_v1 store on (web.item_sk = store.item_sk - and web.d_date = store.d_date) - )x )y -where web_cumulative > store_cumulative -order by item_sk - ,d_date -limit 100; - --- end template query51.tpl query 57 in stream 6 --- start template query98.tpl query 58 in stream 6 -select /* TPC-DS query98.tpl 0.32 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ss_ext_sales_price) as itemrevenue - ,sum(ss_ext_sales_price)*100/sum(sum(ss_ext_sales_price)) over - (partition by i_class) as revenueratio -from - store_sales - ,item - ,date_dim -where - ss_item_sk = i_item_sk - and i_category in ('Sports', 'Books', 'Electronics') - and ss_sold_date_sk = d_date_sk - and d_date between cast('2002-01-15' as date) - and dateadd(day,30,cast('2002-01-15' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio; - --- end template query98.tpl query 58 in stream 6 --- start template query62.tpl query 59 in stream 6 -select /* TPC-DS query62.tpl 0.24 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 30) and - (ws_ship_date_sk - ws_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 60) and - (ws_ship_date_sk - ws_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 90) and - (ws_ship_date_sk - ws_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - web_sales - ,warehouse - ,ship_mode - ,web_site - ,date_dim -where - d_month_seq between 1209 and 1209 + 11 -and ws_ship_date_sk = d_date_sk -and ws_warehouse_sk = w_warehouse_sk -and ws_ship_mode_sk = sm_ship_mode_sk -and ws_web_site_sk = web_site_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -limit 100; - --- end template query62.tpl query 59 in stream 6 --- start template query97.tpl query 60 in stream 6 -with /* TPC-DS query97.tpl 0.38 */ ssci as ( -select ss_customer_sk customer_sk - ,ss_item_sk item_sk -from store_sales,date_dim -where ss_sold_date_sk = d_date_sk - and d_month_seq between 1177 and 1177 + 11 -group by ss_customer_sk - ,ss_item_sk), -csci as( - select cs_bill_customer_sk customer_sk - ,cs_item_sk item_sk -from catalog_sales,date_dim -where cs_sold_date_sk = d_date_sk - and d_month_seq between 1177 and 1177 + 11 -group by cs_bill_customer_sk - ,cs_item_sk) - select sum(case when ssci.customer_sk is not null and csci.customer_sk is null then 1 else 0 end) store_only - ,sum(case when ssci.customer_sk is null and csci.customer_sk is not null then 1 else 0 end) catalog_only - ,sum(case when ssci.customer_sk is not null and csci.customer_sk is not null then 1 else 0 end) store_and_catalog -from ssci full outer join csci on (ssci.customer_sk=csci.customer_sk - and ssci.item_sk = csci.item_sk) -limit 100; - --- end template query97.tpl query 60 in stream 6 --- start template query22a.tpl query 61 in stream 6 -with /* TPC-DS query22a.tpl 0.55 */ results as -(select i_product_name - ,i_brand - ,i_class - ,i_category - ,avg(inv_quantity_on_hand) qoh - from inventory - ,date_dim - ,item --- ,warehouse - where inv_date_sk=d_date_sk - and inv_item_sk=i_item_sk --- and inv_warehouse_sk = w_warehouse_sk - and d_month_seq between 1200 and 1200 + 11 - group by i_product_name,i_brand,i_class,i_category), -results_rollup as -(select i_product_name, i_brand, i_class, i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class,i_category -union all -select i_product_name, i_brand, i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class -union all -select i_product_name, i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand -union all -select i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name -union all -select null i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results) - select i_product_name, i_brand, i_class, i_category,qoh - from results_rollup - order by qoh, i_product_name, i_brand, i_class, i_category -limit 100; - --- end template query22a.tpl query 61 in stream 6 --- start template query48.tpl query 62 in stream 6 -select /* TPC-DS query48.tpl 0.74 */ sum (ss_quantity) - from store_sales, store, customer_demographics, customer_address, date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2000 - and - ( - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'S' - and - cd_education_status = 'Primary' - and - ss_sales_price between 100.00 and 150.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'U' - and - cd_education_status = '4 yr Degree' - and - ss_sales_price between 50.00 and 100.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'D' - and - cd_education_status = '2 yr Degree' - and - ss_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('TN', 'TX', 'GA') - and ss_net_profit between 0 and 2000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('IN', 'MD', 'CO') - and ss_net_profit between 150 and 3000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('NH', 'AZ', 'NC') - and ss_net_profit between 50 and 25000 - ) - ) -; - --- end template query48.tpl query 62 in stream 6 --- start template query2.tpl query 63 in stream 6 -with /* TPC-DS query2.tpl 0.84 */ wscs as - (select sold_date_sk - ,sales_price - from (select ws_sold_date_sk sold_date_sk - ,ws_ext_sales_price sales_price - from web_sales - union all - select cs_sold_date_sk sold_date_sk - ,cs_ext_sales_price sales_price - from catalog_sales)), - wswscs as - (select d_week_seq, - sum(case when (d_day_name='Sunday') then sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then sales_price else null end) sat_sales - from wscs - ,date_dim - where d_date_sk = sold_date_sk - group by d_week_seq) - select d_week_seq1 - ,round(sun_sales1/sun_sales2,2) - ,round(mon_sales1/mon_sales2,2) - ,round(tue_sales1/tue_sales2,2) - ,round(wed_sales1/wed_sales2,2) - ,round(thu_sales1/thu_sales2,2) - ,round(fri_sales1/fri_sales2,2) - ,round(sat_sales1/sat_sales2,2) - from - (select wswscs.d_week_seq d_week_seq1 - ,sun_sales sun_sales1 - ,mon_sales mon_sales1 - ,tue_sales tue_sales1 - ,wed_sales wed_sales1 - ,thu_sales thu_sales1 - ,fri_sales fri_sales1 - ,sat_sales sat_sales1 - from wswscs,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 2001) y, - (select wswscs.d_week_seq d_week_seq2 - ,sun_sales sun_sales2 - ,mon_sales mon_sales2 - ,tue_sales tue_sales2 - ,wed_sales wed_sales2 - ,thu_sales thu_sales2 - ,fri_sales fri_sales2 - ,sat_sales sat_sales2 - from wswscs - ,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 2001+1) z - where d_week_seq1=d_week_seq2-53 - order by d_week_seq1; - --- end template query2.tpl query 63 in stream 6 --- start template query79.tpl query 64 in stream 6 -select /* TPC-DS query79.tpl 0.89 */ - c_last_name,c_first_name,substring(s_city,1,30),ss_ticket_number,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,store.s_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (household_demographics.hd_dep_count = 3 or household_demographics.hd_vehicle_count > 1) - and date_dim.d_dow = 1 - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_number_employees between 200 and 295 - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,store.s_city) ms,customer - where ss_customer_sk = c_customer_sk - order by c_last_name,c_first_name,substring(s_city,1,30), profit -limit 100; - --- end template query79.tpl query 64 in stream 6 --- start template query56.tpl query 65 in stream 6 -with /* TPC-DS query56.tpl 0.83 */ ss as ( - select i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where i_item_id in (select - i_item_id -from item -where i_color in ('powder','smoke','grey')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 4 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id), - cs as ( - select i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('powder','smoke','grey')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 4 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id), - ws as ( - select i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('powder','smoke','grey')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 4 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id) - select i_item_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by total_sales, - i_item_id - limit 100; - --- end template query56.tpl query 65 in stream 6 --- start template query37.tpl query 66 in stream 6 -select /* TPC-DS query37.tpl 0.31 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, catalog_sales - where i_current_price between 38 and 38 + 30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('2001-04-24' as date) and dateadd(day,60,cast('2001-04-24' as date)) - and i_manufact_id in (956,941,793,901) - and inv_quantity_on_hand between 100 and 500 - and cs_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query37.tpl query 66 in stream 6 --- start template query10.tpl query 67 in stream 6 -select /* TPC-DS query10.tpl 0.26 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3, - cd_dep_count, - count(*) cnt4, - cd_dep_employed_count, - count(*) cnt5, - cd_dep_college_count, - count(*) cnt6 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_county in ('Pulaski County','Dickey County','Benton County','Worcester County','Monroe County') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 3 and 3+3) and - (exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 3 ANd 3+3) or - exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 3 and 3+3)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count -limit 100; - --- end template query10.tpl query 67 in stream 6 --- start template query90.tpl query 68 in stream 6 -select /* TPC-DS query90.tpl 0.40 */ cast(amc as decimal(15,4))/cast(pmc as decimal(15,4)) am_pm_ratio - from ( select count(*) amc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 7 and 7+1 - and household_demographics.hd_dep_count = 5 - and web_page.wp_char_count between 5000 and 5200) at, - ( select count(*) pmc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 20 and 20+1 - and household_demographics.hd_dep_count = 5 - and web_page.wp_char_count between 5000 and 5200) pt - order by am_pm_ratio - limit 100; - --- end template query90.tpl query 68 in stream 6 --- start template query21.tpl query 69 in stream 6 -select /* TPC-DS query21.tpl 0.14 */ * - from(select w_warehouse_name - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('1999-06-20' as date)) - then inv_quantity_on_hand - else 0 end) as inv_before - ,sum(case when (cast(d_date as date) >= cast ('1999-06-20' as date)) - then inv_quantity_on_hand - else 0 end) as inv_after - from inventory - ,warehouse - ,item - ,date_dim - where i_current_price between 0.99 and 1.49 - and i_item_sk = inv_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('1999-06-20' as date)) - and dateadd(day,30,cast ('1999-06-20' as date)) - group by w_warehouse_name, i_item_id) x - where (case when inv_before > 0 - then inv_after / inv_before - else null - end) between 2.0/3.0 and 3.0/2.0 - order by w_warehouse_name - ,i_item_id - limit 100; - --- end template query21.tpl query 69 in stream 6 --- start template query46.tpl query 70 in stream 6 -select /* TPC-DS query46.tpl 0.23 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and (household_demographics.hd_dep_count = 5 or - household_demographics.hd_vehicle_count= 4) - and date_dim.d_dow in (6,0) - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_city in ('Oakland','Union','Spring Hill','Midway','Friendship') - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,ca_city) dn,customer,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - limit 100; - --- end template query46.tpl query 70 in stream 6 --- start template query83.tpl query 71 in stream 6 -with /* TPC-DS query83.tpl 0.96 */ sr_items as - (select i_item_id item_id, - sum(sr_return_quantity) sr_item_qty - from store_returns, - item, - date_dim - where sr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2001-04-29','2001-08-03','2001-11-11'))) - and sr_returned_date_sk = d_date_sk - group by i_item_id), - cr_items as - (select i_item_id item_id, - sum(cr_return_quantity) cr_item_qty - from catalog_returns, - item, - date_dim - where cr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2001-04-29','2001-08-03','2001-11-11'))) - and cr_returned_date_sk = d_date_sk - group by i_item_id), - wr_items as - (select i_item_id item_id, - sum(wr_return_quantity) wr_item_qty - from web_returns, - item, - date_dim - where wr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2001-04-29','2001-08-03','2001-11-11'))) - and wr_returned_date_sk = d_date_sk - group by i_item_id) - select sr_items.item_id - ,sr_item_qty - ,sr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 sr_dev - ,cr_item_qty - ,cr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 cr_dev - ,wr_item_qty - ,wr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 wr_dev - ,(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 average - from sr_items - ,cr_items - ,wr_items - where sr_items.item_id=cr_items.item_id - and sr_items.item_id=wr_items.item_id - order by sr_items.item_id - ,sr_item_qty - limit 100; - --- end template query83.tpl query 71 in stream 6 --- start template query96.tpl query 72 in stream 6 -select /* TPC-DS query96.tpl 0.1 */ count(*) -from store_sales - ,household_demographics - ,time_dim, store -where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 20 - and time_dim.t_minute >= 30 - and household_demographics.hd_dep_count = 0 - and store.s_store_name = 'ese' -order by count(*) -limit 100; - --- end template query96.tpl query 72 in stream 6 --- start template query68.tpl query 73 in stream 6 -select /* TPC-DS query68.tpl 0.95 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,extended_price - ,extended_tax - ,list_price - from (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_ext_sales_price) extended_price - ,sum(ss_ext_list_price) list_price - ,sum(ss_ext_tax) extended_tax - from store_sales - ,date_dim - ,store - ,household_demographics - ,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_dep_count = 2 or - household_demographics.hd_vehicle_count= 2) - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_city in ('Salem','Woodland') - group by ss_ticket_number - ,ss_customer_sk - ,ss_addr_sk,ca_city) dn - ,customer - ,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,ss_ticket_number - limit 100; - --- end template query68.tpl query 73 in stream 6 --- start template query63.tpl query 74 in stream 6 -select /* TPC-DS query63.tpl 0.27 */ * -from (select i_manager_id - ,sum(ss_sales_price) sum_sales - ,avg(sum(ss_sales_price)) over (partition by i_manager_id) avg_monthly_sales - from item - ,store_sales - ,date_dim - ,store - where ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and d_month_seq in (1178,1178+1,1178+2,1178+3,1178+4,1178+5,1178+6,1178+7,1178+8,1178+9,1178+10,1178+11) - and (( i_category in ('Books','Children','Electronics') - and i_class in ('personal','portable','reference','self-help') - and i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) - or( i_category in ('Women','Music','Men') - and i_class in ('accessories','classical','fragrances','pants') - and i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manager_id, d_moy) tmp1 -where case when avg_monthly_sales > 0 then abs (sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 -order by i_manager_id - ,avg_monthly_sales - ,sum_sales -limit 100; - --- end template query63.tpl query 74 in stream 6 --- start template query92.tpl query 75 in stream 6 -select /* TPC-DS query92.tpl 0.44 */ - sum(ws_ext_discount_amt) as "Excess Discount Amount" -from - web_sales - ,item - ,date_dim -where -i_manufact_id = 322 -and i_item_sk = ws_item_sk -and d_date between '2000-02-06' and - dateadd(day,90,cast('2000-02-06' as date)) -and d_date_sk = ws_sold_date_sk -and ws_ext_discount_amt - > ( - SELECT - 1.3 * avg(ws_ext_discount_amt) - FROM - web_sales - ,date_dim - WHERE - ws_item_sk = i_item_sk - and d_date between '2000-02-06' and - dateadd(day,90,cast('2000-02-06' as date)) - and d_date_sk = ws_sold_date_sk - ) -order by sum(ws_ext_discount_amt) -limit 100; - --- end template query92.tpl query 75 in stream 6 --- start template query27a.tpl query 76 in stream 6 -with /* TPC-DS query27a.tpl 0.16 */ results as - (select i_item_id, - s_state, 0 as g_state, - ss_quantity agg1, - ss_list_price agg2, - ss_coupon_amt agg3, - ss_sales_price agg4 - from store_sales, customer_demographics, date_dim, store, item - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_store_sk = s_store_sk and - ss_cdemo_sk = cd_demo_sk and - cd_gender = 'F' and - cd_marital_status = 'M' and - cd_education_status = 'Primary' and - d_year = 2001 and - s_state in ('NC','GA', 'MI', 'MI', 'NM', 'NE') - ) - - select i_item_id, - s_state, g_state, agg1, agg2, agg3, agg4 - from ( - select i_item_id, s_state, 0 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4 from results - group by i_item_id, s_state - union all - select i_item_id, NULL AS s_state, 1 AS g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as s_state, 1 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - ) foo - order by i_item_id, s_state - limit 100; - --- end template query27a.tpl query 76 in stream 6 --- start template query12.tpl query 77 in stream 6 -select /* TPC-DS query12.tpl 0.64 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ws_ext_sales_price) as itemrevenue - ,sum(ws_ext_sales_price)*100/sum(sum(ws_ext_sales_price)) over - (partition by i_class) as revenueratio -from - web_sales - ,item - ,date_dim -where - ws_item_sk = i_item_sk - and i_category in ('Shoes', 'Electronics', 'Sports') - and ws_sold_date_sk = d_date_sk - and d_date between cast('2000-03-13' as date) - and dateadd(day,30,cast('2000-03-13' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query12.tpl query 77 in stream 6 --- start template query64.tpl query 78 in stream 6 -with /* TPC-DS query64.tpl 0.20 */ cs_ui as - (select cs_item_sk - ,sum(cs_ext_list_price) as sale,sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit) as refund - from catalog_sales - ,catalog_returns - where cs_item_sk = cr_item_sk - and cs_order_number = cr_order_number - group by cs_item_sk - having sum(cs_ext_list_price)>2*sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit)), -cross_sales as - (select i_product_name product_name - ,i_item_sk item_sk - ,s_store_name store_name - ,s_zip store_zip - ,ad1.ca_street_number b_street_number - ,ad1.ca_street_name b_street_name - ,ad1.ca_city b_city - ,ad1.ca_zip b_zip - ,ad2.ca_street_number c_street_number - ,ad2.ca_street_name c_street_name - ,ad2.ca_city c_city - ,ad2.ca_zip c_zip - ,d1.d_year as syear - ,d2.d_year as fsyear - ,d3.d_year s2year - ,count(*) cnt - ,sum(ss_wholesale_cost) s1 - ,sum(ss_list_price) s2 - ,sum(ss_coupon_amt) s3 - FROM store_sales - ,store_returns - ,cs_ui - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,customer - ,customer_demographics cd1 - ,customer_demographics cd2 - ,promotion - ,household_demographics hd1 - ,household_demographics hd2 - ,customer_address ad1 - ,customer_address ad2 - ,income_band ib1 - ,income_band ib2 - ,item - WHERE ss_store_sk = s_store_sk AND - ss_sold_date_sk = d1.d_date_sk AND - ss_customer_sk = c_customer_sk AND - ss_cdemo_sk= cd1.cd_demo_sk AND - ss_hdemo_sk = hd1.hd_demo_sk AND - ss_addr_sk = ad1.ca_address_sk and - ss_item_sk = i_item_sk and - ss_item_sk = sr_item_sk and - ss_ticket_number = sr_ticket_number and - ss_item_sk = cs_ui.cs_item_sk and - c_current_cdemo_sk = cd2.cd_demo_sk AND - c_current_hdemo_sk = hd2.hd_demo_sk AND - c_current_addr_sk = ad2.ca_address_sk and - c_first_sales_date_sk = d2.d_date_sk and - c_first_shipto_date_sk = d3.d_date_sk and - ss_promo_sk = p_promo_sk and - hd1.hd_income_band_sk = ib1.ib_income_band_sk and - hd2.hd_income_band_sk = ib2.ib_income_band_sk and - cd1.cd_marital_status <> cd2.cd_marital_status and - i_color in ('beige','medium','ivory','powder','almond','papaya') and - i_current_price between 20 and 20 + 10 and - i_current_price between 20 + 1 and 20 + 15 -group by i_product_name - ,i_item_sk - ,s_store_name - ,s_zip - ,ad1.ca_street_number - ,ad1.ca_street_name - ,ad1.ca_city - ,ad1.ca_zip - ,ad2.ca_street_number - ,ad2.ca_street_name - ,ad2.ca_city - ,ad2.ca_zip - ,d1.d_year - ,d2.d_year - ,d3.d_year -) -select cs1.product_name - ,cs1.store_name - ,cs1.store_zip - ,cs1.b_street_number - ,cs1.b_street_name - ,cs1.b_city - ,cs1.b_zip - ,cs1.c_street_number - ,cs1.c_street_name - ,cs1.c_city - ,cs1.c_zip - ,cs1.syear - ,cs1.cnt - ,cs1.s1 as s11 - ,cs1.s2 as s21 - ,cs1.s3 as s31 - ,cs2.s1 as s12 - ,cs2.s2 as s22 - ,cs2.s3 as s32 - ,cs2.syear - ,cs2.cnt -from cross_sales cs1,cross_sales cs2 -where cs1.item_sk=cs2.item_sk and - cs1.syear = 2001 and - cs2.syear = 2001 + 1 and - cs2.cnt <= cs1.cnt and - cs1.store_name = cs2.store_name and - cs1.store_zip = cs2.store_zip -order by cs1.product_name - ,cs1.store_name - ,cs2.cnt - ,cs1.s1 - ,cs2.s1; - --- end template query64.tpl query 78 in stream 6 --- start template query95.tpl query 79 in stream 6 -with /* TPC-DS query95.tpl 0.43 */ ws_wh as -(select ws1.ws_order_number,ws1.ws_warehouse_sk wh1,ws2.ws_warehouse_sk wh2 - from web_sales ws1,web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) - select - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2002-3-01' and - dateadd(day,60,cast('2002-3-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'KS' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and ws1.ws_order_number in (select ws_order_number - from ws_wh) -and ws1.ws_order_number in (select wr_order_number - from web_returns,ws_wh - where wr_order_number = ws_wh.ws_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query95.tpl query 79 in stream 6 --- start template query39.tpl query 80 in stream 6 -with /* TPC-DS query39.tpl 0.5 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =2002 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=3 - and inv2.d_moy=3+1 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; -with /* TPC-DS query39.tpl 0.5 part2 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =2002 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=3 - and inv2.d_moy=3+1 - and inv1.cov > 1.5 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; - --- end template query39.tpl query 80 in stream 6 --- start template query35a.tpl query 81 in stream 6 -select /* TPC-DS query35a.tpl 0.47 */ - ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - count(*) cnt1, - stddev_samp(cd_dep_count), - stddev_samp(cd_dep_count), - max(cd_dep_count), - cd_dep_employed_count, - count(*) cnt2, - stddev_samp(cd_dep_employed_count), - stddev_samp(cd_dep_employed_count), - max(cd_dep_employed_count), - cd_dep_college_count, - count(*) cnt3, - stddev_samp(cd_dep_college_count), - stddev_samp(cd_dep_college_count), - max(cd_dep_college_count) - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2002 and - d_qoy < 4) and - exists (select * from - (select ws_bill_customer_sk customsk - from web_sales,date_dim - where - ws_sold_date_sk = d_date_sk and - d_year = 2002 and - d_qoy < 4 - union all - select cs_ship_customer_sk customsk - from catalog_sales,date_dim - where - cs_sold_date_sk = d_date_sk and - d_year = 2002 and - d_qoy < 4)x - where x.customsk = c.c_customer_sk) - group by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - limit 100; - --- end template query35a.tpl query 81 in stream 6 --- start template query78.tpl query 82 in stream 6 -with /* TPC-DS query78.tpl 0.10 */ ws as - (select d_year AS ws_sold_year, ws_item_sk, - ws_bill_customer_sk ws_customer_sk, - sum(ws_quantity) ws_qty, - sum(ws_wholesale_cost) ws_wc, - sum(ws_sales_price) ws_sp - from web_sales - left join web_returns on wr_order_number=ws_order_number and ws_item_sk=wr_item_sk - join date_dim on ws_sold_date_sk = d_date_sk - where wr_order_number is null - group by d_year, ws_item_sk, ws_bill_customer_sk - ), -cs as - (select d_year AS cs_sold_year, cs_item_sk, - cs_bill_customer_sk cs_customer_sk, - sum(cs_quantity) cs_qty, - sum(cs_wholesale_cost) cs_wc, - sum(cs_sales_price) cs_sp - from catalog_sales - left join catalog_returns on cr_order_number=cs_order_number and cs_item_sk=cr_item_sk - join date_dim on cs_sold_date_sk = d_date_sk - where cr_order_number is null - group by d_year, cs_item_sk, cs_bill_customer_sk - ), -ss as - (select d_year AS ss_sold_year, ss_item_sk, - ss_customer_sk, - sum(ss_quantity) ss_qty, - sum(ss_wholesale_cost) ss_wc, - sum(ss_sales_price) ss_sp - from store_sales - left join store_returns on sr_ticket_number=ss_ticket_number and ss_item_sk=sr_item_sk - join date_dim on ss_sold_date_sk = d_date_sk - where sr_ticket_number is null - group by d_year, ss_item_sk, ss_customer_sk - ) - select -ss_sold_year, ss_item_sk, ss_customer_sk, -round(ss_qty/(coalesce(ws_qty,0)+coalesce(cs_qty,0)),2) ratio, -ss_qty store_qty, ss_wc store_wholesale_cost, ss_sp store_sales_price, -coalesce(ws_qty,0)+coalesce(cs_qty,0) other_chan_qty, -coalesce(ws_wc,0)+coalesce(cs_wc,0) other_chan_wholesale_cost, -coalesce(ws_sp,0)+coalesce(cs_sp,0) other_chan_sales_price -from ss -left join ws on (ws_sold_year=ss_sold_year and ws_item_sk=ss_item_sk and ws_customer_sk=ss_customer_sk) -left join cs on (cs_sold_year=ss_sold_year and cs_item_sk=ss_item_sk and cs_customer_sk=ss_customer_sk) -where (coalesce(ws_qty,0)>0 or coalesce(cs_qty, 0)>0) and ss_sold_year=1998 -order by - ss_sold_year, ss_item_sk, ss_customer_sk, - ss_qty desc, ss_wc desc, ss_sp desc, - other_chan_qty, - other_chan_wholesale_cost, - other_chan_sales_price, - ratio -limit 100; - --- end template query78.tpl query 82 in stream 6 --- start template query57.tpl query 83 in stream 6 -with /* TPC-DS query57.tpl 0.70 */ v1 as( - select i_category, i_brand, - cc_name, - d_year, d_moy, - sum(cs_sales_price) sum_sales, - avg(sum(cs_sales_price)) over - (partition by i_category, i_brand, - cc_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - cc_name - order by d_year, d_moy) rn - from item, catalog_sales, date_dim, call_center - where cs_item_sk = i_item_sk and - cs_sold_date_sk = d_date_sk and - cc_call_center_sk= cs_call_center_sk and - ( - d_year = 1999 or - ( d_year = 1999-1 and d_moy =12) or - ( d_year = 1999+1 and d_moy =1) - ) - group by i_category, i_brand, - cc_name , d_year, d_moy), - v2 as( - select v1.i_category - ,v1.d_year, v1.d_moy - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1. cc_name = v1_lag. cc_name and - v1. cc_name = v1_lead. cc_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 1999 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, psum - limit 100; - --- end template query57.tpl query 83 in stream 6 --- start template query66.tpl query 84 in stream 6 -select /* TPC-DS query66.tpl 0.39 */ - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - ,sum(jan_sales) as jan_sales - ,sum(feb_sales) as feb_sales - ,sum(mar_sales) as mar_sales - ,sum(apr_sales) as apr_sales - ,sum(may_sales) as may_sales - ,sum(jun_sales) as jun_sales - ,sum(jul_sales) as jul_sales - ,sum(aug_sales) as aug_sales - ,sum(sep_sales) as sep_sales - ,sum(oct_sales) as oct_sales - ,sum(nov_sales) as nov_sales - ,sum(dec_sales) as dec_sales - ,sum(jan_sales/w_warehouse_sq_ft) as jan_sales_per_sq_foot - ,sum(feb_sales/w_warehouse_sq_ft) as feb_sales_per_sq_foot - ,sum(mar_sales/w_warehouse_sq_ft) as mar_sales_per_sq_foot - ,sum(apr_sales/w_warehouse_sq_ft) as apr_sales_per_sq_foot - ,sum(may_sales/w_warehouse_sq_ft) as may_sales_per_sq_foot - ,sum(jun_sales/w_warehouse_sq_ft) as jun_sales_per_sq_foot - ,sum(jul_sales/w_warehouse_sq_ft) as jul_sales_per_sq_foot - ,sum(aug_sales/w_warehouse_sq_ft) as aug_sales_per_sq_foot - ,sum(sep_sales/w_warehouse_sq_ft) as sep_sales_per_sq_foot - ,sum(oct_sales/w_warehouse_sq_ft) as oct_sales_per_sq_foot - ,sum(nov_sales/w_warehouse_sq_ft) as nov_sales_per_sq_foot - ,sum(dec_sales/w_warehouse_sq_ft) as dec_sales_per_sq_foot - ,sum(jan_net) as jan_net - ,sum(feb_net) as feb_net - ,sum(mar_net) as mar_net - ,sum(apr_net) as apr_net - ,sum(may_net) as may_net - ,sum(jun_net) as jun_net - ,sum(jul_net) as jul_net - ,sum(aug_net) as aug_net - ,sum(sep_net) as sep_net - ,sum(oct_net) as oct_net - ,sum(nov_net) as nov_net - ,sum(dec_net) as dec_net - from ( - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'AIRBORNE' || ',' || 'ALLIANCE' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then ws_ext_sales_price* ws_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then ws_ext_sales_price* ws_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then ws_ext_sales_price* ws_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then ws_ext_sales_price* ws_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then ws_ext_sales_price* ws_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then ws_ext_sales_price* ws_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then ws_ext_sales_price* ws_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then ws_ext_sales_price* ws_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then ws_ext_sales_price* ws_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then ws_ext_sales_price* ws_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then ws_ext_sales_price* ws_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then ws_ext_sales_price* ws_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as dec_net - from - web_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - ws_warehouse_sk = w_warehouse_sk - and ws_sold_date_sk = d_date_sk - and ws_sold_time_sk = t_time_sk - and ws_ship_mode_sk = sm_ship_mode_sk - and d_year = 2000 - and t_time between 26880 and 26880+28800 - and sm_carrier in ('AIRBORNE','ALLIANCE') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - union all - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'AIRBORNE' || ',' || 'ALLIANCE' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then cs_ext_list_price* cs_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then cs_ext_list_price* cs_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then cs_ext_list_price* cs_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then cs_ext_list_price* cs_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then cs_ext_list_price* cs_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then cs_ext_list_price* cs_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then cs_ext_list_price* cs_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then cs_ext_list_price* cs_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then cs_ext_list_price* cs_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then cs_ext_list_price* cs_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then cs_ext_list_price* cs_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then cs_ext_list_price* cs_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then cs_net_profit * cs_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then cs_net_profit * cs_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then cs_net_profit * cs_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then cs_net_profit * cs_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then cs_net_profit * cs_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then cs_net_profit * cs_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then cs_net_profit * cs_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then cs_net_profit * cs_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then cs_net_profit * cs_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then cs_net_profit * cs_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then cs_net_profit * cs_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then cs_net_profit * cs_quantity else 0 end) as dec_net - from - catalog_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and cs_sold_time_sk = t_time_sk - and cs_ship_mode_sk = sm_ship_mode_sk - and d_year = 2000 - and t_time between 26880 AND 26880+28800 - and sm_carrier in ('AIRBORNE','ALLIANCE') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - ) x - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - order by w_warehouse_name - limit 100; - --- end template query66.tpl query 84 in stream 6 --- start template query71.tpl query 85 in stream 6 -select /* TPC-DS query71.tpl 0.72 */ i_brand_id brand_id, i_brand brand,t_hour,t_minute, - sum(ext_price) ext_price - from item, (select ws_ext_sales_price as ext_price, - ws_sold_date_sk as sold_date_sk, - ws_item_sk as sold_item_sk, - ws_sold_time_sk as time_sk - from web_sales,date_dim - where d_date_sk = ws_sold_date_sk - and d_moy=11 - and d_year=2002 - union all - select cs_ext_sales_price as ext_price, - cs_sold_date_sk as sold_date_sk, - cs_item_sk as sold_item_sk, - cs_sold_time_sk as time_sk - from catalog_sales,date_dim - where d_date_sk = cs_sold_date_sk - and d_moy=11 - and d_year=2002 - union all - select ss_ext_sales_price as ext_price, - ss_sold_date_sk as sold_date_sk, - ss_item_sk as sold_item_sk, - ss_sold_time_sk as time_sk - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - and d_moy=11 - and d_year=2002 - ) tmp,time_dim - where - sold_item_sk = i_item_sk - and i_manager_id=1 - and time_sk = t_time_sk - and (t_meal_time = 'breakfast' or t_meal_time = 'dinner') - group by i_brand, i_brand_id,t_hour,t_minute - order by ext_price desc, i_brand_id - ; - --- end template query71.tpl query 85 in stream 6 --- start template query30.tpl query 86 in stream 6 -with /* TPC-DS query30.tpl 0.75 */ customer_total_return as - (select wr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(wr_return_amt) as ctr_total_return - from web_returns - ,date_dim - ,customer_address - where wr_returned_date_sk = d_date_sk - and d_year =1999 - and wr_returning_addr_sk = ca_address_sk - group by wr_returning_customer_sk - ,ca_state) - select c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'SD' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return -limit 100; - --- end template query30.tpl query 86 in stream 6 --- start template query1.tpl query 87 in stream 6 -with /* TPC-DS query1.tpl 0.12 */ customer_total_return as -(select sr_customer_sk as ctr_customer_sk -,sr_store_sk as ctr_store_sk -,sum(SR_FEE) as ctr_total_return -from store_returns -,date_dim -where sr_returned_date_sk = d_date_sk -and d_year =2000 -group by sr_customer_sk -,sr_store_sk) - select c_customer_id -from customer_total_return ctr1 -,store -,customer -where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 -from customer_total_return ctr2 -where ctr1.ctr_store_sk = ctr2.ctr_store_sk) -and s_store_sk = ctr1.ctr_store_sk -and s_state = 'IN' -and ctr1.ctr_customer_sk = c_customer_sk -order by c_customer_id -limit 100; - --- end template query1.tpl query 87 in stream 6 --- start template query81.tpl query 88 in stream 6 -with /* TPC-DS query81.tpl 0.37 */ customer_total_return as - (select cr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(cr_return_amt_inc_tax) as ctr_total_return - from catalog_returns - ,date_dim - ,customer_address - where cr_returned_date_sk = d_date_sk - and d_year =2000 - and cr_returning_addr_sk = ca_address_sk - group by cr_returning_customer_sk - ,ca_state ) - select c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'SC' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - limit 100; - --- end template query81.tpl query 88 in stream 6 --- start template query43.tpl query 89 in stream 6 -select /* TPC-DS query43.tpl 0.15 */ s_store_name, s_store_id, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from date_dim, store_sales, store - where d_date_sk = ss_sold_date_sk and - s_store_sk = ss_store_sk and - s_gmt_offset = -7 and - d_year = 2001 - group by s_store_name, s_store_id - order by s_store_name, s_store_id,sun_sales,mon_sales,tue_sales,wed_sales,thu_sales,fri_sales,sat_sales - limit 100; - --- end template query43.tpl query 89 in stream 6 --- start template query52.tpl query 90 in stream 6 -select /* TPC-DS query52.tpl 0.59 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_sales_price) ext_price - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=12 - and dt.d_year=1998 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,ext_price desc - ,brand_id -limit 100 ; - --- end template query52.tpl query 90 in stream 6 --- start template query13.tpl query 91 in stream 6 -select /* TPC-DS query13.tpl 0.91 */ avg(ss_quantity) - ,avg(ss_ext_sales_price) - ,avg(ss_ext_wholesale_cost) - ,sum(ss_ext_wholesale_cost) - from store_sales - ,store - ,customer_demographics - ,household_demographics - ,customer_address - ,date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2001 - and((ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'W' - and cd_education_status = 'Advanced Degree' - and ss_sales_price between 100.00 and 150.00 - and hd_dep_count = 3 - )or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'S' - and cd_education_status = '4 yr Degree' - and ss_sales_price between 50.00 and 100.00 - and hd_dep_count = 1 - ) or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'M' - and cd_education_status = 'Unknown' - and ss_sales_price between 150.00 and 200.00 - and hd_dep_count = 1 - )) - and((ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('MO', 'TX', 'GA') - and ss_net_profit between 100 and 200 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('MI', 'NY', 'SD') - and ss_net_profit between 150 and 300 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('WV', 'FL', 'VA') - and ss_net_profit between 50 and 250 - )) -; - --- end template query13.tpl query 91 in stream 6 --- start template query76.tpl query 92 in stream 6 -select /* TPC-DS query76.tpl 0.99 */ channel, col_name, d_year, d_qoy, i_category, COUNT(*) sales_cnt, SUM(ext_sales_price) sales_amt FROM ( - SELECT 'store' as channel, 'ss_addr_sk' col_name, d_year, d_qoy, i_category, ss_ext_sales_price ext_sales_price - FROM store_sales, item, date_dim - WHERE ss_addr_sk IS NULL - AND ss_sold_date_sk=d_date_sk - AND ss_item_sk=i_item_sk - UNION ALL - SELECT 'web' as channel, 'ws_ship_addr_sk' col_name, d_year, d_qoy, i_category, ws_ext_sales_price ext_sales_price - FROM web_sales, item, date_dim - WHERE ws_ship_addr_sk IS NULL - AND ws_sold_date_sk=d_date_sk - AND ws_item_sk=i_item_sk - UNION ALL - SELECT 'catalog' as channel, 'cs_ship_customer_sk' col_name, d_year, d_qoy, i_category, cs_ext_sales_price ext_sales_price - FROM catalog_sales, item, date_dim - WHERE cs_ship_customer_sk IS NULL - AND cs_sold_date_sk=d_date_sk - AND cs_item_sk=i_item_sk) foo -GROUP BY channel, col_name, d_year, d_qoy, i_category -ORDER BY channel, col_name, d_year, d_qoy, i_category -limit 100; - --- end template query76.tpl query 92 in stream 6 --- start template query17.tpl query 93 in stream 6 -select /* TPC-DS query17.tpl 0.41 */ i_item_id - ,i_item_desc - ,s_state - ,count(ss_quantity) as store_sales_quantitycount - ,avg(ss_quantity) as store_sales_quantityave - ,stddev_samp(ss_quantity) as store_sales_quantitystdev - ,stddev_samp(ss_quantity)/avg(ss_quantity) as store_sales_quantitycov - ,count(sr_return_quantity) as store_returns_quantitycount - ,avg(sr_return_quantity) as store_returns_quantityave - ,stddev_samp(sr_return_quantity) as store_returns_quantitystdev - ,stddev_samp(sr_return_quantity)/avg(sr_return_quantity) as store_returns_quantitycov - ,count(cs_quantity) as catalog_sales_quantitycount ,avg(cs_quantity) as catalog_sales_quantityave - ,stddev_samp(cs_quantity) as catalog_sales_quantitystdev - ,stddev_samp(cs_quantity)/avg(cs_quantity) as catalog_sales_quantitycov - from store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where d1.d_quarter_name = '2001Q1' - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_quarter_name in ('2001Q1','2001Q2','2001Q3') - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_quarter_name in ('2001Q1','2001Q2','2001Q3') - group by i_item_id - ,i_item_desc - ,s_state - order by i_item_id - ,i_item_desc - ,s_state -limit 100; - --- end template query17.tpl query 93 in stream 6 --- start template query25.tpl query 94 in stream 6 -select /* TPC-DS query25.tpl 0.9 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,sum(ss_net_profit) as store_sales_profit - ,sum(sr_net_loss) as store_returns_loss - ,sum(cs_net_profit) as catalog_sales_profit - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 2000 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 10 - and d2.d_year = 2000 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_moy between 4 and 10 - and d3.d_year = 2000 - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query25.tpl query 94 in stream 6 --- start template query40.tpl query 95 in stream 6 -select /* TPC-DS query40.tpl 0.86 */ - w_state - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('2000-05-18' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_before - ,sum(case when (cast(d_date as date) >= cast ('2000-05-18' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_after - from - catalog_sales left outer join catalog_returns on - (cs_order_number = cr_order_number - and cs_item_sk = cr_item_sk) - ,warehouse - ,item - ,date_dim - where - i_current_price between 0.99 and 1.49 - and i_item_sk = cs_item_sk - and cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('2000-05-18' as date)) - and dateadd(day,30,cast ('2000-05-18' as date)) - group by - w_state,i_item_id - order by w_state,i_item_id -limit 100; - --- end template query40.tpl query 95 in stream 6 --- start template query70a.tpl query 96 in stream 6 -with /* TPC-DS query70a.tpl 0.34 */ results as -( select - sum(ss_net_profit) as total_sum ,s_state ,s_county, 0 as gstate, 0 as g_county - from - store_sales - ,date_dim d1 - ,store - where - d1.d_month_seq between 1218 and 1218 + 11 - and d1.d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - and s_state in - ( select s_state - from (select s_state as s_state, - rank() over ( partition by s_state order by sum(ss_net_profit) desc) as ranking - from store_sales, store, date_dim - where d_month_seq between 1218 and 1218 + 11 - and d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - group by s_state - ) tmp1 - where ranking <= 5) - group by s_state,s_county) , - results_rollup as -(select total_sum ,s_state ,s_county, 0 as g_state, 0 as g_county, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum,s_state, NULL as s_county, 0 as g_state, 1 as g_county, 1 as lochierarchy from results group by s_state - union - select sum(total_sum) as total_sum ,NULL as s_state ,NULL as s_county, 1 as g_state, 1 as g_county, 2 as lochierarchy from results) - select total_sum ,s_state ,s_county, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_county = 0 then s_state end - order by total_sum desc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then s_state end - ,rank_within_parent - limit 100; - --- end template query70a.tpl query 96 in stream 6 --- start template query55.tpl query 97 in stream 6 -select /* TPC-DS query55.tpl 0.82 */ i_brand_id brand_id, i_brand brand, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=51 - and d_moy=11 - and d_year=2000 - group by i_brand, i_brand_id - order by ext_price desc, i_brand_id -limit 100 ; - --- end template query55.tpl query 97 in stream 6 --- start template query60.tpl query 98 in stream 6 -with /* TPC-DS query60.tpl 0.29 */ ss as ( - select - i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Children')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 10 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - cs as ( - select - i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Children')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 10 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - ws as ( - select - i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Children')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 10 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id) - select - i_item_id -,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by i_item_id - ,total_sales - limit 100; - --- end template query60.tpl query 98 in stream 6 --- start template query16.tpl query 99 in stream 6 -select /* TPC-DS query16.tpl 0.25 */ - count(distinct cs_order_number) as "order count" - ,sum(cs_ext_ship_cost) as "total shipping cost" - ,sum(cs_net_profit) as "total net profit" -from - catalog_sales cs1 - ,date_dim - ,customer_address - ,call_center -where - d_date between '2002-2-01' and - dateadd(day, 60, cast('2002-2-01' as date)) -and cs1.cs_ship_date_sk = d_date_sk -and cs1.cs_ship_addr_sk = ca_address_sk -and ca_state = 'MO' -and cs1.cs_call_center_sk = cc_call_center_sk -and cc_county in ('Walker County','Mobile County','Barrow County','Dauphin County', - 'Levy County' -) -and exists (select * - from catalog_sales cs2 - where cs1.cs_order_number = cs2.cs_order_number - and cs1.cs_warehouse_sk <> cs2.cs_warehouse_sk) -and not exists(select * - from catalog_returns cr1 - where cs1.cs_order_number = cr1.cr_order_number) -order by count(distinct cs_order_number) -limit 100; - --- end template query16.tpl query 99 in stream 6 diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/10TB/queries/query_7.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/10TB/queries/query_7.sql deleted file mode 100644 index 70bf794b..00000000 --- a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/10TB/queries/query_7.sql +++ /dev/null @@ -1,5027 +0,0 @@ --- start template query70a.tpl query 1 in stream 7 -with /* TPC-DS query70a.tpl 0.34 */ results as -( select - sum(ss_net_profit) as total_sum ,s_state ,s_county, 0 as gstate, 0 as g_county - from - store_sales - ,date_dim d1 - ,store - where - d1.d_month_seq between 1213 and 1213 + 11 - and d1.d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - and s_state in - ( select s_state - from (select s_state as s_state, - rank() over ( partition by s_state order by sum(ss_net_profit) desc) as ranking - from store_sales, store, date_dim - where d_month_seq between 1213 and 1213 + 11 - and d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - group by s_state - ) tmp1 - where ranking <= 5) - group by s_state,s_county) , - results_rollup as -(select total_sum ,s_state ,s_county, 0 as g_state, 0 as g_county, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum,s_state, NULL as s_county, 0 as g_state, 1 as g_county, 1 as lochierarchy from results group by s_state - union - select sum(total_sum) as total_sum ,NULL as s_state ,NULL as s_county, 1 as g_state, 1 as g_county, 2 as lochierarchy from results) - select total_sum ,s_state ,s_county, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_county = 0 then s_state end - order by total_sum desc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then s_state end - ,rank_within_parent - limit 100; - --- end template query70a.tpl query 1 in stream 7 --- start template query53.tpl query 2 in stream 7 -select /* TPC-DS query53.tpl 0.88 */ * from -(select i_manufact_id, -sum(ss_sales_price) sum_sales, -avg(sum(ss_sales_price)) over (partition by i_manufact_id) avg_quarterly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and -ss_sold_date_sk = d_date_sk and -ss_store_sk = s_store_sk and -d_month_seq in (1224,1224+1,1224+2,1224+3,1224+4,1224+5,1224+6,1224+7,1224+8,1224+9,1224+10,1224+11) and -((i_category in ('Books','Children','Electronics') and -i_class in ('personal','portable','reference','self-help') and -i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) -or(i_category in ('Women','Music','Men') and -i_class in ('accessories','classical','fragrances','pants') and -i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manufact_id, d_qoy ) tmp1 -where case when avg_quarterly_sales > 0 - then abs (sum_sales - avg_quarterly_sales)/ avg_quarterly_sales - else null end > 0.1 -order by avg_quarterly_sales, - sum_sales, - i_manufact_id -limit 100; - --- end template query53.tpl query 2 in stream 7 --- start template query92.tpl query 3 in stream 7 -select /* TPC-DS query92.tpl 0.44 */ - sum(ws_ext_discount_amt) as "Excess Discount Amount" -from - web_sales - ,item - ,date_dim -where -i_manufact_id = 749 -and i_item_sk = ws_item_sk -and d_date between '1999-03-07' and - dateadd(day,90,cast('1999-03-07' as date)) -and d_date_sk = ws_sold_date_sk -and ws_ext_discount_amt - > ( - SELECT - 1.3 * avg(ws_ext_discount_amt) - FROM - web_sales - ,date_dim - WHERE - ws_item_sk = i_item_sk - and d_date between '1999-03-07' and - dateadd(day,90,cast('1999-03-07' as date)) - and d_date_sk = ws_sold_date_sk - ) -order by sum(ws_ext_discount_amt) -limit 100; - --- end template query92.tpl query 3 in stream 7 --- start template query99.tpl query 4 in stream 7 -select /* TPC-DS query99.tpl 0.94 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 30) and - (cs_ship_date_sk - cs_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 60) and - (cs_ship_date_sk - cs_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 90) and - (cs_ship_date_sk - cs_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - catalog_sales - ,warehouse - ,ship_mode - ,call_center - ,date_dim -where - d_month_seq between 1217 and 1217 + 11 -and cs_ship_date_sk = d_date_sk -and cs_warehouse_sk = w_warehouse_sk -and cs_ship_mode_sk = sm_ship_mode_sk -and cs_call_center_sk = cc_call_center_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -limit 100; - --- end template query99.tpl query 4 in stream 7 --- start template query31.tpl query 5 in stream 7 -with /* TPC-DS query31.tpl 0.50 */ ss as - (select ca_county,d_qoy, d_year,sum(ss_ext_sales_price) as store_sales - from store_sales,date_dim,customer_address - where ss_sold_date_sk = d_date_sk - and ss_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year), - ws as - (select ca_county,d_qoy, d_year,sum(ws_ext_sales_price) as web_sales - from web_sales,date_dim,customer_address - where ws_sold_date_sk = d_date_sk - and ws_bill_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year) - select - ss1.ca_county - ,ss1.d_year - ,ws2.web_sales/ws1.web_sales web_q1_q2_increase - ,ss2.store_sales/ss1.store_sales store_q1_q2_increase - ,ws3.web_sales/ws2.web_sales web_q2_q3_increase - ,ss3.store_sales/ss2.store_sales store_q2_q3_increase - from - ss ss1 - ,ss ss2 - ,ss ss3 - ,ws ws1 - ,ws ws2 - ,ws ws3 - where - ss1.d_qoy = 1 - and ss1.d_year = 1998 - and ss1.ca_county = ss2.ca_county - and ss2.d_qoy = 2 - and ss2.d_year = 1998 - and ss2.ca_county = ss3.ca_county - and ss3.d_qoy = 3 - and ss3.d_year = 1998 - and ss1.ca_county = ws1.ca_county - and ws1.d_qoy = 1 - and ws1.d_year = 1998 - and ws1.ca_county = ws2.ca_county - and ws2.d_qoy = 2 - and ws2.d_year = 1998 - and ws1.ca_county = ws3.ca_county - and ws3.d_qoy = 3 - and ws3.d_year =1998 - and case when ws1.web_sales > 0 then ws2.web_sales/ws1.web_sales else null end - > case when ss1.store_sales > 0 then ss2.store_sales/ss1.store_sales else null end - and case when ws2.web_sales > 0 then ws3.web_sales/ws2.web_sales else null end - > case when ss2.store_sales > 0 then ss3.store_sales/ss2.store_sales else null end - order by store_q2_q3_increase; - --- end template query31.tpl query 5 in stream 7 --- start template query39.tpl query 6 in stream 7 -with /* TPC-DS query39.tpl 0.5 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =2002 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=3 - and inv2.d_moy=3+1 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; -with /* TPC-DS query39.tpl 0.5 part2 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =2002 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=3 - and inv2.d_moy=3+1 - and inv1.cov > 1.5 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; - --- end template query39.tpl query 6 in stream 7 --- start template query29.tpl query 7 in stream 7 -select /* TPC-DS query29.tpl 0.53 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,sum(ss_quantity) as store_sales_quantity - ,sum(sr_return_quantity) as store_returns_quantity - ,sum(cs_quantity) as catalog_sales_quantity - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 1999 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 4 + 3 - and d2.d_year = 1999 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_year in (1999,1999+1,1999+2) - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query29.tpl query 7 in stream 7 --- start template query32.tpl query 8 in stream 7 -select /* TPC-DS query32.tpl 0.7 */ sum(cs_ext_discount_amt) as "excess discount amount" -from - catalog_sales - ,item - ,date_dim -where -i_manufact_id = 64 -and i_item_sk = cs_item_sk -and d_date between '1999-03-13' and - dateadd(day,90,cast('1999-03-13' as date)) -and d_date_sk = cs_sold_date_sk -and cs_ext_discount_amt - > ( - select - 1.3 * avg(cs_ext_discount_amt) - from - catalog_sales - ,date_dim - where - cs_item_sk = i_item_sk - and d_date between '1999-03-13' and - dateadd(day,90,cast('1999-03-13' as date)) - and d_date_sk = cs_sold_date_sk - ) -limit 100; - --- end template query32.tpl query 8 in stream 7 --- start template query6.tpl query 9 in stream 7 -select /* TPC-DS query6.tpl 0.58 */ a.ca_state state, count(*) cnt - from customer_address a - ,customer c - ,store_sales s - ,date_dim d - ,item i - where a.ca_address_sk = c.c_current_addr_sk - and c.c_customer_sk = s.ss_customer_sk - and s.ss_sold_date_sk = d.d_date_sk - and s.ss_item_sk = i.i_item_sk - and d.d_month_seq = - (select distinct (d_month_seq) - from date_dim - where d_year = 2000 - and d_moy = 4 ) - and i.i_current_price > 1.2 * - (select avg(j.i_current_price) - from item j - where j.i_category = i.i_category) - group by a.ca_state - having count(*) >= 10 - order by cnt, a.ca_state - limit 100; - --- end template query6.tpl query 9 in stream 7 --- start template query64.tpl query 10 in stream 7 -with /* TPC-DS query64.tpl 0.20 */ cs_ui as - (select cs_item_sk - ,sum(cs_ext_list_price) as sale,sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit) as refund - from catalog_sales - ,catalog_returns - where cs_item_sk = cr_item_sk - and cs_order_number = cr_order_number - group by cs_item_sk - having sum(cs_ext_list_price)>2*sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit)), -cross_sales as - (select i_product_name product_name - ,i_item_sk item_sk - ,s_store_name store_name - ,s_zip store_zip - ,ad1.ca_street_number b_street_number - ,ad1.ca_street_name b_street_name - ,ad1.ca_city b_city - ,ad1.ca_zip b_zip - ,ad2.ca_street_number c_street_number - ,ad2.ca_street_name c_street_name - ,ad2.ca_city c_city - ,ad2.ca_zip c_zip - ,d1.d_year as syear - ,d2.d_year as fsyear - ,d3.d_year s2year - ,count(*) cnt - ,sum(ss_wholesale_cost) s1 - ,sum(ss_list_price) s2 - ,sum(ss_coupon_amt) s3 - FROM store_sales - ,store_returns - ,cs_ui - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,customer - ,customer_demographics cd1 - ,customer_demographics cd2 - ,promotion - ,household_demographics hd1 - ,household_demographics hd2 - ,customer_address ad1 - ,customer_address ad2 - ,income_band ib1 - ,income_band ib2 - ,item - WHERE ss_store_sk = s_store_sk AND - ss_sold_date_sk = d1.d_date_sk AND - ss_customer_sk = c_customer_sk AND - ss_cdemo_sk= cd1.cd_demo_sk AND - ss_hdemo_sk = hd1.hd_demo_sk AND - ss_addr_sk = ad1.ca_address_sk and - ss_item_sk = i_item_sk and - ss_item_sk = sr_item_sk and - ss_ticket_number = sr_ticket_number and - ss_item_sk = cs_ui.cs_item_sk and - c_current_cdemo_sk = cd2.cd_demo_sk AND - c_current_hdemo_sk = hd2.hd_demo_sk AND - c_current_addr_sk = ad2.ca_address_sk and - c_first_sales_date_sk = d2.d_date_sk and - c_first_shipto_date_sk = d3.d_date_sk and - ss_promo_sk = p_promo_sk and - hd1.hd_income_band_sk = ib1.ib_income_band_sk and - hd2.hd_income_band_sk = ib2.ib_income_band_sk and - cd1.cd_marital_status <> cd2.cd_marital_status and - i_color in ('khaki','floral','cornsilk','firebrick','orchid','chiffon') and - i_current_price between 68 and 68 + 10 and - i_current_price between 68 + 1 and 68 + 15 -group by i_product_name - ,i_item_sk - ,s_store_name - ,s_zip - ,ad1.ca_street_number - ,ad1.ca_street_name - ,ad1.ca_city - ,ad1.ca_zip - ,ad2.ca_street_number - ,ad2.ca_street_name - ,ad2.ca_city - ,ad2.ca_zip - ,d1.d_year - ,d2.d_year - ,d3.d_year -) -select cs1.product_name - ,cs1.store_name - ,cs1.store_zip - ,cs1.b_street_number - ,cs1.b_street_name - ,cs1.b_city - ,cs1.b_zip - ,cs1.c_street_number - ,cs1.c_street_name - ,cs1.c_city - ,cs1.c_zip - ,cs1.syear - ,cs1.cnt - ,cs1.s1 as s11 - ,cs1.s2 as s21 - ,cs1.s3 as s31 - ,cs2.s1 as s12 - ,cs2.s2 as s22 - ,cs2.s3 as s32 - ,cs2.syear - ,cs2.cnt -from cross_sales cs1,cross_sales cs2 -where cs1.item_sk=cs2.item_sk and - cs1.syear = 2000 and - cs2.syear = 2000 + 1 and - cs2.cnt <= cs1.cnt and - cs1.store_name = cs2.store_name and - cs1.store_zip = cs2.store_zip -order by cs1.product_name - ,cs1.store_name - ,cs2.cnt - ,cs1.s1 - ,cs2.s1; - --- end template query64.tpl query 10 in stream 7 --- start template query30.tpl query 11 in stream 7 -with /* TPC-DS query30.tpl 0.75 */ customer_total_return as - (select wr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(wr_return_amt) as ctr_total_return - from web_returns - ,date_dim - ,customer_address - where wr_returned_date_sk = d_date_sk - and d_year =1999 - and wr_returning_addr_sk = ca_address_sk - group by wr_returning_customer_sk - ,ca_state) - select c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'AR' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return -limit 100; - --- end template query30.tpl query 11 in stream 7 --- start template query34.tpl query 12 in stream 7 -select /* TPC-DS query34.tpl 0.73 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (date_dim.d_dom between 1 and 3 or date_dim.d_dom between 25 and 28) - and (household_demographics.hd_buy_potential = '1001-5000' or - household_demographics.hd_buy_potential = '0-500') - and household_demographics.hd_vehicle_count > 0 - and (case when household_demographics.hd_vehicle_count > 0 - then household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count - else null - end) > 1.2 - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_county in ('Salem County','Bronx County','Richland County','Arthur County', - 'Dauphin County','Levy County','Hubbard County','Gage County') - group by ss_ticket_number,ss_customer_sk) dn,customer - where ss_customer_sk = c_customer_sk - and cnt between 15 and 20 - order by c_last_name,c_first_name,c_salutation,c_preferred_cust_flag desc, ss_ticket_number; - --- end template query34.tpl query 12 in stream 7 --- start template query13.tpl query 13 in stream 7 -select /* TPC-DS query13.tpl 0.91 */ avg(ss_quantity) - ,avg(ss_ext_sales_price) - ,avg(ss_ext_wholesale_cost) - ,sum(ss_ext_wholesale_cost) - from store_sales - ,store - ,customer_demographics - ,household_demographics - ,customer_address - ,date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2001 - and((ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'S' - and cd_education_status = 'Unknown' - and ss_sales_price between 100.00 and 150.00 - and hd_dep_count = 3 - )or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'W' - and cd_education_status = 'College' - and ss_sales_price between 50.00 and 100.00 - and hd_dep_count = 1 - ) or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'U' - and cd_education_status = 'Advanced Degree' - and ss_sales_price between 150.00 and 200.00 - and hd_dep_count = 1 - )) - and((ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('TX', 'CO', 'GA') - and ss_net_profit between 100 and 200 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('WI', 'IA', 'WV') - and ss_net_profit between 150 and 300 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('OK', 'IL', 'CA') - and ss_net_profit between 50 and 250 - )) -; - --- end template query13.tpl query 13 in stream 7 --- start template query28.tpl query 14 in stream 7 -select /* TPC-DS query28.tpl 0.36 */ * -from (select avg(ss_list_price) B1_LP - ,count(ss_list_price) B1_CNT - ,count(distinct ss_list_price) B1_CNTD - from store_sales - where ss_quantity between 0 and 5 - and (ss_list_price between 186 and 186+10 - or ss_coupon_amt between 5420 and 5420+1000 - or ss_wholesale_cost between 71 and 71+20)) B1, - (select avg(ss_list_price) B2_LP - ,count(ss_list_price) B2_CNT - ,count(distinct ss_list_price) B2_CNTD - from store_sales - where ss_quantity between 6 and 10 - and (ss_list_price between 171 and 171+10 - or ss_coupon_amt between 4492 and 4492+1000 - or ss_wholesale_cost between 73 and 73+20)) B2, - (select avg(ss_list_price) B3_LP - ,count(ss_list_price) B3_CNT - ,count(distinct ss_list_price) B3_CNTD - from store_sales - where ss_quantity between 11 and 15 - and (ss_list_price between 34 and 34+10 - or ss_coupon_amt between 10339 and 10339+1000 - or ss_wholesale_cost between 10 and 10+20)) B3, - (select avg(ss_list_price) B4_LP - ,count(ss_list_price) B4_CNT - ,count(distinct ss_list_price) B4_CNTD - from store_sales - where ss_quantity between 16 and 20 - and (ss_list_price between 138 and 138+10 - or ss_coupon_amt between 8046 and 8046+1000 - or ss_wholesale_cost between 9 and 9+20)) B4, - (select avg(ss_list_price) B5_LP - ,count(ss_list_price) B5_CNT - ,count(distinct ss_list_price) B5_CNTD - from store_sales - where ss_quantity between 21 and 25 - and (ss_list_price between 6 and 6+10 - or ss_coupon_amt between 10036 and 10036+1000 - or ss_wholesale_cost between 33 and 33+20)) B5, - (select avg(ss_list_price) B6_LP - ,count(ss_list_price) B6_CNT - ,count(distinct ss_list_price) B6_CNTD - from store_sales - where ss_quantity between 26 and 30 - and (ss_list_price between 37 and 37+10 - or ss_coupon_amt between 12948 and 12948+1000 - or ss_wholesale_cost between 12 and 12+20)) B6 -limit 100; - --- end template query28.tpl query 14 in stream 7 --- start template query86a.tpl query 15 in stream 7 -with /* TPC-DS query86a.tpl 0.11 */ results as -( select sum(ws_net_paid) as total_sum, i_category, i_class, 0 as g_category, 0 as g_class - from - web_sales - ,date_dim d1 - ,item - where - d1.d_month_seq between 1206 and 1206+11 - and d1.d_date_sk = ws_sold_date_sk - and i_item_sk = ws_item_sk - group by i_category,i_class - ) , - - results_rollup as -( select total_sum ,i_category ,i_class, g_category, g_class, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum, i_category, NULL as i_class, 0 as g_category, 1 as g_class, 1 as lochierarchy from results group by i_category - union - select sum(total_sum) as total_sum, NULL as i_category, NULL as i_class, 1 as g_category, 1 as g_class, 2 as lochierarchy from results) - select - total_sum ,i_category ,i_class, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_class = 0 then i_category end - order by total_sum desc) as rank_within_parent - from - results_rollup - order by - lochierarchy desc, - case when lochierarchy = 0 then i_category end, - rank_within_parent - limit 100; - --- end template query86a.tpl query 15 in stream 7 --- start template query84.tpl query 16 in stream 7 -select /* TPC-DS query84.tpl 0.80 */ c_customer_id as customer_id - , coalesce(c_last_name,'') || ', ' || coalesce(c_first_name,'') as customername - from customer - ,customer_address - ,customer_demographics - ,household_demographics - ,income_band - ,store_returns - where ca_city = 'White Oak' - and c_current_addr_sk = ca_address_sk - and ib_lower_bound >= 14454 - and ib_upper_bound <= 14454 + 50000 - and ib_income_band_sk = hd_income_band_sk - and cd_demo_sk = c_current_cdemo_sk - and hd_demo_sk = c_current_hdemo_sk - and sr_cdemo_sk = cd_demo_sk - order by c_customer_id - limit 100; - --- end template query84.tpl query 16 in stream 7 --- start template query25.tpl query 17 in stream 7 -select /* TPC-DS query25.tpl 0.9 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,max(ss_net_profit) as store_sales_profit - ,max(sr_net_loss) as store_returns_loss - ,max(cs_net_profit) as catalog_sales_profit - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 1998 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 10 - and d2.d_year = 1998 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_moy between 4 and 10 - and d3.d_year = 1998 - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query25.tpl query 17 in stream 7 --- start template query4.tpl query 18 in stream 7 -with /* TPC-DS query4.tpl 0.93 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(((ss_ext_list_price-ss_ext_wholesale_cost-ss_ext_discount_amt)+ss_ext_sales_price)/2) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((cs_ext_list_price-cs_ext_wholesale_cost-cs_ext_discount_amt)+cs_ext_sales_price)/2) ) year_total - ,'c' sale_type - from customer - ,catalog_sales - ,date_dim - where c_customer_sk = cs_bill_customer_sk - and cs_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year -union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((ws_ext_list_price-ws_ext_wholesale_cost-ws_ext_discount_amt)+ws_ext_sales_price)/2) ) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_birth_country - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_c_firstyear - ,year_total t_c_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_c_secyear.customer_id - and t_s_firstyear.customer_id = t_c_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_c_firstyear.sale_type = 'c' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_c_secyear.sale_type = 'c' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 2000 - and t_s_secyear.dyear = 2000+1 - and t_c_firstyear.dyear = 2000 - and t_c_secyear.dyear = 2000+1 - and t_w_firstyear.dyear = 2000 - and t_w_secyear.dyear = 2000+1 - and t_s_firstyear.year_total > 0 - and t_c_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_birth_country -limit 100; - --- end template query4.tpl query 18 in stream 7 --- start template query98.tpl query 19 in stream 7 -select /* TPC-DS query98.tpl 0.32 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ss_ext_sales_price) as itemrevenue - ,sum(ss_ext_sales_price)*100/sum(sum(ss_ext_sales_price)) over - (partition by i_class) as revenueratio -from - store_sales - ,item - ,date_dim -where - ss_item_sk = i_item_sk - and i_category in ('Books', 'Music', 'Sports') - and ss_sold_date_sk = d_date_sk - and d_date between cast('2000-05-04' as date) - and dateadd(day,30,cast('2000-05-04' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio; - --- end template query98.tpl query 19 in stream 7 --- start template query79.tpl query 20 in stream 7 -select /* TPC-DS query79.tpl 0.89 */ - c_last_name,c_first_name,substring(s_city,1,30),ss_ticket_number,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,store.s_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (household_demographics.hd_dep_count = 4 or household_demographics.hd_vehicle_count > 2) - and date_dim.d_dow = 1 - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_number_employees between 200 and 295 - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,store.s_city) ms,customer - where ss_customer_sk = c_customer_sk - order by c_last_name,c_first_name,substring(s_city,1,30), profit -limit 100; - --- end template query79.tpl query 20 in stream 7 --- start template query69.tpl query 21 in stream 7 -select /* TPC-DS query69.tpl 0.28 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_state in ('MN','CO','TN') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 1999 and - d_moy between 2 and 2+2) and - (not exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 1999 and - d_moy between 2 and 2+2) and - not exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 1999 and - d_moy between 2 and 2+2)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - limit 100; - --- end template query69.tpl query 21 in stream 7 --- start template query72.tpl query 22 in stream 7 -select /* TPC-DS query72.tpl 0.87 */ i_item_desc - ,w_warehouse_name - ,d1.d_week_seq - ,sum(case when p_promo_sk is null then 1 else 0 end) no_promo - ,sum(case when p_promo_sk is not null then 1 else 0 end) promo - ,count(*) total_cnt -from catalog_sales -join inventory on (cs_item_sk = inv_item_sk) -join warehouse on (w_warehouse_sk=inv_warehouse_sk) -join item on (i_item_sk = cs_item_sk) -join customer_demographics on (cs_bill_cdemo_sk = cd_demo_sk) -join household_demographics on (cs_bill_hdemo_sk = hd_demo_sk) -join date_dim d1 on (cs_sold_date_sk = d1.d_date_sk) -join date_dim d2 on (inv_date_sk = d2.d_date_sk) -join date_dim d3 on (cs_ship_date_sk = d3.d_date_sk) -left outer join promotion on (cs_promo_sk=p_promo_sk) -left outer join catalog_returns on (cr_item_sk = cs_item_sk and cr_order_number = cs_order_number) -where d1.d_week_seq = d2.d_week_seq - and inv_quantity_on_hand < cs_quantity - and d3.d_date > d1.d_date + 5 - and hd_buy_potential = '>10000' - and d1.d_year = 2000 - and cd_marital_status = 'U' -group by i_item_desc,w_warehouse_name,d1.d_week_seq -order by total_cnt desc, i_item_desc, w_warehouse_name, d_week_seq -limit 100; - --- end template query72.tpl query 22 in stream 7 --- start template query45.tpl query 23 in stream 7 -select /* TPC-DS query45.tpl 0.18 */ ca_zip, ca_county, sum(ws_sales_price) - from web_sales, customer, customer_address, date_dim, item - where ws_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ws_item_sk = i_item_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', '85392', '85460', '80348', '81792') - or - i_item_id in (select i_item_id - from item - where i_item_sk in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29) - ) - ) - and ws_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 1999 - group by ca_zip, ca_county - order by ca_zip, ca_county - limit 100; - --- end template query45.tpl query 23 in stream 7 --- start template query48.tpl query 24 in stream 7 -select /* TPC-DS query48.tpl 0.74 */ sum (ss_quantity) - from store_sales, store, customer_demographics, customer_address, date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2002 - and - ( - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'D' - and - cd_education_status = '4 yr Degree' - and - ss_sales_price between 100.00 and 150.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'M' - and - cd_education_status = 'Advanced Degree' - and - ss_sales_price between 50.00 and 100.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'S' - and - cd_education_status = 'Unknown' - and - ss_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('KY', 'FL', 'SD') - and ss_net_profit between 0 and 2000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('MT', 'MI', 'NY') - and ss_net_profit between 150 and 3000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('KS', 'IL', 'WV') - and ss_net_profit between 50 and 25000 - ) - ) -; - --- end template query48.tpl query 24 in stream 7 --- start template query80a.tpl query 25 in stream 7 -with /* TPC-DS query80a.tpl 0.6 */ ssr as - (select s_store_id as store_id, - sum(ss_ext_sales_price) as sales, - sum(coalesce(sr_return_amt, 0)) as returns, - sum(ss_net_profit - coalesce(sr_net_loss, 0)) as profit - from store_sales left outer join store_returns on - (ss_item_sk = sr_item_sk and ss_ticket_number = sr_ticket_number), - date_dim, - store, - item, - promotion - where ss_sold_date_sk = d_date_sk - and d_date between cast('2002-08-08' as date) - and dateadd(day,30,cast('2002-08-08' as date)) - and ss_store_sk = s_store_sk - and ss_item_sk = i_item_sk - and i_current_price > 50 - and ss_promo_sk = p_promo_sk - and p_channel_tv = 'N' - group by s_store_id) - , - csr as - (select cp_catalog_page_id as catalog_page_id, - sum(cs_ext_sales_price) as sales, - sum(coalesce(cr_return_amount, 0)) as returns, - sum(cs_net_profit - coalesce(cr_net_loss, 0)) as profit - from catalog_sales left outer join catalog_returns on - (cs_item_sk = cr_item_sk and cs_order_number = cr_order_number), - date_dim, - catalog_page, - item, - promotion - where cs_sold_date_sk = d_date_sk - and d_date between cast('2002-08-08' as date) - and dateadd(day,30,cast('2002-08-08' as date)) - and cs_catalog_page_sk = cp_catalog_page_sk - and cs_item_sk = i_item_sk - and i_current_price > 50 - and cs_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(ws_ext_sales_price) as sales, - sum(coalesce(wr_return_amt, 0)) as returns, - sum(ws_net_profit - coalesce(wr_net_loss, 0)) as profit - from web_sales left outer join web_returns on - (ws_item_sk = wr_item_sk and ws_order_number = wr_order_number), - date_dim, - web_site, - item, - promotion - where ws_sold_date_sk = d_date_sk - and d_date between cast('2002-08-08' as date) - and dateadd(day,30,cast('2002-08-08' as date)) - and ws_web_site_sk = web_site_sk - and ws_item_sk = i_item_sk - and i_current_price > 50 - and ws_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by web_site_id) -, -results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || store_id as id - , sales - , returns - , profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || catalog_page_id as id - , sales - , returns - , profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , profit - from wsr - ) x - group by channel, id) - - select channel - , id - , sales - , returns - , profit - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results - ) foo - order by channel, id - limit 100; - --- end template query80a.tpl query 25 in stream 7 --- start template query20.tpl query 26 in stream 7 -select /* TPC-DS query20.tpl 0.65 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(cs_ext_sales_price) as itemrevenue - ,sum(cs_ext_sales_price)*100/sum(sum(cs_ext_sales_price)) over - (partition by i_class) as revenueratio - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and i_category in ('Books', 'Jewelry', 'Electronics') - and cs_sold_date_sk = d_date_sk - and d_date between cast('1999-04-18' as date) - and dateadd(day,30,cast('1999-04-18' as date)) - group by i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - order by i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query20.tpl query 26 in stream 7 --- start template query2.tpl query 27 in stream 7 -with /* TPC-DS query2.tpl 0.84 */ wscs as - (select sold_date_sk - ,sales_price - from (select ws_sold_date_sk sold_date_sk - ,ws_ext_sales_price sales_price - from web_sales - union all - select cs_sold_date_sk sold_date_sk - ,cs_ext_sales_price sales_price - from catalog_sales)), - wswscs as - (select d_week_seq, - sum(case when (d_day_name='Sunday') then sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then sales_price else null end) sat_sales - from wscs - ,date_dim - where d_date_sk = sold_date_sk - group by d_week_seq) - select d_week_seq1 - ,round(sun_sales1/sun_sales2,2) - ,round(mon_sales1/mon_sales2,2) - ,round(tue_sales1/tue_sales2,2) - ,round(wed_sales1/wed_sales2,2) - ,round(thu_sales1/thu_sales2,2) - ,round(fri_sales1/fri_sales2,2) - ,round(sat_sales1/sat_sales2,2) - from - (select wswscs.d_week_seq d_week_seq1 - ,sun_sales sun_sales1 - ,mon_sales mon_sales1 - ,tue_sales tue_sales1 - ,wed_sales wed_sales1 - ,thu_sales thu_sales1 - ,fri_sales fri_sales1 - ,sat_sales sat_sales1 - from wswscs,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 1999) y, - (select wswscs.d_week_seq d_week_seq2 - ,sun_sales sun_sales2 - ,mon_sales mon_sales2 - ,tue_sales tue_sales2 - ,wed_sales wed_sales2 - ,thu_sales thu_sales2 - ,fri_sales fri_sales2 - ,sat_sales sat_sales2 - from wswscs - ,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 1999+1) z - where d_week_seq1=d_week_seq2-53 - order by d_week_seq1; - --- end template query2.tpl query 27 in stream 7 --- start template query21.tpl query 28 in stream 7 -select /* TPC-DS query21.tpl 0.14 */ * - from(select w_warehouse_name - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('2001-02-26' as date)) - then inv_quantity_on_hand - else 0 end) as inv_before - ,sum(case when (cast(d_date as date) >= cast ('2001-02-26' as date)) - then inv_quantity_on_hand - else 0 end) as inv_after - from inventory - ,warehouse - ,item - ,date_dim - where i_current_price between 0.99 and 1.49 - and i_item_sk = inv_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('2001-02-26' as date)) - and dateadd(day,30,cast ('2001-02-26' as date)) - group by w_warehouse_name, i_item_id) x - where (case when inv_before > 0 - then inv_after / inv_before - else null - end) between 2.0/3.0 and 3.0/2.0 - order by w_warehouse_name - ,i_item_id - limit 100; - --- end template query21.tpl query 28 in stream 7 --- start template query97.tpl query 29 in stream 7 -with /* TPC-DS query97.tpl 0.38 */ ssci as ( -select ss_customer_sk customer_sk - ,ss_item_sk item_sk -from store_sales,date_dim -where ss_sold_date_sk = d_date_sk - and d_month_seq between 1194 and 1194 + 11 -group by ss_customer_sk - ,ss_item_sk), -csci as( - select cs_bill_customer_sk customer_sk - ,cs_item_sk item_sk -from catalog_sales,date_dim -where cs_sold_date_sk = d_date_sk - and d_month_seq between 1194 and 1194 + 11 -group by cs_bill_customer_sk - ,cs_item_sk) - select sum(case when ssci.customer_sk is not null and csci.customer_sk is null then 1 else 0 end) store_only - ,sum(case when ssci.customer_sk is null and csci.customer_sk is not null then 1 else 0 end) catalog_only - ,sum(case when ssci.customer_sk is not null and csci.customer_sk is not null then 1 else 0 end) store_and_catalog -from ssci full outer join csci on (ssci.customer_sk=csci.customer_sk - and ssci.item_sk = csci.item_sk) -limit 100; - --- end template query97.tpl query 29 in stream 7 --- start template query62.tpl query 30 in stream 7 -select /* TPC-DS query62.tpl 0.24 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 30) and - (ws_ship_date_sk - ws_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 60) and - (ws_ship_date_sk - ws_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 90) and - (ws_ship_date_sk - ws_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - web_sales - ,warehouse - ,ship_mode - ,web_site - ,date_dim -where - d_month_seq between 1201 and 1201 + 11 -and ws_ship_date_sk = d_date_sk -and ws_warehouse_sk = w_warehouse_sk -and ws_ship_mode_sk = sm_ship_mode_sk -and ws_web_site_sk = web_site_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -limit 100; - --- end template query62.tpl query 30 in stream 7 --- start template query47.tpl query 31 in stream 7 -with /* TPC-DS query47.tpl 0.42 */ v1 as( - select i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, - s_store_name, s_company_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - s_store_name, s_company_name - order by d_year, d_moy) rn - from item, store_sales, date_dim, store - where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - ( - d_year = 2001 or - ( d_year = 2001-1 and d_moy =12) or - ( d_year = 2001+1 and d_moy =1) - ) - group by i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy), - v2 as( - select v1.i_brand - ,v1.d_year - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1.s_store_name = v1_lag.s_store_name and - v1.s_store_name = v1_lead.s_store_name and - v1.s_company_name = v1_lag.s_company_name and - v1.s_company_name = v1_lead.s_company_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 2001 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, psum - limit 100; - --- end template query47.tpl query 31 in stream 7 --- start template query60.tpl query 32 in stream 7 -with /* TPC-DS query60.tpl 0.29 */ ss as ( - select - i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Jewelry')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 8 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - cs as ( - select - i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Jewelry')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 8 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - ws as ( - select - i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Jewelry')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 8 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id) - select - i_item_id -,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by i_item_id - ,total_sales - limit 100; - --- end template query60.tpl query 32 in stream 7 --- start template query71.tpl query 33 in stream 7 -select /* TPC-DS query71.tpl 0.72 */ i_brand_id brand_id, i_brand brand,t_hour,t_minute, - sum(ext_price) ext_price - from item, (select ws_ext_sales_price as ext_price, - ws_sold_date_sk as sold_date_sk, - ws_item_sk as sold_item_sk, - ws_sold_time_sk as time_sk - from web_sales,date_dim - where d_date_sk = ws_sold_date_sk - and d_moy=11 - and d_year=1998 - union all - select cs_ext_sales_price as ext_price, - cs_sold_date_sk as sold_date_sk, - cs_item_sk as sold_item_sk, - cs_sold_time_sk as time_sk - from catalog_sales,date_dim - where d_date_sk = cs_sold_date_sk - and d_moy=11 - and d_year=1998 - union all - select ss_ext_sales_price as ext_price, - ss_sold_date_sk as sold_date_sk, - ss_item_sk as sold_item_sk, - ss_sold_time_sk as time_sk - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - and d_moy=11 - and d_year=1998 - ) tmp,time_dim - where - sold_item_sk = i_item_sk - and i_manager_id=1 - and time_sk = t_time_sk - and (t_meal_time = 'breakfast' or t_meal_time = 'dinner') - group by i_brand, i_brand_id,t_hour,t_minute - order by ext_price desc, i_brand_id - ; - --- end template query71.tpl query 33 in stream 7 --- start template query46.tpl query 34 in stream 7 -select /* TPC-DS query46.tpl 0.23 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and (household_demographics.hd_dep_count = 0 or - household_demographics.hd_vehicle_count= -1) - and date_dim.d_dow in (6,0) - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_city in ('Pine Grove','Pleasant Grove','Pleasant Hill','Stringtown','Clinton') - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,ca_city) dn,customer,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - limit 100; - --- end template query46.tpl query 34 in stream 7 --- start template query10.tpl query 35 in stream 7 -select /* TPC-DS query10.tpl 0.26 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3, - cd_dep_count, - count(*) cnt4, - cd_dep_employed_count, - count(*) cnt5, - cd_dep_college_count, - count(*) cnt6 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_county in ('Walsh County','Logan County','Ross County','Freestone County','Pike County') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 1999 and - d_moy between 4 and 4+3) and - (exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 1999 and - d_moy between 4 ANd 4+3) or - exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 1999 and - d_moy between 4 and 4+3)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count -limit 100; - --- end template query10.tpl query 35 in stream 7 --- start template query14a.tpl query 36 in stream 7 -with /* TPC-DS query14a.tpl 0.69 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 2000 AND 2000 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 2000 AND 2000 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 2000 AND 2000 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as - (select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2) x) -, - results AS -(select channel, i_brand_id, i_class_id, i_category_id, sum(sales) sum_sales, sum(number_sales) number_sales - from ( - select 'store' channel, i_brand_id,i_class_id - ,i_category_id,sum(ss_quantity*ss_list_price) sales - , count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2000+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales) - union all - select 'catalog' channel, i_brand_id,i_class_id,i_category_id, sum(cs_quantity*cs_list_price) sales, count(*) number_sales - from catalog_sales - ,item - ,date_dim - where cs_item_sk in (select ss_item_sk from cross_items) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2000+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(cs_quantity*cs_list_price) > (select average_sales from avg_sales) - union all - select 'web' channel, i_brand_id,i_class_id,i_category_id, sum(ws_quantity*ws_list_price) sales , count(*) number_sales - from web_sales - ,item - ,date_dim - where ws_item_sk in (select ss_item_sk from cross_items) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2000+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ws_quantity*ws_list_price) > (select average_sales from avg_sales) - ) y - group by channel, i_brand_id,i_class_id,i_category_id) - - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales -from ( - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales from results - union - select channel, i_brand_id, i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id, i_class_id - union - select channel, i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id - union - select channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel - union - select null as channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results) z -order by channel, i_brand_id, i_class_id, i_category_id - limit 100; -with /* TPC-DS query14a.tpl 0.69 part2 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 2000 AND 2000 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 2000 AND 2000 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 2000 AND 2000 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as -(select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2) x) - select this_year.channel ty_channel - ,this_year.i_brand_id ty_brand - ,this_year.i_class_id ty_class - ,this_year.i_category_id ty_category - ,this_year.sales ty_sales - ,this_year.number_sales ty_number_sales - ,last_year.channel ly_channel - ,last_year.i_brand_id ly_brand - ,last_year.i_class_id ly_class - ,last_year.i_category_id ly_category - ,last_year.sales ly_sales - ,last_year.number_sales ly_number_sales -from - (select 'store' channel, i_brand_id,i_class_id,i_category_id - ,sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 2000 + 1 - and d_moy = 12 - and d_dom = 1) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) this_year, - (select 'store' channel, i_brand_id,i_class_id - ,i_category_id, sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 2000 - and d_moy = 12 - and d_dom = 1) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) last_year - where this_year.i_brand_id= last_year.i_brand_id - and this_year.i_class_id = last_year.i_class_id - and this_year.i_category_id = last_year.i_category_id - order by this_year.channel, this_year.i_brand_id, this_year.i_class_id, this_year.i_category_id - limit 100; - --- end template query14a.tpl query 36 in stream 7 --- start template query35a.tpl query 37 in stream 7 -select /* TPC-DS query35a.tpl 0.47 */ - ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - count(*) cnt1, - sum(cd_dep_count), - sum(cd_dep_count), - min(cd_dep_count), - cd_dep_employed_count, - count(*) cnt2, - sum(cd_dep_employed_count), - sum(cd_dep_employed_count), - min(cd_dep_employed_count), - cd_dep_college_count, - count(*) cnt3, - sum(cd_dep_college_count), - sum(cd_dep_college_count), - min(cd_dep_college_count) - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2000 and - d_qoy < 4) and - exists (select * from - (select ws_bill_customer_sk customsk - from web_sales,date_dim - where - ws_sold_date_sk = d_date_sk and - d_year = 2000 and - d_qoy < 4 - union all - select cs_ship_customer_sk customsk - from catalog_sales,date_dim - where - cs_sold_date_sk = d_date_sk and - d_year = 2000 and - d_qoy < 4)x - where x.customsk = c.c_customer_sk) - group by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - limit 100; - --- end template query35a.tpl query 37 in stream 7 --- start template query55.tpl query 38 in stream 7 -select /* TPC-DS query55.tpl 0.82 */ i_brand_id brand_id, i_brand brand, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=65 - and d_moy=11 - and d_year=1999 - group by i_brand, i_brand_id - order by ext_price desc, i_brand_id -limit 100 ; - --- end template query55.tpl query 38 in stream 7 --- start template query37.tpl query 39 in stream 7 -select /* TPC-DS query37.tpl 0.31 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, catalog_sales - where i_current_price between 48 and 48 + 30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('2001-01-03' as date) and dateadd(day,60,cast('2001-01-03' as date)) - and i_manufact_id in (781,934,761,803) - and inv_quantity_on_hand between 100 and 500 - and cs_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query37.tpl query 39 in stream 7 --- start template query52.tpl query 40 in stream 7 -select /* TPC-DS query52.tpl 0.59 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_sales_price) ext_price - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=11 - and dt.d_year=2001 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,ext_price desc - ,brand_id -limit 100 ; - --- end template query52.tpl query 40 in stream 7 --- start template query9.tpl query 41 in stream 7 -select /* TPC-DS query9.tpl 0.49 */ case when (select count(*) - from store_sales - where ss_quantity between 1 and 20) > 11059080 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 1 and 20) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 1 and 20) end bucket1 , - case when (select count(*) - from store_sales - where ss_quantity between 21 and 40) > 67713305 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 21 and 40) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 21 and 40) end bucket2, - case when (select count(*) - from store_sales - where ss_quantity between 41 and 60) > 110927476 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 41 and 60) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 41 and 60) end bucket3, - case when (select count(*) - from store_sales - where ss_quantity between 61 and 80) > 138660616 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 61 and 80) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 61 and 80) end bucket4, - case when (select count(*) - from store_sales - where ss_quantity between 81 and 100) > 35618279 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 81 and 100) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 81 and 100) end bucket5 -from reason -where r_reason_sk = 1 -; - --- end template query9.tpl query 41 in stream 7 --- start template query85.tpl query 42 in stream 7 -select /* TPC-DS query85.tpl 0.33 */ substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) - from web_sales, web_returns, web_page, customer_demographics cd1, - customer_demographics cd2, customer_address, date_dim, reason - where ws_web_page_sk = wp_web_page_sk - and ws_item_sk = wr_item_sk - and ws_order_number = wr_order_number - and ws_sold_date_sk = d_date_sk and d_year = 2001 - and cd1.cd_demo_sk = wr_refunded_cdemo_sk - and cd2.cd_demo_sk = wr_returning_cdemo_sk - and ca_address_sk = wr_refunded_addr_sk - and r_reason_sk = wr_reason_sk - and - ( - ( - cd1.cd_marital_status = 'S' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Advanced Degree' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 100.00 and 150.00 - ) - or - ( - cd1.cd_marital_status = 'U' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'College' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 50.00 and 100.00 - ) - or - ( - cd1.cd_marital_status = 'D' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Unknown' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ca_country = 'United States' - and - ca_state in ('MS', 'AK', 'KS') - and ws_net_profit between 100 and 200 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('TX', 'OH', 'PA') - and ws_net_profit between 150 and 300 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('MI', 'AR', 'IN') - and ws_net_profit between 50 and 250 - ) - ) -group by r_reason_desc -order by substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) -limit 100; - --- end template query85.tpl query 42 in stream 7 --- start template query40.tpl query 43 in stream 7 -select /* TPC-DS query40.tpl 0.86 */ - w_state - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('1999-04-16' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_before - ,sum(case when (cast(d_date as date) >= cast ('1999-04-16' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_after - from - catalog_sales left outer join catalog_returns on - (cs_order_number = cr_order_number - and cs_item_sk = cr_item_sk) - ,warehouse - ,item - ,date_dim - where - i_current_price between 0.99 and 1.49 - and i_item_sk = cs_item_sk - and cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('1999-04-16' as date)) - and dateadd(day,30,cast ('1999-04-16' as date)) - group by - w_state,i_item_id - order by w_state,i_item_id -limit 100; - --- end template query40.tpl query 43 in stream 7 --- start template query76.tpl query 44 in stream 7 -select /* TPC-DS query76.tpl 0.99 */ channel, col_name, d_year, d_qoy, i_category, COUNT(*) sales_cnt, SUM(ext_sales_price) sales_amt FROM ( - SELECT 'store' as channel, 'ss_customer_sk' col_name, d_year, d_qoy, i_category, ss_ext_sales_price ext_sales_price - FROM store_sales, item, date_dim - WHERE ss_customer_sk IS NULL - AND ss_sold_date_sk=d_date_sk - AND ss_item_sk=i_item_sk - UNION ALL - SELECT 'web' as channel, 'ws_warehouse_sk' col_name, d_year, d_qoy, i_category, ws_ext_sales_price ext_sales_price - FROM web_sales, item, date_dim - WHERE ws_warehouse_sk IS NULL - AND ws_sold_date_sk=d_date_sk - AND ws_item_sk=i_item_sk - UNION ALL - SELECT 'catalog' as channel, 'cs_warehouse_sk' col_name, d_year, d_qoy, i_category, cs_ext_sales_price ext_sales_price - FROM catalog_sales, item, date_dim - WHERE cs_warehouse_sk IS NULL - AND cs_sold_date_sk=d_date_sk - AND cs_item_sk=i_item_sk) foo -GROUP BY channel, col_name, d_year, d_qoy, i_category -ORDER BY channel, col_name, d_year, d_qoy, i_category -limit 100; - --- end template query76.tpl query 44 in stream 7 --- start template query44.tpl query 45 in stream 7 -select /* TPC-DS query44.tpl 0.4 */ asceding.rnk, i1.i_product_name best_performing, i2.i_product_name worst_performing -from(select * - from (select item_sk,rank() over (order by rank_col asc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 158 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 158 - and ss_customer_sk is null - group by ss_store_sk))V1)V11 - where rnk < 11) asceding, - (select * - from (select item_sk,rank() over (order by rank_col desc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 158 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 158 - and ss_customer_sk is null - group by ss_store_sk))V2)V21 - where rnk < 11) descending, -item i1, -item i2 -where asceding.rnk = descending.rnk - and i1.i_item_sk=asceding.item_sk - and i2.i_item_sk=descending.item_sk -order by asceding.rnk -limit 100; - --- end template query44.tpl query 45 in stream 7 --- start template query3.tpl query 46 in stream 7 -select /* TPC-DS query3.tpl 0.45 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_sales_price) sum_agg - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manufact_id = 57 - and dt.d_moy=12 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,sum_agg desc - ,brand_id - limit 100; - --- end template query3.tpl query 46 in stream 7 --- start template query26.tpl query 47 in stream 7 -select /* TPC-DS query26.tpl 0.85 */ i_item_id, - avg(cs_quantity) agg1, - avg(cs_list_price) agg2, - avg(cs_coupon_amt) agg3, - avg(cs_sales_price) agg4 - from catalog_sales, customer_demographics, date_dim, item, promotion - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd_demo_sk and - cs_promo_sk = p_promo_sk and - cd_gender = 'M' and - cd_marital_status = 'M' and - cd_education_status = 'Advanced Degree' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 2002 - group by i_item_id - order by i_item_id - limit 100; - --- end template query26.tpl query 47 in stream 7 --- start template query19.tpl query 48 in stream 7 -select /* TPC-DS query19.tpl 0.8 */ i_brand_id brand_id, i_brand brand, i_manufact_id, i_manufact, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item,customer,customer_address,store - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=51 - and d_moy=12 - and d_year=2001 - and ss_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and substring(ca_zip,1,5) <> substring(s_zip,1,5) - and ss_store_sk = s_store_sk - group by i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact - order by ext_price desc - ,i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact -limit 100 ; - --- end template query19.tpl query 48 in stream 7 --- start template query58.tpl query 49 in stream 7 -with /* TPC-DS query58.tpl 0.19 */ ss_items as - (select i_item_id item_id - ,sum(ss_ext_sales_price) ss_item_rev - from store_sales - ,item - ,date_dim - where ss_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '2002-04-13')) - and ss_sold_date_sk = d_date_sk - group by i_item_id), - cs_items as - (select i_item_id item_id - ,sum(cs_ext_sales_price) cs_item_rev - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '2002-04-13')) - and cs_sold_date_sk = d_date_sk - group by i_item_id), - ws_items as - (select i_item_id item_id - ,sum(ws_ext_sales_price) ws_item_rev - from web_sales - ,item - ,date_dim - where ws_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq =(select d_week_seq - from date_dim - where d_date = '2002-04-13')) - and ws_sold_date_sk = d_date_sk - group by i_item_id) - select ss_items.item_id - ,ss_item_rev - ,ss_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ss_dev - ,cs_item_rev - ,cs_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 cs_dev - ,ws_item_rev - ,ws_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ws_dev - ,(ss_item_rev+cs_item_rev+ws_item_rev)/3 average - from ss_items,cs_items,ws_items - where ss_items.item_id=cs_items.item_id - and ss_items.item_id=ws_items.item_id - and ss_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - and ss_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and cs_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and cs_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and ws_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and ws_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - order by item_id - ,ss_item_rev - limit 100; - --- end template query58.tpl query 49 in stream 7 --- start template query42.tpl query 50 in stream 7 -select /* TPC-DS query42.tpl 0.61 */ dt.d_year - ,item.i_category_id - ,item.i_category - ,sum(ss_ext_sales_price) - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=11 - and dt.d_year=2000 - group by dt.d_year - ,item.i_category_id - ,item.i_category - order by sum(ss_ext_sales_price) desc,dt.d_year - ,item.i_category_id - ,item.i_category -limit 100 ; - --- end template query42.tpl query 50 in stream 7 --- start template query75.tpl query 51 in stream 7 -WITH /* TPC-DS query75.tpl 0.3 */ all_sales AS ( - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,SUM(sales_cnt) AS sales_cnt - ,SUM(sales_amt) AS sales_amt - FROM (SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,cs_quantity - COALESCE(cr_return_quantity,0) AS sales_cnt - ,cs_ext_sales_price - COALESCE(cr_return_amount,0.0) AS sales_amt - FROM catalog_sales JOIN item ON i_item_sk=cs_item_sk - JOIN date_dim ON d_date_sk=cs_sold_date_sk - LEFT JOIN catalog_returns ON (cs_order_number=cr_order_number - AND cs_item_sk=cr_item_sk) - WHERE i_category='Sports' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ss_quantity - COALESCE(sr_return_quantity,0) AS sales_cnt - ,ss_ext_sales_price - COALESCE(sr_return_amt,0.0) AS sales_amt - FROM store_sales JOIN item ON i_item_sk=ss_item_sk - JOIN date_dim ON d_date_sk=ss_sold_date_sk - LEFT JOIN store_returns ON (ss_ticket_number=sr_ticket_number - AND ss_item_sk=sr_item_sk) - WHERE i_category='Sports' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ws_quantity - COALESCE(wr_return_quantity,0) AS sales_cnt - ,ws_ext_sales_price - COALESCE(wr_return_amt,0.0) AS sales_amt - FROM web_sales JOIN item ON i_item_sk=ws_item_sk - JOIN date_dim ON d_date_sk=ws_sold_date_sk - LEFT JOIN web_returns ON (ws_order_number=wr_order_number - AND ws_item_sk=wr_item_sk) - WHERE i_category='Sports') sales_detail - GROUP BY d_year, i_brand_id, i_class_id, i_category_id, i_manufact_id) - SELECT prev_yr.d_year AS prev_year - ,curr_yr.d_year AS year - ,curr_yr.i_brand_id - ,curr_yr.i_class_id - ,curr_yr.i_category_id - ,curr_yr.i_manufact_id - ,prev_yr.sales_cnt AS prev_yr_cnt - ,curr_yr.sales_cnt AS curr_yr_cnt - ,curr_yr.sales_cnt-prev_yr.sales_cnt AS sales_cnt_diff - ,curr_yr.sales_amt-prev_yr.sales_amt AS sales_amt_diff - FROM all_sales curr_yr, all_sales prev_yr - WHERE curr_yr.i_brand_id=prev_yr.i_brand_id - AND curr_yr.i_class_id=prev_yr.i_class_id - AND curr_yr.i_category_id=prev_yr.i_category_id - AND curr_yr.i_manufact_id=prev_yr.i_manufact_id - AND curr_yr.d_year=2000 - AND prev_yr.d_year=2000-1 - AND CAST(curr_yr.sales_cnt AS DECIMAL(17,2))/CAST(prev_yr.sales_cnt AS DECIMAL(17,2))<0.9 - ORDER BY sales_cnt_diff,sales_amt_diff - limit 100; - --- end template query75.tpl query 51 in stream 7 --- start template query17.tpl query 52 in stream 7 -select /* TPC-DS query17.tpl 0.41 */ i_item_id - ,i_item_desc - ,s_state - ,count(ss_quantity) as store_sales_quantitycount - ,avg(ss_quantity) as store_sales_quantityave - ,stddev_samp(ss_quantity) as store_sales_quantitystdev - ,stddev_samp(ss_quantity)/avg(ss_quantity) as store_sales_quantitycov - ,count(sr_return_quantity) as store_returns_quantitycount - ,avg(sr_return_quantity) as store_returns_quantityave - ,stddev_samp(sr_return_quantity) as store_returns_quantitystdev - ,stddev_samp(sr_return_quantity)/avg(sr_return_quantity) as store_returns_quantitycov - ,count(cs_quantity) as catalog_sales_quantitycount ,avg(cs_quantity) as catalog_sales_quantityave - ,stddev_samp(cs_quantity) as catalog_sales_quantitystdev - ,stddev_samp(cs_quantity)/avg(cs_quantity) as catalog_sales_quantitycov - from store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where d1.d_quarter_name = '1999Q1' - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_quarter_name in ('1999Q1','1999Q2','1999Q3') - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_quarter_name in ('1999Q1','1999Q2','1999Q3') - group by i_item_id - ,i_item_desc - ,s_state - order by i_item_id - ,i_item_desc - ,s_state -limit 100; - --- end template query17.tpl query 52 in stream 7 --- start template query38.tpl query 53 in stream 7 -select /* TPC-DS query38.tpl 0.54 */ count(*) from ( - select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1180 and 1180 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1180 and 1180 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1180 and 1180 + 11 -) hot_cust -limit 100; - --- end template query38.tpl query 53 in stream 7 --- start template query82.tpl query 54 in stream 7 -select /* TPC-DS query82.tpl 0.67 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, store_sales - where i_current_price between 61 and 61+30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('2002-03-16' as date) and dateadd(day,60,cast('2002-03-16' as date)) - and i_manufact_id in (62,714,617,604) - and inv_quantity_on_hand between 100 and 500 - and ss_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query82.tpl query 54 in stream 7 --- start template query87.tpl query 55 in stream 7 -select /* TPC-DS query87.tpl 0.77 */ count(*) -from ((select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1206 and 1206+11) - except - (select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1206 and 1206+11) - except - (select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1206 and 1206+11) -) cool_cust -; - --- end template query87.tpl query 55 in stream 7 --- start template query43.tpl query 56 in stream 7 -select /* TPC-DS query43.tpl 0.15 */ s_store_name, s_store_id, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from date_dim, store_sales, store - where d_date_sk = ss_sold_date_sk and - s_store_sk = ss_store_sk and - s_gmt_offset = -5 and - d_year = 2002 - group by s_store_name, s_store_id - order by s_store_name, s_store_id,sun_sales,mon_sales,tue_sales,wed_sales,thu_sales,fri_sales,sat_sales - limit 100; - --- end template query43.tpl query 56 in stream 7 --- start template query11.tpl query 57 in stream 7 -with /* TPC-DS query11.tpl 0.51 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ss_ext_list_price-ss_ext_discount_amt) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ws_ext_list_price-ws_ext_discount_amt) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_login - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 2001 - and t_s_secyear.dyear = 2001+1 - and t_w_firstyear.dyear = 2001 - and t_w_secyear.dyear = 2001+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else 0.0 end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else 0.0 end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_login -limit 100; - --- end template query11.tpl query 57 in stream 7 --- start template query5a.tpl query 58 in stream 7 -with /* TPC-DS query5a.tpl 0.98 */ ssr as - (select s_store_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ss_store_sk as store_sk, - ss_sold_date_sk as date_sk, - ss_ext_sales_price as sales_price, - ss_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from store_sales - union all - select sr_store_sk as store_sk, - sr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - sr_return_amt as return_amt, - sr_net_loss as net_loss - from store_returns - ) salesreturns, - date_dim, - store - where date_sk = d_date_sk - and d_date between cast('2002-08-12' as date) - and dateadd(day,14,cast('2002-08-12' as date)) - and store_sk = s_store_sk - group by s_store_id) - , - csr as - (select cp_catalog_page_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select cs_catalog_page_sk as page_sk, - cs_sold_date_sk as date_sk, - cs_ext_sales_price as sales_price, - cs_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from catalog_sales - union all - select cr_catalog_page_sk as page_sk, - cr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - cr_return_amount as return_amt, - cr_net_loss as net_loss - from catalog_returns - ) salesreturns, - date_dim, - catalog_page - where date_sk = d_date_sk - and d_date between cast('2002-08-12' as date) - and dateadd(day,14,cast('2002-08-12' as date)) - and page_sk = cp_catalog_page_sk - group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ws_web_site_sk as wsr_web_site_sk, - ws_sold_date_sk as date_sk, - ws_ext_sales_price as sales_price, - ws_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from web_sales - union all - select ws_web_site_sk as wsr_web_site_sk, - wr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - wr_return_amt as return_amt, - wr_net_loss as net_loss - from web_returns left outer join web_sales on - ( wr_item_sk = ws_item_sk - and wr_order_number = ws_order_number) - ) salesreturns, - date_dim, - web_site - where date_sk = d_date_sk - and d_date between cast('2002-08-12' as date) - and dateadd(day,14,cast('2002-08-12' as date)) - and wsr_web_site_sk = web_site_sk - group by web_site_id) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || s_store_id as id - , sales - , returns - , (profit - profit_loss) as profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || cp_catalog_page_id as id - , sales - , returns - , (profit - profit_loss) as profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , (profit - profit_loss) as profit - from wsr - ) x - group by channel, id) - select channel, id, sales, returns, profit from ( - select channel, id, sales, returns, profit from results - union - select channel, null as id, sum(sales), sum(returns), sum(profit) from results group by channel - union - select null as channel, null as id, sum(sales), sum(returns), sum(profit) from results) foo -order by channel, id -limit 100; - --- end template query5a.tpl query 58 in stream 7 --- start template query41.tpl query 59 in stream 7 -select /* TPC-DS query41.tpl 0.62 */ distinct(i_product_name) - from item i1 - where i_manufact_id between 696 and 696+40 - and (select count(*) as item_cnt - from item - where (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'yellow' or i_color = 'peru') and - (i_units = 'Dozen' or i_units = 'Carton') and - (i_size = 'extra large' or i_size = 'N/A') - ) or - (i_category = 'Women' and - (i_color = 'cornsilk' or i_color = 'metallic') and - (i_units = 'Lb' or i_units = 'Tsp') and - (i_size = 'small' or i_size = 'medium') - ) or - (i_category = 'Men' and - (i_color = 'dark' or i_color = 'plum') and - (i_units = 'Each' or i_units = 'Gram') and - (i_size = 'petite' or i_size = 'economy') - ) or - (i_category = 'Men' and - (i_color = 'linen' or i_color = 'thistle') and - (i_units = 'Cup' or i_units = 'Ounce') and - (i_size = 'extra large' or i_size = 'N/A') - ))) or - (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'frosted' or i_color = 'sienna') and - (i_units = 'Box' or i_units = 'Pound') and - (i_size = 'extra large' or i_size = 'N/A') - ) or - (i_category = 'Women' and - (i_color = 'cream' or i_color = 'moccasin') and - (i_units = 'Dram' or i_units = 'Bundle') and - (i_size = 'small' or i_size = 'medium') - ) or - (i_category = 'Men' and - (i_color = 'firebrick' or i_color = 'misty') and - (i_units = 'Pallet' or i_units = 'Tbl') and - (i_size = 'petite' or i_size = 'economy') - ) or - (i_category = 'Men' and - (i_color = 'olive' or i_color = 'deep') and - (i_units = 'Unknown' or i_units = 'Bunch') and - (i_size = 'extra large' or i_size = 'N/A') - )))) > 0 - order by i_product_name - limit 100; - --- end template query41.tpl query 59 in stream 7 --- start template query61.tpl query 60 in stream 7 -select /* TPC-DS query61.tpl 0.97 */ promotions,total,cast(promotions as decimal(15,4))/cast(total as decimal(15,4))*100 -from - (select sum(ss_ext_sales_price) promotions - from store_sales - ,store - ,promotion - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_promo_sk = p_promo_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -7 - and i_category = 'Electronics' - and (p_channel_dmail = 'Y' or p_channel_email = 'Y' or p_channel_tv = 'Y') - and s_gmt_offset = -7 - and d_year = 1999 - and d_moy = 11) promotional_sales, - (select sum(ss_ext_sales_price) total - from store_sales - ,store - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -7 - and i_category = 'Electronics' - and s_gmt_offset = -7 - and d_year = 1999 - and d_moy = 11) all_sales -order by promotions, total -limit 100; - --- end template query61.tpl query 60 in stream 7 --- start template query33.tpl query 61 in stream 7 -with /* TPC-DS query33.tpl 0.22 */ ss as ( - select - i_manufact_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Jewelry')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 7 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id), - cs as ( - select - i_manufact_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Jewelry')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 7 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id), - ws as ( - select - i_manufact_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Jewelry')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 7 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id) - select i_manufact_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_manufact_id - order by total_sales -limit 100; - --- end template query33.tpl query 61 in stream 7 --- start template query49.tpl query 62 in stream 7 -select /* TPC-DS query49.tpl 0.48 */ channel, item, return_ratio, return_rank, currency_rank from - (select - 'web' as channel - ,web.item - ,web.return_ratio - ,web.return_rank - ,web.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select ws.ws_item_sk as item - ,(cast(sum(coalesce(wr.wr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(wr.wr_return_amt,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - web_sales ws left outer join web_returns wr - on (ws.ws_order_number = wr.wr_order_number and - ws.ws_item_sk = wr.wr_item_sk) - ,date_dim - where - wr.wr_return_amt > 10000 - and ws.ws_net_profit > 1 - and ws.ws_net_paid > 0 - and ws.ws_quantity > 0 - and ws_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 12 - group by ws.ws_item_sk - ) in_web - ) web - where - ( - web.return_rank <= 10 - or - web.currency_rank <= 10 - ) - union - select - 'catalog' as channel - ,catalog.item - ,catalog.return_ratio - ,catalog.return_rank - ,catalog.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select - cs.cs_item_sk as item - ,(cast(sum(coalesce(cr.cr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(cr.cr_return_amount,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - catalog_sales cs left outer join catalog_returns cr - on (cs.cs_order_number = cr.cr_order_number and - cs.cs_item_sk = cr.cr_item_sk) - ,date_dim - where - cr.cr_return_amount > 10000 - and cs.cs_net_profit > 1 - and cs.cs_net_paid > 0 - and cs.cs_quantity > 0 - and cs_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 12 - group by cs.cs_item_sk - ) in_cat - ) catalog - where - ( - catalog.return_rank <= 10 - or - catalog.currency_rank <=10 - ) - union - select - 'store' as channel - ,store.item - ,store.return_ratio - ,store.return_rank - ,store.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select sts.ss_item_sk as item - ,(cast(sum(coalesce(sr.sr_return_quantity,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(sr.sr_return_amt,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - store_sales sts left outer join store_returns sr - on (sts.ss_ticket_number = sr.sr_ticket_number and sts.ss_item_sk = sr.sr_item_sk) - ,date_dim - where - sr.sr_return_amt > 10000 - and sts.ss_net_profit > 1 - and sts.ss_net_paid > 0 - and sts.ss_quantity > 0 - and ss_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 12 - group by sts.ss_item_sk - ) in_store - ) store - where ( - store.return_rank <= 10 - or - store.currency_rank <= 10 - ) - ) - order by 1,4,5,2 - limit 100; - --- end template query49.tpl query 62 in stream 7 --- start template query7.tpl query 63 in stream 7 -select /* TPC-DS query7.tpl 0.2 */ i_item_id, - avg(ss_quantity) agg1, - avg(ss_list_price) agg2, - avg(ss_coupon_amt) agg3, - avg(ss_sales_price) agg4 - from store_sales, customer_demographics, date_dim, item, promotion - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_cdemo_sk = cd_demo_sk and - ss_promo_sk = p_promo_sk and - cd_gender = 'M' and - cd_marital_status = 'U' and - cd_education_status = 'College' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 1998 - group by i_item_id - order by i_item_id - limit 100; - --- end template query7.tpl query 63 in stream 7 --- start template query73.tpl query 64 in stream 7 -select /* TPC-DS query73.tpl 0.79 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_buy_potential = '1001-5000' or - household_demographics.hd_buy_potential = 'Unknown') - and household_demographics.hd_vehicle_count > 0 - and case when household_demographics.hd_vehicle_count > 0 then - household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count else null end > 1 - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_county in ('Walker County','Ziebach County','Kittitas County','Gogebic County') - group by ss_ticket_number,ss_customer_sk) dj,customer - where ss_customer_sk = c_customer_sk - and cnt between 1 and 5 - order by cnt desc, c_last_name asc; - --- end template query73.tpl query 64 in stream 7 --- start template query89.tpl query 65 in stream 7 -select /* TPC-DS query89.tpl 0.56 */ * -from( -select i_category, i_class, i_brand, - s_store_name, s_company_name, - d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, s_store_name, s_company_name) - avg_monthly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - d_year in (2000) and - ((i_category in ('Books','Music','Electronics') and - i_class in ('parenting','classical','automotive') - ) - or (i_category in ('Children','Sports','Home') and - i_class in ('infants','outdoor','wallpaper') - )) -group by i_category, i_class, i_brand, - s_store_name, s_company_name, d_moy) tmp1 -where case when (avg_monthly_sales <> 0) then (abs(sum_sales - avg_monthly_sales) / avg_monthly_sales) else null end > 0.1 -order by sum_sales - avg_monthly_sales, s_store_name -limit 100; - --- end template query89.tpl query 65 in stream 7 --- start template query81.tpl query 66 in stream 7 -with /* TPC-DS query81.tpl 0.37 */ customer_total_return as - (select cr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(cr_return_amt_inc_tax) as ctr_total_return - from catalog_returns - ,date_dim - ,customer_address - where cr_returned_date_sk = d_date_sk - and d_year =2002 - and cr_returning_addr_sk = ca_address_sk - group by cr_returning_customer_sk - ,ca_state ) - select c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'NE' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - limit 100; - --- end template query81.tpl query 66 in stream 7 --- start template query78.tpl query 67 in stream 7 -with /* TPC-DS query78.tpl 0.10 */ ws as - (select d_year AS ws_sold_year, ws_item_sk, - ws_bill_customer_sk ws_customer_sk, - sum(ws_quantity) ws_qty, - sum(ws_wholesale_cost) ws_wc, - sum(ws_sales_price) ws_sp - from web_sales - left join web_returns on wr_order_number=ws_order_number and ws_item_sk=wr_item_sk - join date_dim on ws_sold_date_sk = d_date_sk - where wr_order_number is null - group by d_year, ws_item_sk, ws_bill_customer_sk - ), -cs as - (select d_year AS cs_sold_year, cs_item_sk, - cs_bill_customer_sk cs_customer_sk, - sum(cs_quantity) cs_qty, - sum(cs_wholesale_cost) cs_wc, - sum(cs_sales_price) cs_sp - from catalog_sales - left join catalog_returns on cr_order_number=cs_order_number and cs_item_sk=cr_item_sk - join date_dim on cs_sold_date_sk = d_date_sk - where cr_order_number is null - group by d_year, cs_item_sk, cs_bill_customer_sk - ), -ss as - (select d_year AS ss_sold_year, ss_item_sk, - ss_customer_sk, - sum(ss_quantity) ss_qty, - sum(ss_wholesale_cost) ss_wc, - sum(ss_sales_price) ss_sp - from store_sales - left join store_returns on sr_ticket_number=ss_ticket_number and ss_item_sk=sr_item_sk - join date_dim on ss_sold_date_sk = d_date_sk - where sr_ticket_number is null - group by d_year, ss_item_sk, ss_customer_sk - ) - select -ss_item_sk, -round(ss_qty/(coalesce(ws_qty,0)+coalesce(cs_qty,0)),2) ratio, -ss_qty store_qty, ss_wc store_wholesale_cost, ss_sp store_sales_price, -coalesce(ws_qty,0)+coalesce(cs_qty,0) other_chan_qty, -coalesce(ws_wc,0)+coalesce(cs_wc,0) other_chan_wholesale_cost, -coalesce(ws_sp,0)+coalesce(cs_sp,0) other_chan_sales_price -from ss -left join ws on (ws_sold_year=ss_sold_year and ws_item_sk=ss_item_sk and ws_customer_sk=ss_customer_sk) -left join cs on (cs_sold_year=ss_sold_year and cs_item_sk=ss_item_sk and cs_customer_sk=ss_customer_sk) -where (coalesce(ws_qty,0)>0 or coalesce(cs_qty, 0)>0) and ss_sold_year=1999 -order by - ss_item_sk, - ss_qty desc, ss_wc desc, ss_sp desc, - other_chan_qty, - other_chan_wholesale_cost, - other_chan_sales_price, - ratio -limit 100; - --- end template query78.tpl query 67 in stream 7 --- start template query18a.tpl query 68 in stream 7 -with /* TPC-DS query18a.tpl 0.90 */ results as - (select i_item_id, - ca_country, - ca_state, - ca_county, - cast(cs_quantity as decimal(12,2)) agg1, - cast(cs_list_price as decimal(12,2)) agg2, - cast(cs_coupon_amt as decimal(12,2)) agg3, - cast(cs_sales_price as decimal(12,2)) agg4, - cast(cs_net_profit as decimal(12,2)) agg5, - cast(c_birth_year as decimal(12,2)) agg6, - cast(cd1.cd_dep_count as decimal(12,2)) agg7 - from catalog_sales, customer_demographics cd1, customer_demographics cd2, customer, customer_address, date_dim, item - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd1.cd_demo_sk and - cs_bill_customer_sk = c_customer_sk and - cd1.cd_gender = 'F' and - cd1.cd_education_status = 'Unknown' and - c_current_cdemo_sk = cd2.cd_demo_sk and - c_current_addr_sk = ca_address_sk and - c_birth_month in (9,2,8,10,7,3) and - d_year = 2002 and - ca_state in ('TN','TX','NC','MT','CO','FL','AK') - ) - select i_item_id, ca_country, ca_state, ca_county, agg1, agg2, agg3, agg4, agg5, agg6, agg7 - from ( - select i_item_id, ca_country, ca_state, ca_county, avg(agg1) agg1, - avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state, ca_county - union all - select i_item_id, ca_country, ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state - union all - select i_item_id, ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country - union all - select i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - ) foo - order by ca_country, ca_state, ca_county, i_item_id - limit 100; - --- end template query18a.tpl query 68 in stream 7 --- start template query36a.tpl query 69 in stream 7 -with /* TPC-DS query36a.tpl 0.21 */ results as - (select - sum(ss_net_profit) as ss_net_profit, sum(ss_ext_sales_price) as ss_ext_sales_price, - sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin - ,i_category - ,i_class - ,0 as g_category, 0 as g_class - from - store_sales - ,date_dim d1 - ,item - ,store - where - d1.d_year = 2000 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and s_state in ('GA','TN','OH','NE', - 'AL','PA','NY','AL') - group by i_category,i_class) - , - results_rollup as - (select gross_margin ,i_category ,i_class,0 as t_category, 0 as t_class, 0 as lochierarchy from results - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - i_category, NULL AS i_class, 0 as t_category, 1 as t_class, 1 as lochierarchy from results group by i_category - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - NULL AS i_category ,NULL AS i_class, 1 as t_category, 1 as t_class, 2 as lochierarchy from results) - select - gross_margin ,i_category ,i_class, lochierarchy,rank() over ( - partition by lochierarchy, case when t_class = 0 then i_category end - order by gross_margin asc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then i_category end - ,rank_within_parent - limit 100; - --- end template query36a.tpl query 69 in stream 7 --- start template query51.tpl query 70 in stream 7 -WITH /* TPC-DS query51.tpl 0.46 */ web_v1 as ( -select - ws_item_sk item_sk, d_date, - sum(sum(ws_sales_price)) - over (partition by ws_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from web_sales - ,date_dim -where ws_sold_date_sk=d_date_sk - and d_month_seq between 1191 and 1191+11 - and ws_item_sk is not NULL -group by ws_item_sk, d_date), -store_v1 as ( -select - ss_item_sk item_sk, d_date, - sum(sum(ss_sales_price)) - over (partition by ss_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from store_sales - ,date_dim -where ss_sold_date_sk=d_date_sk - and d_month_seq between 1191 and 1191+11 - and ss_item_sk is not NULL -group by ss_item_sk, d_date) - select * -from (select item_sk - ,d_date - ,web_sales - ,store_sales - ,max(web_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) web_cumulative - ,max(store_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) store_cumulative - from (select case when web.item_sk is not null then web.item_sk else store.item_sk end item_sk - ,case when web.d_date is not null then web.d_date else store.d_date end d_date - ,web.cume_sales web_sales - ,store.cume_sales store_sales - from web_v1 web full outer join store_v1 store on (web.item_sk = store.item_sk - and web.d_date = store.d_date) - )x )y -where web_cumulative > store_cumulative -order by item_sk - ,d_date -limit 100; - --- end template query51.tpl query 70 in stream 7 --- start template query56.tpl query 71 in stream 7 -with /* TPC-DS query56.tpl 0.83 */ ss as ( - select i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where i_item_id in (select - i_item_id -from item -where i_color in ('purple','rose','deep')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 7 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - cs as ( - select i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('purple','rose','deep')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 7 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - ws as ( - select i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('purple','rose','deep')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 7 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id) - select i_item_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by total_sales, - i_item_id - limit 100; - --- end template query56.tpl query 71 in stream 7 --- start template query83.tpl query 72 in stream 7 -with /* TPC-DS query83.tpl 0.96 */ sr_items as - (select i_item_id item_id, - sum(sr_return_quantity) sr_item_qty - from store_returns, - item, - date_dim - where sr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('1999-07-23','1999-09-10','1999-11-09'))) - and sr_returned_date_sk = d_date_sk - group by i_item_id), - cr_items as - (select i_item_id item_id, - sum(cr_return_quantity) cr_item_qty - from catalog_returns, - item, - date_dim - where cr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('1999-07-23','1999-09-10','1999-11-09'))) - and cr_returned_date_sk = d_date_sk - group by i_item_id), - wr_items as - (select i_item_id item_id, - sum(wr_return_quantity) wr_item_qty - from web_returns, - item, - date_dim - where wr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('1999-07-23','1999-09-10','1999-11-09'))) - and wr_returned_date_sk = d_date_sk - group by i_item_id) - select sr_items.item_id - ,sr_item_qty - ,sr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 sr_dev - ,cr_item_qty - ,cr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 cr_dev - ,wr_item_qty - ,wr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 wr_dev - ,(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 average - from sr_items - ,cr_items - ,wr_items - where sr_items.item_id=cr_items.item_id - and sr_items.item_id=wr_items.item_id - order by sr_items.item_id - ,sr_item_qty - limit 100; - --- end template query83.tpl query 72 in stream 7 --- start template query23.tpl query 73 in stream 7 -with /* TPC-DS query23.tpl 0.68 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (1999,1999+1,1999+2,1999+3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1999,1999+1,1999+2,1999+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * -from - max_store_sales)) - select sum(sales) - from (select cs_quantity*cs_list_price sales - from catalog_sales - ,date_dim - where d_year = 1999 - and d_moy = 4 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - union all - select ws_quantity*ws_list_price sales - from web_sales - ,date_dim - where d_year = 1999 - and d_moy = 4 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer)) - limit 100; -with /* TPC-DS query23.tpl 0.68 part2 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (1999,1999 + 1,1999 + 2,1999 + 3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1999,1999+1,1999+2,1999+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * - from max_store_sales)) - select c_last_name,c_first_name,sales - from (select c_last_name,c_first_name,sum(cs_quantity*cs_list_price) sales - from catalog_sales - ,customer - ,date_dim - where d_year = 1999 - and d_moy = 4 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and cs_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name - union all - select c_last_name,c_first_name,sum(ws_quantity*ws_list_price) sales - from web_sales - ,customer - ,date_dim - where d_year = 1999 - and d_moy = 4 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and ws_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name) - order by c_last_name,c_first_name,sales - limit 100; - --- end template query23.tpl query 73 in stream 7 --- start template query8.tpl query 74 in stream 7 -select /* TPC-DS query8.tpl 0.63 */ s_store_name - ,sum(ss_net_profit) - from store_sales - ,date_dim - ,store, - (select ca_zip - from ( - SELECT substring(ca_zip,1,5) ca_zip - FROM customer_address - WHERE substring(ca_zip,1,5) IN ( - '84453','82541','17371','77534','66266','74556', - '27140','17954','39342','43846','18988', - '49625','41194','87375','22927','11307', - '75228','92814','18015','72626','44225', - '60432','43371','57357','14328','61786', - '52206','18566','64971','42948','13109', - '57056','71246','82389','16815','35246', - '77118','21986','75029','87698','71948', - '48916','59972','68899','78437','80847', - '37733','89975','20439','35161','47911', - '59870','15424','35604','15803','91825', - '31214','73105','83275','26109','20195', - '99375','60648','19023','51611','61166', - '37029','99873','20343','42965','96699', - '45289','40763','79790','25692','58032', - '68822','85440','85438','75825','75090', - '21902','42555','29884','86898','50763', - '82741','55607','38002','78908','81041', - '18305','73998','17034','29009','50497', - '35058','69988','14825','78700','24682', - '52512','45571','33536','64410','14454', - '88881','74540','88821','99110','38080', - '73684','86442','12805','79913','22729', - '13484','49550','88190','14960','71827', - '42410','38192','66842','13203','39715', - '82592','97745','68630','76113','12331', - '80817','76275','34180','60875','99764', - '46427','95637','22333','64890','72878', - '21900','86754','36391','21656','34075', - '83885','36443','50478','66053','87646', - '71609','70137','41048','48889','80960', - '26339','59772','48778','45424','21941', - '29289','36650','69800','94358','30854', - '79276','40670','19342','83571','75232', - '47651','10713','92805','86349','52250', - '51584','75508','82854','94114','29186', - '11230','65309','39614','55120','86136', - '33890','13231','40073','81825','45386', - '70024','48717','96895','96571','26505', - '21095','99095','78261','81506','97978', - '25319','88601','10151','88392','61064', - '36760','99496','41154','88834','38979', - '69729','79353','68299','84664','12880', - '88522','45653','97319','91215','93448', - '55996','38594','28593','47426','67450', - '92316','36953','18910','52437','98584', - '19153','84430','26534','46182','29897', - '73571','86279','21352','65423','41343', - '20734','46011','96518','25930','96131', - '30424','87786','22541','13759','41898', - '47001','94793','66371','80918','12512', - '16192','82650','53764','97678','75540', - '88894','47252','68429','89135','89112', - '96287','78472','35942','70392','92970', - '26565','77587','25003','54721','57386', - '57306','17527','21740','78365','82171', - '32559','96859','48546','61059','75411', - '10470','34935','57323','63601','18035', - '11362','95547','89132','54861','12841', - '12120','94789','40951','84930','85772', - '11658','71020','82903','93646','56340', - '27875','73667','60607','75608','18772', - '45530','61710','78338','88425','97584', - '60067','51433','65037','90991','66378', - '54734','17198','37976','24941','92190', - '29975','73237','62851','62569','30648', - '66353','48955','77510','54577','98202', - '45109','53200','28613','29077','74037', - '98101','90841','53366','76537','57514', - '17965','14319','99972','93170','20875', - '51539','56323','13373','58954','27938', - '24172','46552','22470','32001','26880', - '60768','38551','22695','53765','23713', - '78018','69623','71945','17355','99717', - '16299','48622','86486','86561','17137', - '15025','23872','29069','67881','33299', - '80468','94180','79959','79953','19139', - '51237','52466','31085','32023','94832', - '63632','50780','73425','56197','73465', - '91994','61173','85756','15369') - intersect - select ca_zip - from (SELECT substring(ca_zip,1,5) ca_zip,count(*) cnt - FROM customer_address, customer - WHERE ca_address_sk = c_current_addr_sk and - c_preferred_cust_flag='Y' - group by ca_zip - having count(*) > 10)A1)A2) V1 - where ss_store_sk = s_store_sk - and ss_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 2000 - and (substring(s_zip,1,2) = substring(V1.ca_zip,1,2)) - group by s_store_name - order by s_store_name - limit 100; - --- end template query8.tpl query 74 in stream 7 --- start template query24.tpl query 75 in stream 7 -with /* TPC-DS query24.tpl 0.92 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_net_paid) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip -and s_market_id=6 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'cream' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; -with /* TPC-DS query24.tpl 0.92 part2 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_net_paid) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip - and s_market_id = 6 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'metallic' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; - --- end template query24.tpl query 75 in stream 7 --- start template query63.tpl query 76 in stream 7 -select /* TPC-DS query63.tpl 0.27 */ * -from (select i_manager_id - ,sum(ss_sales_price) sum_sales - ,avg(sum(ss_sales_price)) over (partition by i_manager_id) avg_monthly_sales - from item - ,store_sales - ,date_dim - ,store - where ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and d_month_seq in (1200,1200+1,1200+2,1200+3,1200+4,1200+5,1200+6,1200+7,1200+8,1200+9,1200+10,1200+11) - and (( i_category in ('Books','Children','Electronics') - and i_class in ('personal','portable','reference','self-help') - and i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) - or( i_category in ('Women','Music','Men') - and i_class in ('accessories','classical','fragrances','pants') - and i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manager_id, d_moy) tmp1 -where case when avg_monthly_sales > 0 then abs (sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 -order by i_manager_id - ,avg_monthly_sales - ,sum_sales -limit 100; - --- end template query63.tpl query 76 in stream 7 --- start template query1.tpl query 77 in stream 7 -with /* TPC-DS query1.tpl 0.12 */ customer_total_return as -(select sr_customer_sk as ctr_customer_sk -,sr_store_sk as ctr_store_sk -,sum(SR_STORE_CREDIT) as ctr_total_return -from store_returns -,date_dim -where sr_returned_date_sk = d_date_sk -and d_year =2001 -group by sr_customer_sk -,sr_store_sk) - select c_customer_id -from customer_total_return ctr1 -,store -,customer -where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 -from customer_total_return ctr2 -where ctr1.ctr_store_sk = ctr2.ctr_store_sk) -and s_store_sk = ctr1.ctr_store_sk -and s_state = 'AL' -and ctr1.ctr_customer_sk = c_customer_sk -order by c_customer_id -limit 100; - --- end template query1.tpl query 77 in stream 7 --- start template query12.tpl query 78 in stream 7 -select /* TPC-DS query12.tpl 0.64 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ws_ext_sales_price) as itemrevenue - ,sum(ws_ext_sales_price)*100/sum(sum(ws_ext_sales_price)) over - (partition by i_class) as revenueratio -from - web_sales - ,item - ,date_dim -where - ws_item_sk = i_item_sk - and i_category in ('Children', 'Sports', 'Men') - and ws_sold_date_sk = d_date_sk - and d_date between cast('2001-05-06' as date) - and dateadd(day,30,cast('2001-05-06' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query12.tpl query 78 in stream 7 --- start template query68.tpl query 79 in stream 7 -select /* TPC-DS query68.tpl 0.95 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,extended_price - ,extended_tax - ,list_price - from (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_ext_sales_price) extended_price - ,sum(ss_ext_list_price) list_price - ,sum(ss_ext_tax) extended_tax - from store_sales - ,date_dim - ,store - ,household_demographics - ,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_dep_count = 1 or - household_demographics.hd_vehicle_count= 3) - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_city in ('Farmington','Oakwood') - group by ss_ticket_number - ,ss_customer_sk - ,ss_addr_sk,ca_city) dn - ,customer - ,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,ss_ticket_number - limit 100; - --- end template query68.tpl query 79 in stream 7 --- start template query66.tpl query 80 in stream 7 -select /* TPC-DS query66.tpl 0.39 */ - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - ,sum(jan_sales) as jan_sales - ,sum(feb_sales) as feb_sales - ,sum(mar_sales) as mar_sales - ,sum(apr_sales) as apr_sales - ,sum(may_sales) as may_sales - ,sum(jun_sales) as jun_sales - ,sum(jul_sales) as jul_sales - ,sum(aug_sales) as aug_sales - ,sum(sep_sales) as sep_sales - ,sum(oct_sales) as oct_sales - ,sum(nov_sales) as nov_sales - ,sum(dec_sales) as dec_sales - ,sum(jan_sales/w_warehouse_sq_ft) as jan_sales_per_sq_foot - ,sum(feb_sales/w_warehouse_sq_ft) as feb_sales_per_sq_foot - ,sum(mar_sales/w_warehouse_sq_ft) as mar_sales_per_sq_foot - ,sum(apr_sales/w_warehouse_sq_ft) as apr_sales_per_sq_foot - ,sum(may_sales/w_warehouse_sq_ft) as may_sales_per_sq_foot - ,sum(jun_sales/w_warehouse_sq_ft) as jun_sales_per_sq_foot - ,sum(jul_sales/w_warehouse_sq_ft) as jul_sales_per_sq_foot - ,sum(aug_sales/w_warehouse_sq_ft) as aug_sales_per_sq_foot - ,sum(sep_sales/w_warehouse_sq_ft) as sep_sales_per_sq_foot - ,sum(oct_sales/w_warehouse_sq_ft) as oct_sales_per_sq_foot - ,sum(nov_sales/w_warehouse_sq_ft) as nov_sales_per_sq_foot - ,sum(dec_sales/w_warehouse_sq_ft) as dec_sales_per_sq_foot - ,sum(jan_net) as jan_net - ,sum(feb_net) as feb_net - ,sum(mar_net) as mar_net - ,sum(apr_net) as apr_net - ,sum(may_net) as may_net - ,sum(jun_net) as jun_net - ,sum(jul_net) as jul_net - ,sum(aug_net) as aug_net - ,sum(sep_net) as sep_net - ,sum(oct_net) as oct_net - ,sum(nov_net) as nov_net - ,sum(dec_net) as dec_net - from ( - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'LATVIAN' || ',' || 'GREAT EASTERN' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then ws_ext_list_price* ws_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then ws_ext_list_price* ws_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then ws_ext_list_price* ws_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then ws_ext_list_price* ws_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then ws_ext_list_price* ws_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then ws_ext_list_price* ws_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then ws_ext_list_price* ws_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then ws_ext_list_price* ws_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then ws_ext_list_price* ws_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then ws_ext_list_price* ws_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then ws_ext_list_price* ws_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then ws_ext_list_price* ws_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as dec_net - from - web_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - ws_warehouse_sk = w_warehouse_sk - and ws_sold_date_sk = d_date_sk - and ws_sold_time_sk = t_time_sk - and ws_ship_mode_sk = sm_ship_mode_sk - and d_year = 1998 - and t_time between 47504 and 47504+28800 - and sm_carrier in ('LATVIAN','GREAT EASTERN') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - union all - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'LATVIAN' || ',' || 'GREAT EASTERN' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then cs_ext_list_price* cs_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then cs_ext_list_price* cs_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then cs_ext_list_price* cs_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then cs_ext_list_price* cs_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then cs_ext_list_price* cs_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then cs_ext_list_price* cs_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then cs_ext_list_price* cs_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then cs_ext_list_price* cs_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then cs_ext_list_price* cs_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then cs_ext_list_price* cs_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then cs_ext_list_price* cs_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then cs_ext_list_price* cs_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then cs_net_profit * cs_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then cs_net_profit * cs_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then cs_net_profit * cs_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then cs_net_profit * cs_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then cs_net_profit * cs_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then cs_net_profit * cs_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then cs_net_profit * cs_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then cs_net_profit * cs_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then cs_net_profit * cs_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then cs_net_profit * cs_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then cs_net_profit * cs_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then cs_net_profit * cs_quantity else 0 end) as dec_net - from - catalog_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and cs_sold_time_sk = t_time_sk - and cs_ship_mode_sk = sm_ship_mode_sk - and d_year = 1998 - and t_time between 47504 AND 47504+28800 - and sm_carrier in ('LATVIAN','GREAT EASTERN') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - ) x - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - order by w_warehouse_name - limit 100; - --- end template query66.tpl query 80 in stream 7 --- start template query67a.tpl query 81 in stream 7 -with /* TPC-DS query67a.tpl 0.35 */ results as -( select i_category ,i_class ,i_brand ,i_product_name ,d_year ,d_qoy ,d_moy ,s_store_id - ,sum(coalesce(ss_sales_price*ss_quantity,0)) sumsales - from store_sales ,date_dim ,store ,item - where ss_sold_date_sk=d_date_sk - and ss_item_sk=i_item_sk - and ss_store_sk = s_store_sk - and d_month_seq between 1200 and 1200 + 11 - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy,s_store_id) - , - results_rollup as - (select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, s_store_id, sumsales - from results - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy - union all - select i_category, i_class, i_brand, i_product_name, d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year - union all - select i_category, i_class, i_brand, i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name - union all - select i_category, i_class, i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand - union all - select i_category, i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class - union all - select i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category - union all - select null i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results) - - select * -from (select i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rank() over (partition by i_category order by sumsales desc) rk - from results_rollup) dw2 -where rk <= 100 -order by i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rk -limit 100; - --- end template query67a.tpl query 81 in stream 7 --- start template query77a.tpl query 82 in stream 7 -with /* TPC-DS query77a.tpl 0.78 */ ss as - (select s_store_sk, - sum(ss_ext_sales_price) as sales, - sum(ss_net_profit) as profit - from store_sales, - date_dim, - store - where ss_sold_date_sk = d_date_sk - and d_date between cast('2001-08-19' as date) - and dateadd(day,30,cast('2001-08-19' as date)) - and ss_store_sk = s_store_sk - group by s_store_sk) - , - sr as - (select s_store_sk, - sum(sr_return_amt) as returns, - sum(sr_net_loss) as profit_loss - from store_returns, - date_dim, - store - where sr_returned_date_sk = d_date_sk - and d_date between cast('2001-08-19' as date) - and dateadd(day,30,cast('2001-08-19' as date)) - and sr_store_sk = s_store_sk - group by s_store_sk), - cs as - (select cs_call_center_sk, - sum(cs_ext_sales_price) as sales, - sum(cs_net_profit) as profit - from catalog_sales, - date_dim - where cs_sold_date_sk = d_date_sk - and d_date between cast('2001-08-19' as date) - and dateadd(day,30,cast('2001-08-19' as date)) - group by cs_call_center_sk - ), - cr as - (select cr_call_center_sk, - sum(cr_return_amount) as returns, - sum(cr_net_loss) as profit_loss - from catalog_returns, - date_dim - where cr_returned_date_sk = d_date_sk - and d_date between cast('2001-08-19' as date) - and dateadd(day,30,cast('2001-08-19' as date)) - group by cr_call_center_sk), - ws as - ( select wp_web_page_sk, - sum(ws_ext_sales_price) as sales, - sum(ws_net_profit) as profit - from web_sales, - date_dim, - web_page - where ws_sold_date_sk = d_date_sk - and d_date between cast('2001-08-19' as date) - and dateadd(day,30,cast('2001-08-19' as date)) - and ws_web_page_sk = wp_web_page_sk - group by wp_web_page_sk), - wr as - (select wp_web_page_sk, - sum(wr_return_amt) as returns, - sum(wr_net_loss) as profit_loss - from web_returns, - date_dim, - web_page - where wr_returned_date_sk = d_date_sk - and d_date between cast('2001-08-19' as date) - and dateadd(day,30,cast('2001-08-19' as date)) - and wr_web_page_sk = wp_web_page_sk - group by wp_web_page_sk) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , ss.s_store_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ss left join sr - on ss.s_store_sk = sr.s_store_sk - union all - select 'catalog channel' as channel - , cs_call_center_sk as id - , sales - , returns - , (profit - profit_loss) as profit - from cs - , cr - union all - select 'web channel' as channel - , ws.wp_web_page_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ws left join wr - on ws.wp_web_page_sk = wr.wp_web_page_sk - ) x - group by channel, id ) - - select * - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results -) foo -order by channel, id - limit 100; - --- end template query77a.tpl query 82 in stream 7 --- start template query15.tpl query 83 in stream 7 -select /* TPC-DS query15.tpl 0.57 */ ca_zip - ,sum(cs_sales_price) - from catalog_sales - ,customer - ,customer_address - ,date_dim - where cs_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', - '85392', '85460', '80348', '81792') - or ca_state in ('CA','WA','GA') - or cs_sales_price > 500) - and cs_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 1999 - group by ca_zip - order by ca_zip - limit 100; - --- end template query15.tpl query 83 in stream 7 --- start template query88.tpl query 84 in stream 7 -select /* TPC-DS query88.tpl 0.66 */ * -from - (select count(*) h8_30_to_9 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s1, - (select count(*) h9_to_9_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s2, - (select count(*) h9_30_to_10 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s3, - (select count(*) h10_to_10_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s4, - (select count(*) h10_30_to_11 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s5, - (select count(*) h11_to_11_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s6, - (select count(*) h11_30_to_12 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s7, - (select count(*) h12_to_12_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 12 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s8 -; - --- end template query88.tpl query 84 in stream 7 --- start template query65.tpl query 85 in stream 7 -select /* TPC-DS query65.tpl 0.71 */ - s_store_name, - i_item_desc, - sc.revenue, - i_current_price, - i_wholesale_cost, - i_brand - from store, item, - (select ss_store_sk, avg(revenue) as ave - from - (select ss_store_sk, ss_item_sk, - sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1177 and 1177+11 - group by ss_store_sk, ss_item_sk) sa - group by ss_store_sk) sb, - (select ss_store_sk, ss_item_sk, sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1177 and 1177+11 - group by ss_store_sk, ss_item_sk) sc - where sb.ss_store_sk = sc.ss_store_sk and - sc.revenue <= 0.1 * sb.ave and - s_store_sk = sc.ss_store_sk and - i_item_sk = sc.ss_item_sk - order by s_store_name, i_item_desc -limit 100; - --- end template query65.tpl query 85 in stream 7 --- start template query59.tpl query 86 in stream 7 -with /* TPC-DS query59.tpl 0.30 */ wss as - (select d_week_seq, - ss_store_sk, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - group by d_week_seq,ss_store_sk - ) - select s_store_name1,s_store_id1,d_week_seq1 - ,sun_sales1/sun_sales2,mon_sales1/mon_sales2 - ,tue_sales1/tue_sales2,wed_sales1/wed_sales2,thu_sales1/thu_sales2 - ,fri_sales1/fri_sales2,sat_sales1/sat_sales2 - from - (select s_store_name s_store_name1,wss.d_week_seq d_week_seq1 - ,s_store_id s_store_id1,sun_sales sun_sales1 - ,mon_sales mon_sales1,tue_sales tue_sales1 - ,wed_sales wed_sales1,thu_sales thu_sales1 - ,fri_sales fri_sales1,sat_sales sat_sales1 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1196 and 1196 + 11) y, - (select s_store_name s_store_name2,wss.d_week_seq d_week_seq2 - ,s_store_id s_store_id2,sun_sales sun_sales2 - ,mon_sales mon_sales2,tue_sales tue_sales2 - ,wed_sales wed_sales2,thu_sales thu_sales2 - ,fri_sales fri_sales2,sat_sales sat_sales2 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1196+ 12 and 1196 + 23) x - where s_store_id1=s_store_id2 - and d_week_seq1=d_week_seq2-52 - order by s_store_name1,s_store_id1,d_week_seq1 -limit 100; - --- end template query59.tpl query 86 in stream 7 --- start template query96.tpl query 87 in stream 7 -select /* TPC-DS query96.tpl 0.1 */ count(*) -from store_sales - ,household_demographics - ,time_dim, store -where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and household_demographics.hd_dep_count = 3 - and store.s_store_name = 'ese' -order by count(*) -limit 100; - --- end template query96.tpl query 87 in stream 7 --- start template query54.tpl query 88 in stream 7 -with /* TPC-DS query54.tpl 0.81 */ my_customers as ( - select distinct c_customer_sk - , c_current_addr_sk - from - ( select cs_sold_date_sk sold_date_sk, - cs_bill_customer_sk customer_sk, - cs_item_sk item_sk - from catalog_sales - union all - select ws_sold_date_sk sold_date_sk, - ws_bill_customer_sk customer_sk, - ws_item_sk item_sk - from web_sales - ) cs_or_ws_sales, - item, - date_dim, - customer - where sold_date_sk = d_date_sk - and item_sk = i_item_sk - and i_category = 'Electronics' - and i_class = 'memory' - and c_customer_sk = cs_or_ws_sales.customer_sk - and d_moy = 1 - and d_year = 2000 - ) - , my_revenue as ( - select c_customer_sk, - sum(ss_ext_sales_price) as revenue - from my_customers, - store_sales, - customer_address, - store, - date_dim - where c_current_addr_sk = ca_address_sk - and ca_county = s_county - and ca_state = s_state - and ss_sold_date_sk = d_date_sk - and c_customer_sk = ss_customer_sk - and d_month_seq between (select distinct d_month_seq+1 - from date_dim where d_year = 2000 and d_moy = 1) - and (select distinct d_month_seq+3 - from date_dim where d_year = 2000 and d_moy = 1) - group by c_customer_sk - ) - , segments as - (select cast((revenue/50) as int) as segment - from my_revenue - ) - select segment, count(*) as num_customers, segment*50 as segment_base - from segments - group by segment - order by segment, num_customers - limit 100; - --- end template query54.tpl query 88 in stream 7 --- start template query95.tpl query 89 in stream 7 -with /* TPC-DS query95.tpl 0.43 */ ws_wh as -(select ws1.ws_order_number,ws1.ws_warehouse_sk wh1,ws2.ws_warehouse_sk wh2 - from web_sales ws1,web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) - select - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2000-3-01' and - dateadd(day,60,cast('2000-3-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'LA' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and ws1.ws_order_number in (select ws_order_number - from ws_wh) -and ws1.ws_order_number in (select wr_order_number - from web_returns,ws_wh - where wr_order_number = ws_wh.ws_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query95.tpl query 89 in stream 7 --- start template query93.tpl query 90 in stream 7 -select /* TPC-DS query93.tpl 0.52 */ ss_customer_sk - ,sum(act_sales) sumsales - from (select ss_item_sk - ,ss_ticket_number - ,ss_customer_sk - ,case when sr_return_quantity is not null then (ss_quantity-sr_return_quantity)*ss_sales_price - else (ss_quantity*ss_sales_price) end act_sales - from store_sales left outer join store_returns on (sr_item_sk = ss_item_sk - and sr_ticket_number = ss_ticket_number) - ,reason - where sr_reason_sk = r_reason_sk - and r_reason_desc = 'reason 71') t - group by ss_customer_sk - order by sumsales, ss_customer_sk -limit 100; - --- end template query93.tpl query 90 in stream 7 --- start template query91.tpl query 91 in stream 7 -select /* TPC-DS query91.tpl 0.13 */ - cc_call_center_id Call_Center, - cc_name Call_Center_Name, - cc_manager Manager, - sum(cr_net_loss) Returns_Loss -from - call_center, - catalog_returns, - date_dim, - customer, - customer_address, - customer_demographics, - household_demographics -where - cr_call_center_sk = cc_call_center_sk -and cr_returned_date_sk = d_date_sk -and cr_returning_customer_sk= c_customer_sk -and cd_demo_sk = c_current_cdemo_sk -and hd_demo_sk = c_current_hdemo_sk -and ca_address_sk = c_current_addr_sk -and d_year = 1998 -and d_moy = 12 -and ( (cd_marital_status = 'M' and cd_education_status = 'Unknown') - or(cd_marital_status = 'W' and cd_education_status = 'Advanced Degree')) -and hd_buy_potential like 'Unknown%' -and ca_gmt_offset = -7 -group by cc_call_center_id,cc_name,cc_manager,cd_marital_status,cd_education_status -order by sum(cr_net_loss) desc; - --- end template query91.tpl query 91 in stream 7 --- start template query74.tpl query 92 in stream 7 -with /* TPC-DS query74.tpl 0.76 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,max(ss_net_paid) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (2001,2001+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,max(ws_net_paid) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - and d_year in (2001,2001+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - ) - select - t_s_secyear.customer_id, t_s_secyear.customer_first_name, t_s_secyear.customer_last_name - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.year = 2001 - and t_s_secyear.year = 2001+1 - and t_w_firstyear.year = 2001 - and t_w_secyear.year = 2001+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - order by 2,3,1 -limit 100; - --- end template query74.tpl query 92 in stream 7 --- start template query94.tpl query 93 in stream 7 -select /* TPC-DS query94.tpl 0.17 */ - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2002-5-01' and - dateadd(day,60,cast('2002-5-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'AL' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and exists (select * - from web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) -and not exists(select * - from web_returns wr1 - where ws1.ws_order_number = wr1.wr_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query94.tpl query 93 in stream 7 --- start template query16.tpl query 94 in stream 7 -select /* TPC-DS query16.tpl 0.25 */ - count(distinct cs_order_number) as "order count" - ,sum(cs_ext_ship_cost) as "total shipping cost" - ,sum(cs_net_profit) as "total net profit" -from - catalog_sales cs1 - ,date_dim - ,customer_address - ,call_center -where - d_date between '2001-4-01' and - dateadd(day, 60, cast('2001-4-01' as date)) -and cs1.cs_ship_date_sk = d_date_sk -and cs1.cs_ship_addr_sk = ca_address_sk -and ca_state = 'OK' -and cs1.cs_call_center_sk = cc_call_center_sk -and cc_county in ('Wadena County','Richland County','Dauphin County','San Miguel County', - 'Daviess County' -) -and exists (select * - from catalog_sales cs2 - where cs1.cs_order_number = cs2.cs_order_number - and cs1.cs_warehouse_sk <> cs2.cs_warehouse_sk) -and not exists(select * - from catalog_returns cr1 - where cs1.cs_order_number = cr1.cr_order_number) -order by count(distinct cs_order_number) -limit 100; - --- end template query16.tpl query 94 in stream 7 --- start template query90.tpl query 95 in stream 7 -select /* TPC-DS query90.tpl 0.40 */ cast(amc as decimal(15,4))/cast(pmc as decimal(15,4)) am_pm_ratio - from ( select count(*) amc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 7 and 7+1 - and household_demographics.hd_dep_count = 7 - and web_page.wp_char_count between 5000 and 5200) at, - ( select count(*) pmc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 13 and 13+1 - and household_demographics.hd_dep_count = 7 - and web_page.wp_char_count between 5000 and 5200) pt - order by am_pm_ratio - limit 100; - --- end template query90.tpl query 95 in stream 7 --- start template query57.tpl query 96 in stream 7 -with /* TPC-DS query57.tpl 0.70 */ v1 as( - select i_category, i_brand, - cc_name, - d_year, d_moy, - sum(cs_sales_price) sum_sales, - avg(sum(cs_sales_price)) over - (partition by i_category, i_brand, - cc_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - cc_name - order by d_year, d_moy) rn - from item, catalog_sales, date_dim, call_center - where cs_item_sk = i_item_sk and - cs_sold_date_sk = d_date_sk and - cc_call_center_sk= cs_call_center_sk and - ( - d_year = 2000 or - ( d_year = 2000-1 and d_moy =12) or - ( d_year = 2000+1 and d_moy =1) - ) - group by i_category, i_brand, - cc_name , d_year, d_moy), - v2 as( - select v1.i_category, v1.i_brand - ,v1.d_year, v1.d_moy - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1. cc_name = v1_lag. cc_name and - v1. cc_name = v1_lead. cc_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 2000 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, avg_monthly_sales - limit 100; - --- end template query57.tpl query 96 in stream 7 --- start template query22a.tpl query 97 in stream 7 -with /* TPC-DS query22a.tpl 0.55 */ results as -(select i_product_name - ,i_brand - ,i_class - ,i_category - ,avg(inv_quantity_on_hand) qoh - from inventory - ,date_dim - ,item --- ,warehouse - where inv_date_sk=d_date_sk - and inv_item_sk=i_item_sk --- and inv_warehouse_sk = w_warehouse_sk - and d_month_seq between 1221 and 1221 + 11 - group by i_product_name,i_brand,i_class,i_category), -results_rollup as -(select i_product_name, i_brand, i_class, i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class,i_category -union all -select i_product_name, i_brand, i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class -union all -select i_product_name, i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand -union all -select i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name -union all -select null i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results) - select i_product_name, i_brand, i_class, i_category,qoh - from results_rollup - order by qoh, i_product_name, i_brand, i_class, i_category -limit 100; - --- end template query22a.tpl query 97 in stream 7 --- start template query50.tpl query 98 in stream 7 -select /* TPC-DS query50.tpl 0.60 */ - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 30) and - (sr_returned_date_sk - ss_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 60) and - (sr_returned_date_sk - ss_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 90) and - (sr_returned_date_sk - ss_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - store_sales - ,store_returns - ,store - ,date_dim d1 - ,date_dim d2 -where - d2.d_year = 1999 -and d2.d_moy = 10 -and ss_ticket_number = sr_ticket_number -and ss_item_sk = sr_item_sk -and ss_sold_date_sk = d1.d_date_sk -and sr_returned_date_sk = d2.d_date_sk -and ss_customer_sk = sr_customer_sk -and ss_store_sk = s_store_sk -group by - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -order by s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -limit 100; - --- end template query50.tpl query 98 in stream 7 --- start template query27a.tpl query 99 in stream 7 -with /* TPC-DS query27a.tpl 0.16 */ results as - (select i_item_id, - s_state, 0 as g_state, - ss_quantity agg1, - ss_list_price agg2, - ss_coupon_amt agg3, - ss_sales_price agg4 - from store_sales, customer_demographics, date_dim, store, item - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_store_sk = s_store_sk and - ss_cdemo_sk = cd_demo_sk and - cd_gender = 'F' and - cd_marital_status = 'M' and - cd_education_status = '2 yr Degree' and - d_year = 1998 and - s_state in ('MO','FL', 'MN', 'LA', 'AL', 'NM') - ) - - select i_item_id, - s_state, g_state, agg1, agg2, agg3, agg4 - from ( - select i_item_id, s_state, 0 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4 from results - group by i_item_id, s_state - union all - select i_item_id, NULL AS s_state, 1 AS g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as s_state, 1 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - ) foo - order by i_item_id, s_state - limit 100; - --- end template query27a.tpl query 99 in stream 7 diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/10TB/queries/query_8.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/10TB/queries/query_8.sql deleted file mode 100644 index 0c77c09a..00000000 --- a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/10TB/queries/query_8.sql +++ /dev/null @@ -1,5027 +0,0 @@ --- start template query57.tpl query 1 in stream 8 -with /* TPC-DS query57.tpl 0.70 */ v1 as( - select i_category, i_brand, - cc_name, - d_year, d_moy, - sum(cs_sales_price) sum_sales, - avg(sum(cs_sales_price)) over - (partition by i_category, i_brand, - cc_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - cc_name - order by d_year, d_moy) rn - from item, catalog_sales, date_dim, call_center - where cs_item_sk = i_item_sk and - cs_sold_date_sk = d_date_sk and - cc_call_center_sk= cs_call_center_sk and - ( - d_year = 2000 or - ( d_year = 2000-1 and d_moy =12) or - ( d_year = 2000+1 and d_moy =1) - ) - group by i_category, i_brand, - cc_name , d_year, d_moy), - v2 as( - select v1.cc_name - ,v1.d_year, v1.d_moy - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1. cc_name = v1_lag. cc_name and - v1. cc_name = v1_lead. cc_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 2000 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, nsum - limit 100; - --- end template query57.tpl query 1 in stream 8 --- start template query29.tpl query 2 in stream 8 -select /* TPC-DS query29.tpl 0.53 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,sum(ss_quantity) as store_sales_quantity - ,sum(sr_return_quantity) as store_returns_quantity - ,sum(cs_quantity) as catalog_sales_quantity - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 1998 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 4 + 3 - and d2.d_year = 1998 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_year in (1998,1998+1,1998+2) - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query29.tpl query 2 in stream 8 --- start template query24.tpl query 3 in stream 8 -with /* TPC-DS query24.tpl 0.92 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_ext_sales_price) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip -and s_market_id=10 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'salmon' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; -with /* TPC-DS query24.tpl 0.92 part2 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_ext_sales_price) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip - and s_market_id = 10 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'goldenrod' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; - --- end template query24.tpl query 3 in stream 8 --- start template query76.tpl query 4 in stream 8 -select /* TPC-DS query76.tpl 0.99 */ channel, col_name, d_year, d_qoy, i_category, COUNT(*) sales_cnt, SUM(ext_sales_price) sales_amt FROM ( - SELECT 'store' as channel, 'ss_addr_sk' col_name, d_year, d_qoy, i_category, ss_ext_sales_price ext_sales_price - FROM store_sales, item, date_dim - WHERE ss_addr_sk IS NULL - AND ss_sold_date_sk=d_date_sk - AND ss_item_sk=i_item_sk - UNION ALL - SELECT 'web' as channel, 'ws_bill_customer_sk' col_name, d_year, d_qoy, i_category, ws_ext_sales_price ext_sales_price - FROM web_sales, item, date_dim - WHERE ws_bill_customer_sk IS NULL - AND ws_sold_date_sk=d_date_sk - AND ws_item_sk=i_item_sk - UNION ALL - SELECT 'catalog' as channel, 'cs_bill_addr_sk' col_name, d_year, d_qoy, i_category, cs_ext_sales_price ext_sales_price - FROM catalog_sales, item, date_dim - WHERE cs_bill_addr_sk IS NULL - AND cs_sold_date_sk=d_date_sk - AND cs_item_sk=i_item_sk) foo -GROUP BY channel, col_name, d_year, d_qoy, i_category -ORDER BY channel, col_name, d_year, d_qoy, i_category -limit 100; - --- end template query76.tpl query 4 in stream 8 --- start template query37.tpl query 5 in stream 8 -select /* TPC-DS query37.tpl 0.31 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, catalog_sales - where i_current_price between 37 and 37 + 30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('1998-02-14' as date) and dateadd(day,60,cast('1998-02-14' as date)) - and i_manufact_id in (767,894,861,948) - and inv_quantity_on_hand between 100 and 500 - and cs_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query37.tpl query 5 in stream 8 --- start template query66.tpl query 6 in stream 8 -select /* TPC-DS query66.tpl 0.39 */ - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - ,sum(jan_sales) as jan_sales - ,sum(feb_sales) as feb_sales - ,sum(mar_sales) as mar_sales - ,sum(apr_sales) as apr_sales - ,sum(may_sales) as may_sales - ,sum(jun_sales) as jun_sales - ,sum(jul_sales) as jul_sales - ,sum(aug_sales) as aug_sales - ,sum(sep_sales) as sep_sales - ,sum(oct_sales) as oct_sales - ,sum(nov_sales) as nov_sales - ,sum(dec_sales) as dec_sales - ,sum(jan_sales/w_warehouse_sq_ft) as jan_sales_per_sq_foot - ,sum(feb_sales/w_warehouse_sq_ft) as feb_sales_per_sq_foot - ,sum(mar_sales/w_warehouse_sq_ft) as mar_sales_per_sq_foot - ,sum(apr_sales/w_warehouse_sq_ft) as apr_sales_per_sq_foot - ,sum(may_sales/w_warehouse_sq_ft) as may_sales_per_sq_foot - ,sum(jun_sales/w_warehouse_sq_ft) as jun_sales_per_sq_foot - ,sum(jul_sales/w_warehouse_sq_ft) as jul_sales_per_sq_foot - ,sum(aug_sales/w_warehouse_sq_ft) as aug_sales_per_sq_foot - ,sum(sep_sales/w_warehouse_sq_ft) as sep_sales_per_sq_foot - ,sum(oct_sales/w_warehouse_sq_ft) as oct_sales_per_sq_foot - ,sum(nov_sales/w_warehouse_sq_ft) as nov_sales_per_sq_foot - ,sum(dec_sales/w_warehouse_sq_ft) as dec_sales_per_sq_foot - ,sum(jan_net) as jan_net - ,sum(feb_net) as feb_net - ,sum(mar_net) as mar_net - ,sum(apr_net) as apr_net - ,sum(may_net) as may_net - ,sum(jun_net) as jun_net - ,sum(jul_net) as jul_net - ,sum(aug_net) as aug_net - ,sum(sep_net) as sep_net - ,sum(oct_net) as oct_net - ,sum(nov_net) as nov_net - ,sum(dec_net) as dec_net - from ( - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'DIAMOND' || ',' || 'TBS' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then ws_ext_list_price* ws_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then ws_ext_list_price* ws_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then ws_ext_list_price* ws_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then ws_ext_list_price* ws_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then ws_ext_list_price* ws_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then ws_ext_list_price* ws_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then ws_ext_list_price* ws_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then ws_ext_list_price* ws_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then ws_ext_list_price* ws_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then ws_ext_list_price* ws_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then ws_ext_list_price* ws_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then ws_ext_list_price* ws_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as dec_net - from - web_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - ws_warehouse_sk = w_warehouse_sk - and ws_sold_date_sk = d_date_sk - and ws_sold_time_sk = t_time_sk - and ws_ship_mode_sk = sm_ship_mode_sk - and d_year = 2001 - and t_time between 51000 and 51000+28800 - and sm_carrier in ('DIAMOND','TBS') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - union all - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'DIAMOND' || ',' || 'TBS' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then cs_ext_sales_price* cs_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then cs_ext_sales_price* cs_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then cs_ext_sales_price* cs_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then cs_ext_sales_price* cs_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then cs_ext_sales_price* cs_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then cs_ext_sales_price* cs_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then cs_ext_sales_price* cs_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then cs_ext_sales_price* cs_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then cs_ext_sales_price* cs_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then cs_ext_sales_price* cs_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then cs_ext_sales_price* cs_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then cs_ext_sales_price* cs_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as dec_net - from - catalog_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and cs_sold_time_sk = t_time_sk - and cs_ship_mode_sk = sm_ship_mode_sk - and d_year = 2001 - and t_time between 51000 AND 51000+28800 - and sm_carrier in ('DIAMOND','TBS') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - ) x - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - order by w_warehouse_name - limit 100; - --- end template query66.tpl query 6 in stream 8 --- start template query60.tpl query 7 in stream 8 -with /* TPC-DS query60.tpl 0.29 */ ss as ( - select - i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Jewelry')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 10 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - cs as ( - select - i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Jewelry')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 10 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - ws as ( - select - i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Jewelry')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 10 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id) - select - i_item_id -,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by i_item_id - ,total_sales - limit 100; - --- end template query60.tpl query 7 in stream 8 --- start template query98.tpl query 8 in stream 8 -select /* TPC-DS query98.tpl 0.32 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ss_ext_sales_price) as itemrevenue - ,sum(ss_ext_sales_price)*100/sum(sum(ss_ext_sales_price)) over - (partition by i_class) as revenueratio -from - store_sales - ,item - ,date_dim -where - ss_item_sk = i_item_sk - and i_category in ('Sports', 'Music', 'Men') - and ss_sold_date_sk = d_date_sk - and d_date between cast('2000-04-19' as date) - and dateadd(day,30,cast('2000-04-19' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio; - --- end template query98.tpl query 8 in stream 8 --- start template query80a.tpl query 9 in stream 8 -with /* TPC-DS query80a.tpl 0.6 */ ssr as - (select s_store_id as store_id, - sum(ss_ext_sales_price) as sales, - sum(coalesce(sr_return_amt, 0)) as returns, - sum(ss_net_profit - coalesce(sr_net_loss, 0)) as profit - from store_sales left outer join store_returns on - (ss_item_sk = sr_item_sk and ss_ticket_number = sr_ticket_number), - date_dim, - store, - item, - promotion - where ss_sold_date_sk = d_date_sk - and d_date between cast('1999-08-19' as date) - and dateadd(day,30,cast('1999-08-19' as date)) - and ss_store_sk = s_store_sk - and ss_item_sk = i_item_sk - and i_current_price > 50 - and ss_promo_sk = p_promo_sk - and p_channel_tv = 'N' - group by s_store_id) - , - csr as - (select cp_catalog_page_id as catalog_page_id, - sum(cs_ext_sales_price) as sales, - sum(coalesce(cr_return_amount, 0)) as returns, - sum(cs_net_profit - coalesce(cr_net_loss, 0)) as profit - from catalog_sales left outer join catalog_returns on - (cs_item_sk = cr_item_sk and cs_order_number = cr_order_number), - date_dim, - catalog_page, - item, - promotion - where cs_sold_date_sk = d_date_sk - and d_date between cast('1999-08-19' as date) - and dateadd(day,30,cast('1999-08-19' as date)) - and cs_catalog_page_sk = cp_catalog_page_sk - and cs_item_sk = i_item_sk - and i_current_price > 50 - and cs_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(ws_ext_sales_price) as sales, - sum(coalesce(wr_return_amt, 0)) as returns, - sum(ws_net_profit - coalesce(wr_net_loss, 0)) as profit - from web_sales left outer join web_returns on - (ws_item_sk = wr_item_sk and ws_order_number = wr_order_number), - date_dim, - web_site, - item, - promotion - where ws_sold_date_sk = d_date_sk - and d_date between cast('1999-08-19' as date) - and dateadd(day,30,cast('1999-08-19' as date)) - and ws_web_site_sk = web_site_sk - and ws_item_sk = i_item_sk - and i_current_price > 50 - and ws_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by web_site_id) -, -results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || store_id as id - , sales - , returns - , profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || catalog_page_id as id - , sales - , returns - , profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , profit - from wsr - ) x - group by channel, id) - - select channel - , id - , sales - , returns - , profit - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results - ) foo - order by channel, id - limit 100; - --- end template query80a.tpl query 9 in stream 8 --- start template query12.tpl query 10 in stream 8 -select /* TPC-DS query12.tpl 0.64 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ws_ext_sales_price) as itemrevenue - ,sum(ws_ext_sales_price)*100/sum(sum(ws_ext_sales_price)) over - (partition by i_class) as revenueratio -from - web_sales - ,item - ,date_dim -where - ws_item_sk = i_item_sk - and i_category in ('Women', 'Sports', 'Children') - and ws_sold_date_sk = d_date_sk - and d_date between cast('1999-06-25' as date) - and dateadd(day,30,cast('1999-06-25' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query12.tpl query 10 in stream 8 --- start template query59.tpl query 11 in stream 8 -with /* TPC-DS query59.tpl 0.30 */ wss as - (select d_week_seq, - ss_store_sk, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - group by d_week_seq,ss_store_sk - ) - select s_store_name1,s_store_id1,d_week_seq1 - ,sun_sales1/sun_sales2,mon_sales1/mon_sales2 - ,tue_sales1/tue_sales2,wed_sales1/wed_sales2,thu_sales1/thu_sales2 - ,fri_sales1/fri_sales2,sat_sales1/sat_sales2 - from - (select s_store_name s_store_name1,wss.d_week_seq d_week_seq1 - ,s_store_id s_store_id1,sun_sales sun_sales1 - ,mon_sales mon_sales1,tue_sales tue_sales1 - ,wed_sales wed_sales1,thu_sales thu_sales1 - ,fri_sales fri_sales1,sat_sales sat_sales1 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1211 and 1211 + 11) y, - (select s_store_name s_store_name2,wss.d_week_seq d_week_seq2 - ,s_store_id s_store_id2,sun_sales sun_sales2 - ,mon_sales mon_sales2,tue_sales tue_sales2 - ,wed_sales wed_sales2,thu_sales thu_sales2 - ,fri_sales fri_sales2,sat_sales sat_sales2 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1211+ 12 and 1211 + 23) x - where s_store_id1=s_store_id2 - and d_week_seq1=d_week_seq2-52 - order by s_store_name1,s_store_id1,d_week_seq1 -limit 100; - --- end template query59.tpl query 11 in stream 8 --- start template query70a.tpl query 12 in stream 8 -with /* TPC-DS query70a.tpl 0.34 */ results as -( select - sum(ss_net_profit) as total_sum ,s_state ,s_county, 0 as gstate, 0 as g_county - from - store_sales - ,date_dim d1 - ,store - where - d1.d_month_seq between 1179 and 1179 + 11 - and d1.d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - and s_state in - ( select s_state - from (select s_state as s_state, - rank() over ( partition by s_state order by sum(ss_net_profit) desc) as ranking - from store_sales, store, date_dim - where d_month_seq between 1179 and 1179 + 11 - and d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - group by s_state - ) tmp1 - where ranking <= 5) - group by s_state,s_county) , - results_rollup as -(select total_sum ,s_state ,s_county, 0 as g_state, 0 as g_county, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum,s_state, NULL as s_county, 0 as g_state, 1 as g_county, 1 as lochierarchy from results group by s_state - union - select sum(total_sum) as total_sum ,NULL as s_state ,NULL as s_county, 1 as g_state, 1 as g_county, 2 as lochierarchy from results) - select total_sum ,s_state ,s_county, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_county = 0 then s_state end - order by total_sum desc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then s_state end - ,rank_within_parent - limit 100; - --- end template query70a.tpl query 12 in stream 8 --- start template query91.tpl query 13 in stream 8 -select /* TPC-DS query91.tpl 0.13 */ - cc_call_center_id Call_Center, - cc_name Call_Center_Name, - cc_manager Manager, - sum(cr_net_loss) Returns_Loss -from - call_center, - catalog_returns, - date_dim, - customer, - customer_address, - customer_demographics, - household_demographics -where - cr_call_center_sk = cc_call_center_sk -and cr_returned_date_sk = d_date_sk -and cr_returning_customer_sk= c_customer_sk -and cd_demo_sk = c_current_cdemo_sk -and hd_demo_sk = c_current_hdemo_sk -and ca_address_sk = c_current_addr_sk -and d_year = 2002 -and d_moy = 11 -and ( (cd_marital_status = 'M' and cd_education_status = 'Unknown') - or(cd_marital_status = 'W' and cd_education_status = 'Advanced Degree')) -and hd_buy_potential like 'Unknown%' -and ca_gmt_offset = -6 -group by cc_call_center_id,cc_name,cc_manager,cd_marital_status,cd_education_status -order by sum(cr_net_loss) desc; - --- end template query91.tpl query 13 in stream 8 --- start template query69.tpl query 14 in stream 8 -select /* TPC-DS query69.tpl 0.28 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_state in ('KY','WY','VA') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2001 and - d_moy between 2 and 2+2) and - (not exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2001 and - d_moy between 2 and 2+2) and - not exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2001 and - d_moy between 2 and 2+2)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - limit 100; - --- end template query69.tpl query 14 in stream 8 --- start template query40.tpl query 15 in stream 8 -select /* TPC-DS query40.tpl 0.86 */ - w_state - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('2000-03-21' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_before - ,sum(case when (cast(d_date as date) >= cast ('2000-03-21' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_after - from - catalog_sales left outer join catalog_returns on - (cs_order_number = cr_order_number - and cs_item_sk = cr_item_sk) - ,warehouse - ,item - ,date_dim - where - i_current_price between 0.99 and 1.49 - and i_item_sk = cs_item_sk - and cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('2000-03-21' as date)) - and dateadd(day,30,cast ('2000-03-21' as date)) - group by - w_state,i_item_id - order by w_state,i_item_id -limit 100; - --- end template query40.tpl query 15 in stream 8 --- start template query2.tpl query 16 in stream 8 -with /* TPC-DS query2.tpl 0.84 */ wscs as - (select sold_date_sk - ,sales_price - from (select ws_sold_date_sk sold_date_sk - ,ws_ext_sales_price sales_price - from web_sales - union all - select cs_sold_date_sk sold_date_sk - ,cs_ext_sales_price sales_price - from catalog_sales)), - wswscs as - (select d_week_seq, - sum(case when (d_day_name='Sunday') then sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then sales_price else null end) sat_sales - from wscs - ,date_dim - where d_date_sk = sold_date_sk - group by d_week_seq) - select d_week_seq1 - ,round(sun_sales1/sun_sales2,2) - ,round(mon_sales1/mon_sales2,2) - ,round(tue_sales1/tue_sales2,2) - ,round(wed_sales1/wed_sales2,2) - ,round(thu_sales1/thu_sales2,2) - ,round(fri_sales1/fri_sales2,2) - ,round(sat_sales1/sat_sales2,2) - from - (select wswscs.d_week_seq d_week_seq1 - ,sun_sales sun_sales1 - ,mon_sales mon_sales1 - ,tue_sales tue_sales1 - ,wed_sales wed_sales1 - ,thu_sales thu_sales1 - ,fri_sales fri_sales1 - ,sat_sales sat_sales1 - from wswscs,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 2001) y, - (select wswscs.d_week_seq d_week_seq2 - ,sun_sales sun_sales2 - ,mon_sales mon_sales2 - ,tue_sales tue_sales2 - ,wed_sales wed_sales2 - ,thu_sales thu_sales2 - ,fri_sales fri_sales2 - ,sat_sales sat_sales2 - from wswscs - ,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 2001+1) z - where d_week_seq1=d_week_seq2-53 - order by d_week_seq1; - --- end template query2.tpl query 16 in stream 8 --- start template query16.tpl query 17 in stream 8 -select /* TPC-DS query16.tpl 0.25 */ - count(distinct cs_order_number) as "order count" - ,sum(cs_ext_ship_cost) as "total shipping cost" - ,sum(cs_net_profit) as "total net profit" -from - catalog_sales cs1 - ,date_dim - ,customer_address - ,call_center -where - d_date between '1999-2-01' and - dateadd(day, 60, cast('1999-2-01' as date)) -and cs1.cs_ship_date_sk = d_date_sk -and cs1.cs_ship_addr_sk = ca_address_sk -and ca_state = 'GA' -and cs1.cs_call_center_sk = cc_call_center_sk -and cc_county in ('Franklin Parish','Pennington County','Daviess County','Barrow County', - 'Kittitas County' -) -and exists (select * - from catalog_sales cs2 - where cs1.cs_order_number = cs2.cs_order_number - and cs1.cs_warehouse_sk <> cs2.cs_warehouse_sk) -and not exists(select * - from catalog_returns cr1 - where cs1.cs_order_number = cr1.cr_order_number) -order by count(distinct cs_order_number) -limit 100; - --- end template query16.tpl query 17 in stream 8 --- start template query44.tpl query 18 in stream 8 -select /* TPC-DS query44.tpl 0.4 */ asceding.rnk, i1.i_product_name best_performing, i2.i_product_name worst_performing -from(select * - from (select item_sk,rank() over (order by rank_col asc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 333 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 333 - and ss_promo_sk is null - group by ss_store_sk))V1)V11 - where rnk < 11) asceding, - (select * - from (select item_sk,rank() over (order by rank_col desc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 333 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 333 - and ss_promo_sk is null - group by ss_store_sk))V2)V21 - where rnk < 11) descending, -item i1, -item i2 -where asceding.rnk = descending.rnk - and i1.i_item_sk=asceding.item_sk - and i2.i_item_sk=descending.item_sk -order by asceding.rnk -limit 100; - --- end template query44.tpl query 18 in stream 8 --- start template query5a.tpl query 19 in stream 8 -with /* TPC-DS query5a.tpl 0.98 */ ssr as - (select s_store_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ss_store_sk as store_sk, - ss_sold_date_sk as date_sk, - ss_ext_sales_price as sales_price, - ss_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from store_sales - union all - select sr_store_sk as store_sk, - sr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - sr_return_amt as return_amt, - sr_net_loss as net_loss - from store_returns - ) salesreturns, - date_dim, - store - where date_sk = d_date_sk - and d_date between cast('1999-08-29' as date) - and dateadd(day,14,cast('1999-08-29' as date)) - and store_sk = s_store_sk - group by s_store_id) - , - csr as - (select cp_catalog_page_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select cs_catalog_page_sk as page_sk, - cs_sold_date_sk as date_sk, - cs_ext_sales_price as sales_price, - cs_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from catalog_sales - union all - select cr_catalog_page_sk as page_sk, - cr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - cr_return_amount as return_amt, - cr_net_loss as net_loss - from catalog_returns - ) salesreturns, - date_dim, - catalog_page - where date_sk = d_date_sk - and d_date between cast('1999-08-29' as date) - and dateadd(day,14,cast('1999-08-29' as date)) - and page_sk = cp_catalog_page_sk - group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ws_web_site_sk as wsr_web_site_sk, - ws_sold_date_sk as date_sk, - ws_ext_sales_price as sales_price, - ws_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from web_sales - union all - select ws_web_site_sk as wsr_web_site_sk, - wr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - wr_return_amt as return_amt, - wr_net_loss as net_loss - from web_returns left outer join web_sales on - ( wr_item_sk = ws_item_sk - and wr_order_number = ws_order_number) - ) salesreturns, - date_dim, - web_site - where date_sk = d_date_sk - and d_date between cast('1999-08-29' as date) - and dateadd(day,14,cast('1999-08-29' as date)) - and wsr_web_site_sk = web_site_sk - group by web_site_id) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || s_store_id as id - , sales - , returns - , (profit - profit_loss) as profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || cp_catalog_page_id as id - , sales - , returns - , (profit - profit_loss) as profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , (profit - profit_loss) as profit - from wsr - ) x - group by channel, id) - select channel, id, sales, returns, profit from ( - select channel, id, sales, returns, profit from results - union - select channel, null as id, sum(sales), sum(returns), sum(profit) from results group by channel - union - select null as channel, null as id, sum(sales), sum(returns), sum(profit) from results) foo -order by channel, id -limit 100; - --- end template query5a.tpl query 19 in stream 8 --- start template query73.tpl query 20 in stream 8 -select /* TPC-DS query73.tpl 0.79 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_buy_potential = '501-1000' or - household_demographics.hd_buy_potential = '0-500') - and household_demographics.hd_vehicle_count > 0 - and case when household_demographics.hd_vehicle_count > 0 then - household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count else null end > 1 - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_county in ('Perry County','Anderson County','Huron County','Oglethorpe County') - group by ss_ticket_number,ss_customer_sk) dj,customer - where ss_customer_sk = c_customer_sk - and cnt between 1 and 5 - order by cnt desc, c_last_name asc; - --- end template query73.tpl query 20 in stream 8 --- start template query14a.tpl query 21 in stream 8 -with /* TPC-DS query14a.tpl 0.69 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 2000 AND 2000 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 2000 AND 2000 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 2000 AND 2000 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as - (select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2) x) -, - results AS -(select channel, i_brand_id, i_class_id, i_category_id, sum(sales) sum_sales, sum(number_sales) number_sales - from ( - select 'store' channel, i_brand_id,i_class_id - ,i_category_id,sum(ss_quantity*ss_list_price) sales - , count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2000+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales) - union all - select 'catalog' channel, i_brand_id,i_class_id,i_category_id, sum(cs_quantity*cs_list_price) sales, count(*) number_sales - from catalog_sales - ,item - ,date_dim - where cs_item_sk in (select ss_item_sk from cross_items) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2000+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(cs_quantity*cs_list_price) > (select average_sales from avg_sales) - union all - select 'web' channel, i_brand_id,i_class_id,i_category_id, sum(ws_quantity*ws_list_price) sales , count(*) number_sales - from web_sales - ,item - ,date_dim - where ws_item_sk in (select ss_item_sk from cross_items) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2000+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ws_quantity*ws_list_price) > (select average_sales from avg_sales) - ) y - group by channel, i_brand_id,i_class_id,i_category_id) - - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales -from ( - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales from results - union - select channel, i_brand_id, i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id, i_class_id - union - select channel, i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id - union - select channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel - union - select null as channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results) z -order by channel, i_brand_id, i_class_id, i_category_id - limit 100; -with /* TPC-DS query14a.tpl 0.69 part2 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 2000 AND 2000 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 2000 AND 2000 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 2000 AND 2000 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as -(select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2) x) - select this_year.channel ty_channel - ,this_year.i_brand_id ty_brand - ,this_year.i_class_id ty_class - ,this_year.i_category_id ty_category - ,this_year.sales ty_sales - ,this_year.number_sales ty_number_sales - ,last_year.channel ly_channel - ,last_year.i_brand_id ly_brand - ,last_year.i_class_id ly_class - ,last_year.i_category_id ly_category - ,last_year.sales ly_sales - ,last_year.number_sales ly_number_sales -from - (select 'store' channel, i_brand_id,i_class_id,i_category_id - ,sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 2000 + 1 - and d_moy = 12 - and d_dom = 15) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) this_year, - (select 'store' channel, i_brand_id,i_class_id - ,i_category_id, sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 2000 - and d_moy = 12 - and d_dom = 15) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) last_year - where this_year.i_brand_id= last_year.i_brand_id - and this_year.i_class_id = last_year.i_class_id - and this_year.i_category_id = last_year.i_category_id - order by this_year.channel, this_year.i_brand_id, this_year.i_class_id, this_year.i_category_id - limit 100; - --- end template query14a.tpl query 21 in stream 8 --- start template query71.tpl query 22 in stream 8 -select /* TPC-DS query71.tpl 0.72 */ i_brand_id brand_id, i_brand brand,t_hour,t_minute, - sum(ext_price) ext_price - from item, (select ws_ext_sales_price as ext_price, - ws_sold_date_sk as sold_date_sk, - ws_item_sk as sold_item_sk, - ws_sold_time_sk as time_sk - from web_sales,date_dim - where d_date_sk = ws_sold_date_sk - and d_moy=11 - and d_year=2000 - union all - select cs_ext_sales_price as ext_price, - cs_sold_date_sk as sold_date_sk, - cs_item_sk as sold_item_sk, - cs_sold_time_sk as time_sk - from catalog_sales,date_dim - where d_date_sk = cs_sold_date_sk - and d_moy=11 - and d_year=2000 - union all - select ss_ext_sales_price as ext_price, - ss_sold_date_sk as sold_date_sk, - ss_item_sk as sold_item_sk, - ss_sold_time_sk as time_sk - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - and d_moy=11 - and d_year=2000 - ) tmp,time_dim - where - sold_item_sk = i_item_sk - and i_manager_id=1 - and time_sk = t_time_sk - and (t_meal_time = 'breakfast' or t_meal_time = 'dinner') - group by i_brand, i_brand_id,t_hour,t_minute - order by ext_price desc, i_brand_id - ; - --- end template query71.tpl query 22 in stream 8 --- start template query3.tpl query 23 in stream 8 -select /* TPC-DS query3.tpl 0.45 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_net_profit) sum_agg - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manufact_id = 409 - and dt.d_moy=12 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,sum_agg desc - ,brand_id - limit 100; - --- end template query3.tpl query 23 in stream 8 --- start template query49.tpl query 24 in stream 8 -select /* TPC-DS query49.tpl 0.48 */ channel, item, return_ratio, return_rank, currency_rank from - (select - 'web' as channel - ,web.item - ,web.return_ratio - ,web.return_rank - ,web.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select ws.ws_item_sk as item - ,(cast(sum(coalesce(wr.wr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(wr.wr_return_amt,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - web_sales ws left outer join web_returns wr - on (ws.ws_order_number = wr.wr_order_number and - ws.ws_item_sk = wr.wr_item_sk) - ,date_dim - where - wr.wr_return_amt > 10000 - and ws.ws_net_profit > 1 - and ws.ws_net_paid > 0 - and ws.ws_quantity > 0 - and ws_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 12 - group by ws.ws_item_sk - ) in_web - ) web - where - ( - web.return_rank <= 10 - or - web.currency_rank <= 10 - ) - union - select - 'catalog' as channel - ,catalog.item - ,catalog.return_ratio - ,catalog.return_rank - ,catalog.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select - cs.cs_item_sk as item - ,(cast(sum(coalesce(cr.cr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(cr.cr_return_amount,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - catalog_sales cs left outer join catalog_returns cr - on (cs.cs_order_number = cr.cr_order_number and - cs.cs_item_sk = cr.cr_item_sk) - ,date_dim - where - cr.cr_return_amount > 10000 - and cs.cs_net_profit > 1 - and cs.cs_net_paid > 0 - and cs.cs_quantity > 0 - and cs_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 12 - group by cs.cs_item_sk - ) in_cat - ) catalog - where - ( - catalog.return_rank <= 10 - or - catalog.currency_rank <=10 - ) - union - select - 'store' as channel - ,store.item - ,store.return_ratio - ,store.return_rank - ,store.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select sts.ss_item_sk as item - ,(cast(sum(coalesce(sr.sr_return_quantity,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(sr.sr_return_amt,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - store_sales sts left outer join store_returns sr - on (sts.ss_ticket_number = sr.sr_ticket_number and sts.ss_item_sk = sr.sr_item_sk) - ,date_dim - where - sr.sr_return_amt > 10000 - and sts.ss_net_profit > 1 - and sts.ss_net_paid > 0 - and sts.ss_quantity > 0 - and ss_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 12 - group by sts.ss_item_sk - ) in_store - ) store - where ( - store.return_rank <= 10 - or - store.currency_rank <= 10 - ) - ) - order by 1,4,5,2 - limit 100; - --- end template query49.tpl query 24 in stream 8 --- start template query84.tpl query 25 in stream 8 -select /* TPC-DS query84.tpl 0.80 */ c_customer_id as customer_id - , coalesce(c_last_name,'') || ', ' || coalesce(c_first_name,'') as customername - from customer - ,customer_address - ,customer_demographics - ,household_demographics - ,income_band - ,store_returns - where ca_city = 'Pine Grove' - and c_current_addr_sk = ca_address_sk - and ib_lower_bound >= 65534 - and ib_upper_bound <= 65534 + 50000 - and ib_income_band_sk = hd_income_band_sk - and cd_demo_sk = c_current_cdemo_sk - and hd_demo_sk = c_current_hdemo_sk - and sr_cdemo_sk = cd_demo_sk - order by c_customer_id - limit 100; - --- end template query84.tpl query 25 in stream 8 --- start template query64.tpl query 26 in stream 8 -with /* TPC-DS query64.tpl 0.20 */ cs_ui as - (select cs_item_sk - ,sum(cs_ext_list_price) as sale,sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit) as refund - from catalog_sales - ,catalog_returns - where cs_item_sk = cr_item_sk - and cs_order_number = cr_order_number - group by cs_item_sk - having sum(cs_ext_list_price)>2*sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit)), -cross_sales as - (select i_product_name product_name - ,i_item_sk item_sk - ,s_store_name store_name - ,s_zip store_zip - ,ad1.ca_street_number b_street_number - ,ad1.ca_street_name b_street_name - ,ad1.ca_city b_city - ,ad1.ca_zip b_zip - ,ad2.ca_street_number c_street_number - ,ad2.ca_street_name c_street_name - ,ad2.ca_city c_city - ,ad2.ca_zip c_zip - ,d1.d_year as syear - ,d2.d_year as fsyear - ,d3.d_year s2year - ,count(*) cnt - ,sum(ss_wholesale_cost) s1 - ,sum(ss_list_price) s2 - ,sum(ss_coupon_amt) s3 - FROM store_sales - ,store_returns - ,cs_ui - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,customer - ,customer_demographics cd1 - ,customer_demographics cd2 - ,promotion - ,household_demographics hd1 - ,household_demographics hd2 - ,customer_address ad1 - ,customer_address ad2 - ,income_band ib1 - ,income_band ib2 - ,item - WHERE ss_store_sk = s_store_sk AND - ss_sold_date_sk = d1.d_date_sk AND - ss_customer_sk = c_customer_sk AND - ss_cdemo_sk= cd1.cd_demo_sk AND - ss_hdemo_sk = hd1.hd_demo_sk AND - ss_addr_sk = ad1.ca_address_sk and - ss_item_sk = i_item_sk and - ss_item_sk = sr_item_sk and - ss_ticket_number = sr_ticket_number and - ss_item_sk = cs_ui.cs_item_sk and - c_current_cdemo_sk = cd2.cd_demo_sk AND - c_current_hdemo_sk = hd2.hd_demo_sk AND - c_current_addr_sk = ad2.ca_address_sk and - c_first_sales_date_sk = d2.d_date_sk and - c_first_shipto_date_sk = d3.d_date_sk and - ss_promo_sk = p_promo_sk and - hd1.hd_income_band_sk = ib1.ib_income_band_sk and - hd2.hd_income_band_sk = ib2.ib_income_band_sk and - cd1.cd_marital_status <> cd2.cd_marital_status and - i_color in ('sienna','royal','chiffon','cream','chocolate','maroon') and - i_current_price between 52 and 52 + 10 and - i_current_price between 52 + 1 and 52 + 15 -group by i_product_name - ,i_item_sk - ,s_store_name - ,s_zip - ,ad1.ca_street_number - ,ad1.ca_street_name - ,ad1.ca_city - ,ad1.ca_zip - ,ad2.ca_street_number - ,ad2.ca_street_name - ,ad2.ca_city - ,ad2.ca_zip - ,d1.d_year - ,d2.d_year - ,d3.d_year -) -select cs1.product_name - ,cs1.store_name - ,cs1.store_zip - ,cs1.b_street_number - ,cs1.b_street_name - ,cs1.b_city - ,cs1.b_zip - ,cs1.c_street_number - ,cs1.c_street_name - ,cs1.c_city - ,cs1.c_zip - ,cs1.syear - ,cs1.cnt - ,cs1.s1 as s11 - ,cs1.s2 as s21 - ,cs1.s3 as s31 - ,cs2.s1 as s12 - ,cs2.s2 as s22 - ,cs2.s3 as s32 - ,cs2.syear - ,cs2.cnt -from cross_sales cs1,cross_sales cs2 -where cs1.item_sk=cs2.item_sk and - cs1.syear = 2000 and - cs2.syear = 2000 + 1 and - cs2.cnt <= cs1.cnt and - cs1.store_name = cs2.store_name and - cs1.store_zip = cs2.store_zip -order by cs1.product_name - ,cs1.store_name - ,cs2.cnt - ,cs1.s1 - ,cs2.s1; - --- end template query64.tpl query 26 in stream 8 --- start template query7.tpl query 27 in stream 8 -select /* TPC-DS query7.tpl 0.2 */ i_item_id, - avg(ss_quantity) agg1, - avg(ss_list_price) agg2, - avg(ss_coupon_amt) agg3, - avg(ss_sales_price) agg4 - from store_sales, customer_demographics, date_dim, item, promotion - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_cdemo_sk = cd_demo_sk and - ss_promo_sk = p_promo_sk and - cd_gender = 'F' and - cd_marital_status = 'W' and - cd_education_status = '2 yr Degree' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 2000 - group by i_item_id - order by i_item_id - limit 100; - --- end template query7.tpl query 27 in stream 8 --- start template query36a.tpl query 28 in stream 8 -with /* TPC-DS query36a.tpl 0.21 */ results as - (select - sum(ss_net_profit) as ss_net_profit, sum(ss_ext_sales_price) as ss_ext_sales_price, - sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin - ,i_category - ,i_class - ,0 as g_category, 0 as g_class - from - store_sales - ,date_dim d1 - ,item - ,store - where - d1.d_year = 1998 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and s_state in ('NY','PA','OH','WV', - 'SC','LA','WA','CO') - group by i_category,i_class) - , - results_rollup as - (select gross_margin ,i_category ,i_class,0 as t_category, 0 as t_class, 0 as lochierarchy from results - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - i_category, NULL AS i_class, 0 as t_category, 1 as t_class, 1 as lochierarchy from results group by i_category - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - NULL AS i_category ,NULL AS i_class, 1 as t_category, 1 as t_class, 2 as lochierarchy from results) - select - gross_margin ,i_category ,i_class, lochierarchy,rank() over ( - partition by lochierarchy, case when t_class = 0 then i_category end - order by gross_margin asc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then i_category end - ,rank_within_parent - limit 100; - --- end template query36a.tpl query 28 in stream 8 --- start template query61.tpl query 29 in stream 8 -select /* TPC-DS query61.tpl 0.97 */ promotions,total,cast(promotions as decimal(15,4))/cast(total as decimal(15,4))*100 -from - (select sum(ss_ext_sales_price) promotions - from store_sales - ,store - ,promotion - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_promo_sk = p_promo_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -7 - and i_category = 'Home' - and (p_channel_dmail = 'Y' or p_channel_email = 'Y' or p_channel_tv = 'Y') - and s_gmt_offset = -7 - and d_year = 1999 - and d_moy = 11) promotional_sales, - (select sum(ss_ext_sales_price) total - from store_sales - ,store - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -7 - and i_category = 'Home' - and s_gmt_offset = -7 - and d_year = 1999 - and d_moy = 11) all_sales -order by promotions, total -limit 100; - --- end template query61.tpl query 29 in stream 8 --- start template query41.tpl query 30 in stream 8 -select /* TPC-DS query41.tpl 0.62 */ distinct(i_product_name) - from item i1 - where i_manufact_id between 767 and 767+40 - and (select count(*) as item_cnt - from item - where (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'puff' or i_color = 'burnished') and - (i_units = 'Each' or i_units = 'Cup') and - (i_size = 'small' or i_size = 'large') - ) or - (i_category = 'Women' and - (i_color = 'cyan' or i_color = 'bisque') and - (i_units = 'Bundle' or i_units = 'Bunch') and - (i_size = 'extra large' or i_size = 'medium') - ) or - (i_category = 'Men' and - (i_color = 'white' or i_color = 'yellow') and - (i_units = 'Unknown' or i_units = 'Oz') and - (i_size = 'N/A' or i_size = 'economy') - ) or - (i_category = 'Men' and - (i_color = 'beige' or i_color = 'dodger') and - (i_units = 'Box' or i_units = 'Case') and - (i_size = 'small' or i_size = 'large') - ))) or - (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'deep' or i_color = 'olive') and - (i_units = 'Dram' or i_units = 'N/A') and - (i_size = 'small' or i_size = 'large') - ) or - (i_category = 'Women' and - (i_color = 'honeydew' or i_color = 'midnight') and - (i_units = 'Pallet' or i_units = 'Ounce') and - (i_size = 'extra large' or i_size = 'medium') - ) or - (i_category = 'Men' and - (i_color = 'maroon' or i_color = 'papaya') and - (i_units = 'Ton' or i_units = 'Gross') and - (i_size = 'N/A' or i_size = 'economy') - ) or - (i_category = 'Men' and - (i_color = 'orange' or i_color = 'moccasin') and - (i_units = 'Lb' or i_units = 'Pound') and - (i_size = 'small' or i_size = 'large') - )))) > 0 - order by i_product_name - limit 100; - --- end template query41.tpl query 30 in stream 8 --- start template query35a.tpl query 31 in stream 8 -select /* TPC-DS query35a.tpl 0.47 */ - ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - count(*) cnt1, - min(cd_dep_count), - max(cd_dep_count), - sum(cd_dep_count), - cd_dep_employed_count, - count(*) cnt2, - min(cd_dep_employed_count), - max(cd_dep_employed_count), - sum(cd_dep_employed_count), - cd_dep_college_count, - count(*) cnt3, - min(cd_dep_college_count), - max(cd_dep_college_count), - sum(cd_dep_college_count) - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 1999 and - d_qoy < 4) and - exists (select * from - (select ws_bill_customer_sk customsk - from web_sales,date_dim - where - ws_sold_date_sk = d_date_sk and - d_year = 1999 and - d_qoy < 4 - union all - select cs_ship_customer_sk customsk - from catalog_sales,date_dim - where - cs_sold_date_sk = d_date_sk and - d_year = 1999 and - d_qoy < 4)x - where x.customsk = c.c_customer_sk) - group by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - limit 100; - --- end template query35a.tpl query 31 in stream 8 --- start template query50.tpl query 32 in stream 8 -select /* TPC-DS query50.tpl 0.60 */ - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 30) and - (sr_returned_date_sk - ss_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 60) and - (sr_returned_date_sk - ss_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 90) and - (sr_returned_date_sk - ss_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - store_sales - ,store_returns - ,store - ,date_dim d1 - ,date_dim d2 -where - d2.d_year = 2000 -and d2.d_moy = 10 -and ss_ticket_number = sr_ticket_number -and ss_item_sk = sr_item_sk -and ss_sold_date_sk = d1.d_date_sk -and sr_returned_date_sk = d2.d_date_sk -and ss_customer_sk = sr_customer_sk -and ss_store_sk = s_store_sk -group by - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -order by s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -limit 100; - --- end template query50.tpl query 32 in stream 8 --- start template query65.tpl query 33 in stream 8 -select /* TPC-DS query65.tpl 0.71 */ - s_store_name, - i_item_desc, - sc.revenue, - i_current_price, - i_wholesale_cost, - i_brand - from store, item, - (select ss_store_sk, avg(revenue) as ave - from - (select ss_store_sk, ss_item_sk, - sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1203 and 1203+11 - group by ss_store_sk, ss_item_sk) sa - group by ss_store_sk) sb, - (select ss_store_sk, ss_item_sk, sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1203 and 1203+11 - group by ss_store_sk, ss_item_sk) sc - where sb.ss_store_sk = sc.ss_store_sk and - sc.revenue <= 0.1 * sb.ave and - s_store_sk = sc.ss_store_sk and - i_item_sk = sc.ss_item_sk - order by s_store_name, i_item_desc -limit 100; - --- end template query65.tpl query 33 in stream 8 --- start template query51.tpl query 34 in stream 8 -WITH /* TPC-DS query51.tpl 0.46 */ web_v1 as ( -select - ws_item_sk item_sk, d_date, - sum(sum(ws_sales_price)) - over (partition by ws_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from web_sales - ,date_dim -where ws_sold_date_sk=d_date_sk - and d_month_seq between 1206 and 1206+11 - and ws_item_sk is not NULL -group by ws_item_sk, d_date), -store_v1 as ( -select - ss_item_sk item_sk, d_date, - sum(sum(ss_sales_price)) - over (partition by ss_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from store_sales - ,date_dim -where ss_sold_date_sk=d_date_sk - and d_month_seq between 1206 and 1206+11 - and ss_item_sk is not NULL -group by ss_item_sk, d_date) - select * -from (select item_sk - ,d_date - ,web_sales - ,store_sales - ,max(web_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) web_cumulative - ,max(store_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) store_cumulative - from (select case when web.item_sk is not null then web.item_sk else store.item_sk end item_sk - ,case when web.d_date is not null then web.d_date else store.d_date end d_date - ,web.cume_sales web_sales - ,store.cume_sales store_sales - from web_v1 web full outer join store_v1 store on (web.item_sk = store.item_sk - and web.d_date = store.d_date) - )x )y -where web_cumulative > store_cumulative -order by item_sk - ,d_date -limit 100; - --- end template query51.tpl query 34 in stream 8 --- start template query78.tpl query 35 in stream 8 -with /* TPC-DS query78.tpl 0.10 */ ws as - (select d_year AS ws_sold_year, ws_item_sk, - ws_bill_customer_sk ws_customer_sk, - sum(ws_quantity) ws_qty, - sum(ws_wholesale_cost) ws_wc, - sum(ws_sales_price) ws_sp - from web_sales - left join web_returns on wr_order_number=ws_order_number and ws_item_sk=wr_item_sk - join date_dim on ws_sold_date_sk = d_date_sk - where wr_order_number is null - group by d_year, ws_item_sk, ws_bill_customer_sk - ), -cs as - (select d_year AS cs_sold_year, cs_item_sk, - cs_bill_customer_sk cs_customer_sk, - sum(cs_quantity) cs_qty, - sum(cs_wholesale_cost) cs_wc, - sum(cs_sales_price) cs_sp - from catalog_sales - left join catalog_returns on cr_order_number=cs_order_number and cs_item_sk=cr_item_sk - join date_dim on cs_sold_date_sk = d_date_sk - where cr_order_number is null - group by d_year, cs_item_sk, cs_bill_customer_sk - ), -ss as - (select d_year AS ss_sold_year, ss_item_sk, - ss_customer_sk, - sum(ss_quantity) ss_qty, - sum(ss_wholesale_cost) ss_wc, - sum(ss_sales_price) ss_sp - from store_sales - left join store_returns on sr_ticket_number=ss_ticket_number and ss_item_sk=sr_item_sk - join date_dim on ss_sold_date_sk = d_date_sk - where sr_ticket_number is null - group by d_year, ss_item_sk, ss_customer_sk - ) - select -ss_sold_year, ss_item_sk, ss_customer_sk, -round(ss_qty/(coalesce(ws_qty,0)+coalesce(cs_qty,0)),2) ratio, -ss_qty store_qty, ss_wc store_wholesale_cost, ss_sp store_sales_price, -coalesce(ws_qty,0)+coalesce(cs_qty,0) other_chan_qty, -coalesce(ws_wc,0)+coalesce(cs_wc,0) other_chan_wholesale_cost, -coalesce(ws_sp,0)+coalesce(cs_sp,0) other_chan_sales_price -from ss -left join ws on (ws_sold_year=ss_sold_year and ws_item_sk=ss_item_sk and ws_customer_sk=ss_customer_sk) -left join cs on (cs_sold_year=ss_sold_year and cs_item_sk=ss_item_sk and cs_customer_sk=ss_customer_sk) -where (coalesce(ws_qty,0)>0 or coalesce(cs_qty, 0)>0) and ss_sold_year=1999 -order by - ss_sold_year, ss_item_sk, ss_customer_sk, - ss_qty desc, ss_wc desc, ss_sp desc, - other_chan_qty, - other_chan_wholesale_cost, - other_chan_sales_price, - ratio -limit 100; - --- end template query78.tpl query 35 in stream 8 --- start template query21.tpl query 36 in stream 8 -select /* TPC-DS query21.tpl 0.14 */ * - from(select w_warehouse_name - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('2001-05-15' as date)) - then inv_quantity_on_hand - else 0 end) as inv_before - ,sum(case when (cast(d_date as date) >= cast ('2001-05-15' as date)) - then inv_quantity_on_hand - else 0 end) as inv_after - from inventory - ,warehouse - ,item - ,date_dim - where i_current_price between 0.99 and 1.49 - and i_item_sk = inv_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('2001-05-15' as date)) - and dateadd(day,30,cast ('2001-05-15' as date)) - group by w_warehouse_name, i_item_id) x - where (case when inv_before > 0 - then inv_after / inv_before - else null - end) between 2.0/3.0 and 3.0/2.0 - order by w_warehouse_name - ,i_item_id - limit 100; - --- end template query21.tpl query 36 in stream 8 --- start template query67a.tpl query 37 in stream 8 -with /* TPC-DS query67a.tpl 0.35 */ results as -( select i_category ,i_class ,i_brand ,i_product_name ,d_year ,d_qoy ,d_moy ,s_store_id - ,sum(coalesce(ss_sales_price*ss_quantity,0)) sumsales - from store_sales ,date_dim ,store ,item - where ss_sold_date_sk=d_date_sk - and ss_item_sk=i_item_sk - and ss_store_sk = s_store_sk - and d_month_seq between 1183 and 1183 + 11 - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy,s_store_id) - , - results_rollup as - (select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, s_store_id, sumsales - from results - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy - union all - select i_category, i_class, i_brand, i_product_name, d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year - union all - select i_category, i_class, i_brand, i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name - union all - select i_category, i_class, i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand - union all - select i_category, i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class - union all - select i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category - union all - select null i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results) - - select * -from (select i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rank() over (partition by i_category order by sumsales desc) rk - from results_rollup) dw2 -where rk <= 100 -order by i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rk -limit 100; - --- end template query67a.tpl query 37 in stream 8 --- start template query22a.tpl query 38 in stream 8 -with /* TPC-DS query22a.tpl 0.55 */ results as -(select i_product_name - ,i_brand - ,i_class - ,i_category - ,avg(inv_quantity_on_hand) qoh - from inventory - ,date_dim - ,item --- ,warehouse - where inv_date_sk=d_date_sk - and inv_item_sk=i_item_sk --- and inv_warehouse_sk = w_warehouse_sk - and d_month_seq between 1197 and 1197 + 11 - group by i_product_name,i_brand,i_class,i_category), -results_rollup as -(select i_product_name, i_brand, i_class, i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class,i_category -union all -select i_product_name, i_brand, i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class -union all -select i_product_name, i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand -union all -select i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name -union all -select null i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results) - select i_product_name, i_brand, i_class, i_category,qoh - from results_rollup - order by qoh, i_product_name, i_brand, i_class, i_category -limit 100; - --- end template query22a.tpl query 38 in stream 8 --- start template query81.tpl query 39 in stream 8 -with /* TPC-DS query81.tpl 0.37 */ customer_total_return as - (select cr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(cr_return_amt_inc_tax) as ctr_total_return - from catalog_returns - ,date_dim - ,customer_address - where cr_returned_date_sk = d_date_sk - and d_year =2002 - and cr_returning_addr_sk = ca_address_sk - group by cr_returning_customer_sk - ,ca_state ) - select c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'AL' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - limit 100; - --- end template query81.tpl query 39 in stream 8 --- start template query93.tpl query 40 in stream 8 -select /* TPC-DS query93.tpl 0.52 */ ss_customer_sk - ,sum(act_sales) sumsales - from (select ss_item_sk - ,ss_ticket_number - ,ss_customer_sk - ,case when sr_return_quantity is not null then (ss_quantity-sr_return_quantity)*ss_sales_price - else (ss_quantity*ss_sales_price) end act_sales - from store_sales left outer join store_returns on (sr_item_sk = ss_item_sk - and sr_ticket_number = ss_ticket_number) - ,reason - where sr_reason_sk = r_reason_sk - and r_reason_desc = 'reason 50') t - group by ss_customer_sk - order by sumsales, ss_customer_sk -limit 100; - --- end template query93.tpl query 40 in stream 8 --- start template query25.tpl query 41 in stream 8 -select /* TPC-DS query25.tpl 0.9 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,min(ss_net_profit) as store_sales_profit - ,min(sr_net_loss) as store_returns_loss - ,min(cs_net_profit) as catalog_sales_profit - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 1999 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 10 - and d2.d_year = 1999 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_moy between 4 and 10 - and d3.d_year = 1999 - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query25.tpl query 41 in stream 8 --- start template query26.tpl query 42 in stream 8 -select /* TPC-DS query26.tpl 0.85 */ i_item_id, - avg(cs_quantity) agg1, - avg(cs_list_price) agg2, - avg(cs_coupon_amt) agg3, - avg(cs_sales_price) agg4 - from catalog_sales, customer_demographics, date_dim, item, promotion - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd_demo_sk and - cs_promo_sk = p_promo_sk and - cd_gender = 'F' and - cd_marital_status = 'D' and - cd_education_status = 'Secondary' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 2002 - group by i_item_id - order by i_item_id - limit 100; - --- end template query26.tpl query 42 in stream 8 --- start template query90.tpl query 43 in stream 8 -select /* TPC-DS query90.tpl 0.40 */ cast(amc as decimal(15,4))/cast(pmc as decimal(15,4)) am_pm_ratio - from ( select count(*) amc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 11 and 11+1 - and household_demographics.hd_dep_count = 9 - and web_page.wp_char_count between 5000 and 5200) at, - ( select count(*) pmc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 20 and 20+1 - and household_demographics.hd_dep_count = 9 - and web_page.wp_char_count between 5000 and 5200) pt - order by am_pm_ratio - limit 100; - --- end template query90.tpl query 43 in stream 8 --- start template query74.tpl query 44 in stream 8 -with /* TPC-DS query74.tpl 0.76 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,min(ss_net_paid) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1998,1998+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,min(ws_net_paid) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - and d_year in (1998,1998+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - ) - select - t_s_secyear.customer_id, t_s_secyear.customer_first_name, t_s_secyear.customer_last_name - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.year = 1998 - and t_s_secyear.year = 1998+1 - and t_w_firstyear.year = 1998 - and t_w_secyear.year = 1998+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - order by 2,3,1 -limit 100; - --- end template query74.tpl query 44 in stream 8 --- start template query92.tpl query 45 in stream 8 -select /* TPC-DS query92.tpl 0.44 */ - sum(ws_ext_discount_amt) as "Excess Discount Amount" -from - web_sales - ,item - ,date_dim -where -i_manufact_id = 393 -and i_item_sk = ws_item_sk -and d_date between '2002-02-03' and - dateadd(day,90,cast('2002-02-03' as date)) -and d_date_sk = ws_sold_date_sk -and ws_ext_discount_amt - > ( - SELECT - 1.3 * avg(ws_ext_discount_amt) - FROM - web_sales - ,date_dim - WHERE - ws_item_sk = i_item_sk - and d_date between '2002-02-03' and - dateadd(day,90,cast('2002-02-03' as date)) - and d_date_sk = ws_sold_date_sk - ) -order by sum(ws_ext_discount_amt) -limit 100; - --- end template query92.tpl query 45 in stream 8 --- start template query75.tpl query 46 in stream 8 -WITH /* TPC-DS query75.tpl 0.3 */ all_sales AS ( - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,SUM(sales_cnt) AS sales_cnt - ,SUM(sales_amt) AS sales_amt - FROM (SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,cs_quantity - COALESCE(cr_return_quantity,0) AS sales_cnt - ,cs_ext_sales_price - COALESCE(cr_return_amount,0.0) AS sales_amt - FROM catalog_sales JOIN item ON i_item_sk=cs_item_sk - JOIN date_dim ON d_date_sk=cs_sold_date_sk - LEFT JOIN catalog_returns ON (cs_order_number=cr_order_number - AND cs_item_sk=cr_item_sk) - WHERE i_category='Jewelry' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ss_quantity - COALESCE(sr_return_quantity,0) AS sales_cnt - ,ss_ext_sales_price - COALESCE(sr_return_amt,0.0) AS sales_amt - FROM store_sales JOIN item ON i_item_sk=ss_item_sk - JOIN date_dim ON d_date_sk=ss_sold_date_sk - LEFT JOIN store_returns ON (ss_ticket_number=sr_ticket_number - AND ss_item_sk=sr_item_sk) - WHERE i_category='Jewelry' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ws_quantity - COALESCE(wr_return_quantity,0) AS sales_cnt - ,ws_ext_sales_price - COALESCE(wr_return_amt,0.0) AS sales_amt - FROM web_sales JOIN item ON i_item_sk=ws_item_sk - JOIN date_dim ON d_date_sk=ws_sold_date_sk - LEFT JOIN web_returns ON (ws_order_number=wr_order_number - AND ws_item_sk=wr_item_sk) - WHERE i_category='Jewelry') sales_detail - GROUP BY d_year, i_brand_id, i_class_id, i_category_id, i_manufact_id) - SELECT prev_yr.d_year AS prev_year - ,curr_yr.d_year AS year - ,curr_yr.i_brand_id - ,curr_yr.i_class_id - ,curr_yr.i_category_id - ,curr_yr.i_manufact_id - ,prev_yr.sales_cnt AS prev_yr_cnt - ,curr_yr.sales_cnt AS curr_yr_cnt - ,curr_yr.sales_cnt-prev_yr.sales_cnt AS sales_cnt_diff - ,curr_yr.sales_amt-prev_yr.sales_amt AS sales_amt_diff - FROM all_sales curr_yr, all_sales prev_yr - WHERE curr_yr.i_brand_id=prev_yr.i_brand_id - AND curr_yr.i_class_id=prev_yr.i_class_id - AND curr_yr.i_category_id=prev_yr.i_category_id - AND curr_yr.i_manufact_id=prev_yr.i_manufact_id - AND curr_yr.d_year=1999 - AND prev_yr.d_year=1999-1 - AND CAST(curr_yr.sales_cnt AS DECIMAL(17,2))/CAST(prev_yr.sales_cnt AS DECIMAL(17,2))<0.9 - ORDER BY sales_cnt_diff,sales_amt_diff - limit 100; - --- end template query75.tpl query 46 in stream 8 --- start template query10.tpl query 47 in stream 8 -select /* TPC-DS query10.tpl 0.26 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3, - cd_dep_count, - count(*) cnt4, - cd_dep_employed_count, - count(*) cnt5, - cd_dep_college_count, - count(*) cnt6 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_county in ('Ottawa County','Wayne County','Dearborn County','Fall River County','Edwards County') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 4 and 4+3) and - (exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 4 ANd 4+3) or - exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 4 and 4+3)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count -limit 100; - --- end template query10.tpl query 47 in stream 8 --- start template query58.tpl query 48 in stream 8 -with /* TPC-DS query58.tpl 0.19 */ ss_items as - (select i_item_id item_id - ,sum(ss_ext_sales_price) ss_item_rev - from store_sales - ,item - ,date_dim - where ss_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '1998-04-26')) - and ss_sold_date_sk = d_date_sk - group by i_item_id), - cs_items as - (select i_item_id item_id - ,sum(cs_ext_sales_price) cs_item_rev - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '1998-04-26')) - and cs_sold_date_sk = d_date_sk - group by i_item_id), - ws_items as - (select i_item_id item_id - ,sum(ws_ext_sales_price) ws_item_rev - from web_sales - ,item - ,date_dim - where ws_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq =(select d_week_seq - from date_dim - where d_date = '1998-04-26')) - and ws_sold_date_sk = d_date_sk - group by i_item_id) - select ss_items.item_id - ,ss_item_rev - ,ss_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ss_dev - ,cs_item_rev - ,cs_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 cs_dev - ,ws_item_rev - ,ws_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ws_dev - ,(ss_item_rev+cs_item_rev+ws_item_rev)/3 average - from ss_items,cs_items,ws_items - where ss_items.item_id=cs_items.item_id - and ss_items.item_id=ws_items.item_id - and ss_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - and ss_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and cs_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and cs_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and ws_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and ws_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - order by item_id - ,ss_item_rev - limit 100; - --- end template query58.tpl query 48 in stream 8 --- start template query6.tpl query 49 in stream 8 -select /* TPC-DS query6.tpl 0.58 */ a.ca_state state, count(*) cnt - from customer_address a - ,customer c - ,store_sales s - ,date_dim d - ,item i - where a.ca_address_sk = c.c_current_addr_sk - and c.c_customer_sk = s.ss_customer_sk - and s.ss_sold_date_sk = d.d_date_sk - and s.ss_item_sk = i.i_item_sk - and d.d_month_seq = - (select distinct (d_month_seq) - from date_dim - where d_year = 2001 - and d_moy = 6 ) - and i.i_current_price > 1.2 * - (select avg(j.i_current_price) - from item j - where j.i_category = i.i_category) - group by a.ca_state - having count(*) >= 10 - order by cnt, a.ca_state - limit 100; - --- end template query6.tpl query 49 in stream 8 --- start template query47.tpl query 50 in stream 8 -with /* TPC-DS query47.tpl 0.42 */ v1 as( - select i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, - s_store_name, s_company_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - s_store_name, s_company_name - order by d_year, d_moy) rn - from item, store_sales, date_dim, store - where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - ( - d_year = 1999 or - ( d_year = 1999-1 and d_moy =12) or - ( d_year = 1999+1 and d_moy =1) - ) - group by i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy), - v2 as( - select v1.s_company_name - ,v1.d_year, v1.d_moy - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1.s_store_name = v1_lag.s_store_name and - v1.s_store_name = v1_lead.s_store_name and - v1.s_company_name = v1_lag.s_company_name and - v1.s_company_name = v1_lead.s_company_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 1999 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, sum_sales - limit 100; - --- end template query47.tpl query 50 in stream 8 --- start template query30.tpl query 51 in stream 8 -with /* TPC-DS query30.tpl 0.75 */ customer_total_return as - (select wr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(wr_return_amt) as ctr_total_return - from web_returns - ,date_dim - ,customer_address - where wr_returned_date_sk = d_date_sk - and d_year =2001 - and wr_returning_addr_sk = ca_address_sk - group by wr_returning_customer_sk - ,ca_state) - select c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'CA' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return -limit 100; - --- end template query30.tpl query 51 in stream 8 --- start template query94.tpl query 52 in stream 8 -select /* TPC-DS query94.tpl 0.17 */ - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2001-4-01' and - dateadd(day,60,cast('2001-4-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'CO' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and exists (select * - from web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) -and not exists(select * - from web_returns wr1 - where ws1.ws_order_number = wr1.wr_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query94.tpl query 52 in stream 8 --- start template query97.tpl query 53 in stream 8 -with /* TPC-DS query97.tpl 0.38 */ ssci as ( -select ss_customer_sk customer_sk - ,ss_item_sk item_sk -from store_sales,date_dim -where ss_sold_date_sk = d_date_sk - and d_month_seq between 1201 and 1201 + 11 -group by ss_customer_sk - ,ss_item_sk), -csci as( - select cs_bill_customer_sk customer_sk - ,cs_item_sk item_sk -from catalog_sales,date_dim -where cs_sold_date_sk = d_date_sk - and d_month_seq between 1201 and 1201 + 11 -group by cs_bill_customer_sk - ,cs_item_sk) - select sum(case when ssci.customer_sk is not null and csci.customer_sk is null then 1 else 0 end) store_only - ,sum(case when ssci.customer_sk is null and csci.customer_sk is not null then 1 else 0 end) catalog_only - ,sum(case when ssci.customer_sk is not null and csci.customer_sk is not null then 1 else 0 end) store_and_catalog -from ssci full outer join csci on (ssci.customer_sk=csci.customer_sk - and ssci.item_sk = csci.item_sk) -limit 100; - --- end template query97.tpl query 53 in stream 8 --- start template query55.tpl query 54 in stream 8 -select /* TPC-DS query55.tpl 0.82 */ i_brand_id brand_id, i_brand brand, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=61 - and d_moy=11 - and d_year=2001 - group by i_brand, i_brand_id - order by ext_price desc, i_brand_id -limit 100 ; - --- end template query55.tpl query 54 in stream 8 --- start template query72.tpl query 55 in stream 8 -select /* TPC-DS query72.tpl 0.87 */ i_item_desc - ,w_warehouse_name - ,d1.d_week_seq - ,sum(case when p_promo_sk is null then 1 else 0 end) no_promo - ,sum(case when p_promo_sk is not null then 1 else 0 end) promo - ,count(*) total_cnt -from catalog_sales -join inventory on (cs_item_sk = inv_item_sk) -join warehouse on (w_warehouse_sk=inv_warehouse_sk) -join item on (i_item_sk = cs_item_sk) -join customer_demographics on (cs_bill_cdemo_sk = cd_demo_sk) -join household_demographics on (cs_bill_hdemo_sk = hd_demo_sk) -join date_dim d1 on (cs_sold_date_sk = d1.d_date_sk) -join date_dim d2 on (inv_date_sk = d2.d_date_sk) -join date_dim d3 on (cs_ship_date_sk = d3.d_date_sk) -left outer join promotion on (cs_promo_sk=p_promo_sk) -left outer join catalog_returns on (cr_item_sk = cs_item_sk and cr_order_number = cs_order_number) -where d1.d_week_seq = d2.d_week_seq - and inv_quantity_on_hand < cs_quantity - and d3.d_date > d1.d_date + 5 - and hd_buy_potential = '>10000' - and d1.d_year = 1999 - and cd_marital_status = 'U' -group by i_item_desc,w_warehouse_name,d1.d_week_seq -order by total_cnt desc, i_item_desc, w_warehouse_name, d_week_seq -limit 100; - --- end template query72.tpl query 55 in stream 8 --- start template query95.tpl query 56 in stream 8 -with /* TPC-DS query95.tpl 0.43 */ ws_wh as -(select ws1.ws_order_number,ws1.ws_warehouse_sk wh1,ws2.ws_warehouse_sk wh2 - from web_sales ws1,web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) - select - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '1999-2-01' and - dateadd(day,60,cast('1999-2-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'VA' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and ws1.ws_order_number in (select ws_order_number - from ws_wh) -and ws1.ws_order_number in (select wr_order_number - from web_returns,ws_wh - where wr_order_number = ws_wh.ws_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query95.tpl query 56 in stream 8 --- start template query86a.tpl query 57 in stream 8 -with /* TPC-DS query86a.tpl 0.11 */ results as -( select sum(ws_net_paid) as total_sum, i_category, i_class, 0 as g_category, 0 as g_class - from - web_sales - ,date_dim d1 - ,item - where - d1.d_month_seq between 1222 and 1222+11 - and d1.d_date_sk = ws_sold_date_sk - and i_item_sk = ws_item_sk - group by i_category,i_class - ) , - - results_rollup as -( select total_sum ,i_category ,i_class, g_category, g_class, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum, i_category, NULL as i_class, 0 as g_category, 1 as g_class, 1 as lochierarchy from results group by i_category - union - select sum(total_sum) as total_sum, NULL as i_category, NULL as i_class, 1 as g_category, 1 as g_class, 2 as lochierarchy from results) - select - total_sum ,i_category ,i_class, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_class = 0 then i_category end - order by total_sum desc) as rank_within_parent - from - results_rollup - order by - lochierarchy desc, - case when lochierarchy = 0 then i_category end, - rank_within_parent - limit 100; - --- end template query86a.tpl query 57 in stream 8 --- start template query39.tpl query 58 in stream 8 -with /* TPC-DS query39.tpl 0.5 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =1999 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=3 - and inv2.d_moy=3+1 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; -with /* TPC-DS query39.tpl 0.5 part2 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =1999 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=3 - and inv2.d_moy=3+1 - and inv1.cov > 1.5 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; - --- end template query39.tpl query 58 in stream 8 --- start template query17.tpl query 59 in stream 8 -select /* TPC-DS query17.tpl 0.41 */ i_item_id - ,i_item_desc - ,s_state - ,count(ss_quantity) as store_sales_quantitycount - ,avg(ss_quantity) as store_sales_quantityave - ,stddev_samp(ss_quantity) as store_sales_quantitystdev - ,stddev_samp(ss_quantity)/avg(ss_quantity) as store_sales_quantitycov - ,count(sr_return_quantity) as store_returns_quantitycount - ,avg(sr_return_quantity) as store_returns_quantityave - ,stddev_samp(sr_return_quantity) as store_returns_quantitystdev - ,stddev_samp(sr_return_quantity)/avg(sr_return_quantity) as store_returns_quantitycov - ,count(cs_quantity) as catalog_sales_quantitycount ,avg(cs_quantity) as catalog_sales_quantityave - ,stddev_samp(cs_quantity) as catalog_sales_quantitystdev - ,stddev_samp(cs_quantity)/avg(cs_quantity) as catalog_sales_quantitycov - from store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where d1.d_quarter_name = '1999Q1' - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_quarter_name in ('1999Q1','1999Q2','1999Q3') - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_quarter_name in ('1999Q1','1999Q2','1999Q3') - group by i_item_id - ,i_item_desc - ,s_state - order by i_item_id - ,i_item_desc - ,s_state -limit 100; - --- end template query17.tpl query 59 in stream 8 --- start template query42.tpl query 60 in stream 8 -select /* TPC-DS query42.tpl 0.61 */ dt.d_year - ,item.i_category_id - ,item.i_category - ,sum(ss_ext_sales_price) - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=12 - and dt.d_year=2000 - group by dt.d_year - ,item.i_category_id - ,item.i_category - order by sum(ss_ext_sales_price) desc,dt.d_year - ,item.i_category_id - ,item.i_category -limit 100 ; - --- end template query42.tpl query 60 in stream 8 --- start template query85.tpl query 61 in stream 8 -select /* TPC-DS query85.tpl 0.33 */ substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) - from web_sales, web_returns, web_page, customer_demographics cd1, - customer_demographics cd2, customer_address, date_dim, reason - where ws_web_page_sk = wp_web_page_sk - and ws_item_sk = wr_item_sk - and ws_order_number = wr_order_number - and ws_sold_date_sk = d_date_sk and d_year = 1998 - and cd1.cd_demo_sk = wr_refunded_cdemo_sk - and cd2.cd_demo_sk = wr_returning_cdemo_sk - and ca_address_sk = wr_refunded_addr_sk - and r_reason_sk = wr_reason_sk - and - ( - ( - cd1.cd_marital_status = 'U' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Primary' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 100.00 and 150.00 - ) - or - ( - cd1.cd_marital_status = 'M' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = '4 yr Degree' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 50.00 and 100.00 - ) - or - ( - cd1.cd_marital_status = 'W' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Secondary' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ca_country = 'United States' - and - ca_state in ('AR', 'NY', 'CT') - and ws_net_profit between 100 and 200 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('SD', 'VA', 'MS') - and ws_net_profit between 150 and 300 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('IL', 'WV', 'AL') - and ws_net_profit between 50 and 250 - ) - ) -group by r_reason_desc -order by substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) -limit 100; - --- end template query85.tpl query 61 in stream 8 --- start template query9.tpl query 62 in stream 8 -select /* TPC-DS query9.tpl 0.49 */ case when (select count(*) - from store_sales - where ss_quantity between 1 and 20) > 15256314 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 1 and 20) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 1 and 20) end bucket1 , - case when (select count(*) - from store_sales - where ss_quantity between 21 and 40) > 96142604 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 21 and 40) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 21 and 40) end bucket2, - case when (select count(*) - from store_sales - where ss_quantity between 41 and 60) > 64752420 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 41 and 60) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 41 and 60) end bucket3, - case when (select count(*) - from store_sales - where ss_quantity between 61 and 80) > 97828692 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 61 and 80) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 61 and 80) end bucket4, - case when (select count(*) - from store_sales - where ss_quantity between 81 and 100) > 110058222 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 81 and 100) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 81 and 100) end bucket5 -from reason -where r_reason_sk = 1 -; - --- end template query9.tpl query 62 in stream 8 --- start template query32.tpl query 63 in stream 8 -select /* TPC-DS query32.tpl 0.7 */ sum(cs_ext_discount_amt) as "excess discount amount" -from - catalog_sales - ,item - ,date_dim -where -i_manufact_id = 944 -and i_item_sk = cs_item_sk -and d_date between '2002-03-27' and - dateadd(day,90,cast('2002-03-27' as date)) -and d_date_sk = cs_sold_date_sk -and cs_ext_discount_amt - > ( - select - 1.3 * avg(cs_ext_discount_amt) - from - catalog_sales - ,date_dim - where - cs_item_sk = i_item_sk - and d_date between '2002-03-27' and - dateadd(day,90,cast('2002-03-27' as date)) - and d_date_sk = cs_sold_date_sk - ) -limit 100; - --- end template query32.tpl query 63 in stream 8 --- start template query34.tpl query 64 in stream 8 -select /* TPC-DS query34.tpl 0.73 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (date_dim.d_dom between 1 and 3 or date_dim.d_dom between 25 and 28) - and (household_demographics.hd_buy_potential = '501-1000' or - household_demographics.hd_buy_potential = '0-500') - and household_demographics.hd_vehicle_count > 0 - and (case when household_demographics.hd_vehicle_count > 0 - then household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count - else null - end) > 1.2 - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_county in ('Perry County','Essex County','Williamson County','Arthur County', - 'Contra Costa County','Walker County','Daviess County','Kittitas County') - group by ss_ticket_number,ss_customer_sk) dn,customer - where ss_customer_sk = c_customer_sk - and cnt between 15 and 20 - order by c_last_name,c_first_name,c_salutation,c_preferred_cust_flag desc, ss_ticket_number; - --- end template query34.tpl query 64 in stream 8 --- start template query79.tpl query 65 in stream 8 -select /* TPC-DS query79.tpl 0.89 */ - c_last_name,c_first_name,substring(s_city,1,30),ss_ticket_number,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,store.s_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (household_demographics.hd_dep_count = 2 or household_demographics.hd_vehicle_count > 2) - and date_dim.d_dow = 1 - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_number_employees between 200 and 295 - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,store.s_city) ms,customer - where ss_customer_sk = c_customer_sk - order by c_last_name,c_first_name,substring(s_city,1,30), profit -limit 100; - --- end template query79.tpl query 65 in stream 8 --- start template query54.tpl query 66 in stream 8 -with /* TPC-DS query54.tpl 0.81 */ my_customers as ( - select distinct c_customer_sk - , c_current_addr_sk - from - ( select cs_sold_date_sk sold_date_sk, - cs_bill_customer_sk customer_sk, - cs_item_sk item_sk - from catalog_sales - union all - select ws_sold_date_sk sold_date_sk, - ws_bill_customer_sk customer_sk, - ws_item_sk item_sk - from web_sales - ) cs_or_ws_sales, - item, - date_dim, - customer - where sold_date_sk = d_date_sk - and item_sk = i_item_sk - and i_category = 'Sports' - and i_class = 'sailing' - and c_customer_sk = cs_or_ws_sales.customer_sk - and d_moy = 5 - and d_year = 1999 - ) - , my_revenue as ( - select c_customer_sk, - sum(ss_ext_sales_price) as revenue - from my_customers, - store_sales, - customer_address, - store, - date_dim - where c_current_addr_sk = ca_address_sk - and ca_county = s_county - and ca_state = s_state - and ss_sold_date_sk = d_date_sk - and c_customer_sk = ss_customer_sk - and d_month_seq between (select distinct d_month_seq+1 - from date_dim where d_year = 1999 and d_moy = 5) - and (select distinct d_month_seq+3 - from date_dim where d_year = 1999 and d_moy = 5) - group by c_customer_sk - ) - , segments as - (select cast((revenue/50) as int) as segment - from my_revenue - ) - select segment, count(*) as num_customers, segment*50 as segment_base - from segments - group by segment - order by segment, num_customers - limit 100; - --- end template query54.tpl query 66 in stream 8 --- start template query77a.tpl query 67 in stream 8 -with /* TPC-DS query77a.tpl 0.78 */ ss as - (select s_store_sk, - sum(ss_ext_sales_price) as sales, - sum(ss_net_profit) as profit - from store_sales, - date_dim, - store - where ss_sold_date_sk = d_date_sk - and d_date between cast('1999-08-19' as date) - and dateadd(day,30,cast('1999-08-19' as date)) - and ss_store_sk = s_store_sk - group by s_store_sk) - , - sr as - (select s_store_sk, - sum(sr_return_amt) as returns, - sum(sr_net_loss) as profit_loss - from store_returns, - date_dim, - store - where sr_returned_date_sk = d_date_sk - and d_date between cast('1999-08-19' as date) - and dateadd(day,30,cast('1999-08-19' as date)) - and sr_store_sk = s_store_sk - group by s_store_sk), - cs as - (select cs_call_center_sk, - sum(cs_ext_sales_price) as sales, - sum(cs_net_profit) as profit - from catalog_sales, - date_dim - where cs_sold_date_sk = d_date_sk - and d_date between cast('1999-08-19' as date) - and dateadd(day,30,cast('1999-08-19' as date)) - group by cs_call_center_sk - ), - cr as - (select cr_call_center_sk, - sum(cr_return_amount) as returns, - sum(cr_net_loss) as profit_loss - from catalog_returns, - date_dim - where cr_returned_date_sk = d_date_sk - and d_date between cast('1999-08-19' as date) - and dateadd(day,30,cast('1999-08-19' as date)) - group by cr_call_center_sk), - ws as - ( select wp_web_page_sk, - sum(ws_ext_sales_price) as sales, - sum(ws_net_profit) as profit - from web_sales, - date_dim, - web_page - where ws_sold_date_sk = d_date_sk - and d_date between cast('1999-08-19' as date) - and dateadd(day,30,cast('1999-08-19' as date)) - and ws_web_page_sk = wp_web_page_sk - group by wp_web_page_sk), - wr as - (select wp_web_page_sk, - sum(wr_return_amt) as returns, - sum(wr_net_loss) as profit_loss - from web_returns, - date_dim, - web_page - where wr_returned_date_sk = d_date_sk - and d_date between cast('1999-08-19' as date) - and dateadd(day,30,cast('1999-08-19' as date)) - and wr_web_page_sk = wp_web_page_sk - group by wp_web_page_sk) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , ss.s_store_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ss left join sr - on ss.s_store_sk = sr.s_store_sk - union all - select 'catalog channel' as channel - , cs_call_center_sk as id - , sales - , returns - , (profit - profit_loss) as profit - from cs - , cr - union all - select 'web channel' as channel - , ws.wp_web_page_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ws left join wr - on ws.wp_web_page_sk = wr.wp_web_page_sk - ) x - group by channel, id ) - - select * - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results -) foo -order by channel, id - limit 100; - --- end template query77a.tpl query 67 in stream 8 --- start template query45.tpl query 68 in stream 8 -select /* TPC-DS query45.tpl 0.18 */ ca_zip, ca_city, sum(ws_sales_price) - from web_sales, customer, customer_address, date_dim, item - where ws_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ws_item_sk = i_item_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', '85392', '85460', '80348', '81792') - or - i_item_id in (select i_item_id - from item - where i_item_sk in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29) - ) - ) - and ws_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 2002 - group by ca_zip, ca_city - order by ca_zip, ca_city - limit 100; - --- end template query45.tpl query 68 in stream 8 --- start template query28.tpl query 69 in stream 8 -select /* TPC-DS query28.tpl 0.36 */ * -from (select avg(ss_list_price) B1_LP - ,count(ss_list_price) B1_CNT - ,count(distinct ss_list_price) B1_CNTD - from store_sales - where ss_quantity between 0 and 5 - and (ss_list_price between 31 and 31+10 - or ss_coupon_amt between 13026 and 13026+1000 - or ss_wholesale_cost between 8 and 8+20)) B1, - (select avg(ss_list_price) B2_LP - ,count(ss_list_price) B2_CNT - ,count(distinct ss_list_price) B2_CNTD - from store_sales - where ss_quantity between 6 and 10 - and (ss_list_price between 72 and 72+10 - or ss_coupon_amt between 17504 and 17504+1000 - or ss_wholesale_cost between 67 and 67+20)) B2, - (select avg(ss_list_price) B3_LP - ,count(ss_list_price) B3_CNT - ,count(distinct ss_list_price) B3_CNTD - from store_sales - where ss_quantity between 11 and 15 - and (ss_list_price between 110 and 110+10 - or ss_coupon_amt between 9026 and 9026+1000 - or ss_wholesale_cost between 47 and 47+20)) B3, - (select avg(ss_list_price) B4_LP - ,count(ss_list_price) B4_CNT - ,count(distinct ss_list_price) B4_CNTD - from store_sales - where ss_quantity between 16 and 20 - and (ss_list_price between 68 and 68+10 - or ss_coupon_amt between 3865 and 3865+1000 - or ss_wholesale_cost between 72 and 72+20)) B4, - (select avg(ss_list_price) B5_LP - ,count(ss_list_price) B5_CNT - ,count(distinct ss_list_price) B5_CNTD - from store_sales - where ss_quantity between 21 and 25 - and (ss_list_price between 24 and 24+10 - or ss_coupon_amt between 4926 and 4926+1000 - or ss_wholesale_cost between 35 and 35+20)) B5, - (select avg(ss_list_price) B6_LP - ,count(ss_list_price) B6_CNT - ,count(distinct ss_list_price) B6_CNTD - from store_sales - where ss_quantity between 26 and 30 - and (ss_list_price between 27 and 27+10 - or ss_coupon_amt between 13868 and 13868+1000 - or ss_wholesale_cost between 80 and 80+20)) B6 -limit 100; - --- end template query28.tpl query 69 in stream 8 --- start template query11.tpl query 70 in stream 8 -with /* TPC-DS query11.tpl 0.51 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ss_ext_list_price-ss_ext_discount_amt) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ws_ext_list_price-ws_ext_discount_amt) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_preferred_cust_flag - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 2001 - and t_s_secyear.dyear = 2001+1 - and t_w_firstyear.dyear = 2001 - and t_w_secyear.dyear = 2001+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else 0.0 end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else 0.0 end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_preferred_cust_flag -limit 100; - --- end template query11.tpl query 70 in stream 8 --- start template query89.tpl query 71 in stream 8 -select /* TPC-DS query89.tpl 0.56 */ * -from( -select i_category, i_class, i_brand, - s_store_name, s_company_name, - d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, s_store_name, s_company_name) - avg_monthly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - d_year in (1998) and - ((i_category in ('Shoes','Music','Home') and - i_class in ('athletic','country','blinds/shades') - ) - or (i_category in ('Children','Men','Jewelry') and - i_class in ('newborn','accessories','birdal') - )) -group by i_category, i_class, i_brand, - s_store_name, s_company_name, d_moy) tmp1 -where case when (avg_monthly_sales <> 0) then (abs(sum_sales - avg_monthly_sales) / avg_monthly_sales) else null end > 0.1 -order by sum_sales - avg_monthly_sales, s_store_name -limit 100; - --- end template query89.tpl query 71 in stream 8 --- start template query56.tpl query 72 in stream 8 -with /* TPC-DS query56.tpl 0.83 */ ss as ( - select i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where i_item_id in (select - i_item_id -from item -where i_color in ('violet','dodger','orchid')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 6 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - cs as ( - select i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('violet','dodger','orchid')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 6 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - ws as ( - select i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('violet','dodger','orchid')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 6 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id) - select i_item_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by total_sales, - i_item_id - limit 100; - --- end template query56.tpl query 72 in stream 8 --- start template query46.tpl query 73 in stream 8 -select /* TPC-DS query46.tpl 0.23 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and (household_demographics.hd_dep_count = 9 or - household_demographics.hd_vehicle_count= 0) - and date_dim.d_dow in (6,0) - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_city in ('New Hope','Mount Pleasant','Lebanon','Sulphur Springs','Springfield') - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,ca_city) dn,customer,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - limit 100; - --- end template query46.tpl query 73 in stream 8 --- start template query19.tpl query 74 in stream 8 -select /* TPC-DS query19.tpl 0.8 */ i_brand_id brand_id, i_brand brand, i_manufact_id, i_manufact, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item,customer,customer_address,store - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=47 - and d_moy=11 - and d_year=2000 - and ss_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and substring(ca_zip,1,5) <> substring(s_zip,1,5) - and ss_store_sk = s_store_sk - group by i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact - order by ext_price desc - ,i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact -limit 100 ; - --- end template query19.tpl query 74 in stream 8 --- start template query62.tpl query 75 in stream 8 -select /* TPC-DS query62.tpl 0.24 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 30) and - (ws_ship_date_sk - ws_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 60) and - (ws_ship_date_sk - ws_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 90) and - (ws_ship_date_sk - ws_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - web_sales - ,warehouse - ,ship_mode - ,web_site - ,date_dim -where - d_month_seq between 1224 and 1224 + 11 -and ws_ship_date_sk = d_date_sk -and ws_warehouse_sk = w_warehouse_sk -and ws_ship_mode_sk = sm_ship_mode_sk -and ws_web_site_sk = web_site_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -limit 100; - --- end template query62.tpl query 75 in stream 8 --- start template query8.tpl query 76 in stream 8 -select /* TPC-DS query8.tpl 0.63 */ s_store_name - ,sum(ss_net_profit) - from store_sales - ,date_dim - ,store, - (select ca_zip - from ( - SELECT substring(ca_zip,1,5) ca_zip - FROM customer_address - WHERE substring(ca_zip,1,5) IN ( - '13716','26981','47813','11334','23406','84891', - '45157','29831','19642','79801','59935', - '47470','67096','35893','72818','79501', - '90702','15272','60303','23529','14424', - '41378','84952','53862','53606','28784', - '86638','45817','66574','44301','23734', - '85926','76384','65928','40812','77510', - '46369','54152','59743','90230','25299', - '25714','49696','39211','54678','43800', - '63578','20562','88099','66530','12421', - '12073','33923','95024','22299','84062', - '95186','37755','26758','55500','46802', - '14343','65378','83493','74980','59031', - '75838','69910','14946','29196','38664', - '58717','91219','24714','75237','98535', - '76684','43693','32958','63873','18189', - '65508','39425','36728','97813','69256', - '91192','49531','18050','99795','14811', - '30719','91348','31092','88089','80628', - '78307','51492','20949','61882','97538', - '38351','18809','98302','93095','18326', - '10279','95446','41373','99708','32661', - '28333','66333','67786','17984','58358', - '56525','57593','36460','19170','76994', - '71920','82571','76858','50047','82056', - '55026','56031','58330','73247','23065', - '40019','13866','75551','53155','58751', - '40846','34484','27239','20659','69206', - '78836','72226','99196','85574','26979', - '87451','73770','67822','51289','55955', - '90312','93146','43465','61210','89775', - '31716','64380','17685','78488','93459', - '86419','37298','51357','12165','44816', - '45670','38285','66744','91620','25658', - '57105','85735','95617','43990','53964', - '79550','58010','45934','37848','81278', - '44445','47352','28641','71990','14592', - '60760','29411','42759','26802','48296', - '40199','84076','24027','39491','36142', - '21589','81115','99799','71028','18873', - '84105','62010','63608','36918','22829', - '23666','41214','11358','43862','87823', - '14405','98329','59278','75417','81635', - '74834','41649','27467','19949','70003', - '23367','61963','63333','73125','60028', - '88228','50840','86534','90746','74320', - '57565','17721','36112','79380','14441', - '49814','65536','61157','11059','49676', - '98598','16685','19366','55151','60694', - '46861','97716','26811','89883','14013', - '82866','29225','81783','19340','64880', - '29031','69820','11709','25922','12131', - '45798','62769','46975','84914','97070', - '53822','35460','11421','32062','68918', - '69956','31684','53465','64832','75342', - '90813','49029','57592','33391','69716', - '41533','62502','50026','55435','90377', - '72943','29904','62333','69086','91574', - '57810','64154','40172','75235','17962', - '70683','93729','37498','37997','42839', - '82735','35067','89822','63214','53474', - '97196','61862','25633','23805','21415', - '30005','86716','16208','57996','91968', - '83385','42976','46583','86044','97271', - '79862','54417','82502','72935','36284', - '41037','83318','23324','89430','55413', - '19786','67291','42060','48080','84473', - '25678','14055','38506','13001','19552', - '61612','47104','90500','77742','23546', - '10518','53565','56137','47471','13880', - '40921','97854','82204','31383','41605', - '43633','23762','18736','13631','39580', - '25225','82336','58794','85863','98209', - '20884','18532','64752','79921','51745', - '34012','37476','61724','51951','13156', - '99937','25725','73257','80551','17785', - '72893','62610','57730','30290','21976', - '97910','34302','48773','43812','99069', - '34834','47091','81522','12329','24305', - '19989','35176','69601','44246') - intersect - select ca_zip - from (SELECT substring(ca_zip,1,5) ca_zip,count(*) cnt - FROM customer_address, customer - WHERE ca_address_sk = c_current_addr_sk and - c_preferred_cust_flag='Y' - group by ca_zip - having count(*) > 10)A1)A2) V1 - where ss_store_sk = s_store_sk - and ss_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 2001 - and (substring(s_zip,1,2) = substring(V1.ca_zip,1,2)) - group by s_store_name - order by s_store_name - limit 100; - --- end template query8.tpl query 76 in stream 8 --- start template query96.tpl query 77 in stream 8 -select /* TPC-DS query96.tpl 0.1 */ count(*) -from store_sales - ,household_demographics - ,time_dim, store -where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 15 - and time_dim.t_minute >= 30 - and household_demographics.hd_dep_count = 2 - and store.s_store_name = 'ese' -order by count(*) -limit 100; - --- end template query96.tpl query 77 in stream 8 --- start template query1.tpl query 78 in stream 8 -with /* TPC-DS query1.tpl 0.12 */ customer_total_return as -(select sr_customer_sk as ctr_customer_sk -,sr_store_sk as ctr_store_sk -,sum(SR_REVERSED_CHARGE) as ctr_total_return -from store_returns -,date_dim -where sr_returned_date_sk = d_date_sk -and d_year =2000 -group by sr_customer_sk -,sr_store_sk) - select c_customer_id -from customer_total_return ctr1 -,store -,customer -where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 -from customer_total_return ctr2 -where ctr1.ctr_store_sk = ctr2.ctr_store_sk) -and s_store_sk = ctr1.ctr_store_sk -and s_state = 'PA' -and ctr1.ctr_customer_sk = c_customer_sk -order by c_customer_id -limit 100; - --- end template query1.tpl query 78 in stream 8 --- start template query23.tpl query 79 in stream 8 -with /* TPC-DS query23.tpl 0.68 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (2000,2000+1,2000+2,2000+3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (2000,2000+1,2000+2,2000+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * -from - max_store_sales)) - select sum(sales) - from (select cs_quantity*cs_list_price sales - from catalog_sales - ,date_dim - where d_year = 2000 - and d_moy = 2 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - union all - select ws_quantity*ws_list_price sales - from web_sales - ,date_dim - where d_year = 2000 - and d_moy = 2 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer)) - limit 100; -with /* TPC-DS query23.tpl 0.68 part2 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (2000,2000 + 1,2000 + 2,2000 + 3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (2000,2000+1,2000+2,2000+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * - from max_store_sales)) - select c_last_name,c_first_name,sales - from (select c_last_name,c_first_name,sum(cs_quantity*cs_list_price) sales - from catalog_sales - ,customer - ,date_dim - where d_year = 2000 - and d_moy = 2 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and cs_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name - union all - select c_last_name,c_first_name,sum(ws_quantity*ws_list_price) sales - from web_sales - ,customer - ,date_dim - where d_year = 2000 - and d_moy = 2 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and ws_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name) - order by c_last_name,c_first_name,sales - limit 100; - --- end template query23.tpl query 79 in stream 8 --- start template query88.tpl query 80 in stream 8 -select /* TPC-DS query88.tpl 0.66 */ * -from - (select count(*) h8_30_to_9 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2)) - and store.s_store_name = 'ese') s1, - (select count(*) h9_to_9_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2)) - and store.s_store_name = 'ese') s2, - (select count(*) h9_30_to_10 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2)) - and store.s_store_name = 'ese') s3, - (select count(*) h10_to_10_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2)) - and store.s_store_name = 'ese') s4, - (select count(*) h10_30_to_11 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2)) - and store.s_store_name = 'ese') s5, - (select count(*) h11_to_11_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2)) - and store.s_store_name = 'ese') s6, - (select count(*) h11_30_to_12 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2)) - and store.s_store_name = 'ese') s7, - (select count(*) h12_to_12_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 12 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2)) - and store.s_store_name = 'ese') s8 -; - --- end template query88.tpl query 80 in stream 8 --- start template query82.tpl query 81 in stream 8 -select /* TPC-DS query82.tpl 0.67 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, store_sales - where i_current_price between 67 and 67+30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('2000-03-21' as date) and dateadd(day,60,cast('2000-03-21' as date)) - and i_manufact_id in (509,410,487,347) - and inv_quantity_on_hand between 100 and 500 - and ss_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query82.tpl query 81 in stream 8 --- start template query87.tpl query 82 in stream 8 -select /* TPC-DS query87.tpl 0.77 */ count(*) -from ((select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1200 and 1200+11) - except - (select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1200 and 1200+11) - except - (select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1200 and 1200+11) -) cool_cust -; - --- end template query87.tpl query 82 in stream 8 --- start template query43.tpl query 83 in stream 8 -select /* TPC-DS query43.tpl 0.15 */ s_store_name, s_store_id, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from date_dim, store_sales, store - where d_date_sk = ss_sold_date_sk and - s_store_sk = ss_store_sk and - s_gmt_offset = -6 and - d_year = 1998 - group by s_store_name, s_store_id - order by s_store_name, s_store_id,sun_sales,mon_sales,tue_sales,wed_sales,thu_sales,fri_sales,sat_sales - limit 100; - --- end template query43.tpl query 83 in stream 8 --- start template query53.tpl query 84 in stream 8 -select /* TPC-DS query53.tpl 0.88 */ * from -(select i_manufact_id, -sum(ss_sales_price) sum_sales, -avg(sum(ss_sales_price)) over (partition by i_manufact_id) avg_quarterly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and -ss_sold_date_sk = d_date_sk and -ss_store_sk = s_store_sk and -d_month_seq in (1221,1221+1,1221+2,1221+3,1221+4,1221+5,1221+6,1221+7,1221+8,1221+9,1221+10,1221+11) and -((i_category in ('Books','Children','Electronics') and -i_class in ('personal','portable','reference','self-help') and -i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) -or(i_category in ('Women','Music','Men') and -i_class in ('accessories','classical','fragrances','pants') and -i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manufact_id, d_qoy ) tmp1 -where case when avg_quarterly_sales > 0 - then abs (sum_sales - avg_quarterly_sales)/ avg_quarterly_sales - else null end > 0.1 -order by avg_quarterly_sales, - sum_sales, - i_manufact_id -limit 100; - --- end template query53.tpl query 84 in stream 8 --- start template query20.tpl query 85 in stream 8 -select /* TPC-DS query20.tpl 0.65 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(cs_ext_sales_price) as itemrevenue - ,sum(cs_ext_sales_price)*100/sum(sum(cs_ext_sales_price)) over - (partition by i_class) as revenueratio - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and i_category in ('Books', 'Electronics', 'Home') - and cs_sold_date_sk = d_date_sk - and d_date between cast('2002-01-22' as date) - and dateadd(day,30,cast('2002-01-22' as date)) - group by i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - order by i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query20.tpl query 85 in stream 8 --- start template query52.tpl query 86 in stream 8 -select /* TPC-DS query52.tpl 0.59 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_sales_price) ext_price - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=11 - and dt.d_year=1998 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,ext_price desc - ,brand_id -limit 100 ; - --- end template query52.tpl query 86 in stream 8 --- start template query83.tpl query 87 in stream 8 -with /* TPC-DS query83.tpl 0.96 */ sr_items as - (select i_item_id item_id, - sum(sr_return_quantity) sr_item_qty - from store_returns, - item, - date_dim - where sr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2002-02-01','2002-09-03','2002-11-17'))) - and sr_returned_date_sk = d_date_sk - group by i_item_id), - cr_items as - (select i_item_id item_id, - sum(cr_return_quantity) cr_item_qty - from catalog_returns, - item, - date_dim - where cr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2002-02-01','2002-09-03','2002-11-17'))) - and cr_returned_date_sk = d_date_sk - group by i_item_id), - wr_items as - (select i_item_id item_id, - sum(wr_return_quantity) wr_item_qty - from web_returns, - item, - date_dim - where wr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2002-02-01','2002-09-03','2002-11-17'))) - and wr_returned_date_sk = d_date_sk - group by i_item_id) - select sr_items.item_id - ,sr_item_qty - ,sr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 sr_dev - ,cr_item_qty - ,cr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 cr_dev - ,wr_item_qty - ,wr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 wr_dev - ,(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 average - from sr_items - ,cr_items - ,wr_items - where sr_items.item_id=cr_items.item_id - and sr_items.item_id=wr_items.item_id - order by sr_items.item_id - ,sr_item_qty - limit 100; - --- end template query83.tpl query 87 in stream 8 --- start template query38.tpl query 88 in stream 8 -select /* TPC-DS query38.tpl 0.54 */ count(*) from ( - select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1214 and 1214 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1214 and 1214 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1214 and 1214 + 11 -) hot_cust -limit 100; - --- end template query38.tpl query 88 in stream 8 --- start template query68.tpl query 89 in stream 8 -select /* TPC-DS query68.tpl 0.95 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,extended_price - ,extended_tax - ,list_price - from (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_ext_sales_price) extended_price - ,sum(ss_ext_list_price) list_price - ,sum(ss_ext_tax) extended_tax - from store_sales - ,date_dim - ,store - ,household_demographics - ,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_dep_count = 2 or - household_demographics.hd_vehicle_count= -1) - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_city in ('Walnut Grove','Springfield') - group by ss_ticket_number - ,ss_customer_sk - ,ss_addr_sk,ca_city) dn - ,customer - ,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,ss_ticket_number - limit 100; - --- end template query68.tpl query 89 in stream 8 --- start template query4.tpl query 90 in stream 8 -with /* TPC-DS query4.tpl 0.93 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(((ss_ext_list_price-ss_ext_wholesale_cost-ss_ext_discount_amt)+ss_ext_sales_price)/2) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((cs_ext_list_price-cs_ext_wholesale_cost-cs_ext_discount_amt)+cs_ext_sales_price)/2) ) year_total - ,'c' sale_type - from customer - ,catalog_sales - ,date_dim - where c_customer_sk = cs_bill_customer_sk - and cs_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year -union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((ws_ext_list_price-ws_ext_wholesale_cost-ws_ext_discount_amt)+ws_ext_sales_price)/2) ) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_login - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_c_firstyear - ,year_total t_c_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_c_secyear.customer_id - and t_s_firstyear.customer_id = t_c_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_c_firstyear.sale_type = 'c' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_c_secyear.sale_type = 'c' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 1999 - and t_s_secyear.dyear = 1999+1 - and t_c_firstyear.dyear = 1999 - and t_c_secyear.dyear = 1999+1 - and t_w_firstyear.dyear = 1999 - and t_w_secyear.dyear = 1999+1 - and t_s_firstyear.year_total > 0 - and t_c_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_login -limit 100; - --- end template query4.tpl query 90 in stream 8 --- start template query13.tpl query 91 in stream 8 -select /* TPC-DS query13.tpl 0.91 */ avg(ss_quantity) - ,avg(ss_ext_sales_price) - ,avg(ss_ext_wholesale_cost) - ,sum(ss_ext_wholesale_cost) - from store_sales - ,store - ,customer_demographics - ,household_demographics - ,customer_address - ,date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2001 - and((ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'D' - and cd_education_status = 'Advanced Degree' - and ss_sales_price between 100.00 and 150.00 - and hd_dep_count = 3 - )or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'W' - and cd_education_status = 'Unknown' - and ss_sales_price between 50.00 and 100.00 - and hd_dep_count = 1 - ) or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'M' - and cd_education_status = 'College' - and ss_sales_price between 150.00 and 200.00 - and hd_dep_count = 1 - )) - and((ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('VA', 'CO', 'KS') - and ss_net_profit between 100 and 200 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('PA', 'WI', 'AK') - and ss_net_profit between 150 and 300 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('TN', 'ID', 'SD') - and ss_net_profit between 50 and 250 - )) -; - --- end template query13.tpl query 91 in stream 8 --- start template query48.tpl query 92 in stream 8 -select /* TPC-DS query48.tpl 0.74 */ sum (ss_quantity) - from store_sales, store, customer_demographics, customer_address, date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2001 - and - ( - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'M' - and - cd_education_status = 'Secondary' - and - ss_sales_price between 100.00 and 150.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'S' - and - cd_education_status = 'Unknown' - and - ss_sales_price between 50.00 and 100.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'D' - and - cd_education_status = 'College' - and - ss_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('SC', 'CO', 'TX') - and ss_net_profit between 0 and 2000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('SD', 'KY', 'WI') - and ss_net_profit between 150 and 3000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('AL', 'VA', 'ND') - and ss_net_profit between 50 and 25000 - ) - ) -; - --- end template query48.tpl query 92 in stream 8 --- start template query99.tpl query 93 in stream 8 -select /* TPC-DS query99.tpl 0.94 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 30) and - (cs_ship_date_sk - cs_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 60) and - (cs_ship_date_sk - cs_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 90) and - (cs_ship_date_sk - cs_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - catalog_sales - ,warehouse - ,ship_mode - ,call_center - ,date_dim -where - d_month_seq between 1190 and 1190 + 11 -and cs_ship_date_sk = d_date_sk -and cs_warehouse_sk = w_warehouse_sk -and cs_ship_mode_sk = sm_ship_mode_sk -and cs_call_center_sk = cc_call_center_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -limit 100; - --- end template query99.tpl query 93 in stream 8 --- start template query27a.tpl query 94 in stream 8 -with /* TPC-DS query27a.tpl 0.16 */ results as - (select i_item_id, - s_state, 0 as g_state, - ss_quantity agg1, - ss_list_price agg2, - ss_coupon_amt agg3, - ss_sales_price agg4 - from store_sales, customer_demographics, date_dim, store, item - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_store_sk = s_store_sk and - ss_cdemo_sk = cd_demo_sk and - cd_gender = 'M' and - cd_marital_status = 'M' and - cd_education_status = '2 yr Degree' and - d_year = 1999 and - s_state in ('MO','NY', 'WV', 'LA', 'AL', 'NM') - ) - - select i_item_id, - s_state, g_state, agg1, agg2, agg3, agg4 - from ( - select i_item_id, s_state, 0 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4 from results - group by i_item_id, s_state - union all - select i_item_id, NULL AS s_state, 1 AS g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as s_state, 1 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - ) foo - order by i_item_id, s_state - limit 100; - --- end template query27a.tpl query 94 in stream 8 --- start template query18a.tpl query 95 in stream 8 -with /* TPC-DS query18a.tpl 0.90 */ results as - (select i_item_id, - ca_country, - ca_state, - ca_county, - cast(cs_quantity as decimal(12,2)) agg1, - cast(cs_list_price as decimal(12,2)) agg2, - cast(cs_coupon_amt as decimal(12,2)) agg3, - cast(cs_sales_price as decimal(12,2)) agg4, - cast(cs_net_profit as decimal(12,2)) agg5, - cast(c_birth_year as decimal(12,2)) agg6, - cast(cd1.cd_dep_count as decimal(12,2)) agg7 - from catalog_sales, customer_demographics cd1, customer_demographics cd2, customer, customer_address, date_dim, item - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd1.cd_demo_sk and - cs_bill_customer_sk = c_customer_sk and - cd1.cd_gender = 'F' and - cd1.cd_education_status = '4 yr Degree' and - c_current_cdemo_sk = cd2.cd_demo_sk and - c_current_addr_sk = ca_address_sk and - c_birth_month in (12,5,7,1,6,2) and - d_year = 1998 and - ca_state in ('VA','NC','IA','NV','KY','MI','MO') - ) - select i_item_id, ca_country, ca_state, ca_county, agg1, agg2, agg3, agg4, agg5, agg6, agg7 - from ( - select i_item_id, ca_country, ca_state, ca_county, avg(agg1) agg1, - avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state, ca_county - union all - select i_item_id, ca_country, ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state - union all - select i_item_id, ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country - union all - select i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - ) foo - order by ca_country, ca_state, ca_county, i_item_id - limit 100; - --- end template query18a.tpl query 95 in stream 8 --- start template query15.tpl query 96 in stream 8 -select /* TPC-DS query15.tpl 0.57 */ ca_zip - ,sum(cs_sales_price) - from catalog_sales - ,customer - ,customer_address - ,date_dim - where cs_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', - '85392', '85460', '80348', '81792') - or ca_state in ('CA','WA','GA') - or cs_sales_price > 500) - and cs_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 1998 - group by ca_zip - order by ca_zip - limit 100; - --- end template query15.tpl query 96 in stream 8 --- start template query33.tpl query 97 in stream 8 -with /* TPC-DS query33.tpl 0.22 */ ss as ( - select - i_manufact_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Sports')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 5 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id), - cs as ( - select - i_manufact_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Sports')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 5 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id), - ws as ( - select - i_manufact_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Sports')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 5 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id) - select i_manufact_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_manufact_id - order by total_sales -limit 100; - --- end template query33.tpl query 97 in stream 8 --- start template query31.tpl query 98 in stream 8 -with /* TPC-DS query31.tpl 0.50 */ ss as - (select ca_county,d_qoy, d_year,sum(ss_ext_sales_price) as store_sales - from store_sales,date_dim,customer_address - where ss_sold_date_sk = d_date_sk - and ss_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year), - ws as - (select ca_county,d_qoy, d_year,sum(ws_ext_sales_price) as web_sales - from web_sales,date_dim,customer_address - where ws_sold_date_sk = d_date_sk - and ws_bill_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year) - select - ss1.ca_county - ,ss1.d_year - ,ws2.web_sales/ws1.web_sales web_q1_q2_increase - ,ss2.store_sales/ss1.store_sales store_q1_q2_increase - ,ws3.web_sales/ws2.web_sales web_q2_q3_increase - ,ss3.store_sales/ss2.store_sales store_q2_q3_increase - from - ss ss1 - ,ss ss2 - ,ss ss3 - ,ws ws1 - ,ws ws2 - ,ws ws3 - where - ss1.d_qoy = 1 - and ss1.d_year = 1999 - and ss1.ca_county = ss2.ca_county - and ss2.d_qoy = 2 - and ss2.d_year = 1999 - and ss2.ca_county = ss3.ca_county - and ss3.d_qoy = 3 - and ss3.d_year = 1999 - and ss1.ca_county = ws1.ca_county - and ws1.d_qoy = 1 - and ws1.d_year = 1999 - and ws1.ca_county = ws2.ca_county - and ws2.d_qoy = 2 - and ws2.d_year = 1999 - and ws1.ca_county = ws3.ca_county - and ws3.d_qoy = 3 - and ws3.d_year =1999 - and case when ws1.web_sales > 0 then ws2.web_sales/ws1.web_sales else null end - > case when ss1.store_sales > 0 then ss2.store_sales/ss1.store_sales else null end - and case when ws2.web_sales > 0 then ws3.web_sales/ws2.web_sales else null end - > case when ss2.store_sales > 0 then ss3.store_sales/ss2.store_sales else null end - order by ss1.d_year; - --- end template query31.tpl query 98 in stream 8 --- start template query63.tpl query 99 in stream 8 -select /* TPC-DS query63.tpl 0.27 */ * -from (select i_manager_id - ,sum(ss_sales_price) sum_sales - ,avg(sum(ss_sales_price)) over (partition by i_manager_id) avg_monthly_sales - from item - ,store_sales - ,date_dim - ,store - where ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and d_month_seq in (1184,1184+1,1184+2,1184+3,1184+4,1184+5,1184+6,1184+7,1184+8,1184+9,1184+10,1184+11) - and (( i_category in ('Books','Children','Electronics') - and i_class in ('personal','portable','reference','self-help') - and i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) - or( i_category in ('Women','Music','Men') - and i_class in ('accessories','classical','fragrances','pants') - and i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manager_id, d_moy) tmp1 -where case when avg_monthly_sales > 0 then abs (sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 -order by i_manager_id - ,avg_monthly_sales - ,sum_sales -limit 100; - --- end template query63.tpl query 99 in stream 8 diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/10TB/queries/query_9.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/10TB/queries/query_9.sql deleted file mode 100644 index f179f07a..00000000 --- a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/10TB/queries/query_9.sql +++ /dev/null @@ -1,5027 +0,0 @@ --- start template query15.tpl query 1 in stream 9 -select /* TPC-DS query15.tpl 0.57 */ ca_zip - ,sum(cs_sales_price) - from catalog_sales - ,customer - ,customer_address - ,date_dim - where cs_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', - '85392', '85460', '80348', '81792') - or ca_state in ('CA','WA','GA') - or cs_sales_price > 500) - and cs_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 2000 - group by ca_zip - order by ca_zip - limit 100; - --- end template query15.tpl query 1 in stream 9 --- start template query60.tpl query 2 in stream 9 -with /* TPC-DS query60.tpl 0.29 */ ss as ( - select - i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Music')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 10 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - cs as ( - select - i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Music')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 10 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - ws as ( - select - i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Music')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 10 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id) - select - i_item_id -,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by i_item_id - ,total_sales - limit 100; - --- end template query60.tpl query 2 in stream 9 --- start template query62.tpl query 3 in stream 9 -select /* TPC-DS query62.tpl 0.24 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 30) and - (ws_ship_date_sk - ws_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 60) and - (ws_ship_date_sk - ws_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 90) and - (ws_ship_date_sk - ws_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - web_sales - ,warehouse - ,ship_mode - ,web_site - ,date_dim -where - d_month_seq between 1215 and 1215 + 11 -and ws_ship_date_sk = d_date_sk -and ws_warehouse_sk = w_warehouse_sk -and ws_ship_mode_sk = sm_ship_mode_sk -and ws_web_site_sk = web_site_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -limit 100; - --- end template query62.tpl query 3 in stream 9 --- start template query74.tpl query 4 in stream 9 -with /* TPC-DS query74.tpl 0.76 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,avg(ss_net_paid) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (2000,2000+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,avg(ws_net_paid) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - and d_year in (2000,2000+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - ) - select - t_s_secyear.customer_id, t_s_secyear.customer_first_name, t_s_secyear.customer_last_name - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.year = 2000 - and t_s_secyear.year = 2000+1 - and t_w_firstyear.year = 2000 - and t_w_secyear.year = 2000+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - order by 2,3,1 -limit 100; - --- end template query74.tpl query 4 in stream 9 --- start template query81.tpl query 5 in stream 9 -with /* TPC-DS query81.tpl 0.37 */ customer_total_return as - (select cr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(cr_return_amt_inc_tax) as ctr_total_return - from catalog_returns - ,date_dim - ,customer_address - where cr_returned_date_sk = d_date_sk - and d_year =2001 - and cr_returning_addr_sk = ca_address_sk - group by cr_returning_customer_sk - ,ca_state ) - select c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'KY' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - limit 100; - --- end template query81.tpl query 5 in stream 9 --- start template query88.tpl query 6 in stream 9 -select /* TPC-DS query88.tpl 0.66 */ * -from - (select count(*) h8_30_to_9 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s1, - (select count(*) h9_to_9_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s2, - (select count(*) h9_30_to_10 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s3, - (select count(*) h10_to_10_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s4, - (select count(*) h10_30_to_11 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s5, - (select count(*) h11_to_11_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s6, - (select count(*) h11_30_to_12 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s7, - (select count(*) h12_to_12_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 12 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s8 -; - --- end template query88.tpl query 6 in stream 9 --- start template query50.tpl query 7 in stream 9 -select /* TPC-DS query50.tpl 0.60 */ - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 30) and - (sr_returned_date_sk - ss_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 60) and - (sr_returned_date_sk - ss_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 90) and - (sr_returned_date_sk - ss_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - store_sales - ,store_returns - ,store - ,date_dim d1 - ,date_dim d2 -where - d2.d_year = 2001 -and d2.d_moy = 10 -and ss_ticket_number = sr_ticket_number -and ss_item_sk = sr_item_sk -and ss_sold_date_sk = d1.d_date_sk -and sr_returned_date_sk = d2.d_date_sk -and ss_customer_sk = sr_customer_sk -and ss_store_sk = s_store_sk -group by - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -order by s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -limit 100; - --- end template query50.tpl query 7 in stream 9 --- start template query5a.tpl query 8 in stream 9 -with /* TPC-DS query5a.tpl 0.98 */ ssr as - (select s_store_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ss_store_sk as store_sk, - ss_sold_date_sk as date_sk, - ss_ext_sales_price as sales_price, - ss_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from store_sales - union all - select sr_store_sk as store_sk, - sr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - sr_return_amt as return_amt, - sr_net_loss as net_loss - from store_returns - ) salesreturns, - date_dim, - store - where date_sk = d_date_sk - and d_date between cast('2001-08-22' as date) - and dateadd(day,14,cast('2001-08-22' as date)) - and store_sk = s_store_sk - group by s_store_id) - , - csr as - (select cp_catalog_page_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select cs_catalog_page_sk as page_sk, - cs_sold_date_sk as date_sk, - cs_ext_sales_price as sales_price, - cs_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from catalog_sales - union all - select cr_catalog_page_sk as page_sk, - cr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - cr_return_amount as return_amt, - cr_net_loss as net_loss - from catalog_returns - ) salesreturns, - date_dim, - catalog_page - where date_sk = d_date_sk - and d_date between cast('2001-08-22' as date) - and dateadd(day,14,cast('2001-08-22' as date)) - and page_sk = cp_catalog_page_sk - group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ws_web_site_sk as wsr_web_site_sk, - ws_sold_date_sk as date_sk, - ws_ext_sales_price as sales_price, - ws_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from web_sales - union all - select ws_web_site_sk as wsr_web_site_sk, - wr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - wr_return_amt as return_amt, - wr_net_loss as net_loss - from web_returns left outer join web_sales on - ( wr_item_sk = ws_item_sk - and wr_order_number = ws_order_number) - ) salesreturns, - date_dim, - web_site - where date_sk = d_date_sk - and d_date between cast('2001-08-22' as date) - and dateadd(day,14,cast('2001-08-22' as date)) - and wsr_web_site_sk = web_site_sk - group by web_site_id) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || s_store_id as id - , sales - , returns - , (profit - profit_loss) as profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || cp_catalog_page_id as id - , sales - , returns - , (profit - profit_loss) as profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , (profit - profit_loss) as profit - from wsr - ) x - group by channel, id) - select channel, id, sales, returns, profit from ( - select channel, id, sales, returns, profit from results - union - select channel, null as id, sum(sales), sum(returns), sum(profit) from results group by channel - union - select null as channel, null as id, sum(sales), sum(returns), sum(profit) from results) foo -order by channel, id -limit 100; - --- end template query5a.tpl query 8 in stream 9 --- start template query84.tpl query 9 in stream 9 -select /* TPC-DS query84.tpl 0.80 */ c_customer_id as customer_id - , coalesce(c_last_name,'') || ', ' || coalesce(c_first_name,'') as customername - from customer - ,customer_address - ,customer_demographics - ,household_demographics - ,income_band - ,store_returns - where ca_city = 'Bridgeport' - and c_current_addr_sk = ca_address_sk - and ib_lower_bound >= 24624 - and ib_upper_bound <= 24624 + 50000 - and ib_income_band_sk = hd_income_band_sk - and cd_demo_sk = c_current_cdemo_sk - and hd_demo_sk = c_current_hdemo_sk - and sr_cdemo_sk = cd_demo_sk - order by c_customer_id - limit 100; - --- end template query84.tpl query 9 in stream 9 --- start template query1.tpl query 10 in stream 9 -with /* TPC-DS query1.tpl 0.12 */ customer_total_return as -(select sr_customer_sk as ctr_customer_sk -,sr_store_sk as ctr_store_sk -,sum(SR_FEE) as ctr_total_return -from store_returns -,date_dim -where sr_returned_date_sk = d_date_sk -and d_year =1999 -group by sr_customer_sk -,sr_store_sk) - select c_customer_id -from customer_total_return ctr1 -,store -,customer -where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 -from customer_total_return ctr2 -where ctr1.ctr_store_sk = ctr2.ctr_store_sk) -and s_store_sk = ctr1.ctr_store_sk -and s_state = 'AL' -and ctr1.ctr_customer_sk = c_customer_sk -order by c_customer_id -limit 100; - --- end template query1.tpl query 10 in stream 9 --- start template query52.tpl query 11 in stream 9 -select /* TPC-DS query52.tpl 0.59 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_sales_price) ext_price - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=12 - and dt.d_year=2001 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,ext_price desc - ,brand_id -limit 100 ; - --- end template query52.tpl query 11 in stream 9 --- start template query57.tpl query 12 in stream 9 -with /* TPC-DS query57.tpl 0.70 */ v1 as( - select i_category, i_brand, - cc_name, - d_year, d_moy, - sum(cs_sales_price) sum_sales, - avg(sum(cs_sales_price)) over - (partition by i_category, i_brand, - cc_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - cc_name - order by d_year, d_moy) rn - from item, catalog_sales, date_dim, call_center - where cs_item_sk = i_item_sk and - cs_sold_date_sk = d_date_sk and - cc_call_center_sk= cs_call_center_sk and - ( - d_year = 2001 or - ( d_year = 2001-1 and d_moy =12) or - ( d_year = 2001+1 and d_moy =1) - ) - group by i_category, i_brand, - cc_name , d_year, d_moy), - v2 as( - select v1.cc_name - ,v1.d_year - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1. cc_name = v1_lag. cc_name and - v1. cc_name = v1_lead. cc_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 2001 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, sum_sales - limit 100; - --- end template query57.tpl query 12 in stream 9 --- start template query13.tpl query 13 in stream 9 -select /* TPC-DS query13.tpl 0.91 */ avg(ss_quantity) - ,avg(ss_ext_sales_price) - ,avg(ss_ext_wholesale_cost) - ,sum(ss_ext_wholesale_cost) - from store_sales - ,store - ,customer_demographics - ,household_demographics - ,customer_address - ,date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2001 - and((ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'W' - and cd_education_status = 'College' - and ss_sales_price between 100.00 and 150.00 - and hd_dep_count = 3 - )or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'M' - and cd_education_status = '4 yr Degree' - and ss_sales_price between 50.00 and 100.00 - and hd_dep_count = 1 - ) or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'S' - and cd_education_status = 'Advanced Degree' - and ss_sales_price between 150.00 and 200.00 - and hd_dep_count = 1 - )) - and((ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('MI', 'IA', 'VT') - and ss_net_profit between 100 and 200 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('KY', 'OH', 'NE') - and ss_net_profit between 150 and 300 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('SC', 'OR', 'MO') - and ss_net_profit between 50 and 250 - )) -; - --- end template query13.tpl query 13 in stream 9 --- start template query14a.tpl query 14 in stream 9 -with /* TPC-DS query14a.tpl 0.69 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1998 AND 1998 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1998 AND 1998 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1998 AND 1998 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as - (select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2) x) -, - results AS -(select channel, i_brand_id, i_class_id, i_category_id, sum(sales) sum_sales, sum(number_sales) number_sales - from ( - select 'store' channel, i_brand_id,i_class_id - ,i_category_id,sum(ss_quantity*ss_list_price) sales - , count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1998+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales) - union all - select 'catalog' channel, i_brand_id,i_class_id,i_category_id, sum(cs_quantity*cs_list_price) sales, count(*) number_sales - from catalog_sales - ,item - ,date_dim - where cs_item_sk in (select ss_item_sk from cross_items) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1998+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(cs_quantity*cs_list_price) > (select average_sales from avg_sales) - union all - select 'web' channel, i_brand_id,i_class_id,i_category_id, sum(ws_quantity*ws_list_price) sales , count(*) number_sales - from web_sales - ,item - ,date_dim - where ws_item_sk in (select ss_item_sk from cross_items) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1998+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ws_quantity*ws_list_price) > (select average_sales from avg_sales) - ) y - group by channel, i_brand_id,i_class_id,i_category_id) - - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales -from ( - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales from results - union - select channel, i_brand_id, i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id, i_class_id - union - select channel, i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id - union - select channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel - union - select null as channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results) z -order by channel, i_brand_id, i_class_id, i_category_id - limit 100; -with /* TPC-DS query14a.tpl 0.69 part2 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1998 AND 1998 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1998 AND 1998 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1998 AND 1998 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as -(select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2) x) - select this_year.channel ty_channel - ,this_year.i_brand_id ty_brand - ,this_year.i_class_id ty_class - ,this_year.i_category_id ty_category - ,this_year.sales ty_sales - ,this_year.number_sales ty_number_sales - ,last_year.channel ly_channel - ,last_year.i_brand_id ly_brand - ,last_year.i_class_id ly_class - ,last_year.i_category_id ly_category - ,last_year.sales ly_sales - ,last_year.number_sales ly_number_sales -from - (select 'store' channel, i_brand_id,i_class_id,i_category_id - ,sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1998 + 1 - and d_moy = 12 - and d_dom = 16) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) this_year, - (select 'store' channel, i_brand_id,i_class_id - ,i_category_id, sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1998 - and d_moy = 12 - and d_dom = 16) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) last_year - where this_year.i_brand_id= last_year.i_brand_id - and this_year.i_class_id = last_year.i_class_id - and this_year.i_category_id = last_year.i_category_id - order by this_year.channel, this_year.i_brand_id, this_year.i_class_id, this_year.i_category_id - limit 100; - --- end template query14a.tpl query 14 in stream 9 --- start template query90.tpl query 15 in stream 9 -select /* TPC-DS query90.tpl 0.40 */ cast(amc as decimal(15,4))/cast(pmc as decimal(15,4)) am_pm_ratio - from ( select count(*) amc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 7 and 7+1 - and household_demographics.hd_dep_count = 6 - and web_page.wp_char_count between 5000 and 5200) at, - ( select count(*) pmc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 16 and 16+1 - and household_demographics.hd_dep_count = 6 - and web_page.wp_char_count between 5000 and 5200) pt - order by am_pm_ratio - limit 100; - --- end template query90.tpl query 15 in stream 9 --- start template query7.tpl query 16 in stream 9 -select /* TPC-DS query7.tpl 0.2 */ i_item_id, - avg(ss_quantity) agg1, - avg(ss_list_price) agg2, - avg(ss_coupon_amt) agg3, - avg(ss_sales_price) agg4 - from store_sales, customer_demographics, date_dim, item, promotion - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_cdemo_sk = cd_demo_sk and - ss_promo_sk = p_promo_sk and - cd_gender = 'M' and - cd_marital_status = 'S' and - cd_education_status = 'Secondary' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 2001 - group by i_item_id - order by i_item_id - limit 100; - --- end template query7.tpl query 16 in stream 9 --- start template query27a.tpl query 17 in stream 9 -with /* TPC-DS query27a.tpl 0.16 */ results as - (select i_item_id, - s_state, 0 as g_state, - ss_quantity agg1, - ss_list_price agg2, - ss_coupon_amt agg3, - ss_sales_price agg4 - from store_sales, customer_demographics, date_dim, store, item - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_store_sk = s_store_sk and - ss_cdemo_sk = cd_demo_sk and - cd_gender = 'M' and - cd_marital_status = 'W' and - cd_education_status = 'College' and - d_year = 2000 and - s_state in ('NY','WA', 'MI', 'TN', 'NM', 'LA') - ) - - select i_item_id, - s_state, g_state, agg1, agg2, agg3, agg4 - from ( - select i_item_id, s_state, 0 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4 from results - group by i_item_id, s_state - union all - select i_item_id, NULL AS s_state, 1 AS g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as s_state, 1 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - ) foo - order by i_item_id, s_state - limit 100; - --- end template query27a.tpl query 17 in stream 9 --- start template query92.tpl query 18 in stream 9 -select /* TPC-DS query92.tpl 0.44 */ - sum(ws_ext_discount_amt) as "Excess Discount Amount" -from - web_sales - ,item - ,date_dim -where -i_manufact_id = 892 -and i_item_sk = ws_item_sk -and d_date between '1999-03-20' and - dateadd(day,90,cast('1999-03-20' as date)) -and d_date_sk = ws_sold_date_sk -and ws_ext_discount_amt - > ( - SELECT - 1.3 * avg(ws_ext_discount_amt) - FROM - web_sales - ,date_dim - WHERE - ws_item_sk = i_item_sk - and d_date between '1999-03-20' and - dateadd(day,90,cast('1999-03-20' as date)) - and d_date_sk = ws_sold_date_sk - ) -order by sum(ws_ext_discount_amt) -limit 100; - --- end template query92.tpl query 18 in stream 9 --- start template query39.tpl query 19 in stream 9 -with /* TPC-DS query39.tpl 0.5 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =1998 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=3 - and inv2.d_moy=3+1 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; -with /* TPC-DS query39.tpl 0.5 part2 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =1998 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=3 - and inv2.d_moy=3+1 - and inv1.cov > 1.5 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; - --- end template query39.tpl query 19 in stream 9 --- start template query34.tpl query 20 in stream 9 -select /* TPC-DS query34.tpl 0.73 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (date_dim.d_dom between 1 and 3 or date_dim.d_dom between 25 and 28) - and (household_demographics.hd_buy_potential = '501-1000' or - household_demographics.hd_buy_potential = 'Unknown') - and household_demographics.hd_vehicle_count > 0 - and (case when household_demographics.hd_vehicle_count > 0 - then household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count - else null - end) > 1.2 - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_county in ('Terry County','Franklin Parish','Fairfield County','Kittitas County', - 'Gage County','Harmon County','Sumner County','Raleigh County') - group by ss_ticket_number,ss_customer_sk) dn,customer - where ss_customer_sk = c_customer_sk - and cnt between 15 and 20 - order by c_last_name,c_first_name,c_salutation,c_preferred_cust_flag desc, ss_ticket_number; - --- end template query34.tpl query 20 in stream 9 --- start template query21.tpl query 21 in stream 9 -select /* TPC-DS query21.tpl 0.14 */ * - from(select w_warehouse_name - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('1998-03-15' as date)) - then inv_quantity_on_hand - else 0 end) as inv_before - ,sum(case when (cast(d_date as date) >= cast ('1998-03-15' as date)) - then inv_quantity_on_hand - else 0 end) as inv_after - from inventory - ,warehouse - ,item - ,date_dim - where i_current_price between 0.99 and 1.49 - and i_item_sk = inv_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('1998-03-15' as date)) - and dateadd(day,30,cast ('1998-03-15' as date)) - group by w_warehouse_name, i_item_id) x - where (case when inv_before > 0 - then inv_after / inv_before - else null - end) between 2.0/3.0 and 3.0/2.0 - order by w_warehouse_name - ,i_item_id - limit 100; - --- end template query21.tpl query 21 in stream 9 --- start template query65.tpl query 22 in stream 9 -select /* TPC-DS query65.tpl 0.71 */ - s_store_name, - i_item_desc, - sc.revenue, - i_current_price, - i_wholesale_cost, - i_brand - from store, item, - (select ss_store_sk, avg(revenue) as ave - from - (select ss_store_sk, ss_item_sk, - sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1196 and 1196+11 - group by ss_store_sk, ss_item_sk) sa - group by ss_store_sk) sb, - (select ss_store_sk, ss_item_sk, sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1196 and 1196+11 - group by ss_store_sk, ss_item_sk) sc - where sb.ss_store_sk = sc.ss_store_sk and - sc.revenue <= 0.1 * sb.ave and - s_store_sk = sc.ss_store_sk and - i_item_sk = sc.ss_item_sk - order by s_store_name, i_item_desc -limit 100; - --- end template query65.tpl query 22 in stream 9 --- start template query75.tpl query 23 in stream 9 -WITH /* TPC-DS query75.tpl 0.3 */ all_sales AS ( - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,SUM(sales_cnt) AS sales_cnt - ,SUM(sales_amt) AS sales_amt - FROM (SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,cs_quantity - COALESCE(cr_return_quantity,0) AS sales_cnt - ,cs_ext_sales_price - COALESCE(cr_return_amount,0.0) AS sales_amt - FROM catalog_sales JOIN item ON i_item_sk=cs_item_sk - JOIN date_dim ON d_date_sk=cs_sold_date_sk - LEFT JOIN catalog_returns ON (cs_order_number=cr_order_number - AND cs_item_sk=cr_item_sk) - WHERE i_category='Men' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ss_quantity - COALESCE(sr_return_quantity,0) AS sales_cnt - ,ss_ext_sales_price - COALESCE(sr_return_amt,0.0) AS sales_amt - FROM store_sales JOIN item ON i_item_sk=ss_item_sk - JOIN date_dim ON d_date_sk=ss_sold_date_sk - LEFT JOIN store_returns ON (ss_ticket_number=sr_ticket_number - AND ss_item_sk=sr_item_sk) - WHERE i_category='Men' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ws_quantity - COALESCE(wr_return_quantity,0) AS sales_cnt - ,ws_ext_sales_price - COALESCE(wr_return_amt,0.0) AS sales_amt - FROM web_sales JOIN item ON i_item_sk=ws_item_sk - JOIN date_dim ON d_date_sk=ws_sold_date_sk - LEFT JOIN web_returns ON (ws_order_number=wr_order_number - AND ws_item_sk=wr_item_sk) - WHERE i_category='Men') sales_detail - GROUP BY d_year, i_brand_id, i_class_id, i_category_id, i_manufact_id) - SELECT prev_yr.d_year AS prev_year - ,curr_yr.d_year AS year - ,curr_yr.i_brand_id - ,curr_yr.i_class_id - ,curr_yr.i_category_id - ,curr_yr.i_manufact_id - ,prev_yr.sales_cnt AS prev_yr_cnt - ,curr_yr.sales_cnt AS curr_yr_cnt - ,curr_yr.sales_cnt-prev_yr.sales_cnt AS sales_cnt_diff - ,curr_yr.sales_amt-prev_yr.sales_amt AS sales_amt_diff - FROM all_sales curr_yr, all_sales prev_yr - WHERE curr_yr.i_brand_id=prev_yr.i_brand_id - AND curr_yr.i_class_id=prev_yr.i_class_id - AND curr_yr.i_category_id=prev_yr.i_category_id - AND curr_yr.i_manufact_id=prev_yr.i_manufact_id - AND curr_yr.d_year=1999 - AND prev_yr.d_year=1999-1 - AND CAST(curr_yr.sales_cnt AS DECIMAL(17,2))/CAST(prev_yr.sales_cnt AS DECIMAL(17,2))<0.9 - ORDER BY sales_cnt_diff,sales_amt_diff - limit 100; - --- end template query75.tpl query 23 in stream 9 --- start template query9.tpl query 24 in stream 9 -select /* TPC-DS query9.tpl 0.49 */ case when (select count(*) - from store_sales - where ss_quantity between 1 and 20) > 75780808 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 1 and 20) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 1 and 20) end bucket1 , - case when (select count(*) - from store_sales - where ss_quantity between 21 and 40) > 131643214 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 21 and 40) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 21 and 40) end bucket2, - case when (select count(*) - from store_sales - where ss_quantity between 41 and 60) > 116201008 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 41 and 60) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 41 and 60) end bucket3, - case when (select count(*) - from store_sales - where ss_quantity between 61 and 80) > 84450646 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 61 and 80) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 61 and 80) end bucket4, - case when (select count(*) - from store_sales - where ss_quantity between 81 and 100) > 62714526 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 81 and 100) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 81 and 100) end bucket5 -from reason -where r_reason_sk = 1 -; - --- end template query9.tpl query 24 in stream 9 --- start template query2.tpl query 25 in stream 9 -with /* TPC-DS query2.tpl 0.84 */ wscs as - (select sold_date_sk - ,sales_price - from (select ws_sold_date_sk sold_date_sk - ,ws_ext_sales_price sales_price - from web_sales - union all - select cs_sold_date_sk sold_date_sk - ,cs_ext_sales_price sales_price - from catalog_sales)), - wswscs as - (select d_week_seq, - sum(case when (d_day_name='Sunday') then sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then sales_price else null end) sat_sales - from wscs - ,date_dim - where d_date_sk = sold_date_sk - group by d_week_seq) - select d_week_seq1 - ,round(sun_sales1/sun_sales2,2) - ,round(mon_sales1/mon_sales2,2) - ,round(tue_sales1/tue_sales2,2) - ,round(wed_sales1/wed_sales2,2) - ,round(thu_sales1/thu_sales2,2) - ,round(fri_sales1/fri_sales2,2) - ,round(sat_sales1/sat_sales2,2) - from - (select wswscs.d_week_seq d_week_seq1 - ,sun_sales sun_sales1 - ,mon_sales mon_sales1 - ,tue_sales tue_sales1 - ,wed_sales wed_sales1 - ,thu_sales thu_sales1 - ,fri_sales fri_sales1 - ,sat_sales sat_sales1 - from wswscs,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 1999) y, - (select wswscs.d_week_seq d_week_seq2 - ,sun_sales sun_sales2 - ,mon_sales mon_sales2 - ,tue_sales tue_sales2 - ,wed_sales wed_sales2 - ,thu_sales thu_sales2 - ,fri_sales fri_sales2 - ,sat_sales sat_sales2 - from wswscs - ,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 1999+1) z - where d_week_seq1=d_week_seq2-53 - order by d_week_seq1; - --- end template query2.tpl query 25 in stream 9 --- start template query12.tpl query 26 in stream 9 -select /* TPC-DS query12.tpl 0.64 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ws_ext_sales_price) as itemrevenue - ,sum(ws_ext_sales_price)*100/sum(sum(ws_ext_sales_price)) over - (partition by i_class) as revenueratio -from - web_sales - ,item - ,date_dim -where - ws_item_sk = i_item_sk - and i_category in ('Music', 'Children', 'Men') - and ws_sold_date_sk = d_date_sk - and d_date between cast('2001-03-27' as date) - and dateadd(day,30,cast('2001-03-27' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query12.tpl query 26 in stream 9 --- start template query32.tpl query 27 in stream 9 -select /* TPC-DS query32.tpl 0.7 */ sum(cs_ext_discount_amt) as "excess discount amount" -from - catalog_sales - ,item - ,date_dim -where -i_manufact_id = 523 -and i_item_sk = cs_item_sk -and d_date between '2000-03-20' and - dateadd(day,90,cast('2000-03-20' as date)) -and d_date_sk = cs_sold_date_sk -and cs_ext_discount_amt - > ( - select - 1.3 * avg(cs_ext_discount_amt) - from - catalog_sales - ,date_dim - where - cs_item_sk = i_item_sk - and d_date between '2000-03-20' and - dateadd(day,90,cast('2000-03-20' as date)) - and d_date_sk = cs_sold_date_sk - ) -limit 100; - --- end template query32.tpl query 27 in stream 9 --- start template query28.tpl query 28 in stream 9 -select /* TPC-DS query28.tpl 0.36 */ * -from (select avg(ss_list_price) B1_LP - ,count(ss_list_price) B1_CNT - ,count(distinct ss_list_price) B1_CNTD - from store_sales - where ss_quantity between 0 and 5 - and (ss_list_price between 64 and 64+10 - or ss_coupon_amt between 14078 and 14078+1000 - or ss_wholesale_cost between 52 and 52+20)) B1, - (select avg(ss_list_price) B2_LP - ,count(ss_list_price) B2_CNT - ,count(distinct ss_list_price) B2_CNTD - from store_sales - where ss_quantity between 6 and 10 - and (ss_list_price between 37 and 37+10 - or ss_coupon_amt between 10126 and 10126+1000 - or ss_wholesale_cost between 22 and 22+20)) B2, - (select avg(ss_list_price) B3_LP - ,count(ss_list_price) B3_CNT - ,count(distinct ss_list_price) B3_CNTD - from store_sales - where ss_quantity between 11 and 15 - and (ss_list_price between 179 and 179+10 - or ss_coupon_amt between 10159 and 10159+1000 - or ss_wholesale_cost between 0 and 0+20)) B3, - (select avg(ss_list_price) B4_LP - ,count(ss_list_price) B4_CNT - ,count(distinct ss_list_price) B4_CNTD - from store_sales - where ss_quantity between 16 and 20 - and (ss_list_price between 67 and 67+10 - or ss_coupon_amt between 9737 and 9737+1000 - or ss_wholesale_cost between 60 and 60+20)) B4, - (select avg(ss_list_price) B5_LP - ,count(ss_list_price) B5_CNT - ,count(distinct ss_list_price) B5_CNTD - from store_sales - where ss_quantity between 21 and 25 - and (ss_list_price between 17 and 17+10 - or ss_coupon_amt between 10238 and 10238+1000 - or ss_wholesale_cost between 77 and 77+20)) B5, - (select avg(ss_list_price) B6_LP - ,count(ss_list_price) B6_CNT - ,count(distinct ss_list_price) B6_CNTD - from store_sales - where ss_quantity between 26 and 30 - and (ss_list_price between 155 and 155+10 - or ss_coupon_amt between 6021 and 6021+1000 - or ss_wholesale_cost between 30 and 30+20)) B6 -limit 100; - --- end template query28.tpl query 28 in stream 9 --- start template query42.tpl query 29 in stream 9 -select /* TPC-DS query42.tpl 0.61 */ dt.d_year - ,item.i_category_id - ,item.i_category - ,sum(ss_ext_sales_price) - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=11 - and dt.d_year=1998 - group by dt.d_year - ,item.i_category_id - ,item.i_category - order by sum(ss_ext_sales_price) desc,dt.d_year - ,item.i_category_id - ,item.i_category -limit 100 ; - --- end template query42.tpl query 29 in stream 9 --- start template query17.tpl query 30 in stream 9 -select /* TPC-DS query17.tpl 0.41 */ i_item_id - ,i_item_desc - ,s_state - ,count(ss_quantity) as store_sales_quantitycount - ,avg(ss_quantity) as store_sales_quantityave - ,stddev_samp(ss_quantity) as store_sales_quantitystdev - ,stddev_samp(ss_quantity)/avg(ss_quantity) as store_sales_quantitycov - ,count(sr_return_quantity) as store_returns_quantitycount - ,avg(sr_return_quantity) as store_returns_quantityave - ,stddev_samp(sr_return_quantity) as store_returns_quantitystdev - ,stddev_samp(sr_return_quantity)/avg(sr_return_quantity) as store_returns_quantitycov - ,count(cs_quantity) as catalog_sales_quantitycount ,avg(cs_quantity) as catalog_sales_quantityave - ,stddev_samp(cs_quantity) as catalog_sales_quantitystdev - ,stddev_samp(cs_quantity)/avg(cs_quantity) as catalog_sales_quantitycov - from store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where d1.d_quarter_name = '2000Q1' - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_quarter_name in ('2000Q1','2000Q2','2000Q3') - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_quarter_name in ('2000Q1','2000Q2','2000Q3') - group by i_item_id - ,i_item_desc - ,s_state - order by i_item_id - ,i_item_desc - ,s_state -limit 100; - --- end template query17.tpl query 30 in stream 9 --- start template query67a.tpl query 31 in stream 9 -with /* TPC-DS query67a.tpl 0.35 */ results as -( select i_category ,i_class ,i_brand ,i_product_name ,d_year ,d_qoy ,d_moy ,s_store_id - ,sum(coalesce(ss_sales_price*ss_quantity,0)) sumsales - from store_sales ,date_dim ,store ,item - where ss_sold_date_sk=d_date_sk - and ss_item_sk=i_item_sk - and ss_store_sk = s_store_sk - and d_month_seq between 1180 and 1180 + 11 - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy,s_store_id) - , - results_rollup as - (select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, s_store_id, sumsales - from results - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy - union all - select i_category, i_class, i_brand, i_product_name, d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year - union all - select i_category, i_class, i_brand, i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name - union all - select i_category, i_class, i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand - union all - select i_category, i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class - union all - select i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category - union all - select null i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results) - - select * -from (select i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rank() over (partition by i_category order by sumsales desc) rk - from results_rollup) dw2 -where rk <= 100 -order by i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rk -limit 100; - --- end template query67a.tpl query 31 in stream 9 --- start template query31.tpl query 32 in stream 9 -with /* TPC-DS query31.tpl 0.50 */ ss as - (select ca_county,d_qoy, d_year,sum(ss_ext_sales_price) as store_sales - from store_sales,date_dim,customer_address - where ss_sold_date_sk = d_date_sk - and ss_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year), - ws as - (select ca_county,d_qoy, d_year,sum(ws_ext_sales_price) as web_sales - from web_sales,date_dim,customer_address - where ws_sold_date_sk = d_date_sk - and ws_bill_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year) - select - ss1.ca_county - ,ss1.d_year - ,ws2.web_sales/ws1.web_sales web_q1_q2_increase - ,ss2.store_sales/ss1.store_sales store_q1_q2_increase - ,ws3.web_sales/ws2.web_sales web_q2_q3_increase - ,ss3.store_sales/ss2.store_sales store_q2_q3_increase - from - ss ss1 - ,ss ss2 - ,ss ss3 - ,ws ws1 - ,ws ws2 - ,ws ws3 - where - ss1.d_qoy = 1 - and ss1.d_year = 2002 - and ss1.ca_county = ss2.ca_county - and ss2.d_qoy = 2 - and ss2.d_year = 2002 - and ss2.ca_county = ss3.ca_county - and ss3.d_qoy = 3 - and ss3.d_year = 2002 - and ss1.ca_county = ws1.ca_county - and ws1.d_qoy = 1 - and ws1.d_year = 2002 - and ws1.ca_county = ws2.ca_county - and ws2.d_qoy = 2 - and ws2.d_year = 2002 - and ws1.ca_county = ws3.ca_county - and ws3.d_qoy = 3 - and ws3.d_year =2002 - and case when ws1.web_sales > 0 then ws2.web_sales/ws1.web_sales else null end - > case when ss1.store_sales > 0 then ss2.store_sales/ss1.store_sales else null end - and case when ws2.web_sales > 0 then ws3.web_sales/ws2.web_sales else null end - > case when ss2.store_sales > 0 then ss3.store_sales/ss2.store_sales else null end - order by ss1.d_year; - --- end template query31.tpl query 32 in stream 9 --- start template query20.tpl query 33 in stream 9 -select /* TPC-DS query20.tpl 0.65 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(cs_ext_sales_price) as itemrevenue - ,sum(cs_ext_sales_price)*100/sum(sum(cs_ext_sales_price)) over - (partition by i_class) as revenueratio - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and i_category in ('Jewelry', 'Music', 'Electronics') - and cs_sold_date_sk = d_date_sk - and d_date between cast('1999-05-31' as date) - and dateadd(day,30,cast('1999-05-31' as date)) - group by i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - order by i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query20.tpl query 33 in stream 9 --- start template query11.tpl query 34 in stream 9 -with /* TPC-DS query11.tpl 0.51 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ss_ext_list_price-ss_ext_discount_amt) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ws_ext_list_price-ws_ext_discount_amt) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_email_address - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 1999 - and t_s_secyear.dyear = 1999+1 - and t_w_firstyear.dyear = 1999 - and t_w_secyear.dyear = 1999+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else 0.0 end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else 0.0 end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_email_address -limit 100; - --- end template query11.tpl query 34 in stream 9 --- start template query77a.tpl query 35 in stream 9 -with /* TPC-DS query77a.tpl 0.78 */ ss as - (select s_store_sk, - sum(ss_ext_sales_price) as sales, - sum(ss_net_profit) as profit - from store_sales, - date_dim, - store - where ss_sold_date_sk = d_date_sk - and d_date between cast('2001-08-19' as date) - and dateadd(day,30,cast('2001-08-19' as date)) - and ss_store_sk = s_store_sk - group by s_store_sk) - , - sr as - (select s_store_sk, - sum(sr_return_amt) as returns, - sum(sr_net_loss) as profit_loss - from store_returns, - date_dim, - store - where sr_returned_date_sk = d_date_sk - and d_date between cast('2001-08-19' as date) - and dateadd(day,30,cast('2001-08-19' as date)) - and sr_store_sk = s_store_sk - group by s_store_sk), - cs as - (select cs_call_center_sk, - sum(cs_ext_sales_price) as sales, - sum(cs_net_profit) as profit - from catalog_sales, - date_dim - where cs_sold_date_sk = d_date_sk - and d_date between cast('2001-08-19' as date) - and dateadd(day,30,cast('2001-08-19' as date)) - group by cs_call_center_sk - ), - cr as - (select cr_call_center_sk, - sum(cr_return_amount) as returns, - sum(cr_net_loss) as profit_loss - from catalog_returns, - date_dim - where cr_returned_date_sk = d_date_sk - and d_date between cast('2001-08-19' as date) - and dateadd(day,30,cast('2001-08-19' as date)) - group by cr_call_center_sk), - ws as - ( select wp_web_page_sk, - sum(ws_ext_sales_price) as sales, - sum(ws_net_profit) as profit - from web_sales, - date_dim, - web_page - where ws_sold_date_sk = d_date_sk - and d_date between cast('2001-08-19' as date) - and dateadd(day,30,cast('2001-08-19' as date)) - and ws_web_page_sk = wp_web_page_sk - group by wp_web_page_sk), - wr as - (select wp_web_page_sk, - sum(wr_return_amt) as returns, - sum(wr_net_loss) as profit_loss - from web_returns, - date_dim, - web_page - where wr_returned_date_sk = d_date_sk - and d_date between cast('2001-08-19' as date) - and dateadd(day,30,cast('2001-08-19' as date)) - and wr_web_page_sk = wp_web_page_sk - group by wp_web_page_sk) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , ss.s_store_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ss left join sr - on ss.s_store_sk = sr.s_store_sk - union all - select 'catalog channel' as channel - , cs_call_center_sk as id - , sales - , returns - , (profit - profit_loss) as profit - from cs - , cr - union all - select 'web channel' as channel - , ws.wp_web_page_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ws left join wr - on ws.wp_web_page_sk = wr.wp_web_page_sk - ) x - group by channel, id ) - - select * - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results -) foo -order by channel, id - limit 100; - --- end template query77a.tpl query 35 in stream 9 --- start template query36a.tpl query 36 in stream 9 -with /* TPC-DS query36a.tpl 0.21 */ results as - (select - sum(ss_net_profit) as ss_net_profit, sum(ss_ext_sales_price) as ss_ext_sales_price, - sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin - ,i_category - ,i_class - ,0 as g_category, 0 as g_class - from - store_sales - ,date_dim d1 - ,item - ,store - where - d1.d_year = 1998 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and s_state in ('AL','MN','SC','GA', - 'MO','LA','MI','AL') - group by i_category,i_class) - , - results_rollup as - (select gross_margin ,i_category ,i_class,0 as t_category, 0 as t_class, 0 as lochierarchy from results - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - i_category, NULL AS i_class, 0 as t_category, 1 as t_class, 1 as lochierarchy from results group by i_category - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - NULL AS i_category ,NULL AS i_class, 1 as t_category, 1 as t_class, 2 as lochierarchy from results) - select - gross_margin ,i_category ,i_class, lochierarchy,rank() over ( - partition by lochierarchy, case when t_class = 0 then i_category end - order by gross_margin asc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then i_category end - ,rank_within_parent - limit 100; - --- end template query36a.tpl query 36 in stream 9 --- start template query82.tpl query 37 in stream 9 -select /* TPC-DS query82.tpl 0.67 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, store_sales - where i_current_price between 56 and 56+30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('1998-07-04' as date) and dateadd(day,60,cast('1998-07-04' as date)) - and i_manufact_id in (689,650,803,591) - and inv_quantity_on_hand between 100 and 500 - and ss_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query82.tpl query 37 in stream 9 --- start template query33.tpl query 38 in stream 9 -with /* TPC-DS query33.tpl 0.22 */ ss as ( - select - i_manufact_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Jewelry')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 4 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id), - cs as ( - select - i_manufact_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Jewelry')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 4 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id), - ws as ( - select - i_manufact_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Jewelry')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 4 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id) - select i_manufact_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_manufact_id - order by total_sales -limit 100; - --- end template query33.tpl query 38 in stream 9 --- start template query54.tpl query 39 in stream 9 -with /* TPC-DS query54.tpl 0.81 */ my_customers as ( - select distinct c_customer_sk - , c_current_addr_sk - from - ( select cs_sold_date_sk sold_date_sk, - cs_bill_customer_sk customer_sk, - cs_item_sk item_sk - from catalog_sales - union all - select ws_sold_date_sk sold_date_sk, - ws_bill_customer_sk customer_sk, - ws_item_sk item_sk - from web_sales - ) cs_or_ws_sales, - item, - date_dim, - customer - where sold_date_sk = d_date_sk - and item_sk = i_item_sk - and i_category = 'Home' - and i_class = 'mattresses' - and c_customer_sk = cs_or_ws_sales.customer_sk - and d_moy = 1 - and d_year = 2002 - ) - , my_revenue as ( - select c_customer_sk, - sum(ss_ext_sales_price) as revenue - from my_customers, - store_sales, - customer_address, - store, - date_dim - where c_current_addr_sk = ca_address_sk - and ca_county = s_county - and ca_state = s_state - and ss_sold_date_sk = d_date_sk - and c_customer_sk = ss_customer_sk - and d_month_seq between (select distinct d_month_seq+1 - from date_dim where d_year = 2002 and d_moy = 1) - and (select distinct d_month_seq+3 - from date_dim where d_year = 2002 and d_moy = 1) - group by c_customer_sk - ) - , segments as - (select cast((revenue/50) as int) as segment - from my_revenue - ) - select segment, count(*) as num_customers, segment*50 as segment_base - from segments - group by segment - order by segment, num_customers - limit 100; - --- end template query54.tpl query 39 in stream 9 --- start template query4.tpl query 40 in stream 9 -with /* TPC-DS query4.tpl 0.93 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(((ss_ext_list_price-ss_ext_wholesale_cost-ss_ext_discount_amt)+ss_ext_sales_price)/2) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((cs_ext_list_price-cs_ext_wholesale_cost-cs_ext_discount_amt)+cs_ext_sales_price)/2) ) year_total - ,'c' sale_type - from customer - ,catalog_sales - ,date_dim - where c_customer_sk = cs_bill_customer_sk - and cs_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year -union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((ws_ext_list_price-ws_ext_wholesale_cost-ws_ext_discount_amt)+ws_ext_sales_price)/2) ) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_preferred_cust_flag - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_c_firstyear - ,year_total t_c_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_c_secyear.customer_id - and t_s_firstyear.customer_id = t_c_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_c_firstyear.sale_type = 'c' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_c_secyear.sale_type = 'c' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 1998 - and t_s_secyear.dyear = 1998+1 - and t_c_firstyear.dyear = 1998 - and t_c_secyear.dyear = 1998+1 - and t_w_firstyear.dyear = 1998 - and t_w_secyear.dyear = 1998+1 - and t_s_firstyear.year_total > 0 - and t_c_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_preferred_cust_flag -limit 100; - --- end template query4.tpl query 40 in stream 9 --- start template query16.tpl query 41 in stream 9 -select /* TPC-DS query16.tpl 0.25 */ - count(distinct cs_order_number) as "order count" - ,sum(cs_ext_ship_cost) as "total shipping cost" - ,sum(cs_net_profit) as "total net profit" -from - catalog_sales cs1 - ,date_dim - ,customer_address - ,call_center -where - d_date between '2002-4-01' and - dateadd(day, 60, cast('2002-4-01' as date)) -and cs1.cs_ship_date_sk = d_date_sk -and cs1.cs_ship_addr_sk = ca_address_sk -and ca_state = 'CA' -and cs1.cs_call_center_sk = cc_call_center_sk -and cc_county in ('Pennington County','Levy County','Richland County','Walker County', - 'Mesa County' -) -and exists (select * - from catalog_sales cs2 - where cs1.cs_order_number = cs2.cs_order_number - and cs1.cs_warehouse_sk <> cs2.cs_warehouse_sk) -and not exists(select * - from catalog_returns cr1 - where cs1.cs_order_number = cr1.cr_order_number) -order by count(distinct cs_order_number) -limit 100; - --- end template query16.tpl query 41 in stream 9 --- start template query10.tpl query 42 in stream 9 -select /* TPC-DS query10.tpl 0.26 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3, - cd_dep_count, - count(*) cnt4, - cd_dep_employed_count, - count(*) cnt5, - cd_dep_college_count, - count(*) cnt6 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_county in ('Webster County','Los Angeles County','Floyd County','Early County','Gray County') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 4 and 4+3) and - (exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 4 ANd 4+3) or - exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 4 and 4+3)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count -limit 100; - --- end template query10.tpl query 42 in stream 9 --- start template query18a.tpl query 43 in stream 9 -with /* TPC-DS query18a.tpl 0.90 */ results as - (select i_item_id, - ca_country, - ca_state, - ca_county, - cast(cs_quantity as decimal(12,2)) agg1, - cast(cs_list_price as decimal(12,2)) agg2, - cast(cs_coupon_amt as decimal(12,2)) agg3, - cast(cs_sales_price as decimal(12,2)) agg4, - cast(cs_net_profit as decimal(12,2)) agg5, - cast(c_birth_year as decimal(12,2)) agg6, - cast(cd1.cd_dep_count as decimal(12,2)) agg7 - from catalog_sales, customer_demographics cd1, customer_demographics cd2, customer, customer_address, date_dim, item - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd1.cd_demo_sk and - cs_bill_customer_sk = c_customer_sk and - cd1.cd_gender = 'M' and - cd1.cd_education_status = 'Primary' and - c_current_cdemo_sk = cd2.cd_demo_sk and - c_current_addr_sk = ca_address_sk and - c_birth_month in (5,3,2,8,12,10) and - d_year = 2002 and - ca_state in ('KS','MS','NJ','IN','OK','TX','UT') - ) - select i_item_id, ca_country, ca_state, ca_county, agg1, agg2, agg3, agg4, agg5, agg6, agg7 - from ( - select i_item_id, ca_country, ca_state, ca_county, avg(agg1) agg1, - avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state, ca_county - union all - select i_item_id, ca_country, ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state - union all - select i_item_id, ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country - union all - select i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - ) foo - order by ca_country, ca_state, ca_county, i_item_id - limit 100; - --- end template query18a.tpl query 43 in stream 9 --- start template query48.tpl query 44 in stream 9 -select /* TPC-DS query48.tpl 0.74 */ sum (ss_quantity) - from store_sales, store, customer_demographics, customer_address, date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2001 - and - ( - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'W' - and - cd_education_status = 'College' - and - ss_sales_price between 100.00 and 150.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'U' - and - cd_education_status = 'Secondary' - and - ss_sales_price between 50.00 and 100.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'S' - and - cd_education_status = '2 yr Degree' - and - ss_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('GA', 'VA', 'TN') - and ss_net_profit between 0 and 2000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('FL', 'CT', 'PA') - and ss_net_profit between 150 and 3000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('MI', 'TX', 'IA') - and ss_net_profit between 50 and 25000 - ) - ) -; - --- end template query48.tpl query 44 in stream 9 --- start template query24.tpl query 45 in stream 9 -with /* TPC-DS query24.tpl 0.92 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_ext_sales_price) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip -and s_market_id=7 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'puff' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; -with /* TPC-DS query24.tpl 0.92 part2 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_ext_sales_price) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip - and s_market_id = 7 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'khaki' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; - --- end template query24.tpl query 45 in stream 9 --- start template query30.tpl query 46 in stream 9 -with /* TPC-DS query30.tpl 0.75 */ customer_total_return as - (select wr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(wr_return_amt) as ctr_total_return - from web_returns - ,date_dim - ,customer_address - where wr_returned_date_sk = d_date_sk - and d_year =2000 - and wr_returning_addr_sk = ca_address_sk - group by wr_returning_customer_sk - ,ca_state) - select c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'CA' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return -limit 100; - --- end template query30.tpl query 46 in stream 9 --- start template query78.tpl query 47 in stream 9 -with /* TPC-DS query78.tpl 0.10 */ ws as - (select d_year AS ws_sold_year, ws_item_sk, - ws_bill_customer_sk ws_customer_sk, - sum(ws_quantity) ws_qty, - sum(ws_wholesale_cost) ws_wc, - sum(ws_sales_price) ws_sp - from web_sales - left join web_returns on wr_order_number=ws_order_number and ws_item_sk=wr_item_sk - join date_dim on ws_sold_date_sk = d_date_sk - where wr_order_number is null - group by d_year, ws_item_sk, ws_bill_customer_sk - ), -cs as - (select d_year AS cs_sold_year, cs_item_sk, - cs_bill_customer_sk cs_customer_sk, - sum(cs_quantity) cs_qty, - sum(cs_wholesale_cost) cs_wc, - sum(cs_sales_price) cs_sp - from catalog_sales - left join catalog_returns on cr_order_number=cs_order_number and cs_item_sk=cr_item_sk - join date_dim on cs_sold_date_sk = d_date_sk - where cr_order_number is null - group by d_year, cs_item_sk, cs_bill_customer_sk - ), -ss as - (select d_year AS ss_sold_year, ss_item_sk, - ss_customer_sk, - sum(ss_quantity) ss_qty, - sum(ss_wholesale_cost) ss_wc, - sum(ss_sales_price) ss_sp - from store_sales - left join store_returns on sr_ticket_number=ss_ticket_number and ss_item_sk=sr_item_sk - join date_dim on ss_sold_date_sk = d_date_sk - where sr_ticket_number is null - group by d_year, ss_item_sk, ss_customer_sk - ) - select -ss_sold_year, -round(ss_qty/(coalesce(ws_qty,0)+coalesce(cs_qty,0)),2) ratio, -ss_qty store_qty, ss_wc store_wholesale_cost, ss_sp store_sales_price, -coalesce(ws_qty,0)+coalesce(cs_qty,0) other_chan_qty, -coalesce(ws_wc,0)+coalesce(cs_wc,0) other_chan_wholesale_cost, -coalesce(ws_sp,0)+coalesce(cs_sp,0) other_chan_sales_price -from ss -left join ws on (ws_sold_year=ss_sold_year and ws_item_sk=ss_item_sk and ws_customer_sk=ss_customer_sk) -left join cs on (cs_sold_year=ss_sold_year and cs_item_sk=ss_item_sk and cs_customer_sk=ss_customer_sk) -where (coalesce(ws_qty,0)>0 or coalesce(cs_qty, 0)>0) and ss_sold_year=2000 -order by - ss_sold_year, - ss_qty desc, ss_wc desc, ss_sp desc, - other_chan_qty, - other_chan_wholesale_cost, - other_chan_sales_price, - ratio -limit 100; - --- end template query78.tpl query 47 in stream 9 --- start template query6.tpl query 48 in stream 9 -select /* TPC-DS query6.tpl 0.58 */ a.ca_state state, count(*) cnt - from customer_address a - ,customer c - ,store_sales s - ,date_dim d - ,item i - where a.ca_address_sk = c.c_current_addr_sk - and c.c_customer_sk = s.ss_customer_sk - and s.ss_sold_date_sk = d.d_date_sk - and s.ss_item_sk = i.i_item_sk - and d.d_month_seq = - (select distinct (d_month_seq) - from date_dim - where d_year = 1998 - and d_moy = 3 ) - and i.i_current_price > 1.2 * - (select avg(j.i_current_price) - from item j - where j.i_category = i.i_category) - group by a.ca_state - having count(*) >= 10 - order by cnt, a.ca_state - limit 100; - --- end template query6.tpl query 48 in stream 9 --- start template query80a.tpl query 49 in stream 9 -with /* TPC-DS query80a.tpl 0.6 */ ssr as - (select s_store_id as store_id, - sum(ss_ext_sales_price) as sales, - sum(coalesce(sr_return_amt, 0)) as returns, - sum(ss_net_profit - coalesce(sr_net_loss, 0)) as profit - from store_sales left outer join store_returns on - (ss_item_sk = sr_item_sk and ss_ticket_number = sr_ticket_number), - date_dim, - store, - item, - promotion - where ss_sold_date_sk = d_date_sk - and d_date between cast('1999-08-29' as date) - and dateadd(day,30,cast('1999-08-29' as date)) - and ss_store_sk = s_store_sk - and ss_item_sk = i_item_sk - and i_current_price > 50 - and ss_promo_sk = p_promo_sk - and p_channel_tv = 'N' - group by s_store_id) - , - csr as - (select cp_catalog_page_id as catalog_page_id, - sum(cs_ext_sales_price) as sales, - sum(coalesce(cr_return_amount, 0)) as returns, - sum(cs_net_profit - coalesce(cr_net_loss, 0)) as profit - from catalog_sales left outer join catalog_returns on - (cs_item_sk = cr_item_sk and cs_order_number = cr_order_number), - date_dim, - catalog_page, - item, - promotion - where cs_sold_date_sk = d_date_sk - and d_date between cast('1999-08-29' as date) - and dateadd(day,30,cast('1999-08-29' as date)) - and cs_catalog_page_sk = cp_catalog_page_sk - and cs_item_sk = i_item_sk - and i_current_price > 50 - and cs_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(ws_ext_sales_price) as sales, - sum(coalesce(wr_return_amt, 0)) as returns, - sum(ws_net_profit - coalesce(wr_net_loss, 0)) as profit - from web_sales left outer join web_returns on - (ws_item_sk = wr_item_sk and ws_order_number = wr_order_number), - date_dim, - web_site, - item, - promotion - where ws_sold_date_sk = d_date_sk - and d_date between cast('1999-08-29' as date) - and dateadd(day,30,cast('1999-08-29' as date)) - and ws_web_site_sk = web_site_sk - and ws_item_sk = i_item_sk - and i_current_price > 50 - and ws_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by web_site_id) -, -results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || store_id as id - , sales - , returns - , profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || catalog_page_id as id - , sales - , returns - , profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , profit - from wsr - ) x - group by channel, id) - - select channel - , id - , sales - , returns - , profit - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results - ) foo - order by channel, id - limit 100; - --- end template query80a.tpl query 49 in stream 9 --- start template query35a.tpl query 50 in stream 9 -select /* TPC-DS query35a.tpl 0.47 */ - ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - count(*) cnt1, - avg(cd_dep_count), - avg(cd_dep_count), - max(cd_dep_count), - cd_dep_employed_count, - count(*) cnt2, - avg(cd_dep_employed_count), - avg(cd_dep_employed_count), - max(cd_dep_employed_count), - cd_dep_college_count, - count(*) cnt3, - avg(cd_dep_college_count), - avg(cd_dep_college_count), - max(cd_dep_college_count) - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2000 and - d_qoy < 4) and - exists (select * from - (select ws_bill_customer_sk customsk - from web_sales,date_dim - where - ws_sold_date_sk = d_date_sk and - d_year = 2000 and - d_qoy < 4 - union all - select cs_ship_customer_sk customsk - from catalog_sales,date_dim - where - cs_sold_date_sk = d_date_sk and - d_year = 2000 and - d_qoy < 4)x - where x.customsk = c.c_customer_sk) - group by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - limit 100; - --- end template query35a.tpl query 50 in stream 9 --- start template query59.tpl query 51 in stream 9 -with /* TPC-DS query59.tpl 0.30 */ wss as - (select d_week_seq, - ss_store_sk, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - group by d_week_seq,ss_store_sk - ) - select s_store_name1,s_store_id1,d_week_seq1 - ,sun_sales1/sun_sales2,mon_sales1/mon_sales2 - ,tue_sales1/tue_sales2,wed_sales1/wed_sales2,thu_sales1/thu_sales2 - ,fri_sales1/fri_sales2,sat_sales1/sat_sales2 - from - (select s_store_name s_store_name1,wss.d_week_seq d_week_seq1 - ,s_store_id s_store_id1,sun_sales sun_sales1 - ,mon_sales mon_sales1,tue_sales tue_sales1 - ,wed_sales wed_sales1,thu_sales thu_sales1 - ,fri_sales fri_sales1,sat_sales sat_sales1 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1201 and 1201 + 11) y, - (select s_store_name s_store_name2,wss.d_week_seq d_week_seq2 - ,s_store_id s_store_id2,sun_sales sun_sales2 - ,mon_sales mon_sales2,tue_sales tue_sales2 - ,wed_sales wed_sales2,thu_sales thu_sales2 - ,fri_sales fri_sales2,sat_sales sat_sales2 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1201+ 12 and 1201 + 23) x - where s_store_id1=s_store_id2 - and d_week_seq1=d_week_seq2-52 - order by s_store_name1,s_store_id1,d_week_seq1 -limit 100; - --- end template query59.tpl query 51 in stream 9 --- start template query99.tpl query 52 in stream 9 -select /* TPC-DS query99.tpl 0.94 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 30) and - (cs_ship_date_sk - cs_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 60) and - (cs_ship_date_sk - cs_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 90) and - (cs_ship_date_sk - cs_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - catalog_sales - ,warehouse - ,ship_mode - ,call_center - ,date_dim -where - d_month_seq between 1186 and 1186 + 11 -and cs_ship_date_sk = d_date_sk -and cs_warehouse_sk = w_warehouse_sk -and cs_ship_mode_sk = sm_ship_mode_sk -and cs_call_center_sk = cc_call_center_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -limit 100; - --- end template query99.tpl query 52 in stream 9 --- start template query61.tpl query 53 in stream 9 -select /* TPC-DS query61.tpl 0.97 */ promotions,total,cast(promotions as decimal(15,4))/cast(total as decimal(15,4))*100 -from - (select sum(ss_ext_sales_price) promotions - from store_sales - ,store - ,promotion - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_promo_sk = p_promo_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -6 - and i_category = 'Jewelry' - and (p_channel_dmail = 'Y' or p_channel_email = 'Y' or p_channel_tv = 'Y') - and s_gmt_offset = -6 - and d_year = 1998 - and d_moy = 12) promotional_sales, - (select sum(ss_ext_sales_price) total - from store_sales - ,store - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -6 - and i_category = 'Jewelry' - and s_gmt_offset = -6 - and d_year = 1998 - and d_moy = 12) all_sales -order by promotions, total -limit 100; - --- end template query61.tpl query 53 in stream 9 --- start template query22a.tpl query 54 in stream 9 -with /* TPC-DS query22a.tpl 0.55 */ results as -(select i_product_name - ,i_brand - ,i_class - ,i_category - ,avg(inv_quantity_on_hand) qoh - from inventory - ,date_dim - ,item --- ,warehouse - where inv_date_sk=d_date_sk - and inv_item_sk=i_item_sk --- and inv_warehouse_sk = w_warehouse_sk - and d_month_seq between 1202 and 1202 + 11 - group by i_product_name,i_brand,i_class,i_category), -results_rollup as -(select i_product_name, i_brand, i_class, i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class,i_category -union all -select i_product_name, i_brand, i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class -union all -select i_product_name, i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand -union all -select i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name -union all -select null i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results) - select i_product_name, i_brand, i_class, i_category,qoh - from results_rollup - order by qoh, i_product_name, i_brand, i_class, i_category -limit 100; - --- end template query22a.tpl query 54 in stream 9 --- start template query71.tpl query 55 in stream 9 -select /* TPC-DS query71.tpl 0.72 */ i_brand_id brand_id, i_brand brand,t_hour,t_minute, - sum(ext_price) ext_price - from item, (select ws_ext_sales_price as ext_price, - ws_sold_date_sk as sold_date_sk, - ws_item_sk as sold_item_sk, - ws_sold_time_sk as time_sk - from web_sales,date_dim - where d_date_sk = ws_sold_date_sk - and d_moy=11 - and d_year=2000 - union all - select cs_ext_sales_price as ext_price, - cs_sold_date_sk as sold_date_sk, - cs_item_sk as sold_item_sk, - cs_sold_time_sk as time_sk - from catalog_sales,date_dim - where d_date_sk = cs_sold_date_sk - and d_moy=11 - and d_year=2000 - union all - select ss_ext_sales_price as ext_price, - ss_sold_date_sk as sold_date_sk, - ss_item_sk as sold_item_sk, - ss_sold_time_sk as time_sk - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - and d_moy=11 - and d_year=2000 - ) tmp,time_dim - where - sold_item_sk = i_item_sk - and i_manager_id=1 - and time_sk = t_time_sk - and (t_meal_time = 'breakfast' or t_meal_time = 'dinner') - group by i_brand, i_brand_id,t_hour,t_minute - order by ext_price desc, i_brand_id - ; - --- end template query71.tpl query 55 in stream 9 --- start template query68.tpl query 56 in stream 9 -select /* TPC-DS query68.tpl 0.95 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,extended_price - ,extended_tax - ,list_price - from (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_ext_sales_price) extended_price - ,sum(ss_ext_list_price) list_price - ,sum(ss_ext_tax) extended_tax - from store_sales - ,date_dim - ,store - ,household_demographics - ,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_dep_count = 7 or - household_demographics.hd_vehicle_count= 0) - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_city in ('Springfield','Lincoln') - group by ss_ticket_number - ,ss_customer_sk - ,ss_addr_sk,ca_city) dn - ,customer - ,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,ss_ticket_number - limit 100; - --- end template query68.tpl query 56 in stream 9 --- start template query40.tpl query 57 in stream 9 -select /* TPC-DS query40.tpl 0.86 */ - w_state - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('2000-03-07' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_before - ,sum(case when (cast(d_date as date) >= cast ('2000-03-07' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_after - from - catalog_sales left outer join catalog_returns on - (cs_order_number = cr_order_number - and cs_item_sk = cr_item_sk) - ,warehouse - ,item - ,date_dim - where - i_current_price between 0.99 and 1.49 - and i_item_sk = cs_item_sk - and cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('2000-03-07' as date)) - and dateadd(day,30,cast ('2000-03-07' as date)) - group by - w_state,i_item_id - order by w_state,i_item_id -limit 100; - --- end template query40.tpl query 57 in stream 9 --- start template query66.tpl query 58 in stream 9 -select /* TPC-DS query66.tpl 0.39 */ - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - ,sum(jan_sales) as jan_sales - ,sum(feb_sales) as feb_sales - ,sum(mar_sales) as mar_sales - ,sum(apr_sales) as apr_sales - ,sum(may_sales) as may_sales - ,sum(jun_sales) as jun_sales - ,sum(jul_sales) as jul_sales - ,sum(aug_sales) as aug_sales - ,sum(sep_sales) as sep_sales - ,sum(oct_sales) as oct_sales - ,sum(nov_sales) as nov_sales - ,sum(dec_sales) as dec_sales - ,sum(jan_sales/w_warehouse_sq_ft) as jan_sales_per_sq_foot - ,sum(feb_sales/w_warehouse_sq_ft) as feb_sales_per_sq_foot - ,sum(mar_sales/w_warehouse_sq_ft) as mar_sales_per_sq_foot - ,sum(apr_sales/w_warehouse_sq_ft) as apr_sales_per_sq_foot - ,sum(may_sales/w_warehouse_sq_ft) as may_sales_per_sq_foot - ,sum(jun_sales/w_warehouse_sq_ft) as jun_sales_per_sq_foot - ,sum(jul_sales/w_warehouse_sq_ft) as jul_sales_per_sq_foot - ,sum(aug_sales/w_warehouse_sq_ft) as aug_sales_per_sq_foot - ,sum(sep_sales/w_warehouse_sq_ft) as sep_sales_per_sq_foot - ,sum(oct_sales/w_warehouse_sq_ft) as oct_sales_per_sq_foot - ,sum(nov_sales/w_warehouse_sq_ft) as nov_sales_per_sq_foot - ,sum(dec_sales/w_warehouse_sq_ft) as dec_sales_per_sq_foot - ,sum(jan_net) as jan_net - ,sum(feb_net) as feb_net - ,sum(mar_net) as mar_net - ,sum(apr_net) as apr_net - ,sum(may_net) as may_net - ,sum(jun_net) as jun_net - ,sum(jul_net) as jul_net - ,sum(aug_net) as aug_net - ,sum(sep_net) as sep_net - ,sum(oct_net) as oct_net - ,sum(nov_net) as nov_net - ,sum(dec_net) as dec_net - from ( - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'HARMSTORF' || ',' || 'UPS' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then ws_ext_list_price* ws_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then ws_ext_list_price* ws_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then ws_ext_list_price* ws_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then ws_ext_list_price* ws_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then ws_ext_list_price* ws_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then ws_ext_list_price* ws_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then ws_ext_list_price* ws_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then ws_ext_list_price* ws_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then ws_ext_list_price* ws_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then ws_ext_list_price* ws_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then ws_ext_list_price* ws_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then ws_ext_list_price* ws_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as dec_net - from - web_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - ws_warehouse_sk = w_warehouse_sk - and ws_sold_date_sk = d_date_sk - and ws_sold_time_sk = t_time_sk - and ws_ship_mode_sk = sm_ship_mode_sk - and d_year = 1999 - and t_time between 54112 and 54112+28800 - and sm_carrier in ('HARMSTORF','UPS') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - union all - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'HARMSTORF' || ',' || 'UPS' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then cs_ext_sales_price* cs_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then cs_ext_sales_price* cs_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then cs_ext_sales_price* cs_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then cs_ext_sales_price* cs_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then cs_ext_sales_price* cs_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then cs_ext_sales_price* cs_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then cs_ext_sales_price* cs_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then cs_ext_sales_price* cs_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then cs_ext_sales_price* cs_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then cs_ext_sales_price* cs_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then cs_ext_sales_price* cs_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then cs_ext_sales_price* cs_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as dec_net - from - catalog_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and cs_sold_time_sk = t_time_sk - and cs_ship_mode_sk = sm_ship_mode_sk - and d_year = 1999 - and t_time between 54112 AND 54112+28800 - and sm_carrier in ('HARMSTORF','UPS') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - ) x - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - order by w_warehouse_name - limit 100; - --- end template query66.tpl query 58 in stream 9 --- start template query94.tpl query 59 in stream 9 -select /* TPC-DS query94.tpl 0.17 */ - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2001-2-01' and - dateadd(day,60,cast('2001-2-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'VA' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and exists (select * - from web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) -and not exists(select * - from web_returns wr1 - where ws1.ws_order_number = wr1.wr_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query94.tpl query 59 in stream 9 --- start template query47.tpl query 60 in stream 9 -with /* TPC-DS query47.tpl 0.42 */ v1 as( - select i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, - s_store_name, s_company_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - s_store_name, s_company_name - order by d_year, d_moy) rn - from item, store_sales, date_dim, store - where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - ( - d_year = 2000 or - ( d_year = 2000-1 and d_moy =12) or - ( d_year = 2000+1 and d_moy =1) - ) - group by i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy), - v2 as( - select v1.i_brand - ,v1.d_year - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1.s_store_name = v1_lag.s_store_name and - v1.s_store_name = v1_lead.s_store_name and - v1.s_company_name = v1_lag.s_company_name and - v1.s_company_name = v1_lead.s_company_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 2000 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, avg_monthly_sales - limit 100; - --- end template query47.tpl query 60 in stream 9 --- start template query26.tpl query 61 in stream 9 -select /* TPC-DS query26.tpl 0.85 */ i_item_id, - avg(cs_quantity) agg1, - avg(cs_list_price) agg2, - avg(cs_coupon_amt) agg3, - avg(cs_sales_price) agg4 - from catalog_sales, customer_demographics, date_dim, item, promotion - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd_demo_sk and - cs_promo_sk = p_promo_sk and - cd_gender = 'M' and - cd_marital_status = 'S' and - cd_education_status = 'Unknown' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 2000 - group by i_item_id - order by i_item_id - limit 100; - --- end template query26.tpl query 61 in stream 9 --- start template query25.tpl query 62 in stream 9 -select /* TPC-DS query25.tpl 0.9 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,stddev_samp(ss_net_profit) as store_sales_profit - ,stddev_samp(sr_net_loss) as store_returns_loss - ,stddev_samp(cs_net_profit) as catalog_sales_profit - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 1998 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 10 - and d2.d_year = 1998 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_moy between 4 and 10 - and d3.d_year = 1998 - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query25.tpl query 62 in stream 9 --- start template query98.tpl query 63 in stream 9 -select /* TPC-DS query98.tpl 0.32 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ss_ext_sales_price) as itemrevenue - ,sum(ss_ext_sales_price)*100/sum(sum(ss_ext_sales_price)) over - (partition by i_class) as revenueratio -from - store_sales - ,item - ,date_dim -where - ss_item_sk = i_item_sk - and i_category in ('Jewelry', 'Sports', 'Women') - and ss_sold_date_sk = d_date_sk - and d_date between cast('2000-02-12' as date) - and dateadd(day,30,cast('2000-02-12' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio; - --- end template query98.tpl query 63 in stream 9 --- start template query70a.tpl query 64 in stream 9 -with /* TPC-DS query70a.tpl 0.34 */ results as -( select - sum(ss_net_profit) as total_sum ,s_state ,s_county, 0 as gstate, 0 as g_county - from - store_sales - ,date_dim d1 - ,store - where - d1.d_month_seq between 1212 and 1212 + 11 - and d1.d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - and s_state in - ( select s_state - from (select s_state as s_state, - rank() over ( partition by s_state order by sum(ss_net_profit) desc) as ranking - from store_sales, store, date_dim - where d_month_seq between 1212 and 1212 + 11 - and d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - group by s_state - ) tmp1 - where ranking <= 5) - group by s_state,s_county) , - results_rollup as -(select total_sum ,s_state ,s_county, 0 as g_state, 0 as g_county, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum,s_state, NULL as s_county, 0 as g_state, 1 as g_county, 1 as lochierarchy from results group by s_state - union - select sum(total_sum) as total_sum ,NULL as s_state ,NULL as s_county, 1 as g_state, 1 as g_county, 2 as lochierarchy from results) - select total_sum ,s_state ,s_county, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_county = 0 then s_state end - order by total_sum desc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then s_state end - ,rank_within_parent - limit 100; - --- end template query70a.tpl query 64 in stream 9 --- start template query73.tpl query 65 in stream 9 -select /* TPC-DS query73.tpl 0.79 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_buy_potential = '501-1000' or - household_demographics.hd_buy_potential = '0-500') - and household_demographics.hd_vehicle_count > 0 - and case when household_demographics.hd_vehicle_count > 0 then - household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count else null end > 1 - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_county in ('Fairfield County','Walker County','Arthur County','San Miguel County') - group by ss_ticket_number,ss_customer_sk) dj,customer - where ss_customer_sk = c_customer_sk - and cnt between 1 and 5 - order by cnt desc, c_last_name asc; - --- end template query73.tpl query 65 in stream 9 --- start template query38.tpl query 66 in stream 9 -select /* TPC-DS query38.tpl 0.54 */ count(*) from ( - select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1205 and 1205 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1205 and 1205 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1205 and 1205 + 11 -) hot_cust -limit 100; - --- end template query38.tpl query 66 in stream 9 --- start template query87.tpl query 67 in stream 9 -select /* TPC-DS query87.tpl 0.77 */ count(*) -from ((select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1203 and 1203+11) - except - (select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1203 and 1203+11) - except - (select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1203 and 1203+11) -) cool_cust -; - --- end template query87.tpl query 67 in stream 9 --- start template query3.tpl query 68 in stream 9 -select /* TPC-DS query3.tpl 0.45 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_net_profit) sum_agg - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manufact_id = 526 - and dt.d_moy=11 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,sum_agg desc - ,brand_id - limit 100; - --- end template query3.tpl query 68 in stream 9 --- start template query69.tpl query 69 in stream 9 -select /* TPC-DS query69.tpl 0.28 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_state in ('NE','GA','OH') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2001 and - d_moy between 3 and 3+2) and - (not exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2001 and - d_moy between 3 and 3+2) and - not exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2001 and - d_moy between 3 and 3+2)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - limit 100; - --- end template query69.tpl query 69 in stream 9 --- start template query86a.tpl query 70 in stream 9 -with /* TPC-DS query86a.tpl 0.11 */ results as -( select sum(ws_net_paid) as total_sum, i_category, i_class, 0 as g_category, 0 as g_class - from - web_sales - ,date_dim d1 - ,item - where - d1.d_month_seq between 1184 and 1184+11 - and d1.d_date_sk = ws_sold_date_sk - and i_item_sk = ws_item_sk - group by i_category,i_class - ) , - - results_rollup as -( select total_sum ,i_category ,i_class, g_category, g_class, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum, i_category, NULL as i_class, 0 as g_category, 1 as g_class, 1 as lochierarchy from results group by i_category - union - select sum(total_sum) as total_sum, NULL as i_category, NULL as i_class, 1 as g_category, 1 as g_class, 2 as lochierarchy from results) - select - total_sum ,i_category ,i_class, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_class = 0 then i_category end - order by total_sum desc) as rank_within_parent - from - results_rollup - order by - lochierarchy desc, - case when lochierarchy = 0 then i_category end, - rank_within_parent - limit 100; - --- end template query86a.tpl query 70 in stream 9 --- start template query79.tpl query 71 in stream 9 -select /* TPC-DS query79.tpl 0.89 */ - c_last_name,c_first_name,substring(s_city,1,30),ss_ticket_number,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,store.s_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (household_demographics.hd_dep_count = 1 or household_demographics.hd_vehicle_count > 3) - and date_dim.d_dow = 1 - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_number_employees between 200 and 295 - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,store.s_city) ms,customer - where ss_customer_sk = c_customer_sk - order by c_last_name,c_first_name,substring(s_city,1,30), profit -limit 100; - --- end template query79.tpl query 71 in stream 9 --- start template query89.tpl query 72 in stream 9 -select /* TPC-DS query89.tpl 0.56 */ * -from( -select i_category, i_class, i_brand, - s_store_name, s_company_name, - d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, s_store_name, s_company_name) - avg_monthly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - d_year in (2001) and - ((i_category in ('Sports','Home','Jewelry') and - i_class in ('basketball','kids','custom') - ) - or (i_category in ('Women','Music','Electronics') and - i_class in ('fragrances','country','stereo') - )) -group by i_category, i_class, i_brand, - s_store_name, s_company_name, d_moy) tmp1 -where case when (avg_monthly_sales <> 0) then (abs(sum_sales - avg_monthly_sales) / avg_monthly_sales) else null end > 0.1 -order by sum_sales - avg_monthly_sales, s_store_name -limit 100; - --- end template query89.tpl query 72 in stream 9 --- start template query51.tpl query 73 in stream 9 -WITH /* TPC-DS query51.tpl 0.46 */ web_v1 as ( -select - ws_item_sk item_sk, d_date, - sum(sum(ws_sales_price)) - over (partition by ws_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from web_sales - ,date_dim -where ws_sold_date_sk=d_date_sk - and d_month_seq between 1189 and 1189+11 - and ws_item_sk is not NULL -group by ws_item_sk, d_date), -store_v1 as ( -select - ss_item_sk item_sk, d_date, - sum(sum(ss_sales_price)) - over (partition by ss_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from store_sales - ,date_dim -where ss_sold_date_sk=d_date_sk - and d_month_seq between 1189 and 1189+11 - and ss_item_sk is not NULL -group by ss_item_sk, d_date) - select * -from (select item_sk - ,d_date - ,web_sales - ,store_sales - ,max(web_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) web_cumulative - ,max(store_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) store_cumulative - from (select case when web.item_sk is not null then web.item_sk else store.item_sk end item_sk - ,case when web.d_date is not null then web.d_date else store.d_date end d_date - ,web.cume_sales web_sales - ,store.cume_sales store_sales - from web_v1 web full outer join store_v1 store on (web.item_sk = store.item_sk - and web.d_date = store.d_date) - )x )y -where web_cumulative > store_cumulative -order by item_sk - ,d_date -limit 100; - --- end template query51.tpl query 73 in stream 9 --- start template query58.tpl query 74 in stream 9 -with /* TPC-DS query58.tpl 0.19 */ ss_items as - (select i_item_id item_id - ,sum(ss_ext_sales_price) ss_item_rev - from store_sales - ,item - ,date_dim - where ss_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '1999-07-04')) - and ss_sold_date_sk = d_date_sk - group by i_item_id), - cs_items as - (select i_item_id item_id - ,sum(cs_ext_sales_price) cs_item_rev - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '1999-07-04')) - and cs_sold_date_sk = d_date_sk - group by i_item_id), - ws_items as - (select i_item_id item_id - ,sum(ws_ext_sales_price) ws_item_rev - from web_sales - ,item - ,date_dim - where ws_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq =(select d_week_seq - from date_dim - where d_date = '1999-07-04')) - and ws_sold_date_sk = d_date_sk - group by i_item_id) - select ss_items.item_id - ,ss_item_rev - ,ss_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ss_dev - ,cs_item_rev - ,cs_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 cs_dev - ,ws_item_rev - ,ws_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ws_dev - ,(ss_item_rev+cs_item_rev+ws_item_rev)/3 average - from ss_items,cs_items,ws_items - where ss_items.item_id=cs_items.item_id - and ss_items.item_id=ws_items.item_id - and ss_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - and ss_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and cs_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and cs_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and ws_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and ws_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - order by item_id - ,ss_item_rev - limit 100; - --- end template query58.tpl query 74 in stream 9 --- start template query41.tpl query 75 in stream 9 -select /* TPC-DS query41.tpl 0.62 */ distinct(i_product_name) - from item i1 - where i_manufact_id between 671 and 671+40 - and (select count(*) as item_cnt - from item - where (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'peru' or i_color = 'blush') and - (i_units = 'Each' or i_units = 'Lb') and - (i_size = 'extra large' or i_size = 'small') - ) or - (i_category = 'Women' and - (i_color = 'lace' or i_color = 'burnished') and - (i_units = 'Case' or i_units = 'Bunch') and - (i_size = 'petite' or i_size = 'economy') - ) or - (i_category = 'Men' and - (i_color = 'turquoise' or i_color = 'snow') and - (i_units = 'Box' or i_units = 'Oz') and - (i_size = 'large' or i_size = 'N/A') - ) or - (i_category = 'Men' and - (i_color = 'dodger' or i_color = 'spring') and - (i_units = 'N/A' or i_units = 'Dram') and - (i_size = 'extra large' or i_size = 'small') - ))) or - (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'plum' or i_color = 'orange') and - (i_units = 'Bundle' or i_units = 'Cup') and - (i_size = 'extra large' or i_size = 'small') - ) or - (i_category = 'Women' and - (i_color = 'dark' or i_color = 'ghost') and - (i_units = 'Gram' or i_units = 'Pound') and - (i_size = 'petite' or i_size = 'economy') - ) or - (i_category = 'Men' and - (i_color = 'cyan' or i_color = 'dim') and - (i_units = 'Tsp' or i_units = 'Pallet') and - (i_size = 'large' or i_size = 'N/A') - ) or - (i_category = 'Men' and - (i_color = 'chartreuse' or i_color = 'deep') and - (i_units = 'Dozen' or i_units = 'Carton') and - (i_size = 'extra large' or i_size = 'small') - )))) > 0 - order by i_product_name - limit 100; - --- end template query41.tpl query 75 in stream 9 --- start template query19.tpl query 76 in stream 9 -select /* TPC-DS query19.tpl 0.8 */ i_brand_id brand_id, i_brand brand, i_manufact_id, i_manufact, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item,customer,customer_address,store - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=14 - and d_moy=11 - and d_year=1998 - and ss_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and substring(ca_zip,1,5) <> substring(s_zip,1,5) - and ss_store_sk = s_store_sk - group by i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact - order by ext_price desc - ,i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact -limit 100 ; - --- end template query19.tpl query 76 in stream 9 --- start template query83.tpl query 77 in stream 9 -with /* TPC-DS query83.tpl 0.96 */ sr_items as - (select i_item_id item_id, - sum(sr_return_quantity) sr_item_qty - from store_returns, - item, - date_dim - where sr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2000-02-07','2000-09-27','2000-11-20'))) - and sr_returned_date_sk = d_date_sk - group by i_item_id), - cr_items as - (select i_item_id item_id, - sum(cr_return_quantity) cr_item_qty - from catalog_returns, - item, - date_dim - where cr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2000-02-07','2000-09-27','2000-11-20'))) - and cr_returned_date_sk = d_date_sk - group by i_item_id), - wr_items as - (select i_item_id item_id, - sum(wr_return_quantity) wr_item_qty - from web_returns, - item, - date_dim - where wr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2000-02-07','2000-09-27','2000-11-20'))) - and wr_returned_date_sk = d_date_sk - group by i_item_id) - select sr_items.item_id - ,sr_item_qty - ,sr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 sr_dev - ,cr_item_qty - ,cr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 cr_dev - ,wr_item_qty - ,wr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 wr_dev - ,(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 average - from sr_items - ,cr_items - ,wr_items - where sr_items.item_id=cr_items.item_id - and sr_items.item_id=wr_items.item_id - order by sr_items.item_id - ,sr_item_qty - limit 100; - --- end template query83.tpl query 77 in stream 9 --- start template query96.tpl query 78 in stream 9 -select /* TPC-DS query96.tpl 0.1 */ count(*) -from store_sales - ,household_demographics - ,time_dim, store -where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 16 - and time_dim.t_minute >= 30 - and household_demographics.hd_dep_count = 9 - and store.s_store_name = 'ese' -order by count(*) -limit 100; - --- end template query96.tpl query 78 in stream 9 --- start template query46.tpl query 79 in stream 9 -select /* TPC-DS query46.tpl 0.23 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and (household_demographics.hd_dep_count = 6 or - household_demographics.hd_vehicle_count= 2) - and date_dim.d_dow in (6,0) - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_city in ('Crossroads','Oakland','Lakeview','Mount Vernon','Edgewood') - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,ca_city) dn,customer,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - limit 100; - --- end template query46.tpl query 79 in stream 9 --- start template query53.tpl query 80 in stream 9 -select /* TPC-DS query53.tpl 0.88 */ * from -(select i_manufact_id, -sum(ss_sales_price) sum_sales, -avg(sum(ss_sales_price)) over (partition by i_manufact_id) avg_quarterly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and -ss_sold_date_sk = d_date_sk and -ss_store_sk = s_store_sk and -d_month_seq in (1185,1185+1,1185+2,1185+3,1185+4,1185+5,1185+6,1185+7,1185+8,1185+9,1185+10,1185+11) and -((i_category in ('Books','Children','Electronics') and -i_class in ('personal','portable','reference','self-help') and -i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) -or(i_category in ('Women','Music','Men') and -i_class in ('accessories','classical','fragrances','pants') and -i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manufact_id, d_qoy ) tmp1 -where case when avg_quarterly_sales > 0 - then abs (sum_sales - avg_quarterly_sales)/ avg_quarterly_sales - else null end > 0.1 -order by avg_quarterly_sales, - sum_sales, - i_manufact_id -limit 100; - --- end template query53.tpl query 80 in stream 9 --- start template query55.tpl query 81 in stream 9 -select /* TPC-DS query55.tpl 0.82 */ i_brand_id brand_id, i_brand brand, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=3 - and d_moy=12 - and d_year=1999 - group by i_brand, i_brand_id - order by ext_price desc, i_brand_id -limit 100 ; - --- end template query55.tpl query 81 in stream 9 --- start template query72.tpl query 82 in stream 9 -select /* TPC-DS query72.tpl 0.87 */ i_item_desc - ,w_warehouse_name - ,d1.d_week_seq - ,sum(case when p_promo_sk is null then 1 else 0 end) no_promo - ,sum(case when p_promo_sk is not null then 1 else 0 end) promo - ,count(*) total_cnt -from catalog_sales -join inventory on (cs_item_sk = inv_item_sk) -join warehouse on (w_warehouse_sk=inv_warehouse_sk) -join item on (i_item_sk = cs_item_sk) -join customer_demographics on (cs_bill_cdemo_sk = cd_demo_sk) -join household_demographics on (cs_bill_hdemo_sk = hd_demo_sk) -join date_dim d1 on (cs_sold_date_sk = d1.d_date_sk) -join date_dim d2 on (inv_date_sk = d2.d_date_sk) -join date_dim d3 on (cs_ship_date_sk = d3.d_date_sk) -left outer join promotion on (cs_promo_sk=p_promo_sk) -left outer join catalog_returns on (cr_item_sk = cs_item_sk and cr_order_number = cs_order_number) -where d1.d_week_seq = d2.d_week_seq - and inv_quantity_on_hand < cs_quantity - and d3.d_date > d1.d_date + 5 - and hd_buy_potential = '1001-5000' - and d1.d_year = 1998 - and cd_marital_status = 'S' -group by i_item_desc,w_warehouse_name,d1.d_week_seq -order by total_cnt desc, i_item_desc, w_warehouse_name, d_week_seq -limit 100; - --- end template query72.tpl query 82 in stream 9 --- start template query95.tpl query 83 in stream 9 -with /* TPC-DS query95.tpl 0.43 */ ws_wh as -(select ws1.ws_order_number,ws1.ws_warehouse_sk wh1,ws2.ws_warehouse_sk wh2 - from web_sales ws1,web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) - select - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '1999-2-01' and - dateadd(day,60,cast('1999-2-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'TN' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and ws1.ws_order_number in (select ws_order_number - from ws_wh) -and ws1.ws_order_number in (select wr_order_number - from web_returns,ws_wh - where wr_order_number = ws_wh.ws_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query95.tpl query 83 in stream 9 --- start template query29.tpl query 84 in stream 9 -select /* TPC-DS query29.tpl 0.53 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,stddev_samp(ss_quantity) as store_sales_quantity - ,stddev_samp(sr_return_quantity) as store_returns_quantity - ,stddev_samp(cs_quantity) as catalog_sales_quantity - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 1998 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 4 + 3 - and d2.d_year = 1998 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_year in (1998,1998+1,1998+2) - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query29.tpl query 84 in stream 9 --- start template query64.tpl query 85 in stream 9 -with /* TPC-DS query64.tpl 0.20 */ cs_ui as - (select cs_item_sk - ,sum(cs_ext_list_price) as sale,sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit) as refund - from catalog_sales - ,catalog_returns - where cs_item_sk = cr_item_sk - and cs_order_number = cr_order_number - group by cs_item_sk - having sum(cs_ext_list_price)>2*sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit)), -cross_sales as - (select i_product_name product_name - ,i_item_sk item_sk - ,s_store_name store_name - ,s_zip store_zip - ,ad1.ca_street_number b_street_number - ,ad1.ca_street_name b_street_name - ,ad1.ca_city b_city - ,ad1.ca_zip b_zip - ,ad2.ca_street_number c_street_number - ,ad2.ca_street_name c_street_name - ,ad2.ca_city c_city - ,ad2.ca_zip c_zip - ,d1.d_year as syear - ,d2.d_year as fsyear - ,d3.d_year s2year - ,count(*) cnt - ,sum(ss_wholesale_cost) s1 - ,sum(ss_list_price) s2 - ,sum(ss_coupon_amt) s3 - FROM store_sales - ,store_returns - ,cs_ui - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,customer - ,customer_demographics cd1 - ,customer_demographics cd2 - ,promotion - ,household_demographics hd1 - ,household_demographics hd2 - ,customer_address ad1 - ,customer_address ad2 - ,income_band ib1 - ,income_band ib2 - ,item - WHERE ss_store_sk = s_store_sk AND - ss_sold_date_sk = d1.d_date_sk AND - ss_customer_sk = c_customer_sk AND - ss_cdemo_sk= cd1.cd_demo_sk AND - ss_hdemo_sk = hd1.hd_demo_sk AND - ss_addr_sk = ad1.ca_address_sk and - ss_item_sk = i_item_sk and - ss_item_sk = sr_item_sk and - ss_ticket_number = sr_ticket_number and - ss_item_sk = cs_ui.cs_item_sk and - c_current_cdemo_sk = cd2.cd_demo_sk AND - c_current_hdemo_sk = hd2.hd_demo_sk AND - c_current_addr_sk = ad2.ca_address_sk and - c_first_sales_date_sk = d2.d_date_sk and - c_first_shipto_date_sk = d3.d_date_sk and - ss_promo_sk = p_promo_sk and - hd1.hd_income_band_sk = ib1.ib_income_band_sk and - hd2.hd_income_band_sk = ib2.ib_income_band_sk and - cd1.cd_marital_status <> cd2.cd_marital_status and - i_color in ('sandy','seashell','black','peru','misty','spring') and - i_current_price between 6 and 6 + 10 and - i_current_price between 6 + 1 and 6 + 15 -group by i_product_name - ,i_item_sk - ,s_store_name - ,s_zip - ,ad1.ca_street_number - ,ad1.ca_street_name - ,ad1.ca_city - ,ad1.ca_zip - ,ad2.ca_street_number - ,ad2.ca_street_name - ,ad2.ca_city - ,ad2.ca_zip - ,d1.d_year - ,d2.d_year - ,d3.d_year -) -select cs1.product_name - ,cs1.store_name - ,cs1.store_zip - ,cs1.b_street_number - ,cs1.b_street_name - ,cs1.b_city - ,cs1.b_zip - ,cs1.c_street_number - ,cs1.c_street_name - ,cs1.c_city - ,cs1.c_zip - ,cs1.syear - ,cs1.cnt - ,cs1.s1 as s11 - ,cs1.s2 as s21 - ,cs1.s3 as s31 - ,cs2.s1 as s12 - ,cs2.s2 as s22 - ,cs2.s3 as s32 - ,cs2.syear - ,cs2.cnt -from cross_sales cs1,cross_sales cs2 -where cs1.item_sk=cs2.item_sk and - cs1.syear = 2001 and - cs2.syear = 2001 + 1 and - cs2.cnt <= cs1.cnt and - cs1.store_name = cs2.store_name and - cs1.store_zip = cs2.store_zip -order by cs1.product_name - ,cs1.store_name - ,cs2.cnt - ,cs1.s1 - ,cs2.s1; - --- end template query64.tpl query 85 in stream 9 --- start template query93.tpl query 86 in stream 9 -select /* TPC-DS query93.tpl 0.52 */ ss_customer_sk - ,sum(act_sales) sumsales - from (select ss_item_sk - ,ss_ticket_number - ,ss_customer_sk - ,case when sr_return_quantity is not null then (ss_quantity-sr_return_quantity)*ss_sales_price - else (ss_quantity*ss_sales_price) end act_sales - from store_sales left outer join store_returns on (sr_item_sk = ss_item_sk - and sr_ticket_number = ss_ticket_number) - ,reason - where sr_reason_sk = r_reason_sk - and r_reason_desc = 'reason 31') t - group by ss_customer_sk - order by sumsales, ss_customer_sk -limit 100; - --- end template query93.tpl query 86 in stream 9 --- start template query56.tpl query 87 in stream 9 -with /* TPC-DS query56.tpl 0.83 */ ss as ( - select i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where i_item_id in (select - i_item_id -from item -where i_color in ('azure','cornsilk','orchid')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 1 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - cs as ( - select i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('azure','cornsilk','orchid')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 1 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - ws as ( - select i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('azure','cornsilk','orchid')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 1 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id) - select i_item_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by total_sales, - i_item_id - limit 100; - --- end template query56.tpl query 87 in stream 9 --- start template query97.tpl query 88 in stream 9 -with /* TPC-DS query97.tpl 0.38 */ ssci as ( -select ss_customer_sk customer_sk - ,ss_item_sk item_sk -from store_sales,date_dim -where ss_sold_date_sk = d_date_sk - and d_month_seq between 1217 and 1217 + 11 -group by ss_customer_sk - ,ss_item_sk), -csci as( - select cs_bill_customer_sk customer_sk - ,cs_item_sk item_sk -from catalog_sales,date_dim -where cs_sold_date_sk = d_date_sk - and d_month_seq between 1217 and 1217 + 11 -group by cs_bill_customer_sk - ,cs_item_sk) - select sum(case when ssci.customer_sk is not null and csci.customer_sk is null then 1 else 0 end) store_only - ,sum(case when ssci.customer_sk is null and csci.customer_sk is not null then 1 else 0 end) catalog_only - ,sum(case when ssci.customer_sk is not null and csci.customer_sk is not null then 1 else 0 end) store_and_catalog -from ssci full outer join csci on (ssci.customer_sk=csci.customer_sk - and ssci.item_sk = csci.item_sk) -limit 100; - --- end template query97.tpl query 88 in stream 9 --- start template query23.tpl query 89 in stream 9 -with /* TPC-DS query23.tpl 0.68 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (1999,1999+1,1999+2,1999+3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1999,1999+1,1999+2,1999+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * -from - max_store_sales)) - select sum(sales) - from (select cs_quantity*cs_list_price sales - from catalog_sales - ,date_dim - where d_year = 1999 - and d_moy = 2 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - union all - select ws_quantity*ws_list_price sales - from web_sales - ,date_dim - where d_year = 1999 - and d_moy = 2 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer)) - limit 100; -with /* TPC-DS query23.tpl 0.68 part2 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (1999,1999 + 1,1999 + 2,1999 + 3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1999,1999+1,1999+2,1999+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * - from max_store_sales)) - select c_last_name,c_first_name,sales - from (select c_last_name,c_first_name,sum(cs_quantity*cs_list_price) sales - from catalog_sales - ,customer - ,date_dim - where d_year = 1999 - and d_moy = 2 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and cs_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name - union all - select c_last_name,c_first_name,sum(ws_quantity*ws_list_price) sales - from web_sales - ,customer - ,date_dim - where d_year = 1999 - and d_moy = 2 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and ws_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name) - order by c_last_name,c_first_name,sales - limit 100; - --- end template query23.tpl query 89 in stream 9 --- start template query44.tpl query 90 in stream 9 -select /* TPC-DS query44.tpl 0.4 */ asceding.rnk, i1.i_product_name best_performing, i2.i_product_name worst_performing -from(select * - from (select item_sk,rank() over (order by rank_col asc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 42 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 42 - and ss_addr_sk is null - group by ss_store_sk))V1)V11 - where rnk < 11) asceding, - (select * - from (select item_sk,rank() over (order by rank_col desc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 42 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 42 - and ss_addr_sk is null - group by ss_store_sk))V2)V21 - where rnk < 11) descending, -item i1, -item i2 -where asceding.rnk = descending.rnk - and i1.i_item_sk=asceding.item_sk - and i2.i_item_sk=descending.item_sk -order by asceding.rnk -limit 100; - --- end template query44.tpl query 90 in stream 9 --- start template query91.tpl query 91 in stream 9 -select /* TPC-DS query91.tpl 0.13 */ - cc_call_center_id Call_Center, - cc_name Call_Center_Name, - cc_manager Manager, - sum(cr_net_loss) Returns_Loss -from - call_center, - catalog_returns, - date_dim, - customer, - customer_address, - customer_demographics, - household_demographics -where - cr_call_center_sk = cc_call_center_sk -and cr_returned_date_sk = d_date_sk -and cr_returning_customer_sk= c_customer_sk -and cd_demo_sk = c_current_cdemo_sk -and hd_demo_sk = c_current_hdemo_sk -and ca_address_sk = c_current_addr_sk -and d_year = 1998 -and d_moy = 12 -and ( (cd_marital_status = 'M' and cd_education_status = 'Unknown') - or(cd_marital_status = 'W' and cd_education_status = 'Advanced Degree')) -and hd_buy_potential like '>10000%' -and ca_gmt_offset = -7 -group by cc_call_center_id,cc_name,cc_manager,cd_marital_status,cd_education_status -order by sum(cr_net_loss) desc; - --- end template query91.tpl query 91 in stream 9 --- start template query49.tpl query 92 in stream 9 -select /* TPC-DS query49.tpl 0.48 */ channel, item, return_ratio, return_rank, currency_rank from - (select - 'web' as channel - ,web.item - ,web.return_ratio - ,web.return_rank - ,web.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select ws.ws_item_sk as item - ,(cast(sum(coalesce(wr.wr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(wr.wr_return_amt,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - web_sales ws left outer join web_returns wr - on (ws.ws_order_number = wr.wr_order_number and - ws.ws_item_sk = wr.wr_item_sk) - ,date_dim - where - wr.wr_return_amt > 10000 - and ws.ws_net_profit > 1 - and ws.ws_net_paid > 0 - and ws.ws_quantity > 0 - and ws_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 12 - group by ws.ws_item_sk - ) in_web - ) web - where - ( - web.return_rank <= 10 - or - web.currency_rank <= 10 - ) - union - select - 'catalog' as channel - ,catalog.item - ,catalog.return_ratio - ,catalog.return_rank - ,catalog.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select - cs.cs_item_sk as item - ,(cast(sum(coalesce(cr.cr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(cr.cr_return_amount,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - catalog_sales cs left outer join catalog_returns cr - on (cs.cs_order_number = cr.cr_order_number and - cs.cs_item_sk = cr.cr_item_sk) - ,date_dim - where - cr.cr_return_amount > 10000 - and cs.cs_net_profit > 1 - and cs.cs_net_paid > 0 - and cs.cs_quantity > 0 - and cs_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 12 - group by cs.cs_item_sk - ) in_cat - ) catalog - where - ( - catalog.return_rank <= 10 - or - catalog.currency_rank <=10 - ) - union - select - 'store' as channel - ,store.item - ,store.return_ratio - ,store.return_rank - ,store.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select sts.ss_item_sk as item - ,(cast(sum(coalesce(sr.sr_return_quantity,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(sr.sr_return_amt,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - store_sales sts left outer join store_returns sr - on (sts.ss_ticket_number = sr.sr_ticket_number and sts.ss_item_sk = sr.sr_item_sk) - ,date_dim - where - sr.sr_return_amt > 10000 - and sts.ss_net_profit > 1 - and sts.ss_net_paid > 0 - and sts.ss_quantity > 0 - and ss_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 12 - group by sts.ss_item_sk - ) in_store - ) store - where ( - store.return_rank <= 10 - or - store.currency_rank <= 10 - ) - ) - order by 1,4,5,2 - limit 100; - --- end template query49.tpl query 92 in stream 9 --- start template query76.tpl query 93 in stream 9 -select /* TPC-DS query76.tpl 0.99 */ channel, col_name, d_year, d_qoy, i_category, COUNT(*) sales_cnt, SUM(ext_sales_price) sales_amt FROM ( - SELECT 'store' as channel, 'ss_hdemo_sk' col_name, d_year, d_qoy, i_category, ss_ext_sales_price ext_sales_price - FROM store_sales, item, date_dim - WHERE ss_hdemo_sk IS NULL - AND ss_sold_date_sk=d_date_sk - AND ss_item_sk=i_item_sk - UNION ALL - SELECT 'web' as channel, 'ws_warehouse_sk' col_name, d_year, d_qoy, i_category, ws_ext_sales_price ext_sales_price - FROM web_sales, item, date_dim - WHERE ws_warehouse_sk IS NULL - AND ws_sold_date_sk=d_date_sk - AND ws_item_sk=i_item_sk - UNION ALL - SELECT 'catalog' as channel, 'cs_promo_sk' col_name, d_year, d_qoy, i_category, cs_ext_sales_price ext_sales_price - FROM catalog_sales, item, date_dim - WHERE cs_promo_sk IS NULL - AND cs_sold_date_sk=d_date_sk - AND cs_item_sk=i_item_sk) foo -GROUP BY channel, col_name, d_year, d_qoy, i_category -ORDER BY channel, col_name, d_year, d_qoy, i_category -limit 100; - --- end template query76.tpl query 93 in stream 9 --- start template query63.tpl query 94 in stream 9 -select /* TPC-DS query63.tpl 0.27 */ * -from (select i_manager_id - ,sum(ss_sales_price) sum_sales - ,avg(sum(ss_sales_price)) over (partition by i_manager_id) avg_monthly_sales - from item - ,store_sales - ,date_dim - ,store - where ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and d_month_seq in (1214,1214+1,1214+2,1214+3,1214+4,1214+5,1214+6,1214+7,1214+8,1214+9,1214+10,1214+11) - and (( i_category in ('Books','Children','Electronics') - and i_class in ('personal','portable','reference','self-help') - and i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) - or( i_category in ('Women','Music','Men') - and i_class in ('accessories','classical','fragrances','pants') - and i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manager_id, d_moy) tmp1 -where case when avg_monthly_sales > 0 then abs (sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 -order by i_manager_id - ,avg_monthly_sales - ,sum_sales -limit 100; - --- end template query63.tpl query 94 in stream 9 --- start template query45.tpl query 95 in stream 9 -select /* TPC-DS query45.tpl 0.18 */ ca_zip, ca_state, sum(ws_sales_price) - from web_sales, customer, customer_address, date_dim, item - where ws_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ws_item_sk = i_item_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', '85392', '85460', '80348', '81792') - or - i_item_id in (select i_item_id - from item - where i_item_sk in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29) - ) - ) - and ws_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 1999 - group by ca_zip, ca_state - order by ca_zip, ca_state - limit 100; - --- end template query45.tpl query 95 in stream 9 --- start template query43.tpl query 96 in stream 9 -select /* TPC-DS query43.tpl 0.15 */ s_store_name, s_store_id, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from date_dim, store_sales, store - where d_date_sk = ss_sold_date_sk and - s_store_sk = ss_store_sk and - s_gmt_offset = -6 and - d_year = 1998 - group by s_store_name, s_store_id - order by s_store_name, s_store_id,sun_sales,mon_sales,tue_sales,wed_sales,thu_sales,fri_sales,sat_sales - limit 100; - --- end template query43.tpl query 96 in stream 9 --- start template query85.tpl query 97 in stream 9 -select /* TPC-DS query85.tpl 0.33 */ substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) - from web_sales, web_returns, web_page, customer_demographics cd1, - customer_demographics cd2, customer_address, date_dim, reason - where ws_web_page_sk = wp_web_page_sk - and ws_item_sk = wr_item_sk - and ws_order_number = wr_order_number - and ws_sold_date_sk = d_date_sk and d_year = 1998 - and cd1.cd_demo_sk = wr_refunded_cdemo_sk - and cd2.cd_demo_sk = wr_returning_cdemo_sk - and ca_address_sk = wr_refunded_addr_sk - and r_reason_sk = wr_reason_sk - and - ( - ( - cd1.cd_marital_status = 'D' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Primary' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 100.00 and 150.00 - ) - or - ( - cd1.cd_marital_status = 'U' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Unknown' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 50.00 and 100.00 - ) - or - ( - cd1.cd_marital_status = 'S' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'College' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ca_country = 'United States' - and - ca_state in ('IN', 'GA', 'ND') - and ws_net_profit between 100 and 200 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('NC', 'MI', 'AR') - and ws_net_profit between 150 and 300 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('MS', 'MT', 'CO') - and ws_net_profit between 50 and 250 - ) - ) -group by r_reason_desc -order by substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) -limit 100; - --- end template query85.tpl query 97 in stream 9 --- start template query37.tpl query 98 in stream 9 -select /* TPC-DS query37.tpl 0.31 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, catalog_sales - where i_current_price between 32 and 32 + 30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('2002-03-30' as date) and dateadd(day,60,cast('2002-03-30' as date)) - and i_manufact_id in (839,730,801,892) - and inv_quantity_on_hand between 100 and 500 - and cs_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query37.tpl query 98 in stream 9 --- start template query8.tpl query 99 in stream 9 -select /* TPC-DS query8.tpl 0.63 */ s_store_name - ,sum(ss_net_profit) - from store_sales - ,date_dim - ,store, - (select ca_zip - from ( - SELECT substring(ca_zip,1,5) ca_zip - FROM customer_address - WHERE substring(ca_zip,1,5) IN ( - '62046','89526','85296','21879','11716','99602', - '37453','68232','69551','26076','61061', - '42848','26745','11744','49061','64110', - '24130','69073','11561','58328','37732', - '23084','35956','40810','36647','83788', - '58704','93116','58595','23718','55377', - '81570','63830','56636','43016','55653', - '21707','13294','53407','96700','86667', - '25958','47023','25933','78868','57341', - '88874','67465','52947','20999','56855', - '74939','49091','11510','52773','20787', - '33779','40713','73768','11836','13848', - '67141','75046','61290','72146','85721', - '44891','21818','74932','11053','47771', - '10587','75500','18155','67274','15559', - '77862','41647','70013','51783','82437', - '79590','86463','24137','98275','77642', - '21508','50459','40605','90023','16621', - '41918','78990','85875','36888','81469', - '79572','49563','24923','71978','90232', - '68486','75833','73207','26780','38957', - '27743','50709','62451','59746','37248', - '25638','18498','52829','66662','49383', - '38051','60441','20278','91681','94786', - '83261','20169','93868','38861','60456', - '79430','48408','71880','42448','22915', - '93839','33158','74139','75252','20541', - '13631','99592','84860','71434','70100', - '73083','25346','39806','45935','15298', - '51337','85342','88531','50284','66976', - '13197','85080','64664','90660','84299', - '40019','59000','32645','62839','38903', - '90589','19990','82111','65907','12774', - '50234','51447','28651','49411','52696', - '50734','94926','73742','51326','27376', - '59120','75257','34848','80036','61388', - '48053','56231','81987','88140','41584', - '17186','48647','93045','51467','97560', - '71519','75139','42525','62112','65703', - '11232','27070','76524','90036','82172', - '64596','78729','30497','68208','85995', - '54660','90003','30706','56765','11170', - '16270','71208','51606','23309','72486', - '65384','29220','93707','68058','32531', - '24743','24373','81069','72861','68681', - '37867','78339','38557','97810','32927', - '99337','34076','25307','73572','39778', - '65862','85233','23225','99581','79234', - '92427','40228','24894','50906','57962', - '37871','57331','40561','51699','83441', - '75294','94413','47349','40619','99529', - '47243','89221','91652','17917','99877', - '25816','34147','20044','59643','66850', - '58046','75772','94378','45323','48195', - '94518','73073','72377','13773','86191', - '76733','78289','69195','99596','71363', - '83215','15816','70440','56838','53161', - '82189','50545','31368','57994','60439', - '99127','47817','50820','23776','17481', - '86283','16638','41559','39055','84928', - '79560','18978','35593','45299','18960', - '73504','23397','61838','86617','59290', - '28639','45814','60120','57745','45386', - '93664','64771','50974','62158','40964', - '88837','24705','73895','12359','45218', - '84035','87454','89227','45930','58764', - '91012','35744','10976','80398','31960', - '77346','79640','81015','69520','37315', - '33250','99629','21592','64683','27318', - '59463','35256','92250','63183','56540', - '86540','88933','55140','54730','37171', - '88109','62087','25092','32186','26993', - '92835','76650','79319','14925','96321', - '12834','87512','94362','92674','32840', - '73425','11068','47346','97338','22698', - '28267','65786','67514','62956','92984', - '56762','51277','69986','81634','67402', - '31378','55783','63994','35274','51306', - '85205','85303','66517','44871','11684', - '51693','64213','23679','23073') - intersect - select ca_zip - from (SELECT substring(ca_zip,1,5) ca_zip,count(*) cnt - FROM customer_address, customer - WHERE ca_address_sk = c_current_addr_sk and - c_preferred_cust_flag='Y' - group by ca_zip - having count(*) > 10)A1)A2) V1 - where ss_store_sk = s_store_sk - and ss_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 2001 - and (substring(s_zip,1,2) = substring(V1.ca_zip,1,2)) - group by s_store_name - order by s_store_name - limit 100; - --- end template query8.tpl query 99 in stream 9 diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/1TB/queries/query_0.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/1TB/queries/query_0.sql index fb619f6d..85b02934 100644 --- a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/1TB/queries/query_0.sql +++ b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/1TB/queries/query_0.sql @@ -194,8 +194,8 @@ order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov ; -- end template query39.tpl query 5 in stream 0 --- start template query80a.tpl query 6 in stream 0 -with /* TPC-DS query80a.tpl 0.6 */ ssr as +-- start template query80.tpl query 6 in stream 0 +with /* TPC-DS query80.tpl 0.6 */ ssr as (select s_store_id as store_id, sum(ss_ext_sales_price) as sales, sum(coalesce(sr_return_amt, 0)) as returns, @@ -208,7 +208,7 @@ with /* TPC-DS query80a.tpl 0.6 */ ssr as promotion where ss_sold_date_sk = d_date_sk and d_date between cast('2000-08-10' as date) - and dateadd(day,30,cast('2000-08-10' as date)) + and dateadd(day,30,cast('2000-08-10' as date)) and ss_store_sk = s_store_sk and ss_item_sk = i_item_sk and i_current_price > 50 @@ -229,7 +229,7 @@ with /* TPC-DS query80a.tpl 0.6 */ ssr as promotion where cs_sold_date_sk = d_date_sk and d_date between cast('2000-08-10' as date) - and dateadd(day,30,cast('2000-08-10' as date)) + and dateadd(day,30,cast('2000-08-10' as date)) and cs_catalog_page_sk = cp_catalog_page_sk and cs_item_sk = i_item_sk and i_current_price > 50 @@ -257,9 +257,7 @@ group by cp_catalog_page_id) and ws_promo_sk = p_promo_sk and p_channel_tv = 'N' group by web_site_id) -, -results as - (select channel + select channel , id , sum(sales) as sales , sum(returns) as returns @@ -286,24 +284,12 @@ results as , profit from wsr ) x - group by channel, id) - - select channel - , id - , sales - , returns - , profit - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results - ) foo - order by channel, id + group by rollup (channel, id) + order by channel + ,id limit 100; --- end template query80a.tpl query 6 in stream 0 +-- end template query80.tpl query 6 in stream 0 -- start template query32.tpl query 7 in stream 0 select /* TPC-DS query32.tpl 0.7 */ sum(cs_ext_discount_amt) as "excess discount amount" from @@ -463,9 +449,16 @@ order by limit 100; -- end template query78.tpl query 10 in stream 0 --- start template query86a.tpl query 11 in stream 0 -with /* TPC-DS query86a.tpl 0.11 */ results as -( select sum(ws_net_paid) as total_sum, i_category, i_class, 0 as g_category, 0 as g_class +-- start template query86.tpl query 11 in stream 0 +select /* TPC-DS query86.tpl 0.11 */ + sum(ws_net_paid) as total_sum + ,i_category + ,i_class + ,grouping(i_category)+grouping(i_class) as lochierarchy + ,rank() over ( + partition by grouping(i_category)+grouping(i_class), + case when grouping(i_class) = 0 then i_category end + order by sum(ws_net_paid) desc) as rank_within_parent from web_sales ,date_dim d1 @@ -474,30 +467,14 @@ with /* TPC-DS query86a.tpl 0.11 */ results as d1.d_month_seq between 1193 and 1193+11 and d1.d_date_sk = ws_sold_date_sk and i_item_sk = ws_item_sk - group by i_category,i_class - ) , - - results_rollup as -( select total_sum ,i_category ,i_class, g_category, g_class, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum, i_category, NULL as i_class, 0 as g_category, 1 as g_class, 1 as lochierarchy from results group by i_category - union - select sum(total_sum) as total_sum, NULL as i_category, NULL as i_class, 1 as g_category, 1 as g_class, 2 as lochierarchy from results) - select - total_sum ,i_category ,i_class, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_class = 0 then i_category end - order by total_sum desc) as rank_within_parent - from - results_rollup + group by rollup(i_category,i_class) order by lochierarchy desc, - case when lochierarchy = 0 then i_category end, - rank_within_parent + case when grouping(i_category)+grouping(i_class) = 0 then i_category end, + rank_within_parent limit 100; --- end template query86a.tpl query 11 in stream 0 +-- end template query86.tpl query 11 in stream 0 -- start template query1.tpl query 12 in stream 0 with /* TPC-DS query1.tpl 0.12 */ customer_total_return as (select sr_customer_sk as ctr_customer_sk @@ -603,14 +580,13 @@ select /* TPC-DS query43.tpl 0.15 */ s_store_name, s_store_id, limit 100; -- end template query43.tpl query 15 in stream 0 --- start template query27a.tpl query 16 in stream 0 -with /* TPC-DS query27a.tpl 0.16 */ results as - (select i_item_id, - s_state, 0 as g_state, - ss_quantity agg1, - ss_list_price agg2, - ss_coupon_amt agg3, - ss_sales_price agg4 +-- start template query27.tpl query 16 in stream 0 +select /* TPC-DS query27.tpl 0.16 */ i_item_id, + s_state, grouping(s_state) g_state, + avg(ss_quantity) agg1, + avg(ss_list_price) agg2, + avg(ss_coupon_amt) agg3, + avg(ss_sales_price) agg4 from store_sales, customer_demographics, date_dim, store, item where ss_sold_date_sk = d_date_sk and ss_item_sk = i_item_sk and @@ -621,25 +597,12 @@ with /* TPC-DS query27a.tpl 0.16 */ results as cd_education_status = 'Unknown' and d_year = 1999 and s_state in ('GA','NY', 'OH', 'WA', 'MI', 'LA') - ) - - select i_item_id, - s_state, g_state, agg1, agg2, agg3, agg4 - from ( - select i_item_id, s_state, 0 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4 from results - group by i_item_id, s_state - union all - select i_item_id, NULL AS s_state, 1 AS g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as s_state, 1 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - ) foo - order by i_item_id, s_state + group by rollup (i_item_id, s_state) + order by i_item_id + ,s_state limit 100; --- end template query27a.tpl query 16 in stream 0 +-- end template query27.tpl query 16 in stream 0 -- start template query94.tpl query 17 in stream 0 select /* TPC-DS query94.tpl 0.17 */ count(distinct ws_order_number) as "order count" @@ -875,14 +838,16 @@ order by cs1.product_name ,cs2.s1; -- end template query64.tpl query 20 in stream 0 --- start template query36a.tpl query 21 in stream 0 -with /* TPC-DS query36a.tpl 0.21 */ results as - (select - sum(ss_net_profit) as ss_net_profit, sum(ss_ext_sales_price) as ss_ext_sales_price, +-- start template query36.tpl query 21 in stream 0 +select /* TPC-DS query36.tpl 0.21 */ sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin ,i_category ,i_class - ,0 as g_category, 0 as g_class + ,grouping(i_category)+grouping(i_class) as lochierarchy + ,rank() over ( + partition by grouping(i_category)+grouping(i_class), + case when grouping(i_class) = 0 then i_category end + order by sum(ss_net_profit)/sum(ss_ext_sales_price) asc) as rank_within_parent from store_sales ,date_dim d1 @@ -890,33 +855,19 @@ with /* TPC-DS query36a.tpl 0.21 */ results as ,store where d1.d_year = 1998 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and s_state in ('SD','MO','GA','WA', + and d1.d_date_sk = ss_sold_date_sk + and i_item_sk = ss_item_sk + and s_store_sk = ss_store_sk + and s_state in ('SD','MO','GA','WA', 'MI','LA','OH','SC') - group by i_category,i_class) - , - results_rollup as - (select gross_margin ,i_category ,i_class,0 as t_category, 0 as t_class, 0 as lochierarchy from results - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - i_category, NULL AS i_class, 0 as t_category, 1 as t_class, 1 as lochierarchy from results group by i_category - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - NULL AS i_category ,NULL AS i_class, 1 as t_category, 1 as t_class, 2 as lochierarchy from results) - select - gross_margin ,i_category ,i_class, lochierarchy,rank() over ( - partition by lochierarchy, case when t_class = 0 then i_category end - order by gross_margin asc) as rank_within_parent - from results_rollup + group by rollup(i_category,i_class) order by lochierarchy desc - ,case when lochierarchy = 0 then i_category end + ,case when grouping(i_category)+grouping(i_class) = 0 then i_category end ,rank_within_parent limit 100; --- end template query36a.tpl query 21 in stream 0 +-- end template query36.tpl query 21 in stream 0 -- start template query33.tpl query 22 in stream 0 with /* TPC-DS query33.tpl 0.22 */ ss as ( select @@ -1484,96 +1435,46 @@ order by substring(r_reason_desc,1,20) limit 100; -- end template query85.tpl query 33 in stream 0 --- start template query70a.tpl query 34 in stream 0 -with /* TPC-DS query70a.tpl 0.34 */ results as -( select - sum(ss_net_profit) as total_sum ,s_state ,s_county, 0 as gstate, 0 as g_county +-- start template query70.tpl query 34 in stream 0 +select /* TPC-DS query70.tpl 0.34 */ + sum(ss_net_profit) as total_sum + ,s_state + ,s_county + ,grouping(s_state)+grouping(s_county) as lochierarchy + ,rank() over ( + partition by grouping(s_state)+grouping(s_county), + case when grouping(s_county) = 0 then s_state end + order by sum(ss_net_profit) desc) as rank_within_parent from store_sales - ,date_dim d1 - ,store + ,date_dim d1 + ,store where - d1.d_month_seq between 1192 and 1192 + 11 + d1.d_month_seq between 1192 and 1192+11 and d1.d_date_sk = ss_sold_date_sk and s_store_sk = ss_store_sk and s_state in - ( select s_state - from (select s_state as s_state, - rank() over ( partition by s_state order by sum(ss_net_profit) desc) as ranking - from store_sales, store, date_dim - where d_month_seq between 1192 and 1192 + 11 - and d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk + ( select s_state + from (select s_state as s_state, + rank() over ( partition by s_state order by sum(ss_net_profit) desc) as ranking + from store_sales, store, date_dim + where d_month_seq between 1192 and 1192+11 + and d_date_sk = ss_sold_date_sk + and s_store_sk = ss_store_sk group by s_state - ) tmp1 - where ranking <= 5) - group by s_state,s_county) , - results_rollup as -(select total_sum ,s_state ,s_county, 0 as g_state, 0 as g_county, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum,s_state, NULL as s_county, 0 as g_state, 1 as g_county, 1 as lochierarchy from results group by s_state - union - select sum(total_sum) as total_sum ,NULL as s_state ,NULL as s_county, 1 as g_state, 1 as g_county, 2 as lochierarchy from results) - select total_sum ,s_state ,s_county, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_county = 0 then s_state end - order by total_sum desc) as rank_within_parent - from results_rollup + ) tmp1 + where ranking <= 5 + ) + group by rollup(s_state,s_county) order by - lochierarchy desc - ,case when lochierarchy = 0 then s_state end + lochierarchy desc + ,case when grouping(s_state)+grouping(s_county) = 0 then s_state end ,rank_within_parent limit 100; --- end template query70a.tpl query 34 in stream 0 --- start template query67a.tpl query 35 in stream 0 -with /* TPC-DS query67a.tpl 0.35 */ results as -( select i_category ,i_class ,i_brand ,i_product_name ,d_year ,d_qoy ,d_moy ,s_store_id - ,sum(coalesce(ss_sales_price*ss_quantity,0)) sumsales - from store_sales ,date_dim ,store ,item - where ss_sold_date_sk=d_date_sk - and ss_item_sk=i_item_sk - and ss_store_sk = s_store_sk - and d_month_seq between 1180 and 1180 + 11 - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy,s_store_id) - , - results_rollup as - (select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, s_store_id, sumsales - from results - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy - union all - select i_category, i_class, i_brand, i_product_name, d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year - union all - select i_category, i_class, i_brand, i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name - union all - select i_category, i_class, i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand - union all - select i_category, i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class - union all - select i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category - union all - select null i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results) - - select * +-- end template query70.tpl query 34 in stream 0 +-- start template query67.tpl query 35 in stream 0 +select /* TPC-DS query67.tpl 0.35 */ * from (select i_category ,i_class ,i_brand @@ -1584,7 +1485,24 @@ from (select i_category ,s_store_id ,sumsales ,rank() over (partition by i_category order by sumsales desc) rk - from results_rollup) dw2 + from (select i_category + ,i_class + ,i_brand + ,i_product_name + ,d_year + ,d_qoy + ,d_moy + ,s_store_id + ,sum(coalesce(ss_sales_price*ss_quantity,0)) sumsales + from store_sales + ,date_dim + ,store + ,item + where ss_sold_date_sk=d_date_sk + and ss_item_sk=i_item_sk + and ss_store_sk = s_store_sk + and d_month_seq between 1180 and 1180+11 + group by rollup(i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy,s_store_id))dw1) dw2 where rk <= 100 order by i_category ,i_class @@ -1598,7 +1516,7 @@ order by i_category ,rk limit 100; --- end template query67a.tpl query 35 in stream 0 +-- end template query67.tpl query 35 in stream 0 -- start template query28.tpl query 36 in stream 0 select /* TPC-DS query28.tpl 0.36 */ * from (select avg(ss_list_price) B1_LP @@ -2174,8 +2092,8 @@ order by item_sk limit 100; -- end template query51.tpl query 46 in stream 0 --- start template query35a.tpl query 47 in stream 0 -select /* TPC-DS query35a.tpl 0.47 */ +-- start template query35.tpl query 47 in stream 0 +select /* TPC-DS query35.tpl 0.47 */ ca_state, cd_gender, cd_marital_status, @@ -2205,21 +2123,18 @@ select /* TPC-DS query35a.tpl 0.47 */ ss_sold_date_sk = d_date_sk and d_year = 1999 and d_qoy < 4) and - exists (select * from - (select ws_bill_customer_sk customsk + (exists (select * from web_sales,date_dim - where + where c.c_customer_sk = ws_bill_customer_sk and ws_sold_date_sk = d_date_sk and d_year = 1999 and - d_qoy < 4 - union all - select cs_ship_customer_sk customsk + d_qoy < 4) or + exists (select * from catalog_sales,date_dim - where + where c.c_customer_sk = cs_ship_customer_sk and cs_sold_date_sk = d_date_sk and d_year = 1999 and - d_qoy < 4)x - where x.customsk = c.c_customer_sk) + d_qoy < 4)) group by ca_state, cd_gender, cd_marital_status, @@ -2234,7 +2149,7 @@ select /* TPC-DS query35a.tpl 0.47 */ cd_dep_college_count limit 100; --- end template query35a.tpl query 47 in stream 0 +-- end template query35.tpl query 47 in stream 0 -- start template query49.tpl query 48 in stream 0 select /* TPC-DS query49.tpl 0.48 */ channel, item, return_ratio, return_rank, currency_rank from (select @@ -2636,9 +2551,8 @@ select /* TPC-DS query38.tpl 0.54 */ count(*) from ( limit 100; -- end template query38.tpl query 54 in stream 0 --- start template query22a.tpl query 55 in stream 0 -with /* TPC-DS query22a.tpl 0.55 */ results as -(select i_product_name +-- start template query22.tpl query 55 in stream 0 +select /* TPC-DS query22.tpl 0.55 */ i_product_name ,i_brand ,i_class ,i_category @@ -2646,37 +2560,17 @@ with /* TPC-DS query22a.tpl 0.55 */ results as from inventory ,date_dim ,item --- ,warehouse - where inv_date_sk=d_date_sk + where inv_date_sk=d_date_sk and inv_item_sk=i_item_sk --- and inv_warehouse_sk = w_warehouse_sk and d_month_seq between 1209 and 1209 + 11 - group by i_product_name,i_brand,i_class,i_category), -results_rollup as -(select i_product_name, i_brand, i_class, i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class,i_category -union all -select i_product_name, i_brand, i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class -union all -select i_product_name, i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand -union all -select i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name -union all -select null i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results) - select i_product_name, i_brand, i_class, i_category,qoh - from results_rollup - order by qoh, i_product_name, i_brand, i_class, i_category + group by rollup(i_product_name + ,i_brand + ,i_class + ,i_category) +order by qoh, i_product_name, i_brand, i_class, i_category limit 100; --- end template query22a.tpl query 55 in stream 0 +-- end template query22.tpl query 55 in stream 0 -- start template query89.tpl query 56 in stream 0 select /* TPC-DS query89.tpl 0.56 */ * from( @@ -3296,8 +3190,8 @@ with /* TPC-DS query23.tpl 0.68 part2 */ frequent_ss_items as limit 100; -- end template query23.tpl query 68 in stream 0 --- start template query14a.tpl query 69 in stream 0 -with /* TPC-DS query14a.tpl 0.69 */ cross_items as +-- start template query14.tpl query 69 in stream 0 +with /* TPC-DS query14.tpl 0.69 */ cross_items as (select i_item_sk ss_item_sk from item, (select iss.i_brand_id brand_id @@ -3328,7 +3222,7 @@ with /* TPC-DS query14a.tpl 0.69 */ cross_items as ,date_dim d3 where ws_item_sk = iws.i_item_sk and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 2000 AND 2000 + 2) x + and d3.d_year between 2000 AND 2000 + 2) where i_brand_id = brand_id and i_class_id = class_id and i_category_id = category_id @@ -3340,7 +3234,7 @@ with /* TPC-DS query14a.tpl 0.69 */ cross_items as from store_sales ,date_dim where ss_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2 + and d_year between 2000 and 2000 + 2 union all select cs_quantity quantity ,cs_list_price list_price @@ -3355,10 +3249,8 @@ with /* TPC-DS query14a.tpl 0.69 */ cross_items as ,date_dim where ws_sold_date_sk = d_date_sk and d_year between 2000 and 2000 + 2) x) -, - results AS -(select channel, i_brand_id, i_class_id, i_category_id, sum(sales) sum_sales, sum(number_sales) number_sales - from ( + select channel, i_brand_id,i_class_id,i_category_id,sum(sales), sum(number_sales) + from( select 'store' channel, i_brand_id,i_class_id ,i_category_id,sum(ss_quantity*ss_list_price) sales , count(*) number_sales @@ -3397,25 +3289,10 @@ with /* TPC-DS query14a.tpl 0.69 */ cross_items as group by i_brand_id,i_class_id,i_category_id having sum(ws_quantity*ws_list_price) > (select average_sales from avg_sales) ) y - group by channel, i_brand_id,i_class_id,i_category_id) - - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales -from ( - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales from results - union - select channel, i_brand_id, i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id, i_class_id - union - select channel, i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id - union - select channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel - union - select null as channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results) z -order by channel, i_brand_id, i_class_id, i_category_id + group by rollup (channel, i_brand_id,i_class_id,i_category_id) + order by channel,i_brand_id,i_class_id,i_category_id limit 100; -with /* TPC-DS query14a.tpl 0.69 part2 */ cross_items as +with /* TPC-DS query14.tpl 0.69 part2 */ cross_items as (select i_item_sk ss_item_sk from item, (select iss.i_brand_id brand_id @@ -3485,7 +3362,7 @@ with /* TPC-DS query14a.tpl 0.69 part2 */ cross_items as ,last_year.i_category_id ly_category ,last_year.sales ly_sales ,last_year.number_sales ly_number_sales -from + from (select 'store' channel, i_brand_id,i_class_id,i_category_id ,sum(ss_quantity*ss_list_price) sales, count(*) number_sales from store_sales @@ -3522,7 +3399,7 @@ from order by this_year.channel, this_year.i_brand_id, this_year.i_class_id, this_year.i_category_id limit 100; --- end template query14a.tpl query 69 in stream 0 +-- end template query14.tpl query 69 in stream 0 -- start template query57.tpl query 70 in stream 0 with /* TPC-DS query57.tpl 0.70 */ v1 as( select i_category, i_brand, @@ -3853,8 +3730,8 @@ from ((select distinct c_last_name, c_first_name, d_date ; -- end template query87.tpl query 77 in stream 0 --- start template query77a.tpl query 78 in stream 0 -with /* TPC-DS query77a.tpl 0.78 */ ss as +-- start template query77.tpl query 78 in stream 0 +with /* TPC-DS query77.tpl 0.78 */ ss as (select s_store_sk, sum(ss_ext_sales_price) as sales, sum(ss_net_profit) as profit @@ -3863,7 +3740,7 @@ with /* TPC-DS query77a.tpl 0.78 */ ss as store where ss_sold_date_sk = d_date_sk and d_date between cast('1999-08-16' as date) - and dateadd(day,30,cast('1999-08-16' as date)) + and dateadd(day,30,cast('1999-08-16' as date)) and ss_store_sk = s_store_sk group by s_store_sk) , @@ -3876,7 +3753,7 @@ with /* TPC-DS query77a.tpl 0.78 */ ss as store where sr_returned_date_sk = d_date_sk and d_date between cast('1999-08-16' as date) - and dateadd(day,30,cast('1999-08-16' as date)) + and dateadd(day,30,cast('1999-08-16' as date)) and sr_store_sk = s_store_sk group by s_store_sk), cs as @@ -3887,7 +3764,7 @@ with /* TPC-DS query77a.tpl 0.78 */ ss as date_dim where cs_sold_date_sk = d_date_sk and d_date between cast('1999-08-16' as date) - and dateadd(day,30,cast('1999-08-16' as date)) + and dateadd(day,30,cast('1999-08-16' as date)) group by cs_call_center_sk ), cr as @@ -3898,8 +3775,9 @@ with /* TPC-DS query77a.tpl 0.78 */ ss as date_dim where cr_returned_date_sk = d_date_sk and d_date between cast('1999-08-16' as date) - and dateadd(day,30,cast('1999-08-16' as date)) - group by cr_call_center_sk), + and dateadd(day,30,cast('1999-08-16' as date)) + group by cr_call_center_sk + ), ws as ( select wp_web_page_sk, sum(ws_ext_sales_price) as sales, @@ -3909,7 +3787,7 @@ with /* TPC-DS query77a.tpl 0.78 */ ss as web_page where ws_sold_date_sk = d_date_sk and d_date between cast('1999-08-16' as date) - and dateadd(day,30,cast('1999-08-16' as date)) + and dateadd(day,30,cast('1999-08-16' as date)) and ws_web_page_sk = wp_web_page_sk group by wp_web_page_sk), wr as @@ -3921,12 +3799,10 @@ with /* TPC-DS query77a.tpl 0.78 */ ss as web_page where wr_returned_date_sk = d_date_sk and d_date between cast('1999-08-16' as date) - and dateadd(day,30,cast('1999-08-16' as date)) + and dateadd(day,30,cast('1999-08-16' as date)) and wr_web_page_sk = wp_web_page_sk group by wp_web_page_sk) - , - results as - (select channel + select channel , id , sum(sales) as sales , sum(returns) as returns @@ -3956,20 +3832,12 @@ with /* TPC-DS query77a.tpl 0.78 */ ss as from ws left join wr on ws.wp_web_page_sk = wr.wp_web_page_sk ) x - group by channel, id ) - - select * - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results -) foo -order by channel, id + group by rollup (channel, id) + order by channel + ,id limit 100; --- end template query77a.tpl query 78 in stream 0 +-- end template query77.tpl query 78 in stream 0 -- start template query73.tpl query 79 in stream 0 select /* TPC-DS query73.tpl 0.79 */ c_last_name ,c_first_name @@ -4347,20 +4215,20 @@ select /* TPC-DS query79.tpl 0.89 */ limit 100; -- end template query79.tpl query 89 in stream 0 --- start template query18a.tpl query 90 in stream 0 -with /* TPC-DS query18a.tpl 0.90 */ results as - (select i_item_id, +-- start template query18.tpl query 90 in stream 0 +select /* TPC-DS query18.tpl 0.90 */ i_item_id, ca_country, ca_state, ca_county, - cast(cs_quantity as decimal(12,2)) agg1, - cast(cs_list_price as decimal(12,2)) agg2, - cast(cs_coupon_amt as decimal(12,2)) agg3, - cast(cs_sales_price as decimal(12,2)) agg4, - cast(cs_net_profit as decimal(12,2)) agg5, - cast(c_birth_year as decimal(12,2)) agg6, - cast(cd1.cd_dep_count as decimal(12,2)) agg7 - from catalog_sales, customer_demographics cd1, customer_demographics cd2, customer, customer_address, date_dim, item + avg( cast(cs_quantity as decimal(12,2))) agg1, + avg( cast(cs_list_price as decimal(12,2))) agg2, + avg( cast(cs_coupon_amt as decimal(12,2))) agg3, + avg( cast(cs_sales_price as decimal(12,2))) agg4, + avg( cast(cs_net_profit as decimal(12,2))) agg5, + avg( cast(c_birth_year as decimal(12,2))) agg6, + avg( cast(cd1.cd_dep_count as decimal(12,2))) agg7 + from catalog_sales, customer_demographics cd1, + customer_demographics cd2, customer, customer_address, date_dim, item where cs_sold_date_sk = d_date_sk and cs_item_sk = i_item_sk and cs_bill_cdemo_sk = cd1.cd_demo_sk and @@ -4371,38 +4239,16 @@ with /* TPC-DS query18a.tpl 0.90 */ results as c_current_addr_sk = ca_address_sk and c_birth_month in (3,9,1,8,12,2) and d_year = 2000 and - ca_state in ('LA','TX','OH','VA','ND','IL','MO') - ) - select i_item_id, ca_country, ca_state, ca_county, agg1, agg2, agg3, agg4, agg5, agg6, agg7 - from ( - select i_item_id, ca_country, ca_state, ca_county, avg(agg1) agg1, - avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state, ca_county - union all - select i_item_id, ca_country, ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state - union all - select i_item_id, ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country - union all - select i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - ) foo - order by ca_country, ca_state, ca_county, i_item_id + ca_state in ('LA','TX','OH' + ,'VA','ND','IL','MO') + group by rollup (i_item_id, ca_country, ca_state, ca_county) + order by ca_country, + ca_state, + ca_county, + i_item_id limit 100; --- end template query18a.tpl query 90 in stream 0 +-- end template query18.tpl query 90 in stream 0 -- start template query13.tpl query 91 in stream 0 select /* TPC-DS query13.tpl 0.91 */ avg(ss_quantity) ,avg(ss_ext_sales_price) @@ -4866,8 +4712,8 @@ order by promotions, total limit 100; -- end template query61.tpl query 97 in stream 0 --- start template query5a.tpl query 98 in stream 0 -with /* TPC-DS query5a.tpl 0.98 */ ssr as +-- start template query5.tpl query 98 in stream 0 +with /* TPC-DS query5.tpl 0.98 */ ssr as (select s_store_id, sum(sales_price) as sales, sum(profit) as profit, @@ -4961,9 +4807,7 @@ with /* TPC-DS query5a.tpl 0.98 */ ssr as and dateadd(day,14,cast('2002-08-26' as date)) and wsr_web_site_sk = web_site_sk group by web_site_id) - , - results as - (select channel + select channel , id , sum(sales) as sales , sum(returns) as returns @@ -4990,17 +4834,12 @@ with /* TPC-DS query5a.tpl 0.98 */ ssr as , (profit - profit_loss) as profit from wsr ) x - group by channel, id) - select channel, id, sales, returns, profit from ( - select channel, id, sales, returns, profit from results - union - select channel, null as id, sum(sales), sum(returns), sum(profit) from results group by channel - union - select null as channel, null as id, sum(sales), sum(returns), sum(profit) from results) foo -order by channel, id -limit 100; + group by rollup (channel, id) + order by channel + ,id + limit 100; --- end template query5a.tpl query 98 in stream 0 +-- end template query5.tpl query 98 in stream 0 -- start template query76.tpl query 99 in stream 0 select /* TPC-DS query76.tpl 0.99 */ channel, col_name, d_year, d_qoy, i_category, COUNT(*) sales_cnt, SUM(ext_sales_price) sales_amt FROM ( SELECT 'store' as channel, 'ss_cdemo_sk' col_name, d_year, d_qoy, i_category, ss_ext_sales_price ext_sales_price diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/1TB/queries/query_1.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/1TB/queries/query_1.sql deleted file mode 100644 index 1b79b2cf..00000000 --- a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/1TB/queries/query_1.sql +++ /dev/null @@ -1,5027 +0,0 @@ --- start template query83.tpl query 1 in stream 1 -with /* TPC-DS query83.tpl 0.96 */ sr_items as - (select i_item_id item_id, - sum(sr_return_quantity) sr_item_qty - from store_returns, - item, - date_dim - where sr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2002-02-10','2002-10-03','2002-11-02'))) - and sr_returned_date_sk = d_date_sk - group by i_item_id), - cr_items as - (select i_item_id item_id, - sum(cr_return_quantity) cr_item_qty - from catalog_returns, - item, - date_dim - where cr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2002-02-10','2002-10-03','2002-11-02'))) - and cr_returned_date_sk = d_date_sk - group by i_item_id), - wr_items as - (select i_item_id item_id, - sum(wr_return_quantity) wr_item_qty - from web_returns, - item, - date_dim - where wr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2002-02-10','2002-10-03','2002-11-02'))) - and wr_returned_date_sk = d_date_sk - group by i_item_id) - select sr_items.item_id - ,sr_item_qty - ,sr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 sr_dev - ,cr_item_qty - ,cr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 cr_dev - ,wr_item_qty - ,wr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 wr_dev - ,(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 average - from sr_items - ,cr_items - ,wr_items - where sr_items.item_id=cr_items.item_id - and sr_items.item_id=wr_items.item_id - order by sr_items.item_id - ,sr_item_qty - limit 100; - --- end template query83.tpl query 1 in stream 1 --- start template query32.tpl query 2 in stream 1 -select /* TPC-DS query32.tpl 0.7 */ sum(cs_ext_discount_amt) as "excess discount amount" -from - catalog_sales - ,item - ,date_dim -where -i_manufact_id = 950 -and i_item_sk = cs_item_sk -and d_date between '2001-01-06' and - dateadd(day,90,cast('2001-01-06' as date)) -and d_date_sk = cs_sold_date_sk -and cs_ext_discount_amt - > ( - select - 1.3 * avg(cs_ext_discount_amt) - from - catalog_sales - ,date_dim - where - cs_item_sk = i_item_sk - and d_date between '2001-01-06' and - dateadd(day,90,cast('2001-01-06' as date)) - and d_date_sk = cs_sold_date_sk - ) -limit 100; - --- end template query32.tpl query 2 in stream 1 --- start template query30.tpl query 3 in stream 1 -with /* TPC-DS query30.tpl 0.75 */ customer_total_return as - (select wr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(wr_return_amt) as ctr_total_return - from web_returns - ,date_dim - ,customer_address - where wr_returned_date_sk = d_date_sk - and d_year =2000 - and wr_returning_addr_sk = ca_address_sk - group by wr_returning_customer_sk - ,ca_state) - select c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'MS' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return -limit 100; - --- end template query30.tpl query 3 in stream 1 --- start template query92.tpl query 4 in stream 1 -select /* TPC-DS query92.tpl 0.44 */ - sum(ws_ext_discount_amt) as "Excess Discount Amount" -from - web_sales - ,item - ,date_dim -where -i_manufact_id = 343 -and i_item_sk = ws_item_sk -and d_date between '2002-02-17' and - dateadd(day,90,cast('2002-02-17' as date)) -and d_date_sk = ws_sold_date_sk -and ws_ext_discount_amt - > ( - SELECT - 1.3 * avg(ws_ext_discount_amt) - FROM - web_sales - ,date_dim - WHERE - ws_item_sk = i_item_sk - and d_date between '2002-02-17' and - dateadd(day,90,cast('2002-02-17' as date)) - and d_date_sk = ws_sold_date_sk - ) -order by sum(ws_ext_discount_amt) -limit 100; - --- end template query92.tpl query 4 in stream 1 --- start template query66.tpl query 5 in stream 1 -select /* TPC-DS query66.tpl 0.39 */ - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - ,sum(jan_sales) as jan_sales - ,sum(feb_sales) as feb_sales - ,sum(mar_sales) as mar_sales - ,sum(apr_sales) as apr_sales - ,sum(may_sales) as may_sales - ,sum(jun_sales) as jun_sales - ,sum(jul_sales) as jul_sales - ,sum(aug_sales) as aug_sales - ,sum(sep_sales) as sep_sales - ,sum(oct_sales) as oct_sales - ,sum(nov_sales) as nov_sales - ,sum(dec_sales) as dec_sales - ,sum(jan_sales/w_warehouse_sq_ft) as jan_sales_per_sq_foot - ,sum(feb_sales/w_warehouse_sq_ft) as feb_sales_per_sq_foot - ,sum(mar_sales/w_warehouse_sq_ft) as mar_sales_per_sq_foot - ,sum(apr_sales/w_warehouse_sq_ft) as apr_sales_per_sq_foot - ,sum(may_sales/w_warehouse_sq_ft) as may_sales_per_sq_foot - ,sum(jun_sales/w_warehouse_sq_ft) as jun_sales_per_sq_foot - ,sum(jul_sales/w_warehouse_sq_ft) as jul_sales_per_sq_foot - ,sum(aug_sales/w_warehouse_sq_ft) as aug_sales_per_sq_foot - ,sum(sep_sales/w_warehouse_sq_ft) as sep_sales_per_sq_foot - ,sum(oct_sales/w_warehouse_sq_ft) as oct_sales_per_sq_foot - ,sum(nov_sales/w_warehouse_sq_ft) as nov_sales_per_sq_foot - ,sum(dec_sales/w_warehouse_sq_ft) as dec_sales_per_sq_foot - ,sum(jan_net) as jan_net - ,sum(feb_net) as feb_net - ,sum(mar_net) as mar_net - ,sum(apr_net) as apr_net - ,sum(may_net) as may_net - ,sum(jun_net) as jun_net - ,sum(jul_net) as jul_net - ,sum(aug_net) as aug_net - ,sum(sep_net) as sep_net - ,sum(oct_net) as oct_net - ,sum(nov_net) as nov_net - ,sum(dec_net) as dec_net - from ( - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'MSC' || ',' || 'AIRBORNE' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then ws_sales_price* ws_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then ws_sales_price* ws_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then ws_sales_price* ws_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then ws_sales_price* ws_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then ws_sales_price* ws_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then ws_sales_price* ws_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then ws_sales_price* ws_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then ws_sales_price* ws_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then ws_sales_price* ws_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then ws_sales_price* ws_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then ws_sales_price* ws_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then ws_sales_price* ws_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then ws_net_paid_inc_tax * ws_quantity else 0 end) as dec_net - from - web_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - ws_warehouse_sk = w_warehouse_sk - and ws_sold_date_sk = d_date_sk - and ws_sold_time_sk = t_time_sk - and ws_ship_mode_sk = sm_ship_mode_sk - and d_year = 2002 - and t_time between 27365 and 27365+28800 - and sm_carrier in ('MSC','AIRBORNE') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - union all - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'MSC' || ',' || 'AIRBORNE' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then cs_ext_sales_price* cs_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then cs_ext_sales_price* cs_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then cs_ext_sales_price* cs_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then cs_ext_sales_price* cs_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then cs_ext_sales_price* cs_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then cs_ext_sales_price* cs_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then cs_ext_sales_price* cs_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then cs_ext_sales_price* cs_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then cs_ext_sales_price* cs_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then cs_ext_sales_price* cs_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then cs_ext_sales_price* cs_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then cs_ext_sales_price* cs_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then cs_net_profit * cs_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then cs_net_profit * cs_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then cs_net_profit * cs_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then cs_net_profit * cs_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then cs_net_profit * cs_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then cs_net_profit * cs_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then cs_net_profit * cs_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then cs_net_profit * cs_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then cs_net_profit * cs_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then cs_net_profit * cs_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then cs_net_profit * cs_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then cs_net_profit * cs_quantity else 0 end) as dec_net - from - catalog_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and cs_sold_time_sk = t_time_sk - and cs_ship_mode_sk = sm_ship_mode_sk - and d_year = 2002 - and t_time between 27365 AND 27365+28800 - and sm_carrier in ('MSC','AIRBORNE') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - ) x - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - order by w_warehouse_name - limit 100; - --- end template query66.tpl query 5 in stream 1 --- start template query84.tpl query 6 in stream 1 -select /* TPC-DS query84.tpl 0.80 */ c_customer_id as customer_id - , coalesce(c_last_name,'') || ', ' || coalesce(c_first_name,'') as customername - from customer - ,customer_address - ,customer_demographics - ,household_demographics - ,income_band - ,store_returns - where ca_city = 'Belmont' - and c_current_addr_sk = ca_address_sk - and ib_lower_bound >= 42907 - and ib_upper_bound <= 42907 + 50000 - and ib_income_band_sk = hd_income_band_sk - and cd_demo_sk = c_current_cdemo_sk - and hd_demo_sk = c_current_hdemo_sk - and sr_cdemo_sk = cd_demo_sk - order by c_customer_id - limit 100; - --- end template query84.tpl query 6 in stream 1 --- start template query98.tpl query 7 in stream 1 -select /* TPC-DS query98.tpl 0.32 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ss_ext_sales_price) as itemrevenue - ,sum(ss_ext_sales_price)*100/sum(sum(ss_ext_sales_price)) over - (partition by i_class) as revenueratio -from - store_sales - ,item - ,date_dim -where - ss_item_sk = i_item_sk - and i_category in ('Jewelry', 'Sports', 'Music') - and ss_sold_date_sk = d_date_sk - and d_date between cast('1999-03-18' as date) - and dateadd(day,30,cast('1999-03-18' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio; - --- end template query98.tpl query 7 in stream 1 --- start template query58.tpl query 8 in stream 1 -with /* TPC-DS query58.tpl 0.19 */ ss_items as - (select i_item_id item_id - ,sum(ss_ext_sales_price) ss_item_rev - from store_sales - ,item - ,date_dim - where ss_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '2001-05-18')) - and ss_sold_date_sk = d_date_sk - group by i_item_id), - cs_items as - (select i_item_id item_id - ,sum(cs_ext_sales_price) cs_item_rev - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '2001-05-18')) - and cs_sold_date_sk = d_date_sk - group by i_item_id), - ws_items as - (select i_item_id item_id - ,sum(ws_ext_sales_price) ws_item_rev - from web_sales - ,item - ,date_dim - where ws_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq =(select d_week_seq - from date_dim - where d_date = '2001-05-18')) - and ws_sold_date_sk = d_date_sk - group by i_item_id) - select ss_items.item_id - ,ss_item_rev - ,ss_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ss_dev - ,cs_item_rev - ,cs_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 cs_dev - ,ws_item_rev - ,ws_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ws_dev - ,(ss_item_rev+cs_item_rev+ws_item_rev)/3 average - from ss_items,cs_items,ws_items - where ss_items.item_id=cs_items.item_id - and ss_items.item_id=ws_items.item_id - and ss_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - and ss_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and cs_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and cs_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and ws_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and ws_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - order by item_id - ,ss_item_rev - limit 100; - --- end template query58.tpl query 8 in stream 1 --- start template query16.tpl query 9 in stream 1 -select /* TPC-DS query16.tpl 0.25 */ - count(distinct cs_order_number) as "order count" - ,sum(cs_ext_ship_cost) as "total shipping cost" - ,sum(cs_net_profit) as "total net profit" -from - catalog_sales cs1 - ,date_dim - ,customer_address - ,call_center -where - d_date between '2000-3-01' and - dateadd(day, 60, cast('2000-3-01' as date)) -and cs1.cs_ship_date_sk = d_date_sk -and cs1.cs_ship_addr_sk = ca_address_sk -and ca_state = 'ID' -and cs1.cs_call_center_sk = cc_call_center_sk -and cc_county in ('Kittitas County','Walker County','Huron County','Marshall County', - 'Williamson County' -) -and exists (select * - from catalog_sales cs2 - where cs1.cs_order_number = cs2.cs_order_number - and cs1.cs_warehouse_sk <> cs2.cs_warehouse_sk) -and not exists(select * - from catalog_returns cr1 - where cs1.cs_order_number = cr1.cr_order_number) -order by count(distinct cs_order_number) -limit 100; - --- end template query16.tpl query 9 in stream 1 --- start template query77a.tpl query 10 in stream 1 -with /* TPC-DS query77a.tpl 0.78 */ ss as - (select s_store_sk, - sum(ss_ext_sales_price) as sales, - sum(ss_net_profit) as profit - from store_sales, - date_dim, - store - where ss_sold_date_sk = d_date_sk - and d_date between cast('1999-08-16' as date) - and dateadd(day,30,cast('1999-08-16' as date)) - and ss_store_sk = s_store_sk - group by s_store_sk) - , - sr as - (select s_store_sk, - sum(sr_return_amt) as returns, - sum(sr_net_loss) as profit_loss - from store_returns, - date_dim, - store - where sr_returned_date_sk = d_date_sk - and d_date between cast('1999-08-16' as date) - and dateadd(day,30,cast('1999-08-16' as date)) - and sr_store_sk = s_store_sk - group by s_store_sk), - cs as - (select cs_call_center_sk, - sum(cs_ext_sales_price) as sales, - sum(cs_net_profit) as profit - from catalog_sales, - date_dim - where cs_sold_date_sk = d_date_sk - and d_date between cast('1999-08-16' as date) - and dateadd(day,30,cast('1999-08-16' as date)) - group by cs_call_center_sk - ), - cr as - (select cr_call_center_sk, - sum(cr_return_amount) as returns, - sum(cr_net_loss) as profit_loss - from catalog_returns, - date_dim - where cr_returned_date_sk = d_date_sk - and d_date between cast('1999-08-16' as date) - and dateadd(day,30,cast('1999-08-16' as date)) - group by cr_call_center_sk), - ws as - ( select wp_web_page_sk, - sum(ws_ext_sales_price) as sales, - sum(ws_net_profit) as profit - from web_sales, - date_dim, - web_page - where ws_sold_date_sk = d_date_sk - and d_date between cast('1999-08-16' as date) - and dateadd(day,30,cast('1999-08-16' as date)) - and ws_web_page_sk = wp_web_page_sk - group by wp_web_page_sk), - wr as - (select wp_web_page_sk, - sum(wr_return_amt) as returns, - sum(wr_net_loss) as profit_loss - from web_returns, - date_dim, - web_page - where wr_returned_date_sk = d_date_sk - and d_date between cast('1999-08-16' as date) - and dateadd(day,30,cast('1999-08-16' as date)) - and wr_web_page_sk = wp_web_page_sk - group by wp_web_page_sk) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , ss.s_store_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ss left join sr - on ss.s_store_sk = sr.s_store_sk - union all - select 'catalog channel' as channel - , cs_call_center_sk as id - , sales - , returns - , (profit - profit_loss) as profit - from cs - , cr - union all - select 'web channel' as channel - , ws.wp_web_page_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ws left join wr - on ws.wp_web_page_sk = wr.wp_web_page_sk - ) x - group by channel, id ) - - select * - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results -) foo -order by channel, id - limit 100; - --- end template query77a.tpl query 10 in stream 1 --- start template query40.tpl query 11 in stream 1 -select /* TPC-DS query40.tpl 0.86 */ - w_state - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('1999-04-16' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_before - ,sum(case when (cast(d_date as date) >= cast ('1999-04-16' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_after - from - catalog_sales left outer join catalog_returns on - (cs_order_number = cr_order_number - and cs_item_sk = cr_item_sk) - ,warehouse - ,item - ,date_dim - where - i_current_price between 0.99 and 1.49 - and i_item_sk = cs_item_sk - and cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('1999-04-16' as date)) - and dateadd(day,30,cast ('1999-04-16' as date)) - group by - w_state,i_item_id - order by w_state,i_item_id -limit 100; - --- end template query40.tpl query 11 in stream 1 --- start template query96.tpl query 12 in stream 1 -select /* TPC-DS query96.tpl 0.1 */ count(*) -from store_sales - ,household_demographics - ,time_dim, store -where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 20 - and time_dim.t_minute >= 30 - and household_demographics.hd_dep_count = 6 - and store.s_store_name = 'ese' -order by count(*) -limit 100; - --- end template query96.tpl query 12 in stream 1 --- start template query13.tpl query 13 in stream 1 -select /* TPC-DS query13.tpl 0.91 */ avg(ss_quantity) - ,avg(ss_ext_sales_price) - ,avg(ss_ext_wholesale_cost) - ,sum(ss_ext_wholesale_cost) - from store_sales - ,store - ,customer_demographics - ,household_demographics - ,customer_address - ,date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2001 - and((ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'U' - and cd_education_status = 'Secondary' - and ss_sales_price between 100.00 and 150.00 - and hd_dep_count = 3 - )or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'D' - and cd_education_status = '2 yr Degree' - and ss_sales_price between 50.00 and 100.00 - and hd_dep_count = 1 - ) or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'M' - and cd_education_status = '4 yr Degree' - and ss_sales_price between 150.00 and 200.00 - and hd_dep_count = 1 - )) - and((ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('NM', 'SD', 'NV') - and ss_net_profit between 100 and 200 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('NY', 'MS', 'MO') - and ss_net_profit between 150 and 300 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('OH', 'TX', 'MI') - and ss_net_profit between 50 and 250 - )) -; - --- end template query13.tpl query 13 in stream 1 --- start template query36a.tpl query 14 in stream 1 -with /* TPC-DS query36a.tpl 0.21 */ results as - (select - sum(ss_net_profit) as ss_net_profit, sum(ss_ext_sales_price) as ss_ext_sales_price, - sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin - ,i_category - ,i_class - ,0 as g_category, 0 as g_class - from - store_sales - ,date_dim d1 - ,item - ,store - where - d1.d_year = 2002 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and s_state in ('LA','FL','MO','SD', - 'LA','NM','GA','IN') - group by i_category,i_class) - , - results_rollup as - (select gross_margin ,i_category ,i_class,0 as t_category, 0 as t_class, 0 as lochierarchy from results - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - i_category, NULL AS i_class, 0 as t_category, 1 as t_class, 1 as lochierarchy from results group by i_category - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - NULL AS i_category ,NULL AS i_class, 1 as t_category, 1 as t_class, 2 as lochierarchy from results) - select - gross_margin ,i_category ,i_class, lochierarchy,rank() over ( - partition by lochierarchy, case when t_class = 0 then i_category end - order by gross_margin asc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then i_category end - ,rank_within_parent - limit 100; - --- end template query36a.tpl query 14 in stream 1 --- start template query95.tpl query 15 in stream 1 -with /* TPC-DS query95.tpl 0.43 */ ws_wh as -(select ws1.ws_order_number,ws1.ws_warehouse_sk wh1,ws2.ws_warehouse_sk wh2 - from web_sales ws1,web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) - select - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '1999-2-01' and - dateadd(day,60,cast('1999-2-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'MT' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and ws1.ws_order_number in (select ws_order_number - from ws_wh) -and ws1.ws_order_number in (select wr_order_number - from web_returns,ws_wh - where wr_order_number = ws_wh.ws_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query95.tpl query 15 in stream 1 --- start template query63.tpl query 16 in stream 1 -select /* TPC-DS query63.tpl 0.27 */ * -from (select i_manager_id - ,sum(ss_sales_price) sum_sales - ,avg(sum(ss_sales_price)) over (partition by i_manager_id) avg_monthly_sales - from item - ,store_sales - ,date_dim - ,store - where ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and d_month_seq in (1205,1205+1,1205+2,1205+3,1205+4,1205+5,1205+6,1205+7,1205+8,1205+9,1205+10,1205+11) - and (( i_category in ('Books','Children','Electronics') - and i_class in ('personal','portable','reference','self-help') - and i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) - or( i_category in ('Women','Music','Men') - and i_class in ('accessories','classical','fragrances','pants') - and i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manager_id, d_moy) tmp1 -where case when avg_monthly_sales > 0 then abs (sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 -order by i_manager_id - ,avg_monthly_sales - ,sum_sales -limit 100; - --- end template query63.tpl query 16 in stream 1 --- start template query99.tpl query 17 in stream 1 -select /* TPC-DS query99.tpl 0.94 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 30) and - (cs_ship_date_sk - cs_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 60) and - (cs_ship_date_sk - cs_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 90) and - (cs_ship_date_sk - cs_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - catalog_sales - ,warehouse - ,ship_mode - ,call_center - ,date_dim -where - d_month_seq between 1206 and 1206 + 11 -and cs_ship_date_sk = d_date_sk -and cs_warehouse_sk = w_warehouse_sk -and cs_ship_mode_sk = sm_ship_mode_sk -and cs_call_center_sk = cc_call_center_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -limit 100; - --- end template query99.tpl query 17 in stream 1 --- start template query3.tpl query 18 in stream 1 -select /* TPC-DS query3.tpl 0.45 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_net_profit) sum_agg - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manufact_id = 276 - and dt.d_moy=11 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,sum_agg desc - ,brand_id - limit 100; - --- end template query3.tpl query 18 in stream 1 --- start template query6.tpl query 19 in stream 1 -select /* TPC-DS query6.tpl 0.58 */ a.ca_state state, count(*) cnt - from customer_address a - ,customer c - ,store_sales s - ,date_dim d - ,item i - where a.ca_address_sk = c.c_current_addr_sk - and c.c_customer_sk = s.ss_customer_sk - and s.ss_sold_date_sk = d.d_date_sk - and s.ss_item_sk = i.i_item_sk - and d.d_month_seq = - (select distinct (d_month_seq) - from date_dim - where d_year = 1999 - and d_moy = 2 ) - and i.i_current_price > 1.2 * - (select avg(j.i_current_price) - from item j - where j.i_category = i.i_category) - group by a.ca_state - having count(*) >= 10 - order by cnt, a.ca_state - limit 100; - --- end template query6.tpl query 19 in stream 1 --- start template query12.tpl query 20 in stream 1 -select /* TPC-DS query12.tpl 0.64 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ws_ext_sales_price) as itemrevenue - ,sum(ws_ext_sales_price)*100/sum(sum(ws_ext_sales_price)) over - (partition by i_class) as revenueratio -from - web_sales - ,item - ,date_dim -where - ws_item_sk = i_item_sk - and i_category in ('Women', 'Shoes', 'Jewelry') - and ws_sold_date_sk = d_date_sk - and d_date between cast('2002-04-03' as date) - and dateadd(day,30,cast('2002-04-03' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query12.tpl query 20 in stream 1 --- start template query28.tpl query 21 in stream 1 -select /* TPC-DS query28.tpl 0.36 */ * -from (select avg(ss_list_price) B1_LP - ,count(ss_list_price) B1_CNT - ,count(distinct ss_list_price) B1_CNTD - from store_sales - where ss_quantity between 0 and 5 - and (ss_list_price between 84 and 84+10 - or ss_coupon_amt between 96 and 96+1000 - or ss_wholesale_cost between 16 and 16+20)) B1, - (select avg(ss_list_price) B2_LP - ,count(ss_list_price) B2_CNT - ,count(distinct ss_list_price) B2_CNTD - from store_sales - where ss_quantity between 6 and 10 - and (ss_list_price between 9 and 9+10 - or ss_coupon_amt between 898 and 898+1000 - or ss_wholesale_cost between 50 and 50+20)) B2, - (select avg(ss_list_price) B3_LP - ,count(ss_list_price) B3_CNT - ,count(distinct ss_list_price) B3_CNTD - from store_sales - where ss_quantity between 11 and 15 - and (ss_list_price between 3 and 3+10 - or ss_coupon_amt between 10139 and 10139+1000 - or ss_wholesale_cost between 54 and 54+20)) B3, - (select avg(ss_list_price) B4_LP - ,count(ss_list_price) B4_CNT - ,count(distinct ss_list_price) B4_CNTD - from store_sales - where ss_quantity between 16 and 20 - and (ss_list_price between 82 and 82+10 - or ss_coupon_amt between 6957 and 6957+1000 - or ss_wholesale_cost between 5 and 5+20)) B4, - (select avg(ss_list_price) B5_LP - ,count(ss_list_price) B5_CNT - ,count(distinct ss_list_price) B5_CNTD - from store_sales - where ss_quantity between 21 and 25 - and (ss_list_price between 79 and 79+10 - or ss_coupon_amt between 10133 and 10133+1000 - or ss_wholesale_cost between 73 and 73+20)) B5, - (select avg(ss_list_price) B6_LP - ,count(ss_list_price) B6_CNT - ,count(distinct ss_list_price) B6_CNTD - from store_sales - where ss_quantity between 26 and 30 - and (ss_list_price between 147 and 147+10 - or ss_coupon_amt between 10294 and 10294+1000 - or ss_wholesale_cost between 68 and 68+20)) B6 -limit 100; - --- end template query28.tpl query 21 in stream 1 --- start template query85.tpl query 22 in stream 1 -select /* TPC-DS query85.tpl 0.33 */ substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) - from web_sales, web_returns, web_page, customer_demographics cd1, - customer_demographics cd2, customer_address, date_dim, reason - where ws_web_page_sk = wp_web_page_sk - and ws_item_sk = wr_item_sk - and ws_order_number = wr_order_number - and ws_sold_date_sk = d_date_sk and d_year = 1999 - and cd1.cd_demo_sk = wr_refunded_cdemo_sk - and cd2.cd_demo_sk = wr_returning_cdemo_sk - and ca_address_sk = wr_refunded_addr_sk - and r_reason_sk = wr_reason_sk - and - ( - ( - cd1.cd_marital_status = 'D' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = '2 yr Degree' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 100.00 and 150.00 - ) - or - ( - cd1.cd_marital_status = 'S' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Primary' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 50.00 and 100.00 - ) - or - ( - cd1.cd_marital_status = 'M' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'College' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ca_country = 'United States' - and - ca_state in ('GA', 'MO', 'AL') - and ws_net_profit between 100 and 200 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('MI', 'OH', 'VA') - and ws_net_profit between 150 and 300 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('UT', 'OK', 'IA') - and ws_net_profit between 50 and 250 - ) - ) -group by r_reason_desc -order by substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) -limit 100; - --- end template query85.tpl query 22 in stream 1 --- start template query51.tpl query 23 in stream 1 -WITH /* TPC-DS query51.tpl 0.46 */ web_v1 as ( -select - ws_item_sk item_sk, d_date, - sum(sum(ws_sales_price)) - over (partition by ws_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from web_sales - ,date_dim -where ws_sold_date_sk=d_date_sk - and d_month_seq between 1176 and 1176+11 - and ws_item_sk is not NULL -group by ws_item_sk, d_date), -store_v1 as ( -select - ss_item_sk item_sk, d_date, - sum(sum(ss_sales_price)) - over (partition by ss_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from store_sales - ,date_dim -where ss_sold_date_sk=d_date_sk - and d_month_seq between 1176 and 1176+11 - and ss_item_sk is not NULL -group by ss_item_sk, d_date) - select * -from (select item_sk - ,d_date - ,web_sales - ,store_sales - ,max(web_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) web_cumulative - ,max(store_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) store_cumulative - from (select case when web.item_sk is not null then web.item_sk else store.item_sk end item_sk - ,case when web.d_date is not null then web.d_date else store.d_date end d_date - ,web.cume_sales web_sales - ,store.cume_sales store_sales - from web_v1 web full outer join store_v1 store on (web.item_sk = store.item_sk - and web.d_date = store.d_date) - )x )y -where web_cumulative > store_cumulative -order by item_sk - ,d_date -limit 100; - --- end template query51.tpl query 23 in stream 1 --- start template query41.tpl query 24 in stream 1 -select /* TPC-DS query41.tpl 0.62 */ distinct(i_product_name) - from item i1 - where i_manufact_id between 768 and 768+40 - and (select count(*) as item_cnt - from item - where (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'magenta' or i_color = 'azure') and - (i_units = 'Bunch' or i_units = 'Box') and - (i_size = 'small' or i_size = 'N/A') - ) or - (i_category = 'Women' and - (i_color = 'sky' or i_color = 'ivory') and - (i_units = 'Pallet' or i_units = 'Lb') and - (i_size = 'petite' or i_size = 'extra large') - ) or - (i_category = 'Men' and - (i_color = 'pale' or i_color = 'lime') and - (i_units = 'Dozen' or i_units = 'Case') and - (i_size = 'economy' or i_size = 'medium') - ) or - (i_category = 'Men' and - (i_color = 'forest' or i_color = 'floral') and - (i_units = 'Ounce' or i_units = 'Unknown') and - (i_size = 'small' or i_size = 'N/A') - ))) or - (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'blanched' or i_color = 'lavender') and - (i_units = 'Gross' or i_units = 'Carton') and - (i_size = 'small' or i_size = 'N/A') - ) or - (i_category = 'Women' and - (i_color = 'firebrick' or i_color = 'pink') and - (i_units = 'Tsp' or i_units = 'Tbl') and - (i_size = 'petite' or i_size = 'extra large') - ) or - (i_category = 'Men' and - (i_color = 'moccasin' or i_color = 'puff') and - (i_units = 'Pound' or i_units = 'Bundle') and - (i_size = 'economy' or i_size = 'medium') - ) or - (i_category = 'Men' and - (i_color = 'blush' or i_color = 'beige') and - (i_units = 'Oz' or i_units = 'N/A') and - (i_size = 'small' or i_size = 'N/A') - )))) > 0 - order by i_product_name - limit 100; - --- end template query41.tpl query 24 in stream 1 --- start template query27a.tpl query 25 in stream 1 -with /* TPC-DS query27a.tpl 0.16 */ results as - (select i_item_id, - s_state, 0 as g_state, - ss_quantity agg1, - ss_list_price agg2, - ss_coupon_amt agg3, - ss_sales_price agg4 - from store_sales, customer_demographics, date_dim, store, item - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_store_sk = s_store_sk and - ss_cdemo_sk = cd_demo_sk and - cd_gender = 'F' and - cd_marital_status = 'D' and - cd_education_status = 'Advanced Degree' and - d_year = 2000 and - s_state in ('FL','MI', 'TN', 'AL', 'IN', 'MO') - ) - - select i_item_id, - s_state, g_state, agg1, agg2, agg3, agg4 - from ( - select i_item_id, s_state, 0 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4 from results - group by i_item_id, s_state - union all - select i_item_id, NULL AS s_state, 1 AS g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as s_state, 1 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - ) foo - order by i_item_id, s_state - limit 100; - --- end template query27a.tpl query 25 in stream 1 --- start template query78.tpl query 26 in stream 1 -with /* TPC-DS query78.tpl 0.10 */ ws as - (select d_year AS ws_sold_year, ws_item_sk, - ws_bill_customer_sk ws_customer_sk, - sum(ws_quantity) ws_qty, - sum(ws_wholesale_cost) ws_wc, - sum(ws_sales_price) ws_sp - from web_sales - left join web_returns on wr_order_number=ws_order_number and ws_item_sk=wr_item_sk - join date_dim on ws_sold_date_sk = d_date_sk - where wr_order_number is null - group by d_year, ws_item_sk, ws_bill_customer_sk - ), -cs as - (select d_year AS cs_sold_year, cs_item_sk, - cs_bill_customer_sk cs_customer_sk, - sum(cs_quantity) cs_qty, - sum(cs_wholesale_cost) cs_wc, - sum(cs_sales_price) cs_sp - from catalog_sales - left join catalog_returns on cr_order_number=cs_order_number and cs_item_sk=cr_item_sk - join date_dim on cs_sold_date_sk = d_date_sk - where cr_order_number is null - group by d_year, cs_item_sk, cs_bill_customer_sk - ), -ss as - (select d_year AS ss_sold_year, ss_item_sk, - ss_customer_sk, - sum(ss_quantity) ss_qty, - sum(ss_wholesale_cost) ss_wc, - sum(ss_sales_price) ss_sp - from store_sales - left join store_returns on sr_ticket_number=ss_ticket_number and ss_item_sk=sr_item_sk - join date_dim on ss_sold_date_sk = d_date_sk - where sr_ticket_number is null - group by d_year, ss_item_sk, ss_customer_sk - ) - select -ss_item_sk, -round(ss_qty/(coalesce(ws_qty,0)+coalesce(cs_qty,0)),2) ratio, -ss_qty store_qty, ss_wc store_wholesale_cost, ss_sp store_sales_price, -coalesce(ws_qty,0)+coalesce(cs_qty,0) other_chan_qty, -coalesce(ws_wc,0)+coalesce(cs_wc,0) other_chan_wholesale_cost, -coalesce(ws_sp,0)+coalesce(cs_sp,0) other_chan_sales_price -from ss -left join ws on (ws_sold_year=ss_sold_year and ws_item_sk=ss_item_sk and ws_customer_sk=ss_customer_sk) -left join cs on (cs_sold_year=ss_sold_year and cs_item_sk=ss_item_sk and cs_customer_sk=ss_customer_sk) -where (coalesce(ws_qty,0)>0 or coalesce(cs_qty, 0)>0) and ss_sold_year=1998 -order by - ss_item_sk, - ss_qty desc, ss_wc desc, ss_sp desc, - other_chan_qty, - other_chan_wholesale_cost, - other_chan_sales_price, - ratio -limit 100; - --- end template query78.tpl query 26 in stream 1 --- start template query8.tpl query 27 in stream 1 -select /* TPC-DS query8.tpl 0.63 */ s_store_name - ,sum(ss_net_profit) - from store_sales - ,date_dim - ,store, - (select ca_zip - from ( - SELECT substring(ca_zip,1,5) ca_zip - FROM customer_address - WHERE substring(ca_zip,1,5) IN ( - '29556','91868','39424','86934','99892','26912', - '28347','83321','86227','51530','38262', - '13103','36699','15149','37270','87248', - '93735','76771','37178','71862','18173', - '19917','61836','97325','37463','13281', - '82156','23160','31655','18698','96692', - '16236','29573','98922','49623','16402', - '45783','78397','60604','66869','86132', - '19758','46188','66559','55761','37391', - '60432','12867','81185','86260','21946', - '99008','45191','78631','79755','32917', - '51375','76012','23475','35821','10439', - '43528','58239','96195','82141','32745', - '85034','88681','56512','84228','36894', - '87279','26815','15549','92055','99162', - '33626','60313','47818','65356','33683', - '51442','24810','15723','78545','33339', - '25199','36857','93419','62236','26988', - '37960','48310','84351','40400','48330', - '60121','53706','93582','50070','90472', - '14252','21726','39503','68174','41884', - '59366','45280','95435','30565','31974', - '80063','97970','96521','18287','20949', - '19389','70558','63466','36410','32588', - '62027','69210','85431','34679','98416', - '23736','16147','34306','42971','49271', - '70802','62660','55028','34172','80759', - '78264','80485','14989','76739','72536', - '60899','81413','70197','25717','61002', - '53568','73247','90488','35364','78001', - '79122','14997','41906','90589','95758', - '80409','68779','39182','51199','83892', - '18544','42862','62877','66909','32509', - '58492','17171','98965','79265','88779', - '53432','20943','49289','54139','34514', - '14300','39504','94960','44648','82682', - '43307','68920','24634','34957','53633', - '42724','17119','77396','46821','12806', - '65534','19211','38869','66296','66802', - '90850','20421','80787','29961','69531', - '21369','46012','12851','36455','90122', - '38616','59554','88750','50809','34086', - '33611','54942','56281','97484','90627', - '13047','96057','64220','46628','51570', - '85393','43294','96486','27553','32897', - '48641','69520','83073','53161','23438', - '97461','23571','98672','45235','24180', - '99809','28232','21350','98213','23891', - '68449','70499','84397','42868','79752', - '81628','81676','25740','88945','86003', - '32768','25021','24332','14490','82162', - '22696','47811','51118','62648','39500', - '34371','44216','97513','95590','74907', - '78923','48837','53498','18729','94348', - '89609','47278','68151','98723','41352', - '86531','57578','70671','83695','93668', - '12299','68805','11212','36381','66164', - '71637','10747','99032','87429','42008', - '99770','87330','89086','39403','33010', - '28548','82784','92125','85086','47575', - '94851','99341','27945','42205','90954', - '98793','51157','82674','89875','66309', - '66785','78526','61949','89690','46717', - '92980','64557','80504','31256','91329', - '80421','90432','85938','29750','65398', - '55953','99577','79685','89261','24953', - '71660','78293','90756','14798','98178', - '99864','16005','54920','85147','10974', - '82859','83900','93152','12146','68561', - '59425','80431','48561','98260','19701', - '55827','57775','25182','58013','35093', - '91140','90957','58647','14200','67963', - '71403','48070','37615','45885','12944', - '85054','11041','40302','98043','31066', - '47030','57590','78635','86529','86300', - '48203','60668','53417','50747','40298', - '24063','93369','42099','47320','62695', - '38629','92162','73434','16452','47161', - '23192','85311','12253','19120','36509', - '39070','87645','12864','97508') - intersect - select ca_zip - from (SELECT substring(ca_zip,1,5) ca_zip,count(*) cnt - FROM customer_address, customer - WHERE ca_address_sk = c_current_addr_sk and - c_preferred_cust_flag='Y' - group by ca_zip - having count(*) > 10)A1)A2) V1 - where ss_store_sk = s_store_sk - and ss_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 2000 - and (substring(s_zip,1,2) = substring(V1.ca_zip,1,2)) - group by s_store_name - order by s_store_name - limit 100; - --- end template query8.tpl query 27 in stream 1 --- start template query14a.tpl query 28 in stream 1 -with /* TPC-DS query14a.tpl 0.69 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 2000 AND 2000 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 2000 AND 2000 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 2000 AND 2000 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as - (select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2) x) -, - results AS -(select channel, i_brand_id, i_class_id, i_category_id, sum(sales) sum_sales, sum(number_sales) number_sales - from ( - select 'store' channel, i_brand_id,i_class_id - ,i_category_id,sum(ss_quantity*ss_list_price) sales - , count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2000+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales) - union all - select 'catalog' channel, i_brand_id,i_class_id,i_category_id, sum(cs_quantity*cs_list_price) sales, count(*) number_sales - from catalog_sales - ,item - ,date_dim - where cs_item_sk in (select ss_item_sk from cross_items) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2000+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(cs_quantity*cs_list_price) > (select average_sales from avg_sales) - union all - select 'web' channel, i_brand_id,i_class_id,i_category_id, sum(ws_quantity*ws_list_price) sales , count(*) number_sales - from web_sales - ,item - ,date_dim - where ws_item_sk in (select ss_item_sk from cross_items) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2000+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ws_quantity*ws_list_price) > (select average_sales from avg_sales) - ) y - group by channel, i_brand_id,i_class_id,i_category_id) - - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales -from ( - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales from results - union - select channel, i_brand_id, i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id, i_class_id - union - select channel, i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id - union - select channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel - union - select null as channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results) z -order by channel, i_brand_id, i_class_id, i_category_id - limit 100; -with /* TPC-DS query14a.tpl 0.69 part2 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 2000 AND 2000 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 2000 AND 2000 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 2000 AND 2000 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as -(select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2) x) - select this_year.channel ty_channel - ,this_year.i_brand_id ty_brand - ,this_year.i_class_id ty_class - ,this_year.i_category_id ty_category - ,this_year.sales ty_sales - ,this_year.number_sales ty_number_sales - ,last_year.channel ly_channel - ,last_year.i_brand_id ly_brand - ,last_year.i_class_id ly_class - ,last_year.i_category_id ly_category - ,last_year.sales ly_sales - ,last_year.number_sales ly_number_sales -from - (select 'store' channel, i_brand_id,i_class_id,i_category_id - ,sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 2000 + 1 - and d_moy = 12 - and d_dom = 20) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) this_year, - (select 'store' channel, i_brand_id,i_class_id - ,i_category_id, sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 2000 - and d_moy = 12 - and d_dom = 20) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) last_year - where this_year.i_brand_id= last_year.i_brand_id - and this_year.i_class_id = last_year.i_class_id - and this_year.i_category_id = last_year.i_category_id - order by this_year.channel, this_year.i_brand_id, this_year.i_class_id, this_year.i_category_id - limit 100; - --- end template query14a.tpl query 28 in stream 1 --- start template query50.tpl query 29 in stream 1 -select /* TPC-DS query50.tpl 0.60 */ - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 30) and - (sr_returned_date_sk - ss_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 60) and - (sr_returned_date_sk - ss_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 90) and - (sr_returned_date_sk - ss_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - store_sales - ,store_returns - ,store - ,date_dim d1 - ,date_dim d2 -where - d2.d_year = 2001 -and d2.d_moy = 8 -and ss_ticket_number = sr_ticket_number -and ss_item_sk = sr_item_sk -and ss_sold_date_sk = d1.d_date_sk -and sr_returned_date_sk = d2.d_date_sk -and ss_customer_sk = sr_customer_sk -and ss_store_sk = s_store_sk -group by - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -order by s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -limit 100; - --- end template query50.tpl query 29 in stream 1 --- start template query52.tpl query 30 in stream 1 -select /* TPC-DS query52.tpl 0.59 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_sales_price) ext_price - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=11 - and dt.d_year=2002 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,ext_price desc - ,brand_id -limit 100 ; - --- end template query52.tpl query 30 in stream 1 --- start template query81.tpl query 31 in stream 1 -with /* TPC-DS query81.tpl 0.37 */ customer_total_return as - (select cr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(cr_return_amt_inc_tax) as ctr_total_return - from catalog_returns - ,date_dim - ,customer_address - where cr_returned_date_sk = d_date_sk - and d_year =2002 - and cr_returning_addr_sk = ca_address_sk - group by cr_returning_customer_sk - ,ca_state ) - select c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'OH' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - limit 100; - --- end template query81.tpl query 31 in stream 1 --- start template query5a.tpl query 32 in stream 1 -with /* TPC-DS query5a.tpl 0.98 */ ssr as - (select s_store_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ss_store_sk as store_sk, - ss_sold_date_sk as date_sk, - ss_ext_sales_price as sales_price, - ss_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from store_sales - union all - select sr_store_sk as store_sk, - sr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - sr_return_amt as return_amt, - sr_net_loss as net_loss - from store_returns - ) salesreturns, - date_dim, - store - where date_sk = d_date_sk - and d_date between cast('1999-08-28' as date) - and dateadd(day,14,cast('1999-08-28' as date)) - and store_sk = s_store_sk - group by s_store_id) - , - csr as - (select cp_catalog_page_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select cs_catalog_page_sk as page_sk, - cs_sold_date_sk as date_sk, - cs_ext_sales_price as sales_price, - cs_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from catalog_sales - union all - select cr_catalog_page_sk as page_sk, - cr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - cr_return_amount as return_amt, - cr_net_loss as net_loss - from catalog_returns - ) salesreturns, - date_dim, - catalog_page - where date_sk = d_date_sk - and d_date between cast('1999-08-28' as date) - and dateadd(day,14,cast('1999-08-28' as date)) - and page_sk = cp_catalog_page_sk - group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ws_web_site_sk as wsr_web_site_sk, - ws_sold_date_sk as date_sk, - ws_ext_sales_price as sales_price, - ws_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from web_sales - union all - select ws_web_site_sk as wsr_web_site_sk, - wr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - wr_return_amt as return_amt, - wr_net_loss as net_loss - from web_returns left outer join web_sales on - ( wr_item_sk = ws_item_sk - and wr_order_number = ws_order_number) - ) salesreturns, - date_dim, - web_site - where date_sk = d_date_sk - and d_date between cast('1999-08-28' as date) - and dateadd(day,14,cast('1999-08-28' as date)) - and wsr_web_site_sk = web_site_sk - group by web_site_id) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || s_store_id as id - , sales - , returns - , (profit - profit_loss) as profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || cp_catalog_page_id as id - , sales - , returns - , (profit - profit_loss) as profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , (profit - profit_loss) as profit - from wsr - ) x - group by channel, id) - select channel, id, sales, returns, profit from ( - select channel, id, sales, returns, profit from results - union - select channel, null as id, sum(sales), sum(returns), sum(profit) from results group by channel - union - select null as channel, null as id, sum(sales), sum(returns), sum(profit) from results) foo -order by channel, id -limit 100; - --- end template query5a.tpl query 32 in stream 1 --- start template query26.tpl query 33 in stream 1 -select /* TPC-DS query26.tpl 0.85 */ i_item_id, - avg(cs_quantity) agg1, - avg(cs_list_price) agg2, - avg(cs_coupon_amt) agg3, - avg(cs_sales_price) agg4 - from catalog_sales, customer_demographics, date_dim, item, promotion - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd_demo_sk and - cs_promo_sk = p_promo_sk and - cd_gender = 'M' and - cd_marital_status = 'S' and - cd_education_status = 'College' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 2001 - group by i_item_id - order by i_item_id - limit 100; - --- end template query26.tpl query 33 in stream 1 --- start template query57.tpl query 34 in stream 1 -with /* TPC-DS query57.tpl 0.70 */ v1 as( - select i_category, i_brand, - cc_name, - d_year, d_moy, - sum(cs_sales_price) sum_sales, - avg(sum(cs_sales_price)) over - (partition by i_category, i_brand, - cc_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - cc_name - order by d_year, d_moy) rn - from item, catalog_sales, date_dim, call_center - where cs_item_sk = i_item_sk and - cs_sold_date_sk = d_date_sk and - cc_call_center_sk= cs_call_center_sk and - ( - d_year = 2001 or - ( d_year = 2001-1 and d_moy =12) or - ( d_year = 2001+1 and d_moy =1) - ) - group by i_category, i_brand, - cc_name , d_year, d_moy), - v2 as( - select v1.i_category, v1.i_brand - ,v1.d_year, v1.d_moy - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1. cc_name = v1_lag. cc_name and - v1. cc_name = v1_lead. cc_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 2001 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, sum_sales - limit 100; - --- end template query57.tpl query 34 in stream 1 --- start template query82.tpl query 35 in stream 1 -select /* TPC-DS query82.tpl 0.67 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, store_sales - where i_current_price between 26 and 26+30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('2002-04-20' as date) and dateadd(day,60,cast('2002-04-20' as date)) - and i_manufact_id in (651,15,421,157) - and inv_quantity_on_hand between 100 and 500 - and ss_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query82.tpl query 35 in stream 1 --- start template query69.tpl query 36 in stream 1 -select /* TPC-DS query69.tpl 0.28 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_state in ('OK','MO','SD') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 1 and 1+2) and - (not exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 1 and 1+2) and - not exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 1 and 1+2)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - limit 100; - --- end template query69.tpl query 36 in stream 1 --- start template query54.tpl query 37 in stream 1 -with /* TPC-DS query54.tpl 0.81 */ my_customers as ( - select distinct c_customer_sk - , c_current_addr_sk - from - ( select cs_sold_date_sk sold_date_sk, - cs_bill_customer_sk customer_sk, - cs_item_sk item_sk - from catalog_sales - union all - select ws_sold_date_sk sold_date_sk, - ws_bill_customer_sk customer_sk, - ws_item_sk item_sk - from web_sales - ) cs_or_ws_sales, - item, - date_dim, - customer - where sold_date_sk = d_date_sk - and item_sk = i_item_sk - and i_category = 'Music' - and i_class = 'classical' - and c_customer_sk = cs_or_ws_sales.customer_sk - and d_moy = 2 - and d_year = 1999 - ) - , my_revenue as ( - select c_customer_sk, - sum(ss_ext_sales_price) as revenue - from my_customers, - store_sales, - customer_address, - store, - date_dim - where c_current_addr_sk = ca_address_sk - and ca_county = s_county - and ca_state = s_state - and ss_sold_date_sk = d_date_sk - and c_customer_sk = ss_customer_sk - and d_month_seq between (select distinct d_month_seq+1 - from date_dim where d_year = 1999 and d_moy = 2) - and (select distinct d_month_seq+3 - from date_dim where d_year = 1999 and d_moy = 2) - group by c_customer_sk - ) - , segments as - (select cast((revenue/50) as bigint) as segment - from my_revenue - ) - select segment, count(*) as num_customers, segment*50 as segment_base - from segments - group by segment - order by segment, num_customers - limit 100; - --- end template query54.tpl query 37 in stream 1 --- start template query61.tpl query 38 in stream 1 -select /* TPC-DS query61.tpl 0.97 */ promotions,total,cast(promotions as decimal(15,4))/cast(total as decimal(15,4))*100 -from - (select sum(ss_ext_sales_price) promotions - from store_sales - ,store - ,promotion - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_promo_sk = p_promo_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -6 - and i_category = 'Jewelry' - and (p_channel_dmail = 'Y' or p_channel_email = 'Y' or p_channel_tv = 'Y') - and s_gmt_offset = -6 - and d_year = 2001 - and d_moy = 12) promotional_sales, - (select sum(ss_ext_sales_price) total - from store_sales - ,store - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -6 - and i_category = 'Jewelry' - and s_gmt_offset = -6 - and d_year = 2001 - and d_moy = 12) all_sales -order by promotions, total -limit 100; - --- end template query61.tpl query 38 in stream 1 --- start template query88.tpl query 39 in stream 1 -select /* TPC-DS query88.tpl 0.66 */ * -from - (select count(*) h8_30_to_9 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s1, - (select count(*) h9_to_9_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s2, - (select count(*) h9_30_to_10 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s3, - (select count(*) h10_to_10_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s4, - (select count(*) h10_30_to_11 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s5, - (select count(*) h11_to_11_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s6, - (select count(*) h11_30_to_12 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s7, - (select count(*) h12_to_12_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 12 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s8 -; - --- end template query88.tpl query 39 in stream 1 --- start template query18a.tpl query 40 in stream 1 -with /* TPC-DS query18a.tpl 0.90 */ results as - (select i_item_id, - ca_country, - ca_state, - ca_county, - cast(cs_quantity as decimal(12,2)) agg1, - cast(cs_list_price as decimal(12,2)) agg2, - cast(cs_coupon_amt as decimal(12,2)) agg3, - cast(cs_sales_price as decimal(12,2)) agg4, - cast(cs_net_profit as decimal(12,2)) agg5, - cast(c_birth_year as decimal(12,2)) agg6, - cast(cd1.cd_dep_count as decimal(12,2)) agg7 - from catalog_sales, customer_demographics cd1, customer_demographics cd2, customer, customer_address, date_dim, item - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd1.cd_demo_sk and - cs_bill_customer_sk = c_customer_sk and - cd1.cd_gender = 'M' and - cd1.cd_education_status = 'Secondary' and - c_current_cdemo_sk = cd2.cd_demo_sk and - c_current_addr_sk = ca_address_sk and - c_birth_month in (9,2,12,1,7,11) and - d_year = 2001 and - ca_state in ('OH','MS','KS','TN','MI','IA','GA') - ) - select i_item_id, ca_country, ca_state, ca_county, agg1, agg2, agg3, agg4, agg5, agg6, agg7 - from ( - select i_item_id, ca_country, ca_state, ca_county, avg(agg1) agg1, - avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state, ca_county - union all - select i_item_id, ca_country, ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state - union all - select i_item_id, ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country - union all - select i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - ) foo - order by ca_country, ca_state, ca_county, i_item_id - limit 100; - --- end template query18a.tpl query 40 in stream 1 --- start template query94.tpl query 41 in stream 1 -select /* TPC-DS query94.tpl 0.17 */ - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '1999-3-01' and - dateadd(day,60,cast('1999-3-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'VA' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and exists (select * - from web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) -and not exists(select * - from web_returns wr1 - where ws1.ws_order_number = wr1.wr_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query94.tpl query 41 in stream 1 --- start template query35a.tpl query 42 in stream 1 -select /* TPC-DS query35a.tpl 0.47 */ - ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - count(*) cnt1, - stddev_samp(cd_dep_count), - sum(cd_dep_count), - min(cd_dep_count), - cd_dep_employed_count, - count(*) cnt2, - stddev_samp(cd_dep_employed_count), - sum(cd_dep_employed_count), - min(cd_dep_employed_count), - cd_dep_college_count, - count(*) cnt3, - stddev_samp(cd_dep_college_count), - sum(cd_dep_college_count), - min(cd_dep_college_count) - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2000 and - d_qoy < 4) and - exists (select * from - (select ws_bill_customer_sk customsk - from web_sales,date_dim - where - ws_sold_date_sk = d_date_sk and - d_year = 2000 and - d_qoy < 4 - union all - select cs_ship_customer_sk customsk - from catalog_sales,date_dim - where - cs_sold_date_sk = d_date_sk and - d_year = 2000 and - d_qoy < 4)x - where x.customsk = c.c_customer_sk) - group by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - limit 100; - --- end template query35a.tpl query 42 in stream 1 --- start template query68.tpl query 43 in stream 1 -select /* TPC-DS query68.tpl 0.95 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,extended_price - ,extended_tax - ,list_price - from (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_ext_sales_price) extended_price - ,sum(ss_ext_list_price) list_price - ,sum(ss_ext_tax) extended_tax - from store_sales - ,date_dim - ,store - ,household_demographics - ,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_dep_count = 2 or - household_demographics.hd_vehicle_count= 0) - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_city in ('Union','Salem') - group by ss_ticket_number - ,ss_customer_sk - ,ss_addr_sk,ca_city) dn - ,customer - ,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,ss_ticket_number - limit 100; - --- end template query68.tpl query 43 in stream 1 --- start template query24.tpl query 44 in stream 1 -with /* TPC-DS query24.tpl 0.92 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_ext_sales_price) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip -and s_market_id=9 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'almond' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; -with /* TPC-DS query24.tpl 0.92 part2 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_ext_sales_price) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip - and s_market_id = 9 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'royal' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; - --- end template query24.tpl query 44 in stream 1 --- start template query75.tpl query 45 in stream 1 -WITH /* TPC-DS query75.tpl 0.3 */ all_sales AS ( - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,SUM(sales_cnt) AS sales_cnt - ,SUM(sales_amt) AS sales_amt - FROM (SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,cs_quantity - COALESCE(cr_return_quantity,0) AS sales_cnt - ,cs_ext_sales_price - COALESCE(cr_return_amount,0.0) AS sales_amt - FROM catalog_sales JOIN item ON i_item_sk=cs_item_sk - JOIN date_dim ON d_date_sk=cs_sold_date_sk - LEFT JOIN catalog_returns ON (cs_order_number=cr_order_number - AND cs_item_sk=cr_item_sk) - WHERE i_category='Sports' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ss_quantity - COALESCE(sr_return_quantity,0) AS sales_cnt - ,ss_ext_sales_price - COALESCE(sr_return_amt,0.0) AS sales_amt - FROM store_sales JOIN item ON i_item_sk=ss_item_sk - JOIN date_dim ON d_date_sk=ss_sold_date_sk - LEFT JOIN store_returns ON (ss_ticket_number=sr_ticket_number - AND ss_item_sk=sr_item_sk) - WHERE i_category='Sports' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ws_quantity - COALESCE(wr_return_quantity,0) AS sales_cnt - ,ws_ext_sales_price - COALESCE(wr_return_amt,0.0) AS sales_amt - FROM web_sales JOIN item ON i_item_sk=ws_item_sk - JOIN date_dim ON d_date_sk=ws_sold_date_sk - LEFT JOIN web_returns ON (ws_order_number=wr_order_number - AND ws_item_sk=wr_item_sk) - WHERE i_category='Sports') sales_detail - GROUP BY d_year, i_brand_id, i_class_id, i_category_id, i_manufact_id) - SELECT prev_yr.d_year AS prev_year - ,curr_yr.d_year AS year - ,curr_yr.i_brand_id - ,curr_yr.i_class_id - ,curr_yr.i_category_id - ,curr_yr.i_manufact_id - ,prev_yr.sales_cnt AS prev_yr_cnt - ,curr_yr.sales_cnt AS curr_yr_cnt - ,curr_yr.sales_cnt-prev_yr.sales_cnt AS sales_cnt_diff - ,curr_yr.sales_amt-prev_yr.sales_amt AS sales_amt_diff - FROM all_sales curr_yr, all_sales prev_yr - WHERE curr_yr.i_brand_id=prev_yr.i_brand_id - AND curr_yr.i_class_id=prev_yr.i_class_id - AND curr_yr.i_category_id=prev_yr.i_category_id - AND curr_yr.i_manufact_id=prev_yr.i_manufact_id - AND curr_yr.d_year=2001 - AND prev_yr.d_year=2001-1 - AND CAST(curr_yr.sales_cnt AS DECIMAL(17,2))/CAST(prev_yr.sales_cnt AS DECIMAL(17,2))<0.9 - ORDER BY sales_cnt_diff,sales_amt_diff - limit 100; - --- end template query75.tpl query 45 in stream 1 --- start template query11.tpl query 46 in stream 1 -with /* TPC-DS query11.tpl 0.51 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ss_ext_list_price-ss_ext_discount_amt) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ws_ext_list_price-ws_ext_discount_amt) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_login - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 1998 - and t_s_secyear.dyear = 1998+1 - and t_w_firstyear.dyear = 1998 - and t_w_secyear.dyear = 1998+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else 0.0 end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else 0.0 end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_login -limit 100; - --- end template query11.tpl query 46 in stream 1 --- start template query67a.tpl query 47 in stream 1 -with /* TPC-DS query67a.tpl 0.35 */ results as -( select i_category ,i_class ,i_brand ,i_product_name ,d_year ,d_qoy ,d_moy ,s_store_id - ,sum(coalesce(ss_sales_price*ss_quantity,0)) sumsales - from store_sales ,date_dim ,store ,item - where ss_sold_date_sk=d_date_sk - and ss_item_sk=i_item_sk - and ss_store_sk = s_store_sk - and d_month_seq between 1182 and 1182 + 11 - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy,s_store_id) - , - results_rollup as - (select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, s_store_id, sumsales - from results - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy - union all - select i_category, i_class, i_brand, i_product_name, d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year - union all - select i_category, i_class, i_brand, i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name - union all - select i_category, i_class, i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand - union all - select i_category, i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class - union all - select i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category - union all - select null i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results) - - select * -from (select i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rank() over (partition by i_category order by sumsales desc) rk - from results_rollup) dw2 -where rk <= 100 -order by i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rk -limit 100; - --- end template query67a.tpl query 47 in stream 1 --- start template query9.tpl query 48 in stream 1 -select /* TPC-DS query9.tpl 0.49 */ case when (select count(*) - from store_sales - where ss_quantity between 1 and 20) > 41205389 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 1 and 20) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 1 and 20) end bucket1 , - case when (select count(*) - from store_sales - where ss_quantity between 21 and 40) > 45723841 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 21 and 40) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 21 and 40) end bucket2, - case when (select count(*) - from store_sales - where ss_quantity between 41 and 60) > 18205645 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 41 and 60) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 41 and 60) end bucket3, - case when (select count(*) - from store_sales - where ss_quantity between 61 and 80) > 26064582 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 61 and 80) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 61 and 80) end bucket4, - case when (select count(*) - from store_sales - where ss_quantity between 81 and 100) > 30622538 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 81 and 100) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 81 and 100) end bucket5 -from reason -where r_reason_sk = 1 -; - --- end template query9.tpl query 48 in stream 1 --- start template query25.tpl query 49 in stream 1 -select /* TPC-DS query25.tpl 0.9 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,max(ss_net_profit) as store_sales_profit - ,max(sr_net_loss) as store_returns_loss - ,max(cs_net_profit) as catalog_sales_profit - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 2000 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 10 - and d2.d_year = 2000 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_moy between 4 and 10 - and d3.d_year = 2000 - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query25.tpl query 49 in stream 1 --- start template query37.tpl query 50 in stream 1 -select /* TPC-DS query37.tpl 0.31 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, catalog_sales - where i_current_price between 23 and 23 + 30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('1998-07-12' as date) and dateadd(day,60,cast('1998-07-12' as date)) - and i_manufact_id in (928,736,888,966) - and inv_quantity_on_hand between 100 and 500 - and cs_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query37.tpl query 50 in stream 1 --- start template query86a.tpl query 51 in stream 1 -with /* TPC-DS query86a.tpl 0.11 */ results as -( select sum(ws_net_paid) as total_sum, i_category, i_class, 0 as g_category, 0 as g_class - from - web_sales - ,date_dim d1 - ,item - where - d1.d_month_seq between 1203 and 1203+11 - and d1.d_date_sk = ws_sold_date_sk - and i_item_sk = ws_item_sk - group by i_category,i_class - ) , - - results_rollup as -( select total_sum ,i_category ,i_class, g_category, g_class, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum, i_category, NULL as i_class, 0 as g_category, 1 as g_class, 1 as lochierarchy from results group by i_category - union - select sum(total_sum) as total_sum, NULL as i_category, NULL as i_class, 1 as g_category, 1 as g_class, 2 as lochierarchy from results) - select - total_sum ,i_category ,i_class, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_class = 0 then i_category end - order by total_sum desc) as rank_within_parent - from - results_rollup - order by - lochierarchy desc, - case when lochierarchy = 0 then i_category end, - rank_within_parent - limit 100; - --- end template query86a.tpl query 51 in stream 1 --- start template query4.tpl query 52 in stream 1 -with /* TPC-DS query4.tpl 0.93 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(((ss_ext_list_price-ss_ext_wholesale_cost-ss_ext_discount_amt)+ss_ext_sales_price)/2) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((cs_ext_list_price-cs_ext_wholesale_cost-cs_ext_discount_amt)+cs_ext_sales_price)/2) ) year_total - ,'c' sale_type - from customer - ,catalog_sales - ,date_dim - where c_customer_sk = cs_bill_customer_sk - and cs_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year -union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((ws_ext_list_price-ws_ext_wholesale_cost-ws_ext_discount_amt)+ws_ext_sales_price)/2) ) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_preferred_cust_flag - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_c_firstyear - ,year_total t_c_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_c_secyear.customer_id - and t_s_firstyear.customer_id = t_c_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_c_firstyear.sale_type = 'c' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_c_secyear.sale_type = 'c' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 2000 - and t_s_secyear.dyear = 2000+1 - and t_c_firstyear.dyear = 2000 - and t_c_secyear.dyear = 2000+1 - and t_w_firstyear.dyear = 2000 - and t_w_secyear.dyear = 2000+1 - and t_s_firstyear.year_total > 0 - and t_c_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_preferred_cust_flag -limit 100; - --- end template query4.tpl query 52 in stream 1 --- start template query60.tpl query 53 in stream 1 -with /* TPC-DS query60.tpl 0.29 */ ss as ( - select - i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Children')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 8 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -8 - group by i_item_id), - cs as ( - select - i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Children')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 8 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -8 - group by i_item_id), - ws as ( - select - i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Children')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 8 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -8 - group by i_item_id) - select - i_item_id -,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by i_item_id - ,total_sales - limit 100; - --- end template query60.tpl query 53 in stream 1 --- start template query97.tpl query 54 in stream 1 -with /* TPC-DS query97.tpl 0.38 */ ssci as ( -select ss_customer_sk customer_sk - ,ss_item_sk item_sk -from store_sales,date_dim -where ss_sold_date_sk = d_date_sk - and d_month_seq between 1218 and 1218 + 11 -group by ss_customer_sk - ,ss_item_sk), -csci as( - select cs_bill_customer_sk customer_sk - ,cs_item_sk item_sk -from catalog_sales,date_dim -where cs_sold_date_sk = d_date_sk - and d_month_seq between 1218 and 1218 + 11 -group by cs_bill_customer_sk - ,cs_item_sk) - select sum(case when ssci.customer_sk is not null and csci.customer_sk is null then 1 else 0 end) store_only - ,sum(case when ssci.customer_sk is null and csci.customer_sk is not null then 1 else 0 end) catalog_only - ,sum(case when ssci.customer_sk is not null and csci.customer_sk is not null then 1 else 0 end) store_and_catalog -from ssci full outer join csci on (ssci.customer_sk=csci.customer_sk - and ssci.item_sk = csci.item_sk) -limit 100; - --- end template query97.tpl query 54 in stream 1 --- start template query33.tpl query 55 in stream 1 -with /* TPC-DS query33.tpl 0.22 */ ss as ( - select - i_manufact_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Electronics')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 1 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_manufact_id), - cs as ( - select - i_manufact_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Electronics')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 1 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_manufact_id), - ws as ( - select - i_manufact_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Electronics')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 1 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_manufact_id) - select i_manufact_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_manufact_id - order by total_sales -limit 100; - --- end template query33.tpl query 55 in stream 1 --- start template query79.tpl query 56 in stream 1 -select /* TPC-DS query79.tpl 0.89 */ - c_last_name,c_first_name,substring(s_city,1,30),ss_ticket_number,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,store.s_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (household_demographics.hd_dep_count = 7 or household_demographics.hd_vehicle_count > 4) - and date_dim.d_dow = 1 - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_number_employees between 200 and 295 - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,store.s_city) ms,customer - where ss_customer_sk = c_customer_sk - order by c_last_name,c_first_name,substring(s_city,1,30), profit -limit 100; - --- end template query79.tpl query 56 in stream 1 --- start template query43.tpl query 57 in stream 1 -select /* TPC-DS query43.tpl 0.15 */ s_store_name, s_store_id, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from date_dim, store_sales, store - where d_date_sk = ss_sold_date_sk and - s_store_sk = ss_store_sk and - s_gmt_offset = -5 and - d_year = 2002 - group by s_store_name, s_store_id - order by s_store_name, s_store_id,sun_sales,mon_sales,tue_sales,wed_sales,thu_sales,fri_sales,sat_sales - limit 100; - --- end template query43.tpl query 57 in stream 1 --- start template query80a.tpl query 58 in stream 1 -with /* TPC-DS query80a.tpl 0.6 */ ssr as - (select s_store_id as store_id, - sum(ss_ext_sales_price) as sales, - sum(coalesce(sr_return_amt, 0)) as returns, - sum(ss_net_profit - coalesce(sr_net_loss, 0)) as profit - from store_sales left outer join store_returns on - (ss_item_sk = sr_item_sk and ss_ticket_number = sr_ticket_number), - date_dim, - store, - item, - promotion - where ss_sold_date_sk = d_date_sk - and d_date between cast('1999-08-04' as date) - and dateadd(day,30,cast('1999-08-04' as date)) - and ss_store_sk = s_store_sk - and ss_item_sk = i_item_sk - and i_current_price > 50 - and ss_promo_sk = p_promo_sk - and p_channel_tv = 'N' - group by s_store_id) - , - csr as - (select cp_catalog_page_id as catalog_page_id, - sum(cs_ext_sales_price) as sales, - sum(coalesce(cr_return_amount, 0)) as returns, - sum(cs_net_profit - coalesce(cr_net_loss, 0)) as profit - from catalog_sales left outer join catalog_returns on - (cs_item_sk = cr_item_sk and cs_order_number = cr_order_number), - date_dim, - catalog_page, - item, - promotion - where cs_sold_date_sk = d_date_sk - and d_date between cast('1999-08-04' as date) - and dateadd(day,30,cast('1999-08-04' as date)) - and cs_catalog_page_sk = cp_catalog_page_sk - and cs_item_sk = i_item_sk - and i_current_price > 50 - and cs_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(ws_ext_sales_price) as sales, - sum(coalesce(wr_return_amt, 0)) as returns, - sum(ws_net_profit - coalesce(wr_net_loss, 0)) as profit - from web_sales left outer join web_returns on - (ws_item_sk = wr_item_sk and ws_order_number = wr_order_number), - date_dim, - web_site, - item, - promotion - where ws_sold_date_sk = d_date_sk - and d_date between cast('1999-08-04' as date) - and dateadd(day,30,cast('1999-08-04' as date)) - and ws_web_site_sk = web_site_sk - and ws_item_sk = i_item_sk - and i_current_price > 50 - and ws_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by web_site_id) -, -results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || store_id as id - , sales - , returns - , profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || catalog_page_id as id - , sales - , returns - , profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , profit - from wsr - ) x - group by channel, id) - - select channel - , id - , sales - , returns - , profit - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results - ) foo - order by channel, id - limit 100; - --- end template query80a.tpl query 58 in stream 1 --- start template query93.tpl query 59 in stream 1 -select /* TPC-DS query93.tpl 0.52 */ ss_customer_sk - ,sum(act_sales) sumsales - from (select ss_item_sk - ,ss_ticket_number - ,ss_customer_sk - ,case when sr_return_quantity is not null then (ss_quantity-sr_return_quantity)*ss_sales_price - else (ss_quantity*ss_sales_price) end act_sales - from store_sales left outer join store_returns on (sr_item_sk = ss_item_sk - and sr_ticket_number = ss_ticket_number) - ,reason - where sr_reason_sk = r_reason_sk - and r_reason_desc = 'reason 68') t - group by ss_customer_sk - order by sumsales, ss_customer_sk -limit 100; - --- end template query93.tpl query 59 in stream 1 --- start template query31.tpl query 60 in stream 1 -with /* TPC-DS query31.tpl 0.50 */ ss as - (select ca_county,d_qoy, d_year,sum(ss_ext_sales_price) as store_sales - from store_sales,date_dim,customer_address - where ss_sold_date_sk = d_date_sk - and ss_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year), - ws as - (select ca_county,d_qoy, d_year,sum(ws_ext_sales_price) as web_sales - from web_sales,date_dim,customer_address - where ws_sold_date_sk = d_date_sk - and ws_bill_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year) - select - ss1.ca_county - ,ss1.d_year - ,ws2.web_sales/ws1.web_sales web_q1_q2_increase - ,ss2.store_sales/ss1.store_sales store_q1_q2_increase - ,ws3.web_sales/ws2.web_sales web_q2_q3_increase - ,ss3.store_sales/ss2.store_sales store_q2_q3_increase - from - ss ss1 - ,ss ss2 - ,ss ss3 - ,ws ws1 - ,ws ws2 - ,ws ws3 - where - ss1.d_qoy = 1 - and ss1.d_year = 2001 - and ss1.ca_county = ss2.ca_county - and ss2.d_qoy = 2 - and ss2.d_year = 2001 - and ss2.ca_county = ss3.ca_county - and ss3.d_qoy = 3 - and ss3.d_year = 2001 - and ss1.ca_county = ws1.ca_county - and ws1.d_qoy = 1 - and ws1.d_year = 2001 - and ws1.ca_county = ws2.ca_county - and ws2.d_qoy = 2 - and ws2.d_year = 2001 - and ws1.ca_county = ws3.ca_county - and ws3.d_qoy = 3 - and ws3.d_year =2001 - and case when ws1.web_sales > 0 then ws2.web_sales/ws1.web_sales else null end - > case when ss1.store_sales > 0 then ss2.store_sales/ss1.store_sales else null end - and case when ws2.web_sales > 0 then ws3.web_sales/ws2.web_sales else null end - > case when ss2.store_sales > 0 then ss3.store_sales/ss2.store_sales else null end - order by ss1.d_year; - --- end template query31.tpl query 60 in stream 1 --- start template query47.tpl query 61 in stream 1 -with /* TPC-DS query47.tpl 0.42 */ v1 as( - select i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, - s_store_name, s_company_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - s_store_name, s_company_name - order by d_year, d_moy) rn - from item, store_sales, date_dim, store - where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - ( - d_year = 1999 or - ( d_year = 1999-1 and d_moy =12) or - ( d_year = 1999+1 and d_moy =1) - ) - group by i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy), - v2 as( - select v1.i_category, v1.i_brand - ,v1.d_year - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1.s_store_name = v1_lag.s_store_name and - v1.s_store_name = v1_lead.s_store_name and - v1.s_company_name = v1_lag.s_company_name and - v1.s_company_name = v1_lead.s_company_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 1999 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, psum - limit 100; - --- end template query47.tpl query 61 in stream 1 --- start template query17.tpl query 62 in stream 1 -select /* TPC-DS query17.tpl 0.41 */ i_item_id - ,i_item_desc - ,s_state - ,count(ss_quantity) as store_sales_quantitycount - ,avg(ss_quantity) as store_sales_quantityave - ,stddev_samp(ss_quantity) as store_sales_quantitystdev - ,stddev_samp(ss_quantity)/avg(ss_quantity) as store_sales_quantitycov - ,count(sr_return_quantity) as store_returns_quantitycount - ,avg(sr_return_quantity) as store_returns_quantityave - ,stddev_samp(sr_return_quantity) as store_returns_quantitystdev - ,stddev_samp(sr_return_quantity)/avg(sr_return_quantity) as store_returns_quantitycov - ,count(cs_quantity) as catalog_sales_quantitycount ,avg(cs_quantity) as catalog_sales_quantityave - ,stddev_samp(cs_quantity) as catalog_sales_quantitystdev - ,stddev_samp(cs_quantity)/avg(cs_quantity) as catalog_sales_quantitycov - from store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where d1.d_quarter_name = '2000Q1' - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_quarter_name in ('2000Q1','2000Q2','2000Q3') - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_quarter_name in ('2000Q1','2000Q2','2000Q3') - group by i_item_id - ,i_item_desc - ,s_state - order by i_item_id - ,i_item_desc - ,s_state -limit 100; - --- end template query17.tpl query 62 in stream 1 --- start template query19.tpl query 63 in stream 1 -select /* TPC-DS query19.tpl 0.8 */ i_brand_id brand_id, i_brand brand, i_manufact_id, i_manufact, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item,customer,customer_address,store - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=18 - and d_moy=12 - and d_year=2001 - and ss_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and substring(ca_zip,1,5) <> substring(s_zip,1,5) - and ss_store_sk = s_store_sk - group by i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact - order by ext_price desc - ,i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact -limit 100 ; - --- end template query19.tpl query 63 in stream 1 --- start template query1.tpl query 64 in stream 1 -with /* TPC-DS query1.tpl 0.12 */ customer_total_return as -(select sr_customer_sk as ctr_customer_sk -,sr_store_sk as ctr_store_sk -,sum(SR_REFUNDED_CASH) as ctr_total_return -from store_returns -,date_dim -where sr_returned_date_sk = d_date_sk -and d_year =1998 -group by sr_customer_sk -,sr_store_sk) - select c_customer_id -from customer_total_return ctr1 -,store -,customer -where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 -from customer_total_return ctr2 -where ctr1.ctr_store_sk = ctr2.ctr_store_sk) -and s_store_sk = ctr1.ctr_store_sk -and s_state = 'OH' -and ctr1.ctr_customer_sk = c_customer_sk -order by c_customer_id -limit 100; - --- end template query1.tpl query 64 in stream 1 --- start template query64.tpl query 65 in stream 1 -with /* TPC-DS query64.tpl 0.20 */ cs_ui as - (select cs_item_sk - ,sum(cs_ext_list_price) as sale,sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit) as refund - from catalog_sales - ,catalog_returns - where cs_item_sk = cr_item_sk - and cs_order_number = cr_order_number - group by cs_item_sk - having sum(cs_ext_list_price)>2*sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit)), -cross_sales as - (select i_product_name product_name - ,i_item_sk item_sk - ,s_store_name store_name - ,s_zip store_zip - ,ad1.ca_street_number b_street_number - ,ad1.ca_street_name b_street_name - ,ad1.ca_city b_city - ,ad1.ca_zip b_zip - ,ad2.ca_street_number c_street_number - ,ad2.ca_street_name c_street_name - ,ad2.ca_city c_city - ,ad2.ca_zip c_zip - ,d1.d_year as syear - ,d2.d_year as fsyear - ,d3.d_year s2year - ,count(*) cnt - ,sum(ss_wholesale_cost) s1 - ,sum(ss_list_price) s2 - ,sum(ss_coupon_amt) s3 - FROM store_sales - ,store_returns - ,cs_ui - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,customer - ,customer_demographics cd1 - ,customer_demographics cd2 - ,promotion - ,household_demographics hd1 - ,household_demographics hd2 - ,customer_address ad1 - ,customer_address ad2 - ,income_band ib1 - ,income_band ib2 - ,item - WHERE ss_store_sk = s_store_sk AND - ss_sold_date_sk = d1.d_date_sk AND - ss_customer_sk = c_customer_sk AND - ss_cdemo_sk= cd1.cd_demo_sk AND - ss_hdemo_sk = hd1.hd_demo_sk AND - ss_addr_sk = ad1.ca_address_sk and - ss_item_sk = i_item_sk and - ss_item_sk = sr_item_sk and - ss_ticket_number = sr_ticket_number and - ss_item_sk = cs_ui.cs_item_sk and - c_current_cdemo_sk = cd2.cd_demo_sk AND - c_current_hdemo_sk = hd2.hd_demo_sk AND - c_current_addr_sk = ad2.ca_address_sk and - c_first_sales_date_sk = d2.d_date_sk and - c_first_shipto_date_sk = d3.d_date_sk and - ss_promo_sk = p_promo_sk and - hd1.hd_income_band_sk = ib1.ib_income_band_sk and - hd2.hd_income_band_sk = ib2.ib_income_band_sk and - cd1.cd_marital_status <> cd2.cd_marital_status and - i_color in ('olive','honeydew','ivory','blush','coral','bisque') and - i_current_price between 8 and 8 + 10 and - i_current_price between 8 + 1 and 8 + 15 -group by i_product_name - ,i_item_sk - ,s_store_name - ,s_zip - ,ad1.ca_street_number - ,ad1.ca_street_name - ,ad1.ca_city - ,ad1.ca_zip - ,ad2.ca_street_number - ,ad2.ca_street_name - ,ad2.ca_city - ,ad2.ca_zip - ,d1.d_year - ,d2.d_year - ,d3.d_year -) -select cs1.product_name - ,cs1.store_name - ,cs1.store_zip - ,cs1.b_street_number - ,cs1.b_street_name - ,cs1.b_city - ,cs1.b_zip - ,cs1.c_street_number - ,cs1.c_street_name - ,cs1.c_city - ,cs1.c_zip - ,cs1.syear - ,cs1.cnt - ,cs1.s1 as s11 - ,cs1.s2 as s21 - ,cs1.s3 as s31 - ,cs2.s1 as s12 - ,cs2.s2 as s22 - ,cs2.s3 as s32 - ,cs2.syear - ,cs2.cnt -from cross_sales cs1,cross_sales cs2 -where cs1.item_sk=cs2.item_sk and - cs1.syear = 1999 and - cs2.syear = 1999 + 1 and - cs2.cnt <= cs1.cnt and - cs1.store_name = cs2.store_name and - cs1.store_zip = cs2.store_zip -order by cs1.product_name - ,cs1.store_name - ,cs2.cnt - ,cs1.s1 - ,cs2.s1; - --- end template query64.tpl query 65 in stream 1 --- start template query53.tpl query 66 in stream 1 -select /* TPC-DS query53.tpl 0.88 */ * from -(select i_manufact_id, -sum(ss_sales_price) sum_sales, -avg(sum(ss_sales_price)) over (partition by i_manufact_id) avg_quarterly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and -ss_sold_date_sk = d_date_sk and -ss_store_sk = s_store_sk and -d_month_seq in (1211,1211+1,1211+2,1211+3,1211+4,1211+5,1211+6,1211+7,1211+8,1211+9,1211+10,1211+11) and -((i_category in ('Books','Children','Electronics') and -i_class in ('personal','portable','reference','self-help') and -i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) -or(i_category in ('Women','Music','Men') and -i_class in ('accessories','classical','fragrances','pants') and -i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manufact_id, d_qoy ) tmp1 -where case when avg_quarterly_sales > 0 - then abs (sum_sales - avg_quarterly_sales)/ avg_quarterly_sales - else null end > 0.1 -order by avg_quarterly_sales, - sum_sales, - i_manufact_id -limit 100; - --- end template query53.tpl query 66 in stream 1 --- start template query55.tpl query 67 in stream 1 -select /* TPC-DS query55.tpl 0.82 */ i_brand_id brand_id, i_brand brand, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=12 - and d_moy=11 - and d_year=1999 - group by i_brand, i_brand_id - order by ext_price desc, i_brand_id -limit 100 ; - --- end template query55.tpl query 67 in stream 1 --- start template query46.tpl query 68 in stream 1 -select /* TPC-DS query46.tpl 0.23 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and (household_demographics.hd_dep_count = 1 or - household_demographics.hd_vehicle_count= 2) - and date_dim.d_dow in (6,0) - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_city in ('Harmony','Five Points','Oak Grove','Liberty','Springfield') - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,ca_city) dn,customer,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - limit 100; - --- end template query46.tpl query 68 in stream 1 --- start template query21.tpl query 69 in stream 1 -select /* TPC-DS query21.tpl 0.14 */ * - from(select w_warehouse_name - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('2000-05-07' as date)) - then inv_quantity_on_hand - else 0 end) as inv_before - ,sum(case when (cast(d_date as date) >= cast ('2000-05-07' as date)) - then inv_quantity_on_hand - else 0 end) as inv_after - from inventory - ,warehouse - ,item - ,date_dim - where i_current_price between 0.99 and 1.49 - and i_item_sk = inv_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('2000-05-07' as date)) - and dateadd(day,30,cast ('2000-05-07' as date)) - group by w_warehouse_name, i_item_id) x - where (case when inv_before > 0 - then inv_after / inv_before - else null - end) between 2.0/3.0 and 3.0/2.0 - order by w_warehouse_name - ,i_item_id - limit 100; - --- end template query21.tpl query 69 in stream 1 --- start template query15.tpl query 70 in stream 1 -select /* TPC-DS query15.tpl 0.57 */ ca_zip - ,sum(cs_sales_price) - from catalog_sales - ,customer - ,customer_address - ,date_dim - where cs_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', - '85392', '85460', '80348', '81792') - or ca_state in ('CA','WA','GA') - or cs_sales_price > 500) - and cs_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 1999 - group by ca_zip - order by ca_zip - limit 100; - --- end template query15.tpl query 70 in stream 1 --- start template query20.tpl query 71 in stream 1 -select /* TPC-DS query20.tpl 0.65 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(cs_ext_sales_price) as itemrevenue - ,sum(cs_ext_sales_price)*100/sum(sum(cs_ext_sales_price)) over - (partition by i_class) as revenueratio - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and i_category in ('Music', 'Home', 'Men') - and cs_sold_date_sk = d_date_sk - and d_date between cast('2000-04-11' as date) - and dateadd(day,30,cast('2000-04-11' as date)) - group by i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - order by i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query20.tpl query 71 in stream 1 --- start template query65.tpl query 72 in stream 1 -select /* TPC-DS query65.tpl 0.71 */ - s_store_name, - i_item_desc, - sc.revenue, - i_current_price, - i_wholesale_cost, - i_brand - from store, item, - (select ss_store_sk, avg(revenue) as ave - from - (select ss_store_sk, ss_item_sk, - sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1197 and 1197+11 - group by ss_store_sk, ss_item_sk) sa - group by ss_store_sk) sb, - (select ss_store_sk, ss_item_sk, sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1197 and 1197+11 - group by ss_store_sk, ss_item_sk) sc - where sb.ss_store_sk = sc.ss_store_sk and - sc.revenue <= 0.1 * sb.ave and - s_store_sk = sc.ss_store_sk and - i_item_sk = sc.ss_item_sk - order by s_store_name, i_item_desc -limit 100; - --- end template query65.tpl query 72 in stream 1 --- start template query70a.tpl query 73 in stream 1 -with /* TPC-DS query70a.tpl 0.34 */ results as -( select - sum(ss_net_profit) as total_sum ,s_state ,s_county, 0 as gstate, 0 as g_county - from - store_sales - ,date_dim d1 - ,store - where - d1.d_month_seq between 1209 and 1209 + 11 - and d1.d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - and s_state in - ( select s_state - from (select s_state as s_state, - rank() over ( partition by s_state order by sum(ss_net_profit) desc) as ranking - from store_sales, store, date_dim - where d_month_seq between 1209 and 1209 + 11 - and d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - group by s_state - ) tmp1 - where ranking <= 5) - group by s_state,s_county) , - results_rollup as -(select total_sum ,s_state ,s_county, 0 as g_state, 0 as g_county, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum,s_state, NULL as s_county, 0 as g_state, 1 as g_county, 1 as lochierarchy from results group by s_state - union - select sum(total_sum) as total_sum ,NULL as s_state ,NULL as s_county, 1 as g_state, 1 as g_county, 2 as lochierarchy from results) - select total_sum ,s_state ,s_county, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_county = 0 then s_state end - order by total_sum desc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then s_state end - ,rank_within_parent - limit 100; - --- end template query70a.tpl query 73 in stream 1 --- start template query49.tpl query 74 in stream 1 -select /* TPC-DS query49.tpl 0.48 */ channel, item, return_ratio, return_rank, currency_rank from - (select - 'web' as channel - ,web.item - ,web.return_ratio - ,web.return_rank - ,web.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select ws.ws_item_sk as item - ,(cast(sum(coalesce(wr.wr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(wr.wr_return_amt,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - web_sales ws left outer join web_returns wr - on (ws.ws_order_number = wr.wr_order_number and - ws.ws_item_sk = wr.wr_item_sk) - ,date_dim - where - wr.wr_return_amt > 10000 - and ws.ws_net_profit > 1 - and ws.ws_net_paid > 0 - and ws.ws_quantity > 0 - and ws_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 12 - group by ws.ws_item_sk - ) in_web - ) web - where - ( - web.return_rank <= 10 - or - web.currency_rank <= 10 - ) - union - select - 'catalog' as channel - ,catalog.item - ,catalog.return_ratio - ,catalog.return_rank - ,catalog.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select - cs.cs_item_sk as item - ,(cast(sum(coalesce(cr.cr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(cr.cr_return_amount,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - catalog_sales cs left outer join catalog_returns cr - on (cs.cs_order_number = cr.cr_order_number and - cs.cs_item_sk = cr.cr_item_sk) - ,date_dim - where - cr.cr_return_amount > 10000 - and cs.cs_net_profit > 1 - and cs.cs_net_paid > 0 - and cs.cs_quantity > 0 - and cs_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 12 - group by cs.cs_item_sk - ) in_cat - ) catalog - where - ( - catalog.return_rank <= 10 - or - catalog.currency_rank <=10 - ) - union - select - 'store' as channel - ,store.item - ,store.return_ratio - ,store.return_rank - ,store.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select sts.ss_item_sk as item - ,(cast(sum(coalesce(sr.sr_return_quantity,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(sr.sr_return_amt,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - store_sales sts left outer join store_returns sr - on (sts.ss_ticket_number = sr.sr_ticket_number and sts.ss_item_sk = sr.sr_item_sk) - ,date_dim - where - sr.sr_return_amt > 10000 - and sts.ss_net_profit > 1 - and sts.ss_net_paid > 0 - and sts.ss_quantity > 0 - and ss_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 12 - group by sts.ss_item_sk - ) in_store - ) store - where ( - store.return_rank <= 10 - or - store.currency_rank <= 10 - ) - ) - order by 1,4,5,2 - limit 100; - --- end template query49.tpl query 74 in stream 1 --- start template query59.tpl query 75 in stream 1 -with /* TPC-DS query59.tpl 0.30 */ wss as - (select d_week_seq, - ss_store_sk, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - group by d_week_seq,ss_store_sk - ) - select s_store_name1,s_store_id1,d_week_seq1 - ,sun_sales1/sun_sales2,mon_sales1/mon_sales2 - ,tue_sales1/tue_sales2,wed_sales1/wed_sales2,thu_sales1/thu_sales2 - ,fri_sales1/fri_sales2,sat_sales1/sat_sales2 - from - (select s_store_name s_store_name1,wss.d_week_seq d_week_seq1 - ,s_store_id s_store_id1,sun_sales sun_sales1 - ,mon_sales mon_sales1,tue_sales tue_sales1 - ,wed_sales wed_sales1,thu_sales thu_sales1 - ,fri_sales fri_sales1,sat_sales sat_sales1 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1198 and 1198 + 11) y, - (select s_store_name s_store_name2,wss.d_week_seq d_week_seq2 - ,s_store_id s_store_id2,sun_sales sun_sales2 - ,mon_sales mon_sales2,tue_sales tue_sales2 - ,wed_sales wed_sales2,thu_sales thu_sales2 - ,fri_sales fri_sales2,sat_sales sat_sales2 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1198+ 12 and 1198 + 23) x - where s_store_id1=s_store_id2 - and d_week_seq1=d_week_seq2-52 - order by s_store_name1,s_store_id1,d_week_seq1 -limit 100; - --- end template query59.tpl query 75 in stream 1 --- start template query48.tpl query 76 in stream 1 -select /* TPC-DS query48.tpl 0.74 */ sum (ss_quantity) - from store_sales, store, customer_demographics, customer_address, date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2001 - and - ( - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'M' - and - cd_education_status = 'Secondary' - and - ss_sales_price between 100.00 and 150.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'D' - and - cd_education_status = 'Advanced Degree' - and - ss_sales_price between 50.00 and 100.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'S' - and - cd_education_status = 'College' - and - ss_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('MO', 'SD', 'IN') - and ss_net_profit between 0 and 2000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('GA', 'NE', 'AR') - and ss_net_profit between 150 and 3000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('SC', 'MN', 'IA') - and ss_net_profit between 50 and 25000 - ) - ) -; - --- end template query48.tpl query 76 in stream 1 --- start template query72.tpl query 77 in stream 1 -select /* TPC-DS query72.tpl 0.87 */ i_item_desc - ,w_warehouse_name - ,d1.d_week_seq - ,sum(case when p_promo_sk is null then 1 else 0 end) no_promo - ,sum(case when p_promo_sk is not null then 1 else 0 end) promo - ,count(*) total_cnt -from catalog_sales -join inventory on (cs_item_sk = inv_item_sk) -join warehouse on (w_warehouse_sk=inv_warehouse_sk) -join item on (i_item_sk = cs_item_sk) -join customer_demographics on (cs_bill_cdemo_sk = cd_demo_sk) -join household_demographics on (cs_bill_hdemo_sk = hd_demo_sk) -join date_dim d1 on (cs_sold_date_sk = d1.d_date_sk) -join date_dim d2 on (inv_date_sk = d2.d_date_sk) -join date_dim d3 on (cs_ship_date_sk = d3.d_date_sk) -left outer join promotion on (cs_promo_sk=p_promo_sk) -left outer join catalog_returns on (cr_item_sk = cs_item_sk and cr_order_number = cs_order_number) -where d1.d_week_seq = d2.d_week_seq - and inv_quantity_on_hand < cs_quantity - and d3.d_date > d1.d_date + 5 - and hd_buy_potential = '1001-5000' - and d1.d_year = 1998 - and cd_marital_status = 'M' -group by i_item_desc,w_warehouse_name,d1.d_week_seq -order by total_cnt desc, i_item_desc, w_warehouse_name, d_week_seq -limit 100; - --- end template query72.tpl query 77 in stream 1 --- start template query87.tpl query 78 in stream 1 -select /* TPC-DS query87.tpl 0.77 */ count(*) -from ((select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1195 and 1195+11) - except - (select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1195 and 1195+11) - except - (select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1195 and 1195+11) -) cool_cust -; - --- end template query87.tpl query 78 in stream 1 --- start template query34.tpl query 79 in stream 1 -select /* TPC-DS query34.tpl 0.73 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (date_dim.d_dom between 1 and 3 or date_dim.d_dom between 25 and 28) - and (household_demographics.hd_buy_potential = '1001-5000' or - household_demographics.hd_buy_potential = '0-500') - and household_demographics.hd_vehicle_count > 0 - and (case when household_demographics.hd_vehicle_count > 0 - then household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count - else null - end) > 1.2 - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_county in ('Richland County','Oglethorpe County','Gogebic County','Huron County', - 'Luce County','Jackson County','Levy County','Pennington County') - group by ss_ticket_number,ss_customer_sk) dn,customer - where ss_customer_sk = c_customer_sk - and cnt between 15 and 20 - order by c_last_name,c_first_name,c_salutation,c_preferred_cust_flag desc, ss_ticket_number; - --- end template query34.tpl query 79 in stream 1 --- start template query2.tpl query 80 in stream 1 -with /* TPC-DS query2.tpl 0.84 */ wscs as - (select sold_date_sk - ,sales_price - from (select ws_sold_date_sk sold_date_sk - ,ws_ext_sales_price sales_price - from web_sales - union all - select cs_sold_date_sk sold_date_sk - ,cs_ext_sales_price sales_price - from catalog_sales)), - wswscs as - (select d_week_seq, - sum(case when (d_day_name='Sunday') then sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then sales_price else null end) sat_sales - from wscs - ,date_dim - where d_date_sk = sold_date_sk - group by d_week_seq) - select d_week_seq1 - ,round(sun_sales1/sun_sales2,2) - ,round(mon_sales1/mon_sales2,2) - ,round(tue_sales1/tue_sales2,2) - ,round(wed_sales1/wed_sales2,2) - ,round(thu_sales1/thu_sales2,2) - ,round(fri_sales1/fri_sales2,2) - ,round(sat_sales1/sat_sales2,2) - from - (select wswscs.d_week_seq d_week_seq1 - ,sun_sales sun_sales1 - ,mon_sales mon_sales1 - ,tue_sales tue_sales1 - ,wed_sales wed_sales1 - ,thu_sales thu_sales1 - ,fri_sales fri_sales1 - ,sat_sales sat_sales1 - from wswscs,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 2000) y, - (select wswscs.d_week_seq d_week_seq2 - ,sun_sales sun_sales2 - ,mon_sales mon_sales2 - ,tue_sales tue_sales2 - ,wed_sales wed_sales2 - ,thu_sales thu_sales2 - ,fri_sales fri_sales2 - ,sat_sales sat_sales2 - from wswscs - ,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 2000+1) z - where d_week_seq1=d_week_seq2-53 - order by d_week_seq1; - --- end template query2.tpl query 80 in stream 1 --- start template query38.tpl query 81 in stream 1 -select /* TPC-DS query38.tpl 0.54 */ count(*) from ( - select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1184 and 1184 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1184 and 1184 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1184 and 1184 + 11 -) hot_cust -limit 100; - --- end template query38.tpl query 81 in stream 1 --- start template query22a.tpl query 82 in stream 1 -with /* TPC-DS query22a.tpl 0.55 */ results as -(select i_product_name - ,i_brand - ,i_class - ,i_category - ,avg(inv_quantity_on_hand) qoh - from inventory - ,date_dim - ,item --- ,warehouse - where inv_date_sk=d_date_sk - and inv_item_sk=i_item_sk --- and inv_warehouse_sk = w_warehouse_sk - and d_month_seq between 1205 and 1205 + 11 - group by i_product_name,i_brand,i_class,i_category), -results_rollup as -(select i_product_name, i_brand, i_class, i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class,i_category -union all -select i_product_name, i_brand, i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class -union all -select i_product_name, i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand -union all -select i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name -union all -select null i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results) - select i_product_name, i_brand, i_class, i_category,qoh - from results_rollup - order by qoh, i_product_name, i_brand, i_class, i_category -limit 100; - --- end template query22a.tpl query 82 in stream 1 --- start template query89.tpl query 83 in stream 1 -select /* TPC-DS query89.tpl 0.56 */ * -from( -select i_category, i_class, i_brand, - s_store_name, s_company_name, - d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, s_store_name, s_company_name) - avg_monthly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - d_year in (2000) and - ((i_category in ('Shoes','Men','Children') and - i_class in ('mens','pants','infants') - ) - or (i_category in ('Sports','Electronics','Music') and - i_class in ('golf','audio','rock') - )) -group by i_category, i_class, i_brand, - s_store_name, s_company_name, d_moy) tmp1 -where case when (avg_monthly_sales <> 0) then (abs(sum_sales - avg_monthly_sales) / avg_monthly_sales) else null end > 0.1 -order by sum_sales - avg_monthly_sales, s_store_name -limit 100; - --- end template query89.tpl query 83 in stream 1 --- start template query7.tpl query 84 in stream 1 -select /* TPC-DS query7.tpl 0.2 */ i_item_id, - avg(ss_quantity) agg1, - avg(ss_list_price) agg2, - avg(ss_coupon_amt) agg3, - avg(ss_sales_price) agg4 - from store_sales, customer_demographics, date_dim, item, promotion - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_cdemo_sk = cd_demo_sk and - ss_promo_sk = p_promo_sk and - cd_gender = 'M' and - cd_marital_status = 'U' and - cd_education_status = 'Unknown' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 1998 - group by i_item_id - order by i_item_id - limit 100; - --- end template query7.tpl query 84 in stream 1 --- start template query10.tpl query 85 in stream 1 -select /* TPC-DS query10.tpl 0.26 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3, - cd_dep_count, - count(*) cnt4, - cd_dep_employed_count, - count(*) cnt5, - cd_dep_college_count, - count(*) cnt6 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_county in ('Ouachita County','King George County','Brazos County','Lyon County','Hancock County') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 3 and 3+3) and - (exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 3 ANd 3+3) or - exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 3 and 3+3)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count -limit 100; - --- end template query10.tpl query 85 in stream 1 --- start template query90.tpl query 86 in stream 1 -select /* TPC-DS query90.tpl 0.40 */ cast(amc as decimal(15,4))/cast(pmc as decimal(15,4)) am_pm_ratio - from ( select count(*) amc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 10 and 10+1 - and household_demographics.hd_dep_count = 0 - and web_page.wp_char_count between 5000 and 5200) at, - ( select count(*) pmc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 18 and 18+1 - and household_demographics.hd_dep_count = 0 - and web_page.wp_char_count between 5000 and 5200) pt - order by am_pm_ratio - limit 100; - --- end template query90.tpl query 86 in stream 1 --- start template query71.tpl query 87 in stream 1 -select /* TPC-DS query71.tpl 0.72 */ i_brand_id brand_id, i_brand brand,t_hour,t_minute, - sum(ext_price) ext_price - from item, (select ws_ext_sales_price as ext_price, - ws_sold_date_sk as sold_date_sk, - ws_item_sk as sold_item_sk, - ws_sold_time_sk as time_sk - from web_sales,date_dim - where d_date_sk = ws_sold_date_sk - and d_moy=11 - and d_year=2000 - union all - select cs_ext_sales_price as ext_price, - cs_sold_date_sk as sold_date_sk, - cs_item_sk as sold_item_sk, - cs_sold_time_sk as time_sk - from catalog_sales,date_dim - where d_date_sk = cs_sold_date_sk - and d_moy=11 - and d_year=2000 - union all - select ss_ext_sales_price as ext_price, - ss_sold_date_sk as sold_date_sk, - ss_item_sk as sold_item_sk, - ss_sold_time_sk as time_sk - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - and d_moy=11 - and d_year=2000 - ) tmp,time_dim - where - sold_item_sk = i_item_sk - and i_manager_id=1 - and time_sk = t_time_sk - and (t_meal_time = 'breakfast' or t_meal_time = 'dinner') - group by i_brand, i_brand_id,t_hour,t_minute - order by ext_price desc, i_brand_id - ; - --- end template query71.tpl query 87 in stream 1 --- start template query29.tpl query 88 in stream 1 -select /* TPC-DS query29.tpl 0.53 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,sum(ss_quantity) as store_sales_quantity - ,sum(sr_return_quantity) as store_returns_quantity - ,sum(cs_quantity) as catalog_sales_quantity - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 2000 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 4 + 3 - and d2.d_year = 2000 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_year in (2000,2000+1,2000+2) - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query29.tpl query 88 in stream 1 --- start template query73.tpl query 89 in stream 1 -select /* TPC-DS query73.tpl 0.79 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_buy_potential = '501-1000' or - household_demographics.hd_buy_potential = 'Unknown') - and household_demographics.hd_vehicle_count > 0 - and case when household_demographics.hd_vehicle_count > 0 then - household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count else null end > 1 - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_county in ('Oglethorpe County','Raleigh County','Dauphin County','Ziebach County') - group by ss_ticket_number,ss_customer_sk) dj,customer - where ss_customer_sk = c_customer_sk - and cnt between 1 and 5 - order by cnt desc, c_last_name asc; - --- end template query73.tpl query 89 in stream 1 --- start template query45.tpl query 90 in stream 1 -select /* TPC-DS query45.tpl 0.18 */ ca_zip, ca_state, sum(ws_sales_price) - from web_sales, customer, customer_address, date_dim, item - where ws_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ws_item_sk = i_item_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', '85392', '85460', '80348', '81792') - or - i_item_id in (select i_item_id - from item - where i_item_sk in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29) - ) - ) - and ws_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 2001 - group by ca_zip, ca_state - order by ca_zip, ca_state - limit 100; - --- end template query45.tpl query 90 in stream 1 --- start template query91.tpl query 91 in stream 1 -select /* TPC-DS query91.tpl 0.13 */ - cc_call_center_id Call_Center, - cc_name Call_Center_Name, - cc_manager Manager, - sum(cr_net_loss) Returns_Loss -from - call_center, - catalog_returns, - date_dim, - customer, - customer_address, - customer_demographics, - household_demographics -where - cr_call_center_sk = cc_call_center_sk -and cr_returned_date_sk = d_date_sk -and cr_returning_customer_sk= c_customer_sk -and cd_demo_sk = c_current_cdemo_sk -and hd_demo_sk = c_current_hdemo_sk -and ca_address_sk = c_current_addr_sk -and d_year = 1998 -and d_moy = 12 -and ( (cd_marital_status = 'M' and cd_education_status = 'Unknown') - or(cd_marital_status = 'W' and cd_education_status = 'Advanced Degree')) -and hd_buy_potential like '1001-5000%' -and ca_gmt_offset = -7 -group by cc_call_center_id,cc_name,cc_manager,cd_marital_status,cd_education_status -order by sum(cr_net_loss) desc; - --- end template query91.tpl query 91 in stream 1 --- start template query62.tpl query 92 in stream 1 -select /* TPC-DS query62.tpl 0.24 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 30) and - (ws_ship_date_sk - ws_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 60) and - (ws_ship_date_sk - ws_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 90) and - (ws_ship_date_sk - ws_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - web_sales - ,warehouse - ,ship_mode - ,web_site - ,date_dim -where - d_month_seq between 1201 and 1201 + 11 -and ws_ship_date_sk = d_date_sk -and ws_warehouse_sk = w_warehouse_sk -and ws_ship_mode_sk = sm_ship_mode_sk -and ws_web_site_sk = web_site_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -limit 100; - --- end template query62.tpl query 92 in stream 1 --- start template query44.tpl query 93 in stream 1 -select /* TPC-DS query44.tpl 0.4 */ asceding.rnk, i1.i_product_name best_performing, i2.i_product_name worst_performing -from(select * - from (select item_sk,rank() over (order by rank_col asc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 334 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 334 - and ss_addr_sk is null - group by ss_store_sk))V1)V11 - where rnk < 11) asceding, - (select * - from (select item_sk,rank() over (order by rank_col desc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 334 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 334 - and ss_addr_sk is null - group by ss_store_sk))V2)V21 - where rnk < 11) descending, -item i1, -item i2 -where asceding.rnk = descending.rnk - and i1.i_item_sk=asceding.item_sk - and i2.i_item_sk=descending.item_sk -order by asceding.rnk -limit 100; - --- end template query44.tpl query 93 in stream 1 --- start template query76.tpl query 94 in stream 1 -select /* TPC-DS query76.tpl 0.99 */ channel, col_name, d_year, d_qoy, i_category, COUNT(*) sales_cnt, SUM(ext_sales_price) sales_amt FROM ( - SELECT 'store' as channel, 'ss_addr_sk' col_name, d_year, d_qoy, i_category, ss_ext_sales_price ext_sales_price - FROM store_sales, item, date_dim - WHERE ss_addr_sk IS NULL - AND ss_sold_date_sk=d_date_sk - AND ss_item_sk=i_item_sk - UNION ALL - SELECT 'web' as channel, 'ws_warehouse_sk' col_name, d_year, d_qoy, i_category, ws_ext_sales_price ext_sales_price - FROM web_sales, item, date_dim - WHERE ws_warehouse_sk IS NULL - AND ws_sold_date_sk=d_date_sk - AND ws_item_sk=i_item_sk - UNION ALL - SELECT 'catalog' as channel, 'cs_promo_sk' col_name, d_year, d_qoy, i_category, cs_ext_sales_price ext_sales_price - FROM catalog_sales, item, date_dim - WHERE cs_promo_sk IS NULL - AND cs_sold_date_sk=d_date_sk - AND cs_item_sk=i_item_sk) foo -GROUP BY channel, col_name, d_year, d_qoy, i_category -ORDER BY channel, col_name, d_year, d_qoy, i_category -limit 100; - --- end template query76.tpl query 94 in stream 1 --- start template query23.tpl query 95 in stream 1 -with /* TPC-DS query23.tpl 0.68 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (1998,1998+1,1998+2,1998+3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1998,1998+1,1998+2,1998+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * -from - max_store_sales)) - select sum(sales) - from (select cs_quantity*cs_list_price sales - from catalog_sales - ,date_dim - where d_year = 1998 - and d_moy = 4 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - union all - select ws_quantity*ws_list_price sales - from web_sales - ,date_dim - where d_year = 1998 - and d_moy = 4 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer)) - limit 100; -with /* TPC-DS query23.tpl 0.68 part2 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (1998,1998 + 1,1998 + 2,1998 + 3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1998,1998+1,1998+2,1998+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * - from max_store_sales)) - select c_last_name,c_first_name,sales - from (select c_last_name,c_first_name,sum(cs_quantity*cs_list_price) sales - from catalog_sales - ,customer - ,date_dim - where d_year = 1998 - and d_moy = 4 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and cs_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name - union all - select c_last_name,c_first_name,sum(ws_quantity*ws_list_price) sales - from web_sales - ,customer - ,date_dim - where d_year = 1998 - and d_moy = 4 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and ws_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name) - order by c_last_name,c_first_name,sales - limit 100; - --- end template query23.tpl query 95 in stream 1 --- start template query56.tpl query 96 in stream 1 -with /* TPC-DS query56.tpl 0.83 */ ss as ( - select i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where i_item_id in (select - i_item_id -from item -where i_color in ('dim','peach','sandy')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 2 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - cs as ( - select i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('dim','peach','sandy')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 2 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - ws as ( - select i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('dim','peach','sandy')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 2 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id) - select i_item_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by total_sales, - i_item_id - limit 100; - --- end template query56.tpl query 96 in stream 1 --- start template query42.tpl query 97 in stream 1 -select /* TPC-DS query42.tpl 0.61 */ dt.d_year - ,item.i_category_id - ,item.i_category - ,sum(ss_ext_sales_price) - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=11 - and dt.d_year=1998 - group by dt.d_year - ,item.i_category_id - ,item.i_category - order by sum(ss_ext_sales_price) desc,dt.d_year - ,item.i_category_id - ,item.i_category -limit 100 ; - --- end template query42.tpl query 97 in stream 1 --- start template query39.tpl query 98 in stream 1 -with /* TPC-DS query39.tpl 0.5 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =2002 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=2 - and inv2.d_moy=2+1 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; -with /* TPC-DS query39.tpl 0.5 part2 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =2002 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=2 - and inv2.d_moy=2+1 - and inv1.cov > 1.5 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; - --- end template query39.tpl query 98 in stream 1 --- start template query74.tpl query 99 in stream 1 -with /* TPC-DS query74.tpl 0.76 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,avg(ss_net_paid) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1999,1999+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,avg(ws_net_paid) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - and d_year in (1999,1999+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - ) - select - t_s_secyear.customer_id, t_s_secyear.customer_first_name, t_s_secyear.customer_last_name - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.year = 1999 - and t_s_secyear.year = 1999+1 - and t_w_firstyear.year = 1999 - and t_w_secyear.year = 1999+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - order by 1,3,2 -limit 100; - --- end template query74.tpl query 99 in stream 1 diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/1TB/queries/query_10.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/1TB/queries/query_10.sql deleted file mode 100644 index 3ce704c8..00000000 --- a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/1TB/queries/query_10.sql +++ /dev/null @@ -1,5027 +0,0 @@ --- start template query43.tpl query 1 in stream 10 -select /* TPC-DS query43.tpl 0.15 */ s_store_name, s_store_id, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from date_dim, store_sales, store - where d_date_sk = ss_sold_date_sk and - s_store_sk = ss_store_sk and - s_gmt_offset = -6 and - d_year = 2002 - group by s_store_name, s_store_id - order by s_store_name, s_store_id,sun_sales,mon_sales,tue_sales,wed_sales,thu_sales,fri_sales,sat_sales - limit 100; - --- end template query43.tpl query 1 in stream 10 --- start template query50.tpl query 2 in stream 10 -select /* TPC-DS query50.tpl 0.60 */ - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 30) and - (sr_returned_date_sk - ss_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 60) and - (sr_returned_date_sk - ss_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 90) and - (sr_returned_date_sk - ss_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - store_sales - ,store_returns - ,store - ,date_dim d1 - ,date_dim d2 -where - d2.d_year = 2002 -and d2.d_moy = 8 -and ss_ticket_number = sr_ticket_number -and ss_item_sk = sr_item_sk -and ss_sold_date_sk = d1.d_date_sk -and sr_returned_date_sk = d2.d_date_sk -and ss_customer_sk = sr_customer_sk -and ss_store_sk = s_store_sk -group by - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -order by s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -limit 100; - --- end template query50.tpl query 2 in stream 10 --- start template query41.tpl query 3 in stream 10 -select /* TPC-DS query41.tpl 0.62 */ distinct(i_product_name) - from item i1 - where i_manufact_id between 792 and 792+40 - and (select count(*) as item_cnt - from item - where (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'blue' or i_color = 'ivory') and - (i_units = 'Dozen' or i_units = 'Case') and - (i_size = 'medium' or i_size = 'extra large') - ) or - (i_category = 'Women' and - (i_color = 'navy' or i_color = 'purple') and - (i_units = 'Unknown' or i_units = 'Each') and - (i_size = 'N/A' or i_size = 'small') - ) or - (i_category = 'Men' and - (i_color = 'orchid' or i_color = 'tan') and - (i_units = 'Bunch' or i_units = 'Lb') and - (i_size = 'petite' or i_size = 'large') - ) or - (i_category = 'Men' and - (i_color = 'wheat' or i_color = 'olive') and - (i_units = 'Cup' or i_units = 'Oz') and - (i_size = 'medium' or i_size = 'extra large') - ))) or - (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'goldenrod' or i_color = 'maroon') and - (i_units = 'Ton' or i_units = 'N/A') and - (i_size = 'medium' or i_size = 'extra large') - ) or - (i_category = 'Women' and - (i_color = 'azure' or i_color = 'pink') and - (i_units = 'Bundle' or i_units = 'Box') and - (i_size = 'N/A' or i_size = 'small') - ) or - (i_category = 'Men' and - (i_color = 'burlywood' or i_color = 'ghost') and - (i_units = 'Dram' or i_units = 'Tsp') and - (i_size = 'petite' or i_size = 'large') - ) or - (i_category = 'Men' and - (i_color = 'puff' or i_color = 'gainsboro') and - (i_units = 'Pound' or i_units = 'Ounce') and - (i_size = 'medium' or i_size = 'extra large') - )))) > 0 - order by i_product_name - limit 100; - --- end template query41.tpl query 3 in stream 10 --- start template query48.tpl query 4 in stream 10 -select /* TPC-DS query48.tpl 0.74 */ sum (ss_quantity) - from store_sales, store, customer_demographics, customer_address, date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2000 - and - ( - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'U' - and - cd_education_status = '4 yr Degree' - and - ss_sales_price between 100.00 and 150.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'M' - and - cd_education_status = 'Advanced Degree' - and - ss_sales_price between 50.00 and 100.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'S' - and - cd_education_status = 'Unknown' - and - ss_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('MI', 'OH', 'NY') - and ss_net_profit between 0 and 2000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('WA', 'VA', 'NV') - and ss_net_profit between 150 and 3000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('NE', 'KS', 'GA') - and ss_net_profit between 50 and 25000 - ) - ) -; - --- end template query48.tpl query 4 in stream 10 --- start template query54.tpl query 5 in stream 10 -with /* TPC-DS query54.tpl 0.81 */ my_customers as ( - select distinct c_customer_sk - , c_current_addr_sk - from - ( select cs_sold_date_sk sold_date_sk, - cs_bill_customer_sk customer_sk, - cs_item_sk item_sk - from catalog_sales - union all - select ws_sold_date_sk sold_date_sk, - ws_bill_customer_sk customer_sk, - ws_item_sk item_sk - from web_sales - ) cs_or_ws_sales, - item, - date_dim, - customer - where sold_date_sk = d_date_sk - and item_sk = i_item_sk - and i_category = 'Music' - and i_class = 'classical' - and c_customer_sk = cs_or_ws_sales.customer_sk - and d_moy = 2 - and d_year = 1999 - ) - , my_revenue as ( - select c_customer_sk, - sum(ss_ext_sales_price) as revenue - from my_customers, - store_sales, - customer_address, - store, - date_dim - where c_current_addr_sk = ca_address_sk - and ca_county = s_county - and ca_state = s_state - and ss_sold_date_sk = d_date_sk - and c_customer_sk = ss_customer_sk - and d_month_seq between (select distinct d_month_seq+1 - from date_dim where d_year = 1999 and d_moy = 2) - and (select distinct d_month_seq+3 - from date_dim where d_year = 1999 and d_moy = 2) - group by c_customer_sk - ) - , segments as - (select cast((revenue/50) as bigint) as segment - from my_revenue - ) - select segment, count(*) as num_customers, segment*50 as segment_base - from segments - group by segment - order by segment, num_customers - limit 100; - --- end template query54.tpl query 5 in stream 10 --- start template query53.tpl query 6 in stream 10 -select /* TPC-DS query53.tpl 0.88 */ * from -(select i_manufact_id, -sum(ss_sales_price) sum_sales, -avg(sum(ss_sales_price)) over (partition by i_manufact_id) avg_quarterly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and -ss_sold_date_sk = d_date_sk and -ss_store_sk = s_store_sk and -d_month_seq in (1193,1193+1,1193+2,1193+3,1193+4,1193+5,1193+6,1193+7,1193+8,1193+9,1193+10,1193+11) and -((i_category in ('Books','Children','Electronics') and -i_class in ('personal','portable','reference','self-help') and -i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) -or(i_category in ('Women','Music','Men') and -i_class in ('accessories','classical','fragrances','pants') and -i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manufact_id, d_qoy ) tmp1 -where case when avg_quarterly_sales > 0 - then abs (sum_sales - avg_quarterly_sales)/ avg_quarterly_sales - else null end > 0.1 -order by avg_quarterly_sales, - sum_sales, - i_manufact_id -limit 100; - --- end template query53.tpl query 6 in stream 10 --- start template query31.tpl query 7 in stream 10 -with /* TPC-DS query31.tpl 0.50 */ ss as - (select ca_county,d_qoy, d_year,sum(ss_ext_sales_price) as store_sales - from store_sales,date_dim,customer_address - where ss_sold_date_sk = d_date_sk - and ss_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year), - ws as - (select ca_county,d_qoy, d_year,sum(ws_ext_sales_price) as web_sales - from web_sales,date_dim,customer_address - where ws_sold_date_sk = d_date_sk - and ws_bill_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year) - select - ss1.ca_county - ,ss1.d_year - ,ws2.web_sales/ws1.web_sales web_q1_q2_increase - ,ss2.store_sales/ss1.store_sales store_q1_q2_increase - ,ws3.web_sales/ws2.web_sales web_q2_q3_increase - ,ss3.store_sales/ss2.store_sales store_q2_q3_increase - from - ss ss1 - ,ss ss2 - ,ss ss3 - ,ws ws1 - ,ws ws2 - ,ws ws3 - where - ss1.d_qoy = 1 - and ss1.d_year = 2000 - and ss1.ca_county = ss2.ca_county - and ss2.d_qoy = 2 - and ss2.d_year = 2000 - and ss2.ca_county = ss3.ca_county - and ss3.d_qoy = 3 - and ss3.d_year = 2000 - and ss1.ca_county = ws1.ca_county - and ws1.d_qoy = 1 - and ws1.d_year = 2000 - and ws1.ca_county = ws2.ca_county - and ws2.d_qoy = 2 - and ws2.d_year = 2000 - and ws1.ca_county = ws3.ca_county - and ws3.d_qoy = 3 - and ws3.d_year =2000 - and case when ws1.web_sales > 0 then ws2.web_sales/ws1.web_sales else null end - > case when ss1.store_sales > 0 then ss2.store_sales/ss1.store_sales else null end - and case when ws2.web_sales > 0 then ws3.web_sales/ws2.web_sales else null end - > case when ss2.store_sales > 0 then ss3.store_sales/ss2.store_sales else null end - order by ss1.ca_county; - --- end template query31.tpl query 7 in stream 10 --- start template query39.tpl query 8 in stream 10 -with /* TPC-DS query39.tpl 0.5 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =1999 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=2 - and inv2.d_moy=2+1 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; -with /* TPC-DS query39.tpl 0.5 part2 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =1999 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=2 - and inv2.d_moy=2+1 - and inv1.cov > 1.5 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; - --- end template query39.tpl query 8 in stream 10 --- start template query2.tpl query 9 in stream 10 -with /* TPC-DS query2.tpl 0.84 */ wscs as - (select sold_date_sk - ,sales_price - from (select ws_sold_date_sk sold_date_sk - ,ws_ext_sales_price sales_price - from web_sales - union all - select cs_sold_date_sk sold_date_sk - ,cs_ext_sales_price sales_price - from catalog_sales)), - wswscs as - (select d_week_seq, - sum(case when (d_day_name='Sunday') then sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then sales_price else null end) sat_sales - from wscs - ,date_dim - where d_date_sk = sold_date_sk - group by d_week_seq) - select d_week_seq1 - ,round(sun_sales1/sun_sales2,2) - ,round(mon_sales1/mon_sales2,2) - ,round(tue_sales1/tue_sales2,2) - ,round(wed_sales1/wed_sales2,2) - ,round(thu_sales1/thu_sales2,2) - ,round(fri_sales1/fri_sales2,2) - ,round(sat_sales1/sat_sales2,2) - from - (select wswscs.d_week_seq d_week_seq1 - ,sun_sales sun_sales1 - ,mon_sales mon_sales1 - ,tue_sales tue_sales1 - ,wed_sales wed_sales1 - ,thu_sales thu_sales1 - ,fri_sales fri_sales1 - ,sat_sales sat_sales1 - from wswscs,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 2000) y, - (select wswscs.d_week_seq d_week_seq2 - ,sun_sales sun_sales2 - ,mon_sales mon_sales2 - ,tue_sales tue_sales2 - ,wed_sales wed_sales2 - ,thu_sales thu_sales2 - ,fri_sales fri_sales2 - ,sat_sales sat_sales2 - from wswscs - ,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 2000+1) z - where d_week_seq1=d_week_seq2-53 - order by d_week_seq1; - --- end template query2.tpl query 9 in stream 10 --- start template query96.tpl query 10 in stream 10 -select /* TPC-DS query96.tpl 0.1 */ count(*) -from store_sales - ,household_demographics - ,time_dim, store -where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 20 - and time_dim.t_minute >= 30 - and household_demographics.hd_dep_count = 6 - and store.s_store_name = 'ese' -order by count(*) -limit 100; - --- end template query96.tpl query 10 in stream 10 --- start template query93.tpl query 11 in stream 10 -select /* TPC-DS query93.tpl 0.52 */ ss_customer_sk - ,sum(act_sales) sumsales - from (select ss_item_sk - ,ss_ticket_number - ,ss_customer_sk - ,case when sr_return_quantity is not null then (ss_quantity-sr_return_quantity)*ss_sales_price - else (ss_quantity*ss_sales_price) end act_sales - from store_sales left outer join store_returns on (sr_item_sk = ss_item_sk - and sr_ticket_number = ss_ticket_number) - ,reason - where sr_reason_sk = r_reason_sk - and r_reason_desc = 'reason 25') t - group by ss_customer_sk - order by sumsales, ss_customer_sk -limit 100; - --- end template query93.tpl query 11 in stream 10 --- start template query15.tpl query 12 in stream 10 -select /* TPC-DS query15.tpl 0.57 */ ca_zip - ,sum(cs_sales_price) - from catalog_sales - ,customer - ,customer_address - ,date_dim - where cs_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', - '85392', '85460', '80348', '81792') - or ca_state in ('CA','WA','GA') - or cs_sales_price > 500) - and cs_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 2002 - group by ca_zip - order by ca_zip - limit 100; - --- end template query15.tpl query 12 in stream 10 --- start template query91.tpl query 13 in stream 10 -select /* TPC-DS query91.tpl 0.13 */ - cc_call_center_id Call_Center, - cc_name Call_Center_Name, - cc_manager Manager, - sum(cr_net_loss) Returns_Loss -from - call_center, - catalog_returns, - date_dim, - customer, - customer_address, - customer_demographics, - household_demographics -where - cr_call_center_sk = cc_call_center_sk -and cr_returned_date_sk = d_date_sk -and cr_returning_customer_sk= c_customer_sk -and cd_demo_sk = c_current_cdemo_sk -and hd_demo_sk = c_current_hdemo_sk -and ca_address_sk = c_current_addr_sk -and d_year = 2000 -and d_moy = 11 -and ( (cd_marital_status = 'M' and cd_education_status = 'Unknown') - or(cd_marital_status = 'W' and cd_education_status = 'Advanced Degree')) -and hd_buy_potential like '0-500%' -and ca_gmt_offset = -7 -group by cc_call_center_id,cc_name,cc_manager,cd_marital_status,cd_education_status -order by sum(cr_net_loss) desc; - --- end template query91.tpl query 13 in stream 10 --- start template query21.tpl query 14 in stream 10 -select /* TPC-DS query21.tpl 0.14 */ * - from(select w_warehouse_name - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('1998-02-24' as date)) - then inv_quantity_on_hand - else 0 end) as inv_before - ,sum(case when (cast(d_date as date) >= cast ('1998-02-24' as date)) - then inv_quantity_on_hand - else 0 end) as inv_after - from inventory - ,warehouse - ,item - ,date_dim - where i_current_price between 0.99 and 1.49 - and i_item_sk = inv_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('1998-02-24' as date)) - and dateadd(day,30,cast ('1998-02-24' as date)) - group by w_warehouse_name, i_item_id) x - where (case when inv_before > 0 - then inv_after / inv_before - else null - end) between 2.0/3.0 and 3.0/2.0 - order by w_warehouse_name - ,i_item_id - limit 100; - --- end template query21.tpl query 14 in stream 10 --- start template query18a.tpl query 15 in stream 10 -with /* TPC-DS query18a.tpl 0.90 */ results as - (select i_item_id, - ca_country, - ca_state, - ca_county, - cast(cs_quantity as decimal(12,2)) agg1, - cast(cs_list_price as decimal(12,2)) agg2, - cast(cs_coupon_amt as decimal(12,2)) agg3, - cast(cs_sales_price as decimal(12,2)) agg4, - cast(cs_net_profit as decimal(12,2)) agg5, - cast(c_birth_year as decimal(12,2)) agg6, - cast(cd1.cd_dep_count as decimal(12,2)) agg7 - from catalog_sales, customer_demographics cd1, customer_demographics cd2, customer, customer_address, date_dim, item - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd1.cd_demo_sk and - cs_bill_customer_sk = c_customer_sk and - cd1.cd_gender = 'F' and - cd1.cd_education_status = 'Advanced Degree' and - c_current_cdemo_sk = cd2.cd_demo_sk and - c_current_addr_sk = ca_address_sk and - c_birth_month in (3,9,7,8,10,4) and - d_year = 1998 and - ca_state in ('AK','IA','MN','AL','IN','MO','NC') - ) - select i_item_id, ca_country, ca_state, ca_county, agg1, agg2, agg3, agg4, agg5, agg6, agg7 - from ( - select i_item_id, ca_country, ca_state, ca_county, avg(agg1) agg1, - avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state, ca_county - union all - select i_item_id, ca_country, ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state - union all - select i_item_id, ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country - union all - select i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - ) foo - order by ca_country, ca_state, ca_county, i_item_id - limit 100; - --- end template query18a.tpl query 15 in stream 10 --- start template query32.tpl query 16 in stream 10 -select /* TPC-DS query32.tpl 0.7 */ sum(cs_ext_discount_amt) as "excess discount amount" -from - catalog_sales - ,item - ,date_dim -where -i_manufact_id = 290 -and i_item_sk = cs_item_sk -and d_date between '2000-03-22' and - dateadd(day,90,cast('2000-03-22' as date)) -and d_date_sk = cs_sold_date_sk -and cs_ext_discount_amt - > ( - select - 1.3 * avg(cs_ext_discount_amt) - from - catalog_sales - ,date_dim - where - cs_item_sk = i_item_sk - and d_date between '2000-03-22' and - dateadd(day,90,cast('2000-03-22' as date)) - and d_date_sk = cs_sold_date_sk - ) -limit 100; - --- end template query32.tpl query 16 in stream 10 --- start template query63.tpl query 17 in stream 10 -select /* TPC-DS query63.tpl 0.27 */ * -from (select i_manager_id - ,sum(ss_sales_price) sum_sales - ,avg(sum(ss_sales_price)) over (partition by i_manager_id) avg_monthly_sales - from item - ,store_sales - ,date_dim - ,store - where ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and d_month_seq in (1184,1184+1,1184+2,1184+3,1184+4,1184+5,1184+6,1184+7,1184+8,1184+9,1184+10,1184+11) - and (( i_category in ('Books','Children','Electronics') - and i_class in ('personal','portable','reference','self-help') - and i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) - or( i_category in ('Women','Music','Men') - and i_class in ('accessories','classical','fragrances','pants') - and i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manager_id, d_moy) tmp1 -where case when avg_monthly_sales > 0 then abs (sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 -order by i_manager_id - ,avg_monthly_sales - ,sum_sales -limit 100; - --- end template query63.tpl query 17 in stream 10 --- start template query24.tpl query 18 in stream 10 -with /* TPC-DS query24.tpl 0.92 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_ext_sales_price) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip -and s_market_id=6 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'frosted' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; -with /* TPC-DS query24.tpl 0.92 part2 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_ext_sales_price) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip - and s_market_id = 6 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'pink' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; - --- end template query24.tpl query 18 in stream 10 --- start template query66.tpl query 19 in stream 10 -select /* TPC-DS query66.tpl 0.39 */ - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - ,sum(jan_sales) as jan_sales - ,sum(feb_sales) as feb_sales - ,sum(mar_sales) as mar_sales - ,sum(apr_sales) as apr_sales - ,sum(may_sales) as may_sales - ,sum(jun_sales) as jun_sales - ,sum(jul_sales) as jul_sales - ,sum(aug_sales) as aug_sales - ,sum(sep_sales) as sep_sales - ,sum(oct_sales) as oct_sales - ,sum(nov_sales) as nov_sales - ,sum(dec_sales) as dec_sales - ,sum(jan_sales/w_warehouse_sq_ft) as jan_sales_per_sq_foot - ,sum(feb_sales/w_warehouse_sq_ft) as feb_sales_per_sq_foot - ,sum(mar_sales/w_warehouse_sq_ft) as mar_sales_per_sq_foot - ,sum(apr_sales/w_warehouse_sq_ft) as apr_sales_per_sq_foot - ,sum(may_sales/w_warehouse_sq_ft) as may_sales_per_sq_foot - ,sum(jun_sales/w_warehouse_sq_ft) as jun_sales_per_sq_foot - ,sum(jul_sales/w_warehouse_sq_ft) as jul_sales_per_sq_foot - ,sum(aug_sales/w_warehouse_sq_ft) as aug_sales_per_sq_foot - ,sum(sep_sales/w_warehouse_sq_ft) as sep_sales_per_sq_foot - ,sum(oct_sales/w_warehouse_sq_ft) as oct_sales_per_sq_foot - ,sum(nov_sales/w_warehouse_sq_ft) as nov_sales_per_sq_foot - ,sum(dec_sales/w_warehouse_sq_ft) as dec_sales_per_sq_foot - ,sum(jan_net) as jan_net - ,sum(feb_net) as feb_net - ,sum(mar_net) as mar_net - ,sum(apr_net) as apr_net - ,sum(may_net) as may_net - ,sum(jun_net) as jun_net - ,sum(jul_net) as jul_net - ,sum(aug_net) as aug_net - ,sum(sep_net) as sep_net - ,sum(oct_net) as oct_net - ,sum(nov_net) as nov_net - ,sum(dec_net) as dec_net - from ( - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'AIRBORNE' || ',' || 'TBS' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then ws_ext_list_price* ws_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then ws_ext_list_price* ws_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then ws_ext_list_price* ws_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then ws_ext_list_price* ws_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then ws_ext_list_price* ws_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then ws_ext_list_price* ws_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then ws_ext_list_price* ws_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then ws_ext_list_price* ws_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then ws_ext_list_price* ws_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then ws_ext_list_price* ws_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then ws_ext_list_price* ws_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then ws_ext_list_price* ws_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as dec_net - from - web_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - ws_warehouse_sk = w_warehouse_sk - and ws_sold_date_sk = d_date_sk - and ws_sold_time_sk = t_time_sk - and ws_ship_mode_sk = sm_ship_mode_sk - and d_year = 1998 - and t_time between 13476 and 13476+28800 - and sm_carrier in ('AIRBORNE','TBS') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - union all - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'AIRBORNE' || ',' || 'TBS' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then cs_ext_sales_price* cs_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then cs_ext_sales_price* cs_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then cs_ext_sales_price* cs_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then cs_ext_sales_price* cs_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then cs_ext_sales_price* cs_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then cs_ext_sales_price* cs_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then cs_ext_sales_price* cs_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then cs_ext_sales_price* cs_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then cs_ext_sales_price* cs_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then cs_ext_sales_price* cs_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then cs_ext_sales_price* cs_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then cs_ext_sales_price* cs_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as dec_net - from - catalog_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and cs_sold_time_sk = t_time_sk - and cs_ship_mode_sk = sm_ship_mode_sk - and d_year = 1998 - and t_time between 13476 AND 13476+28800 - and sm_carrier in ('AIRBORNE','TBS') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - ) x - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - order by w_warehouse_name - limit 100; - --- end template query66.tpl query 19 in stream 10 --- start template query70a.tpl query 20 in stream 10 -with /* TPC-DS query70a.tpl 0.34 */ results as -( select - sum(ss_net_profit) as total_sum ,s_state ,s_county, 0 as gstate, 0 as g_county - from - store_sales - ,date_dim d1 - ,store - where - d1.d_month_seq between 1206 and 1206 + 11 - and d1.d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - and s_state in - ( select s_state - from (select s_state as s_state, - rank() over ( partition by s_state order by sum(ss_net_profit) desc) as ranking - from store_sales, store, date_dim - where d_month_seq between 1206 and 1206 + 11 - and d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - group by s_state - ) tmp1 - where ranking <= 5) - group by s_state,s_county) , - results_rollup as -(select total_sum ,s_state ,s_county, 0 as g_state, 0 as g_county, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum,s_state, NULL as s_county, 0 as g_state, 1 as g_county, 1 as lochierarchy from results group by s_state - union - select sum(total_sum) as total_sum ,NULL as s_state ,NULL as s_county, 1 as g_state, 1 as g_county, 2 as lochierarchy from results) - select total_sum ,s_state ,s_county, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_county = 0 then s_state end - order by total_sum desc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then s_state end - ,rank_within_parent - limit 100; - --- end template query70a.tpl query 20 in stream 10 --- start template query36a.tpl query 21 in stream 10 -with /* TPC-DS query36a.tpl 0.21 */ results as - (select - sum(ss_net_profit) as ss_net_profit, sum(ss_ext_sales_price) as ss_ext_sales_price, - sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin - ,i_category - ,i_class - ,0 as g_category, 0 as g_class - from - store_sales - ,date_dim d1 - ,item - ,store - where - d1.d_year = 2000 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and s_state in ('MI','WA','GA','AL', - 'SD','MN','IN','AL') - group by i_category,i_class) - , - results_rollup as - (select gross_margin ,i_category ,i_class,0 as t_category, 0 as t_class, 0 as lochierarchy from results - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - i_category, NULL AS i_class, 0 as t_category, 1 as t_class, 1 as lochierarchy from results group by i_category - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - NULL AS i_category ,NULL AS i_class, 1 as t_category, 1 as t_class, 2 as lochierarchy from results) - select - gross_margin ,i_category ,i_class, lochierarchy,rank() over ( - partition by lochierarchy, case when t_class = 0 then i_category end - order by gross_margin asc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then i_category end - ,rank_within_parent - limit 100; - --- end template query36a.tpl query 21 in stream 10 --- start template query20.tpl query 22 in stream 10 -select /* TPC-DS query20.tpl 0.65 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(cs_ext_sales_price) as itemrevenue - ,sum(cs_ext_sales_price)*100/sum(sum(cs_ext_sales_price)) over - (partition by i_class) as revenueratio - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and i_category in ('Music', 'Home', 'Shoes') - and cs_sold_date_sk = d_date_sk - and d_date between cast('2001-04-18' as date) - and dateadd(day,30,cast('2001-04-18' as date)) - group by i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - order by i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query20.tpl query 22 in stream 10 --- start template query30.tpl query 23 in stream 10 -with /* TPC-DS query30.tpl 0.75 */ customer_total_return as - (select wr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(wr_return_amt) as ctr_total_return - from web_returns - ,date_dim - ,customer_address - where wr_returned_date_sk = d_date_sk - and d_year =1999 - and wr_returning_addr_sk = ca_address_sk - group by wr_returning_customer_sk - ,ca_state) - select c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'CA' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return -limit 100; - --- end template query30.tpl query 23 in stream 10 --- start template query25.tpl query 24 in stream 10 -select /* TPC-DS query25.tpl 0.9 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,stddev_samp(ss_net_profit) as store_sales_profit - ,stddev_samp(sr_net_loss) as store_returns_loss - ,stddev_samp(cs_net_profit) as catalog_sales_profit - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 1998 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 10 - and d2.d_year = 1998 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_moy between 4 and 10 - and d3.d_year = 1998 - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query25.tpl query 24 in stream 10 --- start template query7.tpl query 25 in stream 10 -select /* TPC-DS query7.tpl 0.2 */ i_item_id, - avg(ss_quantity) agg1, - avg(ss_list_price) agg2, - avg(ss_coupon_amt) agg3, - avg(ss_sales_price) agg4 - from store_sales, customer_demographics, date_dim, item, promotion - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_cdemo_sk = cd_demo_sk and - ss_promo_sk = p_promo_sk and - cd_gender = 'M' and - cd_marital_status = 'W' and - cd_education_status = 'Unknown' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 2001 - group by i_item_id - order by i_item_id - limit 100; - --- end template query7.tpl query 25 in stream 10 --- start template query1.tpl query 26 in stream 10 -with /* TPC-DS query1.tpl 0.12 */ customer_total_return as -(select sr_customer_sk as ctr_customer_sk -,sr_store_sk as ctr_store_sk -,sum(SR_RETURN_AMT_INC_TAX) as ctr_total_return -from store_returns -,date_dim -where sr_returned_date_sk = d_date_sk -and d_year =2002 -group by sr_customer_sk -,sr_store_sk) - select c_customer_id -from customer_total_return ctr1 -,store -,customer -where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 -from customer_total_return ctr2 -where ctr1.ctr_store_sk = ctr2.ctr_store_sk) -and s_store_sk = ctr1.ctr_store_sk -and s_state = 'OH' -and ctr1.ctr_customer_sk = c_customer_sk -order by c_customer_id -limit 100; - --- end template query1.tpl query 26 in stream 10 --- start template query98.tpl query 27 in stream 10 -select /* TPC-DS query98.tpl 0.32 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ss_ext_sales_price) as itemrevenue - ,sum(ss_ext_sales_price)*100/sum(sum(ss_ext_sales_price)) over - (partition by i_class) as revenueratio -from - store_sales - ,item - ,date_dim -where - ss_item_sk = i_item_sk - and i_category in ('Shoes', 'Music', 'Children') - and ss_sold_date_sk = d_date_sk - and d_date between cast('2000-01-31' as date) - and dateadd(day,30,cast('2000-01-31' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio; - --- end template query98.tpl query 27 in stream 10 --- start template query69.tpl query 28 in stream 10 -select /* TPC-DS query69.tpl 0.28 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_state in ('UT','PA','ME') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 1999 and - d_moy between 3 and 3+2) and - (not exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 1999 and - d_moy between 3 and 3+2) and - not exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 1999 and - d_moy between 3 and 3+2)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - limit 100; - --- end template query69.tpl query 28 in stream 10 --- start template query47.tpl query 29 in stream 10 -with /* TPC-DS query47.tpl 0.42 */ v1 as( - select i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, - s_store_name, s_company_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - s_store_name, s_company_name - order by d_year, d_moy) rn - from item, store_sales, date_dim, store - where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - ( - d_year = 1999 or - ( d_year = 1999-1 and d_moy =12) or - ( d_year = 1999+1 and d_moy =1) - ) - group by i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy), - v2 as( - select v1.i_brand - ,v1.d_year, v1.d_moy - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1.s_store_name = v1_lag.s_store_name and - v1.s_store_name = v1_lead.s_store_name and - v1.s_company_name = v1_lag.s_company_name and - v1.s_company_name = v1_lead.s_company_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 1999 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, psum - limit 100; - --- end template query47.tpl query 29 in stream 10 --- start template query94.tpl query 30 in stream 10 -select /* TPC-DS query94.tpl 0.17 */ - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2002-5-01' and - dateadd(day,60,cast('2002-5-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'GA' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and exists (select * - from web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) -and not exists(select * - from web_returns wr1 - where ws1.ws_order_number = wr1.wr_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query94.tpl query 30 in stream 10 --- start template query82.tpl query 31 in stream 10 -select /* TPC-DS query82.tpl 0.67 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, store_sales - where i_current_price between 23 and 23+30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('2000-03-09' as date) and dateadd(day,60,cast('2000-03-09' as date)) - and i_manufact_id in (172,190,323,452) - and inv_quantity_on_hand between 100 and 500 - and ss_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query82.tpl query 31 in stream 10 --- start template query37.tpl query 32 in stream 10 -select /* TPC-DS query37.tpl 0.31 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, catalog_sales - where i_current_price between 18 and 18 + 30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('2001-07-20' as date) and dateadd(day,60,cast('2001-07-20' as date)) - and i_manufact_id in (772,813,798,897) - and inv_quantity_on_hand between 100 and 500 - and cs_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query37.tpl query 32 in stream 10 --- start template query64.tpl query 33 in stream 10 -with /* TPC-DS query64.tpl 0.20 */ cs_ui as - (select cs_item_sk - ,sum(cs_ext_list_price) as sale,sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit) as refund - from catalog_sales - ,catalog_returns - where cs_item_sk = cr_item_sk - and cs_order_number = cr_order_number - group by cs_item_sk - having sum(cs_ext_list_price)>2*sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit)), -cross_sales as - (select i_product_name product_name - ,i_item_sk item_sk - ,s_store_name store_name - ,s_zip store_zip - ,ad1.ca_street_number b_street_number - ,ad1.ca_street_name b_street_name - ,ad1.ca_city b_city - ,ad1.ca_zip b_zip - ,ad2.ca_street_number c_street_number - ,ad2.ca_street_name c_street_name - ,ad2.ca_city c_city - ,ad2.ca_zip c_zip - ,d1.d_year as syear - ,d2.d_year as fsyear - ,d3.d_year s2year - ,count(*) cnt - ,sum(ss_wholesale_cost) s1 - ,sum(ss_list_price) s2 - ,sum(ss_coupon_amt) s3 - FROM store_sales - ,store_returns - ,cs_ui - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,customer - ,customer_demographics cd1 - ,customer_demographics cd2 - ,promotion - ,household_demographics hd1 - ,household_demographics hd2 - ,customer_address ad1 - ,customer_address ad2 - ,income_band ib1 - ,income_band ib2 - ,item - WHERE ss_store_sk = s_store_sk AND - ss_sold_date_sk = d1.d_date_sk AND - ss_customer_sk = c_customer_sk AND - ss_cdemo_sk= cd1.cd_demo_sk AND - ss_hdemo_sk = hd1.hd_demo_sk AND - ss_addr_sk = ad1.ca_address_sk and - ss_item_sk = i_item_sk and - ss_item_sk = sr_item_sk and - ss_ticket_number = sr_ticket_number and - ss_item_sk = cs_ui.cs_item_sk and - c_current_cdemo_sk = cd2.cd_demo_sk AND - c_current_hdemo_sk = hd2.hd_demo_sk AND - c_current_addr_sk = ad2.ca_address_sk and - c_first_sales_date_sk = d2.d_date_sk and - c_first_shipto_date_sk = d3.d_date_sk and - ss_promo_sk = p_promo_sk and - hd1.hd_income_band_sk = ib1.ib_income_band_sk and - hd2.hd_income_band_sk = ib2.ib_income_band_sk and - cd1.cd_marital_status <> cd2.cd_marital_status and - i_color in ('lime','rose','blush','sandy','lavender','pale') and - i_current_price between 72 and 72 + 10 and - i_current_price between 72 + 1 and 72 + 15 -group by i_product_name - ,i_item_sk - ,s_store_name - ,s_zip - ,ad1.ca_street_number - ,ad1.ca_street_name - ,ad1.ca_city - ,ad1.ca_zip - ,ad2.ca_street_number - ,ad2.ca_street_name - ,ad2.ca_city - ,ad2.ca_zip - ,d1.d_year - ,d2.d_year - ,d3.d_year -) -select cs1.product_name - ,cs1.store_name - ,cs1.store_zip - ,cs1.b_street_number - ,cs1.b_street_name - ,cs1.b_city - ,cs1.b_zip - ,cs1.c_street_number - ,cs1.c_street_name - ,cs1.c_city - ,cs1.c_zip - ,cs1.syear - ,cs1.cnt - ,cs1.s1 as s11 - ,cs1.s2 as s21 - ,cs1.s3 as s31 - ,cs2.s1 as s12 - ,cs2.s2 as s22 - ,cs2.s3 as s32 - ,cs2.syear - ,cs2.cnt -from cross_sales cs1,cross_sales cs2 -where cs1.item_sk=cs2.item_sk and - cs1.syear = 1999 and - cs2.syear = 1999 + 1 and - cs2.cnt <= cs1.cnt and - cs1.store_name = cs2.store_name and - cs1.store_zip = cs2.store_zip -order by cs1.product_name - ,cs1.store_name - ,cs2.cnt - ,cs1.s1 - ,cs2.s1; - --- end template query64.tpl query 33 in stream 10 --- start template query86a.tpl query 34 in stream 10 -with /* TPC-DS query86a.tpl 0.11 */ results as -( select sum(ws_net_paid) as total_sum, i_category, i_class, 0 as g_category, 0 as g_class - from - web_sales - ,date_dim d1 - ,item - where - d1.d_month_seq between 1194 and 1194+11 - and d1.d_date_sk = ws_sold_date_sk - and i_item_sk = ws_item_sk - group by i_category,i_class - ) , - - results_rollup as -( select total_sum ,i_category ,i_class, g_category, g_class, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum, i_category, NULL as i_class, 0 as g_category, 1 as g_class, 1 as lochierarchy from results group by i_category - union - select sum(total_sum) as total_sum, NULL as i_category, NULL as i_class, 1 as g_category, 1 as g_class, 2 as lochierarchy from results) - select - total_sum ,i_category ,i_class, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_class = 0 then i_category end - order by total_sum desc) as rank_within_parent - from - results_rollup - order by - lochierarchy desc, - case when lochierarchy = 0 then i_category end, - rank_within_parent - limit 100; - --- end template query86a.tpl query 34 in stream 10 --- start template query87.tpl query 35 in stream 10 -select /* TPC-DS query87.tpl 0.77 */ count(*) -from ((select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1188 and 1188+11) - except - (select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1188 and 1188+11) - except - (select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1188 and 1188+11) -) cool_cust -; - --- end template query87.tpl query 35 in stream 10 --- start template query28.tpl query 36 in stream 10 -select /* TPC-DS query28.tpl 0.36 */ * -from (select avg(ss_list_price) B1_LP - ,count(ss_list_price) B1_CNT - ,count(distinct ss_list_price) B1_CNTD - from store_sales - where ss_quantity between 0 and 5 - and (ss_list_price between 156 and 156+10 - or ss_coupon_amt between 10211 and 10211+1000 - or ss_wholesale_cost between 43 and 43+20)) B1, - (select avg(ss_list_price) B2_LP - ,count(ss_list_price) B2_CNT - ,count(distinct ss_list_price) B2_CNTD - from store_sales - where ss_quantity between 6 and 10 - and (ss_list_price between 183 and 183+10 - or ss_coupon_amt between 14349 and 14349+1000 - or ss_wholesale_cost between 44 and 44+20)) B2, - (select avg(ss_list_price) B3_LP - ,count(ss_list_price) B3_CNT - ,count(distinct ss_list_price) B3_CNTD - from store_sales - where ss_quantity between 11 and 15 - and (ss_list_price between 184 and 184+10 - or ss_coupon_amt between 10438 and 10438+1000 - or ss_wholesale_cost between 75 and 75+20)) B3, - (select avg(ss_list_price) B4_LP - ,count(ss_list_price) B4_CNT - ,count(distinct ss_list_price) B4_CNTD - from store_sales - where ss_quantity between 16 and 20 - and (ss_list_price between 62 and 62+10 - or ss_coupon_amt between 5443 and 5443+1000 - or ss_wholesale_cost between 80 and 80+20)) B4, - (select avg(ss_list_price) B5_LP - ,count(ss_list_price) B5_CNT - ,count(distinct ss_list_price) B5_CNTD - from store_sales - where ss_quantity between 21 and 25 - and (ss_list_price between 24 and 24+10 - or ss_coupon_amt between 10899 and 10899+1000 - or ss_wholesale_cost between 22 and 22+20)) B5, - (select avg(ss_list_price) B6_LP - ,count(ss_list_price) B6_CNT - ,count(distinct ss_list_price) B6_CNTD - from store_sales - where ss_quantity between 26 and 30 - and (ss_list_price between 50 and 50+10 - or ss_coupon_amt between 4189 and 4189+1000 - or ss_wholesale_cost between 45 and 45+20)) B6 -limit 100; - --- end template query28.tpl query 36 in stream 10 --- start template query55.tpl query 37 in stream 10 -select /* TPC-DS query55.tpl 0.82 */ i_brand_id brand_id, i_brand brand, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=52 - and d_moy=11 - and d_year=2001 - group by i_brand, i_brand_id - order by ext_price desc, i_brand_id -limit 100 ; - --- end template query55.tpl query 37 in stream 10 --- start template query85.tpl query 38 in stream 10 -select /* TPC-DS query85.tpl 0.33 */ substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) - from web_sales, web_returns, web_page, customer_demographics cd1, - customer_demographics cd2, customer_address, date_dim, reason - where ws_web_page_sk = wp_web_page_sk - and ws_item_sk = wr_item_sk - and ws_order_number = wr_order_number - and ws_sold_date_sk = d_date_sk and d_year = 2001 - and cd1.cd_demo_sk = wr_refunded_cdemo_sk - and cd2.cd_demo_sk = wr_returning_cdemo_sk - and ca_address_sk = wr_refunded_addr_sk - and r_reason_sk = wr_reason_sk - and - ( - ( - cd1.cd_marital_status = 'D' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Secondary' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 100.00 and 150.00 - ) - or - ( - cd1.cd_marital_status = 'W' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Advanced Degree' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 50.00 and 100.00 - ) - or - ( - cd1.cd_marital_status = 'S' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Primary' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ca_country = 'United States' - and - ca_state in ('GA', 'NC', 'KS') - and ws_net_profit between 100 and 200 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('IL', 'TX', 'WA') - and ws_net_profit between 150 and 300 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('TN', 'MO', 'OK') - and ws_net_profit between 50 and 250 - ) - ) -group by r_reason_desc -order by substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) -limit 100; - --- end template query85.tpl query 38 in stream 10 --- start template query38.tpl query 39 in stream 10 -select /* TPC-DS query38.tpl 0.54 */ count(*) from ( - select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1184 and 1184 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1184 and 1184 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1184 and 1184 + 11 -) hot_cust -limit 100; - --- end template query38.tpl query 39 in stream 10 --- start template query44.tpl query 40 in stream 10 -select /* TPC-DS query44.tpl 0.4 */ asceding.rnk, i1.i_product_name best_performing, i2.i_product_name worst_performing -from(select * - from (select item_sk,rank() over (order by rank_col asc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 405 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 405 - and ss_cdemo_sk is null - group by ss_store_sk))V1)V11 - where rnk < 11) asceding, - (select * - from (select item_sk,rank() over (order by rank_col desc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 405 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 405 - and ss_cdemo_sk is null - group by ss_store_sk))V2)V21 - where rnk < 11) descending, -item i1, -item i2 -where asceding.rnk = descending.rnk - and i1.i_item_sk=asceding.item_sk - and i2.i_item_sk=descending.item_sk -order by asceding.rnk -limit 100; - --- end template query44.tpl query 40 in stream 10 --- start template query27a.tpl query 41 in stream 10 -with /* TPC-DS query27a.tpl 0.16 */ results as - (select i_item_id, - s_state, 0 as g_state, - ss_quantity agg1, - ss_list_price agg2, - ss_coupon_amt agg3, - ss_sales_price agg4 - from store_sales, customer_demographics, date_dim, store, item - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_store_sk = s_store_sk and - ss_cdemo_sk = cd_demo_sk and - cd_gender = 'M' and - cd_marital_status = 'M' and - cd_education_status = 'Primary' and - d_year = 2000 and - s_state in ('NM','LA', 'MO', 'GA', 'SD', 'FL') - ) - - select i_item_id, - s_state, g_state, agg1, agg2, agg3, agg4 - from ( - select i_item_id, s_state, 0 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4 from results - group by i_item_id, s_state - union all - select i_item_id, NULL AS s_state, 1 AS g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as s_state, 1 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - ) foo - order by i_item_id, s_state - limit 100; - --- end template query27a.tpl query 41 in stream 10 --- start template query78.tpl query 42 in stream 10 -with /* TPC-DS query78.tpl 0.10 */ ws as - (select d_year AS ws_sold_year, ws_item_sk, - ws_bill_customer_sk ws_customer_sk, - sum(ws_quantity) ws_qty, - sum(ws_wholesale_cost) ws_wc, - sum(ws_sales_price) ws_sp - from web_sales - left join web_returns on wr_order_number=ws_order_number and ws_item_sk=wr_item_sk - join date_dim on ws_sold_date_sk = d_date_sk - where wr_order_number is null - group by d_year, ws_item_sk, ws_bill_customer_sk - ), -cs as - (select d_year AS cs_sold_year, cs_item_sk, - cs_bill_customer_sk cs_customer_sk, - sum(cs_quantity) cs_qty, - sum(cs_wholesale_cost) cs_wc, - sum(cs_sales_price) cs_sp - from catalog_sales - left join catalog_returns on cr_order_number=cs_order_number and cs_item_sk=cr_item_sk - join date_dim on cs_sold_date_sk = d_date_sk - where cr_order_number is null - group by d_year, cs_item_sk, cs_bill_customer_sk - ), -ss as - (select d_year AS ss_sold_year, ss_item_sk, - ss_customer_sk, - sum(ss_quantity) ss_qty, - sum(ss_wholesale_cost) ss_wc, - sum(ss_sales_price) ss_sp - from store_sales - left join store_returns on sr_ticket_number=ss_ticket_number and ss_item_sk=sr_item_sk - join date_dim on ss_sold_date_sk = d_date_sk - where sr_ticket_number is null - group by d_year, ss_item_sk, ss_customer_sk - ) - select -ss_sold_year, ss_item_sk, ss_customer_sk, -round(ss_qty/(coalesce(ws_qty,0)+coalesce(cs_qty,0)),2) ratio, -ss_qty store_qty, ss_wc store_wholesale_cost, ss_sp store_sales_price, -coalesce(ws_qty,0)+coalesce(cs_qty,0) other_chan_qty, -coalesce(ws_wc,0)+coalesce(cs_wc,0) other_chan_wholesale_cost, -coalesce(ws_sp,0)+coalesce(cs_sp,0) other_chan_sales_price -from ss -left join ws on (ws_sold_year=ss_sold_year and ws_item_sk=ss_item_sk and ws_customer_sk=ss_customer_sk) -left join cs on (cs_sold_year=ss_sold_year and cs_item_sk=ss_item_sk and cs_customer_sk=ss_customer_sk) -where (coalesce(ws_qty,0)>0 or coalesce(cs_qty, 0)>0) and ss_sold_year=2002 -order by - ss_sold_year, ss_item_sk, ss_customer_sk, - ss_qty desc, ss_wc desc, ss_sp desc, - other_chan_qty, - other_chan_wholesale_cost, - other_chan_sales_price, - ratio -limit 100; - --- end template query78.tpl query 42 in stream 10 --- start template query45.tpl query 43 in stream 10 -select /* TPC-DS query45.tpl 0.18 */ ca_zip, ca_state, sum(ws_sales_price) - from web_sales, customer, customer_address, date_dim, item - where ws_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ws_item_sk = i_item_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', '85392', '85460', '80348', '81792') - or - i_item_id in (select i_item_id - from item - where i_item_sk in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29) - ) - ) - and ws_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 1999 - group by ca_zip, ca_state - order by ca_zip, ca_state - limit 100; - --- end template query45.tpl query 43 in stream 10 --- start template query49.tpl query 44 in stream 10 -select /* TPC-DS query49.tpl 0.48 */ channel, item, return_ratio, return_rank, currency_rank from - (select - 'web' as channel - ,web.item - ,web.return_ratio - ,web.return_rank - ,web.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select ws.ws_item_sk as item - ,(cast(sum(coalesce(wr.wr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(wr.wr_return_amt,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - web_sales ws left outer join web_returns wr - on (ws.ws_order_number = wr.wr_order_number and - ws.ws_item_sk = wr.wr_item_sk) - ,date_dim - where - wr.wr_return_amt > 10000 - and ws.ws_net_profit > 1 - and ws.ws_net_paid > 0 - and ws.ws_quantity > 0 - and ws_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 12 - group by ws.ws_item_sk - ) in_web - ) web - where - ( - web.return_rank <= 10 - or - web.currency_rank <= 10 - ) - union - select - 'catalog' as channel - ,catalog.item - ,catalog.return_ratio - ,catalog.return_rank - ,catalog.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select - cs.cs_item_sk as item - ,(cast(sum(coalesce(cr.cr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(cr.cr_return_amount,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - catalog_sales cs left outer join catalog_returns cr - on (cs.cs_order_number = cr.cr_order_number and - cs.cs_item_sk = cr.cr_item_sk) - ,date_dim - where - cr.cr_return_amount > 10000 - and cs.cs_net_profit > 1 - and cs.cs_net_paid > 0 - and cs.cs_quantity > 0 - and cs_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 12 - group by cs.cs_item_sk - ) in_cat - ) catalog - where - ( - catalog.return_rank <= 10 - or - catalog.currency_rank <=10 - ) - union - select - 'store' as channel - ,store.item - ,store.return_ratio - ,store.return_rank - ,store.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select sts.ss_item_sk as item - ,(cast(sum(coalesce(sr.sr_return_quantity,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(sr.sr_return_amt,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - store_sales sts left outer join store_returns sr - on (sts.ss_ticket_number = sr.sr_ticket_number and sts.ss_item_sk = sr.sr_item_sk) - ,date_dim - where - sr.sr_return_amt > 10000 - and sts.ss_net_profit > 1 - and sts.ss_net_paid > 0 - and sts.ss_quantity > 0 - and ss_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 12 - group by sts.ss_item_sk - ) in_store - ) store - where ( - store.return_rank <= 10 - or - store.currency_rank <= 10 - ) - ) - order by 1,4,5,2 - limit 100; - --- end template query49.tpl query 44 in stream 10 --- start template query62.tpl query 45 in stream 10 -select /* TPC-DS query62.tpl 0.24 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 30) and - (ws_ship_date_sk - ws_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 60) and - (ws_ship_date_sk - ws_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 90) and - (ws_ship_date_sk - ws_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - web_sales - ,warehouse - ,ship_mode - ,web_site - ,date_dim -where - d_month_seq between 1193 and 1193 + 11 -and ws_ship_date_sk = d_date_sk -and ws_warehouse_sk = w_warehouse_sk -and ws_ship_mode_sk = sm_ship_mode_sk -and ws_web_site_sk = web_site_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -limit 100; - --- end template query62.tpl query 45 in stream 10 --- start template query59.tpl query 46 in stream 10 -with /* TPC-DS query59.tpl 0.30 */ wss as - (select d_week_seq, - ss_store_sk, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - group by d_week_seq,ss_store_sk - ) - select s_store_name1,s_store_id1,d_week_seq1 - ,sun_sales1/sun_sales2,mon_sales1/mon_sales2 - ,tue_sales1/tue_sales2,wed_sales1/wed_sales2,thu_sales1/thu_sales2 - ,fri_sales1/fri_sales2,sat_sales1/sat_sales2 - from - (select s_store_name s_store_name1,wss.d_week_seq d_week_seq1 - ,s_store_id s_store_id1,sun_sales sun_sales1 - ,mon_sales mon_sales1,tue_sales tue_sales1 - ,wed_sales wed_sales1,thu_sales thu_sales1 - ,fri_sales fri_sales1,sat_sales sat_sales1 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1187 and 1187 + 11) y, - (select s_store_name s_store_name2,wss.d_week_seq d_week_seq2 - ,s_store_id s_store_id2,sun_sales sun_sales2 - ,mon_sales mon_sales2,tue_sales tue_sales2 - ,wed_sales wed_sales2,thu_sales thu_sales2 - ,fri_sales fri_sales2,sat_sales sat_sales2 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1187+ 12 and 1187 + 23) x - where s_store_id1=s_store_id2 - and d_week_seq1=d_week_seq2-52 - order by s_store_name1,s_store_id1,d_week_seq1 -limit 100; - --- end template query59.tpl query 46 in stream 10 --- start template query77a.tpl query 47 in stream 10 -with /* TPC-DS query77a.tpl 0.78 */ ss as - (select s_store_sk, - sum(ss_ext_sales_price) as sales, - sum(ss_net_profit) as profit - from store_sales, - date_dim, - store - where ss_sold_date_sk = d_date_sk - and d_date between cast('1998-08-08' as date) - and dateadd(day,30,cast('1998-08-08' as date)) - and ss_store_sk = s_store_sk - group by s_store_sk) - , - sr as - (select s_store_sk, - sum(sr_return_amt) as returns, - sum(sr_net_loss) as profit_loss - from store_returns, - date_dim, - store - where sr_returned_date_sk = d_date_sk - and d_date between cast('1998-08-08' as date) - and dateadd(day,30,cast('1998-08-08' as date)) - and sr_store_sk = s_store_sk - group by s_store_sk), - cs as - (select cs_call_center_sk, - sum(cs_ext_sales_price) as sales, - sum(cs_net_profit) as profit - from catalog_sales, - date_dim - where cs_sold_date_sk = d_date_sk - and d_date between cast('1998-08-08' as date) - and dateadd(day,30,cast('1998-08-08' as date)) - group by cs_call_center_sk - ), - cr as - (select cr_call_center_sk, - sum(cr_return_amount) as returns, - sum(cr_net_loss) as profit_loss - from catalog_returns, - date_dim - where cr_returned_date_sk = d_date_sk - and d_date between cast('1998-08-08' as date) - and dateadd(day,30,cast('1998-08-08' as date)) - group by cr_call_center_sk), - ws as - ( select wp_web_page_sk, - sum(ws_ext_sales_price) as sales, - sum(ws_net_profit) as profit - from web_sales, - date_dim, - web_page - where ws_sold_date_sk = d_date_sk - and d_date between cast('1998-08-08' as date) - and dateadd(day,30,cast('1998-08-08' as date)) - and ws_web_page_sk = wp_web_page_sk - group by wp_web_page_sk), - wr as - (select wp_web_page_sk, - sum(wr_return_amt) as returns, - sum(wr_net_loss) as profit_loss - from web_returns, - date_dim, - web_page - where wr_returned_date_sk = d_date_sk - and d_date between cast('1998-08-08' as date) - and dateadd(day,30,cast('1998-08-08' as date)) - and wr_web_page_sk = wp_web_page_sk - group by wp_web_page_sk) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , ss.s_store_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ss left join sr - on ss.s_store_sk = sr.s_store_sk - union all - select 'catalog channel' as channel - , cs_call_center_sk as id - , sales - , returns - , (profit - profit_loss) as profit - from cs - , cr - union all - select 'web channel' as channel - , ws.wp_web_page_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ws left join wr - on ws.wp_web_page_sk = wr.wp_web_page_sk - ) x - group by channel, id ) - - select * - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results -) foo -order by channel, id - limit 100; - --- end template query77a.tpl query 47 in stream 10 --- start template query80a.tpl query 48 in stream 10 -with /* TPC-DS query80a.tpl 0.6 */ ssr as - (select s_store_id as store_id, - sum(ss_ext_sales_price) as sales, - sum(coalesce(sr_return_amt, 0)) as returns, - sum(ss_net_profit - coalesce(sr_net_loss, 0)) as profit - from store_sales left outer join store_returns on - (ss_item_sk = sr_item_sk and ss_ticket_number = sr_ticket_number), - date_dim, - store, - item, - promotion - where ss_sold_date_sk = d_date_sk - and d_date between cast('2002-08-24' as date) - and dateadd(day,30,cast('2002-08-24' as date)) - and ss_store_sk = s_store_sk - and ss_item_sk = i_item_sk - and i_current_price > 50 - and ss_promo_sk = p_promo_sk - and p_channel_tv = 'N' - group by s_store_id) - , - csr as - (select cp_catalog_page_id as catalog_page_id, - sum(cs_ext_sales_price) as sales, - sum(coalesce(cr_return_amount, 0)) as returns, - sum(cs_net_profit - coalesce(cr_net_loss, 0)) as profit - from catalog_sales left outer join catalog_returns on - (cs_item_sk = cr_item_sk and cs_order_number = cr_order_number), - date_dim, - catalog_page, - item, - promotion - where cs_sold_date_sk = d_date_sk - and d_date between cast('2002-08-24' as date) - and dateadd(day,30,cast('2002-08-24' as date)) - and cs_catalog_page_sk = cp_catalog_page_sk - and cs_item_sk = i_item_sk - and i_current_price > 50 - and cs_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(ws_ext_sales_price) as sales, - sum(coalesce(wr_return_amt, 0)) as returns, - sum(ws_net_profit - coalesce(wr_net_loss, 0)) as profit - from web_sales left outer join web_returns on - (ws_item_sk = wr_item_sk and ws_order_number = wr_order_number), - date_dim, - web_site, - item, - promotion - where ws_sold_date_sk = d_date_sk - and d_date between cast('2002-08-24' as date) - and dateadd(day,30,cast('2002-08-24' as date)) - and ws_web_site_sk = web_site_sk - and ws_item_sk = i_item_sk - and i_current_price > 50 - and ws_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by web_site_id) -, -results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || store_id as id - , sales - , returns - , profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || catalog_page_id as id - , sales - , returns - , profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , profit - from wsr - ) x - group by channel, id) - - select channel - , id - , sales - , returns - , profit - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results - ) foo - order by channel, id - limit 100; - --- end template query80a.tpl query 48 in stream 10 --- start template query84.tpl query 49 in stream 10 -select /* TPC-DS query84.tpl 0.80 */ c_customer_id as customer_id - , coalesce(c_last_name,'') || ', ' || coalesce(c_first_name,'') as customername - from customer - ,customer_address - ,customer_demographics - ,household_demographics - ,income_band - ,store_returns - where ca_city = 'Springfield' - and c_current_addr_sk = ca_address_sk - and ib_lower_bound >= 9487 - and ib_upper_bound <= 9487 + 50000 - and ib_income_band_sk = hd_income_band_sk - and cd_demo_sk = c_current_cdemo_sk - and hd_demo_sk = c_current_hdemo_sk - and sr_cdemo_sk = cd_demo_sk - order by c_customer_id - limit 100; - --- end template query84.tpl query 49 in stream 10 --- start template query67a.tpl query 50 in stream 10 -with /* TPC-DS query67a.tpl 0.35 */ results as -( select i_category ,i_class ,i_brand ,i_product_name ,d_year ,d_qoy ,d_moy ,s_store_id - ,sum(coalesce(ss_sales_price*ss_quantity,0)) sumsales - from store_sales ,date_dim ,store ,item - where ss_sold_date_sk=d_date_sk - and ss_item_sk=i_item_sk - and ss_store_sk = s_store_sk - and d_month_seq between 1189 and 1189 + 11 - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy,s_store_id) - , - results_rollup as - (select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, s_store_id, sumsales - from results - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy - union all - select i_category, i_class, i_brand, i_product_name, d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year - union all - select i_category, i_class, i_brand, i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name - union all - select i_category, i_class, i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand - union all - select i_category, i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class - union all - select i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category - union all - select null i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results) - - select * -from (select i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rank() over (partition by i_category order by sumsales desc) rk - from results_rollup) dw2 -where rk <= 100 -order by i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rk -limit 100; - --- end template query67a.tpl query 50 in stream 10 --- start template query52.tpl query 51 in stream 10 -select /* TPC-DS query52.tpl 0.59 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_sales_price) ext_price - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=12 - and dt.d_year=1999 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,ext_price desc - ,brand_id -limit 100 ; - --- end template query52.tpl query 51 in stream 10 --- start template query76.tpl query 52 in stream 10 -select /* TPC-DS query76.tpl 0.99 */ channel, col_name, d_year, d_qoy, i_category, COUNT(*) sales_cnt, SUM(ext_sales_price) sales_amt FROM ( - SELECT 'store' as channel, 'ss_hdemo_sk' col_name, d_year, d_qoy, i_category, ss_ext_sales_price ext_sales_price - FROM store_sales, item, date_dim - WHERE ss_hdemo_sk IS NULL - AND ss_sold_date_sk=d_date_sk - AND ss_item_sk=i_item_sk - UNION ALL - SELECT 'web' as channel, 'ws_bill_addr_sk' col_name, d_year, d_qoy, i_category, ws_ext_sales_price ext_sales_price - FROM web_sales, item, date_dim - WHERE ws_bill_addr_sk IS NULL - AND ws_sold_date_sk=d_date_sk - AND ws_item_sk=i_item_sk - UNION ALL - SELECT 'catalog' as channel, 'cs_ship_customer_sk' col_name, d_year, d_qoy, i_category, cs_ext_sales_price ext_sales_price - FROM catalog_sales, item, date_dim - WHERE cs_ship_customer_sk IS NULL - AND cs_sold_date_sk=d_date_sk - AND cs_item_sk=i_item_sk) foo -GROUP BY channel, col_name, d_year, d_qoy, i_category -ORDER BY channel, col_name, d_year, d_qoy, i_category -limit 100; - --- end template query76.tpl query 52 in stream 10 --- start template query42.tpl query 53 in stream 10 -select /* TPC-DS query42.tpl 0.61 */ dt.d_year - ,item.i_category_id - ,item.i_category - ,sum(ss_ext_sales_price) - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=12 - and dt.d_year=2001 - group by dt.d_year - ,item.i_category_id - ,item.i_category - order by sum(ss_ext_sales_price) desc,dt.d_year - ,item.i_category_id - ,item.i_category -limit 100 ; - --- end template query42.tpl query 53 in stream 10 --- start template query33.tpl query 54 in stream 10 -with /* TPC-DS query33.tpl 0.22 */ ss as ( - select - i_manufact_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Home')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 4 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_manufact_id), - cs as ( - select - i_manufact_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Home')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 4 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_manufact_id), - ws as ( - select - i_manufact_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Home')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 4 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_manufact_id) - select i_manufact_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_manufact_id - order by total_sales -limit 100; - --- end template query33.tpl query 54 in stream 10 --- start template query65.tpl query 55 in stream 10 -select /* TPC-DS query65.tpl 0.71 */ - s_store_name, - i_item_desc, - sc.revenue, - i_current_price, - i_wholesale_cost, - i_brand - from store, item, - (select ss_store_sk, avg(revenue) as ave - from - (select ss_store_sk, ss_item_sk, - sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1184 and 1184+11 - group by ss_store_sk, ss_item_sk) sa - group by ss_store_sk) sb, - (select ss_store_sk, ss_item_sk, sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1184 and 1184+11 - group by ss_store_sk, ss_item_sk) sc - where sb.ss_store_sk = sc.ss_store_sk and - sc.revenue <= 0.1 * sb.ave and - s_store_sk = sc.ss_store_sk and - i_item_sk = sc.ss_item_sk - order by s_store_name, i_item_desc -limit 100; - --- end template query65.tpl query 55 in stream 10 --- start template query23.tpl query 56 in stream 10 -with /* TPC-DS query23.tpl 0.68 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (1998,1998+1,1998+2,1998+3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1998,1998+1,1998+2,1998+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * -from - max_store_sales)) - select sum(sales) - from (select cs_quantity*cs_list_price sales - from catalog_sales - ,date_dim - where d_year = 1998 - and d_moy = 7 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - union all - select ws_quantity*ws_list_price sales - from web_sales - ,date_dim - where d_year = 1998 - and d_moy = 7 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer)) - limit 100; -with /* TPC-DS query23.tpl 0.68 part2 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (1998,1998 + 1,1998 + 2,1998 + 3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1998,1998+1,1998+2,1998+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * - from max_store_sales)) - select c_last_name,c_first_name,sales - from (select c_last_name,c_first_name,sum(cs_quantity*cs_list_price) sales - from catalog_sales - ,customer - ,date_dim - where d_year = 1998 - and d_moy = 7 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and cs_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name - union all - select c_last_name,c_first_name,sum(ws_quantity*ws_list_price) sales - from web_sales - ,customer - ,date_dim - where d_year = 1998 - and d_moy = 7 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and ws_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name) - order by c_last_name,c_first_name,sales - limit 100; - --- end template query23.tpl query 56 in stream 10 --- start template query90.tpl query 57 in stream 10 -select /* TPC-DS query90.tpl 0.40 */ cast(amc as decimal(15,4))/cast(pmc as decimal(15,4)) am_pm_ratio - from ( select count(*) amc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 6 and 6+1 - and household_demographics.hd_dep_count = 1 - and web_page.wp_char_count between 5000 and 5200) at, - ( select count(*) pmc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 16 and 16+1 - and household_demographics.hd_dep_count = 1 - and web_page.wp_char_count between 5000 and 5200) pt - order by am_pm_ratio - limit 100; - --- end template query90.tpl query 57 in stream 10 --- start template query88.tpl query 58 in stream 10 -select /* TPC-DS query88.tpl 0.66 */ * -from - (select count(*) h8_30_to_9 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2)) - and store.s_store_name = 'ese') s1, - (select count(*) h9_to_9_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2)) - and store.s_store_name = 'ese') s2, - (select count(*) h9_30_to_10 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2)) - and store.s_store_name = 'ese') s3, - (select count(*) h10_to_10_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2)) - and store.s_store_name = 'ese') s4, - (select count(*) h10_30_to_11 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2)) - and store.s_store_name = 'ese') s5, - (select count(*) h11_to_11_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2)) - and store.s_store_name = 'ese') s6, - (select count(*) h11_30_to_12 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2)) - and store.s_store_name = 'ese') s7, - (select count(*) h12_to_12_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 12 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2)) - and store.s_store_name = 'ese') s8 -; - --- end template query88.tpl query 58 in stream 10 --- start template query99.tpl query 59 in stream 10 -select /* TPC-DS query99.tpl 0.94 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 30) and - (cs_ship_date_sk - cs_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 60) and - (cs_ship_date_sk - cs_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 90) and - (cs_ship_date_sk - cs_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - catalog_sales - ,warehouse - ,ship_mode - ,call_center - ,date_dim -where - d_month_seq between 1206 and 1206 + 11 -and cs_ship_date_sk = d_date_sk -and cs_warehouse_sk = w_warehouse_sk -and cs_ship_mode_sk = sm_ship_mode_sk -and cs_call_center_sk = cc_call_center_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -limit 100; - --- end template query99.tpl query 59 in stream 10 --- start template query35a.tpl query 60 in stream 10 -select /* TPC-DS query35a.tpl 0.47 */ - ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - count(*) cnt1, - stddev_samp(cd_dep_count), - min(cd_dep_count), - avg(cd_dep_count), - cd_dep_employed_count, - count(*) cnt2, - stddev_samp(cd_dep_employed_count), - min(cd_dep_employed_count), - avg(cd_dep_employed_count), - cd_dep_college_count, - count(*) cnt3, - stddev_samp(cd_dep_college_count), - min(cd_dep_college_count), - avg(cd_dep_college_count) - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2001 and - d_qoy < 4) and - exists (select * from - (select ws_bill_customer_sk customsk - from web_sales,date_dim - where - ws_sold_date_sk = d_date_sk and - d_year = 2001 and - d_qoy < 4 - union all - select cs_ship_customer_sk customsk - from catalog_sales,date_dim - where - cs_sold_date_sk = d_date_sk and - d_year = 2001 and - d_qoy < 4)x - where x.customsk = c.c_customer_sk) - group by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - limit 100; - --- end template query35a.tpl query 60 in stream 10 --- start template query10.tpl query 61 in stream 10 -select /* TPC-DS query10.tpl 0.26 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3, - cd_dep_count, - count(*) cnt4, - cd_dep_employed_count, - count(*) cnt5, - cd_dep_college_count, - count(*) cnt6 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_county in ('Montgomery County','Covington County','Oconee County','Fergus County','Webster Parish') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 3 and 3+3) and - (exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 3 ANd 3+3) or - exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 3 and 3+3)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count -limit 100; - --- end template query10.tpl query 61 in stream 10 --- start template query16.tpl query 62 in stream 10 -select /* TPC-DS query16.tpl 0.25 */ - count(distinct cs_order_number) as "order count" - ,sum(cs_ext_ship_cost) as "total shipping cost" - ,sum(cs_net_profit) as "total net profit" -from - catalog_sales cs1 - ,date_dim - ,customer_address - ,call_center -where - d_date between '2000-4-01' and - dateadd(day, 60, cast('2000-4-01' as date)) -and cs1.cs_ship_date_sk = d_date_sk -and cs1.cs_ship_addr_sk = ca_address_sk -and ca_state = 'PA' -and cs1.cs_call_center_sk = cc_call_center_sk -and cc_county in ('Pennington County','Fairfield County','Mobile County','San Miguel County', - 'Daviess County' -) -and exists (select * - from catalog_sales cs2 - where cs1.cs_order_number = cs2.cs_order_number - and cs1.cs_warehouse_sk <> cs2.cs_warehouse_sk) -and not exists(select * - from catalog_returns cr1 - where cs1.cs_order_number = cr1.cr_order_number) -order by count(distinct cs_order_number) -limit 100; - --- end template query16.tpl query 62 in stream 10 --- start template query5a.tpl query 63 in stream 10 -with /* TPC-DS query5a.tpl 0.98 */ ssr as - (select s_store_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ss_store_sk as store_sk, - ss_sold_date_sk as date_sk, - ss_ext_sales_price as sales_price, - ss_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from store_sales - union all - select sr_store_sk as store_sk, - sr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - sr_return_amt as return_amt, - sr_net_loss as net_loss - from store_returns - ) salesreturns, - date_dim, - store - where date_sk = d_date_sk - and d_date between cast('1998-08-11' as date) - and dateadd(day,14,cast('1998-08-11' as date)) - and store_sk = s_store_sk - group by s_store_id) - , - csr as - (select cp_catalog_page_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select cs_catalog_page_sk as page_sk, - cs_sold_date_sk as date_sk, - cs_ext_sales_price as sales_price, - cs_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from catalog_sales - union all - select cr_catalog_page_sk as page_sk, - cr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - cr_return_amount as return_amt, - cr_net_loss as net_loss - from catalog_returns - ) salesreturns, - date_dim, - catalog_page - where date_sk = d_date_sk - and d_date between cast('1998-08-11' as date) - and dateadd(day,14,cast('1998-08-11' as date)) - and page_sk = cp_catalog_page_sk - group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ws_web_site_sk as wsr_web_site_sk, - ws_sold_date_sk as date_sk, - ws_ext_sales_price as sales_price, - ws_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from web_sales - union all - select ws_web_site_sk as wsr_web_site_sk, - wr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - wr_return_amt as return_amt, - wr_net_loss as net_loss - from web_returns left outer join web_sales on - ( wr_item_sk = ws_item_sk - and wr_order_number = ws_order_number) - ) salesreturns, - date_dim, - web_site - where date_sk = d_date_sk - and d_date between cast('1998-08-11' as date) - and dateadd(day,14,cast('1998-08-11' as date)) - and wsr_web_site_sk = web_site_sk - group by web_site_id) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || s_store_id as id - , sales - , returns - , (profit - profit_loss) as profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || cp_catalog_page_id as id - , sales - , returns - , (profit - profit_loss) as profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , (profit - profit_loss) as profit - from wsr - ) x - group by channel, id) - select channel, id, sales, returns, profit from ( - select channel, id, sales, returns, profit from results - union - select channel, null as id, sum(sales), sum(returns), sum(profit) from results group by channel - union - select null as channel, null as id, sum(sales), sum(returns), sum(profit) from results) foo -order by channel, id -limit 100; - --- end template query5a.tpl query 63 in stream 10 --- start template query57.tpl query 64 in stream 10 -with /* TPC-DS query57.tpl 0.70 */ v1 as( - select i_category, i_brand, - cc_name, - d_year, d_moy, - sum(cs_sales_price) sum_sales, - avg(sum(cs_sales_price)) over - (partition by i_category, i_brand, - cc_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - cc_name - order by d_year, d_moy) rn - from item, catalog_sales, date_dim, call_center - where cs_item_sk = i_item_sk and - cs_sold_date_sk = d_date_sk and - cc_call_center_sk= cs_call_center_sk and - ( - d_year = 2001 or - ( d_year = 2001-1 and d_moy =12) or - ( d_year = 2001+1 and d_moy =1) - ) - group by i_category, i_brand, - cc_name , d_year, d_moy), - v2 as( - select v1.cc_name - ,v1.d_year - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1. cc_name = v1_lag. cc_name and - v1. cc_name = v1_lead. cc_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 2001 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, psum - limit 100; - --- end template query57.tpl query 64 in stream 10 --- start template query34.tpl query 65 in stream 10 -select /* TPC-DS query34.tpl 0.73 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (date_dim.d_dom between 1 and 3 or date_dim.d_dom between 25 and 28) - and (household_demographics.hd_buy_potential = '501-1000' or - household_demographics.hd_buy_potential = '5001-10000') - and household_demographics.hd_vehicle_count > 0 - and (case when household_demographics.hd_vehicle_count > 0 - then household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count - else null - end) > 1.2 - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_county in ('Walker County','Bronx County','Barrow County','Pennington County', - 'Jackson County','Fairfield County','Kittitas County','Raleigh County') - group by ss_ticket_number,ss_customer_sk) dn,customer - where ss_customer_sk = c_customer_sk - and cnt between 15 and 20 - order by c_last_name,c_first_name,c_salutation,c_preferred_cust_flag desc, ss_ticket_number; - --- end template query34.tpl query 65 in stream 10 --- start template query97.tpl query 66 in stream 10 -with /* TPC-DS query97.tpl 0.38 */ ssci as ( -select ss_customer_sk customer_sk - ,ss_item_sk item_sk -from store_sales,date_dim -where ss_sold_date_sk = d_date_sk - and d_month_seq between 1192 and 1192 + 11 -group by ss_customer_sk - ,ss_item_sk), -csci as( - select cs_bill_customer_sk customer_sk - ,cs_item_sk item_sk -from catalog_sales,date_dim -where cs_sold_date_sk = d_date_sk - and d_month_seq between 1192 and 1192 + 11 -group by cs_bill_customer_sk - ,cs_item_sk) - select sum(case when ssci.customer_sk is not null and csci.customer_sk is null then 1 else 0 end) store_only - ,sum(case when ssci.customer_sk is null and csci.customer_sk is not null then 1 else 0 end) catalog_only - ,sum(case when ssci.customer_sk is not null and csci.customer_sk is not null then 1 else 0 end) store_and_catalog -from ssci full outer join csci on (ssci.customer_sk=csci.customer_sk - and ssci.item_sk = csci.item_sk) -limit 100; - --- end template query97.tpl query 66 in stream 10 --- start template query72.tpl query 67 in stream 10 -select /* TPC-DS query72.tpl 0.87 */ i_item_desc - ,w_warehouse_name - ,d1.d_week_seq - ,sum(case when p_promo_sk is null then 1 else 0 end) no_promo - ,sum(case when p_promo_sk is not null then 1 else 0 end) promo - ,count(*) total_cnt -from catalog_sales -join inventory on (cs_item_sk = inv_item_sk) -join warehouse on (w_warehouse_sk=inv_warehouse_sk) -join item on (i_item_sk = cs_item_sk) -join customer_demographics on (cs_bill_cdemo_sk = cd_demo_sk) -join household_demographics on (cs_bill_hdemo_sk = hd_demo_sk) -join date_dim d1 on (cs_sold_date_sk = d1.d_date_sk) -join date_dim d2 on (inv_date_sk = d2.d_date_sk) -join date_dim d3 on (cs_ship_date_sk = d3.d_date_sk) -left outer join promotion on (cs_promo_sk=p_promo_sk) -left outer join catalog_returns on (cr_item_sk = cs_item_sk and cr_order_number = cs_order_number) -where d1.d_week_seq = d2.d_week_seq - and inv_quantity_on_hand < cs_quantity - and d3.d_date > d1.d_date + 5 - and hd_buy_potential = '>10000' - and d1.d_year = 1998 - and cd_marital_status = 'W' -group by i_item_desc,w_warehouse_name,d1.d_week_seq -order by total_cnt desc, i_item_desc, w_warehouse_name, d_week_seq -limit 100; - --- end template query72.tpl query 67 in stream 10 --- start template query75.tpl query 68 in stream 10 -WITH /* TPC-DS query75.tpl 0.3 */ all_sales AS ( - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,SUM(sales_cnt) AS sales_cnt - ,SUM(sales_amt) AS sales_amt - FROM (SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,cs_quantity - COALESCE(cr_return_quantity,0) AS sales_cnt - ,cs_ext_sales_price - COALESCE(cr_return_amount,0.0) AS sales_amt - FROM catalog_sales JOIN item ON i_item_sk=cs_item_sk - JOIN date_dim ON d_date_sk=cs_sold_date_sk - LEFT JOIN catalog_returns ON (cs_order_number=cr_order_number - AND cs_item_sk=cr_item_sk) - WHERE i_category='Men' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ss_quantity - COALESCE(sr_return_quantity,0) AS sales_cnt - ,ss_ext_sales_price - COALESCE(sr_return_amt,0.0) AS sales_amt - FROM store_sales JOIN item ON i_item_sk=ss_item_sk - JOIN date_dim ON d_date_sk=ss_sold_date_sk - LEFT JOIN store_returns ON (ss_ticket_number=sr_ticket_number - AND ss_item_sk=sr_item_sk) - WHERE i_category='Men' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ws_quantity - COALESCE(wr_return_quantity,0) AS sales_cnt - ,ws_ext_sales_price - COALESCE(wr_return_amt,0.0) AS sales_amt - FROM web_sales JOIN item ON i_item_sk=ws_item_sk - JOIN date_dim ON d_date_sk=ws_sold_date_sk - LEFT JOIN web_returns ON (ws_order_number=wr_order_number - AND ws_item_sk=wr_item_sk) - WHERE i_category='Men') sales_detail - GROUP BY d_year, i_brand_id, i_class_id, i_category_id, i_manufact_id) - SELECT prev_yr.d_year AS prev_year - ,curr_yr.d_year AS year - ,curr_yr.i_brand_id - ,curr_yr.i_class_id - ,curr_yr.i_category_id - ,curr_yr.i_manufact_id - ,prev_yr.sales_cnt AS prev_yr_cnt - ,curr_yr.sales_cnt AS curr_yr_cnt - ,curr_yr.sales_cnt-prev_yr.sales_cnt AS sales_cnt_diff - ,curr_yr.sales_amt-prev_yr.sales_amt AS sales_amt_diff - FROM all_sales curr_yr, all_sales prev_yr - WHERE curr_yr.i_brand_id=prev_yr.i_brand_id - AND curr_yr.i_class_id=prev_yr.i_class_id - AND curr_yr.i_category_id=prev_yr.i_category_id - AND curr_yr.i_manufact_id=prev_yr.i_manufact_id - AND curr_yr.d_year=2000 - AND prev_yr.d_year=2000-1 - AND CAST(curr_yr.sales_cnt AS DECIMAL(17,2))/CAST(prev_yr.sales_cnt AS DECIMAL(17,2))<0.9 - ORDER BY sales_cnt_diff,sales_amt_diff - limit 100; - --- end template query75.tpl query 68 in stream 10 --- start template query14a.tpl query 69 in stream 10 -with /* TPC-DS query14a.tpl 0.69 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 2000 AND 2000 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 2000 AND 2000 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 2000 AND 2000 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as - (select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2) x) -, - results AS -(select channel, i_brand_id, i_class_id, i_category_id, sum(sales) sum_sales, sum(number_sales) number_sales - from ( - select 'store' channel, i_brand_id,i_class_id - ,i_category_id,sum(ss_quantity*ss_list_price) sales - , count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2000+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales) - union all - select 'catalog' channel, i_brand_id,i_class_id,i_category_id, sum(cs_quantity*cs_list_price) sales, count(*) number_sales - from catalog_sales - ,item - ,date_dim - where cs_item_sk in (select ss_item_sk from cross_items) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2000+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(cs_quantity*cs_list_price) > (select average_sales from avg_sales) - union all - select 'web' channel, i_brand_id,i_class_id,i_category_id, sum(ws_quantity*ws_list_price) sales , count(*) number_sales - from web_sales - ,item - ,date_dim - where ws_item_sk in (select ss_item_sk from cross_items) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2000+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ws_quantity*ws_list_price) > (select average_sales from avg_sales) - ) y - group by channel, i_brand_id,i_class_id,i_category_id) - - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales -from ( - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales from results - union - select channel, i_brand_id, i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id, i_class_id - union - select channel, i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id - union - select channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel - union - select null as channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results) z -order by channel, i_brand_id, i_class_id, i_category_id - limit 100; -with /* TPC-DS query14a.tpl 0.69 part2 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 2000 AND 2000 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 2000 AND 2000 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 2000 AND 2000 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as -(select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2) x) - select this_year.channel ty_channel - ,this_year.i_brand_id ty_brand - ,this_year.i_class_id ty_class - ,this_year.i_category_id ty_category - ,this_year.sales ty_sales - ,this_year.number_sales ty_number_sales - ,last_year.channel ly_channel - ,last_year.i_brand_id ly_brand - ,last_year.i_class_id ly_class - ,last_year.i_category_id ly_category - ,last_year.sales ly_sales - ,last_year.number_sales ly_number_sales -from - (select 'store' channel, i_brand_id,i_class_id,i_category_id - ,sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 2000 + 1 - and d_moy = 12 - and d_dom = 25) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) this_year, - (select 'store' channel, i_brand_id,i_class_id - ,i_category_id, sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 2000 - and d_moy = 12 - and d_dom = 25) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) last_year - where this_year.i_brand_id= last_year.i_brand_id - and this_year.i_class_id = last_year.i_class_id - and this_year.i_category_id = last_year.i_category_id - order by this_year.channel, this_year.i_brand_id, this_year.i_class_id, this_year.i_category_id - limit 100; - --- end template query14a.tpl query 69 in stream 10 --- start template query40.tpl query 70 in stream 10 -select /* TPC-DS query40.tpl 0.86 */ - w_state - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('2001-03-09' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_before - ,sum(case when (cast(d_date as date) >= cast ('2001-03-09' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_after - from - catalog_sales left outer join catalog_returns on - (cs_order_number = cr_order_number - and cs_item_sk = cr_item_sk) - ,warehouse - ,item - ,date_dim - where - i_current_price between 0.99 and 1.49 - and i_item_sk = cs_item_sk - and cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('2001-03-09' as date)) - and dateadd(day,30,cast ('2001-03-09' as date)) - group by - w_state,i_item_id - order by w_state,i_item_id -limit 100; - --- end template query40.tpl query 70 in stream 10 --- start template query73.tpl query 71 in stream 10 -select /* TPC-DS query73.tpl 0.79 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_buy_potential = '1001-5000' or - household_demographics.hd_buy_potential = 'Unknown') - and household_demographics.hd_vehicle_count > 0 - and case when household_demographics.hd_vehicle_count > 0 then - household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count else null end > 1 - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_county in ('Gage County','Jackson County','Levy County','Bronx County') - group by ss_ticket_number,ss_customer_sk) dj,customer - where ss_customer_sk = c_customer_sk - and cnt between 1 and 5 - order by cnt desc, c_last_name asc; - --- end template query73.tpl query 71 in stream 10 --- start template query79.tpl query 72 in stream 10 -select /* TPC-DS query79.tpl 0.89 */ - c_last_name,c_first_name,substring(s_city,1,30),ss_ticket_number,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,store.s_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (household_demographics.hd_dep_count = 7 or household_demographics.hd_vehicle_count > 0) - and date_dim.d_dow = 1 - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_number_employees between 200 and 295 - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,store.s_city) ms,customer - where ss_customer_sk = c_customer_sk - order by c_last_name,c_first_name,substring(s_city,1,30), profit -limit 100; - --- end template query79.tpl query 72 in stream 10 --- start template query11.tpl query 73 in stream 10 -with /* TPC-DS query11.tpl 0.51 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ss_ext_list_price-ss_ext_discount_amt) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ws_ext_list_price-ws_ext_discount_amt) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_birth_country - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 2001 - and t_s_secyear.dyear = 2001+1 - and t_w_firstyear.dyear = 2001 - and t_w_secyear.dyear = 2001+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else 0.0 end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else 0.0 end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_birth_country -limit 100; - --- end template query11.tpl query 73 in stream 10 --- start template query6.tpl query 74 in stream 10 -select /* TPC-DS query6.tpl 0.58 */ a.ca_state state, count(*) cnt - from customer_address a - ,customer c - ,store_sales s - ,date_dim d - ,item i - where a.ca_address_sk = c.c_current_addr_sk - and c.c_customer_sk = s.ss_customer_sk - and s.ss_sold_date_sk = d.d_date_sk - and s.ss_item_sk = i.i_item_sk - and d.d_month_seq = - (select distinct (d_month_seq) - from date_dim - where d_year = 2001 - and d_moy = 2 ) - and i.i_current_price > 1.2 * - (select avg(j.i_current_price) - from item j - where j.i_category = i.i_category) - group by a.ca_state - having count(*) >= 10 - order by cnt, a.ca_state - limit 100; - --- end template query6.tpl query 74 in stream 10 --- start template query17.tpl query 75 in stream 10 -select /* TPC-DS query17.tpl 0.41 */ i_item_id - ,i_item_desc - ,s_state - ,count(ss_quantity) as store_sales_quantitycount - ,avg(ss_quantity) as store_sales_quantityave - ,stddev_samp(ss_quantity) as store_sales_quantitystdev - ,stddev_samp(ss_quantity)/avg(ss_quantity) as store_sales_quantitycov - ,count(sr_return_quantity) as store_returns_quantitycount - ,avg(sr_return_quantity) as store_returns_quantityave - ,stddev_samp(sr_return_quantity) as store_returns_quantitystdev - ,stddev_samp(sr_return_quantity)/avg(sr_return_quantity) as store_returns_quantitycov - ,count(cs_quantity) as catalog_sales_quantitycount ,avg(cs_quantity) as catalog_sales_quantityave - ,stddev_samp(cs_quantity) as catalog_sales_quantitystdev - ,stddev_samp(cs_quantity)/avg(cs_quantity) as catalog_sales_quantitycov - from store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where d1.d_quarter_name = '2000Q1' - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_quarter_name in ('2000Q1','2000Q2','2000Q3') - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_quarter_name in ('2000Q1','2000Q2','2000Q3') - group by i_item_id - ,i_item_desc - ,s_state - order by i_item_id - ,i_item_desc - ,s_state -limit 100; - --- end template query17.tpl query 75 in stream 10 --- start template query58.tpl query 76 in stream 10 -with /* TPC-DS query58.tpl 0.19 */ ss_items as - (select i_item_id item_id - ,sum(ss_ext_sales_price) ss_item_rev - from store_sales - ,item - ,date_dim - where ss_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '2002-01-08')) - and ss_sold_date_sk = d_date_sk - group by i_item_id), - cs_items as - (select i_item_id item_id - ,sum(cs_ext_sales_price) cs_item_rev - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '2002-01-08')) - and cs_sold_date_sk = d_date_sk - group by i_item_id), - ws_items as - (select i_item_id item_id - ,sum(ws_ext_sales_price) ws_item_rev - from web_sales - ,item - ,date_dim - where ws_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq =(select d_week_seq - from date_dim - where d_date = '2002-01-08')) - and ws_sold_date_sk = d_date_sk - group by i_item_id) - select ss_items.item_id - ,ss_item_rev - ,ss_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ss_dev - ,cs_item_rev - ,cs_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 cs_dev - ,ws_item_rev - ,ws_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ws_dev - ,(ss_item_rev+cs_item_rev+ws_item_rev)/3 average - from ss_items,cs_items,ws_items - where ss_items.item_id=cs_items.item_id - and ss_items.item_id=ws_items.item_id - and ss_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - and ss_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and cs_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and cs_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and ws_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and ws_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - order by item_id - ,ss_item_rev - limit 100; - --- end template query58.tpl query 76 in stream 10 --- start template query56.tpl query 77 in stream 10 -with /* TPC-DS query56.tpl 0.83 */ ss as ( - select i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where i_item_id in (select - i_item_id -from item -where i_color in ('moccasin','lawn','cyan')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 1 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id), - cs as ( - select i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('moccasin','lawn','cyan')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 1 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id), - ws as ( - select i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('moccasin','lawn','cyan')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 1 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id) - select i_item_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by total_sales, - i_item_id - limit 100; - --- end template query56.tpl query 77 in stream 10 --- start template query83.tpl query 78 in stream 10 -with /* TPC-DS query83.tpl 0.96 */ sr_items as - (select i_item_id item_id, - sum(sr_return_quantity) sr_item_qty - from store_returns, - item, - date_dim - where sr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2001-02-08','2001-09-09','2001-11-16'))) - and sr_returned_date_sk = d_date_sk - group by i_item_id), - cr_items as - (select i_item_id item_id, - sum(cr_return_quantity) cr_item_qty - from catalog_returns, - item, - date_dim - where cr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2001-02-08','2001-09-09','2001-11-16'))) - and cr_returned_date_sk = d_date_sk - group by i_item_id), - wr_items as - (select i_item_id item_id, - sum(wr_return_quantity) wr_item_qty - from web_returns, - item, - date_dim - where wr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2001-02-08','2001-09-09','2001-11-16'))) - and wr_returned_date_sk = d_date_sk - group by i_item_id) - select sr_items.item_id - ,sr_item_qty - ,sr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 sr_dev - ,cr_item_qty - ,cr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 cr_dev - ,wr_item_qty - ,wr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 wr_dev - ,(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 average - from sr_items - ,cr_items - ,wr_items - where sr_items.item_id=cr_items.item_id - and sr_items.item_id=wr_items.item_id - order by sr_items.item_id - ,sr_item_qty - limit 100; - --- end template query83.tpl query 78 in stream 10 --- start template query51.tpl query 79 in stream 10 -WITH /* TPC-DS query51.tpl 0.46 */ web_v1 as ( -select - ws_item_sk item_sk, d_date, - sum(sum(ws_sales_price)) - over (partition by ws_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from web_sales - ,date_dim -where ws_sold_date_sk=d_date_sk - and d_month_seq between 1199 and 1199+11 - and ws_item_sk is not NULL -group by ws_item_sk, d_date), -store_v1 as ( -select - ss_item_sk item_sk, d_date, - sum(sum(ss_sales_price)) - over (partition by ss_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from store_sales - ,date_dim -where ss_sold_date_sk=d_date_sk - and d_month_seq between 1199 and 1199+11 - and ss_item_sk is not NULL -group by ss_item_sk, d_date) - select * -from (select item_sk - ,d_date - ,web_sales - ,store_sales - ,max(web_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) web_cumulative - ,max(store_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) store_cumulative - from (select case when web.item_sk is not null then web.item_sk else store.item_sk end item_sk - ,case when web.d_date is not null then web.d_date else store.d_date end d_date - ,web.cume_sales web_sales - ,store.cume_sales store_sales - from web_v1 web full outer join store_v1 store on (web.item_sk = store.item_sk - and web.d_date = store.d_date) - )x )y -where web_cumulative > store_cumulative -order by item_sk - ,d_date -limit 100; - --- end template query51.tpl query 79 in stream 10 --- start template query29.tpl query 80 in stream 10 -select /* TPC-DS query29.tpl 0.53 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,max(ss_quantity) as store_sales_quantity - ,max(sr_return_quantity) as store_returns_quantity - ,max(cs_quantity) as catalog_sales_quantity - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 1998 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 4 + 3 - and d2.d_year = 1998 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_year in (1998,1998+1,1998+2) - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query29.tpl query 80 in stream 10 --- start template query22a.tpl query 81 in stream 10 -with /* TPC-DS query22a.tpl 0.55 */ results as -(select i_product_name - ,i_brand - ,i_class - ,i_category - ,avg(inv_quantity_on_hand) qoh - from inventory - ,date_dim - ,item --- ,warehouse - where inv_date_sk=d_date_sk - and inv_item_sk=i_item_sk --- and inv_warehouse_sk = w_warehouse_sk - and d_month_seq between 1195 and 1195 + 11 - group by i_product_name,i_brand,i_class,i_category), -results_rollup as -(select i_product_name, i_brand, i_class, i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class,i_category -union all -select i_product_name, i_brand, i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class -union all -select i_product_name, i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand -union all -select i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name -union all -select null i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results) - select i_product_name, i_brand, i_class, i_category,qoh - from results_rollup - order by qoh, i_product_name, i_brand, i_class, i_category -limit 100; - --- end template query22a.tpl query 81 in stream 10 --- start template query71.tpl query 82 in stream 10 -select /* TPC-DS query71.tpl 0.72 */ i_brand_id brand_id, i_brand brand,t_hour,t_minute, - sum(ext_price) ext_price - from item, (select ws_ext_sales_price as ext_price, - ws_sold_date_sk as sold_date_sk, - ws_item_sk as sold_item_sk, - ws_sold_time_sk as time_sk - from web_sales,date_dim - where d_date_sk = ws_sold_date_sk - and d_moy=11 - and d_year=2000 - union all - select cs_ext_sales_price as ext_price, - cs_sold_date_sk as sold_date_sk, - cs_item_sk as sold_item_sk, - cs_sold_time_sk as time_sk - from catalog_sales,date_dim - where d_date_sk = cs_sold_date_sk - and d_moy=11 - and d_year=2000 - union all - select ss_ext_sales_price as ext_price, - ss_sold_date_sk as sold_date_sk, - ss_item_sk as sold_item_sk, - ss_sold_time_sk as time_sk - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - and d_moy=11 - and d_year=2000 - ) tmp,time_dim - where - sold_item_sk = i_item_sk - and i_manager_id=1 - and time_sk = t_time_sk - and (t_meal_time = 'breakfast' or t_meal_time = 'dinner') - group by i_brand, i_brand_id,t_hour,t_minute - order by ext_price desc, i_brand_id - ; - --- end template query71.tpl query 82 in stream 10 --- start template query68.tpl query 83 in stream 10 -select /* TPC-DS query68.tpl 0.95 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,extended_price - ,extended_tax - ,list_price - from (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_ext_sales_price) extended_price - ,sum(ss_ext_list_price) list_price - ,sum(ss_ext_tax) extended_tax - from store_sales - ,date_dim - ,store - ,household_demographics - ,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_dep_count = 6 or - household_demographics.hd_vehicle_count= 2) - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_city in ('Hillcrest','Fairfield') - group by ss_ticket_number - ,ss_customer_sk - ,ss_addr_sk,ca_city) dn - ,customer - ,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,ss_ticket_number - limit 100; - --- end template query68.tpl query 83 in stream 10 --- start template query60.tpl query 84 in stream 10 -with /* TPC-DS query60.tpl 0.29 */ ss as ( - select - i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Jewelry')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 9 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id), - cs as ( - select - i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Jewelry')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 9 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id), - ws as ( - select - i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Jewelry')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 9 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id) - select - i_item_id -,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by i_item_id - ,total_sales - limit 100; - --- end template query60.tpl query 84 in stream 10 --- start template query12.tpl query 85 in stream 10 -select /* TPC-DS query12.tpl 0.64 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ws_ext_sales_price) as itemrevenue - ,sum(ws_ext_sales_price)*100/sum(sum(ws_ext_sales_price)) over - (partition by i_class) as revenueratio -from - web_sales - ,item - ,date_dim -where - ws_item_sk = i_item_sk - and i_category in ('Electronics', 'Sports', 'Women') - and ws_sold_date_sk = d_date_sk - and d_date between cast('2000-01-15' as date) - and dateadd(day,30,cast('2000-01-15' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query12.tpl query 85 in stream 10 --- start template query4.tpl query 86 in stream 10 -with /* TPC-DS query4.tpl 0.93 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(((ss_ext_list_price-ss_ext_wholesale_cost-ss_ext_discount_amt)+ss_ext_sales_price)/2) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((cs_ext_list_price-cs_ext_wholesale_cost-cs_ext_discount_amt)+cs_ext_sales_price)/2) ) year_total - ,'c' sale_type - from customer - ,catalog_sales - ,date_dim - where c_customer_sk = cs_bill_customer_sk - and cs_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year -union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((ws_ext_list_price-ws_ext_wholesale_cost-ws_ext_discount_amt)+ws_ext_sales_price)/2) ) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_login - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_c_firstyear - ,year_total t_c_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_c_secyear.customer_id - and t_s_firstyear.customer_id = t_c_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_c_firstyear.sale_type = 'c' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_c_secyear.sale_type = 'c' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 1999 - and t_s_secyear.dyear = 1999+1 - and t_c_firstyear.dyear = 1999 - and t_c_secyear.dyear = 1999+1 - and t_w_firstyear.dyear = 1999 - and t_w_secyear.dyear = 1999+1 - and t_s_firstyear.year_total > 0 - and t_c_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_login -limit 100; - --- end template query4.tpl query 86 in stream 10 --- start template query89.tpl query 87 in stream 10 -select /* TPC-DS query89.tpl 0.56 */ * -from( -select i_category, i_class, i_brand, - s_store_name, s_company_name, - d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, s_store_name, s_company_name) - avg_monthly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - d_year in (1999) and - ((i_category in ('Women','Home','Electronics') and - i_class in ('fragrances','lighting','portable') - ) - or (i_category in ('Men','Books','Sports') and - i_class in ('pants','travel','fitness') - )) -group by i_category, i_class, i_brand, - s_store_name, s_company_name, d_moy) tmp1 -where case when (avg_monthly_sales <> 0) then (abs(sum_sales - avg_monthly_sales) / avg_monthly_sales) else null end > 0.1 -order by sum_sales - avg_monthly_sales, s_store_name -limit 100; - --- end template query89.tpl query 87 in stream 10 --- start template query61.tpl query 88 in stream 10 -select /* TPC-DS query61.tpl 0.97 */ promotions,total,cast(promotions as decimal(15,4))/cast(total as decimal(15,4))*100 -from - (select sum(ss_ext_sales_price) promotions - from store_sales - ,store - ,promotion - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_promo_sk = p_promo_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -6 - and i_category = 'Jewelry' - and (p_channel_dmail = 'Y' or p_channel_email = 'Y' or p_channel_tv = 'Y') - and s_gmt_offset = -6 - and d_year = 1999 - and d_moy = 12) promotional_sales, - (select sum(ss_ext_sales_price) total - from store_sales - ,store - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -6 - and i_category = 'Jewelry' - and s_gmt_offset = -6 - and d_year = 1999 - and d_moy = 12) all_sales -order by promotions, total -limit 100; - --- end template query61.tpl query 88 in stream 10 --- start template query46.tpl query 89 in stream 10 -select /* TPC-DS query46.tpl 0.23 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and (household_demographics.hd_dep_count = 4 or - household_demographics.hd_vehicle_count= 0) - and date_dim.d_dow in (6,0) - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_city in ('Pine Grove','Riverview','Mount Vernon','Liberty','Mount Olive') - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,ca_city) dn,customer,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - limit 100; - --- end template query46.tpl query 89 in stream 10 --- start template query92.tpl query 90 in stream 10 -select /* TPC-DS query92.tpl 0.44 */ - sum(ws_ext_discount_amt) as "Excess Discount Amount" -from - web_sales - ,item - ,date_dim -where -i_manufact_id = 197 -and i_item_sk = ws_item_sk -and d_date between '2002-02-19' and - dateadd(day,90,cast('2002-02-19' as date)) -and d_date_sk = ws_sold_date_sk -and ws_ext_discount_amt - > ( - SELECT - 1.3 * avg(ws_ext_discount_amt) - FROM - web_sales - ,date_dim - WHERE - ws_item_sk = i_item_sk - and d_date between '2002-02-19' and - dateadd(day,90,cast('2002-02-19' as date)) - and d_date_sk = ws_sold_date_sk - ) -order by sum(ws_ext_discount_amt) -limit 100; - --- end template query92.tpl query 90 in stream 10 --- start template query13.tpl query 91 in stream 10 -select /* TPC-DS query13.tpl 0.91 */ avg(ss_quantity) - ,avg(ss_ext_sales_price) - ,avg(ss_ext_wholesale_cost) - ,sum(ss_ext_wholesale_cost) - from store_sales - ,store - ,customer_demographics - ,household_demographics - ,customer_address - ,date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2001 - and((ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'S' - and cd_education_status = '2 yr Degree' - and ss_sales_price between 100.00 and 150.00 - and hd_dep_count = 3 - )or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'U' - and cd_education_status = 'Advanced Degree' - and ss_sales_price between 50.00 and 100.00 - and hd_dep_count = 1 - ) or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'M' - and cd_education_status = 'Unknown' - and ss_sales_price between 150.00 and 200.00 - and hd_dep_count = 1 - )) - and((ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('OH', 'MN', 'KS') - and ss_net_profit between 100 and 200 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('TN', 'MS', 'CA') - and ss_net_profit between 150 and 300 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('MO', 'WA', 'AR') - and ss_net_profit between 50 and 250 - )) -; - --- end template query13.tpl query 91 in stream 10 --- start template query9.tpl query 92 in stream 10 -select /* TPC-DS query9.tpl 0.49 */ case when (select count(*) - from store_sales - where ss_quantity between 1 and 20) > 15625418 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 1 and 20) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 1 and 20) end bucket1 , - case when (select count(*) - from store_sales - where ss_quantity between 21 and 40) > 2542155 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 21 and 40) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 21 and 40) end bucket2, - case when (select count(*) - from store_sales - where ss_quantity between 41 and 60) > 29263305 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 41 and 60) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 41 and 60) end bucket3, - case when (select count(*) - from store_sales - where ss_quantity between 61 and 80) > 177631 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 61 and 80) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 61 and 80) end bucket4, - case when (select count(*) - from store_sales - where ss_quantity between 81 and 100) > 42701197 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 81 and 100) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 81 and 100) end bucket5 -from reason -where r_reason_sk = 1 -; - --- end template query9.tpl query 92 in stream 10 --- start template query74.tpl query 93 in stream 10 -with /* TPC-DS query74.tpl 0.76 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,max(ss_net_paid) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1998,1998+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,max(ws_net_paid) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - and d_year in (1998,1998+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - ) - select - t_s_secyear.customer_id, t_s_secyear.customer_first_name, t_s_secyear.customer_last_name - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.year = 1998 - and t_s_secyear.year = 1998+1 - and t_w_firstyear.year = 1998 - and t_w_secyear.year = 1998+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - order by 1,2,3 -limit 100; - --- end template query74.tpl query 93 in stream 10 --- start template query8.tpl query 94 in stream 10 -select /* TPC-DS query8.tpl 0.63 */ s_store_name - ,sum(ss_net_profit) - from store_sales - ,date_dim - ,store, - (select ca_zip - from ( - SELECT substring(ca_zip,1,5) ca_zip - FROM customer_address - WHERE substring(ca_zip,1,5) IN ( - '30922','50280','22984','45868','40057','92700', - '95934','57967','31997','85025','84580', - '65051','22295','65440','16300','50002', - '62309','57905','31801','70919','63179', - '96087','40944','34503','81400','42740', - '71196','75696','68400','28982','77749', - '18797','42423','63507','42840','95304', - '72065','61323','12381','59726','47999', - '67428','22490','67050','63376','21156', - '57853','94123','15409','80202','79862', - '82811','18126','78463','55310','15290', - '62829','27767','11681','20704','51635', - '87899','34711','31042','51135','21975', - '11870','44680','61894','67540','44671', - '11053','16613','56491','61712','20321', - '27928','34094','31602','19771','64268', - '69353','30581','97559','93157','71965', - '57317','18104','27503','36930','87605', - '68462','91711','68632','36301','36035', - '84480','74388','88190','20362','68591', - '71174','77123','26838','61991','66197', - '38209','39197','32958','45258','32078', - '83414','50286','98155','50231','46170', - '11252','98760','30266','42757','26438', - '46703','41994','99081','36862','96497', - '57946','51685','99062','88623','45625', - '91376','92790','32141','17182','37515', - '53180','95698','91928','25143','60092', - '19186','57330','98941','65283','26329', - '12731','53184','69819','29119','75460', - '19001','79601','50359','21154','19878', - '81065','62367','34922','46212','77202', - '89420','58217','82163','39727','12203', - '18879','52469','43608','60276','68325', - '31992','27129','68534','67883','66693', - '61176','23379','56606','10385','87653', - '99153','87115','10218','51438','47623', - '75788','98847','66262','45018','66990', - '18049','54604','58751','11445','94887', - '89024','12892','72555','55188','53646', - '12097','25051','90157','92754','80023', - '76793','34077','21569','75807','17166', - '68348','60748','14883','75990','20386', - '52138','96001','16881','24733','26375', - '57842','48469','13341','62532','55046', - '92962','77476','82974','95076','98684', - '35441','38239','56961','84638','97125', - '81982','23875','79316','94658','94862', - '77465','46911','83653','29228','16946', - '48814','79063','29646','21437','52526', - '34346','81455','24465','53852','22324', - '87032','11830','23517','38185','63273', - '14178','32219','12222','51879','75611', - '49076','64203','54536','69176','52179', - '54773','73951','19973','39608','57336', - '30486','35870','20830','13361','70036', - '53453','80375','35547','67928','25197', - '73009','52713','53311','77716','87639', - '23464','96961','86748','89040','44861', - '22860','14342','57128','37727','13288', - '75854','71951','52384','64349','50748', - '83254','98515','70878','54233','33059', - '96215','10256','81466','82223','64290', - '63860','96411','31970','97094','63789', - '99370','14213','69292','10896','51472', - '91597','66718','77767','78434','16566', - '79160','85882','87844','28879','19225', - '82839','77664','83422','95995','59313', - '95808','57900','76662','84911','51285', - '34017','55724','69383','51228','28640', - '71598','89479','13495','50201','68373', - '18069','14951','23316','50312','16552', - '44800','48606','71819','42452','24213', - '81404','44149','90539','79311','68940', - '41226','44200','87420','39273','94690', - '40100','89269','94921','20070','59073', - '39748','65455','33749','63821','71709', - '46498','30151','63624','94069','76917', - '15868','82965','98255','72246','19217', - '53665','74202','14585','51975') - intersect - select ca_zip - from (SELECT substring(ca_zip,1,5) ca_zip,count(*) cnt - FROM customer_address, customer - WHERE ca_address_sk = c_current_addr_sk and - c_preferred_cust_flag='Y' - group by ca_zip - having count(*) > 10)A1)A2) V1 - where ss_store_sk = s_store_sk - and ss_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 2002 - and (substring(s_zip,1,2) = substring(V1.ca_zip,1,2)) - group by s_store_name - order by s_store_name - limit 100; - --- end template query8.tpl query 94 in stream 10 --- start template query3.tpl query 95 in stream 10 -select /* TPC-DS query3.tpl 0.45 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_net_profit) sum_agg - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manufact_id = 834 - and dt.d_moy=12 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,sum_agg desc - ,brand_id - limit 100; - --- end template query3.tpl query 95 in stream 10 --- start template query95.tpl query 96 in stream 10 -with /* TPC-DS query95.tpl 0.43 */ ws_wh as -(select ws1.ws_order_number,ws1.ws_warehouse_sk wh1,ws2.ws_warehouse_sk wh2 - from web_sales ws1,web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) - select - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '1999-4-01' and - dateadd(day,60,cast('1999-4-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'PA' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and ws1.ws_order_number in (select ws_order_number - from ws_wh) -and ws1.ws_order_number in (select wr_order_number - from web_returns,ws_wh - where wr_order_number = ws_wh.ws_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query95.tpl query 96 in stream 10 --- start template query26.tpl query 97 in stream 10 -select /* TPC-DS query26.tpl 0.85 */ i_item_id, - avg(cs_quantity) agg1, - avg(cs_list_price) agg2, - avg(cs_coupon_amt) agg3, - avg(cs_sales_price) agg4 - from catalog_sales, customer_demographics, date_dim, item, promotion - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd_demo_sk and - cs_promo_sk = p_promo_sk and - cd_gender = 'M' and - cd_marital_status = 'U' and - cd_education_status = 'Primary' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 2000 - group by i_item_id - order by i_item_id - limit 100; - --- end template query26.tpl query 97 in stream 10 --- start template query81.tpl query 98 in stream 10 -with /* TPC-DS query81.tpl 0.37 */ customer_total_return as - (select cr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(cr_return_amt_inc_tax) as ctr_total_return - from catalog_returns - ,date_dim - ,customer_address - where cr_returned_date_sk = d_date_sk - and d_year =2001 - and cr_returning_addr_sk = ca_address_sk - group by cr_returning_customer_sk - ,ca_state ) - select c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'IL' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - limit 100; - --- end template query81.tpl query 98 in stream 10 --- start template query19.tpl query 99 in stream 10 -select /* TPC-DS query19.tpl 0.8 */ i_brand_id brand_id, i_brand brand, i_manufact_id, i_manufact, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item,customer,customer_address,store - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=8 - and d_moy=11 - and d_year=1999 - and ss_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and substring(ca_zip,1,5) <> substring(s_zip,1,5) - and ss_store_sk = s_store_sk - group by i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact - order by ext_price desc - ,i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact -limit 100 ; - --- end template query19.tpl query 99 in stream 10 diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/1TB/queries/query_2.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/1TB/queries/query_2.sql deleted file mode 100644 index f8f45636..00000000 --- a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/1TB/queries/query_2.sql +++ /dev/null @@ -1,5027 +0,0 @@ --- start template query56.tpl query 1 in stream 2 -with /* TPC-DS query56.tpl 0.83 */ ss as ( - select i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where i_item_id in (select - i_item_id -from item -where i_color in ('misty','chartreuse','sienna')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 7 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -7 - group by i_item_id), - cs as ( - select i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('misty','chartreuse','sienna')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 7 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -7 - group by i_item_id), - ws as ( - select i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('misty','chartreuse','sienna')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 7 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -7 - group by i_item_id) - select i_item_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by total_sales, - i_item_id - limit 100; - --- end template query56.tpl query 1 in stream 2 --- start template query98.tpl query 2 in stream 2 -select /* TPC-DS query98.tpl 0.32 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ss_ext_sales_price) as itemrevenue - ,sum(ss_ext_sales_price)*100/sum(sum(ss_ext_sales_price)) over - (partition by i_class) as revenueratio -from - store_sales - ,item - ,date_dim -where - ss_item_sk = i_item_sk - and i_category in ('Children', 'Sports', 'Jewelry') - and ss_sold_date_sk = d_date_sk - and d_date between cast('1999-04-24' as date) - and dateadd(day,30,cast('1999-04-24' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio; - --- end template query98.tpl query 2 in stream 2 --- start template query59.tpl query 3 in stream 2 -with /* TPC-DS query59.tpl 0.30 */ wss as - (select d_week_seq, - ss_store_sk, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - group by d_week_seq,ss_store_sk - ) - select s_store_name1,s_store_id1,d_week_seq1 - ,sun_sales1/sun_sales2,mon_sales1/mon_sales2 - ,tue_sales1/tue_sales2,wed_sales1/wed_sales2,thu_sales1/thu_sales2 - ,fri_sales1/fri_sales2,sat_sales1/sat_sales2 - from - (select s_store_name s_store_name1,wss.d_week_seq d_week_seq1 - ,s_store_id s_store_id1,sun_sales sun_sales1 - ,mon_sales mon_sales1,tue_sales tue_sales1 - ,wed_sales wed_sales1,thu_sales thu_sales1 - ,fri_sales fri_sales1,sat_sales sat_sales1 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1211 and 1211 + 11) y, - (select s_store_name s_store_name2,wss.d_week_seq d_week_seq2 - ,s_store_id s_store_id2,sun_sales sun_sales2 - ,mon_sales mon_sales2,tue_sales tue_sales2 - ,wed_sales wed_sales2,thu_sales thu_sales2 - ,fri_sales fri_sales2,sat_sales sat_sales2 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1211+ 12 and 1211 + 23) x - where s_store_id1=s_store_id2 - and d_week_seq1=d_week_seq2-52 - order by s_store_name1,s_store_id1,d_week_seq1 -limit 100; - --- end template query59.tpl query 3 in stream 2 --- start template query24.tpl query 4 in stream 2 -with /* TPC-DS query24.tpl 0.92 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_net_profit) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip -and s_market_id=7 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'brown' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; -with /* TPC-DS query24.tpl 0.92 part2 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_net_profit) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip - and s_market_id = 7 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'lace' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; - --- end template query24.tpl query 4 in stream 2 --- start template query88.tpl query 5 in stream 2 -select /* TPC-DS query88.tpl 0.66 */ * -from - (select count(*) h8_30_to_9 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s1, - (select count(*) h9_to_9_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s2, - (select count(*) h9_30_to_10 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s3, - (select count(*) h10_to_10_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s4, - (select count(*) h10_30_to_11 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s5, - (select count(*) h11_to_11_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s6, - (select count(*) h11_30_to_12 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s7, - (select count(*) h12_to_12_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 12 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2)) - and store.s_store_name = 'ese') s8 -; - --- end template query88.tpl query 5 in stream 2 --- start template query2.tpl query 6 in stream 2 -with /* TPC-DS query2.tpl 0.84 */ wscs as - (select sold_date_sk - ,sales_price - from (select ws_sold_date_sk sold_date_sk - ,ws_ext_sales_price sales_price - from web_sales - union all - select cs_sold_date_sk sold_date_sk - ,cs_ext_sales_price sales_price - from catalog_sales)), - wswscs as - (select d_week_seq, - sum(case when (d_day_name='Sunday') then sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then sales_price else null end) sat_sales - from wscs - ,date_dim - where d_date_sk = sold_date_sk - group by d_week_seq) - select d_week_seq1 - ,round(sun_sales1/sun_sales2,2) - ,round(mon_sales1/mon_sales2,2) - ,round(tue_sales1/tue_sales2,2) - ,round(wed_sales1/wed_sales2,2) - ,round(thu_sales1/thu_sales2,2) - ,round(fri_sales1/fri_sales2,2) - ,round(sat_sales1/sat_sales2,2) - from - (select wswscs.d_week_seq d_week_seq1 - ,sun_sales sun_sales1 - ,mon_sales mon_sales1 - ,tue_sales tue_sales1 - ,wed_sales wed_sales1 - ,thu_sales thu_sales1 - ,fri_sales fri_sales1 - ,sat_sales sat_sales1 - from wswscs,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 1999) y, - (select wswscs.d_week_seq d_week_seq2 - ,sun_sales sun_sales2 - ,mon_sales mon_sales2 - ,tue_sales tue_sales2 - ,wed_sales wed_sales2 - ,thu_sales thu_sales2 - ,fri_sales fri_sales2 - ,sat_sales sat_sales2 - from wswscs - ,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 1999+1) z - where d_week_seq1=d_week_seq2-53 - order by d_week_seq1; - --- end template query2.tpl query 6 in stream 2 --- start template query5a.tpl query 7 in stream 2 -with /* TPC-DS query5a.tpl 0.98 */ ssr as - (select s_store_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ss_store_sk as store_sk, - ss_sold_date_sk as date_sk, - ss_ext_sales_price as sales_price, - ss_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from store_sales - union all - select sr_store_sk as store_sk, - sr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - sr_return_amt as return_amt, - sr_net_loss as net_loss - from store_returns - ) salesreturns, - date_dim, - store - where date_sk = d_date_sk - and d_date between cast('1998-08-21' as date) - and dateadd(day,14,cast('1998-08-21' as date)) - and store_sk = s_store_sk - group by s_store_id) - , - csr as - (select cp_catalog_page_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select cs_catalog_page_sk as page_sk, - cs_sold_date_sk as date_sk, - cs_ext_sales_price as sales_price, - cs_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from catalog_sales - union all - select cr_catalog_page_sk as page_sk, - cr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - cr_return_amount as return_amt, - cr_net_loss as net_loss - from catalog_returns - ) salesreturns, - date_dim, - catalog_page - where date_sk = d_date_sk - and d_date between cast('1998-08-21' as date) - and dateadd(day,14,cast('1998-08-21' as date)) - and page_sk = cp_catalog_page_sk - group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ws_web_site_sk as wsr_web_site_sk, - ws_sold_date_sk as date_sk, - ws_ext_sales_price as sales_price, - ws_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from web_sales - union all - select ws_web_site_sk as wsr_web_site_sk, - wr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - wr_return_amt as return_amt, - wr_net_loss as net_loss - from web_returns left outer join web_sales on - ( wr_item_sk = ws_item_sk - and wr_order_number = ws_order_number) - ) salesreturns, - date_dim, - web_site - where date_sk = d_date_sk - and d_date between cast('1998-08-21' as date) - and dateadd(day,14,cast('1998-08-21' as date)) - and wsr_web_site_sk = web_site_sk - group by web_site_id) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || s_store_id as id - , sales - , returns - , (profit - profit_loss) as profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || cp_catalog_page_id as id - , sales - , returns - , (profit - profit_loss) as profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , (profit - profit_loss) as profit - from wsr - ) x - group by channel, id) - select channel, id, sales, returns, profit from ( - select channel, id, sales, returns, profit from results - union - select channel, null as id, sum(sales), sum(returns), sum(profit) from results group by channel - union - select null as channel, null as id, sum(sales), sum(returns), sum(profit) from results) foo -order by channel, id -limit 100; - --- end template query5a.tpl query 7 in stream 2 --- start template query6.tpl query 8 in stream 2 -select /* TPC-DS query6.tpl 0.58 */ a.ca_state state, count(*) cnt - from customer_address a - ,customer c - ,store_sales s - ,date_dim d - ,item i - where a.ca_address_sk = c.c_current_addr_sk - and c.c_customer_sk = s.ss_customer_sk - and s.ss_sold_date_sk = d.d_date_sk - and s.ss_item_sk = i.i_item_sk - and d.d_month_seq = - (select distinct (d_month_seq) - from date_dim - where d_year = 2001 - and d_moy = 6 ) - and i.i_current_price > 1.2 * - (select avg(j.i_current_price) - from item j - where j.i_category = i.i_category) - group by a.ca_state - having count(*) >= 10 - order by cnt, a.ca_state - limit 100; - --- end template query6.tpl query 8 in stream 2 --- start template query27a.tpl query 9 in stream 2 -with /* TPC-DS query27a.tpl 0.16 */ results as - (select i_item_id, - s_state, 0 as g_state, - ss_quantity agg1, - ss_list_price agg2, - ss_coupon_amt agg3, - ss_sales_price agg4 - from store_sales, customer_demographics, date_dim, store, item - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_store_sk = s_store_sk and - ss_cdemo_sk = cd_demo_sk and - cd_gender = 'M' and - cd_marital_status = 'D' and - cd_education_status = '2 yr Degree' and - d_year = 2002 and - s_state in ('AL','SC', 'GA', 'NY', 'OH', 'PA') - ) - - select i_item_id, - s_state, g_state, agg1, agg2, agg3, agg4 - from ( - select i_item_id, s_state, 0 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4 from results - group by i_item_id, s_state - union all - select i_item_id, NULL AS s_state, 1 AS g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as s_state, 1 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - ) foo - order by i_item_id, s_state - limit 100; - --- end template query27a.tpl query 9 in stream 2 --- start template query87.tpl query 10 in stream 2 -select /* TPC-DS query87.tpl 0.77 */ count(*) -from ((select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1222 and 1222+11) - except - (select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1222 and 1222+11) - except - (select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1222 and 1222+11) -) cool_cust -; - --- end template query87.tpl query 10 in stream 2 --- start template query90.tpl query 11 in stream 2 -select /* TPC-DS query90.tpl 0.40 */ cast(amc as decimal(15,4))/cast(pmc as decimal(15,4)) am_pm_ratio - from ( select count(*) amc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 9 and 9+1 - and household_demographics.hd_dep_count = 5 - and web_page.wp_char_count between 5000 and 5200) at, - ( select count(*) pmc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 17 and 17+1 - and household_demographics.hd_dep_count = 5 - and web_page.wp_char_count between 5000 and 5200) pt - order by am_pm_ratio - limit 100; - --- end template query90.tpl query 11 in stream 2 --- start template query83.tpl query 12 in stream 2 -with /* TPC-DS query83.tpl 0.96 */ sr_items as - (select i_item_id item_id, - sum(sr_return_quantity) sr_item_qty - from store_returns, - item, - date_dim - where sr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('1999-02-05','1999-08-20','1999-11-12'))) - and sr_returned_date_sk = d_date_sk - group by i_item_id), - cr_items as - (select i_item_id item_id, - sum(cr_return_quantity) cr_item_qty - from catalog_returns, - item, - date_dim - where cr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('1999-02-05','1999-08-20','1999-11-12'))) - and cr_returned_date_sk = d_date_sk - group by i_item_id), - wr_items as - (select i_item_id item_id, - sum(wr_return_quantity) wr_item_qty - from web_returns, - item, - date_dim - where wr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('1999-02-05','1999-08-20','1999-11-12'))) - and wr_returned_date_sk = d_date_sk - group by i_item_id) - select sr_items.item_id - ,sr_item_qty - ,sr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 sr_dev - ,cr_item_qty - ,cr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 cr_dev - ,wr_item_qty - ,wr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 wr_dev - ,(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 average - from sr_items - ,cr_items - ,wr_items - where sr_items.item_id=cr_items.item_id - and sr_items.item_id=wr_items.item_id - order by sr_items.item_id - ,sr_item_qty - limit 100; - --- end template query83.tpl query 12 in stream 2 --- start template query91.tpl query 13 in stream 2 -select /* TPC-DS query91.tpl 0.13 */ - cc_call_center_id Call_Center, - cc_name Call_Center_Name, - cc_manager Manager, - sum(cr_net_loss) Returns_Loss -from - call_center, - catalog_returns, - date_dim, - customer, - customer_address, - customer_demographics, - household_demographics -where - cr_call_center_sk = cc_call_center_sk -and cr_returned_date_sk = d_date_sk -and cr_returning_customer_sk= c_customer_sk -and cd_demo_sk = c_current_cdemo_sk -and hd_demo_sk = c_current_hdemo_sk -and ca_address_sk = c_current_addr_sk -and d_year = 1999 -and d_moy = 11 -and ( (cd_marital_status = 'M' and cd_education_status = 'Unknown') - or(cd_marital_status = 'W' and cd_education_status = 'Advanced Degree')) -and hd_buy_potential like '501-1000%' -and ca_gmt_offset = -7 -group by cc_call_center_id,cc_name,cc_manager,cd_marital_status,cd_education_status -order by sum(cr_net_loss) desc; - --- end template query91.tpl query 13 in stream 2 --- start template query28.tpl query 14 in stream 2 -select /* TPC-DS query28.tpl 0.36 */ * -from (select avg(ss_list_price) B1_LP - ,count(ss_list_price) B1_CNT - ,count(distinct ss_list_price) B1_CNTD - from store_sales - where ss_quantity between 0 and 5 - and (ss_list_price between 32 and 32+10 - or ss_coupon_amt between 15396 and 15396+1000 - or ss_wholesale_cost between 56 and 56+20)) B1, - (select avg(ss_list_price) B2_LP - ,count(ss_list_price) B2_CNT - ,count(distinct ss_list_price) B2_CNTD - from store_sales - where ss_quantity between 6 and 10 - and (ss_list_price between 80 and 80+10 - or ss_coupon_amt between 15672 and 15672+1000 - or ss_wholesale_cost between 61 and 61+20)) B2, - (select avg(ss_list_price) B3_LP - ,count(ss_list_price) B3_CNT - ,count(distinct ss_list_price) B3_CNTD - from store_sales - where ss_quantity between 11 and 15 - and (ss_list_price between 57 and 57+10 - or ss_coupon_amt between 1467 and 1467+1000 - or ss_wholesale_cost between 76 and 76+20)) B3, - (select avg(ss_list_price) B4_LP - ,count(ss_list_price) B4_CNT - ,count(distinct ss_list_price) B4_CNTD - from store_sales - where ss_quantity between 16 and 20 - and (ss_list_price between 13 and 13+10 - or ss_coupon_amt between 11625 and 11625+1000 - or ss_wholesale_cost between 45 and 45+20)) B4, - (select avg(ss_list_price) B5_LP - ,count(ss_list_price) B5_CNT - ,count(distinct ss_list_price) B5_CNTD - from store_sales - where ss_quantity between 21 and 25 - and (ss_list_price between 21 and 21+10 - or ss_coupon_amt between 13443 and 13443+1000 - or ss_wholesale_cost between 2 and 2+20)) B5, - (select avg(ss_list_price) B6_LP - ,count(ss_list_price) B6_CNT - ,count(distinct ss_list_price) B6_CNTD - from store_sales - where ss_quantity between 26 and 30 - and (ss_list_price between 52 and 52+10 - or ss_coupon_amt between 15825 and 15825+1000 - or ss_wholesale_cost between 3 and 3+20)) B6 -limit 100; - --- end template query28.tpl query 14 in stream 2 --- start template query68.tpl query 15 in stream 2 -select /* TPC-DS query68.tpl 0.95 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,extended_price - ,extended_tax - ,list_price - from (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_ext_sales_price) extended_price - ,sum(ss_ext_list_price) list_price - ,sum(ss_ext_tax) extended_tax - from store_sales - ,date_dim - ,store - ,household_demographics - ,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_dep_count = 2 or - household_demographics.hd_vehicle_count= 4) - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_city in ('Mount Olive','Greenwood') - group by ss_ticket_number - ,ss_customer_sk - ,ss_addr_sk,ca_city) dn - ,customer - ,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,ss_ticket_number - limit 100; - --- end template query68.tpl query 15 in stream 2 --- start template query8.tpl query 16 in stream 2 -select /* TPC-DS query8.tpl 0.63 */ s_store_name - ,sum(ss_net_profit) - from store_sales - ,date_dim - ,store, - (select ca_zip - from ( - SELECT substring(ca_zip,1,5) ca_zip - FROM customer_address - WHERE substring(ca_zip,1,5) IN ( - '91010','55859','24810','95679','92904','35248', - '84607','67408','82747','65026','57189', - '59244','42987','93042','38417','30036', - '25966','70440','60821','91170','12009', - '93558','58380','50762','82107','99279', - '38896','53204','88354','30290','31659', - '88619','10825','88858','25086','64106', - '67470','59763','94173','10325','53980', - '12298','36624','26415','28885','23113', - '60014','55793','59715','59589','71512', - '81614','51862','65163','32507','44183', - '37855','98888','87785','33665','54913', - '90005','99418','69458','47334','98448', - '16718','85934','20578','30012','73555', - '80713','31987','96789','73159','99590', - '55101','28966','63174','13317','74199', - '21470','17829','61548','66594','39848', - '86073','37409','23092','80443','69085', - '20790','58867','88087','89996','85736', - '34453','18814','92203','81630','40179', - '10864','64344','24731','26509','26964', - '21816','81336','34459','14746','55223', - '97660','15560','84156','78573','71825', - '75809','83273','99208','26908','45421', - '65792','75895','82026','91977','38980', - '72437','61373','16117','80066','21909', - '77487','71408','21986','47274','44618', - '62508','76569','13052','26142','71143', - '14352','28172','98807','81907','90590', - '53751','31846','13813','77486','60473', - '93124','43549','15889','50196','23501', - '93130','98279','60228','14001','48992', - '91304','29563','12785','38374','48151', - '63453','89848','69774','58681','42741', - '43215','44999','27043','63894','67674', - '81629','75855','62461','35208','87316', - '33634','90625','99289','18215','85769', - '79282','54659','88701','86578','99051', - '67766','23054','21793','55367','89207', - '54623','97853','78369','37019','28075', - '71672','97614','14050','23992','19269', - '82022','93693','69558','34837','90114', - '89110','18365','56784','98113','39804', - '25920','63539','17651','86057','67518', - '34909','48869','83488','27179','84493', - '52038','64618','62325','89502','11476', - '55249','85776','90862','42285','23935', - '93782','47705','30353','86835','17266', - '98418','35148','48313','18430','84823', - '16705','43634','10887','31345','40242', - '17995','38880','28286','57812','84717', - '70858','85128','27997','61783','46466', - '17971','24892','78801','43216','10343', - '93018','10876','75408','92695','90583', - '51887','14187','87476','23724','23288', - '38474','50766','53553','44520','60029', - '62093','97197','25736','35372','78387', - '99119','74111','80759','45186','83655', - '94162','62979','64665','81508','19042', - '53742','25702','15650','71026','88331', - '29375','42752','82081','82691','72754', - '31688','47462','73364','77283','98570', - '11986','17723','61449','78809','63269', - '55303','46939','76658','14103','43326', - '66470','77647','93142','69072','20462', - '80674','56132','76805','30901','96827', - '26102','37361','34766','46513','39972', - '19555','20374','21809','67616','31488', - '93385','80521','97483','56679','22586', - '19007','57991','18554','53901','73502', - '12066','51827','63137','44672','96773', - '30438','67529','24196','26205','93192', - '16367','97984','18962','37093','23731', - '65012','80648','22861','16135','63532', - '81591','67643','96268','93899','56924', - '90009','37020','39964','33111','18857', - '94117','51478','91257','79848','88806', - '49584','86393','92269','54958','47349', - '40375','88121','33106','13288','81876', - '36479','42350','92460','39087') - intersect - select ca_zip - from (SELECT substring(ca_zip,1,5) ca_zip,count(*) cnt - FROM customer_address, customer - WHERE ca_address_sk = c_current_addr_sk and - c_preferred_cust_flag='Y' - group by ca_zip - having count(*) > 10)A1)A2) V1 - where ss_store_sk = s_store_sk - and ss_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 1998 - and (substring(s_zip,1,2) = substring(V1.ca_zip,1,2)) - group by s_store_name - order by s_store_name - limit 100; - --- end template query8.tpl query 16 in stream 2 --- start template query76.tpl query 17 in stream 2 -select /* TPC-DS query76.tpl 0.99 */ channel, col_name, d_year, d_qoy, i_category, COUNT(*) sales_cnt, SUM(ext_sales_price) sales_amt FROM ( - SELECT 'store' as channel, 'ss_customer_sk' col_name, d_year, d_qoy, i_category, ss_ext_sales_price ext_sales_price - FROM store_sales, item, date_dim - WHERE ss_customer_sk IS NULL - AND ss_sold_date_sk=d_date_sk - AND ss_item_sk=i_item_sk - UNION ALL - SELECT 'web' as channel, 'ws_promo_sk' col_name, d_year, d_qoy, i_category, ws_ext_sales_price ext_sales_price - FROM web_sales, item, date_dim - WHERE ws_promo_sk IS NULL - AND ws_sold_date_sk=d_date_sk - AND ws_item_sk=i_item_sk - UNION ALL - SELECT 'catalog' as channel, 'cs_ship_cdemo_sk' col_name, d_year, d_qoy, i_category, cs_ext_sales_price ext_sales_price - FROM catalog_sales, item, date_dim - WHERE cs_ship_cdemo_sk IS NULL - AND cs_sold_date_sk=d_date_sk - AND cs_item_sk=i_item_sk) foo -GROUP BY channel, col_name, d_year, d_qoy, i_category -ORDER BY channel, col_name, d_year, d_qoy, i_category -limit 100; - --- end template query76.tpl query 17 in stream 2 --- start template query75.tpl query 18 in stream 2 -WITH /* TPC-DS query75.tpl 0.3 */ all_sales AS ( - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,SUM(sales_cnt) AS sales_cnt - ,SUM(sales_amt) AS sales_amt - FROM (SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,cs_quantity - COALESCE(cr_return_quantity,0) AS sales_cnt - ,cs_ext_sales_price - COALESCE(cr_return_amount,0.0) AS sales_amt - FROM catalog_sales JOIN item ON i_item_sk=cs_item_sk - JOIN date_dim ON d_date_sk=cs_sold_date_sk - LEFT JOIN catalog_returns ON (cs_order_number=cr_order_number - AND cs_item_sk=cr_item_sk) - WHERE i_category='Music' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ss_quantity - COALESCE(sr_return_quantity,0) AS sales_cnt - ,ss_ext_sales_price - COALESCE(sr_return_amt,0.0) AS sales_amt - FROM store_sales JOIN item ON i_item_sk=ss_item_sk - JOIN date_dim ON d_date_sk=ss_sold_date_sk - LEFT JOIN store_returns ON (ss_ticket_number=sr_ticket_number - AND ss_item_sk=sr_item_sk) - WHERE i_category='Music' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ws_quantity - COALESCE(wr_return_quantity,0) AS sales_cnt - ,ws_ext_sales_price - COALESCE(wr_return_amt,0.0) AS sales_amt - FROM web_sales JOIN item ON i_item_sk=ws_item_sk - JOIN date_dim ON d_date_sk=ws_sold_date_sk - LEFT JOIN web_returns ON (ws_order_number=wr_order_number - AND ws_item_sk=wr_item_sk) - WHERE i_category='Music') sales_detail - GROUP BY d_year, i_brand_id, i_class_id, i_category_id, i_manufact_id) - SELECT prev_yr.d_year AS prev_year - ,curr_yr.d_year AS year - ,curr_yr.i_brand_id - ,curr_yr.i_class_id - ,curr_yr.i_category_id - ,curr_yr.i_manufact_id - ,prev_yr.sales_cnt AS prev_yr_cnt - ,curr_yr.sales_cnt AS curr_yr_cnt - ,curr_yr.sales_cnt-prev_yr.sales_cnt AS sales_cnt_diff - ,curr_yr.sales_amt-prev_yr.sales_amt AS sales_amt_diff - FROM all_sales curr_yr, all_sales prev_yr - WHERE curr_yr.i_brand_id=prev_yr.i_brand_id - AND curr_yr.i_class_id=prev_yr.i_class_id - AND curr_yr.i_category_id=prev_yr.i_category_id - AND curr_yr.i_manufact_id=prev_yr.i_manufact_id - AND curr_yr.d_year=2001 - AND prev_yr.d_year=2001-1 - AND CAST(curr_yr.sales_cnt AS DECIMAL(17,2))/CAST(prev_yr.sales_cnt AS DECIMAL(17,2))<0.9 - ORDER BY sales_cnt_diff,sales_amt_diff - limit 100; - --- end template query75.tpl query 18 in stream 2 --- start template query80a.tpl query 19 in stream 2 -with /* TPC-DS query80a.tpl 0.6 */ ssr as - (select s_store_id as store_id, - sum(ss_ext_sales_price) as sales, - sum(coalesce(sr_return_amt, 0)) as returns, - sum(ss_net_profit - coalesce(sr_net_loss, 0)) as profit - from store_sales left outer join store_returns on - (ss_item_sk = sr_item_sk and ss_ticket_number = sr_ticket_number), - date_dim, - store, - item, - promotion - where ss_sold_date_sk = d_date_sk - and d_date between cast('1999-08-03' as date) - and dateadd(day,30,cast('1999-08-03' as date)) - and ss_store_sk = s_store_sk - and ss_item_sk = i_item_sk - and i_current_price > 50 - and ss_promo_sk = p_promo_sk - and p_channel_tv = 'N' - group by s_store_id) - , - csr as - (select cp_catalog_page_id as catalog_page_id, - sum(cs_ext_sales_price) as sales, - sum(coalesce(cr_return_amount, 0)) as returns, - sum(cs_net_profit - coalesce(cr_net_loss, 0)) as profit - from catalog_sales left outer join catalog_returns on - (cs_item_sk = cr_item_sk and cs_order_number = cr_order_number), - date_dim, - catalog_page, - item, - promotion - where cs_sold_date_sk = d_date_sk - and d_date between cast('1999-08-03' as date) - and dateadd(day,30,cast('1999-08-03' as date)) - and cs_catalog_page_sk = cp_catalog_page_sk - and cs_item_sk = i_item_sk - and i_current_price > 50 - and cs_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(ws_ext_sales_price) as sales, - sum(coalesce(wr_return_amt, 0)) as returns, - sum(ws_net_profit - coalesce(wr_net_loss, 0)) as profit - from web_sales left outer join web_returns on - (ws_item_sk = wr_item_sk and ws_order_number = wr_order_number), - date_dim, - web_site, - item, - promotion - where ws_sold_date_sk = d_date_sk - and d_date between cast('1999-08-03' as date) - and dateadd(day,30,cast('1999-08-03' as date)) - and ws_web_site_sk = web_site_sk - and ws_item_sk = i_item_sk - and i_current_price > 50 - and ws_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by web_site_id) -, -results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || store_id as id - , sales - , returns - , profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || catalog_page_id as id - , sales - , returns - , profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , profit - from wsr - ) x - group by channel, id) - - select channel - , id - , sales - , returns - , profit - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results - ) foo - order by channel, id - limit 100; - --- end template query80a.tpl query 19 in stream 2 --- start template query1.tpl query 20 in stream 2 -with /* TPC-DS query1.tpl 0.12 */ customer_total_return as -(select sr_customer_sk as ctr_customer_sk -,sr_store_sk as ctr_store_sk -,sum(SR_REVERSED_CHARGE) as ctr_total_return -from store_returns -,date_dim -where sr_returned_date_sk = d_date_sk -and d_year =1998 -group by sr_customer_sk -,sr_store_sk) - select c_customer_id -from customer_total_return ctr1 -,store -,customer -where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 -from customer_total_return ctr2 -where ctr1.ctr_store_sk = ctr2.ctr_store_sk) -and s_store_sk = ctr1.ctr_store_sk -and s_state = 'FL' -and ctr1.ctr_customer_sk = c_customer_sk -order by c_customer_id -limit 100; - --- end template query1.tpl query 20 in stream 2 --- start template query69.tpl query 21 in stream 2 -select /* TPC-DS query69.tpl 0.28 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_state in ('IN','VA','ID') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 3 and 3+2) and - (not exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 3 and 3+2) and - not exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 3 and 3+2)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - limit 100; - --- end template query69.tpl query 21 in stream 2 --- start template query26.tpl query 22 in stream 2 -select /* TPC-DS query26.tpl 0.85 */ i_item_id, - avg(cs_quantity) agg1, - avg(cs_list_price) agg2, - avg(cs_coupon_amt) agg3, - avg(cs_sales_price) agg4 - from catalog_sales, customer_demographics, date_dim, item, promotion - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd_demo_sk and - cs_promo_sk = p_promo_sk and - cd_gender = 'F' and - cd_marital_status = 'M' and - cd_education_status = 'Primary' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 2002 - group by i_item_id - order by i_item_id - limit 100; - --- end template query26.tpl query 22 in stream 2 --- start template query11.tpl query 23 in stream 2 -with /* TPC-DS query11.tpl 0.51 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ss_ext_list_price-ss_ext_discount_amt) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ws_ext_list_price-ws_ext_discount_amt) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_preferred_cust_flag - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 2000 - and t_s_secyear.dyear = 2000+1 - and t_w_firstyear.dyear = 2000 - and t_w_secyear.dyear = 2000+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else 0.0 end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else 0.0 end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_preferred_cust_flag -limit 100; - --- end template query11.tpl query 23 in stream 2 --- start template query17.tpl query 24 in stream 2 -select /* TPC-DS query17.tpl 0.41 */ i_item_id - ,i_item_desc - ,s_state - ,count(ss_quantity) as store_sales_quantitycount - ,avg(ss_quantity) as store_sales_quantityave - ,stddev_samp(ss_quantity) as store_sales_quantitystdev - ,stddev_samp(ss_quantity)/avg(ss_quantity) as store_sales_quantitycov - ,count(sr_return_quantity) as store_returns_quantitycount - ,avg(sr_return_quantity) as store_returns_quantityave - ,stddev_samp(sr_return_quantity) as store_returns_quantitystdev - ,stddev_samp(sr_return_quantity)/avg(sr_return_quantity) as store_returns_quantitycov - ,count(cs_quantity) as catalog_sales_quantitycount ,avg(cs_quantity) as catalog_sales_quantityave - ,stddev_samp(cs_quantity) as catalog_sales_quantitystdev - ,stddev_samp(cs_quantity)/avg(cs_quantity) as catalog_sales_quantitycov - from store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where d1.d_quarter_name = '1999Q1' - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_quarter_name in ('1999Q1','1999Q2','1999Q3') - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_quarter_name in ('1999Q1','1999Q2','1999Q3') - group by i_item_id - ,i_item_desc - ,s_state - order by i_item_id - ,i_item_desc - ,s_state -limit 100; - --- end template query17.tpl query 24 in stream 2 --- start template query63.tpl query 25 in stream 2 -select /* TPC-DS query63.tpl 0.27 */ * -from (select i_manager_id - ,sum(ss_sales_price) sum_sales - ,avg(sum(ss_sales_price)) over (partition by i_manager_id) avg_monthly_sales - from item - ,store_sales - ,date_dim - ,store - where ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and d_month_seq in (1206,1206+1,1206+2,1206+3,1206+4,1206+5,1206+6,1206+7,1206+8,1206+9,1206+10,1206+11) - and (( i_category in ('Books','Children','Electronics') - and i_class in ('personal','portable','reference','self-help') - and i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) - or( i_category in ('Women','Music','Men') - and i_class in ('accessories','classical','fragrances','pants') - and i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manager_id, d_moy) tmp1 -where case when avg_monthly_sales > 0 then abs (sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 -order by i_manager_id - ,avg_monthly_sales - ,sum_sales -limit 100; - --- end template query63.tpl query 25 in stream 2 --- start template query77a.tpl query 26 in stream 2 -with /* TPC-DS query77a.tpl 0.78 */ ss as - (select s_store_sk, - sum(ss_ext_sales_price) as sales, - sum(ss_net_profit) as profit - from store_sales, - date_dim, - store - where ss_sold_date_sk = d_date_sk - and d_date between cast('2002-08-13' as date) - and dateadd(day,30,cast('2002-08-13' as date)) - and ss_store_sk = s_store_sk - group by s_store_sk) - , - sr as - (select s_store_sk, - sum(sr_return_amt) as returns, - sum(sr_net_loss) as profit_loss - from store_returns, - date_dim, - store - where sr_returned_date_sk = d_date_sk - and d_date between cast('2002-08-13' as date) - and dateadd(day,30,cast('2002-08-13' as date)) - and sr_store_sk = s_store_sk - group by s_store_sk), - cs as - (select cs_call_center_sk, - sum(cs_ext_sales_price) as sales, - sum(cs_net_profit) as profit - from catalog_sales, - date_dim - where cs_sold_date_sk = d_date_sk - and d_date between cast('2002-08-13' as date) - and dateadd(day,30,cast('2002-08-13' as date)) - group by cs_call_center_sk - ), - cr as - (select cr_call_center_sk, - sum(cr_return_amount) as returns, - sum(cr_net_loss) as profit_loss - from catalog_returns, - date_dim - where cr_returned_date_sk = d_date_sk - and d_date between cast('2002-08-13' as date) - and dateadd(day,30,cast('2002-08-13' as date)) - group by cr_call_center_sk), - ws as - ( select wp_web_page_sk, - sum(ws_ext_sales_price) as sales, - sum(ws_net_profit) as profit - from web_sales, - date_dim, - web_page - where ws_sold_date_sk = d_date_sk - and d_date between cast('2002-08-13' as date) - and dateadd(day,30,cast('2002-08-13' as date)) - and ws_web_page_sk = wp_web_page_sk - group by wp_web_page_sk), - wr as - (select wp_web_page_sk, - sum(wr_return_amt) as returns, - sum(wr_net_loss) as profit_loss - from web_returns, - date_dim, - web_page - where wr_returned_date_sk = d_date_sk - and d_date between cast('2002-08-13' as date) - and dateadd(day,30,cast('2002-08-13' as date)) - and wr_web_page_sk = wp_web_page_sk - group by wp_web_page_sk) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , ss.s_store_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ss left join sr - on ss.s_store_sk = sr.s_store_sk - union all - select 'catalog channel' as channel - , cs_call_center_sk as id - , sales - , returns - , (profit - profit_loss) as profit - from cs - , cr - union all - select 'web channel' as channel - , ws.wp_web_page_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ws left join wr - on ws.wp_web_page_sk = wr.wp_web_page_sk - ) x - group by channel, id ) - - select * - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results -) foo -order by channel, id - limit 100; - --- end template query77a.tpl query 26 in stream 2 --- start template query19.tpl query 27 in stream 2 -select /* TPC-DS query19.tpl 0.8 */ i_brand_id brand_id, i_brand brand, i_manufact_id, i_manufact, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item,customer,customer_address,store - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=62 - and d_moy=11 - and d_year=1999 - and ss_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and substring(ca_zip,1,5) <> substring(s_zip,1,5) - and ss_store_sk = s_store_sk - group by i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact - order by ext_price desc - ,i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact -limit 100 ; - --- end template query19.tpl query 27 in stream 2 --- start template query21.tpl query 28 in stream 2 -select /* TPC-DS query21.tpl 0.14 */ * - from(select w_warehouse_name - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('1998-06-26' as date)) - then inv_quantity_on_hand - else 0 end) as inv_before - ,sum(case when (cast(d_date as date) >= cast ('1998-06-26' as date)) - then inv_quantity_on_hand - else 0 end) as inv_after - from inventory - ,warehouse - ,item - ,date_dim - where i_current_price between 0.99 and 1.49 - and i_item_sk = inv_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('1998-06-26' as date)) - and dateadd(day,30,cast ('1998-06-26' as date)) - group by w_warehouse_name, i_item_id) x - where (case when inv_before > 0 - then inv_after / inv_before - else null - end) between 2.0/3.0 and 3.0/2.0 - order by w_warehouse_name - ,i_item_id - limit 100; - --- end template query21.tpl query 28 in stream 2 --- start template query31.tpl query 29 in stream 2 -with /* TPC-DS query31.tpl 0.50 */ ss as - (select ca_county,d_qoy, d_year,sum(ss_ext_sales_price) as store_sales - from store_sales,date_dim,customer_address - where ss_sold_date_sk = d_date_sk - and ss_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year), - ws as - (select ca_county,d_qoy, d_year,sum(ws_ext_sales_price) as web_sales - from web_sales,date_dim,customer_address - where ws_sold_date_sk = d_date_sk - and ws_bill_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year) - select - ss1.ca_county - ,ss1.d_year - ,ws2.web_sales/ws1.web_sales web_q1_q2_increase - ,ss2.store_sales/ss1.store_sales store_q1_q2_increase - ,ws3.web_sales/ws2.web_sales web_q2_q3_increase - ,ss3.store_sales/ss2.store_sales store_q2_q3_increase - from - ss ss1 - ,ss ss2 - ,ss ss3 - ,ws ws1 - ,ws ws2 - ,ws ws3 - where - ss1.d_qoy = 1 - and ss1.d_year = 1998 - and ss1.ca_county = ss2.ca_county - and ss2.d_qoy = 2 - and ss2.d_year = 1998 - and ss2.ca_county = ss3.ca_county - and ss3.d_qoy = 3 - and ss3.d_year = 1998 - and ss1.ca_county = ws1.ca_county - and ws1.d_qoy = 1 - and ws1.d_year = 1998 - and ws1.ca_county = ws2.ca_county - and ws2.d_qoy = 2 - and ws2.d_year = 1998 - and ws1.ca_county = ws3.ca_county - and ws3.d_qoy = 3 - and ws3.d_year =1998 - and case when ws1.web_sales > 0 then ws2.web_sales/ws1.web_sales else null end - > case when ss1.store_sales > 0 then ss2.store_sales/ss1.store_sales else null end - and case when ws2.web_sales > 0 then ws3.web_sales/ws2.web_sales else null end - > case when ss2.store_sales > 0 then ss3.store_sales/ss2.store_sales else null end - order by web_q2_q3_increase; - --- end template query31.tpl query 29 in stream 2 --- start template query93.tpl query 30 in stream 2 -select /* TPC-DS query93.tpl 0.52 */ ss_customer_sk - ,sum(act_sales) sumsales - from (select ss_item_sk - ,ss_ticket_number - ,ss_customer_sk - ,case when sr_return_quantity is not null then (ss_quantity-sr_return_quantity)*ss_sales_price - else (ss_quantity*ss_sales_price) end act_sales - from store_sales left outer join store_returns on (sr_item_sk = ss_item_sk - and sr_ticket_number = ss_ticket_number) - ,reason - where sr_reason_sk = r_reason_sk - and r_reason_desc = 'reason 24') t - group by ss_customer_sk - order by sumsales, ss_customer_sk -limit 100; - --- end template query93.tpl query 30 in stream 2 --- start template query54.tpl query 31 in stream 2 -with /* TPC-DS query54.tpl 0.81 */ my_customers as ( - select distinct c_customer_sk - , c_current_addr_sk - from - ( select cs_sold_date_sk sold_date_sk, - cs_bill_customer_sk customer_sk, - cs_item_sk item_sk - from catalog_sales - union all - select ws_sold_date_sk sold_date_sk, - ws_bill_customer_sk customer_sk, - ws_item_sk item_sk - from web_sales - ) cs_or_ws_sales, - item, - date_dim, - customer - where sold_date_sk = d_date_sk - and item_sk = i_item_sk - and i_category = 'Children' - and i_class = 'toddlers' - and c_customer_sk = cs_or_ws_sales.customer_sk - and d_moy = 2 - and d_year = 1999 - ) - , my_revenue as ( - select c_customer_sk, - sum(ss_ext_sales_price) as revenue - from my_customers, - store_sales, - customer_address, - store, - date_dim - where c_current_addr_sk = ca_address_sk - and ca_county = s_county - and ca_state = s_state - and ss_sold_date_sk = d_date_sk - and c_customer_sk = ss_customer_sk - and d_month_seq between (select distinct d_month_seq+1 - from date_dim where d_year = 1999 and d_moy = 2) - and (select distinct d_month_seq+3 - from date_dim where d_year = 1999 and d_moy = 2) - group by c_customer_sk - ) - , segments as - (select cast((revenue/50) as bigint) as segment - from my_revenue - ) - select segment, count(*) as num_customers, segment*50 as segment_base - from segments - group by segment - order by segment, num_customers - limit 100; - --- end template query54.tpl query 31 in stream 2 --- start template query39.tpl query 32 in stream 2 -with /* TPC-DS query39.tpl 0.5 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =1998 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=4 - and inv2.d_moy=4+1 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; -with /* TPC-DS query39.tpl 0.5 part2 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =1998 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=4 - and inv2.d_moy=4+1 - and inv1.cov > 1.5 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; - --- end template query39.tpl query 32 in stream 2 --- start template query10.tpl query 33 in stream 2 -select /* TPC-DS query10.tpl 0.26 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3, - cd_dep_count, - count(*) cnt4, - cd_dep_employed_count, - count(*) cnt5, - cd_dep_college_count, - count(*) cnt6 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_county in ('Guadalupe County','Telfair County','Hayes County','Cherokee County','Orange County') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 4 and 4+3) and - (exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 4 ANd 4+3) or - exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 4 and 4+3)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count -limit 100; - --- end template query10.tpl query 33 in stream 2 --- start template query15.tpl query 34 in stream 2 -select /* TPC-DS query15.tpl 0.57 */ ca_zip - ,sum(cs_sales_price) - from catalog_sales - ,customer - ,customer_address - ,date_dim - where cs_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', - '85392', '85460', '80348', '81792') - or ca_state in ('CA','WA','GA') - or cs_sales_price > 500) - and cs_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 1999 - group by ca_zip - order by ca_zip - limit 100; - --- end template query15.tpl query 34 in stream 2 --- start template query55.tpl query 35 in stream 2 -select /* TPC-DS query55.tpl 0.82 */ i_brand_id brand_id, i_brand brand, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=35 - and d_moy=11 - and d_year=1999 - group by i_brand, i_brand_id - order by ext_price desc, i_brand_id -limit 100 ; - --- end template query55.tpl query 35 in stream 2 --- start template query14a.tpl query 36 in stream 2 -with /* TPC-DS query14a.tpl 0.69 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 2000 AND 2000 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 2000 AND 2000 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 2000 AND 2000 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as - (select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2) x) -, - results AS -(select channel, i_brand_id, i_class_id, i_category_id, sum(sales) sum_sales, sum(number_sales) number_sales - from ( - select 'store' channel, i_brand_id,i_class_id - ,i_category_id,sum(ss_quantity*ss_list_price) sales - , count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2000+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales) - union all - select 'catalog' channel, i_brand_id,i_class_id,i_category_id, sum(cs_quantity*cs_list_price) sales, count(*) number_sales - from catalog_sales - ,item - ,date_dim - where cs_item_sk in (select ss_item_sk from cross_items) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2000+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(cs_quantity*cs_list_price) > (select average_sales from avg_sales) - union all - select 'web' channel, i_brand_id,i_class_id,i_category_id, sum(ws_quantity*ws_list_price) sales , count(*) number_sales - from web_sales - ,item - ,date_dim - where ws_item_sk in (select ss_item_sk from cross_items) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2000+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ws_quantity*ws_list_price) > (select average_sales from avg_sales) - ) y - group by channel, i_brand_id,i_class_id,i_category_id) - - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales -from ( - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales from results - union - select channel, i_brand_id, i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id, i_class_id - union - select channel, i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id - union - select channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel - union - select null as channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results) z -order by channel, i_brand_id, i_class_id, i_category_id - limit 100; -with /* TPC-DS query14a.tpl 0.69 part2 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 2000 AND 2000 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 2000 AND 2000 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 2000 AND 2000 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as -(select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2) x) - select this_year.channel ty_channel - ,this_year.i_brand_id ty_brand - ,this_year.i_class_id ty_class - ,this_year.i_category_id ty_category - ,this_year.sales ty_sales - ,this_year.number_sales ty_number_sales - ,last_year.channel ly_channel - ,last_year.i_brand_id ly_brand - ,last_year.i_class_id ly_class - ,last_year.i_category_id ly_category - ,last_year.sales ly_sales - ,last_year.number_sales ly_number_sales -from - (select 'store' channel, i_brand_id,i_class_id,i_category_id - ,sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 2000 + 1 - and d_moy = 12 - and d_dom = 5) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) this_year, - (select 'store' channel, i_brand_id,i_class_id - ,i_category_id, sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 2000 - and d_moy = 12 - and d_dom = 5) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) last_year - where this_year.i_brand_id= last_year.i_brand_id - and this_year.i_class_id = last_year.i_class_id - and this_year.i_category_id = last_year.i_category_id - order by this_year.channel, this_year.i_brand_id, this_year.i_class_id, this_year.i_category_id - limit 100; - --- end template query14a.tpl query 36 in stream 2 --- start template query38.tpl query 37 in stream 2 -select /* TPC-DS query38.tpl 0.54 */ count(*) from ( - select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1212 and 1212 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1212 and 1212 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1212 and 1212 + 11 -) hot_cust -limit 100; - --- end template query38.tpl query 37 in stream 2 --- start template query42.tpl query 38 in stream 2 -select /* TPC-DS query42.tpl 0.61 */ dt.d_year - ,item.i_category_id - ,item.i_category - ,sum(ss_ext_sales_price) - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=12 - and dt.d_year=1998 - group by dt.d_year - ,item.i_category_id - ,item.i_category - order by sum(ss_ext_sales_price) desc,dt.d_year - ,item.i_category_id - ,item.i_category -limit 100 ; - --- end template query42.tpl query 38 in stream 2 --- start template query53.tpl query 39 in stream 2 -select /* TPC-DS query53.tpl 0.88 */ * from -(select i_manufact_id, -sum(ss_sales_price) sum_sales, -avg(sum(ss_sales_price)) over (partition by i_manufact_id) avg_quarterly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and -ss_sold_date_sk = d_date_sk and -ss_store_sk = s_store_sk and -d_month_seq in (1208,1208+1,1208+2,1208+3,1208+4,1208+5,1208+6,1208+7,1208+8,1208+9,1208+10,1208+11) and -((i_category in ('Books','Children','Electronics') and -i_class in ('personal','portable','reference','self-help') and -i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) -or(i_category in ('Women','Music','Men') and -i_class in ('accessories','classical','fragrances','pants') and -i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manufact_id, d_qoy ) tmp1 -where case when avg_quarterly_sales > 0 - then abs (sum_sales - avg_quarterly_sales)/ avg_quarterly_sales - else null end > 0.1 -order by avg_quarterly_sales, - sum_sales, - i_manufact_id -limit 100; - --- end template query53.tpl query 39 in stream 2 --- start template query45.tpl query 40 in stream 2 -select /* TPC-DS query45.tpl 0.18 */ ca_zip, ca_county, sum(ws_sales_price) - from web_sales, customer, customer_address, date_dim, item - where ws_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ws_item_sk = i_item_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', '85392', '85460', '80348', '81792') - or - i_item_id in (select i_item_id - from item - where i_item_sk in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29) - ) - ) - and ws_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 2001 - group by ca_zip, ca_county - order by ca_zip, ca_county - limit 100; - --- end template query45.tpl query 40 in stream 2 --- start template query99.tpl query 41 in stream 2 -select /* TPC-DS query99.tpl 0.94 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 30) and - (cs_ship_date_sk - cs_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 60) and - (cs_ship_date_sk - cs_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 90) and - (cs_ship_date_sk - cs_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - catalog_sales - ,warehouse - ,ship_mode - ,call_center - ,date_dim -where - d_month_seq between 1202 and 1202 + 11 -and cs_ship_date_sk = d_date_sk -and cs_warehouse_sk = w_warehouse_sk -and cs_ship_mode_sk = sm_ship_mode_sk -and cs_call_center_sk = cc_call_center_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -limit 100; - --- end template query99.tpl query 41 in stream 2 --- start template query67a.tpl query 42 in stream 2 -with /* TPC-DS query67a.tpl 0.35 */ results as -( select i_category ,i_class ,i_brand ,i_product_name ,d_year ,d_qoy ,d_moy ,s_store_id - ,sum(coalesce(ss_sales_price*ss_quantity,0)) sumsales - from store_sales ,date_dim ,store ,item - where ss_sold_date_sk=d_date_sk - and ss_item_sk=i_item_sk - and ss_store_sk = s_store_sk - and d_month_seq between 1213 and 1213 + 11 - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy,s_store_id) - , - results_rollup as - (select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, s_store_id, sumsales - from results - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy - union all - select i_category, i_class, i_brand, i_product_name, d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year - union all - select i_category, i_class, i_brand, i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name - union all - select i_category, i_class, i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand - union all - select i_category, i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class - union all - select i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category - union all - select null i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results) - - select * -from (select i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rank() over (partition by i_category order by sumsales desc) rk - from results_rollup) dw2 -where rk <= 100 -order by i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rk -limit 100; - --- end template query67a.tpl query 42 in stream 2 --- start template query23.tpl query 43 in stream 2 -with /* TPC-DS query23.tpl 0.68 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (1999,1999+1,1999+2,1999+3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1999,1999+1,1999+2,1999+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * -from - max_store_sales)) - select sum(sales) - from (select cs_quantity*cs_list_price sales - from catalog_sales - ,date_dim - where d_year = 1999 - and d_moy = 1 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - union all - select ws_quantity*ws_list_price sales - from web_sales - ,date_dim - where d_year = 1999 - and d_moy = 1 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer)) - limit 100; -with /* TPC-DS query23.tpl 0.68 part2 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (1999,1999 + 1,1999 + 2,1999 + 3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1999,1999+1,1999+2,1999+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * - from max_store_sales)) - select c_last_name,c_first_name,sales - from (select c_last_name,c_first_name,sum(cs_quantity*cs_list_price) sales - from catalog_sales - ,customer - ,date_dim - where d_year = 1999 - and d_moy = 1 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and cs_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name - union all - select c_last_name,c_first_name,sum(ws_quantity*ws_list_price) sales - from web_sales - ,customer - ,date_dim - where d_year = 1999 - and d_moy = 1 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and ws_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name) - order by c_last_name,c_first_name,sales - limit 100; - --- end template query23.tpl query 43 in stream 2 --- start template query62.tpl query 44 in stream 2 -select /* TPC-DS query62.tpl 0.24 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 30) and - (ws_ship_date_sk - ws_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 60) and - (ws_ship_date_sk - ws_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 90) and - (ws_ship_date_sk - ws_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - web_sales - ,warehouse - ,ship_mode - ,web_site - ,date_dim -where - d_month_seq between 1205 and 1205 + 11 -and ws_ship_date_sk = d_date_sk -and ws_warehouse_sk = w_warehouse_sk -and ws_ship_mode_sk = sm_ship_mode_sk -and ws_web_site_sk = web_site_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -limit 100; - --- end template query62.tpl query 44 in stream 2 --- start template query30.tpl query 45 in stream 2 -with /* TPC-DS query30.tpl 0.75 */ customer_total_return as - (select wr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(wr_return_amt) as ctr_total_return - from web_returns - ,date_dim - ,customer_address - where wr_returned_date_sk = d_date_sk - and d_year =1999 - and wr_returning_addr_sk = ca_address_sk - group by wr_returning_customer_sk - ,ca_state) - select c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'TN' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return -limit 100; - --- end template query30.tpl query 45 in stream 2 --- start template query86a.tpl query 46 in stream 2 -with /* TPC-DS query86a.tpl 0.11 */ results as -( select sum(ws_net_paid) as total_sum, i_category, i_class, 0 as g_category, 0 as g_class - from - web_sales - ,date_dim d1 - ,item - where - d1.d_month_seq between 1199 and 1199+11 - and d1.d_date_sk = ws_sold_date_sk - and i_item_sk = ws_item_sk - group by i_category,i_class - ) , - - results_rollup as -( select total_sum ,i_category ,i_class, g_category, g_class, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum, i_category, NULL as i_class, 0 as g_category, 1 as g_class, 1 as lochierarchy from results group by i_category - union - select sum(total_sum) as total_sum, NULL as i_category, NULL as i_class, 1 as g_category, 1 as g_class, 2 as lochierarchy from results) - select - total_sum ,i_category ,i_class, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_class = 0 then i_category end - order by total_sum desc) as rank_within_parent - from - results_rollup - order by - lochierarchy desc, - case when lochierarchy = 0 then i_category end, - rank_within_parent - limit 100; - --- end template query86a.tpl query 46 in stream 2 --- start template query82.tpl query 47 in stream 2 -select /* TPC-DS query82.tpl 0.67 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, store_sales - where i_current_price between 61 and 61+30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('2000-05-06' as date) and dateadd(day,60,cast('2000-05-06' as date)) - and i_manufact_id in (718,269,922,559) - and inv_quantity_on_hand between 100 and 500 - and ss_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query82.tpl query 47 in stream 2 --- start template query25.tpl query 48 in stream 2 -select /* TPC-DS query25.tpl 0.9 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,avg(ss_net_profit) as store_sales_profit - ,avg(sr_net_loss) as store_returns_loss - ,avg(cs_net_profit) as catalog_sales_profit - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 2002 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 10 - and d2.d_year = 2002 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_moy between 4 and 10 - and d3.d_year = 2002 - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query25.tpl query 48 in stream 2 --- start template query16.tpl query 49 in stream 2 -select /* TPC-DS query16.tpl 0.25 */ - count(distinct cs_order_number) as "order count" - ,sum(cs_ext_ship_cost) as "total shipping cost" - ,sum(cs_net_profit) as "total net profit" -from - catalog_sales cs1 - ,date_dim - ,customer_address - ,call_center -where - d_date between '2001-2-01' and - dateadd(day, 60, cast('2001-2-01' as date)) -and cs1.cs_ship_date_sk = d_date_sk -and cs1.cs_ship_addr_sk = ca_address_sk -and ca_state = 'MO' -and cs1.cs_call_center_sk = cc_call_center_sk -and cc_county in ('Oglethorpe County','Huron County','Wadena County','Fairfield County', - 'Williamson County' -) -and exists (select * - from catalog_sales cs2 - where cs1.cs_order_number = cs2.cs_order_number - and cs1.cs_warehouse_sk <> cs2.cs_warehouse_sk) -and not exists(select * - from catalog_returns cr1 - where cs1.cs_order_number = cr1.cr_order_number) -order by count(distinct cs_order_number) -limit 100; - --- end template query16.tpl query 49 in stream 2 --- start template query81.tpl query 50 in stream 2 -with /* TPC-DS query81.tpl 0.37 */ customer_total_return as - (select cr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(cr_return_amt_inc_tax) as ctr_total_return - from catalog_returns - ,date_dim - ,customer_address - where cr_returned_date_sk = d_date_sk - and d_year =1999 - and cr_returning_addr_sk = ca_address_sk - group by cr_returning_customer_sk - ,ca_state ) - select c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'MT' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - limit 100; - --- end template query81.tpl query 50 in stream 2 --- start template query40.tpl query 51 in stream 2 -select /* TPC-DS query40.tpl 0.86 */ - w_state - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('2001-04-23' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_before - ,sum(case when (cast(d_date as date) >= cast ('2001-04-23' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_after - from - catalog_sales left outer join catalog_returns on - (cs_order_number = cr_order_number - and cs_item_sk = cr_item_sk) - ,warehouse - ,item - ,date_dim - where - i_current_price between 0.99 and 1.49 - and i_item_sk = cs_item_sk - and cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('2001-04-23' as date)) - and dateadd(day,30,cast ('2001-04-23' as date)) - group by - w_state,i_item_id - order by w_state,i_item_id -limit 100; - --- end template query40.tpl query 51 in stream 2 --- start template query44.tpl query 52 in stream 2 -select /* TPC-DS query44.tpl 0.4 */ asceding.rnk, i1.i_product_name best_performing, i2.i_product_name worst_performing -from(select * - from (select item_sk,rank() over (order by rank_col asc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 112 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 112 - and ss_customer_sk is null - group by ss_store_sk))V1)V11 - where rnk < 11) asceding, - (select * - from (select item_sk,rank() over (order by rank_col desc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 112 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 112 - and ss_customer_sk is null - group by ss_store_sk))V2)V21 - where rnk < 11) descending, -item i1, -item i2 -where asceding.rnk = descending.rnk - and i1.i_item_sk=asceding.item_sk - and i2.i_item_sk=descending.item_sk -order by asceding.rnk -limit 100; - --- end template query44.tpl query 52 in stream 2 --- start template query50.tpl query 53 in stream 2 -select /* TPC-DS query50.tpl 0.60 */ - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 30) and - (sr_returned_date_sk - ss_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 60) and - (sr_returned_date_sk - ss_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 90) and - (sr_returned_date_sk - ss_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - store_sales - ,store_returns - ,store - ,date_dim d1 - ,date_dim d2 -where - d2.d_year = 2002 -and d2.d_moy = 9 -and ss_ticket_number = sr_ticket_number -and ss_item_sk = sr_item_sk -and ss_sold_date_sk = d1.d_date_sk -and sr_returned_date_sk = d2.d_date_sk -and ss_customer_sk = sr_customer_sk -and ss_store_sk = s_store_sk -group by - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -order by s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -limit 100; - --- end template query50.tpl query 53 in stream 2 --- start template query61.tpl query 54 in stream 2 -select /* TPC-DS query61.tpl 0.97 */ promotions,total,cast(promotions as decimal(15,4))/cast(total as decimal(15,4))*100 -from - (select sum(ss_ext_sales_price) promotions - from store_sales - ,store - ,promotion - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_promo_sk = p_promo_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -7 - and i_category = 'Electronics' - and (p_channel_dmail = 'Y' or p_channel_email = 'Y' or p_channel_tv = 'Y') - and s_gmt_offset = -7 - and d_year = 2001 - and d_moy = 11) promotional_sales, - (select sum(ss_ext_sales_price) total - from store_sales - ,store - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -7 - and i_category = 'Electronics' - and s_gmt_offset = -7 - and d_year = 2001 - and d_moy = 11) all_sales -order by promotions, total -limit 100; - --- end template query61.tpl query 54 in stream 2 --- start template query85.tpl query 55 in stream 2 -select /* TPC-DS query85.tpl 0.33 */ substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) - from web_sales, web_returns, web_page, customer_demographics cd1, - customer_demographics cd2, customer_address, date_dim, reason - where ws_web_page_sk = wp_web_page_sk - and ws_item_sk = wr_item_sk - and ws_order_number = wr_order_number - and ws_sold_date_sk = d_date_sk and d_year = 1999 - and cd1.cd_demo_sk = wr_refunded_cdemo_sk - and cd2.cd_demo_sk = wr_returning_cdemo_sk - and ca_address_sk = wr_refunded_addr_sk - and r_reason_sk = wr_reason_sk - and - ( - ( - cd1.cd_marital_status = 'M' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'College' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 100.00 and 150.00 - ) - or - ( - cd1.cd_marital_status = 'D' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = '2 yr Degree' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 50.00 and 100.00 - ) - or - ( - cd1.cd_marital_status = 'U' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Primary' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ca_country = 'United States' - and - ca_state in ('WA', 'LA', 'CA') - and ws_net_profit between 100 and 200 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('NY', 'IN', 'IA') - and ws_net_profit between 150 and 300 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('NC', 'GA', 'ID') - and ws_net_profit between 50 and 250 - ) - ) -group by r_reason_desc -order by substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) -limit 100; - --- end template query85.tpl query 55 in stream 2 --- start template query73.tpl query 56 in stream 2 -select /* TPC-DS query73.tpl 0.79 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_buy_potential = '501-1000' or - household_demographics.hd_buy_potential = '0-500') - and household_demographics.hd_vehicle_count > 0 - and case when household_demographics.hd_vehicle_count > 0 then - household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count else null end > 1 - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_county in ('Levy County','Daviess County','Gage County','Walker County') - group by ss_ticket_number,ss_customer_sk) dj,customer - where ss_customer_sk = c_customer_sk - and cnt between 1 and 5 - order by cnt desc, c_last_name asc; - --- end template query73.tpl query 56 in stream 2 --- start template query95.tpl query 57 in stream 2 -with /* TPC-DS query95.tpl 0.43 */ ws_wh as -(select ws1.ws_order_number,ws1.ws_warehouse_sk wh1,ws2.ws_warehouse_sk wh2 - from web_sales ws1,web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) - select - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2000-5-01' and - dateadd(day,60,cast('2000-5-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'MO' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and ws1.ws_order_number in (select ws_order_number - from ws_wh) -and ws1.ws_order_number in (select wr_order_number - from web_returns,ws_wh - where wr_order_number = ws_wh.ws_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query95.tpl query 57 in stream 2 --- start template query84.tpl query 58 in stream 2 -select /* TPC-DS query84.tpl 0.80 */ c_customer_id as customer_id - , coalesce(c_last_name,'') || ', ' || coalesce(c_first_name,'') as customername - from customer - ,customer_address - ,customer_demographics - ,household_demographics - ,income_band - ,store_returns - where ca_city = 'Waterloo' - and c_current_addr_sk = ca_address_sk - and ib_lower_bound >= 42575 - and ib_upper_bound <= 42575 + 50000 - and ib_income_band_sk = hd_income_band_sk - and cd_demo_sk = c_current_cdemo_sk - and hd_demo_sk = c_current_hdemo_sk - and sr_cdemo_sk = cd_demo_sk - order by c_customer_id - limit 100; - --- end template query84.tpl query 58 in stream 2 --- start template query4.tpl query 59 in stream 2 -with /* TPC-DS query4.tpl 0.93 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(((ss_ext_list_price-ss_ext_wholesale_cost-ss_ext_discount_amt)+ss_ext_sales_price)/2) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((cs_ext_list_price-cs_ext_wholesale_cost-cs_ext_discount_amt)+cs_ext_sales_price)/2) ) year_total - ,'c' sale_type - from customer - ,catalog_sales - ,date_dim - where c_customer_sk = cs_bill_customer_sk - and cs_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year -union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((ws_ext_list_price-ws_ext_wholesale_cost-ws_ext_discount_amt)+ws_ext_sales_price)/2) ) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_birth_country - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_c_firstyear - ,year_total t_c_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_c_secyear.customer_id - and t_s_firstyear.customer_id = t_c_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_c_firstyear.sale_type = 'c' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_c_secyear.sale_type = 'c' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 1998 - and t_s_secyear.dyear = 1998+1 - and t_c_firstyear.dyear = 1998 - and t_c_secyear.dyear = 1998+1 - and t_w_firstyear.dyear = 1998 - and t_w_secyear.dyear = 1998+1 - and t_s_firstyear.year_total > 0 - and t_c_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_birth_country -limit 100; - --- end template query4.tpl query 59 in stream 2 --- start template query37.tpl query 60 in stream 2 -select /* TPC-DS query37.tpl 0.31 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, catalog_sales - where i_current_price between 15 and 15 + 30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('1999-03-26' as date) and dateadd(day,60,cast('1999-03-26' as date)) - and i_manufact_id in (688,697,943,712) - and inv_quantity_on_hand between 100 and 500 - and cs_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query37.tpl query 60 in stream 2 --- start template query35a.tpl query 61 in stream 2 -select /* TPC-DS query35a.tpl 0.47 */ - ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - count(*) cnt1, - avg(cd_dep_count), - min(cd_dep_count), - min(cd_dep_count), - cd_dep_employed_count, - count(*) cnt2, - avg(cd_dep_employed_count), - min(cd_dep_employed_count), - min(cd_dep_employed_count), - cd_dep_college_count, - count(*) cnt3, - avg(cd_dep_college_count), - min(cd_dep_college_count), - min(cd_dep_college_count) - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2001 and - d_qoy < 4) and - exists (select * from - (select ws_bill_customer_sk customsk - from web_sales,date_dim - where - ws_sold_date_sk = d_date_sk and - d_year = 2001 and - d_qoy < 4 - union all - select cs_ship_customer_sk customsk - from catalog_sales,date_dim - where - cs_sold_date_sk = d_date_sk and - d_year = 2001 and - d_qoy < 4)x - where x.customsk = c.c_customer_sk) - group by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - limit 100; - --- end template query35a.tpl query 61 in stream 2 --- start template query94.tpl query 62 in stream 2 -select /* TPC-DS query94.tpl 0.17 */ - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2000-2-01' and - dateadd(day,60,cast('2000-2-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'SD' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and exists (select * - from web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) -and not exists(select * - from web_returns wr1 - where ws1.ws_order_number = wr1.wr_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query94.tpl query 62 in stream 2 --- start template query58.tpl query 63 in stream 2 -with /* TPC-DS query58.tpl 0.19 */ ss_items as - (select i_item_id item_id - ,sum(ss_ext_sales_price) ss_item_rev - from store_sales - ,item - ,date_dim - where ss_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '2002-07-18')) - and ss_sold_date_sk = d_date_sk - group by i_item_id), - cs_items as - (select i_item_id item_id - ,sum(cs_ext_sales_price) cs_item_rev - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '2002-07-18')) - and cs_sold_date_sk = d_date_sk - group by i_item_id), - ws_items as - (select i_item_id item_id - ,sum(ws_ext_sales_price) ws_item_rev - from web_sales - ,item - ,date_dim - where ws_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq =(select d_week_seq - from date_dim - where d_date = '2002-07-18')) - and ws_sold_date_sk = d_date_sk - group by i_item_id) - select ss_items.item_id - ,ss_item_rev - ,ss_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ss_dev - ,cs_item_rev - ,cs_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 cs_dev - ,ws_item_rev - ,ws_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ws_dev - ,(ss_item_rev+cs_item_rev+ws_item_rev)/3 average - from ss_items,cs_items,ws_items - where ss_items.item_id=cs_items.item_id - and ss_items.item_id=ws_items.item_id - and ss_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - and ss_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and cs_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and cs_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and ws_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and ws_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - order by item_id - ,ss_item_rev - limit 100; - --- end template query58.tpl query 63 in stream 2 --- start template query96.tpl query 64 in stream 2 -select /* TPC-DS query96.tpl 0.1 */ count(*) -from store_sales - ,household_demographics - ,time_dim, store -where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 16 - and time_dim.t_minute >= 30 - and household_demographics.hd_dep_count = 6 - and store.s_store_name = 'ese' -order by count(*) -limit 100; - --- end template query96.tpl query 64 in stream 2 --- start template query12.tpl query 65 in stream 2 -select /* TPC-DS query12.tpl 0.64 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ws_ext_sales_price) as itemrevenue - ,sum(ws_ext_sales_price)*100/sum(sum(ws_ext_sales_price)) over - (partition by i_class) as revenueratio -from - web_sales - ,item - ,date_dim -where - ws_item_sk = i_item_sk - and i_category in ('Home', 'Jewelry', 'Children') - and ws_sold_date_sk = d_date_sk - and d_date between cast('2002-01-07' as date) - and dateadd(day,30,cast('2002-01-07' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query12.tpl query 65 in stream 2 --- start template query29.tpl query 66 in stream 2 -select /* TPC-DS query29.tpl 0.53 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,avg(ss_quantity) as store_sales_quantity - ,avg(sr_return_quantity) as store_returns_quantity - ,avg(cs_quantity) as catalog_sales_quantity - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 2000 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 4 + 3 - and d2.d_year = 2000 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_year in (2000,2000+1,2000+2) - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query29.tpl query 66 in stream 2 --- start template query22a.tpl query 67 in stream 2 -with /* TPC-DS query22a.tpl 0.55 */ results as -(select i_product_name - ,i_brand - ,i_class - ,i_category - ,avg(inv_quantity_on_hand) qoh - from inventory - ,date_dim - ,item --- ,warehouse - where inv_date_sk=d_date_sk - and inv_item_sk=i_item_sk --- and inv_warehouse_sk = w_warehouse_sk - and d_month_seq between 1219 and 1219 + 11 - group by i_product_name,i_brand,i_class,i_category), -results_rollup as -(select i_product_name, i_brand, i_class, i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class,i_category -union all -select i_product_name, i_brand, i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class -union all -select i_product_name, i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand -union all -select i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name -union all -select null i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results) - select i_product_name, i_brand, i_class, i_category,qoh - from results_rollup - order by qoh, i_product_name, i_brand, i_class, i_category -limit 100; - --- end template query22a.tpl query 67 in stream 2 --- start template query51.tpl query 68 in stream 2 -WITH /* TPC-DS query51.tpl 0.46 */ web_v1 as ( -select - ws_item_sk item_sk, d_date, - sum(sum(ws_sales_price)) - over (partition by ws_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from web_sales - ,date_dim -where ws_sold_date_sk=d_date_sk - and d_month_seq between 1180 and 1180+11 - and ws_item_sk is not NULL -group by ws_item_sk, d_date), -store_v1 as ( -select - ss_item_sk item_sk, d_date, - sum(sum(ss_sales_price)) - over (partition by ss_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from store_sales - ,date_dim -where ss_sold_date_sk=d_date_sk - and d_month_seq between 1180 and 1180+11 - and ss_item_sk is not NULL -group by ss_item_sk, d_date) - select * -from (select item_sk - ,d_date - ,web_sales - ,store_sales - ,max(web_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) web_cumulative - ,max(store_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) store_cumulative - from (select case when web.item_sk is not null then web.item_sk else store.item_sk end item_sk - ,case when web.d_date is not null then web.d_date else store.d_date end d_date - ,web.cume_sales web_sales - ,store.cume_sales store_sales - from web_v1 web full outer join store_v1 store on (web.item_sk = store.item_sk - and web.d_date = store.d_date) - )x )y -where web_cumulative > store_cumulative -order by item_sk - ,d_date -limit 100; - --- end template query51.tpl query 68 in stream 2 --- start template query36a.tpl query 69 in stream 2 -with /* TPC-DS query36a.tpl 0.21 */ results as - (select - sum(ss_net_profit) as ss_net_profit, sum(ss_ext_sales_price) as ss_ext_sales_price, - sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin - ,i_category - ,i_class - ,0 as g_category, 0 as g_class - from - store_sales - ,date_dim d1 - ,item - ,store - where - d1.d_year = 1998 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and s_state in ('MI','NM','MN','TN', - 'MO','MI','AL','GA') - group by i_category,i_class) - , - results_rollup as - (select gross_margin ,i_category ,i_class,0 as t_category, 0 as t_class, 0 as lochierarchy from results - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - i_category, NULL AS i_class, 0 as t_category, 1 as t_class, 1 as lochierarchy from results group by i_category - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - NULL AS i_category ,NULL AS i_class, 1 as t_category, 1 as t_class, 2 as lochierarchy from results) - select - gross_margin ,i_category ,i_class, lochierarchy,rank() over ( - partition by lochierarchy, case when t_class = 0 then i_category end - order by gross_margin asc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then i_category end - ,rank_within_parent - limit 100; - --- end template query36a.tpl query 69 in stream 2 --- start template query43.tpl query 70 in stream 2 -select /* TPC-DS query43.tpl 0.15 */ s_store_name, s_store_id, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from date_dim, store_sales, store - where d_date_sk = ss_sold_date_sk and - s_store_sk = ss_store_sk and - s_gmt_offset = -5 and - d_year = 2001 - group by s_store_name, s_store_id - order by s_store_name, s_store_id,sun_sales,mon_sales,tue_sales,wed_sales,thu_sales,fri_sales,sat_sales - limit 100; - --- end template query43.tpl query 70 in stream 2 --- start template query64.tpl query 71 in stream 2 -with /* TPC-DS query64.tpl 0.20 */ cs_ui as - (select cs_item_sk - ,sum(cs_ext_list_price) as sale,sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit) as refund - from catalog_sales - ,catalog_returns - where cs_item_sk = cr_item_sk - and cs_order_number = cr_order_number - group by cs_item_sk - having sum(cs_ext_list_price)>2*sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit)), -cross_sales as - (select i_product_name product_name - ,i_item_sk item_sk - ,s_store_name store_name - ,s_zip store_zip - ,ad1.ca_street_number b_street_number - ,ad1.ca_street_name b_street_name - ,ad1.ca_city b_city - ,ad1.ca_zip b_zip - ,ad2.ca_street_number c_street_number - ,ad2.ca_street_name c_street_name - ,ad2.ca_city c_city - ,ad2.ca_zip c_zip - ,d1.d_year as syear - ,d2.d_year as fsyear - ,d3.d_year s2year - ,count(*) cnt - ,sum(ss_wholesale_cost) s1 - ,sum(ss_list_price) s2 - ,sum(ss_coupon_amt) s3 - FROM store_sales - ,store_returns - ,cs_ui - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,customer - ,customer_demographics cd1 - ,customer_demographics cd2 - ,promotion - ,household_demographics hd1 - ,household_demographics hd2 - ,customer_address ad1 - ,customer_address ad2 - ,income_band ib1 - ,income_band ib2 - ,item - WHERE ss_store_sk = s_store_sk AND - ss_sold_date_sk = d1.d_date_sk AND - ss_customer_sk = c_customer_sk AND - ss_cdemo_sk= cd1.cd_demo_sk AND - ss_hdemo_sk = hd1.hd_demo_sk AND - ss_addr_sk = ad1.ca_address_sk and - ss_item_sk = i_item_sk and - ss_item_sk = sr_item_sk and - ss_ticket_number = sr_ticket_number and - ss_item_sk = cs_ui.cs_item_sk and - c_current_cdemo_sk = cd2.cd_demo_sk AND - c_current_hdemo_sk = hd2.hd_demo_sk AND - c_current_addr_sk = ad2.ca_address_sk and - c_first_sales_date_sk = d2.d_date_sk and - c_first_shipto_date_sk = d3.d_date_sk and - ss_promo_sk = p_promo_sk and - hd1.hd_income_band_sk = ib1.ib_income_band_sk and - hd2.hd_income_band_sk = ib2.ib_income_band_sk and - cd1.cd_marital_status <> cd2.cd_marital_status and - i_color in ('almond','burnished','medium','burlywood','salmon','sandy') and - i_current_price between 74 and 74 + 10 and - i_current_price between 74 + 1 and 74 + 15 -group by i_product_name - ,i_item_sk - ,s_store_name - ,s_zip - ,ad1.ca_street_number - ,ad1.ca_street_name - ,ad1.ca_city - ,ad1.ca_zip - ,ad2.ca_street_number - ,ad2.ca_street_name - ,ad2.ca_city - ,ad2.ca_zip - ,d1.d_year - ,d2.d_year - ,d3.d_year -) -select cs1.product_name - ,cs1.store_name - ,cs1.store_zip - ,cs1.b_street_number - ,cs1.b_street_name - ,cs1.b_city - ,cs1.b_zip - ,cs1.c_street_number - ,cs1.c_street_name - ,cs1.c_city - ,cs1.c_zip - ,cs1.syear - ,cs1.cnt - ,cs1.s1 as s11 - ,cs1.s2 as s21 - ,cs1.s3 as s31 - ,cs2.s1 as s12 - ,cs2.s2 as s22 - ,cs2.s3 as s32 - ,cs2.syear - ,cs2.cnt -from cross_sales cs1,cross_sales cs2 -where cs1.item_sk=cs2.item_sk and - cs1.syear = 2001 and - cs2.syear = 2001 + 1 and - cs2.cnt <= cs1.cnt and - cs1.store_name = cs2.store_name and - cs1.store_zip = cs2.store_zip -order by cs1.product_name - ,cs1.store_name - ,cs2.cnt - ,cs1.s1 - ,cs2.s1; - --- end template query64.tpl query 71 in stream 2 --- start template query20.tpl query 72 in stream 2 -select /* TPC-DS query20.tpl 0.65 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(cs_ext_sales_price) as itemrevenue - ,sum(cs_ext_sales_price)*100/sum(sum(cs_ext_sales_price)) over - (partition by i_class) as revenueratio - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and i_category in ('Children', 'Jewelry', 'Sports') - and cs_sold_date_sk = d_date_sk - and d_date between cast('1999-06-18' as date) - and dateadd(day,30,cast('1999-06-18' as date)) - group by i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - order by i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query20.tpl query 72 in stream 2 --- start template query57.tpl query 73 in stream 2 -with /* TPC-DS query57.tpl 0.70 */ v1 as( - select i_category, i_brand, - cc_name, - d_year, d_moy, - sum(cs_sales_price) sum_sales, - avg(sum(cs_sales_price)) over - (partition by i_category, i_brand, - cc_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - cc_name - order by d_year, d_moy) rn - from item, catalog_sales, date_dim, call_center - where cs_item_sk = i_item_sk and - cs_sold_date_sk = d_date_sk and - cc_call_center_sk= cs_call_center_sk and - ( - d_year = 1999 or - ( d_year = 1999-1 and d_moy =12) or - ( d_year = 1999+1 and d_moy =1) - ) - group by i_category, i_brand, - cc_name , d_year, d_moy), - v2 as( - select v1.cc_name - ,v1.d_year, v1.d_moy - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1. cc_name = v1_lag. cc_name and - v1. cc_name = v1_lead. cc_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 1999 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, nsum - limit 100; - --- end template query57.tpl query 73 in stream 2 --- start template query9.tpl query 74 in stream 2 -select /* TPC-DS query9.tpl 0.49 */ case when (select count(*) - from store_sales - where ss_quantity between 1 and 20) > 1897925 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 1 and 20) - else (select avg(ss_net_profit) - from store_sales - where ss_quantity between 1 and 20) end bucket1 , - case when (select count(*) - from store_sales - where ss_quantity between 21 and 40) > 7384454 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 21 and 40) - else (select avg(ss_net_profit) - from store_sales - where ss_quantity between 21 and 40) end bucket2, - case when (select count(*) - from store_sales - where ss_quantity between 41 and 60) > 5309215 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 41 and 60) - else (select avg(ss_net_profit) - from store_sales - where ss_quantity between 41 and 60) end bucket3, - case when (select count(*) - from store_sales - where ss_quantity between 61 and 80) > 14717020 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 61 and 80) - else (select avg(ss_net_profit) - from store_sales - where ss_quantity between 61 and 80) end bucket4, - case when (select count(*) - from store_sales - where ss_quantity between 81 and 100) > 18063548 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 81 and 100) - else (select avg(ss_net_profit) - from store_sales - where ss_quantity between 81 and 100) end bucket5 -from reason -where r_reason_sk = 1 -; - --- end template query9.tpl query 74 in stream 2 --- start template query52.tpl query 75 in stream 2 -select /* TPC-DS query52.tpl 0.59 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_sales_price) ext_price - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=12 - and dt.d_year=2000 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,ext_price desc - ,brand_id -limit 100 ; - --- end template query52.tpl query 75 in stream 2 --- start template query49.tpl query 76 in stream 2 -select /* TPC-DS query49.tpl 0.48 */ channel, item, return_ratio, return_rank, currency_rank from - (select - 'web' as channel - ,web.item - ,web.return_ratio - ,web.return_rank - ,web.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select ws.ws_item_sk as item - ,(cast(sum(coalesce(wr.wr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(wr.wr_return_amt,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - web_sales ws left outer join web_returns wr - on (ws.ws_order_number = wr.wr_order_number and - ws.ws_item_sk = wr.wr_item_sk) - ,date_dim - where - wr.wr_return_amt > 10000 - and ws.ws_net_profit > 1 - and ws.ws_net_paid > 0 - and ws.ws_quantity > 0 - and ws_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 11 - group by ws.ws_item_sk - ) in_web - ) web - where - ( - web.return_rank <= 10 - or - web.currency_rank <= 10 - ) - union - select - 'catalog' as channel - ,catalog.item - ,catalog.return_ratio - ,catalog.return_rank - ,catalog.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select - cs.cs_item_sk as item - ,(cast(sum(coalesce(cr.cr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(cr.cr_return_amount,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - catalog_sales cs left outer join catalog_returns cr - on (cs.cs_order_number = cr.cr_order_number and - cs.cs_item_sk = cr.cr_item_sk) - ,date_dim - where - cr.cr_return_amount > 10000 - and cs.cs_net_profit > 1 - and cs.cs_net_paid > 0 - and cs.cs_quantity > 0 - and cs_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 11 - group by cs.cs_item_sk - ) in_cat - ) catalog - where - ( - catalog.return_rank <= 10 - or - catalog.currency_rank <=10 - ) - union - select - 'store' as channel - ,store.item - ,store.return_ratio - ,store.return_rank - ,store.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select sts.ss_item_sk as item - ,(cast(sum(coalesce(sr.sr_return_quantity,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(sr.sr_return_amt,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - store_sales sts left outer join store_returns sr - on (sts.ss_ticket_number = sr.sr_ticket_number and sts.ss_item_sk = sr.sr_item_sk) - ,date_dim - where - sr.sr_return_amt > 10000 - and sts.ss_net_profit > 1 - and sts.ss_net_paid > 0 - and sts.ss_quantity > 0 - and ss_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 11 - group by sts.ss_item_sk - ) in_store - ) store - where ( - store.return_rank <= 10 - or - store.currency_rank <= 10 - ) - ) - order by 1,4,5,2 - limit 100; - --- end template query49.tpl query 76 in stream 2 --- start template query71.tpl query 77 in stream 2 -select /* TPC-DS query71.tpl 0.72 */ i_brand_id brand_id, i_brand brand,t_hour,t_minute, - sum(ext_price) ext_price - from item, (select ws_ext_sales_price as ext_price, - ws_sold_date_sk as sold_date_sk, - ws_item_sk as sold_item_sk, - ws_sold_time_sk as time_sk - from web_sales,date_dim - where d_date_sk = ws_sold_date_sk - and d_moy=11 - and d_year=2001 - union all - select cs_ext_sales_price as ext_price, - cs_sold_date_sk as sold_date_sk, - cs_item_sk as sold_item_sk, - cs_sold_time_sk as time_sk - from catalog_sales,date_dim - where d_date_sk = cs_sold_date_sk - and d_moy=11 - and d_year=2001 - union all - select ss_ext_sales_price as ext_price, - ss_sold_date_sk as sold_date_sk, - ss_item_sk as sold_item_sk, - ss_sold_time_sk as time_sk - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - and d_moy=11 - and d_year=2001 - ) tmp,time_dim - where - sold_item_sk = i_item_sk - and i_manager_id=1 - and time_sk = t_time_sk - and (t_meal_time = 'breakfast' or t_meal_time = 'dinner') - group by i_brand, i_brand_id,t_hour,t_minute - order by ext_price desc, i_brand_id - ; - --- end template query71.tpl query 77 in stream 2 --- start template query72.tpl query 78 in stream 2 -select /* TPC-DS query72.tpl 0.87 */ i_item_desc - ,w_warehouse_name - ,d1.d_week_seq - ,sum(case when p_promo_sk is null then 1 else 0 end) no_promo - ,sum(case when p_promo_sk is not null then 1 else 0 end) promo - ,count(*) total_cnt -from catalog_sales -join inventory on (cs_item_sk = inv_item_sk) -join warehouse on (w_warehouse_sk=inv_warehouse_sk) -join item on (i_item_sk = cs_item_sk) -join customer_demographics on (cs_bill_cdemo_sk = cd_demo_sk) -join household_demographics on (cs_bill_hdemo_sk = hd_demo_sk) -join date_dim d1 on (cs_sold_date_sk = d1.d_date_sk) -join date_dim d2 on (inv_date_sk = d2.d_date_sk) -join date_dim d3 on (cs_ship_date_sk = d3.d_date_sk) -left outer join promotion on (cs_promo_sk=p_promo_sk) -left outer join catalog_returns on (cr_item_sk = cs_item_sk and cr_order_number = cs_order_number) -where d1.d_week_seq = d2.d_week_seq - and inv_quantity_on_hand < cs_quantity - and d3.d_date > d1.d_date + 5 - and hd_buy_potential = '>10000' - and d1.d_year = 2001 - and cd_marital_status = 'S' -group by i_item_desc,w_warehouse_name,d1.d_week_seq -order by total_cnt desc, i_item_desc, w_warehouse_name, d_week_seq -limit 100; - --- end template query72.tpl query 78 in stream 2 --- start template query70a.tpl query 79 in stream 2 -with /* TPC-DS query70a.tpl 0.34 */ results as -( select - sum(ss_net_profit) as total_sum ,s_state ,s_county, 0 as gstate, 0 as g_county - from - store_sales - ,date_dim d1 - ,store - where - d1.d_month_seq between 1216 and 1216 + 11 - and d1.d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - and s_state in - ( select s_state - from (select s_state as s_state, - rank() over ( partition by s_state order by sum(ss_net_profit) desc) as ranking - from store_sales, store, date_dim - where d_month_seq between 1216 and 1216 + 11 - and d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - group by s_state - ) tmp1 - where ranking <= 5) - group by s_state,s_county) , - results_rollup as -(select total_sum ,s_state ,s_county, 0 as g_state, 0 as g_county, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum,s_state, NULL as s_county, 0 as g_state, 1 as g_county, 1 as lochierarchy from results group by s_state - union - select sum(total_sum) as total_sum ,NULL as s_state ,NULL as s_county, 1 as g_state, 1 as g_county, 2 as lochierarchy from results) - select total_sum ,s_state ,s_county, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_county = 0 then s_state end - order by total_sum desc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then s_state end - ,rank_within_parent - limit 100; - --- end template query70a.tpl query 79 in stream 2 --- start template query7.tpl query 80 in stream 2 -select /* TPC-DS query7.tpl 0.2 */ i_item_id, - avg(ss_quantity) agg1, - avg(ss_list_price) agg2, - avg(ss_coupon_amt) agg3, - avg(ss_sales_price) agg4 - from store_sales, customer_demographics, date_dim, item, promotion - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_cdemo_sk = cd_demo_sk and - ss_promo_sk = p_promo_sk and - cd_gender = 'F' and - cd_marital_status = 'W' and - cd_education_status = '2 yr Degree' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 1998 - group by i_item_id - order by i_item_id - limit 100; - --- end template query7.tpl query 80 in stream 2 --- start template query97.tpl query 81 in stream 2 -with /* TPC-DS query97.tpl 0.38 */ ssci as ( -select ss_customer_sk customer_sk - ,ss_item_sk item_sk -from store_sales,date_dim -where ss_sold_date_sk = d_date_sk - and d_month_seq between 1178 and 1178 + 11 -group by ss_customer_sk - ,ss_item_sk), -csci as( - select cs_bill_customer_sk customer_sk - ,cs_item_sk item_sk -from catalog_sales,date_dim -where cs_sold_date_sk = d_date_sk - and d_month_seq between 1178 and 1178 + 11 -group by cs_bill_customer_sk - ,cs_item_sk) - select sum(case when ssci.customer_sk is not null and csci.customer_sk is null then 1 else 0 end) store_only - ,sum(case when ssci.customer_sk is null and csci.customer_sk is not null then 1 else 0 end) catalog_only - ,sum(case when ssci.customer_sk is not null and csci.customer_sk is not null then 1 else 0 end) store_and_catalog -from ssci full outer join csci on (ssci.customer_sk=csci.customer_sk - and ssci.item_sk = csci.item_sk) -limit 100; - --- end template query97.tpl query 81 in stream 2 --- start template query33.tpl query 82 in stream 2 -with /* TPC-DS query33.tpl 0.22 */ ss as ( - select - i_manufact_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Home')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 3 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_manufact_id), - cs as ( - select - i_manufact_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Home')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 3 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_manufact_id), - ws as ( - select - i_manufact_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Home')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 3 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_manufact_id) - select i_manufact_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_manufact_id - order by total_sales -limit 100; - --- end template query33.tpl query 82 in stream 2 --- start template query79.tpl query 83 in stream 2 -select /* TPC-DS query79.tpl 0.89 */ - c_last_name,c_first_name,substring(s_city,1,30),ss_ticket_number,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,store.s_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (household_demographics.hd_dep_count = 0 or household_demographics.hd_vehicle_count > 3) - and date_dim.d_dow = 1 - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_number_employees between 200 and 295 - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,store.s_city) ms,customer - where ss_customer_sk = c_customer_sk - order by c_last_name,c_first_name,substring(s_city,1,30), profit -limit 100; - --- end template query79.tpl query 83 in stream 2 --- start template query32.tpl query 84 in stream 2 -select /* TPC-DS query32.tpl 0.7 */ sum(cs_ext_discount_amt) as "excess discount amount" -from - catalog_sales - ,item - ,date_dim -where -i_manufact_id = 4 -and i_item_sk = cs_item_sk -and d_date between '2001-03-17' and - dateadd(day,90,cast('2001-03-17' as date)) -and d_date_sk = cs_sold_date_sk -and cs_ext_discount_amt - > ( - select - 1.3 * avg(cs_ext_discount_amt) - from - catalog_sales - ,date_dim - where - cs_item_sk = i_item_sk - and d_date between '2001-03-17' and - dateadd(day,90,cast('2001-03-17' as date)) - and d_date_sk = cs_sold_date_sk - ) -limit 100; - --- end template query32.tpl query 84 in stream 2 --- start template query78.tpl query 85 in stream 2 -with /* TPC-DS query78.tpl 0.10 */ ws as - (select d_year AS ws_sold_year, ws_item_sk, - ws_bill_customer_sk ws_customer_sk, - sum(ws_quantity) ws_qty, - sum(ws_wholesale_cost) ws_wc, - sum(ws_sales_price) ws_sp - from web_sales - left join web_returns on wr_order_number=ws_order_number and ws_item_sk=wr_item_sk - join date_dim on ws_sold_date_sk = d_date_sk - where wr_order_number is null - group by d_year, ws_item_sk, ws_bill_customer_sk - ), -cs as - (select d_year AS cs_sold_year, cs_item_sk, - cs_bill_customer_sk cs_customer_sk, - sum(cs_quantity) cs_qty, - sum(cs_wholesale_cost) cs_wc, - sum(cs_sales_price) cs_sp - from catalog_sales - left join catalog_returns on cr_order_number=cs_order_number and cs_item_sk=cr_item_sk - join date_dim on cs_sold_date_sk = d_date_sk - where cr_order_number is null - group by d_year, cs_item_sk, cs_bill_customer_sk - ), -ss as - (select d_year AS ss_sold_year, ss_item_sk, - ss_customer_sk, - sum(ss_quantity) ss_qty, - sum(ss_wholesale_cost) ss_wc, - sum(ss_sales_price) ss_sp - from store_sales - left join store_returns on sr_ticket_number=ss_ticket_number and ss_item_sk=sr_item_sk - join date_dim on ss_sold_date_sk = d_date_sk - where sr_ticket_number is null - group by d_year, ss_item_sk, ss_customer_sk - ) - select -ss_customer_sk, -round(ss_qty/(coalesce(ws_qty,0)+coalesce(cs_qty,0)),2) ratio, -ss_qty store_qty, ss_wc store_wholesale_cost, ss_sp store_sales_price, -coalesce(ws_qty,0)+coalesce(cs_qty,0) other_chan_qty, -coalesce(ws_wc,0)+coalesce(cs_wc,0) other_chan_wholesale_cost, -coalesce(ws_sp,0)+coalesce(cs_sp,0) other_chan_sales_price -from ss -left join ws on (ws_sold_year=ss_sold_year and ws_item_sk=ss_item_sk and ws_customer_sk=ss_customer_sk) -left join cs on (cs_sold_year=ss_sold_year and cs_item_sk=ss_item_sk and cs_customer_sk=ss_customer_sk) -where (coalesce(ws_qty,0)>0 or coalesce(cs_qty, 0)>0) and ss_sold_year=1999 -order by - ss_customer_sk, - ss_qty desc, ss_wc desc, ss_sp desc, - other_chan_qty, - other_chan_wholesale_cost, - other_chan_sales_price, - ratio -limit 100; - --- end template query78.tpl query 85 in stream 2 --- start template query18a.tpl query 86 in stream 2 -with /* TPC-DS query18a.tpl 0.90 */ results as - (select i_item_id, - ca_country, - ca_state, - ca_county, - cast(cs_quantity as decimal(12,2)) agg1, - cast(cs_list_price as decimal(12,2)) agg2, - cast(cs_coupon_amt as decimal(12,2)) agg3, - cast(cs_sales_price as decimal(12,2)) agg4, - cast(cs_net_profit as decimal(12,2)) agg5, - cast(c_birth_year as decimal(12,2)) agg6, - cast(cd1.cd_dep_count as decimal(12,2)) agg7 - from catalog_sales, customer_demographics cd1, customer_demographics cd2, customer, customer_address, date_dim, item - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd1.cd_demo_sk and - cs_bill_customer_sk = c_customer_sk and - cd1.cd_gender = 'M' and - cd1.cd_education_status = '4 yr Degree' and - c_current_cdemo_sk = cd2.cd_demo_sk and - c_current_addr_sk = ca_address_sk and - c_birth_month in (10,5,11,12,6,8) and - d_year = 1998 and - ca_state in ('GA','SC','LA','TX','SD','VA','KS') - ) - select i_item_id, ca_country, ca_state, ca_county, agg1, agg2, agg3, agg4, agg5, agg6, agg7 - from ( - select i_item_id, ca_country, ca_state, ca_county, avg(agg1) agg1, - avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state, ca_county - union all - select i_item_id, ca_country, ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state - union all - select i_item_id, ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country - union all - select i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - ) foo - order by ca_country, ca_state, ca_county, i_item_id - limit 100; - --- end template query18a.tpl query 86 in stream 2 --- start template query65.tpl query 87 in stream 2 -select /* TPC-DS query65.tpl 0.71 */ - s_store_name, - i_item_desc, - sc.revenue, - i_current_price, - i_wholesale_cost, - i_brand - from store, item, - (select ss_store_sk, avg(revenue) as ave - from - (select ss_store_sk, ss_item_sk, - sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1214 and 1214+11 - group by ss_store_sk, ss_item_sk) sa - group by ss_store_sk) sb, - (select ss_store_sk, ss_item_sk, sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1214 and 1214+11 - group by ss_store_sk, ss_item_sk) sc - where sb.ss_store_sk = sc.ss_store_sk and - sc.revenue <= 0.1 * sb.ave and - s_store_sk = sc.ss_store_sk and - i_item_sk = sc.ss_item_sk - order by s_store_name, i_item_desc -limit 100; - --- end template query65.tpl query 87 in stream 2 --- start template query60.tpl query 88 in stream 2 -with /* TPC-DS query60.tpl 0.29 */ ss as ( - select - i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Jewelry')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 10 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -7 - group by i_item_id), - cs as ( - select - i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Jewelry')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 10 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -7 - group by i_item_id), - ws as ( - select - i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Jewelry')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 10 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -7 - group by i_item_id) - select - i_item_id -,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by i_item_id - ,total_sales - limit 100; - --- end template query60.tpl query 88 in stream 2 --- start template query34.tpl query 89 in stream 2 -select /* TPC-DS query34.tpl 0.73 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (date_dim.d_dom between 1 and 3 or date_dim.d_dom between 25 and 28) - and (household_demographics.hd_buy_potential = '>10000' or - household_demographics.hd_buy_potential = 'Unknown') - and household_demographics.hd_vehicle_count > 0 - and (case when household_demographics.hd_vehicle_count > 0 - then household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count - else null - end) > 1.2 - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_county in ('Williamson County','Walker County','Franklin Parish','Daviess County', - 'Dauphin County','Raleigh County','Jefferson Davis Parish','Marshall County') - group by ss_ticket_number,ss_customer_sk) dn,customer - where ss_customer_sk = c_customer_sk - and cnt between 15 and 20 - order by c_last_name,c_first_name,c_salutation,c_preferred_cust_flag desc, ss_ticket_number; - --- end template query34.tpl query 89 in stream 2 --- start template query3.tpl query 90 in stream 2 -select /* TPC-DS query3.tpl 0.45 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_net_profit) sum_agg - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manufact_id = 156 - and dt.d_moy=11 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,sum_agg desc - ,brand_id - limit 100; - --- end template query3.tpl query 90 in stream 2 --- start template query13.tpl query 91 in stream 2 -select /* TPC-DS query13.tpl 0.91 */ avg(ss_quantity) - ,avg(ss_ext_sales_price) - ,avg(ss_ext_wholesale_cost) - ,sum(ss_ext_wholesale_cost) - from store_sales - ,store - ,customer_demographics - ,household_demographics - ,customer_address - ,date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2001 - and((ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'W' - and cd_education_status = '4 yr Degree' - and ss_sales_price between 100.00 and 150.00 - and hd_dep_count = 3 - )or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'S' - and cd_education_status = 'Unknown' - and ss_sales_price between 50.00 and 100.00 - and hd_dep_count = 1 - ) or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'D' - and cd_education_status = '2 yr Degree' - and ss_sales_price between 150.00 and 200.00 - and hd_dep_count = 1 - )) - and((ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('FL', 'TX', 'NY') - and ss_net_profit between 100 and 200 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('KS', 'SC', 'NC') - and ss_net_profit between 150 and 300 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('AR', 'MO', 'WI') - and ss_net_profit between 50 and 250 - )) -; - --- end template query13.tpl query 91 in stream 2 --- start template query41.tpl query 92 in stream 2 -select /* TPC-DS query41.tpl 0.62 */ distinct(i_product_name) - from item i1 - where i_manufact_id between 706 and 706+40 - and (select count(*) as item_cnt - from item - where (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'purple' or i_color = 'tan') and - (i_units = 'Cup' or i_units = 'Ounce') and - (i_size = 'economy' or i_size = 'small') - ) or - (i_category = 'Women' and - (i_color = 'salmon' or i_color = 'pale') and - (i_units = 'Pallet' or i_units = 'Gram') and - (i_size = 'extra large' or i_size = 'medium') - ) or - (i_category = 'Men' and - (i_color = 'lime' or i_color = 'misty') and - (i_units = 'Lb' or i_units = 'Pound') and - (i_size = 'large' or i_size = 'petite') - ) or - (i_category = 'Men' and - (i_color = 'green' or i_color = 'brown') and - (i_units = 'Dram' or i_units = 'Ton') and - (i_size = 'economy' or i_size = 'small') - ))) or - (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'dim' or i_color = 'maroon') and - (i_units = 'Case' or i_units = 'Bundle') and - (i_size = 'economy' or i_size = 'small') - ) or - (i_category = 'Women' and - (i_color = 'wheat' or i_color = 'azure') and - (i_units = 'Dozen' or i_units = 'N/A') and - (i_size = 'extra large' or i_size = 'medium') - ) or - (i_category = 'Men' and - (i_color = 'royal' or i_color = 'drab') and - (i_units = 'Each' or i_units = 'Box') and - (i_size = 'large' or i_size = 'petite') - ) or - (i_category = 'Men' and - (i_color = 'cornsilk' or i_color = 'spring') and - (i_units = 'Bunch' or i_units = 'Tsp') and - (i_size = 'economy' or i_size = 'small') - )))) > 0 - order by i_product_name - limit 100; - --- end template query41.tpl query 92 in stream 2 --- start template query92.tpl query 93 in stream 2 -select /* TPC-DS query92.tpl 0.44 */ - sum(ws_ext_discount_amt) as "Excess Discount Amount" -from - web_sales - ,item - ,date_dim -where -i_manufact_id = 308 -and i_item_sk = ws_item_sk -and d_date between '2001-01-04' and - dateadd(day,90,cast('2001-01-04' as date)) -and d_date_sk = ws_sold_date_sk -and ws_ext_discount_amt - > ( - SELECT - 1.3 * avg(ws_ext_discount_amt) - FROM - web_sales - ,date_dim - WHERE - ws_item_sk = i_item_sk - and d_date between '2001-01-04' and - dateadd(day,90,cast('2001-01-04' as date)) - and d_date_sk = ws_sold_date_sk - ) -order by sum(ws_ext_discount_amt) -limit 100; - --- end template query92.tpl query 93 in stream 2 --- start template query74.tpl query 94 in stream 2 -with /* TPC-DS query74.tpl 0.76 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,max(ss_net_paid) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (2001,2001+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,max(ws_net_paid) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - and d_year in (2001,2001+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - ) - select - t_s_secyear.customer_id, t_s_secyear.customer_first_name, t_s_secyear.customer_last_name - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.year = 2001 - and t_s_secyear.year = 2001+1 - and t_w_firstyear.year = 2001 - and t_w_secyear.year = 2001+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - order by 2,1,3 -limit 100; - --- end template query74.tpl query 94 in stream 2 --- start template query46.tpl query 95 in stream 2 -select /* TPC-DS query46.tpl 0.23 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and (household_demographics.hd_dep_count = 4 or - household_demographics.hd_vehicle_count= -1) - and date_dim.d_dow in (6,0) - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_city in ('Fairview','Harmony','Oak Grove','Salem','Woodlawn') - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,ca_city) dn,customer,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - limit 100; - --- end template query46.tpl query 95 in stream 2 --- start template query89.tpl query 96 in stream 2 -select /* TPC-DS query89.tpl 0.56 */ * -from( -select i_category, i_class, i_brand, - s_store_name, s_company_name, - d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, s_store_name, s_company_name) - avg_monthly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - d_year in (2001) and - ((i_category in ('Men','Shoes','Sports') and - i_class in ('accessories','athletic','athletic shoes') - ) - or (i_category in ('Children','Home','Jewelry') and - i_class in ('toddlers','rugs','earings') - )) -group by i_category, i_class, i_brand, - s_store_name, s_company_name, d_moy) tmp1 -where case when (avg_monthly_sales <> 0) then (abs(sum_sales - avg_monthly_sales) / avg_monthly_sales) else null end > 0.1 -order by sum_sales - avg_monthly_sales, s_store_name -limit 100; - --- end template query89.tpl query 96 in stream 2 --- start template query47.tpl query 97 in stream 2 -with /* TPC-DS query47.tpl 0.42 */ v1 as( - select i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, - s_store_name, s_company_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - s_store_name, s_company_name - order by d_year, d_moy) rn - from item, store_sales, date_dim, store - where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - ( - d_year = 2000 or - ( d_year = 2000-1 and d_moy =12) or - ( d_year = 2000+1 and d_moy =1) - ) - group by i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy), - v2 as( - select v1.s_store_name - ,v1.d_year, v1.d_moy - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1.s_store_name = v1_lag.s_store_name and - v1.s_store_name = v1_lead.s_store_name and - v1.s_company_name = v1_lag.s_company_name and - v1.s_company_name = v1_lead.s_company_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 2000 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, sum_sales - limit 100; - --- end template query47.tpl query 97 in stream 2 --- start template query66.tpl query 98 in stream 2 -select /* TPC-DS query66.tpl 0.39 */ - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - ,sum(jan_sales) as jan_sales - ,sum(feb_sales) as feb_sales - ,sum(mar_sales) as mar_sales - ,sum(apr_sales) as apr_sales - ,sum(may_sales) as may_sales - ,sum(jun_sales) as jun_sales - ,sum(jul_sales) as jul_sales - ,sum(aug_sales) as aug_sales - ,sum(sep_sales) as sep_sales - ,sum(oct_sales) as oct_sales - ,sum(nov_sales) as nov_sales - ,sum(dec_sales) as dec_sales - ,sum(jan_sales/w_warehouse_sq_ft) as jan_sales_per_sq_foot - ,sum(feb_sales/w_warehouse_sq_ft) as feb_sales_per_sq_foot - ,sum(mar_sales/w_warehouse_sq_ft) as mar_sales_per_sq_foot - ,sum(apr_sales/w_warehouse_sq_ft) as apr_sales_per_sq_foot - ,sum(may_sales/w_warehouse_sq_ft) as may_sales_per_sq_foot - ,sum(jun_sales/w_warehouse_sq_ft) as jun_sales_per_sq_foot - ,sum(jul_sales/w_warehouse_sq_ft) as jul_sales_per_sq_foot - ,sum(aug_sales/w_warehouse_sq_ft) as aug_sales_per_sq_foot - ,sum(sep_sales/w_warehouse_sq_ft) as sep_sales_per_sq_foot - ,sum(oct_sales/w_warehouse_sq_ft) as oct_sales_per_sq_foot - ,sum(nov_sales/w_warehouse_sq_ft) as nov_sales_per_sq_foot - ,sum(dec_sales/w_warehouse_sq_ft) as dec_sales_per_sq_foot - ,sum(jan_net) as jan_net - ,sum(feb_net) as feb_net - ,sum(mar_net) as mar_net - ,sum(apr_net) as apr_net - ,sum(may_net) as may_net - ,sum(jun_net) as jun_net - ,sum(jul_net) as jul_net - ,sum(aug_net) as aug_net - ,sum(sep_net) as sep_net - ,sum(oct_net) as oct_net - ,sum(nov_net) as nov_net - ,sum(dec_net) as dec_net - from ( - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'GREAT EASTERN' || ',' || 'GERMA' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then ws_sales_price* ws_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then ws_sales_price* ws_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then ws_sales_price* ws_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then ws_sales_price* ws_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then ws_sales_price* ws_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then ws_sales_price* ws_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then ws_sales_price* ws_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then ws_sales_price* ws_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then ws_sales_price* ws_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then ws_sales_price* ws_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then ws_sales_price* ws_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then ws_sales_price* ws_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then ws_net_paid * ws_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then ws_net_paid * ws_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then ws_net_paid * ws_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then ws_net_paid * ws_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then ws_net_paid * ws_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then ws_net_paid * ws_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then ws_net_paid * ws_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then ws_net_paid * ws_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then ws_net_paid * ws_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then ws_net_paid * ws_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then ws_net_paid * ws_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then ws_net_paid * ws_quantity else 0 end) as dec_net - from - web_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - ws_warehouse_sk = w_warehouse_sk - and ws_sold_date_sk = d_date_sk - and ws_sold_time_sk = t_time_sk - and ws_ship_mode_sk = sm_ship_mode_sk - and d_year = 2001 - and t_time between 25782 and 25782+28800 - and sm_carrier in ('GREAT EASTERN','GERMA') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - union all - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'GREAT EASTERN' || ',' || 'GERMA' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then cs_sales_price* cs_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then cs_sales_price* cs_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then cs_sales_price* cs_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then cs_sales_price* cs_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then cs_sales_price* cs_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then cs_sales_price* cs_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then cs_sales_price* cs_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then cs_sales_price* cs_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then cs_sales_price* cs_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then cs_sales_price* cs_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then cs_sales_price* cs_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then cs_sales_price* cs_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then cs_net_profit * cs_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then cs_net_profit * cs_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then cs_net_profit * cs_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then cs_net_profit * cs_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then cs_net_profit * cs_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then cs_net_profit * cs_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then cs_net_profit * cs_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then cs_net_profit * cs_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then cs_net_profit * cs_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then cs_net_profit * cs_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then cs_net_profit * cs_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then cs_net_profit * cs_quantity else 0 end) as dec_net - from - catalog_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and cs_sold_time_sk = t_time_sk - and cs_ship_mode_sk = sm_ship_mode_sk - and d_year = 2001 - and t_time between 25782 AND 25782+28800 - and sm_carrier in ('GREAT EASTERN','GERMA') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - ) x - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - order by w_warehouse_name - limit 100; - --- end template query66.tpl query 98 in stream 2 --- start template query48.tpl query 99 in stream 2 -select /* TPC-DS query48.tpl 0.74 */ sum (ss_quantity) - from store_sales, store, customer_demographics, customer_address, date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2000 - and - ( - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'M' - and - cd_education_status = 'Primary' - and - ss_sales_price between 100.00 and 150.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'S' - and - cd_education_status = '4 yr Degree' - and - ss_sales_price between 50.00 and 100.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'U' - and - cd_education_status = 'Advanced Degree' - and - ss_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('TX', 'NV', 'CO') - and ss_net_profit between 0 and 2000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('IN', 'LA', 'SC') - and ss_net_profit between 150 and 3000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('NJ', 'GA', 'UT') - and ss_net_profit between 50 and 25000 - ) - ) -; - --- end template query48.tpl query 99 in stream 2 diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/1TB/queries/query_3.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/1TB/queries/query_3.sql deleted file mode 100644 index 81cb6f69..00000000 --- a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/1TB/queries/query_3.sql +++ /dev/null @@ -1,5027 +0,0 @@ --- start template query89.tpl query 1 in stream 3 -select /* TPC-DS query89.tpl 0.56 */ * -from( -select i_category, i_class, i_brand, - s_store_name, s_company_name, - d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, s_store_name, s_company_name) - avg_monthly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - d_year in (2001) and - ((i_category in ('Music','Children','Books') and - i_class in ('pop','school-uniforms','mystery') - ) - or (i_category in ('Jewelry','Home','Shoes') and - i_class in ('earings','bathroom','athletic') - )) -group by i_category, i_class, i_brand, - s_store_name, s_company_name, d_moy) tmp1 -where case when (avg_monthly_sales <> 0) then (abs(sum_sales - avg_monthly_sales) / avg_monthly_sales) else null end > 0.1 -order by sum_sales - avg_monthly_sales, s_store_name -limit 100; - --- end template query89.tpl query 1 in stream 3 --- start template query5a.tpl query 2 in stream 3 -with /* TPC-DS query5a.tpl 0.98 */ ssr as - (select s_store_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ss_store_sk as store_sk, - ss_sold_date_sk as date_sk, - ss_ext_sales_price as sales_price, - ss_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from store_sales - union all - select sr_store_sk as store_sk, - sr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - sr_return_amt as return_amt, - sr_net_loss as net_loss - from store_returns - ) salesreturns, - date_dim, - store - where date_sk = d_date_sk - and d_date between cast('2000-08-21' as date) - and dateadd(day,14,cast('2000-08-21' as date)) - and store_sk = s_store_sk - group by s_store_id) - , - csr as - (select cp_catalog_page_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select cs_catalog_page_sk as page_sk, - cs_sold_date_sk as date_sk, - cs_ext_sales_price as sales_price, - cs_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from catalog_sales - union all - select cr_catalog_page_sk as page_sk, - cr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - cr_return_amount as return_amt, - cr_net_loss as net_loss - from catalog_returns - ) salesreturns, - date_dim, - catalog_page - where date_sk = d_date_sk - and d_date between cast('2000-08-21' as date) - and dateadd(day,14,cast('2000-08-21' as date)) - and page_sk = cp_catalog_page_sk - group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ws_web_site_sk as wsr_web_site_sk, - ws_sold_date_sk as date_sk, - ws_ext_sales_price as sales_price, - ws_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from web_sales - union all - select ws_web_site_sk as wsr_web_site_sk, - wr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - wr_return_amt as return_amt, - wr_net_loss as net_loss - from web_returns left outer join web_sales on - ( wr_item_sk = ws_item_sk - and wr_order_number = ws_order_number) - ) salesreturns, - date_dim, - web_site - where date_sk = d_date_sk - and d_date between cast('2000-08-21' as date) - and dateadd(day,14,cast('2000-08-21' as date)) - and wsr_web_site_sk = web_site_sk - group by web_site_id) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || s_store_id as id - , sales - , returns - , (profit - profit_loss) as profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || cp_catalog_page_id as id - , sales - , returns - , (profit - profit_loss) as profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , (profit - profit_loss) as profit - from wsr - ) x - group by channel, id) - select channel, id, sales, returns, profit from ( - select channel, id, sales, returns, profit from results - union - select channel, null as id, sum(sales), sum(returns), sum(profit) from results group by channel - union - select null as channel, null as id, sum(sales), sum(returns), sum(profit) from results) foo -order by channel, id -limit 100; - --- end template query5a.tpl query 2 in stream 3 --- start template query52.tpl query 3 in stream 3 -select /* TPC-DS query52.tpl 0.59 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_sales_price) ext_price - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=11 - and dt.d_year=2000 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,ext_price desc - ,brand_id -limit 100 ; - --- end template query52.tpl query 3 in stream 3 --- start template query62.tpl query 4 in stream 3 -select /* TPC-DS query62.tpl 0.24 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 30) and - (ws_ship_date_sk - ws_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 60) and - (ws_ship_date_sk - ws_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 90) and - (ws_ship_date_sk - ws_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - web_sales - ,warehouse - ,ship_mode - ,web_site - ,date_dim -where - d_month_seq between 1177 and 1177 + 11 -and ws_ship_date_sk = d_date_sk -and ws_warehouse_sk = w_warehouse_sk -and ws_ship_mode_sk = sm_ship_mode_sk -and ws_web_site_sk = web_site_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -limit 100; - --- end template query62.tpl query 4 in stream 3 --- start template query53.tpl query 5 in stream 3 -select /* TPC-DS query53.tpl 0.88 */ * from -(select i_manufact_id, -sum(ss_sales_price) sum_sales, -avg(sum(ss_sales_price)) over (partition by i_manufact_id) avg_quarterly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and -ss_sold_date_sk = d_date_sk and -ss_store_sk = s_store_sk and -d_month_seq in (1187,1187+1,1187+2,1187+3,1187+4,1187+5,1187+6,1187+7,1187+8,1187+9,1187+10,1187+11) and -((i_category in ('Books','Children','Electronics') and -i_class in ('personal','portable','reference','self-help') and -i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) -or(i_category in ('Women','Music','Men') and -i_class in ('accessories','classical','fragrances','pants') and -i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manufact_id, d_qoy ) tmp1 -where case when avg_quarterly_sales > 0 - then abs (sum_sales - avg_quarterly_sales)/ avg_quarterly_sales - else null end > 0.1 -order by avg_quarterly_sales, - sum_sales, - i_manufact_id -limit 100; - --- end template query53.tpl query 5 in stream 3 --- start template query7.tpl query 6 in stream 3 -select /* TPC-DS query7.tpl 0.2 */ i_item_id, - avg(ss_quantity) agg1, - avg(ss_list_price) agg2, - avg(ss_coupon_amt) agg3, - avg(ss_sales_price) agg4 - from store_sales, customer_demographics, date_dim, item, promotion - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_cdemo_sk = cd_demo_sk and - ss_promo_sk = p_promo_sk and - cd_gender = 'F' and - cd_marital_status = 'U' and - cd_education_status = '2 yr Degree' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 1998 - group by i_item_id - order by i_item_id - limit 100; - --- end template query7.tpl query 6 in stream 3 --- start template query39.tpl query 7 in stream 3 -with /* TPC-DS query39.tpl 0.5 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =1998 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=3 - and inv2.d_moy=3+1 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; -with /* TPC-DS query39.tpl 0.5 part2 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =1998 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=3 - and inv2.d_moy=3+1 - and inv1.cov > 1.5 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; - --- end template query39.tpl query 7 in stream 3 --- start template query80a.tpl query 8 in stream 3 -with /* TPC-DS query80a.tpl 0.6 */ ssr as - (select s_store_id as store_id, - sum(ss_ext_sales_price) as sales, - sum(coalesce(sr_return_amt, 0)) as returns, - sum(ss_net_profit - coalesce(sr_net_loss, 0)) as profit - from store_sales left outer join store_returns on - (ss_item_sk = sr_item_sk and ss_ticket_number = sr_ticket_number), - date_dim, - store, - item, - promotion - where ss_sold_date_sk = d_date_sk - and d_date between cast('1998-08-07' as date) - and dateadd(day,30,cast('1998-08-07' as date)) - and ss_store_sk = s_store_sk - and ss_item_sk = i_item_sk - and i_current_price > 50 - and ss_promo_sk = p_promo_sk - and p_channel_tv = 'N' - group by s_store_id) - , - csr as - (select cp_catalog_page_id as catalog_page_id, - sum(cs_ext_sales_price) as sales, - sum(coalesce(cr_return_amount, 0)) as returns, - sum(cs_net_profit - coalesce(cr_net_loss, 0)) as profit - from catalog_sales left outer join catalog_returns on - (cs_item_sk = cr_item_sk and cs_order_number = cr_order_number), - date_dim, - catalog_page, - item, - promotion - where cs_sold_date_sk = d_date_sk - and d_date between cast('1998-08-07' as date) - and dateadd(day,30,cast('1998-08-07' as date)) - and cs_catalog_page_sk = cp_catalog_page_sk - and cs_item_sk = i_item_sk - and i_current_price > 50 - and cs_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(ws_ext_sales_price) as sales, - sum(coalesce(wr_return_amt, 0)) as returns, - sum(ws_net_profit - coalesce(wr_net_loss, 0)) as profit - from web_sales left outer join web_returns on - (ws_item_sk = wr_item_sk and ws_order_number = wr_order_number), - date_dim, - web_site, - item, - promotion - where ws_sold_date_sk = d_date_sk - and d_date between cast('1998-08-07' as date) - and dateadd(day,30,cast('1998-08-07' as date)) - and ws_web_site_sk = web_site_sk - and ws_item_sk = i_item_sk - and i_current_price > 50 - and ws_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by web_site_id) -, -results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || store_id as id - , sales - , returns - , profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || catalog_page_id as id - , sales - , returns - , profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , profit - from wsr - ) x - group by channel, id) - - select channel - , id - , sales - , returns - , profit - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results - ) foo - order by channel, id - limit 100; - --- end template query80a.tpl query 8 in stream 3 --- start template query63.tpl query 9 in stream 3 -select /* TPC-DS query63.tpl 0.27 */ * -from (select i_manager_id - ,sum(ss_sales_price) sum_sales - ,avg(sum(ss_sales_price)) over (partition by i_manager_id) avg_monthly_sales - from item - ,store_sales - ,date_dim - ,store - where ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and d_month_seq in (1217,1217+1,1217+2,1217+3,1217+4,1217+5,1217+6,1217+7,1217+8,1217+9,1217+10,1217+11) - and (( i_category in ('Books','Children','Electronics') - and i_class in ('personal','portable','reference','self-help') - and i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) - or( i_category in ('Women','Music','Men') - and i_class in ('accessories','classical','fragrances','pants') - and i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manager_id, d_moy) tmp1 -where case when avg_monthly_sales > 0 then abs (sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 -order by i_manager_id - ,avg_monthly_sales - ,sum_sales -limit 100; - --- end template query63.tpl query 9 in stream 3 --- start template query72.tpl query 10 in stream 3 -select /* TPC-DS query72.tpl 0.87 */ i_item_desc - ,w_warehouse_name - ,d1.d_week_seq - ,sum(case when p_promo_sk is null then 1 else 0 end) no_promo - ,sum(case when p_promo_sk is not null then 1 else 0 end) promo - ,count(*) total_cnt -from catalog_sales -join inventory on (cs_item_sk = inv_item_sk) -join warehouse on (w_warehouse_sk=inv_warehouse_sk) -join item on (i_item_sk = cs_item_sk) -join customer_demographics on (cs_bill_cdemo_sk = cd_demo_sk) -join household_demographics on (cs_bill_hdemo_sk = hd_demo_sk) -join date_dim d1 on (cs_sold_date_sk = d1.d_date_sk) -join date_dim d2 on (inv_date_sk = d2.d_date_sk) -join date_dim d3 on (cs_ship_date_sk = d3.d_date_sk) -left outer join promotion on (cs_promo_sk=p_promo_sk) -left outer join catalog_returns on (cr_item_sk = cs_item_sk and cr_order_number = cs_order_number) -where d1.d_week_seq = d2.d_week_seq - and inv_quantity_on_hand < cs_quantity - and d3.d_date > d1.d_date + 5 - and hd_buy_potential = '>10000' - and d1.d_year = 1998 - and cd_marital_status = 'U' -group by i_item_desc,w_warehouse_name,d1.d_week_seq -order by total_cnt desc, i_item_desc, w_warehouse_name, d_week_seq -limit 100; - --- end template query72.tpl query 10 in stream 3 --- start template query18a.tpl query 11 in stream 3 -with /* TPC-DS query18a.tpl 0.90 */ results as - (select i_item_id, - ca_country, - ca_state, - ca_county, - cast(cs_quantity as decimal(12,2)) agg1, - cast(cs_list_price as decimal(12,2)) agg2, - cast(cs_coupon_amt as decimal(12,2)) agg3, - cast(cs_sales_price as decimal(12,2)) agg4, - cast(cs_net_profit as decimal(12,2)) agg5, - cast(c_birth_year as decimal(12,2)) agg6, - cast(cd1.cd_dep_count as decimal(12,2)) agg7 - from catalog_sales, customer_demographics cd1, customer_demographics cd2, customer, customer_address, date_dim, item - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd1.cd_demo_sk and - cs_bill_customer_sk = c_customer_sk and - cd1.cd_gender = 'F' and - cd1.cd_education_status = '2 yr Degree' and - c_current_cdemo_sk = cd2.cd_demo_sk and - c_current_addr_sk = ca_address_sk and - c_birth_month in (3,1,2,12,7,4) and - d_year = 1999 and - ca_state in ('IA','TX','AL','AK','ND','VA','KY') - ) - select i_item_id, ca_country, ca_state, ca_county, agg1, agg2, agg3, agg4, agg5, agg6, agg7 - from ( - select i_item_id, ca_country, ca_state, ca_county, avg(agg1) agg1, - avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state, ca_county - union all - select i_item_id, ca_country, ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state - union all - select i_item_id, ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country - union all - select i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - ) foo - order by ca_country, ca_state, ca_county, i_item_id - limit 100; - --- end template query18a.tpl query 11 in stream 3 --- start template query56.tpl query 12 in stream 3 -with /* TPC-DS query56.tpl 0.83 */ ss as ( - select i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where i_item_id in (select - i_item_id -from item -where i_color in ('mint','light','midnight')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 2 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id), - cs as ( - select i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('mint','light','midnight')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 2 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id), - ws as ( - select i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('mint','light','midnight')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 2 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id) - select i_item_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by total_sales, - i_item_id - limit 100; - --- end template query56.tpl query 12 in stream 3 --- start template query13.tpl query 13 in stream 3 -select /* TPC-DS query13.tpl 0.91 */ avg(ss_quantity) - ,avg(ss_ext_sales_price) - ,avg(ss_ext_wholesale_cost) - ,sum(ss_ext_wholesale_cost) - from store_sales - ,store - ,customer_demographics - ,household_demographics - ,customer_address - ,date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2001 - and((ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'W' - and cd_education_status = '2 yr Degree' - and ss_sales_price between 100.00 and 150.00 - and hd_dep_count = 3 - )or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'U' - and cd_education_status = 'Primary' - and ss_sales_price between 50.00 and 100.00 - and hd_dep_count = 1 - ) or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'M' - and cd_education_status = '4 yr Degree' - and ss_sales_price between 150.00 and 200.00 - and hd_dep_count = 1 - )) - and((ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('KY', 'MI', 'GA') - and ss_net_profit between 100 and 200 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('AK', 'IA', 'TX') - and ss_net_profit between 150 and 300 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('NY', 'NJ', 'MN') - and ss_net_profit between 50 and 250 - )) -; - --- end template query13.tpl query 13 in stream 3 --- start template query69.tpl query 14 in stream 3 -select /* TPC-DS query69.tpl 0.28 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_state in ('RI','TX','NY') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 2 and 2+2) and - (not exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 2 and 2+2) and - not exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 2 and 2+2)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - limit 100; - --- end template query69.tpl query 14 in stream 3 --- start template query23.tpl query 15 in stream 3 -with /* TPC-DS query23.tpl 0.68 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (1998,1998+1,1998+2,1998+3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1998,1998+1,1998+2,1998+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * -from - max_store_sales)) - select sum(sales) - from (select cs_quantity*cs_list_price sales - from catalog_sales - ,date_dim - where d_year = 1998 - and d_moy = 4 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - union all - select ws_quantity*ws_list_price sales - from web_sales - ,date_dim - where d_year = 1998 - and d_moy = 4 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer)) - limit 100; -with /* TPC-DS query23.tpl 0.68 part2 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (1998,1998 + 1,1998 + 2,1998 + 3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1998,1998+1,1998+2,1998+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * - from max_store_sales)) - select c_last_name,c_first_name,sales - from (select c_last_name,c_first_name,sum(cs_quantity*cs_list_price) sales - from catalog_sales - ,customer - ,date_dim - where d_year = 1998 - and d_moy = 4 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and cs_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name - union all - select c_last_name,c_first_name,sum(ws_quantity*ws_list_price) sales - from web_sales - ,customer - ,date_dim - where d_year = 1998 - and d_moy = 4 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and ws_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name) - order by c_last_name,c_first_name,sales - limit 100; - --- end template query23.tpl query 15 in stream 3 --- start template query19.tpl query 16 in stream 3 -select /* TPC-DS query19.tpl 0.8 */ i_brand_id brand_id, i_brand brand, i_manufact_id, i_manufact, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item,customer,customer_address,store - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=32 - and d_moy=12 - and d_year=1998 - and ss_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and substring(ca_zip,1,5) <> substring(s_zip,1,5) - and ss_store_sk = s_store_sk - group by i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact - order by ext_price desc - ,i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact -limit 100 ; - --- end template query19.tpl query 16 in stream 3 --- start template query74.tpl query 17 in stream 3 -with /* TPC-DS query74.tpl 0.76 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,max(ss_net_paid) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1998,1998+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,max(ws_net_paid) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - and d_year in (1998,1998+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - ) - select - t_s_secyear.customer_id, t_s_secyear.customer_first_name, t_s_secyear.customer_last_name - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.year = 1998 - and t_s_secyear.year = 1998+1 - and t_w_firstyear.year = 1998 - and t_w_secyear.year = 1998+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - order by 3,2,1 -limit 100; - --- end template query74.tpl query 17 in stream 3 --- start template query30.tpl query 18 in stream 3 -with /* TPC-DS query30.tpl 0.75 */ customer_total_return as - (select wr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(wr_return_amt) as ctr_total_return - from web_returns - ,date_dim - ,customer_address - where wr_returned_date_sk = d_date_sk - and d_year =2000 - and wr_returning_addr_sk = ca_address_sk - group by wr_returning_customer_sk - ,ca_state) - select c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'LA' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return -limit 100; - --- end template query30.tpl query 18 in stream 3 --- start template query84.tpl query 19 in stream 3 -select /* TPC-DS query84.tpl 0.80 */ c_customer_id as customer_id - , coalesce(c_last_name,'') || ', ' || coalesce(c_first_name,'') as customername - from customer - ,customer_address - ,customer_demographics - ,household_demographics - ,income_band - ,store_returns - where ca_city = 'Wildwood' - and c_current_addr_sk = ca_address_sk - and ib_lower_bound >= 1343 - and ib_upper_bound <= 1343 + 50000 - and ib_income_band_sk = hd_income_band_sk - and cd_demo_sk = c_current_cdemo_sk - and hd_demo_sk = c_current_hdemo_sk - and sr_cdemo_sk = cd_demo_sk - order by c_customer_id - limit 100; - --- end template query84.tpl query 19 in stream 3 --- start template query96.tpl query 20 in stream 3 -select /* TPC-DS query96.tpl 0.1 */ count(*) -from store_sales - ,household_demographics - ,time_dim, store -where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and household_demographics.hd_dep_count = 5 - and store.s_store_name = 'ese' -order by count(*) -limit 100; - --- end template query96.tpl query 20 in stream 3 --- start template query14a.tpl query 21 in stream 3 -with /* TPC-DS query14a.tpl 0.69 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1999 AND 1999 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1999 AND 1999 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1999 AND 1999 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as - (select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2) x) -, - results AS -(select channel, i_brand_id, i_class_id, i_category_id, sum(sales) sum_sales, sum(number_sales) number_sales - from ( - select 'store' channel, i_brand_id,i_class_id - ,i_category_id,sum(ss_quantity*ss_list_price) sales - , count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1999+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales) - union all - select 'catalog' channel, i_brand_id,i_class_id,i_category_id, sum(cs_quantity*cs_list_price) sales, count(*) number_sales - from catalog_sales - ,item - ,date_dim - where cs_item_sk in (select ss_item_sk from cross_items) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1999+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(cs_quantity*cs_list_price) > (select average_sales from avg_sales) - union all - select 'web' channel, i_brand_id,i_class_id,i_category_id, sum(ws_quantity*ws_list_price) sales , count(*) number_sales - from web_sales - ,item - ,date_dim - where ws_item_sk in (select ss_item_sk from cross_items) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1999+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ws_quantity*ws_list_price) > (select average_sales from avg_sales) - ) y - group by channel, i_brand_id,i_class_id,i_category_id) - - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales -from ( - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales from results - union - select channel, i_brand_id, i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id, i_class_id - union - select channel, i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id - union - select channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel - union - select null as channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results) z -order by channel, i_brand_id, i_class_id, i_category_id - limit 100; -with /* TPC-DS query14a.tpl 0.69 part2 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1999 AND 1999 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1999 AND 1999 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1999 AND 1999 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as -(select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2) x) - select this_year.channel ty_channel - ,this_year.i_brand_id ty_brand - ,this_year.i_class_id ty_class - ,this_year.i_category_id ty_category - ,this_year.sales ty_sales - ,this_year.number_sales ty_number_sales - ,last_year.channel ly_channel - ,last_year.i_brand_id ly_brand - ,last_year.i_class_id ly_class - ,last_year.i_category_id ly_category - ,last_year.sales ly_sales - ,last_year.number_sales ly_number_sales -from - (select 'store' channel, i_brand_id,i_class_id,i_category_id - ,sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1999 + 1 - and d_moy = 12 - and d_dom = 17) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) this_year, - (select 'store' channel, i_brand_id,i_class_id - ,i_category_id, sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1999 - and d_moy = 12 - and d_dom = 17) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) last_year - where this_year.i_brand_id= last_year.i_brand_id - and this_year.i_class_id = last_year.i_class_id - and this_year.i_category_id = last_year.i_category_id - order by this_year.channel, this_year.i_brand_id, this_year.i_class_id, this_year.i_category_id - limit 100; - --- end template query14a.tpl query 21 in stream 3 --- start template query10.tpl query 22 in stream 3 -select /* TPC-DS query10.tpl 0.26 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3, - cd_dep_count, - count(*) cnt4, - cd_dep_employed_count, - count(*) cnt5, - cd_dep_college_count, - count(*) cnt6 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_county in ('Keokuk County','Hartford County','Chickasaw County','Loudon County','Winnebago County') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 3 and 3+3) and - (exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 3 ANd 3+3) or - exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 3 and 3+3)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count -limit 100; - --- end template query10.tpl query 22 in stream 3 --- start template query86a.tpl query 23 in stream 3 -with /* TPC-DS query86a.tpl 0.11 */ results as -( select sum(ws_net_paid) as total_sum, i_category, i_class, 0 as g_category, 0 as g_class - from - web_sales - ,date_dim d1 - ,item - where - d1.d_month_seq between 1185 and 1185+11 - and d1.d_date_sk = ws_sold_date_sk - and i_item_sk = ws_item_sk - group by i_category,i_class - ) , - - results_rollup as -( select total_sum ,i_category ,i_class, g_category, g_class, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum, i_category, NULL as i_class, 0 as g_category, 1 as g_class, 1 as lochierarchy from results group by i_category - union - select sum(total_sum) as total_sum, NULL as i_category, NULL as i_class, 1 as g_category, 1 as g_class, 2 as lochierarchy from results) - select - total_sum ,i_category ,i_class, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_class = 0 then i_category end - order by total_sum desc) as rank_within_parent - from - results_rollup - order by - lochierarchy desc, - case when lochierarchy = 0 then i_category end, - rank_within_parent - limit 100; - --- end template query86a.tpl query 23 in stream 3 --- start template query94.tpl query 24 in stream 3 -select /* TPC-DS query94.tpl 0.17 */ - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2002-5-01' and - dateadd(day,60,cast('2002-5-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'NE' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and exists (select * - from web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) -and not exists(select * - from web_returns wr1 - where ws1.ws_order_number = wr1.wr_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query94.tpl query 24 in stream 3 --- start template query8.tpl query 25 in stream 3 -select /* TPC-DS query8.tpl 0.63 */ s_store_name - ,sum(ss_net_profit) - from store_sales - ,date_dim - ,store, - (select ca_zip - from ( - SELECT substring(ca_zip,1,5) ca_zip - FROM customer_address - WHERE substring(ca_zip,1,5) IN ( - '92817','79001','47088','58647','55896','15263', - '36198','80242','79483','70416','22272', - '84430','36233','36355','90031','43538', - '10655','33025','34972','44056','14064', - '43891','45168','84049','10513','24319', - '72385','92885','22319','93443','32827', - '29233','23550','12642','94979','56879', - '88171','50377','27802','98537','46038', - '11066','83392','78728','98322','17476', - '67135','55903','83098','46193','44313', - '51463','66769','48790','52059','58922', - '59698','75248','52430','18634','98092', - '70218','74575','68600','19961','10347', - '72460','64634','73483','35793','12583', - '27879','83929','83784','10605','49565', - '27307','37267','45948','95178','52867', - '46094','32787','99645','83492','85179', - '93687','76814','88498','44515','80551', - '92893','47757','99202','44121','35780', - '24146','46023','86203','18968','11012', - '77635','63926','20937','82060','42650', - '96874','54868','31746','85927','58677', - '27401','82725','62363','77760','37804', - '96999','34541','46125','66798','10898', - '27985','48968','75510','62905','78897', - '70671','50417','44948','33863','55126', - '46278','32721','30955','42516','77129', - '19863','17920','89128','95055','50885', - '49402','12174','79397','26021','13001', - '52078','78171','21453','77037','87693', - '42728','98071','97230','39739','67466', - '31331','66137','17087','67999','53588', - '81959','48936','28477','78202','40022', - '27708','36740','92789','40116','55098', - '10051','28257','85843','11430','62797', - '79622','60995','61249','40518','20904', - '98197','90730','76424','90746','18727', - '26123','67933','95618','75984','62412', - '37786','38265','54702','84134','60224', - '80908','42388','73076','69728','33817', - '63123','71094','81052','61403','41849', - '41809','42997','87551','36610','24180', - '70084','82664','10010','81108','40129', - '73339','68490','36662','33557','35967', - '87949','86648','12250','38580','63384', - '34679','61128','31337','23112','61494', - '45403','28928','25347','37618','39332', - '52433','97316','66254','57101','32220', - '14862','93394','85988','69232','11143', - '70824','98915','75124','39388','77925', - '72394','25296','14903','16932','87422', - '16994','72812','70551','19427','54781', - '51857','83655','12886','96500','82946', - '18263','73234','42083','73176','27178', - '68904','17220','94797','95462','69024', - '66417','99194','27854','29830','55211', - '81447','64992','96823','40969','13493', - '94194','85707','64412','40864','75269', - '22608','38795','35790','91787','28864', - '27447','44760','99581','80367','59989', - '70855','42574','27977','83209','57205', - '75798','44281','62090','96842','38316', - '69776','79354','47917','47178','87802', - '68350','23369','31104','48236','91321', - '52665','91110','82642','22879','72936', - '38706','60408','42985','76520','17709', - '59299','29903','83366','20812','31019', - '39917','44439','17686','40068','91644', - '61676','48579','29604','84809','33664', - '33043','38582','45613','36990','85101', - '19460','90640','89624','99088','89096', - '16534','38741','74247','46428','64115', - '49856','50888','78574','60350','15642', - '27840','45813','51790','61078','82761', - '12662','59388','70148','87666','39285', - '50804','75493','99603','56072','42905', - '99164','83718','54075','79795','20435', - '24510','11352','75450','70260','34418', - '51656','74711','26807','51715','81068', - '41097','82894','36275','42810') - intersect - select ca_zip - from (SELECT substring(ca_zip,1,5) ca_zip,count(*) cnt - FROM customer_address, customer - WHERE ca_address_sk = c_current_addr_sk and - c_preferred_cust_flag='Y' - group by ca_zip - having count(*) > 10)A1)A2) V1 - where ss_store_sk = s_store_sk - and ss_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 2000 - and (substring(s_zip,1,2) = substring(V1.ca_zip,1,2)) - group by s_store_name - order by s_store_name - limit 100; - --- end template query8.tpl query 25 in stream 3 --- start template query87.tpl query 26 in stream 3 -select /* TPC-DS query87.tpl 0.77 */ count(*) -from ((select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1183 and 1183+11) - except - (select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1183 and 1183+11) - except - (select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1183 and 1183+11) -) cool_cust -; - --- end template query87.tpl query 26 in stream 3 --- start template query58.tpl query 27 in stream 3 -with /* TPC-DS query58.tpl 0.19 */ ss_items as - (select i_item_id item_id - ,sum(ss_ext_sales_price) ss_item_rev - from store_sales - ,item - ,date_dim - where ss_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '2001-03-10')) - and ss_sold_date_sk = d_date_sk - group by i_item_id), - cs_items as - (select i_item_id item_id - ,sum(cs_ext_sales_price) cs_item_rev - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '2001-03-10')) - and cs_sold_date_sk = d_date_sk - group by i_item_id), - ws_items as - (select i_item_id item_id - ,sum(ws_ext_sales_price) ws_item_rev - from web_sales - ,item - ,date_dim - where ws_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq =(select d_week_seq - from date_dim - where d_date = '2001-03-10')) - and ws_sold_date_sk = d_date_sk - group by i_item_id) - select ss_items.item_id - ,ss_item_rev - ,ss_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ss_dev - ,cs_item_rev - ,cs_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 cs_dev - ,ws_item_rev - ,ws_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ws_dev - ,(ss_item_rev+cs_item_rev+ws_item_rev)/3 average - from ss_items,cs_items,ws_items - where ss_items.item_id=cs_items.item_id - and ss_items.item_id=ws_items.item_id - and ss_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - and ss_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and cs_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and cs_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and ws_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and ws_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - order by item_id - ,ss_item_rev - limit 100; - --- end template query58.tpl query 27 in stream 3 --- start template query36a.tpl query 28 in stream 3 -with /* TPC-DS query36a.tpl 0.21 */ results as - (select - sum(ss_net_profit) as ss_net_profit, sum(ss_ext_sales_price) as ss_ext_sales_price, - sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin - ,i_category - ,i_class - ,0 as g_category, 0 as g_class - from - store_sales - ,date_dim d1 - ,item - ,store - where - d1.d_year = 2002 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and s_state in ('GA','MO','AL','PA', - 'MI','WA','LA','GA') - group by i_category,i_class) - , - results_rollup as - (select gross_margin ,i_category ,i_class,0 as t_category, 0 as t_class, 0 as lochierarchy from results - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - i_category, NULL AS i_class, 0 as t_category, 1 as t_class, 1 as lochierarchy from results group by i_category - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - NULL AS i_category ,NULL AS i_class, 1 as t_category, 1 as t_class, 2 as lochierarchy from results) - select - gross_margin ,i_category ,i_class, lochierarchy,rank() over ( - partition by lochierarchy, case when t_class = 0 then i_category end - order by gross_margin asc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then i_category end - ,rank_within_parent - limit 100; - --- end template query36a.tpl query 28 in stream 3 --- start template query37.tpl query 29 in stream 3 -select /* TPC-DS query37.tpl 0.31 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, catalog_sales - where i_current_price between 11 and 11 + 30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('2000-06-16' as date) and dateadd(day,60,cast('2000-06-16' as date)) - and i_manufact_id in (700,707,816,679) - and inv_quantity_on_hand between 100 and 500 - and cs_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query37.tpl query 29 in stream 3 --- start template query4.tpl query 30 in stream 3 -with /* TPC-DS query4.tpl 0.93 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(((ss_ext_list_price-ss_ext_wholesale_cost-ss_ext_discount_amt)+ss_ext_sales_price)/2) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((cs_ext_list_price-cs_ext_wholesale_cost-cs_ext_discount_amt)+cs_ext_sales_price)/2) ) year_total - ,'c' sale_type - from customer - ,catalog_sales - ,date_dim - where c_customer_sk = cs_bill_customer_sk - and cs_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year -union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((ws_ext_list_price-ws_ext_wholesale_cost-ws_ext_discount_amt)+ws_ext_sales_price)/2) ) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_preferred_cust_flag - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_c_firstyear - ,year_total t_c_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_c_secyear.customer_id - and t_s_firstyear.customer_id = t_c_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_c_firstyear.sale_type = 'c' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_c_secyear.sale_type = 'c' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 1998 - and t_s_secyear.dyear = 1998+1 - and t_c_firstyear.dyear = 1998 - and t_c_secyear.dyear = 1998+1 - and t_w_firstyear.dyear = 1998 - and t_w_secyear.dyear = 1998+1 - and t_s_firstyear.year_total > 0 - and t_c_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_preferred_cust_flag -limit 100; - --- end template query4.tpl query 30 in stream 3 --- start template query38.tpl query 31 in stream 3 -select /* TPC-DS query38.tpl 0.54 */ count(*) from ( - select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1184 and 1184 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1184 and 1184 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1184 and 1184 + 11 -) hot_cust -limit 100; - --- end template query38.tpl query 31 in stream 3 --- start template query66.tpl query 32 in stream 3 -select /* TPC-DS query66.tpl 0.39 */ - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - ,sum(jan_sales) as jan_sales - ,sum(feb_sales) as feb_sales - ,sum(mar_sales) as mar_sales - ,sum(apr_sales) as apr_sales - ,sum(may_sales) as may_sales - ,sum(jun_sales) as jun_sales - ,sum(jul_sales) as jul_sales - ,sum(aug_sales) as aug_sales - ,sum(sep_sales) as sep_sales - ,sum(oct_sales) as oct_sales - ,sum(nov_sales) as nov_sales - ,sum(dec_sales) as dec_sales - ,sum(jan_sales/w_warehouse_sq_ft) as jan_sales_per_sq_foot - ,sum(feb_sales/w_warehouse_sq_ft) as feb_sales_per_sq_foot - ,sum(mar_sales/w_warehouse_sq_ft) as mar_sales_per_sq_foot - ,sum(apr_sales/w_warehouse_sq_ft) as apr_sales_per_sq_foot - ,sum(may_sales/w_warehouse_sq_ft) as may_sales_per_sq_foot - ,sum(jun_sales/w_warehouse_sq_ft) as jun_sales_per_sq_foot - ,sum(jul_sales/w_warehouse_sq_ft) as jul_sales_per_sq_foot - ,sum(aug_sales/w_warehouse_sq_ft) as aug_sales_per_sq_foot - ,sum(sep_sales/w_warehouse_sq_ft) as sep_sales_per_sq_foot - ,sum(oct_sales/w_warehouse_sq_ft) as oct_sales_per_sq_foot - ,sum(nov_sales/w_warehouse_sq_ft) as nov_sales_per_sq_foot - ,sum(dec_sales/w_warehouse_sq_ft) as dec_sales_per_sq_foot - ,sum(jan_net) as jan_net - ,sum(feb_net) as feb_net - ,sum(mar_net) as mar_net - ,sum(apr_net) as apr_net - ,sum(may_net) as may_net - ,sum(jun_net) as jun_net - ,sum(jul_net) as jul_net - ,sum(aug_net) as aug_net - ,sum(sep_net) as sep_net - ,sum(oct_net) as oct_net - ,sum(nov_net) as nov_net - ,sum(dec_net) as dec_net - from ( - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'BOXBUNDLES' || ',' || 'ZOUROS' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then ws_ext_list_price* ws_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then ws_ext_list_price* ws_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then ws_ext_list_price* ws_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then ws_ext_list_price* ws_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then ws_ext_list_price* ws_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then ws_ext_list_price* ws_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then ws_ext_list_price* ws_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then ws_ext_list_price* ws_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then ws_ext_list_price* ws_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then ws_ext_list_price* ws_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then ws_ext_list_price* ws_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then ws_ext_list_price* ws_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then ws_net_paid_inc_ship * ws_quantity else 0 end) as dec_net - from - web_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - ws_warehouse_sk = w_warehouse_sk - and ws_sold_date_sk = d_date_sk - and ws_sold_time_sk = t_time_sk - and ws_ship_mode_sk = sm_ship_mode_sk - and d_year = 1999 - and t_time between 7680 and 7680+28800 - and sm_carrier in ('BOXBUNDLES','ZOUROS') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - union all - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'BOXBUNDLES' || ',' || 'ZOUROS' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then cs_ext_list_price* cs_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then cs_ext_list_price* cs_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then cs_ext_list_price* cs_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then cs_ext_list_price* cs_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then cs_ext_list_price* cs_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then cs_ext_list_price* cs_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then cs_ext_list_price* cs_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then cs_ext_list_price* cs_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then cs_ext_list_price* cs_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then cs_ext_list_price* cs_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then cs_ext_list_price* cs_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then cs_ext_list_price* cs_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then cs_net_paid_inc_tax * cs_quantity else 0 end) as dec_net - from - catalog_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and cs_sold_time_sk = t_time_sk - and cs_ship_mode_sk = sm_ship_mode_sk - and d_year = 1999 - and t_time between 7680 AND 7680+28800 - and sm_carrier in ('BOXBUNDLES','ZOUROS') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - ) x - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - order by w_warehouse_name - limit 100; - --- end template query66.tpl query 32 in stream 3 --- start template query78.tpl query 33 in stream 3 -with /* TPC-DS query78.tpl 0.10 */ ws as - (select d_year AS ws_sold_year, ws_item_sk, - ws_bill_customer_sk ws_customer_sk, - sum(ws_quantity) ws_qty, - sum(ws_wholesale_cost) ws_wc, - sum(ws_sales_price) ws_sp - from web_sales - left join web_returns on wr_order_number=ws_order_number and ws_item_sk=wr_item_sk - join date_dim on ws_sold_date_sk = d_date_sk - where wr_order_number is null - group by d_year, ws_item_sk, ws_bill_customer_sk - ), -cs as - (select d_year AS cs_sold_year, cs_item_sk, - cs_bill_customer_sk cs_customer_sk, - sum(cs_quantity) cs_qty, - sum(cs_wholesale_cost) cs_wc, - sum(cs_sales_price) cs_sp - from catalog_sales - left join catalog_returns on cr_order_number=cs_order_number and cs_item_sk=cr_item_sk - join date_dim on cs_sold_date_sk = d_date_sk - where cr_order_number is null - group by d_year, cs_item_sk, cs_bill_customer_sk - ), -ss as - (select d_year AS ss_sold_year, ss_item_sk, - ss_customer_sk, - sum(ss_quantity) ss_qty, - sum(ss_wholesale_cost) ss_wc, - sum(ss_sales_price) ss_sp - from store_sales - left join store_returns on sr_ticket_number=ss_ticket_number and ss_item_sk=sr_item_sk - join date_dim on ss_sold_date_sk = d_date_sk - where sr_ticket_number is null - group by d_year, ss_item_sk, ss_customer_sk - ) - select -ss_sold_year, -round(ss_qty/(coalesce(ws_qty,0)+coalesce(cs_qty,0)),2) ratio, -ss_qty store_qty, ss_wc store_wholesale_cost, ss_sp store_sales_price, -coalesce(ws_qty,0)+coalesce(cs_qty,0) other_chan_qty, -coalesce(ws_wc,0)+coalesce(cs_wc,0) other_chan_wholesale_cost, -coalesce(ws_sp,0)+coalesce(cs_sp,0) other_chan_sales_price -from ss -left join ws on (ws_sold_year=ss_sold_year and ws_item_sk=ss_item_sk and ws_customer_sk=ss_customer_sk) -left join cs on (cs_sold_year=ss_sold_year and cs_item_sk=ss_item_sk and cs_customer_sk=ss_customer_sk) -where (coalesce(ws_qty,0)>0 or coalesce(cs_qty, 0)>0) and ss_sold_year=1999 -order by - ss_sold_year, - ss_qty desc, ss_wc desc, ss_sp desc, - other_chan_qty, - other_chan_wholesale_cost, - other_chan_sales_price, - ratio -limit 100; - --- end template query78.tpl query 33 in stream 3 --- start template query43.tpl query 34 in stream 3 -select /* TPC-DS query43.tpl 0.15 */ s_store_name, s_store_id, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from date_dim, store_sales, store - where d_date_sk = ss_sold_date_sk and - s_store_sk = ss_store_sk and - s_gmt_offset = -5 and - d_year = 2000 - group by s_store_name, s_store_id - order by s_store_name, s_store_id,sun_sales,mon_sales,tue_sales,wed_sales,thu_sales,fri_sales,sat_sales - limit 100; - --- end template query43.tpl query 34 in stream 3 --- start template query22a.tpl query 35 in stream 3 -with /* TPC-DS query22a.tpl 0.55 */ results as -(select i_product_name - ,i_brand - ,i_class - ,i_category - ,avg(inv_quantity_on_hand) qoh - from inventory - ,date_dim - ,item --- ,warehouse - where inv_date_sk=d_date_sk - and inv_item_sk=i_item_sk --- and inv_warehouse_sk = w_warehouse_sk - and d_month_seq between 1178 and 1178 + 11 - group by i_product_name,i_brand,i_class,i_category), -results_rollup as -(select i_product_name, i_brand, i_class, i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class,i_category -union all -select i_product_name, i_brand, i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class -union all -select i_product_name, i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand -union all -select i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name -union all -select null i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results) - select i_product_name, i_brand, i_class, i_category,qoh - from results_rollup - order by qoh, i_product_name, i_brand, i_class, i_category -limit 100; - --- end template query22a.tpl query 35 in stream 3 --- start template query21.tpl query 36 in stream 3 -select /* TPC-DS query21.tpl 0.14 */ * - from(select w_warehouse_name - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('2000-03-14' as date)) - then inv_quantity_on_hand - else 0 end) as inv_before - ,sum(case when (cast(d_date as date) >= cast ('2000-03-14' as date)) - then inv_quantity_on_hand - else 0 end) as inv_after - from inventory - ,warehouse - ,item - ,date_dim - where i_current_price between 0.99 and 1.49 - and i_item_sk = inv_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('2000-03-14' as date)) - and dateadd(day,30,cast ('2000-03-14' as date)) - group by w_warehouse_name, i_item_id) x - where (case when inv_before > 0 - then inv_after / inv_before - else null - end) between 2.0/3.0 and 3.0/2.0 - order by w_warehouse_name - ,i_item_id - limit 100; - --- end template query21.tpl query 36 in stream 3 --- start template query97.tpl query 37 in stream 3 -with /* TPC-DS query97.tpl 0.38 */ ssci as ( -select ss_customer_sk customer_sk - ,ss_item_sk item_sk -from store_sales,date_dim -where ss_sold_date_sk = d_date_sk - and d_month_seq between 1182 and 1182 + 11 -group by ss_customer_sk - ,ss_item_sk), -csci as( - select cs_bill_customer_sk customer_sk - ,cs_item_sk item_sk -from catalog_sales,date_dim -where cs_sold_date_sk = d_date_sk - and d_month_seq between 1182 and 1182 + 11 -group by cs_bill_customer_sk - ,cs_item_sk) - select sum(case when ssci.customer_sk is not null and csci.customer_sk is null then 1 else 0 end) store_only - ,sum(case when ssci.customer_sk is null and csci.customer_sk is not null then 1 else 0 end) catalog_only - ,sum(case when ssci.customer_sk is not null and csci.customer_sk is not null then 1 else 0 end) store_and_catalog -from ssci full outer join csci on (ssci.customer_sk=csci.customer_sk - and ssci.item_sk = csci.item_sk) -limit 100; - --- end template query97.tpl query 37 in stream 3 --- start template query47.tpl query 38 in stream 3 -with /* TPC-DS query47.tpl 0.42 */ v1 as( - select i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, - s_store_name, s_company_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - s_store_name, s_company_name - order by d_year, d_moy) rn - from item, store_sales, date_dim, store - where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - ( - d_year = 1999 or - ( d_year = 1999-1 and d_moy =12) or - ( d_year = 1999+1 and d_moy =1) - ) - group by i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy), - v2 as( - select v1.i_category, v1.i_brand - ,v1.d_year, v1.d_moy - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1.s_store_name = v1_lag.s_store_name and - v1.s_store_name = v1_lead.s_store_name and - v1.s_company_name = v1_lag.s_company_name and - v1.s_company_name = v1_lead.s_company_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 1999 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, sum_sales - limit 100; - --- end template query47.tpl query 38 in stream 3 --- start template query29.tpl query 39 in stream 3 -select /* TPC-DS query29.tpl 0.53 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,stddev_samp(ss_quantity) as store_sales_quantity - ,stddev_samp(sr_return_quantity) as store_returns_quantity - ,stddev_samp(cs_quantity) as catalog_sales_quantity - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 2000 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 4 + 3 - and d2.d_year = 2000 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_year in (2000,2000+1,2000+2) - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query29.tpl query 39 in stream 3 --- start template query3.tpl query 40 in stream 3 -select /* TPC-DS query3.tpl 0.45 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_sales_price) sum_agg - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manufact_id = 307 - and dt.d_moy=12 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,sum_agg desc - ,brand_id - limit 100; - --- end template query3.tpl query 40 in stream 3 --- start template query76.tpl query 41 in stream 3 -select /* TPC-DS query76.tpl 0.99 */ channel, col_name, d_year, d_qoy, i_category, COUNT(*) sales_cnt, SUM(ext_sales_price) sales_amt FROM ( - SELECT 'store' as channel, 'ss_promo_sk' col_name, d_year, d_qoy, i_category, ss_ext_sales_price ext_sales_price - FROM store_sales, item, date_dim - WHERE ss_promo_sk IS NULL - AND ss_sold_date_sk=d_date_sk - AND ss_item_sk=i_item_sk - UNION ALL - SELECT 'web' as channel, 'ws_web_page_sk' col_name, d_year, d_qoy, i_category, ws_ext_sales_price ext_sales_price - FROM web_sales, item, date_dim - WHERE ws_web_page_sk IS NULL - AND ws_sold_date_sk=d_date_sk - AND ws_item_sk=i_item_sk - UNION ALL - SELECT 'catalog' as channel, 'cs_ship_customer_sk' col_name, d_year, d_qoy, i_category, cs_ext_sales_price ext_sales_price - FROM catalog_sales, item, date_dim - WHERE cs_ship_customer_sk IS NULL - AND cs_sold_date_sk=d_date_sk - AND cs_item_sk=i_item_sk) foo -GROUP BY channel, col_name, d_year, d_qoy, i_category -ORDER BY channel, col_name, d_year, d_qoy, i_category -limit 100; - --- end template query76.tpl query 41 in stream 3 --- start template query82.tpl query 42 in stream 3 -select /* TPC-DS query82.tpl 0.67 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, store_sales - where i_current_price between 44 and 44+30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('2000-05-07' as date) and dateadd(day,60,cast('2000-05-07' as date)) - and i_manufact_id in (929,95,341,793) - and inv_quantity_on_hand between 100 and 500 - and ss_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query82.tpl query 42 in stream 3 --- start template query46.tpl query 43 in stream 3 -select /* TPC-DS query46.tpl 0.23 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and (household_demographics.hd_dep_count = 0 or - household_demographics.hd_vehicle_count= -1) - and date_dim.d_dow in (6,0) - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_city in ('Shady Grove','Pleasant Grove','Oakdale','New Hope','Walnut Grove') - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,ca_city) dn,customer,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - limit 100; - --- end template query46.tpl query 43 in stream 3 --- start template query41.tpl query 44 in stream 3 -select /* TPC-DS query41.tpl 0.62 */ distinct(i_product_name) - from item i1 - where i_manufact_id between 981 and 981+40 - and (select count(*) as item_cnt - from item - where (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'maroon' or i_color = 'magenta') and - (i_units = 'Pound' or i_units = 'Each') and - (i_size = 'N/A' or i_size = 'petite') - ) or - (i_category = 'Women' and - (i_color = 'turquoise' or i_color = 'cyan') and - (i_units = 'Cup' or i_units = 'Unknown') and - (i_size = 'economy' or i_size = 'large') - ) or - (i_category = 'Men' and - (i_color = 'purple' or i_color = 'lavender') and - (i_units = 'Lb' or i_units = 'Box') and - (i_size = 'small' or i_size = 'medium') - ) or - (i_category = 'Men' and - (i_color = 'dodger' or i_color = 'azure') and - (i_units = 'Bunch' or i_units = 'Dozen') and - (i_size = 'N/A' or i_size = 'petite') - ))) or - (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'royal' or i_color = 'chartreuse') and - (i_units = 'Bundle' or i_units = 'Ounce') and - (i_size = 'N/A' or i_size = 'petite') - ) or - (i_category = 'Women' and - (i_color = 'sienna' or i_color = 'ivory') and - (i_units = 'Tsp' or i_units = 'Tbl') and - (i_size = 'economy' or i_size = 'large') - ) or - (i_category = 'Men' and - (i_color = 'sandy' or i_color = 'hot') and - (i_units = 'Oz' or i_units = 'Case') and - (i_size = 'small' or i_size = 'medium') - ) or - (i_category = 'Men' and - (i_color = 'orange' or i_color = 'blanched') and - (i_units = 'Ton' or i_units = 'Dram') and - (i_size = 'N/A' or i_size = 'petite') - )))) > 0 - order by i_product_name - limit 100; - --- end template query41.tpl query 44 in stream 3 --- start template query59.tpl query 45 in stream 3 -with /* TPC-DS query59.tpl 0.30 */ wss as - (select d_week_seq, - ss_store_sk, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - group by d_week_seq,ss_store_sk - ) - select s_store_name1,s_store_id1,d_week_seq1 - ,sun_sales1/sun_sales2,mon_sales1/mon_sales2 - ,tue_sales1/tue_sales2,wed_sales1/wed_sales2,thu_sales1/thu_sales2 - ,fri_sales1/fri_sales2,sat_sales1/sat_sales2 - from - (select s_store_name s_store_name1,wss.d_week_seq d_week_seq1 - ,s_store_id s_store_id1,sun_sales sun_sales1 - ,mon_sales mon_sales1,tue_sales tue_sales1 - ,wed_sales wed_sales1,thu_sales thu_sales1 - ,fri_sales fri_sales1,sat_sales sat_sales1 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1209 and 1209 + 11) y, - (select s_store_name s_store_name2,wss.d_week_seq d_week_seq2 - ,s_store_id s_store_id2,sun_sales sun_sales2 - ,mon_sales mon_sales2,tue_sales tue_sales2 - ,wed_sales wed_sales2,thu_sales thu_sales2 - ,fri_sales fri_sales2,sat_sales sat_sales2 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1209+ 12 and 1209 + 23) x - where s_store_id1=s_store_id2 - and d_week_seq1=d_week_seq2-52 - order by s_store_name1,s_store_id1,d_week_seq1 -limit 100; - --- end template query59.tpl query 45 in stream 3 --- start template query40.tpl query 46 in stream 3 -select /* TPC-DS query40.tpl 0.86 */ - w_state - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('1998-05-07' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_before - ,sum(case when (cast(d_date as date) >= cast ('1998-05-07' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_after - from - catalog_sales left outer join catalog_returns on - (cs_order_number = cr_order_number - and cs_item_sk = cr_item_sk) - ,warehouse - ,item - ,date_dim - where - i_current_price between 0.99 and 1.49 - and i_item_sk = cs_item_sk - and cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('1998-05-07' as date)) - and dateadd(day,30,cast ('1998-05-07' as date)) - group by - w_state,i_item_id - order by w_state,i_item_id -limit 100; - --- end template query40.tpl query 46 in stream 3 --- start template query55.tpl query 47 in stream 3 -select /* TPC-DS query55.tpl 0.82 */ i_brand_id brand_id, i_brand brand, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=62 - and d_moy=12 - and d_year=2000 - group by i_brand, i_brand_id - order by ext_price desc, i_brand_id -limit 100 ; - --- end template query55.tpl query 47 in stream 3 --- start template query16.tpl query 48 in stream 3 -select /* TPC-DS query16.tpl 0.25 */ - count(distinct cs_order_number) as "order count" - ,sum(cs_ext_ship_cost) as "total shipping cost" - ,sum(cs_net_profit) as "total net profit" -from - catalog_sales cs1 - ,date_dim - ,customer_address - ,call_center -where - d_date between '2001-5-01' and - dateadd(day, 60, cast('2001-5-01' as date)) -and cs1.cs_ship_date_sk = d_date_sk -and cs1.cs_ship_addr_sk = ca_address_sk -and ca_state = 'CA' -and cs1.cs_call_center_sk = cc_call_center_sk -and cc_county in ('Mobile County','Huron County','Ziebach County','Franklin Parish', - 'Kittitas County' -) -and exists (select * - from catalog_sales cs2 - where cs1.cs_order_number = cs2.cs_order_number - and cs1.cs_warehouse_sk <> cs2.cs_warehouse_sk) -and not exists(select * - from catalog_returns cr1 - where cs1.cs_order_number = cr1.cr_order_number) -order by count(distinct cs_order_number) -limit 100; - --- end template query16.tpl query 48 in stream 3 --- start template query27a.tpl query 49 in stream 3 -with /* TPC-DS query27a.tpl 0.16 */ results as - (select i_item_id, - s_state, 0 as g_state, - ss_quantity agg1, - ss_list_price agg2, - ss_coupon_amt agg3, - ss_sales_price agg4 - from store_sales, customer_demographics, date_dim, store, item - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_store_sk = s_store_sk and - ss_cdemo_sk = cd_demo_sk and - cd_gender = 'M' and - cd_marital_status = 'U' and - cd_education_status = 'Advanced Degree' and - d_year = 2001 and - s_state in ('SC','FL', 'MN', 'GA', 'LA', 'AL') - ) - - select i_item_id, - s_state, g_state, agg1, agg2, agg3, agg4 - from ( - select i_item_id, s_state, 0 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4 from results - group by i_item_id, s_state - union all - select i_item_id, NULL AS s_state, 1 AS g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as s_state, 1 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - ) foo - order by i_item_id, s_state - limit 100; - --- end template query27a.tpl query 49 in stream 3 --- start template query54.tpl query 50 in stream 3 -with /* TPC-DS query54.tpl 0.81 */ my_customers as ( - select distinct c_customer_sk - , c_current_addr_sk - from - ( select cs_sold_date_sk sold_date_sk, - cs_bill_customer_sk customer_sk, - cs_item_sk item_sk - from catalog_sales - union all - select ws_sold_date_sk sold_date_sk, - ws_bill_customer_sk customer_sk, - ws_item_sk item_sk - from web_sales - ) cs_or_ws_sales, - item, - date_dim, - customer - where sold_date_sk = d_date_sk - and item_sk = i_item_sk - and i_category = 'Books' - and i_class = 'romance' - and c_customer_sk = cs_or_ws_sales.customer_sk - and d_moy = 2 - and d_year = 2000 - ) - , my_revenue as ( - select c_customer_sk, - sum(ss_ext_sales_price) as revenue - from my_customers, - store_sales, - customer_address, - store, - date_dim - where c_current_addr_sk = ca_address_sk - and ca_county = s_county - and ca_state = s_state - and ss_sold_date_sk = d_date_sk - and c_customer_sk = ss_customer_sk - and d_month_seq between (select distinct d_month_seq+1 - from date_dim where d_year = 2000 and d_moy = 2) - and (select distinct d_month_seq+3 - from date_dim where d_year = 2000 and d_moy = 2) - group by c_customer_sk - ) - , segments as - (select cast((revenue/50) as bigint) as segment - from my_revenue - ) - select segment, count(*) as num_customers, segment*50 as segment_base - from segments - group by segment - order by segment, num_customers - limit 100; - --- end template query54.tpl query 50 in stream 3 --- start template query90.tpl query 51 in stream 3 -select /* TPC-DS query90.tpl 0.40 */ cast(amc as decimal(15,4))/cast(pmc as decimal(15,4)) am_pm_ratio - from ( select count(*) amc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 7 and 7+1 - and household_demographics.hd_dep_count = 3 - and web_page.wp_char_count between 5000 and 5200) at, - ( select count(*) pmc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 21 and 21+1 - and household_demographics.hd_dep_count = 3 - and web_page.wp_char_count between 5000 and 5200) pt - order by am_pm_ratio - limit 100; - --- end template query90.tpl query 51 in stream 3 --- start template query92.tpl query 52 in stream 3 -select /* TPC-DS query92.tpl 0.44 */ - sum(ws_ext_discount_amt) as "Excess Discount Amount" -from - web_sales - ,item - ,date_dim -where -i_manufact_id = 36 -and i_item_sk = ws_item_sk -and d_date between '2001-03-15' and - dateadd(day,90,cast('2001-03-15' as date)) -and d_date_sk = ws_sold_date_sk -and ws_ext_discount_amt - > ( - SELECT - 1.3 * avg(ws_ext_discount_amt) - FROM - web_sales - ,date_dim - WHERE - ws_item_sk = i_item_sk - and d_date between '2001-03-15' and - dateadd(day,90,cast('2001-03-15' as date)) - and d_date_sk = ws_sold_date_sk - ) -order by sum(ws_ext_discount_amt) -limit 100; - --- end template query92.tpl query 52 in stream 3 --- start template query31.tpl query 53 in stream 3 -with /* TPC-DS query31.tpl 0.50 */ ss as - (select ca_county,d_qoy, d_year,sum(ss_ext_sales_price) as store_sales - from store_sales,date_dim,customer_address - where ss_sold_date_sk = d_date_sk - and ss_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year), - ws as - (select ca_county,d_qoy, d_year,sum(ws_ext_sales_price) as web_sales - from web_sales,date_dim,customer_address - where ws_sold_date_sk = d_date_sk - and ws_bill_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year) - select - ss1.ca_county - ,ss1.d_year - ,ws2.web_sales/ws1.web_sales web_q1_q2_increase - ,ss2.store_sales/ss1.store_sales store_q1_q2_increase - ,ws3.web_sales/ws2.web_sales web_q2_q3_increase - ,ss3.store_sales/ss2.store_sales store_q2_q3_increase - from - ss ss1 - ,ss ss2 - ,ss ss3 - ,ws ws1 - ,ws ws2 - ,ws ws3 - where - ss1.d_qoy = 1 - and ss1.d_year = 2002 - and ss1.ca_county = ss2.ca_county - and ss2.d_qoy = 2 - and ss2.d_year = 2002 - and ss2.ca_county = ss3.ca_county - and ss3.d_qoy = 3 - and ss3.d_year = 2002 - and ss1.ca_county = ws1.ca_county - and ws1.d_qoy = 1 - and ws1.d_year = 2002 - and ws1.ca_county = ws2.ca_county - and ws2.d_qoy = 2 - and ws2.d_year = 2002 - and ws1.ca_county = ws3.ca_county - and ws3.d_qoy = 3 - and ws3.d_year =2002 - and case when ws1.web_sales > 0 then ws2.web_sales/ws1.web_sales else null end - > case when ss1.store_sales > 0 then ss2.store_sales/ss1.store_sales else null end - and case when ws2.web_sales > 0 then ws3.web_sales/ws2.web_sales else null end - > case when ss2.store_sales > 0 then ss3.store_sales/ss2.store_sales else null end - order by store_q2_q3_increase; - --- end template query31.tpl query 53 in stream 3 --- start template query42.tpl query 54 in stream 3 -select /* TPC-DS query42.tpl 0.61 */ dt.d_year - ,item.i_category_id - ,item.i_category - ,sum(ss_ext_sales_price) - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=11 - and dt.d_year=1999 - group by dt.d_year - ,item.i_category_id - ,item.i_category - order by sum(ss_ext_sales_price) desc,dt.d_year - ,item.i_category_id - ,item.i_category -limit 100 ; - --- end template query42.tpl query 54 in stream 3 --- start template query26.tpl query 55 in stream 3 -select /* TPC-DS query26.tpl 0.85 */ i_item_id, - avg(cs_quantity) agg1, - avg(cs_list_price) agg2, - avg(cs_coupon_amt) agg3, - avg(cs_sales_price) agg4 - from catalog_sales, customer_demographics, date_dim, item, promotion - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd_demo_sk and - cs_promo_sk = p_promo_sk and - cd_gender = 'F' and - cd_marital_status = 'M' and - cd_education_status = '2 yr Degree' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 2000 - group by i_item_id - order by i_item_id - limit 100; - --- end template query26.tpl query 55 in stream 3 --- start template query34.tpl query 56 in stream 3 -select /* TPC-DS query34.tpl 0.73 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (date_dim.d_dom between 1 and 3 or date_dim.d_dom between 25 and 28) - and (household_demographics.hd_buy_potential = '1001-5000' or - household_demographics.hd_buy_potential = 'Unknown') - and household_demographics.hd_vehicle_count > 0 - and (case when household_demographics.hd_vehicle_count > 0 - then household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count - else null - end) > 1.2 - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_county in ('Dauphin County','Mesa County','Walker County','Luce County', - 'Huron County','Wadena County','Mobile County','Daviess County') - group by ss_ticket_number,ss_customer_sk) dn,customer - where ss_customer_sk = c_customer_sk - and cnt between 15 and 20 - order by c_last_name,c_first_name,c_salutation,c_preferred_cust_flag desc, ss_ticket_number; - --- end template query34.tpl query 56 in stream 3 --- start template query68.tpl query 57 in stream 3 -select /* TPC-DS query68.tpl 0.95 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,extended_price - ,extended_tax - ,list_price - from (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_ext_sales_price) extended_price - ,sum(ss_ext_list_price) list_price - ,sum(ss_ext_tax) extended_tax - from store_sales - ,date_dim - ,store - ,household_demographics - ,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_dep_count = 2 or - household_demographics.hd_vehicle_count= -1) - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_city in ('Mount Vernon','Union') - group by ss_ticket_number - ,ss_customer_sk - ,ss_addr_sk,ca_city) dn - ,customer - ,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,ss_ticket_number - limit 100; - --- end template query68.tpl query 57 in stream 3 --- start template query2.tpl query 58 in stream 3 -with /* TPC-DS query2.tpl 0.84 */ wscs as - (select sold_date_sk - ,sales_price - from (select ws_sold_date_sk sold_date_sk - ,ws_ext_sales_price sales_price - from web_sales - union all - select cs_sold_date_sk sold_date_sk - ,cs_ext_sales_price sales_price - from catalog_sales)), - wswscs as - (select d_week_seq, - sum(case when (d_day_name='Sunday') then sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then sales_price else null end) sat_sales - from wscs - ,date_dim - where d_date_sk = sold_date_sk - group by d_week_seq) - select d_week_seq1 - ,round(sun_sales1/sun_sales2,2) - ,round(mon_sales1/mon_sales2,2) - ,round(tue_sales1/tue_sales2,2) - ,round(wed_sales1/wed_sales2,2) - ,round(thu_sales1/thu_sales2,2) - ,round(fri_sales1/fri_sales2,2) - ,round(sat_sales1/sat_sales2,2) - from - (select wswscs.d_week_seq d_week_seq1 - ,sun_sales sun_sales1 - ,mon_sales mon_sales1 - ,tue_sales tue_sales1 - ,wed_sales wed_sales1 - ,thu_sales thu_sales1 - ,fri_sales fri_sales1 - ,sat_sales sat_sales1 - from wswscs,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 2000) y, - (select wswscs.d_week_seq d_week_seq2 - ,sun_sales sun_sales2 - ,mon_sales mon_sales2 - ,tue_sales tue_sales2 - ,wed_sales wed_sales2 - ,thu_sales thu_sales2 - ,fri_sales fri_sales2 - ,sat_sales sat_sales2 - from wswscs - ,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 2000+1) z - where d_week_seq1=d_week_seq2-53 - order by d_week_seq1; - --- end template query2.tpl query 58 in stream 3 --- start template query44.tpl query 59 in stream 3 -select /* TPC-DS query44.tpl 0.4 */ asceding.rnk, i1.i_product_name best_performing, i2.i_product_name worst_performing -from(select * - from (select item_sk,rank() over (order by rank_col asc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 267 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 267 - and ss_promo_sk is null - group by ss_store_sk))V1)V11 - where rnk < 11) asceding, - (select * - from (select item_sk,rank() over (order by rank_col desc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 267 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 267 - and ss_promo_sk is null - group by ss_store_sk))V2)V21 - where rnk < 11) descending, -item i1, -item i2 -where asceding.rnk = descending.rnk - and i1.i_item_sk=asceding.item_sk - and i2.i_item_sk=descending.item_sk -order by asceding.rnk -limit 100; - --- end template query44.tpl query 59 in stream 3 --- start template query81.tpl query 60 in stream 3 -with /* TPC-DS query81.tpl 0.37 */ customer_total_return as - (select cr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(cr_return_amt_inc_tax) as ctr_total_return - from catalog_returns - ,date_dim - ,customer_address - where cr_returned_date_sk = d_date_sk - and d_year =2002 - and cr_returning_addr_sk = ca_address_sk - group by cr_returning_customer_sk - ,ca_state ) - select c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'LA' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - limit 100; - --- end template query81.tpl query 60 in stream 3 --- start template query67a.tpl query 61 in stream 3 -with /* TPC-DS query67a.tpl 0.35 */ results as -( select i_category ,i_class ,i_brand ,i_product_name ,d_year ,d_qoy ,d_moy ,s_store_id - ,sum(coalesce(ss_sales_price*ss_quantity,0)) sumsales - from store_sales ,date_dim ,store ,item - where ss_sold_date_sk=d_date_sk - and ss_item_sk=i_item_sk - and ss_store_sk = s_store_sk - and d_month_seq between 1191 and 1191 + 11 - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy,s_store_id) - , - results_rollup as - (select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, s_store_id, sumsales - from results - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy - union all - select i_category, i_class, i_brand, i_product_name, d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year - union all - select i_category, i_class, i_brand, i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name - union all - select i_category, i_class, i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand - union all - select i_category, i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class - union all - select i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category - union all - select null i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results) - - select * -from (select i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rank() over (partition by i_category order by sumsales desc) rk - from results_rollup) dw2 -where rk <= 100 -order by i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rk -limit 100; - --- end template query67a.tpl query 61 in stream 3 --- start template query99.tpl query 62 in stream 3 -select /* TPC-DS query99.tpl 0.94 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 30) and - (cs_ship_date_sk - cs_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 60) and - (cs_ship_date_sk - cs_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 90) and - (cs_ship_date_sk - cs_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - catalog_sales - ,warehouse - ,ship_mode - ,call_center - ,date_dim -where - d_month_seq between 1194 and 1194 + 11 -and cs_ship_date_sk = d_date_sk -and cs_warehouse_sk = w_warehouse_sk -and cs_ship_mode_sk = sm_ship_mode_sk -and cs_call_center_sk = cc_call_center_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -limit 100; - --- end template query99.tpl query 62 in stream 3 --- start template query6.tpl query 63 in stream 3 -select /* TPC-DS query6.tpl 0.58 */ a.ca_state state, count(*) cnt - from customer_address a - ,customer c - ,store_sales s - ,date_dim d - ,item i - where a.ca_address_sk = c.c_current_addr_sk - and c.c_customer_sk = s.ss_customer_sk - and s.ss_sold_date_sk = d.d_date_sk - and s.ss_item_sk = i.i_item_sk - and d.d_month_seq = - (select distinct (d_month_seq) - from date_dim - where d_year = 2002 - and d_moy = 5 ) - and i.i_current_price > 1.2 * - (select avg(j.i_current_price) - from item j - where j.i_category = i.i_category) - group by a.ca_state - having count(*) >= 10 - order by cnt, a.ca_state - limit 100; - --- end template query6.tpl query 63 in stream 3 --- start template query83.tpl query 64 in stream 3 -with /* TPC-DS query83.tpl 0.96 */ sr_items as - (select i_item_id item_id, - sum(sr_return_quantity) sr_item_qty - from store_returns, - item, - date_dim - where sr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('1999-05-17','1999-10-01','1999-11-13'))) - and sr_returned_date_sk = d_date_sk - group by i_item_id), - cr_items as - (select i_item_id item_id, - sum(cr_return_quantity) cr_item_qty - from catalog_returns, - item, - date_dim - where cr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('1999-05-17','1999-10-01','1999-11-13'))) - and cr_returned_date_sk = d_date_sk - group by i_item_id), - wr_items as - (select i_item_id item_id, - sum(wr_return_quantity) wr_item_qty - from web_returns, - item, - date_dim - where wr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('1999-05-17','1999-10-01','1999-11-13'))) - and wr_returned_date_sk = d_date_sk - group by i_item_id) - select sr_items.item_id - ,sr_item_qty - ,sr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 sr_dev - ,cr_item_qty - ,cr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 cr_dev - ,wr_item_qty - ,wr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 wr_dev - ,(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 average - from sr_items - ,cr_items - ,wr_items - where sr_items.item_id=cr_items.item_id - and sr_items.item_id=wr_items.item_id - order by sr_items.item_id - ,sr_item_qty - limit 100; - --- end template query83.tpl query 64 in stream 3 --- start template query1.tpl query 65 in stream 3 -with /* TPC-DS query1.tpl 0.12 */ customer_total_return as -(select sr_customer_sk as ctr_customer_sk -,sr_store_sk as ctr_store_sk -,sum(SR_REVERSED_CHARGE) as ctr_total_return -from store_returns -,date_dim -where sr_returned_date_sk = d_date_sk -and d_year =1999 -group by sr_customer_sk -,sr_store_sk) - select c_customer_id -from customer_total_return ctr1 -,store -,customer -where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 -from customer_total_return ctr2 -where ctr1.ctr_store_sk = ctr2.ctr_store_sk) -and s_store_sk = ctr1.ctr_store_sk -and s_state = 'SC' -and ctr1.ctr_customer_sk = c_customer_sk -order by c_customer_id -limit 100; - --- end template query1.tpl query 65 in stream 3 --- start template query60.tpl query 66 in stream 3 -with /* TPC-DS query60.tpl 0.29 */ ss as ( - select - i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Music')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 9 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - cs as ( - select - i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Music')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 9 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - ws as ( - select - i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Music')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 9 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id) - select - i_item_id -,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by i_item_id - ,total_sales - limit 100; - --- end template query60.tpl query 66 in stream 3 --- start template query33.tpl query 67 in stream 3 -with /* TPC-DS query33.tpl 0.22 */ ss as ( - select - i_manufact_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Books')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 3 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_manufact_id), - cs as ( - select - i_manufact_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Books')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 3 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_manufact_id), - ws as ( - select - i_manufact_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Books')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 3 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_manufact_id) - select i_manufact_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_manufact_id - order by total_sales -limit 100; - --- end template query33.tpl query 67 in stream 3 --- start template query11.tpl query 68 in stream 3 -with /* TPC-DS query11.tpl 0.51 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ss_ext_list_price-ss_ext_discount_amt) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ws_ext_list_price-ws_ext_discount_amt) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_login - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 2000 - and t_s_secyear.dyear = 2000+1 - and t_w_firstyear.dyear = 2000 - and t_w_secyear.dyear = 2000+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else 0.0 end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else 0.0 end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_login -limit 100; - --- end template query11.tpl query 68 in stream 3 --- start template query28.tpl query 69 in stream 3 -select /* TPC-DS query28.tpl 0.36 */ * -from (select avg(ss_list_price) B1_LP - ,count(ss_list_price) B1_CNT - ,count(distinct ss_list_price) B1_CNTD - from store_sales - where ss_quantity between 0 and 5 - and (ss_list_price between 146 and 146+10 - or ss_coupon_amt between 13140 and 13140+1000 - or ss_wholesale_cost between 26 and 26+20)) B1, - (select avg(ss_list_price) B2_LP - ,count(ss_list_price) B2_CNT - ,count(distinct ss_list_price) B2_CNTD - from store_sales - where ss_quantity between 6 and 10 - and (ss_list_price between 137 and 137+10 - or ss_coupon_amt between 1106 and 1106+1000 - or ss_wholesale_cost between 28 and 28+20)) B2, - (select avg(ss_list_price) B3_LP - ,count(ss_list_price) B3_CNT - ,count(distinct ss_list_price) B3_CNTD - from store_sales - where ss_quantity between 11 and 15 - and (ss_list_price between 47 and 47+10 - or ss_coupon_amt between 12671 and 12671+1000 - or ss_wholesale_cost between 20 and 20+20)) B3, - (select avg(ss_list_price) B4_LP - ,count(ss_list_price) B4_CNT - ,count(distinct ss_list_price) B4_CNTD - from store_sales - where ss_quantity between 16 and 20 - and (ss_list_price between 95 and 95+10 - or ss_coupon_amt between 8521 and 8521+1000 - or ss_wholesale_cost between 64 and 64+20)) B4, - (select avg(ss_list_price) B5_LP - ,count(ss_list_price) B5_CNT - ,count(distinct ss_list_price) B5_CNTD - from store_sales - where ss_quantity between 21 and 25 - and (ss_list_price between 175 and 175+10 - or ss_coupon_amt between 14193 and 14193+1000 - or ss_wholesale_cost between 79 and 79+20)) B5, - (select avg(ss_list_price) B6_LP - ,count(ss_list_price) B6_CNT - ,count(distinct ss_list_price) B6_CNTD - from store_sales - where ss_quantity between 26 and 30 - and (ss_list_price between 174 and 174+10 - or ss_coupon_amt between 7229 and 7229+1000 - or ss_wholesale_cost between 33 and 33+20)) B6 -limit 100; - --- end template query28.tpl query 69 in stream 3 --- start template query95.tpl query 70 in stream 3 -with /* TPC-DS query95.tpl 0.43 */ ws_wh as -(select ws1.ws_order_number,ws1.ws_warehouse_sk wh1,ws2.ws_warehouse_sk wh2 - from web_sales ws1,web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) - select - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2002-4-01' and - dateadd(day,60,cast('2002-4-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'FL' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and ws1.ws_order_number in (select ws_order_number - from ws_wh) -and ws1.ws_order_number in (select wr_order_number - from web_returns,ws_wh - where wr_order_number = ws_wh.ws_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query95.tpl query 70 in stream 3 --- start template query12.tpl query 71 in stream 3 -select /* TPC-DS query12.tpl 0.64 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ws_ext_sales_price) as itemrevenue - ,sum(ws_ext_sales_price)*100/sum(sum(ws_ext_sales_price)) over - (partition by i_class) as revenueratio -from - web_sales - ,item - ,date_dim -where - ws_item_sk = i_item_sk - and i_category in ('Children', 'Sports', 'Men') - and ws_sold_date_sk = d_date_sk - and d_date between cast('1998-02-10' as date) - and dateadd(day,30,cast('1998-02-10' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query12.tpl query 71 in stream 3 --- start template query64.tpl query 72 in stream 3 -with /* TPC-DS query64.tpl 0.20 */ cs_ui as - (select cs_item_sk - ,sum(cs_ext_list_price) as sale,sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit) as refund - from catalog_sales - ,catalog_returns - where cs_item_sk = cr_item_sk - and cs_order_number = cr_order_number - group by cs_item_sk - having sum(cs_ext_list_price)>2*sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit)), -cross_sales as - (select i_product_name product_name - ,i_item_sk item_sk - ,s_store_name store_name - ,s_zip store_zip - ,ad1.ca_street_number b_street_number - ,ad1.ca_street_name b_street_name - ,ad1.ca_city b_city - ,ad1.ca_zip b_zip - ,ad2.ca_street_number c_street_number - ,ad2.ca_street_name c_street_name - ,ad2.ca_city c_city - ,ad2.ca_zip c_zip - ,d1.d_year as syear - ,d2.d_year as fsyear - ,d3.d_year s2year - ,count(*) cnt - ,sum(ss_wholesale_cost) s1 - ,sum(ss_list_price) s2 - ,sum(ss_coupon_amt) s3 - FROM store_sales - ,store_returns - ,cs_ui - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,customer - ,customer_demographics cd1 - ,customer_demographics cd2 - ,promotion - ,household_demographics hd1 - ,household_demographics hd2 - ,customer_address ad1 - ,customer_address ad2 - ,income_band ib1 - ,income_band ib2 - ,item - WHERE ss_store_sk = s_store_sk AND - ss_sold_date_sk = d1.d_date_sk AND - ss_customer_sk = c_customer_sk AND - ss_cdemo_sk= cd1.cd_demo_sk AND - ss_hdemo_sk = hd1.hd_demo_sk AND - ss_addr_sk = ad1.ca_address_sk and - ss_item_sk = i_item_sk and - ss_item_sk = sr_item_sk and - ss_ticket_number = sr_ticket_number and - ss_item_sk = cs_ui.cs_item_sk and - c_current_cdemo_sk = cd2.cd_demo_sk AND - c_current_hdemo_sk = hd2.hd_demo_sk AND - c_current_addr_sk = ad2.ca_address_sk and - c_first_sales_date_sk = d2.d_date_sk and - c_first_shipto_date_sk = d3.d_date_sk and - ss_promo_sk = p_promo_sk and - hd1.hd_income_band_sk = ib1.ib_income_band_sk and - hd2.hd_income_band_sk = ib2.ib_income_band_sk and - cd1.cd_marital_status <> cd2.cd_marital_status and - i_color in ('light','burnished','sky','smoke','dodger','cornflower') and - i_current_price between 83 and 83 + 10 and - i_current_price between 83 + 1 and 83 + 15 -group by i_product_name - ,i_item_sk - ,s_store_name - ,s_zip - ,ad1.ca_street_number - ,ad1.ca_street_name - ,ad1.ca_city - ,ad1.ca_zip - ,ad2.ca_street_number - ,ad2.ca_street_name - ,ad2.ca_city - ,ad2.ca_zip - ,d1.d_year - ,d2.d_year - ,d3.d_year -) -select cs1.product_name - ,cs1.store_name - ,cs1.store_zip - ,cs1.b_street_number - ,cs1.b_street_name - ,cs1.b_city - ,cs1.b_zip - ,cs1.c_street_number - ,cs1.c_street_name - ,cs1.c_city - ,cs1.c_zip - ,cs1.syear - ,cs1.cnt - ,cs1.s1 as s11 - ,cs1.s2 as s21 - ,cs1.s3 as s31 - ,cs2.s1 as s12 - ,cs2.s2 as s22 - ,cs2.s3 as s32 - ,cs2.syear - ,cs2.cnt -from cross_sales cs1,cross_sales cs2 -where cs1.item_sk=cs2.item_sk and - cs1.syear = 2001 and - cs2.syear = 2001 + 1 and - cs2.cnt <= cs1.cnt and - cs1.store_name = cs2.store_name and - cs1.store_zip = cs2.store_zip -order by cs1.product_name - ,cs1.store_name - ,cs2.cnt - ,cs1.s1 - ,cs2.s1; - --- end template query64.tpl query 72 in stream 3 --- start template query15.tpl query 73 in stream 3 -select /* TPC-DS query15.tpl 0.57 */ ca_zip - ,sum(cs_sales_price) - from catalog_sales - ,customer - ,customer_address - ,date_dim - where cs_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', - '85392', '85460', '80348', '81792') - or ca_state in ('CA','WA','GA') - or cs_sales_price > 500) - and cs_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 1998 - group by ca_zip - order by ca_zip - limit 100; - --- end template query15.tpl query 73 in stream 3 --- start template query25.tpl query 74 in stream 3 -select /* TPC-DS query25.tpl 0.9 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,max(ss_net_profit) as store_sales_profit - ,max(sr_net_loss) as store_returns_loss - ,max(cs_net_profit) as catalog_sales_profit - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 2002 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 10 - and d2.d_year = 2002 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_moy between 4 and 10 - and d3.d_year = 2002 - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query25.tpl query 74 in stream 3 --- start template query93.tpl query 75 in stream 3 -select /* TPC-DS query93.tpl 0.52 */ ss_customer_sk - ,sum(act_sales) sumsales - from (select ss_item_sk - ,ss_ticket_number - ,ss_customer_sk - ,case when sr_return_quantity is not null then (ss_quantity-sr_return_quantity)*ss_sales_price - else (ss_quantity*ss_sales_price) end act_sales - from store_sales left outer join store_returns on (sr_item_sk = ss_item_sk - and sr_ticket_number = ss_ticket_number) - ,reason - where sr_reason_sk = r_reason_sk - and r_reason_desc = 'Package was damaged') t - group by ss_customer_sk - order by sumsales, ss_customer_sk -limit 100; - --- end template query93.tpl query 75 in stream 3 --- start template query9.tpl query 76 in stream 3 -select /* TPC-DS query9.tpl 0.49 */ case when (select count(*) - from store_sales - where ss_quantity between 1 and 20) > 47236180 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 1 and 20) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 1 and 20) end bucket1 , - case when (select count(*) - from store_sales - where ss_quantity between 21 and 40) > 5289053 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 21 and 40) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 21 and 40) end bucket2, - case when (select count(*) - from store_sales - where ss_quantity between 41 and 60) > 3676053 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 41 and 60) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 41 and 60) end bucket3, - case when (select count(*) - from store_sales - where ss_quantity between 61 and 80) > 4662835 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 61 and 80) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 61 and 80) end bucket4, - case when (select count(*) - from store_sales - where ss_quantity between 81 and 100) > 20199102 - then (select avg(ss_ext_tax) - from store_sales - where ss_quantity between 81 and 100) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 81 and 100) end bucket5 -from reason -where r_reason_sk = 1 -; - --- end template query9.tpl query 76 in stream 3 --- start template query65.tpl query 77 in stream 3 -select /* TPC-DS query65.tpl 0.71 */ - s_store_name, - i_item_desc, - sc.revenue, - i_current_price, - i_wholesale_cost, - i_brand - from store, item, - (select ss_store_sk, avg(revenue) as ave - from - (select ss_store_sk, ss_item_sk, - sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1180 and 1180+11 - group by ss_store_sk, ss_item_sk) sa - group by ss_store_sk) sb, - (select ss_store_sk, ss_item_sk, sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1180 and 1180+11 - group by ss_store_sk, ss_item_sk) sc - where sb.ss_store_sk = sc.ss_store_sk and - sc.revenue <= 0.1 * sb.ave and - s_store_sk = sc.ss_store_sk and - i_item_sk = sc.ss_item_sk - order by s_store_name, i_item_desc -limit 100; - --- end template query65.tpl query 77 in stream 3 --- start template query71.tpl query 78 in stream 3 -select /* TPC-DS query71.tpl 0.72 */ i_brand_id brand_id, i_brand brand,t_hour,t_minute, - sum(ext_price) ext_price - from item, (select ws_ext_sales_price as ext_price, - ws_sold_date_sk as sold_date_sk, - ws_item_sk as sold_item_sk, - ws_sold_time_sk as time_sk - from web_sales,date_dim - where d_date_sk = ws_sold_date_sk - and d_moy=11 - and d_year=2001 - union all - select cs_ext_sales_price as ext_price, - cs_sold_date_sk as sold_date_sk, - cs_item_sk as sold_item_sk, - cs_sold_time_sk as time_sk - from catalog_sales,date_dim - where d_date_sk = cs_sold_date_sk - and d_moy=11 - and d_year=2001 - union all - select ss_ext_sales_price as ext_price, - ss_sold_date_sk as sold_date_sk, - ss_item_sk as sold_item_sk, - ss_sold_time_sk as time_sk - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - and d_moy=11 - and d_year=2001 - ) tmp,time_dim - where - sold_item_sk = i_item_sk - and i_manager_id=1 - and time_sk = t_time_sk - and (t_meal_time = 'breakfast' or t_meal_time = 'dinner') - group by i_brand, i_brand_id,t_hour,t_minute - order by ext_price desc, i_brand_id - ; - --- end template query71.tpl query 78 in stream 3 --- start template query57.tpl query 79 in stream 3 -with /* TPC-DS query57.tpl 0.70 */ v1 as( - select i_category, i_brand, - cc_name, - d_year, d_moy, - sum(cs_sales_price) sum_sales, - avg(sum(cs_sales_price)) over - (partition by i_category, i_brand, - cc_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - cc_name - order by d_year, d_moy) rn - from item, catalog_sales, date_dim, call_center - where cs_item_sk = i_item_sk and - cs_sold_date_sk = d_date_sk and - cc_call_center_sk= cs_call_center_sk and - ( - d_year = 2001 or - ( d_year = 2001-1 and d_moy =12) or - ( d_year = 2001+1 and d_moy =1) - ) - group by i_category, i_brand, - cc_name , d_year, d_moy), - v2 as( - select v1.i_category, v1.i_brand, v1.cc_name - ,v1.d_year - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1. cc_name = v1_lag. cc_name and - v1. cc_name = v1_lead. cc_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 2001 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, nsum - limit 100; - --- end template query57.tpl query 79 in stream 3 --- start template query32.tpl query 80 in stream 3 -select /* TPC-DS query32.tpl 0.7 */ sum(cs_ext_discount_amt) as "excess discount amount" -from - catalog_sales - ,item - ,date_dim -where -i_manufact_id = 112 -and i_item_sk = cs_item_sk -and d_date between '2001-02-02' and - dateadd(day,90,cast('2001-02-02' as date)) -and d_date_sk = cs_sold_date_sk -and cs_ext_discount_amt - > ( - select - 1.3 * avg(cs_ext_discount_amt) - from - catalog_sales - ,date_dim - where - cs_item_sk = i_item_sk - and d_date between '2001-02-02' and - dateadd(day,90,cast('2001-02-02' as date)) - and d_date_sk = cs_sold_date_sk - ) -limit 100; - --- end template query32.tpl query 80 in stream 3 --- start template query61.tpl query 81 in stream 3 -select /* TPC-DS query61.tpl 0.97 */ promotions,total,cast(promotions as decimal(15,4))/cast(total as decimal(15,4))*100 -from - (select sum(ss_ext_sales_price) promotions - from store_sales - ,store - ,promotion - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_promo_sk = p_promo_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -7 - and i_category = 'Books' - and (p_channel_dmail = 'Y' or p_channel_email = 'Y' or p_channel_tv = 'Y') - and s_gmt_offset = -7 - and d_year = 2002 - and d_moy = 11) promotional_sales, - (select sum(ss_ext_sales_price) total - from store_sales - ,store - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -7 - and i_category = 'Books' - and s_gmt_offset = -7 - and d_year = 2002 - and d_moy = 11) all_sales -order by promotions, total -limit 100; - --- end template query61.tpl query 81 in stream 3 --- start template query85.tpl query 82 in stream 3 -select /* TPC-DS query85.tpl 0.33 */ substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) - from web_sales, web_returns, web_page, customer_demographics cd1, - customer_demographics cd2, customer_address, date_dim, reason - where ws_web_page_sk = wp_web_page_sk - and ws_item_sk = wr_item_sk - and ws_order_number = wr_order_number - and ws_sold_date_sk = d_date_sk and d_year = 1999 - and cd1.cd_demo_sk = wr_refunded_cdemo_sk - and cd2.cd_demo_sk = wr_returning_cdemo_sk - and ca_address_sk = wr_refunded_addr_sk - and r_reason_sk = wr_reason_sk - and - ( - ( - cd1.cd_marital_status = 'M' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'College' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 100.00 and 150.00 - ) - or - ( - cd1.cd_marital_status = 'S' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Primary' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 50.00 and 100.00 - ) - or - ( - cd1.cd_marital_status = 'D' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Secondary' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ca_country = 'United States' - and - ca_state in ('CA', 'NE', 'VA') - and ws_net_profit between 100 and 200 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('NC', 'SD', 'ND') - and ws_net_profit between 150 and 300 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('RI', 'NY', 'GA') - and ws_net_profit between 50 and 250 - ) - ) -group by r_reason_desc -order by substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) -limit 100; - --- end template query85.tpl query 82 in stream 3 --- start template query73.tpl query 83 in stream 3 -select /* TPC-DS query73.tpl 0.79 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_buy_potential = '501-1000' or - household_demographics.hd_buy_potential = '5001-10000') - and household_demographics.hd_vehicle_count > 0 - and case when household_demographics.hd_vehicle_count > 0 then - household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count else null end > 1 - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_county in ('San Miguel County','Wadena County','Maverick County','Luce County') - group by ss_ticket_number,ss_customer_sk) dj,customer - where ss_customer_sk = c_customer_sk - and cnt between 1 and 5 - order by cnt desc, c_last_name asc; - --- end template query73.tpl query 83 in stream 3 --- start template query98.tpl query 84 in stream 3 -select /* TPC-DS query98.tpl 0.32 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ss_ext_sales_price) as itemrevenue - ,sum(ss_ext_sales_price)*100/sum(sum(ss_ext_sales_price)) over - (partition by i_class) as revenueratio -from - store_sales - ,item - ,date_dim -where - ss_item_sk = i_item_sk - and i_category in ('Home', 'Shoes', 'Books') - and ss_sold_date_sk = d_date_sk - and d_date between cast('2001-03-09' as date) - and dateadd(day,30,cast('2001-03-09' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio; - --- end template query98.tpl query 84 in stream 3 --- start template query77a.tpl query 85 in stream 3 -with /* TPC-DS query77a.tpl 0.78 */ ss as - (select s_store_sk, - sum(ss_ext_sales_price) as sales, - sum(ss_net_profit) as profit - from store_sales, - date_dim, - store - where ss_sold_date_sk = d_date_sk - and d_date between cast('1999-08-29' as date) - and dateadd(day,30,cast('1999-08-29' as date)) - and ss_store_sk = s_store_sk - group by s_store_sk) - , - sr as - (select s_store_sk, - sum(sr_return_amt) as returns, - sum(sr_net_loss) as profit_loss - from store_returns, - date_dim, - store - where sr_returned_date_sk = d_date_sk - and d_date between cast('1999-08-29' as date) - and dateadd(day,30,cast('1999-08-29' as date)) - and sr_store_sk = s_store_sk - group by s_store_sk), - cs as - (select cs_call_center_sk, - sum(cs_ext_sales_price) as sales, - sum(cs_net_profit) as profit - from catalog_sales, - date_dim - where cs_sold_date_sk = d_date_sk - and d_date between cast('1999-08-29' as date) - and dateadd(day,30,cast('1999-08-29' as date)) - group by cs_call_center_sk - ), - cr as - (select cr_call_center_sk, - sum(cr_return_amount) as returns, - sum(cr_net_loss) as profit_loss - from catalog_returns, - date_dim - where cr_returned_date_sk = d_date_sk - and d_date between cast('1999-08-29' as date) - and dateadd(day,30,cast('1999-08-29' as date)) - group by cr_call_center_sk), - ws as - ( select wp_web_page_sk, - sum(ws_ext_sales_price) as sales, - sum(ws_net_profit) as profit - from web_sales, - date_dim, - web_page - where ws_sold_date_sk = d_date_sk - and d_date between cast('1999-08-29' as date) - and dateadd(day,30,cast('1999-08-29' as date)) - and ws_web_page_sk = wp_web_page_sk - group by wp_web_page_sk), - wr as - (select wp_web_page_sk, - sum(wr_return_amt) as returns, - sum(wr_net_loss) as profit_loss - from web_returns, - date_dim, - web_page - where wr_returned_date_sk = d_date_sk - and d_date between cast('1999-08-29' as date) - and dateadd(day,30,cast('1999-08-29' as date)) - and wr_web_page_sk = wp_web_page_sk - group by wp_web_page_sk) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , ss.s_store_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ss left join sr - on ss.s_store_sk = sr.s_store_sk - union all - select 'catalog channel' as channel - , cs_call_center_sk as id - , sales - , returns - , (profit - profit_loss) as profit - from cs - , cr - union all - select 'web channel' as channel - , ws.wp_web_page_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ws left join wr - on ws.wp_web_page_sk = wr.wp_web_page_sk - ) x - group by channel, id ) - - select * - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results -) foo -order by channel, id - limit 100; - --- end template query77a.tpl query 85 in stream 3 --- start template query45.tpl query 86 in stream 3 -select /* TPC-DS query45.tpl 0.18 */ ca_zip, ca_city, sum(ws_sales_price) - from web_sales, customer, customer_address, date_dim, item - where ws_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ws_item_sk = i_item_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', '85392', '85460', '80348', '81792') - or - i_item_id in (select i_item_id - from item - where i_item_sk in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29) - ) - ) - and ws_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 2002 - group by ca_zip, ca_city - order by ca_zip, ca_city - limit 100; - --- end template query45.tpl query 86 in stream 3 --- start template query20.tpl query 87 in stream 3 -select /* TPC-DS query20.tpl 0.65 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(cs_ext_sales_price) as itemrevenue - ,sum(cs_ext_sales_price)*100/sum(sum(cs_ext_sales_price)) over - (partition by i_class) as revenueratio - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and i_category in ('Sports', 'Men', 'Home') - and cs_sold_date_sk = d_date_sk - and d_date between cast('2000-03-19' as date) - and dateadd(day,30,cast('2000-03-19' as date)) - group by i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - order by i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query20.tpl query 87 in stream 3 --- start template query50.tpl query 88 in stream 3 -select /* TPC-DS query50.tpl 0.60 */ - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 30) and - (sr_returned_date_sk - ss_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 60) and - (sr_returned_date_sk - ss_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 90) and - (sr_returned_date_sk - ss_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - store_sales - ,store_returns - ,store - ,date_dim d1 - ,date_dim d2 -where - d2.d_year = 2002 -and d2.d_moy = 9 -and ss_ticket_number = sr_ticket_number -and ss_item_sk = sr_item_sk -and ss_sold_date_sk = d1.d_date_sk -and sr_returned_date_sk = d2.d_date_sk -and ss_customer_sk = sr_customer_sk -and ss_store_sk = s_store_sk -group by - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -order by s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -limit 100; - --- end template query50.tpl query 88 in stream 3 --- start template query70a.tpl query 89 in stream 3 -with /* TPC-DS query70a.tpl 0.34 */ results as -( select - sum(ss_net_profit) as total_sum ,s_state ,s_county, 0 as gstate, 0 as g_county - from - store_sales - ,date_dim d1 - ,store - where - d1.d_month_seq between 1211 and 1211 + 11 - and d1.d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - and s_state in - ( select s_state - from (select s_state as s_state, - rank() over ( partition by s_state order by sum(ss_net_profit) desc) as ranking - from store_sales, store, date_dim - where d_month_seq between 1211 and 1211 + 11 - and d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - group by s_state - ) tmp1 - where ranking <= 5) - group by s_state,s_county) , - results_rollup as -(select total_sum ,s_state ,s_county, 0 as g_state, 0 as g_county, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum,s_state, NULL as s_county, 0 as g_state, 1 as g_county, 1 as lochierarchy from results group by s_state - union - select sum(total_sum) as total_sum ,NULL as s_state ,NULL as s_county, 1 as g_state, 1 as g_county, 2 as lochierarchy from results) - select total_sum ,s_state ,s_county, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_county = 0 then s_state end - order by total_sum desc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then s_state end - ,rank_within_parent - limit 100; - --- end template query70a.tpl query 89 in stream 3 --- start template query75.tpl query 90 in stream 3 -WITH /* TPC-DS query75.tpl 0.3 */ all_sales AS ( - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,SUM(sales_cnt) AS sales_cnt - ,SUM(sales_amt) AS sales_amt - FROM (SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,cs_quantity - COALESCE(cr_return_quantity,0) AS sales_cnt - ,cs_ext_sales_price - COALESCE(cr_return_amount,0.0) AS sales_amt - FROM catalog_sales JOIN item ON i_item_sk=cs_item_sk - JOIN date_dim ON d_date_sk=cs_sold_date_sk - LEFT JOIN catalog_returns ON (cs_order_number=cr_order_number - AND cs_item_sk=cr_item_sk) - WHERE i_category='Shoes' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ss_quantity - COALESCE(sr_return_quantity,0) AS sales_cnt - ,ss_ext_sales_price - COALESCE(sr_return_amt,0.0) AS sales_amt - FROM store_sales JOIN item ON i_item_sk=ss_item_sk - JOIN date_dim ON d_date_sk=ss_sold_date_sk - LEFT JOIN store_returns ON (ss_ticket_number=sr_ticket_number - AND ss_item_sk=sr_item_sk) - WHERE i_category='Shoes' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ws_quantity - COALESCE(wr_return_quantity,0) AS sales_cnt - ,ws_ext_sales_price - COALESCE(wr_return_amt,0.0) AS sales_amt - FROM web_sales JOIN item ON i_item_sk=ws_item_sk - JOIN date_dim ON d_date_sk=ws_sold_date_sk - LEFT JOIN web_returns ON (ws_order_number=wr_order_number - AND ws_item_sk=wr_item_sk) - WHERE i_category='Shoes') sales_detail - GROUP BY d_year, i_brand_id, i_class_id, i_category_id, i_manufact_id) - SELECT prev_yr.d_year AS prev_year - ,curr_yr.d_year AS year - ,curr_yr.i_brand_id - ,curr_yr.i_class_id - ,curr_yr.i_category_id - ,curr_yr.i_manufact_id - ,prev_yr.sales_cnt AS prev_yr_cnt - ,curr_yr.sales_cnt AS curr_yr_cnt - ,curr_yr.sales_cnt-prev_yr.sales_cnt AS sales_cnt_diff - ,curr_yr.sales_amt-prev_yr.sales_amt AS sales_amt_diff - FROM all_sales curr_yr, all_sales prev_yr - WHERE curr_yr.i_brand_id=prev_yr.i_brand_id - AND curr_yr.i_class_id=prev_yr.i_class_id - AND curr_yr.i_category_id=prev_yr.i_category_id - AND curr_yr.i_manufact_id=prev_yr.i_manufact_id - AND curr_yr.d_year=2000 - AND prev_yr.d_year=2000-1 - AND CAST(curr_yr.sales_cnt AS DECIMAL(17,2))/CAST(prev_yr.sales_cnt AS DECIMAL(17,2))<0.9 - ORDER BY sales_cnt_diff,sales_amt_diff - limit 100; - --- end template query75.tpl query 90 in stream 3 --- start template query91.tpl query 91 in stream 3 -select /* TPC-DS query91.tpl 0.13 */ - cc_call_center_id Call_Center, - cc_name Call_Center_Name, - cc_manager Manager, - sum(cr_net_loss) Returns_Loss -from - call_center, - catalog_returns, - date_dim, - customer, - customer_address, - customer_demographics, - household_demographics -where - cr_call_center_sk = cc_call_center_sk -and cr_returned_date_sk = d_date_sk -and cr_returning_customer_sk= c_customer_sk -and cd_demo_sk = c_current_cdemo_sk -and hd_demo_sk = c_current_hdemo_sk -and ca_address_sk = c_current_addr_sk -and d_year = 1998 -and d_moy = 12 -and ( (cd_marital_status = 'M' and cd_education_status = 'Unknown') - or(cd_marital_status = 'W' and cd_education_status = 'Advanced Degree')) -and hd_buy_potential like '>10000%' -and ca_gmt_offset = -7 -group by cc_call_center_id,cc_name,cc_manager,cd_marital_status,cd_education_status -order by sum(cr_net_loss) desc; - --- end template query91.tpl query 91 in stream 3 --- start template query17.tpl query 92 in stream 3 -select /* TPC-DS query17.tpl 0.41 */ i_item_id - ,i_item_desc - ,s_state - ,count(ss_quantity) as store_sales_quantitycount - ,avg(ss_quantity) as store_sales_quantityave - ,stddev_samp(ss_quantity) as store_sales_quantitystdev - ,stddev_samp(ss_quantity)/avg(ss_quantity) as store_sales_quantitycov - ,count(sr_return_quantity) as store_returns_quantitycount - ,avg(sr_return_quantity) as store_returns_quantityave - ,stddev_samp(sr_return_quantity) as store_returns_quantitystdev - ,stddev_samp(sr_return_quantity)/avg(sr_return_quantity) as store_returns_quantitycov - ,count(cs_quantity) as catalog_sales_quantitycount ,avg(cs_quantity) as catalog_sales_quantityave - ,stddev_samp(cs_quantity) as catalog_sales_quantitystdev - ,stddev_samp(cs_quantity)/avg(cs_quantity) as catalog_sales_quantitycov - from store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where d1.d_quarter_name = '1998Q1' - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_quarter_name in ('1998Q1','1998Q2','1998Q3') - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_quarter_name in ('1998Q1','1998Q2','1998Q3') - group by i_item_id - ,i_item_desc - ,s_state - order by i_item_id - ,i_item_desc - ,s_state -limit 100; - --- end template query17.tpl query 92 in stream 3 --- start template query24.tpl query 93 in stream 3 -with /* TPC-DS query24.tpl 0.92 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_ext_sales_price) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip -and s_market_id=9 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'mint' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; -with /* TPC-DS query24.tpl 0.92 part2 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_ext_sales_price) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip - and s_market_id = 9 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'lemon' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; - --- end template query24.tpl query 93 in stream 3 --- start template query48.tpl query 94 in stream 3 -select /* TPC-DS query48.tpl 0.74 */ sum (ss_quantity) - from store_sales, store, customer_demographics, customer_address, date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 1998 - and - ( - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'U' - and - cd_education_status = 'Secondary' - and - ss_sales_price between 100.00 and 150.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'M' - and - cd_education_status = 'Advanced Degree' - and - ss_sales_price between 50.00 and 100.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'D' - and - cd_education_status = 'College' - and - ss_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('KS', 'SC', 'GA') - and ss_net_profit between 0 and 2000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('MN', 'KY', 'CA') - and ss_net_profit between 150 and 3000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('MT', 'MI', 'WV') - and ss_net_profit between 50 and 25000 - ) - ) -; - --- end template query48.tpl query 94 in stream 3 --- start template query51.tpl query 95 in stream 3 -WITH /* TPC-DS query51.tpl 0.46 */ web_v1 as ( -select - ws_item_sk item_sk, d_date, - sum(sum(ws_sales_price)) - over (partition by ws_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from web_sales - ,date_dim -where ws_sold_date_sk=d_date_sk - and d_month_seq between 1199 and 1199+11 - and ws_item_sk is not NULL -group by ws_item_sk, d_date), -store_v1 as ( -select - ss_item_sk item_sk, d_date, - sum(sum(ss_sales_price)) - over (partition by ss_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from store_sales - ,date_dim -where ss_sold_date_sk=d_date_sk - and d_month_seq between 1199 and 1199+11 - and ss_item_sk is not NULL -group by ss_item_sk, d_date) - select * -from (select item_sk - ,d_date - ,web_sales - ,store_sales - ,max(web_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) web_cumulative - ,max(store_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) store_cumulative - from (select case when web.item_sk is not null then web.item_sk else store.item_sk end item_sk - ,case when web.d_date is not null then web.d_date else store.d_date end d_date - ,web.cume_sales web_sales - ,store.cume_sales store_sales - from web_v1 web full outer join store_v1 store on (web.item_sk = store.item_sk - and web.d_date = store.d_date) - )x )y -where web_cumulative > store_cumulative -order by item_sk - ,d_date -limit 100; - --- end template query51.tpl query 95 in stream 3 --- start template query79.tpl query 96 in stream 3 -select /* TPC-DS query79.tpl 0.89 */ - c_last_name,c_first_name,substring(s_city,1,30),ss_ticket_number,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,store.s_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (household_demographics.hd_dep_count = 4 or household_demographics.hd_vehicle_count > 3) - and date_dim.d_dow = 1 - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_number_employees between 200 and 295 - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,store.s_city) ms,customer - where ss_customer_sk = c_customer_sk - order by c_last_name,c_first_name,substring(s_city,1,30), profit -limit 100; - --- end template query79.tpl query 96 in stream 3 --- start template query35a.tpl query 97 in stream 3 -select /* TPC-DS query35a.tpl 0.47 */ - ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - count(*) cnt1, - stddev_samp(cd_dep_count), - min(cd_dep_count), - sum(cd_dep_count), - cd_dep_employed_count, - count(*) cnt2, - stddev_samp(cd_dep_employed_count), - min(cd_dep_employed_count), - sum(cd_dep_employed_count), - cd_dep_college_count, - count(*) cnt3, - stddev_samp(cd_dep_college_count), - min(cd_dep_college_count), - sum(cd_dep_college_count) - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2002 and - d_qoy < 4) and - exists (select * from - (select ws_bill_customer_sk customsk - from web_sales,date_dim - where - ws_sold_date_sk = d_date_sk and - d_year = 2002 and - d_qoy < 4 - union all - select cs_ship_customer_sk customsk - from catalog_sales,date_dim - where - cs_sold_date_sk = d_date_sk and - d_year = 2002 and - d_qoy < 4)x - where x.customsk = c.c_customer_sk) - group by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - limit 100; - --- end template query35a.tpl query 97 in stream 3 --- start template query88.tpl query 98 in stream 3 -select /* TPC-DS query88.tpl 0.66 */ * -from - (select count(*) h8_30_to_9 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s1, - (select count(*) h9_to_9_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s2, - (select count(*) h9_30_to_10 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s3, - (select count(*) h10_to_10_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s4, - (select count(*) h10_30_to_11 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s5, - (select count(*) h11_to_11_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s6, - (select count(*) h11_30_to_12 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s7, - (select count(*) h12_to_12_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 12 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s8 -; - --- end template query88.tpl query 98 in stream 3 --- start template query49.tpl query 99 in stream 3 -select /* TPC-DS query49.tpl 0.48 */ channel, item, return_ratio, return_rank, currency_rank from - (select - 'web' as channel - ,web.item - ,web.return_ratio - ,web.return_rank - ,web.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select ws.ws_item_sk as item - ,(cast(sum(coalesce(wr.wr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(wr.wr_return_amt,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - web_sales ws left outer join web_returns wr - on (ws.ws_order_number = wr.wr_order_number and - ws.ws_item_sk = wr.wr_item_sk) - ,date_dim - where - wr.wr_return_amt > 10000 - and ws.ws_net_profit > 1 - and ws.ws_net_paid > 0 - and ws.ws_quantity > 0 - and ws_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 12 - group by ws.ws_item_sk - ) in_web - ) web - where - ( - web.return_rank <= 10 - or - web.currency_rank <= 10 - ) - union - select - 'catalog' as channel - ,catalog.item - ,catalog.return_ratio - ,catalog.return_rank - ,catalog.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select - cs.cs_item_sk as item - ,(cast(sum(coalesce(cr.cr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(cr.cr_return_amount,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - catalog_sales cs left outer join catalog_returns cr - on (cs.cs_order_number = cr.cr_order_number and - cs.cs_item_sk = cr.cr_item_sk) - ,date_dim - where - cr.cr_return_amount > 10000 - and cs.cs_net_profit > 1 - and cs.cs_net_paid > 0 - and cs.cs_quantity > 0 - and cs_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 12 - group by cs.cs_item_sk - ) in_cat - ) catalog - where - ( - catalog.return_rank <= 10 - or - catalog.currency_rank <=10 - ) - union - select - 'store' as channel - ,store.item - ,store.return_ratio - ,store.return_rank - ,store.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select sts.ss_item_sk as item - ,(cast(sum(coalesce(sr.sr_return_quantity,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(sr.sr_return_amt,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - store_sales sts left outer join store_returns sr - on (sts.ss_ticket_number = sr.sr_ticket_number and sts.ss_item_sk = sr.sr_item_sk) - ,date_dim - where - sr.sr_return_amt > 10000 - and sts.ss_net_profit > 1 - and sts.ss_net_paid > 0 - and sts.ss_quantity > 0 - and ss_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 12 - group by sts.ss_item_sk - ) in_store - ) store - where ( - store.return_rank <= 10 - or - store.currency_rank <= 10 - ) - ) - order by 1,4,5,2 - limit 100; - --- end template query49.tpl query 99 in stream 3 diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/1TB/queries/query_4.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/1TB/queries/query_4.sql deleted file mode 100644 index 66b2047c..00000000 --- a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/1TB/queries/query_4.sql +++ /dev/null @@ -1,5027 +0,0 @@ --- start template query79.tpl query 1 in stream 4 -select /* TPC-DS query79.tpl 0.89 */ - c_last_name,c_first_name,substring(s_city,1,30),ss_ticket_number,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,store.s_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (household_demographics.hd_dep_count = 1 or household_demographics.hd_vehicle_count > 3) - and date_dim.d_dow = 1 - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_number_employees between 200 and 295 - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,store.s_city) ms,customer - where ss_customer_sk = c_customer_sk - order by c_last_name,c_first_name,substring(s_city,1,30), profit -limit 100; - --- end template query79.tpl query 1 in stream 4 --- start template query39.tpl query 2 in stream 4 -with /* TPC-DS query39.tpl 0.5 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =2002 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=3 - and inv2.d_moy=3+1 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; -with /* TPC-DS query39.tpl 0.5 part2 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =2002 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=3 - and inv2.d_moy=3+1 - and inv1.cov > 1.5 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; - --- end template query39.tpl query 2 in stream 4 --- start template query93.tpl query 3 in stream 4 -select /* TPC-DS query93.tpl 0.52 */ ss_customer_sk - ,sum(act_sales) sumsales - from (select ss_item_sk - ,ss_ticket_number - ,ss_customer_sk - ,case when sr_return_quantity is not null then (ss_quantity-sr_return_quantity)*ss_sales_price - else (ss_quantity*ss_sales_price) end act_sales - from store_sales left outer join store_returns on (sr_item_sk = ss_item_sk - and sr_ticket_number = ss_ticket_number) - ,reason - where sr_reason_sk = r_reason_sk - and r_reason_desc = 'Did not get it on time') t - group by ss_customer_sk - order by sumsales, ss_customer_sk -limit 100; - --- end template query93.tpl query 3 in stream 4 --- start template query41.tpl query 4 in stream 4 -select /* TPC-DS query41.tpl 0.62 */ distinct(i_product_name) - from item i1 - where i_manufact_id between 939 and 939+40 - and (select count(*) as item_cnt - from item - where (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'cream' or i_color = 'magenta') and - (i_units = 'Gross' or i_units = 'Each') and - (i_size = 'small' or i_size = 'economy') - ) or - (i_category = 'Women' and - (i_color = 'rose' or i_color = 'black') and - (i_units = 'Gram' or i_units = 'Carton') and - (i_size = 'petite' or i_size = 'N/A') - ) or - (i_category = 'Men' and - (i_color = 'burnished' or i_color = 'cyan') and - (i_units = 'Tbl' or i_units = 'Ton') and - (i_size = 'large' or i_size = 'medium') - ) or - (i_category = 'Men' and - (i_color = 'peru' or i_color = 'light') and - (i_units = 'Box' or i_units = 'Case') and - (i_size = 'small' or i_size = 'economy') - ))) or - (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'dodger' or i_color = 'ghost') and - (i_units = 'Pallet' or i_units = 'Bundle') and - (i_size = 'small' or i_size = 'economy') - ) or - (i_category = 'Women' and - (i_color = 'grey' or i_color = 'aquamarine') and - (i_units = 'Lb' or i_units = 'Unknown') and - (i_size = 'petite' or i_size = 'N/A') - ) or - (i_category = 'Men' and - (i_color = 'snow' or i_color = 'dark') and - (i_units = 'Bunch' or i_units = 'Oz') and - (i_size = 'large' or i_size = 'medium') - ) or - (i_category = 'Men' and - (i_color = 'gainsboro' or i_color = 'olive') and - (i_units = 'Pound' or i_units = 'N/A') and - (i_size = 'small' or i_size = 'economy') - )))) > 0 - order by i_product_name - limit 100; - --- end template query41.tpl query 4 in stream 4 --- start template query29.tpl query 5 in stream 4 -select /* TPC-DS query29.tpl 0.53 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,stddev_samp(ss_quantity) as store_sales_quantity - ,stddev_samp(sr_return_quantity) as store_returns_quantity - ,stddev_samp(cs_quantity) as catalog_sales_quantity - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 1998 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 4 + 3 - and d2.d_year = 1998 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_year in (1998,1998+1,1998+2) - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query29.tpl query 5 in stream 4 --- start template query32.tpl query 6 in stream 4 -select /* TPC-DS query32.tpl 0.7 */ sum(cs_ext_discount_amt) as "excess discount amount" -from - catalog_sales - ,item - ,date_dim -where -i_manufact_id = 618 -and i_item_sk = cs_item_sk -and d_date between '1999-01-22' and - dateadd(day,90,cast('1999-01-22' as date)) -and d_date_sk = cs_sold_date_sk -and cs_ext_discount_amt - > ( - select - 1.3 * avg(cs_ext_discount_amt) - from - catalog_sales - ,date_dim - where - cs_item_sk = i_item_sk - and d_date between '1999-01-22' and - dateadd(day,90,cast('1999-01-22' as date)) - and d_date_sk = cs_sold_date_sk - ) -limit 100; - --- end template query32.tpl query 6 in stream 4 --- start template query66.tpl query 7 in stream 4 -select /* TPC-DS query66.tpl 0.39 */ - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - ,sum(jan_sales) as jan_sales - ,sum(feb_sales) as feb_sales - ,sum(mar_sales) as mar_sales - ,sum(apr_sales) as apr_sales - ,sum(may_sales) as may_sales - ,sum(jun_sales) as jun_sales - ,sum(jul_sales) as jul_sales - ,sum(aug_sales) as aug_sales - ,sum(sep_sales) as sep_sales - ,sum(oct_sales) as oct_sales - ,sum(nov_sales) as nov_sales - ,sum(dec_sales) as dec_sales - ,sum(jan_sales/w_warehouse_sq_ft) as jan_sales_per_sq_foot - ,sum(feb_sales/w_warehouse_sq_ft) as feb_sales_per_sq_foot - ,sum(mar_sales/w_warehouse_sq_ft) as mar_sales_per_sq_foot - ,sum(apr_sales/w_warehouse_sq_ft) as apr_sales_per_sq_foot - ,sum(may_sales/w_warehouse_sq_ft) as may_sales_per_sq_foot - ,sum(jun_sales/w_warehouse_sq_ft) as jun_sales_per_sq_foot - ,sum(jul_sales/w_warehouse_sq_ft) as jul_sales_per_sq_foot - ,sum(aug_sales/w_warehouse_sq_ft) as aug_sales_per_sq_foot - ,sum(sep_sales/w_warehouse_sq_ft) as sep_sales_per_sq_foot - ,sum(oct_sales/w_warehouse_sq_ft) as oct_sales_per_sq_foot - ,sum(nov_sales/w_warehouse_sq_ft) as nov_sales_per_sq_foot - ,sum(dec_sales/w_warehouse_sq_ft) as dec_sales_per_sq_foot - ,sum(jan_net) as jan_net - ,sum(feb_net) as feb_net - ,sum(mar_net) as mar_net - ,sum(apr_net) as apr_net - ,sum(may_net) as may_net - ,sum(jun_net) as jun_net - ,sum(jul_net) as jul_net - ,sum(aug_net) as aug_net - ,sum(sep_net) as sep_net - ,sum(oct_net) as oct_net - ,sum(nov_net) as nov_net - ,sum(dec_net) as dec_net - from ( - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'ALLIANCE' || ',' || 'FEDEX' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then ws_ext_list_price* ws_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then ws_ext_list_price* ws_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then ws_ext_list_price* ws_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then ws_ext_list_price* ws_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then ws_ext_list_price* ws_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then ws_ext_list_price* ws_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then ws_ext_list_price* ws_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then ws_ext_list_price* ws_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then ws_ext_list_price* ws_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then ws_ext_list_price* ws_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then ws_ext_list_price* ws_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then ws_ext_list_price* ws_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then ws_net_paid * ws_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then ws_net_paid * ws_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then ws_net_paid * ws_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then ws_net_paid * ws_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then ws_net_paid * ws_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then ws_net_paid * ws_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then ws_net_paid * ws_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then ws_net_paid * ws_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then ws_net_paid * ws_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then ws_net_paid * ws_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then ws_net_paid * ws_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then ws_net_paid * ws_quantity else 0 end) as dec_net - from - web_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - ws_warehouse_sk = w_warehouse_sk - and ws_sold_date_sk = d_date_sk - and ws_sold_time_sk = t_time_sk - and ws_ship_mode_sk = sm_ship_mode_sk - and d_year = 2002 - and t_time between 23252 and 23252+28800 - and sm_carrier in ('ALLIANCE','FEDEX') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - union all - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'ALLIANCE' || ',' || 'FEDEX' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then cs_ext_list_price* cs_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then cs_ext_list_price* cs_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then cs_ext_list_price* cs_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then cs_ext_list_price* cs_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then cs_ext_list_price* cs_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then cs_ext_list_price* cs_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then cs_ext_list_price* cs_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then cs_ext_list_price* cs_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then cs_ext_list_price* cs_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then cs_ext_list_price* cs_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then cs_ext_list_price* cs_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then cs_ext_list_price* cs_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as dec_net - from - catalog_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and cs_sold_time_sk = t_time_sk - and cs_ship_mode_sk = sm_ship_mode_sk - and d_year = 2002 - and t_time between 23252 AND 23252+28800 - and sm_carrier in ('ALLIANCE','FEDEX') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - ) x - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - order by w_warehouse_name - limit 100; - --- end template query66.tpl query 7 in stream 4 --- start template query84.tpl query 8 in stream 4 -select /* TPC-DS query84.tpl 0.80 */ c_customer_id as customer_id - , coalesce(c_last_name,'') || ', ' || coalesce(c_first_name,'') as customername - from customer - ,customer_address - ,customer_demographics - ,household_demographics - ,income_band - ,store_returns - where ca_city = 'Springdale' - and c_current_addr_sk = ca_address_sk - and ib_lower_bound >= 59457 - and ib_upper_bound <= 59457 + 50000 - and ib_income_band_sk = hd_income_band_sk - and cd_demo_sk = c_current_cdemo_sk - and hd_demo_sk = c_current_hdemo_sk - and sr_cdemo_sk = cd_demo_sk - order by c_customer_id - limit 100; - --- end template query84.tpl query 8 in stream 4 --- start template query8.tpl query 9 in stream 4 -select /* TPC-DS query8.tpl 0.63 */ s_store_name - ,sum(ss_net_profit) - from store_sales - ,date_dim - ,store, - (select ca_zip - from ( - SELECT substring(ca_zip,1,5) ca_zip - FROM customer_address - WHERE substring(ca_zip,1,5) IN ( - '11721','52808','46481','61062','98891','59200', - '21286','16096','25238','12029','27800', - '19458','54524','25921','57374','35520', - '39922','88825','39987','17541','44043', - '23063','87873','55386','95874','58709', - '62023','57557','38960','63942','77582', - '65666','47352','96965','88639','80279', - '81460','67375','80530','27053','21595', - '76486','47870','43866','69806','31515', - '60055','30504','52442','37445','11463', - '38061','18799','22492','92238','56741', - '30574','59522','15692','43763','39283', - '57580','74933','40082','14098','61547', - '43870','30835','17427','25143','41890', - '40828','48673','37259','47625','63515', - '53670','33318','12070','42090','68525', - '23908','58495','87614','76877','46645', - '15768','94024','80262','79433','45413', - '15451','17191','26914','65305','19377', - '56197','12921','13423','78523','37397', - '18904','58634','49573','35981','35161', - '54752','55638','65909','35282','22413', - '40917','18104','20244','35135','81343', - '84925','81074','91173','17770','61874', - '85036','19626','20144','17698','19587', - '44829','27378','64791','77166','65864', - '36687','84284','89854','61677','83642', - '90833','30899','24976','67748','21057', - '55521','24128','97855','42998','88780', - '58769','90247','91882','84489','95051', - '33343','69610','89333','66749','35856', - '92213','20676','30173','52818','14820', - '79388','64401','15046','76756','38743', - '27839','42024','34875','77144','55910', - '39059','16211','76542','69133','47645', - '46521','78267','40394','44656','53538', - '91701','26622','25612','56472','78557', - '79664','74858','98915','90481','78350', - '24089','22245','98808','24829','72908', - '95233','97936','16940','56462','42513', - '28621','81742','90418','68813','64052', - '67038','30682','65453','13681','27055', - '50689','66607','64132','63503','33519', - '51146','21732','79081','43938','75817', - '88510','33821','22414','37980','18111', - '96771','28357','48083','61482','35402', - '37944','30945','49800','25286','28804', - '52475','53656','70214','43026','78836', - '89117','71981','82990','43879','75257', - '23731','74687','14084','10415','52592', - '77823','39360','74300','78455','13772', - '28043','20671','13597','47849','30571', - '77891','20633','17053','68960','26206', - '14479','13668','23804','22655','24233', - '88660','21034','21998','46957','48318', - '51479','92401','92243','66528','34199', - '78730','50931','54438','25117','78270', - '54646','27304','35945','84180','99804', - '90337','85676','56341','30895','37163', - '32673','18778','19013','54544','42107', - '95690','51823','86082','97440','12633', - '44600','78042','13320','73353','22249', - '46156','79832','81237','36260','31063', - '13349','26357','66888','79040','43260', - '49560','27512','15084','93081','57089', - '87062','70689','60771','66169','28051', - '27521','66250','57988','69414','52714', - '53849','38987','72963','51261','37267', - '17898','13946','22645','68435','57167', - '33016','80341','99760','61124','65205', - '98721','68029','32741','58409','38934', - '84856','79623','38845','16474','16870', - '77521','42789','84424','54840','84243', - '42466','32699','56210','73254','33632', - '83847','53965','29794','42784','72833', - '14058','18358','21320','18657','65695', - '45128','50779','42038','95240','16687', - '84735','50525','38039','21010','10127', - '13124','93067','96504','30856','12993', - '46616','44155','27132','24762') - intersect - select ca_zip - from (SELECT substring(ca_zip,1,5) ca_zip,count(*) cnt - FROM customer_address, customer - WHERE ca_address_sk = c_current_addr_sk and - c_preferred_cust_flag='Y' - group by ca_zip - having count(*) > 10)A1)A2) V1 - where ss_store_sk = s_store_sk - and ss_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 1998 - and (substring(s_zip,1,2) = substring(V1.ca_zip,1,2)) - group by s_store_name - order by s_store_name - limit 100; - --- end template query8.tpl query 9 in stream 4 --- start template query71.tpl query 10 in stream 4 -select /* TPC-DS query71.tpl 0.72 */ i_brand_id brand_id, i_brand brand,t_hour,t_minute, - sum(ext_price) ext_price - from item, (select ws_ext_sales_price as ext_price, - ws_sold_date_sk as sold_date_sk, - ws_item_sk as sold_item_sk, - ws_sold_time_sk as time_sk - from web_sales,date_dim - where d_date_sk = ws_sold_date_sk - and d_moy=12 - and d_year=1999 - union all - select cs_ext_sales_price as ext_price, - cs_sold_date_sk as sold_date_sk, - cs_item_sk as sold_item_sk, - cs_sold_time_sk as time_sk - from catalog_sales,date_dim - where d_date_sk = cs_sold_date_sk - and d_moy=12 - and d_year=1999 - union all - select ss_ext_sales_price as ext_price, - ss_sold_date_sk as sold_date_sk, - ss_item_sk as sold_item_sk, - ss_sold_time_sk as time_sk - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - and d_moy=12 - and d_year=1999 - ) tmp,time_dim - where - sold_item_sk = i_item_sk - and i_manager_id=1 - and time_sk = t_time_sk - and (t_meal_time = 'breakfast' or t_meal_time = 'dinner') - group by i_brand, i_brand_id,t_hour,t_minute - order by ext_price desc, i_brand_id - ; - --- end template query71.tpl query 10 in stream 4 --- start template query45.tpl query 11 in stream 4 -select /* TPC-DS query45.tpl 0.18 */ ca_zip, ca_state, sum(ws_sales_price) - from web_sales, customer, customer_address, date_dim, item - where ws_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ws_item_sk = i_item_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', '85392', '85460', '80348', '81792') - or - i_item_id in (select i_item_id - from item - where i_item_sk in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29) - ) - ) - and ws_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 1998 - group by ca_zip, ca_state - order by ca_zip, ca_state - limit 100; - --- end template query45.tpl query 11 in stream 4 --- start template query89.tpl query 12 in stream 4 -select /* TPC-DS query89.tpl 0.56 */ * -from( -select i_category, i_class, i_brand, - s_store_name, s_company_name, - d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, s_store_name, s_company_name) - avg_monthly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - d_year in (2001) and - ((i_category in ('Electronics','Children','Men') and - i_class in ('memory','infants','shirts') - ) - or (i_category in ('Sports','Home','Jewelry') and - i_class in ('sailing','curtains/drapes','jewelry boxes') - )) -group by i_category, i_class, i_brand, - s_store_name, s_company_name, d_moy) tmp1 -where case when (avg_monthly_sales <> 0) then (abs(sum_sales - avg_monthly_sales) / avg_monthly_sales) else null end > 0.1 -order by sum_sales - avg_monthly_sales, s_store_name -limit 100; - --- end template query89.tpl query 12 in stream 4 --- start template query91.tpl query 13 in stream 4 -select /* TPC-DS query91.tpl 0.13 */ - cc_call_center_id Call_Center, - cc_name Call_Center_Name, - cc_manager Manager, - sum(cr_net_loss) Returns_Loss -from - call_center, - catalog_returns, - date_dim, - customer, - customer_address, - customer_demographics, - household_demographics -where - cr_call_center_sk = cc_call_center_sk -and cr_returned_date_sk = d_date_sk -and cr_returning_customer_sk= c_customer_sk -and cd_demo_sk = c_current_cdemo_sk -and hd_demo_sk = c_current_hdemo_sk -and ca_address_sk = c_current_addr_sk -and d_year = 2000 -and d_moy = 12 -and ( (cd_marital_status = 'M' and cd_education_status = 'Unknown') - or(cd_marital_status = 'W' and cd_education_status = 'Advanced Degree')) -and hd_buy_potential like '5001-10000%' -and ca_gmt_offset = -6 -group by cc_call_center_id,cc_name,cc_manager,cd_marital_status,cd_education_status -order by sum(cr_net_loss) desc; - --- end template query91.tpl query 13 in stream 4 --- start template query14a.tpl query 14 in stream 4 -with /* TPC-DS query14a.tpl 0.69 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1998 AND 1998 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1998 AND 1998 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1998 AND 1998 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as - (select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2) x) -, - results AS -(select channel, i_brand_id, i_class_id, i_category_id, sum(sales) sum_sales, sum(number_sales) number_sales - from ( - select 'store' channel, i_brand_id,i_class_id - ,i_category_id,sum(ss_quantity*ss_list_price) sales - , count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1998+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales) - union all - select 'catalog' channel, i_brand_id,i_class_id,i_category_id, sum(cs_quantity*cs_list_price) sales, count(*) number_sales - from catalog_sales - ,item - ,date_dim - where cs_item_sk in (select ss_item_sk from cross_items) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1998+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(cs_quantity*cs_list_price) > (select average_sales from avg_sales) - union all - select 'web' channel, i_brand_id,i_class_id,i_category_id, sum(ws_quantity*ws_list_price) sales , count(*) number_sales - from web_sales - ,item - ,date_dim - where ws_item_sk in (select ss_item_sk from cross_items) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1998+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ws_quantity*ws_list_price) > (select average_sales from avg_sales) - ) y - group by channel, i_brand_id,i_class_id,i_category_id) - - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales -from ( - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales from results - union - select channel, i_brand_id, i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id, i_class_id - union - select channel, i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id - union - select channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel - union - select null as channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results) z -order by channel, i_brand_id, i_class_id, i_category_id - limit 100; -with /* TPC-DS query14a.tpl 0.69 part2 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1998 AND 1998 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1998 AND 1998 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1998 AND 1998 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as -(select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2) x) - select this_year.channel ty_channel - ,this_year.i_brand_id ty_brand - ,this_year.i_class_id ty_class - ,this_year.i_category_id ty_category - ,this_year.sales ty_sales - ,this_year.number_sales ty_number_sales - ,last_year.channel ly_channel - ,last_year.i_brand_id ly_brand - ,last_year.i_class_id ly_class - ,last_year.i_category_id ly_category - ,last_year.sales ly_sales - ,last_year.number_sales ly_number_sales -from - (select 'store' channel, i_brand_id,i_class_id,i_category_id - ,sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1998 + 1 - and d_moy = 12 - and d_dom = 9) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) this_year, - (select 'store' channel, i_brand_id,i_class_id - ,i_category_id, sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1998 - and d_moy = 12 - and d_dom = 9) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) last_year - where this_year.i_brand_id= last_year.i_brand_id - and this_year.i_class_id = last_year.i_class_id - and this_year.i_category_id = last_year.i_category_id - order by this_year.channel, this_year.i_brand_id, this_year.i_class_id, this_year.i_category_id - limit 100; - --- end template query14a.tpl query 14 in stream 4 --- start template query46.tpl query 15 in stream 4 -select /* TPC-DS query46.tpl 0.23 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and (household_demographics.hd_dep_count = 2 or - household_demographics.hd_vehicle_count= -1) - and date_dim.d_dow in (6,0) - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_city in ('Friendship','Spring Hill','Mount Vernon','Mount Olive','Fairview') - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,ca_city) dn,customer,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - limit 100; - --- end template query46.tpl query 15 in stream 4 --- start template query58.tpl query 16 in stream 4 -with /* TPC-DS query58.tpl 0.19 */ ss_items as - (select i_item_id item_id - ,sum(ss_ext_sales_price) ss_item_rev - from store_sales - ,item - ,date_dim - where ss_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '2001-04-08')) - and ss_sold_date_sk = d_date_sk - group by i_item_id), - cs_items as - (select i_item_id item_id - ,sum(cs_ext_sales_price) cs_item_rev - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '2001-04-08')) - and cs_sold_date_sk = d_date_sk - group by i_item_id), - ws_items as - (select i_item_id item_id - ,sum(ws_ext_sales_price) ws_item_rev - from web_sales - ,item - ,date_dim - where ws_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq =(select d_week_seq - from date_dim - where d_date = '2001-04-08')) - and ws_sold_date_sk = d_date_sk - group by i_item_id) - select ss_items.item_id - ,ss_item_rev - ,ss_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ss_dev - ,cs_item_rev - ,cs_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 cs_dev - ,ws_item_rev - ,ws_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ws_dev - ,(ss_item_rev+cs_item_rev+ws_item_rev)/3 average - from ss_items,cs_items,ws_items - where ss_items.item_id=cs_items.item_id - and ss_items.item_id=ws_items.item_id - and ss_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - and ss_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and cs_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and cs_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and ws_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and ws_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - order by item_id - ,ss_item_rev - limit 100; - --- end template query58.tpl query 16 in stream 4 --- start template query48.tpl query 17 in stream 4 -select /* TPC-DS query48.tpl 0.74 */ sum (ss_quantity) - from store_sales, store, customer_demographics, customer_address, date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 1998 - and - ( - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'M' - and - cd_education_status = 'Unknown' - and - ss_sales_price between 100.00 and 150.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'W' - and - cd_education_status = 'Secondary' - and - ss_sales_price between 50.00 and 100.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'U' - and - cd_education_status = '4 yr Degree' - and - ss_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('VA', 'LA', 'TN') - and ss_net_profit between 0 and 2000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('AR', 'KS', 'IN') - and ss_net_profit between 150 and 3000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('IL', 'WI', 'TX') - and ss_net_profit between 50 and 25000 - ) - ) -; - --- end template query48.tpl query 17 in stream 4 --- start template query59.tpl query 18 in stream 4 -with /* TPC-DS query59.tpl 0.30 */ wss as - (select d_week_seq, - ss_store_sk, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - group by d_week_seq,ss_store_sk - ) - select s_store_name1,s_store_id1,d_week_seq1 - ,sun_sales1/sun_sales2,mon_sales1/mon_sales2 - ,tue_sales1/tue_sales2,wed_sales1/wed_sales2,thu_sales1/thu_sales2 - ,fri_sales1/fri_sales2,sat_sales1/sat_sales2 - from - (select s_store_name s_store_name1,wss.d_week_seq d_week_seq1 - ,s_store_id s_store_id1,sun_sales sun_sales1 - ,mon_sales mon_sales1,tue_sales tue_sales1 - ,wed_sales wed_sales1,thu_sales thu_sales1 - ,fri_sales fri_sales1,sat_sales sat_sales1 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1201 and 1201 + 11) y, - (select s_store_name s_store_name2,wss.d_week_seq d_week_seq2 - ,s_store_id s_store_id2,sun_sales sun_sales2 - ,mon_sales mon_sales2,tue_sales tue_sales2 - ,wed_sales wed_sales2,thu_sales thu_sales2 - ,fri_sales fri_sales2,sat_sales sat_sales2 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1201+ 12 and 1201 + 23) x - where s_store_id1=s_store_id2 - and d_week_seq1=d_week_seq2-52 - order by s_store_name1,s_store_id1,d_week_seq1 -limit 100; - --- end template query59.tpl query 18 in stream 4 --- start template query2.tpl query 19 in stream 4 -with /* TPC-DS query2.tpl 0.84 */ wscs as - (select sold_date_sk - ,sales_price - from (select ws_sold_date_sk sold_date_sk - ,ws_ext_sales_price sales_price - from web_sales - union all - select cs_sold_date_sk sold_date_sk - ,cs_ext_sales_price sales_price - from catalog_sales)), - wswscs as - (select d_week_seq, - sum(case when (d_day_name='Sunday') then sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then sales_price else null end) sat_sales - from wscs - ,date_dim - where d_date_sk = sold_date_sk - group by d_week_seq) - select d_week_seq1 - ,round(sun_sales1/sun_sales2,2) - ,round(mon_sales1/mon_sales2,2) - ,round(tue_sales1/tue_sales2,2) - ,round(wed_sales1/wed_sales2,2) - ,round(thu_sales1/thu_sales2,2) - ,round(fri_sales1/fri_sales2,2) - ,round(sat_sales1/sat_sales2,2) - from - (select wswscs.d_week_seq d_week_seq1 - ,sun_sales sun_sales1 - ,mon_sales mon_sales1 - ,tue_sales tue_sales1 - ,wed_sales wed_sales1 - ,thu_sales thu_sales1 - ,fri_sales fri_sales1 - ,sat_sales sat_sales1 - from wswscs,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 1999) y, - (select wswscs.d_week_seq d_week_seq2 - ,sun_sales sun_sales2 - ,mon_sales mon_sales2 - ,tue_sales tue_sales2 - ,wed_sales wed_sales2 - ,thu_sales thu_sales2 - ,fri_sales fri_sales2 - ,sat_sales sat_sales2 - from wswscs - ,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 1999+1) z - where d_week_seq1=d_week_seq2-53 - order by d_week_seq1; - --- end template query2.tpl query 19 in stream 4 --- start template query83.tpl query 20 in stream 4 -with /* TPC-DS query83.tpl 0.96 */ sr_items as - (select i_item_id item_id, - sum(sr_return_quantity) sr_item_qty - from store_returns, - item, - date_dim - where sr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('1998-06-01','1998-09-01','1998-11-09'))) - and sr_returned_date_sk = d_date_sk - group by i_item_id), - cr_items as - (select i_item_id item_id, - sum(cr_return_quantity) cr_item_qty - from catalog_returns, - item, - date_dim - where cr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('1998-06-01','1998-09-01','1998-11-09'))) - and cr_returned_date_sk = d_date_sk - group by i_item_id), - wr_items as - (select i_item_id item_id, - sum(wr_return_quantity) wr_item_qty - from web_returns, - item, - date_dim - where wr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('1998-06-01','1998-09-01','1998-11-09'))) - and wr_returned_date_sk = d_date_sk - group by i_item_id) - select sr_items.item_id - ,sr_item_qty - ,sr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 sr_dev - ,cr_item_qty - ,cr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 cr_dev - ,wr_item_qty - ,wr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 wr_dev - ,(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 average - from sr_items - ,cr_items - ,wr_items - where sr_items.item_id=cr_items.item_id - and sr_items.item_id=wr_items.item_id - order by sr_items.item_id - ,sr_item_qty - limit 100; - --- end template query83.tpl query 20 in stream 4 --- start template query21.tpl query 21 in stream 4 -select /* TPC-DS query21.tpl 0.14 */ * - from(select w_warehouse_name - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('2001-02-14' as date)) - then inv_quantity_on_hand - else 0 end) as inv_before - ,sum(case when (cast(d_date as date) >= cast ('2001-02-14' as date)) - then inv_quantity_on_hand - else 0 end) as inv_after - from inventory - ,warehouse - ,item - ,date_dim - where i_current_price between 0.99 and 1.49 - and i_item_sk = inv_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('2001-02-14' as date)) - and dateadd(day,30,cast ('2001-02-14' as date)) - group by w_warehouse_name, i_item_id) x - where (case when inv_before > 0 - then inv_after / inv_before - else null - end) between 2.0/3.0 and 3.0/2.0 - order by w_warehouse_name - ,i_item_id - limit 100; - --- end template query21.tpl query 21 in stream 4 --- start template query78.tpl query 22 in stream 4 -with /* TPC-DS query78.tpl 0.10 */ ws as - (select d_year AS ws_sold_year, ws_item_sk, - ws_bill_customer_sk ws_customer_sk, - sum(ws_quantity) ws_qty, - sum(ws_wholesale_cost) ws_wc, - sum(ws_sales_price) ws_sp - from web_sales - left join web_returns on wr_order_number=ws_order_number and ws_item_sk=wr_item_sk - join date_dim on ws_sold_date_sk = d_date_sk - where wr_order_number is null - group by d_year, ws_item_sk, ws_bill_customer_sk - ), -cs as - (select d_year AS cs_sold_year, cs_item_sk, - cs_bill_customer_sk cs_customer_sk, - sum(cs_quantity) cs_qty, - sum(cs_wholesale_cost) cs_wc, - sum(cs_sales_price) cs_sp - from catalog_sales - left join catalog_returns on cr_order_number=cs_order_number and cs_item_sk=cr_item_sk - join date_dim on cs_sold_date_sk = d_date_sk - where cr_order_number is null - group by d_year, cs_item_sk, cs_bill_customer_sk - ), -ss as - (select d_year AS ss_sold_year, ss_item_sk, - ss_customer_sk, - sum(ss_quantity) ss_qty, - sum(ss_wholesale_cost) ss_wc, - sum(ss_sales_price) ss_sp - from store_sales - left join store_returns on sr_ticket_number=ss_ticket_number and ss_item_sk=sr_item_sk - join date_dim on ss_sold_date_sk = d_date_sk - where sr_ticket_number is null - group by d_year, ss_item_sk, ss_customer_sk - ) - select -ss_sold_year, -round(ss_qty/(coalesce(ws_qty,0)+coalesce(cs_qty,0)),2) ratio, -ss_qty store_qty, ss_wc store_wholesale_cost, ss_sp store_sales_price, -coalesce(ws_qty,0)+coalesce(cs_qty,0) other_chan_qty, -coalesce(ws_wc,0)+coalesce(cs_wc,0) other_chan_wholesale_cost, -coalesce(ws_sp,0)+coalesce(cs_sp,0) other_chan_sales_price -from ss -left join ws on (ws_sold_year=ss_sold_year and ws_item_sk=ss_item_sk and ws_customer_sk=ss_customer_sk) -left join cs on (cs_sold_year=ss_sold_year and cs_item_sk=ss_item_sk and cs_customer_sk=ss_customer_sk) -where (coalesce(ws_qty,0)>0 or coalesce(cs_qty, 0)>0) and ss_sold_year=1999 -order by - ss_sold_year, - ss_qty desc, ss_wc desc, ss_sp desc, - other_chan_qty, - other_chan_wholesale_cost, - other_chan_sales_price, - ratio -limit 100; - --- end template query78.tpl query 22 in stream 4 --- start template query40.tpl query 23 in stream 4 -select /* TPC-DS query40.tpl 0.86 */ - w_state - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('2001-05-06' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_before - ,sum(case when (cast(d_date as date) >= cast ('2001-05-06' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_after - from - catalog_sales left outer join catalog_returns on - (cs_order_number = cr_order_number - and cs_item_sk = cr_item_sk) - ,warehouse - ,item - ,date_dim - where - i_current_price between 0.99 and 1.49 - and i_item_sk = cs_item_sk - and cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('2001-05-06' as date)) - and dateadd(day,30,cast ('2001-05-06' as date)) - group by - w_state,i_item_id - order by w_state,i_item_id -limit 100; - --- end template query40.tpl query 23 in stream 4 --- start template query99.tpl query 24 in stream 4 -select /* TPC-DS query99.tpl 0.94 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 30) and - (cs_ship_date_sk - cs_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 60) and - (cs_ship_date_sk - cs_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 90) and - (cs_ship_date_sk - cs_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - catalog_sales - ,warehouse - ,ship_mode - ,call_center - ,date_dim -where - d_month_seq between 1210 and 1210 + 11 -and cs_ship_date_sk = d_date_sk -and cs_warehouse_sk = w_warehouse_sk -and cs_ship_mode_sk = sm_ship_mode_sk -and cs_call_center_sk = cc_call_center_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -limit 100; - --- end template query99.tpl query 24 in stream 4 --- start template query19.tpl query 25 in stream 4 -select /* TPC-DS query19.tpl 0.8 */ i_brand_id brand_id, i_brand brand, i_manufact_id, i_manufact, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item,customer,customer_address,store - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=30 - and d_moy=11 - and d_year=1998 - and ss_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and substring(ca_zip,1,5) <> substring(s_zip,1,5) - and ss_store_sk = s_store_sk - group by i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact - order by ext_price desc - ,i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact -limit 100 ; - --- end template query19.tpl query 25 in stream 4 --- start template query72.tpl query 26 in stream 4 -select /* TPC-DS query72.tpl 0.87 */ i_item_desc - ,w_warehouse_name - ,d1.d_week_seq - ,sum(case when p_promo_sk is null then 1 else 0 end) no_promo - ,sum(case when p_promo_sk is not null then 1 else 0 end) promo - ,count(*) total_cnt -from catalog_sales -join inventory on (cs_item_sk = inv_item_sk) -join warehouse on (w_warehouse_sk=inv_warehouse_sk) -join item on (i_item_sk = cs_item_sk) -join customer_demographics on (cs_bill_cdemo_sk = cd_demo_sk) -join household_demographics on (cs_bill_hdemo_sk = hd_demo_sk) -join date_dim d1 on (cs_sold_date_sk = d1.d_date_sk) -join date_dim d2 on (inv_date_sk = d2.d_date_sk) -join date_dim d3 on (cs_ship_date_sk = d3.d_date_sk) -left outer join promotion on (cs_promo_sk=p_promo_sk) -left outer join catalog_returns on (cr_item_sk = cs_item_sk and cr_order_number = cs_order_number) -where d1.d_week_seq = d2.d_week_seq - and inv_quantity_on_hand < cs_quantity - and d3.d_date > d1.d_date + 5 - and hd_buy_potential = '1001-5000' - and d1.d_year = 1998 - and cd_marital_status = 'D' -group by i_item_desc,w_warehouse_name,d1.d_week_seq -order by total_cnt desc, i_item_desc, w_warehouse_name, d_week_seq -limit 100; - --- end template query72.tpl query 26 in stream 4 --- start template query6.tpl query 27 in stream 4 -select /* TPC-DS query6.tpl 0.58 */ a.ca_state state, count(*) cnt - from customer_address a - ,customer c - ,store_sales s - ,date_dim d - ,item i - where a.ca_address_sk = c.c_current_addr_sk - and c.c_customer_sk = s.ss_customer_sk - and s.ss_sold_date_sk = d.d_date_sk - and s.ss_item_sk = i.i_item_sk - and d.d_month_seq = - (select distinct (d_month_seq) - from date_dim - where d_year = 2000 - and d_moy = 1 ) - and i.i_current_price > 1.2 * - (select avg(j.i_current_price) - from item j - where j.i_category = i.i_category) - group by a.ca_state - having count(*) >= 10 - order by cnt, a.ca_state - limit 100; - --- end template query6.tpl query 27 in stream 4 --- start template query28.tpl query 28 in stream 4 -select /* TPC-DS query28.tpl 0.36 */ * -from (select avg(ss_list_price) B1_LP - ,count(ss_list_price) B1_CNT - ,count(distinct ss_list_price) B1_CNTD - from store_sales - where ss_quantity between 0 and 5 - and (ss_list_price between 75 and 75+10 - or ss_coupon_amt between 1405 and 1405+1000 - or ss_wholesale_cost between 13 and 13+20)) B1, - (select avg(ss_list_price) B2_LP - ,count(ss_list_price) B2_CNT - ,count(distinct ss_list_price) B2_CNTD - from store_sales - where ss_quantity between 6 and 10 - and (ss_list_price between 81 and 81+10 - or ss_coupon_amt between 2050 and 2050+1000 - or ss_wholesale_cost between 14 and 14+20)) B2, - (select avg(ss_list_price) B3_LP - ,count(ss_list_price) B3_CNT - ,count(distinct ss_list_price) B3_CNTD - from store_sales - where ss_quantity between 11 and 15 - and (ss_list_price between 19 and 19+10 - or ss_coupon_amt between 1073 and 1073+1000 - or ss_wholesale_cost between 76 and 76+20)) B3, - (select avg(ss_list_price) B4_LP - ,count(ss_list_price) B4_CNT - ,count(distinct ss_list_price) B4_CNTD - from store_sales - where ss_quantity between 16 and 20 - and (ss_list_price between 20 and 20+10 - or ss_coupon_amt between 14228 and 14228+1000 - or ss_wholesale_cost between 50 and 50+20)) B4, - (select avg(ss_list_price) B5_LP - ,count(ss_list_price) B5_CNT - ,count(distinct ss_list_price) B5_CNTD - from store_sales - where ss_quantity between 21 and 25 - and (ss_list_price between 96 and 96+10 - or ss_coupon_amt between 15342 and 15342+1000 - or ss_wholesale_cost between 41 and 41+20)) B5, - (select avg(ss_list_price) B6_LP - ,count(ss_list_price) B6_CNT - ,count(distinct ss_list_price) B6_CNTD - from store_sales - where ss_quantity between 26 and 30 - and (ss_list_price between 18 and 18+10 - or ss_coupon_amt between 12972 and 12972+1000 - or ss_wholesale_cost between 48 and 48+20)) B6 -limit 100; - --- end template query28.tpl query 28 in stream 4 --- start template query81.tpl query 29 in stream 4 -with /* TPC-DS query81.tpl 0.37 */ customer_total_return as - (select cr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(cr_return_amt_inc_tax) as ctr_total_return - from catalog_returns - ,date_dim - ,customer_address - where cr_returned_date_sk = d_date_sk - and d_year =2000 - and cr_returning_addr_sk = ca_address_sk - group by cr_returning_customer_sk - ,ca_state ) - select c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'VA' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - limit 100; - --- end template query81.tpl query 29 in stream 4 --- start template query44.tpl query 30 in stream 4 -select /* TPC-DS query44.tpl 0.4 */ asceding.rnk, i1.i_product_name best_performing, i2.i_product_name worst_performing -from(select * - from (select item_sk,rank() over (order by rank_col asc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 147 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 147 - and ss_addr_sk is null - group by ss_store_sk))V1)V11 - where rnk < 11) asceding, - (select * - from (select item_sk,rank() over (order by rank_col desc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 147 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 147 - and ss_addr_sk is null - group by ss_store_sk))V2)V21 - where rnk < 11) descending, -item i1, -item i2 -where asceding.rnk = descending.rnk - and i1.i_item_sk=asceding.item_sk - and i2.i_item_sk=descending.item_sk -order by asceding.rnk -limit 100; - --- end template query44.tpl query 30 in stream 4 --- start template query97.tpl query 31 in stream 4 -with /* TPC-DS query97.tpl 0.38 */ ssci as ( -select ss_customer_sk customer_sk - ,ss_item_sk item_sk -from store_sales,date_dim -where ss_sold_date_sk = d_date_sk - and d_month_seq between 1208 and 1208 + 11 -group by ss_customer_sk - ,ss_item_sk), -csci as( - select cs_bill_customer_sk customer_sk - ,cs_item_sk item_sk -from catalog_sales,date_dim -where cs_sold_date_sk = d_date_sk - and d_month_seq between 1208 and 1208 + 11 -group by cs_bill_customer_sk - ,cs_item_sk) - select sum(case when ssci.customer_sk is not null and csci.customer_sk is null then 1 else 0 end) store_only - ,sum(case when ssci.customer_sk is null and csci.customer_sk is not null then 1 else 0 end) catalog_only - ,sum(case when ssci.customer_sk is not null and csci.customer_sk is not null then 1 else 0 end) store_and_catalog -from ssci full outer join csci on (ssci.customer_sk=csci.customer_sk - and ssci.item_sk = csci.item_sk) -limit 100; - --- end template query97.tpl query 31 in stream 4 --- start template query88.tpl query 32 in stream 4 -select /* TPC-DS query88.tpl 0.66 */ * -from - (select count(*) h8_30_to_9 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s1, - (select count(*) h9_to_9_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s2, - (select count(*) h9_30_to_10 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s3, - (select count(*) h10_to_10_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s4, - (select count(*) h10_30_to_11 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s5, - (select count(*) h11_to_11_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s6, - (select count(*) h11_30_to_12 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s7, - (select count(*) h12_to_12_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 12 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) - and store.s_store_name = 'ese') s8 -; - --- end template query88.tpl query 32 in stream 4 --- start template query77a.tpl query 33 in stream 4 -with /* TPC-DS query77a.tpl 0.78 */ ss as - (select s_store_sk, - sum(ss_ext_sales_price) as sales, - sum(ss_net_profit) as profit - from store_sales, - date_dim, - store - where ss_sold_date_sk = d_date_sk - and d_date between cast('2001-08-16' as date) - and dateadd(day,30,cast('2001-08-16' as date)) - and ss_store_sk = s_store_sk - group by s_store_sk) - , - sr as - (select s_store_sk, - sum(sr_return_amt) as returns, - sum(sr_net_loss) as profit_loss - from store_returns, - date_dim, - store - where sr_returned_date_sk = d_date_sk - and d_date between cast('2001-08-16' as date) - and dateadd(day,30,cast('2001-08-16' as date)) - and sr_store_sk = s_store_sk - group by s_store_sk), - cs as - (select cs_call_center_sk, - sum(cs_ext_sales_price) as sales, - sum(cs_net_profit) as profit - from catalog_sales, - date_dim - where cs_sold_date_sk = d_date_sk - and d_date between cast('2001-08-16' as date) - and dateadd(day,30,cast('2001-08-16' as date)) - group by cs_call_center_sk - ), - cr as - (select cr_call_center_sk, - sum(cr_return_amount) as returns, - sum(cr_net_loss) as profit_loss - from catalog_returns, - date_dim - where cr_returned_date_sk = d_date_sk - and d_date between cast('2001-08-16' as date) - and dateadd(day,30,cast('2001-08-16' as date)) - group by cr_call_center_sk), - ws as - ( select wp_web_page_sk, - sum(ws_ext_sales_price) as sales, - sum(ws_net_profit) as profit - from web_sales, - date_dim, - web_page - where ws_sold_date_sk = d_date_sk - and d_date between cast('2001-08-16' as date) - and dateadd(day,30,cast('2001-08-16' as date)) - and ws_web_page_sk = wp_web_page_sk - group by wp_web_page_sk), - wr as - (select wp_web_page_sk, - sum(wr_return_amt) as returns, - sum(wr_net_loss) as profit_loss - from web_returns, - date_dim, - web_page - where wr_returned_date_sk = d_date_sk - and d_date between cast('2001-08-16' as date) - and dateadd(day,30,cast('2001-08-16' as date)) - and wr_web_page_sk = wp_web_page_sk - group by wp_web_page_sk) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , ss.s_store_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ss left join sr - on ss.s_store_sk = sr.s_store_sk - union all - select 'catalog channel' as channel - , cs_call_center_sk as id - , sales - , returns - , (profit - profit_loss) as profit - from cs - , cr - union all - select 'web channel' as channel - , ws.wp_web_page_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ws left join wr - on ws.wp_web_page_sk = wr.wp_web_page_sk - ) x - group by channel, id ) - - select * - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results -) foo -order by channel, id - limit 100; - --- end template query77a.tpl query 33 in stream 4 --- start template query95.tpl query 34 in stream 4 -with /* TPC-DS query95.tpl 0.43 */ ws_wh as -(select ws1.ws_order_number,ws1.ws_warehouse_sk wh1,ws2.ws_warehouse_sk wh2 - from web_sales ws1,web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) - select - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '1999-2-01' and - dateadd(day,60,cast('1999-2-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'TN' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and ws1.ws_order_number in (select ws_order_number - from ws_wh) -and ws1.ws_order_number in (select wr_order_number - from web_returns,ws_wh - where wr_order_number = ws_wh.ws_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query95.tpl query 34 in stream 4 --- start template query33.tpl query 35 in stream 4 -with /* TPC-DS query33.tpl 0.22 */ ss as ( - select - i_manufact_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Home')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 5 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id), - cs as ( - select - i_manufact_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Home')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 5 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id), - ws as ( - select - i_manufact_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Home')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 5 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id) - select i_manufact_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_manufact_id - order by total_sales -limit 100; - --- end template query33.tpl query 35 in stream 4 --- start template query36a.tpl query 36 in stream 4 -with /* TPC-DS query36a.tpl 0.21 */ results as - (select - sum(ss_net_profit) as ss_net_profit, sum(ss_ext_sales_price) as ss_ext_sales_price, - sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin - ,i_category - ,i_class - ,0 as g_category, 0 as g_class - from - store_sales - ,date_dim d1 - ,item - ,store - where - d1.d_year = 1999 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and s_state in ('WA','FL','OH','GA', - 'IN','LA','MI','SC') - group by i_category,i_class) - , - results_rollup as - (select gross_margin ,i_category ,i_class,0 as t_category, 0 as t_class, 0 as lochierarchy from results - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - i_category, NULL AS i_class, 0 as t_category, 1 as t_class, 1 as lochierarchy from results group by i_category - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - NULL AS i_category ,NULL AS i_class, 1 as t_category, 1 as t_class, 2 as lochierarchy from results) - select - gross_margin ,i_category ,i_class, lochierarchy,rank() over ( - partition by lochierarchy, case when t_class = 0 then i_category end - order by gross_margin asc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then i_category end - ,rank_within_parent - limit 100; - --- end template query36a.tpl query 36 in stream 4 --- start template query61.tpl query 37 in stream 4 -select /* TPC-DS query61.tpl 0.97 */ promotions,total,cast(promotions as decimal(15,4))/cast(total as decimal(15,4))*100 -from - (select sum(ss_ext_sales_price) promotions - from store_sales - ,store - ,promotion - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_promo_sk = p_promo_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -7 - and i_category = 'Sports' - and (p_channel_dmail = 'Y' or p_channel_email = 'Y' or p_channel_tv = 'Y') - and s_gmt_offset = -7 - and d_year = 1998 - and d_moy = 12) promotional_sales, - (select sum(ss_ext_sales_price) total - from store_sales - ,store - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -7 - and i_category = 'Sports' - and s_gmt_offset = -7 - and d_year = 1998 - and d_moy = 12) all_sales -order by promotions, total -limit 100; - --- end template query61.tpl query 37 in stream 4 --- start template query35a.tpl query 38 in stream 4 -select /* TPC-DS query35a.tpl 0.47 */ - ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - count(*) cnt1, - min(cd_dep_count), - avg(cd_dep_count), - sum(cd_dep_count), - cd_dep_employed_count, - count(*) cnt2, - min(cd_dep_employed_count), - avg(cd_dep_employed_count), - sum(cd_dep_employed_count), - cd_dep_college_count, - count(*) cnt3, - min(cd_dep_college_count), - avg(cd_dep_college_count), - sum(cd_dep_college_count) - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2002 and - d_qoy < 4) and - exists (select * from - (select ws_bill_customer_sk customsk - from web_sales,date_dim - where - ws_sold_date_sk = d_date_sk and - d_year = 2002 and - d_qoy < 4 - union all - select cs_ship_customer_sk customsk - from catalog_sales,date_dim - where - cs_sold_date_sk = d_date_sk and - d_year = 2002 and - d_qoy < 4)x - where x.customsk = c.c_customer_sk) - group by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - limit 100; - --- end template query35a.tpl query 38 in stream 4 --- start template query60.tpl query 39 in stream 4 -with /* TPC-DS query60.tpl 0.29 */ ss as ( - select - i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Men')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 10 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - cs as ( - select - i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Men')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 10 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - ws as ( - select - i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Men')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 10 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id) - select - i_item_id -,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by i_item_id - ,total_sales - limit 100; - --- end template query60.tpl query 39 in stream 4 --- start template query75.tpl query 40 in stream 4 -WITH /* TPC-DS query75.tpl 0.3 */ all_sales AS ( - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,SUM(sales_cnt) AS sales_cnt - ,SUM(sales_amt) AS sales_amt - FROM (SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,cs_quantity - COALESCE(cr_return_quantity,0) AS sales_cnt - ,cs_ext_sales_price - COALESCE(cr_return_amount,0.0) AS sales_amt - FROM catalog_sales JOIN item ON i_item_sk=cs_item_sk - JOIN date_dim ON d_date_sk=cs_sold_date_sk - LEFT JOIN catalog_returns ON (cs_order_number=cr_order_number - AND cs_item_sk=cr_item_sk) - WHERE i_category='Home' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ss_quantity - COALESCE(sr_return_quantity,0) AS sales_cnt - ,ss_ext_sales_price - COALESCE(sr_return_amt,0.0) AS sales_amt - FROM store_sales JOIN item ON i_item_sk=ss_item_sk - JOIN date_dim ON d_date_sk=ss_sold_date_sk - LEFT JOIN store_returns ON (ss_ticket_number=sr_ticket_number - AND ss_item_sk=sr_item_sk) - WHERE i_category='Home' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ws_quantity - COALESCE(wr_return_quantity,0) AS sales_cnt - ,ws_ext_sales_price - COALESCE(wr_return_amt,0.0) AS sales_amt - FROM web_sales JOIN item ON i_item_sk=ws_item_sk - JOIN date_dim ON d_date_sk=ws_sold_date_sk - LEFT JOIN web_returns ON (ws_order_number=wr_order_number - AND ws_item_sk=wr_item_sk) - WHERE i_category='Home') sales_detail - GROUP BY d_year, i_brand_id, i_class_id, i_category_id, i_manufact_id) - SELECT prev_yr.d_year AS prev_year - ,curr_yr.d_year AS year - ,curr_yr.i_brand_id - ,curr_yr.i_class_id - ,curr_yr.i_category_id - ,curr_yr.i_manufact_id - ,prev_yr.sales_cnt AS prev_yr_cnt - ,curr_yr.sales_cnt AS curr_yr_cnt - ,curr_yr.sales_cnt-prev_yr.sales_cnt AS sales_cnt_diff - ,curr_yr.sales_amt-prev_yr.sales_amt AS sales_amt_diff - FROM all_sales curr_yr, all_sales prev_yr - WHERE curr_yr.i_brand_id=prev_yr.i_brand_id - AND curr_yr.i_class_id=prev_yr.i_class_id - AND curr_yr.i_category_id=prev_yr.i_category_id - AND curr_yr.i_manufact_id=prev_yr.i_manufact_id - AND curr_yr.d_year=2000 - AND prev_yr.d_year=2000-1 - AND CAST(curr_yr.sales_cnt AS DECIMAL(17,2))/CAST(prev_yr.sales_cnt AS DECIMAL(17,2))<0.9 - ORDER BY sales_cnt_diff,sales_amt_diff - limit 100; - --- end template query75.tpl query 40 in stream 4 --- start template query74.tpl query 41 in stream 4 -with /* TPC-DS query74.tpl 0.76 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,sum(ss_net_paid) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (2001,2001+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,sum(ws_net_paid) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - and d_year in (2001,2001+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - ) - select - t_s_secyear.customer_id, t_s_secyear.customer_first_name, t_s_secyear.customer_last_name - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.year = 2001 - and t_s_secyear.year = 2001+1 - and t_w_firstyear.year = 2001 - and t_w_secyear.year = 2001+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - order by 1,2,3 -limit 100; - --- end template query74.tpl query 41 in stream 4 --- start template query55.tpl query 42 in stream 4 -select /* TPC-DS query55.tpl 0.82 */ i_brand_id brand_id, i_brand brand, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=2 - and d_moy=11 - and d_year=1998 - group by i_brand, i_brand_id - order by ext_price desc, i_brand_id -limit 100 ; - --- end template query55.tpl query 42 in stream 4 --- start template query51.tpl query 43 in stream 4 -WITH /* TPC-DS query51.tpl 0.46 */ web_v1 as ( -select - ws_item_sk item_sk, d_date, - sum(sum(ws_sales_price)) - over (partition by ws_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from web_sales - ,date_dim -where ws_sold_date_sk=d_date_sk - and d_month_seq between 1222 and 1222+11 - and ws_item_sk is not NULL -group by ws_item_sk, d_date), -store_v1 as ( -select - ss_item_sk item_sk, d_date, - sum(sum(ss_sales_price)) - over (partition by ss_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from store_sales - ,date_dim -where ss_sold_date_sk=d_date_sk - and d_month_seq between 1222 and 1222+11 - and ss_item_sk is not NULL -group by ss_item_sk, d_date) - select * -from (select item_sk - ,d_date - ,web_sales - ,store_sales - ,max(web_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) web_cumulative - ,max(store_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) store_cumulative - from (select case when web.item_sk is not null then web.item_sk else store.item_sk end item_sk - ,case when web.d_date is not null then web.d_date else store.d_date end d_date - ,web.cume_sales web_sales - ,store.cume_sales store_sales - from web_v1 web full outer join store_v1 store on (web.item_sk = store.item_sk - and web.d_date = store.d_date) - )x )y -where web_cumulative > store_cumulative -order by item_sk - ,d_date -limit 100; - --- end template query51.tpl query 43 in stream 4 --- start template query17.tpl query 44 in stream 4 -select /* TPC-DS query17.tpl 0.41 */ i_item_id - ,i_item_desc - ,s_state - ,count(ss_quantity) as store_sales_quantitycount - ,avg(ss_quantity) as store_sales_quantityave - ,stddev_samp(ss_quantity) as store_sales_quantitystdev - ,stddev_samp(ss_quantity)/avg(ss_quantity) as store_sales_quantitycov - ,count(sr_return_quantity) as store_returns_quantitycount - ,avg(sr_return_quantity) as store_returns_quantityave - ,stddev_samp(sr_return_quantity) as store_returns_quantitystdev - ,stddev_samp(sr_return_quantity)/avg(sr_return_quantity) as store_returns_quantitycov - ,count(cs_quantity) as catalog_sales_quantitycount ,avg(cs_quantity) as catalog_sales_quantityave - ,stddev_samp(cs_quantity) as catalog_sales_quantitystdev - ,stddev_samp(cs_quantity)/avg(cs_quantity) as catalog_sales_quantitycov - from store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where d1.d_quarter_name = '2002Q1' - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_quarter_name in ('2002Q1','2002Q2','2002Q3') - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_quarter_name in ('2002Q1','2002Q2','2002Q3') - group by i_item_id - ,i_item_desc - ,s_state - order by i_item_id - ,i_item_desc - ,s_state -limit 100; - --- end template query17.tpl query 44 in stream 4 --- start template query52.tpl query 45 in stream 4 -select /* TPC-DS query52.tpl 0.59 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_sales_price) ext_price - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=11 - and dt.d_year=1999 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,ext_price desc - ,brand_id -limit 100 ; - --- end template query52.tpl query 45 in stream 4 --- start template query90.tpl query 46 in stream 4 -select /* TPC-DS query90.tpl 0.40 */ cast(amc as decimal(15,4))/cast(pmc as decimal(15,4)) am_pm_ratio - from ( select count(*) amc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 7 and 7+1 - and household_demographics.hd_dep_count = 5 - and web_page.wp_char_count between 5000 and 5200) at, - ( select count(*) pmc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 19 and 19+1 - and household_demographics.hd_dep_count = 5 - and web_page.wp_char_count between 5000 and 5200) pt - order by am_pm_ratio - limit 100; - --- end template query90.tpl query 46 in stream 4 --- start template query22a.tpl query 47 in stream 4 -with /* TPC-DS query22a.tpl 0.55 */ results as -(select i_product_name - ,i_brand - ,i_class - ,i_category - ,avg(inv_quantity_on_hand) qoh - from inventory - ,date_dim - ,item --- ,warehouse - where inv_date_sk=d_date_sk - and inv_item_sk=i_item_sk --- and inv_warehouse_sk = w_warehouse_sk - and d_month_seq between 1188 and 1188 + 11 - group by i_product_name,i_brand,i_class,i_category), -results_rollup as -(select i_product_name, i_brand, i_class, i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class,i_category -union all -select i_product_name, i_brand, i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class -union all -select i_product_name, i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand -union all -select i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name -union all -select null i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results) - select i_product_name, i_brand, i_class, i_category,qoh - from results_rollup - order by qoh, i_product_name, i_brand, i_class, i_category -limit 100; - --- end template query22a.tpl query 47 in stream 4 --- start template query27a.tpl query 48 in stream 4 -with /* TPC-DS query27a.tpl 0.16 */ results as - (select i_item_id, - s_state, 0 as g_state, - ss_quantity agg1, - ss_list_price agg2, - ss_coupon_amt agg3, - ss_sales_price agg4 - from store_sales, customer_demographics, date_dim, store, item - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_store_sk = s_store_sk and - ss_cdemo_sk = cd_demo_sk and - cd_gender = 'M' and - cd_marital_status = 'U' and - cd_education_status = 'Primary' and - d_year = 2002 and - s_state in ('NY','NM', 'OH', 'LA', 'LA', 'MI') - ) - - select i_item_id, - s_state, g_state, agg1, agg2, agg3, agg4 - from ( - select i_item_id, s_state, 0 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4 from results - group by i_item_id, s_state - union all - select i_item_id, NULL AS s_state, 1 AS g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as s_state, 1 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - ) foo - order by i_item_id, s_state - limit 100; - --- end template query27a.tpl query 48 in stream 4 --- start template query63.tpl query 49 in stream 4 -select /* TPC-DS query63.tpl 0.27 */ * -from (select i_manager_id - ,sum(ss_sales_price) sum_sales - ,avg(sum(ss_sales_price)) over (partition by i_manager_id) avg_monthly_sales - from item - ,store_sales - ,date_dim - ,store - where ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and d_month_seq in (1200,1200+1,1200+2,1200+3,1200+4,1200+5,1200+6,1200+7,1200+8,1200+9,1200+10,1200+11) - and (( i_category in ('Books','Children','Electronics') - and i_class in ('personal','portable','reference','self-help') - and i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) - or( i_category in ('Women','Music','Men') - and i_class in ('accessories','classical','fragrances','pants') - and i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manager_id, d_moy) tmp1 -where case when avg_monthly_sales > 0 then abs (sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 -order by i_manager_id - ,avg_monthly_sales - ,sum_sales -limit 100; - --- end template query63.tpl query 49 in stream 4 --- start template query38.tpl query 50 in stream 4 -select /* TPC-DS query38.tpl 0.54 */ count(*) from ( - select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1207 and 1207 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1207 and 1207 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1207 and 1207 + 11 -) hot_cust -limit 100; - --- end template query38.tpl query 50 in stream 4 --- start template query18a.tpl query 51 in stream 4 -with /* TPC-DS query18a.tpl 0.90 */ results as - (select i_item_id, - ca_country, - ca_state, - ca_county, - cast(cs_quantity as decimal(12,2)) agg1, - cast(cs_list_price as decimal(12,2)) agg2, - cast(cs_coupon_amt as decimal(12,2)) agg3, - cast(cs_sales_price as decimal(12,2)) agg4, - cast(cs_net_profit as decimal(12,2)) agg5, - cast(c_birth_year as decimal(12,2)) agg6, - cast(cd1.cd_dep_count as decimal(12,2)) agg7 - from catalog_sales, customer_demographics cd1, customer_demographics cd2, customer, customer_address, date_dim, item - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd1.cd_demo_sk and - cs_bill_customer_sk = c_customer_sk and - cd1.cd_gender = 'M' and - cd1.cd_education_status = '4 yr Degree' and - c_current_cdemo_sk = cd2.cd_demo_sk and - c_current_addr_sk = ca_address_sk and - c_birth_month in (5,9,4,8,10,11) and - d_year = 1999 and - ca_state in ('TX','NY','AR','MO','WI','AL','GA') - ) - select i_item_id, ca_country, ca_state, ca_county, agg1, agg2, agg3, agg4, agg5, agg6, agg7 - from ( - select i_item_id, ca_country, ca_state, ca_county, avg(agg1) agg1, - avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state, ca_county - union all - select i_item_id, ca_country, ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state - union all - select i_item_id, ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country - union all - select i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - ) foo - order by ca_country, ca_state, ca_county, i_item_id - limit 100; - --- end template query18a.tpl query 51 in stream 4 --- start template query24.tpl query 52 in stream 4 -with /* TPC-DS query24.tpl 0.92 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_sales_price) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip -and s_market_id=6 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'magenta' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; -with /* TPC-DS query24.tpl 0.92 part2 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_sales_price) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip - and s_market_id = 6 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'rosy' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; - --- end template query24.tpl query 52 in stream 4 --- start template query37.tpl query 53 in stream 4 -select /* TPC-DS query37.tpl 0.31 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, catalog_sales - where i_current_price between 52 and 52 + 30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('2001-03-03' as date) and dateadd(day,60,cast('2001-03-03' as date)) - and i_manufact_id in (887,806,909,728) - and inv_quantity_on_hand between 100 and 500 - and cs_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query37.tpl query 53 in stream 4 --- start template query47.tpl query 54 in stream 4 -with /* TPC-DS query47.tpl 0.42 */ v1 as( - select i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, - s_store_name, s_company_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - s_store_name, s_company_name - order by d_year, d_moy) rn - from item, store_sales, date_dim, store - where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - ( - d_year = 1999 or - ( d_year = 1999-1 and d_moy =12) or - ( d_year = 1999+1 and d_moy =1) - ) - group by i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy), - v2 as( - select v1.i_category - ,v1.d_year, v1.d_moy - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1.s_store_name = v1_lag.s_store_name and - v1.s_store_name = v1_lead.s_store_name and - v1.s_company_name = v1_lag.s_company_name and - v1.s_company_name = v1_lead.s_company_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 1999 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, nsum - limit 100; - --- end template query47.tpl query 54 in stream 4 --- start template query10.tpl query 55 in stream 4 -select /* TPC-DS query10.tpl 0.26 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3, - cd_dep_count, - count(*) cnt4, - cd_dep_employed_count, - count(*) cnt5, - cd_dep_college_count, - count(*) cnt6 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_county in ('Weld County','Clarendon County','Randolph County','Caldwell County','Union County') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2001 and - d_moy between 3 and 3+3) and - (exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2001 and - d_moy between 3 ANd 3+3) or - exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2001 and - d_moy between 3 and 3+3)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count -limit 100; - --- end template query10.tpl query 55 in stream 4 --- start template query70a.tpl query 56 in stream 4 -with /* TPC-DS query70a.tpl 0.34 */ results as -( select - sum(ss_net_profit) as total_sum ,s_state ,s_county, 0 as gstate, 0 as g_county - from - store_sales - ,date_dim d1 - ,store - where - d1.d_month_seq between 1180 and 1180 + 11 - and d1.d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - and s_state in - ( select s_state - from (select s_state as s_state, - rank() over ( partition by s_state order by sum(ss_net_profit) desc) as ranking - from store_sales, store, date_dim - where d_month_seq between 1180 and 1180 + 11 - and d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - group by s_state - ) tmp1 - where ranking <= 5) - group by s_state,s_county) , - results_rollup as -(select total_sum ,s_state ,s_county, 0 as g_state, 0 as g_county, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum,s_state, NULL as s_county, 0 as g_state, 1 as g_county, 1 as lochierarchy from results group by s_state - union - select sum(total_sum) as total_sum ,NULL as s_state ,NULL as s_county, 1 as g_state, 1 as g_county, 2 as lochierarchy from results) - select total_sum ,s_state ,s_county, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_county = 0 then s_state end - order by total_sum desc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then s_state end - ,rank_within_parent - limit 100; - --- end template query70a.tpl query 56 in stream 4 --- start template query23.tpl query 57 in stream 4 -with /* TPC-DS query23.tpl 0.68 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (2000,2000+1,2000+2,2000+3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (2000,2000+1,2000+2,2000+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * -from - max_store_sales)) - select sum(sales) - from (select cs_quantity*cs_list_price sales - from catalog_sales - ,date_dim - where d_year = 2000 - and d_moy = 2 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - union all - select ws_quantity*ws_list_price sales - from web_sales - ,date_dim - where d_year = 2000 - and d_moy = 2 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer)) - limit 100; -with /* TPC-DS query23.tpl 0.68 part2 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (2000,2000 + 1,2000 + 2,2000 + 3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (2000,2000+1,2000+2,2000+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * - from max_store_sales)) - select c_last_name,c_first_name,sales - from (select c_last_name,c_first_name,sum(cs_quantity*cs_list_price) sales - from catalog_sales - ,customer - ,date_dim - where d_year = 2000 - and d_moy = 2 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and cs_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name - union all - select c_last_name,c_first_name,sum(ws_quantity*ws_list_price) sales - from web_sales - ,customer - ,date_dim - where d_year = 2000 - and d_moy = 2 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and ws_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name) - order by c_last_name,c_first_name,sales - limit 100; - --- end template query23.tpl query 57 in stream 4 --- start template query7.tpl query 58 in stream 4 -select /* TPC-DS query7.tpl 0.2 */ i_item_id, - avg(ss_quantity) agg1, - avg(ss_list_price) agg2, - avg(ss_coupon_amt) agg3, - avg(ss_sales_price) agg4 - from store_sales, customer_demographics, date_dim, item, promotion - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_cdemo_sk = cd_demo_sk and - ss_promo_sk = p_promo_sk and - cd_gender = 'M' and - cd_marital_status = 'M' and - cd_education_status = 'Unknown' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 2001 - group by i_item_id - order by i_item_id - limit 100; - --- end template query7.tpl query 58 in stream 4 --- start template query92.tpl query 59 in stream 4 -select /* TPC-DS query92.tpl 0.44 */ - sum(ws_ext_discount_amt) as "Excess Discount Amount" -from - web_sales - ,item - ,date_dim -where -i_manufact_id = 49 -and i_item_sk = ws_item_sk -and d_date between '2002-02-18' and - dateadd(day,90,cast('2002-02-18' as date)) -and d_date_sk = ws_sold_date_sk -and ws_ext_discount_amt - > ( - SELECT - 1.3 * avg(ws_ext_discount_amt) - FROM - web_sales - ,date_dim - WHERE - ws_item_sk = i_item_sk - and d_date between '2002-02-18' and - dateadd(day,90,cast('2002-02-18' as date)) - and d_date_sk = ws_sold_date_sk - ) -order by sum(ws_ext_discount_amt) -limit 100; - --- end template query92.tpl query 59 in stream 4 --- start template query54.tpl query 60 in stream 4 -with /* TPC-DS query54.tpl 0.81 */ my_customers as ( - select distinct c_customer_sk - , c_current_addr_sk - from - ( select cs_sold_date_sk sold_date_sk, - cs_bill_customer_sk customer_sk, - cs_item_sk item_sk - from catalog_sales - union all - select ws_sold_date_sk sold_date_sk, - ws_bill_customer_sk customer_sk, - ws_item_sk item_sk - from web_sales - ) cs_or_ws_sales, - item, - date_dim, - customer - where sold_date_sk = d_date_sk - and item_sk = i_item_sk - and i_category = 'Jewelry' - and i_class = 'earings' - and c_customer_sk = cs_or_ws_sales.customer_sk - and d_moy = 3 - and d_year = 1999 - ) - , my_revenue as ( - select c_customer_sk, - sum(ss_ext_sales_price) as revenue - from my_customers, - store_sales, - customer_address, - store, - date_dim - where c_current_addr_sk = ca_address_sk - and ca_county = s_county - and ca_state = s_state - and ss_sold_date_sk = d_date_sk - and c_customer_sk = ss_customer_sk - and d_month_seq between (select distinct d_month_seq+1 - from date_dim where d_year = 1999 and d_moy = 3) - and (select distinct d_month_seq+3 - from date_dim where d_year = 1999 and d_moy = 3) - group by c_customer_sk - ) - , segments as - (select cast((revenue/50) as bigint) as segment - from my_revenue - ) - select segment, count(*) as num_customers, segment*50 as segment_base - from segments - group by segment - order by segment, num_customers - limit 100; - --- end template query54.tpl query 60 in stream 4 --- start template query82.tpl query 61 in stream 4 -select /* TPC-DS query82.tpl 0.67 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, store_sales - where i_current_price between 57 and 57+30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('1998-04-22' as date) and dateadd(day,60,cast('1998-04-22' as date)) - and i_manufact_id in (772,636,188,93) - and inv_quantity_on_hand between 100 and 500 - and ss_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query82.tpl query 61 in stream 4 --- start template query76.tpl query 62 in stream 4 -select /* TPC-DS query76.tpl 0.99 */ channel, col_name, d_year, d_qoy, i_category, COUNT(*) sales_cnt, SUM(ext_sales_price) sales_amt FROM ( - SELECT 'store' as channel, 'ss_cdemo_sk' col_name, d_year, d_qoy, i_category, ss_ext_sales_price ext_sales_price - FROM store_sales, item, date_dim - WHERE ss_cdemo_sk IS NULL - AND ss_sold_date_sk=d_date_sk - AND ss_item_sk=i_item_sk - UNION ALL - SELECT 'web' as channel, 'ws_bill_hdemo_sk' col_name, d_year, d_qoy, i_category, ws_ext_sales_price ext_sales_price - FROM web_sales, item, date_dim - WHERE ws_bill_hdemo_sk IS NULL - AND ws_sold_date_sk=d_date_sk - AND ws_item_sk=i_item_sk - UNION ALL - SELECT 'catalog' as channel, 'cs_bill_addr_sk' col_name, d_year, d_qoy, i_category, cs_ext_sales_price ext_sales_price - FROM catalog_sales, item, date_dim - WHERE cs_bill_addr_sk IS NULL - AND cs_sold_date_sk=d_date_sk - AND cs_item_sk=i_item_sk) foo -GROUP BY channel, col_name, d_year, d_qoy, i_category -ORDER BY channel, col_name, d_year, d_qoy, i_category -limit 100; - --- end template query76.tpl query 62 in stream 4 --- start template query80a.tpl query 63 in stream 4 -with /* TPC-DS query80a.tpl 0.6 */ ssr as - (select s_store_id as store_id, - sum(ss_ext_sales_price) as sales, - sum(coalesce(sr_return_amt, 0)) as returns, - sum(ss_net_profit - coalesce(sr_net_loss, 0)) as profit - from store_sales left outer join store_returns on - (ss_item_sk = sr_item_sk and ss_ticket_number = sr_ticket_number), - date_dim, - store, - item, - promotion - where ss_sold_date_sk = d_date_sk - and d_date between cast('1998-08-09' as date) - and dateadd(day,30,cast('1998-08-09' as date)) - and ss_store_sk = s_store_sk - and ss_item_sk = i_item_sk - and i_current_price > 50 - and ss_promo_sk = p_promo_sk - and p_channel_tv = 'N' - group by s_store_id) - , - csr as - (select cp_catalog_page_id as catalog_page_id, - sum(cs_ext_sales_price) as sales, - sum(coalesce(cr_return_amount, 0)) as returns, - sum(cs_net_profit - coalesce(cr_net_loss, 0)) as profit - from catalog_sales left outer join catalog_returns on - (cs_item_sk = cr_item_sk and cs_order_number = cr_order_number), - date_dim, - catalog_page, - item, - promotion - where cs_sold_date_sk = d_date_sk - and d_date between cast('1998-08-09' as date) - and dateadd(day,30,cast('1998-08-09' as date)) - and cs_catalog_page_sk = cp_catalog_page_sk - and cs_item_sk = i_item_sk - and i_current_price > 50 - and cs_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(ws_ext_sales_price) as sales, - sum(coalesce(wr_return_amt, 0)) as returns, - sum(ws_net_profit - coalesce(wr_net_loss, 0)) as profit - from web_sales left outer join web_returns on - (ws_item_sk = wr_item_sk and ws_order_number = wr_order_number), - date_dim, - web_site, - item, - promotion - where ws_sold_date_sk = d_date_sk - and d_date between cast('1998-08-09' as date) - and dateadd(day,30,cast('1998-08-09' as date)) - and ws_web_site_sk = web_site_sk - and ws_item_sk = i_item_sk - and i_current_price > 50 - and ws_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by web_site_id) -, -results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || store_id as id - , sales - , returns - , profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || catalog_page_id as id - , sales - , returns - , profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , profit - from wsr - ) x - group by channel, id) - - select channel - , id - , sales - , returns - , profit - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results - ) foo - order by channel, id - limit 100; - --- end template query80a.tpl query 63 in stream 4 --- start template query56.tpl query 64 in stream 4 -with /* TPC-DS query56.tpl 0.83 */ ss as ( - select i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where i_item_id in (select - i_item_id -from item -where i_color in ('brown','violet','coral')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 5 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id), - cs as ( - select i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('brown','violet','coral')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 5 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id), - ws as ( - select i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('brown','violet','coral')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 5 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id) - select i_item_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by total_sales, - i_item_id - limit 100; - --- end template query56.tpl query 64 in stream 4 --- start template query96.tpl query 65 in stream 4 -select /* TPC-DS query96.tpl 0.1 */ count(*) -from store_sales - ,household_demographics - ,time_dim, store -where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 15 - and time_dim.t_minute >= 30 - and household_demographics.hd_dep_count = 8 - and store.s_store_name = 'ese' -order by count(*) -limit 100; - --- end template query96.tpl query 65 in stream 4 --- start template query50.tpl query 66 in stream 4 -select /* TPC-DS query50.tpl 0.60 */ - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 30) and - (sr_returned_date_sk - ss_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 60) and - (sr_returned_date_sk - ss_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 90) and - (sr_returned_date_sk - ss_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - store_sales - ,store_returns - ,store - ,date_dim d1 - ,date_dim d2 -where - d2.d_year = 1998 -and d2.d_moy = 9 -and ss_ticket_number = sr_ticket_number -and ss_item_sk = sr_item_sk -and ss_sold_date_sk = d1.d_date_sk -and sr_returned_date_sk = d2.d_date_sk -and ss_customer_sk = sr_customer_sk -and ss_store_sk = s_store_sk -group by - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -order by s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -limit 100; - --- end template query50.tpl query 66 in stream 4 --- start template query85.tpl query 67 in stream 4 -select /* TPC-DS query85.tpl 0.33 */ substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) - from web_sales, web_returns, web_page, customer_demographics cd1, - customer_demographics cd2, customer_address, date_dim, reason - where ws_web_page_sk = wp_web_page_sk - and ws_item_sk = wr_item_sk - and ws_order_number = wr_order_number - and ws_sold_date_sk = d_date_sk and d_year = 2000 - and cd1.cd_demo_sk = wr_refunded_cdemo_sk - and cd2.cd_demo_sk = wr_returning_cdemo_sk - and ca_address_sk = wr_refunded_addr_sk - and r_reason_sk = wr_reason_sk - and - ( - ( - cd1.cd_marital_status = 'U' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = '4 yr Degree' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 100.00 and 150.00 - ) - or - ( - cd1.cd_marital_status = 'D' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Primary' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 50.00 and 100.00 - ) - or - ( - cd1.cd_marital_status = 'S' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Secondary' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ca_country = 'United States' - and - ca_state in ('AL', 'VA', 'NE') - and ws_net_profit between 100 and 200 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('TX', 'AK', 'GA') - and ws_net_profit between 150 and 300 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('OK', 'WV', 'MT') - and ws_net_profit between 50 and 250 - ) - ) -group by r_reason_desc -order by substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) -limit 100; - --- end template query85.tpl query 67 in stream 4 --- start template query86a.tpl query 68 in stream 4 -with /* TPC-DS query86a.tpl 0.11 */ results as -( select sum(ws_net_paid) as total_sum, i_category, i_class, 0 as g_category, 0 as g_class - from - web_sales - ,date_dim d1 - ,item - where - d1.d_month_seq between 1189 and 1189+11 - and d1.d_date_sk = ws_sold_date_sk - and i_item_sk = ws_item_sk - group by i_category,i_class - ) , - - results_rollup as -( select total_sum ,i_category ,i_class, g_category, g_class, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum, i_category, NULL as i_class, 0 as g_category, 1 as g_class, 1 as lochierarchy from results group by i_category - union - select sum(total_sum) as total_sum, NULL as i_category, NULL as i_class, 1 as g_category, 1 as g_class, 2 as lochierarchy from results) - select - total_sum ,i_category ,i_class, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_class = 0 then i_category end - order by total_sum desc) as rank_within_parent - from - results_rollup - order by - lochierarchy desc, - case when lochierarchy = 0 then i_category end, - rank_within_parent - limit 100; - --- end template query86a.tpl query 68 in stream 4 --- start template query69.tpl query 69 in stream 4 -select /* TPC-DS query69.tpl 0.28 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_state in ('NE','TN','OK') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 3 and 3+2) and - (not exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 3 and 3+2) and - not exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 3 and 3+2)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - limit 100; - --- end template query69.tpl query 69 in stream 4 --- start template query68.tpl query 70 in stream 4 -select /* TPC-DS query68.tpl 0.95 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,extended_price - ,extended_tax - ,list_price - from (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_ext_sales_price) extended_price - ,sum(ss_ext_list_price) list_price - ,sum(ss_ext_tax) extended_tax - from store_sales - ,date_dim - ,store - ,household_demographics - ,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_dep_count = 9 or - household_demographics.hd_vehicle_count= 3) - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_city in ('Hopewell','Lakeside') - group by ss_ticket_number - ,ss_customer_sk - ,ss_addr_sk,ca_city) dn - ,customer - ,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,ss_ticket_number - limit 100; - --- end template query68.tpl query 70 in stream 4 --- start template query1.tpl query 71 in stream 4 -with /* TPC-DS query1.tpl 0.12 */ customer_total_return as -(select sr_customer_sk as ctr_customer_sk -,sr_store_sk as ctr_store_sk -,sum(SR_REVERSED_CHARGE) as ctr_total_return -from store_returns -,date_dim -where sr_returned_date_sk = d_date_sk -and d_year =1998 -group by sr_customer_sk -,sr_store_sk) - select c_customer_id -from customer_total_return ctr1 -,store -,customer -where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 -from customer_total_return ctr2 -where ctr1.ctr_store_sk = ctr2.ctr_store_sk) -and s_store_sk = ctr1.ctr_store_sk -and s_state = 'SC' -and ctr1.ctr_customer_sk = c_customer_sk -order by c_customer_id -limit 100; - --- end template query1.tpl query 71 in stream 4 --- start template query12.tpl query 72 in stream 4 -select /* TPC-DS query12.tpl 0.64 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ws_ext_sales_price) as itemrevenue - ,sum(ws_ext_sales_price)*100/sum(sum(ws_ext_sales_price)) over - (partition by i_class) as revenueratio -from - web_sales - ,item - ,date_dim -where - ws_item_sk = i_item_sk - and i_category in ('Books', 'Jewelry', 'Electronics') - and ws_sold_date_sk = d_date_sk - and d_date between cast('2000-01-21' as date) - and dateadd(day,30,cast('2000-01-21' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query12.tpl query 72 in stream 4 --- start template query43.tpl query 73 in stream 4 -select /* TPC-DS query43.tpl 0.15 */ s_store_name, s_store_id, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from date_dim, store_sales, store - where d_date_sk = ss_sold_date_sk and - s_store_sk = ss_store_sk and - s_gmt_offset = -7 and - d_year = 2002 - group by s_store_name, s_store_id - order by s_store_name, s_store_id,sun_sales,mon_sales,tue_sales,wed_sales,thu_sales,fri_sales,sat_sales - limit 100; - --- end template query43.tpl query 73 in stream 4 --- start template query16.tpl query 74 in stream 4 -select /* TPC-DS query16.tpl 0.25 */ - count(distinct cs_order_number) as "order count" - ,sum(cs_ext_ship_cost) as "total shipping cost" - ,sum(cs_net_profit) as "total net profit" -from - catalog_sales cs1 - ,date_dim - ,customer_address - ,call_center -where - d_date between '2002-5-01' and - dateadd(day, 60, cast('2002-5-01' as date)) -and cs1.cs_ship_date_sk = d_date_sk -and cs1.cs_ship_addr_sk = ca_address_sk -and ca_state = 'LA' -and cs1.cs_call_center_sk = cc_call_center_sk -and cc_county in ('Barrow County','Luce County','Pennington County','Fairfield County', - 'Daviess County' -) -and exists (select * - from catalog_sales cs2 - where cs1.cs_order_number = cs2.cs_order_number - and cs1.cs_warehouse_sk <> cs2.cs_warehouse_sk) -and not exists(select * - from catalog_returns cr1 - where cs1.cs_order_number = cr1.cr_order_number) -order by count(distinct cs_order_number) -limit 100; - --- end template query16.tpl query 74 in stream 4 --- start template query4.tpl query 75 in stream 4 -with /* TPC-DS query4.tpl 0.93 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(((ss_ext_list_price-ss_ext_wholesale_cost-ss_ext_discount_amt)+ss_ext_sales_price)/2) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((cs_ext_list_price-cs_ext_wholesale_cost-cs_ext_discount_amt)+cs_ext_sales_price)/2) ) year_total - ,'c' sale_type - from customer - ,catalog_sales - ,date_dim - where c_customer_sk = cs_bill_customer_sk - and cs_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year -union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((ws_ext_list_price-ws_ext_wholesale_cost-ws_ext_discount_amt)+ws_ext_sales_price)/2) ) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_login - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_c_firstyear - ,year_total t_c_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_c_secyear.customer_id - and t_s_firstyear.customer_id = t_c_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_c_firstyear.sale_type = 'c' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_c_secyear.sale_type = 'c' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 2000 - and t_s_secyear.dyear = 2000+1 - and t_c_firstyear.dyear = 2000 - and t_c_secyear.dyear = 2000+1 - and t_w_firstyear.dyear = 2000 - and t_w_secyear.dyear = 2000+1 - and t_s_firstyear.year_total > 0 - and t_c_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_login -limit 100; - --- end template query4.tpl query 75 in stream 4 --- start template query25.tpl query 76 in stream 4 -select /* TPC-DS query25.tpl 0.9 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,max(ss_net_profit) as store_sales_profit - ,max(sr_net_loss) as store_returns_loss - ,max(cs_net_profit) as catalog_sales_profit - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 2001 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 10 - and d2.d_year = 2001 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_moy between 4 and 10 - and d3.d_year = 2001 - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query25.tpl query 76 in stream 4 --- start template query20.tpl query 77 in stream 4 -select /* TPC-DS query20.tpl 0.65 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(cs_ext_sales_price) as itemrevenue - ,sum(cs_ext_sales_price)*100/sum(sum(cs_ext_sales_price)) over - (partition by i_class) as revenueratio - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and i_category in ('Electronics', 'Home', 'Music') - and cs_sold_date_sk = d_date_sk - and d_date between cast('2002-04-22' as date) - and dateadd(day,30,cast('2002-04-22' as date)) - group by i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - order by i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query20.tpl query 77 in stream 4 --- start template query65.tpl query 78 in stream 4 -select /* TPC-DS query65.tpl 0.71 */ - s_store_name, - i_item_desc, - sc.revenue, - i_current_price, - i_wholesale_cost, - i_brand - from store, item, - (select ss_store_sk, avg(revenue) as ave - from - (select ss_store_sk, ss_item_sk, - sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1203 and 1203+11 - group by ss_store_sk, ss_item_sk) sa - group by ss_store_sk) sb, - (select ss_store_sk, ss_item_sk, sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1203 and 1203+11 - group by ss_store_sk, ss_item_sk) sc - where sb.ss_store_sk = sc.ss_store_sk and - sc.revenue <= 0.1 * sb.ave and - s_store_sk = sc.ss_store_sk and - i_item_sk = sc.ss_item_sk - order by s_store_name, i_item_desc -limit 100; - --- end template query65.tpl query 78 in stream 4 --- start template query15.tpl query 79 in stream 4 -select /* TPC-DS query15.tpl 0.57 */ ca_zip - ,sum(cs_sales_price) - from catalog_sales - ,customer - ,customer_address - ,date_dim - where cs_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', - '85392', '85460', '80348', '81792') - or ca_state in ('CA','WA','GA') - or cs_sales_price > 500) - and cs_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 1999 - group by ca_zip - order by ca_zip - limit 100; - --- end template query15.tpl query 79 in stream 4 --- start template query98.tpl query 80 in stream 4 -select /* TPC-DS query98.tpl 0.32 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ss_ext_sales_price) as itemrevenue - ,sum(ss_ext_sales_price)*100/sum(sum(ss_ext_sales_price)) over - (partition by i_class) as revenueratio -from - store_sales - ,item - ,date_dim -where - ss_item_sk = i_item_sk - and i_category in ('Children', 'Books', 'Women') - and ss_sold_date_sk = d_date_sk - and d_date between cast('1998-04-09' as date) - and dateadd(day,30,cast('1998-04-09' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio; - --- end template query98.tpl query 80 in stream 4 --- start template query42.tpl query 81 in stream 4 -select /* TPC-DS query42.tpl 0.61 */ dt.d_year - ,item.i_category_id - ,item.i_category - ,sum(ss_ext_sales_price) - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=11 - and dt.d_year=2000 - group by dt.d_year - ,item.i_category_id - ,item.i_category - order by sum(ss_ext_sales_price) desc,dt.d_year - ,item.i_category_id - ,item.i_category -limit 100 ; - --- end template query42.tpl query 81 in stream 4 --- start template query26.tpl query 82 in stream 4 -select /* TPC-DS query26.tpl 0.85 */ i_item_id, - avg(cs_quantity) agg1, - avg(cs_list_price) agg2, - avg(cs_coupon_amt) agg3, - avg(cs_sales_price) agg4 - from catalog_sales, customer_demographics, date_dim, item, promotion - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd_demo_sk and - cs_promo_sk = p_promo_sk and - cd_gender = 'F' and - cd_marital_status = 'U' and - cd_education_status = 'Unknown' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 1999 - group by i_item_id - order by i_item_id - limit 100; - --- end template query26.tpl query 82 in stream 4 --- start template query34.tpl query 83 in stream 4 -select /* TPC-DS query34.tpl 0.73 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (date_dim.d_dom between 1 and 3 or date_dim.d_dom between 25 and 28) - and (household_demographics.hd_buy_potential = '501-1000' or - household_demographics.hd_buy_potential = '0-500') - and household_demographics.hd_vehicle_count > 0 - and (case when household_demographics.hd_vehicle_count > 0 - then household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count - else null - end) > 1.2 - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_county in ('Daviess County','Richland County','Levy County','Mobile County', - 'Williamson County','Marshall County','Oglethorpe County','Gage County') - group by ss_ticket_number,ss_customer_sk) dn,customer - where ss_customer_sk = c_customer_sk - and cnt between 15 and 20 - order by c_last_name,c_first_name,c_salutation,c_preferred_cust_flag desc, ss_ticket_number; - --- end template query34.tpl query 83 in stream 4 --- start template query5a.tpl query 84 in stream 4 -with /* TPC-DS query5a.tpl 0.98 */ ssr as - (select s_store_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ss_store_sk as store_sk, - ss_sold_date_sk as date_sk, - ss_ext_sales_price as sales_price, - ss_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from store_sales - union all - select sr_store_sk as store_sk, - sr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - sr_return_amt as return_amt, - sr_net_loss as net_loss - from store_returns - ) salesreturns, - date_dim, - store - where date_sk = d_date_sk - and d_date between cast('2002-08-19' as date) - and dateadd(day,14,cast('2002-08-19' as date)) - and store_sk = s_store_sk - group by s_store_id) - , - csr as - (select cp_catalog_page_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select cs_catalog_page_sk as page_sk, - cs_sold_date_sk as date_sk, - cs_ext_sales_price as sales_price, - cs_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from catalog_sales - union all - select cr_catalog_page_sk as page_sk, - cr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - cr_return_amount as return_amt, - cr_net_loss as net_loss - from catalog_returns - ) salesreturns, - date_dim, - catalog_page - where date_sk = d_date_sk - and d_date between cast('2002-08-19' as date) - and dateadd(day,14,cast('2002-08-19' as date)) - and page_sk = cp_catalog_page_sk - group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ws_web_site_sk as wsr_web_site_sk, - ws_sold_date_sk as date_sk, - ws_ext_sales_price as sales_price, - ws_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from web_sales - union all - select ws_web_site_sk as wsr_web_site_sk, - wr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - wr_return_amt as return_amt, - wr_net_loss as net_loss - from web_returns left outer join web_sales on - ( wr_item_sk = ws_item_sk - and wr_order_number = ws_order_number) - ) salesreturns, - date_dim, - web_site - where date_sk = d_date_sk - and d_date between cast('2002-08-19' as date) - and dateadd(day,14,cast('2002-08-19' as date)) - and wsr_web_site_sk = web_site_sk - group by web_site_id) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || s_store_id as id - , sales - , returns - , (profit - profit_loss) as profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || cp_catalog_page_id as id - , sales - , returns - , (profit - profit_loss) as profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , (profit - profit_loss) as profit - from wsr - ) x - group by channel, id) - select channel, id, sales, returns, profit from ( - select channel, id, sales, returns, profit from results - union - select channel, null as id, sum(sales), sum(returns), sum(profit) from results group by channel - union - select null as channel, null as id, sum(sales), sum(returns), sum(profit) from results) foo -order by channel, id -limit 100; - --- end template query5a.tpl query 84 in stream 4 --- start template query87.tpl query 85 in stream 4 -select /* TPC-DS query87.tpl 0.77 */ count(*) -from ((select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1219 and 1219+11) - except - (select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1219 and 1219+11) - except - (select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1219 and 1219+11) -) cool_cust -; - --- end template query87.tpl query 85 in stream 4 --- start template query3.tpl query 86 in stream 4 -select /* TPC-DS query3.tpl 0.45 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_sales_price) sum_agg - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manufact_id = 408 - and dt.d_moy=11 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,sum_agg desc - ,brand_id - limit 100; - --- end template query3.tpl query 86 in stream 4 --- start template query64.tpl query 87 in stream 4 -with /* TPC-DS query64.tpl 0.20 */ cs_ui as - (select cs_item_sk - ,sum(cs_ext_list_price) as sale,sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit) as refund - from catalog_sales - ,catalog_returns - where cs_item_sk = cr_item_sk - and cs_order_number = cr_order_number - group by cs_item_sk - having sum(cs_ext_list_price)>2*sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit)), -cross_sales as - (select i_product_name product_name - ,i_item_sk item_sk - ,s_store_name store_name - ,s_zip store_zip - ,ad1.ca_street_number b_street_number - ,ad1.ca_street_name b_street_name - ,ad1.ca_city b_city - ,ad1.ca_zip b_zip - ,ad2.ca_street_number c_street_number - ,ad2.ca_street_name c_street_name - ,ad2.ca_city c_city - ,ad2.ca_zip c_zip - ,d1.d_year as syear - ,d2.d_year as fsyear - ,d3.d_year s2year - ,count(*) cnt - ,sum(ss_wholesale_cost) s1 - ,sum(ss_list_price) s2 - ,sum(ss_coupon_amt) s3 - FROM store_sales - ,store_returns - ,cs_ui - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,customer - ,customer_demographics cd1 - ,customer_demographics cd2 - ,promotion - ,household_demographics hd1 - ,household_demographics hd2 - ,customer_address ad1 - ,customer_address ad2 - ,income_band ib1 - ,income_band ib2 - ,item - WHERE ss_store_sk = s_store_sk AND - ss_sold_date_sk = d1.d_date_sk AND - ss_customer_sk = c_customer_sk AND - ss_cdemo_sk= cd1.cd_demo_sk AND - ss_hdemo_sk = hd1.hd_demo_sk AND - ss_addr_sk = ad1.ca_address_sk and - ss_item_sk = i_item_sk and - ss_item_sk = sr_item_sk and - ss_ticket_number = sr_ticket_number and - ss_item_sk = cs_ui.cs_item_sk and - c_current_cdemo_sk = cd2.cd_demo_sk AND - c_current_hdemo_sk = hd2.hd_demo_sk AND - c_current_addr_sk = ad2.ca_address_sk and - c_first_sales_date_sk = d2.d_date_sk and - c_first_shipto_date_sk = d3.d_date_sk and - ss_promo_sk = p_promo_sk and - hd1.hd_income_band_sk = ib1.ib_income_band_sk and - hd2.hd_income_band_sk = ib2.ib_income_band_sk and - cd1.cd_marital_status <> cd2.cd_marital_status and - i_color in ('beige','magenta','ivory','brown','frosted','floral') and - i_current_price between 55 and 55 + 10 and - i_current_price between 55 + 1 and 55 + 15 -group by i_product_name - ,i_item_sk - ,s_store_name - ,s_zip - ,ad1.ca_street_number - ,ad1.ca_street_name - ,ad1.ca_city - ,ad1.ca_zip - ,ad2.ca_street_number - ,ad2.ca_street_name - ,ad2.ca_city - ,ad2.ca_zip - ,d1.d_year - ,d2.d_year - ,d3.d_year -) -select cs1.product_name - ,cs1.store_name - ,cs1.store_zip - ,cs1.b_street_number - ,cs1.b_street_name - ,cs1.b_city - ,cs1.b_zip - ,cs1.c_street_number - ,cs1.c_street_name - ,cs1.c_city - ,cs1.c_zip - ,cs1.syear - ,cs1.cnt - ,cs1.s1 as s11 - ,cs1.s2 as s21 - ,cs1.s3 as s31 - ,cs2.s1 as s12 - ,cs2.s2 as s22 - ,cs2.s3 as s32 - ,cs2.syear - ,cs2.cnt -from cross_sales cs1,cross_sales cs2 -where cs1.item_sk=cs2.item_sk and - cs1.syear = 1999 and - cs2.syear = 1999 + 1 and - cs2.cnt <= cs1.cnt and - cs1.store_name = cs2.store_name and - cs1.store_zip = cs2.store_zip -order by cs1.product_name - ,cs1.store_name - ,cs2.cnt - ,cs1.s1 - ,cs2.s1; - --- end template query64.tpl query 87 in stream 4 --- start template query31.tpl query 88 in stream 4 -with /* TPC-DS query31.tpl 0.50 */ ss as - (select ca_county,d_qoy, d_year,sum(ss_ext_sales_price) as store_sales - from store_sales,date_dim,customer_address - where ss_sold_date_sk = d_date_sk - and ss_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year), - ws as - (select ca_county,d_qoy, d_year,sum(ws_ext_sales_price) as web_sales - from web_sales,date_dim,customer_address - where ws_sold_date_sk = d_date_sk - and ws_bill_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year) - select - ss1.ca_county - ,ss1.d_year - ,ws2.web_sales/ws1.web_sales web_q1_q2_increase - ,ss2.store_sales/ss1.store_sales store_q1_q2_increase - ,ws3.web_sales/ws2.web_sales web_q2_q3_increase - ,ss3.store_sales/ss2.store_sales store_q2_q3_increase - from - ss ss1 - ,ss ss2 - ,ss ss3 - ,ws ws1 - ,ws ws2 - ,ws ws3 - where - ss1.d_qoy = 1 - and ss1.d_year = 2000 - and ss1.ca_county = ss2.ca_county - and ss2.d_qoy = 2 - and ss2.d_year = 2000 - and ss2.ca_county = ss3.ca_county - and ss3.d_qoy = 3 - and ss3.d_year = 2000 - and ss1.ca_county = ws1.ca_county - and ws1.d_qoy = 1 - and ws1.d_year = 2000 - and ws1.ca_county = ws2.ca_county - and ws2.d_qoy = 2 - and ws2.d_year = 2000 - and ws1.ca_county = ws3.ca_county - and ws3.d_qoy = 3 - and ws3.d_year =2000 - and case when ws1.web_sales > 0 then ws2.web_sales/ws1.web_sales else null end - > case when ss1.store_sales > 0 then ss2.store_sales/ss1.store_sales else null end - and case when ws2.web_sales > 0 then ws3.web_sales/ws2.web_sales else null end - > case when ss2.store_sales > 0 then ss3.store_sales/ss2.store_sales else null end - order by store_q1_q2_increase; - --- end template query31.tpl query 88 in stream 4 --- start template query57.tpl query 89 in stream 4 -with /* TPC-DS query57.tpl 0.70 */ v1 as( - select i_category, i_brand, - cc_name, - d_year, d_moy, - sum(cs_sales_price) sum_sales, - avg(sum(cs_sales_price)) over - (partition by i_category, i_brand, - cc_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - cc_name - order by d_year, d_moy) rn - from item, catalog_sales, date_dim, call_center - where cs_item_sk = i_item_sk and - cs_sold_date_sk = d_date_sk and - cc_call_center_sk= cs_call_center_sk and - ( - d_year = 2000 or - ( d_year = 2000-1 and d_moy =12) or - ( d_year = 2000+1 and d_moy =1) - ) - group by i_category, i_brand, - cc_name , d_year, d_moy), - v2 as( - select v1.i_category, v1.i_brand, v1.cc_name - ,v1.d_year, v1.d_moy - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1. cc_name = v1_lag. cc_name and - v1. cc_name = v1_lead. cc_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 2000 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, nsum - limit 100; - --- end template query57.tpl query 89 in stream 4 --- start template query30.tpl query 90 in stream 4 -with /* TPC-DS query30.tpl 0.75 */ customer_total_return as - (select wr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(wr_return_amt) as ctr_total_return - from web_returns - ,date_dim - ,customer_address - where wr_returned_date_sk = d_date_sk - and d_year =2001 - and wr_returning_addr_sk = ca_address_sk - group by wr_returning_customer_sk - ,ca_state) - select c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'RI' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return -limit 100; - --- end template query30.tpl query 90 in stream 4 --- start template query13.tpl query 91 in stream 4 -select /* TPC-DS query13.tpl 0.91 */ avg(ss_quantity) - ,avg(ss_ext_sales_price) - ,avg(ss_ext_wholesale_cost) - ,sum(ss_ext_wholesale_cost) - from store_sales - ,store - ,customer_demographics - ,household_demographics - ,customer_address - ,date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2001 - and((ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'S' - and cd_education_status = 'College' - and ss_sales_price between 100.00 and 150.00 - and hd_dep_count = 3 - )or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'D' - and cd_education_status = '4 yr Degree' - and ss_sales_price between 50.00 and 100.00 - and hd_dep_count = 1 - ) or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'U' - and cd_education_status = '2 yr Degree' - and ss_sales_price between 150.00 and 200.00 - and hd_dep_count = 1 - )) - and((ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('WY', 'ID', 'GA') - and ss_net_profit between 100 and 200 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('VA', 'SC', 'MT') - and ss_net_profit between 150 and 300 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('MS', 'MO', 'FL') - and ss_net_profit between 50 and 250 - )) -; - --- end template query13.tpl query 91 in stream 4 --- start template query94.tpl query 92 in stream 4 -select /* TPC-DS query94.tpl 0.17 */ - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2000-2-01' and - dateadd(day,60,cast('2000-2-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'WY' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and exists (select * - from web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) -and not exists(select * - from web_returns wr1 - where ws1.ws_order_number = wr1.wr_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query94.tpl query 92 in stream 4 --- start template query62.tpl query 93 in stream 4 -select /* TPC-DS query62.tpl 0.24 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 30) and - (ws_ship_date_sk - ws_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 60) and - (ws_ship_date_sk - ws_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 90) and - (ws_ship_date_sk - ws_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - web_sales - ,warehouse - ,ship_mode - ,web_site - ,date_dim -where - d_month_seq between 1204 and 1204 + 11 -and ws_ship_date_sk = d_date_sk -and ws_warehouse_sk = w_warehouse_sk -and ws_ship_mode_sk = sm_ship_mode_sk -and ws_web_site_sk = web_site_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -limit 100; - --- end template query62.tpl query 93 in stream 4 --- start template query49.tpl query 94 in stream 4 -select /* TPC-DS query49.tpl 0.48 */ channel, item, return_ratio, return_rank, currency_rank from - (select - 'web' as channel - ,web.item - ,web.return_ratio - ,web.return_rank - ,web.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select ws.ws_item_sk as item - ,(cast(sum(coalesce(wr.wr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(wr.wr_return_amt,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - web_sales ws left outer join web_returns wr - on (ws.ws_order_number = wr.wr_order_number and - ws.ws_item_sk = wr.wr_item_sk) - ,date_dim - where - wr.wr_return_amt > 10000 - and ws.ws_net_profit > 1 - and ws.ws_net_paid > 0 - and ws.ws_quantity > 0 - and ws_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 12 - group by ws.ws_item_sk - ) in_web - ) web - where - ( - web.return_rank <= 10 - or - web.currency_rank <= 10 - ) - union - select - 'catalog' as channel - ,catalog.item - ,catalog.return_ratio - ,catalog.return_rank - ,catalog.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select - cs.cs_item_sk as item - ,(cast(sum(coalesce(cr.cr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(cr.cr_return_amount,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - catalog_sales cs left outer join catalog_returns cr - on (cs.cs_order_number = cr.cr_order_number and - cs.cs_item_sk = cr.cr_item_sk) - ,date_dim - where - cr.cr_return_amount > 10000 - and cs.cs_net_profit > 1 - and cs.cs_net_paid > 0 - and cs.cs_quantity > 0 - and cs_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 12 - group by cs.cs_item_sk - ) in_cat - ) catalog - where - ( - catalog.return_rank <= 10 - or - catalog.currency_rank <=10 - ) - union - select - 'store' as channel - ,store.item - ,store.return_ratio - ,store.return_rank - ,store.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select sts.ss_item_sk as item - ,(cast(sum(coalesce(sr.sr_return_quantity,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(sr.sr_return_amt,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - store_sales sts left outer join store_returns sr - on (sts.ss_ticket_number = sr.sr_ticket_number and sts.ss_item_sk = sr.sr_item_sk) - ,date_dim - where - sr.sr_return_amt > 10000 - and sts.ss_net_profit > 1 - and sts.ss_net_paid > 0 - and sts.ss_quantity > 0 - and ss_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 12 - group by sts.ss_item_sk - ) in_store - ) store - where ( - store.return_rank <= 10 - or - store.currency_rank <= 10 - ) - ) - order by 1,4,5,2 - limit 100; - --- end template query49.tpl query 94 in stream 4 --- start template query11.tpl query 95 in stream 4 -with /* TPC-DS query11.tpl 0.51 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ss_ext_list_price-ss_ext_discount_amt) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ws_ext_list_price-ws_ext_discount_amt) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_birth_country - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 1999 - and t_s_secyear.dyear = 1999+1 - and t_w_firstyear.dyear = 1999 - and t_w_secyear.dyear = 1999+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else 0.0 end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else 0.0 end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_birth_country -limit 100; - --- end template query11.tpl query 95 in stream 4 --- start template query73.tpl query 96 in stream 4 -select /* TPC-DS query73.tpl 0.79 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_buy_potential = '501-1000' or - household_demographics.hd_buy_potential = '0-500') - and household_demographics.hd_vehicle_count > 0 - and case when household_demographics.hd_vehicle_count > 0 then - household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count else null end > 1 - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_county in ('Levy County','Gogebic County','Wadena County','Franklin Parish') - group by ss_ticket_number,ss_customer_sk) dj,customer - where ss_customer_sk = c_customer_sk - and cnt between 1 and 5 - order by cnt desc, c_last_name asc; - --- end template query73.tpl query 96 in stream 4 --- start template query67a.tpl query 97 in stream 4 -with /* TPC-DS query67a.tpl 0.35 */ results as -( select i_category ,i_class ,i_brand ,i_product_name ,d_year ,d_qoy ,d_moy ,s_store_id - ,sum(coalesce(ss_sales_price*ss_quantity,0)) sumsales - from store_sales ,date_dim ,store ,item - where ss_sold_date_sk=d_date_sk - and ss_item_sk=i_item_sk - and ss_store_sk = s_store_sk - and d_month_seq between 1202 and 1202 + 11 - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy,s_store_id) - , - results_rollup as - (select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, s_store_id, sumsales - from results - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy - union all - select i_category, i_class, i_brand, i_product_name, d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year - union all - select i_category, i_class, i_brand, i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name - union all - select i_category, i_class, i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand - union all - select i_category, i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class - union all - select i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category - union all - select null i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results) - - select * -from (select i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rank() over (partition by i_category order by sumsales desc) rk - from results_rollup) dw2 -where rk <= 100 -order by i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rk -limit 100; - --- end template query67a.tpl query 97 in stream 4 --- start template query53.tpl query 98 in stream 4 -select /* TPC-DS query53.tpl 0.88 */ * from -(select i_manufact_id, -sum(ss_sales_price) sum_sales, -avg(sum(ss_sales_price)) over (partition by i_manufact_id) avg_quarterly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and -ss_sold_date_sk = d_date_sk and -ss_store_sk = s_store_sk and -d_month_seq in (1194,1194+1,1194+2,1194+3,1194+4,1194+5,1194+6,1194+7,1194+8,1194+9,1194+10,1194+11) and -((i_category in ('Books','Children','Electronics') and -i_class in ('personal','portable','reference','self-help') and -i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) -or(i_category in ('Women','Music','Men') and -i_class in ('accessories','classical','fragrances','pants') and -i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manufact_id, d_qoy ) tmp1 -where case when avg_quarterly_sales > 0 - then abs (sum_sales - avg_quarterly_sales)/ avg_quarterly_sales - else null end > 0.1 -order by avg_quarterly_sales, - sum_sales, - i_manufact_id -limit 100; - --- end template query53.tpl query 98 in stream 4 --- start template query9.tpl query 99 in stream 4 -select /* TPC-DS query9.tpl 0.49 */ case when (select count(*) - from store_sales - where ss_quantity between 1 and 20) > 12702857 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 1 and 20) - else (select avg(ss_net_profit) - from store_sales - where ss_quantity between 1 and 20) end bucket1 , - case when (select count(*) - from store_sales - where ss_quantity between 21 and 40) > 15506992 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 21 and 40) - else (select avg(ss_net_profit) - from store_sales - where ss_quantity between 21 and 40) end bucket2, - case when (select count(*) - from store_sales - where ss_quantity between 41 and 60) > 30830083 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 41 and 60) - else (select avg(ss_net_profit) - from store_sales - where ss_quantity between 41 and 60) end bucket3, - case when (select count(*) - from store_sales - where ss_quantity between 61 and 80) > 33887993 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 61 and 80) - else (select avg(ss_net_profit) - from store_sales - where ss_quantity between 61 and 80) end bucket4, - case when (select count(*) - from store_sales - where ss_quantity between 81 and 100) > 9825503 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 81 and 100) - else (select avg(ss_net_profit) - from store_sales - where ss_quantity between 81 and 100) end bucket5 -from reason -where r_reason_sk = 1 -; - --- end template query9.tpl query 99 in stream 4 diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/1TB/queries/query_5.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/1TB/queries/query_5.sql deleted file mode 100644 index f27268a0..00000000 --- a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/1TB/queries/query_5.sql +++ /dev/null @@ -1,5027 +0,0 @@ --- start template query73.tpl query 1 in stream 5 -select /* TPC-DS query73.tpl 0.79 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_buy_potential = '1001-5000' or - household_demographics.hd_buy_potential = '0-500') - and household_demographics.hd_vehicle_count > 0 - and case when household_demographics.hd_vehicle_count > 0 then - household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count else null end > 1 - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_county in ('Jackson County','Maverick County','Barrow County','Bronx County') - group by ss_ticket_number,ss_customer_sk) dj,customer - where ss_customer_sk = c_customer_sk - and cnt between 1 and 5 - order by cnt desc, c_last_name asc; - --- end template query73.tpl query 1 in stream 5 --- start template query66.tpl query 2 in stream 5 -select /* TPC-DS query66.tpl 0.39 */ - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - ,sum(jan_sales) as jan_sales - ,sum(feb_sales) as feb_sales - ,sum(mar_sales) as mar_sales - ,sum(apr_sales) as apr_sales - ,sum(may_sales) as may_sales - ,sum(jun_sales) as jun_sales - ,sum(jul_sales) as jul_sales - ,sum(aug_sales) as aug_sales - ,sum(sep_sales) as sep_sales - ,sum(oct_sales) as oct_sales - ,sum(nov_sales) as nov_sales - ,sum(dec_sales) as dec_sales - ,sum(jan_sales/w_warehouse_sq_ft) as jan_sales_per_sq_foot - ,sum(feb_sales/w_warehouse_sq_ft) as feb_sales_per_sq_foot - ,sum(mar_sales/w_warehouse_sq_ft) as mar_sales_per_sq_foot - ,sum(apr_sales/w_warehouse_sq_ft) as apr_sales_per_sq_foot - ,sum(may_sales/w_warehouse_sq_ft) as may_sales_per_sq_foot - ,sum(jun_sales/w_warehouse_sq_ft) as jun_sales_per_sq_foot - ,sum(jul_sales/w_warehouse_sq_ft) as jul_sales_per_sq_foot - ,sum(aug_sales/w_warehouse_sq_ft) as aug_sales_per_sq_foot - ,sum(sep_sales/w_warehouse_sq_ft) as sep_sales_per_sq_foot - ,sum(oct_sales/w_warehouse_sq_ft) as oct_sales_per_sq_foot - ,sum(nov_sales/w_warehouse_sq_ft) as nov_sales_per_sq_foot - ,sum(dec_sales/w_warehouse_sq_ft) as dec_sales_per_sq_foot - ,sum(jan_net) as jan_net - ,sum(feb_net) as feb_net - ,sum(mar_net) as mar_net - ,sum(apr_net) as apr_net - ,sum(may_net) as may_net - ,sum(jun_net) as jun_net - ,sum(jul_net) as jul_net - ,sum(aug_net) as aug_net - ,sum(sep_net) as sep_net - ,sum(oct_net) as oct_net - ,sum(nov_net) as nov_net - ,sum(dec_net) as dec_net - from ( - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'AIRBORNE' || ',' || 'BARIAN' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then ws_ext_list_price* ws_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then ws_ext_list_price* ws_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then ws_ext_list_price* ws_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then ws_ext_list_price* ws_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then ws_ext_list_price* ws_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then ws_ext_list_price* ws_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then ws_ext_list_price* ws_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then ws_ext_list_price* ws_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then ws_ext_list_price* ws_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then ws_ext_list_price* ws_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then ws_ext_list_price* ws_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then ws_ext_list_price* ws_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then ws_net_profit * ws_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then ws_net_profit * ws_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then ws_net_profit * ws_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then ws_net_profit * ws_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then ws_net_profit * ws_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then ws_net_profit * ws_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then ws_net_profit * ws_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then ws_net_profit * ws_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then ws_net_profit * ws_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then ws_net_profit * ws_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then ws_net_profit * ws_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then ws_net_profit * ws_quantity else 0 end) as dec_net - from - web_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - ws_warehouse_sk = w_warehouse_sk - and ws_sold_date_sk = d_date_sk - and ws_sold_time_sk = t_time_sk - and ws_ship_mode_sk = sm_ship_mode_sk - and d_year = 2002 - and t_time between 44854 and 44854+28800 - and sm_carrier in ('AIRBORNE','BARIAN') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - union all - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'AIRBORNE' || ',' || 'BARIAN' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then cs_sales_price* cs_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then cs_sales_price* cs_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then cs_sales_price* cs_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then cs_sales_price* cs_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then cs_sales_price* cs_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then cs_sales_price* cs_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then cs_sales_price* cs_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then cs_sales_price* cs_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then cs_sales_price* cs_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then cs_sales_price* cs_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then cs_sales_price* cs_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then cs_sales_price* cs_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then cs_net_profit * cs_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then cs_net_profit * cs_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then cs_net_profit * cs_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then cs_net_profit * cs_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then cs_net_profit * cs_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then cs_net_profit * cs_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then cs_net_profit * cs_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then cs_net_profit * cs_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then cs_net_profit * cs_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then cs_net_profit * cs_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then cs_net_profit * cs_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then cs_net_profit * cs_quantity else 0 end) as dec_net - from - catalog_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and cs_sold_time_sk = t_time_sk - and cs_ship_mode_sk = sm_ship_mode_sk - and d_year = 2002 - and t_time between 44854 AND 44854+28800 - and sm_carrier in ('AIRBORNE','BARIAN') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - ) x - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - order by w_warehouse_name - limit 100; - --- end template query66.tpl query 2 in stream 5 --- start template query4.tpl query 3 in stream 5 -with /* TPC-DS query4.tpl 0.93 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(((ss_ext_list_price-ss_ext_wholesale_cost-ss_ext_discount_amt)+ss_ext_sales_price)/2) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((cs_ext_list_price-cs_ext_wholesale_cost-cs_ext_discount_amt)+cs_ext_sales_price)/2) ) year_total - ,'c' sale_type - from customer - ,catalog_sales - ,date_dim - where c_customer_sk = cs_bill_customer_sk - and cs_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year -union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((ws_ext_list_price-ws_ext_wholesale_cost-ws_ext_discount_amt)+ws_ext_sales_price)/2) ) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_birth_country - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_c_firstyear - ,year_total t_c_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_c_secyear.customer_id - and t_s_firstyear.customer_id = t_c_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_c_firstyear.sale_type = 'c' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_c_secyear.sale_type = 'c' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 2000 - and t_s_secyear.dyear = 2000+1 - and t_c_firstyear.dyear = 2000 - and t_c_secyear.dyear = 2000+1 - and t_w_firstyear.dyear = 2000 - and t_w_secyear.dyear = 2000+1 - and t_s_firstyear.year_total > 0 - and t_c_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_birth_country -limit 100; - --- end template query4.tpl query 3 in stream 5 --- start template query17.tpl query 4 in stream 5 -select /* TPC-DS query17.tpl 0.41 */ i_item_id - ,i_item_desc - ,s_state - ,count(ss_quantity) as store_sales_quantitycount - ,avg(ss_quantity) as store_sales_quantityave - ,stddev_samp(ss_quantity) as store_sales_quantitystdev - ,stddev_samp(ss_quantity)/avg(ss_quantity) as store_sales_quantitycov - ,count(sr_return_quantity) as store_returns_quantitycount - ,avg(sr_return_quantity) as store_returns_quantityave - ,stddev_samp(sr_return_quantity) as store_returns_quantitystdev - ,stddev_samp(sr_return_quantity)/avg(sr_return_quantity) as store_returns_quantitycov - ,count(cs_quantity) as catalog_sales_quantitycount ,avg(cs_quantity) as catalog_sales_quantityave - ,stddev_samp(cs_quantity) as catalog_sales_quantitystdev - ,stddev_samp(cs_quantity)/avg(cs_quantity) as catalog_sales_quantitycov - from store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where d1.d_quarter_name = '1998Q1' - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_quarter_name in ('1998Q1','1998Q2','1998Q3') - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_quarter_name in ('1998Q1','1998Q2','1998Q3') - group by i_item_id - ,i_item_desc - ,s_state - order by i_item_id - ,i_item_desc - ,s_state -limit 100; - --- end template query17.tpl query 4 in stream 5 --- start template query60.tpl query 5 in stream 5 -with /* TPC-DS query60.tpl 0.29 */ ss as ( - select - i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Jewelry')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 10 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - cs as ( - select - i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Jewelry')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 10 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - ws as ( - select - i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Jewelry')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 10 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id) - select - i_item_id -,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by i_item_id - ,total_sales - limit 100; - --- end template query60.tpl query 5 in stream 5 --- start template query98.tpl query 6 in stream 5 -select /* TPC-DS query98.tpl 0.32 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ss_ext_sales_price) as itemrevenue - ,sum(ss_ext_sales_price)*100/sum(sum(ss_ext_sales_price)) over - (partition by i_class) as revenueratio -from - store_sales - ,item - ,date_dim -where - ss_item_sk = i_item_sk - and i_category in ('Books', 'Women', 'Children') - and ss_sold_date_sk = d_date_sk - and d_date between cast('2000-04-10' as date) - and dateadd(day,30,cast('2000-04-10' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio; - --- end template query98.tpl query 6 in stream 5 --- start template query88.tpl query 7 in stream 5 -select /* TPC-DS query88.tpl 0.66 */ * -from - (select count(*) h8_30_to_9 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2)) - and store.s_store_name = 'ese') s1, - (select count(*) h9_to_9_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2)) - and store.s_store_name = 'ese') s2, - (select count(*) h9_30_to_10 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2)) - and store.s_store_name = 'ese') s3, - (select count(*) h10_to_10_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2)) - and store.s_store_name = 'ese') s4, - (select count(*) h10_30_to_11 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2)) - and store.s_store_name = 'ese') s5, - (select count(*) h11_to_11_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2)) - and store.s_store_name = 'ese') s6, - (select count(*) h11_30_to_12 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2)) - and store.s_store_name = 'ese') s7, - (select count(*) h12_to_12_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 12 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2)) - and store.s_store_name = 'ese') s8 -; - --- end template query88.tpl query 7 in stream 5 --- start template query2.tpl query 8 in stream 5 -with /* TPC-DS query2.tpl 0.84 */ wscs as - (select sold_date_sk - ,sales_price - from (select ws_sold_date_sk sold_date_sk - ,ws_ext_sales_price sales_price - from web_sales - union all - select cs_sold_date_sk sold_date_sk - ,cs_ext_sales_price sales_price - from catalog_sales)), - wswscs as - (select d_week_seq, - sum(case when (d_day_name='Sunday') then sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then sales_price else null end) sat_sales - from wscs - ,date_dim - where d_date_sk = sold_date_sk - group by d_week_seq) - select d_week_seq1 - ,round(sun_sales1/sun_sales2,2) - ,round(mon_sales1/mon_sales2,2) - ,round(tue_sales1/tue_sales2,2) - ,round(wed_sales1/wed_sales2,2) - ,round(thu_sales1/thu_sales2,2) - ,round(fri_sales1/fri_sales2,2) - ,round(sat_sales1/sat_sales2,2) - from - (select wswscs.d_week_seq d_week_seq1 - ,sun_sales sun_sales1 - ,mon_sales mon_sales1 - ,tue_sales tue_sales1 - ,wed_sales wed_sales1 - ,thu_sales thu_sales1 - ,fri_sales fri_sales1 - ,sat_sales sat_sales1 - from wswscs,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 1999) y, - (select wswscs.d_week_seq d_week_seq2 - ,sun_sales sun_sales2 - ,mon_sales mon_sales2 - ,tue_sales tue_sales2 - ,wed_sales wed_sales2 - ,thu_sales thu_sales2 - ,fri_sales fri_sales2 - ,sat_sales sat_sales2 - from wswscs - ,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 1999+1) z - where d_week_seq1=d_week_seq2-53 - order by d_week_seq1; - --- end template query2.tpl query 8 in stream 5 --- start template query19.tpl query 9 in stream 5 -select /* TPC-DS query19.tpl 0.8 */ i_brand_id brand_id, i_brand brand, i_manufact_id, i_manufact, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item,customer,customer_address,store - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=23 - and d_moy=12 - and d_year=2000 - and ss_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and substring(ca_zip,1,5) <> substring(s_zip,1,5) - and ss_store_sk = s_store_sk - group by i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact - order by ext_price desc - ,i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact -limit 100 ; - --- end template query19.tpl query 9 in stream 5 --- start template query65.tpl query 10 in stream 5 -select /* TPC-DS query65.tpl 0.71 */ - s_store_name, - i_item_desc, - sc.revenue, - i_current_price, - i_wholesale_cost, - i_brand - from store, item, - (select ss_store_sk, avg(revenue) as ave - from - (select ss_store_sk, ss_item_sk, - sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1204 and 1204+11 - group by ss_store_sk, ss_item_sk) sa - group by ss_store_sk) sb, - (select ss_store_sk, ss_item_sk, sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1204 and 1204+11 - group by ss_store_sk, ss_item_sk) sc - where sb.ss_store_sk = sc.ss_store_sk and - sc.revenue <= 0.1 * sb.ave and - s_store_sk = sc.ss_store_sk and - i_item_sk = sc.ss_item_sk - order by s_store_name, i_item_desc -limit 100; - --- end template query65.tpl query 10 in stream 5 --- start template query3.tpl query 11 in stream 5 -select /* TPC-DS query3.tpl 0.45 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_net_profit) sum_agg - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manufact_id = 638 - and dt.d_moy=12 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,sum_agg desc - ,brand_id - limit 100; - --- end template query3.tpl query 11 in stream 5 --- start template query79.tpl query 12 in stream 5 -select /* TPC-DS query79.tpl 0.89 */ - c_last_name,c_first_name,substring(s_city,1,30),ss_ticket_number,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,store.s_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (household_demographics.hd_dep_count = 0 or household_demographics.hd_vehicle_count > 2) - and date_dim.d_dow = 1 - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_number_employees between 200 and 295 - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,store.s_city) ms,customer - where ss_customer_sk = c_customer_sk - order by c_last_name,c_first_name,substring(s_city,1,30), profit -limit 100; - --- end template query79.tpl query 12 in stream 5 --- start template query13.tpl query 13 in stream 5 -select /* TPC-DS query13.tpl 0.91 */ avg(ss_quantity) - ,avg(ss_ext_sales_price) - ,avg(ss_ext_wholesale_cost) - ,sum(ss_ext_wholesale_cost) - from store_sales - ,store - ,customer_demographics - ,household_demographics - ,customer_address - ,date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2001 - and((ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'S' - and cd_education_status = '2 yr Degree' - and ss_sales_price between 100.00 and 150.00 - and hd_dep_count = 3 - )or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'U' - and cd_education_status = 'Secondary' - and ss_sales_price between 50.00 and 100.00 - and hd_dep_count = 1 - ) or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'M' - and cd_education_status = 'Advanced Degree' - and ss_sales_price between 150.00 and 200.00 - and hd_dep_count = 1 - )) - and((ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('OK', 'AR', 'TX') - and ss_net_profit between 100 and 200 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('UT', 'OH', 'IA') - and ss_net_profit between 150 and 300 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('IL', 'IN', 'TN') - and ss_net_profit between 50 and 250 - )) -; - --- end template query13.tpl query 13 in stream 5 --- start template query21.tpl query 14 in stream 5 -select /* TPC-DS query21.tpl 0.14 */ * - from(select w_warehouse_name - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('2002-03-19' as date)) - then inv_quantity_on_hand - else 0 end) as inv_before - ,sum(case when (cast(d_date as date) >= cast ('2002-03-19' as date)) - then inv_quantity_on_hand - else 0 end) as inv_after - from inventory - ,warehouse - ,item - ,date_dim - where i_current_price between 0.99 and 1.49 - and i_item_sk = inv_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('2002-03-19' as date)) - and dateadd(day,30,cast ('2002-03-19' as date)) - group by w_warehouse_name, i_item_id) x - where (case when inv_before > 0 - then inv_after / inv_before - else null - end) between 2.0/3.0 and 3.0/2.0 - order by w_warehouse_name - ,i_item_id - limit 100; - --- end template query21.tpl query 14 in stream 5 --- start template query51.tpl query 15 in stream 5 -WITH /* TPC-DS query51.tpl 0.46 */ web_v1 as ( -select - ws_item_sk item_sk, d_date, - sum(sum(ws_sales_price)) - over (partition by ws_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from web_sales - ,date_dim -where ws_sold_date_sk=d_date_sk - and d_month_seq between 1223 and 1223+11 - and ws_item_sk is not NULL -group by ws_item_sk, d_date), -store_v1 as ( -select - ss_item_sk item_sk, d_date, - sum(sum(ss_sales_price)) - over (partition by ss_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from store_sales - ,date_dim -where ss_sold_date_sk=d_date_sk - and d_month_seq between 1223 and 1223+11 - and ss_item_sk is not NULL -group by ss_item_sk, d_date) - select * -from (select item_sk - ,d_date - ,web_sales - ,store_sales - ,max(web_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) web_cumulative - ,max(store_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) store_cumulative - from (select case when web.item_sk is not null then web.item_sk else store.item_sk end item_sk - ,case when web.d_date is not null then web.d_date else store.d_date end d_date - ,web.cume_sales web_sales - ,store.cume_sales store_sales - from web_v1 web full outer join store_v1 store on (web.item_sk = store.item_sk - and web.d_date = store.d_date) - )x )y -where web_cumulative > store_cumulative -order by item_sk - ,d_date -limit 100; - --- end template query51.tpl query 15 in stream 5 --- start template query6.tpl query 16 in stream 5 -select /* TPC-DS query6.tpl 0.58 */ a.ca_state state, count(*) cnt - from customer_address a - ,customer c - ,store_sales s - ,date_dim d - ,item i - where a.ca_address_sk = c.c_current_addr_sk - and c.c_customer_sk = s.ss_customer_sk - and s.ss_sold_date_sk = d.d_date_sk - and s.ss_item_sk = i.i_item_sk - and d.d_month_seq = - (select distinct (d_month_seq) - from date_dim - where d_year = 2000 - and d_moy = 4 ) - and i.i_current_price > 1.2 * - (select avg(j.i_current_price) - from item j - where j.i_category = i.i_category) - group by a.ca_state - having count(*) >= 10 - order by cnt, a.ca_state - limit 100; - --- end template query6.tpl query 16 in stream 5 --- start template query49.tpl query 17 in stream 5 -select /* TPC-DS query49.tpl 0.48 */ channel, item, return_ratio, return_rank, currency_rank from - (select - 'web' as channel - ,web.item - ,web.return_ratio - ,web.return_rank - ,web.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select ws.ws_item_sk as item - ,(cast(sum(coalesce(wr.wr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(wr.wr_return_amt,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - web_sales ws left outer join web_returns wr - on (ws.ws_order_number = wr.wr_order_number and - ws.ws_item_sk = wr.wr_item_sk) - ,date_dim - where - wr.wr_return_amt > 10000 - and ws.ws_net_profit > 1 - and ws.ws_net_paid > 0 - and ws.ws_quantity > 0 - and ws_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 11 - group by ws.ws_item_sk - ) in_web - ) web - where - ( - web.return_rank <= 10 - or - web.currency_rank <= 10 - ) - union - select - 'catalog' as channel - ,catalog.item - ,catalog.return_ratio - ,catalog.return_rank - ,catalog.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select - cs.cs_item_sk as item - ,(cast(sum(coalesce(cr.cr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(cr.cr_return_amount,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - catalog_sales cs left outer join catalog_returns cr - on (cs.cs_order_number = cr.cr_order_number and - cs.cs_item_sk = cr.cr_item_sk) - ,date_dim - where - cr.cr_return_amount > 10000 - and cs.cs_net_profit > 1 - and cs.cs_net_paid > 0 - and cs.cs_quantity > 0 - and cs_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 11 - group by cs.cs_item_sk - ) in_cat - ) catalog - where - ( - catalog.return_rank <= 10 - or - catalog.currency_rank <=10 - ) - union - select - 'store' as channel - ,store.item - ,store.return_ratio - ,store.return_rank - ,store.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select sts.ss_item_sk as item - ,(cast(sum(coalesce(sr.sr_return_quantity,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(sr.sr_return_amt,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - store_sales sts left outer join store_returns sr - on (sts.ss_ticket_number = sr.sr_ticket_number and sts.ss_item_sk = sr.sr_item_sk) - ,date_dim - where - sr.sr_return_amt > 10000 - and sts.ss_net_profit > 1 - and sts.ss_net_paid > 0 - and sts.ss_quantity > 0 - and ss_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 11 - group by sts.ss_item_sk - ) in_store - ) store - where ( - store.return_rank <= 10 - or - store.currency_rank <= 10 - ) - ) - order by 1,4,5,2 - limit 100; - --- end template query49.tpl query 17 in stream 5 --- start template query52.tpl query 18 in stream 5 -select /* TPC-DS query52.tpl 0.59 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_sales_price) ext_price - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=11 - and dt.d_year=2000 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,ext_price desc - ,brand_id -limit 100 ; - --- end template query52.tpl query 18 in stream 5 --- start template query7.tpl query 19 in stream 5 -select /* TPC-DS query7.tpl 0.2 */ i_item_id, - avg(ss_quantity) agg1, - avg(ss_list_price) agg2, - avg(ss_coupon_amt) agg3, - avg(ss_sales_price) agg4 - from store_sales, customer_demographics, date_dim, item, promotion - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_cdemo_sk = cd_demo_sk and - ss_promo_sk = p_promo_sk and - cd_gender = 'F' and - cd_marital_status = 'U' and - cd_education_status = '4 yr Degree' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 2002 - group by i_item_id - order by i_item_id - limit 100; - --- end template query7.tpl query 19 in stream 5 --- start template query56.tpl query 20 in stream 5 -with /* TPC-DS query56.tpl 0.83 */ ss as ( - select i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where i_item_id in (select - i_item_id -from item -where i_color in ('smoke','chocolate','chiffon')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 6 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - cs as ( - select i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('smoke','chocolate','chiffon')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 6 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - ws as ( - select i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('smoke','chocolate','chiffon')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 6 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id) - select i_item_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by total_sales, - i_item_id - limit 100; - --- end template query56.tpl query 20 in stream 5 --- start template query36a.tpl query 21 in stream 5 -with /* TPC-DS query36a.tpl 0.21 */ results as - (select - sum(ss_net_profit) as ss_net_profit, sum(ss_ext_sales_price) as ss_ext_sales_price, - sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin - ,i_category - ,i_class - ,0 as g_category, 0 as g_class - from - store_sales - ,date_dim d1 - ,item - ,store - where - d1.d_year = 2001 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and s_state in ('AL','MI','SD','NY', - 'WA','PA','IN','FL') - group by i_category,i_class) - , - results_rollup as - (select gross_margin ,i_category ,i_class,0 as t_category, 0 as t_class, 0 as lochierarchy from results - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - i_category, NULL AS i_class, 0 as t_category, 1 as t_class, 1 as lochierarchy from results group by i_category - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - NULL AS i_category ,NULL AS i_class, 1 as t_category, 1 as t_class, 2 as lochierarchy from results) - select - gross_margin ,i_category ,i_class, lochierarchy,rank() over ( - partition by lochierarchy, case when t_class = 0 then i_category end - order by gross_margin asc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then i_category end - ,rank_within_parent - limit 100; - --- end template query36a.tpl query 21 in stream 5 --- start template query77a.tpl query 22 in stream 5 -with /* TPC-DS query77a.tpl 0.78 */ ss as - (select s_store_sk, - sum(ss_ext_sales_price) as sales, - sum(ss_net_profit) as profit - from store_sales, - date_dim, - store - where ss_sold_date_sk = d_date_sk - and d_date between cast('1999-08-22' as date) - and dateadd(day,30,cast('1999-08-22' as date)) - and ss_store_sk = s_store_sk - group by s_store_sk) - , - sr as - (select s_store_sk, - sum(sr_return_amt) as returns, - sum(sr_net_loss) as profit_loss - from store_returns, - date_dim, - store - where sr_returned_date_sk = d_date_sk - and d_date between cast('1999-08-22' as date) - and dateadd(day,30,cast('1999-08-22' as date)) - and sr_store_sk = s_store_sk - group by s_store_sk), - cs as - (select cs_call_center_sk, - sum(cs_ext_sales_price) as sales, - sum(cs_net_profit) as profit - from catalog_sales, - date_dim - where cs_sold_date_sk = d_date_sk - and d_date between cast('1999-08-22' as date) - and dateadd(day,30,cast('1999-08-22' as date)) - group by cs_call_center_sk - ), - cr as - (select cr_call_center_sk, - sum(cr_return_amount) as returns, - sum(cr_net_loss) as profit_loss - from catalog_returns, - date_dim - where cr_returned_date_sk = d_date_sk - and d_date between cast('1999-08-22' as date) - and dateadd(day,30,cast('1999-08-22' as date)) - group by cr_call_center_sk), - ws as - ( select wp_web_page_sk, - sum(ws_ext_sales_price) as sales, - sum(ws_net_profit) as profit - from web_sales, - date_dim, - web_page - where ws_sold_date_sk = d_date_sk - and d_date between cast('1999-08-22' as date) - and dateadd(day,30,cast('1999-08-22' as date)) - and ws_web_page_sk = wp_web_page_sk - group by wp_web_page_sk), - wr as - (select wp_web_page_sk, - sum(wr_return_amt) as returns, - sum(wr_net_loss) as profit_loss - from web_returns, - date_dim, - web_page - where wr_returned_date_sk = d_date_sk - and d_date between cast('1999-08-22' as date) - and dateadd(day,30,cast('1999-08-22' as date)) - and wr_web_page_sk = wp_web_page_sk - group by wp_web_page_sk) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , ss.s_store_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ss left join sr - on ss.s_store_sk = sr.s_store_sk - union all - select 'catalog channel' as channel - , cs_call_center_sk as id - , sales - , returns - , (profit - profit_loss) as profit - from cs - , cr - union all - select 'web channel' as channel - , ws.wp_web_page_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ws left join wr - on ws.wp_web_page_sk = wr.wp_web_page_sk - ) x - group by channel, id ) - - select * - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results -) foo -order by channel, id - limit 100; - --- end template query77a.tpl query 22 in stream 5 --- start template query90.tpl query 23 in stream 5 -select /* TPC-DS query90.tpl 0.40 */ cast(amc as decimal(15,4))/cast(pmc as decimal(15,4)) am_pm_ratio - from ( select count(*) amc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 7 and 7+1 - and household_demographics.hd_dep_count = 2 - and web_page.wp_char_count between 5000 and 5200) at, - ( select count(*) pmc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 19 and 19+1 - and household_demographics.hd_dep_count = 2 - and web_page.wp_char_count between 5000 and 5200) pt - order by am_pm_ratio - limit 100; - --- end template query90.tpl query 23 in stream 5 --- start template query76.tpl query 24 in stream 5 -select /* TPC-DS query76.tpl 0.99 */ channel, col_name, d_year, d_qoy, i_category, COUNT(*) sales_cnt, SUM(ext_sales_price) sales_amt FROM ( - SELECT 'store' as channel, 'ss_promo_sk' col_name, d_year, d_qoy, i_category, ss_ext_sales_price ext_sales_price - FROM store_sales, item, date_dim - WHERE ss_promo_sk IS NULL - AND ss_sold_date_sk=d_date_sk - AND ss_item_sk=i_item_sk - UNION ALL - SELECT 'web' as channel, 'ws_ship_customer_sk' col_name, d_year, d_qoy, i_category, ws_ext_sales_price ext_sales_price - FROM web_sales, item, date_dim - WHERE ws_ship_customer_sk IS NULL - AND ws_sold_date_sk=d_date_sk - AND ws_item_sk=i_item_sk - UNION ALL - SELECT 'catalog' as channel, 'cs_bill_customer_sk' col_name, d_year, d_qoy, i_category, cs_ext_sales_price ext_sales_price - FROM catalog_sales, item, date_dim - WHERE cs_bill_customer_sk IS NULL - AND cs_sold_date_sk=d_date_sk - AND cs_item_sk=i_item_sk) foo -GROUP BY channel, col_name, d_year, d_qoy, i_category -ORDER BY channel, col_name, d_year, d_qoy, i_category -limit 100; - --- end template query76.tpl query 24 in stream 5 --- start template query58.tpl query 25 in stream 5 -with /* TPC-DS query58.tpl 0.19 */ ss_items as - (select i_item_id item_id - ,sum(ss_ext_sales_price) ss_item_rev - from store_sales - ,item - ,date_dim - where ss_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '1999-02-02')) - and ss_sold_date_sk = d_date_sk - group by i_item_id), - cs_items as - (select i_item_id item_id - ,sum(cs_ext_sales_price) cs_item_rev - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '1999-02-02')) - and cs_sold_date_sk = d_date_sk - group by i_item_id), - ws_items as - (select i_item_id item_id - ,sum(ws_ext_sales_price) ws_item_rev - from web_sales - ,item - ,date_dim - where ws_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq =(select d_week_seq - from date_dim - where d_date = '1999-02-02')) - and ws_sold_date_sk = d_date_sk - group by i_item_id) - select ss_items.item_id - ,ss_item_rev - ,ss_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ss_dev - ,cs_item_rev - ,cs_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 cs_dev - ,ws_item_rev - ,ws_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ws_dev - ,(ss_item_rev+cs_item_rev+ws_item_rev)/3 average - from ss_items,cs_items,ws_items - where ss_items.item_id=cs_items.item_id - and ss_items.item_id=ws_items.item_id - and ss_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - and ss_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and cs_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and cs_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and ws_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and ws_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - order by item_id - ,ss_item_rev - limit 100; - --- end template query58.tpl query 25 in stream 5 --- start template query71.tpl query 26 in stream 5 -select /* TPC-DS query71.tpl 0.72 */ i_brand_id brand_id, i_brand brand,t_hour,t_minute, - sum(ext_price) ext_price - from item, (select ws_ext_sales_price as ext_price, - ws_sold_date_sk as sold_date_sk, - ws_item_sk as sold_item_sk, - ws_sold_time_sk as time_sk - from web_sales,date_dim - where d_date_sk = ws_sold_date_sk - and d_moy=11 - and d_year=1998 - union all - select cs_ext_sales_price as ext_price, - cs_sold_date_sk as sold_date_sk, - cs_item_sk as sold_item_sk, - cs_sold_time_sk as time_sk - from catalog_sales,date_dim - where d_date_sk = cs_sold_date_sk - and d_moy=11 - and d_year=1998 - union all - select ss_ext_sales_price as ext_price, - ss_sold_date_sk as sold_date_sk, - ss_item_sk as sold_item_sk, - ss_sold_time_sk as time_sk - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - and d_moy=11 - and d_year=1998 - ) tmp,time_dim - where - sold_item_sk = i_item_sk - and i_manager_id=1 - and time_sk = t_time_sk - and (t_meal_time = 'breakfast' or t_meal_time = 'dinner') - group by i_brand, i_brand_id,t_hour,t_minute - order by ext_price desc, i_brand_id - ; - --- end template query71.tpl query 26 in stream 5 --- start template query80a.tpl query 27 in stream 5 -with /* TPC-DS query80a.tpl 0.6 */ ssr as - (select s_store_id as store_id, - sum(ss_ext_sales_price) as sales, - sum(coalesce(sr_return_amt, 0)) as returns, - sum(ss_net_profit - coalesce(sr_net_loss, 0)) as profit - from store_sales left outer join store_returns on - (ss_item_sk = sr_item_sk and ss_ticket_number = sr_ticket_number), - date_dim, - store, - item, - promotion - where ss_sold_date_sk = d_date_sk - and d_date between cast('2001-08-21' as date) - and dateadd(day,30,cast('2001-08-21' as date)) - and ss_store_sk = s_store_sk - and ss_item_sk = i_item_sk - and i_current_price > 50 - and ss_promo_sk = p_promo_sk - and p_channel_tv = 'N' - group by s_store_id) - , - csr as - (select cp_catalog_page_id as catalog_page_id, - sum(cs_ext_sales_price) as sales, - sum(coalesce(cr_return_amount, 0)) as returns, - sum(cs_net_profit - coalesce(cr_net_loss, 0)) as profit - from catalog_sales left outer join catalog_returns on - (cs_item_sk = cr_item_sk and cs_order_number = cr_order_number), - date_dim, - catalog_page, - item, - promotion - where cs_sold_date_sk = d_date_sk - and d_date between cast('2001-08-21' as date) - and dateadd(day,30,cast('2001-08-21' as date)) - and cs_catalog_page_sk = cp_catalog_page_sk - and cs_item_sk = i_item_sk - and i_current_price > 50 - and cs_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(ws_ext_sales_price) as sales, - sum(coalesce(wr_return_amt, 0)) as returns, - sum(ws_net_profit - coalesce(wr_net_loss, 0)) as profit - from web_sales left outer join web_returns on - (ws_item_sk = wr_item_sk and ws_order_number = wr_order_number), - date_dim, - web_site, - item, - promotion - where ws_sold_date_sk = d_date_sk - and d_date between cast('2001-08-21' as date) - and dateadd(day,30,cast('2001-08-21' as date)) - and ws_web_site_sk = web_site_sk - and ws_item_sk = i_item_sk - and i_current_price > 50 - and ws_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by web_site_id) -, -results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || store_id as id - , sales - , returns - , profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || catalog_page_id as id - , sales - , returns - , profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , profit - from wsr - ) x - group by channel, id) - - select channel - , id - , sales - , returns - , profit - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results - ) foo - order by channel, id - limit 100; - --- end template query80a.tpl query 27 in stream 5 --- start template query69.tpl query 28 in stream 5 -select /* TPC-DS query69.tpl 0.28 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_state in ('CA','TX','ID') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 1 and 1+2) and - (not exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 1 and 1+2) and - not exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 1 and 1+2)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - limit 100; - --- end template query69.tpl query 28 in stream 5 --- start template query54.tpl query 29 in stream 5 -with /* TPC-DS query54.tpl 0.81 */ my_customers as ( - select distinct c_customer_sk - , c_current_addr_sk - from - ( select cs_sold_date_sk sold_date_sk, - cs_bill_customer_sk customer_sk, - cs_item_sk item_sk - from catalog_sales - union all - select ws_sold_date_sk sold_date_sk, - ws_bill_customer_sk customer_sk, - ws_item_sk item_sk - from web_sales - ) cs_or_ws_sales, - item, - date_dim, - customer - where sold_date_sk = d_date_sk - and item_sk = i_item_sk - and i_category = 'Women' - and i_class = 'maternity' - and c_customer_sk = cs_or_ws_sales.customer_sk - and d_moy = 1 - and d_year = 2000 - ) - , my_revenue as ( - select c_customer_sk, - sum(ss_ext_sales_price) as revenue - from my_customers, - store_sales, - customer_address, - store, - date_dim - where c_current_addr_sk = ca_address_sk - and ca_county = s_county - and ca_state = s_state - and ss_sold_date_sk = d_date_sk - and c_customer_sk = ss_customer_sk - and d_month_seq between (select distinct d_month_seq+1 - from date_dim where d_year = 2000 and d_moy = 1) - and (select distinct d_month_seq+3 - from date_dim where d_year = 2000 and d_moy = 1) - group by c_customer_sk - ) - , segments as - (select cast((revenue/50) as bigint) as segment - from my_revenue - ) - select segment, count(*) as num_customers, segment*50 as segment_base - from segments - group by segment - order by segment, num_customers - limit 100; - --- end template query54.tpl query 29 in stream 5 --- start template query92.tpl query 30 in stream 5 -select /* TPC-DS query92.tpl 0.44 */ - sum(ws_ext_discount_amt) as "Excess Discount Amount" -from - web_sales - ,item - ,date_dim -where -i_manufact_id = 418 -and i_item_sk = ws_item_sk -and d_date between '1998-03-24' and - dateadd(day,90,cast('1998-03-24' as date)) -and d_date_sk = ws_sold_date_sk -and ws_ext_discount_amt - > ( - SELECT - 1.3 * avg(ws_ext_discount_amt) - FROM - web_sales - ,date_dim - WHERE - ws_item_sk = i_item_sk - and d_date between '1998-03-24' and - dateadd(day,90,cast('1998-03-24' as date)) - and d_date_sk = ws_sold_date_sk - ) -order by sum(ws_ext_discount_amt) -limit 100; - --- end template query92.tpl query 30 in stream 5 --- start template query61.tpl query 31 in stream 5 -select /* TPC-DS query61.tpl 0.97 */ promotions,total,cast(promotions as decimal(15,4))/cast(total as decimal(15,4))*100 -from - (select sum(ss_ext_sales_price) promotions - from store_sales - ,store - ,promotion - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_promo_sk = p_promo_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -6 - and i_category = 'Sports' - and (p_channel_dmail = 'Y' or p_channel_email = 'Y' or p_channel_tv = 'Y') - and s_gmt_offset = -6 - and d_year = 2001 - and d_moy = 11) promotional_sales, - (select sum(ss_ext_sales_price) total - from store_sales - ,store - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -6 - and i_category = 'Sports' - and s_gmt_offset = -6 - and d_year = 2001 - and d_moy = 11) all_sales -order by promotions, total -limit 100; - --- end template query61.tpl query 31 in stream 5 --- start template query53.tpl query 32 in stream 5 -select /* TPC-DS query53.tpl 0.88 */ * from -(select i_manufact_id, -sum(ss_sales_price) sum_sales, -avg(sum(ss_sales_price)) over (partition by i_manufact_id) avg_quarterly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and -ss_sold_date_sk = d_date_sk and -ss_store_sk = s_store_sk and -d_month_seq in (1191,1191+1,1191+2,1191+3,1191+4,1191+5,1191+6,1191+7,1191+8,1191+9,1191+10,1191+11) and -((i_category in ('Books','Children','Electronics') and -i_class in ('personal','portable','reference','self-help') and -i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) -or(i_category in ('Women','Music','Men') and -i_class in ('accessories','classical','fragrances','pants') and -i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manufact_id, d_qoy ) tmp1 -where case when avg_quarterly_sales > 0 - then abs (sum_sales - avg_quarterly_sales)/ avg_quarterly_sales - else null end > 0.1 -order by avg_quarterly_sales, - sum_sales, - i_manufact_id -limit 100; - --- end template query53.tpl query 32 in stream 5 --- start template query87.tpl query 33 in stream 5 -select /* TPC-DS query87.tpl 0.77 */ count(*) -from ((select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1184 and 1184+11) - except - (select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1184 and 1184+11) - except - (select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1184 and 1184+11) -) cool_cust -; - --- end template query87.tpl query 33 in stream 5 --- start template query68.tpl query 34 in stream 5 -select /* TPC-DS query68.tpl 0.95 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,extended_price - ,extended_tax - ,list_price - from (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_ext_sales_price) extended_price - ,sum(ss_ext_list_price) list_price - ,sum(ss_ext_tax) extended_tax - from store_sales - ,date_dim - ,store - ,household_demographics - ,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_dep_count = 9 or - household_demographics.hd_vehicle_count= 4) - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_city in ('Fairview','Lakeside') - group by ss_ticket_number - ,ss_customer_sk - ,ss_addr_sk,ca_city) dn - ,customer - ,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,ss_ticket_number - limit 100; - --- end template query68.tpl query 34 in stream 5 --- start template query85.tpl query 35 in stream 5 -select /* TPC-DS query85.tpl 0.33 */ substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) - from web_sales, web_returns, web_page, customer_demographics cd1, - customer_demographics cd2, customer_address, date_dim, reason - where ws_web_page_sk = wp_web_page_sk - and ws_item_sk = wr_item_sk - and ws_order_number = wr_order_number - and ws_sold_date_sk = d_date_sk and d_year = 2001 - and cd1.cd_demo_sk = wr_refunded_cdemo_sk - and cd2.cd_demo_sk = wr_returning_cdemo_sk - and ca_address_sk = wr_refunded_addr_sk - and r_reason_sk = wr_reason_sk - and - ( - ( - cd1.cd_marital_status = 'S' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Secondary' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 100.00 and 150.00 - ) - or - ( - cd1.cd_marital_status = 'D' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = '2 yr Degree' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 50.00 and 100.00 - ) - or - ( - cd1.cd_marital_status = 'M' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Unknown' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ca_country = 'United States' - and - ca_state in ('MO', 'NE', 'TX') - and ws_net_profit between 100 and 200 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('NH', 'LA', 'MI') - and ws_net_profit between 150 and 300 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('MT', 'MS', 'AL') - and ws_net_profit between 50 and 250 - ) - ) -group by r_reason_desc -order by substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) -limit 100; - --- end template query85.tpl query 35 in stream 5 --- start template query28.tpl query 36 in stream 5 -select /* TPC-DS query28.tpl 0.36 */ * -from (select avg(ss_list_price) B1_LP - ,count(ss_list_price) B1_CNT - ,count(distinct ss_list_price) B1_CNTD - from store_sales - where ss_quantity between 0 and 5 - and (ss_list_price between 156 and 156+10 - or ss_coupon_amt between 3904 and 3904+1000 - or ss_wholesale_cost between 63 and 63+20)) B1, - (select avg(ss_list_price) B2_LP - ,count(ss_list_price) B2_CNT - ,count(distinct ss_list_price) B2_CNTD - from store_sales - where ss_quantity between 6 and 10 - and (ss_list_price between 110 and 110+10 - or ss_coupon_amt between 5902 and 5902+1000 - or ss_wholesale_cost between 26 and 26+20)) B2, - (select avg(ss_list_price) B3_LP - ,count(ss_list_price) B3_CNT - ,count(distinct ss_list_price) B3_CNTD - from store_sales - where ss_quantity between 11 and 15 - and (ss_list_price between 34 and 34+10 - or ss_coupon_amt between 1108 and 1108+1000 - or ss_wholesale_cost between 14 and 14+20)) B3, - (select avg(ss_list_price) B4_LP - ,count(ss_list_price) B4_CNT - ,count(distinct ss_list_price) B4_CNTD - from store_sales - where ss_quantity between 16 and 20 - and (ss_list_price between 69 and 69+10 - or ss_coupon_amt between 10862 and 10862+1000 - or ss_wholesale_cost between 7 and 7+20)) B4, - (select avg(ss_list_price) B5_LP - ,count(ss_list_price) B5_CNT - ,count(distinct ss_list_price) B5_CNTD - from store_sales - where ss_quantity between 21 and 25 - and (ss_list_price between 184 and 184+10 - or ss_coupon_amt between 13887 and 13887+1000 - or ss_wholesale_cost between 18 and 18+20)) B5, - (select avg(ss_list_price) B6_LP - ,count(ss_list_price) B6_CNT - ,count(distinct ss_list_price) B6_CNTD - from store_sales - where ss_quantity between 26 and 30 - and (ss_list_price between 39 and 39+10 - or ss_coupon_amt between 6070 and 6070+1000 - or ss_wholesale_cost between 69 and 69+20)) B6 -limit 100; - --- end template query28.tpl query 36 in stream 5 --- start template query42.tpl query 37 in stream 5 -select /* TPC-DS query42.tpl 0.61 */ dt.d_year - ,item.i_category_id - ,item.i_category - ,sum(ss_ext_sales_price) - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=12 - and dt.d_year=2002 - group by dt.d_year - ,item.i_category_id - ,item.i_category - order by sum(ss_ext_sales_price) desc,dt.d_year - ,item.i_category_id - ,item.i_category -limit 100 ; - --- end template query42.tpl query 37 in stream 5 --- start template query67a.tpl query 38 in stream 5 -with /* TPC-DS query67a.tpl 0.35 */ results as -( select i_category ,i_class ,i_brand ,i_product_name ,d_year ,d_qoy ,d_moy ,s_store_id - ,sum(coalesce(ss_sales_price*ss_quantity,0)) sumsales - from store_sales ,date_dim ,store ,item - where ss_sold_date_sk=d_date_sk - and ss_item_sk=i_item_sk - and ss_store_sk = s_store_sk - and d_month_seq between 1207 and 1207 + 11 - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy,s_store_id) - , - results_rollup as - (select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, s_store_id, sumsales - from results - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy - union all - select i_category, i_class, i_brand, i_product_name, d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year - union all - select i_category, i_class, i_brand, i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name - union all - select i_category, i_class, i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand - union all - select i_category, i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class - union all - select i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category - union all - select null i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results) - - select * -from (select i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rank() over (partition by i_category order by sumsales desc) rk - from results_rollup) dw2 -where rk <= 100 -order by i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rk -limit 100; - --- end template query67a.tpl query 38 in stream 5 --- start template query50.tpl query 39 in stream 5 -select /* TPC-DS query50.tpl 0.60 */ - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 30) and - (sr_returned_date_sk - ss_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 60) and - (sr_returned_date_sk - ss_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 90) and - (sr_returned_date_sk - ss_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - store_sales - ,store_returns - ,store - ,date_dim d1 - ,date_dim d2 -where - d2.d_year = 2001 -and d2.d_moy = 10 -and ss_ticket_number = sr_ticket_number -and ss_item_sk = sr_item_sk -and ss_sold_date_sk = d1.d_date_sk -and sr_returned_date_sk = d2.d_date_sk -and ss_customer_sk = sr_customer_sk -and ss_store_sk = s_store_sk -group by - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -order by s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -limit 100; - --- end template query50.tpl query 39 in stream 5 --- start template query30.tpl query 40 in stream 5 -with /* TPC-DS query30.tpl 0.75 */ customer_total_return as - (select wr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(wr_return_amt) as ctr_total_return - from web_returns - ,date_dim - ,customer_address - where wr_returned_date_sk = d_date_sk - and d_year =2000 - and wr_returning_addr_sk = ca_address_sk - group by wr_returning_customer_sk - ,ca_state) - select c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'SD' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return -limit 100; - --- end template query30.tpl query 40 in stream 5 --- start template query48.tpl query 41 in stream 5 -select /* TPC-DS query48.tpl 0.74 */ sum (ss_quantity) - from store_sales, store, customer_demographics, customer_address, date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2002 - and - ( - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'M' - and - cd_education_status = 'Unknown' - and - ss_sales_price between 100.00 and 150.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'W' - and - cd_education_status = '2 yr Degree' - and - ss_sales_price between 50.00 and 100.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'S' - and - cd_education_status = 'College' - and - ss_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('VT', 'LA', 'MN') - and ss_net_profit between 0 and 2000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('SC', 'MO', 'MS') - and ss_net_profit between 150 and 3000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('NM', 'AR', 'IA') - and ss_net_profit between 50 and 25000 - ) - ) -; - --- end template query48.tpl query 41 in stream 5 --- start template query22a.tpl query 42 in stream 5 -with /* TPC-DS query22a.tpl 0.55 */ results as -(select i_product_name - ,i_brand - ,i_class - ,i_category - ,avg(inv_quantity_on_hand) qoh - from inventory - ,date_dim - ,item --- ,warehouse - where inv_date_sk=d_date_sk - and inv_item_sk=i_item_sk --- and inv_warehouse_sk = w_warehouse_sk - and d_month_seq between 1181 and 1181 + 11 - group by i_product_name,i_brand,i_class,i_category), -results_rollup as -(select i_product_name, i_brand, i_class, i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class,i_category -union all -select i_product_name, i_brand, i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class -union all -select i_product_name, i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand -union all -select i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name -union all -select null i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results) - select i_product_name, i_brand, i_class, i_category,qoh - from results_rollup - order by qoh, i_product_name, i_brand, i_class, i_category -limit 100; - --- end template query22a.tpl query 42 in stream 5 --- start template query11.tpl query 43 in stream 5 -with /* TPC-DS query11.tpl 0.51 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ss_ext_list_price-ss_ext_discount_amt) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ws_ext_list_price-ws_ext_discount_amt) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_email_address - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 1998 - and t_s_secyear.dyear = 1998+1 - and t_w_firstyear.dyear = 1998 - and t_w_secyear.dyear = 1998+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else 0.0 end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else 0.0 end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_email_address -limit 100; - --- end template query11.tpl query 43 in stream 5 --- start template query94.tpl query 44 in stream 5 -select /* TPC-DS query94.tpl 0.17 */ - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '1999-3-01' and - dateadd(day,60,cast('1999-3-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'IN' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and exists (select * - from web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) -and not exists(select * - from web_returns wr1 - where ws1.ws_order_number = wr1.wr_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query94.tpl query 44 in stream 5 --- start template query93.tpl query 45 in stream 5 -select /* TPC-DS query93.tpl 0.52 */ ss_customer_sk - ,sum(act_sales) sumsales - from (select ss_item_sk - ,ss_ticket_number - ,ss_customer_sk - ,case when sr_return_quantity is not null then (ss_quantity-sr_return_quantity)*ss_sales_price - else (ss_quantity*ss_sales_price) end act_sales - from store_sales left outer join store_returns on (sr_item_sk = ss_item_sk - and sr_ticket_number = ss_ticket_number) - ,reason - where sr_reason_sk = r_reason_sk - and r_reason_desc = 'reason 69') t - group by ss_customer_sk - order by sumsales, ss_customer_sk -limit 100; - --- end template query93.tpl query 45 in stream 5 --- start template query18a.tpl query 46 in stream 5 -with /* TPC-DS query18a.tpl 0.90 */ results as - (select i_item_id, - ca_country, - ca_state, - ca_county, - cast(cs_quantity as decimal(12,2)) agg1, - cast(cs_list_price as decimal(12,2)) agg2, - cast(cs_coupon_amt as decimal(12,2)) agg3, - cast(cs_sales_price as decimal(12,2)) agg4, - cast(cs_net_profit as decimal(12,2)) agg5, - cast(c_birth_year as decimal(12,2)) agg6, - cast(cd1.cd_dep_count as decimal(12,2)) agg7 - from catalog_sales, customer_demographics cd1, customer_demographics cd2, customer, customer_address, date_dim, item - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd1.cd_demo_sk and - cs_bill_customer_sk = c_customer_sk and - cd1.cd_gender = 'F' and - cd1.cd_education_status = 'Primary' and - c_current_cdemo_sk = cd2.cd_demo_sk and - c_current_addr_sk = ca_address_sk and - c_birth_month in (3,2,5,7,12,11) and - d_year = 1998 and - ca_state in ('TX','KY','OH','MO','IL','MI','GA') - ) - select i_item_id, ca_country, ca_state, ca_county, agg1, agg2, agg3, agg4, agg5, agg6, agg7 - from ( - select i_item_id, ca_country, ca_state, ca_county, avg(agg1) agg1, - avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state, ca_county - union all - select i_item_id, ca_country, ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state - union all - select i_item_id, ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country - union all - select i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - ) foo - order by ca_country, ca_state, ca_county, i_item_id - limit 100; - --- end template query18a.tpl query 46 in stream 5 --- start template query33.tpl query 47 in stream 5 -with /* TPC-DS query33.tpl 0.22 */ ss as ( - select - i_manufact_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Electronics')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 3 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_manufact_id), - cs as ( - select - i_manufact_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Electronics')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 3 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_manufact_id), - ws as ( - select - i_manufact_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Electronics')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 3 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_manufact_id) - select i_manufact_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_manufact_id - order by total_sales -limit 100; - --- end template query33.tpl query 47 in stream 5 --- start template query63.tpl query 48 in stream 5 -select /* TPC-DS query63.tpl 0.27 */ * -from (select i_manager_id - ,sum(ss_sales_price) sum_sales - ,avg(sum(ss_sales_price)) over (partition by i_manager_id) avg_monthly_sales - from item - ,store_sales - ,date_dim - ,store - where ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and d_month_seq in (1224,1224+1,1224+2,1224+3,1224+4,1224+5,1224+6,1224+7,1224+8,1224+9,1224+10,1224+11) - and (( i_category in ('Books','Children','Electronics') - and i_class in ('personal','portable','reference','self-help') - and i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) - or( i_category in ('Women','Music','Men') - and i_class in ('accessories','classical','fragrances','pants') - and i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manager_id, d_moy) tmp1 -where case when avg_monthly_sales > 0 then abs (sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 -order by i_manager_id - ,avg_monthly_sales - ,sum_sales -limit 100; - --- end template query63.tpl query 48 in stream 5 --- start template query8.tpl query 49 in stream 5 -select /* TPC-DS query8.tpl 0.63 */ s_store_name - ,sum(ss_net_profit) - from store_sales - ,date_dim - ,store, - (select ca_zip - from ( - SELECT substring(ca_zip,1,5) ca_zip - FROM customer_address - WHERE substring(ca_zip,1,5) IN ( - '75361','86011','75014','94535','85914','70464', - '98030','84023','37326','95577','70862', - '76722','36935','78483','85158','78592', - '77921','72627','48724','47364','97087', - '81966','40653','14229','19520','10276', - '18435','61822','10872','41096','29150', - '28242','96024','38134','92444','76903', - '42615','77702','99451','36745','25618', - '34950','46881','12635','92966','58308', - '85704','61927','53088','89033','78019', - '66231','20346','10467','67428','21114', - '32237','30177','57504','73514','48992', - '91304','40937','71117','30739','38314', - '88222','76975','71267','50939','92968', - '40504','41179','93046','57699','41651', - '35552','62686','84363','12047','58666', - '85304','84998','48116','38448','17556', - '63518','27955','97603','28163','75982', - '85087','68127','65948','14909','35404', - '36879','63777','43281','17049','31064', - '25792','36138','75679','90708','39383', - '47406','68829','64488','11291','85186', - '52536','39703','75969','78579','95665', - '98681','20199','85975','77020','53594', - '66504','21718','76510','14232','29489', - '47983','17279','84632','54289','74395', - '80240','98876','56747','24511','41575', - '48583','96027','24579','37182','35014', - '85227','41528','64327','57415','53601', - '24293','38566','43224','62382','43337', - '98194','75864','91763','80631','84379', - '84001','45859','20398','89798','15984', - '55203','79803','72725','84738','74050', - '83680','26075','59207','83932','82878', - '65681','66316','83237','19839','71464', - '38213','61379','73101','18912','60995', - '82532','94772','28978','12615','30110', - '22423','58747','52795','34474','39356', - '99117','55861','27134','10717','11096', - '94626','60726','71327','52687','27613', - '90071','20367','62321','25298','19231', - '23532','74968','19324','66373','37873', - '99488','38279','71869','92216','80237', - '16068','38486','98374','71305','35763', - '57804','80931','36201','73770','42351', - '51799','22941','57246','37612','87842', - '75577','90488','57878','87930','60762', - '70921','39682','74818','94573','45548', - '23303','36193','94118','73776','86628', - '19253','20765','41742','35111','58785', - '74537','49768','35444','47014','94110', - '90881','49036','54917','11716','10413', - '17096','48320','99077','87777','35965', - '64860','68943','41817','16387','86935', - '25679','71322','39679','56336','97471', - '65964','74817','59221','29895','99779', - '14092','12458','25112','69149','40360', - '92130','82716','13965','41349','93943', - '81100','88956','47728','29052','25880', - '61017','48558','55468','14387','75390', - '58729','92091','95985','70039','24087', - '91179','20615','66541','94743','11173', - '77705','22383','70432','24720','75275', - '12087','18980','85442','89895','42574', - '46605','69074','82207','71684','64195', - '67202','78379','95372','76122','23609', - '86636','36000','84592','38624','74534', - '36809','28762','91466','71210','57607', - '44505','24689','28638','61826','72129', - '35415','74268','83972','47836','42225', - '72668','37381','61759','84064','68638', - '56130','67558','35593','48044','38958', - '72658','32129','74179','32937','89368', - '66468','99303','48315','70367','65515', - '25020','47074','38016','49865','48939', - '11040','54606','40912','67589','84124', - '65510','21811','18334','46078','17764', - '40648','89529','72862','25506','16282', - '71020','11362','89596','46961','37058', - '61029','84353','31273','32489') - intersect - select ca_zip - from (SELECT substring(ca_zip,1,5) ca_zip,count(*) cnt - FROM customer_address, customer - WHERE ca_address_sk = c_current_addr_sk and - c_preferred_cust_flag='Y' - group by ca_zip - having count(*) > 10)A1)A2) V1 - where ss_store_sk = s_store_sk - and ss_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 1998 - and (substring(s_zip,1,2) = substring(V1.ca_zip,1,2)) - group by s_store_name - order by s_store_name - limit 100; - --- end template query8.tpl query 49 in stream 5 --- start template query97.tpl query 50 in stream 5 -with /* TPC-DS query97.tpl 0.38 */ ssci as ( -select ss_customer_sk customer_sk - ,ss_item_sk item_sk -from store_sales,date_dim -where ss_sold_date_sk = d_date_sk - and d_month_seq between 1198 and 1198 + 11 -group by ss_customer_sk - ,ss_item_sk), -csci as( - select cs_bill_customer_sk customer_sk - ,cs_item_sk item_sk -from catalog_sales,date_dim -where cs_sold_date_sk = d_date_sk - and d_month_seq between 1198 and 1198 + 11 -group by cs_bill_customer_sk - ,cs_item_sk) - select sum(case when ssci.customer_sk is not null and csci.customer_sk is null then 1 else 0 end) store_only - ,sum(case when ssci.customer_sk is null and csci.customer_sk is not null then 1 else 0 end) catalog_only - ,sum(case when ssci.customer_sk is not null and csci.customer_sk is not null then 1 else 0 end) store_and_catalog -from ssci full outer join csci on (ssci.customer_sk=csci.customer_sk - and ssci.item_sk = csci.item_sk) -limit 100; - --- end template query97.tpl query 50 in stream 5 --- start template query45.tpl query 51 in stream 5 -select /* TPC-DS query45.tpl 0.18 */ ca_zip, ca_state, sum(ws_sales_price) - from web_sales, customer, customer_address, date_dim, item - where ws_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ws_item_sk = i_item_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', '85392', '85460', '80348', '81792') - or - i_item_id in (select i_item_id - from item - where i_item_sk in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29) - ) - ) - and ws_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 2000 - group by ca_zip, ca_state - order by ca_zip, ca_state - limit 100; - --- end template query45.tpl query 51 in stream 5 --- start template query62.tpl query 52 in stream 5 -select /* TPC-DS query62.tpl 0.24 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 30) and - (ws_ship_date_sk - ws_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 60) and - (ws_ship_date_sk - ws_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 90) and - (ws_ship_date_sk - ws_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - web_sales - ,warehouse - ,ship_mode - ,web_site - ,date_dim -where - d_month_seq between 1213 and 1213 + 11 -and ws_ship_date_sk = d_date_sk -and ws_warehouse_sk = w_warehouse_sk -and ws_ship_mode_sk = sm_ship_mode_sk -and ws_web_site_sk = web_site_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -limit 100; - --- end template query62.tpl query 52 in stream 5 --- start template query81.tpl query 53 in stream 5 -with /* TPC-DS query81.tpl 0.37 */ customer_total_return as - (select cr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(cr_return_amt_inc_tax) as ctr_total_return - from catalog_returns - ,date_dim - ,customer_address - where cr_returned_date_sk = d_date_sk - and d_year =2000 - and cr_returning_addr_sk = ca_address_sk - group by cr_returning_customer_sk - ,ca_state ) - select c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'AL' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - limit 100; - --- end template query81.tpl query 53 in stream 5 --- start template query35a.tpl query 54 in stream 5 -select /* TPC-DS query35a.tpl 0.47 */ - ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - count(*) cnt1, - stddev_samp(cd_dep_count), - avg(cd_dep_count), - sum(cd_dep_count), - cd_dep_employed_count, - count(*) cnt2, - stddev_samp(cd_dep_employed_count), - avg(cd_dep_employed_count), - sum(cd_dep_employed_count), - cd_dep_college_count, - count(*) cnt3, - stddev_samp(cd_dep_college_count), - avg(cd_dep_college_count), - sum(cd_dep_college_count) - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2001 and - d_qoy < 4) and - exists (select * from - (select ws_bill_customer_sk customsk - from web_sales,date_dim - where - ws_sold_date_sk = d_date_sk and - d_year = 2001 and - d_qoy < 4 - union all - select cs_ship_customer_sk customsk - from catalog_sales,date_dim - where - cs_sold_date_sk = d_date_sk and - d_year = 2001 and - d_qoy < 4)x - where x.customsk = c.c_customer_sk) - group by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - limit 100; - --- end template query35a.tpl query 54 in stream 5 --- start template query78.tpl query 55 in stream 5 -with /* TPC-DS query78.tpl 0.10 */ ws as - (select d_year AS ws_sold_year, ws_item_sk, - ws_bill_customer_sk ws_customer_sk, - sum(ws_quantity) ws_qty, - sum(ws_wholesale_cost) ws_wc, - sum(ws_sales_price) ws_sp - from web_sales - left join web_returns on wr_order_number=ws_order_number and ws_item_sk=wr_item_sk - join date_dim on ws_sold_date_sk = d_date_sk - where wr_order_number is null - group by d_year, ws_item_sk, ws_bill_customer_sk - ), -cs as - (select d_year AS cs_sold_year, cs_item_sk, - cs_bill_customer_sk cs_customer_sk, - sum(cs_quantity) cs_qty, - sum(cs_wholesale_cost) cs_wc, - sum(cs_sales_price) cs_sp - from catalog_sales - left join catalog_returns on cr_order_number=cs_order_number and cs_item_sk=cr_item_sk - join date_dim on cs_sold_date_sk = d_date_sk - where cr_order_number is null - group by d_year, cs_item_sk, cs_bill_customer_sk - ), -ss as - (select d_year AS ss_sold_year, ss_item_sk, - ss_customer_sk, - sum(ss_quantity) ss_qty, - sum(ss_wholesale_cost) ss_wc, - sum(ss_sales_price) ss_sp - from store_sales - left join store_returns on sr_ticket_number=ss_ticket_number and ss_item_sk=sr_item_sk - join date_dim on ss_sold_date_sk = d_date_sk - where sr_ticket_number is null - group by d_year, ss_item_sk, ss_customer_sk - ) - select -ss_item_sk, -round(ss_qty/(coalesce(ws_qty,0)+coalesce(cs_qty,0)),2) ratio, -ss_qty store_qty, ss_wc store_wholesale_cost, ss_sp store_sales_price, -coalesce(ws_qty,0)+coalesce(cs_qty,0) other_chan_qty, -coalesce(ws_wc,0)+coalesce(cs_wc,0) other_chan_wholesale_cost, -coalesce(ws_sp,0)+coalesce(cs_sp,0) other_chan_sales_price -from ss -left join ws on (ws_sold_year=ss_sold_year and ws_item_sk=ss_item_sk and ws_customer_sk=ss_customer_sk) -left join cs on (cs_sold_year=ss_sold_year and cs_item_sk=ss_item_sk and cs_customer_sk=ss_customer_sk) -where (coalesce(ws_qty,0)>0 or coalesce(cs_qty, 0)>0) and ss_sold_year=1999 -order by - ss_item_sk, - ss_qty desc, ss_wc desc, ss_sp desc, - other_chan_qty, - other_chan_wholesale_cost, - other_chan_sales_price, - ratio -limit 100; - --- end template query78.tpl query 55 in stream 5 --- start template query57.tpl query 56 in stream 5 -with /* TPC-DS query57.tpl 0.70 */ v1 as( - select i_category, i_brand, - cc_name, - d_year, d_moy, - sum(cs_sales_price) sum_sales, - avg(sum(cs_sales_price)) over - (partition by i_category, i_brand, - cc_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - cc_name - order by d_year, d_moy) rn - from item, catalog_sales, date_dim, call_center - where cs_item_sk = i_item_sk and - cs_sold_date_sk = d_date_sk and - cc_call_center_sk= cs_call_center_sk and - ( - d_year = 2001 or - ( d_year = 2001-1 and d_moy =12) or - ( d_year = 2001+1 and d_moy =1) - ) - group by i_category, i_brand, - cc_name , d_year, d_moy), - v2 as( - select v1.i_brand - ,v1.d_year - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1. cc_name = v1_lag. cc_name and - v1. cc_name = v1_lead. cc_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 2001 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, psum - limit 100; - --- end template query57.tpl query 56 in stream 5 --- start template query46.tpl query 57 in stream 5 -select /* TPC-DS query46.tpl 0.23 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and (household_demographics.hd_dep_count = 7 or - household_demographics.hd_vehicle_count= -1) - and date_dim.d_dow in (6,0) - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_city in ('New Hope','Midway','Fairview','Highland Park','Riverview') - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,ca_city) dn,customer,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - limit 100; - --- end template query46.tpl query 57 in stream 5 --- start template query32.tpl query 58 in stream 5 -select /* TPC-DS query32.tpl 0.7 */ sum(cs_ext_discount_amt) as "excess discount amount" -from - catalog_sales - ,item - ,date_dim -where -i_manufact_id = 116 -and i_item_sk = cs_item_sk -and d_date between '2001-03-24' and - dateadd(day,90,cast('2001-03-24' as date)) -and d_date_sk = cs_sold_date_sk -and cs_ext_discount_amt - > ( - select - 1.3 * avg(cs_ext_discount_amt) - from - catalog_sales - ,date_dim - where - cs_item_sk = i_item_sk - and d_date between '2001-03-24' and - dateadd(day,90,cast('2001-03-24' as date)) - and d_date_sk = cs_sold_date_sk - ) -limit 100; - --- end template query32.tpl query 58 in stream 5 --- start template query24.tpl query 59 in stream 5 -with /* TPC-DS query24.tpl 0.92 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_net_profit) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip -and s_market_id=7 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'blush' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; -with /* TPC-DS query24.tpl 0.92 part2 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_net_profit) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip - and s_market_id = 7 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'drab' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; - --- end template query24.tpl query 59 in stream 5 --- start template query38.tpl query 60 in stream 5 -select /* TPC-DS query38.tpl 0.54 */ count(*) from ( - select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1187 and 1187 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1187 and 1187 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1187 and 1187 + 11 -) hot_cust -limit 100; - --- end template query38.tpl query 60 in stream 5 --- start template query55.tpl query 61 in stream 5 -select /* TPC-DS query55.tpl 0.82 */ i_brand_id brand_id, i_brand brand, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=47 - and d_moy=12 - and d_year=2001 - group by i_brand, i_brand_id - order by ext_price desc, i_brand_id -limit 100 ; - --- end template query55.tpl query 61 in stream 5 --- start template query74.tpl query 62 in stream 5 -with /* TPC-DS query74.tpl 0.76 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,max(ss_net_paid) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1999,1999+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,max(ws_net_paid) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - and d_year in (1999,1999+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - ) - select - t_s_secyear.customer_id, t_s_secyear.customer_first_name, t_s_secyear.customer_last_name - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.year = 1999 - and t_s_secyear.year = 1999+1 - and t_w_firstyear.year = 1999 - and t_w_secyear.year = 1999+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - order by 3,1,2 -limit 100; - --- end template query74.tpl query 62 in stream 5 --- start template query84.tpl query 63 in stream 5 -select /* TPC-DS query84.tpl 0.80 */ c_customer_id as customer_id - , coalesce(c_last_name,'') || ', ' || coalesce(c_first_name,'') as customername - from customer - ,customer_address - ,customer_demographics - ,household_demographics - ,income_band - ,store_returns - where ca_city = 'Mount Olive' - and c_current_addr_sk = ca_address_sk - and ib_lower_bound >= 25235 - and ib_upper_bound <= 25235 + 50000 - and ib_income_band_sk = hd_income_band_sk - and cd_demo_sk = c_current_cdemo_sk - and hd_demo_sk = c_current_hdemo_sk - and sr_cdemo_sk = cd_demo_sk - order by c_customer_id - limit 100; - --- end template query84.tpl query 63 in stream 5 --- start template query89.tpl query 64 in stream 5 -select /* TPC-DS query89.tpl 0.56 */ * -from( -select i_category, i_class, i_brand, - s_store_name, s_company_name, - d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, s_store_name, s_company_name) - avg_monthly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - d_year in (2000) and - ((i_category in ('Sports','Jewelry','Music') and - i_class in ('camping','bracelets','classical') - ) - or (i_category in ('Men','Women','Children') and - i_class in ('shirts','swimwear','toddlers') - )) -group by i_category, i_class, i_brand, - s_store_name, s_company_name, d_moy) tmp1 -where case when (avg_monthly_sales <> 0) then (abs(sum_sales - avg_monthly_sales) / avg_monthly_sales) else null end > 0.1 -order by sum_sales - avg_monthly_sales, s_store_name -limit 100; - --- end template query89.tpl query 64 in stream 5 --- start template query83.tpl query 65 in stream 5 -with /* TPC-DS query83.tpl 0.96 */ sr_items as - (select i_item_id item_id, - sum(sr_return_quantity) sr_item_qty - from store_returns, - item, - date_dim - where sr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2000-06-27','2000-09-17','2000-11-08'))) - and sr_returned_date_sk = d_date_sk - group by i_item_id), - cr_items as - (select i_item_id item_id, - sum(cr_return_quantity) cr_item_qty - from catalog_returns, - item, - date_dim - where cr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2000-06-27','2000-09-17','2000-11-08'))) - and cr_returned_date_sk = d_date_sk - group by i_item_id), - wr_items as - (select i_item_id item_id, - sum(wr_return_quantity) wr_item_qty - from web_returns, - item, - date_dim - where wr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2000-06-27','2000-09-17','2000-11-08'))) - and wr_returned_date_sk = d_date_sk - group by i_item_id) - select sr_items.item_id - ,sr_item_qty - ,sr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 sr_dev - ,cr_item_qty - ,cr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 cr_dev - ,wr_item_qty - ,wr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 wr_dev - ,(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 average - from sr_items - ,cr_items - ,wr_items - where sr_items.item_id=cr_items.item_id - and sr_items.item_id=wr_items.item_id - order by sr_items.item_id - ,sr_item_qty - limit 100; - --- end template query83.tpl query 65 in stream 5 --- start template query31.tpl query 66 in stream 5 -with /* TPC-DS query31.tpl 0.50 */ ss as - (select ca_county,d_qoy, d_year,sum(ss_ext_sales_price) as store_sales - from store_sales,date_dim,customer_address - where ss_sold_date_sk = d_date_sk - and ss_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year), - ws as - (select ca_county,d_qoy, d_year,sum(ws_ext_sales_price) as web_sales - from web_sales,date_dim,customer_address - where ws_sold_date_sk = d_date_sk - and ws_bill_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year) - select - ss1.ca_county - ,ss1.d_year - ,ws2.web_sales/ws1.web_sales web_q1_q2_increase - ,ss2.store_sales/ss1.store_sales store_q1_q2_increase - ,ws3.web_sales/ws2.web_sales web_q2_q3_increase - ,ss3.store_sales/ss2.store_sales store_q2_q3_increase - from - ss ss1 - ,ss ss2 - ,ss ss3 - ,ws ws1 - ,ws ws2 - ,ws ws3 - where - ss1.d_qoy = 1 - and ss1.d_year = 2001 - and ss1.ca_county = ss2.ca_county - and ss2.d_qoy = 2 - and ss2.d_year = 2001 - and ss2.ca_county = ss3.ca_county - and ss3.d_qoy = 3 - and ss3.d_year = 2001 - and ss1.ca_county = ws1.ca_county - and ws1.d_qoy = 1 - and ws1.d_year = 2001 - and ws1.ca_county = ws2.ca_county - and ws2.d_qoy = 2 - and ws2.d_year = 2001 - and ws1.ca_county = ws3.ca_county - and ws3.d_qoy = 3 - and ws3.d_year =2001 - and case when ws1.web_sales > 0 then ws2.web_sales/ws1.web_sales else null end - > case when ss1.store_sales > 0 then ss2.store_sales/ss1.store_sales else null end - and case when ws2.web_sales > 0 then ws3.web_sales/ws2.web_sales else null end - > case when ss2.store_sales > 0 then ss3.store_sales/ss2.store_sales else null end - order by ss1.ca_county; - --- end template query31.tpl query 66 in stream 5 --- start template query26.tpl query 67 in stream 5 -select /* TPC-DS query26.tpl 0.85 */ i_item_id, - avg(cs_quantity) agg1, - avg(cs_list_price) agg2, - avg(cs_coupon_amt) agg3, - avg(cs_sales_price) agg4 - from catalog_sales, customer_demographics, date_dim, item, promotion - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd_demo_sk and - cs_promo_sk = p_promo_sk and - cd_gender = 'M' and - cd_marital_status = 'U' and - cd_education_status = '2 yr Degree' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 2002 - group by i_item_id - order by i_item_id - limit 100; - --- end template query26.tpl query 67 in stream 5 --- start template query40.tpl query 68 in stream 5 -select /* TPC-DS query40.tpl 0.86 */ - w_state - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('1998-06-09' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_before - ,sum(case when (cast(d_date as date) >= cast ('1998-06-09' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_after - from - catalog_sales left outer join catalog_returns on - (cs_order_number = cr_order_number - and cs_item_sk = cr_item_sk) - ,warehouse - ,item - ,date_dim - where - i_current_price between 0.99 and 1.49 - and i_item_sk = cs_item_sk - and cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('1998-06-09' as date)) - and dateadd(day,30,cast ('1998-06-09' as date)) - group by - w_state,i_item_id - order by w_state,i_item_id -limit 100; - --- end template query40.tpl query 68 in stream 5 --- start template query14a.tpl query 69 in stream 5 -with /* TPC-DS query14a.tpl 0.69 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1999 AND 1999 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1999 AND 1999 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1999 AND 1999 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as - (select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2) x) -, - results AS -(select channel, i_brand_id, i_class_id, i_category_id, sum(sales) sum_sales, sum(number_sales) number_sales - from ( - select 'store' channel, i_brand_id,i_class_id - ,i_category_id,sum(ss_quantity*ss_list_price) sales - , count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1999+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales) - union all - select 'catalog' channel, i_brand_id,i_class_id,i_category_id, sum(cs_quantity*cs_list_price) sales, count(*) number_sales - from catalog_sales - ,item - ,date_dim - where cs_item_sk in (select ss_item_sk from cross_items) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1999+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(cs_quantity*cs_list_price) > (select average_sales from avg_sales) - union all - select 'web' channel, i_brand_id,i_class_id,i_category_id, sum(ws_quantity*ws_list_price) sales , count(*) number_sales - from web_sales - ,item - ,date_dim - where ws_item_sk in (select ss_item_sk from cross_items) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1999+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ws_quantity*ws_list_price) > (select average_sales from avg_sales) - ) y - group by channel, i_brand_id,i_class_id,i_category_id) - - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales -from ( - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales from results - union - select channel, i_brand_id, i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id, i_class_id - union - select channel, i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id - union - select channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel - union - select null as channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results) z -order by channel, i_brand_id, i_class_id, i_category_id - limit 100; -with /* TPC-DS query14a.tpl 0.69 part2 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1999 AND 1999 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1999 AND 1999 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1999 AND 1999 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as -(select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1999 and 1999 + 2) x) - select this_year.channel ty_channel - ,this_year.i_brand_id ty_brand - ,this_year.i_class_id ty_class - ,this_year.i_category_id ty_category - ,this_year.sales ty_sales - ,this_year.number_sales ty_number_sales - ,last_year.channel ly_channel - ,last_year.i_brand_id ly_brand - ,last_year.i_class_id ly_class - ,last_year.i_category_id ly_category - ,last_year.sales ly_sales - ,last_year.number_sales ly_number_sales -from - (select 'store' channel, i_brand_id,i_class_id,i_category_id - ,sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1999 + 1 - and d_moy = 12 - and d_dom = 8) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) this_year, - (select 'store' channel, i_brand_id,i_class_id - ,i_category_id, sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1999 - and d_moy = 12 - and d_dom = 8) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) last_year - where this_year.i_brand_id= last_year.i_brand_id - and this_year.i_class_id = last_year.i_class_id - and this_year.i_category_id = last_year.i_category_id - order by this_year.channel, this_year.i_brand_id, this_year.i_class_id, this_year.i_category_id - limit 100; - --- end template query14a.tpl query 69 in stream 5 --- start template query23.tpl query 70 in stream 5 -with /* TPC-DS query23.tpl 0.68 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (1998,1998+1,1998+2,1998+3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1998,1998+1,1998+2,1998+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * -from - max_store_sales)) - select sum(sales) - from (select cs_quantity*cs_list_price sales - from catalog_sales - ,date_dim - where d_year = 1998 - and d_moy = 1 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - union all - select ws_quantity*ws_list_price sales - from web_sales - ,date_dim - where d_year = 1998 - and d_moy = 1 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer)) - limit 100; -with /* TPC-DS query23.tpl 0.68 part2 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (1998,1998 + 1,1998 + 2,1998 + 3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1998,1998+1,1998+2,1998+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * - from max_store_sales)) - select c_last_name,c_first_name,sales - from (select c_last_name,c_first_name,sum(cs_quantity*cs_list_price) sales - from catalog_sales - ,customer - ,date_dim - where d_year = 1998 - and d_moy = 1 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and cs_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name - union all - select c_last_name,c_first_name,sum(ws_quantity*ws_list_price) sales - from web_sales - ,customer - ,date_dim - where d_year = 1998 - and d_moy = 1 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and ws_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name) - order by c_last_name,c_first_name,sales - limit 100; - --- end template query23.tpl query 70 in stream 5 --- start template query96.tpl query 71 in stream 5 -select /* TPC-DS query96.tpl 0.1 */ count(*) -from store_sales - ,household_demographics - ,time_dim, store -where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 16 - and time_dim.t_minute >= 30 - and household_demographics.hd_dep_count = 3 - and store.s_store_name = 'ese' -order by count(*) -limit 100; - --- end template query96.tpl query 71 in stream 5 --- start template query1.tpl query 72 in stream 5 -with /* TPC-DS query1.tpl 0.12 */ customer_total_return as -(select sr_customer_sk as ctr_customer_sk -,sr_store_sk as ctr_store_sk -,sum(SR_REVERSED_CHARGE) as ctr_total_return -from store_returns -,date_dim -where sr_returned_date_sk = d_date_sk -and d_year =1998 -group by sr_customer_sk -,sr_store_sk) - select c_customer_id -from customer_total_return ctr1 -,store -,customer -where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 -from customer_total_return ctr2 -where ctr1.ctr_store_sk = ctr2.ctr_store_sk) -and s_store_sk = ctr1.ctr_store_sk -and s_state = 'CO' -and ctr1.ctr_customer_sk = c_customer_sk -order by c_customer_id -limit 100; - --- end template query1.tpl query 72 in stream 5 --- start template query95.tpl query 73 in stream 5 -with /* TPC-DS query95.tpl 0.43 */ ws_wh as -(select ws1.ws_order_number,ws1.ws_warehouse_sk wh1,ws2.ws_warehouse_sk wh2 - from web_sales ws1,web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) - select - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2000-5-01' and - dateadd(day,60,cast('2000-5-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'IA' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and ws1.ws_order_number in (select ws_order_number - from ws_wh) -and ws1.ws_order_number in (select wr_order_number - from web_returns,ws_wh - where wr_order_number = ws_wh.ws_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query95.tpl query 73 in stream 5 --- start template query27a.tpl query 74 in stream 5 -with /* TPC-DS query27a.tpl 0.16 */ results as - (select i_item_id, - s_state, 0 as g_state, - ss_quantity agg1, - ss_list_price agg2, - ss_coupon_amt agg3, - ss_sales_price agg4 - from store_sales, customer_demographics, date_dim, store, item - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_store_sk = s_store_sk and - ss_cdemo_sk = cd_demo_sk and - cd_gender = 'M' and - cd_marital_status = 'D' and - cd_education_status = '4 yr Degree' and - d_year = 2002 and - s_state in ('MN','AL', 'PA', 'AL', 'LA', 'IN') - ) - - select i_item_id, - s_state, g_state, agg1, agg2, agg3, agg4 - from ( - select i_item_id, s_state, 0 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4 from results - group by i_item_id, s_state - union all - select i_item_id, NULL AS s_state, 1 AS g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as s_state, 1 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - ) foo - order by i_item_id, s_state - limit 100; - --- end template query27a.tpl query 74 in stream 5 --- start template query44.tpl query 75 in stream 5 -select /* TPC-DS query44.tpl 0.4 */ asceding.rnk, i1.i_product_name best_performing, i2.i_product_name worst_performing -from(select * - from (select item_sk,rank() over (order by rank_col asc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 438 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 438 - and ss_cdemo_sk is null - group by ss_store_sk))V1)V11 - where rnk < 11) asceding, - (select * - from (select item_sk,rank() over (order by rank_col desc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 438 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 438 - and ss_cdemo_sk is null - group by ss_store_sk))V2)V21 - where rnk < 11) descending, -item i1, -item i2 -where asceding.rnk = descending.rnk - and i1.i_item_sk=asceding.item_sk - and i2.i_item_sk=descending.item_sk -order by asceding.rnk -limit 100; - --- end template query44.tpl query 75 in stream 5 --- start template query16.tpl query 76 in stream 5 -select /* TPC-DS query16.tpl 0.25 */ - count(distinct cs_order_number) as "order count" - ,sum(cs_ext_ship_cost) as "total shipping cost" - ,sum(cs_net_profit) as "total net profit" -from - catalog_sales cs1 - ,date_dim - ,customer_address - ,call_center -where - d_date between '2000-3-01' and - dateadd(day, 60, cast('2000-3-01' as date)) -and cs1.cs_ship_date_sk = d_date_sk -and cs1.cs_ship_addr_sk = ca_address_sk -and ca_state = 'GA' -and cs1.cs_call_center_sk = cc_call_center_sk -and cc_county in ('Levy County','Fairfield County','Huron County','Barrow County', - 'Williamson County' -) -and exists (select * - from catalog_sales cs2 - where cs1.cs_order_number = cs2.cs_order_number - and cs1.cs_warehouse_sk <> cs2.cs_warehouse_sk) -and not exists(select * - from catalog_returns cr1 - where cs1.cs_order_number = cr1.cr_order_number) -order by count(distinct cs_order_number) -limit 100; - --- end template query16.tpl query 76 in stream 5 --- start template query64.tpl query 77 in stream 5 -with /* TPC-DS query64.tpl 0.20 */ cs_ui as - (select cs_item_sk - ,sum(cs_ext_list_price) as sale,sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit) as refund - from catalog_sales - ,catalog_returns - where cs_item_sk = cr_item_sk - and cs_order_number = cr_order_number - group by cs_item_sk - having sum(cs_ext_list_price)>2*sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit)), -cross_sales as - (select i_product_name product_name - ,i_item_sk item_sk - ,s_store_name store_name - ,s_zip store_zip - ,ad1.ca_street_number b_street_number - ,ad1.ca_street_name b_street_name - ,ad1.ca_city b_city - ,ad1.ca_zip b_zip - ,ad2.ca_street_number c_street_number - ,ad2.ca_street_name c_street_name - ,ad2.ca_city c_city - ,ad2.ca_zip c_zip - ,d1.d_year as syear - ,d2.d_year as fsyear - ,d3.d_year s2year - ,count(*) cnt - ,sum(ss_wholesale_cost) s1 - ,sum(ss_list_price) s2 - ,sum(ss_coupon_amt) s3 - FROM store_sales - ,store_returns - ,cs_ui - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,customer - ,customer_demographics cd1 - ,customer_demographics cd2 - ,promotion - ,household_demographics hd1 - ,household_demographics hd2 - ,customer_address ad1 - ,customer_address ad2 - ,income_band ib1 - ,income_band ib2 - ,item - WHERE ss_store_sk = s_store_sk AND - ss_sold_date_sk = d1.d_date_sk AND - ss_customer_sk = c_customer_sk AND - ss_cdemo_sk= cd1.cd_demo_sk AND - ss_hdemo_sk = hd1.hd_demo_sk AND - ss_addr_sk = ad1.ca_address_sk and - ss_item_sk = i_item_sk and - ss_item_sk = sr_item_sk and - ss_ticket_number = sr_ticket_number and - ss_item_sk = cs_ui.cs_item_sk and - c_current_cdemo_sk = cd2.cd_demo_sk AND - c_current_hdemo_sk = hd2.hd_demo_sk AND - c_current_addr_sk = ad2.ca_address_sk and - c_first_sales_date_sk = d2.d_date_sk and - c_first_shipto_date_sk = d3.d_date_sk and - ss_promo_sk = p_promo_sk and - hd1.hd_income_band_sk = ib1.ib_income_band_sk and - hd2.hd_income_band_sk = ib2.ib_income_band_sk and - cd1.cd_marital_status <> cd2.cd_marital_status and - i_color in ('snow','sienna','slate','royal','floral','light') and - i_current_price between 29 and 29 + 10 and - i_current_price between 29 + 1 and 29 + 15 -group by i_product_name - ,i_item_sk - ,s_store_name - ,s_zip - ,ad1.ca_street_number - ,ad1.ca_street_name - ,ad1.ca_city - ,ad1.ca_zip - ,ad2.ca_street_number - ,ad2.ca_street_name - ,ad2.ca_city - ,ad2.ca_zip - ,d1.d_year - ,d2.d_year - ,d3.d_year -) -select cs1.product_name - ,cs1.store_name - ,cs1.store_zip - ,cs1.b_street_number - ,cs1.b_street_name - ,cs1.b_city - ,cs1.b_zip - ,cs1.c_street_number - ,cs1.c_street_name - ,cs1.c_city - ,cs1.c_zip - ,cs1.syear - ,cs1.cnt - ,cs1.s1 as s11 - ,cs1.s2 as s21 - ,cs1.s3 as s31 - ,cs2.s1 as s12 - ,cs2.s2 as s22 - ,cs2.s3 as s32 - ,cs2.syear - ,cs2.cnt -from cross_sales cs1,cross_sales cs2 -where cs1.item_sk=cs2.item_sk and - cs1.syear = 2000 and - cs2.syear = 2000 + 1 and - cs2.cnt <= cs1.cnt and - cs1.store_name = cs2.store_name and - cs1.store_zip = cs2.store_zip -order by cs1.product_name - ,cs1.store_name - ,cs2.cnt - ,cs1.s1 - ,cs2.s1; - --- end template query64.tpl query 77 in stream 5 --- start template query20.tpl query 78 in stream 5 -select /* TPC-DS query20.tpl 0.65 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(cs_ext_sales_price) as itemrevenue - ,sum(cs_ext_sales_price)*100/sum(sum(cs_ext_sales_price)) over - (partition by i_class) as revenueratio - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and i_category in ('Jewelry', 'Children', 'Books') - and cs_sold_date_sk = d_date_sk - and d_date between cast('1999-04-03' as date) - and dateadd(day,30,cast('1999-04-03' as date)) - group by i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - order by i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query20.tpl query 78 in stream 5 --- start template query43.tpl query 79 in stream 5 -select /* TPC-DS query43.tpl 0.15 */ s_store_name, s_store_id, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from date_dim, store_sales, store - where d_date_sk = ss_sold_date_sk and - s_store_sk = ss_store_sk and - s_gmt_offset = -5 and - d_year = 2001 - group by s_store_name, s_store_id - order by s_store_name, s_store_id,sun_sales,mon_sales,tue_sales,wed_sales,thu_sales,fri_sales,sat_sales - limit 100; - --- end template query43.tpl query 79 in stream 5 --- start template query5a.tpl query 80 in stream 5 -with /* TPC-DS query5a.tpl 0.98 */ ssr as - (select s_store_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ss_store_sk as store_sk, - ss_sold_date_sk as date_sk, - ss_ext_sales_price as sales_price, - ss_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from store_sales - union all - select sr_store_sk as store_sk, - sr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - sr_return_amt as return_amt, - sr_net_loss as net_loss - from store_returns - ) salesreturns, - date_dim, - store - where date_sk = d_date_sk - and d_date between cast('2002-08-10' as date) - and dateadd(day,14,cast('2002-08-10' as date)) - and store_sk = s_store_sk - group by s_store_id) - , - csr as - (select cp_catalog_page_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select cs_catalog_page_sk as page_sk, - cs_sold_date_sk as date_sk, - cs_ext_sales_price as sales_price, - cs_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from catalog_sales - union all - select cr_catalog_page_sk as page_sk, - cr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - cr_return_amount as return_amt, - cr_net_loss as net_loss - from catalog_returns - ) salesreturns, - date_dim, - catalog_page - where date_sk = d_date_sk - and d_date between cast('2002-08-10' as date) - and dateadd(day,14,cast('2002-08-10' as date)) - and page_sk = cp_catalog_page_sk - group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ws_web_site_sk as wsr_web_site_sk, - ws_sold_date_sk as date_sk, - ws_ext_sales_price as sales_price, - ws_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from web_sales - union all - select ws_web_site_sk as wsr_web_site_sk, - wr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - wr_return_amt as return_amt, - wr_net_loss as net_loss - from web_returns left outer join web_sales on - ( wr_item_sk = ws_item_sk - and wr_order_number = ws_order_number) - ) salesreturns, - date_dim, - web_site - where date_sk = d_date_sk - and d_date between cast('2002-08-10' as date) - and dateadd(day,14,cast('2002-08-10' as date)) - and wsr_web_site_sk = web_site_sk - group by web_site_id) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || s_store_id as id - , sales - , returns - , (profit - profit_loss) as profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || cp_catalog_page_id as id - , sales - , returns - , (profit - profit_loss) as profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , (profit - profit_loss) as profit - from wsr - ) x - group by channel, id) - select channel, id, sales, returns, profit from ( - select channel, id, sales, returns, profit from results - union - select channel, null as id, sum(sales), sum(returns), sum(profit) from results group by channel - union - select null as channel, null as id, sum(sales), sum(returns), sum(profit) from results) foo -order by channel, id -limit 100; - --- end template query5a.tpl query 80 in stream 5 --- start template query47.tpl query 81 in stream 5 -with /* TPC-DS query47.tpl 0.42 */ v1 as( - select i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, - s_store_name, s_company_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - s_store_name, s_company_name - order by d_year, d_moy) rn - from item, store_sales, date_dim, store - where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - ( - d_year = 1999 or - ( d_year = 1999-1 and d_moy =12) or - ( d_year = 1999+1 and d_moy =1) - ) - group by i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy), - v2 as( - select v1.i_brand - ,v1.d_year, v1.d_moy - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1.s_store_name = v1_lag.s_store_name and - v1.s_store_name = v1_lead.s_store_name and - v1.s_company_name = v1_lag.s_company_name and - v1.s_company_name = v1_lead.s_company_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 1999 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, avg_monthly_sales - limit 100; - --- end template query47.tpl query 81 in stream 5 --- start template query10.tpl query 82 in stream 5 -select /* TPC-DS query10.tpl 0.26 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3, - cd_dep_count, - count(*) cnt4, - cd_dep_employed_count, - count(*) cnt5, - cd_dep_college_count, - count(*) cnt6 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_county in ('Lonoke County','Stanly County','White County','Greeley County','Le Flore County') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 2 and 2+3) and - (exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 2 ANd 2+3) or - exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 2 and 2+3)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count -limit 100; - --- end template query10.tpl query 82 in stream 5 --- start template query70a.tpl query 83 in stream 5 -with /* TPC-DS query70a.tpl 0.34 */ results as -( select - sum(ss_net_profit) as total_sum ,s_state ,s_county, 0 as gstate, 0 as g_county - from - store_sales - ,date_dim d1 - ,store - where - d1.d_month_seq between 1192 and 1192 + 11 - and d1.d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - and s_state in - ( select s_state - from (select s_state as s_state, - rank() over ( partition by s_state order by sum(ss_net_profit) desc) as ranking - from store_sales, store, date_dim - where d_month_seq between 1192 and 1192 + 11 - and d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - group by s_state - ) tmp1 - where ranking <= 5) - group by s_state,s_county) , - results_rollup as -(select total_sum ,s_state ,s_county, 0 as g_state, 0 as g_county, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum,s_state, NULL as s_county, 0 as g_state, 1 as g_county, 1 as lochierarchy from results group by s_state - union - select sum(total_sum) as total_sum ,NULL as s_state ,NULL as s_county, 1 as g_state, 1 as g_county, 2 as lochierarchy from results) - select total_sum ,s_state ,s_county, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_county = 0 then s_state end - order by total_sum desc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then s_state end - ,rank_within_parent - limit 100; - --- end template query70a.tpl query 83 in stream 5 --- start template query39.tpl query 84 in stream 5 -with /* TPC-DS query39.tpl 0.5 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =2000 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=3 - and inv2.d_moy=3+1 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; -with /* TPC-DS query39.tpl 0.5 part2 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =2000 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=3 - and inv2.d_moy=3+1 - and inv1.cov > 1.5 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; - --- end template query39.tpl query 84 in stream 5 --- start template query72.tpl query 85 in stream 5 -select /* TPC-DS query72.tpl 0.87 */ i_item_desc - ,w_warehouse_name - ,d1.d_week_seq - ,sum(case when p_promo_sk is null then 1 else 0 end) no_promo - ,sum(case when p_promo_sk is not null then 1 else 0 end) promo - ,count(*) total_cnt -from catalog_sales -join inventory on (cs_item_sk = inv_item_sk) -join warehouse on (w_warehouse_sk=inv_warehouse_sk) -join item on (i_item_sk = cs_item_sk) -join customer_demographics on (cs_bill_cdemo_sk = cd_demo_sk) -join household_demographics on (cs_bill_hdemo_sk = hd_demo_sk) -join date_dim d1 on (cs_sold_date_sk = d1.d_date_sk) -join date_dim d2 on (inv_date_sk = d2.d_date_sk) -join date_dim d3 on (cs_ship_date_sk = d3.d_date_sk) -left outer join promotion on (cs_promo_sk=p_promo_sk) -left outer join catalog_returns on (cr_item_sk = cs_item_sk and cr_order_number = cs_order_number) -where d1.d_week_seq = d2.d_week_seq - and inv_quantity_on_hand < cs_quantity - and d3.d_date > d1.d_date + 5 - and hd_buy_potential = '501-1000' - and d1.d_year = 1999 - and cd_marital_status = 'D' -group by i_item_desc,w_warehouse_name,d1.d_week_seq -order by total_cnt desc, i_item_desc, w_warehouse_name, d_week_seq -limit 100; - --- end template query72.tpl query 85 in stream 5 --- start template query75.tpl query 86 in stream 5 -WITH /* TPC-DS query75.tpl 0.3 */ all_sales AS ( - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,SUM(sales_cnt) AS sales_cnt - ,SUM(sales_amt) AS sales_amt - FROM (SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,cs_quantity - COALESCE(cr_return_quantity,0) AS sales_cnt - ,cs_ext_sales_price - COALESCE(cr_return_amount,0.0) AS sales_amt - FROM catalog_sales JOIN item ON i_item_sk=cs_item_sk - JOIN date_dim ON d_date_sk=cs_sold_date_sk - LEFT JOIN catalog_returns ON (cs_order_number=cr_order_number - AND cs_item_sk=cr_item_sk) - WHERE i_category='Home' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ss_quantity - COALESCE(sr_return_quantity,0) AS sales_cnt - ,ss_ext_sales_price - COALESCE(sr_return_amt,0.0) AS sales_amt - FROM store_sales JOIN item ON i_item_sk=ss_item_sk - JOIN date_dim ON d_date_sk=ss_sold_date_sk - LEFT JOIN store_returns ON (ss_ticket_number=sr_ticket_number - AND ss_item_sk=sr_item_sk) - WHERE i_category='Home' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ws_quantity - COALESCE(wr_return_quantity,0) AS sales_cnt - ,ws_ext_sales_price - COALESCE(wr_return_amt,0.0) AS sales_amt - FROM web_sales JOIN item ON i_item_sk=ws_item_sk - JOIN date_dim ON d_date_sk=ws_sold_date_sk - LEFT JOIN web_returns ON (ws_order_number=wr_order_number - AND ws_item_sk=wr_item_sk) - WHERE i_category='Home') sales_detail - GROUP BY d_year, i_brand_id, i_class_id, i_category_id, i_manufact_id) - SELECT prev_yr.d_year AS prev_year - ,curr_yr.d_year AS year - ,curr_yr.i_brand_id - ,curr_yr.i_class_id - ,curr_yr.i_category_id - ,curr_yr.i_manufact_id - ,prev_yr.sales_cnt AS prev_yr_cnt - ,curr_yr.sales_cnt AS curr_yr_cnt - ,curr_yr.sales_cnt-prev_yr.sales_cnt AS sales_cnt_diff - ,curr_yr.sales_amt-prev_yr.sales_amt AS sales_amt_diff - FROM all_sales curr_yr, all_sales prev_yr - WHERE curr_yr.i_brand_id=prev_yr.i_brand_id - AND curr_yr.i_class_id=prev_yr.i_class_id - AND curr_yr.i_category_id=prev_yr.i_category_id - AND curr_yr.i_manufact_id=prev_yr.i_manufact_id - AND curr_yr.d_year=1999 - AND prev_yr.d_year=1999-1 - AND CAST(curr_yr.sales_cnt AS DECIMAL(17,2))/CAST(prev_yr.sales_cnt AS DECIMAL(17,2))<0.9 - ORDER BY sales_cnt_diff,sales_amt_diff - limit 100; - --- end template query75.tpl query 86 in stream 5 --- start template query12.tpl query 87 in stream 5 -select /* TPC-DS query12.tpl 0.64 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ws_ext_sales_price) as itemrevenue - ,sum(ws_ext_sales_price)*100/sum(sum(ws_ext_sales_price)) over - (partition by i_class) as revenueratio -from - web_sales - ,item - ,date_dim -where - ws_item_sk = i_item_sk - and i_category in ('Music', 'Electronics', 'Sports') - and ws_sold_date_sk = d_date_sk - and d_date between cast('1999-05-14' as date) - and dateadd(day,30,cast('1999-05-14' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query12.tpl query 87 in stream 5 --- start template query37.tpl query 88 in stream 5 -select /* TPC-DS query37.tpl 0.31 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, catalog_sales - where i_current_price between 41 and 41 + 30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('1998-02-21' as date) and dateadd(day,60,cast('1998-02-21' as date)) - and i_manufact_id in (931,745,928,775) - and inv_quantity_on_hand between 100 and 500 - and cs_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query37.tpl query 88 in stream 5 --- start template query15.tpl query 89 in stream 5 -select /* TPC-DS query15.tpl 0.57 */ ca_zip - ,sum(cs_sales_price) - from catalog_sales - ,customer - ,customer_address - ,date_dim - where cs_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', - '85392', '85460', '80348', '81792') - or ca_state in ('CA','WA','GA') - or cs_sales_price > 500) - and cs_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 2002 - group by ca_zip - order by ca_zip - limit 100; - --- end template query15.tpl query 89 in stream 5 --- start template query59.tpl query 90 in stream 5 -with /* TPC-DS query59.tpl 0.30 */ wss as - (select d_week_seq, - ss_store_sk, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - group by d_week_seq,ss_store_sk - ) - select s_store_name1,s_store_id1,d_week_seq1 - ,sun_sales1/sun_sales2,mon_sales1/mon_sales2 - ,tue_sales1/tue_sales2,wed_sales1/wed_sales2,thu_sales1/thu_sales2 - ,fri_sales1/fri_sales2,sat_sales1/sat_sales2 - from - (select s_store_name s_store_name1,wss.d_week_seq d_week_seq1 - ,s_store_id s_store_id1,sun_sales sun_sales1 - ,mon_sales mon_sales1,tue_sales tue_sales1 - ,wed_sales wed_sales1,thu_sales thu_sales1 - ,fri_sales fri_sales1,sat_sales sat_sales1 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1194 and 1194 + 11) y, - (select s_store_name s_store_name2,wss.d_week_seq d_week_seq2 - ,s_store_id s_store_id2,sun_sales sun_sales2 - ,mon_sales mon_sales2,tue_sales tue_sales2 - ,wed_sales wed_sales2,thu_sales thu_sales2 - ,fri_sales fri_sales2,sat_sales sat_sales2 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1194+ 12 and 1194 + 23) x - where s_store_id1=s_store_id2 - and d_week_seq1=d_week_seq2-52 - order by s_store_name1,s_store_id1,d_week_seq1 -limit 100; - --- end template query59.tpl query 90 in stream 5 --- start template query91.tpl query 91 in stream 5 -select /* TPC-DS query91.tpl 0.13 */ - cc_call_center_id Call_Center, - cc_name Call_Center_Name, - cc_manager Manager, - sum(cr_net_loss) Returns_Loss -from - call_center, - catalog_returns, - date_dim, - customer, - customer_address, - customer_demographics, - household_demographics -where - cr_call_center_sk = cc_call_center_sk -and cr_returned_date_sk = d_date_sk -and cr_returning_customer_sk= c_customer_sk -and cd_demo_sk = c_current_cdemo_sk -and hd_demo_sk = c_current_hdemo_sk -and ca_address_sk = c_current_addr_sk -and d_year = 2001 -and d_moy = 12 -and ( (cd_marital_status = 'M' and cd_education_status = 'Unknown') - or(cd_marital_status = 'W' and cd_education_status = 'Advanced Degree')) -and hd_buy_potential like '1001-5000%' -and ca_gmt_offset = -6 -group by cc_call_center_id,cc_name,cc_manager,cd_marital_status,cd_education_status -order by sum(cr_net_loss) desc; - --- end template query91.tpl query 91 in stream 5 --- start template query99.tpl query 92 in stream 5 -select /* TPC-DS query99.tpl 0.94 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 30) and - (cs_ship_date_sk - cs_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 60) and - (cs_ship_date_sk - cs_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 90) and - (cs_ship_date_sk - cs_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - catalog_sales - ,warehouse - ,ship_mode - ,call_center - ,date_dim -where - d_month_seq between 1200 and 1200 + 11 -and cs_ship_date_sk = d_date_sk -and cs_warehouse_sk = w_warehouse_sk -and cs_ship_mode_sk = sm_ship_mode_sk -and cs_call_center_sk = cc_call_center_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -limit 100; - --- end template query99.tpl query 92 in stream 5 --- start template query41.tpl query 93 in stream 5 -select /* TPC-DS query41.tpl 0.62 */ distinct(i_product_name) - from item i1 - where i_manufact_id between 721 and 721+40 - and (select count(*) as item_cnt - from item - where (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'wheat' or i_color = 'deep') and - (i_units = 'Lb' or i_units = 'Dozen') and - (i_size = 'large' or i_size = 'N/A') - ) or - (i_category = 'Women' and - (i_color = 'lavender' or i_color = 'chiffon') and - (i_units = 'Pallet' or i_units = 'Ounce') and - (i_size = 'petite' or i_size = 'medium') - ) or - (i_category = 'Men' and - (i_color = 'navajo' or i_color = 'lawn') and - (i_units = 'Tsp' or i_units = 'Gross') and - (i_size = 'small' or i_size = 'economy') - ) or - (i_category = 'Men' and - (i_color = 'sandy' or i_color = 'cornflower') and - (i_units = 'Gram' or i_units = 'Each') and - (i_size = 'large' or i_size = 'N/A') - ))) or - (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'peach' or i_color = 'magenta') and - (i_units = 'Bundle' or i_units = 'Cup') and - (i_size = 'large' or i_size = 'N/A') - ) or - (i_category = 'Women' and - (i_color = 'blue' or i_color = 'indian') and - (i_units = 'Tbl' or i_units = 'Carton') and - (i_size = 'petite' or i_size = 'medium') - ) or - (i_category = 'Men' and - (i_color = 'pink' or i_color = 'papaya') and - (i_units = 'N/A' or i_units = 'Dram') and - (i_size = 'small' or i_size = 'economy') - ) or - (i_category = 'Men' and - (i_color = 'tan' or i_color = 'lemon') and - (i_units = 'Bunch' or i_units = 'Oz') and - (i_size = 'large' or i_size = 'N/A') - )))) > 0 - order by i_product_name - limit 100; - --- end template query41.tpl query 93 in stream 5 --- start template query9.tpl query 94 in stream 5 -select /* TPC-DS query9.tpl 0.49 */ case when (select count(*) - from store_sales - where ss_quantity between 1 and 20) > 7649765 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 1 and 20) - else (select avg(ss_net_profit) - from store_sales - where ss_quantity between 1 and 20) end bucket1 , - case when (select count(*) - from store_sales - where ss_quantity between 21 and 40) > 2312674 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 21 and 40) - else (select avg(ss_net_profit) - from store_sales - where ss_quantity between 21 and 40) end bucket2, - case when (select count(*) - from store_sales - where ss_quantity between 41 and 60) > 21856370 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 41 and 60) - else (select avg(ss_net_profit) - from store_sales - where ss_quantity between 41 and 60) end bucket3, - case when (select count(*) - from store_sales - where ss_quantity between 61 and 80) > 17768571 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 61 and 80) - else (select avg(ss_net_profit) - from store_sales - where ss_quantity between 61 and 80) end bucket4, - case when (select count(*) - from store_sales - where ss_quantity between 81 and 100) > 46038805 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 81 and 100) - else (select avg(ss_net_profit) - from store_sales - where ss_quantity between 81 and 100) end bucket5 -from reason -where r_reason_sk = 1 -; - --- end template query9.tpl query 94 in stream 5 --- start template query86a.tpl query 95 in stream 5 -with /* TPC-DS query86a.tpl 0.11 */ results as -( select sum(ws_net_paid) as total_sum, i_category, i_class, 0 as g_category, 0 as g_class - from - web_sales - ,date_dim d1 - ,item - where - d1.d_month_seq between 1208 and 1208+11 - and d1.d_date_sk = ws_sold_date_sk - and i_item_sk = ws_item_sk - group by i_category,i_class - ) , - - results_rollup as -( select total_sum ,i_category ,i_class, g_category, g_class, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum, i_category, NULL as i_class, 0 as g_category, 1 as g_class, 1 as lochierarchy from results group by i_category - union - select sum(total_sum) as total_sum, NULL as i_category, NULL as i_class, 1 as g_category, 1 as g_class, 2 as lochierarchy from results) - select - total_sum ,i_category ,i_class, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_class = 0 then i_category end - order by total_sum desc) as rank_within_parent - from - results_rollup - order by - lochierarchy desc, - case when lochierarchy = 0 then i_category end, - rank_within_parent - limit 100; - --- end template query86a.tpl query 95 in stream 5 --- start template query34.tpl query 96 in stream 5 -select /* TPC-DS query34.tpl 0.73 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (date_dim.d_dom between 1 and 3 or date_dim.d_dom between 25 and 28) - and (household_demographics.hd_buy_potential = '>10000' or - household_demographics.hd_buy_potential = '0-500') - and household_demographics.hd_vehicle_count > 0 - and (case when household_demographics.hd_vehicle_count > 0 - then household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count - else null - end) > 1.2 - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_county in ('Maverick County','Barrow County','Levy County','Gogebic County', - 'Kittitas County','Huron County','Jackson County','Pennington County') - group by ss_ticket_number,ss_customer_sk) dn,customer - where ss_customer_sk = c_customer_sk - and cnt between 15 and 20 - order by c_last_name,c_first_name,c_salutation,c_preferred_cust_flag desc, ss_ticket_number; - --- end template query34.tpl query 96 in stream 5 --- start template query82.tpl query 97 in stream 5 -select /* TPC-DS query82.tpl 0.67 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, store_sales - where i_current_price between 30 and 30+30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('1999-05-15' as date) and dateadd(day,60,cast('1999-05-15' as date)) - and i_manufact_id in (475,583,955,934) - and inv_quantity_on_hand between 100 and 500 - and ss_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query82.tpl query 97 in stream 5 --- start template query29.tpl query 98 in stream 5 -select /* TPC-DS query29.tpl 0.53 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,stddev_samp(ss_quantity) as store_sales_quantity - ,stddev_samp(sr_return_quantity) as store_returns_quantity - ,stddev_samp(cs_quantity) as catalog_sales_quantity - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 2000 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 4 + 3 - and d2.d_year = 2000 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_year in (2000,2000+1,2000+2) - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query29.tpl query 98 in stream 5 --- start template query25.tpl query 99 in stream 5 -select /* TPC-DS query25.tpl 0.9 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,avg(ss_net_profit) as store_sales_profit - ,avg(sr_net_loss) as store_returns_loss - ,avg(cs_net_profit) as catalog_sales_profit - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 2002 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 10 - and d2.d_year = 2002 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_moy between 4 and 10 - and d3.d_year = 2002 - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query25.tpl query 99 in stream 5 diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/1TB/queries/query_6.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/1TB/queries/query_6.sql deleted file mode 100644 index 7db3a613..00000000 --- a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/1TB/queries/query_6.sql +++ /dev/null @@ -1,5027 +0,0 @@ --- start template query34.tpl query 1 in stream 6 -select /* TPC-DS query34.tpl 0.73 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (date_dim.d_dom between 1 and 3 or date_dim.d_dom between 25 and 28) - and (household_demographics.hd_buy_potential = '>10000' or - household_demographics.hd_buy_potential = '0-500') - and household_demographics.hd_vehicle_count > 0 - and (case when household_demographics.hd_vehicle_count > 0 - then household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count - else null - end) > 1.2 - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_county in ('Ziebach County','Mobile County','Maverick County','Richland County', - 'Bronx County','Kittitas County','Jefferson Davis Parish','Williamson County') - group by ss_ticket_number,ss_customer_sk) dn,customer - where ss_customer_sk = c_customer_sk - and cnt between 15 and 20 - order by c_last_name,c_first_name,c_salutation,c_preferred_cust_flag desc, ss_ticket_number; - --- end template query34.tpl query 1 in stream 6 --- start template query88.tpl query 2 in stream 6 -select /* TPC-DS query88.tpl 0.66 */ * -from - (select count(*) h8_30_to_9 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2)) - and store.s_store_name = 'ese') s1, - (select count(*) h9_to_9_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2)) - and store.s_store_name = 'ese') s2, - (select count(*) h9_30_to_10 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2)) - and store.s_store_name = 'ese') s3, - (select count(*) h10_to_10_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2)) - and store.s_store_name = 'ese') s4, - (select count(*) h10_30_to_11 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2)) - and store.s_store_name = 'ese') s5, - (select count(*) h11_to_11_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2)) - and store.s_store_name = 'ese') s6, - (select count(*) h11_30_to_12 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2)) - and store.s_store_name = 'ese') s7, - (select count(*) h12_to_12_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 12 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2)) - and store.s_store_name = 'ese') s8 -; - --- end template query88.tpl query 2 in stream 6 --- start template query44.tpl query 3 in stream 6 -select /* TPC-DS query44.tpl 0.4 */ asceding.rnk, i1.i_product_name best_performing, i2.i_product_name worst_performing -from(select * - from (select item_sk,rank() over (order by rank_col asc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 340 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 340 - and ss_addr_sk is null - group by ss_store_sk))V1)V11 - where rnk < 11) asceding, - (select * - from (select item_sk,rank() over (order by rank_col desc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 340 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 340 - and ss_addr_sk is null - group by ss_store_sk))V2)V21 - where rnk < 11) descending, -item i1, -item i2 -where asceding.rnk = descending.rnk - and i1.i_item_sk=asceding.item_sk - and i2.i_item_sk=descending.item_sk -order by asceding.rnk -limit 100; - --- end template query44.tpl query 3 in stream 6 --- start template query94.tpl query 4 in stream 6 -select /* TPC-DS query94.tpl 0.17 */ - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2000-2-01' and - dateadd(day,60,cast('2000-2-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'GA' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and exists (select * - from web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) -and not exists(select * - from web_returns wr1 - where ws1.ws_order_number = wr1.wr_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query94.tpl query 4 in stream 6 --- start template query50.tpl query 5 in stream 6 -select /* TPC-DS query50.tpl 0.60 */ - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 30) and - (sr_returned_date_sk - ss_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 60) and - (sr_returned_date_sk - ss_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 90) and - (sr_returned_date_sk - ss_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - store_sales - ,store_returns - ,store - ,date_dim d1 - ,date_dim d2 -where - d2.d_year = 2001 -and d2.d_moy = 10 -and ss_ticket_number = sr_ticket_number -and ss_item_sk = sr_item_sk -and ss_sold_date_sk = d1.d_date_sk -and sr_returned_date_sk = d2.d_date_sk -and ss_customer_sk = sr_customer_sk -and ss_store_sk = s_store_sk -group by - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -order by s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -limit 100; - --- end template query50.tpl query 5 in stream 6 --- start template query5a.tpl query 6 in stream 6 -with /* TPC-DS query5a.tpl 0.98 */ ssr as - (select s_store_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ss_store_sk as store_sk, - ss_sold_date_sk as date_sk, - ss_ext_sales_price as sales_price, - ss_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from store_sales - union all - select sr_store_sk as store_sk, - sr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - sr_return_amt as return_amt, - sr_net_loss as net_loss - from store_returns - ) salesreturns, - date_dim, - store - where date_sk = d_date_sk - and d_date between cast('1998-08-12' as date) - and dateadd(day,14,cast('1998-08-12' as date)) - and store_sk = s_store_sk - group by s_store_id) - , - csr as - (select cp_catalog_page_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select cs_catalog_page_sk as page_sk, - cs_sold_date_sk as date_sk, - cs_ext_sales_price as sales_price, - cs_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from catalog_sales - union all - select cr_catalog_page_sk as page_sk, - cr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - cr_return_amount as return_amt, - cr_net_loss as net_loss - from catalog_returns - ) salesreturns, - date_dim, - catalog_page - where date_sk = d_date_sk - and d_date between cast('1998-08-12' as date) - and dateadd(day,14,cast('1998-08-12' as date)) - and page_sk = cp_catalog_page_sk - group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ws_web_site_sk as wsr_web_site_sk, - ws_sold_date_sk as date_sk, - ws_ext_sales_price as sales_price, - ws_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from web_sales - union all - select ws_web_site_sk as wsr_web_site_sk, - wr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - wr_return_amt as return_amt, - wr_net_loss as net_loss - from web_returns left outer join web_sales on - ( wr_item_sk = ws_item_sk - and wr_order_number = ws_order_number) - ) salesreturns, - date_dim, - web_site - where date_sk = d_date_sk - and d_date between cast('1998-08-12' as date) - and dateadd(day,14,cast('1998-08-12' as date)) - and wsr_web_site_sk = web_site_sk - group by web_site_id) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || s_store_id as id - , sales - , returns - , (profit - profit_loss) as profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || cp_catalog_page_id as id - , sales - , returns - , (profit - profit_loss) as profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , (profit - profit_loss) as profit - from wsr - ) x - group by channel, id) - select channel, id, sales, returns, profit from ( - select channel, id, sales, returns, profit from results - union - select channel, null as id, sum(sales), sum(returns), sum(profit) from results group by channel - union - select null as channel, null as id, sum(sales), sum(returns), sum(profit) from results) foo -order by channel, id -limit 100; - --- end template query5a.tpl query 6 in stream 6 --- start template query53.tpl query 7 in stream 6 -select /* TPC-DS query53.tpl 0.88 */ * from -(select i_manufact_id, -sum(ss_sales_price) sum_sales, -avg(sum(ss_sales_price)) over (partition by i_manufact_id) avg_quarterly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and -ss_sold_date_sk = d_date_sk and -ss_store_sk = s_store_sk and -d_month_seq in (1213,1213+1,1213+2,1213+3,1213+4,1213+5,1213+6,1213+7,1213+8,1213+9,1213+10,1213+11) and -((i_category in ('Books','Children','Electronics') and -i_class in ('personal','portable','reference','self-help') and -i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) -or(i_category in ('Women','Music','Men') and -i_class in ('accessories','classical','fragrances','pants') and -i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manufact_id, d_qoy ) tmp1 -where case when avg_quarterly_sales > 0 - then abs (sum_sales - avg_quarterly_sales)/ avg_quarterly_sales - else null end > 0.1 -order by avg_quarterly_sales, - sum_sales, - i_manufact_id -limit 100; - --- end template query53.tpl query 7 in stream 6 --- start template query7.tpl query 8 in stream 6 -select /* TPC-DS query7.tpl 0.2 */ i_item_id, - avg(ss_quantity) agg1, - avg(ss_list_price) agg2, - avg(ss_coupon_amt) agg3, - avg(ss_sales_price) agg4 - from store_sales, customer_demographics, date_dim, item, promotion - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_cdemo_sk = cd_demo_sk and - ss_promo_sk = p_promo_sk and - cd_gender = 'M' and - cd_marital_status = 'M' and - cd_education_status = 'Secondary' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 2001 - group by i_item_id - order by i_item_id - limit 100; - --- end template query7.tpl query 8 in stream 6 --- start template query58.tpl query 9 in stream 6 -with /* TPC-DS query58.tpl 0.19 */ ss_items as - (select i_item_id item_id - ,sum(ss_ext_sales_price) ss_item_rev - from store_sales - ,item - ,date_dim - where ss_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '1998-07-05')) - and ss_sold_date_sk = d_date_sk - group by i_item_id), - cs_items as - (select i_item_id item_id - ,sum(cs_ext_sales_price) cs_item_rev - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '1998-07-05')) - and cs_sold_date_sk = d_date_sk - group by i_item_id), - ws_items as - (select i_item_id item_id - ,sum(ws_ext_sales_price) ws_item_rev - from web_sales - ,item - ,date_dim - where ws_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq =(select d_week_seq - from date_dim - where d_date = '1998-07-05')) - and ws_sold_date_sk = d_date_sk - group by i_item_id) - select ss_items.item_id - ,ss_item_rev - ,ss_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ss_dev - ,cs_item_rev - ,cs_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 cs_dev - ,ws_item_rev - ,ws_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ws_dev - ,(ss_item_rev+cs_item_rev+ws_item_rev)/3 average - from ss_items,cs_items,ws_items - where ss_items.item_id=cs_items.item_id - and ss_items.item_id=ws_items.item_id - and ss_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - and ss_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and cs_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and cs_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and ws_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and ws_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - order by item_id - ,ss_item_rev - limit 100; - --- end template query58.tpl query 9 in stream 6 --- start template query20.tpl query 10 in stream 6 -select /* TPC-DS query20.tpl 0.65 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(cs_ext_sales_price) as itemrevenue - ,sum(cs_ext_sales_price)*100/sum(sum(cs_ext_sales_price)) over - (partition by i_class) as revenueratio - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and i_category in ('Children', 'Men', 'Shoes') - and cs_sold_date_sk = d_date_sk - and d_date between cast('2001-03-15' as date) - and dateadd(day,30,cast('2001-03-15' as date)) - group by i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - order by i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query20.tpl query 10 in stream 6 --- start template query75.tpl query 11 in stream 6 -WITH /* TPC-DS query75.tpl 0.3 */ all_sales AS ( - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,SUM(sales_cnt) AS sales_cnt - ,SUM(sales_amt) AS sales_amt - FROM (SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,cs_quantity - COALESCE(cr_return_quantity,0) AS sales_cnt - ,cs_ext_sales_price - COALESCE(cr_return_amount,0.0) AS sales_amt - FROM catalog_sales JOIN item ON i_item_sk=cs_item_sk - JOIN date_dim ON d_date_sk=cs_sold_date_sk - LEFT JOIN catalog_returns ON (cs_order_number=cr_order_number - AND cs_item_sk=cr_item_sk) - WHERE i_category='Home' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ss_quantity - COALESCE(sr_return_quantity,0) AS sales_cnt - ,ss_ext_sales_price - COALESCE(sr_return_amt,0.0) AS sales_amt - FROM store_sales JOIN item ON i_item_sk=ss_item_sk - JOIN date_dim ON d_date_sk=ss_sold_date_sk - LEFT JOIN store_returns ON (ss_ticket_number=sr_ticket_number - AND ss_item_sk=sr_item_sk) - WHERE i_category='Home' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ws_quantity - COALESCE(wr_return_quantity,0) AS sales_cnt - ,ws_ext_sales_price - COALESCE(wr_return_amt,0.0) AS sales_amt - FROM web_sales JOIN item ON i_item_sk=ws_item_sk - JOIN date_dim ON d_date_sk=ws_sold_date_sk - LEFT JOIN web_returns ON (ws_order_number=wr_order_number - AND ws_item_sk=wr_item_sk) - WHERE i_category='Home') sales_detail - GROUP BY d_year, i_brand_id, i_class_id, i_category_id, i_manufact_id) - SELECT prev_yr.d_year AS prev_year - ,curr_yr.d_year AS year - ,curr_yr.i_brand_id - ,curr_yr.i_class_id - ,curr_yr.i_category_id - ,curr_yr.i_manufact_id - ,prev_yr.sales_cnt AS prev_yr_cnt - ,curr_yr.sales_cnt AS curr_yr_cnt - ,curr_yr.sales_cnt-prev_yr.sales_cnt AS sales_cnt_diff - ,curr_yr.sales_amt-prev_yr.sales_amt AS sales_amt_diff - FROM all_sales curr_yr, all_sales prev_yr - WHERE curr_yr.i_brand_id=prev_yr.i_brand_id - AND curr_yr.i_class_id=prev_yr.i_class_id - AND curr_yr.i_category_id=prev_yr.i_category_id - AND curr_yr.i_manufact_id=prev_yr.i_manufact_id - AND curr_yr.d_year=1999 - AND prev_yr.d_year=1999-1 - AND CAST(curr_yr.sales_cnt AS DECIMAL(17,2))/CAST(prev_yr.sales_cnt AS DECIMAL(17,2))<0.9 - ORDER BY sales_cnt_diff,sales_amt_diff - limit 100; - --- end template query75.tpl query 11 in stream 6 --- start template query73.tpl query 12 in stream 6 -select /* TPC-DS query73.tpl 0.79 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_buy_potential = '>10000' or - household_demographics.hd_buy_potential = '5001-10000') - and household_demographics.hd_vehicle_count > 0 - and case when household_demographics.hd_vehicle_count > 0 then - household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count else null end > 1 - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_county in ('Gogebic County','Levy County','Mobile County','Mesa County') - group by ss_ticket_number,ss_customer_sk) dj,customer - where ss_customer_sk = c_customer_sk - and cnt between 1 and 5 - order by cnt desc, c_last_name asc; - --- end template query73.tpl query 12 in stream 6 --- start template query91.tpl query 13 in stream 6 -select /* TPC-DS query91.tpl 0.13 */ - cc_call_center_id Call_Center, - cc_name Call_Center_Name, - cc_manager Manager, - sum(cr_net_loss) Returns_Loss -from - call_center, - catalog_returns, - date_dim, - customer, - customer_address, - customer_demographics, - household_demographics -where - cr_call_center_sk = cc_call_center_sk -and cr_returned_date_sk = d_date_sk -and cr_returning_customer_sk= c_customer_sk -and cd_demo_sk = c_current_cdemo_sk -and hd_demo_sk = c_current_hdemo_sk -and ca_address_sk = c_current_addr_sk -and d_year = 2001 -and d_moy = 11 -and ( (cd_marital_status = 'M' and cd_education_status = 'Unknown') - or(cd_marital_status = 'W' and cd_education_status = 'Advanced Degree')) -and hd_buy_potential like 'Unknown%' -and ca_gmt_offset = -7 -group by cc_call_center_id,cc_name,cc_manager,cd_marital_status,cd_education_status -order by sum(cr_net_loss) desc; - --- end template query91.tpl query 13 in stream 6 --- start template query36a.tpl query 14 in stream 6 -with /* TPC-DS query36a.tpl 0.21 */ results as - (select - sum(ss_net_profit) as ss_net_profit, sum(ss_ext_sales_price) as ss_ext_sales_price, - sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin - ,i_category - ,i_class - ,0 as g_category, 0 as g_class - from - store_sales - ,date_dim d1 - ,item - ,store - where - d1.d_year = 1998 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and s_state in ('FL','MI','OH','AL', - 'SC','TN','PA','MO') - group by i_category,i_class) - , - results_rollup as - (select gross_margin ,i_category ,i_class,0 as t_category, 0 as t_class, 0 as lochierarchy from results - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - i_category, NULL AS i_class, 0 as t_category, 1 as t_class, 1 as lochierarchy from results group by i_category - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - NULL AS i_category ,NULL AS i_class, 1 as t_category, 1 as t_class, 2 as lochierarchy from results) - select - gross_margin ,i_category ,i_class, lochierarchy,rank() over ( - partition by lochierarchy, case when t_class = 0 then i_category end - order by gross_margin asc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then i_category end - ,rank_within_parent - limit 100; - --- end template query36a.tpl query 14 in stream 6 --- start template query11.tpl query 15 in stream 6 -with /* TPC-DS query11.tpl 0.51 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ss_ext_list_price-ss_ext_discount_amt) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ws_ext_list_price-ws_ext_discount_amt) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_preferred_cust_flag - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 1998 - and t_s_secyear.dyear = 1998+1 - and t_w_firstyear.dyear = 1998 - and t_w_secyear.dyear = 1998+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else 0.0 end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else 0.0 end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_preferred_cust_flag -limit 100; - --- end template query11.tpl query 15 in stream 6 --- start template query80a.tpl query 16 in stream 6 -with /* TPC-DS query80a.tpl 0.6 */ ssr as - (select s_store_id as store_id, - sum(ss_ext_sales_price) as sales, - sum(coalesce(sr_return_amt, 0)) as returns, - sum(ss_net_profit - coalesce(sr_net_loss, 0)) as profit - from store_sales left outer join store_returns on - (ss_item_sk = sr_item_sk and ss_ticket_number = sr_ticket_number), - date_dim, - store, - item, - promotion - where ss_sold_date_sk = d_date_sk - and d_date between cast('1999-08-09' as date) - and dateadd(day,30,cast('1999-08-09' as date)) - and ss_store_sk = s_store_sk - and ss_item_sk = i_item_sk - and i_current_price > 50 - and ss_promo_sk = p_promo_sk - and p_channel_tv = 'N' - group by s_store_id) - , - csr as - (select cp_catalog_page_id as catalog_page_id, - sum(cs_ext_sales_price) as sales, - sum(coalesce(cr_return_amount, 0)) as returns, - sum(cs_net_profit - coalesce(cr_net_loss, 0)) as profit - from catalog_sales left outer join catalog_returns on - (cs_item_sk = cr_item_sk and cs_order_number = cr_order_number), - date_dim, - catalog_page, - item, - promotion - where cs_sold_date_sk = d_date_sk - and d_date between cast('1999-08-09' as date) - and dateadd(day,30,cast('1999-08-09' as date)) - and cs_catalog_page_sk = cp_catalog_page_sk - and cs_item_sk = i_item_sk - and i_current_price > 50 - and cs_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(ws_ext_sales_price) as sales, - sum(coalesce(wr_return_amt, 0)) as returns, - sum(ws_net_profit - coalesce(wr_net_loss, 0)) as profit - from web_sales left outer join web_returns on - (ws_item_sk = wr_item_sk and ws_order_number = wr_order_number), - date_dim, - web_site, - item, - promotion - where ws_sold_date_sk = d_date_sk - and d_date between cast('1999-08-09' as date) - and dateadd(day,30,cast('1999-08-09' as date)) - and ws_web_site_sk = web_site_sk - and ws_item_sk = i_item_sk - and i_current_price > 50 - and ws_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by web_site_id) -, -results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || store_id as id - , sales - , returns - , profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || catalog_page_id as id - , sales - , returns - , profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , profit - from wsr - ) x - group by channel, id) - - select channel - , id - , sales - , returns - , profit - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results - ) foo - order by channel, id - limit 100; - --- end template query80a.tpl query 16 in stream 6 --- start template query9.tpl query 17 in stream 6 -select /* TPC-DS query9.tpl 0.49 */ case when (select count(*) - from store_sales - where ss_quantity between 1 and 20) > 22244363 - then (select avg(ss_ext_list_price) - from store_sales - where ss_quantity between 1 and 20) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 1 and 20) end bucket1 , - case when (select count(*) - from store_sales - where ss_quantity between 21 and 40) > 28508541 - then (select avg(ss_ext_list_price) - from store_sales - where ss_quantity between 21 and 40) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 21 and 40) end bucket2, - case when (select count(*) - from store_sales - where ss_quantity between 41 and 60) > 17213740 - then (select avg(ss_ext_list_price) - from store_sales - where ss_quantity between 41 and 60) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 41 and 60) end bucket3, - case when (select count(*) - from store_sales - where ss_quantity between 61 and 80) > 47995649 - then (select avg(ss_ext_list_price) - from store_sales - where ss_quantity between 61 and 80) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 61 and 80) end bucket4, - case when (select count(*) - from store_sales - where ss_quantity between 81 and 100) > 20609507 - then (select avg(ss_ext_list_price) - from store_sales - where ss_quantity between 81 and 100) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 81 and 100) end bucket5 -from reason -where r_reason_sk = 1 -; - --- end template query9.tpl query 17 in stream 6 --- start template query93.tpl query 18 in stream 6 -select /* TPC-DS query93.tpl 0.52 */ ss_customer_sk - ,sum(act_sales) sumsales - from (select ss_item_sk - ,ss_ticket_number - ,ss_customer_sk - ,case when sr_return_quantity is not null then (ss_quantity-sr_return_quantity)*ss_sales_price - else (ss_quantity*ss_sales_price) end act_sales - from store_sales left outer join store_returns on (sr_item_sk = ss_item_sk - and sr_ticket_number = ss_ticket_number) - ,reason - where sr_reason_sk = r_reason_sk - and r_reason_desc = 'reason 35') t - group by ss_customer_sk - order by sumsales, ss_customer_sk -limit 100; - --- end template query93.tpl query 18 in stream 6 --- start template query32.tpl query 19 in stream 6 -select /* TPC-DS query32.tpl 0.7 */ sum(cs_ext_discount_amt) as "excess discount amount" -from - catalog_sales - ,item - ,date_dim -where -i_manufact_id = 649 -and i_item_sk = cs_item_sk -and d_date between '1999-01-11' and - dateadd(day,90,cast('1999-01-11' as date)) -and d_date_sk = cs_sold_date_sk -and cs_ext_discount_amt - > ( - select - 1.3 * avg(cs_ext_discount_amt) - from - catalog_sales - ,date_dim - where - cs_item_sk = i_item_sk - and d_date between '1999-01-11' and - dateadd(day,90,cast('1999-01-11' as date)) - and d_date_sk = cs_sold_date_sk - ) -limit 100; - --- end template query32.tpl query 19 in stream 6 --- start template query89.tpl query 20 in stream 6 -select /* TPC-DS query89.tpl 0.56 */ * -from( -select i_category, i_class, i_brand, - s_store_name, s_company_name, - d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, s_store_name, s_company_name) - avg_monthly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - d_year in (1998) and - ((i_category in ('Children','Sports','Jewelry') and - i_class in ('infants','sailing','estate') - ) - or (i_category in ('Men','Home','Music') and - i_class in ('shirts','wallpaper','pop') - )) -group by i_category, i_class, i_brand, - s_store_name, s_company_name, d_moy) tmp1 -where case when (avg_monthly_sales <> 0) then (abs(sum_sales - avg_monthly_sales) / avg_monthly_sales) else null end > 0.1 -order by sum_sales - avg_monthly_sales, s_store_name -limit 100; - --- end template query89.tpl query 20 in stream 6 --- start template query28.tpl query 21 in stream 6 -select /* TPC-DS query28.tpl 0.36 */ * -from (select avg(ss_list_price) B1_LP - ,count(ss_list_price) B1_CNT - ,count(distinct ss_list_price) B1_CNTD - from store_sales - where ss_quantity between 0 and 5 - and (ss_list_price between 181 and 181+10 - or ss_coupon_amt between 13607 and 13607+1000 - or ss_wholesale_cost between 30 and 30+20)) B1, - (select avg(ss_list_price) B2_LP - ,count(ss_list_price) B2_CNT - ,count(distinct ss_list_price) B2_CNTD - from store_sales - where ss_quantity between 6 and 10 - and (ss_list_price between 168 and 168+10 - or ss_coupon_amt between 16247 and 16247+1000 - or ss_wholesale_cost between 1 and 1+20)) B2, - (select avg(ss_list_price) B3_LP - ,count(ss_list_price) B3_CNT - ,count(distinct ss_list_price) B3_CNTD - from store_sales - where ss_quantity between 11 and 15 - and (ss_list_price between 48 and 48+10 - or ss_coupon_amt between 10057 and 10057+1000 - or ss_wholesale_cost between 34 and 34+20)) B3, - (select avg(ss_list_price) B4_LP - ,count(ss_list_price) B4_CNT - ,count(distinct ss_list_price) B4_CNTD - from store_sales - where ss_quantity between 16 and 20 - and (ss_list_price between 37 and 37+10 - or ss_coupon_amt between 17855 and 17855+1000 - or ss_wholesale_cost between 44 and 44+20)) B4, - (select avg(ss_list_price) B5_LP - ,count(ss_list_price) B5_CNT - ,count(distinct ss_list_price) B5_CNTD - from store_sales - where ss_quantity between 21 and 25 - and (ss_list_price between 121 and 121+10 - or ss_coupon_amt between 1690 and 1690+1000 - or ss_wholesale_cost between 25 and 25+20)) B5, - (select avg(ss_list_price) B6_LP - ,count(ss_list_price) B6_CNT - ,count(distinct ss_list_price) B6_CNTD - from store_sales - where ss_quantity between 26 and 30 - and (ss_list_price between 125 and 125+10 - or ss_coupon_amt between 9887 and 9887+1000 - or ss_wholesale_cost between 75 and 75+20)) B6 -limit 100; - --- end template query28.tpl query 21 in stream 6 --- start template query87.tpl query 22 in stream 6 -select /* TPC-DS query87.tpl 0.77 */ count(*) -from ((select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1206 and 1206+11) - except - (select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1206 and 1206+11) - except - (select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1206 and 1206+11) -) cool_cust -; - --- end template query87.tpl query 22 in stream 6 --- start template query18a.tpl query 23 in stream 6 -with /* TPC-DS query18a.tpl 0.90 */ results as - (select i_item_id, - ca_country, - ca_state, - ca_county, - cast(cs_quantity as decimal(12,2)) agg1, - cast(cs_list_price as decimal(12,2)) agg2, - cast(cs_coupon_amt as decimal(12,2)) agg3, - cast(cs_sales_price as decimal(12,2)) agg4, - cast(cs_net_profit as decimal(12,2)) agg5, - cast(c_birth_year as decimal(12,2)) agg6, - cast(cd1.cd_dep_count as decimal(12,2)) agg7 - from catalog_sales, customer_demographics cd1, customer_demographics cd2, customer, customer_address, date_dim, item - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd1.cd_demo_sk and - cs_bill_customer_sk = c_customer_sk and - cd1.cd_gender = 'F' and - cd1.cd_education_status = 'College' and - c_current_cdemo_sk = cd2.cd_demo_sk and - c_current_addr_sk = ca_address_sk and - c_birth_month in (10,4,7,3,9,12) and - d_year = 1998 and - ca_state in ('MS','GA','ID','SC','KS','OH','LA') - ) - select i_item_id, ca_country, ca_state, ca_county, agg1, agg2, agg3, agg4, agg5, agg6, agg7 - from ( - select i_item_id, ca_country, ca_state, ca_county, avg(agg1) agg1, - avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state, ca_county - union all - select i_item_id, ca_country, ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state - union all - select i_item_id, ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country - union all - select i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - ) foo - order by ca_country, ca_state, ca_county, i_item_id - limit 100; - --- end template query18a.tpl query 23 in stream 6 --- start template query74.tpl query 24 in stream 6 -with /* TPC-DS query74.tpl 0.76 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,max(ss_net_paid) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1998,1998+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,max(ws_net_paid) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - and d_year in (1998,1998+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - ) - select - t_s_secyear.customer_id, t_s_secyear.customer_first_name, t_s_secyear.customer_last_name - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.year = 1998 - and t_s_secyear.year = 1998+1 - and t_w_firstyear.year = 1998 - and t_w_secyear.year = 1998+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - order by 1,2,3 -limit 100; - --- end template query74.tpl query 24 in stream 6 --- start template query6.tpl query 25 in stream 6 -select /* TPC-DS query6.tpl 0.58 */ a.ca_state state, count(*) cnt - from customer_address a - ,customer c - ,store_sales s - ,date_dim d - ,item i - where a.ca_address_sk = c.c_current_addr_sk - and c.c_customer_sk = s.ss_customer_sk - and s.ss_sold_date_sk = d.d_date_sk - and s.ss_item_sk = i.i_item_sk - and d.d_month_seq = - (select distinct (d_month_seq) - from date_dim - where d_year = 1998 - and d_moy = 5 ) - and i.i_current_price > 1.2 * - (select avg(j.i_current_price) - from item j - where j.i_category = i.i_category) - group by a.ca_state - having count(*) >= 10 - order by cnt, a.ca_state - limit 100; - --- end template query6.tpl query 25 in stream 6 --- start template query65.tpl query 26 in stream 6 -select /* TPC-DS query65.tpl 0.71 */ - s_store_name, - i_item_desc, - sc.revenue, - i_current_price, - i_wholesale_cost, - i_brand - from store, item, - (select ss_store_sk, avg(revenue) as ave - from - (select ss_store_sk, ss_item_sk, - sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1192 and 1192+11 - group by ss_store_sk, ss_item_sk) sa - group by ss_store_sk) sb, - (select ss_store_sk, ss_item_sk, sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1192 and 1192+11 - group by ss_store_sk, ss_item_sk) sc - where sb.ss_store_sk = sc.ss_store_sk and - sc.revenue <= 0.1 * sb.ave and - s_store_sk = sc.ss_store_sk and - i_item_sk = sc.ss_item_sk - order by s_store_name, i_item_desc -limit 100; - --- end template query65.tpl query 26 in stream 6 --- start template query84.tpl query 27 in stream 6 -select /* TPC-DS query84.tpl 0.80 */ c_customer_id as customer_id - , coalesce(c_last_name,'') || ', ' || coalesce(c_first_name,'') as customername - from customer - ,customer_address - ,customer_demographics - ,household_demographics - ,income_band - ,store_returns - where ca_city = 'Oak Grove' - and c_current_addr_sk = ca_address_sk - and ib_lower_bound >= 48003 - and ib_upper_bound <= 48003 + 50000 - and ib_income_band_sk = hd_income_band_sk - and cd_demo_sk = c_current_cdemo_sk - and hd_demo_sk = c_current_hdemo_sk - and sr_cdemo_sk = cd_demo_sk - order by c_customer_id - limit 100; - --- end template query84.tpl query 27 in stream 6 --- start template query14a.tpl query 28 in stream 6 -with /* TPC-DS query14a.tpl 0.69 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1998 AND 1998 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1998 AND 1998 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1998 AND 1998 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as - (select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2) x) -, - results AS -(select channel, i_brand_id, i_class_id, i_category_id, sum(sales) sum_sales, sum(number_sales) number_sales - from ( - select 'store' channel, i_brand_id,i_class_id - ,i_category_id,sum(ss_quantity*ss_list_price) sales - , count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1998+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales) - union all - select 'catalog' channel, i_brand_id,i_class_id,i_category_id, sum(cs_quantity*cs_list_price) sales, count(*) number_sales - from catalog_sales - ,item - ,date_dim - where cs_item_sk in (select ss_item_sk from cross_items) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1998+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(cs_quantity*cs_list_price) > (select average_sales from avg_sales) - union all - select 'web' channel, i_brand_id,i_class_id,i_category_id, sum(ws_quantity*ws_list_price) sales , count(*) number_sales - from web_sales - ,item - ,date_dim - where ws_item_sk in (select ss_item_sk from cross_items) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1998+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ws_quantity*ws_list_price) > (select average_sales from avg_sales) - ) y - group by channel, i_brand_id,i_class_id,i_category_id) - - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales -from ( - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales from results - union - select channel, i_brand_id, i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id, i_class_id - union - select channel, i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id - union - select channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel - union - select null as channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results) z -order by channel, i_brand_id, i_class_id, i_category_id - limit 100; -with /* TPC-DS query14a.tpl 0.69 part2 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1998 AND 1998 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1998 AND 1998 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1998 AND 1998 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as -(select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2) x) - select this_year.channel ty_channel - ,this_year.i_brand_id ty_brand - ,this_year.i_class_id ty_class - ,this_year.i_category_id ty_category - ,this_year.sales ty_sales - ,this_year.number_sales ty_number_sales - ,last_year.channel ly_channel - ,last_year.i_brand_id ly_brand - ,last_year.i_class_id ly_class - ,last_year.i_category_id ly_category - ,last_year.sales ly_sales - ,last_year.number_sales ly_number_sales -from - (select 'store' channel, i_brand_id,i_class_id,i_category_id - ,sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1998 + 1 - and d_moy = 12 - and d_dom = 1) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) this_year, - (select 'store' channel, i_brand_id,i_class_id - ,i_category_id, sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1998 - and d_moy = 12 - and d_dom = 1) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) last_year - where this_year.i_brand_id= last_year.i_brand_id - and this_year.i_class_id = last_year.i_class_id - and this_year.i_category_id = last_year.i_category_id - order by this_year.channel, this_year.i_brand_id, this_year.i_class_id, this_year.i_category_id - limit 100; - --- end template query14a.tpl query 28 in stream 6 --- start template query38.tpl query 29 in stream 6 -select /* TPC-DS query38.tpl 0.54 */ count(*) from ( - select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1218 and 1218 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1218 and 1218 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1218 and 1218 + 11 -) hot_cust -limit 100; - --- end template query38.tpl query 29 in stream 6 --- start template query24.tpl query 30 in stream 6 -with /* TPC-DS query24.tpl 0.92 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_net_paid_inc_tax) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip -and s_market_id=8 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'chiffon' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; -with /* TPC-DS query24.tpl 0.92 part2 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_net_paid_inc_tax) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip - and s_market_id = 8 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'brown' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; - --- end template query24.tpl query 30 in stream 6 --- start template query42.tpl query 31 in stream 6 -select /* TPC-DS query42.tpl 0.61 */ dt.d_year - ,item.i_category_id - ,item.i_category - ,sum(ss_ext_sales_price) - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=12 - and dt.d_year=2002 - group by dt.d_year - ,item.i_category_id - ,item.i_category - order by sum(ss_ext_sales_price) desc,dt.d_year - ,item.i_category_id - ,item.i_category -limit 100 ; - --- end template query42.tpl query 31 in stream 6 --- start template query29.tpl query 32 in stream 6 -select /* TPC-DS query29.tpl 0.53 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,avg(ss_quantity) as store_sales_quantity - ,avg(sr_return_quantity) as store_returns_quantity - ,avg(cs_quantity) as catalog_sales_quantity - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 1998 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 4 + 3 - and d2.d_year = 1998 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_year in (1998,1998+1,1998+2) - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query29.tpl query 32 in stream 6 --- start template query72.tpl query 33 in stream 6 -select /* TPC-DS query72.tpl 0.87 */ i_item_desc - ,w_warehouse_name - ,d1.d_week_seq - ,sum(case when p_promo_sk is null then 1 else 0 end) no_promo - ,sum(case when p_promo_sk is not null then 1 else 0 end) promo - ,count(*) total_cnt -from catalog_sales -join inventory on (cs_item_sk = inv_item_sk) -join warehouse on (w_warehouse_sk=inv_warehouse_sk) -join item on (i_item_sk = cs_item_sk) -join customer_demographics on (cs_bill_cdemo_sk = cd_demo_sk) -join household_demographics on (cs_bill_hdemo_sk = hd_demo_sk) -join date_dim d1 on (cs_sold_date_sk = d1.d_date_sk) -join date_dim d2 on (inv_date_sk = d2.d_date_sk) -join date_dim d3 on (cs_ship_date_sk = d3.d_date_sk) -left outer join promotion on (cs_promo_sk=p_promo_sk) -left outer join catalog_returns on (cr_item_sk = cs_item_sk and cr_order_number = cs_order_number) -where d1.d_week_seq = d2.d_week_seq - and inv_quantity_on_hand < cs_quantity - and d3.d_date > d1.d_date + 5 - and hd_buy_potential = '1001-5000' - and d1.d_year = 2001 - and cd_marital_status = 'U' -group by i_item_desc,w_warehouse_name,d1.d_week_seq -order by total_cnt desc, i_item_desc, w_warehouse_name, d_week_seq -limit 100; - --- end template query72.tpl query 33 in stream 6 --- start template query23.tpl query 34 in stream 6 -with /* TPC-DS query23.tpl 0.68 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (1999,1999+1,1999+2,1999+3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1999,1999+1,1999+2,1999+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * -from - max_store_sales)) - select sum(sales) - from (select cs_quantity*cs_list_price sales - from catalog_sales - ,date_dim - where d_year = 1999 - and d_moy = 7 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - union all - select ws_quantity*ws_list_price sales - from web_sales - ,date_dim - where d_year = 1999 - and d_moy = 7 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer)) - limit 100; -with /* TPC-DS query23.tpl 0.68 part2 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (1999,1999 + 1,1999 + 2,1999 + 3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1999,1999+1,1999+2,1999+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * - from max_store_sales)) - select c_last_name,c_first_name,sales - from (select c_last_name,c_first_name,sum(cs_quantity*cs_list_price) sales - from catalog_sales - ,customer - ,date_dim - where d_year = 1999 - and d_moy = 7 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and cs_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name - union all - select c_last_name,c_first_name,sum(ws_quantity*ws_list_price) sales - from web_sales - ,customer - ,date_dim - where d_year = 1999 - and d_moy = 7 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and ws_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name) - order by c_last_name,c_first_name,sales - limit 100; - --- end template query23.tpl query 34 in stream 6 --- start template query26.tpl query 35 in stream 6 -select /* TPC-DS query26.tpl 0.85 */ i_item_id, - avg(cs_quantity) agg1, - avg(cs_list_price) agg2, - avg(cs_coupon_amt) agg3, - avg(cs_sales_price) agg4 - from catalog_sales, customer_demographics, date_dim, item, promotion - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd_demo_sk and - cs_promo_sk = p_promo_sk and - cd_gender = 'F' and - cd_marital_status = 'M' and - cd_education_status = '4 yr Degree' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 1999 - group by i_item_id - order by i_item_id - limit 100; - --- end template query26.tpl query 35 in stream 6 --- start template query69.tpl query 36 in stream 6 -select /* TPC-DS query69.tpl 0.28 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_state in ('MO','OR','KY') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2001 and - d_moy between 1 and 1+2) and - (not exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2001 and - d_moy between 1 and 1+2) and - not exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2001 and - d_moy between 1 and 1+2)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - limit 100; - --- end template query69.tpl query 36 in stream 6 --- start template query47.tpl query 37 in stream 6 -with /* TPC-DS query47.tpl 0.42 */ v1 as( - select i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, - s_store_name, s_company_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - s_store_name, s_company_name - order by d_year, d_moy) rn - from item, store_sales, date_dim, store - where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - ( - d_year = 2000 or - ( d_year = 2000-1 and d_moy =12) or - ( d_year = 2000+1 and d_moy =1) - ) - group by i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy), - v2 as( - select v1.s_store_name - ,v1.d_year, v1.d_moy - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1.s_store_name = v1_lag.s_store_name and - v1.s_store_name = v1_lead.s_store_name and - v1.s_company_name = v1_lag.s_company_name and - v1.s_company_name = v1_lead.s_company_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 2000 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, sum_sales - limit 100; - --- end template query47.tpl query 37 in stream 6 --- start template query82.tpl query 38 in stream 6 -select /* TPC-DS query82.tpl 0.67 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, store_sales - where i_current_price between 65 and 65+30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('2002-01-14' as date) and dateadd(day,60,cast('2002-01-14' as date)) - and i_manufact_id in (907,198,964,659) - and inv_quantity_on_hand between 100 and 500 - and ss_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query82.tpl query 38 in stream 6 --- start template query31.tpl query 39 in stream 6 -with /* TPC-DS query31.tpl 0.50 */ ss as - (select ca_county,d_qoy, d_year,sum(ss_ext_sales_price) as store_sales - from store_sales,date_dim,customer_address - where ss_sold_date_sk = d_date_sk - and ss_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year), - ws as - (select ca_county,d_qoy, d_year,sum(ws_ext_sales_price) as web_sales - from web_sales,date_dim,customer_address - where ws_sold_date_sk = d_date_sk - and ws_bill_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year) - select - ss1.ca_county - ,ss1.d_year - ,ws2.web_sales/ws1.web_sales web_q1_q2_increase - ,ss2.store_sales/ss1.store_sales store_q1_q2_increase - ,ws3.web_sales/ws2.web_sales web_q2_q3_increase - ,ss3.store_sales/ss2.store_sales store_q2_q3_increase - from - ss ss1 - ,ss ss2 - ,ss ss3 - ,ws ws1 - ,ws ws2 - ,ws ws3 - where - ss1.d_qoy = 1 - and ss1.d_year = 2002 - and ss1.ca_county = ss2.ca_county - and ss2.d_qoy = 2 - and ss2.d_year = 2002 - and ss2.ca_county = ss3.ca_county - and ss3.d_qoy = 3 - and ss3.d_year = 2002 - and ss1.ca_county = ws1.ca_county - and ws1.d_qoy = 1 - and ws1.d_year = 2002 - and ws1.ca_county = ws2.ca_county - and ws2.d_qoy = 2 - and ws2.d_year = 2002 - and ws1.ca_county = ws3.ca_county - and ws3.d_qoy = 3 - and ws3.d_year =2002 - and case when ws1.web_sales > 0 then ws2.web_sales/ws1.web_sales else null end - > case when ss1.store_sales > 0 then ss2.store_sales/ss1.store_sales else null end - and case when ws2.web_sales > 0 then ws3.web_sales/ws2.web_sales else null end - > case when ss2.store_sales > 0 then ss3.store_sales/ss2.store_sales else null end - order by ss1.d_year; - --- end template query31.tpl query 39 in stream 6 --- start template query59.tpl query 40 in stream 6 -with /* TPC-DS query59.tpl 0.30 */ wss as - (select d_week_seq, - ss_store_sk, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - group by d_week_seq,ss_store_sk - ) - select s_store_name1,s_store_id1,d_week_seq1 - ,sun_sales1/sun_sales2,mon_sales1/mon_sales2 - ,tue_sales1/tue_sales2,wed_sales1/wed_sales2,thu_sales1/thu_sales2 - ,fri_sales1/fri_sales2,sat_sales1/sat_sales2 - from - (select s_store_name s_store_name1,wss.d_week_seq d_week_seq1 - ,s_store_id s_store_id1,sun_sales sun_sales1 - ,mon_sales mon_sales1,tue_sales tue_sales1 - ,wed_sales wed_sales1,thu_sales thu_sales1 - ,fri_sales fri_sales1,sat_sales sat_sales1 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1198 and 1198 + 11) y, - (select s_store_name s_store_name2,wss.d_week_seq d_week_seq2 - ,s_store_id s_store_id2,sun_sales sun_sales2 - ,mon_sales mon_sales2,tue_sales tue_sales2 - ,wed_sales wed_sales2,thu_sales thu_sales2 - ,fri_sales fri_sales2,sat_sales sat_sales2 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1198+ 12 and 1198 + 23) x - where s_store_id1=s_store_id2 - and d_week_seq1=d_week_seq2-52 - order by s_store_name1,s_store_id1,d_week_seq1 -limit 100; - --- end template query59.tpl query 40 in stream 6 --- start template query49.tpl query 41 in stream 6 -select /* TPC-DS query49.tpl 0.48 */ channel, item, return_ratio, return_rank, currency_rank from - (select - 'web' as channel - ,web.item - ,web.return_ratio - ,web.return_rank - ,web.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select ws.ws_item_sk as item - ,(cast(sum(coalesce(wr.wr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(wr.wr_return_amt,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - web_sales ws left outer join web_returns wr - on (ws.ws_order_number = wr.wr_order_number and - ws.ws_item_sk = wr.wr_item_sk) - ,date_dim - where - wr.wr_return_amt > 10000 - and ws.ws_net_profit > 1 - and ws.ws_net_paid > 0 - and ws.ws_quantity > 0 - and ws_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 11 - group by ws.ws_item_sk - ) in_web - ) web - where - ( - web.return_rank <= 10 - or - web.currency_rank <= 10 - ) - union - select - 'catalog' as channel - ,catalog.item - ,catalog.return_ratio - ,catalog.return_rank - ,catalog.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select - cs.cs_item_sk as item - ,(cast(sum(coalesce(cr.cr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(cr.cr_return_amount,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - catalog_sales cs left outer join catalog_returns cr - on (cs.cs_order_number = cr.cr_order_number and - cs.cs_item_sk = cr.cr_item_sk) - ,date_dim - where - cr.cr_return_amount > 10000 - and cs.cs_net_profit > 1 - and cs.cs_net_paid > 0 - and cs.cs_quantity > 0 - and cs_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 11 - group by cs.cs_item_sk - ) in_cat - ) catalog - where - ( - catalog.return_rank <= 10 - or - catalog.currency_rank <=10 - ) - union - select - 'store' as channel - ,store.item - ,store.return_ratio - ,store.return_rank - ,store.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select sts.ss_item_sk as item - ,(cast(sum(coalesce(sr.sr_return_quantity,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(sr.sr_return_amt,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - store_sales sts left outer join store_returns sr - on (sts.ss_ticket_number = sr.sr_ticket_number and sts.ss_item_sk = sr.sr_item_sk) - ,date_dim - where - sr.sr_return_amt > 10000 - and sts.ss_net_profit > 1 - and sts.ss_net_paid > 0 - and sts.ss_quantity > 0 - and ss_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 11 - group by sts.ss_item_sk - ) in_store - ) store - where ( - store.return_rank <= 10 - or - store.currency_rank <= 10 - ) - ) - order by 1,4,5,2 - limit 100; - --- end template query49.tpl query 41 in stream 6 --- start template query33.tpl query 42 in stream 6 -with /* TPC-DS query33.tpl 0.22 */ ss as ( - select - i_manufact_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Sports')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 3 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id), - cs as ( - select - i_manufact_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Sports')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 3 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id), - ws as ( - select - i_manufact_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Sports')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 3 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id) - select i_manufact_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_manufact_id - order by total_sales -limit 100; - --- end template query33.tpl query 42 in stream 6 --- start template query86a.tpl query 43 in stream 6 -with /* TPC-DS query86a.tpl 0.11 */ results as -( select sum(ws_net_paid) as total_sum, i_category, i_class, 0 as g_category, 0 as g_class - from - web_sales - ,date_dim d1 - ,item - where - d1.d_month_seq between 1182 and 1182+11 - and d1.d_date_sk = ws_sold_date_sk - and i_item_sk = ws_item_sk - group by i_category,i_class - ) , - - results_rollup as -( select total_sum ,i_category ,i_class, g_category, g_class, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum, i_category, NULL as i_class, 0 as g_category, 1 as g_class, 1 as lochierarchy from results group by i_category - union - select sum(total_sum) as total_sum, NULL as i_category, NULL as i_class, 1 as g_category, 1 as g_class, 2 as lochierarchy from results) - select - total_sum ,i_category ,i_class, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_class = 0 then i_category end - order by total_sum desc) as rank_within_parent - from - results_rollup - order by - lochierarchy desc, - case when lochierarchy = 0 then i_category end, - rank_within_parent - limit 100; - --- end template query86a.tpl query 43 in stream 6 --- start template query99.tpl query 44 in stream 6 -select /* TPC-DS query99.tpl 0.94 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 30) and - (cs_ship_date_sk - cs_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 60) and - (cs_ship_date_sk - cs_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 90) and - (cs_ship_date_sk - cs_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - catalog_sales - ,warehouse - ,ship_mode - ,call_center - ,date_dim -where - d_month_seq between 1202 and 1202 + 11 -and cs_ship_date_sk = d_date_sk -and cs_warehouse_sk = w_warehouse_sk -and cs_ship_mode_sk = sm_ship_mode_sk -and cs_call_center_sk = cc_call_center_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -limit 100; - --- end template query99.tpl query 44 in stream 6 --- start template query4.tpl query 45 in stream 6 -with /* TPC-DS query4.tpl 0.93 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(((ss_ext_list_price-ss_ext_wholesale_cost-ss_ext_discount_amt)+ss_ext_sales_price)/2) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((cs_ext_list_price-cs_ext_wholesale_cost-cs_ext_discount_amt)+cs_ext_sales_price)/2) ) year_total - ,'c' sale_type - from customer - ,catalog_sales - ,date_dim - where c_customer_sk = cs_bill_customer_sk - and cs_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year -union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((ws_ext_list_price-ws_ext_wholesale_cost-ws_ext_discount_amt)+ws_ext_sales_price)/2) ) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_preferred_cust_flag - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_c_firstyear - ,year_total t_c_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_c_secyear.customer_id - and t_s_firstyear.customer_id = t_c_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_c_firstyear.sale_type = 'c' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_c_secyear.sale_type = 'c' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 1999 - and t_s_secyear.dyear = 1999+1 - and t_c_firstyear.dyear = 1999 - and t_c_secyear.dyear = 1999+1 - and t_w_firstyear.dyear = 1999 - and t_w_secyear.dyear = 1999+1 - and t_s_firstyear.year_total > 0 - and t_c_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_preferred_cust_flag -limit 100; - --- end template query4.tpl query 45 in stream 6 --- start template query45.tpl query 46 in stream 6 -select /* TPC-DS query45.tpl 0.18 */ ca_zip, ca_state, sum(ws_sales_price) - from web_sales, customer, customer_address, date_dim, item - where ws_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ws_item_sk = i_item_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', '85392', '85460', '80348', '81792') - or - i_item_id in (select i_item_id - from item - where i_item_sk in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29) - ) - ) - and ws_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 1998 - group by ca_zip, ca_state - order by ca_zip, ca_state - limit 100; - --- end template query45.tpl query 46 in stream 6 --- start template query85.tpl query 47 in stream 6 -select /* TPC-DS query85.tpl 0.33 */ substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) - from web_sales, web_returns, web_page, customer_demographics cd1, - customer_demographics cd2, customer_address, date_dim, reason - where ws_web_page_sk = wp_web_page_sk - and ws_item_sk = wr_item_sk - and ws_order_number = wr_order_number - and ws_sold_date_sk = d_date_sk and d_year = 2001 - and cd1.cd_demo_sk = wr_refunded_cdemo_sk - and cd2.cd_demo_sk = wr_returning_cdemo_sk - and ca_address_sk = wr_refunded_addr_sk - and r_reason_sk = wr_reason_sk - and - ( - ( - cd1.cd_marital_status = 'S' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Primary' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 100.00 and 150.00 - ) - or - ( - cd1.cd_marital_status = 'W' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = '2 yr Degree' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 50.00 and 100.00 - ) - or - ( - cd1.cd_marital_status = 'U' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Secondary' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ca_country = 'United States' - and - ca_state in ('GA', 'PA', 'TX') - and ws_net_profit between 100 and 200 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('MS', 'OH', 'OR') - and ws_net_profit between 150 and 300 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('WV', 'KY', 'NC') - and ws_net_profit between 50 and 250 - ) - ) -group by r_reason_desc -order by substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) -limit 100; - --- end template query85.tpl query 47 in stream 6 --- start template query8.tpl query 48 in stream 6 -select /* TPC-DS query8.tpl 0.63 */ s_store_name - ,sum(ss_net_profit) - from store_sales - ,date_dim - ,store, - (select ca_zip - from ( - SELECT substring(ca_zip,1,5) ca_zip - FROM customer_address - WHERE substring(ca_zip,1,5) IN ( - '79000','85163','30346','76576','61790','59398', - '85531','27753','56776','69757','14963', - '29255','28280','61223','82873','23304', - '73433','27652','36214','20833','68494', - '58810','89929','22099','85502','64510', - '80710','70353','96979','46226','68380', - '77215','33089','21744','67794','83041', - '46864','57545','64905','31553','97151', - '29671','91599','24554','20608','32031', - '76379','75948','20658','63960','54770', - '59916','55173','27896','94811','35164', - '39387','21679','39627','23582','58563', - '91919','56358','45235','63266','83675', - '78137','64222','67826','80478','92964', - '56225','51006','89120','53235','11644', - '32308','35081','89726','59522','26549', - '37731','48051','71979','52404','75086', - '94591','49199','48639','27377','23675', - '60152','71355','63779','49396','74339', - '11342','57677','49317','32734','76496', - '83893','32227','80457','58614','45806', - '47821','11478','86881','93155','44450', - '46886','25507','77532','32540','67298', - '25660','47168','58018','80899','96773', - '51215','27258','90681','93590','44598', - '19331','22394','57978','37026','24714', - '64530','20576','48116','26671','23073', - '69327','97514','67855','77107','43473', - '12765','84348','42353','74849','90475', - '24772','33870','20663','45312','66854', - '87200','43466','67553','20531','33383', - '62942','45162','29924','85475','26233', - '70370','31415','78771','74765','69788', - '28400','73828','41875','69608','23075', - '36400','18448','82956','26051','30543', - '11359','67104','91737','70498','17146', - '54674','42011','20724','29094','59495', - '60754','81001','18069','31181','79805', - '38728','46946','76840','58052','61540', - '91703','47661','78482','43561','85567', - '94236','26001','58055','28216','22574', - '89276','23562','35343','96065','93766', - '91272','57380','84547','30912','66938', - '97632','32225','64083','48429','71660', - '44779','47944','75691','64882','24146', - '82146','18274','16420','48260','78290', - '64934','81974','57594','30822','49557', - '52776','46025','87859','92728','97064', - '80258','40668','86948','97959','57317', - '41246','77134','62856','64331','46724', - '23625','75725','13271','23942','72067', - '18520','63059','58214','42357','25474', - '24488','43089','73280','77616','49630', - '79981','24305','24800','34959','19765', - '39594','69749','94066','85278','81068', - '30004','72232','22652','76186','60093', - '14256','28946','75617','70572','94610', - '79354','68605','70147','34806','38298', - '98708','57275','92013','65267','73170', - '83894','43890','93259','23641','15778', - '34367','76771','19200','12217','78842', - '49614','19914','79872','20341','62541', - '33762','73392','87791','75695','61759', - '57019','37702','60948','53714','93551', - '16678','20329','71536','31042','74211', - '52517','48014','82553','62889','76767', - '61757','72838','95974','56698','24376', - '75927','67214','31357','24012','72406', - '99707','40374','36016','84613','49352', - '60115','29297','26856','11843','54154', - '51250','27015','98000','72927','38783', - '10908','32251','36193','64288','51263', - '50446','16554','88198','56412','74555', - '64693','45831','97028','53534','62144', - '14568','95812','26091','27092','90065', - '62859','42783','66769','80933','47301', - '73086','31489','95730','16425','84262', - '63791','29685','40196','49784','17860', - '15055','67150','43933','51748','73879', - '52659','61691','81734','81238') - intersect - select ca_zip - from (SELECT substring(ca_zip,1,5) ca_zip,count(*) cnt - FROM customer_address, customer - WHERE ca_address_sk = c_current_addr_sk and - c_preferred_cust_flag='Y' - group by ca_zip - having count(*) > 10)A1)A2) V1 - where ss_store_sk = s_store_sk - and ss_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 1999 - and (substring(s_zip,1,2) = substring(V1.ca_zip,1,2)) - group by s_store_name - order by s_store_name - limit 100; - --- end template query8.tpl query 48 in stream 6 --- start template query19.tpl query 49 in stream 6 -select /* TPC-DS query19.tpl 0.8 */ i_brand_id brand_id, i_brand brand, i_manufact_id, i_manufact, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item,customer,customer_address,store - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=5 - and d_moy=11 - and d_year=2000 - and ss_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and substring(ca_zip,1,5) <> substring(s_zip,1,5) - and ss_store_sk = s_store_sk - group by i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact - order by ext_price desc - ,i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact -limit 100 ; - --- end template query19.tpl query 49 in stream 6 --- start template query61.tpl query 50 in stream 6 -select /* TPC-DS query61.tpl 0.97 */ promotions,total,cast(promotions as decimal(15,4))/cast(total as decimal(15,4))*100 -from - (select sum(ss_ext_sales_price) promotions - from store_sales - ,store - ,promotion - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_promo_sk = p_promo_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -7 - and i_category = 'Books' - and (p_channel_dmail = 'Y' or p_channel_email = 'Y' or p_channel_tv = 'Y') - and s_gmt_offset = -7 - and d_year = 1999 - and d_moy = 12) promotional_sales, - (select sum(ss_ext_sales_price) total - from store_sales - ,store - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -7 - and i_category = 'Books' - and s_gmt_offset = -7 - and d_year = 1999 - and d_moy = 12) all_sales -order by promotions, total -limit 100; - --- end template query61.tpl query 50 in stream 6 --- start template query3.tpl query 51 in stream 6 -select /* TPC-DS query3.tpl 0.45 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_sales_price) sum_agg - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manufact_id = 1000 - and dt.d_moy=12 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,sum_agg desc - ,brand_id - limit 100; - --- end template query3.tpl query 51 in stream 6 --- start template query41.tpl query 52 in stream 6 -select /* TPC-DS query41.tpl 0.62 */ distinct(i_product_name) - from item i1 - where i_manufact_id between 755 and 755+40 - and (select count(*) as item_cnt - from item - where (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'lime' or i_color = 'pink') and - (i_units = 'Oz' or i_units = 'Ton') and - (i_size = 'economy' or i_size = 'medium') - ) or - (i_category = 'Women' and - (i_color = 'blue' or i_color = 'papaya') and - (i_units = 'Bundle' or i_units = 'N/A') and - (i_size = 'extra large' or i_size = 'small') - ) or - (i_category = 'Men' and - (i_color = 'light' or i_color = 'blush') and - (i_units = 'Carton' or i_units = 'Cup') and - (i_size = 'petite' or i_size = 'large') - ) or - (i_category = 'Men' and - (i_color = 'lace' or i_color = 'bisque') and - (i_units = 'Each' or i_units = 'Tsp') and - (i_size = 'economy' or i_size = 'medium') - ))) or - (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'antique' or i_color = 'ghost') and - (i_units = 'Tbl' or i_units = 'Unknown') and - (i_size = 'economy' or i_size = 'medium') - ) or - (i_category = 'Women' and - (i_color = 'goldenrod' or i_color = 'navy') and - (i_units = 'Case' or i_units = 'Lb') and - (i_size = 'extra large' or i_size = 'small') - ) or - (i_category = 'Men' and - (i_color = 'magenta' or i_color = 'red') and - (i_units = 'Gross' or i_units = 'Pound') and - (i_size = 'petite' or i_size = 'large') - ) or - (i_category = 'Men' and - (i_color = 'maroon' or i_color = 'mint') and - (i_units = 'Bunch' or i_units = 'Pallet') and - (i_size = 'economy' or i_size = 'medium') - )))) > 0 - order by i_product_name - limit 100; - --- end template query41.tpl query 52 in stream 6 --- start template query54.tpl query 53 in stream 6 -with /* TPC-DS query54.tpl 0.81 */ my_customers as ( - select distinct c_customer_sk - , c_current_addr_sk - from - ( select cs_sold_date_sk sold_date_sk, - cs_bill_customer_sk customer_sk, - cs_item_sk item_sk - from catalog_sales - union all - select ws_sold_date_sk sold_date_sk, - ws_bill_customer_sk customer_sk, - ws_item_sk item_sk - from web_sales - ) cs_or_ws_sales, - item, - date_dim, - customer - where sold_date_sk = d_date_sk - and item_sk = i_item_sk - and i_category = 'Shoes' - and i_class = 'womens' - and c_customer_sk = cs_or_ws_sales.customer_sk - and d_moy = 2 - and d_year = 2000 - ) - , my_revenue as ( - select c_customer_sk, - sum(ss_ext_sales_price) as revenue - from my_customers, - store_sales, - customer_address, - store, - date_dim - where c_current_addr_sk = ca_address_sk - and ca_county = s_county - and ca_state = s_state - and ss_sold_date_sk = d_date_sk - and c_customer_sk = ss_customer_sk - and d_month_seq between (select distinct d_month_seq+1 - from date_dim where d_year = 2000 and d_moy = 2) - and (select distinct d_month_seq+3 - from date_dim where d_year = 2000 and d_moy = 2) - group by c_customer_sk - ) - , segments as - (select cast((revenue/50) as bigint) as segment - from my_revenue - ) - select segment, count(*) as num_customers, segment*50 as segment_base - from segments - group by segment - order by segment, num_customers - limit 100; - --- end template query54.tpl query 53 in stream 6 --- start template query67a.tpl query 54 in stream 6 -with /* TPC-DS query67a.tpl 0.35 */ results as -( select i_category ,i_class ,i_brand ,i_product_name ,d_year ,d_qoy ,d_moy ,s_store_id - ,sum(coalesce(ss_sales_price*ss_quantity,0)) sumsales - from store_sales ,date_dim ,store ,item - where ss_sold_date_sk=d_date_sk - and ss_item_sk=i_item_sk - and ss_store_sk = s_store_sk - and d_month_seq between 1215 and 1215 + 11 - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy,s_store_id) - , - results_rollup as - (select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, s_store_id, sumsales - from results - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy - union all - select i_category, i_class, i_brand, i_product_name, d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year - union all - select i_category, i_class, i_brand, i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name - union all - select i_category, i_class, i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand - union all - select i_category, i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class - union all - select i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category - union all - select null i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results) - - select * -from (select i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rank() over (partition by i_category order by sumsales desc) rk - from results_rollup) dw2 -where rk <= 100 -order by i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rk -limit 100; - --- end template query67a.tpl query 54 in stream 6 --- start template query77a.tpl query 55 in stream 6 -with /* TPC-DS query77a.tpl 0.78 */ ss as - (select s_store_sk, - sum(ss_ext_sales_price) as sales, - sum(ss_net_profit) as profit - from store_sales, - date_dim, - store - where ss_sold_date_sk = d_date_sk - and d_date between cast('1999-08-23' as date) - and dateadd(day,30,cast('1999-08-23' as date)) - and ss_store_sk = s_store_sk - group by s_store_sk) - , - sr as - (select s_store_sk, - sum(sr_return_amt) as returns, - sum(sr_net_loss) as profit_loss - from store_returns, - date_dim, - store - where sr_returned_date_sk = d_date_sk - and d_date between cast('1999-08-23' as date) - and dateadd(day,30,cast('1999-08-23' as date)) - and sr_store_sk = s_store_sk - group by s_store_sk), - cs as - (select cs_call_center_sk, - sum(cs_ext_sales_price) as sales, - sum(cs_net_profit) as profit - from catalog_sales, - date_dim - where cs_sold_date_sk = d_date_sk - and d_date between cast('1999-08-23' as date) - and dateadd(day,30,cast('1999-08-23' as date)) - group by cs_call_center_sk - ), - cr as - (select cr_call_center_sk, - sum(cr_return_amount) as returns, - sum(cr_net_loss) as profit_loss - from catalog_returns, - date_dim - where cr_returned_date_sk = d_date_sk - and d_date between cast('1999-08-23' as date) - and dateadd(day,30,cast('1999-08-23' as date)) - group by cr_call_center_sk), - ws as - ( select wp_web_page_sk, - sum(ws_ext_sales_price) as sales, - sum(ws_net_profit) as profit - from web_sales, - date_dim, - web_page - where ws_sold_date_sk = d_date_sk - and d_date between cast('1999-08-23' as date) - and dateadd(day,30,cast('1999-08-23' as date)) - and ws_web_page_sk = wp_web_page_sk - group by wp_web_page_sk), - wr as - (select wp_web_page_sk, - sum(wr_return_amt) as returns, - sum(wr_net_loss) as profit_loss - from web_returns, - date_dim, - web_page - where wr_returned_date_sk = d_date_sk - and d_date between cast('1999-08-23' as date) - and dateadd(day,30,cast('1999-08-23' as date)) - and wr_web_page_sk = wp_web_page_sk - group by wp_web_page_sk) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , ss.s_store_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ss left join sr - on ss.s_store_sk = sr.s_store_sk - union all - select 'catalog channel' as channel - , cs_call_center_sk as id - , sales - , returns - , (profit - profit_loss) as profit - from cs - , cr - union all - select 'web channel' as channel - , ws.wp_web_page_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ws left join wr - on ws.wp_web_page_sk = wr.wp_web_page_sk - ) x - group by channel, id ) - - select * - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results -) foo -order by channel, id - limit 100; - --- end template query77a.tpl query 55 in stream 6 --- start template query15.tpl query 56 in stream 6 -select /* TPC-DS query15.tpl 0.57 */ ca_zip - ,sum(cs_sales_price) - from catalog_sales - ,customer - ,customer_address - ,date_dim - where cs_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', - '85392', '85460', '80348', '81792') - or ca_state in ('CA','WA','GA') - or cs_sales_price > 500) - and cs_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 1999 - group by ca_zip - order by ca_zip - limit 100; - --- end template query15.tpl query 56 in stream 6 --- start template query51.tpl query 57 in stream 6 -WITH /* TPC-DS query51.tpl 0.46 */ web_v1 as ( -select - ws_item_sk item_sk, d_date, - sum(sum(ws_sales_price)) - over (partition by ws_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from web_sales - ,date_dim -where ws_sold_date_sk=d_date_sk - and d_month_seq between 1223 and 1223+11 - and ws_item_sk is not NULL -group by ws_item_sk, d_date), -store_v1 as ( -select - ss_item_sk item_sk, d_date, - sum(sum(ss_sales_price)) - over (partition by ss_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from store_sales - ,date_dim -where ss_sold_date_sk=d_date_sk - and d_month_seq between 1223 and 1223+11 - and ss_item_sk is not NULL -group by ss_item_sk, d_date) - select * -from (select item_sk - ,d_date - ,web_sales - ,store_sales - ,max(web_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) web_cumulative - ,max(store_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) store_cumulative - from (select case when web.item_sk is not null then web.item_sk else store.item_sk end item_sk - ,case when web.d_date is not null then web.d_date else store.d_date end d_date - ,web.cume_sales web_sales - ,store.cume_sales store_sales - from web_v1 web full outer join store_v1 store on (web.item_sk = store.item_sk - and web.d_date = store.d_date) - )x )y -where web_cumulative > store_cumulative -order by item_sk - ,d_date -limit 100; - --- end template query51.tpl query 57 in stream 6 --- start template query98.tpl query 58 in stream 6 -select /* TPC-DS query98.tpl 0.32 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ss_ext_sales_price) as itemrevenue - ,sum(ss_ext_sales_price)*100/sum(sum(ss_ext_sales_price)) over - (partition by i_class) as revenueratio -from - store_sales - ,item - ,date_dim -where - ss_item_sk = i_item_sk - and i_category in ('Music', 'Electronics', 'Jewelry') - and ss_sold_date_sk = d_date_sk - and d_date between cast('2001-05-12' as date) - and dateadd(day,30,cast('2001-05-12' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio; - --- end template query98.tpl query 58 in stream 6 --- start template query62.tpl query 59 in stream 6 -select /* TPC-DS query62.tpl 0.24 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 30) and - (ws_ship_date_sk - ws_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 60) and - (ws_ship_date_sk - ws_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 90) and - (ws_ship_date_sk - ws_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - web_sales - ,warehouse - ,ship_mode - ,web_site - ,date_dim -where - d_month_seq between 1207 and 1207 + 11 -and ws_ship_date_sk = d_date_sk -and ws_warehouse_sk = w_warehouse_sk -and ws_ship_mode_sk = sm_ship_mode_sk -and ws_web_site_sk = web_site_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -limit 100; - --- end template query62.tpl query 59 in stream 6 --- start template query97.tpl query 60 in stream 6 -with /* TPC-DS query97.tpl 0.38 */ ssci as ( -select ss_customer_sk customer_sk - ,ss_item_sk item_sk -from store_sales,date_dim -where ss_sold_date_sk = d_date_sk - and d_month_seq between 1184 and 1184 + 11 -group by ss_customer_sk - ,ss_item_sk), -csci as( - select cs_bill_customer_sk customer_sk - ,cs_item_sk item_sk -from catalog_sales,date_dim -where cs_sold_date_sk = d_date_sk - and d_month_seq between 1184 and 1184 + 11 -group by cs_bill_customer_sk - ,cs_item_sk) - select sum(case when ssci.customer_sk is not null and csci.customer_sk is null then 1 else 0 end) store_only - ,sum(case when ssci.customer_sk is null and csci.customer_sk is not null then 1 else 0 end) catalog_only - ,sum(case when ssci.customer_sk is not null and csci.customer_sk is not null then 1 else 0 end) store_and_catalog -from ssci full outer join csci on (ssci.customer_sk=csci.customer_sk - and ssci.item_sk = csci.item_sk) -limit 100; - --- end template query97.tpl query 60 in stream 6 --- start template query22a.tpl query 61 in stream 6 -with /* TPC-DS query22a.tpl 0.55 */ results as -(select i_product_name - ,i_brand - ,i_class - ,i_category - ,avg(inv_quantity_on_hand) qoh - from inventory - ,date_dim - ,item --- ,warehouse - where inv_date_sk=d_date_sk - and inv_item_sk=i_item_sk --- and inv_warehouse_sk = w_warehouse_sk - and d_month_seq between 1179 and 1179 + 11 - group by i_product_name,i_brand,i_class,i_category), -results_rollup as -(select i_product_name, i_brand, i_class, i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class,i_category -union all -select i_product_name, i_brand, i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class -union all -select i_product_name, i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand -union all -select i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name -union all -select null i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results) - select i_product_name, i_brand, i_class, i_category,qoh - from results_rollup - order by qoh, i_product_name, i_brand, i_class, i_category -limit 100; - --- end template query22a.tpl query 61 in stream 6 --- start template query48.tpl query 62 in stream 6 -select /* TPC-DS query48.tpl 0.74 */ sum (ss_quantity) - from store_sales, store, customer_demographics, customer_address, date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2000 - and - ( - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'D' - and - cd_education_status = 'Primary' - and - ss_sales_price between 100.00 and 150.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'M' - and - cd_education_status = '2 yr Degree' - and - ss_sales_price between 50.00 and 100.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'U' - and - cd_education_status = '4 yr Degree' - and - ss_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('IN', 'WY', 'KY') - and ss_net_profit between 0 and 2000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('MI', 'NY', 'WI') - and ss_net_profit between 150 and 3000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('UT', 'TX', 'LA') - and ss_net_profit between 50 and 25000 - ) - ) -; - --- end template query48.tpl query 62 in stream 6 --- start template query2.tpl query 63 in stream 6 -with /* TPC-DS query2.tpl 0.84 */ wscs as - (select sold_date_sk - ,sales_price - from (select ws_sold_date_sk sold_date_sk - ,ws_ext_sales_price sales_price - from web_sales - union all - select cs_sold_date_sk sold_date_sk - ,cs_ext_sales_price sales_price - from catalog_sales)), - wswscs as - (select d_week_seq, - sum(case when (d_day_name='Sunday') then sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then sales_price else null end) sat_sales - from wscs - ,date_dim - where d_date_sk = sold_date_sk - group by d_week_seq) - select d_week_seq1 - ,round(sun_sales1/sun_sales2,2) - ,round(mon_sales1/mon_sales2,2) - ,round(tue_sales1/tue_sales2,2) - ,round(wed_sales1/wed_sales2,2) - ,round(thu_sales1/thu_sales2,2) - ,round(fri_sales1/fri_sales2,2) - ,round(sat_sales1/sat_sales2,2) - from - (select wswscs.d_week_seq d_week_seq1 - ,sun_sales sun_sales1 - ,mon_sales mon_sales1 - ,tue_sales tue_sales1 - ,wed_sales wed_sales1 - ,thu_sales thu_sales1 - ,fri_sales fri_sales1 - ,sat_sales sat_sales1 - from wswscs,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 2001) y, - (select wswscs.d_week_seq d_week_seq2 - ,sun_sales sun_sales2 - ,mon_sales mon_sales2 - ,tue_sales tue_sales2 - ,wed_sales wed_sales2 - ,thu_sales thu_sales2 - ,fri_sales fri_sales2 - ,sat_sales sat_sales2 - from wswscs - ,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 2001+1) z - where d_week_seq1=d_week_seq2-53 - order by d_week_seq1; - --- end template query2.tpl query 63 in stream 6 --- start template query79.tpl query 64 in stream 6 -select /* TPC-DS query79.tpl 0.89 */ - c_last_name,c_first_name,substring(s_city,1,30),ss_ticket_number,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,store.s_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (household_demographics.hd_dep_count = 3 or household_demographics.hd_vehicle_count > 0) - and date_dim.d_dow = 1 - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_number_employees between 200 and 295 - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,store.s_city) ms,customer - where ss_customer_sk = c_customer_sk - order by c_last_name,c_first_name,substring(s_city,1,30), profit -limit 100; - --- end template query79.tpl query 64 in stream 6 --- start template query56.tpl query 65 in stream 6 -with /* TPC-DS query56.tpl 0.83 */ ss as ( - select i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where i_item_id in (select - i_item_id -from item -where i_color in ('sandy','chartreuse','beige')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 7 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -8 - group by i_item_id), - cs as ( - select i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('sandy','chartreuse','beige')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 7 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -8 - group by i_item_id), - ws as ( - select i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('sandy','chartreuse','beige')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 7 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -8 - group by i_item_id) - select i_item_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by total_sales, - i_item_id - limit 100; - --- end template query56.tpl query 65 in stream 6 --- start template query37.tpl query 66 in stream 6 -select /* TPC-DS query37.tpl 0.31 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, catalog_sales - where i_current_price between 47 and 47 + 30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('2002-05-16' as date) and dateadd(day,60,cast('2002-05-16' as date)) - and i_manufact_id in (797,818,982,952) - and inv_quantity_on_hand between 100 and 500 - and cs_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query37.tpl query 66 in stream 6 --- start template query10.tpl query 67 in stream 6 -select /* TPC-DS query10.tpl 0.26 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3, - cd_dep_count, - count(*) cnt4, - cd_dep_employed_count, - count(*) cnt5, - cd_dep_college_count, - count(*) cnt6 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_county in ('Grand Isle County','Liberty County','Montcalm County','Randall County','Pottawattamie County') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 3 and 3+3) and - (exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 3 ANd 3+3) or - exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 3 and 3+3)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count -limit 100; - --- end template query10.tpl query 67 in stream 6 --- start template query90.tpl query 68 in stream 6 -select /* TPC-DS query90.tpl 0.40 */ cast(amc as decimal(15,4))/cast(pmc as decimal(15,4)) am_pm_ratio - from ( select count(*) amc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 7 and 7+1 - and household_demographics.hd_dep_count = 3 - and web_page.wp_char_count between 5000 and 5200) at, - ( select count(*) pmc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 18 and 18+1 - and household_demographics.hd_dep_count = 3 - and web_page.wp_char_count between 5000 and 5200) pt - order by am_pm_ratio - limit 100; - --- end template query90.tpl query 68 in stream 6 --- start template query21.tpl query 69 in stream 6 -select /* TPC-DS query21.tpl 0.14 */ * - from(select w_warehouse_name - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('1999-05-08' as date)) - then inv_quantity_on_hand - else 0 end) as inv_before - ,sum(case when (cast(d_date as date) >= cast ('1999-05-08' as date)) - then inv_quantity_on_hand - else 0 end) as inv_after - from inventory - ,warehouse - ,item - ,date_dim - where i_current_price between 0.99 and 1.49 - and i_item_sk = inv_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('1999-05-08' as date)) - and dateadd(day,30,cast ('1999-05-08' as date)) - group by w_warehouse_name, i_item_id) x - where (case when inv_before > 0 - then inv_after / inv_before - else null - end) between 2.0/3.0 and 3.0/2.0 - order by w_warehouse_name - ,i_item_id - limit 100; - --- end template query21.tpl query 69 in stream 6 --- start template query46.tpl query 70 in stream 6 -select /* TPC-DS query46.tpl 0.23 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and (household_demographics.hd_dep_count = 1 or - household_demographics.hd_vehicle_count= 2) - and date_dim.d_dow in (6,0) - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_city in ('Franklin','Shady Grove','Spring Hill','Spring Valley','Midway') - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,ca_city) dn,customer,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - limit 100; - --- end template query46.tpl query 70 in stream 6 --- start template query83.tpl query 71 in stream 6 -with /* TPC-DS query83.tpl 0.96 */ sr_items as - (select i_item_id item_id, - sum(sr_return_quantity) sr_item_qty - from store_returns, - item, - date_dim - where sr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2001-05-08','2001-10-08','2001-11-14'))) - and sr_returned_date_sk = d_date_sk - group by i_item_id), - cr_items as - (select i_item_id item_id, - sum(cr_return_quantity) cr_item_qty - from catalog_returns, - item, - date_dim - where cr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2001-05-08','2001-10-08','2001-11-14'))) - and cr_returned_date_sk = d_date_sk - group by i_item_id), - wr_items as - (select i_item_id item_id, - sum(wr_return_quantity) wr_item_qty - from web_returns, - item, - date_dim - where wr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2001-05-08','2001-10-08','2001-11-14'))) - and wr_returned_date_sk = d_date_sk - group by i_item_id) - select sr_items.item_id - ,sr_item_qty - ,sr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 sr_dev - ,cr_item_qty - ,cr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 cr_dev - ,wr_item_qty - ,wr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 wr_dev - ,(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 average - from sr_items - ,cr_items - ,wr_items - where sr_items.item_id=cr_items.item_id - and sr_items.item_id=wr_items.item_id - order by sr_items.item_id - ,sr_item_qty - limit 100; - --- end template query83.tpl query 71 in stream 6 --- start template query96.tpl query 72 in stream 6 -select /* TPC-DS query96.tpl 0.1 */ count(*) -from store_sales - ,household_demographics - ,time_dim, store -where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and household_demographics.hd_dep_count = 6 - and store.s_store_name = 'ese' -order by count(*) -limit 100; - --- end template query96.tpl query 72 in stream 6 --- start template query68.tpl query 73 in stream 6 -select /* TPC-DS query68.tpl 0.95 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,extended_price - ,extended_tax - ,list_price - from (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_ext_sales_price) extended_price - ,sum(ss_ext_list_price) list_price - ,sum(ss_ext_tax) extended_tax - from store_sales - ,date_dim - ,store - ,household_demographics - ,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_dep_count = 9 or - household_demographics.hd_vehicle_count= 3) - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_city in ('Stringtown','Midway') - group by ss_ticket_number - ,ss_customer_sk - ,ss_addr_sk,ca_city) dn - ,customer - ,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,ss_ticket_number - limit 100; - --- end template query68.tpl query 73 in stream 6 --- start template query63.tpl query 74 in stream 6 -select /* TPC-DS query63.tpl 0.27 */ * -from (select i_manager_id - ,sum(ss_sales_price) sum_sales - ,avg(sum(ss_sales_price)) over (partition by i_manager_id) avg_monthly_sales - from item - ,store_sales - ,date_dim - ,store - where ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and d_month_seq in (1198,1198+1,1198+2,1198+3,1198+4,1198+5,1198+6,1198+7,1198+8,1198+9,1198+10,1198+11) - and (( i_category in ('Books','Children','Electronics') - and i_class in ('personal','portable','reference','self-help') - and i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) - or( i_category in ('Women','Music','Men') - and i_class in ('accessories','classical','fragrances','pants') - and i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manager_id, d_moy) tmp1 -where case when avg_monthly_sales > 0 then abs (sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 -order by i_manager_id - ,avg_monthly_sales - ,sum_sales -limit 100; - --- end template query63.tpl query 74 in stream 6 --- start template query92.tpl query 75 in stream 6 -select /* TPC-DS query92.tpl 0.44 */ - sum(ws_ext_discount_amt) as "Excess Discount Amount" -from - web_sales - ,item - ,date_dim -where -i_manufact_id = 835 -and i_item_sk = ws_item_sk -and d_date between '2000-02-06' and - dateadd(day,90,cast('2000-02-06' as date)) -and d_date_sk = ws_sold_date_sk -and ws_ext_discount_amt - > ( - SELECT - 1.3 * avg(ws_ext_discount_amt) - FROM - web_sales - ,date_dim - WHERE - ws_item_sk = i_item_sk - and d_date between '2000-02-06' and - dateadd(day,90,cast('2000-02-06' as date)) - and d_date_sk = ws_sold_date_sk - ) -order by sum(ws_ext_discount_amt) -limit 100; - --- end template query92.tpl query 75 in stream 6 --- start template query27a.tpl query 76 in stream 6 -with /* TPC-DS query27a.tpl 0.16 */ results as - (select i_item_id, - s_state, 0 as g_state, - ss_quantity agg1, - ss_list_price agg2, - ss_coupon_amt agg3, - ss_sales_price agg4 - from store_sales, customer_demographics, date_dim, store, item - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_store_sk = s_store_sk and - ss_cdemo_sk = cd_demo_sk and - cd_gender = 'F' and - cd_marital_status = 'M' and - cd_education_status = '4 yr Degree' and - d_year = 2001 and - s_state in ('AL','SC', 'GA', 'NM', 'LA', 'LA') - ) - - select i_item_id, - s_state, g_state, agg1, agg2, agg3, agg4 - from ( - select i_item_id, s_state, 0 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4 from results - group by i_item_id, s_state - union all - select i_item_id, NULL AS s_state, 1 AS g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as s_state, 1 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - ) foo - order by i_item_id, s_state - limit 100; - --- end template query27a.tpl query 76 in stream 6 --- start template query12.tpl query 77 in stream 6 -select /* TPC-DS query12.tpl 0.64 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ws_ext_sales_price) as itemrevenue - ,sum(ws_ext_sales_price)*100/sum(sum(ws_ext_sales_price)) over - (partition by i_class) as revenueratio -from - web_sales - ,item - ,date_dim -where - ws_item_sk = i_item_sk - and i_category in ('Jewelry', 'Electronics', 'Shoes') - and ws_sold_date_sk = d_date_sk - and d_date between cast('2001-04-17' as date) - and dateadd(day,30,cast('2001-04-17' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query12.tpl query 77 in stream 6 --- start template query64.tpl query 78 in stream 6 -with /* TPC-DS query64.tpl 0.20 */ cs_ui as - (select cs_item_sk - ,sum(cs_ext_list_price) as sale,sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit) as refund - from catalog_sales - ,catalog_returns - where cs_item_sk = cr_item_sk - and cs_order_number = cr_order_number - group by cs_item_sk - having sum(cs_ext_list_price)>2*sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit)), -cross_sales as - (select i_product_name product_name - ,i_item_sk item_sk - ,s_store_name store_name - ,s_zip store_zip - ,ad1.ca_street_number b_street_number - ,ad1.ca_street_name b_street_name - ,ad1.ca_city b_city - ,ad1.ca_zip b_zip - ,ad2.ca_street_number c_street_number - ,ad2.ca_street_name c_street_name - ,ad2.ca_city c_city - ,ad2.ca_zip c_zip - ,d1.d_year as syear - ,d2.d_year as fsyear - ,d3.d_year s2year - ,count(*) cnt - ,sum(ss_wholesale_cost) s1 - ,sum(ss_list_price) s2 - ,sum(ss_coupon_amt) s3 - FROM store_sales - ,store_returns - ,cs_ui - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,customer - ,customer_demographics cd1 - ,customer_demographics cd2 - ,promotion - ,household_demographics hd1 - ,household_demographics hd2 - ,customer_address ad1 - ,customer_address ad2 - ,income_band ib1 - ,income_band ib2 - ,item - WHERE ss_store_sk = s_store_sk AND - ss_sold_date_sk = d1.d_date_sk AND - ss_customer_sk = c_customer_sk AND - ss_cdemo_sk= cd1.cd_demo_sk AND - ss_hdemo_sk = hd1.hd_demo_sk AND - ss_addr_sk = ad1.ca_address_sk and - ss_item_sk = i_item_sk and - ss_item_sk = sr_item_sk and - ss_ticket_number = sr_ticket_number and - ss_item_sk = cs_ui.cs_item_sk and - c_current_cdemo_sk = cd2.cd_demo_sk AND - c_current_hdemo_sk = hd2.hd_demo_sk AND - c_current_addr_sk = ad2.ca_address_sk and - c_first_sales_date_sk = d2.d_date_sk and - c_first_shipto_date_sk = d3.d_date_sk and - ss_promo_sk = p_promo_sk and - hd1.hd_income_band_sk = ib1.ib_income_band_sk and - hd2.hd_income_band_sk = ib2.ib_income_band_sk and - cd1.cd_marital_status <> cd2.cd_marital_status and - i_color in ('gainsboro','frosted','peach','wheat','purple','brown') and - i_current_price between 66 and 66 + 10 and - i_current_price between 66 + 1 and 66 + 15 -group by i_product_name - ,i_item_sk - ,s_store_name - ,s_zip - ,ad1.ca_street_number - ,ad1.ca_street_name - ,ad1.ca_city - ,ad1.ca_zip - ,ad2.ca_street_number - ,ad2.ca_street_name - ,ad2.ca_city - ,ad2.ca_zip - ,d1.d_year - ,d2.d_year - ,d3.d_year -) -select cs1.product_name - ,cs1.store_name - ,cs1.store_zip - ,cs1.b_street_number - ,cs1.b_street_name - ,cs1.b_city - ,cs1.b_zip - ,cs1.c_street_number - ,cs1.c_street_name - ,cs1.c_city - ,cs1.c_zip - ,cs1.syear - ,cs1.cnt - ,cs1.s1 as s11 - ,cs1.s2 as s21 - ,cs1.s3 as s31 - ,cs2.s1 as s12 - ,cs2.s2 as s22 - ,cs2.s3 as s32 - ,cs2.syear - ,cs2.cnt -from cross_sales cs1,cross_sales cs2 -where cs1.item_sk=cs2.item_sk and - cs1.syear = 1999 and - cs2.syear = 1999 + 1 and - cs2.cnt <= cs1.cnt and - cs1.store_name = cs2.store_name and - cs1.store_zip = cs2.store_zip -order by cs1.product_name - ,cs1.store_name - ,cs2.cnt - ,cs1.s1 - ,cs2.s1; - --- end template query64.tpl query 78 in stream 6 --- start template query95.tpl query 79 in stream 6 -with /* TPC-DS query95.tpl 0.43 */ ws_wh as -(select ws1.ws_order_number,ws1.ws_warehouse_sk wh1,ws2.ws_warehouse_sk wh2 - from web_sales ws1,web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) - select - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2001-2-01' and - dateadd(day,60,cast('2001-2-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'AK' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and ws1.ws_order_number in (select ws_order_number - from ws_wh) -and ws1.ws_order_number in (select wr_order_number - from web_returns,ws_wh - where wr_order_number = ws_wh.ws_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query95.tpl query 79 in stream 6 --- start template query39.tpl query 80 in stream 6 -with /* TPC-DS query39.tpl 0.5 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =2001 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=4 - and inv2.d_moy=4+1 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; -with /* TPC-DS query39.tpl 0.5 part2 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =2001 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=4 - and inv2.d_moy=4+1 - and inv1.cov > 1.5 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; - --- end template query39.tpl query 80 in stream 6 --- start template query35a.tpl query 81 in stream 6 -select /* TPC-DS query35a.tpl 0.47 */ - ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - count(*) cnt1, - sum(cd_dep_count), - sum(cd_dep_count), - stddev_samp(cd_dep_count), - cd_dep_employed_count, - count(*) cnt2, - sum(cd_dep_employed_count), - sum(cd_dep_employed_count), - stddev_samp(cd_dep_employed_count), - cd_dep_college_count, - count(*) cnt3, - sum(cd_dep_college_count), - sum(cd_dep_college_count), - stddev_samp(cd_dep_college_count) - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2000 and - d_qoy < 4) and - exists (select * from - (select ws_bill_customer_sk customsk - from web_sales,date_dim - where - ws_sold_date_sk = d_date_sk and - d_year = 2000 and - d_qoy < 4 - union all - select cs_ship_customer_sk customsk - from catalog_sales,date_dim - where - cs_sold_date_sk = d_date_sk and - d_year = 2000 and - d_qoy < 4)x - where x.customsk = c.c_customer_sk) - group by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - limit 100; - --- end template query35a.tpl query 81 in stream 6 --- start template query78.tpl query 82 in stream 6 -with /* TPC-DS query78.tpl 0.10 */ ws as - (select d_year AS ws_sold_year, ws_item_sk, - ws_bill_customer_sk ws_customer_sk, - sum(ws_quantity) ws_qty, - sum(ws_wholesale_cost) ws_wc, - sum(ws_sales_price) ws_sp - from web_sales - left join web_returns on wr_order_number=ws_order_number and ws_item_sk=wr_item_sk - join date_dim on ws_sold_date_sk = d_date_sk - where wr_order_number is null - group by d_year, ws_item_sk, ws_bill_customer_sk - ), -cs as - (select d_year AS cs_sold_year, cs_item_sk, - cs_bill_customer_sk cs_customer_sk, - sum(cs_quantity) cs_qty, - sum(cs_wholesale_cost) cs_wc, - sum(cs_sales_price) cs_sp - from catalog_sales - left join catalog_returns on cr_order_number=cs_order_number and cs_item_sk=cr_item_sk - join date_dim on cs_sold_date_sk = d_date_sk - where cr_order_number is null - group by d_year, cs_item_sk, cs_bill_customer_sk - ), -ss as - (select d_year AS ss_sold_year, ss_item_sk, - ss_customer_sk, - sum(ss_quantity) ss_qty, - sum(ss_wholesale_cost) ss_wc, - sum(ss_sales_price) ss_sp - from store_sales - left join store_returns on sr_ticket_number=ss_ticket_number and ss_item_sk=sr_item_sk - join date_dim on ss_sold_date_sk = d_date_sk - where sr_ticket_number is null - group by d_year, ss_item_sk, ss_customer_sk - ) - select -ss_sold_year, ss_item_sk, ss_customer_sk, -round(ss_qty/(coalesce(ws_qty,0)+coalesce(cs_qty,0)),2) ratio, -ss_qty store_qty, ss_wc store_wholesale_cost, ss_sp store_sales_price, -coalesce(ws_qty,0)+coalesce(cs_qty,0) other_chan_qty, -coalesce(ws_wc,0)+coalesce(cs_wc,0) other_chan_wholesale_cost, -coalesce(ws_sp,0)+coalesce(cs_sp,0) other_chan_sales_price -from ss -left join ws on (ws_sold_year=ss_sold_year and ws_item_sk=ss_item_sk and ws_customer_sk=ss_customer_sk) -left join cs on (cs_sold_year=ss_sold_year and cs_item_sk=ss_item_sk and cs_customer_sk=ss_customer_sk) -where (coalesce(ws_qty,0)>0 or coalesce(cs_qty, 0)>0) and ss_sold_year=1999 -order by - ss_sold_year, ss_item_sk, ss_customer_sk, - ss_qty desc, ss_wc desc, ss_sp desc, - other_chan_qty, - other_chan_wholesale_cost, - other_chan_sales_price, - ratio -limit 100; - --- end template query78.tpl query 82 in stream 6 --- start template query57.tpl query 83 in stream 6 -with /* TPC-DS query57.tpl 0.70 */ v1 as( - select i_category, i_brand, - cc_name, - d_year, d_moy, - sum(cs_sales_price) sum_sales, - avg(sum(cs_sales_price)) over - (partition by i_category, i_brand, - cc_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - cc_name - order by d_year, d_moy) rn - from item, catalog_sales, date_dim, call_center - where cs_item_sk = i_item_sk and - cs_sold_date_sk = d_date_sk and - cc_call_center_sk= cs_call_center_sk and - ( - d_year = 2001 or - ( d_year = 2001-1 and d_moy =12) or - ( d_year = 2001+1 and d_moy =1) - ) - group by i_category, i_brand, - cc_name , d_year, d_moy), - v2 as( - select v1.i_brand - ,v1.d_year - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1. cc_name = v1_lag. cc_name and - v1. cc_name = v1_lead. cc_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 2001 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, psum - limit 100; - --- end template query57.tpl query 83 in stream 6 --- start template query66.tpl query 84 in stream 6 -select /* TPC-DS query66.tpl 0.39 */ - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - ,sum(jan_sales) as jan_sales - ,sum(feb_sales) as feb_sales - ,sum(mar_sales) as mar_sales - ,sum(apr_sales) as apr_sales - ,sum(may_sales) as may_sales - ,sum(jun_sales) as jun_sales - ,sum(jul_sales) as jul_sales - ,sum(aug_sales) as aug_sales - ,sum(sep_sales) as sep_sales - ,sum(oct_sales) as oct_sales - ,sum(nov_sales) as nov_sales - ,sum(dec_sales) as dec_sales - ,sum(jan_sales/w_warehouse_sq_ft) as jan_sales_per_sq_foot - ,sum(feb_sales/w_warehouse_sq_ft) as feb_sales_per_sq_foot - ,sum(mar_sales/w_warehouse_sq_ft) as mar_sales_per_sq_foot - ,sum(apr_sales/w_warehouse_sq_ft) as apr_sales_per_sq_foot - ,sum(may_sales/w_warehouse_sq_ft) as may_sales_per_sq_foot - ,sum(jun_sales/w_warehouse_sq_ft) as jun_sales_per_sq_foot - ,sum(jul_sales/w_warehouse_sq_ft) as jul_sales_per_sq_foot - ,sum(aug_sales/w_warehouse_sq_ft) as aug_sales_per_sq_foot - ,sum(sep_sales/w_warehouse_sq_ft) as sep_sales_per_sq_foot - ,sum(oct_sales/w_warehouse_sq_ft) as oct_sales_per_sq_foot - ,sum(nov_sales/w_warehouse_sq_ft) as nov_sales_per_sq_foot - ,sum(dec_sales/w_warehouse_sq_ft) as dec_sales_per_sq_foot - ,sum(jan_net) as jan_net - ,sum(feb_net) as feb_net - ,sum(mar_net) as mar_net - ,sum(apr_net) as apr_net - ,sum(may_net) as may_net - ,sum(jun_net) as jun_net - ,sum(jul_net) as jul_net - ,sum(aug_net) as aug_net - ,sum(sep_net) as sep_net - ,sum(oct_net) as oct_net - ,sum(nov_net) as nov_net - ,sum(dec_net) as dec_net - from ( - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'ZHOU' || ',' || 'LATVIAN' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then ws_ext_list_price* ws_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then ws_ext_list_price* ws_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then ws_ext_list_price* ws_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then ws_ext_list_price* ws_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then ws_ext_list_price* ws_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then ws_ext_list_price* ws_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then ws_ext_list_price* ws_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then ws_ext_list_price* ws_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then ws_ext_list_price* ws_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then ws_ext_list_price* ws_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then ws_ext_list_price* ws_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then ws_ext_list_price* ws_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then ws_net_paid * ws_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then ws_net_paid * ws_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then ws_net_paid * ws_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then ws_net_paid * ws_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then ws_net_paid * ws_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then ws_net_paid * ws_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then ws_net_paid * ws_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then ws_net_paid * ws_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then ws_net_paid * ws_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then ws_net_paid * ws_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then ws_net_paid * ws_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then ws_net_paid * ws_quantity else 0 end) as dec_net - from - web_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - ws_warehouse_sk = w_warehouse_sk - and ws_sold_date_sk = d_date_sk - and ws_sold_time_sk = t_time_sk - and ws_ship_mode_sk = sm_ship_mode_sk - and d_year = 2000 - and t_time between 14428 and 14428+28800 - and sm_carrier in ('ZHOU','LATVIAN') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - union all - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'ZHOU' || ',' || 'LATVIAN' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then cs_ext_list_price* cs_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then cs_ext_list_price* cs_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then cs_ext_list_price* cs_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then cs_ext_list_price* cs_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then cs_ext_list_price* cs_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then cs_ext_list_price* cs_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then cs_ext_list_price* cs_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then cs_ext_list_price* cs_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then cs_ext_list_price* cs_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then cs_ext_list_price* cs_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then cs_ext_list_price* cs_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then cs_ext_list_price* cs_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then cs_net_profit * cs_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then cs_net_profit * cs_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then cs_net_profit * cs_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then cs_net_profit * cs_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then cs_net_profit * cs_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then cs_net_profit * cs_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then cs_net_profit * cs_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then cs_net_profit * cs_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then cs_net_profit * cs_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then cs_net_profit * cs_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then cs_net_profit * cs_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then cs_net_profit * cs_quantity else 0 end) as dec_net - from - catalog_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and cs_sold_time_sk = t_time_sk - and cs_ship_mode_sk = sm_ship_mode_sk - and d_year = 2000 - and t_time between 14428 AND 14428+28800 - and sm_carrier in ('ZHOU','LATVIAN') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - ) x - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - order by w_warehouse_name - limit 100; - --- end template query66.tpl query 84 in stream 6 --- start template query71.tpl query 85 in stream 6 -select /* TPC-DS query71.tpl 0.72 */ i_brand_id brand_id, i_brand brand,t_hour,t_minute, - sum(ext_price) ext_price - from item, (select ws_ext_sales_price as ext_price, - ws_sold_date_sk as sold_date_sk, - ws_item_sk as sold_item_sk, - ws_sold_time_sk as time_sk - from web_sales,date_dim - where d_date_sk = ws_sold_date_sk - and d_moy=11 - and d_year=2000 - union all - select cs_ext_sales_price as ext_price, - cs_sold_date_sk as sold_date_sk, - cs_item_sk as sold_item_sk, - cs_sold_time_sk as time_sk - from catalog_sales,date_dim - where d_date_sk = cs_sold_date_sk - and d_moy=11 - and d_year=2000 - union all - select ss_ext_sales_price as ext_price, - ss_sold_date_sk as sold_date_sk, - ss_item_sk as sold_item_sk, - ss_sold_time_sk as time_sk - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - and d_moy=11 - and d_year=2000 - ) tmp,time_dim - where - sold_item_sk = i_item_sk - and i_manager_id=1 - and time_sk = t_time_sk - and (t_meal_time = 'breakfast' or t_meal_time = 'dinner') - group by i_brand, i_brand_id,t_hour,t_minute - order by ext_price desc, i_brand_id - ; - --- end template query71.tpl query 85 in stream 6 --- start template query30.tpl query 86 in stream 6 -with /* TPC-DS query30.tpl 0.75 */ customer_total_return as - (select wr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(wr_return_amt) as ctr_total_return - from web_returns - ,date_dim - ,customer_address - where wr_returned_date_sk = d_date_sk - and d_year =2001 - and wr_returning_addr_sk = ca_address_sk - group by wr_returning_customer_sk - ,ca_state) - select c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'KS' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return -limit 100; - --- end template query30.tpl query 86 in stream 6 --- start template query1.tpl query 87 in stream 6 -with /* TPC-DS query1.tpl 0.12 */ customer_total_return as -(select sr_customer_sk as ctr_customer_sk -,sr_store_sk as ctr_store_sk -,sum(SR_RETURN_TAX) as ctr_total_return -from store_returns -,date_dim -where sr_returned_date_sk = d_date_sk -and d_year =1998 -group by sr_customer_sk -,sr_store_sk) - select c_customer_id -from customer_total_return ctr1 -,store -,customer -where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 -from customer_total_return ctr2 -where ctr1.ctr_store_sk = ctr2.ctr_store_sk) -and s_store_sk = ctr1.ctr_store_sk -and s_state = 'NC' -and ctr1.ctr_customer_sk = c_customer_sk -order by c_customer_id -limit 100; - --- end template query1.tpl query 87 in stream 6 --- start template query81.tpl query 88 in stream 6 -with /* TPC-DS query81.tpl 0.37 */ customer_total_return as - (select cr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(cr_return_amt_inc_tax) as ctr_total_return - from catalog_returns - ,date_dim - ,customer_address - where cr_returned_date_sk = d_date_sk - and d_year =1999 - and cr_returning_addr_sk = ca_address_sk - group by cr_returning_customer_sk - ,ca_state ) - select c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'PA' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - limit 100; - --- end template query81.tpl query 88 in stream 6 --- start template query43.tpl query 89 in stream 6 -select /* TPC-DS query43.tpl 0.15 */ s_store_name, s_store_id, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from date_dim, store_sales, store - where d_date_sk = ss_sold_date_sk and - s_store_sk = ss_store_sk and - s_gmt_offset = -5 and - d_year = 1998 - group by s_store_name, s_store_id - order by s_store_name, s_store_id,sun_sales,mon_sales,tue_sales,wed_sales,thu_sales,fri_sales,sat_sales - limit 100; - --- end template query43.tpl query 89 in stream 6 --- start template query52.tpl query 90 in stream 6 -select /* TPC-DS query52.tpl 0.59 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_sales_price) ext_price - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=11 - and dt.d_year=2001 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,ext_price desc - ,brand_id -limit 100 ; - --- end template query52.tpl query 90 in stream 6 --- start template query13.tpl query 91 in stream 6 -select /* TPC-DS query13.tpl 0.91 */ avg(ss_quantity) - ,avg(ss_ext_sales_price) - ,avg(ss_ext_wholesale_cost) - ,sum(ss_ext_wholesale_cost) - from store_sales - ,store - ,customer_demographics - ,household_demographics - ,customer_address - ,date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2001 - and((ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'W' - and cd_education_status = 'Primary' - and ss_sales_price between 100.00 and 150.00 - and hd_dep_count = 3 - )or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'M' - and cd_education_status = 'College' - and ss_sales_price between 50.00 and 100.00 - and hd_dep_count = 1 - ) or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'D' - and cd_education_status = '4 yr Degree' - and ss_sales_price between 150.00 and 200.00 - and hd_dep_count = 1 - )) - and((ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('OH', 'MI', 'TX') - and ss_net_profit between 100 and 200 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('VA', 'IN', 'SC') - and ss_net_profit between 150 and 300 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('GA', 'VT', 'MO') - and ss_net_profit between 50 and 250 - )) -; - --- end template query13.tpl query 91 in stream 6 --- start template query76.tpl query 92 in stream 6 -select /* TPC-DS query76.tpl 0.99 */ channel, col_name, d_year, d_qoy, i_category, COUNT(*) sales_cnt, SUM(ext_sales_price) sales_amt FROM ( - SELECT 'store' as channel, 'ss_customer_sk' col_name, d_year, d_qoy, i_category, ss_ext_sales_price ext_sales_price - FROM store_sales, item, date_dim - WHERE ss_customer_sk IS NULL - AND ss_sold_date_sk=d_date_sk - AND ss_item_sk=i_item_sk - UNION ALL - SELECT 'web' as channel, 'ws_bill_customer_sk' col_name, d_year, d_qoy, i_category, ws_ext_sales_price ext_sales_price - FROM web_sales, item, date_dim - WHERE ws_bill_customer_sk IS NULL - AND ws_sold_date_sk=d_date_sk - AND ws_item_sk=i_item_sk - UNION ALL - SELECT 'catalog' as channel, 'cs_bill_hdemo_sk' col_name, d_year, d_qoy, i_category, cs_ext_sales_price ext_sales_price - FROM catalog_sales, item, date_dim - WHERE cs_bill_hdemo_sk IS NULL - AND cs_sold_date_sk=d_date_sk - AND cs_item_sk=i_item_sk) foo -GROUP BY channel, col_name, d_year, d_qoy, i_category -ORDER BY channel, col_name, d_year, d_qoy, i_category -limit 100; - --- end template query76.tpl query 92 in stream 6 --- start template query17.tpl query 93 in stream 6 -select /* TPC-DS query17.tpl 0.41 */ i_item_id - ,i_item_desc - ,s_state - ,count(ss_quantity) as store_sales_quantitycount - ,avg(ss_quantity) as store_sales_quantityave - ,stddev_samp(ss_quantity) as store_sales_quantitystdev - ,stddev_samp(ss_quantity)/avg(ss_quantity) as store_sales_quantitycov - ,count(sr_return_quantity) as store_returns_quantitycount - ,avg(sr_return_quantity) as store_returns_quantityave - ,stddev_samp(sr_return_quantity) as store_returns_quantitystdev - ,stddev_samp(sr_return_quantity)/avg(sr_return_quantity) as store_returns_quantitycov - ,count(cs_quantity) as catalog_sales_quantitycount ,avg(cs_quantity) as catalog_sales_quantityave - ,stddev_samp(cs_quantity) as catalog_sales_quantitystdev - ,stddev_samp(cs_quantity)/avg(cs_quantity) as catalog_sales_quantitycov - from store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where d1.d_quarter_name = '2002Q1' - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_quarter_name in ('2002Q1','2002Q2','2002Q3') - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_quarter_name in ('2002Q1','2002Q2','2002Q3') - group by i_item_id - ,i_item_desc - ,s_state - order by i_item_id - ,i_item_desc - ,s_state -limit 100; - --- end template query17.tpl query 93 in stream 6 --- start template query25.tpl query 94 in stream 6 -select /* TPC-DS query25.tpl 0.9 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,stddev_samp(ss_net_profit) as store_sales_profit - ,stddev_samp(sr_net_loss) as store_returns_loss - ,stddev_samp(cs_net_profit) as catalog_sales_profit - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 1999 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 10 - and d2.d_year = 1999 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_moy between 4 and 10 - and d3.d_year = 1999 - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query25.tpl query 94 in stream 6 --- start template query40.tpl query 95 in stream 6 -select /* TPC-DS query40.tpl 0.86 */ - w_state - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('2000-03-09' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_before - ,sum(case when (cast(d_date as date) >= cast ('2000-03-09' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_after - from - catalog_sales left outer join catalog_returns on - (cs_order_number = cr_order_number - and cs_item_sk = cr_item_sk) - ,warehouse - ,item - ,date_dim - where - i_current_price between 0.99 and 1.49 - and i_item_sk = cs_item_sk - and cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('2000-03-09' as date)) - and dateadd(day,30,cast ('2000-03-09' as date)) - group by - w_state,i_item_id - order by w_state,i_item_id -limit 100; - --- end template query40.tpl query 95 in stream 6 --- start template query70a.tpl query 96 in stream 6 -with /* TPC-DS query70a.tpl 0.34 */ results as -( select - sum(ss_net_profit) as total_sum ,s_state ,s_county, 0 as gstate, 0 as g_county - from - store_sales - ,date_dim d1 - ,store - where - d1.d_month_seq between 1188 and 1188 + 11 - and d1.d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - and s_state in - ( select s_state - from (select s_state as s_state, - rank() over ( partition by s_state order by sum(ss_net_profit) desc) as ranking - from store_sales, store, date_dim - where d_month_seq between 1188 and 1188 + 11 - and d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - group by s_state - ) tmp1 - where ranking <= 5) - group by s_state,s_county) , - results_rollup as -(select total_sum ,s_state ,s_county, 0 as g_state, 0 as g_county, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum,s_state, NULL as s_county, 0 as g_state, 1 as g_county, 1 as lochierarchy from results group by s_state - union - select sum(total_sum) as total_sum ,NULL as s_state ,NULL as s_county, 1 as g_state, 1 as g_county, 2 as lochierarchy from results) - select total_sum ,s_state ,s_county, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_county = 0 then s_state end - order by total_sum desc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then s_state end - ,rank_within_parent - limit 100; - --- end template query70a.tpl query 96 in stream 6 --- start template query55.tpl query 97 in stream 6 -select /* TPC-DS query55.tpl 0.82 */ i_brand_id brand_id, i_brand brand, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=81 - and d_moy=11 - and d_year=2000 - group by i_brand, i_brand_id - order by ext_price desc, i_brand_id -limit 100 ; - --- end template query55.tpl query 97 in stream 6 --- start template query60.tpl query 98 in stream 6 -with /* TPC-DS query60.tpl 0.29 */ ss as ( - select - i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Shoes')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 10 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - cs as ( - select - i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Shoes')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 10 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - ws as ( - select - i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Shoes')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 10 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id) - select - i_item_id -,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by i_item_id - ,total_sales - limit 100; - --- end template query60.tpl query 98 in stream 6 --- start template query16.tpl query 99 in stream 6 -select /* TPC-DS query16.tpl 0.25 */ - count(distinct cs_order_number) as "order count" - ,sum(cs_ext_ship_cost) as "total shipping cost" - ,sum(cs_net_profit) as "total net profit" -from - catalog_sales cs1 - ,date_dim - ,customer_address - ,call_center -where - d_date between '2001-2-01' and - dateadd(day, 60, cast('2001-2-01' as date)) -and cs1.cs_ship_date_sk = d_date_sk -and cs1.cs_ship_addr_sk = ca_address_sk -and ca_state = 'CO' -and cs1.cs_call_center_sk = cc_call_center_sk -and cc_county in ('Wadena County','Dauphin County','Pennington County','Walker County', - 'Marshall County' -) -and exists (select * - from catalog_sales cs2 - where cs1.cs_order_number = cs2.cs_order_number - and cs1.cs_warehouse_sk <> cs2.cs_warehouse_sk) -and not exists(select * - from catalog_returns cr1 - where cs1.cs_order_number = cr1.cr_order_number) -order by count(distinct cs_order_number) -limit 100; - --- end template query16.tpl query 99 in stream 6 diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/1TB/queries/query_7.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/1TB/queries/query_7.sql deleted file mode 100644 index 37aa8de9..00000000 --- a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/1TB/queries/query_7.sql +++ /dev/null @@ -1,5027 +0,0 @@ --- start template query70a.tpl query 1 in stream 7 -with /* TPC-DS query70a.tpl 0.34 */ results as -( select - sum(ss_net_profit) as total_sum ,s_state ,s_county, 0 as gstate, 0 as g_county - from - store_sales - ,date_dim d1 - ,store - where - d1.d_month_seq between 1193 and 1193 + 11 - and d1.d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - and s_state in - ( select s_state - from (select s_state as s_state, - rank() over ( partition by s_state order by sum(ss_net_profit) desc) as ranking - from store_sales, store, date_dim - where d_month_seq between 1193 and 1193 + 11 - and d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - group by s_state - ) tmp1 - where ranking <= 5) - group by s_state,s_county) , - results_rollup as -(select total_sum ,s_state ,s_county, 0 as g_state, 0 as g_county, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum,s_state, NULL as s_county, 0 as g_state, 1 as g_county, 1 as lochierarchy from results group by s_state - union - select sum(total_sum) as total_sum ,NULL as s_state ,NULL as s_county, 1 as g_state, 1 as g_county, 2 as lochierarchy from results) - select total_sum ,s_state ,s_county, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_county = 0 then s_state end - order by total_sum desc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then s_state end - ,rank_within_parent - limit 100; - --- end template query70a.tpl query 1 in stream 7 --- start template query53.tpl query 2 in stream 7 -select /* TPC-DS query53.tpl 0.88 */ * from -(select i_manufact_id, -sum(ss_sales_price) sum_sales, -avg(sum(ss_sales_price)) over (partition by i_manufact_id) avg_quarterly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and -ss_sold_date_sk = d_date_sk and -ss_store_sk = s_store_sk and -d_month_seq in (1222,1222+1,1222+2,1222+3,1222+4,1222+5,1222+6,1222+7,1222+8,1222+9,1222+10,1222+11) and -((i_category in ('Books','Children','Electronics') and -i_class in ('personal','portable','reference','self-help') and -i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) -or(i_category in ('Women','Music','Men') and -i_class in ('accessories','classical','fragrances','pants') and -i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manufact_id, d_qoy ) tmp1 -where case when avg_quarterly_sales > 0 - then abs (sum_sales - avg_quarterly_sales)/ avg_quarterly_sales - else null end > 0.1 -order by avg_quarterly_sales, - sum_sales, - i_manufact_id -limit 100; - --- end template query53.tpl query 2 in stream 7 --- start template query92.tpl query 3 in stream 7 -select /* TPC-DS query92.tpl 0.44 */ - sum(ws_ext_discount_amt) as "Excess Discount Amount" -from - web_sales - ,item - ,date_dim -where -i_manufact_id = 697 -and i_item_sk = ws_item_sk -and d_date between '1999-02-04' and - dateadd(day,90,cast('1999-02-04' as date)) -and d_date_sk = ws_sold_date_sk -and ws_ext_discount_amt - > ( - SELECT - 1.3 * avg(ws_ext_discount_amt) - FROM - web_sales - ,date_dim - WHERE - ws_item_sk = i_item_sk - and d_date between '1999-02-04' and - dateadd(day,90,cast('1999-02-04' as date)) - and d_date_sk = ws_sold_date_sk - ) -order by sum(ws_ext_discount_amt) -limit 100; - --- end template query92.tpl query 3 in stream 7 --- start template query99.tpl query 4 in stream 7 -select /* TPC-DS query99.tpl 0.94 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 30) and - (cs_ship_date_sk - cs_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 60) and - (cs_ship_date_sk - cs_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 90) and - (cs_ship_date_sk - cs_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - catalog_sales - ,warehouse - ,ship_mode - ,call_center - ,date_dim -where - d_month_seq between 1206 and 1206 + 11 -and cs_ship_date_sk = d_date_sk -and cs_warehouse_sk = w_warehouse_sk -and cs_ship_mode_sk = sm_ship_mode_sk -and cs_call_center_sk = cc_call_center_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -limit 100; - --- end template query99.tpl query 4 in stream 7 --- start template query31.tpl query 5 in stream 7 -with /* TPC-DS query31.tpl 0.50 */ ss as - (select ca_county,d_qoy, d_year,sum(ss_ext_sales_price) as store_sales - from store_sales,date_dim,customer_address - where ss_sold_date_sk = d_date_sk - and ss_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year), - ws as - (select ca_county,d_qoy, d_year,sum(ws_ext_sales_price) as web_sales - from web_sales,date_dim,customer_address - where ws_sold_date_sk = d_date_sk - and ws_bill_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year) - select - ss1.ca_county - ,ss1.d_year - ,ws2.web_sales/ws1.web_sales web_q1_q2_increase - ,ss2.store_sales/ss1.store_sales store_q1_q2_increase - ,ws3.web_sales/ws2.web_sales web_q2_q3_increase - ,ss3.store_sales/ss2.store_sales store_q2_q3_increase - from - ss ss1 - ,ss ss2 - ,ss ss3 - ,ws ws1 - ,ws ws2 - ,ws ws3 - where - ss1.d_qoy = 1 - and ss1.d_year = 1998 - and ss1.ca_county = ss2.ca_county - and ss2.d_qoy = 2 - and ss2.d_year = 1998 - and ss2.ca_county = ss3.ca_county - and ss3.d_qoy = 3 - and ss3.d_year = 1998 - and ss1.ca_county = ws1.ca_county - and ws1.d_qoy = 1 - and ws1.d_year = 1998 - and ws1.ca_county = ws2.ca_county - and ws2.d_qoy = 2 - and ws2.d_year = 1998 - and ws1.ca_county = ws3.ca_county - and ws3.d_qoy = 3 - and ws3.d_year =1998 - and case when ws1.web_sales > 0 then ws2.web_sales/ws1.web_sales else null end - > case when ss1.store_sales > 0 then ss2.store_sales/ss1.store_sales else null end - and case when ws2.web_sales > 0 then ws3.web_sales/ws2.web_sales else null end - > case when ss2.store_sales > 0 then ss3.store_sales/ss2.store_sales else null end - order by web_q2_q3_increase; - --- end template query31.tpl query 5 in stream 7 --- start template query39.tpl query 6 in stream 7 -with /* TPC-DS query39.tpl 0.5 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =2000 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=4 - and inv2.d_moy=4+1 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; -with /* TPC-DS query39.tpl 0.5 part2 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =2000 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=4 - and inv2.d_moy=4+1 - and inv1.cov > 1.5 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; - --- end template query39.tpl query 6 in stream 7 --- start template query29.tpl query 7 in stream 7 -select /* TPC-DS query29.tpl 0.53 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,avg(ss_quantity) as store_sales_quantity - ,avg(sr_return_quantity) as store_returns_quantity - ,avg(cs_quantity) as catalog_sales_quantity - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 2000 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 4 + 3 - and d2.d_year = 2000 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_year in (2000,2000+1,2000+2) - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query29.tpl query 7 in stream 7 --- start template query32.tpl query 8 in stream 7 -select /* TPC-DS query32.tpl 0.7 */ sum(cs_ext_discount_amt) as "excess discount amount" -from - catalog_sales - ,item - ,date_dim -where -i_manufact_id = 659 -and i_item_sk = cs_item_sk -and d_date between '2002-02-07' and - dateadd(day,90,cast('2002-02-07' as date)) -and d_date_sk = cs_sold_date_sk -and cs_ext_discount_amt - > ( - select - 1.3 * avg(cs_ext_discount_amt) - from - catalog_sales - ,date_dim - where - cs_item_sk = i_item_sk - and d_date between '2002-02-07' and - dateadd(day,90,cast('2002-02-07' as date)) - and d_date_sk = cs_sold_date_sk - ) -limit 100; - --- end template query32.tpl query 8 in stream 7 --- start template query6.tpl query 9 in stream 7 -select /* TPC-DS query6.tpl 0.58 */ a.ca_state state, count(*) cnt - from customer_address a - ,customer c - ,store_sales s - ,date_dim d - ,item i - where a.ca_address_sk = c.c_current_addr_sk - and c.c_customer_sk = s.ss_customer_sk - and s.ss_sold_date_sk = d.d_date_sk - and s.ss_item_sk = i.i_item_sk - and d.d_month_seq = - (select distinct (d_month_seq) - from date_dim - where d_year = 2000 - and d_moy = 6 ) - and i.i_current_price > 1.2 * - (select avg(j.i_current_price) - from item j - where j.i_category = i.i_category) - group by a.ca_state - having count(*) >= 10 - order by cnt, a.ca_state - limit 100; - --- end template query6.tpl query 9 in stream 7 --- start template query64.tpl query 10 in stream 7 -with /* TPC-DS query64.tpl 0.20 */ cs_ui as - (select cs_item_sk - ,sum(cs_ext_list_price) as sale,sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit) as refund - from catalog_sales - ,catalog_returns - where cs_item_sk = cr_item_sk - and cs_order_number = cr_order_number - group by cs_item_sk - having sum(cs_ext_list_price)>2*sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit)), -cross_sales as - (select i_product_name product_name - ,i_item_sk item_sk - ,s_store_name store_name - ,s_zip store_zip - ,ad1.ca_street_number b_street_number - ,ad1.ca_street_name b_street_name - ,ad1.ca_city b_city - ,ad1.ca_zip b_zip - ,ad2.ca_street_number c_street_number - ,ad2.ca_street_name c_street_name - ,ad2.ca_city c_city - ,ad2.ca_zip c_zip - ,d1.d_year as syear - ,d2.d_year as fsyear - ,d3.d_year s2year - ,count(*) cnt - ,sum(ss_wholesale_cost) s1 - ,sum(ss_list_price) s2 - ,sum(ss_coupon_amt) s3 - FROM store_sales - ,store_returns - ,cs_ui - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,customer - ,customer_demographics cd1 - ,customer_demographics cd2 - ,promotion - ,household_demographics hd1 - ,household_demographics hd2 - ,customer_address ad1 - ,customer_address ad2 - ,income_band ib1 - ,income_band ib2 - ,item - WHERE ss_store_sk = s_store_sk AND - ss_sold_date_sk = d1.d_date_sk AND - ss_customer_sk = c_customer_sk AND - ss_cdemo_sk= cd1.cd_demo_sk AND - ss_hdemo_sk = hd1.hd_demo_sk AND - ss_addr_sk = ad1.ca_address_sk and - ss_item_sk = i_item_sk and - ss_item_sk = sr_item_sk and - ss_ticket_number = sr_ticket_number and - ss_item_sk = cs_ui.cs_item_sk and - c_current_cdemo_sk = cd2.cd_demo_sk AND - c_current_hdemo_sk = hd2.hd_demo_sk AND - c_current_addr_sk = ad2.ca_address_sk and - c_first_sales_date_sk = d2.d_date_sk and - c_first_shipto_date_sk = d3.d_date_sk and - ss_promo_sk = p_promo_sk and - hd1.hd_income_band_sk = ib1.ib_income_band_sk and - hd2.hd_income_band_sk = ib2.ib_income_band_sk and - cd1.cd_marital_status <> cd2.cd_marital_status and - i_color in ('tomato','light','brown','linen','peru','coral') and - i_current_price between 7 and 7 + 10 and - i_current_price between 7 + 1 and 7 + 15 -group by i_product_name - ,i_item_sk - ,s_store_name - ,s_zip - ,ad1.ca_street_number - ,ad1.ca_street_name - ,ad1.ca_city - ,ad1.ca_zip - ,ad2.ca_street_number - ,ad2.ca_street_name - ,ad2.ca_city - ,ad2.ca_zip - ,d1.d_year - ,d2.d_year - ,d3.d_year -) -select cs1.product_name - ,cs1.store_name - ,cs1.store_zip - ,cs1.b_street_number - ,cs1.b_street_name - ,cs1.b_city - ,cs1.b_zip - ,cs1.c_street_number - ,cs1.c_street_name - ,cs1.c_city - ,cs1.c_zip - ,cs1.syear - ,cs1.cnt - ,cs1.s1 as s11 - ,cs1.s2 as s21 - ,cs1.s3 as s31 - ,cs2.s1 as s12 - ,cs2.s2 as s22 - ,cs2.s3 as s32 - ,cs2.syear - ,cs2.cnt -from cross_sales cs1,cross_sales cs2 -where cs1.item_sk=cs2.item_sk and - cs1.syear = 2000 and - cs2.syear = 2000 + 1 and - cs2.cnt <= cs1.cnt and - cs1.store_name = cs2.store_name and - cs1.store_zip = cs2.store_zip -order by cs1.product_name - ,cs1.store_name - ,cs2.cnt - ,cs1.s1 - ,cs2.s1; - --- end template query64.tpl query 10 in stream 7 --- start template query30.tpl query 11 in stream 7 -with /* TPC-DS query30.tpl 0.75 */ customer_total_return as - (select wr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(wr_return_amt) as ctr_total_return - from web_returns - ,date_dim - ,customer_address - where wr_returned_date_sk = d_date_sk - and d_year =2002 - and wr_returning_addr_sk = ca_address_sk - group by wr_returning_customer_sk - ,ca_state) - select c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'MI' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return -limit 100; - --- end template query30.tpl query 11 in stream 7 --- start template query34.tpl query 12 in stream 7 -select /* TPC-DS query34.tpl 0.73 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (date_dim.d_dom between 1 and 3 or date_dim.d_dom between 25 and 28) - and (household_demographics.hd_buy_potential = '501-1000' or - household_demographics.hd_buy_potential = '0-500') - and household_demographics.hd_vehicle_count > 0 - and (case when household_demographics.hd_vehicle_count > 0 - then household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count - else null - end) > 1.2 - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_county in ('Huron County','Franklin Parish','Marshall County','Walker County', - 'Ziebach County','Barrow County','Mesa County','Bronx County') - group by ss_ticket_number,ss_customer_sk) dn,customer - where ss_customer_sk = c_customer_sk - and cnt between 15 and 20 - order by c_last_name,c_first_name,c_salutation,c_preferred_cust_flag desc, ss_ticket_number; - --- end template query34.tpl query 12 in stream 7 --- start template query13.tpl query 13 in stream 7 -select /* TPC-DS query13.tpl 0.91 */ avg(ss_quantity) - ,avg(ss_ext_sales_price) - ,avg(ss_ext_wholesale_cost) - ,sum(ss_ext_wholesale_cost) - from store_sales - ,store - ,customer_demographics - ,household_demographics - ,customer_address - ,date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2001 - and((ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'M' - and cd_education_status = 'Advanced Degree' - and ss_sales_price between 100.00 and 150.00 - and hd_dep_count = 3 - )or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'D' - and cd_education_status = 'College' - and ss_sales_price between 50.00 and 100.00 - and hd_dep_count = 1 - ) or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'S' - and cd_education_status = '2 yr Degree' - and ss_sales_price between 150.00 and 200.00 - and hd_dep_count = 1 - )) - and((ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('MO', 'MI', 'IN') - and ss_net_profit between 100 and 200 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('ME', 'VA', 'KS') - and ss_net_profit between 150 and 300 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('NC', 'TN', 'KY') - and ss_net_profit between 50 and 250 - )) -; - --- end template query13.tpl query 13 in stream 7 --- start template query28.tpl query 14 in stream 7 -select /* TPC-DS query28.tpl 0.36 */ * -from (select avg(ss_list_price) B1_LP - ,count(ss_list_price) B1_CNT - ,count(distinct ss_list_price) B1_CNTD - from store_sales - where ss_quantity between 0 and 5 - and (ss_list_price between 172 and 172+10 - or ss_coupon_amt between 8351 and 8351+1000 - or ss_wholesale_cost between 70 and 70+20)) B1, - (select avg(ss_list_price) B2_LP - ,count(ss_list_price) B2_CNT - ,count(distinct ss_list_price) B2_CNTD - from store_sales - where ss_quantity between 6 and 10 - and (ss_list_price between 96 and 96+10 - or ss_coupon_amt between 13351 and 13351+1000 - or ss_wholesale_cost between 39 and 39+20)) B2, - (select avg(ss_list_price) B3_LP - ,count(ss_list_price) B3_CNT - ,count(distinct ss_list_price) B3_CNTD - from store_sales - where ss_quantity between 11 and 15 - and (ss_list_price between 134 and 134+10 - or ss_coupon_amt between 13577 and 13577+1000 - or ss_wholesale_cost between 45 and 45+20)) B3, - (select avg(ss_list_price) B4_LP - ,count(ss_list_price) B4_CNT - ,count(distinct ss_list_price) B4_CNTD - from store_sales - where ss_quantity between 16 and 20 - and (ss_list_price between 119 and 119+10 - or ss_coupon_amt between 14611 and 14611+1000 - or ss_wholesale_cost between 49 and 49+20)) B4, - (select avg(ss_list_price) B5_LP - ,count(ss_list_price) B5_CNT - ,count(distinct ss_list_price) B5_CNTD - from store_sales - where ss_quantity between 21 and 25 - and (ss_list_price between 38 and 38+10 - or ss_coupon_amt between 16377 and 16377+1000 - or ss_wholesale_cost between 59 and 59+20)) B5, - (select avg(ss_list_price) B6_LP - ,count(ss_list_price) B6_CNT - ,count(distinct ss_list_price) B6_CNTD - from store_sales - where ss_quantity between 26 and 30 - and (ss_list_price between 97 and 97+10 - or ss_coupon_amt between 3089 and 3089+1000 - or ss_wholesale_cost between 51 and 51+20)) B6 -limit 100; - --- end template query28.tpl query 14 in stream 7 --- start template query86a.tpl query 15 in stream 7 -with /* TPC-DS query86a.tpl 0.11 */ results as -( select sum(ws_net_paid) as total_sum, i_category, i_class, 0 as g_category, 0 as g_class - from - web_sales - ,date_dim d1 - ,item - where - d1.d_month_seq between 1192 and 1192+11 - and d1.d_date_sk = ws_sold_date_sk - and i_item_sk = ws_item_sk - group by i_category,i_class - ) , - - results_rollup as -( select total_sum ,i_category ,i_class, g_category, g_class, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum, i_category, NULL as i_class, 0 as g_category, 1 as g_class, 1 as lochierarchy from results group by i_category - union - select sum(total_sum) as total_sum, NULL as i_category, NULL as i_class, 1 as g_category, 1 as g_class, 2 as lochierarchy from results) - select - total_sum ,i_category ,i_class, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_class = 0 then i_category end - order by total_sum desc) as rank_within_parent - from - results_rollup - order by - lochierarchy desc, - case when lochierarchy = 0 then i_category end, - rank_within_parent - limit 100; - --- end template query86a.tpl query 15 in stream 7 --- start template query84.tpl query 16 in stream 7 -select /* TPC-DS query84.tpl 0.80 */ c_customer_id as customer_id - , coalesce(c_last_name,'') || ', ' || coalesce(c_first_name,'') as customername - from customer - ,customer_address - ,customer_demographics - ,household_demographics - ,income_band - ,store_returns - where ca_city = 'Stringtown' - and c_current_addr_sk = ca_address_sk - and ib_lower_bound >= 65038 - and ib_upper_bound <= 65038 + 50000 - and ib_income_band_sk = hd_income_band_sk - and cd_demo_sk = c_current_cdemo_sk - and hd_demo_sk = c_current_hdemo_sk - and sr_cdemo_sk = cd_demo_sk - order by c_customer_id - limit 100; - --- end template query84.tpl query 16 in stream 7 --- start template query25.tpl query 17 in stream 7 -select /* TPC-DS query25.tpl 0.9 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,min(ss_net_profit) as store_sales_profit - ,min(sr_net_loss) as store_returns_loss - ,min(cs_net_profit) as catalog_sales_profit - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 2000 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 10 - and d2.d_year = 2000 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_moy between 4 and 10 - and d3.d_year = 2000 - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query25.tpl query 17 in stream 7 --- start template query4.tpl query 18 in stream 7 -with /* TPC-DS query4.tpl 0.93 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(((ss_ext_list_price-ss_ext_wholesale_cost-ss_ext_discount_amt)+ss_ext_sales_price)/2) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((cs_ext_list_price-cs_ext_wholesale_cost-cs_ext_discount_amt)+cs_ext_sales_price)/2) ) year_total - ,'c' sale_type - from customer - ,catalog_sales - ,date_dim - where c_customer_sk = cs_bill_customer_sk - and cs_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year -union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((ws_ext_list_price-ws_ext_wholesale_cost-ws_ext_discount_amt)+ws_ext_sales_price)/2) ) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_email_address - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_c_firstyear - ,year_total t_c_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_c_secyear.customer_id - and t_s_firstyear.customer_id = t_c_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_c_firstyear.sale_type = 'c' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_c_secyear.sale_type = 'c' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 2001 - and t_s_secyear.dyear = 2001+1 - and t_c_firstyear.dyear = 2001 - and t_c_secyear.dyear = 2001+1 - and t_w_firstyear.dyear = 2001 - and t_w_secyear.dyear = 2001+1 - and t_s_firstyear.year_total > 0 - and t_c_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_email_address -limit 100; - --- end template query4.tpl query 18 in stream 7 --- start template query98.tpl query 19 in stream 7 -select /* TPC-DS query98.tpl 0.32 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ss_ext_sales_price) as itemrevenue - ,sum(ss_ext_sales_price)*100/sum(sum(ss_ext_sales_price)) over - (partition by i_class) as revenueratio -from - store_sales - ,item - ,date_dim -where - ss_item_sk = i_item_sk - and i_category in ('Shoes', 'Women', 'Home') - and ss_sold_date_sk = d_date_sk - and d_date between cast('1999-05-06' as date) - and dateadd(day,30,cast('1999-05-06' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio; - --- end template query98.tpl query 19 in stream 7 --- start template query79.tpl query 20 in stream 7 -select /* TPC-DS query79.tpl 0.89 */ - c_last_name,c_first_name,substring(s_city,1,30),ss_ticket_number,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,store.s_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (household_demographics.hd_dep_count = 1 or household_demographics.hd_vehicle_count > 3) - and date_dim.d_dow = 1 - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_number_employees between 200 and 295 - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,store.s_city) ms,customer - where ss_customer_sk = c_customer_sk - order by c_last_name,c_first_name,substring(s_city,1,30), profit -limit 100; - --- end template query79.tpl query 20 in stream 7 --- start template query69.tpl query 21 in stream 7 -select /* TPC-DS query69.tpl 0.28 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_state in ('UT','KY','WV') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2003 and - d_moy between 3 and 3+2) and - (not exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2003 and - d_moy between 3 and 3+2) and - not exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2003 and - d_moy between 3 and 3+2)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - limit 100; - --- end template query69.tpl query 21 in stream 7 --- start template query72.tpl query 22 in stream 7 -select /* TPC-DS query72.tpl 0.87 */ i_item_desc - ,w_warehouse_name - ,d1.d_week_seq - ,sum(case when p_promo_sk is null then 1 else 0 end) no_promo - ,sum(case when p_promo_sk is not null then 1 else 0 end) promo - ,count(*) total_cnt -from catalog_sales -join inventory on (cs_item_sk = inv_item_sk) -join warehouse on (w_warehouse_sk=inv_warehouse_sk) -join item on (i_item_sk = cs_item_sk) -join customer_demographics on (cs_bill_cdemo_sk = cd_demo_sk) -join household_demographics on (cs_bill_hdemo_sk = hd_demo_sk) -join date_dim d1 on (cs_sold_date_sk = d1.d_date_sk) -join date_dim d2 on (inv_date_sk = d2.d_date_sk) -join date_dim d3 on (cs_ship_date_sk = d3.d_date_sk) -left outer join promotion on (cs_promo_sk=p_promo_sk) -left outer join catalog_returns on (cr_item_sk = cs_item_sk and cr_order_number = cs_order_number) -where d1.d_week_seq = d2.d_week_seq - and inv_quantity_on_hand < cs_quantity - and d3.d_date > d1.d_date + 5 - and hd_buy_potential = '501-1000' - and d1.d_year = 2002 - and cd_marital_status = 'M' -group by i_item_desc,w_warehouse_name,d1.d_week_seq -order by total_cnt desc, i_item_desc, w_warehouse_name, d_week_seq -limit 100; - --- end template query72.tpl query 22 in stream 7 --- start template query45.tpl query 23 in stream 7 -select /* TPC-DS query45.tpl 0.18 */ ca_zip, ca_state, sum(ws_sales_price) - from web_sales, customer, customer_address, date_dim, item - where ws_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ws_item_sk = i_item_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', '85392', '85460', '80348', '81792') - or - i_item_id in (select i_item_id - from item - where i_item_sk in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29) - ) - ) - and ws_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 2001 - group by ca_zip, ca_state - order by ca_zip, ca_state - limit 100; - --- end template query45.tpl query 23 in stream 7 --- start template query48.tpl query 24 in stream 7 -select /* TPC-DS query48.tpl 0.74 */ sum (ss_quantity) - from store_sales, store, customer_demographics, customer_address, date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2001 - and - ( - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'U' - and - cd_education_status = 'Primary' - and - ss_sales_price between 100.00 and 150.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'D' - and - cd_education_status = 'College' - and - ss_sales_price between 50.00 and 100.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'S' - and - cd_education_status = 'Unknown' - and - ss_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('LA', 'KY', 'MO') - and ss_net_profit between 0 and 2000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('SC', 'VA', 'TX') - and ss_net_profit between 150 and 3000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('IN', 'CA', 'OH') - and ss_net_profit between 50 and 25000 - ) - ) -; - --- end template query48.tpl query 24 in stream 7 --- start template query80a.tpl query 25 in stream 7 -with /* TPC-DS query80a.tpl 0.6 */ ssr as - (select s_store_id as store_id, - sum(ss_ext_sales_price) as sales, - sum(coalesce(sr_return_amt, 0)) as returns, - sum(ss_net_profit - coalesce(sr_net_loss, 0)) as profit - from store_sales left outer join store_returns on - (ss_item_sk = sr_item_sk and ss_ticket_number = sr_ticket_number), - date_dim, - store, - item, - promotion - where ss_sold_date_sk = d_date_sk - and d_date between cast('1998-08-27' as date) - and dateadd(day,30,cast('1998-08-27' as date)) - and ss_store_sk = s_store_sk - and ss_item_sk = i_item_sk - and i_current_price > 50 - and ss_promo_sk = p_promo_sk - and p_channel_tv = 'N' - group by s_store_id) - , - csr as - (select cp_catalog_page_id as catalog_page_id, - sum(cs_ext_sales_price) as sales, - sum(coalesce(cr_return_amount, 0)) as returns, - sum(cs_net_profit - coalesce(cr_net_loss, 0)) as profit - from catalog_sales left outer join catalog_returns on - (cs_item_sk = cr_item_sk and cs_order_number = cr_order_number), - date_dim, - catalog_page, - item, - promotion - where cs_sold_date_sk = d_date_sk - and d_date between cast('1998-08-27' as date) - and dateadd(day,30,cast('1998-08-27' as date)) - and cs_catalog_page_sk = cp_catalog_page_sk - and cs_item_sk = i_item_sk - and i_current_price > 50 - and cs_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(ws_ext_sales_price) as sales, - sum(coalesce(wr_return_amt, 0)) as returns, - sum(ws_net_profit - coalesce(wr_net_loss, 0)) as profit - from web_sales left outer join web_returns on - (ws_item_sk = wr_item_sk and ws_order_number = wr_order_number), - date_dim, - web_site, - item, - promotion - where ws_sold_date_sk = d_date_sk - and d_date between cast('1998-08-27' as date) - and dateadd(day,30,cast('1998-08-27' as date)) - and ws_web_site_sk = web_site_sk - and ws_item_sk = i_item_sk - and i_current_price > 50 - and ws_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by web_site_id) -, -results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || store_id as id - , sales - , returns - , profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || catalog_page_id as id - , sales - , returns - , profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , profit - from wsr - ) x - group by channel, id) - - select channel - , id - , sales - , returns - , profit - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results - ) foo - order by channel, id - limit 100; - --- end template query80a.tpl query 25 in stream 7 --- start template query20.tpl query 26 in stream 7 -select /* TPC-DS query20.tpl 0.65 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(cs_ext_sales_price) as itemrevenue - ,sum(cs_ext_sales_price)*100/sum(sum(cs_ext_sales_price)) over - (partition by i_class) as revenueratio - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and i_category in ('Shoes', 'Music', 'Sports') - and cs_sold_date_sk = d_date_sk - and d_date between cast('1998-05-09' as date) - and dateadd(day,30,cast('1998-05-09' as date)) - group by i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - order by i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query20.tpl query 26 in stream 7 --- start template query2.tpl query 27 in stream 7 -with /* TPC-DS query2.tpl 0.84 */ wscs as - (select sold_date_sk - ,sales_price - from (select ws_sold_date_sk sold_date_sk - ,ws_ext_sales_price sales_price - from web_sales - union all - select cs_sold_date_sk sold_date_sk - ,cs_ext_sales_price sales_price - from catalog_sales)), - wswscs as - (select d_week_seq, - sum(case when (d_day_name='Sunday') then sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then sales_price else null end) sat_sales - from wscs - ,date_dim - where d_date_sk = sold_date_sk - group by d_week_seq) - select d_week_seq1 - ,round(sun_sales1/sun_sales2,2) - ,round(mon_sales1/mon_sales2,2) - ,round(tue_sales1/tue_sales2,2) - ,round(wed_sales1/wed_sales2,2) - ,round(thu_sales1/thu_sales2,2) - ,round(fri_sales1/fri_sales2,2) - ,round(sat_sales1/sat_sales2,2) - from - (select wswscs.d_week_seq d_week_seq1 - ,sun_sales sun_sales1 - ,mon_sales mon_sales1 - ,tue_sales tue_sales1 - ,wed_sales wed_sales1 - ,thu_sales thu_sales1 - ,fri_sales fri_sales1 - ,sat_sales sat_sales1 - from wswscs,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 2001) y, - (select wswscs.d_week_seq d_week_seq2 - ,sun_sales sun_sales2 - ,mon_sales mon_sales2 - ,tue_sales tue_sales2 - ,wed_sales wed_sales2 - ,thu_sales thu_sales2 - ,fri_sales fri_sales2 - ,sat_sales sat_sales2 - from wswscs - ,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 2001+1) z - where d_week_seq1=d_week_seq2-53 - order by d_week_seq1; - --- end template query2.tpl query 27 in stream 7 --- start template query21.tpl query 28 in stream 7 -select /* TPC-DS query21.tpl 0.14 */ * - from(select w_warehouse_name - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('2000-03-24' as date)) - then inv_quantity_on_hand - else 0 end) as inv_before - ,sum(case when (cast(d_date as date) >= cast ('2000-03-24' as date)) - then inv_quantity_on_hand - else 0 end) as inv_after - from inventory - ,warehouse - ,item - ,date_dim - where i_current_price between 0.99 and 1.49 - and i_item_sk = inv_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('2000-03-24' as date)) - and dateadd(day,30,cast ('2000-03-24' as date)) - group by w_warehouse_name, i_item_id) x - where (case when inv_before > 0 - then inv_after / inv_before - else null - end) between 2.0/3.0 and 3.0/2.0 - order by w_warehouse_name - ,i_item_id - limit 100; - --- end template query21.tpl query 28 in stream 7 --- start template query97.tpl query 29 in stream 7 -with /* TPC-DS query97.tpl 0.38 */ ssci as ( -select ss_customer_sk customer_sk - ,ss_item_sk item_sk -from store_sales,date_dim -where ss_sold_date_sk = d_date_sk - and d_month_seq between 1210 and 1210 + 11 -group by ss_customer_sk - ,ss_item_sk), -csci as( - select cs_bill_customer_sk customer_sk - ,cs_item_sk item_sk -from catalog_sales,date_dim -where cs_sold_date_sk = d_date_sk - and d_month_seq between 1210 and 1210 + 11 -group by cs_bill_customer_sk - ,cs_item_sk) - select sum(case when ssci.customer_sk is not null and csci.customer_sk is null then 1 else 0 end) store_only - ,sum(case when ssci.customer_sk is null and csci.customer_sk is not null then 1 else 0 end) catalog_only - ,sum(case when ssci.customer_sk is not null and csci.customer_sk is not null then 1 else 0 end) store_and_catalog -from ssci full outer join csci on (ssci.customer_sk=csci.customer_sk - and ssci.item_sk = csci.item_sk) -limit 100; - --- end template query97.tpl query 29 in stream 7 --- start template query62.tpl query 30 in stream 7 -select /* TPC-DS query62.tpl 0.24 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 30) and - (ws_ship_date_sk - ws_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 60) and - (ws_ship_date_sk - ws_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 90) and - (ws_ship_date_sk - ws_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - web_sales - ,warehouse - ,ship_mode - ,web_site - ,date_dim -where - d_month_seq between 1176 and 1176 + 11 -and ws_ship_date_sk = d_date_sk -and ws_warehouse_sk = w_warehouse_sk -and ws_ship_mode_sk = sm_ship_mode_sk -and ws_web_site_sk = web_site_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -limit 100; - --- end template query62.tpl query 30 in stream 7 --- start template query47.tpl query 31 in stream 7 -with /* TPC-DS query47.tpl 0.42 */ v1 as( - select i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, - s_store_name, s_company_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - s_store_name, s_company_name - order by d_year, d_moy) rn - from item, store_sales, date_dim, store - where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - ( - d_year = 1999 or - ( d_year = 1999-1 and d_moy =12) or - ( d_year = 1999+1 and d_moy =1) - ) - group by i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy), - v2 as( - select v1.s_store_name, v1.s_company_name - ,v1.d_year, v1.d_moy - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1.s_store_name = v1_lag.s_store_name and - v1.s_store_name = v1_lead.s_store_name and - v1.s_company_name = v1_lag.s_company_name and - v1.s_company_name = v1_lead.s_company_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 1999 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, avg_monthly_sales - limit 100; - --- end template query47.tpl query 31 in stream 7 --- start template query60.tpl query 32 in stream 7 -with /* TPC-DS query60.tpl 0.29 */ ss as ( - select - i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Children')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 9 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -7 - group by i_item_id), - cs as ( - select - i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Children')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 9 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -7 - group by i_item_id), - ws as ( - select - i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Children')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 9 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -7 - group by i_item_id) - select - i_item_id -,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by i_item_id - ,total_sales - limit 100; - --- end template query60.tpl query 32 in stream 7 --- start template query71.tpl query 33 in stream 7 -select /* TPC-DS query71.tpl 0.72 */ i_brand_id brand_id, i_brand brand,t_hour,t_minute, - sum(ext_price) ext_price - from item, (select ws_ext_sales_price as ext_price, - ws_sold_date_sk as sold_date_sk, - ws_item_sk as sold_item_sk, - ws_sold_time_sk as time_sk - from web_sales,date_dim - where d_date_sk = ws_sold_date_sk - and d_moy=12 - and d_year=2000 - union all - select cs_ext_sales_price as ext_price, - cs_sold_date_sk as sold_date_sk, - cs_item_sk as sold_item_sk, - cs_sold_time_sk as time_sk - from catalog_sales,date_dim - where d_date_sk = cs_sold_date_sk - and d_moy=12 - and d_year=2000 - union all - select ss_ext_sales_price as ext_price, - ss_sold_date_sk as sold_date_sk, - ss_item_sk as sold_item_sk, - ss_sold_time_sk as time_sk - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - and d_moy=12 - and d_year=2000 - ) tmp,time_dim - where - sold_item_sk = i_item_sk - and i_manager_id=1 - and time_sk = t_time_sk - and (t_meal_time = 'breakfast' or t_meal_time = 'dinner') - group by i_brand, i_brand_id,t_hour,t_minute - order by ext_price desc, i_brand_id - ; - --- end template query71.tpl query 33 in stream 7 --- start template query46.tpl query 34 in stream 7 -select /* TPC-DS query46.tpl 0.23 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and (household_demographics.hd_dep_count = 3 or - household_demographics.hd_vehicle_count= 3) - and date_dim.d_dow in (6,0) - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_city in ('Mount Vernon','Antioch','Highland','Liberty','Hopewell') - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,ca_city) dn,customer,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - limit 100; - --- end template query46.tpl query 34 in stream 7 --- start template query10.tpl query 35 in stream 7 -select /* TPC-DS query10.tpl 0.26 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3, - cd_dep_count, - count(*) cnt4, - cd_dep_employed_count, - count(*) cnt5, - cd_dep_college_count, - count(*) cnt6 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_county in ('Day County','Richland Parish','Halifax County','Yell County','Macon County') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 1999 and - d_moy between 1 and 1+3) and - (exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 1999 and - d_moy between 1 ANd 1+3) or - exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 1999 and - d_moy between 1 and 1+3)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count -limit 100; - --- end template query10.tpl query 35 in stream 7 --- start template query14a.tpl query 36 in stream 7 -with /* TPC-DS query14a.tpl 0.69 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1998 AND 1998 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1998 AND 1998 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1998 AND 1998 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as - (select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2) x) -, - results AS -(select channel, i_brand_id, i_class_id, i_category_id, sum(sales) sum_sales, sum(number_sales) number_sales - from ( - select 'store' channel, i_brand_id,i_class_id - ,i_category_id,sum(ss_quantity*ss_list_price) sales - , count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1998+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales) - union all - select 'catalog' channel, i_brand_id,i_class_id,i_category_id, sum(cs_quantity*cs_list_price) sales, count(*) number_sales - from catalog_sales - ,item - ,date_dim - where cs_item_sk in (select ss_item_sk from cross_items) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1998+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(cs_quantity*cs_list_price) > (select average_sales from avg_sales) - union all - select 'web' channel, i_brand_id,i_class_id,i_category_id, sum(ws_quantity*ws_list_price) sales , count(*) number_sales - from web_sales - ,item - ,date_dim - where ws_item_sk in (select ss_item_sk from cross_items) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1998+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ws_quantity*ws_list_price) > (select average_sales from avg_sales) - ) y - group by channel, i_brand_id,i_class_id,i_category_id) - - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales -from ( - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales from results - union - select channel, i_brand_id, i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id, i_class_id - union - select channel, i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id - union - select channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel - union - select null as channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results) z -order by channel, i_brand_id, i_class_id, i_category_id - limit 100; -with /* TPC-DS query14a.tpl 0.69 part2 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1998 AND 1998 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1998 AND 1998 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1998 AND 1998 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as -(select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2) x) - select this_year.channel ty_channel - ,this_year.i_brand_id ty_brand - ,this_year.i_class_id ty_class - ,this_year.i_category_id ty_category - ,this_year.sales ty_sales - ,this_year.number_sales ty_number_sales - ,last_year.channel ly_channel - ,last_year.i_brand_id ly_brand - ,last_year.i_class_id ly_class - ,last_year.i_category_id ly_category - ,last_year.sales ly_sales - ,last_year.number_sales ly_number_sales -from - (select 'store' channel, i_brand_id,i_class_id,i_category_id - ,sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1998 + 1 - and d_moy = 12 - and d_dom = 15) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) this_year, - (select 'store' channel, i_brand_id,i_class_id - ,i_category_id, sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1998 - and d_moy = 12 - and d_dom = 15) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) last_year - where this_year.i_brand_id= last_year.i_brand_id - and this_year.i_class_id = last_year.i_class_id - and this_year.i_category_id = last_year.i_category_id - order by this_year.channel, this_year.i_brand_id, this_year.i_class_id, this_year.i_category_id - limit 100; - --- end template query14a.tpl query 36 in stream 7 --- start template query35a.tpl query 37 in stream 7 -select /* TPC-DS query35a.tpl 0.47 */ - ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - count(*) cnt1, - avg(cd_dep_count), - min(cd_dep_count), - stddev_samp(cd_dep_count), - cd_dep_employed_count, - count(*) cnt2, - avg(cd_dep_employed_count), - min(cd_dep_employed_count), - stddev_samp(cd_dep_employed_count), - cd_dep_college_count, - count(*) cnt3, - avg(cd_dep_college_count), - min(cd_dep_college_count), - stddev_samp(cd_dep_college_count) - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 1999 and - d_qoy < 4) and - exists (select * from - (select ws_bill_customer_sk customsk - from web_sales,date_dim - where - ws_sold_date_sk = d_date_sk and - d_year = 1999 and - d_qoy < 4 - union all - select cs_ship_customer_sk customsk - from catalog_sales,date_dim - where - cs_sold_date_sk = d_date_sk and - d_year = 1999 and - d_qoy < 4)x - where x.customsk = c.c_customer_sk) - group by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - limit 100; - --- end template query35a.tpl query 37 in stream 7 --- start template query55.tpl query 38 in stream 7 -select /* TPC-DS query55.tpl 0.82 */ i_brand_id brand_id, i_brand brand, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=42 - and d_moy=11 - and d_year=1998 - group by i_brand, i_brand_id - order by ext_price desc, i_brand_id -limit 100 ; - --- end template query55.tpl query 38 in stream 7 --- start template query37.tpl query 39 in stream 7 -select /* TPC-DS query37.tpl 0.31 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, catalog_sales - where i_current_price between 38 and 38 + 30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('2002-05-09' as date) and dateadd(day,60,cast('2002-05-09' as date)) - and i_manufact_id in (846,695,891,729) - and inv_quantity_on_hand between 100 and 500 - and cs_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query37.tpl query 39 in stream 7 --- start template query52.tpl query 40 in stream 7 -select /* TPC-DS query52.tpl 0.59 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_sales_price) ext_price - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=12 - and dt.d_year=1999 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,ext_price desc - ,brand_id -limit 100 ; - --- end template query52.tpl query 40 in stream 7 --- start template query9.tpl query 41 in stream 7 -select /* TPC-DS query9.tpl 0.49 */ case when (select count(*) - from store_sales - where ss_quantity between 1 and 20) > 33702262 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 1 and 20) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 1 and 20) end bucket1 , - case when (select count(*) - from store_sales - where ss_quantity between 21 and 40) > 24945373 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 21 and 40) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 21 and 40) end bucket2, - case when (select count(*) - from store_sales - where ss_quantity between 41 and 60) > 34905847 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 41 and 60) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 41 and 60) end bucket3, - case when (select count(*) - from store_sales - where ss_quantity between 61 and 80) > 28344702 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 61 and 80) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 61 and 80) end bucket4, - case when (select count(*) - from store_sales - where ss_quantity between 81 and 100) > 46493740 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 81 and 100) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 81 and 100) end bucket5 -from reason -where r_reason_sk = 1 -; - --- end template query9.tpl query 41 in stream 7 --- start template query85.tpl query 42 in stream 7 -select /* TPC-DS query85.tpl 0.33 */ substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) - from web_sales, web_returns, web_page, customer_demographics cd1, - customer_demographics cd2, customer_address, date_dim, reason - where ws_web_page_sk = wp_web_page_sk - and ws_item_sk = wr_item_sk - and ws_order_number = wr_order_number - and ws_sold_date_sk = d_date_sk and d_year = 2000 - and cd1.cd_demo_sk = wr_refunded_cdemo_sk - and cd2.cd_demo_sk = wr_returning_cdemo_sk - and ca_address_sk = wr_refunded_addr_sk - and r_reason_sk = wr_reason_sk - and - ( - ( - cd1.cd_marital_status = 'U' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'College' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 100.00 and 150.00 - ) - or - ( - cd1.cd_marital_status = 'W' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = '2 yr Degree' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 50.00 and 100.00 - ) - or - ( - cd1.cd_marital_status = 'M' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Advanced Degree' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ca_country = 'United States' - and - ca_state in ('MT', 'FL', 'IN') - and ws_net_profit between 100 and 200 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('MO', 'KY', 'TX') - and ws_net_profit between 150 and 300 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('VA', 'WV', 'CA') - and ws_net_profit between 50 and 250 - ) - ) -group by r_reason_desc -order by substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) -limit 100; - --- end template query85.tpl query 42 in stream 7 --- start template query40.tpl query 43 in stream 7 -select /* TPC-DS query40.tpl 0.86 */ - w_state - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('1999-02-19' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_before - ,sum(case when (cast(d_date as date) >= cast ('1999-02-19' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_after - from - catalog_sales left outer join catalog_returns on - (cs_order_number = cr_order_number - and cs_item_sk = cr_item_sk) - ,warehouse - ,item - ,date_dim - where - i_current_price between 0.99 and 1.49 - and i_item_sk = cs_item_sk - and cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('1999-02-19' as date)) - and dateadd(day,30,cast ('1999-02-19' as date)) - group by - w_state,i_item_id - order by w_state,i_item_id -limit 100; - --- end template query40.tpl query 43 in stream 7 --- start template query76.tpl query 44 in stream 7 -select /* TPC-DS query76.tpl 0.99 */ channel, col_name, d_year, d_qoy, i_category, COUNT(*) sales_cnt, SUM(ext_sales_price) sales_amt FROM ( - SELECT 'store' as channel, 'ss_cdemo_sk' col_name, d_year, d_qoy, i_category, ss_ext_sales_price ext_sales_price - FROM store_sales, item, date_dim - WHERE ss_cdemo_sk IS NULL - AND ss_sold_date_sk=d_date_sk - AND ss_item_sk=i_item_sk - UNION ALL - SELECT 'web' as channel, 'ws_ship_customer_sk' col_name, d_year, d_qoy, i_category, ws_ext_sales_price ext_sales_price - FROM web_sales, item, date_dim - WHERE ws_ship_customer_sk IS NULL - AND ws_sold_date_sk=d_date_sk - AND ws_item_sk=i_item_sk - UNION ALL - SELECT 'catalog' as channel, 'cs_bill_hdemo_sk' col_name, d_year, d_qoy, i_category, cs_ext_sales_price ext_sales_price - FROM catalog_sales, item, date_dim - WHERE cs_bill_hdemo_sk IS NULL - AND cs_sold_date_sk=d_date_sk - AND cs_item_sk=i_item_sk) foo -GROUP BY channel, col_name, d_year, d_qoy, i_category -ORDER BY channel, col_name, d_year, d_qoy, i_category -limit 100; - --- end template query76.tpl query 44 in stream 7 --- start template query44.tpl query 45 in stream 7 -select /* TPC-DS query44.tpl 0.4 */ asceding.rnk, i1.i_product_name best_performing, i2.i_product_name worst_performing -from(select * - from (select item_sk,rank() over (order by rank_col asc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 289 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 289 - and ss_promo_sk is null - group by ss_store_sk))V1)V11 - where rnk < 11) asceding, - (select * - from (select item_sk,rank() over (order by rank_col desc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 289 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 289 - and ss_promo_sk is null - group by ss_store_sk))V2)V21 - where rnk < 11) descending, -item i1, -item i2 -where asceding.rnk = descending.rnk - and i1.i_item_sk=asceding.item_sk - and i2.i_item_sk=descending.item_sk -order by asceding.rnk -limit 100; - --- end template query44.tpl query 45 in stream 7 --- start template query3.tpl query 46 in stream 7 -select /* TPC-DS query3.tpl 0.45 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_sales_price) sum_agg - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manufact_id = 538 - and dt.d_moy=12 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,sum_agg desc - ,brand_id - limit 100; - --- end template query3.tpl query 46 in stream 7 --- start template query26.tpl query 47 in stream 7 -select /* TPC-DS query26.tpl 0.85 */ i_item_id, - avg(cs_quantity) agg1, - avg(cs_list_price) agg2, - avg(cs_coupon_amt) agg3, - avg(cs_sales_price) agg4 - from catalog_sales, customer_demographics, date_dim, item, promotion - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd_demo_sk and - cs_promo_sk = p_promo_sk and - cd_gender = 'F' and - cd_marital_status = 'D' and - cd_education_status = '2 yr Degree' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 2002 - group by i_item_id - order by i_item_id - limit 100; - --- end template query26.tpl query 47 in stream 7 --- start template query19.tpl query 48 in stream 7 -select /* TPC-DS query19.tpl 0.8 */ i_brand_id brand_id, i_brand brand, i_manufact_id, i_manufact, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item,customer,customer_address,store - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=30 - and d_moy=11 - and d_year=1998 - and ss_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and substring(ca_zip,1,5) <> substring(s_zip,1,5) - and ss_store_sk = s_store_sk - group by i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact - order by ext_price desc - ,i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact -limit 100 ; - --- end template query19.tpl query 48 in stream 7 --- start template query58.tpl query 49 in stream 7 -with /* TPC-DS query58.tpl 0.19 */ ss_items as - (select i_item_id item_id - ,sum(ss_ext_sales_price) ss_item_rev - from store_sales - ,item - ,date_dim - where ss_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '2001-04-11')) - and ss_sold_date_sk = d_date_sk - group by i_item_id), - cs_items as - (select i_item_id item_id - ,sum(cs_ext_sales_price) cs_item_rev - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '2001-04-11')) - and cs_sold_date_sk = d_date_sk - group by i_item_id), - ws_items as - (select i_item_id item_id - ,sum(ws_ext_sales_price) ws_item_rev - from web_sales - ,item - ,date_dim - where ws_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq =(select d_week_seq - from date_dim - where d_date = '2001-04-11')) - and ws_sold_date_sk = d_date_sk - group by i_item_id) - select ss_items.item_id - ,ss_item_rev - ,ss_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ss_dev - ,cs_item_rev - ,cs_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 cs_dev - ,ws_item_rev - ,ws_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ws_dev - ,(ss_item_rev+cs_item_rev+ws_item_rev)/3 average - from ss_items,cs_items,ws_items - where ss_items.item_id=cs_items.item_id - and ss_items.item_id=ws_items.item_id - and ss_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - and ss_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and cs_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and cs_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and ws_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and ws_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - order by item_id - ,ss_item_rev - limit 100; - --- end template query58.tpl query 49 in stream 7 --- start template query42.tpl query 50 in stream 7 -select /* TPC-DS query42.tpl 0.61 */ dt.d_year - ,item.i_category_id - ,item.i_category - ,sum(ss_ext_sales_price) - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=12 - and dt.d_year=2002 - group by dt.d_year - ,item.i_category_id - ,item.i_category - order by sum(ss_ext_sales_price) desc,dt.d_year - ,item.i_category_id - ,item.i_category -limit 100 ; - --- end template query42.tpl query 50 in stream 7 --- start template query75.tpl query 51 in stream 7 -WITH /* TPC-DS query75.tpl 0.3 */ all_sales AS ( - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,SUM(sales_cnt) AS sales_cnt - ,SUM(sales_amt) AS sales_amt - FROM (SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,cs_quantity - COALESCE(cr_return_quantity,0) AS sales_cnt - ,cs_ext_sales_price - COALESCE(cr_return_amount,0.0) AS sales_amt - FROM catalog_sales JOIN item ON i_item_sk=cs_item_sk - JOIN date_dim ON d_date_sk=cs_sold_date_sk - LEFT JOIN catalog_returns ON (cs_order_number=cr_order_number - AND cs_item_sk=cr_item_sk) - WHERE i_category='Jewelry' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ss_quantity - COALESCE(sr_return_quantity,0) AS sales_cnt - ,ss_ext_sales_price - COALESCE(sr_return_amt,0.0) AS sales_amt - FROM store_sales JOIN item ON i_item_sk=ss_item_sk - JOIN date_dim ON d_date_sk=ss_sold_date_sk - LEFT JOIN store_returns ON (ss_ticket_number=sr_ticket_number - AND ss_item_sk=sr_item_sk) - WHERE i_category='Jewelry' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ws_quantity - COALESCE(wr_return_quantity,0) AS sales_cnt - ,ws_ext_sales_price - COALESCE(wr_return_amt,0.0) AS sales_amt - FROM web_sales JOIN item ON i_item_sk=ws_item_sk - JOIN date_dim ON d_date_sk=ws_sold_date_sk - LEFT JOIN web_returns ON (ws_order_number=wr_order_number - AND ws_item_sk=wr_item_sk) - WHERE i_category='Jewelry') sales_detail - GROUP BY d_year, i_brand_id, i_class_id, i_category_id, i_manufact_id) - SELECT prev_yr.d_year AS prev_year - ,curr_yr.d_year AS year - ,curr_yr.i_brand_id - ,curr_yr.i_class_id - ,curr_yr.i_category_id - ,curr_yr.i_manufact_id - ,prev_yr.sales_cnt AS prev_yr_cnt - ,curr_yr.sales_cnt AS curr_yr_cnt - ,curr_yr.sales_cnt-prev_yr.sales_cnt AS sales_cnt_diff - ,curr_yr.sales_amt-prev_yr.sales_amt AS sales_amt_diff - FROM all_sales curr_yr, all_sales prev_yr - WHERE curr_yr.i_brand_id=prev_yr.i_brand_id - AND curr_yr.i_class_id=prev_yr.i_class_id - AND curr_yr.i_category_id=prev_yr.i_category_id - AND curr_yr.i_manufact_id=prev_yr.i_manufact_id - AND curr_yr.d_year=1999 - AND prev_yr.d_year=1999-1 - AND CAST(curr_yr.sales_cnt AS DECIMAL(17,2))/CAST(prev_yr.sales_cnt AS DECIMAL(17,2))<0.9 - ORDER BY sales_cnt_diff,sales_amt_diff - limit 100; - --- end template query75.tpl query 51 in stream 7 --- start template query17.tpl query 52 in stream 7 -select /* TPC-DS query17.tpl 0.41 */ i_item_id - ,i_item_desc - ,s_state - ,count(ss_quantity) as store_sales_quantitycount - ,avg(ss_quantity) as store_sales_quantityave - ,stddev_samp(ss_quantity) as store_sales_quantitystdev - ,stddev_samp(ss_quantity)/avg(ss_quantity) as store_sales_quantitycov - ,count(sr_return_quantity) as store_returns_quantitycount - ,avg(sr_return_quantity) as store_returns_quantityave - ,stddev_samp(sr_return_quantity) as store_returns_quantitystdev - ,stddev_samp(sr_return_quantity)/avg(sr_return_quantity) as store_returns_quantitycov - ,count(cs_quantity) as catalog_sales_quantitycount ,avg(cs_quantity) as catalog_sales_quantityave - ,stddev_samp(cs_quantity) as catalog_sales_quantitystdev - ,stddev_samp(cs_quantity)/avg(cs_quantity) as catalog_sales_quantitycov - from store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where d1.d_quarter_name = '1998Q1' - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_quarter_name in ('1998Q1','1998Q2','1998Q3') - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_quarter_name in ('1998Q1','1998Q2','1998Q3') - group by i_item_id - ,i_item_desc - ,s_state - order by i_item_id - ,i_item_desc - ,s_state -limit 100; - --- end template query17.tpl query 52 in stream 7 --- start template query38.tpl query 53 in stream 7 -select /* TPC-DS query38.tpl 0.54 */ count(*) from ( - select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1187 and 1187 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1187 and 1187 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1187 and 1187 + 11 -) hot_cust -limit 100; - --- end template query38.tpl query 53 in stream 7 --- start template query82.tpl query 54 in stream 7 -select /* TPC-DS query82.tpl 0.67 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, store_sales - where i_current_price between 35 and 35+30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('1999-05-12' as date) and dateadd(day,60,cast('1999-05-12' as date)) - and i_manufact_id in (533,414,545,741) - and inv_quantity_on_hand between 100 and 500 - and ss_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query82.tpl query 54 in stream 7 --- start template query87.tpl query 55 in stream 7 -select /* TPC-DS query87.tpl 0.77 */ count(*) -from ((select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1222 and 1222+11) - except - (select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1222 and 1222+11) - except - (select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1222 and 1222+11) -) cool_cust -; - --- end template query87.tpl query 55 in stream 7 --- start template query43.tpl query 56 in stream 7 -select /* TPC-DS query43.tpl 0.15 */ s_store_name, s_store_id, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from date_dim, store_sales, store - where d_date_sk = ss_sold_date_sk and - s_store_sk = ss_store_sk and - s_gmt_offset = -6 and - d_year = 1998 - group by s_store_name, s_store_id - order by s_store_name, s_store_id,sun_sales,mon_sales,tue_sales,wed_sales,thu_sales,fri_sales,sat_sales - limit 100; - --- end template query43.tpl query 56 in stream 7 --- start template query11.tpl query 57 in stream 7 -with /* TPC-DS query11.tpl 0.51 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ss_ext_list_price-ss_ext_discount_amt) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ws_ext_list_price-ws_ext_discount_amt) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_preferred_cust_flag - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 1998 - and t_s_secyear.dyear = 1998+1 - and t_w_firstyear.dyear = 1998 - and t_w_secyear.dyear = 1998+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else 0.0 end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else 0.0 end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_preferred_cust_flag -limit 100; - --- end template query11.tpl query 57 in stream 7 --- start template query5a.tpl query 58 in stream 7 -with /* TPC-DS query5a.tpl 0.98 */ ssr as - (select s_store_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ss_store_sk as store_sk, - ss_sold_date_sk as date_sk, - ss_ext_sales_price as sales_price, - ss_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from store_sales - union all - select sr_store_sk as store_sk, - sr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - sr_return_amt as return_amt, - sr_net_loss as net_loss - from store_returns - ) salesreturns, - date_dim, - store - where date_sk = d_date_sk - and d_date between cast('2001-08-12' as date) - and dateadd(day,14,cast('2001-08-12' as date)) - and store_sk = s_store_sk - group by s_store_id) - , - csr as - (select cp_catalog_page_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select cs_catalog_page_sk as page_sk, - cs_sold_date_sk as date_sk, - cs_ext_sales_price as sales_price, - cs_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from catalog_sales - union all - select cr_catalog_page_sk as page_sk, - cr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - cr_return_amount as return_amt, - cr_net_loss as net_loss - from catalog_returns - ) salesreturns, - date_dim, - catalog_page - where date_sk = d_date_sk - and d_date between cast('2001-08-12' as date) - and dateadd(day,14,cast('2001-08-12' as date)) - and page_sk = cp_catalog_page_sk - group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ws_web_site_sk as wsr_web_site_sk, - ws_sold_date_sk as date_sk, - ws_ext_sales_price as sales_price, - ws_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from web_sales - union all - select ws_web_site_sk as wsr_web_site_sk, - wr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - wr_return_amt as return_amt, - wr_net_loss as net_loss - from web_returns left outer join web_sales on - ( wr_item_sk = ws_item_sk - and wr_order_number = ws_order_number) - ) salesreturns, - date_dim, - web_site - where date_sk = d_date_sk - and d_date between cast('2001-08-12' as date) - and dateadd(day,14,cast('2001-08-12' as date)) - and wsr_web_site_sk = web_site_sk - group by web_site_id) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || s_store_id as id - , sales - , returns - , (profit - profit_loss) as profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || cp_catalog_page_id as id - , sales - , returns - , (profit - profit_loss) as profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , (profit - profit_loss) as profit - from wsr - ) x - group by channel, id) - select channel, id, sales, returns, profit from ( - select channel, id, sales, returns, profit from results - union - select channel, null as id, sum(sales), sum(returns), sum(profit) from results group by channel - union - select null as channel, null as id, sum(sales), sum(returns), sum(profit) from results) foo -order by channel, id -limit 100; - --- end template query5a.tpl query 58 in stream 7 --- start template query41.tpl query 59 in stream 7 -select /* TPC-DS query41.tpl 0.62 */ distinct(i_product_name) - from item i1 - where i_manufact_id between 806 and 806+40 - and (select count(*) as item_cnt - from item - where (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'plum' or i_color = 'purple') and - (i_units = 'Carton' or i_units = 'N/A') and - (i_size = 'N/A' or i_size = 'economy') - ) or - (i_category = 'Women' and - (i_color = 'papaya' or i_color = 'linen') and - (i_units = 'Cup' or i_units = 'Bundle') and - (i_size = 'small' or i_size = 'large') - ) or - (i_category = 'Men' and - (i_color = 'midnight' or i_color = 'spring') and - (i_units = 'Dozen' or i_units = 'Case') and - (i_size = 'petite' or i_size = 'medium') - ) or - (i_category = 'Men' and - (i_color = 'red' or i_color = 'rosy') and - (i_units = 'Tbl' or i_units = 'Ton') and - (i_size = 'N/A' or i_size = 'economy') - ))) or - (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'salmon' or i_color = 'mint') and - (i_units = 'Pound' or i_units = 'Gross') and - (i_size = 'N/A' or i_size = 'economy') - ) or - (i_category = 'Women' and - (i_color = 'moccasin' or i_color = 'smoke') and - (i_units = 'Pallet' or i_units = 'Tsp') and - (i_size = 'small' or i_size = 'large') - ) or - (i_category = 'Men' and - (i_color = 'lawn' or i_color = 'violet') and - (i_units = 'Bunch' or i_units = 'Lb') and - (i_size = 'petite' or i_size = 'medium') - ) or - (i_category = 'Men' and - (i_color = 'burnished' or i_color = 'cyan') and - (i_units = 'Ounce' or i_units = 'Each') and - (i_size = 'N/A' or i_size = 'economy') - )))) > 0 - order by i_product_name - limit 100; - --- end template query41.tpl query 59 in stream 7 --- start template query61.tpl query 60 in stream 7 -select /* TPC-DS query61.tpl 0.97 */ promotions,total,cast(promotions as decimal(15,4))/cast(total as decimal(15,4))*100 -from - (select sum(ss_ext_sales_price) promotions - from store_sales - ,store - ,promotion - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_promo_sk = p_promo_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -6 - and i_category = 'Home' - and (p_channel_dmail = 'Y' or p_channel_email = 'Y' or p_channel_tv = 'Y') - and s_gmt_offset = -6 - and d_year = 2002 - and d_moy = 11) promotional_sales, - (select sum(ss_ext_sales_price) total - from store_sales - ,store - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -6 - and i_category = 'Home' - and s_gmt_offset = -6 - and d_year = 2002 - and d_moy = 11) all_sales -order by promotions, total -limit 100; - --- end template query61.tpl query 60 in stream 7 --- start template query33.tpl query 61 in stream 7 -with /* TPC-DS query33.tpl 0.22 */ ss as ( - select - i_manufact_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Jewelry')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 7 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id), - cs as ( - select - i_manufact_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Jewelry')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 7 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id), - ws as ( - select - i_manufact_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Jewelry')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 7 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id) - select i_manufact_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_manufact_id - order by total_sales -limit 100; - --- end template query33.tpl query 61 in stream 7 --- start template query49.tpl query 62 in stream 7 -select /* TPC-DS query49.tpl 0.48 */ channel, item, return_ratio, return_rank, currency_rank from - (select - 'web' as channel - ,web.item - ,web.return_ratio - ,web.return_rank - ,web.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select ws.ws_item_sk as item - ,(cast(sum(coalesce(wr.wr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(wr.wr_return_amt,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - web_sales ws left outer join web_returns wr - on (ws.ws_order_number = wr.wr_order_number and - ws.ws_item_sk = wr.wr_item_sk) - ,date_dim - where - wr.wr_return_amt > 10000 - and ws.ws_net_profit > 1 - and ws.ws_net_paid > 0 - and ws.ws_quantity > 0 - and ws_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 12 - group by ws.ws_item_sk - ) in_web - ) web - where - ( - web.return_rank <= 10 - or - web.currency_rank <= 10 - ) - union - select - 'catalog' as channel - ,catalog.item - ,catalog.return_ratio - ,catalog.return_rank - ,catalog.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select - cs.cs_item_sk as item - ,(cast(sum(coalesce(cr.cr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(cr.cr_return_amount,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - catalog_sales cs left outer join catalog_returns cr - on (cs.cs_order_number = cr.cr_order_number and - cs.cs_item_sk = cr.cr_item_sk) - ,date_dim - where - cr.cr_return_amount > 10000 - and cs.cs_net_profit > 1 - and cs.cs_net_paid > 0 - and cs.cs_quantity > 0 - and cs_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 12 - group by cs.cs_item_sk - ) in_cat - ) catalog - where - ( - catalog.return_rank <= 10 - or - catalog.currency_rank <=10 - ) - union - select - 'store' as channel - ,store.item - ,store.return_ratio - ,store.return_rank - ,store.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select sts.ss_item_sk as item - ,(cast(sum(coalesce(sr.sr_return_quantity,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(sr.sr_return_amt,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - store_sales sts left outer join store_returns sr - on (sts.ss_ticket_number = sr.sr_ticket_number and sts.ss_item_sk = sr.sr_item_sk) - ,date_dim - where - sr.sr_return_amt > 10000 - and sts.ss_net_profit > 1 - and sts.ss_net_paid > 0 - and sts.ss_quantity > 0 - and ss_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 12 - group by sts.ss_item_sk - ) in_store - ) store - where ( - store.return_rank <= 10 - or - store.currency_rank <= 10 - ) - ) - order by 1,4,5,2 - limit 100; - --- end template query49.tpl query 62 in stream 7 --- start template query7.tpl query 63 in stream 7 -select /* TPC-DS query7.tpl 0.2 */ i_item_id, - avg(ss_quantity) agg1, - avg(ss_list_price) agg2, - avg(ss_coupon_amt) agg3, - avg(ss_sales_price) agg4 - from store_sales, customer_demographics, date_dim, item, promotion - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_cdemo_sk = cd_demo_sk and - ss_promo_sk = p_promo_sk and - cd_gender = 'M' and - cd_marital_status = 'W' and - cd_education_status = 'Unknown' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 2001 - group by i_item_id - order by i_item_id - limit 100; - --- end template query7.tpl query 63 in stream 7 --- start template query73.tpl query 64 in stream 7 -select /* TPC-DS query73.tpl 0.79 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_buy_potential = '1001-5000' or - household_demographics.hd_buy_potential = 'Unknown') - and household_demographics.hd_vehicle_count > 0 - and case when household_demographics.hd_vehicle_count > 0 then - household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count else null end > 1 - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_county in ('Mesa County','Gage County','Gogebic County','Mobile County') - group by ss_ticket_number,ss_customer_sk) dj,customer - where ss_customer_sk = c_customer_sk - and cnt between 1 and 5 - order by cnt desc, c_last_name asc; - --- end template query73.tpl query 64 in stream 7 --- start template query89.tpl query 65 in stream 7 -select /* TPC-DS query89.tpl 0.56 */ * -from( -select i_category, i_class, i_brand, - s_store_name, s_company_name, - d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, s_store_name, s_company_name) - avg_monthly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - d_year in (2000) and - ((i_category in ('Children','Sports','Men') and - i_class in ('infants','archery','pants') - ) - or (i_category in ('Music','Home','Shoes') and - i_class in ('rock','blinds/shades','athletic') - )) -group by i_category, i_class, i_brand, - s_store_name, s_company_name, d_moy) tmp1 -where case when (avg_monthly_sales <> 0) then (abs(sum_sales - avg_monthly_sales) / avg_monthly_sales) else null end > 0.1 -order by sum_sales - avg_monthly_sales, s_store_name -limit 100; - --- end template query89.tpl query 65 in stream 7 --- start template query81.tpl query 66 in stream 7 -with /* TPC-DS query81.tpl 0.37 */ customer_total_return as - (select cr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(cr_return_amt_inc_tax) as ctr_total_return - from catalog_returns - ,date_dim - ,customer_address - where cr_returned_date_sk = d_date_sk - and d_year =2000 - and cr_returning_addr_sk = ca_address_sk - group by cr_returning_customer_sk - ,ca_state ) - select c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'FL' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - limit 100; - --- end template query81.tpl query 66 in stream 7 --- start template query78.tpl query 67 in stream 7 -with /* TPC-DS query78.tpl 0.10 */ ws as - (select d_year AS ws_sold_year, ws_item_sk, - ws_bill_customer_sk ws_customer_sk, - sum(ws_quantity) ws_qty, - sum(ws_wholesale_cost) ws_wc, - sum(ws_sales_price) ws_sp - from web_sales - left join web_returns on wr_order_number=ws_order_number and ws_item_sk=wr_item_sk - join date_dim on ws_sold_date_sk = d_date_sk - where wr_order_number is null - group by d_year, ws_item_sk, ws_bill_customer_sk - ), -cs as - (select d_year AS cs_sold_year, cs_item_sk, - cs_bill_customer_sk cs_customer_sk, - sum(cs_quantity) cs_qty, - sum(cs_wholesale_cost) cs_wc, - sum(cs_sales_price) cs_sp - from catalog_sales - left join catalog_returns on cr_order_number=cs_order_number and cs_item_sk=cr_item_sk - join date_dim on cs_sold_date_sk = d_date_sk - where cr_order_number is null - group by d_year, cs_item_sk, cs_bill_customer_sk - ), -ss as - (select d_year AS ss_sold_year, ss_item_sk, - ss_customer_sk, - sum(ss_quantity) ss_qty, - sum(ss_wholesale_cost) ss_wc, - sum(ss_sales_price) ss_sp - from store_sales - left join store_returns on sr_ticket_number=ss_ticket_number and ss_item_sk=sr_item_sk - join date_dim on ss_sold_date_sk = d_date_sk - where sr_ticket_number is null - group by d_year, ss_item_sk, ss_customer_sk - ) - select -ss_sold_year, -round(ss_qty/(coalesce(ws_qty,0)+coalesce(cs_qty,0)),2) ratio, -ss_qty store_qty, ss_wc store_wholesale_cost, ss_sp store_sales_price, -coalesce(ws_qty,0)+coalesce(cs_qty,0) other_chan_qty, -coalesce(ws_wc,0)+coalesce(cs_wc,0) other_chan_wholesale_cost, -coalesce(ws_sp,0)+coalesce(cs_sp,0) other_chan_sales_price -from ss -left join ws on (ws_sold_year=ss_sold_year and ws_item_sk=ss_item_sk and ws_customer_sk=ss_customer_sk) -left join cs on (cs_sold_year=ss_sold_year and cs_item_sk=ss_item_sk and cs_customer_sk=ss_customer_sk) -where (coalesce(ws_qty,0)>0 or coalesce(cs_qty, 0)>0) and ss_sold_year=1998 -order by - ss_sold_year, - ss_qty desc, ss_wc desc, ss_sp desc, - other_chan_qty, - other_chan_wholesale_cost, - other_chan_sales_price, - ratio -limit 100; - --- end template query78.tpl query 67 in stream 7 --- start template query18a.tpl query 68 in stream 7 -with /* TPC-DS query18a.tpl 0.90 */ results as - (select i_item_id, - ca_country, - ca_state, - ca_county, - cast(cs_quantity as decimal(12,2)) agg1, - cast(cs_list_price as decimal(12,2)) agg2, - cast(cs_coupon_amt as decimal(12,2)) agg3, - cast(cs_sales_price as decimal(12,2)) agg4, - cast(cs_net_profit as decimal(12,2)) agg5, - cast(c_birth_year as decimal(12,2)) agg6, - cast(cd1.cd_dep_count as decimal(12,2)) agg7 - from catalog_sales, customer_demographics cd1, customer_demographics cd2, customer, customer_address, date_dim, item - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd1.cd_demo_sk and - cs_bill_customer_sk = c_customer_sk and - cd1.cd_gender = 'M' and - cd1.cd_education_status = 'Unknown' and - c_current_cdemo_sk = cd2.cd_demo_sk and - c_current_addr_sk = ca_address_sk and - c_birth_month in (4,7,6,10,2,9) and - d_year = 2001 and - ca_state in ('TX','CO','GA','TN','SC','AR','KS') - ) - select i_item_id, ca_country, ca_state, ca_county, agg1, agg2, agg3, agg4, agg5, agg6, agg7 - from ( - select i_item_id, ca_country, ca_state, ca_county, avg(agg1) agg1, - avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state, ca_county - union all - select i_item_id, ca_country, ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state - union all - select i_item_id, ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country - union all - select i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - ) foo - order by ca_country, ca_state, ca_county, i_item_id - limit 100; - --- end template query18a.tpl query 68 in stream 7 --- start template query36a.tpl query 69 in stream 7 -with /* TPC-DS query36a.tpl 0.21 */ results as - (select - sum(ss_net_profit) as ss_net_profit, sum(ss_ext_sales_price) as ss_ext_sales_price, - sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin - ,i_category - ,i_class - ,0 as g_category, 0 as g_class - from - store_sales - ,date_dim d1 - ,item - ,store - where - d1.d_year = 2001 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and s_state in ('MN','MI','FL','NM', - 'PA','MN','OH','GA') - group by i_category,i_class) - , - results_rollup as - (select gross_margin ,i_category ,i_class,0 as t_category, 0 as t_class, 0 as lochierarchy from results - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - i_category, NULL AS i_class, 0 as t_category, 1 as t_class, 1 as lochierarchy from results group by i_category - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - NULL AS i_category ,NULL AS i_class, 1 as t_category, 1 as t_class, 2 as lochierarchy from results) - select - gross_margin ,i_category ,i_class, lochierarchy,rank() over ( - partition by lochierarchy, case when t_class = 0 then i_category end - order by gross_margin asc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then i_category end - ,rank_within_parent - limit 100; - --- end template query36a.tpl query 69 in stream 7 --- start template query51.tpl query 70 in stream 7 -WITH /* TPC-DS query51.tpl 0.46 */ web_v1 as ( -select - ws_item_sk item_sk, d_date, - sum(sum(ws_sales_price)) - over (partition by ws_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from web_sales - ,date_dim -where ws_sold_date_sk=d_date_sk - and d_month_seq between 1210 and 1210+11 - and ws_item_sk is not NULL -group by ws_item_sk, d_date), -store_v1 as ( -select - ss_item_sk item_sk, d_date, - sum(sum(ss_sales_price)) - over (partition by ss_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from store_sales - ,date_dim -where ss_sold_date_sk=d_date_sk - and d_month_seq between 1210 and 1210+11 - and ss_item_sk is not NULL -group by ss_item_sk, d_date) - select * -from (select item_sk - ,d_date - ,web_sales - ,store_sales - ,max(web_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) web_cumulative - ,max(store_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) store_cumulative - from (select case when web.item_sk is not null then web.item_sk else store.item_sk end item_sk - ,case when web.d_date is not null then web.d_date else store.d_date end d_date - ,web.cume_sales web_sales - ,store.cume_sales store_sales - from web_v1 web full outer join store_v1 store on (web.item_sk = store.item_sk - and web.d_date = store.d_date) - )x )y -where web_cumulative > store_cumulative -order by item_sk - ,d_date -limit 100; - --- end template query51.tpl query 70 in stream 7 --- start template query56.tpl query 71 in stream 7 -with /* TPC-DS query56.tpl 0.83 */ ss as ( - select i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where i_item_id in (select - i_item_id -from item -where i_color in ('coral','lime','almond')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 2 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id), - cs as ( - select i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('coral','lime','almond')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 2 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id), - ws as ( - select i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('coral','lime','almond')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 2 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_item_id) - select i_item_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by total_sales, - i_item_id - limit 100; - --- end template query56.tpl query 71 in stream 7 --- start template query83.tpl query 72 in stream 7 -with /* TPC-DS query83.tpl 0.96 */ sr_items as - (select i_item_id item_id, - sum(sr_return_quantity) sr_item_qty - from store_returns, - item, - date_dim - where sr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2000-04-22','2000-10-08','2000-11-17'))) - and sr_returned_date_sk = d_date_sk - group by i_item_id), - cr_items as - (select i_item_id item_id, - sum(cr_return_quantity) cr_item_qty - from catalog_returns, - item, - date_dim - where cr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2000-04-22','2000-10-08','2000-11-17'))) - and cr_returned_date_sk = d_date_sk - group by i_item_id), - wr_items as - (select i_item_id item_id, - sum(wr_return_quantity) wr_item_qty - from web_returns, - item, - date_dim - where wr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2000-04-22','2000-10-08','2000-11-17'))) - and wr_returned_date_sk = d_date_sk - group by i_item_id) - select sr_items.item_id - ,sr_item_qty - ,sr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 sr_dev - ,cr_item_qty - ,cr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 cr_dev - ,wr_item_qty - ,wr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 wr_dev - ,(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 average - from sr_items - ,cr_items - ,wr_items - where sr_items.item_id=cr_items.item_id - and sr_items.item_id=wr_items.item_id - order by sr_items.item_id - ,sr_item_qty - limit 100; - --- end template query83.tpl query 72 in stream 7 --- start template query23.tpl query 73 in stream 7 -with /* TPC-DS query23.tpl 0.68 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (1999,1999+1,1999+2,1999+3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1999,1999+1,1999+2,1999+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * -from - max_store_sales)) - select sum(sales) - from (select cs_quantity*cs_list_price sales - from catalog_sales - ,date_dim - where d_year = 1999 - and d_moy = 1 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - union all - select ws_quantity*ws_list_price sales - from web_sales - ,date_dim - where d_year = 1999 - and d_moy = 1 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer)) - limit 100; -with /* TPC-DS query23.tpl 0.68 part2 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (1999,1999 + 1,1999 + 2,1999 + 3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1999,1999+1,1999+2,1999+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * - from max_store_sales)) - select c_last_name,c_first_name,sales - from (select c_last_name,c_first_name,sum(cs_quantity*cs_list_price) sales - from catalog_sales - ,customer - ,date_dim - where d_year = 1999 - and d_moy = 1 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and cs_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name - union all - select c_last_name,c_first_name,sum(ws_quantity*ws_list_price) sales - from web_sales - ,customer - ,date_dim - where d_year = 1999 - and d_moy = 1 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and ws_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name) - order by c_last_name,c_first_name,sales - limit 100; - --- end template query23.tpl query 73 in stream 7 --- start template query8.tpl query 74 in stream 7 -select /* TPC-DS query8.tpl 0.63 */ s_store_name - ,sum(ss_net_profit) - from store_sales - ,date_dim - ,store, - (select ca_zip - from ( - SELECT substring(ca_zip,1,5) ca_zip - FROM customer_address - WHERE substring(ca_zip,1,5) IN ( - '98054','93480','66655','19448','65152','70957', - '63596','70498','12820','56244','91474', - '53043','68043','67394','93722','76099', - '52876','58477','39104','85460','14500', - '37149','84105','65381','58980','38185', - '16904','56494','91549','84695','51870', - '11821','90346','55551','92958','96850', - '58785','19723','85664','95782','95140', - '55839','71976','49752','57887','37518', - '67728','28318','12578','47393','37558', - '46461','83952','24741','51217','33974', - '31730','34451','14542','66054','27742', - '50320','16427','84604','78603','89350', - '50849','82230','39669','32414','80686', - '43746','90808','95237','82222','82226', - '28711','25564','79740','73948','31674', - '52882','93420','41135','79896','98543', - '75280','64102','98542','56235','95942', - '90905','70195','81271','21384','55747', - '45665','57842','96887','23794','15299', - '42379','44992','17373','29973','32527', - '28212','95876','71058','33339','48424', - '44874','88726','60327','21307','65516', - '56612','42801','88280','30798','99021', - '40296','67893','40972','48882','32459', - '80451','13869','35444','56153','37169', - '33182','15551','92885','37538','36421', - '47865','76325','35261','95207','43365', - '12378','33050','47036','77342','73166', - '92991','59698','31994','21060','54343', - '33837','87783','15652','56584','79148', - '33205','22794','63136','53850','52227', - '81526','54553','11025','65552','81208', - '49453','11701','92144','39796','18215', - '17408','90470','31575','95701','33975', - '81520','79188','58664','52813','15222', - '34776','72108','60725','12823','29476', - '75040','48525','30488','93231','97960', - '38505','36905','73513','64560','95588', - '38395','98608','44769','97352','26911', - '62837','89826','14778','38360','49977', - '43859','35789','27305','86579','93414', - '73869','17375','93702','38404','40571', - '52932','85264','24914','33373','52166', - '14643','63974','60533','69002','72425', - '75737','41620','14032','39210','96288', - '68046','72235','45886','36386','96675', - '87912','24564','71468','25668','41090', - '54511','99501','60786','96419','46695', - '85716','38559','75487','10436','70447', - '10809','58878','55061','80028','76845', - '83334','46846','73670','51536','16229', - '24829','62084','88692','38788','58678', - '60293','36978','32795','85595','24050', - '83275','67317','87515','90780','75975', - '90894','77141','22483','21568','79418', - '64872','70180','90238','32805','32368', - '23169','77954','49928','49837','96461', - '50683','22030','42592','95208','21598', - '23257','50103','47389','47139','67428', - '27339','35292','30964','71479','29632', - '72884','87449','33498','81679','24033', - '67592','47803','11660','70464','74472', - '20242','15871','23787','22325','49131', - '37972','67957','83264','18580','45510', - '74254','78791','30989','88576','44483', - '39419','17662','22476','26942','40411', - '83568','69293','41272','17194','35627', - '38101','42872','74603','90541','55111', - '67717','50283','64932','18369','37501', - '61601','26968','32034','45840','17663', - '49517','23637','14530','10092','81174', - '83047','76440','16157','66702','28966', - '48069','86534','64363','69678','28090', - '49742','14030','95828','88153','81694', - '49769','23804','77549','31174','80969', - '63089','98469','88514','88942','21074', - '36389','92813','36852','55062','78800', - '51016','68249','10208','91459','48195', - '70684','17615','47385','57543') - intersect - select ca_zip - from (SELECT substring(ca_zip,1,5) ca_zip,count(*) cnt - FROM customer_address, customer - WHERE ca_address_sk = c_current_addr_sk and - c_preferred_cust_flag='Y' - group by ca_zip - having count(*) > 10)A1)A2) V1 - where ss_store_sk = s_store_sk - and ss_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 2002 - and (substring(s_zip,1,2) = substring(V1.ca_zip,1,2)) - group by s_store_name - order by s_store_name - limit 100; - --- end template query8.tpl query 74 in stream 7 --- start template query24.tpl query 75 in stream 7 -with /* TPC-DS query24.tpl 0.92 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_net_paid) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip -and s_market_id=7 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'beige' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; -with /* TPC-DS query24.tpl 0.92 part2 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_net_paid) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip - and s_market_id = 7 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'firebrick' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; - --- end template query24.tpl query 75 in stream 7 --- start template query63.tpl query 76 in stream 7 -select /* TPC-DS query63.tpl 0.27 */ * -from (select i_manager_id - ,sum(ss_sales_price) sum_sales - ,avg(sum(ss_sales_price)) over (partition by i_manager_id) avg_monthly_sales - from item - ,store_sales - ,date_dim - ,store - where ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and d_month_seq in (1201,1201+1,1201+2,1201+3,1201+4,1201+5,1201+6,1201+7,1201+8,1201+9,1201+10,1201+11) - and (( i_category in ('Books','Children','Electronics') - and i_class in ('personal','portable','reference','self-help') - and i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) - or( i_category in ('Women','Music','Men') - and i_class in ('accessories','classical','fragrances','pants') - and i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manager_id, d_moy) tmp1 -where case when avg_monthly_sales > 0 then abs (sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 -order by i_manager_id - ,avg_monthly_sales - ,sum_sales -limit 100; - --- end template query63.tpl query 76 in stream 7 --- start template query1.tpl query 77 in stream 7 -with /* TPC-DS query1.tpl 0.12 */ customer_total_return as -(select sr_customer_sk as ctr_customer_sk -,sr_store_sk as ctr_store_sk -,sum(SR_REFUNDED_CASH) as ctr_total_return -from store_returns -,date_dim -where sr_returned_date_sk = d_date_sk -and d_year =1999 -group by sr_customer_sk -,sr_store_sk) - select c_customer_id -from customer_total_return ctr1 -,store -,customer -where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 -from customer_total_return ctr2 -where ctr1.ctr_store_sk = ctr2.ctr_store_sk) -and s_store_sk = ctr1.ctr_store_sk -and s_state = 'LA' -and ctr1.ctr_customer_sk = c_customer_sk -order by c_customer_id -limit 100; - --- end template query1.tpl query 77 in stream 7 --- start template query12.tpl query 78 in stream 7 -select /* TPC-DS query12.tpl 0.64 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ws_ext_sales_price) as itemrevenue - ,sum(ws_ext_sales_price)*100/sum(sum(ws_ext_sales_price)) over - (partition by i_class) as revenueratio -from - web_sales - ,item - ,date_dim -where - ws_item_sk = i_item_sk - and i_category in ('Music', 'Books', 'Home') - and ws_sold_date_sk = d_date_sk - and d_date between cast('2002-06-14' as date) - and dateadd(day,30,cast('2002-06-14' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query12.tpl query 78 in stream 7 --- start template query68.tpl query 79 in stream 7 -select /* TPC-DS query68.tpl 0.95 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,extended_price - ,extended_tax - ,list_price - from (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_ext_sales_price) extended_price - ,sum(ss_ext_list_price) list_price - ,sum(ss_ext_tax) extended_tax - from store_sales - ,date_dim - ,store - ,household_demographics - ,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_dep_count = 0 or - household_demographics.hd_vehicle_count= 4) - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_city in ('Franklin','Highland Park') - group by ss_ticket_number - ,ss_customer_sk - ,ss_addr_sk,ca_city) dn - ,customer - ,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,ss_ticket_number - limit 100; - --- end template query68.tpl query 79 in stream 7 --- start template query66.tpl query 80 in stream 7 -select /* TPC-DS query66.tpl 0.39 */ - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - ,sum(jan_sales) as jan_sales - ,sum(feb_sales) as feb_sales - ,sum(mar_sales) as mar_sales - ,sum(apr_sales) as apr_sales - ,sum(may_sales) as may_sales - ,sum(jun_sales) as jun_sales - ,sum(jul_sales) as jul_sales - ,sum(aug_sales) as aug_sales - ,sum(sep_sales) as sep_sales - ,sum(oct_sales) as oct_sales - ,sum(nov_sales) as nov_sales - ,sum(dec_sales) as dec_sales - ,sum(jan_sales/w_warehouse_sq_ft) as jan_sales_per_sq_foot - ,sum(feb_sales/w_warehouse_sq_ft) as feb_sales_per_sq_foot - ,sum(mar_sales/w_warehouse_sq_ft) as mar_sales_per_sq_foot - ,sum(apr_sales/w_warehouse_sq_ft) as apr_sales_per_sq_foot - ,sum(may_sales/w_warehouse_sq_ft) as may_sales_per_sq_foot - ,sum(jun_sales/w_warehouse_sq_ft) as jun_sales_per_sq_foot - ,sum(jul_sales/w_warehouse_sq_ft) as jul_sales_per_sq_foot - ,sum(aug_sales/w_warehouse_sq_ft) as aug_sales_per_sq_foot - ,sum(sep_sales/w_warehouse_sq_ft) as sep_sales_per_sq_foot - ,sum(oct_sales/w_warehouse_sq_ft) as oct_sales_per_sq_foot - ,sum(nov_sales/w_warehouse_sq_ft) as nov_sales_per_sq_foot - ,sum(dec_sales/w_warehouse_sq_ft) as dec_sales_per_sq_foot - ,sum(jan_net) as jan_net - ,sum(feb_net) as feb_net - ,sum(mar_net) as mar_net - ,sum(apr_net) as apr_net - ,sum(may_net) as may_net - ,sum(jun_net) as jun_net - ,sum(jul_net) as jul_net - ,sum(aug_net) as aug_net - ,sum(sep_net) as sep_net - ,sum(oct_net) as oct_net - ,sum(nov_net) as nov_net - ,sum(dec_net) as dec_net - from ( - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'MSC' || ',' || 'ORIENTAL' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then ws_sales_price* ws_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then ws_sales_price* ws_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then ws_sales_price* ws_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then ws_sales_price* ws_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then ws_sales_price* ws_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then ws_sales_price* ws_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then ws_sales_price* ws_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then ws_sales_price* ws_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then ws_sales_price* ws_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then ws_sales_price* ws_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then ws_sales_price* ws_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then ws_sales_price* ws_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then ws_net_paid_inc_ship_tax * ws_quantity else 0 end) as dec_net - from - web_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - ws_warehouse_sk = w_warehouse_sk - and ws_sold_date_sk = d_date_sk - and ws_sold_time_sk = t_time_sk - and ws_ship_mode_sk = sm_ship_mode_sk - and d_year = 1999 - and t_time between 50190 and 50190+28800 - and sm_carrier in ('MSC','ORIENTAL') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - union all - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'MSC' || ',' || 'ORIENTAL' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then cs_ext_sales_price* cs_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then cs_ext_sales_price* cs_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then cs_ext_sales_price* cs_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then cs_ext_sales_price* cs_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then cs_ext_sales_price* cs_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then cs_ext_sales_price* cs_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then cs_ext_sales_price* cs_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then cs_ext_sales_price* cs_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then cs_ext_sales_price* cs_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then cs_ext_sales_price* cs_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then cs_ext_sales_price* cs_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then cs_ext_sales_price* cs_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then cs_net_paid_inc_ship * cs_quantity else 0 end) as dec_net - from - catalog_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and cs_sold_time_sk = t_time_sk - and cs_ship_mode_sk = sm_ship_mode_sk - and d_year = 1999 - and t_time between 50190 AND 50190+28800 - and sm_carrier in ('MSC','ORIENTAL') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - ) x - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - order by w_warehouse_name - limit 100; - --- end template query66.tpl query 80 in stream 7 --- start template query67a.tpl query 81 in stream 7 -with /* TPC-DS query67a.tpl 0.35 */ results as -( select i_category ,i_class ,i_brand ,i_product_name ,d_year ,d_qoy ,d_moy ,s_store_id - ,sum(coalesce(ss_sales_price*ss_quantity,0)) sumsales - from store_sales ,date_dim ,store ,item - where ss_sold_date_sk=d_date_sk - and ss_item_sk=i_item_sk - and ss_store_sk = s_store_sk - and d_month_seq between 1221 and 1221 + 11 - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy,s_store_id) - , - results_rollup as - (select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, s_store_id, sumsales - from results - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy - union all - select i_category, i_class, i_brand, i_product_name, d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year - union all - select i_category, i_class, i_brand, i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name - union all - select i_category, i_class, i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand - union all - select i_category, i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class - union all - select i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category - union all - select null i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results) - - select * -from (select i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rank() over (partition by i_category order by sumsales desc) rk - from results_rollup) dw2 -where rk <= 100 -order by i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rk -limit 100; - --- end template query67a.tpl query 81 in stream 7 --- start template query77a.tpl query 82 in stream 7 -with /* TPC-DS query77a.tpl 0.78 */ ss as - (select s_store_sk, - sum(ss_ext_sales_price) as sales, - sum(ss_net_profit) as profit - from store_sales, - date_dim, - store - where ss_sold_date_sk = d_date_sk - and d_date between cast('1999-08-11' as date) - and dateadd(day,30,cast('1999-08-11' as date)) - and ss_store_sk = s_store_sk - group by s_store_sk) - , - sr as - (select s_store_sk, - sum(sr_return_amt) as returns, - sum(sr_net_loss) as profit_loss - from store_returns, - date_dim, - store - where sr_returned_date_sk = d_date_sk - and d_date between cast('1999-08-11' as date) - and dateadd(day,30,cast('1999-08-11' as date)) - and sr_store_sk = s_store_sk - group by s_store_sk), - cs as - (select cs_call_center_sk, - sum(cs_ext_sales_price) as sales, - sum(cs_net_profit) as profit - from catalog_sales, - date_dim - where cs_sold_date_sk = d_date_sk - and d_date between cast('1999-08-11' as date) - and dateadd(day,30,cast('1999-08-11' as date)) - group by cs_call_center_sk - ), - cr as - (select cr_call_center_sk, - sum(cr_return_amount) as returns, - sum(cr_net_loss) as profit_loss - from catalog_returns, - date_dim - where cr_returned_date_sk = d_date_sk - and d_date between cast('1999-08-11' as date) - and dateadd(day,30,cast('1999-08-11' as date)) - group by cr_call_center_sk), - ws as - ( select wp_web_page_sk, - sum(ws_ext_sales_price) as sales, - sum(ws_net_profit) as profit - from web_sales, - date_dim, - web_page - where ws_sold_date_sk = d_date_sk - and d_date between cast('1999-08-11' as date) - and dateadd(day,30,cast('1999-08-11' as date)) - and ws_web_page_sk = wp_web_page_sk - group by wp_web_page_sk), - wr as - (select wp_web_page_sk, - sum(wr_return_amt) as returns, - sum(wr_net_loss) as profit_loss - from web_returns, - date_dim, - web_page - where wr_returned_date_sk = d_date_sk - and d_date between cast('1999-08-11' as date) - and dateadd(day,30,cast('1999-08-11' as date)) - and wr_web_page_sk = wp_web_page_sk - group by wp_web_page_sk) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , ss.s_store_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ss left join sr - on ss.s_store_sk = sr.s_store_sk - union all - select 'catalog channel' as channel - , cs_call_center_sk as id - , sales - , returns - , (profit - profit_loss) as profit - from cs - , cr - union all - select 'web channel' as channel - , ws.wp_web_page_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ws left join wr - on ws.wp_web_page_sk = wr.wp_web_page_sk - ) x - group by channel, id ) - - select * - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results -) foo -order by channel, id - limit 100; - --- end template query77a.tpl query 82 in stream 7 --- start template query15.tpl query 83 in stream 7 -select /* TPC-DS query15.tpl 0.57 */ ca_zip - ,sum(cs_sales_price) - from catalog_sales - ,customer - ,customer_address - ,date_dim - where cs_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', - '85392', '85460', '80348', '81792') - or ca_state in ('CA','WA','GA') - or cs_sales_price > 500) - and cs_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 2001 - group by ca_zip - order by ca_zip - limit 100; - --- end template query15.tpl query 83 in stream 7 --- start template query88.tpl query 84 in stream 7 -select /* TPC-DS query88.tpl 0.66 */ * -from - (select count(*) h8_30_to_9 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s1, - (select count(*) h9_to_9_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s2, - (select count(*) h9_30_to_10 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s3, - (select count(*) h10_to_10_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s4, - (select count(*) h10_30_to_11 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s5, - (select count(*) h11_to_11_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s6, - (select count(*) h11_30_to_12 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s7, - (select count(*) h12_to_12_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 12 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or - (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or - (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) - and store.s_store_name = 'ese') s8 -; - --- end template query88.tpl query 84 in stream 7 --- start template query65.tpl query 85 in stream 7 -select /* TPC-DS query65.tpl 0.71 */ - s_store_name, - i_item_desc, - sc.revenue, - i_current_price, - i_wholesale_cost, - i_brand - from store, item, - (select ss_store_sk, avg(revenue) as ave - from - (select ss_store_sk, ss_item_sk, - sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1183 and 1183+11 - group by ss_store_sk, ss_item_sk) sa - group by ss_store_sk) sb, - (select ss_store_sk, ss_item_sk, sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1183 and 1183+11 - group by ss_store_sk, ss_item_sk) sc - where sb.ss_store_sk = sc.ss_store_sk and - sc.revenue <= 0.1 * sb.ave and - s_store_sk = sc.ss_store_sk and - i_item_sk = sc.ss_item_sk - order by s_store_name, i_item_desc -limit 100; - --- end template query65.tpl query 85 in stream 7 --- start template query59.tpl query 86 in stream 7 -with /* TPC-DS query59.tpl 0.30 */ wss as - (select d_week_seq, - ss_store_sk, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - group by d_week_seq,ss_store_sk - ) - select s_store_name1,s_store_id1,d_week_seq1 - ,sun_sales1/sun_sales2,mon_sales1/mon_sales2 - ,tue_sales1/tue_sales2,wed_sales1/wed_sales2,thu_sales1/thu_sales2 - ,fri_sales1/fri_sales2,sat_sales1/sat_sales2 - from - (select s_store_name s_store_name1,wss.d_week_seq d_week_seq1 - ,s_store_id s_store_id1,sun_sales sun_sales1 - ,mon_sales mon_sales1,tue_sales tue_sales1 - ,wed_sales wed_sales1,thu_sales thu_sales1 - ,fri_sales fri_sales1,sat_sales sat_sales1 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1191 and 1191 + 11) y, - (select s_store_name s_store_name2,wss.d_week_seq d_week_seq2 - ,s_store_id s_store_id2,sun_sales sun_sales2 - ,mon_sales mon_sales2,tue_sales tue_sales2 - ,wed_sales wed_sales2,thu_sales thu_sales2 - ,fri_sales fri_sales2,sat_sales sat_sales2 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1191+ 12 and 1191 + 23) x - where s_store_id1=s_store_id2 - and d_week_seq1=d_week_seq2-52 - order by s_store_name1,s_store_id1,d_week_seq1 -limit 100; - --- end template query59.tpl query 86 in stream 7 --- start template query96.tpl query 87 in stream 7 -select /* TPC-DS query96.tpl 0.1 */ count(*) -from store_sales - ,household_demographics - ,time_dim, store -where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 15 - and time_dim.t_minute >= 30 - and household_demographics.hd_dep_count = 9 - and store.s_store_name = 'ese' -order by count(*) -limit 100; - --- end template query96.tpl query 87 in stream 7 --- start template query54.tpl query 88 in stream 7 -with /* TPC-DS query54.tpl 0.81 */ my_customers as ( - select distinct c_customer_sk - , c_current_addr_sk - from - ( select cs_sold_date_sk sold_date_sk, - cs_bill_customer_sk customer_sk, - cs_item_sk item_sk - from catalog_sales - union all - select ws_sold_date_sk sold_date_sk, - ws_bill_customer_sk customer_sk, - ws_item_sk item_sk - from web_sales - ) cs_or_ws_sales, - item, - date_dim, - customer - where sold_date_sk = d_date_sk - and item_sk = i_item_sk - and i_category = 'Jewelry' - and i_class = 'pendants' - and c_customer_sk = cs_or_ws_sales.customer_sk - and d_moy = 3 - and d_year = 2001 - ) - , my_revenue as ( - select c_customer_sk, - sum(ss_ext_sales_price) as revenue - from my_customers, - store_sales, - customer_address, - store, - date_dim - where c_current_addr_sk = ca_address_sk - and ca_county = s_county - and ca_state = s_state - and ss_sold_date_sk = d_date_sk - and c_customer_sk = ss_customer_sk - and d_month_seq between (select distinct d_month_seq+1 - from date_dim where d_year = 2001 and d_moy = 3) - and (select distinct d_month_seq+3 - from date_dim where d_year = 2001 and d_moy = 3) - group by c_customer_sk - ) - , segments as - (select cast((revenue/50) as bigint) as segment - from my_revenue - ) - select segment, count(*) as num_customers, segment*50 as segment_base - from segments - group by segment - order by segment, num_customers - limit 100; - --- end template query54.tpl query 88 in stream 7 --- start template query95.tpl query 89 in stream 7 -with /* TPC-DS query95.tpl 0.43 */ ws_wh as -(select ws1.ws_order_number,ws1.ws_warehouse_sk wh1,ws2.ws_warehouse_sk wh2 - from web_sales ws1,web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) - select - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2001-2-01' and - dateadd(day,60,cast('2001-2-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'MD' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and ws1.ws_order_number in (select ws_order_number - from ws_wh) -and ws1.ws_order_number in (select wr_order_number - from web_returns,ws_wh - where wr_order_number = ws_wh.ws_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query95.tpl query 89 in stream 7 --- start template query93.tpl query 90 in stream 7 -select /* TPC-DS query93.tpl 0.52 */ ss_customer_sk - ,sum(act_sales) sumsales - from (select ss_item_sk - ,ss_ticket_number - ,ss_customer_sk - ,case when sr_return_quantity is not null then (ss_quantity-sr_return_quantity)*ss_sales_price - else (ss_quantity*ss_sales_price) end act_sales - from store_sales left outer join store_returns on (sr_item_sk = ss_item_sk - and sr_ticket_number = ss_ticket_number) - ,reason - where sr_reason_sk = r_reason_sk - and r_reason_desc = 'reason 58') t - group by ss_customer_sk - order by sumsales, ss_customer_sk -limit 100; - --- end template query93.tpl query 90 in stream 7 --- start template query91.tpl query 91 in stream 7 -select /* TPC-DS query91.tpl 0.13 */ - cc_call_center_id Call_Center, - cc_name Call_Center_Name, - cc_manager Manager, - sum(cr_net_loss) Returns_Loss -from - call_center, - catalog_returns, - date_dim, - customer, - customer_address, - customer_demographics, - household_demographics -where - cr_call_center_sk = cc_call_center_sk -and cr_returned_date_sk = d_date_sk -and cr_returning_customer_sk= c_customer_sk -and cd_demo_sk = c_current_cdemo_sk -and hd_demo_sk = c_current_hdemo_sk -and ca_address_sk = c_current_addr_sk -and d_year = 2002 -and d_moy = 12 -and ( (cd_marital_status = 'M' and cd_education_status = 'Unknown') - or(cd_marital_status = 'W' and cd_education_status = 'Advanced Degree')) -and hd_buy_potential like '5001-10000%' -and ca_gmt_offset = -7 -group by cc_call_center_id,cc_name,cc_manager,cd_marital_status,cd_education_status -order by sum(cr_net_loss) desc; - --- end template query91.tpl query 91 in stream 7 --- start template query74.tpl query 92 in stream 7 -with /* TPC-DS query74.tpl 0.76 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,sum(ss_net_paid) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (2001,2001+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,sum(ws_net_paid) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - and d_year in (2001,2001+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - ) - select - t_s_secyear.customer_id, t_s_secyear.customer_first_name, t_s_secyear.customer_last_name - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.year = 2001 - and t_s_secyear.year = 2001+1 - and t_w_firstyear.year = 2001 - and t_w_secyear.year = 2001+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - order by 1,2,3 -limit 100; - --- end template query74.tpl query 92 in stream 7 --- start template query94.tpl query 93 in stream 7 -select /* TPC-DS query94.tpl 0.17 */ - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2001-4-01' and - dateadd(day,60,cast('2001-4-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'PA' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and exists (select * - from web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) -and not exists(select * - from web_returns wr1 - where ws1.ws_order_number = wr1.wr_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query94.tpl query 93 in stream 7 --- start template query16.tpl query 94 in stream 7 -select /* TPC-DS query16.tpl 0.25 */ - count(distinct cs_order_number) as "order count" - ,sum(cs_ext_ship_cost) as "total shipping cost" - ,sum(cs_net_profit) as "total net profit" -from - catalog_sales cs1 - ,date_dim - ,customer_address - ,call_center -where - d_date between '2001-2-01' and - dateadd(day, 60, cast('2001-2-01' as date)) -and cs1.cs_ship_date_sk = d_date_sk -and cs1.cs_ship_addr_sk = ca_address_sk -and ca_state = 'TX' -and cs1.cs_call_center_sk = cc_call_center_sk -and cc_county in ('Jefferson Davis Parish','Bronx County','Dauphin County','Richland County', - 'Barrow County' -) -and exists (select * - from catalog_sales cs2 - where cs1.cs_order_number = cs2.cs_order_number - and cs1.cs_warehouse_sk <> cs2.cs_warehouse_sk) -and not exists(select * - from catalog_returns cr1 - where cs1.cs_order_number = cr1.cr_order_number) -order by count(distinct cs_order_number) -limit 100; - --- end template query16.tpl query 94 in stream 7 --- start template query90.tpl query 95 in stream 7 -select /* TPC-DS query90.tpl 0.40 */ cast(amc as decimal(15,4))/cast(pmc as decimal(15,4)) am_pm_ratio - from ( select count(*) amc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 9 and 9+1 - and household_demographics.hd_dep_count = 8 - and web_page.wp_char_count between 5000 and 5200) at, - ( select count(*) pmc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 16 and 16+1 - and household_demographics.hd_dep_count = 8 - and web_page.wp_char_count between 5000 and 5200) pt - order by am_pm_ratio - limit 100; - --- end template query90.tpl query 95 in stream 7 --- start template query57.tpl query 96 in stream 7 -with /* TPC-DS query57.tpl 0.70 */ v1 as( - select i_category, i_brand, - cc_name, - d_year, d_moy, - sum(cs_sales_price) sum_sales, - avg(sum(cs_sales_price)) over - (partition by i_category, i_brand, - cc_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - cc_name - order by d_year, d_moy) rn - from item, catalog_sales, date_dim, call_center - where cs_item_sk = i_item_sk and - cs_sold_date_sk = d_date_sk and - cc_call_center_sk= cs_call_center_sk and - ( - d_year = 2000 or - ( d_year = 2000-1 and d_moy =12) or - ( d_year = 2000+1 and d_moy =1) - ) - group by i_category, i_brand, - cc_name , d_year, d_moy), - v2 as( - select v1.i_category, v1.i_brand, v1.cc_name - ,v1.d_year, v1.d_moy - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1. cc_name = v1_lag. cc_name and - v1. cc_name = v1_lead. cc_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 2000 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, psum - limit 100; - --- end template query57.tpl query 96 in stream 7 --- start template query22a.tpl query 97 in stream 7 -with /* TPC-DS query22a.tpl 0.55 */ results as -(select i_product_name - ,i_brand - ,i_class - ,i_category - ,avg(inv_quantity_on_hand) qoh - from inventory - ,date_dim - ,item --- ,warehouse - where inv_date_sk=d_date_sk - and inv_item_sk=i_item_sk --- and inv_warehouse_sk = w_warehouse_sk - and d_month_seq between 1211 and 1211 + 11 - group by i_product_name,i_brand,i_class,i_category), -results_rollup as -(select i_product_name, i_brand, i_class, i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class,i_category -union all -select i_product_name, i_brand, i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class -union all -select i_product_name, i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand -union all -select i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name -union all -select null i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results) - select i_product_name, i_brand, i_class, i_category,qoh - from results_rollup - order by qoh, i_product_name, i_brand, i_class, i_category -limit 100; - --- end template query22a.tpl query 97 in stream 7 --- start template query50.tpl query 98 in stream 7 -select /* TPC-DS query50.tpl 0.60 */ - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 30) and - (sr_returned_date_sk - ss_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 60) and - (sr_returned_date_sk - ss_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 90) and - (sr_returned_date_sk - ss_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - store_sales - ,store_returns - ,store - ,date_dim d1 - ,date_dim d2 -where - d2.d_year = 1999 -and d2.d_moy = 8 -and ss_ticket_number = sr_ticket_number -and ss_item_sk = sr_item_sk -and ss_sold_date_sk = d1.d_date_sk -and sr_returned_date_sk = d2.d_date_sk -and ss_customer_sk = sr_customer_sk -and ss_store_sk = s_store_sk -group by - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -order by s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -limit 100; - --- end template query50.tpl query 98 in stream 7 --- start template query27a.tpl query 99 in stream 7 -with /* TPC-DS query27a.tpl 0.16 */ results as - (select i_item_id, - s_state, 0 as g_state, - ss_quantity agg1, - ss_list_price agg2, - ss_coupon_amt agg3, - ss_sales_price agg4 - from store_sales, customer_demographics, date_dim, store, item - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_store_sk = s_store_sk and - ss_cdemo_sk = cd_demo_sk and - cd_gender = 'M' and - cd_marital_status = 'W' and - cd_education_status = 'Advanced Degree' and - d_year = 2001 and - s_state in ('WA','PA', 'AL', 'IN', 'LA', 'OH') - ) - - select i_item_id, - s_state, g_state, agg1, agg2, agg3, agg4 - from ( - select i_item_id, s_state, 0 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4 from results - group by i_item_id, s_state - union all - select i_item_id, NULL AS s_state, 1 AS g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as s_state, 1 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - ) foo - order by i_item_id, s_state - limit 100; - --- end template query27a.tpl query 99 in stream 7 diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/1TB/queries/query_8.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/1TB/queries/query_8.sql deleted file mode 100644 index ce941d14..00000000 --- a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/1TB/queries/query_8.sql +++ /dev/null @@ -1,5027 +0,0 @@ --- start template query57.tpl query 1 in stream 8 -with /* TPC-DS query57.tpl 0.70 */ v1 as( - select i_category, i_brand, - cc_name, - d_year, d_moy, - sum(cs_sales_price) sum_sales, - avg(sum(cs_sales_price)) over - (partition by i_category, i_brand, - cc_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - cc_name - order by d_year, d_moy) rn - from item, catalog_sales, date_dim, call_center - where cs_item_sk = i_item_sk and - cs_sold_date_sk = d_date_sk and - cc_call_center_sk= cs_call_center_sk and - ( - d_year = 2000 or - ( d_year = 2000-1 and d_moy =12) or - ( d_year = 2000+1 and d_moy =1) - ) - group by i_category, i_brand, - cc_name , d_year, d_moy), - v2 as( - select v1.i_category, v1.i_brand, v1.cc_name - ,v1.d_year, v1.d_moy - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1. cc_name = v1_lag. cc_name and - v1. cc_name = v1_lead. cc_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 2000 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, sum_sales - limit 100; - --- end template query57.tpl query 1 in stream 8 --- start template query29.tpl query 2 in stream 8 -select /* TPC-DS query29.tpl 0.53 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,sum(ss_quantity) as store_sales_quantity - ,sum(sr_return_quantity) as store_returns_quantity - ,sum(cs_quantity) as catalog_sales_quantity - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 2000 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 4 + 3 - and d2.d_year = 2000 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_year in (2000,2000+1,2000+2) - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query29.tpl query 2 in stream 8 --- start template query24.tpl query 3 in stream 8 -with /* TPC-DS query24.tpl 0.92 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_sales_price) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip -and s_market_id=9 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'sky' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; -with /* TPC-DS query24.tpl 0.92 part2 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_sales_price) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip - and s_market_id = 9 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'seashell' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; - --- end template query24.tpl query 3 in stream 8 --- start template query76.tpl query 4 in stream 8 -select /* TPC-DS query76.tpl 0.99 */ channel, col_name, d_year, d_qoy, i_category, COUNT(*) sales_cnt, SUM(ext_sales_price) sales_amt FROM ( - SELECT 'store' as channel, 'ss_store_sk' col_name, d_year, d_qoy, i_category, ss_ext_sales_price ext_sales_price - FROM store_sales, item, date_dim - WHERE ss_store_sk IS NULL - AND ss_sold_date_sk=d_date_sk - AND ss_item_sk=i_item_sk - UNION ALL - SELECT 'web' as channel, 'ws_web_page_sk' col_name, d_year, d_qoy, i_category, ws_ext_sales_price ext_sales_price - FROM web_sales, item, date_dim - WHERE ws_web_page_sk IS NULL - AND ws_sold_date_sk=d_date_sk - AND ws_item_sk=i_item_sk - UNION ALL - SELECT 'catalog' as channel, 'cs_ship_cdemo_sk' col_name, d_year, d_qoy, i_category, cs_ext_sales_price ext_sales_price - FROM catalog_sales, item, date_dim - WHERE cs_ship_cdemo_sk IS NULL - AND cs_sold_date_sk=d_date_sk - AND cs_item_sk=i_item_sk) foo -GROUP BY channel, col_name, d_year, d_qoy, i_category -ORDER BY channel, col_name, d_year, d_qoy, i_category -limit 100; - --- end template query76.tpl query 4 in stream 8 --- start template query37.tpl query 5 in stream 8 -select /* TPC-DS query37.tpl 0.31 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, catalog_sales - where i_current_price between 48 and 48 + 30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('2000-07-14' as date) and dateadd(day,60,cast('2000-07-14' as date)) - and i_manufact_id in (878,994,776,691) - and inv_quantity_on_hand between 100 and 500 - and cs_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query37.tpl query 5 in stream 8 --- start template query66.tpl query 6 in stream 8 -select /* TPC-DS query66.tpl 0.39 */ - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - ,sum(jan_sales) as jan_sales - ,sum(feb_sales) as feb_sales - ,sum(mar_sales) as mar_sales - ,sum(apr_sales) as apr_sales - ,sum(may_sales) as may_sales - ,sum(jun_sales) as jun_sales - ,sum(jul_sales) as jul_sales - ,sum(aug_sales) as aug_sales - ,sum(sep_sales) as sep_sales - ,sum(oct_sales) as oct_sales - ,sum(nov_sales) as nov_sales - ,sum(dec_sales) as dec_sales - ,sum(jan_sales/w_warehouse_sq_ft) as jan_sales_per_sq_foot - ,sum(feb_sales/w_warehouse_sq_ft) as feb_sales_per_sq_foot - ,sum(mar_sales/w_warehouse_sq_ft) as mar_sales_per_sq_foot - ,sum(apr_sales/w_warehouse_sq_ft) as apr_sales_per_sq_foot - ,sum(may_sales/w_warehouse_sq_ft) as may_sales_per_sq_foot - ,sum(jun_sales/w_warehouse_sq_ft) as jun_sales_per_sq_foot - ,sum(jul_sales/w_warehouse_sq_ft) as jul_sales_per_sq_foot - ,sum(aug_sales/w_warehouse_sq_ft) as aug_sales_per_sq_foot - ,sum(sep_sales/w_warehouse_sq_ft) as sep_sales_per_sq_foot - ,sum(oct_sales/w_warehouse_sq_ft) as oct_sales_per_sq_foot - ,sum(nov_sales/w_warehouse_sq_ft) as nov_sales_per_sq_foot - ,sum(dec_sales/w_warehouse_sq_ft) as dec_sales_per_sq_foot - ,sum(jan_net) as jan_net - ,sum(feb_net) as feb_net - ,sum(mar_net) as mar_net - ,sum(apr_net) as apr_net - ,sum(may_net) as may_net - ,sum(jun_net) as jun_net - ,sum(jul_net) as jul_net - ,sum(aug_net) as aug_net - ,sum(sep_net) as sep_net - ,sum(oct_net) as oct_net - ,sum(nov_net) as nov_net - ,sum(dec_net) as dec_net - from ( - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'BOXBUNDLES' || ',' || 'GERMA' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then ws_ext_list_price* ws_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then ws_ext_list_price* ws_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then ws_ext_list_price* ws_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then ws_ext_list_price* ws_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then ws_ext_list_price* ws_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then ws_ext_list_price* ws_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then ws_ext_list_price* ws_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then ws_ext_list_price* ws_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then ws_ext_list_price* ws_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then ws_ext_list_price* ws_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then ws_ext_list_price* ws_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then ws_ext_list_price* ws_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then ws_net_profit * ws_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then ws_net_profit * ws_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then ws_net_profit * ws_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then ws_net_profit * ws_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then ws_net_profit * ws_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then ws_net_profit * ws_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then ws_net_profit * ws_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then ws_net_profit * ws_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then ws_net_profit * ws_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then ws_net_profit * ws_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then ws_net_profit * ws_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then ws_net_profit * ws_quantity else 0 end) as dec_net - from - web_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - ws_warehouse_sk = w_warehouse_sk - and ws_sold_date_sk = d_date_sk - and ws_sold_time_sk = t_time_sk - and ws_ship_mode_sk = sm_ship_mode_sk - and d_year = 1999 - and t_time between 55727 and 55727+28800 - and sm_carrier in ('BOXBUNDLES','GERMA') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - union all - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'BOXBUNDLES' || ',' || 'GERMA' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then cs_ext_list_price* cs_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then cs_ext_list_price* cs_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then cs_ext_list_price* cs_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then cs_ext_list_price* cs_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then cs_ext_list_price* cs_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then cs_ext_list_price* cs_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then cs_ext_list_price* cs_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then cs_ext_list_price* cs_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then cs_ext_list_price* cs_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then cs_ext_list_price* cs_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then cs_ext_list_price* cs_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then cs_ext_list_price* cs_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then cs_net_profit * cs_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then cs_net_profit * cs_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then cs_net_profit * cs_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then cs_net_profit * cs_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then cs_net_profit * cs_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then cs_net_profit * cs_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then cs_net_profit * cs_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then cs_net_profit * cs_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then cs_net_profit * cs_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then cs_net_profit * cs_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then cs_net_profit * cs_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then cs_net_profit * cs_quantity else 0 end) as dec_net - from - catalog_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and cs_sold_time_sk = t_time_sk - and cs_ship_mode_sk = sm_ship_mode_sk - and d_year = 1999 - and t_time between 55727 AND 55727+28800 - and sm_carrier in ('BOXBUNDLES','GERMA') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - ) x - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - order by w_warehouse_name - limit 100; - --- end template query66.tpl query 6 in stream 8 --- start template query60.tpl query 7 in stream 8 -with /* TPC-DS query60.tpl 0.29 */ ss as ( - select - i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Men')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 9 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -8 - group by i_item_id), - cs as ( - select - i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Men')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 9 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -8 - group by i_item_id), - ws as ( - select - i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Men')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2001 - and d_moy = 9 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -8 - group by i_item_id) - select - i_item_id -,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by i_item_id - ,total_sales - limit 100; - --- end template query60.tpl query 7 in stream 8 --- start template query98.tpl query 8 in stream 8 -select /* TPC-DS query98.tpl 0.32 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ss_ext_sales_price) as itemrevenue - ,sum(ss_ext_sales_price)*100/sum(sum(ss_ext_sales_price)) over - (partition by i_class) as revenueratio -from - store_sales - ,item - ,date_dim -where - ss_item_sk = i_item_sk - and i_category in ('Shoes', 'Sports', 'Women') - and ss_sold_date_sk = d_date_sk - and d_date between cast('2002-01-26' as date) - and dateadd(day,30,cast('2002-01-26' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio; - --- end template query98.tpl query 8 in stream 8 --- start template query80a.tpl query 9 in stream 8 -with /* TPC-DS query80a.tpl 0.6 */ ssr as - (select s_store_id as store_id, - sum(ss_ext_sales_price) as sales, - sum(coalesce(sr_return_amt, 0)) as returns, - sum(ss_net_profit - coalesce(sr_net_loss, 0)) as profit - from store_sales left outer join store_returns on - (ss_item_sk = sr_item_sk and ss_ticket_number = sr_ticket_number), - date_dim, - store, - item, - promotion - where ss_sold_date_sk = d_date_sk - and d_date between cast('1999-08-21' as date) - and dateadd(day,30,cast('1999-08-21' as date)) - and ss_store_sk = s_store_sk - and ss_item_sk = i_item_sk - and i_current_price > 50 - and ss_promo_sk = p_promo_sk - and p_channel_tv = 'N' - group by s_store_id) - , - csr as - (select cp_catalog_page_id as catalog_page_id, - sum(cs_ext_sales_price) as sales, - sum(coalesce(cr_return_amount, 0)) as returns, - sum(cs_net_profit - coalesce(cr_net_loss, 0)) as profit - from catalog_sales left outer join catalog_returns on - (cs_item_sk = cr_item_sk and cs_order_number = cr_order_number), - date_dim, - catalog_page, - item, - promotion - where cs_sold_date_sk = d_date_sk - and d_date between cast('1999-08-21' as date) - and dateadd(day,30,cast('1999-08-21' as date)) - and cs_catalog_page_sk = cp_catalog_page_sk - and cs_item_sk = i_item_sk - and i_current_price > 50 - and cs_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(ws_ext_sales_price) as sales, - sum(coalesce(wr_return_amt, 0)) as returns, - sum(ws_net_profit - coalesce(wr_net_loss, 0)) as profit - from web_sales left outer join web_returns on - (ws_item_sk = wr_item_sk and ws_order_number = wr_order_number), - date_dim, - web_site, - item, - promotion - where ws_sold_date_sk = d_date_sk - and d_date between cast('1999-08-21' as date) - and dateadd(day,30,cast('1999-08-21' as date)) - and ws_web_site_sk = web_site_sk - and ws_item_sk = i_item_sk - and i_current_price > 50 - and ws_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by web_site_id) -, -results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || store_id as id - , sales - , returns - , profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || catalog_page_id as id - , sales - , returns - , profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , profit - from wsr - ) x - group by channel, id) - - select channel - , id - , sales - , returns - , profit - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results - ) foo - order by channel, id - limit 100; - --- end template query80a.tpl query 9 in stream 8 --- start template query12.tpl query 10 in stream 8 -select /* TPC-DS query12.tpl 0.64 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ws_ext_sales_price) as itemrevenue - ,sum(ws_ext_sales_price)*100/sum(sum(ws_ext_sales_price)) over - (partition by i_class) as revenueratio -from - web_sales - ,item - ,date_dim -where - ws_item_sk = i_item_sk - and i_category in ('Books', 'Children', 'Home') - and ws_sold_date_sk = d_date_sk - and d_date between cast('2001-05-30' as date) - and dateadd(day,30,cast('2001-05-30' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query12.tpl query 10 in stream 8 --- start template query59.tpl query 11 in stream 8 -with /* TPC-DS query59.tpl 0.30 */ wss as - (select d_week_seq, - ss_store_sk, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - group by d_week_seq,ss_store_sk - ) - select s_store_name1,s_store_id1,d_week_seq1 - ,sun_sales1/sun_sales2,mon_sales1/mon_sales2 - ,tue_sales1/tue_sales2,wed_sales1/wed_sales2,thu_sales1/thu_sales2 - ,fri_sales1/fri_sales2,sat_sales1/sat_sales2 - from - (select s_store_name s_store_name1,wss.d_week_seq d_week_seq1 - ,s_store_id s_store_id1,sun_sales sun_sales1 - ,mon_sales mon_sales1,tue_sales tue_sales1 - ,wed_sales wed_sales1,thu_sales thu_sales1 - ,fri_sales fri_sales1,sat_sales sat_sales1 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1176 and 1176 + 11) y, - (select s_store_name s_store_name2,wss.d_week_seq d_week_seq2 - ,s_store_id s_store_id2,sun_sales sun_sales2 - ,mon_sales mon_sales2,tue_sales tue_sales2 - ,wed_sales wed_sales2,thu_sales thu_sales2 - ,fri_sales fri_sales2,sat_sales sat_sales2 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1176+ 12 and 1176 + 23) x - where s_store_id1=s_store_id2 - and d_week_seq1=d_week_seq2-52 - order by s_store_name1,s_store_id1,d_week_seq1 -limit 100; - --- end template query59.tpl query 11 in stream 8 --- start template query70a.tpl query 12 in stream 8 -with /* TPC-DS query70a.tpl 0.34 */ results as -( select - sum(ss_net_profit) as total_sum ,s_state ,s_county, 0 as gstate, 0 as g_county - from - store_sales - ,date_dim d1 - ,store - where - d1.d_month_seq between 1189 and 1189 + 11 - and d1.d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - and s_state in - ( select s_state - from (select s_state as s_state, - rank() over ( partition by s_state order by sum(ss_net_profit) desc) as ranking - from store_sales, store, date_dim - where d_month_seq between 1189 and 1189 + 11 - and d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - group by s_state - ) tmp1 - where ranking <= 5) - group by s_state,s_county) , - results_rollup as -(select total_sum ,s_state ,s_county, 0 as g_state, 0 as g_county, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum,s_state, NULL as s_county, 0 as g_state, 1 as g_county, 1 as lochierarchy from results group by s_state - union - select sum(total_sum) as total_sum ,NULL as s_state ,NULL as s_county, 1 as g_state, 1 as g_county, 2 as lochierarchy from results) - select total_sum ,s_state ,s_county, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_county = 0 then s_state end - order by total_sum desc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then s_state end - ,rank_within_parent - limit 100; - --- end template query70a.tpl query 12 in stream 8 --- start template query91.tpl query 13 in stream 8 -select /* TPC-DS query91.tpl 0.13 */ - cc_call_center_id Call_Center, - cc_name Call_Center_Name, - cc_manager Manager, - sum(cr_net_loss) Returns_Loss -from - call_center, - catalog_returns, - date_dim, - customer, - customer_address, - customer_demographics, - household_demographics -where - cr_call_center_sk = cc_call_center_sk -and cr_returned_date_sk = d_date_sk -and cr_returning_customer_sk= c_customer_sk -and cd_demo_sk = c_current_cdemo_sk -and hd_demo_sk = c_current_hdemo_sk -and ca_address_sk = c_current_addr_sk -and d_year = 1999 -and d_moy = 12 -and ( (cd_marital_status = 'M' and cd_education_status = 'Unknown') - or(cd_marital_status = 'W' and cd_education_status = 'Advanced Degree')) -and hd_buy_potential like '0-500%' -and ca_gmt_offset = -7 -group by cc_call_center_id,cc_name,cc_manager,cd_marital_status,cd_education_status -order by sum(cr_net_loss) desc; - --- end template query91.tpl query 13 in stream 8 --- start template query69.tpl query 14 in stream 8 -select /* TPC-DS query69.tpl 0.28 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_state in ('NE','OK','AL') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 3 and 3+2) and - (not exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 3 and 3+2) and - not exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 3 and 3+2)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - limit 100; - --- end template query69.tpl query 14 in stream 8 --- start template query40.tpl query 15 in stream 8 -select /* TPC-DS query40.tpl 0.86 */ - w_state - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('2002-05-09' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_before - ,sum(case when (cast(d_date as date) >= cast ('2002-05-09' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_after - from - catalog_sales left outer join catalog_returns on - (cs_order_number = cr_order_number - and cs_item_sk = cr_item_sk) - ,warehouse - ,item - ,date_dim - where - i_current_price between 0.99 and 1.49 - and i_item_sk = cs_item_sk - and cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('2002-05-09' as date)) - and dateadd(day,30,cast ('2002-05-09' as date)) - group by - w_state,i_item_id - order by w_state,i_item_id -limit 100; - --- end template query40.tpl query 15 in stream 8 --- start template query2.tpl query 16 in stream 8 -with /* TPC-DS query2.tpl 0.84 */ wscs as - (select sold_date_sk - ,sales_price - from (select ws_sold_date_sk sold_date_sk - ,ws_ext_sales_price sales_price - from web_sales - union all - select cs_sold_date_sk sold_date_sk - ,cs_ext_sales_price sales_price - from catalog_sales)), - wswscs as - (select d_week_seq, - sum(case when (d_day_name='Sunday') then sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then sales_price else null end) sat_sales - from wscs - ,date_dim - where d_date_sk = sold_date_sk - group by d_week_seq) - select d_week_seq1 - ,round(sun_sales1/sun_sales2,2) - ,round(mon_sales1/mon_sales2,2) - ,round(tue_sales1/tue_sales2,2) - ,round(wed_sales1/wed_sales2,2) - ,round(thu_sales1/thu_sales2,2) - ,round(fri_sales1/fri_sales2,2) - ,round(sat_sales1/sat_sales2,2) - from - (select wswscs.d_week_seq d_week_seq1 - ,sun_sales sun_sales1 - ,mon_sales mon_sales1 - ,tue_sales tue_sales1 - ,wed_sales wed_sales1 - ,thu_sales thu_sales1 - ,fri_sales fri_sales1 - ,sat_sales sat_sales1 - from wswscs,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 1999) y, - (select wswscs.d_week_seq d_week_seq2 - ,sun_sales sun_sales2 - ,mon_sales mon_sales2 - ,tue_sales tue_sales2 - ,wed_sales wed_sales2 - ,thu_sales thu_sales2 - ,fri_sales fri_sales2 - ,sat_sales sat_sales2 - from wswscs - ,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 1999+1) z - where d_week_seq1=d_week_seq2-53 - order by d_week_seq1; - --- end template query2.tpl query 16 in stream 8 --- start template query16.tpl query 17 in stream 8 -select /* TPC-DS query16.tpl 0.25 */ - count(distinct cs_order_number) as "order count" - ,sum(cs_ext_ship_cost) as "total shipping cost" - ,sum(cs_net_profit) as "total net profit" -from - catalog_sales cs1 - ,date_dim - ,customer_address - ,call_center -where - d_date between '2002-3-01' and - dateadd(day, 60, cast('2002-3-01' as date)) -and cs1.cs_ship_date_sk = d_date_sk -and cs1.cs_ship_addr_sk = ca_address_sk -and ca_state = 'AR' -and cs1.cs_call_center_sk = cc_call_center_sk -and cc_county in ('Pennington County','Huron County','Franklin Parish','Daviess County', - 'Bronx County' -) -and exists (select * - from catalog_sales cs2 - where cs1.cs_order_number = cs2.cs_order_number - and cs1.cs_warehouse_sk <> cs2.cs_warehouse_sk) -and not exists(select * - from catalog_returns cr1 - where cs1.cs_order_number = cr1.cr_order_number) -order by count(distinct cs_order_number) -limit 100; - --- end template query16.tpl query 17 in stream 8 --- start template query44.tpl query 18 in stream 8 -select /* TPC-DS query44.tpl 0.4 */ asceding.rnk, i1.i_product_name best_performing, i2.i_product_name worst_performing -from(select * - from (select item_sk,rank() over (order by rank_col asc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 420 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 420 - and ss_hdemo_sk is null - group by ss_store_sk))V1)V11 - where rnk < 11) asceding, - (select * - from (select item_sk,rank() over (order by rank_col desc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 420 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 420 - and ss_hdemo_sk is null - group by ss_store_sk))V2)V21 - where rnk < 11) descending, -item i1, -item i2 -where asceding.rnk = descending.rnk - and i1.i_item_sk=asceding.item_sk - and i2.i_item_sk=descending.item_sk -order by asceding.rnk -limit 100; - --- end template query44.tpl query 18 in stream 8 --- start template query5a.tpl query 19 in stream 8 -with /* TPC-DS query5a.tpl 0.98 */ ssr as - (select s_store_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ss_store_sk as store_sk, - ss_sold_date_sk as date_sk, - ss_ext_sales_price as sales_price, - ss_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from store_sales - union all - select sr_store_sk as store_sk, - sr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - sr_return_amt as return_amt, - sr_net_loss as net_loss - from store_returns - ) salesreturns, - date_dim, - store - where date_sk = d_date_sk - and d_date between cast('2002-08-04' as date) - and dateadd(day,14,cast('2002-08-04' as date)) - and store_sk = s_store_sk - group by s_store_id) - , - csr as - (select cp_catalog_page_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select cs_catalog_page_sk as page_sk, - cs_sold_date_sk as date_sk, - cs_ext_sales_price as sales_price, - cs_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from catalog_sales - union all - select cr_catalog_page_sk as page_sk, - cr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - cr_return_amount as return_amt, - cr_net_loss as net_loss - from catalog_returns - ) salesreturns, - date_dim, - catalog_page - where date_sk = d_date_sk - and d_date between cast('2002-08-04' as date) - and dateadd(day,14,cast('2002-08-04' as date)) - and page_sk = cp_catalog_page_sk - group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ws_web_site_sk as wsr_web_site_sk, - ws_sold_date_sk as date_sk, - ws_ext_sales_price as sales_price, - ws_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from web_sales - union all - select ws_web_site_sk as wsr_web_site_sk, - wr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - wr_return_amt as return_amt, - wr_net_loss as net_loss - from web_returns left outer join web_sales on - ( wr_item_sk = ws_item_sk - and wr_order_number = ws_order_number) - ) salesreturns, - date_dim, - web_site - where date_sk = d_date_sk - and d_date between cast('2002-08-04' as date) - and dateadd(day,14,cast('2002-08-04' as date)) - and wsr_web_site_sk = web_site_sk - group by web_site_id) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || s_store_id as id - , sales - , returns - , (profit - profit_loss) as profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || cp_catalog_page_id as id - , sales - , returns - , (profit - profit_loss) as profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , (profit - profit_loss) as profit - from wsr - ) x - group by channel, id) - select channel, id, sales, returns, profit from ( - select channel, id, sales, returns, profit from results - union - select channel, null as id, sum(sales), sum(returns), sum(profit) from results group by channel - union - select null as channel, null as id, sum(sales), sum(returns), sum(profit) from results) foo -order by channel, id -limit 100; - --- end template query5a.tpl query 19 in stream 8 --- start template query73.tpl query 20 in stream 8 -select /* TPC-DS query73.tpl 0.79 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_buy_potential = '1001-5000' or - household_demographics.hd_buy_potential = '0-500') - and household_demographics.hd_vehicle_count > 0 - and case when household_demographics.hd_vehicle_count > 0 then - household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count else null end > 1 - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_county in ('Daviess County','Ziebach County','Oglethorpe County','San Miguel County') - group by ss_ticket_number,ss_customer_sk) dj,customer - where ss_customer_sk = c_customer_sk - and cnt between 1 and 5 - order by cnt desc, c_last_name asc; - --- end template query73.tpl query 20 in stream 8 --- start template query14a.tpl query 21 in stream 8 -with /* TPC-DS query14a.tpl 0.69 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1998 AND 1998 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1998 AND 1998 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1998 AND 1998 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as - (select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2) x) -, - results AS -(select channel, i_brand_id, i_class_id, i_category_id, sum(sales) sum_sales, sum(number_sales) number_sales - from ( - select 'store' channel, i_brand_id,i_class_id - ,i_category_id,sum(ss_quantity*ss_list_price) sales - , count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1998+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales) - union all - select 'catalog' channel, i_brand_id,i_class_id,i_category_id, sum(cs_quantity*cs_list_price) sales, count(*) number_sales - from catalog_sales - ,item - ,date_dim - where cs_item_sk in (select ss_item_sk from cross_items) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1998+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(cs_quantity*cs_list_price) > (select average_sales from avg_sales) - union all - select 'web' channel, i_brand_id,i_class_id,i_category_id, sum(ws_quantity*ws_list_price) sales , count(*) number_sales - from web_sales - ,item - ,date_dim - where ws_item_sk in (select ss_item_sk from cross_items) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1998+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ws_quantity*ws_list_price) > (select average_sales from avg_sales) - ) y - group by channel, i_brand_id,i_class_id,i_category_id) - - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales -from ( - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales from results - union - select channel, i_brand_id, i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id, i_class_id - union - select channel, i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id - union - select channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel - union - select null as channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results) z -order by channel, i_brand_id, i_class_id, i_category_id - limit 100; -with /* TPC-DS query14a.tpl 0.69 part2 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 1998 AND 1998 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 1998 AND 1998 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 1998 AND 1998 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as -(select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 1998 and 1998 + 2) x) - select this_year.channel ty_channel - ,this_year.i_brand_id ty_brand - ,this_year.i_class_id ty_class - ,this_year.i_category_id ty_category - ,this_year.sales ty_sales - ,this_year.number_sales ty_number_sales - ,last_year.channel ly_channel - ,last_year.i_brand_id ly_brand - ,last_year.i_class_id ly_class - ,last_year.i_category_id ly_category - ,last_year.sales ly_sales - ,last_year.number_sales ly_number_sales -from - (select 'store' channel, i_brand_id,i_class_id,i_category_id - ,sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1998 + 1 - and d_moy = 12 - and d_dom = 16) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) this_year, - (select 'store' channel, i_brand_id,i_class_id - ,i_category_id, sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 1998 - and d_moy = 12 - and d_dom = 16) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) last_year - where this_year.i_brand_id= last_year.i_brand_id - and this_year.i_class_id = last_year.i_class_id - and this_year.i_category_id = last_year.i_category_id - order by this_year.channel, this_year.i_brand_id, this_year.i_class_id, this_year.i_category_id - limit 100; - --- end template query14a.tpl query 21 in stream 8 --- start template query71.tpl query 22 in stream 8 -select /* TPC-DS query71.tpl 0.72 */ i_brand_id brand_id, i_brand brand,t_hour,t_minute, - sum(ext_price) ext_price - from item, (select ws_ext_sales_price as ext_price, - ws_sold_date_sk as sold_date_sk, - ws_item_sk as sold_item_sk, - ws_sold_time_sk as time_sk - from web_sales,date_dim - where d_date_sk = ws_sold_date_sk - and d_moy=12 - and d_year=2000 - union all - select cs_ext_sales_price as ext_price, - cs_sold_date_sk as sold_date_sk, - cs_item_sk as sold_item_sk, - cs_sold_time_sk as time_sk - from catalog_sales,date_dim - where d_date_sk = cs_sold_date_sk - and d_moy=12 - and d_year=2000 - union all - select ss_ext_sales_price as ext_price, - ss_sold_date_sk as sold_date_sk, - ss_item_sk as sold_item_sk, - ss_sold_time_sk as time_sk - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - and d_moy=12 - and d_year=2000 - ) tmp,time_dim - where - sold_item_sk = i_item_sk - and i_manager_id=1 - and time_sk = t_time_sk - and (t_meal_time = 'breakfast' or t_meal_time = 'dinner') - group by i_brand, i_brand_id,t_hour,t_minute - order by ext_price desc, i_brand_id - ; - --- end template query71.tpl query 22 in stream 8 --- start template query3.tpl query 23 in stream 8 -select /* TPC-DS query3.tpl 0.45 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_sales_price) sum_agg - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manufact_id = 521 - and dt.d_moy=12 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,sum_agg desc - ,brand_id - limit 100; - --- end template query3.tpl query 23 in stream 8 --- start template query49.tpl query 24 in stream 8 -select /* TPC-DS query49.tpl 0.48 */ channel, item, return_ratio, return_rank, currency_rank from - (select - 'web' as channel - ,web.item - ,web.return_ratio - ,web.return_rank - ,web.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select ws.ws_item_sk as item - ,(cast(sum(coalesce(wr.wr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(wr.wr_return_amt,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - web_sales ws left outer join web_returns wr - on (ws.ws_order_number = wr.wr_order_number and - ws.ws_item_sk = wr.wr_item_sk) - ,date_dim - where - wr.wr_return_amt > 10000 - and ws.ws_net_profit > 1 - and ws.ws_net_paid > 0 - and ws.ws_quantity > 0 - and ws_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 12 - group by ws.ws_item_sk - ) in_web - ) web - where - ( - web.return_rank <= 10 - or - web.currency_rank <= 10 - ) - union - select - 'catalog' as channel - ,catalog.item - ,catalog.return_ratio - ,catalog.return_rank - ,catalog.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select - cs.cs_item_sk as item - ,(cast(sum(coalesce(cr.cr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(cr.cr_return_amount,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - catalog_sales cs left outer join catalog_returns cr - on (cs.cs_order_number = cr.cr_order_number and - cs.cs_item_sk = cr.cr_item_sk) - ,date_dim - where - cr.cr_return_amount > 10000 - and cs.cs_net_profit > 1 - and cs.cs_net_paid > 0 - and cs.cs_quantity > 0 - and cs_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 12 - group by cs.cs_item_sk - ) in_cat - ) catalog - where - ( - catalog.return_rank <= 10 - or - catalog.currency_rank <=10 - ) - union - select - 'store' as channel - ,store.item - ,store.return_ratio - ,store.return_rank - ,store.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select sts.ss_item_sk as item - ,(cast(sum(coalesce(sr.sr_return_quantity,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(sr.sr_return_amt,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - store_sales sts left outer join store_returns sr - on (sts.ss_ticket_number = sr.sr_ticket_number and sts.ss_item_sk = sr.sr_item_sk) - ,date_dim - where - sr.sr_return_amt > 10000 - and sts.ss_net_profit > 1 - and sts.ss_net_paid > 0 - and sts.ss_quantity > 0 - and ss_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 12 - group by sts.ss_item_sk - ) in_store - ) store - where ( - store.return_rank <= 10 - or - store.currency_rank <= 10 - ) - ) - order by 1,4,5,2 - limit 100; - --- end template query49.tpl query 24 in stream 8 --- start template query84.tpl query 25 in stream 8 -select /* TPC-DS query84.tpl 0.80 */ c_customer_id as customer_id - , coalesce(c_last_name,'') || ', ' || coalesce(c_first_name,'') as customername - from customer - ,customer_address - ,customer_demographics - ,household_demographics - ,income_band - ,store_returns - where ca_city = 'Jackson' - and c_current_addr_sk = ca_address_sk - and ib_lower_bound >= 35575 - and ib_upper_bound <= 35575 + 50000 - and ib_income_band_sk = hd_income_band_sk - and cd_demo_sk = c_current_cdemo_sk - and hd_demo_sk = c_current_hdemo_sk - and sr_cdemo_sk = cd_demo_sk - order by c_customer_id - limit 100; - --- end template query84.tpl query 25 in stream 8 --- start template query64.tpl query 26 in stream 8 -with /* TPC-DS query64.tpl 0.20 */ cs_ui as - (select cs_item_sk - ,sum(cs_ext_list_price) as sale,sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit) as refund - from catalog_sales - ,catalog_returns - where cs_item_sk = cr_item_sk - and cs_order_number = cr_order_number - group by cs_item_sk - having sum(cs_ext_list_price)>2*sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit)), -cross_sales as - (select i_product_name product_name - ,i_item_sk item_sk - ,s_store_name store_name - ,s_zip store_zip - ,ad1.ca_street_number b_street_number - ,ad1.ca_street_name b_street_name - ,ad1.ca_city b_city - ,ad1.ca_zip b_zip - ,ad2.ca_street_number c_street_number - ,ad2.ca_street_name c_street_name - ,ad2.ca_city c_city - ,ad2.ca_zip c_zip - ,d1.d_year as syear - ,d2.d_year as fsyear - ,d3.d_year s2year - ,count(*) cnt - ,sum(ss_wholesale_cost) s1 - ,sum(ss_list_price) s2 - ,sum(ss_coupon_amt) s3 - FROM store_sales - ,store_returns - ,cs_ui - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,customer - ,customer_demographics cd1 - ,customer_demographics cd2 - ,promotion - ,household_demographics hd1 - ,household_demographics hd2 - ,customer_address ad1 - ,customer_address ad2 - ,income_band ib1 - ,income_band ib2 - ,item - WHERE ss_store_sk = s_store_sk AND - ss_sold_date_sk = d1.d_date_sk AND - ss_customer_sk = c_customer_sk AND - ss_cdemo_sk= cd1.cd_demo_sk AND - ss_hdemo_sk = hd1.hd_demo_sk AND - ss_addr_sk = ad1.ca_address_sk and - ss_item_sk = i_item_sk and - ss_item_sk = sr_item_sk and - ss_ticket_number = sr_ticket_number and - ss_item_sk = cs_ui.cs_item_sk and - c_current_cdemo_sk = cd2.cd_demo_sk AND - c_current_hdemo_sk = hd2.hd_demo_sk AND - c_current_addr_sk = ad2.ca_address_sk and - c_first_sales_date_sk = d2.d_date_sk and - c_first_shipto_date_sk = d3.d_date_sk and - ss_promo_sk = p_promo_sk and - hd1.hd_income_band_sk = ib1.ib_income_band_sk and - hd2.hd_income_band_sk = ib2.ib_income_band_sk and - cd1.cd_marital_status <> cd2.cd_marital_status and - i_color in ('violet','rose','black','dark','sky','khaki') and - i_current_price between 5 and 5 + 10 and - i_current_price between 5 + 1 and 5 + 15 -group by i_product_name - ,i_item_sk - ,s_store_name - ,s_zip - ,ad1.ca_street_number - ,ad1.ca_street_name - ,ad1.ca_city - ,ad1.ca_zip - ,ad2.ca_street_number - ,ad2.ca_street_name - ,ad2.ca_city - ,ad2.ca_zip - ,d1.d_year - ,d2.d_year - ,d3.d_year -) -select cs1.product_name - ,cs1.store_name - ,cs1.store_zip - ,cs1.b_street_number - ,cs1.b_street_name - ,cs1.b_city - ,cs1.b_zip - ,cs1.c_street_number - ,cs1.c_street_name - ,cs1.c_city - ,cs1.c_zip - ,cs1.syear - ,cs1.cnt - ,cs1.s1 as s11 - ,cs1.s2 as s21 - ,cs1.s3 as s31 - ,cs2.s1 as s12 - ,cs2.s2 as s22 - ,cs2.s3 as s32 - ,cs2.syear - ,cs2.cnt -from cross_sales cs1,cross_sales cs2 -where cs1.item_sk=cs2.item_sk and - cs1.syear = 1999 and - cs2.syear = 1999 + 1 and - cs2.cnt <= cs1.cnt and - cs1.store_name = cs2.store_name and - cs1.store_zip = cs2.store_zip -order by cs1.product_name - ,cs1.store_name - ,cs2.cnt - ,cs1.s1 - ,cs2.s1; - --- end template query64.tpl query 26 in stream 8 --- start template query7.tpl query 27 in stream 8 -select /* TPC-DS query7.tpl 0.2 */ i_item_id, - avg(ss_quantity) agg1, - avg(ss_list_price) agg2, - avg(ss_coupon_amt) agg3, - avg(ss_sales_price) agg4 - from store_sales, customer_demographics, date_dim, item, promotion - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_cdemo_sk = cd_demo_sk and - ss_promo_sk = p_promo_sk and - cd_gender = 'F' and - cd_marital_status = 'M' and - cd_education_status = 'Advanced Degree' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 2002 - group by i_item_id - order by i_item_id - limit 100; - --- end template query7.tpl query 27 in stream 8 --- start template query36a.tpl query 28 in stream 8 -with /* TPC-DS query36a.tpl 0.21 */ results as - (select - sum(ss_net_profit) as ss_net_profit, sum(ss_ext_sales_price) as ss_ext_sales_price, - sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin - ,i_category - ,i_class - ,0 as g_category, 0 as g_class - from - store_sales - ,date_dim d1 - ,item - ,store - where - d1.d_year = 2000 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and s_state in ('LA','MI','LA','NM', - 'GA','PA','AL','TN') - group by i_category,i_class) - , - results_rollup as - (select gross_margin ,i_category ,i_class,0 as t_category, 0 as t_class, 0 as lochierarchy from results - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - i_category, NULL AS i_class, 0 as t_category, 1 as t_class, 1 as lochierarchy from results group by i_category - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - NULL AS i_category ,NULL AS i_class, 1 as t_category, 1 as t_class, 2 as lochierarchy from results) - select - gross_margin ,i_category ,i_class, lochierarchy,rank() over ( - partition by lochierarchy, case when t_class = 0 then i_category end - order by gross_margin asc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then i_category end - ,rank_within_parent - limit 100; - --- end template query36a.tpl query 28 in stream 8 --- start template query61.tpl query 29 in stream 8 -select /* TPC-DS query61.tpl 0.97 */ promotions,total,cast(promotions as decimal(15,4))/cast(total as decimal(15,4))*100 -from - (select sum(ss_ext_sales_price) promotions - from store_sales - ,store - ,promotion - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_promo_sk = p_promo_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -6 - and i_category = 'Electronics' - and (p_channel_dmail = 'Y' or p_channel_email = 'Y' or p_channel_tv = 'Y') - and s_gmt_offset = -6 - and d_year = 2002 - and d_moy = 12) promotional_sales, - (select sum(ss_ext_sales_price) total - from store_sales - ,store - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -6 - and i_category = 'Electronics' - and s_gmt_offset = -6 - and d_year = 2002 - and d_moy = 12) all_sales -order by promotions, total -limit 100; - --- end template query61.tpl query 29 in stream 8 --- start template query41.tpl query 30 in stream 8 -select /* TPC-DS query41.tpl 0.62 */ distinct(i_product_name) - from item i1 - where i_manufact_id between 712 and 712+40 - and (select count(*) as item_cnt - from item - where (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'lawn' or i_color = 'frosted') and - (i_units = 'Cup' or i_units = 'Case') and - (i_size = 'petite' or i_size = 'large') - ) or - (i_category = 'Women' and - (i_color = 'cyan' or i_color = 'deep') and - (i_units = 'N/A' or i_units = 'Bundle') and - (i_size = 'medium' or i_size = 'small') - ) or - (i_category = 'Men' and - (i_color = 'sienna' or i_color = 'peach') and - (i_units = 'Tbl' or i_units = 'Lb') and - (i_size = 'economy' or i_size = 'N/A') - ) or - (i_category = 'Men' and - (i_color = 'green' or i_color = 'coral') and - (i_units = 'Ounce' or i_units = 'Carton') and - (i_size = 'petite' or i_size = 'large') - ))) or - (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'olive' or i_color = 'purple') and - (i_units = 'Dozen' or i_units = 'Gram') and - (i_size = 'petite' or i_size = 'large') - ) or - (i_category = 'Women' and - (i_color = 'floral' or i_color = 'burlywood') and - (i_units = 'Unknown' or i_units = 'Each') and - (i_size = 'medium' or i_size = 'small') - ) or - (i_category = 'Men' and - (i_color = 'smoke' or i_color = 'red') and - (i_units = 'Box' or i_units = 'Gross') and - (i_size = 'economy' or i_size = 'N/A') - ) or - (i_category = 'Men' and - (i_color = 'cornsilk' or i_color = 'lime') and - (i_units = 'Pound' or i_units = 'Dram') and - (i_size = 'petite' or i_size = 'large') - )))) > 0 - order by i_product_name - limit 100; - --- end template query41.tpl query 30 in stream 8 --- start template query35a.tpl query 31 in stream 8 -select /* TPC-DS query35a.tpl 0.47 */ - ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - count(*) cnt1, - max(cd_dep_count), - min(cd_dep_count), - sum(cd_dep_count), - cd_dep_employed_count, - count(*) cnt2, - max(cd_dep_employed_count), - min(cd_dep_employed_count), - sum(cd_dep_employed_count), - cd_dep_college_count, - count(*) cnt3, - max(cd_dep_college_count), - min(cd_dep_college_count), - sum(cd_dep_college_count) - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2002 and - d_qoy < 4) and - exists (select * from - (select ws_bill_customer_sk customsk - from web_sales,date_dim - where - ws_sold_date_sk = d_date_sk and - d_year = 2002 and - d_qoy < 4 - union all - select cs_ship_customer_sk customsk - from catalog_sales,date_dim - where - cs_sold_date_sk = d_date_sk and - d_year = 2002 and - d_qoy < 4)x - where x.customsk = c.c_customer_sk) - group by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - limit 100; - --- end template query35a.tpl query 31 in stream 8 --- start template query50.tpl query 32 in stream 8 -select /* TPC-DS query50.tpl 0.60 */ - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 30) and - (sr_returned_date_sk - ss_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 60) and - (sr_returned_date_sk - ss_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 90) and - (sr_returned_date_sk - ss_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - store_sales - ,store_returns - ,store - ,date_dim d1 - ,date_dim d2 -where - d2.d_year = 1999 -and d2.d_moy = 9 -and ss_ticket_number = sr_ticket_number -and ss_item_sk = sr_item_sk -and ss_sold_date_sk = d1.d_date_sk -and sr_returned_date_sk = d2.d_date_sk -and ss_customer_sk = sr_customer_sk -and ss_store_sk = s_store_sk -group by - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -order by s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -limit 100; - --- end template query50.tpl query 32 in stream 8 --- start template query65.tpl query 33 in stream 8 -select /* TPC-DS query65.tpl 0.71 */ - s_store_name, - i_item_desc, - sc.revenue, - i_current_price, - i_wholesale_cost, - i_brand - from store, item, - (select ss_store_sk, avg(revenue) as ave - from - (select ss_store_sk, ss_item_sk, - sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1187 and 1187+11 - group by ss_store_sk, ss_item_sk) sa - group by ss_store_sk) sb, - (select ss_store_sk, ss_item_sk, sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1187 and 1187+11 - group by ss_store_sk, ss_item_sk) sc - where sb.ss_store_sk = sc.ss_store_sk and - sc.revenue <= 0.1 * sb.ave and - s_store_sk = sc.ss_store_sk and - i_item_sk = sc.ss_item_sk - order by s_store_name, i_item_desc -limit 100; - --- end template query65.tpl query 33 in stream 8 --- start template query51.tpl query 34 in stream 8 -WITH /* TPC-DS query51.tpl 0.46 */ web_v1 as ( -select - ws_item_sk item_sk, d_date, - sum(sum(ws_sales_price)) - over (partition by ws_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from web_sales - ,date_dim -where ws_sold_date_sk=d_date_sk - and d_month_seq between 1211 and 1211+11 - and ws_item_sk is not NULL -group by ws_item_sk, d_date), -store_v1 as ( -select - ss_item_sk item_sk, d_date, - sum(sum(ss_sales_price)) - over (partition by ss_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from store_sales - ,date_dim -where ss_sold_date_sk=d_date_sk - and d_month_seq between 1211 and 1211+11 - and ss_item_sk is not NULL -group by ss_item_sk, d_date) - select * -from (select item_sk - ,d_date - ,web_sales - ,store_sales - ,max(web_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) web_cumulative - ,max(store_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) store_cumulative - from (select case when web.item_sk is not null then web.item_sk else store.item_sk end item_sk - ,case when web.d_date is not null then web.d_date else store.d_date end d_date - ,web.cume_sales web_sales - ,store.cume_sales store_sales - from web_v1 web full outer join store_v1 store on (web.item_sk = store.item_sk - and web.d_date = store.d_date) - )x )y -where web_cumulative > store_cumulative -order by item_sk - ,d_date -limit 100; - --- end template query51.tpl query 34 in stream 8 --- start template query78.tpl query 35 in stream 8 -with /* TPC-DS query78.tpl 0.10 */ ws as - (select d_year AS ws_sold_year, ws_item_sk, - ws_bill_customer_sk ws_customer_sk, - sum(ws_quantity) ws_qty, - sum(ws_wholesale_cost) ws_wc, - sum(ws_sales_price) ws_sp - from web_sales - left join web_returns on wr_order_number=ws_order_number and ws_item_sk=wr_item_sk - join date_dim on ws_sold_date_sk = d_date_sk - where wr_order_number is null - group by d_year, ws_item_sk, ws_bill_customer_sk - ), -cs as - (select d_year AS cs_sold_year, cs_item_sk, - cs_bill_customer_sk cs_customer_sk, - sum(cs_quantity) cs_qty, - sum(cs_wholesale_cost) cs_wc, - sum(cs_sales_price) cs_sp - from catalog_sales - left join catalog_returns on cr_order_number=cs_order_number and cs_item_sk=cr_item_sk - join date_dim on cs_sold_date_sk = d_date_sk - where cr_order_number is null - group by d_year, cs_item_sk, cs_bill_customer_sk - ), -ss as - (select d_year AS ss_sold_year, ss_item_sk, - ss_customer_sk, - sum(ss_quantity) ss_qty, - sum(ss_wholesale_cost) ss_wc, - sum(ss_sales_price) ss_sp - from store_sales - left join store_returns on sr_ticket_number=ss_ticket_number and ss_item_sk=sr_item_sk - join date_dim on ss_sold_date_sk = d_date_sk - where sr_ticket_number is null - group by d_year, ss_item_sk, ss_customer_sk - ) - select -ss_item_sk, -round(ss_qty/(coalesce(ws_qty,0)+coalesce(cs_qty,0)),2) ratio, -ss_qty store_qty, ss_wc store_wholesale_cost, ss_sp store_sales_price, -coalesce(ws_qty,0)+coalesce(cs_qty,0) other_chan_qty, -coalesce(ws_wc,0)+coalesce(cs_wc,0) other_chan_wholesale_cost, -coalesce(ws_sp,0)+coalesce(cs_sp,0) other_chan_sales_price -from ss -left join ws on (ws_sold_year=ss_sold_year and ws_item_sk=ss_item_sk and ws_customer_sk=ss_customer_sk) -left join cs on (cs_sold_year=ss_sold_year and cs_item_sk=ss_item_sk and cs_customer_sk=ss_customer_sk) -where (coalesce(ws_qty,0)>0 or coalesce(cs_qty, 0)>0) and ss_sold_year=1998 -order by - ss_item_sk, - ss_qty desc, ss_wc desc, ss_sp desc, - other_chan_qty, - other_chan_wholesale_cost, - other_chan_sales_price, - ratio -limit 100; - --- end template query78.tpl query 35 in stream 8 --- start template query21.tpl query 36 in stream 8 -select /* TPC-DS query21.tpl 0.14 */ * - from(select w_warehouse_name - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('1999-02-24' as date)) - then inv_quantity_on_hand - else 0 end) as inv_before - ,sum(case when (cast(d_date as date) >= cast ('1999-02-24' as date)) - then inv_quantity_on_hand - else 0 end) as inv_after - from inventory - ,warehouse - ,item - ,date_dim - where i_current_price between 0.99 and 1.49 - and i_item_sk = inv_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('1999-02-24' as date)) - and dateadd(day,30,cast ('1999-02-24' as date)) - group by w_warehouse_name, i_item_id) x - where (case when inv_before > 0 - then inv_after / inv_before - else null - end) between 2.0/3.0 and 3.0/2.0 - order by w_warehouse_name - ,i_item_id - limit 100; - --- end template query21.tpl query 36 in stream 8 --- start template query67a.tpl query 37 in stream 8 -with /* TPC-DS query67a.tpl 0.35 */ results as -( select i_category ,i_class ,i_brand ,i_product_name ,d_year ,d_qoy ,d_moy ,s_store_id - ,sum(coalesce(ss_sales_price*ss_quantity,0)) sumsales - from store_sales ,date_dim ,store ,item - where ss_sold_date_sk=d_date_sk - and ss_item_sk=i_item_sk - and ss_store_sk = s_store_sk - and d_month_seq between 1217 and 1217 + 11 - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy,s_store_id) - , - results_rollup as - (select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, s_store_id, sumsales - from results - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy - union all - select i_category, i_class, i_brand, i_product_name, d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year - union all - select i_category, i_class, i_brand, i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name - union all - select i_category, i_class, i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand - union all - select i_category, i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class - union all - select i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category - union all - select null i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results) - - select * -from (select i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rank() over (partition by i_category order by sumsales desc) rk - from results_rollup) dw2 -where rk <= 100 -order by i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rk -limit 100; - --- end template query67a.tpl query 37 in stream 8 --- start template query22a.tpl query 38 in stream 8 -with /* TPC-DS query22a.tpl 0.55 */ results as -(select i_product_name - ,i_brand - ,i_class - ,i_category - ,avg(inv_quantity_on_hand) qoh - from inventory - ,date_dim - ,item --- ,warehouse - where inv_date_sk=d_date_sk - and inv_item_sk=i_item_sk --- and inv_warehouse_sk = w_warehouse_sk - and d_month_seq between 1184 and 1184 + 11 - group by i_product_name,i_brand,i_class,i_category), -results_rollup as -(select i_product_name, i_brand, i_class, i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class,i_category -union all -select i_product_name, i_brand, i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class -union all -select i_product_name, i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand -union all -select i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name -union all -select null i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results) - select i_product_name, i_brand, i_class, i_category,qoh - from results_rollup - order by qoh, i_product_name, i_brand, i_class, i_category -limit 100; - --- end template query22a.tpl query 38 in stream 8 --- start template query81.tpl query 39 in stream 8 -with /* TPC-DS query81.tpl 0.37 */ customer_total_return as - (select cr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(cr_return_amt_inc_tax) as ctr_total_return - from catalog_returns - ,date_dim - ,customer_address - where cr_returned_date_sk = d_date_sk - and d_year =2000 - and cr_returning_addr_sk = ca_address_sk - group by cr_returning_customer_sk - ,ca_state ) - select c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'MO' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - limit 100; - --- end template query81.tpl query 39 in stream 8 --- start template query93.tpl query 40 in stream 8 -select /* TPC-DS query93.tpl 0.52 */ ss_customer_sk - ,sum(act_sales) sumsales - from (select ss_item_sk - ,ss_ticket_number - ,ss_customer_sk - ,case when sr_return_quantity is not null then (ss_quantity-sr_return_quantity)*ss_sales_price - else (ss_quantity*ss_sales_price) end act_sales - from store_sales left outer join store_returns on (sr_item_sk = ss_item_sk - and sr_ticket_number = ss_ticket_number) - ,reason - where sr_reason_sk = r_reason_sk - and r_reason_desc = 'reason 58') t - group by ss_customer_sk - order by sumsales, ss_customer_sk -limit 100; - --- end template query93.tpl query 40 in stream 8 --- start template query25.tpl query 41 in stream 8 -select /* TPC-DS query25.tpl 0.9 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,min(ss_net_profit) as store_sales_profit - ,min(sr_net_loss) as store_returns_loss - ,min(cs_net_profit) as catalog_sales_profit - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 2000 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 10 - and d2.d_year = 2000 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_moy between 4 and 10 - and d3.d_year = 2000 - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query25.tpl query 41 in stream 8 --- start template query26.tpl query 42 in stream 8 -select /* TPC-DS query26.tpl 0.85 */ i_item_id, - avg(cs_quantity) agg1, - avg(cs_list_price) agg2, - avg(cs_coupon_amt) agg3, - avg(cs_sales_price) agg4 - from catalog_sales, customer_demographics, date_dim, item, promotion - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd_demo_sk and - cs_promo_sk = p_promo_sk and - cd_gender = 'F' and - cd_marital_status = 'D' and - cd_education_status = '4 yr Degree' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 2000 - group by i_item_id - order by i_item_id - limit 100; - --- end template query26.tpl query 42 in stream 8 --- start template query90.tpl query 43 in stream 8 -select /* TPC-DS query90.tpl 0.40 */ cast(amc as decimal(15,4))/cast(pmc as decimal(15,4)) am_pm_ratio - from ( select count(*) amc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 8 and 8+1 - and household_demographics.hd_dep_count = 9 - and web_page.wp_char_count between 5000 and 5200) at, - ( select count(*) pmc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 16 and 16+1 - and household_demographics.hd_dep_count = 9 - and web_page.wp_char_count between 5000 and 5200) pt - order by am_pm_ratio - limit 100; - --- end template query90.tpl query 43 in stream 8 --- start template query74.tpl query 44 in stream 8 -with /* TPC-DS query74.tpl 0.76 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,sum(ss_net_paid) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (2001,2001+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,sum(ws_net_paid) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - and d_year in (2001,2001+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - ) - select - t_s_secyear.customer_id, t_s_secyear.customer_first_name, t_s_secyear.customer_last_name - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.year = 2001 - and t_s_secyear.year = 2001+1 - and t_w_firstyear.year = 2001 - and t_w_secyear.year = 2001+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - order by 2,1,3 -limit 100; - --- end template query74.tpl query 44 in stream 8 --- start template query92.tpl query 45 in stream 8 -select /* TPC-DS query92.tpl 0.44 */ - sum(ws_ext_discount_amt) as "Excess Discount Amount" -from - web_sales - ,item - ,date_dim -where -i_manufact_id = 776 -and i_item_sk = ws_item_sk -and d_date between '2000-02-25' and - dateadd(day,90,cast('2000-02-25' as date)) -and d_date_sk = ws_sold_date_sk -and ws_ext_discount_amt - > ( - SELECT - 1.3 * avg(ws_ext_discount_amt) - FROM - web_sales - ,date_dim - WHERE - ws_item_sk = i_item_sk - and d_date between '2000-02-25' and - dateadd(day,90,cast('2000-02-25' as date)) - and d_date_sk = ws_sold_date_sk - ) -order by sum(ws_ext_discount_amt) -limit 100; - --- end template query92.tpl query 45 in stream 8 --- start template query75.tpl query 46 in stream 8 -WITH /* TPC-DS query75.tpl 0.3 */ all_sales AS ( - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,SUM(sales_cnt) AS sales_cnt - ,SUM(sales_amt) AS sales_amt - FROM (SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,cs_quantity - COALESCE(cr_return_quantity,0) AS sales_cnt - ,cs_ext_sales_price - COALESCE(cr_return_amount,0.0) AS sales_amt - FROM catalog_sales JOIN item ON i_item_sk=cs_item_sk - JOIN date_dim ON d_date_sk=cs_sold_date_sk - LEFT JOIN catalog_returns ON (cs_order_number=cr_order_number - AND cs_item_sk=cr_item_sk) - WHERE i_category='Electronics' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ss_quantity - COALESCE(sr_return_quantity,0) AS sales_cnt - ,ss_ext_sales_price - COALESCE(sr_return_amt,0.0) AS sales_amt - FROM store_sales JOIN item ON i_item_sk=ss_item_sk - JOIN date_dim ON d_date_sk=ss_sold_date_sk - LEFT JOIN store_returns ON (ss_ticket_number=sr_ticket_number - AND ss_item_sk=sr_item_sk) - WHERE i_category='Electronics' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ws_quantity - COALESCE(wr_return_quantity,0) AS sales_cnt - ,ws_ext_sales_price - COALESCE(wr_return_amt,0.0) AS sales_amt - FROM web_sales JOIN item ON i_item_sk=ws_item_sk - JOIN date_dim ON d_date_sk=ws_sold_date_sk - LEFT JOIN web_returns ON (ws_order_number=wr_order_number - AND ws_item_sk=wr_item_sk) - WHERE i_category='Electronics') sales_detail - GROUP BY d_year, i_brand_id, i_class_id, i_category_id, i_manufact_id) - SELECT prev_yr.d_year AS prev_year - ,curr_yr.d_year AS year - ,curr_yr.i_brand_id - ,curr_yr.i_class_id - ,curr_yr.i_category_id - ,curr_yr.i_manufact_id - ,prev_yr.sales_cnt AS prev_yr_cnt - ,curr_yr.sales_cnt AS curr_yr_cnt - ,curr_yr.sales_cnt-prev_yr.sales_cnt AS sales_cnt_diff - ,curr_yr.sales_amt-prev_yr.sales_amt AS sales_amt_diff - FROM all_sales curr_yr, all_sales prev_yr - WHERE curr_yr.i_brand_id=prev_yr.i_brand_id - AND curr_yr.i_class_id=prev_yr.i_class_id - AND curr_yr.i_category_id=prev_yr.i_category_id - AND curr_yr.i_manufact_id=prev_yr.i_manufact_id - AND curr_yr.d_year=2001 - AND prev_yr.d_year=2001-1 - AND CAST(curr_yr.sales_cnt AS DECIMAL(17,2))/CAST(prev_yr.sales_cnt AS DECIMAL(17,2))<0.9 - ORDER BY sales_cnt_diff,sales_amt_diff - limit 100; - --- end template query75.tpl query 46 in stream 8 --- start template query10.tpl query 47 in stream 8 -select /* TPC-DS query10.tpl 0.26 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3, - cd_dep_count, - count(*) cnt4, - cd_dep_employed_count, - count(*) cnt5, - cd_dep_college_count, - count(*) cnt6 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_county in ('Madison County','Lagrange County','Washington County','Johnson County','Huntingdon County') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 4 and 4+3) and - (exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 4 ANd 4+3) or - exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2000 and - d_moy between 4 and 4+3)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count -limit 100; - --- end template query10.tpl query 47 in stream 8 --- start template query58.tpl query 48 in stream 8 -with /* TPC-DS query58.tpl 0.19 */ ss_items as - (select i_item_id item_id - ,sum(ss_ext_sales_price) ss_item_rev - from store_sales - ,item - ,date_dim - where ss_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '2001-03-10')) - and ss_sold_date_sk = d_date_sk - group by i_item_id), - cs_items as - (select i_item_id item_id - ,sum(cs_ext_sales_price) cs_item_rev - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '2001-03-10')) - and cs_sold_date_sk = d_date_sk - group by i_item_id), - ws_items as - (select i_item_id item_id - ,sum(ws_ext_sales_price) ws_item_rev - from web_sales - ,item - ,date_dim - where ws_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq =(select d_week_seq - from date_dim - where d_date = '2001-03-10')) - and ws_sold_date_sk = d_date_sk - group by i_item_id) - select ss_items.item_id - ,ss_item_rev - ,ss_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ss_dev - ,cs_item_rev - ,cs_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 cs_dev - ,ws_item_rev - ,ws_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ws_dev - ,(ss_item_rev+cs_item_rev+ws_item_rev)/3 average - from ss_items,cs_items,ws_items - where ss_items.item_id=cs_items.item_id - and ss_items.item_id=ws_items.item_id - and ss_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - and ss_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and cs_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and cs_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and ws_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and ws_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - order by item_id - ,ss_item_rev - limit 100; - --- end template query58.tpl query 48 in stream 8 --- start template query6.tpl query 49 in stream 8 -select /* TPC-DS query6.tpl 0.58 */ a.ca_state state, count(*) cnt - from customer_address a - ,customer c - ,store_sales s - ,date_dim d - ,item i - where a.ca_address_sk = c.c_current_addr_sk - and c.c_customer_sk = s.ss_customer_sk - and s.ss_sold_date_sk = d.d_date_sk - and s.ss_item_sk = i.i_item_sk - and d.d_month_seq = - (select distinct (d_month_seq) - from date_dim - where d_year = 2002 - and d_moy = 4 ) - and i.i_current_price > 1.2 * - (select avg(j.i_current_price) - from item j - where j.i_category = i.i_category) - group by a.ca_state - having count(*) >= 10 - order by cnt, a.ca_state - limit 100; - --- end template query6.tpl query 49 in stream 8 --- start template query47.tpl query 50 in stream 8 -with /* TPC-DS query47.tpl 0.42 */ v1 as( - select i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, - s_store_name, s_company_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - s_store_name, s_company_name - order by d_year, d_moy) rn - from item, store_sales, date_dim, store - where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - ( - d_year = 1999 or - ( d_year = 1999-1 and d_moy =12) or - ( d_year = 1999+1 and d_moy =1) - ) - group by i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy), - v2 as( - select v1.i_category, v1.i_brand, v1.s_store_name, v1.s_company_name - ,v1.d_year, v1.d_moy - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1.s_store_name = v1_lag.s_store_name and - v1.s_store_name = v1_lead.s_store_name and - v1.s_company_name = v1_lag.s_company_name and - v1.s_company_name = v1_lead.s_company_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 1999 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, sum_sales - limit 100; - --- end template query47.tpl query 50 in stream 8 --- start template query30.tpl query 51 in stream 8 -with /* TPC-DS query30.tpl 0.75 */ customer_total_return as - (select wr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(wr_return_amt) as ctr_total_return - from web_returns - ,date_dim - ,customer_address - where wr_returned_date_sk = d_date_sk - and d_year =2000 - and wr_returning_addr_sk = ca_address_sk - group by wr_returning_customer_sk - ,ca_state) - select c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'CO' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return -limit 100; - --- end template query30.tpl query 51 in stream 8 --- start template query94.tpl query 52 in stream 8 -select /* TPC-DS query94.tpl 0.17 */ - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2000-5-01' and - dateadd(day,60,cast('2000-5-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'NY' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and exists (select * - from web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) -and not exists(select * - from web_returns wr1 - where ws1.ws_order_number = wr1.wr_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query94.tpl query 52 in stream 8 --- start template query97.tpl query 53 in stream 8 -with /* TPC-DS query97.tpl 0.38 */ ssci as ( -select ss_customer_sk customer_sk - ,ss_item_sk item_sk -from store_sales,date_dim -where ss_sold_date_sk = d_date_sk - and d_month_seq between 1214 and 1214 + 11 -group by ss_customer_sk - ,ss_item_sk), -csci as( - select cs_bill_customer_sk customer_sk - ,cs_item_sk item_sk -from catalog_sales,date_dim -where cs_sold_date_sk = d_date_sk - and d_month_seq between 1214 and 1214 + 11 -group by cs_bill_customer_sk - ,cs_item_sk) - select sum(case when ssci.customer_sk is not null and csci.customer_sk is null then 1 else 0 end) store_only - ,sum(case when ssci.customer_sk is null and csci.customer_sk is not null then 1 else 0 end) catalog_only - ,sum(case when ssci.customer_sk is not null and csci.customer_sk is not null then 1 else 0 end) store_and_catalog -from ssci full outer join csci on (ssci.customer_sk=csci.customer_sk - and ssci.item_sk = csci.item_sk) -limit 100; - --- end template query97.tpl query 53 in stream 8 --- start template query55.tpl query 54 in stream 8 -select /* TPC-DS query55.tpl 0.82 */ i_brand_id brand_id, i_brand brand, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=94 - and d_moy=12 - and d_year=1998 - group by i_brand, i_brand_id - order by ext_price desc, i_brand_id -limit 100 ; - --- end template query55.tpl query 54 in stream 8 --- start template query72.tpl query 55 in stream 8 -select /* TPC-DS query72.tpl 0.87 */ i_item_desc - ,w_warehouse_name - ,d1.d_week_seq - ,sum(case when p_promo_sk is null then 1 else 0 end) no_promo - ,sum(case when p_promo_sk is not null then 1 else 0 end) promo - ,count(*) total_cnt -from catalog_sales -join inventory on (cs_item_sk = inv_item_sk) -join warehouse on (w_warehouse_sk=inv_warehouse_sk) -join item on (i_item_sk = cs_item_sk) -join customer_demographics on (cs_bill_cdemo_sk = cd_demo_sk) -join household_demographics on (cs_bill_hdemo_sk = hd_demo_sk) -join date_dim d1 on (cs_sold_date_sk = d1.d_date_sk) -join date_dim d2 on (inv_date_sk = d2.d_date_sk) -join date_dim d3 on (cs_ship_date_sk = d3.d_date_sk) -left outer join promotion on (cs_promo_sk=p_promo_sk) -left outer join catalog_returns on (cr_item_sk = cs_item_sk and cr_order_number = cs_order_number) -where d1.d_week_seq = d2.d_week_seq - and inv_quantity_on_hand < cs_quantity - and d3.d_date > d1.d_date + 5 - and hd_buy_potential = '1001-5000' - and d1.d_year = 1998 - and cd_marital_status = 'U' -group by i_item_desc,w_warehouse_name,d1.d_week_seq -order by total_cnt desc, i_item_desc, w_warehouse_name, d_week_seq -limit 100; - --- end template query72.tpl query 55 in stream 8 --- start template query95.tpl query 56 in stream 8 -with /* TPC-DS query95.tpl 0.43 */ ws_wh as -(select ws1.ws_order_number,ws1.ws_warehouse_sk wh1,ws2.ws_warehouse_sk wh2 - from web_sales ws1,web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) - select - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2001-2-01' and - dateadd(day,60,cast('2001-2-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'MS' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and ws1.ws_order_number in (select ws_order_number - from ws_wh) -and ws1.ws_order_number in (select wr_order_number - from web_returns,ws_wh - where wr_order_number = ws_wh.ws_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query95.tpl query 56 in stream 8 --- start template query86a.tpl query 57 in stream 8 -with /* TPC-DS query86a.tpl 0.11 */ results as -( select sum(ws_net_paid) as total_sum, i_category, i_class, 0 as g_category, 0 as g_class - from - web_sales - ,date_dim d1 - ,item - where - d1.d_month_seq between 1179 and 1179+11 - and d1.d_date_sk = ws_sold_date_sk - and i_item_sk = ws_item_sk - group by i_category,i_class - ) , - - results_rollup as -( select total_sum ,i_category ,i_class, g_category, g_class, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum, i_category, NULL as i_class, 0 as g_category, 1 as g_class, 1 as lochierarchy from results group by i_category - union - select sum(total_sum) as total_sum, NULL as i_category, NULL as i_class, 1 as g_category, 1 as g_class, 2 as lochierarchy from results) - select - total_sum ,i_category ,i_class, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_class = 0 then i_category end - order by total_sum desc) as rank_within_parent - from - results_rollup - order by - lochierarchy desc, - case when lochierarchy = 0 then i_category end, - rank_within_parent - limit 100; - --- end template query86a.tpl query 57 in stream 8 --- start template query39.tpl query 58 in stream 8 -with /* TPC-DS query39.tpl 0.5 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =2001 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=1 - and inv2.d_moy=1+1 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; -with /* TPC-DS query39.tpl 0.5 part2 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =2001 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=1 - and inv2.d_moy=1+1 - and inv1.cov > 1.5 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; - --- end template query39.tpl query 58 in stream 8 --- start template query17.tpl query 59 in stream 8 -select /* TPC-DS query17.tpl 0.41 */ i_item_id - ,i_item_desc - ,s_state - ,count(ss_quantity) as store_sales_quantitycount - ,avg(ss_quantity) as store_sales_quantityave - ,stddev_samp(ss_quantity) as store_sales_quantitystdev - ,stddev_samp(ss_quantity)/avg(ss_quantity) as store_sales_quantitycov - ,count(sr_return_quantity) as store_returns_quantitycount - ,avg(sr_return_quantity) as store_returns_quantityave - ,stddev_samp(sr_return_quantity) as store_returns_quantitystdev - ,stddev_samp(sr_return_quantity)/avg(sr_return_quantity) as store_returns_quantitycov - ,count(cs_quantity) as catalog_sales_quantitycount ,avg(cs_quantity) as catalog_sales_quantityave - ,stddev_samp(cs_quantity) as catalog_sales_quantitystdev - ,stddev_samp(cs_quantity)/avg(cs_quantity) as catalog_sales_quantitycov - from store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where d1.d_quarter_name = '2002Q1' - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_quarter_name in ('2002Q1','2002Q2','2002Q3') - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_quarter_name in ('2002Q1','2002Q2','2002Q3') - group by i_item_id - ,i_item_desc - ,s_state - order by i_item_id - ,i_item_desc - ,s_state -limit 100; - --- end template query17.tpl query 59 in stream 8 --- start template query42.tpl query 60 in stream 8 -select /* TPC-DS query42.tpl 0.61 */ dt.d_year - ,item.i_category_id - ,item.i_category - ,sum(ss_ext_sales_price) - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=11 - and dt.d_year=1999 - group by dt.d_year - ,item.i_category_id - ,item.i_category - order by sum(ss_ext_sales_price) desc,dt.d_year - ,item.i_category_id - ,item.i_category -limit 100 ; - --- end template query42.tpl query 60 in stream 8 --- start template query85.tpl query 61 in stream 8 -select /* TPC-DS query85.tpl 0.33 */ substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) - from web_sales, web_returns, web_page, customer_demographics cd1, - customer_demographics cd2, customer_address, date_dim, reason - where ws_web_page_sk = wp_web_page_sk - and ws_item_sk = wr_item_sk - and ws_order_number = wr_order_number - and ws_sold_date_sk = d_date_sk and d_year = 2002 - and cd1.cd_demo_sk = wr_refunded_cdemo_sk - and cd2.cd_demo_sk = wr_returning_cdemo_sk - and ca_address_sk = wr_refunded_addr_sk - and r_reason_sk = wr_reason_sk - and - ( - ( - cd1.cd_marital_status = 'U' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'College' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 100.00 and 150.00 - ) - or - ( - cd1.cd_marital_status = 'S' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Secondary' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 50.00 and 100.00 - ) - or - ( - cd1.cd_marital_status = 'M' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Primary' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ca_country = 'United States' - and - ca_state in ('TX', 'NE', 'OR') - and ws_net_profit between 100 and 200 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('CA', 'IA', 'SD') - and ws_net_profit between 150 and 300 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('NV', 'NC', 'GA') - and ws_net_profit between 50 and 250 - ) - ) -group by r_reason_desc -order by substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) -limit 100; - --- end template query85.tpl query 61 in stream 8 --- start template query9.tpl query 62 in stream 8 -select /* TPC-DS query9.tpl 0.49 */ case when (select count(*) - from store_sales - where ss_quantity between 1 and 20) > 17877410 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 1 and 20) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 1 and 20) end bucket1 , - case when (select count(*) - from store_sales - where ss_quantity between 21 and 40) > 36489530 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 21 and 40) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 21 and 40) end bucket2, - case when (select count(*) - from store_sales - where ss_quantity between 41 and 60) > 15089799 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 41 and 60) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 41 and 60) end bucket3, - case when (select count(*) - from store_sales - where ss_quantity between 61 and 80) > 39845652 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 61 and 80) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 61 and 80) end bucket4, - case when (select count(*) - from store_sales - where ss_quantity between 81 and 100) > 15904364 - then (select avg(ss_ext_sales_price) - from store_sales - where ss_quantity between 81 and 100) - else (select avg(ss_net_paid_inc_tax) - from store_sales - where ss_quantity between 81 and 100) end bucket5 -from reason -where r_reason_sk = 1 -; - --- end template query9.tpl query 62 in stream 8 --- start template query32.tpl query 63 in stream 8 -select /* TPC-DS query32.tpl 0.7 */ sum(cs_ext_discount_amt) as "excess discount amount" -from - catalog_sales - ,item - ,date_dim -where -i_manufact_id = 126 -and i_item_sk = cs_item_sk -and d_date between '2002-02-11' and - dateadd(day,90,cast('2002-02-11' as date)) -and d_date_sk = cs_sold_date_sk -and cs_ext_discount_amt - > ( - select - 1.3 * avg(cs_ext_discount_amt) - from - catalog_sales - ,date_dim - where - cs_item_sk = i_item_sk - and d_date between '2002-02-11' and - dateadd(day,90,cast('2002-02-11' as date)) - and d_date_sk = cs_sold_date_sk - ) -limit 100; - --- end template query32.tpl query 63 in stream 8 --- start template query34.tpl query 64 in stream 8 -select /* TPC-DS query34.tpl 0.73 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (date_dim.d_dom between 1 and 3 or date_dim.d_dom between 25 and 28) - and (household_demographics.hd_buy_potential = '>10000' or - household_demographics.hd_buy_potential = '5001-10000') - and household_demographics.hd_vehicle_count > 0 - and (case when household_demographics.hd_vehicle_count > 0 - then household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count - else null - end) > 1.2 - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_county in ('Walker County','Oglethorpe County','Marshall County','Bronx County', - 'Luce County','Pennington County','Wadena County','Levy County') - group by ss_ticket_number,ss_customer_sk) dn,customer - where ss_customer_sk = c_customer_sk - and cnt between 15 and 20 - order by c_last_name,c_first_name,c_salutation,c_preferred_cust_flag desc, ss_ticket_number; - --- end template query34.tpl query 64 in stream 8 --- start template query79.tpl query 65 in stream 8 -select /* TPC-DS query79.tpl 0.89 */ - c_last_name,c_first_name,substring(s_city,1,30),ss_ticket_number,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,store.s_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (household_demographics.hd_dep_count = 0 or household_demographics.hd_vehicle_count > 3) - and date_dim.d_dow = 1 - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_number_employees between 200 and 295 - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,store.s_city) ms,customer - where ss_customer_sk = c_customer_sk - order by c_last_name,c_first_name,substring(s_city,1,30), profit -limit 100; - --- end template query79.tpl query 65 in stream 8 --- start template query54.tpl query 66 in stream 8 -with /* TPC-DS query54.tpl 0.81 */ my_customers as ( - select distinct c_customer_sk - , c_current_addr_sk - from - ( select cs_sold_date_sk sold_date_sk, - cs_bill_customer_sk customer_sk, - cs_item_sk item_sk - from catalog_sales - union all - select ws_sold_date_sk sold_date_sk, - ws_bill_customer_sk customer_sk, - ws_item_sk item_sk - from web_sales - ) cs_or_ws_sales, - item, - date_dim, - customer - where sold_date_sk = d_date_sk - and item_sk = i_item_sk - and i_category = 'Music' - and i_class = 'pop' - and c_customer_sk = cs_or_ws_sales.customer_sk - and d_moy = 6 - and d_year = 2001 - ) - , my_revenue as ( - select c_customer_sk, - sum(ss_ext_sales_price) as revenue - from my_customers, - store_sales, - customer_address, - store, - date_dim - where c_current_addr_sk = ca_address_sk - and ca_county = s_county - and ca_state = s_state - and ss_sold_date_sk = d_date_sk - and c_customer_sk = ss_customer_sk - and d_month_seq between (select distinct d_month_seq+1 - from date_dim where d_year = 2001 and d_moy = 6) - and (select distinct d_month_seq+3 - from date_dim where d_year = 2001 and d_moy = 6) - group by c_customer_sk - ) - , segments as - (select cast((revenue/50) as bigint) as segment - from my_revenue - ) - select segment, count(*) as num_customers, segment*50 as segment_base - from segments - group by segment - order by segment, num_customers - limit 100; - --- end template query54.tpl query 66 in stream 8 --- start template query77a.tpl query 67 in stream 8 -with /* TPC-DS query77a.tpl 0.78 */ ss as - (select s_store_sk, - sum(ss_ext_sales_price) as sales, - sum(ss_net_profit) as profit - from store_sales, - date_dim, - store - where ss_sold_date_sk = d_date_sk - and d_date between cast('1998-08-05' as date) - and dateadd(day,30,cast('1998-08-05' as date)) - and ss_store_sk = s_store_sk - group by s_store_sk) - , - sr as - (select s_store_sk, - sum(sr_return_amt) as returns, - sum(sr_net_loss) as profit_loss - from store_returns, - date_dim, - store - where sr_returned_date_sk = d_date_sk - and d_date between cast('1998-08-05' as date) - and dateadd(day,30,cast('1998-08-05' as date)) - and sr_store_sk = s_store_sk - group by s_store_sk), - cs as - (select cs_call_center_sk, - sum(cs_ext_sales_price) as sales, - sum(cs_net_profit) as profit - from catalog_sales, - date_dim - where cs_sold_date_sk = d_date_sk - and d_date between cast('1998-08-05' as date) - and dateadd(day,30,cast('1998-08-05' as date)) - group by cs_call_center_sk - ), - cr as - (select cr_call_center_sk, - sum(cr_return_amount) as returns, - sum(cr_net_loss) as profit_loss - from catalog_returns, - date_dim - where cr_returned_date_sk = d_date_sk - and d_date between cast('1998-08-05' as date) - and dateadd(day,30,cast('1998-08-05' as date)) - group by cr_call_center_sk), - ws as - ( select wp_web_page_sk, - sum(ws_ext_sales_price) as sales, - sum(ws_net_profit) as profit - from web_sales, - date_dim, - web_page - where ws_sold_date_sk = d_date_sk - and d_date between cast('1998-08-05' as date) - and dateadd(day,30,cast('1998-08-05' as date)) - and ws_web_page_sk = wp_web_page_sk - group by wp_web_page_sk), - wr as - (select wp_web_page_sk, - sum(wr_return_amt) as returns, - sum(wr_net_loss) as profit_loss - from web_returns, - date_dim, - web_page - where wr_returned_date_sk = d_date_sk - and d_date between cast('1998-08-05' as date) - and dateadd(day,30,cast('1998-08-05' as date)) - and wr_web_page_sk = wp_web_page_sk - group by wp_web_page_sk) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , ss.s_store_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ss left join sr - on ss.s_store_sk = sr.s_store_sk - union all - select 'catalog channel' as channel - , cs_call_center_sk as id - , sales - , returns - , (profit - profit_loss) as profit - from cs - , cr - union all - select 'web channel' as channel - , ws.wp_web_page_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ws left join wr - on ws.wp_web_page_sk = wr.wp_web_page_sk - ) x - group by channel, id ) - - select * - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results -) foo -order by channel, id - limit 100; - --- end template query77a.tpl query 67 in stream 8 --- start template query45.tpl query 68 in stream 8 -select /* TPC-DS query45.tpl 0.18 */ ca_zip, ca_city, sum(ws_sales_price) - from web_sales, customer, customer_address, date_dim, item - where ws_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ws_item_sk = i_item_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', '85392', '85460', '80348', '81792') - or - i_item_id in (select i_item_id - from item - where i_item_sk in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29) - ) - ) - and ws_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 1999 - group by ca_zip, ca_city - order by ca_zip, ca_city - limit 100; - --- end template query45.tpl query 68 in stream 8 --- start template query28.tpl query 69 in stream 8 -select /* TPC-DS query28.tpl 0.36 */ * -from (select avg(ss_list_price) B1_LP - ,count(ss_list_price) B1_CNT - ,count(distinct ss_list_price) B1_CNTD - from store_sales - where ss_quantity between 0 and 5 - and (ss_list_price between 73 and 73+10 - or ss_coupon_amt between 5583 and 5583+1000 - or ss_wholesale_cost between 26 and 26+20)) B1, - (select avg(ss_list_price) B2_LP - ,count(ss_list_price) B2_CNT - ,count(distinct ss_list_price) B2_CNTD - from store_sales - where ss_quantity between 6 and 10 - and (ss_list_price between 144 and 144+10 - or ss_coupon_amt between 7251 and 7251+1000 - or ss_wholesale_cost between 80 and 80+20)) B2, - (select avg(ss_list_price) B3_LP - ,count(ss_list_price) B3_CNT - ,count(distinct ss_list_price) B3_CNTD - from store_sales - where ss_quantity between 11 and 15 - and (ss_list_price between 185 and 185+10 - or ss_coupon_amt between 16861 and 16861+1000 - or ss_wholesale_cost between 61 and 61+20)) B3, - (select avg(ss_list_price) B4_LP - ,count(ss_list_price) B4_CNT - ,count(distinct ss_list_price) B4_CNTD - from store_sales - where ss_quantity between 16 and 20 - and (ss_list_price between 160 and 160+10 - or ss_coupon_amt between 5629 and 5629+1000 - or ss_wholesale_cost between 15 and 15+20)) B4, - (select avg(ss_list_price) B5_LP - ,count(ss_list_price) B5_CNT - ,count(distinct ss_list_price) B5_CNTD - from store_sales - where ss_quantity between 21 and 25 - and (ss_list_price between 46 and 46+10 - or ss_coupon_amt between 1906 and 1906+1000 - or ss_wholesale_cost between 36 and 36+20)) B5, - (select avg(ss_list_price) B6_LP - ,count(ss_list_price) B6_CNT - ,count(distinct ss_list_price) B6_CNTD - from store_sales - where ss_quantity between 26 and 30 - and (ss_list_price between 94 and 94+10 - or ss_coupon_amt between 12702 and 12702+1000 - or ss_wholesale_cost between 4 and 4+20)) B6 -limit 100; - --- end template query28.tpl query 69 in stream 8 --- start template query11.tpl query 70 in stream 8 -with /* TPC-DS query11.tpl 0.51 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ss_ext_list_price-ss_ext_discount_amt) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ws_ext_list_price-ws_ext_discount_amt) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_email_address - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 1998 - and t_s_secyear.dyear = 1998+1 - and t_w_firstyear.dyear = 1998 - and t_w_secyear.dyear = 1998+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else 0.0 end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else 0.0 end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_email_address -limit 100; - --- end template query11.tpl query 70 in stream 8 --- start template query89.tpl query 71 in stream 8 -select /* TPC-DS query89.tpl 0.56 */ * -from( -select i_category, i_class, i_brand, - s_store_name, s_company_name, - d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, s_store_name, s_company_name) - avg_monthly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - d_year in (2002) and - ((i_category in ('Shoes','Books','Women') and - i_class in ('athletic','mystery','maternity') - ) - or (i_category in ('Electronics','Children','Men') and - i_class in ('dvd/vcr players','infants','accessories') - )) -group by i_category, i_class, i_brand, - s_store_name, s_company_name, d_moy) tmp1 -where case when (avg_monthly_sales <> 0) then (abs(sum_sales - avg_monthly_sales) / avg_monthly_sales) else null end > 0.1 -order by sum_sales - avg_monthly_sales, s_store_name -limit 100; - --- end template query89.tpl query 71 in stream 8 --- start template query56.tpl query 72 in stream 8 -with /* TPC-DS query56.tpl 0.83 */ ss as ( - select i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where i_item_id in (select - i_item_id -from item -where i_color in ('plum','navy','sky')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 4 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -7 - group by i_item_id), - cs as ( - select i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('plum','navy','sky')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 4 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -7 - group by i_item_id), - ws as ( - select i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('plum','navy','sky')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1999 - and d_moy = 4 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -7 - group by i_item_id) - select i_item_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by total_sales, - i_item_id - limit 100; - --- end template query56.tpl query 72 in stream 8 --- start template query46.tpl query 73 in stream 8 -select /* TPC-DS query46.tpl 0.23 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and (household_demographics.hd_dep_count = 9 or - household_demographics.hd_vehicle_count= 1) - and date_dim.d_dow in (6,0) - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_city in ('Lakewood','Fairfield','Bethel','Midway','Pleasant Valley') - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,ca_city) dn,customer,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - limit 100; - --- end template query46.tpl query 73 in stream 8 --- start template query19.tpl query 74 in stream 8 -select /* TPC-DS query19.tpl 0.8 */ i_brand_id brand_id, i_brand brand, i_manufact_id, i_manufact, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item,customer,customer_address,store - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=39 - and d_moy=12 - and d_year=2000 - and ss_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and substring(ca_zip,1,5) <> substring(s_zip,1,5) - and ss_store_sk = s_store_sk - group by i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact - order by ext_price desc - ,i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact -limit 100 ; - --- end template query19.tpl query 74 in stream 8 --- start template query62.tpl query 75 in stream 8 -select /* TPC-DS query62.tpl 0.24 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 30) and - (ws_ship_date_sk - ws_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 60) and - (ws_ship_date_sk - ws_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 90) and - (ws_ship_date_sk - ws_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - web_sales - ,warehouse - ,ship_mode - ,web_site - ,date_dim -where - d_month_seq between 1196 and 1196 + 11 -and ws_ship_date_sk = d_date_sk -and ws_warehouse_sk = w_warehouse_sk -and ws_ship_mode_sk = sm_ship_mode_sk -and ws_web_site_sk = web_site_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -limit 100; - --- end template query62.tpl query 75 in stream 8 --- start template query8.tpl query 76 in stream 8 -select /* TPC-DS query8.tpl 0.63 */ s_store_name - ,sum(ss_net_profit) - from store_sales - ,date_dim - ,store, - (select ca_zip - from ( - SELECT substring(ca_zip,1,5) ca_zip - FROM customer_address - WHERE substring(ca_zip,1,5) IN ( - '48871','20471','42624','50715','28065','34670', - '94486','94915','18633','69919','82857', - '91066','24096','20467','12332','37157', - '78088','92694','58768','43188','79744', - '70511','37705','11931','48067','25428', - '86346','30544','78396','27762','24877', - '13037','32626','31228','36819','83792', - '55973','53855','86500','24902','75287', - '53562','43669','84784','87985','40288', - '74271','48889','79861','75089','32229', - '55593','23914','16821','90897','22971', - '63121','89257','46570','15439','51918', - '67757','54846','20558','71196','97233', - '21330','81352','80706','80130','23273', - '19482','97041','17429','72888','67555', - '39005','14808','94550','98323','26627', - '36748','94564','11367','16931','11998', - '49057','80984','89878','18450','35766', - '29677','67593','73211','86367','18631', - '90563','89648','60402','42718','30271', - '34309','10763','18039','35700','58474', - '63345','15040','57671','56109','42048', - '76053','50361','34669','83624','79240', - '22197','76563','56532','82844','74024', - '29801','48652','38091','41616','38186', - '68241','17275','84247','21943','81946', - '90947','65009','56906','45819','76877', - '97141','98529','63297','15243','68881', - '93491','66609','69815','17905','30612', - '96471','80812','13239','49520','64135', - '80808','60267','82806','41361','25526', - '95582','16030','88719','89000','26120', - '15736','85559','15217','41541','51391', - '83912','45645','38120','53712','69613', - '45283','32152','52785','20462','76530', - '71272','84366','96442','73024','50429', - '36771','69328','49855','32852','64506', - '59221','54416','75488','65902','98906', - '83097','79554','16150','38191','19184', - '30060','96599','47309','61826','11983', - '39842','16562','95297','40567','95661', - '40148','47172','79343','49105','72825', - '73565','66126','17406','20491','55585', - '40207','56203','29430','80011','60643', - '16683','69650','72928','47092','12411', - '79198','24612','64930','16998','65754', - '15129','81234','85024','72261','98926', - '56967','92505','72785','95401','61531', - '31667','59532','57921','53123','38844', - '13174','58851','96873','55083','82505', - '85623','14805','23459','30411','36250', - '54014','17443','39983','50901','24182', - '30604','57138','90106','31718','60285', - '38621','11379','14864','19887','70660', - '48018','34490','32829','58671','23012', - '14563','96587','12056','26706','73414', - '62750','96465','96345','23623','72304', - '92552','55292','12734','80677','16257', - '80729','33360','21419','24466','14189', - '89722','18809','90832','48448','39760', - '92476','24732','38531','36760','30252', - '84962','57759','70300','81193','18083', - '62752','55745','29392','99046','72990', - '50792','44482','29924','23440','52661', - '91873','10609','23979','85437','91237', - '36336','61535','50058','45846','39326', - '52881','19549','47155','51440','57926', - '82425','84874','95371','82915','96742', - '68414','28843','79682','87577','58274', - '43265','42063','75413','59550','73366', - '25939','26564','47689','26110','80964', - '90500','74070','82988','12840','33158', - '39566','86840','66753','64578','35850', - '37874','85567','73415','12523','80037', - '70219','73843','17158','70367','89695', - '46451','64523','47601','61855','12419', - '36234','83989','15229','68895','14033', - '53122','71677','16286','47290','29029', - '75199','35837','64743','66170','26168', - '55075','87870','52308','62621') - intersect - select ca_zip - from (SELECT substring(ca_zip,1,5) ca_zip,count(*) cnt - FROM customer_address, customer - WHERE ca_address_sk = c_current_addr_sk and - c_preferred_cust_flag='Y' - group by ca_zip - having count(*) > 10)A1)A2) V1 - where ss_store_sk = s_store_sk - and ss_sold_date_sk = d_date_sk - and d_qoy = 1 and d_year = 2001 - and (substring(s_zip,1,2) = substring(V1.ca_zip,1,2)) - group by s_store_name - order by s_store_name - limit 100; - --- end template query8.tpl query 76 in stream 8 --- start template query96.tpl query 77 in stream 8 -select /* TPC-DS query96.tpl 0.1 */ count(*) -from store_sales - ,household_demographics - ,time_dim, store -where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 20 - and time_dim.t_minute >= 30 - and household_demographics.hd_dep_count = 7 - and store.s_store_name = 'ese' -order by count(*) -limit 100; - --- end template query96.tpl query 77 in stream 8 --- start template query1.tpl query 78 in stream 8 -with /* TPC-DS query1.tpl 0.12 */ customer_total_return as -(select sr_customer_sk as ctr_customer_sk -,sr_store_sk as ctr_store_sk -,sum(SR_REFUNDED_CASH) as ctr_total_return -from store_returns -,date_dim -where sr_returned_date_sk = d_date_sk -and d_year =2002 -group by sr_customer_sk -,sr_store_sk) - select c_customer_id -from customer_total_return ctr1 -,store -,customer -where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 -from customer_total_return ctr2 -where ctr1.ctr_store_sk = ctr2.ctr_store_sk) -and s_store_sk = ctr1.ctr_store_sk -and s_state = 'TX' -and ctr1.ctr_customer_sk = c_customer_sk -order by c_customer_id -limit 100; - --- end template query1.tpl query 78 in stream 8 --- start template query23.tpl query 79 in stream 8 -with /* TPC-DS query23.tpl 0.68 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (1999,1999+1,1999+2,1999+3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1999,1999+1,1999+2,1999+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * -from - max_store_sales)) - select sum(sales) - from (select cs_quantity*cs_list_price sales - from catalog_sales - ,date_dim - where d_year = 1999 - and d_moy = 4 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - union all - select ws_quantity*ws_list_price sales - from web_sales - ,date_dim - where d_year = 1999 - and d_moy = 4 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer)) - limit 100; -with /* TPC-DS query23.tpl 0.68 part2 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (1999,1999 + 1,1999 + 2,1999 + 3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (1999,1999+1,1999+2,1999+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * - from max_store_sales)) - select c_last_name,c_first_name,sales - from (select c_last_name,c_first_name,sum(cs_quantity*cs_list_price) sales - from catalog_sales - ,customer - ,date_dim - where d_year = 1999 - and d_moy = 4 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and cs_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name - union all - select c_last_name,c_first_name,sum(ws_quantity*ws_list_price) sales - from web_sales - ,customer - ,date_dim - where d_year = 1999 - and d_moy = 4 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and ws_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name) - order by c_last_name,c_first_name,sales - limit 100; - --- end template query23.tpl query 79 in stream 8 --- start template query88.tpl query 80 in stream 8 -select /* TPC-DS query88.tpl 0.66 */ * -from - (select count(*) h8_30_to_9 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2)) - and store.s_store_name = 'ese') s1, - (select count(*) h9_to_9_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2)) - and store.s_store_name = 'ese') s2, - (select count(*) h9_30_to_10 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2)) - and store.s_store_name = 'ese') s3, - (select count(*) h10_to_10_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2)) - and store.s_store_name = 'ese') s4, - (select count(*) h10_30_to_11 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2)) - and store.s_store_name = 'ese') s5, - (select count(*) h11_to_11_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2)) - and store.s_store_name = 'ese') s6, - (select count(*) h11_30_to_12 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2)) - and store.s_store_name = 'ese') s7, - (select count(*) h12_to_12_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 12 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2)) - and store.s_store_name = 'ese') s8 -; - --- end template query88.tpl query 80 in stream 8 --- start template query82.tpl query 81 in stream 8 -select /* TPC-DS query82.tpl 0.67 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, store_sales - where i_current_price between 49 and 49+30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('2001-01-19' as date) and dateadd(day,60,cast('2001-01-19' as date)) - and i_manufact_id in (430,479,518,741) - and inv_quantity_on_hand between 100 and 500 - and ss_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query82.tpl query 81 in stream 8 --- start template query87.tpl query 82 in stream 8 -select /* TPC-DS query87.tpl 0.77 */ count(*) -from ((select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1198 and 1198+11) - except - (select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1198 and 1198+11) - except - (select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1198 and 1198+11) -) cool_cust -; - --- end template query87.tpl query 82 in stream 8 --- start template query43.tpl query 83 in stream 8 -select /* TPC-DS query43.tpl 0.15 */ s_store_name, s_store_id, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from date_dim, store_sales, store - where d_date_sk = ss_sold_date_sk and - s_store_sk = ss_store_sk and - s_gmt_offset = -5 and - d_year = 1998 - group by s_store_name, s_store_id - order by s_store_name, s_store_id,sun_sales,mon_sales,tue_sales,wed_sales,thu_sales,fri_sales,sat_sales - limit 100; - --- end template query43.tpl query 83 in stream 8 --- start template query53.tpl query 84 in stream 8 -select /* TPC-DS query53.tpl 0.88 */ * from -(select i_manufact_id, -sum(ss_sales_price) sum_sales, -avg(sum(ss_sales_price)) over (partition by i_manufact_id) avg_quarterly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and -ss_sold_date_sk = d_date_sk and -ss_store_sk = s_store_sk and -d_month_seq in (1183,1183+1,1183+2,1183+3,1183+4,1183+5,1183+6,1183+7,1183+8,1183+9,1183+10,1183+11) and -((i_category in ('Books','Children','Electronics') and -i_class in ('personal','portable','reference','self-help') and -i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) -or(i_category in ('Women','Music','Men') and -i_class in ('accessories','classical','fragrances','pants') and -i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manufact_id, d_qoy ) tmp1 -where case when avg_quarterly_sales > 0 - then abs (sum_sales - avg_quarterly_sales)/ avg_quarterly_sales - else null end > 0.1 -order by avg_quarterly_sales, - sum_sales, - i_manufact_id -limit 100; - --- end template query53.tpl query 84 in stream 8 --- start template query20.tpl query 85 in stream 8 -select /* TPC-DS query20.tpl 0.65 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(cs_ext_sales_price) as itemrevenue - ,sum(cs_ext_sales_price)*100/sum(sum(cs_ext_sales_price)) over - (partition by i_class) as revenueratio - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and i_category in ('Shoes', 'Home', 'Books') - and cs_sold_date_sk = d_date_sk - and d_date between cast('1998-01-17' as date) - and dateadd(day,30,cast('1998-01-17' as date)) - group by i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - order by i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query20.tpl query 85 in stream 8 --- start template query52.tpl query 86 in stream 8 -select /* TPC-DS query52.tpl 0.59 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_sales_price) ext_price - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=11 - and dt.d_year=2001 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,ext_price desc - ,brand_id -limit 100 ; - --- end template query52.tpl query 86 in stream 8 --- start template query83.tpl query 87 in stream 8 -with /* TPC-DS query83.tpl 0.96 */ sr_items as - (select i_item_id item_id, - sum(sr_return_quantity) sr_item_qty - from store_returns, - item, - date_dim - where sr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2002-04-25','2002-08-12','2002-11-15'))) - and sr_returned_date_sk = d_date_sk - group by i_item_id), - cr_items as - (select i_item_id item_id, - sum(cr_return_quantity) cr_item_qty - from catalog_returns, - item, - date_dim - where cr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2002-04-25','2002-08-12','2002-11-15'))) - and cr_returned_date_sk = d_date_sk - group by i_item_id), - wr_items as - (select i_item_id item_id, - sum(wr_return_quantity) wr_item_qty - from web_returns, - item, - date_dim - where wr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2002-04-25','2002-08-12','2002-11-15'))) - and wr_returned_date_sk = d_date_sk - group by i_item_id) - select sr_items.item_id - ,sr_item_qty - ,sr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 sr_dev - ,cr_item_qty - ,cr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 cr_dev - ,wr_item_qty - ,wr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 wr_dev - ,(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 average - from sr_items - ,cr_items - ,wr_items - where sr_items.item_id=cr_items.item_id - and sr_items.item_id=wr_items.item_id - order by sr_items.item_id - ,sr_item_qty - limit 100; - --- end template query83.tpl query 87 in stream 8 --- start template query38.tpl query 88 in stream 8 -select /* TPC-DS query38.tpl 0.54 */ count(*) from ( - select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1187 and 1187 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1187 and 1187 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1187 and 1187 + 11 -) hot_cust -limit 100; - --- end template query38.tpl query 88 in stream 8 --- start template query68.tpl query 89 in stream 8 -select /* TPC-DS query68.tpl 0.95 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,extended_price - ,extended_tax - ,list_price - from (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_ext_sales_price) extended_price - ,sum(ss_ext_list_price) list_price - ,sum(ss_ext_tax) extended_tax - from store_sales - ,date_dim - ,store - ,household_demographics - ,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_dep_count = 5 or - household_demographics.hd_vehicle_count= 0) - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_city in ('Oakland','Mount Vernon') - group by ss_ticket_number - ,ss_customer_sk - ,ss_addr_sk,ca_city) dn - ,customer - ,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,ss_ticket_number - limit 100; - --- end template query68.tpl query 89 in stream 8 --- start template query4.tpl query 90 in stream 8 -with /* TPC-DS query4.tpl 0.93 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(((ss_ext_list_price-ss_ext_wholesale_cost-ss_ext_discount_amt)+ss_ext_sales_price)/2) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((cs_ext_list_price-cs_ext_wholesale_cost-cs_ext_discount_amt)+cs_ext_sales_price)/2) ) year_total - ,'c' sale_type - from customer - ,catalog_sales - ,date_dim - where c_customer_sk = cs_bill_customer_sk - and cs_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year -union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((ws_ext_list_price-ws_ext_wholesale_cost-ws_ext_discount_amt)+ws_ext_sales_price)/2) ) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_birth_country - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_c_firstyear - ,year_total t_c_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_c_secyear.customer_id - and t_s_firstyear.customer_id = t_c_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_c_firstyear.sale_type = 'c' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_c_secyear.sale_type = 'c' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 2001 - and t_s_secyear.dyear = 2001+1 - and t_c_firstyear.dyear = 2001 - and t_c_secyear.dyear = 2001+1 - and t_w_firstyear.dyear = 2001 - and t_w_secyear.dyear = 2001+1 - and t_s_firstyear.year_total > 0 - and t_c_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_birth_country -limit 100; - --- end template query4.tpl query 90 in stream 8 --- start template query13.tpl query 91 in stream 8 -select /* TPC-DS query13.tpl 0.91 */ avg(ss_quantity) - ,avg(ss_ext_sales_price) - ,avg(ss_ext_wholesale_cost) - ,sum(ss_ext_wholesale_cost) - from store_sales - ,store - ,customer_demographics - ,household_demographics - ,customer_address - ,date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2001 - and((ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'W' - and cd_education_status = 'College' - and ss_sales_price between 100.00 and 150.00 - and hd_dep_count = 3 - )or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'D' - and cd_education_status = 'Secondary' - and ss_sales_price between 50.00 and 100.00 - and hd_dep_count = 1 - ) or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'S' - and cd_education_status = 'Advanced Degree' - and ss_sales_price between 150.00 and 200.00 - and hd_dep_count = 1 - )) - and((ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('AR', 'MI', 'WI') - and ss_net_profit between 100 and 200 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('NE', 'KS', 'VA') - and ss_net_profit between 150 and 300 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('WV', 'ME', 'TX') - and ss_net_profit between 50 and 250 - )) -; - --- end template query13.tpl query 91 in stream 8 --- start template query48.tpl query 92 in stream 8 -select /* TPC-DS query48.tpl 0.74 */ sum (ss_quantity) - from store_sales, store, customer_demographics, customer_address, date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2001 - and - ( - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'S' - and - cd_education_status = 'Primary' - and - ss_sales_price between 100.00 and 150.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'W' - and - cd_education_status = '4 yr Degree' - and - ss_sales_price between 50.00 and 100.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'M' - and - cd_education_status = 'Advanced Degree' - and - ss_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('IL', 'NV', 'UT') - and ss_net_profit between 0 and 2000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('NY', 'IA', 'MO') - and ss_net_profit between 150 and 3000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('OK', 'NE', 'AZ') - and ss_net_profit between 50 and 25000 - ) - ) -; - --- end template query48.tpl query 92 in stream 8 --- start template query99.tpl query 93 in stream 8 -select /* TPC-DS query99.tpl 0.94 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 30) and - (cs_ship_date_sk - cs_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 60) and - (cs_ship_date_sk - cs_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 90) and - (cs_ship_date_sk - cs_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - catalog_sales - ,warehouse - ,ship_mode - ,call_center - ,date_dim -where - d_month_seq between 1201 and 1201 + 11 -and cs_ship_date_sk = d_date_sk -and cs_warehouse_sk = w_warehouse_sk -and cs_ship_mode_sk = sm_ship_mode_sk -and cs_call_center_sk = cc_call_center_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -limit 100; - --- end template query99.tpl query 93 in stream 8 --- start template query27a.tpl query 94 in stream 8 -with /* TPC-DS query27a.tpl 0.16 */ results as - (select i_item_id, - s_state, 0 as g_state, - ss_quantity agg1, - ss_list_price agg2, - ss_coupon_amt agg3, - ss_sales_price agg4 - from store_sales, customer_demographics, date_dim, store, item - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_store_sk = s_store_sk and - ss_cdemo_sk = cd_demo_sk and - cd_gender = 'M' and - cd_marital_status = 'M' and - cd_education_status = '4 yr Degree' and - d_year = 2000 and - s_state in ('AL','PA', 'IN', 'GA', 'MO', 'SD') - ) - - select i_item_id, - s_state, g_state, agg1, agg2, agg3, agg4 - from ( - select i_item_id, s_state, 0 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4 from results - group by i_item_id, s_state - union all - select i_item_id, NULL AS s_state, 1 AS g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as s_state, 1 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - ) foo - order by i_item_id, s_state - limit 100; - --- end template query27a.tpl query 94 in stream 8 --- start template query18a.tpl query 95 in stream 8 -with /* TPC-DS query18a.tpl 0.90 */ results as - (select i_item_id, - ca_country, - ca_state, - ca_county, - cast(cs_quantity as decimal(12,2)) agg1, - cast(cs_list_price as decimal(12,2)) agg2, - cast(cs_coupon_amt as decimal(12,2)) agg3, - cast(cs_sales_price as decimal(12,2)) agg4, - cast(cs_net_profit as decimal(12,2)) agg5, - cast(c_birth_year as decimal(12,2)) agg6, - cast(cd1.cd_dep_count as decimal(12,2)) agg7 - from catalog_sales, customer_demographics cd1, customer_demographics cd2, customer, customer_address, date_dim, item - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd1.cd_demo_sk and - cs_bill_customer_sk = c_customer_sk and - cd1.cd_gender = 'F' and - cd1.cd_education_status = 'Unknown' and - c_current_cdemo_sk = cd2.cd_demo_sk and - c_current_addr_sk = ca_address_sk and - c_birth_month in (9,6,5,10,7,8) and - d_year = 2000 and - ca_state in ('GA','WI','KS','VA','CO','TX','AR') - ) - select i_item_id, ca_country, ca_state, ca_county, agg1, agg2, agg3, agg4, agg5, agg6, agg7 - from ( - select i_item_id, ca_country, ca_state, ca_county, avg(agg1) agg1, - avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state, ca_county - union all - select i_item_id, ca_country, ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state - union all - select i_item_id, ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country - union all - select i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - ) foo - order by ca_country, ca_state, ca_county, i_item_id - limit 100; - --- end template query18a.tpl query 95 in stream 8 --- start template query15.tpl query 96 in stream 8 -select /* TPC-DS query15.tpl 0.57 */ ca_zip - ,sum(cs_sales_price) - from catalog_sales - ,customer - ,customer_address - ,date_dim - where cs_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', - '85392', '85460', '80348', '81792') - or ca_state in ('CA','WA','GA') - or cs_sales_price > 500) - and cs_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 1998 - group by ca_zip - order by ca_zip - limit 100; - --- end template query15.tpl query 96 in stream 8 --- start template query33.tpl query 97 in stream 8 -with /* TPC-DS query33.tpl 0.22 */ ss as ( - select - i_manufact_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Books')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 4 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_manufact_id), - cs as ( - select - i_manufact_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Books')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 4 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_manufact_id), - ws as ( - select - i_manufact_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Books')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 4 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -5 - group by i_manufact_id) - select i_manufact_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_manufact_id - order by total_sales -limit 100; - --- end template query33.tpl query 97 in stream 8 --- start template query31.tpl query 98 in stream 8 -with /* TPC-DS query31.tpl 0.50 */ ss as - (select ca_county,d_qoy, d_year,sum(ss_ext_sales_price) as store_sales - from store_sales,date_dim,customer_address - where ss_sold_date_sk = d_date_sk - and ss_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year), - ws as - (select ca_county,d_qoy, d_year,sum(ws_ext_sales_price) as web_sales - from web_sales,date_dim,customer_address - where ws_sold_date_sk = d_date_sk - and ws_bill_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year) - select - ss1.ca_county - ,ss1.d_year - ,ws2.web_sales/ws1.web_sales web_q1_q2_increase - ,ss2.store_sales/ss1.store_sales store_q1_q2_increase - ,ws3.web_sales/ws2.web_sales web_q2_q3_increase - ,ss3.store_sales/ss2.store_sales store_q2_q3_increase - from - ss ss1 - ,ss ss2 - ,ss ss3 - ,ws ws1 - ,ws ws2 - ,ws ws3 - where - ss1.d_qoy = 1 - and ss1.d_year = 2002 - and ss1.ca_county = ss2.ca_county - and ss2.d_qoy = 2 - and ss2.d_year = 2002 - and ss2.ca_county = ss3.ca_county - and ss3.d_qoy = 3 - and ss3.d_year = 2002 - and ss1.ca_county = ws1.ca_county - and ws1.d_qoy = 1 - and ws1.d_year = 2002 - and ws1.ca_county = ws2.ca_county - and ws2.d_qoy = 2 - and ws2.d_year = 2002 - and ws1.ca_county = ws3.ca_county - and ws3.d_qoy = 3 - and ws3.d_year =2002 - and case when ws1.web_sales > 0 then ws2.web_sales/ws1.web_sales else null end - > case when ss1.store_sales > 0 then ss2.store_sales/ss1.store_sales else null end - and case when ws2.web_sales > 0 then ws3.web_sales/ws2.web_sales else null end - > case when ss2.store_sales > 0 then ss3.store_sales/ss2.store_sales else null end - order by ss1.d_year; - --- end template query31.tpl query 98 in stream 8 --- start template query63.tpl query 99 in stream 8 -select /* TPC-DS query63.tpl 0.27 */ * -from (select i_manager_id - ,sum(ss_sales_price) sum_sales - ,avg(sum(ss_sales_price)) over (partition by i_manager_id) avg_monthly_sales - from item - ,store_sales - ,date_dim - ,store - where ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and d_month_seq in (1177,1177+1,1177+2,1177+3,1177+4,1177+5,1177+6,1177+7,1177+8,1177+9,1177+10,1177+11) - and (( i_category in ('Books','Children','Electronics') - and i_class in ('personal','portable','reference','self-help') - and i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) - or( i_category in ('Women','Music','Men') - and i_class in ('accessories','classical','fragrances','pants') - and i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manager_id, d_moy) tmp1 -where case when avg_monthly_sales > 0 then abs (sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 -order by i_manager_id - ,avg_monthly_sales - ,sum_sales -limit 100; - --- end template query63.tpl query 99 in stream 8 diff --git a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/1TB/queries/query_9.sql b/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/1TB/queries/query_9.sql deleted file mode 100644 index 0500e9d4..00000000 --- a/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCDS/1TB/queries/query_9.sql +++ /dev/null @@ -1,5027 +0,0 @@ --- start template query15.tpl query 1 in stream 9 -select /* TPC-DS query15.tpl 0.57 */ ca_zip - ,sum(cs_sales_price) - from catalog_sales - ,customer - ,customer_address - ,date_dim - where cs_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', - '85392', '85460', '80348', '81792') - or ca_state in ('CA','WA','GA') - or cs_sales_price > 500) - and cs_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 1998 - group by ca_zip - order by ca_zip - limit 100; - --- end template query15.tpl query 1 in stream 9 --- start template query60.tpl query 2 in stream 9 -with /* TPC-DS query60.tpl 0.29 */ ss as ( - select - i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Children')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 10 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - cs as ( - select - i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Children')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 10 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - ws as ( - select - i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from - item -where i_category in ('Children')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2002 - and d_moy = 10 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id) - select - i_item_id -,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by i_item_id - ,total_sales - limit 100; - --- end template query60.tpl query 2 in stream 9 --- start template query62.tpl query 3 in stream 9 -select /* TPC-DS query62.tpl 0.24 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 30) and - (ws_ship_date_sk - ws_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 60) and - (ws_ship_date_sk - ws_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 90) and - (ws_ship_date_sk - ws_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - web_sales - ,warehouse - ,ship_mode - ,web_site - ,date_dim -where - d_month_seq between 1194 and 1194 + 11 -and ws_ship_date_sk = d_date_sk -and ws_warehouse_sk = w_warehouse_sk -and ws_ship_mode_sk = sm_ship_mode_sk -and ws_web_site_sk = web_site_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,web_name -limit 100; - --- end template query62.tpl query 3 in stream 9 --- start template query74.tpl query 4 in stream 9 -with /* TPC-DS query74.tpl 0.76 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,avg(ss_net_paid) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (2001,2001+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,d_year as year - ,avg(ws_net_paid) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - and d_year in (2001,2001+1) - group by c_customer_id - ,c_first_name - ,c_last_name - ,d_year - ) - select - t_s_secyear.customer_id, t_s_secyear.customer_first_name, t_s_secyear.customer_last_name - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.year = 2001 - and t_s_secyear.year = 2001+1 - and t_w_firstyear.year = 2001 - and t_w_secyear.year = 2001+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - order by 2,1,3 -limit 100; - --- end template query74.tpl query 4 in stream 9 --- start template query81.tpl query 5 in stream 9 -with /* TPC-DS query81.tpl 0.37 */ customer_total_return as - (select cr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(cr_return_amt_inc_tax) as ctr_total_return - from catalog_returns - ,date_dim - ,customer_address - where cr_returned_date_sk = d_date_sk - and d_year =2001 - and cr_returning_addr_sk = ca_address_sk - group by cr_returning_customer_sk - ,ca_state ) - select c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'AK' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name - ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset - ,ca_location_type,ctr_total_return - limit 100; - --- end template query81.tpl query 5 in stream 9 --- start template query88.tpl query 6 in stream 9 -select /* TPC-DS query88.tpl 0.66 */ * -from - (select count(*) h8_30_to_9 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 8 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2)) - and store.s_store_name = 'ese') s1, - (select count(*) h9_to_9_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2)) - and store.s_store_name = 'ese') s2, - (select count(*) h9_30_to_10 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 9 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2)) - and store.s_store_name = 'ese') s3, - (select count(*) h10_to_10_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2)) - and store.s_store_name = 'ese') s4, - (select count(*) h10_30_to_11 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 10 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2)) - and store.s_store_name = 'ese') s5, - (select count(*) h11_to_11_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2)) - and store.s_store_name = 'ese') s6, - (select count(*) h11_30_to_12 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 11 - and time_dim.t_minute >= 30 - and ((household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2)) - and store.s_store_name = 'ese') s7, - (select count(*) h12_to_12_30 - from store_sales, household_demographics , time_dim, store - where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 12 - and time_dim.t_minute < 30 - and ((household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or - (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or - (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2)) - and store.s_store_name = 'ese') s8 -; - --- end template query88.tpl query 6 in stream 9 --- start template query50.tpl query 7 in stream 9 -select /* TPC-DS query50.tpl 0.60 */ - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 30) and - (sr_returned_date_sk - ss_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 60) and - (sr_returned_date_sk - ss_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 90) and - (sr_returned_date_sk - ss_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - store_sales - ,store_returns - ,store - ,date_dim d1 - ,date_dim d2 -where - d2.d_year = 1999 -and d2.d_moy = 8 -and ss_ticket_number = sr_ticket_number -and ss_item_sk = sr_item_sk -and ss_sold_date_sk = d1.d_date_sk -and sr_returned_date_sk = d2.d_date_sk -and ss_customer_sk = sr_customer_sk -and ss_store_sk = s_store_sk -group by - s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -order by s_store_name - ,s_company_id - ,s_street_number - ,s_street_name - ,s_street_type - ,s_suite_number - ,s_city - ,s_county - ,s_state - ,s_zip -limit 100; - --- end template query50.tpl query 7 in stream 9 --- start template query5a.tpl query 8 in stream 9 -with /* TPC-DS query5a.tpl 0.98 */ ssr as - (select s_store_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ss_store_sk as store_sk, - ss_sold_date_sk as date_sk, - ss_ext_sales_price as sales_price, - ss_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from store_sales - union all - select sr_store_sk as store_sk, - sr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - sr_return_amt as return_amt, - sr_net_loss as net_loss - from store_returns - ) salesreturns, - date_dim, - store - where date_sk = d_date_sk - and d_date between cast('2000-08-10' as date) - and dateadd(day,14,cast('2000-08-10' as date)) - and store_sk = s_store_sk - group by s_store_id) - , - csr as - (select cp_catalog_page_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select cs_catalog_page_sk as page_sk, - cs_sold_date_sk as date_sk, - cs_ext_sales_price as sales_price, - cs_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from catalog_sales - union all - select cr_catalog_page_sk as page_sk, - cr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - cr_return_amount as return_amt, - cr_net_loss as net_loss - from catalog_returns - ) salesreturns, - date_dim, - catalog_page - where date_sk = d_date_sk - and d_date between cast('2000-08-10' as date) - and dateadd(day,14,cast('2000-08-10' as date)) - and page_sk = cp_catalog_page_sk - group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(sales_price) as sales, - sum(profit) as profit, - sum(return_amt) as returns, - sum(net_loss) as profit_loss - from - ( select ws_web_site_sk as wsr_web_site_sk, - ws_sold_date_sk as date_sk, - ws_ext_sales_price as sales_price, - ws_net_profit as profit, - cast(0 as decimal(7,2)) as return_amt, - cast(0 as decimal(7,2)) as net_loss - from web_sales - union all - select ws_web_site_sk as wsr_web_site_sk, - wr_returned_date_sk as date_sk, - cast(0 as decimal(7,2)) as sales_price, - cast(0 as decimal(7,2)) as profit, - wr_return_amt as return_amt, - wr_net_loss as net_loss - from web_returns left outer join web_sales on - ( wr_item_sk = ws_item_sk - and wr_order_number = ws_order_number) - ) salesreturns, - date_dim, - web_site - where date_sk = d_date_sk - and d_date between cast('2000-08-10' as date) - and dateadd(day,14,cast('2000-08-10' as date)) - and wsr_web_site_sk = web_site_sk - group by web_site_id) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || s_store_id as id - , sales - , returns - , (profit - profit_loss) as profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || cp_catalog_page_id as id - , sales - , returns - , (profit - profit_loss) as profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , (profit - profit_loss) as profit - from wsr - ) x - group by channel, id) - select channel, id, sales, returns, profit from ( - select channel, id, sales, returns, profit from results - union - select channel, null as id, sum(sales), sum(returns), sum(profit) from results group by channel - union - select null as channel, null as id, sum(sales), sum(returns), sum(profit) from results) foo -order by channel, id -limit 100; - --- end template query5a.tpl query 8 in stream 9 --- start template query84.tpl query 9 in stream 9 -select /* TPC-DS query84.tpl 0.80 */ c_customer_id as customer_id - , coalesce(c_last_name,'') || ', ' || coalesce(c_first_name,'') as customername - from customer - ,customer_address - ,customer_demographics - ,household_demographics - ,income_band - ,store_returns - where ca_city = 'Mount Olive' - and c_current_addr_sk = ca_address_sk - and ib_lower_bound >= 57528 - and ib_upper_bound <= 57528 + 50000 - and ib_income_band_sk = hd_income_band_sk - and cd_demo_sk = c_current_cdemo_sk - and hd_demo_sk = c_current_hdemo_sk - and sr_cdemo_sk = cd_demo_sk - order by c_customer_id - limit 100; - --- end template query84.tpl query 9 in stream 9 --- start template query1.tpl query 10 in stream 9 -with /* TPC-DS query1.tpl 0.12 */ customer_total_return as -(select sr_customer_sk as ctr_customer_sk -,sr_store_sk as ctr_store_sk -,sum(SR_RETURN_AMT) as ctr_total_return -from store_returns -,date_dim -where sr_returned_date_sk = d_date_sk -and d_year =2000 -group by sr_customer_sk -,sr_store_sk) - select c_customer_id -from customer_total_return ctr1 -,store -,customer -where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 -from customer_total_return ctr2 -where ctr1.ctr_store_sk = ctr2.ctr_store_sk) -and s_store_sk = ctr1.ctr_store_sk -and s_state = 'WV' -and ctr1.ctr_customer_sk = c_customer_sk -order by c_customer_id -limit 100; - --- end template query1.tpl query 10 in stream 9 --- start template query52.tpl query 11 in stream 9 -select /* TPC-DS query52.tpl 0.59 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_ext_sales_price) ext_price - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=11 - and dt.d_year=1999 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,ext_price desc - ,brand_id -limit 100 ; - --- end template query52.tpl query 11 in stream 9 --- start template query57.tpl query 12 in stream 9 -with /* TPC-DS query57.tpl 0.70 */ v1 as( - select i_category, i_brand, - cc_name, - d_year, d_moy, - sum(cs_sales_price) sum_sales, - avg(sum(cs_sales_price)) over - (partition by i_category, i_brand, - cc_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - cc_name - order by d_year, d_moy) rn - from item, catalog_sales, date_dim, call_center - where cs_item_sk = i_item_sk and - cs_sold_date_sk = d_date_sk and - cc_call_center_sk= cs_call_center_sk and - ( - d_year = 2001 or - ( d_year = 2001-1 and d_moy =12) or - ( d_year = 2001+1 and d_moy =1) - ) - group by i_category, i_brand, - cc_name , d_year, d_moy), - v2 as( - select v1.i_category, v1.i_brand - ,v1.d_year - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1. cc_name = v1_lag. cc_name and - v1. cc_name = v1_lead. cc_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 2001 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, sum_sales - limit 100; - --- end template query57.tpl query 12 in stream 9 --- start template query13.tpl query 13 in stream 9 -select /* TPC-DS query13.tpl 0.91 */ avg(ss_quantity) - ,avg(ss_ext_sales_price) - ,avg(ss_ext_wholesale_cost) - ,sum(ss_ext_wholesale_cost) - from store_sales - ,store - ,customer_demographics - ,household_demographics - ,customer_address - ,date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2001 - and((ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'U' - and cd_education_status = 'College' - and ss_sales_price between 100.00 and 150.00 - and hd_dep_count = 3 - )or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'M' - and cd_education_status = '2 yr Degree' - and ss_sales_price between 50.00 and 100.00 - and hd_dep_count = 1 - ) or - (ss_hdemo_sk=hd_demo_sk - and cd_demo_sk = ss_cdemo_sk - and cd_marital_status = 'W' - and cd_education_status = 'Primary' - and ss_sales_price between 150.00 and 200.00 - and hd_dep_count = 1 - )) - and((ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('MI', 'AL', 'ID') - and ss_net_profit between 100 and 200 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('GA', 'RI', 'AR') - and ss_net_profit between 150 and 300 - ) or - (ss_addr_sk = ca_address_sk - and ca_country = 'United States' - and ca_state in ('TX', 'NC', 'WV') - and ss_net_profit between 50 and 250 - )) -; - --- end template query13.tpl query 13 in stream 9 --- start template query14a.tpl query 14 in stream 9 -with /* TPC-DS query14a.tpl 0.69 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 2000 AND 2000 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 2000 AND 2000 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 2000 AND 2000 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as - (select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2) x) -, - results AS -(select channel, i_brand_id, i_class_id, i_category_id, sum(sales) sum_sales, sum(number_sales) number_sales - from ( - select 'store' channel, i_brand_id,i_class_id - ,i_category_id,sum(ss_quantity*ss_list_price) sales - , count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 2000+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales) - union all - select 'catalog' channel, i_brand_id,i_class_id,i_category_id, sum(cs_quantity*cs_list_price) sales, count(*) number_sales - from catalog_sales - ,item - ,date_dim - where cs_item_sk in (select ss_item_sk from cross_items) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 2000+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(cs_quantity*cs_list_price) > (select average_sales from avg_sales) - union all - select 'web' channel, i_brand_id,i_class_id,i_category_id, sum(ws_quantity*ws_list_price) sales , count(*) number_sales - from web_sales - ,item - ,date_dim - where ws_item_sk in (select ss_item_sk from cross_items) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 2000+2 - and d_moy = 11 - group by i_brand_id,i_class_id,i_category_id - having sum(ws_quantity*ws_list_price) > (select average_sales from avg_sales) - ) y - group by channel, i_brand_id,i_class_id,i_category_id) - - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales -from ( - select channel, i_brand_id, i_class_id, i_category_id, sum_sales, number_sales from results - union - select channel, i_brand_id, i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id, i_class_id - union - select channel, i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel, i_brand_id - union - select channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results - group by channel - union - select null as channel, null as i_brand_id, null as i_class_id, null as i_category_id, sum(sum_sales), sum(number_sales) from results) z -order by channel, i_brand_id, i_class_id, i_category_id - limit 100; -with /* TPC-DS query14a.tpl 0.69 part2 */ cross_items as - (select i_item_sk ss_item_sk - from item, - (select iss.i_brand_id brand_id - ,iss.i_class_id class_id - ,iss.i_category_id category_id - from store_sales - ,item iss - ,date_dim d1 - where ss_item_sk = iss.i_item_sk - and ss_sold_date_sk = d1.d_date_sk - and d1.d_year between 2000 AND 2000 + 2 - intersect - select ics.i_brand_id - ,ics.i_class_id - ,ics.i_category_id - from catalog_sales - ,item ics - ,date_dim d2 - where cs_item_sk = ics.i_item_sk - and cs_sold_date_sk = d2.d_date_sk - and d2.d_year between 2000 AND 2000 + 2 - intersect - select iws.i_brand_id - ,iws.i_class_id - ,iws.i_category_id - from web_sales - ,item iws - ,date_dim d3 - where ws_item_sk = iws.i_item_sk - and ws_sold_date_sk = d3.d_date_sk - and d3.d_year between 2000 AND 2000 + 2) x - where i_brand_id = brand_id - and i_class_id = class_id - and i_category_id = category_id -), - avg_sales as -(select avg(quantity*list_price) average_sales - from (select ss_quantity quantity - ,ss_list_price list_price - from store_sales - ,date_dim - where ss_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2 - union all - select cs_quantity quantity - ,cs_list_price list_price - from catalog_sales - ,date_dim - where cs_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2 - union all - select ws_quantity quantity - ,ws_list_price list_price - from web_sales - ,date_dim - where ws_sold_date_sk = d_date_sk - and d_year between 2000 and 2000 + 2) x) - select this_year.channel ty_channel - ,this_year.i_brand_id ty_brand - ,this_year.i_class_id ty_class - ,this_year.i_category_id ty_category - ,this_year.sales ty_sales - ,this_year.number_sales ty_number_sales - ,last_year.channel ly_channel - ,last_year.i_brand_id ly_brand - ,last_year.i_class_id ly_class - ,last_year.i_category_id ly_category - ,last_year.sales ly_sales - ,last_year.number_sales ly_number_sales -from - (select 'store' channel, i_brand_id,i_class_id,i_category_id - ,sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 2000 + 1 - and d_moy = 12 - and d_dom = 16) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) this_year, - (select 'store' channel, i_brand_id,i_class_id - ,i_category_id, sum(ss_quantity*ss_list_price) sales, count(*) number_sales - from store_sales - ,item - ,date_dim - where ss_item_sk in (select ss_item_sk from cross_items) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_week_seq = (select d_week_seq - from date_dim - where d_year = 2000 - and d_moy = 12 - and d_dom = 16) - group by i_brand_id,i_class_id,i_category_id - having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) last_year - where this_year.i_brand_id= last_year.i_brand_id - and this_year.i_class_id = last_year.i_class_id - and this_year.i_category_id = last_year.i_category_id - order by this_year.channel, this_year.i_brand_id, this_year.i_class_id, this_year.i_category_id - limit 100; - --- end template query14a.tpl query 14 in stream 9 --- start template query90.tpl query 15 in stream 9 -select /* TPC-DS query90.tpl 0.40 */ cast(amc as decimal(15,4))/cast(pmc as decimal(15,4)) am_pm_ratio - from ( select count(*) amc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 10 and 10+1 - and household_demographics.hd_dep_count = 0 - and web_page.wp_char_count between 5000 and 5200) at, - ( select count(*) pmc - from web_sales, household_demographics , time_dim, web_page - where ws_sold_time_sk = time_dim.t_time_sk - and ws_ship_hdemo_sk = household_demographics.hd_demo_sk - and ws_web_page_sk = web_page.wp_web_page_sk - and time_dim.t_hour between 21 and 21+1 - and household_demographics.hd_dep_count = 0 - and web_page.wp_char_count between 5000 and 5200) pt - order by am_pm_ratio - limit 100; - --- end template query90.tpl query 15 in stream 9 --- start template query7.tpl query 16 in stream 9 -select /* TPC-DS query7.tpl 0.2 */ i_item_id, - avg(ss_quantity) agg1, - avg(ss_list_price) agg2, - avg(ss_coupon_amt) agg3, - avg(ss_sales_price) agg4 - from store_sales, customer_demographics, date_dim, item, promotion - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_cdemo_sk = cd_demo_sk and - ss_promo_sk = p_promo_sk and - cd_gender = 'M' and - cd_marital_status = 'W' and - cd_education_status = 'College' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 1999 - group by i_item_id - order by i_item_id - limit 100; - --- end template query7.tpl query 16 in stream 9 --- start template query27a.tpl query 17 in stream 9 -with /* TPC-DS query27a.tpl 0.16 */ results as - (select i_item_id, - s_state, 0 as g_state, - ss_quantity agg1, - ss_list_price agg2, - ss_coupon_amt agg3, - ss_sales_price agg4 - from store_sales, customer_demographics, date_dim, store, item - where ss_sold_date_sk = d_date_sk and - ss_item_sk = i_item_sk and - ss_store_sk = s_store_sk and - ss_cdemo_sk = cd_demo_sk and - cd_gender = 'M' and - cd_marital_status = 'S' and - cd_education_status = '4 yr Degree' and - d_year = 1999 and - s_state in ('IN','FL', 'MO', 'MN', 'OH', 'LA') - ) - - select i_item_id, - s_state, g_state, agg1, agg2, agg3, agg4 - from ( - select i_item_id, s_state, 0 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4 from results - group by i_item_id, s_state - union all - select i_item_id, NULL AS s_state, 1 AS g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as s_state, 1 as g_state, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4 from results - ) foo - order by i_item_id, s_state - limit 100; - --- end template query27a.tpl query 17 in stream 9 --- start template query92.tpl query 18 in stream 9 -select /* TPC-DS query92.tpl 0.44 */ - sum(ws_ext_discount_amt) as "Excess Discount Amount" -from - web_sales - ,item - ,date_dim -where -i_manufact_id = 124 -and i_item_sk = ws_item_sk -and d_date between '1999-03-13' and - dateadd(day,90,cast('1999-03-13' as date)) -and d_date_sk = ws_sold_date_sk -and ws_ext_discount_amt - > ( - SELECT - 1.3 * avg(ws_ext_discount_amt) - FROM - web_sales - ,date_dim - WHERE - ws_item_sk = i_item_sk - and d_date between '1999-03-13' and - dateadd(day,90,cast('1999-03-13' as date)) - and d_date_sk = ws_sold_date_sk - ) -order by sum(ws_ext_discount_amt) -limit 100; - --- end template query92.tpl query 18 in stream 9 --- start template query39.tpl query 19 in stream 9 -with /* TPC-DS query39.tpl 0.5 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =1999 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=4 - and inv2.d_moy=4+1 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; -with /* TPC-DS query39.tpl 0.5 part2 */ inv as -(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stdev,mean, case mean when 0 then null else stdev/mean end cov - from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy - ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean - from inventory - ,item - ,warehouse - ,date_dim - where inv_item_sk = i_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_year =1999 - group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo - where case mean when 0 then 0 else stdev/mean end > 1) -select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov - ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov -from inv inv1,inv inv2 -where inv1.i_item_sk = inv2.i_item_sk - and inv1.w_warehouse_sk = inv2.w_warehouse_sk - and inv1.d_moy=4 - and inv2.d_moy=4+1 - and inv1.cov > 1.5 -order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov - ,inv2.d_moy,inv2.mean, inv2.cov -; - --- end template query39.tpl query 19 in stream 9 --- start template query34.tpl query 20 in stream 9 -select /* TPC-DS query34.tpl 0.73 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (date_dim.d_dom between 1 and 3 or date_dim.d_dom between 25 and 28) - and (household_demographics.hd_buy_potential = '501-1000' or - household_demographics.hd_buy_potential = 'Unknown') - and household_demographics.hd_vehicle_count > 0 - and (case when household_demographics.hd_vehicle_count > 0 - then household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count - else null - end) > 1.2 - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_county in ('Pennington County','Maverick County','Mobile County','Raleigh County', - 'Williamson County','Gage County','Fairfield County','Ziebach County') - group by ss_ticket_number,ss_customer_sk) dn,customer - where ss_customer_sk = c_customer_sk - and cnt between 15 and 20 - order by c_last_name,c_first_name,c_salutation,c_preferred_cust_flag desc, ss_ticket_number; - --- end template query34.tpl query 20 in stream 9 --- start template query21.tpl query 21 in stream 9 -select /* TPC-DS query21.tpl 0.14 */ * - from(select w_warehouse_name - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('1998-02-06' as date)) - then inv_quantity_on_hand - else 0 end) as inv_before - ,sum(case when (cast(d_date as date) >= cast ('1998-02-06' as date)) - then inv_quantity_on_hand - else 0 end) as inv_after - from inventory - ,warehouse - ,item - ,date_dim - where i_current_price between 0.99 and 1.49 - and i_item_sk = inv_item_sk - and inv_warehouse_sk = w_warehouse_sk - and inv_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('1998-02-06' as date)) - and dateadd(day,30,cast ('1998-02-06' as date)) - group by w_warehouse_name, i_item_id) x - where (case when inv_before > 0 - then inv_after / inv_before - else null - end) between 2.0/3.0 and 3.0/2.0 - order by w_warehouse_name - ,i_item_id - limit 100; - --- end template query21.tpl query 21 in stream 9 --- start template query65.tpl query 22 in stream 9 -select /* TPC-DS query65.tpl 0.71 */ - s_store_name, - i_item_desc, - sc.revenue, - i_current_price, - i_wholesale_cost, - i_brand - from store, item, - (select ss_store_sk, avg(revenue) as ave - from - (select ss_store_sk, ss_item_sk, - sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1205 and 1205+11 - group by ss_store_sk, ss_item_sk) sa - group by ss_store_sk) sb, - (select ss_store_sk, ss_item_sk, sum(ss_sales_price) as revenue - from store_sales, date_dim - where ss_sold_date_sk = d_date_sk and d_month_seq between 1205 and 1205+11 - group by ss_store_sk, ss_item_sk) sc - where sb.ss_store_sk = sc.ss_store_sk and - sc.revenue <= 0.1 * sb.ave and - s_store_sk = sc.ss_store_sk and - i_item_sk = sc.ss_item_sk - order by s_store_name, i_item_desc -limit 100; - --- end template query65.tpl query 22 in stream 9 --- start template query75.tpl query 23 in stream 9 -WITH /* TPC-DS query75.tpl 0.3 */ all_sales AS ( - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,SUM(sales_cnt) AS sales_cnt - ,SUM(sales_amt) AS sales_amt - FROM (SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,cs_quantity - COALESCE(cr_return_quantity,0) AS sales_cnt - ,cs_ext_sales_price - COALESCE(cr_return_amount,0.0) AS sales_amt - FROM catalog_sales JOIN item ON i_item_sk=cs_item_sk - JOIN date_dim ON d_date_sk=cs_sold_date_sk - LEFT JOIN catalog_returns ON (cs_order_number=cr_order_number - AND cs_item_sk=cr_item_sk) - WHERE i_category='Children' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ss_quantity - COALESCE(sr_return_quantity,0) AS sales_cnt - ,ss_ext_sales_price - COALESCE(sr_return_amt,0.0) AS sales_amt - FROM store_sales JOIN item ON i_item_sk=ss_item_sk - JOIN date_dim ON d_date_sk=ss_sold_date_sk - LEFT JOIN store_returns ON (ss_ticket_number=sr_ticket_number - AND ss_item_sk=sr_item_sk) - WHERE i_category='Children' - UNION - SELECT d_year - ,i_brand_id - ,i_class_id - ,i_category_id - ,i_manufact_id - ,ws_quantity - COALESCE(wr_return_quantity,0) AS sales_cnt - ,ws_ext_sales_price - COALESCE(wr_return_amt,0.0) AS sales_amt - FROM web_sales JOIN item ON i_item_sk=ws_item_sk - JOIN date_dim ON d_date_sk=ws_sold_date_sk - LEFT JOIN web_returns ON (ws_order_number=wr_order_number - AND ws_item_sk=wr_item_sk) - WHERE i_category='Children') sales_detail - GROUP BY d_year, i_brand_id, i_class_id, i_category_id, i_manufact_id) - SELECT prev_yr.d_year AS prev_year - ,curr_yr.d_year AS year - ,curr_yr.i_brand_id - ,curr_yr.i_class_id - ,curr_yr.i_category_id - ,curr_yr.i_manufact_id - ,prev_yr.sales_cnt AS prev_yr_cnt - ,curr_yr.sales_cnt AS curr_yr_cnt - ,curr_yr.sales_cnt-prev_yr.sales_cnt AS sales_cnt_diff - ,curr_yr.sales_amt-prev_yr.sales_amt AS sales_amt_diff - FROM all_sales curr_yr, all_sales prev_yr - WHERE curr_yr.i_brand_id=prev_yr.i_brand_id - AND curr_yr.i_class_id=prev_yr.i_class_id - AND curr_yr.i_category_id=prev_yr.i_category_id - AND curr_yr.i_manufact_id=prev_yr.i_manufact_id - AND curr_yr.d_year=2002 - AND prev_yr.d_year=2002-1 - AND CAST(curr_yr.sales_cnt AS DECIMAL(17,2))/CAST(prev_yr.sales_cnt AS DECIMAL(17,2))<0.9 - ORDER BY sales_cnt_diff,sales_amt_diff - limit 100; - --- end template query75.tpl query 23 in stream 9 --- start template query9.tpl query 24 in stream 9 -select /* TPC-DS query9.tpl 0.49 */ case when (select count(*) - from store_sales - where ss_quantity between 1 and 20) > 38215218 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 1 and 20) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 1 and 20) end bucket1 , - case when (select count(*) - from store_sales - where ss_quantity between 21 and 40) > 5887994 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 21 and 40) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 21 and 40) end bucket2, - case when (select count(*) - from store_sales - where ss_quantity between 41 and 60) > 12401907 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 41 and 60) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 41 and 60) end bucket3, - case when (select count(*) - from store_sales - where ss_quantity between 61 and 80) > 12726249 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 61 and 80) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 61 and 80) end bucket4, - case when (select count(*) - from store_sales - where ss_quantity between 81 and 100) > 30242569 - then (select avg(ss_ext_discount_amt) - from store_sales - where ss_quantity between 81 and 100) - else (select avg(ss_net_paid) - from store_sales - where ss_quantity between 81 and 100) end bucket5 -from reason -where r_reason_sk = 1 -; - --- end template query9.tpl query 24 in stream 9 --- start template query2.tpl query 25 in stream 9 -with /* TPC-DS query2.tpl 0.84 */ wscs as - (select sold_date_sk - ,sales_price - from (select ws_sold_date_sk sold_date_sk - ,ws_ext_sales_price sales_price - from web_sales - union all - select cs_sold_date_sk sold_date_sk - ,cs_ext_sales_price sales_price - from catalog_sales)), - wswscs as - (select d_week_seq, - sum(case when (d_day_name='Sunday') then sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then sales_price else null end) sat_sales - from wscs - ,date_dim - where d_date_sk = sold_date_sk - group by d_week_seq) - select d_week_seq1 - ,round(sun_sales1/sun_sales2,2) - ,round(mon_sales1/mon_sales2,2) - ,round(tue_sales1/tue_sales2,2) - ,round(wed_sales1/wed_sales2,2) - ,round(thu_sales1/thu_sales2,2) - ,round(fri_sales1/fri_sales2,2) - ,round(sat_sales1/sat_sales2,2) - from - (select wswscs.d_week_seq d_week_seq1 - ,sun_sales sun_sales1 - ,mon_sales mon_sales1 - ,tue_sales tue_sales1 - ,wed_sales wed_sales1 - ,thu_sales thu_sales1 - ,fri_sales fri_sales1 - ,sat_sales sat_sales1 - from wswscs,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 2000) y, - (select wswscs.d_week_seq d_week_seq2 - ,sun_sales sun_sales2 - ,mon_sales mon_sales2 - ,tue_sales tue_sales2 - ,wed_sales wed_sales2 - ,thu_sales thu_sales2 - ,fri_sales fri_sales2 - ,sat_sales sat_sales2 - from wswscs - ,date_dim - where date_dim.d_week_seq = wswscs.d_week_seq and - d_year = 2000+1) z - where d_week_seq1=d_week_seq2-53 - order by d_week_seq1; - --- end template query2.tpl query 25 in stream 9 --- start template query12.tpl query 26 in stream 9 -select /* TPC-DS query12.tpl 0.64 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ws_ext_sales_price) as itemrevenue - ,sum(ws_ext_sales_price)*100/sum(sum(ws_ext_sales_price)) over - (partition by i_class) as revenueratio -from - web_sales - ,item - ,date_dim -where - ws_item_sk = i_item_sk - and i_category in ('Women', 'Books', 'Children') - and ws_sold_date_sk = d_date_sk - and d_date between cast('1998-06-02' as date) - and dateadd(day,30,cast('1998-06-02' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query12.tpl query 26 in stream 9 --- start template query32.tpl query 27 in stream 9 -select /* TPC-DS query32.tpl 0.7 */ sum(cs_ext_discount_amt) as "excess discount amount" -from - catalog_sales - ,item - ,date_dim -where -i_manufact_id = 285 -and i_item_sk = cs_item_sk -and d_date between '1998-01-15' and - dateadd(day,90,cast('1998-01-15' as date)) -and d_date_sk = cs_sold_date_sk -and cs_ext_discount_amt - > ( - select - 1.3 * avg(cs_ext_discount_amt) - from - catalog_sales - ,date_dim - where - cs_item_sk = i_item_sk - and d_date between '1998-01-15' and - dateadd(day,90,cast('1998-01-15' as date)) - and d_date_sk = cs_sold_date_sk - ) -limit 100; - --- end template query32.tpl query 27 in stream 9 --- start template query28.tpl query 28 in stream 9 -select /* TPC-DS query28.tpl 0.36 */ * -from (select avg(ss_list_price) B1_LP - ,count(ss_list_price) B1_CNT - ,count(distinct ss_list_price) B1_CNTD - from store_sales - where ss_quantity between 0 and 5 - and (ss_list_price between 107 and 107+10 - or ss_coupon_amt between 2994 and 2994+1000 - or ss_wholesale_cost between 39 and 39+20)) B1, - (select avg(ss_list_price) B2_LP - ,count(ss_list_price) B2_CNT - ,count(distinct ss_list_price) B2_CNTD - from store_sales - where ss_quantity between 6 and 10 - and (ss_list_price between 71 and 71+10 - or ss_coupon_amt between 8443 and 8443+1000 - or ss_wholesale_cost between 19 and 19+20)) B2, - (select avg(ss_list_price) B3_LP - ,count(ss_list_price) B3_CNT - ,count(distinct ss_list_price) B3_CNTD - from store_sales - where ss_quantity between 11 and 15 - and (ss_list_price between 140 and 140+10 - or ss_coupon_amt between 6138 and 6138+1000 - or ss_wholesale_cost between 65 and 65+20)) B3, - (select avg(ss_list_price) B4_LP - ,count(ss_list_price) B4_CNT - ,count(distinct ss_list_price) B4_CNTD - from store_sales - where ss_quantity between 16 and 20 - and (ss_list_price between 125 and 125+10 - or ss_coupon_amt between 17999 and 17999+1000 - or ss_wholesale_cost between 44 and 44+20)) B4, - (select avg(ss_list_price) B5_LP - ,count(ss_list_price) B5_CNT - ,count(distinct ss_list_price) B5_CNTD - from store_sales - where ss_quantity between 21 and 25 - and (ss_list_price between 116 and 116+10 - or ss_coupon_amt between 2346 and 2346+1000 - or ss_wholesale_cost between 6 and 6+20)) B5, - (select avg(ss_list_price) B6_LP - ,count(ss_list_price) B6_CNT - ,count(distinct ss_list_price) B6_CNTD - from store_sales - where ss_quantity between 26 and 30 - and (ss_list_price between 83 and 83+10 - or ss_coupon_amt between 11967 and 11967+1000 - or ss_wholesale_cost between 34 and 34+20)) B6 -limit 100; - --- end template query28.tpl query 28 in stream 9 --- start template query42.tpl query 29 in stream 9 -select /* TPC-DS query42.tpl 0.61 */ dt.d_year - ,item.i_category_id - ,item.i_category - ,sum(ss_ext_sales_price) - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manager_id = 1 - and dt.d_moy=11 - and dt.d_year=2000 - group by dt.d_year - ,item.i_category_id - ,item.i_category - order by sum(ss_ext_sales_price) desc,dt.d_year - ,item.i_category_id - ,item.i_category -limit 100 ; - --- end template query42.tpl query 29 in stream 9 --- start template query17.tpl query 30 in stream 9 -select /* TPC-DS query17.tpl 0.41 */ i_item_id - ,i_item_desc - ,s_state - ,count(ss_quantity) as store_sales_quantitycount - ,avg(ss_quantity) as store_sales_quantityave - ,stddev_samp(ss_quantity) as store_sales_quantitystdev - ,stddev_samp(ss_quantity)/avg(ss_quantity) as store_sales_quantitycov - ,count(sr_return_quantity) as store_returns_quantitycount - ,avg(sr_return_quantity) as store_returns_quantityave - ,stddev_samp(sr_return_quantity) as store_returns_quantitystdev - ,stddev_samp(sr_return_quantity)/avg(sr_return_quantity) as store_returns_quantitycov - ,count(cs_quantity) as catalog_sales_quantitycount ,avg(cs_quantity) as catalog_sales_quantityave - ,stddev_samp(cs_quantity) as catalog_sales_quantitystdev - ,stddev_samp(cs_quantity)/avg(cs_quantity) as catalog_sales_quantitycov - from store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where d1.d_quarter_name = '1998Q1' - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_quarter_name in ('1998Q1','1998Q2','1998Q3') - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_quarter_name in ('1998Q1','1998Q2','1998Q3') - group by i_item_id - ,i_item_desc - ,s_state - order by i_item_id - ,i_item_desc - ,s_state -limit 100; - --- end template query17.tpl query 30 in stream 9 --- start template query67a.tpl query 31 in stream 9 -with /* TPC-DS query67a.tpl 0.35 */ results as -( select i_category ,i_class ,i_brand ,i_product_name ,d_year ,d_qoy ,d_moy ,s_store_id - ,sum(coalesce(ss_sales_price*ss_quantity,0)) sumsales - from store_sales ,date_dim ,store ,item - where ss_sold_date_sk=d_date_sk - and ss_item_sk=i_item_sk - and ss_store_sk = s_store_sk - and d_month_seq between 1195 and 1195 + 11 - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy,s_store_id) - , - results_rollup as - (select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, s_store_id, sumsales - from results - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy - union all - select i_category, i_class, i_brand, i_product_name, d_year, d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy - union all - select i_category, i_class, i_brand, i_product_name, d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name, d_year - union all - select i_category, i_class, i_brand, i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand, i_product_name - union all - select i_category, i_class, i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class, i_brand - union all - select i_category, i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category, i_class - union all - select i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results - group by i_category - union all - select null i_category, null i_class, null i_brand, null i_product_name, null d_year, null d_qoy, null d_moy, null s_store_id, sum(sumsales) sumsales - from results) - - select * -from (select i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rank() over (partition by i_category order by sumsales desc) rk - from results_rollup) dw2 -where rk <= 100 -order by i_category - ,i_class - ,i_brand - ,i_product_name - ,d_year - ,d_qoy - ,d_moy - ,s_store_id - ,sumsales - ,rk -limit 100; - --- end template query67a.tpl query 31 in stream 9 --- start template query31.tpl query 32 in stream 9 -with /* TPC-DS query31.tpl 0.50 */ ss as - (select ca_county,d_qoy, d_year,sum(ss_ext_sales_price) as store_sales - from store_sales,date_dim,customer_address - where ss_sold_date_sk = d_date_sk - and ss_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year), - ws as - (select ca_county,d_qoy, d_year,sum(ws_ext_sales_price) as web_sales - from web_sales,date_dim,customer_address - where ws_sold_date_sk = d_date_sk - and ws_bill_addr_sk=ca_address_sk - group by ca_county,d_qoy, d_year) - select - ss1.ca_county - ,ss1.d_year - ,ws2.web_sales/ws1.web_sales web_q1_q2_increase - ,ss2.store_sales/ss1.store_sales store_q1_q2_increase - ,ws3.web_sales/ws2.web_sales web_q2_q3_increase - ,ss3.store_sales/ss2.store_sales store_q2_q3_increase - from - ss ss1 - ,ss ss2 - ,ss ss3 - ,ws ws1 - ,ws ws2 - ,ws ws3 - where - ss1.d_qoy = 1 - and ss1.d_year = 2000 - and ss1.ca_county = ss2.ca_county - and ss2.d_qoy = 2 - and ss2.d_year = 2000 - and ss2.ca_county = ss3.ca_county - and ss3.d_qoy = 3 - and ss3.d_year = 2000 - and ss1.ca_county = ws1.ca_county - and ws1.d_qoy = 1 - and ws1.d_year = 2000 - and ws1.ca_county = ws2.ca_county - and ws2.d_qoy = 2 - and ws2.d_year = 2000 - and ws1.ca_county = ws3.ca_county - and ws3.d_qoy = 3 - and ws3.d_year =2000 - and case when ws1.web_sales > 0 then ws2.web_sales/ws1.web_sales else null end - > case when ss1.store_sales > 0 then ss2.store_sales/ss1.store_sales else null end - and case when ws2.web_sales > 0 then ws3.web_sales/ws2.web_sales else null end - > case when ss2.store_sales > 0 then ss3.store_sales/ss2.store_sales else null end - order by web_q1_q2_increase; - --- end template query31.tpl query 32 in stream 9 --- start template query20.tpl query 33 in stream 9 -select /* TPC-DS query20.tpl 0.65 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(cs_ext_sales_price) as itemrevenue - ,sum(cs_ext_sales_price)*100/sum(sum(cs_ext_sales_price)) over - (partition by i_class) as revenueratio - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and i_category in ('Sports', 'Music', 'Books') - and cs_sold_date_sk = d_date_sk - and d_date between cast('2001-03-13' as date) - and dateadd(day,30,cast('2001-03-13' as date)) - group by i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - order by i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio -limit 100; - --- end template query20.tpl query 33 in stream 9 --- start template query11.tpl query 34 in stream 9 -with /* TPC-DS query11.tpl 0.51 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ss_ext_list_price-ss_ext_discount_amt) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(ws_ext_list_price-ws_ext_discount_amt) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_preferred_cust_flag - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 1998 - and t_s_secyear.dyear = 1998+1 - and t_w_firstyear.dyear = 1998 - and t_w_secyear.dyear = 1998+1 - and t_s_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else 0.0 end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else 0.0 end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_preferred_cust_flag -limit 100; - --- end template query11.tpl query 34 in stream 9 --- start template query77a.tpl query 35 in stream 9 -with /* TPC-DS query77a.tpl 0.78 */ ss as - (select s_store_sk, - sum(ss_ext_sales_price) as sales, - sum(ss_net_profit) as profit - from store_sales, - date_dim, - store - where ss_sold_date_sk = d_date_sk - and d_date between cast('2001-08-02' as date) - and dateadd(day,30,cast('2001-08-02' as date)) - and ss_store_sk = s_store_sk - group by s_store_sk) - , - sr as - (select s_store_sk, - sum(sr_return_amt) as returns, - sum(sr_net_loss) as profit_loss - from store_returns, - date_dim, - store - where sr_returned_date_sk = d_date_sk - and d_date between cast('2001-08-02' as date) - and dateadd(day,30,cast('2001-08-02' as date)) - and sr_store_sk = s_store_sk - group by s_store_sk), - cs as - (select cs_call_center_sk, - sum(cs_ext_sales_price) as sales, - sum(cs_net_profit) as profit - from catalog_sales, - date_dim - where cs_sold_date_sk = d_date_sk - and d_date between cast('2001-08-02' as date) - and dateadd(day,30,cast('2001-08-02' as date)) - group by cs_call_center_sk - ), - cr as - (select cr_call_center_sk, - sum(cr_return_amount) as returns, - sum(cr_net_loss) as profit_loss - from catalog_returns, - date_dim - where cr_returned_date_sk = d_date_sk - and d_date between cast('2001-08-02' as date) - and dateadd(day,30,cast('2001-08-02' as date)) - group by cr_call_center_sk), - ws as - ( select wp_web_page_sk, - sum(ws_ext_sales_price) as sales, - sum(ws_net_profit) as profit - from web_sales, - date_dim, - web_page - where ws_sold_date_sk = d_date_sk - and d_date between cast('2001-08-02' as date) - and dateadd(day,30,cast('2001-08-02' as date)) - and ws_web_page_sk = wp_web_page_sk - group by wp_web_page_sk), - wr as - (select wp_web_page_sk, - sum(wr_return_amt) as returns, - sum(wr_net_loss) as profit_loss - from web_returns, - date_dim, - web_page - where wr_returned_date_sk = d_date_sk - and d_date between cast('2001-08-02' as date) - and dateadd(day,30,cast('2001-08-02' as date)) - and wr_web_page_sk = wp_web_page_sk - group by wp_web_page_sk) - , - results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , ss.s_store_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ss left join sr - on ss.s_store_sk = sr.s_store_sk - union all - select 'catalog channel' as channel - , cs_call_center_sk as id - , sales - , returns - , (profit - profit_loss) as profit - from cs - , cr - union all - select 'web channel' as channel - , ws.wp_web_page_sk as id - , sales - , coalesce(returns, 0) as returns - , (profit - coalesce(profit_loss,0)) as profit - from ws left join wr - on ws.wp_web_page_sk = wr.wp_web_page_sk - ) x - group by channel, id ) - - select * - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results -) foo -order by channel, id - limit 100; - --- end template query77a.tpl query 35 in stream 9 --- start template query36a.tpl query 36 in stream 9 -with /* TPC-DS query36a.tpl 0.21 */ results as - (select - sum(ss_net_profit) as ss_net_profit, sum(ss_ext_sales_price) as ss_ext_sales_price, - sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin - ,i_category - ,i_class - ,0 as g_category, 0 as g_class - from - store_sales - ,date_dim d1 - ,item - ,store - where - d1.d_year = 1999 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and s_state in ('SD','AL','MO','MN', - 'MN','MI','PA','OH') - group by i_category,i_class) - , - results_rollup as - (select gross_margin ,i_category ,i_class,0 as t_category, 0 as t_class, 0 as lochierarchy from results - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - i_category, NULL AS i_class, 0 as t_category, 1 as t_class, 1 as lochierarchy from results group by i_category - union - select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin, - NULL AS i_category ,NULL AS i_class, 1 as t_category, 1 as t_class, 2 as lochierarchy from results) - select - gross_margin ,i_category ,i_class, lochierarchy,rank() over ( - partition by lochierarchy, case when t_class = 0 then i_category end - order by gross_margin asc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then i_category end - ,rank_within_parent - limit 100; - --- end template query36a.tpl query 36 in stream 9 --- start template query82.tpl query 37 in stream 9 -select /* TPC-DS query82.tpl 0.67 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, store_sales - where i_current_price between 78 and 78+30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('1999-04-21' as date) and dateadd(day,60,cast('1999-04-21' as date)) - and i_manufact_id in (90,953,293,875) - and inv_quantity_on_hand between 100 and 500 - and ss_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query82.tpl query 37 in stream 9 --- start template query33.tpl query 38 in stream 9 -with /* TPC-DS query33.tpl 0.22 */ ss as ( - select - i_manufact_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Sports')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 6 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id), - cs as ( - select - i_manufact_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Sports')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 6 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id), - ws as ( - select - i_manufact_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_manufact_id in (select - i_manufact_id -from - item -where i_category in ('Sports')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 6 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_manufact_id) - select i_manufact_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_manufact_id - order by total_sales -limit 100; - --- end template query33.tpl query 38 in stream 9 --- start template query54.tpl query 39 in stream 9 -with /* TPC-DS query54.tpl 0.81 */ my_customers as ( - select distinct c_customer_sk - , c_current_addr_sk - from - ( select cs_sold_date_sk sold_date_sk, - cs_bill_customer_sk customer_sk, - cs_item_sk item_sk - from catalog_sales - union all - select ws_sold_date_sk sold_date_sk, - ws_bill_customer_sk customer_sk, - ws_item_sk item_sk - from web_sales - ) cs_or_ws_sales, - item, - date_dim, - customer - where sold_date_sk = d_date_sk - and item_sk = i_item_sk - and i_category = 'Shoes' - and i_class = 'womens' - and c_customer_sk = cs_or_ws_sales.customer_sk - and d_moy = 2 - and d_year = 2001 - ) - , my_revenue as ( - select c_customer_sk, - sum(ss_ext_sales_price) as revenue - from my_customers, - store_sales, - customer_address, - store, - date_dim - where c_current_addr_sk = ca_address_sk - and ca_county = s_county - and ca_state = s_state - and ss_sold_date_sk = d_date_sk - and c_customer_sk = ss_customer_sk - and d_month_seq between (select distinct d_month_seq+1 - from date_dim where d_year = 2001 and d_moy = 2) - and (select distinct d_month_seq+3 - from date_dim where d_year = 2001 and d_moy = 2) - group by c_customer_sk - ) - , segments as - (select cast((revenue/50) as bigint) as segment - from my_revenue - ) - select segment, count(*) as num_customers, segment*50 as segment_base - from segments - group by segment - order by segment, num_customers - limit 100; - --- end template query54.tpl query 39 in stream 9 --- start template query4.tpl query 40 in stream 9 -with /* TPC-DS query4.tpl 0.93 */ year_total as ( - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum(((ss_ext_list_price-ss_ext_wholesale_cost-ss_ext_discount_amt)+ss_ext_sales_price)/2) year_total - ,'s' sale_type - from customer - ,store_sales - ,date_dim - where c_customer_sk = ss_customer_sk - and ss_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((cs_ext_list_price-cs_ext_wholesale_cost-cs_ext_discount_amt)+cs_ext_sales_price)/2) ) year_total - ,'c' sale_type - from customer - ,catalog_sales - ,date_dim - where c_customer_sk = cs_bill_customer_sk - and cs_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year -union all - select c_customer_id customer_id - ,c_first_name customer_first_name - ,c_last_name customer_last_name - ,c_preferred_cust_flag customer_preferred_cust_flag - ,c_birth_country customer_birth_country - ,c_login customer_login - ,c_email_address customer_email_address - ,d_year dyear - ,sum((((ws_ext_list_price-ws_ext_wholesale_cost-ws_ext_discount_amt)+ws_ext_sales_price)/2) ) year_total - ,'w' sale_type - from customer - ,web_sales - ,date_dim - where c_customer_sk = ws_bill_customer_sk - and ws_sold_date_sk = d_date_sk - group by c_customer_id - ,c_first_name - ,c_last_name - ,c_preferred_cust_flag - ,c_birth_country - ,c_login - ,c_email_address - ,d_year - ) - select - t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_email_address - from year_total t_s_firstyear - ,year_total t_s_secyear - ,year_total t_c_firstyear - ,year_total t_c_secyear - ,year_total t_w_firstyear - ,year_total t_w_secyear - where t_s_secyear.customer_id = t_s_firstyear.customer_id - and t_s_firstyear.customer_id = t_c_secyear.customer_id - and t_s_firstyear.customer_id = t_c_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_firstyear.customer_id - and t_s_firstyear.customer_id = t_w_secyear.customer_id - and t_s_firstyear.sale_type = 's' - and t_c_firstyear.sale_type = 'c' - and t_w_firstyear.sale_type = 'w' - and t_s_secyear.sale_type = 's' - and t_c_secyear.sale_type = 'c' - and t_w_secyear.sale_type = 'w' - and t_s_firstyear.dyear = 2000 - and t_s_secyear.dyear = 2000+1 - and t_c_firstyear.dyear = 2000 - and t_c_secyear.dyear = 2000+1 - and t_w_firstyear.dyear = 2000 - and t_w_secyear.dyear = 2000+1 - and t_s_firstyear.year_total > 0 - and t_c_firstyear.year_total > 0 - and t_w_firstyear.year_total > 0 - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end - and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end - > case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end - order by t_s_secyear.customer_id - ,t_s_secyear.customer_first_name - ,t_s_secyear.customer_last_name - ,t_s_secyear.customer_email_address -limit 100; - --- end template query4.tpl query 40 in stream 9 --- start template query16.tpl query 41 in stream 9 -select /* TPC-DS query16.tpl 0.25 */ - count(distinct cs_order_number) as "order count" - ,sum(cs_ext_ship_cost) as "total shipping cost" - ,sum(cs_net_profit) as "total net profit" -from - catalog_sales cs1 - ,date_dim - ,customer_address - ,call_center -where - d_date between '2001-5-01' and - dateadd(day, 60, cast('2001-5-01' as date)) -and cs1.cs_ship_date_sk = d_date_sk -and cs1.cs_ship_addr_sk = ca_address_sk -and ca_state = 'AL' -and cs1.cs_call_center_sk = cc_call_center_sk -and cc_county in ('Franklin Parish','Dauphin County','Fairfield County','Pennington County', - 'Williamson County' -) -and exists (select * - from catalog_sales cs2 - where cs1.cs_order_number = cs2.cs_order_number - and cs1.cs_warehouse_sk <> cs2.cs_warehouse_sk) -and not exists(select * - from catalog_returns cr1 - where cs1.cs_order_number = cr1.cr_order_number) -order by count(distinct cs_order_number) -limit 100; - --- end template query16.tpl query 41 in stream 9 --- start template query10.tpl query 42 in stream 9 -select /* TPC-DS query10.tpl 0.26 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3, - cd_dep_count, - count(*) cnt4, - cd_dep_employed_count, - count(*) cnt5, - cd_dep_college_count, - count(*) cnt6 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_county in ('Fremont County','Malheur County','Goodhue County','Dodge County','Fannin County') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 1 and 1+3) and - (exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 1 ANd 1+3) or - exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2002 and - d_moy between 1 and 1+3)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count -limit 100; - --- end template query10.tpl query 42 in stream 9 --- start template query18a.tpl query 43 in stream 9 -with /* TPC-DS query18a.tpl 0.90 */ results as - (select i_item_id, - ca_country, - ca_state, - ca_county, - cast(cs_quantity as decimal(12,2)) agg1, - cast(cs_list_price as decimal(12,2)) agg2, - cast(cs_coupon_amt as decimal(12,2)) agg3, - cast(cs_sales_price as decimal(12,2)) agg4, - cast(cs_net_profit as decimal(12,2)) agg5, - cast(c_birth_year as decimal(12,2)) agg6, - cast(cd1.cd_dep_count as decimal(12,2)) agg7 - from catalog_sales, customer_demographics cd1, customer_demographics cd2, customer, customer_address, date_dim, item - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd1.cd_demo_sk and - cs_bill_customer_sk = c_customer_sk and - cd1.cd_gender = 'M' and - cd1.cd_education_status = 'Primary' and - c_current_cdemo_sk = cd2.cd_demo_sk and - c_current_addr_sk = ca_address_sk and - c_birth_month in (3,8,1,6,2,11) and - d_year = 2001 and - ca_state in ('MS','TN','PA','GA','NY','MN','WA') - ) - select i_item_id, ca_country, ca_state, ca_county, agg1, agg2, agg3, agg4, agg5, agg6, agg7 - from ( - select i_item_id, ca_country, ca_state, ca_county, avg(agg1) agg1, - avg(agg2) agg2, avg(agg3) agg3, avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state, ca_county - union all - select i_item_id, ca_country, ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country, ca_state - union all - select i_item_id, ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id, ca_country - union all - select i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - group by i_item_id - union all - select NULL AS i_item_id, NULL as ca_country, NULL as ca_state, NULL as county, avg(agg1) agg1, avg(agg2) agg2, avg(agg3) agg3, - avg(agg4) agg4, avg(agg5) agg5, avg(agg6) agg6, avg(agg7) agg7 - from results - ) foo - order by ca_country, ca_state, ca_county, i_item_id - limit 100; - --- end template query18a.tpl query 43 in stream 9 --- start template query48.tpl query 44 in stream 9 -select /* TPC-DS query48.tpl 0.74 */ sum (ss_quantity) - from store_sales, store, customer_demographics, customer_address, date_dim - where s_store_sk = ss_store_sk - and ss_sold_date_sk = d_date_sk and d_year = 2002 - and - ( - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'W' - and - cd_education_status = 'College' - and - ss_sales_price between 100.00 and 150.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'M' - and - cd_education_status = 'Primary' - and - ss_sales_price between 50.00 and 100.00 - ) - or - ( - cd_demo_sk = ss_cdemo_sk - and - cd_marital_status = 'U' - and - cd_education_status = 'Advanced Degree' - and - ss_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('VA', 'LA', 'OH') - and ss_net_profit between 0 and 2000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('MI', 'ID', 'IL') - and ss_net_profit between 150 and 3000 - ) - or - (ss_addr_sk = ca_address_sk - and - ca_country = 'United States' - and - ca_state in ('WA', 'OK', 'MS') - and ss_net_profit between 50 and 25000 - ) - ) -; - --- end template query48.tpl query 44 in stream 9 --- start template query24.tpl query 45 in stream 9 -with /* TPC-DS query24.tpl 0.92 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_ext_sales_price) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip -and s_market_id=5 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'wheat' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; -with /* TPC-DS query24.tpl 0.92 part2 */ ssales as -(select c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size - ,sum(ss_ext_sales_price) netpaid -from store_sales - ,store_returns - ,store - ,item - ,customer - ,customer_address -where ss_ticket_number = sr_ticket_number - and ss_item_sk = sr_item_sk - and ss_customer_sk = c_customer_sk - and ss_item_sk = i_item_sk - and ss_store_sk = s_store_sk - and c_current_addr_sk = ca_address_sk - and c_birth_country <> upper(ca_country) - and s_zip = ca_zip - and s_market_id = 5 -group by c_last_name - ,c_first_name - ,s_store_name - ,ca_state - ,s_state - ,i_color - ,i_current_price - ,i_manager_id - ,i_units - ,i_size) -select c_last_name - ,c_first_name - ,s_store_name - ,sum(netpaid) paid -from ssales -where i_color = 'sky' -group by c_last_name - ,c_first_name - ,s_store_name -having sum(netpaid) > (select 0.05*avg(netpaid) - from ssales) -order by c_last_name - ,c_first_name - ,s_store_name -; - --- end template query24.tpl query 45 in stream 9 --- start template query30.tpl query 46 in stream 9 -with /* TPC-DS query30.tpl 0.75 */ customer_total_return as - (select wr_returning_customer_sk as ctr_customer_sk - ,ca_state as ctr_state, - sum(wr_return_amt) as ctr_total_return - from web_returns - ,date_dim - ,customer_address - where wr_returned_date_sk = d_date_sk - and d_year =2000 - and wr_returning_addr_sk = ca_address_sk - group by wr_returning_customer_sk - ,ca_state) - select c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return - from customer_total_return ctr1 - ,customer_address - ,customer - where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 - from customer_total_return ctr2 - where ctr1.ctr_state = ctr2.ctr_state) - and ca_address_sk = c_current_addr_sk - and ca_state = 'NY' - and ctr1.ctr_customer_sk = c_customer_sk - order by c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag - ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address - ,c_last_review_date_sk,ctr_total_return -limit 100; - --- end template query30.tpl query 46 in stream 9 --- start template query78.tpl query 47 in stream 9 -with /* TPC-DS query78.tpl 0.10 */ ws as - (select d_year AS ws_sold_year, ws_item_sk, - ws_bill_customer_sk ws_customer_sk, - sum(ws_quantity) ws_qty, - sum(ws_wholesale_cost) ws_wc, - sum(ws_sales_price) ws_sp - from web_sales - left join web_returns on wr_order_number=ws_order_number and ws_item_sk=wr_item_sk - join date_dim on ws_sold_date_sk = d_date_sk - where wr_order_number is null - group by d_year, ws_item_sk, ws_bill_customer_sk - ), -cs as - (select d_year AS cs_sold_year, cs_item_sk, - cs_bill_customer_sk cs_customer_sk, - sum(cs_quantity) cs_qty, - sum(cs_wholesale_cost) cs_wc, - sum(cs_sales_price) cs_sp - from catalog_sales - left join catalog_returns on cr_order_number=cs_order_number and cs_item_sk=cr_item_sk - join date_dim on cs_sold_date_sk = d_date_sk - where cr_order_number is null - group by d_year, cs_item_sk, cs_bill_customer_sk - ), -ss as - (select d_year AS ss_sold_year, ss_item_sk, - ss_customer_sk, - sum(ss_quantity) ss_qty, - sum(ss_wholesale_cost) ss_wc, - sum(ss_sales_price) ss_sp - from store_sales - left join store_returns on sr_ticket_number=ss_ticket_number and ss_item_sk=sr_item_sk - join date_dim on ss_sold_date_sk = d_date_sk - where sr_ticket_number is null - group by d_year, ss_item_sk, ss_customer_sk - ) - select -ss_customer_sk, -round(ss_qty/(coalesce(ws_qty,0)+coalesce(cs_qty,0)),2) ratio, -ss_qty store_qty, ss_wc store_wholesale_cost, ss_sp store_sales_price, -coalesce(ws_qty,0)+coalesce(cs_qty,0) other_chan_qty, -coalesce(ws_wc,0)+coalesce(cs_wc,0) other_chan_wholesale_cost, -coalesce(ws_sp,0)+coalesce(cs_sp,0) other_chan_sales_price -from ss -left join ws on (ws_sold_year=ss_sold_year and ws_item_sk=ss_item_sk and ws_customer_sk=ss_customer_sk) -left join cs on (cs_sold_year=ss_sold_year and cs_item_sk=ss_item_sk and cs_customer_sk=ss_customer_sk) -where (coalesce(ws_qty,0)>0 or coalesce(cs_qty, 0)>0) and ss_sold_year=2001 -order by - ss_customer_sk, - ss_qty desc, ss_wc desc, ss_sp desc, - other_chan_qty, - other_chan_wholesale_cost, - other_chan_sales_price, - ratio -limit 100; - --- end template query78.tpl query 47 in stream 9 --- start template query6.tpl query 48 in stream 9 -select /* TPC-DS query6.tpl 0.58 */ a.ca_state state, count(*) cnt - from customer_address a - ,customer c - ,store_sales s - ,date_dim d - ,item i - where a.ca_address_sk = c.c_current_addr_sk - and c.c_customer_sk = s.ss_customer_sk - and s.ss_sold_date_sk = d.d_date_sk - and s.ss_item_sk = i.i_item_sk - and d.d_month_seq = - (select distinct (d_month_seq) - from date_dim - where d_year = 1999 - and d_moy = 6 ) - and i.i_current_price > 1.2 * - (select avg(j.i_current_price) - from item j - where j.i_category = i.i_category) - group by a.ca_state - having count(*) >= 10 - order by cnt, a.ca_state - limit 100; - --- end template query6.tpl query 48 in stream 9 --- start template query80a.tpl query 49 in stream 9 -with /* TPC-DS query80a.tpl 0.6 */ ssr as - (select s_store_id as store_id, - sum(ss_ext_sales_price) as sales, - sum(coalesce(sr_return_amt, 0)) as returns, - sum(ss_net_profit - coalesce(sr_net_loss, 0)) as profit - from store_sales left outer join store_returns on - (ss_item_sk = sr_item_sk and ss_ticket_number = sr_ticket_number), - date_dim, - store, - item, - promotion - where ss_sold_date_sk = d_date_sk - and d_date between cast('2002-08-08' as date) - and dateadd(day,30,cast('2002-08-08' as date)) - and ss_store_sk = s_store_sk - and ss_item_sk = i_item_sk - and i_current_price > 50 - and ss_promo_sk = p_promo_sk - and p_channel_tv = 'N' - group by s_store_id) - , - csr as - (select cp_catalog_page_id as catalog_page_id, - sum(cs_ext_sales_price) as sales, - sum(coalesce(cr_return_amount, 0)) as returns, - sum(cs_net_profit - coalesce(cr_net_loss, 0)) as profit - from catalog_sales left outer join catalog_returns on - (cs_item_sk = cr_item_sk and cs_order_number = cr_order_number), - date_dim, - catalog_page, - item, - promotion - where cs_sold_date_sk = d_date_sk - and d_date between cast('2002-08-08' as date) - and dateadd(day,30,cast('2002-08-08' as date)) - and cs_catalog_page_sk = cp_catalog_page_sk - and cs_item_sk = i_item_sk - and i_current_price > 50 - and cs_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by cp_catalog_page_id) - , - wsr as - (select web_site_id, - sum(ws_ext_sales_price) as sales, - sum(coalesce(wr_return_amt, 0)) as returns, - sum(ws_net_profit - coalesce(wr_net_loss, 0)) as profit - from web_sales left outer join web_returns on - (ws_item_sk = wr_item_sk and ws_order_number = wr_order_number), - date_dim, - web_site, - item, - promotion - where ws_sold_date_sk = d_date_sk - and d_date between cast('2002-08-08' as date) - and dateadd(day,30,cast('2002-08-08' as date)) - and ws_web_site_sk = web_site_sk - and ws_item_sk = i_item_sk - and i_current_price > 50 - and ws_promo_sk = p_promo_sk - and p_channel_tv = 'N' -group by web_site_id) -, -results as - (select channel - , id - , sum(sales) as sales - , sum(returns) as returns - , sum(profit) as profit - from - (select 'store channel' as channel - , 'store' || store_id as id - , sales - , returns - , profit - from ssr - union all - select 'catalog channel' as channel - , 'catalog_page' || catalog_page_id as id - , sales - , returns - , profit - from csr - union all - select 'web channel' as channel - , 'web_site' || web_site_id as id - , sales - , returns - , profit - from wsr - ) x - group by channel, id) - - select channel - , id - , sales - , returns - , profit - from ( - select channel, id, sales, returns, profit from results - union - select channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results group by channel - union - select NULL AS channel, NULL AS id, sum(sales) as sales, sum(returns) as returns, sum(profit) as profit from results - ) foo - order by channel, id - limit 100; - --- end template query80a.tpl query 49 in stream 9 --- start template query35a.tpl query 50 in stream 9 -select /* TPC-DS query35a.tpl 0.47 */ - ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - count(*) cnt1, - stddev_samp(cd_dep_count), - sum(cd_dep_count), - sum(cd_dep_count), - cd_dep_employed_count, - count(*) cnt2, - stddev_samp(cd_dep_employed_count), - sum(cd_dep_employed_count), - sum(cd_dep_employed_count), - cd_dep_college_count, - count(*) cnt3, - stddev_samp(cd_dep_college_count), - sum(cd_dep_college_count), - sum(cd_dep_college_count) - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2001 and - d_qoy < 4) and - exists (select * from - (select ws_bill_customer_sk customsk - from web_sales,date_dim - where - ws_sold_date_sk = d_date_sk and - d_year = 2001 and - d_qoy < 4 - union all - select cs_ship_customer_sk customsk - from catalog_sales,date_dim - where - cs_sold_date_sk = d_date_sk and - d_year = 2001 and - d_qoy < 4)x - where x.customsk = c.c_customer_sk) - group by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - order by ca_state, - cd_gender, - cd_marital_status, - cd_dep_count, - cd_dep_employed_count, - cd_dep_college_count - limit 100; - --- end template query35a.tpl query 50 in stream 9 --- start template query59.tpl query 51 in stream 9 -with /* TPC-DS query59.tpl 0.30 */ wss as - (select d_week_seq, - ss_store_sk, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - group by d_week_seq,ss_store_sk - ) - select s_store_name1,s_store_id1,d_week_seq1 - ,sun_sales1/sun_sales2,mon_sales1/mon_sales2 - ,tue_sales1/tue_sales2,wed_sales1/wed_sales2,thu_sales1/thu_sales2 - ,fri_sales1/fri_sales2,sat_sales1/sat_sales2 - from - (select s_store_name s_store_name1,wss.d_week_seq d_week_seq1 - ,s_store_id s_store_id1,sun_sales sun_sales1 - ,mon_sales mon_sales1,tue_sales tue_sales1 - ,wed_sales wed_sales1,thu_sales thu_sales1 - ,fri_sales fri_sales1,sat_sales sat_sales1 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1186 and 1186 + 11) y, - (select s_store_name s_store_name2,wss.d_week_seq d_week_seq2 - ,s_store_id s_store_id2,sun_sales sun_sales2 - ,mon_sales mon_sales2,tue_sales tue_sales2 - ,wed_sales wed_sales2,thu_sales thu_sales2 - ,fri_sales fri_sales2,sat_sales sat_sales2 - from wss,store,date_dim d - where d.d_week_seq = wss.d_week_seq and - ss_store_sk = s_store_sk and - d_month_seq between 1186+ 12 and 1186 + 23) x - where s_store_id1=s_store_id2 - and d_week_seq1=d_week_seq2-52 - order by s_store_name1,s_store_id1,d_week_seq1 -limit 100; - --- end template query59.tpl query 51 in stream 9 --- start template query99.tpl query 52 in stream 9 -select /* TPC-DS query99.tpl 0.94 */ - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 30) and - (cs_ship_date_sk - cs_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 60) and - (cs_ship_date_sk - cs_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 90) and - (cs_ship_date_sk - cs_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" - ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 120) then 1 else 0 end) as ">120 days" -from - catalog_sales - ,warehouse - ,ship_mode - ,call_center - ,date_dim -where - d_month_seq between 1190 and 1190 + 11 -and cs_ship_date_sk = d_date_sk -and cs_warehouse_sk = w_warehouse_sk -and cs_ship_mode_sk = sm_ship_mode_sk -and cs_call_center_sk = cc_call_center_sk -group by - substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -order by substring(w_warehouse_name,1,20) - ,sm_type - ,cc_name -limit 100; - --- end template query99.tpl query 52 in stream 9 --- start template query61.tpl query 53 in stream 9 -select /* TPC-DS query61.tpl 0.97 */ promotions,total,cast(promotions as decimal(15,4))/cast(total as decimal(15,4))*100 -from - (select sum(ss_ext_sales_price) promotions - from store_sales - ,store - ,promotion - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_promo_sk = p_promo_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -6 - and i_category = 'Jewelry' - and (p_channel_dmail = 'Y' or p_channel_email = 'Y' or p_channel_tv = 'Y') - and s_gmt_offset = -6 - and d_year = 1999 - and d_moy = 12) promotional_sales, - (select sum(ss_ext_sales_price) total - from store_sales - ,store - ,date_dim - ,customer - ,customer_address - ,item - where ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and ss_customer_sk= c_customer_sk - and ca_address_sk = c_current_addr_sk - and ss_item_sk = i_item_sk - and ca_gmt_offset = -6 - and i_category = 'Jewelry' - and s_gmt_offset = -6 - and d_year = 1999 - and d_moy = 12) all_sales -order by promotions, total -limit 100; - --- end template query61.tpl query 53 in stream 9 --- start template query22a.tpl query 54 in stream 9 -with /* TPC-DS query22a.tpl 0.55 */ results as -(select i_product_name - ,i_brand - ,i_class - ,i_category - ,avg(inv_quantity_on_hand) qoh - from inventory - ,date_dim - ,item --- ,warehouse - where inv_date_sk=d_date_sk - and inv_item_sk=i_item_sk --- and inv_warehouse_sk = w_warehouse_sk - and d_month_seq between 1213 and 1213 + 11 - group by i_product_name,i_brand,i_class,i_category), -results_rollup as -(select i_product_name, i_brand, i_class, i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class,i_category -union all -select i_product_name, i_brand, i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand,i_class -union all -select i_product_name, i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name,i_brand -union all -select i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results -group by i_product_name -union all -select null i_product_name, null i_brand, null i_class, null i_category,avg(qoh) qoh -from results) - select i_product_name, i_brand, i_class, i_category,qoh - from results_rollup - order by qoh, i_product_name, i_brand, i_class, i_category -limit 100; - --- end template query22a.tpl query 54 in stream 9 --- start template query71.tpl query 55 in stream 9 -select /* TPC-DS query71.tpl 0.72 */ i_brand_id brand_id, i_brand brand,t_hour,t_minute, - sum(ext_price) ext_price - from item, (select ws_ext_sales_price as ext_price, - ws_sold_date_sk as sold_date_sk, - ws_item_sk as sold_item_sk, - ws_sold_time_sk as time_sk - from web_sales,date_dim - where d_date_sk = ws_sold_date_sk - and d_moy=11 - and d_year=2000 - union all - select cs_ext_sales_price as ext_price, - cs_sold_date_sk as sold_date_sk, - cs_item_sk as sold_item_sk, - cs_sold_time_sk as time_sk - from catalog_sales,date_dim - where d_date_sk = cs_sold_date_sk - and d_moy=11 - and d_year=2000 - union all - select ss_ext_sales_price as ext_price, - ss_sold_date_sk as sold_date_sk, - ss_item_sk as sold_item_sk, - ss_sold_time_sk as time_sk - from store_sales,date_dim - where d_date_sk = ss_sold_date_sk - and d_moy=11 - and d_year=2000 - ) tmp,time_dim - where - sold_item_sk = i_item_sk - and i_manager_id=1 - and time_sk = t_time_sk - and (t_meal_time = 'breakfast' or t_meal_time = 'dinner') - group by i_brand, i_brand_id,t_hour,t_minute - order by ext_price desc, i_brand_id - ; - --- end template query71.tpl query 55 in stream 9 --- start template query68.tpl query 56 in stream 9 -select /* TPC-DS query68.tpl 0.95 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,extended_price - ,extended_tax - ,list_price - from (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_ext_sales_price) extended_price - ,sum(ss_ext_list_price) list_price - ,sum(ss_ext_tax) extended_tax - from store_sales - ,date_dim - ,store - ,household_demographics - ,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_dep_count = 9 or - household_demographics.hd_vehicle_count= 1) - and date_dim.d_year in (1998,1998+1,1998+2) - and store.s_city in ('Buena Vista','Franklin') - group by ss_ticket_number - ,ss_customer_sk - ,ss_addr_sk,ca_city) dn - ,customer - ,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,ss_ticket_number - limit 100; - --- end template query68.tpl query 56 in stream 9 --- start template query40.tpl query 57 in stream 9 -select /* TPC-DS query40.tpl 0.86 */ - w_state - ,i_item_id - ,sum(case when (cast(d_date as date) < cast ('1999-05-30' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_before - ,sum(case when (cast(d_date as date) >= cast ('1999-05-30' as date)) - then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_after - from - catalog_sales left outer join catalog_returns on - (cs_order_number = cr_order_number - and cs_item_sk = cr_item_sk) - ,warehouse - ,item - ,date_dim - where - i_current_price between 0.99 and 1.49 - and i_item_sk = cs_item_sk - and cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and d_date between dateadd(day,-30,cast ('1999-05-30' as date)) - and dateadd(day,30,cast ('1999-05-30' as date)) - group by - w_state,i_item_id - order by w_state,i_item_id -limit 100; - --- end template query40.tpl query 57 in stream 9 --- start template query66.tpl query 58 in stream 9 -select /* TPC-DS query66.tpl 0.39 */ - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - ,sum(jan_sales) as jan_sales - ,sum(feb_sales) as feb_sales - ,sum(mar_sales) as mar_sales - ,sum(apr_sales) as apr_sales - ,sum(may_sales) as may_sales - ,sum(jun_sales) as jun_sales - ,sum(jul_sales) as jul_sales - ,sum(aug_sales) as aug_sales - ,sum(sep_sales) as sep_sales - ,sum(oct_sales) as oct_sales - ,sum(nov_sales) as nov_sales - ,sum(dec_sales) as dec_sales - ,sum(jan_sales/w_warehouse_sq_ft) as jan_sales_per_sq_foot - ,sum(feb_sales/w_warehouse_sq_ft) as feb_sales_per_sq_foot - ,sum(mar_sales/w_warehouse_sq_ft) as mar_sales_per_sq_foot - ,sum(apr_sales/w_warehouse_sq_ft) as apr_sales_per_sq_foot - ,sum(may_sales/w_warehouse_sq_ft) as may_sales_per_sq_foot - ,sum(jun_sales/w_warehouse_sq_ft) as jun_sales_per_sq_foot - ,sum(jul_sales/w_warehouse_sq_ft) as jul_sales_per_sq_foot - ,sum(aug_sales/w_warehouse_sq_ft) as aug_sales_per_sq_foot - ,sum(sep_sales/w_warehouse_sq_ft) as sep_sales_per_sq_foot - ,sum(oct_sales/w_warehouse_sq_ft) as oct_sales_per_sq_foot - ,sum(nov_sales/w_warehouse_sq_ft) as nov_sales_per_sq_foot - ,sum(dec_sales/w_warehouse_sq_ft) as dec_sales_per_sq_foot - ,sum(jan_net) as jan_net - ,sum(feb_net) as feb_net - ,sum(mar_net) as mar_net - ,sum(apr_net) as apr_net - ,sum(may_net) as may_net - ,sum(jun_net) as jun_net - ,sum(jul_net) as jul_net - ,sum(aug_net) as aug_net - ,sum(sep_net) as sep_net - ,sum(oct_net) as oct_net - ,sum(nov_net) as nov_net - ,sum(dec_net) as dec_net - from ( - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'UPS' || ',' || 'FEDEX' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then ws_sales_price* ws_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then ws_sales_price* ws_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then ws_sales_price* ws_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then ws_sales_price* ws_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then ws_sales_price* ws_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then ws_sales_price* ws_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then ws_sales_price* ws_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then ws_sales_price* ws_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then ws_sales_price* ws_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then ws_sales_price* ws_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then ws_sales_price* ws_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then ws_sales_price* ws_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then ws_net_paid * ws_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then ws_net_paid * ws_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then ws_net_paid * ws_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then ws_net_paid * ws_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then ws_net_paid * ws_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then ws_net_paid * ws_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then ws_net_paid * ws_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then ws_net_paid * ws_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then ws_net_paid * ws_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then ws_net_paid * ws_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then ws_net_paid * ws_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then ws_net_paid * ws_quantity else 0 end) as dec_net - from - web_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - ws_warehouse_sk = w_warehouse_sk - and ws_sold_date_sk = d_date_sk - and ws_sold_time_sk = t_time_sk - and ws_ship_mode_sk = sm_ship_mode_sk - and d_year = 2002 - and t_time between 26105 and 26105+28800 - and sm_carrier in ('UPS','FEDEX') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - union all - select - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,'UPS' || ',' || 'FEDEX' as ship_carriers - ,d_year as year - ,sum(case when d_moy = 1 - then cs_sales_price* cs_quantity else 0 end) as jan_sales - ,sum(case when d_moy = 2 - then cs_sales_price* cs_quantity else 0 end) as feb_sales - ,sum(case when d_moy = 3 - then cs_sales_price* cs_quantity else 0 end) as mar_sales - ,sum(case when d_moy = 4 - then cs_sales_price* cs_quantity else 0 end) as apr_sales - ,sum(case when d_moy = 5 - then cs_sales_price* cs_quantity else 0 end) as may_sales - ,sum(case when d_moy = 6 - then cs_sales_price* cs_quantity else 0 end) as jun_sales - ,sum(case when d_moy = 7 - then cs_sales_price* cs_quantity else 0 end) as jul_sales - ,sum(case when d_moy = 8 - then cs_sales_price* cs_quantity else 0 end) as aug_sales - ,sum(case when d_moy = 9 - then cs_sales_price* cs_quantity else 0 end) as sep_sales - ,sum(case when d_moy = 10 - then cs_sales_price* cs_quantity else 0 end) as oct_sales - ,sum(case when d_moy = 11 - then cs_sales_price* cs_quantity else 0 end) as nov_sales - ,sum(case when d_moy = 12 - then cs_sales_price* cs_quantity else 0 end) as dec_sales - ,sum(case when d_moy = 1 - then cs_net_paid * cs_quantity else 0 end) as jan_net - ,sum(case when d_moy = 2 - then cs_net_paid * cs_quantity else 0 end) as feb_net - ,sum(case when d_moy = 3 - then cs_net_paid * cs_quantity else 0 end) as mar_net - ,sum(case when d_moy = 4 - then cs_net_paid * cs_quantity else 0 end) as apr_net - ,sum(case when d_moy = 5 - then cs_net_paid * cs_quantity else 0 end) as may_net - ,sum(case when d_moy = 6 - then cs_net_paid * cs_quantity else 0 end) as jun_net - ,sum(case when d_moy = 7 - then cs_net_paid * cs_quantity else 0 end) as jul_net - ,sum(case when d_moy = 8 - then cs_net_paid * cs_quantity else 0 end) as aug_net - ,sum(case when d_moy = 9 - then cs_net_paid * cs_quantity else 0 end) as sep_net - ,sum(case when d_moy = 10 - then cs_net_paid * cs_quantity else 0 end) as oct_net - ,sum(case when d_moy = 11 - then cs_net_paid * cs_quantity else 0 end) as nov_net - ,sum(case when d_moy = 12 - then cs_net_paid * cs_quantity else 0 end) as dec_net - from - catalog_sales - ,warehouse - ,date_dim - ,time_dim - ,ship_mode - where - cs_warehouse_sk = w_warehouse_sk - and cs_sold_date_sk = d_date_sk - and cs_sold_time_sk = t_time_sk - and cs_ship_mode_sk = sm_ship_mode_sk - and d_year = 2002 - and t_time between 26105 AND 26105+28800 - and sm_carrier in ('UPS','FEDEX') - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,d_year - ) x - group by - w_warehouse_name - ,w_warehouse_sq_ft - ,w_city - ,w_county - ,w_state - ,w_country - ,ship_carriers - ,year - order by w_warehouse_name - limit 100; - --- end template query66.tpl query 58 in stream 9 --- start template query94.tpl query 59 in stream 9 -select /* TPC-DS query94.tpl 0.17 */ - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2001-5-01' and - dateadd(day,60,cast('2001-5-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'NM' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and exists (select * - from web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) -and not exists(select * - from web_returns wr1 - where ws1.ws_order_number = wr1.wr_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query94.tpl query 59 in stream 9 --- start template query47.tpl query 60 in stream 9 -with /* TPC-DS query47.tpl 0.42 */ v1 as( - select i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, - s_store_name, s_company_name, d_year) - avg_monthly_sales, - rank() over - (partition by i_category, i_brand, - s_store_name, s_company_name - order by d_year, d_moy) rn - from item, store_sales, date_dim, store - where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - ( - d_year = 1999 or - ( d_year = 1999-1 and d_moy =12) or - ( d_year = 1999+1 and d_moy =1) - ) - group by i_category, i_brand, - s_store_name, s_company_name, - d_year, d_moy), - v2 as( - select v1.i_brand - ,v1.d_year - ,v1.avg_monthly_sales - ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum - from v1, v1 v1_lag, v1 v1_lead - where v1.i_category = v1_lag.i_category and - v1.i_category = v1_lead.i_category and - v1.i_brand = v1_lag.i_brand and - v1.i_brand = v1_lead.i_brand and - v1.s_store_name = v1_lag.s_store_name and - v1.s_store_name = v1_lead.s_store_name and - v1.s_company_name = v1_lag.s_company_name and - v1.s_company_name = v1_lead.s_company_name and - v1.rn = v1_lag.rn + 1 and - v1.rn = v1_lead.rn - 1) - select * - from v2 - where d_year = 1999 and - avg_monthly_sales > 0 and - case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 - order by sum_sales - avg_monthly_sales, sum_sales - limit 100; - --- end template query47.tpl query 60 in stream 9 --- start template query26.tpl query 61 in stream 9 -select /* TPC-DS query26.tpl 0.85 */ i_item_id, - avg(cs_quantity) agg1, - avg(cs_list_price) agg2, - avg(cs_coupon_amt) agg3, - avg(cs_sales_price) agg4 - from catalog_sales, customer_demographics, date_dim, item, promotion - where cs_sold_date_sk = d_date_sk and - cs_item_sk = i_item_sk and - cs_bill_cdemo_sk = cd_demo_sk and - cs_promo_sk = p_promo_sk and - cd_gender = 'M' and - cd_marital_status = 'M' and - cd_education_status = 'Unknown' and - (p_channel_email = 'N' or p_channel_event = 'N') and - d_year = 2002 - group by i_item_id - order by i_item_id - limit 100; - --- end template query26.tpl query 61 in stream 9 --- start template query25.tpl query 62 in stream 9 -select /* TPC-DS query25.tpl 0.9 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,sum(ss_net_profit) as store_sales_profit - ,sum(sr_net_loss) as store_returns_loss - ,sum(cs_net_profit) as catalog_sales_profit - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 1999 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 10 - and d2.d_year = 1999 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_moy between 4 and 10 - and d3.d_year = 1999 - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query25.tpl query 62 in stream 9 --- start template query98.tpl query 63 in stream 9 -select /* TPC-DS query98.tpl 0.32 */ i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price - ,sum(ss_ext_sales_price) as itemrevenue - ,sum(ss_ext_sales_price)*100/sum(sum(ss_ext_sales_price)) over - (partition by i_class) as revenueratio -from - store_sales - ,item - ,date_dim -where - ss_item_sk = i_item_sk - and i_category in ('Music', 'Men', 'Books') - and ss_sold_date_sk = d_date_sk - and d_date between cast('1999-03-26' as date) - and dateadd(day,30,cast('1999-03-26' as date)) -group by - i_item_id - ,i_item_desc - ,i_category - ,i_class - ,i_current_price -order by - i_category - ,i_class - ,i_item_id - ,i_item_desc - ,revenueratio; - --- end template query98.tpl query 63 in stream 9 --- start template query70a.tpl query 64 in stream 9 -with /* TPC-DS query70a.tpl 0.34 */ results as -( select - sum(ss_net_profit) as total_sum ,s_state ,s_county, 0 as gstate, 0 as g_county - from - store_sales - ,date_dim d1 - ,store - where - d1.d_month_seq between 1222 and 1222 + 11 - and d1.d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - and s_state in - ( select s_state - from (select s_state as s_state, - rank() over ( partition by s_state order by sum(ss_net_profit) desc) as ranking - from store_sales, store, date_dim - where d_month_seq between 1222 and 1222 + 11 - and d_date_sk = ss_sold_date_sk - and s_store_sk = ss_store_sk - group by s_state - ) tmp1 - where ranking <= 5) - group by s_state,s_county) , - results_rollup as -(select total_sum ,s_state ,s_county, 0 as g_state, 0 as g_county, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum,s_state, NULL as s_county, 0 as g_state, 1 as g_county, 1 as lochierarchy from results group by s_state - union - select sum(total_sum) as total_sum ,NULL as s_state ,NULL as s_county, 1 as g_state, 1 as g_county, 2 as lochierarchy from results) - select total_sum ,s_state ,s_county, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_county = 0 then s_state end - order by total_sum desc) as rank_within_parent - from results_rollup - order by - lochierarchy desc - ,case when lochierarchy = 0 then s_state end - ,rank_within_parent - limit 100; - --- end template query70a.tpl query 64 in stream 9 --- start template query73.tpl query 65 in stream 9 -select /* TPC-DS query73.tpl 0.79 */ c_last_name - ,c_first_name - ,c_salutation - ,c_preferred_cust_flag - ,ss_ticket_number - ,cnt from - (select ss_ticket_number - ,ss_customer_sk - ,count(*) cnt - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and date_dim.d_dom between 1 and 2 - and (household_demographics.hd_buy_potential = '>10000' or - household_demographics.hd_buy_potential = '5001-10000') - and household_demographics.hd_vehicle_count > 0 - and case when household_demographics.hd_vehicle_count > 0 then - household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count else null end > 1 - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_county in ('Ziebach County','Daviess County','Kittitas County','Richland County') - group by ss_ticket_number,ss_customer_sk) dj,customer - where ss_customer_sk = c_customer_sk - and cnt between 1 and 5 - order by cnt desc, c_last_name asc; - --- end template query73.tpl query 65 in stream 9 --- start template query38.tpl query 66 in stream 9 -select /* TPC-DS query38.tpl 0.54 */ count(*) from ( - select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1177 and 1177 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1177 and 1177 + 11 - intersect - select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1177 and 1177 + 11 -) hot_cust -limit 100; - --- end template query38.tpl query 66 in stream 9 --- start template query87.tpl query 67 in stream 9 -select /* TPC-DS query87.tpl 0.77 */ count(*) -from ((select distinct c_last_name, c_first_name, d_date - from store_sales, date_dim, customer - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_customer_sk = customer.c_customer_sk - and d_month_seq between 1219 and 1219+11) - except - (select distinct c_last_name, c_first_name, d_date - from catalog_sales, date_dim, customer - where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk - and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1219 and 1219+11) - except - (select distinct c_last_name, c_first_name, d_date - from web_sales, date_dim, customer - where web_sales.ws_sold_date_sk = date_dim.d_date_sk - and web_sales.ws_bill_customer_sk = customer.c_customer_sk - and d_month_seq between 1219 and 1219+11) -) cool_cust -; - --- end template query87.tpl query 67 in stream 9 --- start template query3.tpl query 68 in stream 9 -select /* TPC-DS query3.tpl 0.45 */ dt.d_year - ,item.i_brand_id brand_id - ,item.i_brand brand - ,sum(ss_sales_price) sum_agg - from date_dim dt - ,store_sales - ,item - where dt.d_date_sk = store_sales.ss_sold_date_sk - and store_sales.ss_item_sk = item.i_item_sk - and item.i_manufact_id = 619 - and dt.d_moy=11 - group by dt.d_year - ,item.i_brand - ,item.i_brand_id - order by dt.d_year - ,sum_agg desc - ,brand_id - limit 100; - --- end template query3.tpl query 68 in stream 9 --- start template query69.tpl query 69 in stream 9 -select /* TPC-DS query69.tpl 0.28 */ - cd_gender, - cd_marital_status, - cd_education_status, - count(*) cnt1, - cd_purchase_estimate, - count(*) cnt2, - cd_credit_rating, - count(*) cnt3 - from - customer c,customer_address ca,customer_demographics - where - c.c_current_addr_sk = ca.ca_address_sk and - ca_state in ('ND','MN','CO') and - cd_demo_sk = c.c_current_cdemo_sk and - exists (select * - from store_sales,date_dim - where c.c_customer_sk = ss_customer_sk and - ss_sold_date_sk = d_date_sk and - d_year = 2004 and - d_moy between 4 and 4+2) and - (not exists (select * - from web_sales,date_dim - where c.c_customer_sk = ws_bill_customer_sk and - ws_sold_date_sk = d_date_sk and - d_year = 2004 and - d_moy between 4 and 4+2) and - not exists (select * - from catalog_sales,date_dim - where c.c_customer_sk = cs_ship_customer_sk and - cs_sold_date_sk = d_date_sk and - d_year = 2004 and - d_moy between 4 and 4+2)) - group by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - order by cd_gender, - cd_marital_status, - cd_education_status, - cd_purchase_estimate, - cd_credit_rating - limit 100; - --- end template query69.tpl query 69 in stream 9 --- start template query86a.tpl query 70 in stream 9 -with /* TPC-DS query86a.tpl 0.11 */ results as -( select sum(ws_net_paid) as total_sum, i_category, i_class, 0 as g_category, 0 as g_class - from - web_sales - ,date_dim d1 - ,item - where - d1.d_month_seq between 1203 and 1203+11 - and d1.d_date_sk = ws_sold_date_sk - and i_item_sk = ws_item_sk - group by i_category,i_class - ) , - - results_rollup as -( select total_sum ,i_category ,i_class, g_category, g_class, 0 as lochierarchy from results - union - select sum(total_sum) as total_sum, i_category, NULL as i_class, 0 as g_category, 1 as g_class, 1 as lochierarchy from results group by i_category - union - select sum(total_sum) as total_sum, NULL as i_category, NULL as i_class, 1 as g_category, 1 as g_class, 2 as lochierarchy from results) - select - total_sum ,i_category ,i_class, lochierarchy - ,rank() over ( - partition by lochierarchy, - case when g_class = 0 then i_category end - order by total_sum desc) as rank_within_parent - from - results_rollup - order by - lochierarchy desc, - case when lochierarchy = 0 then i_category end, - rank_within_parent - limit 100; - --- end template query86a.tpl query 70 in stream 9 --- start template query79.tpl query 71 in stream 9 -select /* TPC-DS query79.tpl 0.89 */ - c_last_name,c_first_name,substring(s_city,1,30),ss_ticket_number,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,store.s_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and (household_demographics.hd_dep_count = 9 or household_demographics.hd_vehicle_count > 1) - and date_dim.d_dow = 1 - and date_dim.d_year in (1999,1999+1,1999+2) - and store.s_number_employees between 200 and 295 - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,store.s_city) ms,customer - where ss_customer_sk = c_customer_sk - order by c_last_name,c_first_name,substring(s_city,1,30), profit -limit 100; - --- end template query79.tpl query 71 in stream 9 --- start template query89.tpl query 72 in stream 9 -select /* TPC-DS query89.tpl 0.56 */ * -from( -select i_category, i_class, i_brand, - s_store_name, s_company_name, - d_moy, - sum(ss_sales_price) sum_sales, - avg(sum(ss_sales_price)) over - (partition by i_category, i_brand, s_store_name, s_company_name) - avg_monthly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and - ss_sold_date_sk = d_date_sk and - ss_store_sk = s_store_sk and - d_year in (1998) and - ((i_category in ('Books','Jewelry','Home') and - i_class in ('entertainments','custom','paint') - ) - or (i_category in ('Shoes','Women','Children') and - i_class in ('mens','swimwear','infants') - )) -group by i_category, i_class, i_brand, - s_store_name, s_company_name, d_moy) tmp1 -where case when (avg_monthly_sales <> 0) then (abs(sum_sales - avg_monthly_sales) / avg_monthly_sales) else null end > 0.1 -order by sum_sales - avg_monthly_sales, s_store_name -limit 100; - --- end template query89.tpl query 72 in stream 9 --- start template query51.tpl query 73 in stream 9 -WITH /* TPC-DS query51.tpl 0.46 */ web_v1 as ( -select - ws_item_sk item_sk, d_date, - sum(sum(ws_sales_price)) - over (partition by ws_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from web_sales - ,date_dim -where ws_sold_date_sk=d_date_sk - and d_month_seq between 1199 and 1199+11 - and ws_item_sk is not NULL -group by ws_item_sk, d_date), -store_v1 as ( -select - ss_item_sk item_sk, d_date, - sum(sum(ss_sales_price)) - over (partition by ss_item_sk order by d_date rows between unbounded preceding and current row) cume_sales -from store_sales - ,date_dim -where ss_sold_date_sk=d_date_sk - and d_month_seq between 1199 and 1199+11 - and ss_item_sk is not NULL -group by ss_item_sk, d_date) - select * -from (select item_sk - ,d_date - ,web_sales - ,store_sales - ,max(web_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) web_cumulative - ,max(store_sales) - over (partition by item_sk order by d_date rows between unbounded preceding and current row) store_cumulative - from (select case when web.item_sk is not null then web.item_sk else store.item_sk end item_sk - ,case when web.d_date is not null then web.d_date else store.d_date end d_date - ,web.cume_sales web_sales - ,store.cume_sales store_sales - from web_v1 web full outer join store_v1 store on (web.item_sk = store.item_sk - and web.d_date = store.d_date) - )x )y -where web_cumulative > store_cumulative -order by item_sk - ,d_date -limit 100; - --- end template query51.tpl query 73 in stream 9 --- start template query58.tpl query 74 in stream 9 -with /* TPC-DS query58.tpl 0.19 */ ss_items as - (select i_item_id item_id - ,sum(ss_ext_sales_price) ss_item_rev - from store_sales - ,item - ,date_dim - where ss_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '2002-06-21')) - and ss_sold_date_sk = d_date_sk - group by i_item_id), - cs_items as - (select i_item_id item_id - ,sum(cs_ext_sales_price) cs_item_rev - from catalog_sales - ,item - ,date_dim - where cs_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq = (select d_week_seq - from date_dim - where d_date = '2002-06-21')) - and cs_sold_date_sk = d_date_sk - group by i_item_id), - ws_items as - (select i_item_id item_id - ,sum(ws_ext_sales_price) ws_item_rev - from web_sales - ,item - ,date_dim - where ws_item_sk = i_item_sk - and d_date in (select d_date - from date_dim - where d_week_seq =(select d_week_seq - from date_dim - where d_date = '2002-06-21')) - and ws_sold_date_sk = d_date_sk - group by i_item_id) - select ss_items.item_id - ,ss_item_rev - ,ss_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ss_dev - ,cs_item_rev - ,cs_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 cs_dev - ,ws_item_rev - ,ws_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ws_dev - ,(ss_item_rev+cs_item_rev+ws_item_rev)/3 average - from ss_items,cs_items,ws_items - where ss_items.item_id=cs_items.item_id - and ss_items.item_id=ws_items.item_id - and ss_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - and ss_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and cs_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and cs_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev - and ws_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev - and ws_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev - order by item_id - ,ss_item_rev - limit 100; - --- end template query58.tpl query 74 in stream 9 --- start template query41.tpl query 75 in stream 9 -select /* TPC-DS query41.tpl 0.62 */ distinct(i_product_name) - from item i1 - where i_manufact_id between 721 and 721+40 - and (select count(*) as item_cnt - from item - where (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'chiffon' or i_color = 'coral') and - (i_units = 'Ounce' or i_units = 'Each') and - (i_size = 'N/A' or i_size = 'economy') - ) or - (i_category = 'Women' and - (i_color = 'firebrick' or i_color = 'royal') and - (i_units = 'Bundle' or i_units = 'Carton') and - (i_size = 'extra large' or i_size = 'small') - ) or - (i_category = 'Men' and - (i_color = 'lavender' or i_color = 'bisque') and - (i_units = 'Bunch' or i_units = 'Case') and - (i_size = 'medium' or i_size = 'large') - ) or - (i_category = 'Men' and - (i_color = 'ivory' or i_color = 'rosy') and - (i_units = 'Pallet' or i_units = 'Ton') and - (i_size = 'N/A' or i_size = 'economy') - ))) or - (i_manufact = i1.i_manufact and - ((i_category = 'Women' and - (i_color = 'wheat' or i_color = 'floral') and - (i_units = 'Pound' or i_units = 'N/A') and - (i_size = 'N/A' or i_size = 'economy') - ) or - (i_category = 'Women' and - (i_color = 'indian' or i_color = 'medium') and - (i_units = 'Cup' or i_units = 'Gross') and - (i_size = 'extra large' or i_size = 'small') - ) or - (i_category = 'Men' and - (i_color = 'salmon' or i_color = 'black') and - (i_units = 'Lb' or i_units = 'Dozen') and - (i_size = 'medium' or i_size = 'large') - ) or - (i_category = 'Men' and - (i_color = 'lawn' or i_color = 'ghost') and - (i_units = 'Box' or i_units = 'Unknown') and - (i_size = 'N/A' or i_size = 'economy') - )))) > 0 - order by i_product_name - limit 100; - --- end template query41.tpl query 75 in stream 9 --- start template query19.tpl query 76 in stream 9 -select /* TPC-DS query19.tpl 0.8 */ i_brand_id brand_id, i_brand brand, i_manufact_id, i_manufact, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item,customer,customer_address,store - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=24 - and d_moy=12 - and d_year=2000 - and ss_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and substring(ca_zip,1,5) <> substring(s_zip,1,5) - and ss_store_sk = s_store_sk - group by i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact - order by ext_price desc - ,i_brand - ,i_brand_id - ,i_manufact_id - ,i_manufact -limit 100 ; - --- end template query19.tpl query 76 in stream 9 --- start template query83.tpl query 77 in stream 9 -with /* TPC-DS query83.tpl 0.96 */ sr_items as - (select i_item_id item_id, - sum(sr_return_quantity) sr_item_qty - from store_returns, - item, - date_dim - where sr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2002-02-20','2002-10-05','2002-11-16'))) - and sr_returned_date_sk = d_date_sk - group by i_item_id), - cr_items as - (select i_item_id item_id, - sum(cr_return_quantity) cr_item_qty - from catalog_returns, - item, - date_dim - where cr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2002-02-20','2002-10-05','2002-11-16'))) - and cr_returned_date_sk = d_date_sk - group by i_item_id), - wr_items as - (select i_item_id item_id, - sum(wr_return_quantity) wr_item_qty - from web_returns, - item, - date_dim - where wr_item_sk = i_item_sk - and d_date in - (select d_date - from date_dim - where d_week_seq in - (select d_week_seq - from date_dim - where d_date in ('2002-02-20','2002-10-05','2002-11-16'))) - and wr_returned_date_sk = d_date_sk - group by i_item_id) - select sr_items.item_id - ,sr_item_qty - ,sr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 sr_dev - ,cr_item_qty - ,cr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 cr_dev - ,wr_item_qty - ,wr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 wr_dev - ,(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 average - from sr_items - ,cr_items - ,wr_items - where sr_items.item_id=cr_items.item_id - and sr_items.item_id=wr_items.item_id - order by sr_items.item_id - ,sr_item_qty - limit 100; - --- end template query83.tpl query 77 in stream 9 --- start template query96.tpl query 78 in stream 9 -select /* TPC-DS query96.tpl 0.1 */ count(*) -from store_sales - ,household_demographics - ,time_dim, store -where ss_sold_time_sk = time_dim.t_time_sk - and ss_hdemo_sk = household_demographics.hd_demo_sk - and ss_store_sk = s_store_sk - and time_dim.t_hour = 15 - and time_dim.t_minute >= 30 - and household_demographics.hd_dep_count = 5 - and store.s_store_name = 'ese' -order by count(*) -limit 100; - --- end template query96.tpl query 78 in stream 9 --- start template query46.tpl query 79 in stream 9 -select /* TPC-DS query46.tpl 0.23 */ c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - ,amt,profit - from - (select ss_ticket_number - ,ss_customer_sk - ,ca_city bought_city - ,sum(ss_coupon_amt) amt - ,sum(ss_net_profit) profit - from store_sales,date_dim,store,household_demographics,customer_address - where store_sales.ss_sold_date_sk = date_dim.d_date_sk - and store_sales.ss_store_sk = store.s_store_sk - and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk - and store_sales.ss_addr_sk = customer_address.ca_address_sk - and (household_demographics.hd_dep_count = 3 or - household_demographics.hd_vehicle_count= 1) - and date_dim.d_dow in (6,0) - and date_dim.d_year in (2000,2000+1,2000+2) - and store.s_city in ('Friendship','Liberty','Spring Valley','Mount Pleasant','Greenwood') - group by ss_ticket_number,ss_customer_sk,ss_addr_sk,ca_city) dn,customer,customer_address current_addr - where ss_customer_sk = c_customer_sk - and customer.c_current_addr_sk = current_addr.ca_address_sk - and current_addr.ca_city <> bought_city - order by c_last_name - ,c_first_name - ,ca_city - ,bought_city - ,ss_ticket_number - limit 100; - --- end template query46.tpl query 79 in stream 9 --- start template query53.tpl query 80 in stream 9 -select /* TPC-DS query53.tpl 0.88 */ * from -(select i_manufact_id, -sum(ss_sales_price) sum_sales, -avg(sum(ss_sales_price)) over (partition by i_manufact_id) avg_quarterly_sales -from item, store_sales, date_dim, store -where ss_item_sk = i_item_sk and -ss_sold_date_sk = d_date_sk and -ss_store_sk = s_store_sk and -d_month_seq in (1204,1204+1,1204+2,1204+3,1204+4,1204+5,1204+6,1204+7,1204+8,1204+9,1204+10,1204+11) and -((i_category in ('Books','Children','Electronics') and -i_class in ('personal','portable','reference','self-help') and -i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) -or(i_category in ('Women','Music','Men') and -i_class in ('accessories','classical','fragrances','pants') and -i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manufact_id, d_qoy ) tmp1 -where case when avg_quarterly_sales > 0 - then abs (sum_sales - avg_quarterly_sales)/ avg_quarterly_sales - else null end > 0.1 -order by avg_quarterly_sales, - sum_sales, - i_manufact_id -limit 100; - --- end template query53.tpl query 80 in stream 9 --- start template query55.tpl query 81 in stream 9 -select /* TPC-DS query55.tpl 0.82 */ i_brand_id brand_id, i_brand brand, - sum(ss_ext_sales_price) ext_price - from date_dim, store_sales, item - where d_date_sk = ss_sold_date_sk - and ss_item_sk = i_item_sk - and i_manager_id=99 - and d_moy=11 - and d_year=1998 - group by i_brand, i_brand_id - order by ext_price desc, i_brand_id -limit 100 ; - --- end template query55.tpl query 81 in stream 9 --- start template query72.tpl query 82 in stream 9 -select /* TPC-DS query72.tpl 0.87 */ i_item_desc - ,w_warehouse_name - ,d1.d_week_seq - ,sum(case when p_promo_sk is null then 1 else 0 end) no_promo - ,sum(case when p_promo_sk is not null then 1 else 0 end) promo - ,count(*) total_cnt -from catalog_sales -join inventory on (cs_item_sk = inv_item_sk) -join warehouse on (w_warehouse_sk=inv_warehouse_sk) -join item on (i_item_sk = cs_item_sk) -join customer_demographics on (cs_bill_cdemo_sk = cd_demo_sk) -join household_demographics on (cs_bill_hdemo_sk = hd_demo_sk) -join date_dim d1 on (cs_sold_date_sk = d1.d_date_sk) -join date_dim d2 on (inv_date_sk = d2.d_date_sk) -join date_dim d3 on (cs_ship_date_sk = d3.d_date_sk) -left outer join promotion on (cs_promo_sk=p_promo_sk) -left outer join catalog_returns on (cr_item_sk = cs_item_sk and cr_order_number = cs_order_number) -where d1.d_week_seq = d2.d_week_seq - and inv_quantity_on_hand < cs_quantity - and d3.d_date > d1.d_date + 5 - and hd_buy_potential = '1001-5000' - and d1.d_year = 2002 - and cd_marital_status = 'D' -group by i_item_desc,w_warehouse_name,d1.d_week_seq -order by total_cnt desc, i_item_desc, w_warehouse_name, d_week_seq -limit 100; - --- end template query72.tpl query 82 in stream 9 --- start template query95.tpl query 83 in stream 9 -with /* TPC-DS query95.tpl 0.43 */ ws_wh as -(select ws1.ws_order_number,ws1.ws_warehouse_sk wh1,ws2.ws_warehouse_sk wh2 - from web_sales ws1,web_sales ws2 - where ws1.ws_order_number = ws2.ws_order_number - and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) - select - count(distinct ws_order_number) as "order count" - ,sum(ws_ext_ship_cost) as "total shipping cost" - ,sum(ws_net_profit) as "total net profit" -from - web_sales ws1 - ,date_dim - ,customer_address - ,web_site -where - d_date between '2002-4-01' and - dateadd(day,60,cast('2002-4-01' as date)) -and ws1.ws_ship_date_sk = d_date_sk -and ws1.ws_ship_addr_sk = ca_address_sk -and ca_state = 'IL' -and ws1.ws_web_site_sk = web_site_sk -and web_company_name = 'pri' -and ws1.ws_order_number in (select ws_order_number - from ws_wh) -and ws1.ws_order_number in (select wr_order_number - from web_returns,ws_wh - where wr_order_number = ws_wh.ws_order_number) -order by count(distinct ws_order_number) -limit 100; - --- end template query95.tpl query 83 in stream 9 --- start template query29.tpl query 84 in stream 9 -select /* TPC-DS query29.tpl 0.53 */ - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - ,avg(ss_quantity) as store_sales_quantity - ,avg(sr_return_quantity) as store_returns_quantity - ,avg(cs_quantity) as catalog_sales_quantity - from - store_sales - ,store_returns - ,catalog_sales - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,item - where - d1.d_moy = 4 - and d1.d_year = 1999 - and d1.d_date_sk = ss_sold_date_sk - and i_item_sk = ss_item_sk - and s_store_sk = ss_store_sk - and ss_customer_sk = sr_customer_sk - and ss_item_sk = sr_item_sk - and ss_ticket_number = sr_ticket_number - and sr_returned_date_sk = d2.d_date_sk - and d2.d_moy between 4 and 4 + 3 - and d2.d_year = 1999 - and sr_customer_sk = cs_bill_customer_sk - and sr_item_sk = cs_item_sk - and cs_sold_date_sk = d3.d_date_sk - and d3.d_year in (1999,1999+1,1999+2) - group by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - order by - i_item_id - ,i_item_desc - ,s_store_id - ,s_store_name - limit 100; - --- end template query29.tpl query 84 in stream 9 --- start template query64.tpl query 85 in stream 9 -with /* TPC-DS query64.tpl 0.20 */ cs_ui as - (select cs_item_sk - ,sum(cs_ext_list_price) as sale,sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit) as refund - from catalog_sales - ,catalog_returns - where cs_item_sk = cr_item_sk - and cs_order_number = cr_order_number - group by cs_item_sk - having sum(cs_ext_list_price)>2*sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit)), -cross_sales as - (select i_product_name product_name - ,i_item_sk item_sk - ,s_store_name store_name - ,s_zip store_zip - ,ad1.ca_street_number b_street_number - ,ad1.ca_street_name b_street_name - ,ad1.ca_city b_city - ,ad1.ca_zip b_zip - ,ad2.ca_street_number c_street_number - ,ad2.ca_street_name c_street_name - ,ad2.ca_city c_city - ,ad2.ca_zip c_zip - ,d1.d_year as syear - ,d2.d_year as fsyear - ,d3.d_year s2year - ,count(*) cnt - ,sum(ss_wholesale_cost) s1 - ,sum(ss_list_price) s2 - ,sum(ss_coupon_amt) s3 - FROM store_sales - ,store_returns - ,cs_ui - ,date_dim d1 - ,date_dim d2 - ,date_dim d3 - ,store - ,customer - ,customer_demographics cd1 - ,customer_demographics cd2 - ,promotion - ,household_demographics hd1 - ,household_demographics hd2 - ,customer_address ad1 - ,customer_address ad2 - ,income_band ib1 - ,income_band ib2 - ,item - WHERE ss_store_sk = s_store_sk AND - ss_sold_date_sk = d1.d_date_sk AND - ss_customer_sk = c_customer_sk AND - ss_cdemo_sk= cd1.cd_demo_sk AND - ss_hdemo_sk = hd1.hd_demo_sk AND - ss_addr_sk = ad1.ca_address_sk and - ss_item_sk = i_item_sk and - ss_item_sk = sr_item_sk and - ss_ticket_number = sr_ticket_number and - ss_item_sk = cs_ui.cs_item_sk and - c_current_cdemo_sk = cd2.cd_demo_sk AND - c_current_hdemo_sk = hd2.hd_demo_sk AND - c_current_addr_sk = ad2.ca_address_sk and - c_first_sales_date_sk = d2.d_date_sk and - c_first_shipto_date_sk = d3.d_date_sk and - ss_promo_sk = p_promo_sk and - hd1.hd_income_band_sk = ib1.ib_income_band_sk and - hd2.hd_income_band_sk = ib2.ib_income_band_sk and - cd1.cd_marital_status <> cd2.cd_marital_status and - i_color in ('steel','brown','cornsilk','grey','seashell','sienna') and - i_current_price between 7 and 7 + 10 and - i_current_price between 7 + 1 and 7 + 15 -group by i_product_name - ,i_item_sk - ,s_store_name - ,s_zip - ,ad1.ca_street_number - ,ad1.ca_street_name - ,ad1.ca_city - ,ad1.ca_zip - ,ad2.ca_street_number - ,ad2.ca_street_name - ,ad2.ca_city - ,ad2.ca_zip - ,d1.d_year - ,d2.d_year - ,d3.d_year -) -select cs1.product_name - ,cs1.store_name - ,cs1.store_zip - ,cs1.b_street_number - ,cs1.b_street_name - ,cs1.b_city - ,cs1.b_zip - ,cs1.c_street_number - ,cs1.c_street_name - ,cs1.c_city - ,cs1.c_zip - ,cs1.syear - ,cs1.cnt - ,cs1.s1 as s11 - ,cs1.s2 as s21 - ,cs1.s3 as s31 - ,cs2.s1 as s12 - ,cs2.s2 as s22 - ,cs2.s3 as s32 - ,cs2.syear - ,cs2.cnt -from cross_sales cs1,cross_sales cs2 -where cs1.item_sk=cs2.item_sk and - cs1.syear = 1999 and - cs2.syear = 1999 + 1 and - cs2.cnt <= cs1.cnt and - cs1.store_name = cs2.store_name and - cs1.store_zip = cs2.store_zip -order by cs1.product_name - ,cs1.store_name - ,cs2.cnt - ,cs1.s1 - ,cs2.s1; - --- end template query64.tpl query 85 in stream 9 --- start template query93.tpl query 86 in stream 9 -select /* TPC-DS query93.tpl 0.52 */ ss_customer_sk - ,sum(act_sales) sumsales - from (select ss_item_sk - ,ss_ticket_number - ,ss_customer_sk - ,case when sr_return_quantity is not null then (ss_quantity-sr_return_quantity)*ss_sales_price - else (ss_quantity*ss_sales_price) end act_sales - from store_sales left outer join store_returns on (sr_item_sk = ss_item_sk - and sr_ticket_number = ss_ticket_number) - ,reason - where sr_reason_sk = r_reason_sk - and r_reason_desc = 'reason 28') t - group by ss_customer_sk - order by sumsales, ss_customer_sk -limit 100; - --- end template query93.tpl query 86 in stream 9 --- start template query56.tpl query 87 in stream 9 -with /* TPC-DS query56.tpl 0.83 */ ss as ( - select i_item_id,sum(ss_ext_sales_price) total_sales - from - store_sales, - date_dim, - customer_address, - item - where i_item_id in (select - i_item_id -from item -where i_color in ('wheat','almond','saddle')) - and ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 7 - and ss_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - cs as ( - select i_item_id,sum(cs_ext_sales_price) total_sales - from - catalog_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('wheat','almond','saddle')) - and cs_item_sk = i_item_sk - and cs_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 7 - and cs_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id), - ws as ( - select i_item_id,sum(ws_ext_sales_price) total_sales - from - web_sales, - date_dim, - customer_address, - item - where - i_item_id in (select - i_item_id -from item -where i_color in ('wheat','almond','saddle')) - and ws_item_sk = i_item_sk - and ws_sold_date_sk = d_date_sk - and d_year = 1998 - and d_moy = 7 - and ws_bill_addr_sk = ca_address_sk - and ca_gmt_offset = -6 - group by i_item_id) - select i_item_id ,sum(total_sales) total_sales - from (select * from ss - union all - select * from cs - union all - select * from ws) tmp1 - group by i_item_id - order by total_sales, - i_item_id - limit 100; - --- end template query56.tpl query 87 in stream 9 --- start template query97.tpl query 88 in stream 9 -with /* TPC-DS query97.tpl 0.38 */ ssci as ( -select ss_customer_sk customer_sk - ,ss_item_sk item_sk -from store_sales,date_dim -where ss_sold_date_sk = d_date_sk - and d_month_seq between 1180 and 1180 + 11 -group by ss_customer_sk - ,ss_item_sk), -csci as( - select cs_bill_customer_sk customer_sk - ,cs_item_sk item_sk -from catalog_sales,date_dim -where cs_sold_date_sk = d_date_sk - and d_month_seq between 1180 and 1180 + 11 -group by cs_bill_customer_sk - ,cs_item_sk) - select sum(case when ssci.customer_sk is not null and csci.customer_sk is null then 1 else 0 end) store_only - ,sum(case when ssci.customer_sk is null and csci.customer_sk is not null then 1 else 0 end) catalog_only - ,sum(case when ssci.customer_sk is not null and csci.customer_sk is not null then 1 else 0 end) store_and_catalog -from ssci full outer join csci on (ssci.customer_sk=csci.customer_sk - and ssci.item_sk = csci.item_sk) -limit 100; - --- end template query97.tpl query 88 in stream 9 --- start template query23.tpl query 89 in stream 9 -with /* TPC-DS query23.tpl 0.68 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (2000,2000+1,2000+2,2000+3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (2000,2000+1,2000+2,2000+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * -from - max_store_sales)) - select sum(sales) - from (select cs_quantity*cs_list_price sales - from catalog_sales - ,date_dim - where d_year = 2000 - and d_moy = 2 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - union all - select ws_quantity*ws_list_price sales - from web_sales - ,date_dim - where d_year = 2000 - and d_moy = 2 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer)) - limit 100; -with /* TPC-DS query23.tpl 0.68 part2 */ frequent_ss_items as - (select substring(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt - from store_sales - ,date_dim - ,item - where ss_sold_date_sk = d_date_sk - and ss_item_sk = i_item_sk - and d_year in (2000,2000 + 1,2000 + 2,2000 + 3) - group by substring(i_item_desc,1,30),i_item_sk,d_date - having count(*) >4), - max_store_sales as - (select max(csales) tpcds_cmax - from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales - from store_sales - ,customer - ,date_dim - where ss_customer_sk = c_customer_sk - and ss_sold_date_sk = d_date_sk - and d_year in (2000,2000+1,2000+2,2000+3) - group by c_customer_sk)), - best_ss_customer as - (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales - from store_sales - ,customer - where ss_customer_sk = c_customer_sk - group by c_customer_sk - having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select - * - from max_store_sales)) - select c_last_name,c_first_name,sales - from (select c_last_name,c_first_name,sum(cs_quantity*cs_list_price) sales - from catalog_sales - ,customer - ,date_dim - where d_year = 2000 - and d_moy = 2 - and cs_sold_date_sk = d_date_sk - and cs_item_sk in (select item_sk from frequent_ss_items) - and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and cs_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name - union all - select c_last_name,c_first_name,sum(ws_quantity*ws_list_price) sales - from web_sales - ,customer - ,date_dim - where d_year = 2000 - and d_moy = 2 - and ws_sold_date_sk = d_date_sk - and ws_item_sk in (select item_sk from frequent_ss_items) - and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer) - and ws_bill_customer_sk = c_customer_sk - group by c_last_name,c_first_name) - order by c_last_name,c_first_name,sales - limit 100; - --- end template query23.tpl query 89 in stream 9 --- start template query44.tpl query 90 in stream 9 -select /* TPC-DS query44.tpl 0.4 */ asceding.rnk, i1.i_product_name best_performing, i2.i_product_name worst_performing -from(select * - from (select item_sk,rank() over (order by rank_col asc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 44 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 44 - and ss_addr_sk is null - group by ss_store_sk))V1)V11 - where rnk < 11) asceding, - (select * - from (select item_sk,rank() over (order by rank_col desc) rnk - from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col - from store_sales ss1 - where ss_store_sk = 44 - group by ss_item_sk - having avg(ss_net_profit) > 0.90*(select avg(ss_net_profit) rank_col - from store_sales - where ss_store_sk = 44 - and ss_addr_sk is null - group by ss_store_sk))V2)V21 - where rnk < 11) descending, -item i1, -item i2 -where asceding.rnk = descending.rnk - and i1.i_item_sk=asceding.item_sk - and i2.i_item_sk=descending.item_sk -order by asceding.rnk -limit 100; - --- end template query44.tpl query 90 in stream 9 --- start template query91.tpl query 91 in stream 9 -select /* TPC-DS query91.tpl 0.13 */ - cc_call_center_id Call_Center, - cc_name Call_Center_Name, - cc_manager Manager, - sum(cr_net_loss) Returns_Loss -from - call_center, - catalog_returns, - date_dim, - customer, - customer_address, - customer_demographics, - household_demographics -where - cr_call_center_sk = cc_call_center_sk -and cr_returned_date_sk = d_date_sk -and cr_returning_customer_sk= c_customer_sk -and cd_demo_sk = c_current_cdemo_sk -and hd_demo_sk = c_current_hdemo_sk -and ca_address_sk = c_current_addr_sk -and d_year = 1999 -and d_moy = 11 -and ( (cd_marital_status = 'M' and cd_education_status = 'Unknown') - or(cd_marital_status = 'W' and cd_education_status = 'Advanced Degree')) -and hd_buy_potential like '1001-5000%' -and ca_gmt_offset = -6 -group by cc_call_center_id,cc_name,cc_manager,cd_marital_status,cd_education_status -order by sum(cr_net_loss) desc; - --- end template query91.tpl query 91 in stream 9 --- start template query49.tpl query 92 in stream 9 -select /* TPC-DS query49.tpl 0.48 */ channel, item, return_ratio, return_rank, currency_rank from - (select - 'web' as channel - ,web.item - ,web.return_ratio - ,web.return_rank - ,web.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select ws.ws_item_sk as item - ,(cast(sum(coalesce(wr.wr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(wr.wr_return_amt,0)) as decimal(15,4))/ - cast(sum(coalesce(ws.ws_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - web_sales ws left outer join web_returns wr - on (ws.ws_order_number = wr.wr_order_number and - ws.ws_item_sk = wr.wr_item_sk) - ,date_dim - where - wr.wr_return_amt > 10000 - and ws.ws_net_profit > 1 - and ws.ws_net_paid > 0 - and ws.ws_quantity > 0 - and ws_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 12 - group by ws.ws_item_sk - ) in_web - ) web - where - ( - web.return_rank <= 10 - or - web.currency_rank <= 10 - ) - union - select - 'catalog' as channel - ,catalog.item - ,catalog.return_ratio - ,catalog.return_rank - ,catalog.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select - cs.cs_item_sk as item - ,(cast(sum(coalesce(cr.cr_return_quantity,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(cr.cr_return_amount,0)) as decimal(15,4))/ - cast(sum(coalesce(cs.cs_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - catalog_sales cs left outer join catalog_returns cr - on (cs.cs_order_number = cr.cr_order_number and - cs.cs_item_sk = cr.cr_item_sk) - ,date_dim - where - cr.cr_return_amount > 10000 - and cs.cs_net_profit > 1 - and cs.cs_net_paid > 0 - and cs.cs_quantity > 0 - and cs_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 12 - group by cs.cs_item_sk - ) in_cat - ) catalog - where - ( - catalog.return_rank <= 10 - or - catalog.currency_rank <=10 - ) - union - select - 'store' as channel - ,store.item - ,store.return_ratio - ,store.return_rank - ,store.currency_rank - from ( - select - item - ,return_ratio - ,currency_ratio - ,rank() over (order by return_ratio) as return_rank - ,rank() over (order by currency_ratio) as currency_rank - from - ( select sts.ss_item_sk as item - ,(cast(sum(coalesce(sr.sr_return_quantity,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_quantity,0)) as decimal(15,4) )) as return_ratio - ,(cast(sum(coalesce(sr.sr_return_amt,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_net_paid,0)) as decimal(15,4) )) as currency_ratio - from - store_sales sts left outer join store_returns sr - on (sts.ss_ticket_number = sr.sr_ticket_number and sts.ss_item_sk = sr.sr_item_sk) - ,date_dim - where - sr.sr_return_amt > 10000 - and sts.ss_net_profit > 1 - and sts.ss_net_paid > 0 - and sts.ss_quantity > 0 - and ss_sold_date_sk = d_date_sk - and d_year = 2000 - and d_moy = 12 - group by sts.ss_item_sk - ) in_store - ) store - where ( - store.return_rank <= 10 - or - store.currency_rank <= 10 - ) - ) - order by 1,4,5,2 - limit 100; - --- end template query49.tpl query 92 in stream 9 --- start template query76.tpl query 93 in stream 9 -select /* TPC-DS query76.tpl 0.99 */ channel, col_name, d_year, d_qoy, i_category, COUNT(*) sales_cnt, SUM(ext_sales_price) sales_amt FROM ( - SELECT 'store' as channel, 'ss_store_sk' col_name, d_year, d_qoy, i_category, ss_ext_sales_price ext_sales_price - FROM store_sales, item, date_dim - WHERE ss_store_sk IS NULL - AND ss_sold_date_sk=d_date_sk - AND ss_item_sk=i_item_sk - UNION ALL - SELECT 'web' as channel, 'ws_bill_customer_sk' col_name, d_year, d_qoy, i_category, ws_ext_sales_price ext_sales_price - FROM web_sales, item, date_dim - WHERE ws_bill_customer_sk IS NULL - AND ws_sold_date_sk=d_date_sk - AND ws_item_sk=i_item_sk - UNION ALL - SELECT 'catalog' as channel, 'cs_ship_cdemo_sk' col_name, d_year, d_qoy, i_category, cs_ext_sales_price ext_sales_price - FROM catalog_sales, item, date_dim - WHERE cs_ship_cdemo_sk IS NULL - AND cs_sold_date_sk=d_date_sk - AND cs_item_sk=i_item_sk) foo -GROUP BY channel, col_name, d_year, d_qoy, i_category -ORDER BY channel, col_name, d_year, d_qoy, i_category -limit 100; - --- end template query76.tpl query 93 in stream 9 --- start template query63.tpl query 94 in stream 9 -select /* TPC-DS query63.tpl 0.27 */ * -from (select i_manager_id - ,sum(ss_sales_price) sum_sales - ,avg(sum(ss_sales_price)) over (partition by i_manager_id) avg_monthly_sales - from item - ,store_sales - ,date_dim - ,store - where ss_item_sk = i_item_sk - and ss_sold_date_sk = d_date_sk - and ss_store_sk = s_store_sk - and d_month_seq in (1190,1190+1,1190+2,1190+3,1190+4,1190+5,1190+6,1190+7,1190+8,1190+9,1190+10,1190+11) - and (( i_category in ('Books','Children','Electronics') - and i_class in ('personal','portable','reference','self-help') - and i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', - 'exportiunivamalg #9','scholaramalgamalg #9')) - or( i_category in ('Women','Music','Men') - and i_class in ('accessories','classical','fragrances','pants') - and i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', - 'importoamalg #1'))) -group by i_manager_id, d_moy) tmp1 -where case when avg_monthly_sales > 0 then abs (sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 -order by i_manager_id - ,avg_monthly_sales - ,sum_sales -limit 100; - --- end template query63.tpl query 94 in stream 9 --- start template query45.tpl query 95 in stream 9 -select /* TPC-DS query45.tpl 0.18 */ ca_zip, ca_city, sum(ws_sales_price) - from web_sales, customer, customer_address, date_dim, item - where ws_bill_customer_sk = c_customer_sk - and c_current_addr_sk = ca_address_sk - and ws_item_sk = i_item_sk - and ( substring(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', '85392', '85460', '80348', '81792') - or - i_item_id in (select i_item_id - from item - where i_item_sk in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29) - ) - ) - and ws_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 1999 - group by ca_zip, ca_city - order by ca_zip, ca_city - limit 100; - --- end template query45.tpl query 95 in stream 9 --- start template query43.tpl query 96 in stream 9 -select /* TPC-DS query43.tpl 0.15 */ s_store_name, s_store_id, - sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, - sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, - sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, - sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, - sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, - sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, - sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales - from date_dim, store_sales, store - where d_date_sk = ss_sold_date_sk and - s_store_sk = ss_store_sk and - s_gmt_offset = -5 and - d_year = 2000 - group by s_store_name, s_store_id - order by s_store_name, s_store_id,sun_sales,mon_sales,tue_sales,wed_sales,thu_sales,fri_sales,sat_sales - limit 100; - --- end template query43.tpl query 96 in stream 9 --- start template query85.tpl query 97 in stream 9 -select /* TPC-DS query85.tpl 0.33 */ substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) - from web_sales, web_returns, web_page, customer_demographics cd1, - customer_demographics cd2, customer_address, date_dim, reason - where ws_web_page_sk = wp_web_page_sk - and ws_item_sk = wr_item_sk - and ws_order_number = wr_order_number - and ws_sold_date_sk = d_date_sk and d_year = 2002 - and cd1.cd_demo_sk = wr_refunded_cdemo_sk - and cd2.cd_demo_sk = wr_returning_cdemo_sk - and ca_address_sk = wr_refunded_addr_sk - and r_reason_sk = wr_reason_sk - and - ( - ( - cd1.cd_marital_status = 'U' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Secondary' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 100.00 and 150.00 - ) - or - ( - cd1.cd_marital_status = 'M' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Unknown' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 50.00 and 100.00 - ) - or - ( - cd1.cd_marital_status = 'W' - and - cd1.cd_marital_status = cd2.cd_marital_status - and - cd1.cd_education_status = 'Advanced Degree' - and - cd1.cd_education_status = cd2.cd_education_status - and - ws_sales_price between 150.00 and 200.00 - ) - ) - and - ( - ( - ca_country = 'United States' - and - ca_state in ('TX', 'KS', 'IL') - and ws_net_profit between 100 and 200 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('MN', 'MI', 'NM') - and ws_net_profit between 150 and 300 - ) - or - ( - ca_country = 'United States' - and - ca_state in ('AR', 'MS', 'MD') - and ws_net_profit between 50 and 250 - ) - ) -group by r_reason_desc -order by substring(r_reason_desc,1,20) - ,avg(ws_quantity) - ,avg(wr_refunded_cash) - ,avg(wr_fee) -limit 100; - --- end template query85.tpl query 97 in stream 9 --- start template query37.tpl query 98 in stream 9 -select /* TPC-DS query37.tpl 0.31 */ i_item_id - ,i_item_desc - ,i_current_price - from item, inventory, date_dim, catalog_sales - where i_current_price between 50 and 50 + 30 - and inv_item_sk = i_item_sk - and d_date_sk=inv_date_sk - and d_date between cast('1999-04-24' as date) and dateadd(day,60,cast('1999-04-24' as date)) - and i_manufact_id in (732,921,723,763) - and inv_quantity_on_hand between 100 and 500 - and cs_item_sk = i_item_sk - group by i_item_id,i_item_desc,i_current_price - order by i_item_id - limit 100; - --- end template query37.tpl query 98 in stream 9 --- start template query8.tpl query 99 in stream 9 -select /* TPC-DS query8.tpl 0.63 */ s_store_name - ,sum(ss_net_profit) - from store_sales - ,date_dim - ,store, - (select ca_zip - from ( - SELECT substring(ca_zip,1,5) ca_zip - FROM customer_address - WHERE substring(ca_zip,1,5) IN ( - '92244','37333','28071','24783','85708','19753', - '34181','38280','67907','52971','31247', - '11458','55400','28685','67696','32156', - '39576','38232','91595','16935','41407', - '96784','32877','94613','12763','30789', - '39850','59494','44362','43160','40789', - '63087','28105','66097','96082','16315', - '80238','48882','47327','17086','87200', - '63117','75113','49166','89983','41331', - '50810','46486','24455','45425','70965', - '46261','69565','14656','88879','32095', - '94572','28216','91022','85937','66078', - '29826','55310','33734','18226','99692', - '61710','69082','34285','51483','96070', - '29500','35742','59203','18684','70328', - '77634','88701','25860','14975','89176', - '15105','83799','58331','63925','27240', - '94121','68644','24754','58913','86994', - '93032','45342','48868','95002','69838', - '29772','16904','68743','97018','82640', - '41796','63789','20677','75131','29929', - '88612','72337','69733','11939','19136', - '53838','26606','38069','45436','29176', - '58314','52590','43622','61181','54904', - '52486','76432','29829','11137','72980', - '87675','55117','12377','54085','63666', - '25083','31868','67782','13740','85287', - '30795','89978','27185','27123','67315', - '97717','40227','27452','43207','80640', - '80249','46574','26777','20751','95648', - '65495','33663','61655','77376','92366', - '46145','99506','34680','85892','42380', - '11170','51190','37942','45869','66435', - '29546','22836','17947','43048','47407', - '34775','53683','87718','75601','77761', - '13528','89448','42568','19682','34086', - '75463','34919','28448','56950','46976', - '76762','22595','76265','49639','41920', - '72964','54621','57682','72174','91185', - '26451','71105','70396','72205','52246', - '29983','74304','69252','74408','27374', - '72384','66289','80345','18582','24904', - '95903','95902','38988','12038','52236', - '14391','28239','39927','58426','22909', - '40083','18650','12214','27042','56601', - '73762','53432','27088','29633','58633', - '63555','73978','95296','98351','90441', - '51274','72080','92959','55760','63524', - '85530','54771','42032','26858','78693', - '28221','39483','57876','95437','94312', - '96995','66450','74288','83915','96274', - '18025','65527','80200','17327','35707', - '52185','27649','12562','11643','93725', - '56841','26116','52993','77943','76075', - '48487','80041','12401','34277','48738', - '57515','46827','34529','88594','49956', - '48801','81659','17938','85053','57923', - '54577','63463','54906','93384','76190', - '89472','83894','46525','38910','25336', - '61458','16542','96935','42574','71453', - '57248','50858','54020','56486','81275', - '28996','97438','12674','66491','67024', - '22012','96360','18966','68053','48884', - '99191','45443','28883','59798','85689', - '28698','43041','34673','48878','75694', - '67383','29455','60724','37352','74464', - '92258','76444','13735','93655','27235', - '51771','83005','97073','91015','47121', - '60897','70067','99810','55969','48689', - '28697','76013','53661','44243','65063', - '37093','22185','57171','32242','44208', - '94976','26583','66162','92124','72144', - '53763','49849','45687','60144','74941', - '29249','86621','41605','74407','96603', - '70008','24704','59385','10254','61159', - '20257','44453','16496','98551','37872', - '56117','67553','15706','98663','49255', - '53310','18848','42543','36794','28607', - '95592','14060','77234','85985','30181', - '27585','59727','67578','90646') - intersect - select ca_zip - from (SELECT substring(ca_zip,1,5) ca_zip,count(*) cnt - FROM customer_address, customer - WHERE ca_address_sk = c_current_addr_sk and - c_preferred_cust_flag='Y' - group by ca_zip - having count(*) > 10)A1)A2) V1 - where ss_store_sk = s_store_sk - and ss_sold_date_sk = d_date_sk - and d_qoy = 2 and d_year = 1998 - and (substring(s_zip,1,2) = substring(V1.ca_zip,1,2)) - group by s_store_name - order by s_store_name - limit 100; - --- end template query8.tpl query 99 in stream 9 From 717b01461ed33bcec996470c681272d78e890d69 Mon Sep 17 00:00:00 2001 From: Milind Oke <80077932+milindoke@users.noreply.github.com> Date: Tue, 6 Aug 2024 20:53:09 -0400 Subject: [PATCH 30/49] added Manifest Generator utility Co-Authored-By: Almann Goo <503506+almann@users.noreply.github.com> --- README.md | 6 + src/ManifestGenerator/README.md | 123 +++++++++++++++++++ src/ManifestGenerator/manifestgen.py | 162 +++++++++++++++++++++++++ src/ManifestGenerator/requirements.txt | 7 ++ 4 files changed, 298 insertions(+) create mode 100644 src/ManifestGenerator/README.md create mode 100644 src/ManifestGenerator/manifestgen.py create mode 100644 src/ManifestGenerator/requirements.txt diff --git a/README.md b/README.md index 1cb65b37..6ddb6d6e 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,12 @@ The [Cloud DW Benchmark](src/CloudDataWarehouseBenchmark) consists of a set of w The [Redshift Unload/Copy Utility](src/UnloadCopyUtility) helps you to migrate data between Redshift Clusters or Databases. It exports data from a source cluster to a location on S3, and all data is encrypted with Amazon Key Management Service. It then automatically imports the data into the configured Redshift Cluster, and will cleanup S3 if required. This utility is intended to be used as part of an ongoing scheduled activity, for instance run as part of a Data Pipeline Shell Activity (http://docs.aws.amazon.com/datapipeline/latest/DeveloperGuide/dp-object-shellcommandactivity.html). +# Manifest Generator + +Data loads into Amazon Redshift tables that have a Sort Key are resource intensive, requiring the system to consume large amounts of memory to sort data. For very large loads, you may observe the run times of `COPY` commands grow non-linearly relative to the data size. Instead of single large multi-TB operations, breaking down the load into chunks could yield faster overall ingestion. + +This utility script is to generate Redshift manifest files to be used for `COPY` command to split the ingestion into batches. + # Simple Replay Utility The [Simple Replay Utility](src/SimpleReplay) helps you to collect and replay cluster workloads. It reads the user activity log files (when audit is enabled) and generates sql files to be replayed. There are two replay tools. One that replays at a arbitrary concurrency and other that tries to reproduce the original cadence of work. diff --git a/src/ManifestGenerator/README.md b/src/ManifestGenerator/README.md new file mode 100644 index 00000000..bae9303c --- /dev/null +++ b/src/ManifestGenerator/README.md @@ -0,0 +1,123 @@ +# Manifest Generator + +Data loads into Amazon Redshift tables that have a Sort Key are resource intensive, requiring the system to consume large amounts of memory to sort data. For very large loads, you may observe the run times of `COPY` commands grow non-linearly relative to the data size. Instead of single large multi-TB operations, breaking down the load into chunks could yield faster overall ingestion. + +This utility script is to generate Redshift manifest files to be used for `COPY` command to split the ingestion into batches. + +## Usage + +This utility supports 3 modes for manifest generation, [CSV Input](#csv-input), [AWS CLI Input](#aws-cli-input), and [Direct S3 access](#direct-s3-access) + +### CSV Input + +Executing in the CSV Input mode requires someone to list the S3 files and construct a CSV input file with two columns, file URL and size and a header row. + +> Note: Manifest-based `COPY` for columnar formats like Parquet/ORC requires file sizes to be specified. + +```csv +file_name,file_size +s3://mybucket/mytbl/file1,1004 +s3://mybucket/mytbl/file2,2020 +s3://mybucket/mytbl/file3,5000 +... +``` + +Execute the script referencing the input CSV file. + +``` +$ ./manifestgen.py --prefix="OUTFILE" --num=4 --csv --input-file=INPUT.csv +``` + +Manifest files are written locally. + +``` +Parsing INPUT.csv... +Generating batch 0, 77437 entries, 8416.58 GB. +Writing manifest to file OUTFILE-000.json +Generating batch 1, 77437 entries, 8402.78 GB. +Writing manifest to file OUTFILE-001.json +Generating batch 2, 77437 entries, 8416.99 GB. +Writing manifest to file OUTFILE-002.json +Generating batch 3, 77435 entries, 8418.45 GB. +Writing manifest to file OUTFILE-003.json +``` + +Work with someone who has S3 write access to upload the generated files to S3. Subsequently, the `COPY` command can be executed pointing to the manifest files. + +### AWS CLI Input + +Executing in the AWS CLI input mode uses the `list-objects` command to list the files and pipe those results to the generator script. Notice the `--bucket` and `--prefix` parameters are specified which would match the location of the data you want to load. The script executor needs to have S3 read access. + +``` +$ aws s3api list-objects --bucket my-large-ingest-data-bkt --prefix my-large-tbl1/ --output=json | ./manifestgen.py --prefix=OUTFILE --num 4 --bucket=my-large-ingest-data-bkt --stdin +``` + +Manifest files are written locally. + +``` +Parsing standard input... +Generating batch 0, 154 entries, 618.65 GB. +Writing manifest to file OUTFILE-000.json +Generating batch 1, 154 entries, 601.95 GB. +Writing manifest to file OUTFILE-001.json +Generating batch 2, 154 entries, 578.85 GB. +Writing manifest to file OUTFILE-002.json +Generating batch 3, 154 entries, 588.11 GB. +Writing manifest to file OUTFILE-003.json +``` + +Work with someone who has S3 write access to upload the generated manifest files to S3. Subsequently the `COPY` command can be executed pointing to the manifest files. + +### Direct S3 access + +Executing in Direct S3 mode, the generator script directly performs an S3 list on a prefix, generates the manifest files locally, and uploads the files to destination S3 location. The script executor requires both S3 read access as well as S3 write access. + +``` +$ ./manifestgen.py --prefix=manifests/my-large-tbl1/BATCH_4 --num 4 --bucket=my-large-ingest-data-bkt --input-prefix=my-large-tbl1/ --s3-list --upload-bucket=my-large-ingest-data-bkt +``` + +Manifest files are written locally and subsequently uploaded to S3. + +``` +Generating manifest from listing objects in s3://my-large-ingest-data-bkt/my-large-tbl1/ +Generating batch 0, 192 entries, 750.44 GB. +Uploading s3://my-large-ingest-data-bkt/manifests/my-large-tbl1/BATCH_4-000.json +Generating batch 1, 192 entries, 750.29 GB. +Uploading s3://my-large-ingest-data-bkt/manifests/my-large-tbl1/BATCH_4-001.json +Generating batch 2, 192 entries, 761.92 GB. +Uploading s3://my-large-ingest-data-bkt/manifests/my-large-tbl1/BATCH_4-002.json +Generating batch 3, 192 entries, 733.61 GB. +Uploading s3://my-large-ingest-data-bkt/manifests/my-large-tbl1/BATCH_4-003.json +``` + +To review the S3 location for the uploaded manifest files + +``` +$ aws s3 ls s3://my-large-ingest-data-bkt/manifests/my-large-tbl1/ +2024-07-20 23:27:40 34386 BATCH_4-000.json +2024-07-20 23:27:41 34385 BATCH_4-001.json +2024-07-20 23:27:41 34386 BATCH_4-002.json +2024-07-20 23:27:41 34387 BATCH_4-003.json +``` + +Used the the `COPY` command to load the target table. + +For more usage help, run `./manifest -h` + +## Requirements + +This utility requires Python 3.12 and `boto3` to be already installed on your terminal. + +## Working Details and Limitations + +This utility does not determine the optimal number of split batches, you need to provide the input `num` and the utility will provide those many manifest files. + +For loading large data sets you can benchmark with the single `COPY` command, and use this utility to experiment with 2/4/8/n batches. Compare the total time and determine the right number of batches that meet your performance needs. + +# License + +Amazon Redshift Utils - Manifest Generator + +Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + +This project is licensed under the Apache-2.0 License. diff --git a/src/ManifestGenerator/manifestgen.py b/src/ManifestGenerator/manifestgen.py new file mode 100644 index 00000000..65f8924e --- /dev/null +++ b/src/ManifestGenerator/manifestgen.py @@ -0,0 +1,162 @@ +#!/usr/bin/env python3 + +import argparse +import csv +import io +import json +import dataclasses +import sys +import typing +import random +import boto3 + + +@dataclasses.dataclass +class Entry: + s3_url: str + size: int + + def to_json_dict(self) -> dict: + """Returns a representation of the entry suitable as an entry in the Redshift Manifest JSON representation.""" + return dict( + url=self.s3_url, + mandatory=True, + meta=dict(content_length=self.size) + ) + + +def parse_input_csv(file_obj: io.FileIO, bucket: typing.Optional[str]) -> typing.Iterator[Entry]: + """Returns the CSV parsed into an iterator of entries.""" + if bucket is not None: + raise ValueError('Bucket cannot be specified for CSV input') + reader = csv.reader(file_obj, dialect='excel') + # Ignore header row. + next(reader) + for row in reader: + url = row[0] + size = int(row[1]) + if size > 0: + yield Entry(url, size) + + +def parse_s3_list_response(bucket: str, response: dict) -> typing.Iterator[Entry]: + """Parses the S3 list objects response into an iterator of entries.""" + for summary in response['Contents']: + obj_key = summary['Key'] + yield Entry(f's3://{bucket}/{obj_key}', summary['Size']) + + +def parse_input_json(file_obj: io.FileIO, bucket: typing.Optional[str]) -> typing.Iterator[Entry]: + """Parses the JSON from `aws s3api list-objects --output=json` into an iterator of entries.""" + if bucket is None: + raise ValueError('Bucket must be specified for AWS CLI list-object JSON') + list_json = json.load(file_obj) + yield from parse_s3_list_response(bucket, list_json) + + +def s3_list_entries(client: boto3.client, bucket: str, prefix: str) -> typing.Iterator[Entry]: + paginator = client.get_paginator('list_objects_v2') + for page in paginator.paginate(Bucket=bucket, Prefix=prefix): + yield from parse_s3_list_response(bucket, page) + + +def generate_manifest(entries: typing.Iterable[Entry]) -> dict: + """Generates the Redshift manifest dictionary from the given iterable of entries.""" + entries = list(entry.to_json_dict() for entry in entries) + return dict(entries=entries) + + +def iter_batch(entries: typing.List[Entry], num_batches: int) -> typing.Iterator[typing.List[Entry]]: + """Generates each batch from the list of entries, evenly divided.""" + base_size, remainder = divmod(len(entries), num_batches) + consumed_count = 0 + for curr_batch in range(num_batches): + batch_size = base_size + if curr_batch < remainder: + # spread out the remainder on the first N batches + batch_size += 1 + curr_start = consumed_count + curr_end = consumed_count + batch_size + yield entries[curr_start:curr_end] + consumed_count += batch_size + assert consumed_count == len(entries) + +def main(): + parser = argparse.ArgumentParser( + prog='manifest.py', + description='Generates N Redshift COPY manifests from input.' + ) + # Either source the input from local file or directly from S3 list + group = parser.add_mutually_exclusive_group(required=True) + group.add_argument('--input-file', dest='input_file_name', metavar='FILENAME', type=str, default=None, + help='Input file name, a CSV file with S3 URL and file size or a JSON output from the AWS CLI ' + + 'list-objects.') + group.add_argument('--stdin', dest='use_stdin', action='store_const', default=False, const=True, + help='Read input from stdin instead of reading from file.') + group.add_argument('--s3-list', dest='do_s3_list', action='store_const', const=True, default=False, + help='Use S3 list-objects to source the manifest. Implies --json.') + + parser.add_argument('--input-prefix', dest='input_prefix', metavar='PREFIX', type=str, default=None, + help='The input prefix for --s3-list. Only applicable for this mode.') + parser.add_argument('--prefix', type=str, required=True, + help='Output file prefix') + parser.add_argument('--num', metavar='N', type=int, required=True, + help='Number of manifests to generate.') + parser.add_argument('--bucket', type=str, default=None, + help='S3 bucket name, required if the input is S3 list-objects JSON ' + + 'or if --s3-list is used.') + parser.add_argument('--csv', dest='parse_func', action='store_const', + const=parse_input_csv, default=parse_input_json, + help='Parse a CSV file into the entries for the manifest.') + parser.add_argument('--upload-bucket', type=str, default=None, + help='S3 bucket to upload the resulting manifests to, uses --prefix as the prefix to write to.') + parser.add_argument('--no-shuffle', dest='do_shuffle', action='store_const', default=True, const=False, + help='Does not shuffle the input entries before generating the manifests.') + + args = parser.parse_args() + + s3 = boto3.client('s3') + if args.do_s3_list: + if args.bucket is None: + raise ValueError('Bucket must be specified with --s3-list') + if args.input_prefix is None: + raise ValueError('Input prefix must be specified with --s3-list') + print(f'Generating manifest from listing objects in s3://{args.bucket}/{args.input_prefix}', file=sys.stderr) + entries = list(s3_list_entries(s3, args.bucket, args.input_prefix)) + else: + if args.input_prefix is not None: + raise ValueError('Input prefix must not be specified in file input mode') + if args.use_stdin: + print(f'Parsing standard input...', file=sys.stderr) + in_file = sys.stdin + else: + print(f'Parsing {args.input_file_name}...', file=sys.stderr) + in_file = open(args.input_file_name, 'r') + with in_file: + # Parse out the relevant files to generate manifests from. + entries = list(args.parse_func(in_file, args.bucket)) + if args.do_shuffle: + # Randomize the input. + random.shuffle(entries) + count = len(entries) + if count < args.num: + raise ValueError('Number of manifests to generate is less than the total number of entries') + + for i, batch in enumerate(iter_batch(entries, args.num)): + batch_gb = sum(x.size for x in batch) / 1024.0 / 1024.0 / 1024.0 + print(f'Generating batch {i}, {len(batch)} entries, {batch_gb:.2f} GB.', file=sys.stderr) + manifest = generate_manifest(batch) + manifest_text = json.dumps(manifest, indent=2) + out_name = f'{args.prefix}-{i:03d}.json' + if args.upload_bucket is not None: + print(f'Uploading s3://{args.upload_bucket}/{out_name}', file=sys.stderr) + s3.put_object(Bucket=args.upload_bucket, Key=out_name, ContentType='application/json', Body=manifest_text) + pass + else: + print(f'Writing manifest to file {out_name}', file=sys.stderr) + with open(out_name, 'w') as f: + f.write(manifest_text) + + +if __name__ == '__main__': + main() diff --git a/src/ManifestGenerator/requirements.txt b/src/ManifestGenerator/requirements.txt new file mode 100644 index 00000000..fd684c29 --- /dev/null +++ b/src/ManifestGenerator/requirements.txt @@ -0,0 +1,7 @@ +boto3==1.34.145 +botocore==1.34.145 +jmespath==1.0.1 +python-dateutil==2.9.0.post0 +s3transfer==0.10.2 +six==1.16.0 +urllib3==2.2.2 From 3bf5bb0b0ca182224f608ead31d229613bf38242 Mon Sep 17 00:00:00 2001 From: Dominik Horn Date: Sat, 16 Nov 2024 00:05:31 +0100 Subject: [PATCH 31/49] Add AI-driven scaling and optimization notebooks (#723) Related Announcement: https://aws.amazon.com/about-aws/whats-new/2024/10/amazon-redshift-serverless-ai-driven-scaling-optimization/ authored-by: Dominik Horn --- src/AiDrivenScalingAndOptimization/README.md | 30 +++++++++++++++++++ .../resize_notebook.ipynb | 1 + .../scaling_notebook.ipynb | 1 + 3 files changed, 32 insertions(+) create mode 100644 src/AiDrivenScalingAndOptimization/README.md create mode 100644 src/AiDrivenScalingAndOptimization/resize_notebook.ipynb create mode 100644 src/AiDrivenScalingAndOptimization/scaling_notebook.ipynb diff --git a/src/AiDrivenScalingAndOptimization/README.md b/src/AiDrivenScalingAndOptimization/README.md new file mode 100644 index 00000000..bc891f0e --- /dev/null +++ b/src/AiDrivenScalingAndOptimization/README.md @@ -0,0 +1,30 @@ +# Instructions on how to use the demo notebooks for Amazon Redshift Serverless AI-driven scaling and optimization + +In the repository you will find two demo notebooks demonstrating two key behaviors of the Serverless AI-driven scaling and optimization algorithms. +* Scaling Notebook: In this notebook we demonstrate how the AI algorithms infer various attributes about a SQL query and scale the compute when a same/similar long query is encountered again on the cluster, resulting into a significant performance improvement. +* Resizing Notebook: In this notebook we demonstrate how the AI algorithms infer various attributes about the workload running on the Redshift cluster and scales the cluster size up/down depending on the workload and the price-performance target chosen by the cluster via the performance slider. + +## Scaling Notebook +In this notebook we demonstrate how the AI algorithms infer various attributes about a SQL query and scale the compute when a same/similar long query is encountered again on the cluster, resulting into a significant performance improvement. + +Steps to follow: +* Step 1: Create a new Redshift Serverless cluster from the AWS console. +* Step 2: Choose the performance slider setting as 100 from the console. This setting optimizes for performance. +* Step 3: Upload the notebook in Redshift Query Editor V2. +* Step 4: Open the notebook and connect it to the cluster you just created in Step 1. +* Step 5: Create a new database or connect to an existing database of your choice. +* Step 6: Run the cells in the notebook. The cells will create the necessary tables, load them with data, and run a heavy/long query on the cluster which will take a very long time to finish execution (1.5 to 2.5 hours). It will then calculate the cost of running the query. +* Step 7: The next set of cells will run the same query again with result_cache disabled. This time Amazon Redshift Serverless AI-driven scaling and optimization will scale the query resulting it in a much shorter execution time (0.5 to 1 hour). The last cell will then again calculate the cost of running the query and you the difference in time taken and compute utilized can be clearly observed. + +## Resizing Notebook +In this notebook we demonstrate how the AI algorithms infer various attributes about the workload running on the Redshift cluster and scales the cluster size up/down depending on the workload and the price-performance target chosen by the cluster via the performance slider. + +Steps to follow: +* Step 1: Create a new Redshift Serverless cluster from the AWS console. +* Step 2: Choose the performance slider setting as 1 from the console. This setting optimizes for cost. Note that you will start with the default 128RPUs. +* Step 3: Upload the notebook in Redshift Query Editor V2. +* Step 4: Open the notebook and connect it to the cluster you just created in Step 1. +* Step 5: Create a new database or connect to an existing database of your choice. +* Step 6: Run the cells in the notebook. The first few cells will simply create the necessary tables and load them with data. +* Step 7: To mimic a long multi-hour workload we have provided a procedure which creates a workload that runs 5000 queries every hour. You can use the "Schedule Query" feature in the Redshift Query Editor to schedule this query for next 1 day at an hourly frequency. This feature is available if you paste this query independently into a new query editor window (not a new notebook). You should see a "Schedule" button on top right to configure/schedule this query. +* Step 8: Once successfully scheduled, you can return to the notebook the next day and just run the last cell which shows the compute capacity utilized by cluster over time. You should notice a decline in the compute capacity over time. More specifically, you should see that cluster starts from 128 RPUs which is the default. Over time the AI-based scaling and optimization will learn from the workload and perform necessary optimizations to favor "cost" as we have our slider set to "Optimizes for cost" resulting in the compute capacity to go down to a 64RPUs to 32RPUs. diff --git a/src/AiDrivenScalingAndOptimization/resize_notebook.ipynb b/src/AiDrivenScalingAndOptimization/resize_notebook.ipynb new file mode 100644 index 00000000..ca57b6bb --- /dev/null +++ b/src/AiDrivenScalingAndOptimization/resize_notebook.ipynb @@ -0,0 +1 @@ +{"metadata":{"title":"resize_notebook","kernelspec":{"display_name":"Redshift","language":"postgresql","name":"Redshift"},"language_info":{"file_extension":".sql","name":"Redshift"},"version":1},"nbformat":4,"nbformat_minor":0,"cells":[{"metadata":{"displayMode":"maximized","width":12,"isLimitOn":true},"source":["-- Set the performance slider to Level 1 (Cost effective)\n","\n","-- Connect to any database of your choice"],"cell_type":"code","execution_count":0,"outputs":[]},{"metadata":{"displayMode":"maximized","width":12,"isLimitOn":true},"source":["-- Create the necessary tables: https://github.com/awslabs/amazon-redshift-utils/blob/master/src/CloudDataWarehouseBenchmark/Cloud-DWB-Derived-from-TPCH/10GB/ddl.sql\n","\n","create table lineitem (\n"," l_orderkey int8 not null ,\n"," l_partkey int8 not null,\n"," l_suppkey int4 not null,\n"," l_linenumber int4 not null,\n"," l_quantity numeric(12,2) not null,\n"," l_extendedprice numeric(12,2) not null,\n"," l_discount numeric(12,2) not null,\n"," l_tax numeric(12,2) not null,\n"," l_returnflag char(1) not null,\n"," l_linestatus char(1) not null,\n"," l_shipdate date not null ,\n"," l_commitdate date not null,\n"," l_receiptdate date not null,\n"," l_shipinstruct char(25) not null,\n"," l_shipmode char(10) not null,\n"," l_comment varchar(44) not null,\n"," Primary Key(L_ORDERKEY, L_LINENUMBER)\n",") distkey(l_orderkey) sortkey(l_shipdate,l_orderkey) ;\n","\n","create table part (\n"," p_partkey int8 not null ,\n"," p_name varchar(55) not null,\n"," p_mfgr char(25) not null,\n"," p_brand char(10) not null,\n"," p_type varchar(25) not null,\n"," p_size int4 not null,\n"," p_container char(10) not null,\n"," p_retailprice numeric(12,2) not null,\n"," p_comment varchar(23) not null,\n"," PRIMARY KEY (P_PARTKEY)\n",") distkey(p_partkey) sortkey(p_partkey);"],"cell_type":"code","execution_count":0,"outputs":[]},{"metadata":{"displayMode":"maximized","width":12,"isLimitOn":true},"source":["-- Load data into the tables\n","\n","copy lineitem from 's3://redshift-downloads/TPC-H/2.18/10GB/lineitem.tbl' iam_role default delimiter '|' region 'us-east-1';\n","copy part from 's3://redshift-downloads/TPC-H/2.18/10GB/part.tbl' iam_role default delimiter '|' region 'us-east-1';"],"cell_type":"code","execution_count":0,"outputs":[]},{"metadata":{"displayMode":"maximized","width":12,"isLimitOn":true},"source":["-- Verify if the tables are loaded correctly\n","\n","select count(*) from lineitem; -- 59986052\n","select count(*) from part; -- 2000000"],"cell_type":"code","execution_count":0,"outputs":[]},{"metadata":{"displayMode":"maximized","width":12,"isLimitOn":true},"source":["-- Below is a procedure that will mimic a small workload with 2000 queries. We will use this to create a longer workload that spans over 24 hours. In order to do that we will use the \"Schedule Queries\" feature of the Redshift Query Editor.\n","-- Please schedule this query below to run at a frequency of 1 hour for next 24 hours. See README for more details.\n","\n","CREATE OR REPLACE PROCEDURE loop_example_hourly()\n","LANGUAGE plpgsql\n","AS $$\n","DECLARE\n"," hour_count INT;\n"," i INT;\n"," promo_revenue NUMERIC;\n","BEGIN\n"," FOR i IN 1..5000 LOOP\n"," EXECUTE '\n"," SELECT /* TPC-H Q14 */ 100.00 * SUM(CASE\n"," WHEN p_type LIKE ''PROMO%''\n"," THEN l_extendedprice * (1 - l_discount)\n"," ELSE 0\n"," END) / NULLIF(SUM(l_extendedprice * (1 - l_discount)), 0) AS promo_revenue\n"," FROM lineitem, part\n"," WHERE l_partkey = p_partkey\n"," AND l_shipdate >= DATE ''1995-09-01''\n"," AND l_shipdate < DATEADD(month, 1, CAST(''1995-09-01'' AS DATE));'\n"," INTO promo_revenue;\n","\n"," RAISE NOTICE 'Iteration: %, Promo Revenue: %', i, promo_revenue;\n"," END LOOP;\n","END;\n","$$;\n","\n","-- Disable the result cache\n","SET enable_result_cache_for_session TO off;\n","\n","-- Run the workload\n","CALL loop_example_hourly();"],"cell_type":"code","execution_count":0,"outputs":[]},{"metadata":{"displayMode":"maximized","width":12,"isLimitOn":true},"source":["-- Lets run the following query to observe how the compute_capacity decreases over time. It should start from 128 RPUs which is the default we started with. Over time the AI-based scaling and \n","-- optimization will learn from the workload and perform necessary optimizations to favor \"cost\" as we have our slider position set to \"Optimizes for cost\", i.e., to the lowest setting of 1. \n","\n","select * from sys_serverless_usage\n","where start_time >= (select start_time from sys_query_history where query_text like '%TPC-H Q14%' order by start_time limit 1)\n","and end_time <= DATEADD(minute,1,(select end_time from sys_query_history where query_text like '%TPC-H Q14%' and end_time is not NULL order by end_time desc limit 1))\n","order by end_time asc;"],"cell_type":"code","execution_count":0,"outputs":[]}]} \ No newline at end of file diff --git a/src/AiDrivenScalingAndOptimization/scaling_notebook.ipynb b/src/AiDrivenScalingAndOptimization/scaling_notebook.ipynb new file mode 100644 index 00000000..dbf15978 --- /dev/null +++ b/src/AiDrivenScalingAndOptimization/scaling_notebook.ipynb @@ -0,0 +1 @@ +{"metadata":{"title":"scaling_notebook_16CN","kernelspec":{"display_name":"Redshift","language":"postgresql","name":"Redshift"},"language_info":{"file_extension":".sql","name":"Redshift"},"version":1},"nbformat":4,"nbformat_minor":0,"cells":[{"metadata":{"displayMode":"maximized","width":12,"isLimitOn":true},"source":["-- Start with a fresh/new cluster for the experiment.\n","\n","-- Set the performance slider to Level 100 (Optimizes for Performance).\n","\n","-- Connect to any database of your choice."],"cell_type":"code","execution_count":0,"outputs":[]},{"metadata":{"displayMode":"maximized","width":12,"isLimitOn":true},"source":["-- Create the necessary tables\n","\n","create table catalog_returns\n","(\n"," cr_returned_date_sk int4 , \n"," cr_returned_time_sk int4 , \n"," cr_item_sk int4 not null , \n"," cr_refunded_customer_sk int4 ,\n"," cr_refunded_cdemo_sk int4 , \n"," cr_refunded_hdemo_sk int4 , \n"," cr_refunded_addr_sk int4 , \n"," cr_returning_customer_sk int4 ,\n"," cr_returning_cdemo_sk int4 , \n"," cr_returning_hdemo_sk int4 , \n"," cr_returning_addr_sk int4 , \n"," cr_call_center_sk int4 , \n"," cr_catalog_page_sk int4 , \n"," cr_ship_mode_sk int4 , \n"," cr_warehouse_sk int4 , \n"," cr_reason_sk int4 , \n"," cr_order_number int8 not null,\n"," cr_return_quantity int4 , \n"," cr_return_amount numeric(7,2) ,\n"," cr_return_tax numeric(7,2) , \n"," cr_return_amt_inc_tax numeric(7,2) ,\n"," cr_fee numeric(7,2) , \n"," cr_return_ship_cost numeric(7,2) , \n"," cr_refunded_cash numeric(7,2) , \n"," cr_reversed_charge numeric(7,2) , \n"," cr_store_credit numeric(7,2) ,\n"," cr_net_loss numeric(7,2) \n"," ,primary key (cr_item_sk, cr_order_number)\n",") distkey(cr_item_sk) sortkey(cr_returned_date_sk);\n","\n","create table catalog_sales\n","(\n"," cs_sold_date_sk int4 , \n"," cs_sold_time_sk int4 , \n"," cs_ship_date_sk int4 , \n"," cs_bill_customer_sk int4 , \n"," cs_bill_cdemo_sk int4 , \n"," cs_bill_hdemo_sk int4 , \n"," cs_bill_addr_sk int4 , \n"," cs_ship_customer_sk int4 , \n"," cs_ship_cdemo_sk int4 , \n"," cs_ship_hdemo_sk int4 , \n"," cs_ship_addr_sk int4 , \n"," cs_call_center_sk int4 , \n"," cs_catalog_page_sk int4 , \n"," cs_ship_mode_sk int4 , \n"," cs_warehouse_sk int4 , \n"," cs_item_sk int4 not null , \n"," cs_promo_sk int4 , \n"," cs_order_number int8 not null , \n"," cs_quantity int4 , \n"," cs_wholesale_cost numeric(7,2) , \n"," cs_list_price numeric(7,2) , \n"," cs_sales_price numeric(7,2) , \n"," cs_ext_discount_amt numeric(7,2) , \n"," cs_ext_sales_price numeric(7,2) , \n"," cs_ext_wholesale_cost numeric(7,2) , \n"," cs_ext_list_price numeric(7,2) ,\n"," cs_ext_tax numeric(7,2) , \n"," cs_coupon_amt numeric(7,2) , \n"," cs_ext_ship_cost numeric(7,2) , \n"," cs_net_paid numeric(7,2) , \n"," cs_net_paid_inc_tax numeric(7,2) , \n"," cs_net_paid_inc_ship numeric(7,2) , \n"," cs_net_paid_inc_ship_tax numeric(7,2) , \n"," cs_net_profit numeric(7,2) \n"," ,primary key (cs_item_sk, cs_order_number)\n",") distkey(cs_item_sk) sortkey(cs_sold_date_sk);\n","\n","create table date_dim\n","(\n"," d_date_sk integer not null,\n"," d_date_id char(16) not null,\n"," d_date date,\n"," d_month_seq integer ,\n"," d_week_seq integer ,\n"," d_quarter_seq integer ,\n"," d_year integer ,\n"," d_dow integer ,\n"," d_moy integer ,\n"," d_dom integer ,\n"," d_qoy integer ,\n"," d_fy_year integer ,\n"," d_fy_quarter_seq integer ,\n"," d_fy_week_seq integer ,\n"," d_day_name char(9) ,\n"," d_quarter_name char(6) ,\n"," d_holiday char(1) ,\n"," d_weekend char(1) ,\n"," d_following_holiday char(1) ,\n"," d_first_dom integer ,\n"," d_last_dom integer ,\n"," d_same_day_ly integer ,\n"," d_same_day_lq integer ,\n"," d_current_day char(1) ,\n"," d_current_week char(1) ,\n"," d_current_month char(1) ,\n"," d_current_quarter char(1) ,\n"," d_current_year char(1) ,\n"," primary key (d_date_sk)\n",") diststyle all;\n","\n","create table store_returns\n","(\n","sr_returned_date_sk int4 , \n"," sr_return_time_sk int4 , \n"," sr_item_sk int4 not null , \n"," sr_customer_sk int4 , \n"," sr_cdemo_sk int4 , \n"," sr_hdemo_sk int4 , \n"," sr_addr_sk int4 , \n"," sr_store_sk int4 , \n"," sr_reason_sk int4 , \n"," sr_ticket_number int8 not null, \n"," sr_return_quantity int4 , \n"," sr_return_amt numeric(7,2) ,\n"," sr_return_tax numeric(7,2) ,\n"," sr_return_amt_inc_tax numeric(7,2) , \n"," sr_fee numeric(7,2) , \n"," sr_return_ship_cost numeric(7,2) , \n"," sr_refunded_cash numeric(7,2) , \n"," sr_reversed_charge numeric(7,2) , \n"," sr_store_credit numeric(7,2) , \n"," sr_net_loss numeric(7,2) \n"," ,primary key (sr_item_sk, sr_ticket_number)\n",") distkey(sr_item_sk) sortkey(sr_returned_date_sk);\n","\n","\n","create table store_sales\n","(\n","ss_sold_date_sk int4 , \n"," ss_sold_time_sk int4 , \n"," ss_item_sk int4 not null , \n"," ss_customer_sk int4 , \n"," ss_cdemo_sk int4 , \n"," ss_hdemo_sk int4 , \n"," ss_addr_sk int4 , \n"," ss_store_sk int4 , \n"," ss_promo_sk int4 , \n"," ss_ticket_number int8 not null, \n"," ss_quantity int4 , \n"," ss_wholesale_cost numeric(7,2) , \n"," ss_list_price numeric(7,2) , \n"," ss_sales_price numeric(7,2) ,\n"," ss_ext_discount_amt numeric(7,2) , \n"," ss_ext_sales_price numeric(7,2) , \n"," ss_ext_wholesale_cost numeric(7,2) , \n"," ss_ext_list_price numeric(7,2) , \n"," ss_ext_tax numeric(7,2) , \n"," ss_coupon_amt numeric(7,2) , \n"," ss_net_paid numeric(7,2) , \n"," ss_net_paid_inc_tax numeric(7,2) , \n"," ss_net_profit numeric(7,2) \n"," ,primary key (ss_item_sk, ss_ticket_number)\n",") distkey(ss_item_sk) sortkey(ss_sold_date_sk);\n","\n","create table web_returns\n","(\n","wr_returned_date_sk int4 , \n"," wr_returned_time_sk int4 , \n"," wr_item_sk int4 not null , \n"," wr_refunded_customer_sk int4 ,\n"," wr_refunded_cdemo_sk int4 , \n"," wr_refunded_hdemo_sk int4 , \n"," wr_refunded_addr_sk int4 , \n"," wr_returning_customer_sk int4 ,\n"," wr_returning_cdemo_sk int4 , \n"," wr_returning_hdemo_sk int4 , \n"," wr_returning_addr_sk int4 , \n"," wr_web_page_sk int4 , \n"," wr_reason_sk int4 , \n"," wr_order_number int8 not null,\n"," wr_return_quantity int4 , \n"," wr_return_amt numeric(7,2) , \n"," wr_return_tax numeric(7,2) , \n"," wr_return_amt_inc_tax numeric(7,2) ,\n"," wr_fee numeric(7,2) , \n"," wr_return_ship_cost numeric(7,2) ,\n"," wr_refunded_cash numeric(7,2) , \n"," wr_reversed_charge numeric(7,2) , \n"," wr_account_credit numeric(7,2) , \n"," wr_net_loss numeric(7,2) \n"," ,primary key (wr_item_sk, wr_order_number)\n",") distkey(wr_order_number) sortkey(wr_returned_date_sk);\n","\n","\n","create table web_sales\n","(\n"," ws_sold_date_sk int4 , \n"," ws_sold_time_sk int4 , \n"," ws_ship_date_sk int4 , \n"," ws_item_sk int4 not null , \n"," ws_bill_customer_sk int4 , \n"," ws_bill_cdemo_sk int4 , \n"," ws_bill_hdemo_sk int4 , \n"," ws_bill_addr_sk int4 , \n"," ws_ship_customer_sk int4 , \n"," ws_ship_cdemo_sk int4 , \n"," ws_ship_hdemo_sk int4 , \n"," ws_ship_addr_sk int4 , \n"," ws_web_page_sk int4 , \n"," ws_web_site_sk int4 , \n"," ws_ship_mode_sk int4 , \n"," ws_warehouse_sk int4 , \n"," ws_promo_sk int4 , \n"," ws_order_number int8 not null,\n"," ws_quantity int4 , \n"," ws_wholesale_cost numeric(7,2) , \n"," ws_list_price numeric(7,2) , \n"," ws_sales_price numeric(7,2) , \n"," ws_ext_discount_amt numeric(7,2) , \n"," ws_ext_sales_price numeric(7,2) ,\n"," ws_ext_wholesale_cost numeric(7,2) , \n"," ws_ext_list_price numeric(7,2) , \n"," ws_ext_tax numeric(7,2) , \n"," ws_coupon_amt numeric(7,2) , \n"," ws_ext_ship_cost numeric(7,2) , \n"," ws_net_paid numeric(7,2) , \n"," ws_net_paid_inc_tax numeric(7,2) , \n"," ws_net_paid_inc_ship numeric(7,2) , \n"," ws_net_paid_inc_ship_tax numeric(7,2) , \n"," ws_net_profit numeric(7,2) \n"," ,primary key (ws_item_sk, ws_order_number)\n",") distkey(ws_order_number) sortkey(ws_sold_date_sk);"],"cell_type":"code","execution_count":0,"outputs":[]},{"metadata":{"displayMode":"maximized","width":12,"isLimitOn":true},"source":["-- Check if you have all the tables you needed\n","SELECT table_schema, table_name\n","FROM information_schema.tables\n","WHERE table_type = 'BASE TABLE'\n","AND table_schema = 'public'\n","ORDER BY table_schema, table_name;"],"cell_type":"code","execution_count":0,"outputs":[]},{"metadata":{"displayMode":"maximized","width":12,"isLimitOn":true},"source":["-- Load the data into all the tables\n","copy catalog_returns from 's3://redshift-downloads/TPC-DS/2.13/3TB/catalog_returns/' iam_role default delimiter '|' region 'us-east-1' gzip;\n","copy catalog_sales from 's3://redshift-downloads/TPC-DS/2.13/3TB/catalog_sales/' iam_role default delimiter '|' region 'us-east-1' gzip;\n","copy date_dim from 's3://redshift-downloads/TPC-DS/2.13/3TB/date_dim/' iam_role default delimiter '|' region 'us-east-1' gzip;\n","copy store_returns from 's3://redshift-downloads/TPC-DS/2.13/3TB/store_returns/' iam_role default delimiter '|' region 'us-east-1' gzip;\n","copy store_sales from 's3://redshift-downloads/TPC-DS/2.13/3TB/store_sales/' iam_role default delimiter '|' region 'us-east-1' gzip;\n","copy web_returns from 's3://redshift-downloads/TPC-DS/2.13/3TB/web_returns/' iam_role default delimiter '|' region 'us-east-1' gzip;\n","copy web_sales from 's3://redshift-downloads/TPC-DS/2.13/3TB/web_sales/' iam_role default delimiter '|' region 'us-east-1' gzip;"],"cell_type":"code","execution_count":0,"outputs":[]},{"metadata":{"displayMode":"maximized","width":12,"isLimitOn":true},"source":["-- Ensure all the tables got loaded correctly\n","select count(*) from catalog_returns; -- 432018033\n","select count(*) from catalog_sales; -- 4320078880\n","select count(*) from date_dim; -- 73049\n","select count(*) from store_returns; -- 863989652\n","select count(*) from store_sales; -- 8639936081\n","select count(*) from web_returns; -- 216003761\n","select count(*) from web_sales; -- 2159968881"],"cell_type":"code","execution_count":0,"outputs":[]},{"metadata":{"displayMode":"maximized","width":12,"isLimitOn":true},"source":["-- Disable the result cache\n","SET enable_result_cache_for_session TO off;"],"cell_type":"code","execution_count":0,"outputs":[]},{"metadata":{"displayMode":"maximized","width":12,"isLimitOn":true},"source":["/*\n","RUN 1: This is the run where Redshift Serverless AI-driven scaling will learn about the behavior of this query.\n","\n","The following query analyzes product sales across multiple channels such as websites, wholesale, and retail stores. \n","This complex query typically takes more than 3600 seconds to run with the default 128 RPUs at L100.\n","*/\n","\n","WITH /* TPC-DS Demo Query */\n"," ws AS (\n"," SELECT\n"," d_year AS ws_sold_year,\n"," ws_item_sk,\n"," ws_bill_customer_sk AS ws_customer_sk,\n"," SUM(ws_quantity) AS ws_qty,\n"," SUM(ws_wholesale_cost) AS ws_wc,\n"," SUM(ws_sales_price) AS ws_sp,\n"," AVG(ws_sales_price) AS ws_avg_sp,\n"," COUNT(ws_order_number) AS ws_order_count\n"," FROM\n"," web_sales\n"," LEFT JOIN web_returns ON wr_order_number = ws_order_number AND ws_item_sk = wr_item_sk\n"," JOIN date_dim ON ws_sold_date_sk = d_date_sk\n"," WHERE\n"," wr_order_number IS NULL\n"," GROUP BY\n"," d_year, ws_item_sk, ws_bill_customer_sk\n","),\n","cs AS (\n"," SELECT\n"," d_year AS cs_sold_year,\n"," cs_item_sk,\n"," cs_bill_customer_sk AS cs_customer_sk,\n"," SUM(cs_quantity) AS cs_qty,\n"," SUM(cs_wholesale_cost) AS cs_wc,\n"," SUM(cs_sales_price) AS cs_sp,\n"," AVG(cs_sales_price) AS cs_avg_sp,\n"," COUNT(cs_order_number) AS cs_order_count\n"," FROM\n"," catalog_sales\n"," LEFT JOIN catalog_returns ON cr_order_number = cs_order_number AND cs_item_sk = cr_item_sk\n"," JOIN date_dim ON cs_sold_date_sk = d_date_sk\n"," WHERE\n"," cr_order_number IS NULL\n"," GROUP BY\n"," d_year, cs_item_sk, cs_bill_customer_sk\n","),\n","ss AS (\n"," SELECT\n"," d_year AS ss_sold_year,\n"," ss_item_sk,\n"," ss_customer_sk,\n"," SUM(ss_quantity) AS ss_qty,\n"," SUM(ss_wholesale_cost) AS ss_wc,\n"," SUM(ss_sales_price) AS ss_sp,\n"," AVG(ss_sales_price) AS ss_avg_sp,\n"," COUNT(ss_ticket_number) AS ss_order_count\n"," FROM\n"," store_sales\n"," LEFT JOIN store_returns ON sr_ticket_number = ss_ticket_number AND ss_item_sk = sr_item_sk\n"," JOIN date_dim ON ss_sold_date_sk = d_date_sk\n"," WHERE\n"," sr_ticket_number IS NULL\n"," GROUP BY\n"," d_year, ss_item_sk, ss_customer_sk\n","),\n","customer_agg AS (\n"," SELECT\n"," COALESCE(ws.ws_customer_sk, cs.cs_customer_sk, ss.ss_customer_sk) AS customer_sk,\n"," COALESCE(SUM(ws.ws_qty), 0) AS total_ws_qty,\n"," COALESCE(SUM(cs.cs_qty), 0) AS total_cs_qty,\n"," COALESCE(SUM(ss.ss_qty), 0) AS total_ss_qty\n"," FROM\n"," ws\n"," FULL JOIN cs ON ws.ws_customer_sk = cs.cs_customer_sk\n"," FULL JOIN ss ON ws.ws_customer_sk = ss.ss_customer_sk\n"," GROUP BY\n"," COALESCE(ws.ws_customer_sk, cs.cs_customer_sk, ss.ss_customer_sk)\n","),\n","date_agg AS (\n"," SELECT\n"," d_year,\n"," d_quarter_name,\n"," COUNT(DISTINCT d_date_sk) AS days_in_year\n"," FROM\n"," date_dim\n"," GROUP BY\n"," d_year, d_quarter_name\n","),\n","avg_week_seq AS (\n"," SELECT\n"," d_year,\n"," AVG(d_week_seq) AS avg_week_seq_per_year\n"," FROM\n"," date_dim\n"," GROUP BY\n"," d_year\n","),\n","complex_aggregation AS (\n"," SELECT \n","\t\tss.ss_customer_sk,\n","\t\tROUND(ss.ss_qty / NULLIF(ws.ws_qty + cs.cs_qty, 0), 2) AS qty_ratio,\n","\t\tss.ss_qty AS store_qty,\n","\t\tss.ss_wc AS store_wholesale_cost,\n","\t\tss.ss_sp AS store_sales_price,\n","\n","\t\tCOALESCE(ws.ws_qty, 0) + COALESCE(cs.cs_qty, 0) AS other_chan_qty,\n","\t\tCOALESCE(ws.ws_wc, 0) + COALESCE(cs.cs_wc, 0) AS other_chan_wholesale_cost,\n","\t\tCOALESCE(ws.ws_sp, 0) + COALESCE(cs.cs_sp, 0) AS other_chan_sales_price,\n","\n","\t\tcustomer_agg.total_ws_qty,\n","\t\tcustomer_agg.total_cs_qty,\n","\t\tcustomer_agg.total_ss_qty,\n","\n","\t\tavg_week_seq.avg_week_seq_per_year,\n","\n","\t\tRANK() OVER (PARTITION BY ss.ss_customer_sk ORDER BY ss.ss_qty DESC) AS ss_rank,\n","\n","\t\tSUM(ss.ss_qty) OVER (PARTITION BY ss.ss_customer_sk ORDER BY ss.ss_qty DESC ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS running_qty_total,\n","\n","\t\tAVG(ss.ss_wc) OVER (PARTITION BY ss.ss_customer_sk ORDER BY ss.ss_wc DESC ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS running_avg_wc,\n","\n","\t\tCOUNT(ss.ss_customer_sk) OVER () AS total_customers,\n","\n","\t\tCASE \n","\t\t\tWHEN ss.ss_qty > 100 THEN 'High'\n","\t\t\tWHEN ss.ss_qty BETWEEN 50 AND 100 THEN 'Medium'\n","\t\t\tELSE 'Low'\n","\t\t END AS qty_category\n","\n","\tFROM \n","\t ss \n","\t LEFT JOIN ws ON ws.ws_sold_year = ss.ss_sold_year AND ws.ws_item_sk = ss.ss_item_sk AND ws.ws_customer_sk = ss.ss_customer_sk \n","\t LEFT JOIN cs ON cs.cs_sold_year = ss.ss_sold_year AND cs.cs_item_sk = ss.ss_item_sk AND cs.cs_customer_sk = ss.ss_customer_sk \n","\t LEFT JOIN customer_agg ON customer_agg.customer_sk = ss.ss_customer_sk \n","\t LEFT JOIN date_agg ON date_agg.d_year = ss.ss_sold_year \n","\t LEFT JOIN avg_week_seq ON avg_week_seq.d_year = ss.ss_sold_year \n","\n","\tWHERE \n","\t COALESCE(ws.ws_qty, 0) > 0 \n","\t AND COALESCE(cs.cs_qty, 0) > 0 \n","),\n","ranked_data AS (\n","\tSELECT \n","\t *,\n","\t ROW_NUMBER() OVER (PARTITION BY ss_customer_sk ORDER BY store_qty DESC, store_wholesale_cost DESC) AS qty_rank \n","\tFROM \n","\t complex_aggregation \n",")\n","\n","SELECT \n","\tranked_data.ss_customer_sk, \n","\tranked_data.qty_ratio, \n","\tranked_data.store_qty, \n","\tranked_data.store_wholesale_cost, \n","\tranked_data.store_sales_price, \n","\tranked_data.other_chan_qty, \n","\tranked_data.other_chan_wholesale_cost, \n","\tranked_data.other_chan_sales_price, \n","\tranked_data.total_ws_qty, \n","\tranked_data.total_cs_qty, \n","\tranked_data.total_ss_qty, \n","\tranked_data.avg_week_seq_per_year, \n","\tranked_data.ss_rank, \n","\tranked_data.running_qty_total, \n","\tranked_data.running_avg_wc, \n","\tranked_data.total_customers, \n","\tranked_data.qty_category, \n","\tranked_data.qty_rank \n","\n","FROM ranked_data \n","\n","WHERE ranked_data.qty_rank = 1 \n","\n","ORDER BY ranked_data.ss_customer_sk, store_qty DESC, store_wholesale_cost DESC, store_sales_price DESC, other_chan_qty, other_chan_wholesale_cost, other_chan_sales_price, qty_ratio;"],"cell_type":"code","execution_count":0,"outputs":[]},{"metadata":{"displayMode":"maximized","width":12,"isLimitOn":true},"source":["/*\n","When the query is complete, run the following SQL to capture the start and end times of the query.\n","*/\n","select query_id,query_text,start_time,end_time, elapsed_time/1000000.0 duration_in_seconds\n","from sys_query_history\n","where query_text like '%TPC-DS Demo Query%'\n","and query_text not like '%sys_query_history%'\n","order by start_time desc;"],"cell_type":"code","execution_count":0,"outputs":[]},{"metadata":{"displayMode":"maximized","width":12,"isLimitOn":true},"source":["/*\n","Let’s assess the compute scaled during the preceding start_time and end_time period.\n","*/\n","\n","select * from sys_serverless_usage\n","where start_time >= (select start_time from sys_query_history where query_text like '%TPC-DS Demo Query%' order by start_time limit 1)\n","and end_time <= DATEADD(minute,1,(select end_time from sys_query_history where query_text like '%TPC-DS Demo Query%' and end_time is not NULL order by end_time desc limit 1))\n","order by end_time asc;"],"cell_type":"code","execution_count":0,"outputs":[]},{"metadata":{"displayMode":"maximized","width":12,"isLimitOn":true},"source":["/*\n","RUN 2: Since this query has been seen before, Redshift Serverless AI-based scaling will now make an informed decision for this query to improve its performance.\n","*/\n","\n","WITH /* TPC-DS Demo Query */\n"," ws AS (\n"," SELECT\n"," d_year AS ws_sold_year,\n"," ws_item_sk,\n"," ws_bill_customer_sk AS ws_customer_sk,\n"," SUM(ws_quantity) AS ws_qty,\n"," SUM(ws_wholesale_cost) AS ws_wc,\n"," SUM(ws_sales_price) AS ws_sp,\n"," AVG(ws_sales_price) AS ws_avg_sp,\n"," COUNT(ws_order_number) AS ws_order_count\n"," FROM\n"," web_sales\n"," LEFT JOIN web_returns ON wr_order_number = ws_order_number AND ws_item_sk = wr_item_sk\n"," JOIN date_dim ON ws_sold_date_sk = d_date_sk\n"," WHERE\n"," wr_order_number IS NULL\n"," GROUP BY\n"," d_year, ws_item_sk, ws_bill_customer_sk\n","),\n","cs AS (\n"," SELECT\n"," d_year AS cs_sold_year,\n"," cs_item_sk,\n"," cs_bill_customer_sk AS cs_customer_sk,\n"," SUM(cs_quantity) AS cs_qty,\n"," SUM(cs_wholesale_cost) AS cs_wc,\n"," SUM(cs_sales_price) AS cs_sp,\n"," AVG(cs_sales_price) AS cs_avg_sp,\n"," COUNT(cs_order_number) AS cs_order_count\n"," FROM\n"," catalog_sales\n"," LEFT JOIN catalog_returns ON cr_order_number = cs_order_number AND cs_item_sk = cr_item_sk\n"," JOIN date_dim ON cs_sold_date_sk = d_date_sk\n"," WHERE\n"," cr_order_number IS NULL\n"," GROUP BY\n"," d_year, cs_item_sk, cs_bill_customer_sk\n","),\n","ss AS (\n"," SELECT\n"," d_year AS ss_sold_year,\n"," ss_item_sk,\n"," ss_customer_sk,\n"," SUM(ss_quantity) AS ss_qty,\n"," SUM(ss_wholesale_cost) AS ss_wc,\n"," SUM(ss_sales_price) AS ss_sp,\n"," AVG(ss_sales_price) AS ss_avg_sp,\n"," COUNT(ss_ticket_number) AS ss_order_count\n"," FROM\n"," store_sales\n"," LEFT JOIN store_returns ON sr_ticket_number = ss_ticket_number AND ss_item_sk = sr_item_sk\n"," JOIN date_dim ON ss_sold_date_sk = d_date_sk\n"," WHERE\n"," sr_ticket_number IS NULL\n"," GROUP BY\n"," d_year, ss_item_sk, ss_customer_sk\n","),\n","customer_agg AS (\n"," SELECT\n"," COALESCE(ws.ws_customer_sk, cs.cs_customer_sk, ss.ss_customer_sk) AS customer_sk,\n"," COALESCE(SUM(ws.ws_qty), 0) AS total_ws_qty,\n"," COALESCE(SUM(cs.cs_qty), 0) AS total_cs_qty,\n"," COALESCE(SUM(ss.ss_qty), 0) AS total_ss_qty\n"," FROM\n"," ws\n"," FULL JOIN cs ON ws.ws_customer_sk = cs.cs_customer_sk\n"," FULL JOIN ss ON ws.ws_customer_sk = ss.ss_customer_sk\n"," GROUP BY\n"," COALESCE(ws.ws_customer_sk, cs.cs_customer_sk, ss.ss_customer_sk)\n","),\n","date_agg AS (\n"," SELECT\n"," d_year,\n"," d_quarter_name,\n"," COUNT(DISTINCT d_date_sk) AS days_in_year\n"," FROM\n"," date_dim\n"," GROUP BY\n"," d_year, d_quarter_name\n","),\n","avg_week_seq AS (\n"," SELECT\n"," d_year,\n"," AVG(d_week_seq) AS avg_week_seq_per_year\n"," FROM\n"," date_dim\n"," GROUP BY\n"," d_year\n","),\n","complex_aggregation AS (\n"," SELECT \n","\t\tss.ss_customer_sk,\n","\t\tROUND(ss.ss_qty / NULLIF(ws.ws_qty + cs.cs_qty, 0), 2) AS qty_ratio,\n","\t\tss.ss_qty AS store_qty,\n","\t\tss.ss_wc AS store_wholesale_cost,\n","\t\tss.ss_sp AS store_sales_price,\n","\n","\t\tCOALESCE(ws.ws_qty, 0) + COALESCE(cs.cs_qty, 0) AS other_chan_qty,\n","\t\tCOALESCE(ws.ws_wc, 0) + COALESCE(cs.cs_wc, 0) AS other_chan_wholesale_cost,\n","\t\tCOALESCE(ws.ws_sp, 0) + COALESCE(cs.cs_sp, 0) AS other_chan_sales_price,\n","\n","\t\tcustomer_agg.total_ws_qty,\n","\t\tcustomer_agg.total_cs_qty,\n","\t\tcustomer_agg.total_ss_qty,\n","\n","\t\tavg_week_seq.avg_week_seq_per_year,\n","\n","\t\tRANK() OVER (PARTITION BY ss.ss_customer_sk ORDER BY ss.ss_qty DESC) AS ss_rank,\n","\n","\t\tSUM(ss.ss_qty) OVER (PARTITION BY ss.ss_customer_sk ORDER BY ss.ss_qty DESC ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS running_qty_total,\n","\n","\t\tAVG(ss.ss_wc) OVER (PARTITION BY ss.ss_customer_sk ORDER BY ss.ss_wc DESC ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS running_avg_wc,\n","\n","\t\tCOUNT(ss.ss_customer_sk) OVER () AS total_customers,\n","\n","\t\tCASE \n","\t\t\tWHEN ss.ss_qty > 100 THEN 'High'\n","\t\t\tWHEN ss.ss_qty BETWEEN 50 AND 100 THEN 'Medium'\n","\t\t\tELSE 'Low'\n","\t\t END AS qty_category\n","\n","\tFROM \n","\t ss \n","\t LEFT JOIN ws ON ws.ws_sold_year = ss.ss_sold_year AND ws.ws_item_sk = ss.ss_item_sk AND ws.ws_customer_sk = ss.ss_customer_sk \n","\t LEFT JOIN cs ON cs.cs_sold_year = ss.ss_sold_year AND cs.cs_item_sk = ss.ss_item_sk AND cs.cs_customer_sk = ss.ss_customer_sk \n","\t LEFT JOIN customer_agg ON customer_agg.customer_sk = ss.ss_customer_sk \n","\t LEFT JOIN date_agg ON date_agg.d_year = ss.ss_sold_year \n","\t LEFT JOIN avg_week_seq ON avg_week_seq.d_year = ss.ss_sold_year \n","\n","\tWHERE \n","\t COALESCE(ws.ws_qty, 0) > 0 \n","\t AND COALESCE(cs.cs_qty, 0) > 0 \n","),\n","ranked_data AS (\n","\tSELECT \n","\t *,\n","\t ROW_NUMBER() OVER (PARTITION BY ss_customer_sk ORDER BY store_qty DESC, store_wholesale_cost DESC) AS qty_rank \n","\tFROM \n","\t complex_aggregation \n",")\n","\n","SELECT \n","\tranked_data.ss_customer_sk, \n","\tranked_data.qty_ratio, \n","\tranked_data.store_qty, \n","\tranked_data.store_wholesale_cost, \n","\tranked_data.store_sales_price, \n","\tranked_data.other_chan_qty, \n","\tranked_data.other_chan_wholesale_cost, \n","\tranked_data.other_chan_sales_price, \n","\tranked_data.total_ws_qty, \n","\tranked_data.total_cs_qty, \n","\tranked_data.total_ss_qty, \n","\tranked_data.avg_week_seq_per_year, \n","\tranked_data.ss_rank, \n","\tranked_data.running_qty_total, \n","\tranked_data.running_avg_wc, \n","\tranked_data.total_customers, \n","\tranked_data.qty_category, \n","\tranked_data.qty_rank \n","\n","FROM ranked_data \n","\n","WHERE ranked_data.qty_rank = 1 \n","\n","ORDER BY ranked_data.ss_customer_sk, store_qty DESC, store_wholesale_cost DESC, store_sales_price DESC, other_chan_qty, other_chan_wholesale_cost, other_chan_sales_price, qty_ratio;"],"cell_type":"code","execution_count":0,"outputs":[]},{"metadata":{"displayMode":"maximized","width":12,"isLimitOn":true},"source":["/*\n","When the query is complete, run the following SQL to capture the start and end times of the query.\n","In the results you can note the difference b/w the 1st and 2nd run durations. This speed up is brought\n","by the new AI-driven scaling and optimization algorithm.\n","*/\n","\n","select query_id,query_text,start_time,end_time, elapsed_time/1000000.0 duration_in_seconds\n","from sys_query_history\n","where query_text like '%TPC-DS Demo Query%'\n","and query_text not like '%sys_query_history%'\n","order by start_time desc;"],"cell_type":"code","execution_count":0,"outputs":[]},{"metadata":{"displayMode":"maximized","width":12,"isLimitOn":true},"source":["/*\n","Let’s assess the compute scaled during the preceding start_time and end_time period. \n","You can notice the increase in compute over the duration of this query. \n","This demonstrates how Redshift Serverless scales based on query complexity.\n","*/\n","\n","select * from sys_serverless_usage\n","where start_time >= (select start_time from sys_query_history where query_text like '%TPC-DS Demo Query%' order by start_time limit 1)\n","and end_time <= DATEADD(minute,1,(select end_time from sys_query_history where query_text like '%TPC-DS Demo Query%' and end_time is not NULL order by end_time desc limit 1))\n","order by end_time asc;"],"cell_type":"code","execution_count":0,"outputs":[]}]} \ No newline at end of file From a62a39ad555c48398528b4b7f4b6200cfce87875 Mon Sep 17 00:00:00 2001 From: sksonti Date: Thu, 19 Jun 2025 08:47:24 -0400 Subject: [PATCH 32/49] Adding Redshift to IDC migration Utility --- src/RedshiftIDCMigrationUtility/README.md | 91 +++++++ .../idc_add_users_groups_roles_psets.py | 224 ++++++++++++++++++ .../idc_config.ini | 18 ++ ...ft_unload_indatabase_groups_roles_users.py | 204 ++++++++++++++++ .../redshift_unload.ini | 17 ++ .../vw_local_ugr_to_idc_urgr_priv.sql | 184 ++++++++++++++ 6 files changed, 738 insertions(+) create mode 100644 src/RedshiftIDCMigrationUtility/README.md create mode 100644 src/RedshiftIDCMigrationUtility/idc_add_users_groups_roles_psets.py create mode 100644 src/RedshiftIDCMigrationUtility/idc_config.ini create mode 100644 src/RedshiftIDCMigrationUtility/idc_redshift_unload_indatabase_groups_roles_users.py create mode 100644 src/RedshiftIDCMigrationUtility/redshift_unload.ini create mode 100644 src/RedshiftIDCMigrationUtility/vw_local_ugr_to_idc_urgr_priv.sql diff --git a/src/RedshiftIDCMigrationUtility/README.md b/src/RedshiftIDCMigrationUtility/README.md new file mode 100644 index 00000000..0eaa687d --- /dev/null +++ b/src/RedshiftIDCMigrationUtility/README.md @@ -0,0 +1,91 @@ + User Guide: Migrating Redshift Local Users to AWS IAM IDC + + +This document guides on how to use the utility to migrate local users, groups and roles from your Redshift instance to AWS IAM Identity Center (IDC) users, groups and roles. + +Utility Version: 1.0 +Release Date: 05/31/2025 + +Scope: +Following are the activities performed by this utility. + +1. Create users in IDC for every local user in given Redshift instance. +2. Create groups in IDC for every group and/or role in given Redshift instance. +3. Assign users to groups in IDC as per existing assignments in the Redshift instance. +4. Create IDC roles in Redshift instance matching the IDC group names. +5. Grants permissions to IDC roles in Redshift instance based on the current permissions given to local groups and roles. + + +Considerations: + +* Creating permissions in AWS Lake Formation is currently not in scope +* IDC and IDP integration setup is out of scope for this utility. However, “vw_local_ugr_to_idc_urgr_priv.sql” can be used to create roles and grant permissions to the IDP users/groups passed through IDC. + +* If you have any permissions given directly to local user IDs i.e not via groups or roles, then you need to change that to a role based permission approach for IDC integration. Please create roles and provide permissions via roles instead of directly giving permissions to users. + + +Utility Artifacts: + +Please download the utility artifacts. + +* `idc_redshift_unload_indatabase_groups_roles_users.py`: python script to unload users, groups , roles and their associations. +* `redshift_unload.ini`: Config file used in above script to read redshift cluster details and S3 locations to unload the files. +* `idc_add_users_groups_roles_psets.py`: python script to create users, groups in IDC and then associate the users to groups in IDC. +* `idc_config.ini`: Config file used in the above script to read IDC details. +* `vw_local_ugr_to_idc_urgr_priv.sql`: Generates SQL statements to create IDC roles in Redshift matching with exact names as IDC groups. It also generates SQLs to GRANT permissions to IDC roles created in Redshift. + + + +Pre-requisites: +Following are the pre-requisites before running the utility. + +* Enable AWS IDC in your account. Please refer Enabling AWS IAM Identity Center documentation. +* Complete steps 1 to 8 from the blog Integrate Identity Provider (IdP) with Amazon Redshift Query Editor V2 and SQL Client using AWS IAM Identity Center for seamless Single Sign-On. +* Disable assignments for IDC application. + * In IDC console, navigate to Application Assignments → Applications. + * Select the application. Choose Actions→ Edit details. + * Set “User and group assignments” to “Do not require assignments”. After Redshift-idc application is set up in above step, for testing purposes , edit the details of the application in Identity Center and chose user and group membership not required, so connectivity to Redshift can be tested even without data access +* Enable Identity Center authentication with admin access from ec2 or cloud shell . https://docs.aws.amazon.com/sdkref/latest/guide/access-sso.html + + + + +Run Steps: + + +1. Update Redshift cluster details and S3 locations in redshift_config.ini +2. Update IDC details in idc_config.ini. +3. Create a directory in AWS cloudshellor your own EC2 instance which has connectivity to Redshift. +4. Copy the two ini files and download python scripts to that directory +5. Run idc_redshift_unload_indatabase_groups_roles_users.py either from AWS cloudshell or EC2 instance. + + +python idc_redshift_unload_indatabase_groups_roles_users.py + + +1. Run idc_add_users_groups_roles_psets.py from AWS cloudshell or EC2 instance. + + +python idc_add_users_groups_roles_psets.py + + +1. Connect your Redshift cluster using Query Editor V2 or SQL client of your choice. Please use superuser credentials. +2. Copy the SQL in “vw_local_ugr_to_idc_urgr_priv.sql” file and run in the editor to create the vw_local_ugr_to_idc_urgr_priv +3. Run following SQL to generate the SQL statement for creating roles and permissions. + +select existing_grants,idc_based_grants from vw_local_ugr_to_idc_urgr_priv; + +1. Review the statements in idc_based_grants column. + +NOTE: It generates grant statements on 1/ databases 2/schemas 3/tables 4/views 5/columns 6/functions 7/models 8/data shares. However, please note that this may not be 100% comprehensive list of permissions. So a review is important and the missing ones needs to manually granted. + +1. If all is good, run all the statements from the SQL client. + + +If there is any further help required please reach following contacts +sksonti@amazon.com, shmanee@amazon.com, sumanpun@amazon.com ziadwali@amazon.fr + +NOTE: This utility is continuously enhanced to close gaps and add additional functionality. Please send your issues, feedback, enhancement requests to above contacts with subject “[issue/feedback/enhancement] AWS IDC migration utility from Redshift” + + +Authors: sksonti@amazon.com, shmanee@amazon.com, sumanpun@amazon.com ziadwali@amazon.fr diff --git a/src/RedshiftIDCMigrationUtility/idc_add_users_groups_roles_psets.py b/src/RedshiftIDCMigrationUtility/idc_add_users_groups_roles_psets.py new file mode 100644 index 00000000..57e0c460 --- /dev/null +++ b/src/RedshiftIDCMigrationUtility/idc_add_users_groups_roles_psets.py @@ -0,0 +1,224 @@ +import boto3 +import csv +import io +import logging +import configparser + +# Initialize logger +logging.basicConfig(level=logging.INFO) +logger = logging.getLogger(__name__) + +def load_configuration(config_path='idc_config.ini'): + config = configparser.ConfigParser() + config.read(config_path) + return config + +def read_csv_from_s3(s3_client, bucket, file_key): + try: + response = s3_client.get_object(Bucket=bucket, Key=file_key) + csv_content = response["Body"].read().decode("utf-8") + csv_reader = csv.reader(io.StringIO(csv_content)) + data = list(csv_reader) + return data + except Exception as e: + logger.error(f"Error reading {file_key} from S3: {e}") + return None + +def get_user_id(identity_store_client, identity_store_id, user_name): + """Get user ID from username if exists""" + try: + # List users with filter to find by username + response = identity_store_client.list_users( + IdentityStoreId=identity_store_id, + Filters=[ + { + 'AttributePath': 'UserName', + 'AttributeValue': user_name + } + ] + ) + + for user in response.get('Users', []): + if user.get('UserName') == user_name: + logger.info(f"Found existing user: {user_name} with ID: {user['UserId']}") + return user['UserId'] + + return None + except Exception as e: + logger.error(f"Error searching for user {user_name}: {e}") + return None + +def create_user(identity_store_client, identity_store_id, user_name): + # Check if the user already exists + user_id = get_user_id(identity_store_client, identity_store_id, user_name) + + if user_id: + logger.info(f"User already exists: {user_name}") + return user_id + + # User doesn't exist, create it + try: + response = identity_store_client.create_user( + IdentityStoreId=identity_store_id, + UserName=user_name, + DisplayName=user_name, + Name={'GivenName': user_name, 'FamilyName': 'from Redshift'}, + Emails=[{"Value": f"{user_name}@example.com", "Type": "work"}] + ) + logger.info(f"User created: {user_name}") + return response["UserId"] + except Exception as e: + logger.error(f"Error creating user {user_name}: {e}") + raise + +def get_group_id(identity_store_client, identity_store_id, group_name): + """Get group ID from group name if exists""" + try: + # List groups with filter to find by display name + response = identity_store_client.list_groups( + IdentityStoreId=identity_store_id, + Filters=[ + { + 'AttributePath': 'DisplayName', + 'AttributeValue': group_name + } + ] + ) + + for group in response.get('Groups', []): + if group.get('DisplayName') == group_name: + logger.info(f"Found existing group: {group_name} with ID: {group['GroupId']}") + return group['GroupId'] + + return None + except Exception as e: + logger.error(f"Error searching for group {group_name}: {e}") + return None + +def create_group(identity_store_client, sso_admin_client, identity_store_id, role_name, assign_permission_set=True, **additional_config): + # Check if the group already exists + group_id = get_group_id(identity_store_client, identity_store_id, role_name) + + if group_id: + logger.info(f"Group already exists: {role_name}") + else: + # Group doesn't exist, create it + try: + response = identity_store_client.create_group( + IdentityStoreId=identity_store_id, + DisplayName=role_name + ) + logger.info(f"Group created: {role_name}") + group_id = response["GroupId"] + except Exception as e: + logger.error(f"Error creating group {role_name}: {e}") + raise + + # Assign permission set if requested (for both new and existing groups) + if assign_permission_set: + try: + sso_admin_client.create_account_assignment( + InstanceArn=additional_config['instance_arn'], + TargetId=additional_config['account_id'], + TargetType='AWS_ACCOUNT', + PermissionSetArn=additional_config['permission_set_arn'], + PrincipalType='GROUP', + PrincipalId=group_id + ) + logger.info(f"Permission set assigned to group: {role_name}") + except Exception as e: + if "ConflictException" in str(e): + logger.info(f"Permission set already assigned to group {role_name}") + else: + logger.error(f"Error assigning permission set to group {group_id}: {e}") + + return group_id + +def add_user_to_group(identity_store_client, identity_store_id, user_id, group_id): + try: + identity_store_client.create_group_membership( + IdentityStoreId=identity_store_id, + GroupId=group_id, + MemberId={'UserId': user_id} + ) + logger.info(f"Added user {user_id} to group {group_id}") + except Exception as e: + if "ConflictException" in str(e): + logger.info(f"User {user_id} is already a member of group {group_id}") + else: + logger.error(f"Error adding user {user_id} to group {group_id}: {e}") + raise + +def process_roles(config, aws_clients, assign_permission_set=True): + s3_bucket = config.get('S3', 's3_bucket') + roles_file = config.get('S3', 'roles_file') + identity_store_id = config.get('AWS', 'identity_store_id') + + roles_data = read_csv_from_s3(aws_clients['s3'], s3_bucket, roles_file) + role_ids = {} + + for row in roles_data[1:]: # Skip header + role_name = row[0] + role_id = create_group(aws_clients['identity_store'], aws_clients['sso_admin'], identity_store_id, role_name, assign_permission_set=assign_permission_set, **{ + 'instance_arn': config.get('AWS', 'instance_arn'), + 'account_id': config.get('AWS', 'account_id'), + 'permission_set_arn': config.get('AWS', 'permission_set_arn') + }) + role_ids[role_name] = role_id + + return role_ids + +def process_users(config, aws_clients): + s3_bucket = config.get('S3', 's3_bucket') + users_file = config.get('S3', 'users_file') + identity_store_id = config.get('AWS', 'identity_store_id') + + users_data = read_csv_from_s3(aws_clients['s3'], s3_bucket, users_file) + user_ids = {} + + for row in users_data[1:]: # Skip header + user_name = row[0] + user_id = create_user(aws_clients['identity_store'], identity_store_id, user_name) + user_ids[user_name] = user_id + + return user_ids + +def process_role_memberships(config, aws_clients, user_ids, role_ids): + s3_bucket = config.get('S3', 's3_bucket') + role_memberships_file = config.get('S3', 'role_memberships_file') + identity_store_id = config.get('AWS', 'identity_store_id') + + role_memberships_data = read_csv_from_s3(aws_clients['s3'], s3_bucket, role_memberships_file) + + for row in role_memberships_data[1:]: # Skip header + user_name, role_name = row + user_id = user_ids.get(user_name) + role_id = role_ids.get(role_name) + + if not user_id: + logger.error(f"User ID not found for user {user_name}") + continue + + if not role_id: + logger.error(f"Role ID not found for role {role_name}") + continue + + add_user_to_group(aws_clients['identity_store'], identity_store_id, user_id, role_id) + +def main(): + config = load_configuration() + + aws_clients = { + 's3': boto3.client('s3', region_name=config.get('AWS', 'region')), + 'identity_store': boto3.client('identitystore', region_name=config.get('AWS', 'region')), + 'sso_admin': boto3.client('sso-admin', region_name=config.get('AWS', 'region')) + } + + assign_permission_set = config.getboolean('GROUP_MANAGEMENT', 'assign_permission_set', fallback=True) + + user_ids = process_users(config, aws_clients) + role_ids = process_roles(config, aws_clients, assign_permission_set=assign_permission_set) + process_role_memberships(config, aws_clients, user_ids, role_ids) + +if __name__ == "__main__": + main() diff --git a/src/RedshiftIDCMigrationUtility/idc_config.ini b/src/RedshiftIDCMigrationUtility/idc_config.ini new file mode 100644 index 00000000..36033993 --- /dev/null +++ b/src/RedshiftIDCMigrationUtility/idc_config.ini @@ -0,0 +1,18 @@ +[AWS] +region = us-east-2 +account_id = 123456789123 +identity_store_id = d-9a6760112c +instance_arn = arn:aws:sso:::instance/ssoins-66841ddc5ebdfd42 +permission_set_arn = arn:aws:sso:::permissionSet/ssoins-66841ddc5ebdfd42/ps-ce41b668245bcd56 + + +[GROUP_MANAGEMENT] +assign_permission_set = True + + +[S3] +s3_bucket = redshift-idc-unload +users_file = users.csv +roles_file = roles.csv +role_memberships_file = role_memberships.csv + diff --git a/src/RedshiftIDCMigrationUtility/idc_redshift_unload_indatabase_groups_roles_users.py b/src/RedshiftIDCMigrationUtility/idc_redshift_unload_indatabase_groups_roles_users.py new file mode 100644 index 00000000..46557bb3 --- /dev/null +++ b/src/RedshiftIDCMigrationUtility/idc_redshift_unload_indatabase_groups_roles_users.py @@ -0,0 +1,204 @@ +import boto3 +import psycopg2 +import csv +import logging +import configparser +from io import StringIO + +# setup logging +logging.basicConfig(level=logging.INFO) +logger = logging.getLogger(__name__) + +def load_config(config_file='redshift_unload.ini'): + """Load configuration from file""" + #config = configparser.ConfigParser() + + config = configparser.ConfigParser(inline_comment_prefixes=('#',)) + config.read(config_file) + return config + +def validate_config(config): + """Validate that all required configuration parameters are present based on cluster_type""" + if 'REDSHIFT' not in config: + raise ValueError("Missing configuration section: REDSHIFT") + + cluster_type = config['REDSHIFT'].get('cluster_type') + if not cluster_type: + raise ValueError("Missing 'cluster_type' parameter in [REDSHIFT] section. Must be 'provisioned' or 'serverless'.") + + required_params = { + 'AWS': ['region', 's3_bucket'], + 'S3_FILES': ['roles', 'users', 'role_memberships'] + } + + if cluster_type == 'provisioned': + required_params['REDSHIFT'] = ['cluster_id', 'db_user', 'db_name', 'host', 'port'] + elif cluster_type == 'serverless': + required_params['REDSHIFT'] = ['db_user', 'db_name', 'workgroup_name', 'port'] + else: + raise ValueError(f"Invalid cluster_type: {cluster_type}. Must be 'provisioned' or 'serverless'.") + + for section, params in required_params.items(): + if section not in config: + raise ValueError(f"Missing configuration section: {section}") + + for param in params: + if param not in config[section]: + raise ValueError(f"Missing configuration parameter: {section}.{param}") + +def get_redshift_credentials(config): + """Get Redshift credentials based on cluster type.""" + try: + cluster_type = config['REDSHIFT']['cluster_type'] + + if cluster_type == 'provisioned': + client = boto3.client('redshift', region_name=config['AWS']['region']) + credentials = client.get_cluster_credentials( + DbUser=config['REDSHIFT']['db_user'], + DbName=config['REDSHIFT']['db_name'], + ClusterIdentifier=config['REDSHIFT']['cluster_id'] + ) + return credentials + elif cluster_type == 'serverless': + client = boto3.client('redshift', region_name=config['AWS']['region']) + credentials = client.get_cluster_credentials( + DbUser=config['REDSHIFT']['db_user'], + DbName=config['REDSHIFT']['db_name'], + ClusterIdentifier="redshift-serverless-"+config['REDSHIFT']['workgroup_name'] + ) + client = boto3.client('redshift-serverless', region_name=config['AWS']['region']) + workgroup = client.get_workgroup(workgroupName=config['REDSHIFT']['workgroup_name']) + endpoint = workgroup['workgroup']['endpoint'] + host = endpoint['address'] + return { + "DbUser": credentials['DbUser'], + "DbPassword": credentials['DbPassword'], + "Host": host + } + else: + raise ValueError(f"Unsupported cluster_type: {cluster_type}") + + except Exception as e: + logger.error(f"Error getting credentials: {str(e)}") + return None + +def connect_to_redshift(config): + creds = get_redshift_credentials(config) + if creds is None: + return None + + try: + cluster_type = config['REDSHIFT']['cluster_type'] + + if cluster_type == 'provisioned': + host = config['REDSHIFT']['host'] + elif cluster_type == 'serverless': + host = creds["Host"] # For serverless, host comes from credentials + else: + raise ValueError(f"Unsupported cluster_type: {cluster_type}") + + conn = psycopg2.connect( + dbname=config['REDSHIFT']['db_name'], + user=creds["DbUser"], + password=creds["DbPassword"], + host=host, + port=config['REDSHIFT']['port'] + ) + logger.info("Connected to Redshift successfully!") + return conn + except Exception as e: + logger.error(f"Failed to connect to Redshift: {e}") + return None + +def fetch_data_from_redshift(conn, query): + try: + cursor = conn.cursor() + cursor.execute(query) + cursor_description = cursor.description + result = cursor.fetchall() + cursor.close() + return result, cursor_description + except Exception as e: + logger.error(f"Error fetching data: {e}") + return None, None + +def write_to_s3(data, cursor_description, s3_key, config): + try: + s3_client = boto3.client('s3', region_name=config['AWS']['region']) + csv_buffer = StringIO() + csv_writer = csv.writer(csv_buffer) + + if data: + csv_writer.writerow([desc[0] for desc in cursor_description]) + + for row in data: + csv_writer.writerow(row) + + s3_client.put_object( + Bucket=config['AWS']['s3_bucket'], + Key=s3_key, + Body=csv_buffer.getvalue() + ) + logger.info(f"Data successfully written to S3: {s3_key}") + except Exception as e: + logger.error(f"Error writing to S3: {e}") + +def get_and_write_data(conn, query, s3_key, config): + data, cursor_description = fetch_data_from_redshift(conn, query) + if data is not None: + write_to_s3(data, cursor_description, s3_key, config) + +def main(): + try: + # Load configuration + config = load_config() + validate_config(config) + + # Connect to Redshift + conn = connect_to_redshift(config) + if conn is None: + logger.error("Failed to connect to Redshift. Exiting program.") + return + + # SQL Queries (common to both) + query_roles = """ + select groname from pg_group + where groname not like '%:%' + union + SELECT role_name FROM svv_roles + where role_owner <> 'rdsdb' and role_name not ilike 'awsidc%' and role_name not like '%:%' """ + + query_users = """ + SELECT user_name FROM svv_user_info + where superuser = 'false' + and user_name not ilike 'awsidc%' + and user_name not ilike 'IAM%' + and user_name not like '%:%' + """ + + query_role_memberships = """ + SELECT u.usename, g.groname + FROM (SELECT groname, grolist, generate_series(1, array_upper(grolist, 1)) AS i + FROM pg_group) AS g + JOIN pg_user u ON g.grolist[i] = u.usesysid + where u.usename not like '%:%' + and g.groname not like '%:%' + UNION + SELECT user_name,role_name FROM svv_user_grants + where user_name not like '%:%' + and role_name not like '%:%' + """ + + # Execute queries and write to S3 + get_and_write_data(conn, query_roles, config['S3_FILES']['roles'], config) + get_and_write_data(conn, query_users, config['S3_FILES']['users'], config) + get_and_write_data(conn,query_role_memberships,config['S3_FILES']['role_memberships'], config) + + conn.close() + + except Exception as e: + logger.error(f"Configuration error: {e}") + return + +if __name__ == "__main__": + main() diff --git a/src/RedshiftIDCMigrationUtility/redshift_unload.ini b/src/RedshiftIDCMigrationUtility/redshift_unload.ini new file mode 100644 index 00000000..3331ee6c --- /dev/null +++ b/src/RedshiftIDCMigrationUtility/redshift_unload.ini @@ -0,0 +1,17 @@ +[REDSHIFT] +cluster_type = provisioned # Set to 'provisioned' for a provisioned cluster or 'serverless' for a serverless workgroup +cluster_id = redshift-cluster-1 # Required if cluster_type = provisioned +db_user = admin +db_name = dev +host = redshift-cluster-1.c0lwc6winfis.us-east-2.redshift.amazonaws.com # Required if cluster_type = provisioned +port = 5439 +workgroup_name = rs-serverless-wg-idctest # Required if cluster_type = serverless + +[AWS] +region = us-east-2 +s3_bucket = redshift-idc-unload + +[S3_FILES] +roles = roles.csv +users = users.csv +role_memberships = role_memberships.csv diff --git a/src/RedshiftIDCMigrationUtility/vw_local_ugr_to_idc_urgr_priv.sql b/src/RedshiftIDCMigrationUtility/vw_local_ugr_to_idc_urgr_priv.sql new file mode 100644 index 00000000..a7d4909e --- /dev/null +++ b/src/RedshiftIDCMigrationUtility/vw_local_ugr_to_idc_urgr_priv.sql @@ -0,0 +1,184 @@ +CREATE OR REPLACE VIEW vw_local_ugr_to_idc_urgr_priv +as +with privs as ( +select 1 as seq_no +, NULL as database_name +, NULL as namespace_name +, NULL as relation_name +, NULL as column_name +, NULL as privilege_type +, NULL as identity_name +, NULL as identity_id +, NULL as identity_type +,'CREATE GROUP "' + groname + '";' as "existing_grants" +,'CREATE role "' + namespc + ':' + groname + '";' as "idc_based_grants" +from pg_group,SVV_IDENTITY_PROVIDERS where type='awsidc' +UNION ALL +select 1 as seq_no +, NULL as database_name +, NULL as namespace_name +, NULL as relation_name +, NULL as column_name +, NULL as privilege_type +, NULL as identity_name +, NULL as identity_id +, NULL as identity_type +,'CREATE ROLE "' + role_name + '";' as "existing_grants" +,'CREATE role "' + namespc + ':' + CONCAT(case when role_name like '%:%' then split_part(role_name,':',2) else role_name end, '";') as "idc_based_grants" +from svv_roles,SVV_IDENTITY_PROVIDERS where type='awsidc' and role_name not like '%:%' +UNION ALL +select +2 as seq_no +, database_name +, NULL as namespace_name +, NULL as relation_name +, NULL as column_name +, privilege_type +, identity_name +, identity_id +, identity_type +,'GRANT '+ privilege_type + ' ON DATABASE ' + database_name + ' TO ' + replace(identity_type,'user','') + ' "' + identity_name + '"' + ' ;' as "existing_grants" +,'GRANT '+ privilege_type + ' ON DATABASE ' + database_name + ' TO ' + CONCAT(case when identity_type='user' then '' when identity_type='group' then 'role' else identity_type end, ' "') + namespc + ':' + CONCAT(case when identity_name like '%:%' then split_part(identity_name,':',2) else identity_name end, '";') as "idc_based_grants" +from svv_database_privileges s, SVV_IDENTITY_PROVIDERS where identity_type<>'public' and type='awsidc' +UNION ALL +select +3 as seq_no +,current_database() as database_name +,namespace_name +,NULL as relation_name +,NULL as column_name +,privilege_type +,identity_name +,identity_id +,identity_type +,'GRANT '+ privilege_type + ' ON SCHEMA ' + namespace_name + ' TO ' + replace(identity_type,'user','') + ' "' + identity_name + '"' + ' ;' as "existing_grants" +,'GRANT '+ privilege_type + ' ON SCHEMA ' + namespace_name + ' TO ' + CONCAT(case when identity_type='user' then '' when identity_type='group' then 'role' else identity_type end, ' "') + namespc + ':' + CONCAT(case when identity_name like '%:%' then split_part(identity_name,':',2) else identity_name end, '";') as "idc_based_grants" +from SVV_SCHEMA_PRIVILEGES, SVV_IDENTITY_PROVIDERS where identity_type<>'public' and type='awsidc' +UNION ALL +select +4 as seq_no +,current_database() as database_name +,namespace_name +,relation_name +,NULL as column_name +,privilege_type +,identity_name +,identity_id +,identity_type +,'GRANT '+ privilege_type + ' ON TABLE ' + namespace_name + '.' + relation_name + ' TO ' + replace(identity_type,'user','') + ' "' + identity_name + '"' + ' ;' as "existing_grants" +,'GRANT '+ privilege_type + ' ON TABLE ' + namespace_name + '.' + relation_name + ' TO ' + CONCAT(case when identity_type='user' then '' when identity_type='group' then 'role' else identity_type end, ' "') + namespc + ':' + CONCAT(case when identity_name like '%:%' then split_part(identity_name,':',2) else identity_name end, '";') as "idc_based_grants" +from SVV_RELATION_PRIVILEGES, SVV_IDENTITY_PROVIDERS where identity_type<>'public' and type='awsidc' +UNION ALL +select +5 as seq_no +,current_database() as database_name +,namespace_name +,relation_name +,column_name +,privilege_type +,identity_name +,identity_id +,identity_type +,'GRANT '+ privilege_type + ' (' + column_name + ') ' + 'ON TABLE ' + namespace_name + '.' + relation_name + ' TO ' + replace(identity_type,'user','') + ' "' + identity_name + '" ;' as "existing_grants" +,'GRANT '+ privilege_type + ' (' + column_name + ') ' + 'ON TABLE ' + namespace_name + '.' + relation_name + ' TO ' + CONCAT(case when identity_type='user' then '' when identity_type='group' then 'role' else identity_type end, ' "') + namespc + ':' + CONCAT(case when identity_name like '%:%' then split_part(identity_name,':',2) else identity_name end, '";') as "idc_based_grants" +from svv_column_privileges, SVV_IDENTITY_PROVIDERS where identity_type<>'public' and type='awsidc' +UNION ALL +select +6 as seq_no +,current_database() as database_name +,schema_name as namespace_name +,NULL as relation_name +,NULL as column_name +,privilege_type +,grantee_name as identity_name +,grantee_id as identity_id +,grantee_type as identity_type +,'ALTER DEFAULT PRIVILEGES ' ++ CONCAT(case when schema_name is NULL then ' FOR USER ' else ' IN SCHEMA ' end, ' ') + CONCAT(case when schema_name is NULL then owner_name else schema_name end, '') + ' GRANT ' + privilege_type + ' ON ' ++ CONCAT(case when object_type='RELATION' then ' TABLES ' else object_type end, ' TO ') ++ replace(identity_type,'user','') ++ ' "' + grantee_name + '" ;' +as "existing_grants" +,'GRANT '+ privilege_type + ' FOR ' ++ CONCAT(case when object_type='RELATION' then 'TABLES ' when object_type='PROCEDURE' then 'PROCEDURES ' when object_type='FUNCTION' then 'FUNCTIONS ' else object_type end, ' IN SCHEMA ') ++ schema_name + ' TO ROLE "' ++ namespc + ':' + CONCAT(case when identity_name like '%:%' then split_part(identity_name,':',2) else identity_name end, '";') as "idc_based_grants" +from svv_default_privileges, SVV_IDENTITY_PROVIDERS where identity_type<>'public' and type='awsidc' + +UNION ALL + +select +7 as seq_no +,current_database() as database_name +,namespace_name +,NULL as relation_name +,NULL as column_name +,privilege_type +,identity_name +,identity_id +,identity_type +,'GRANT '+ privilege_type + ' ON FUNCTION ' + namespace_name + '.' + function_name + '(' + argument_types +') TO ROLE' + identity_name +';' as "existing_grants" +,'GRANT '+ privilege_type + ' ON FUNCTION ' + namespace_name + '.' + function_name + '(' + argument_types +') TO ' + + +CONCAT(case when identity_type='user' then '' when identity_type='group' then 'role' else identity_type end, ' "') + namespc + ':' + CONCAT(case when identity_name like '%:%' then split_part(identity_name,':',2) else identity_name end, '";') + as "idc_based_grants" +from SVV_FUNCTION_PRIVILEGES,SVV_IDENTITY_PROVIDERS where identity_type<>'public' and type='awsidc' + +UNION ALL + +select +8 as seq_no +,current_database() as database_name +,NULL as namespace_name +,NULL as relation_name +,NULL as column_name +,privilege_type +,identity_name +,identity_id +,identity_type +,'GRANT '+ privilege_type + ' ON DATASHARE ' + datashare_name + ' TO ROLE' + identity_name +';' as "existing_grants" + +,'GRANT '+ privilege_type + ' ON DATASHARE ' + datashare_name + ' TO ' + +CONCAT(case when identity_type='user' then '' when identity_type='group' then 'role' else identity_type end, ' "') + namespc + ':' + CONCAT(case when identity_name like '%:%' then split_part(identity_name,':',2) else identity_name end, '";') + as "idc_based_grants" +from SVV_DATASHARE_PRIVILEGES,SVV_IDENTITY_PROVIDERS where identity_type<>'public' and type='awsidc' + +UNION ALL + +select +9 as seq_no +,current_database() as database_name +,namespace_name +,NULL as relation_name +,NULL as column_name +,privilege_type +,identity_name +,identity_id +,identity_type +,'GRANT '+ privilege_type + ' ON MODEL ' + namespace_name + '.' + model_name + ' TO ROLE' + identity_name +';' as "existing_grants" +,'GRANT '+ privilege_type + ' ON MODEL ' + namespace_name + '.' + model_name + ' TO ' + + +CONCAT(case when identity_type='user' then '' when identity_type='group' then 'role' else identity_type end, ' "') + namespc + ':' + CONCAT(case when identity_name like '%:%' then split_part(identity_name,':',2) else identity_name end, '";') + as "idc_based_grants" +from SVV_ML_MODEL_PRIVILEGES,SVV_IDENTITY_PROVIDERS where identity_type<>'public' and type='awsidc' + +UNION ALL + +select +10 as seq_no +,current_database() as database_name +,NULL as namespace_name +,NULL as relation_name +,NULL as column_name +,NULL as privilege_type +,role_name as identity_name +,role_id as identity_id +,'role' as identity_type +,'GRANT ROLE '+ granted_role_name + ' TO ROLE ' + role_name +';' as "existing_grants" +,'GRANT ROLE "'+ namespc + ':' + granted_role_name + '" TO ROLE "' + namespc + ':' + role_name + '";' as "idc_based_grants" +from SVV_ROLE_GRANTS, SVV_IDENTITY_PROVIDERS where identity_type<>'public' and type='awsidc' and role_name not like 'sys:%' + +) +select database_name, namespace_name,relation_name,column_name,privilege_type, identity_name, identity_id, identity_type, +existing_grants,idc_based_grants +from privs order by seq_no; \ No newline at end of file From b7874a987443d4862de82bb46e0d4fedf5f0a8d5 Mon Sep 17 00:00:00 2001 From: sksonti Date: Thu, 19 Jun 2025 09:47:45 -0400 Subject: [PATCH 33/49] Updated README --- src/RedshiftIDCMigrationUtility/README.md | 34 ++++++++++++----------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/RedshiftIDCMigrationUtility/README.md b/src/RedshiftIDCMigrationUtility/README.md index 0eaa687d..f4544f6f 100644 --- a/src/RedshiftIDCMigrationUtility/README.md +++ b/src/RedshiftIDCMigrationUtility/README.md @@ -1,12 +1,10 @@ - User Guide: Migrating Redshift Local Users to AWS IAM IDC - This document guides on how to use the utility to migrate local users, groups and roles from your Redshift instance to AWS IAM Identity Center (IDC) users, groups and roles. Utility Version: 1.0 -Release Date: 05/31/2025 +Release Date: 06/20/2025 -Scope: +# Scope: Following are the activities performed by this utility. 1. Create users in IDC for every local user in given Redshift instance. @@ -16,7 +14,7 @@ Following are the activities performed by this utility. 5. Grants permissions to IDC roles in Redshift instance based on the current permissions given to local groups and roles. -Considerations: +# Considerations: * Creating permissions in AWS Lake Formation is currently not in scope * IDC and IDP integration setup is out of scope for this utility. However, “vw_local_ugr_to_idc_urgr_priv.sql” can be used to create roles and grant permissions to the IDP users/groups passed through IDC. @@ -24,7 +22,7 @@ Considerations: * If you have any permissions given directly to local user IDs i.e not via groups or roles, then you need to change that to a role based permission approach for IDC integration. Please create roles and provide permissions via roles instead of directly giving permissions to users. -Utility Artifacts: +# Utility Artifacts: Please download the utility artifacts. @@ -36,7 +34,7 @@ Please download the utility artifacts. -Pre-requisites: +# Pre-requisites: Following are the pre-requisites before running the utility. * Enable AWS IDC in your account. Please refer Enabling AWS IAM Identity Center documentation. @@ -50,7 +48,7 @@ Following are the pre-requisites before running the utility. -Run Steps: +# Run Steps: 1. Update Redshift cluster details and S3 locations in redshift_config.ini @@ -60,26 +58,30 @@ Run Steps: 5. Run idc_redshift_unload_indatabase_groups_roles_users.py either from AWS cloudshell or EC2 instance. +``` python idc_redshift_unload_indatabase_groups_roles_users.py +``` -1. Run idc_add_users_groups_roles_psets.py from AWS cloudshell or EC2 instance. - +6. Run idc_add_users_groups_roles_psets.py from AWS cloudshell or EC2 instance. +``` python idc_add_users_groups_roles_psets.py +``` +7. Connect your Redshift cluster using Query Editor V2 or SQL client of your choice. Please use superuser credentials. +8. Copy the SQL in “vw_local_ugr_to_idc_urgr_priv.sql” file and run in the editor to create the vw_local_ugr_to_idc_urgr_priv +9. Run following SQL to generate the SQL statement for creating roles and permissions. -1. Connect your Redshift cluster using Query Editor V2 or SQL client of your choice. Please use superuser credentials. -2. Copy the SQL in “vw_local_ugr_to_idc_urgr_priv.sql” file and run in the editor to create the vw_local_ugr_to_idc_urgr_priv -3. Run following SQL to generate the SQL statement for creating roles and permissions. - +```sql select existing_grants,idc_based_grants from vw_local_ugr_to_idc_urgr_priv; +``` -1. Review the statements in idc_based_grants column. +10. Review the statements in idc_based_grants column. NOTE: It generates grant statements on 1/ databases 2/schemas 3/tables 4/views 5/columns 6/functions 7/models 8/data shares. However, please note that this may not be 100% comprehensive list of permissions. So a review is important and the missing ones needs to manually granted. -1. If all is good, run all the statements from the SQL client. +11. If all is good, run all the statements from the SQL client. If there is any further help required please reach following contacts From cb9d1737b621d13bcd4370b3e7a27f1a96339a7f Mon Sep 17 00:00:00 2001 From: sksonti Date: Thu, 19 Jun 2025 10:06:27 -0400 Subject: [PATCH 34/49] Updated Readme file --- src/RedshiftIDCMigrationUtility/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/RedshiftIDCMigrationUtility/README.md b/src/RedshiftIDCMigrationUtility/README.md index f4544f6f..3b227af8 100644 --- a/src/RedshiftIDCMigrationUtility/README.md +++ b/src/RedshiftIDCMigrationUtility/README.md @@ -38,7 +38,7 @@ Please download the utility artifacts. Following are the pre-requisites before running the utility. * Enable AWS IDC in your account. Please refer Enabling AWS IAM Identity Center documentation. -* Complete steps 1 to 8 from the blog Integrate Identity Provider (IdP) with Amazon Redshift Query Editor V2 and SQL Client using AWS IAM Identity Center for seamless Single Sign-On. +* Complete steps 1 to 8 from the blog [Integrate Identity Provider (IdP) with Amazon Redshift Query Editor V2 and SQL Client using AWS IAM Identity Center for seamless Single Sign-On](https://aws.amazon.com/blogs/big-data/integrate-identity-provider-idp-with-amazon-redshift-query-editor-v2-and-sql-client-using-aws-iam-identity-center-for-seamless-single-sign-on/). * Disable assignments for IDC application. * In IDC console, navigate to Application Assignments → Applications. * Select the application. Choose Actions→ Edit details. From 5d336bb674aaddbfc2e624dc7a04503c7af9c4a1 Mon Sep 17 00:00:00 2001 From: sksonti Date: Thu, 19 Jun 2025 10:11:58 -0400 Subject: [PATCH 35/49] Updated Readme file --- src/RedshiftIDCMigrationUtility/README.md | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/RedshiftIDCMigrationUtility/README.md b/src/RedshiftIDCMigrationUtility/README.md index 3b227af8..2b2c93dc 100644 --- a/src/RedshiftIDCMigrationUtility/README.md +++ b/src/RedshiftIDCMigrationUtility/README.md @@ -79,9 +79,18 @@ select existing_grants,idc_based_grants from vw_local_ugr_to_idc_urgr_priv; 10. Review the statements in idc_based_grants column. -NOTE: It generates grant statements on 1/ databases 2/schemas 3/tables 4/views 5/columns 6/functions 7/models 8/data shares. However, please note that this may not be 100% comprehensive list of permissions. So a review is important and the missing ones needs to manually granted. - -11. If all is good, run all the statements from the SQL client. +NOTE: The utility generates grant statements for the following objects: +1. Databases +2. Schemas +3. Tables +4. Views +5. Columns +6. Functions +7. Models +8. Data Shares +However, please note that this may not be a 100% comprehensive list of permissions. Therefore, a review is a mandatory step, and any missing permissions will need to be manually granted. + +11. Connect to the Redshift cluster from any SQL editor and run all the reviewed SQL statements to create the IDC roles and permissions. If there is any further help required please reach following contacts From caff2a59d5eebcc3eb822dc9a43304f06fbff9a0 Mon Sep 17 00:00:00 2001 From: sksonti Date: Thu, 19 Jun 2025 10:13:44 -0400 Subject: [PATCH 36/49] Updated Readme file --- src/RedshiftIDCMigrationUtility/README.md | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/RedshiftIDCMigrationUtility/README.md b/src/RedshiftIDCMigrationUtility/README.md index 2b2c93dc..d88b6cc0 100644 --- a/src/RedshiftIDCMigrationUtility/README.md +++ b/src/RedshiftIDCMigrationUtility/README.md @@ -79,16 +79,7 @@ select existing_grants,idc_based_grants from vw_local_ugr_to_idc_urgr_priv; 10. Review the statements in idc_based_grants column. -NOTE: The utility generates grant statements for the following objects: -1. Databases -2. Schemas -3. Tables -4. Views -5. Columns -6. Functions -7. Models -8. Data Shares -However, please note that this may not be a 100% comprehensive list of permissions. Therefore, a review is a mandatory step, and any missing permissions will need to be manually granted. +NOTE: The utility generates grant statements for Databases, Schemas, Tables, Views, Columns, Functions, Models and Data Shares. However, please note that this may not be a 100% comprehensive list of permissions. Therefore, a review is a mandatory step, and any missing permissions will need to be manually granted. 11. Connect to the Redshift cluster from any SQL editor and run all the reviewed SQL statements to create the IDC roles and permissions. From cbde4513c9da096c499263a48b7d6403c4a70e80 Mon Sep 17 00:00:00 2001 From: sksonti Date: Thu, 26 Jun 2025 10:10:06 -0400 Subject: [PATCH 37/49] Updated as per reviewer feedback --- README.md | 4 ++ .../idc_add_users_groups_roles_psets.py | 47 ++++++++++++++++++- .../idc_config.ini | 21 +++++---- ...ft_unload_indatabase_groups_roles_users.py | 35 +++++++++++++- .../redshift_unload.ini | 25 +++++----- 5 files changed, 107 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 6ddb6d6e..9cb575fa 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,10 @@ This [project](src/SnapshotManager) is now deprecated. The automatic capture and This [project](src/QMRNotificationUtility) enables a scheduled Lambda function to pull records from the QMR action system log table (stl_wlm_rule_action) and publish them to an SNS topic. This utility can be used to send periodic notifications based on the WLM query monitoring rule actions taken for your unique workload and rules configuration. +# Redshift to IDC migration utility +Some of the existing Redshift customers rely on local users, roles, groups, and permissions, which presents a significant challenge when adopting the SageMaker Lakehouse, Lakeformation, and other cross-service integration features. This [utility](src/RedshiftIDCMigrationUtility) streamlines the process by automatically creating IDC users, groups, and roles that mirror the existing Redshift configuration. It then assigns users to the appropriate groups and grants the necessary permissions to the IDC roles, ensuring a seamless transition to the centralized identity management system. + + # Investigations This project includes a number of detailed investigations into various types of Redshift edge cases, nuances, and workload scenarios. diff --git a/src/RedshiftIDCMigrationUtility/idc_add_users_groups_roles_psets.py b/src/RedshiftIDCMigrationUtility/idc_add_users_groups_roles_psets.py index 57e0c460..03e1a114 100644 --- a/src/RedshiftIDCMigrationUtility/idc_add_users_groups_roles_psets.py +++ b/src/RedshiftIDCMigrationUtility/idc_add_users_groups_roles_psets.py @@ -1,3 +1,4 @@ + import boto3 import csv import io @@ -11,6 +12,34 @@ def load_configuration(config_path='idc_config.ini'): config = configparser.ConfigParser() config.read(config_path) + + required_aws_params = ['region', 'account_id', 'identity_store_id', 'instance_arn', 'permission_set_arn'] + required_s3_params = ['s3_bucket', 'users_file', 'roles_file', 'role_memberships_file'] + + # Check AWS configuration + if 'AWS' not in config: + raise ValueError("Missing AWS section in the configuration file.") + for param in required_aws_params: + if not config.get('AWS', param): + raise ValueError(f"Missing or empty AWS configuration parameter: {param}") + + # Check S3 configuration + if 'S3' not in config: + raise ValueError("Missing S3 section in the configuration file.") + for param in required_s3_params: + if not config.get('S3', param): + raise ValueError(f"Missing or empty S3 configuration parameter: {param}") + + # Check GROUP_MANAGEMENT section and assign_permission_set parameter + if 'GROUP_MANAGEMENT' not in config: + logger.warning("Missing GROUP_MANAGEMENT section in the configuration file. Defaulting 'assign_permission_set' to True.") + config.add_section('GROUP_MANAGEMENT') + config.set('GROUP_MANAGEMENT', 'assign_permission_set', 'True') + elif not config.get('GROUP_MANAGEMENT', 'assign_permission_set'): + logger.warning("Missing or empty 'assign_permission_set' parameter in GROUP_MANAGEMENT section. Defaulting to True.") + config.set('GROUP_MANAGEMENT', 'assign_permission_set', 'True') + + return config def read_csv_from_s3(s3_client, bucket, file_key): @@ -155,6 +184,10 @@ def process_roles(config, aws_clients, assign_permission_set=True): identity_store_id = config.get('AWS', 'identity_store_id') roles_data = read_csv_from_s3(aws_clients['s3'], s3_bucket, roles_file) + if roles_data is None: + logger.error("Could not read roles data. Exiting process_roles.") + return {} + role_ids = {} for row in roles_data[1:]: # Skip header @@ -174,6 +207,10 @@ def process_users(config, aws_clients): identity_store_id = config.get('AWS', 'identity_store_id') users_data = read_csv_from_s3(aws_clients['s3'], s3_bucket, users_file) + if users_data is None: + logger.error("Could not read users data. Exiting process_users.") + return {} + user_ids = {} for row in users_data[1:]: # Skip header @@ -189,6 +226,9 @@ def process_role_memberships(config, aws_clients, user_ids, role_ids): identity_store_id = config.get('AWS', 'identity_store_id') role_memberships_data = read_csv_from_s3(aws_clients['s3'], s3_bucket, role_memberships_file) + if role_memberships_data is None: + logger.error("Could not read role memberships data. Exiting process_role_memberships.") + return for row in role_memberships_data[1:]: # Skip header user_name, role_name = row @@ -206,7 +246,11 @@ def process_role_memberships(config, aws_clients, user_ids, role_ids): add_user_to_group(aws_clients['identity_store'], identity_store_id, user_id, role_id) def main(): - config = load_configuration() + try: + config = load_configuration() + except ValueError as e: + logger.error(f"Configuration error: {e}") + return aws_clients = { 's3': boto3.client('s3', region_name=config.get('AWS', 'region')), @@ -222,3 +266,4 @@ def main(): if __name__ == "__main__": main() + diff --git a/src/RedshiftIDCMigrationUtility/idc_config.ini b/src/RedshiftIDCMigrationUtility/idc_config.ini index 36033993..c441f46d 100644 --- a/src/RedshiftIDCMigrationUtility/idc_config.ini +++ b/src/RedshiftIDCMigrationUtility/idc_config.ini @@ -1,18 +1,19 @@ +# Example values are provided in the comments [AWS] -region = us-east-2 -account_id = 123456789123 -identity_store_id = d-9a6760112c -instance_arn = arn:aws:sso:::instance/ssoins-66841ddc5ebdfd42 -permission_set_arn = arn:aws:sso:::permissionSet/ssoins-66841ddc5ebdfd42/ps-ce41b668245bcd56 +region = # us-east-2 +account_id = #123456789123 +identity_store_id = # d-9a6760112c +instance_arn = # arn:aws:sso:::instance/ssoins-66841ddc5ebdfd42 +permission_set_arn = #arn:aws:sso:::permissionSet/ssoins-66841ddc5ebdfd42/ps-ce41b668245bcd56 [GROUP_MANAGEMENT] -assign_permission_set = True +assign_permission_set = #True [S3] -s3_bucket = redshift-idc-unload -users_file = users.csv -roles_file = roles.csv -role_memberships_file = role_memberships.csv +s3_bucket = #redshift-idc-unload +users_file = # users.csv +roles_file = # roles.csv +role_memberships_file = # role_memberships.csv diff --git a/src/RedshiftIDCMigrationUtility/idc_redshift_unload_indatabase_groups_roles_users.py b/src/RedshiftIDCMigrationUtility/idc_redshift_unload_indatabase_groups_roles_users.py index 46557bb3..e2e1339b 100644 --- a/src/RedshiftIDCMigrationUtility/idc_redshift_unload_indatabase_groups_roles_users.py +++ b/src/RedshiftIDCMigrationUtility/idc_redshift_unload_indatabase_groups_roles_users.py @@ -4,6 +4,7 @@ import logging import configparser from io import StringIO +from botocore.exceptions import ClientError # setup logging logging.basicConfig(level=logging.INFO) @@ -46,6 +47,29 @@ def validate_config(config): if param not in config[section]: raise ValueError(f"Missing configuration parameter: {section}.{param}") +def check_bucket_encryption(bucket_name): + try: + # Create S3 client + s3_client = boto3.client('s3') + + # Get bucket encryption configuration + response = s3_client.get_bucket_encryption(Bucket=bucket_name) + + # If we get here, bucket is encrypted + encryption_rules = response['ServerSideEncryptionConfiguration']['Rules'] + print(f"Bucket {bucket_name} is encrypted with configuration:") + print(encryption_rules) + return True + + except ClientError as e: + error_code = e.response['Error']['Code'] + if error_code == 'ServerSideEncryptionConfigurationNotFoundError': + print(f"Bucket {bucket_name} is not encrypted") + return False + else: + print(f"Error checking bucket encryption: {str(e)}") + raise + def get_redshift_credentials(config): """Get Redshift credentials based on cluster type.""" try: @@ -64,7 +88,7 @@ def get_redshift_credentials(config): credentials = client.get_cluster_credentials( DbUser=config['REDSHIFT']['db_user'], DbName=config['REDSHIFT']['db_name'], - ClusterIdentifier="redshift-serverless-"+config['REDSHIFT']['workgroup_name'] + ClusterIdentifier=f"redshift-serverless-{config['REDSHIFT']['workgroup_name']}" ) client = boto3.client('redshift-serverless', region_name=config['AWS']['region']) workgroup = client.get_workgroup(workgroupName=config['REDSHIFT']['workgroup_name']) @@ -102,7 +126,9 @@ def connect_to_redshift(config): user=creds["DbUser"], password=creds["DbPassword"], host=host, - port=config['REDSHIFT']['port'] + port=config['REDSHIFT']['port'], + sslmode='require', + timeout=None ) logger.info("Connected to Redshift successfully!") return conn @@ -154,6 +180,11 @@ def main(): config = load_config() validate_config(config) + # Validate if input bucket is encrypted + bucket_name = config['AWS']['s3_bucket'] + if check_bucket_encryption(bucket_name) is False: + logger.error(f"{bucket_name} is not encrypted. Please enable bucket encryption") + # Connect to Redshift conn = connect_to_redshift(config) if conn is None: diff --git a/src/RedshiftIDCMigrationUtility/redshift_unload.ini b/src/RedshiftIDCMigrationUtility/redshift_unload.ini index 3331ee6c..426b41fe 100644 --- a/src/RedshiftIDCMigrationUtility/redshift_unload.ini +++ b/src/RedshiftIDCMigrationUtility/redshift_unload.ini @@ -1,17 +1,18 @@ +# Example values are provided in the comments [REDSHIFT] -cluster_type = provisioned # Set to 'provisioned' for a provisioned cluster or 'serverless' for a serverless workgroup -cluster_id = redshift-cluster-1 # Required if cluster_type = provisioned -db_user = admin -db_name = dev -host = redshift-cluster-1.c0lwc6winfis.us-east-2.redshift.amazonaws.com # Required if cluster_type = provisioned -port = 5439 -workgroup_name = rs-serverless-wg-idctest # Required if cluster_type = serverless +cluster_type = # Set to 'provisioned' for a provisioned cluster or 'serverless' for a serverless workgroup +cluster_id = # e.gredshift-cluster-1. Required if cluster_type = provisioned +db_user = # admin +db_name = # dev +host = # redshift-cluster-1.c0lwc6winfis.us-east-2.redshift.amazonaws.com. Required if cluster_type = provisioned +port = # 5439 +workgroup_name = # rs-serverless-wg-idctest. Required if cluster_type = serverless [AWS] -region = us-east-2 -s3_bucket = redshift-idc-unload +region = #us-east-2 +s3_bucket = #redshift-idc-unload [S3_FILES] -roles = roles.csv -users = users.csv -role_memberships = role_memberships.csv +roles = # roles.csv +users = # users.csv +role_memberships = # role_memberships.csv From 5aa255ec1c1bb9865ae7fbc34fa767b2ae93808a Mon Sep 17 00:00:00 2001 From: sksonti Date: Thu, 26 Jun 2025 10:15:31 -0400 Subject: [PATCH 38/49] Updated readme and fixed reviewer comments. Fixed f string Added readme Add connection paramters Removed hardcoding in config Validating for empty input values Validating bucket encryption. --- src/RedshiftIDCMigrationUtility/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/src/RedshiftIDCMigrationUtility/README.md b/src/RedshiftIDCMigrationUtility/README.md index d88b6cc0..c1c81e83 100644 --- a/src/RedshiftIDCMigrationUtility/README.md +++ b/src/RedshiftIDCMigrationUtility/README.md @@ -44,6 +44,7 @@ Following are the pre-requisites before running the utility. * Select the application. Choose Actions→ Edit details. * Set “User and group assignments” to “Do not require assignments”. After Redshift-idc application is set up in above step, for testing purposes , edit the details of the application in Identity Center and chose user and group membership not required, so connectivity to Redshift can be tested even without data access * Enable Identity Center authentication with admin access from ec2 or cloud shell . https://docs.aws.amazon.com/sdkref/latest/guide/access-sso.html +* Create S3 bucket with server side encryption. Please ensure this bucket is accessible to only user/role that runs this script. If it is open for access by all, then other may be able to view access permissions. From b187d087ff7269573d67f0fd9b4a427c9ced32b2 Mon Sep 17 00:00:00 2001 From: sksonti Date: Thu, 26 Jun 2025 18:19:52 -0400 Subject: [PATCH 39/49] Added code to remove the S3 files --- .../idc_add_users_groups_roles_psets.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/RedshiftIDCMigrationUtility/idc_add_users_groups_roles_psets.py b/src/RedshiftIDCMigrationUtility/idc_add_users_groups_roles_psets.py index 03e1a114..16386d7c 100644 --- a/src/RedshiftIDCMigrationUtility/idc_add_users_groups_roles_psets.py +++ b/src/RedshiftIDCMigrationUtility/idc_add_users_groups_roles_psets.py @@ -245,6 +245,14 @@ def process_role_memberships(config, aws_clients, user_ids, role_ids): add_user_to_group(aws_clients['identity_store'], identity_store_id, user_id, role_id) +def delete_s3_file(bucket_name, file_key): + s3_client = boto3.client('s3') + try: + s3_client.delete_object(Bucket=bucket_name, Key=file_key) + logger.info(f"Deleted file {file_key} from bucket {bucket_name}") + except Exception as e: + logger.error(f"Error deleting file {file_key} from bucket {bucket_name}: {e}") + def main(): try: config = load_configuration() @@ -263,6 +271,11 @@ def main(): user_ids = process_users(config, aws_clients) role_ids = process_roles(config, aws_clients, assign_permission_set=assign_permission_set) process_role_memberships(config, aws_clients, user_ids, role_ids) + delete_s3_file(config.get('S3', 's3_bucket'), config.get('S3', 'users_file')) + delete_s3_file(config.get('S3', 's3_bucket'), config.get('S3', 'roles_file')) + delete_s3_file(config.get('S3', 's3_bucket'), config.get('S3', 'role_memberships_file')) + logger.info("IDC Migration Utility execution completed successfully.") + if __name__ == "__main__": main() From b0e384a9685e302a65991ed65fa020bd34630bd2 Mon Sep 17 00:00:00 2001 From: sksonti Date: Thu, 26 Jun 2025 19:56:26 -0400 Subject: [PATCH 40/49] Updated to include application name --- ...edshift_unload_indatabase_groups_roles_users.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/RedshiftIDCMigrationUtility/idc_redshift_unload_indatabase_groups_roles_users.py b/src/RedshiftIDCMigrationUtility/idc_redshift_unload_indatabase_groups_roles_users.py index e2e1339b..8d555012 100644 --- a/src/RedshiftIDCMigrationUtility/idc_redshift_unload_indatabase_groups_roles_users.py +++ b/src/RedshiftIDCMigrationUtility/idc_redshift_unload_indatabase_groups_roles_users.py @@ -147,6 +147,16 @@ def fetch_data_from_redshift(conn, query): except Exception as e: logger.error(f"Error fetching data: {e}") return None, None + +def run_rs_query(conn, query): + try: + cursor = conn.cursor() + cursor.execute(query) + cursor.close() + return True + except Exception as e: + logger.error(f"Error running query: {e}") + return None def write_to_s3(data, cursor_description, s3_key, config): try: @@ -191,6 +201,10 @@ def main(): logger.error("Failed to connect to Redshift. Exiting program.") return + # Setting application name + query_setapp = "set application_name to 'RedshiftIDCIMigrationUtility'" + run_rs_query(conn, query_setapp) + # SQL Queries (common to both) query_roles = """ select groname from pg_group From 05a7c8b8b8deb5c0c89277a5ccdecef3a9b6a5f7 Mon Sep 17 00:00:00 2001 From: sksonti Date: Thu, 26 Jun 2025 20:16:43 -0400 Subject: [PATCH 41/49] Updated delete function --- .../idc_add_users_groups_roles_psets.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/RedshiftIDCMigrationUtility/idc_add_users_groups_roles_psets.py b/src/RedshiftIDCMigrationUtility/idc_add_users_groups_roles_psets.py index 16386d7c..6ef82910 100644 --- a/src/RedshiftIDCMigrationUtility/idc_add_users_groups_roles_psets.py +++ b/src/RedshiftIDCMigrationUtility/idc_add_users_groups_roles_psets.py @@ -271,12 +271,12 @@ def main(): user_ids = process_users(config, aws_clients) role_ids = process_roles(config, aws_clients, assign_permission_set=assign_permission_set) process_role_memberships(config, aws_clients, user_ids, role_ids) - delete_s3_file(config.get('S3', 's3_bucket'), config.get('S3', 'users_file')) - delete_s3_file(config.get('S3', 's3_bucket'), config.get('S3', 'roles_file')) - delete_s3_file(config.get('S3', 's3_bucket'), config.get('S3', 'role_memberships_file')) - logger.info("IDC Migration Utility execution completed successfully.") - if __name__ == "__main__": - main() - + try: + main() + finally: + delete_s3_file(config.get('S3', 's3_bucket'), config.get('S3', 'users_file')) + delete_s3_file(config.get('S3', 's3_bucket'), config.get('S3', 'roles_file')) + delete_s3_file(config.get('S3', 's3_bucket'), config.get('S3', 'role_memberships_file')) + logger.info("IDC Migration Utility execution completed successfully.") From b16de0b23dd456a003cd807f9cf6613fdb761d63 Mon Sep 17 00:00:00 2001 From: sksonti Date: Thu, 26 Jun 2025 20:17:39 -0400 Subject: [PATCH 42/49] UPdated delete function --- .../idc_add_users_groups_roles_psets.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/RedshiftIDCMigrationUtility/idc_add_users_groups_roles_psets.py b/src/RedshiftIDCMigrationUtility/idc_add_users_groups_roles_psets.py index 6ef82910..d508b962 100644 --- a/src/RedshiftIDCMigrationUtility/idc_add_users_groups_roles_psets.py +++ b/src/RedshiftIDCMigrationUtility/idc_add_users_groups_roles_psets.py @@ -274,6 +274,7 @@ def main(): if __name__ == "__main__": try: + config = load_configuration() main() finally: delete_s3_file(config.get('S3', 's3_bucket'), config.get('S3', 'users_file')) From b7f747fd8e0f426fb9ccf7ed46834183f8dad2b2 Mon Sep 17 00:00:00 2001 From: Adam Gatt Date: Thu, 31 Jul 2025 15:36:50 +0100 Subject: [PATCH 43/49] First version of the Redshift to Lake Formation migration utility --- src/.DS_Store | Bin 12292 -> 12292 bytes src/LakeFormationMigrationUtility/README.md | 235 ++++ .../src/config.ini | 24 + .../src/old/create_redshift_idc_users.py | 279 +++++ .../src/old/redshift_users_to_iam.py | 265 +++++ .../src/rs_privs_to_lf.py | 1034 +++++++++++++++++ .../cleanup_script_generator.py | 466 ++++++++ .../tests/integration_test/int_readme.md | 154 +++ .../integration_test/int_unified_cleanup.py | 214 ++++ .../integration_test/test_int_config.ini | 26 + .../test_int_redshift_to_lakeformation.py | 622 ++++++++++ .../tests/performance_test/perf_readme.md | 199 ++++ .../performance_test/perf_unified_cleanup.py | 138 +++ .../performance_test/test_perf_config.ini | 31 + .../test_perf_redshift_to_lakeformation.py | 427 +++++++ 15 files changed, 4114 insertions(+) create mode 100644 src/LakeFormationMigrationUtility/README.md create mode 100644 src/LakeFormationMigrationUtility/src/config.ini create mode 100644 src/LakeFormationMigrationUtility/src/old/create_redshift_idc_users.py create mode 100644 src/LakeFormationMigrationUtility/src/old/redshift_users_to_iam.py create mode 100644 src/LakeFormationMigrationUtility/src/rs_privs_to_lf.py create mode 100644 src/LakeFormationMigrationUtility/tests/integration_test/cleanup_script_generator.py create mode 100644 src/LakeFormationMigrationUtility/tests/integration_test/int_readme.md create mode 100644 src/LakeFormationMigrationUtility/tests/integration_test/int_unified_cleanup.py create mode 100644 src/LakeFormationMigrationUtility/tests/integration_test/test_int_config.ini create mode 100644 src/LakeFormationMigrationUtility/tests/integration_test/test_int_redshift_to_lakeformation.py create mode 100644 src/LakeFormationMigrationUtility/tests/performance_test/perf_readme.md create mode 100644 src/LakeFormationMigrationUtility/tests/performance_test/perf_unified_cleanup.py create mode 100644 src/LakeFormationMigrationUtility/tests/performance_test/test_perf_config.ini create mode 100644 src/LakeFormationMigrationUtility/tests/performance_test/test_perf_redshift_to_lakeformation.py diff --git a/src/.DS_Store b/src/.DS_Store index 8e507b3aa992bb3f38be83091318a04160142a2f..4f19f00a2e5edf00effcb58000281a3c32463627 100644 GIT binary patch delta 530 zcmZokXi1phFB-tWz`)GFAi%(o&5+9A#*oiY#E?5#kWqQEfeuSJBT$wFh-Ddk7!r|H z0C^=0nLyQf48A}*9jFT-5(<{f0g9I}ROaTVxFqG|Cjm|2$Pj-ecwP3mK5UQB7?DPB&NXE%U`3o?XmX4cRiTyEonyNv+=kp_4z delta 128 zcmZokXi1phFY3dz>% diff --git a/src/LakeFormationMigrationUtility/README.md b/src/LakeFormationMigrationUtility/README.md new file mode 100644 index 00000000..f23411b7 --- /dev/null +++ b/src/LakeFormationMigrationUtility/README.md @@ -0,0 +1,235 @@ +# Redshift Permissions to Lake Formation Migration Utility + +A Python script that extracts permissions from Amazon Redshift (datashares or local databases) and generates AWS Lake Formation permission commands for seamless migration to a SageMaker Lakehouse architecture. + +## Overview + +This tool automates the migration of data access permissions from Amazon Redshift to AWS Lake Formation by: +- Extracting user permissions from Redshift datashare databases or local databases +- Analyzing table-level grants using `SHOW GRANTS` +- Generating AWS CLI commands for Lake Formation permissions +- Supporting AWS Identity Center (IDC) authentication +- Creating rollback scripts for permission cleanup + +## Features + +- **Identity Center Authentication**: Supports AWS Identity Center (IDC) users/groups +- **Permission Granularity**: Schema-level or table-level permissions based on configuration +- **Role Inheritance**: Handles IDC roles with granted Redshift roles. This includes Redshift roles that have been granted permissions via other Redshift roles. +- **Automated Scripts**: Generates executable bash scripts with AWS CLI commands +- **Rollback Support**: Creates corresponding rollback scripts for permission cleanup +- **Debug Mode**: Provides detailed logging and user ID lookup commands + +## Prerequisites + +- Python 3.6+ +- Required Python packages: `psycopg2`, `configparser`, `boto3` +- The Redshift cluster must use AWS Identity Center (IDC) authentication. Use the [RedshiftIDCMigrationUtility](https://github.com/awslabs/amazon-redshift-utils/tree/master/src/RedshiftIDCMigrationUtility) for migrating from Redshift local users and groups/roles. +- An AWS IAM user with an access key to allow programmatic calls to AWS from the AWS CLI +- AWS CLI configured with appropriate permissions +- Admin access to Amazon Redshift cluster with Redshift authentification details stored in AWS Secret Manager +- Lake Formation permissions to grant/revoke access +- A Glue Data Catalog created from the Redshift producer cluster. See [Registering a cluster to the AWS Glue Data Catalog](https://docs.aws.amazon.com/redshift/latest/mgmt/register-cluster.html) + +## Installation + +1. Install dependencies: +```bash +pip install psycopg2-binary configparser boto3 +``` + +2. Configure AWS CLI (if not already done): +```bash +aws configure +``` + +## Configuration + +Create a `config.ini` file with the following structure: + +```ini +[redshift] +host = your-redshift-cluster.region.redshift.amazonaws.com +port = 5439 +dbname = your-database-name +# AWS Secrets Manager secret containing Redshift credentials +secret_name = redshift/credentials + +[aws] +account_id = 123456789012 +region = us-east-1 +producer_catalog = your-producer-catalog-name +# AWS CLI profile to use (optional) +config_profile = your-aws-profile +# Identity Store ID for IDC user lookups +identity_store_id = d-1234567890 + +[parameters] +# Permission source: 'datashare' for datashare permissions, 'local' for local database permissions +permissions_type = datashare +datashare_database_name = your_datashare_db +# Set to true if the datashare database was created with the 'WITH PERMISSIONS' clause +datashare_object_level_permissions = true +``` + +### Configuration Parameters + +#### Redshift Section +- `host`: Redshift cluster endpoint +- `port`: Port number (default: 5439) +- `dbname`: Database name to connect to +- `secret_name`: AWS Secrets Manager secret name containing Redshift credentials (must contain 'username' and 'password' keys) + +#### AWS Section +- `account_id`: AWS account ID for Lake Formation +- `region`: AWS region for API calls (used for Secrets Manager) +- `producer_catalog`: Producer catalog name in Lake Formation + +- `config_profile`: AWS CLI profile name (optional, used for both AWS CLI and boto3) +- `identity_store_id`: Identity Store ID (required) + +#### Parameters Section +- `permissions_type`: Permission source - `datashare` for datashare permissions, `local` for local database permissions +- `datashare_database_name`: Specific datashare database to process (used when permissions_type = datashare) +- `datashare_object_level_permissions`: Enable table-level permissions for datashare mode (`true`/`false`). Use true if the datashare was created 'WITH PERMISSIONS' (used when permissions_type = datashare) + + +## Usage + +**Note**: If `python` command doesn't work, try using `python3` instead. + +### Basic Usage + +```bash +python rs_privs_to_lf.py +``` + +### With Custom Config File + +```bash +python rs_privs_to_lf.py --config /path/to/config.ini +``` + +### With Custom Output Directory + +```bash +python rs_privs_to_lf.py --output-dir /path/to/output +``` + +### Debug Mode + +```bash +python rs_privs_to_lf.py --debug +``` + +### Command Line Options + +- `--config, -c`: Path to configuration file (default: `config.ini`) +- `--output-dir, -o`: Base directory for generated scripts (default: `output`) +- `--debug`: Enable debug output and generate user ID lookup commands + +## Authentication + +### Identity Center Authentication +- Processes only users/roles prefixed with the identity provider namespace (automatically detected from SVV_IDENTITY_PROVIDERS) +- Looks up actual IDC user/group IDs using AWS CLI +- Generates ARNs in format: `arn:aws:identitystore:::user/USER_ID` or `arn:aws:identitystore:::group/GROUP_ID` +- Handles role inheritance from granted Redshift roles in both datashare and local modes + +## Permission Sources + +### Datashare Permissions (`permissions_type = datashare`) +- Extracts permissions from Redshift datashare databases +- Uses `datashare_database_name` parameter to specify target datashare +- Processes users with USAGE permissions on datashare databases +- Uses `SHOW GRANTS` for table-level permission analysis + +### Local Database Permissions (`permissions_type = local`) +- Extracts permissions from the local Redshift database (specified in `dbname`) +- Finds IDC users and roles with table-level permissions on local database tables +- Excludes system schemas (`information_schema`, `pg_catalog`, `pg_internal`) +- Supports IDC role inheritance (roles granted to IDC roles) +- Uses `SHOW GRANTS` for table-level permission analysis +- Ignores `datashare_database_name` and `datashare_object_level_permissions` parameters + +## Permission Modes + +### Schema-Level Permissions (`datashare_object_level_permissions = false`) +- Grants `SELECT` and `DESCRIBE` permissions on all tables in each schema +- Uses `TableWildcard` syntax for efficient bulk permissions +- Based on database `USAGE` permissions + +### Table-Level Permissions (`datashare_object_level_permissions = true`) +- **Datashare mode**: Analyzes individual table grants using `SHOW GRANTS` +- **Local mode**: Uses `SHOW GRANTS` for table-level permission analysis +- Preserves specific permissions (`SELECT`, `INSERT`, `UPDATE`, `DELETE`) +- Automatically adds `DESCRIBE` permission +- Filters out unsupported Lake Formation permissions (`RULE`, `TRIGGER`, etc.) +- Handles IDC role inheritance in both modes + +## Output Files + +The script generates timestamped files in the output directory: + +### Generated Scripts +- `lakeformation_permissions_YYYYMMDD_HHMMSS.sh`: Main permission grant script +- `rollback_lakeformation_YYYYMMDD_HHMMSS.sh`: Rollback script to revoke permissions +- `get_user_id_commands_YYYYMMDD_HHMMSS.sh`: Debug script for IDC user ID lookups (debug mode only) + +### Script Structure +```bash +#!/bin/bash + +# AWS LakeFormation permission commands generated from Redshift datashare permissions +# Generated on: 2024-01-15 10:30:45 +# Authentication type: IDC +# Object-level permissions: true + +aws lakeformation grant-permissions \ + --catalog-id "123456789012" \ + --principal DataLakePrincipalIdentifier=arn:aws:identitystore:::user/12345678-1234-1234-1234-123456789012 \ + --resource '{"Table": {"CatalogId": "123456789012:producer-catalog", "DatabaseName": "schema_name", "Name": "table_name"}}' \ + --permissions "SELECT" "DESCRIBE" +``` + +## Error Handling + +The script includes comprehensive error handling for: +- Missing configuration parameters +- Redshift connection failures +- AWS CLI command failures +- Missing user/group IDs in Identity Center +- Invalid table grants + +## Troubleshooting + +### Common Issues + +1. **Connection Errors**: Verify Redshift credentials and network connectivity +2. **Missing User IDs**: Ensure Identity Center users exist and are properly named +3. **Permission Denied**: Verify AWS CLI permissions for Lake Formation operations +4. **Empty Results**: + - **Datashare mode**: Check datashare database names and user permissions + - **Local mode**: Verify you're connected to the correct cluster and database + - Ensure identity provider namespace prefixed Redshift users/roles exist +5. **No Tables Found**: + - **Local mode**: Confirm tables exist in non-system schemas + - Check if you're connected to the intended Redshift cluster + +### Debug Mode +Enable debug mode to see: +- Current database connection details +- Available schemas in the database +- Detailed user and table information +- Sample table grants +- User ID lookup commands for Identity Center authentication +- Query execution details for troubleshooting + +## Security Considerations + +- Use least-privilege IAM policies +- Review generated scripts before execution +- Test in non-production environments first +- Ensure your AWS Secrets Manager secret contains the keys 'username' and 'password' +- The IAM role/user running the script needs secretsmanager:GetSecretValue permission + diff --git a/src/LakeFormationMigrationUtility/src/config.ini b/src/LakeFormationMigrationUtility/src/config.ini new file mode 100644 index 00000000..d94bce0d --- /dev/null +++ b/src/LakeFormationMigrationUtility/src/config.ini @@ -0,0 +1,24 @@ +# Example values provided +[redshift] +host = your-redshift-cluster.region.redshift.amazonaws.com +port = 5439 +dbname = your-database-name +# AWS Secrets Manager secret containing Redshift credentials +secret_name = your-secret-name + +[aws] +account_id = 123456789012 +region = us-east-1 +producer_catalog = your-producer-catalog-name +# AWS CLI profile to use (optional) +config_profile = your-aws-cli-profile +# Identity Store ID for IDC user lookups +identity_store_id = d-1234567890 + +[parameters] +# Permission source: 'datashare' for datashare permissions, 'local' for local database permissions +permissions_type = local +# Name of database on the consumer cluster created from the datashare +datashare_database_name = your_datashare_db +# Set to true if the datashare database was created with the 'WITH PERMISSIONS' clause +datashare_object_level_permissions = true \ No newline at end of file diff --git a/src/LakeFormationMigrationUtility/src/old/create_redshift_idc_users.py b/src/LakeFormationMigrationUtility/src/old/create_redshift_idc_users.py new file mode 100644 index 00000000..4ccec548 --- /dev/null +++ b/src/LakeFormationMigrationUtility/src/old/create_redshift_idc_users.py @@ -0,0 +1,279 @@ +#!/usr/bin/env python3 +""" +Create Redshift IDC users script + +This script: +1. Connects to Redshift +2. Gets all local users (without IAM:/IAMR:/AWSIDC: prefixes) +3. Maps them to IAM IDC to get their email addresses +4. Creates Redshift CLI commands to create IDC users via get-cluster-credentials +""" + +import os +import sys +import psycopg2 +import argparse +import configparser +import subprocess +import json +from datetime import datetime + +def load_config(config_file='config.ini'): + """Load configuration from config file""" + if not os.path.exists(config_file): + print(f"Error: Config file '{config_file}' not found") + sys.exit(1) + + config = configparser.ConfigParser() + try: + config.read(config_file) + return config + except Exception as e: + print(f"Error reading config file: {e}") + sys.exit(1) + +def connect_to_redshift(config): + """Establish connection to Redshift database using config""" + try: + redshift_config = config['redshift'] + conn = psycopg2.connect( + host=redshift_config['host'], + port=int(redshift_config.get('port', 5439)), + dbname=redshift_config['dbname'], + user=redshift_config['user'], + password=redshift_config['password'] + ) + print(f"Connected to Redshift database: {redshift_config['dbname']}") + return conn + except Exception as e: + print(f"Error connecting to Redshift: {e}") + sys.exit(1) + +def get_local_redshift_users(conn): + """Get local Redshift users (excluding IAM/IAMR/AWSIDC prefixed users)""" + try: + cursor = conn.cursor() + cursor.execute(""" + SELECT usename + FROM pg_user + WHERE usesuper = 'f' + AND usename != 'rdsdb' + AND NOT (usename LIKE 'IAM:%' OR usename LIKE 'IAMR:%' OR usename LIKE 'AWSIDC:%') + ORDER BY usename + """) + + users = [row[0] for row in cursor.fetchall()] + cursor.close() + print(f"Found {len(users)} local Redshift users") + return users + except Exception as e: + print(f"Error retrieving users from Redshift: {e}") + sys.exit(1) + +def get_idc_user_id(username, identity_store_id, config_profile=None): + """Get IDC user ID using AWS CLI get-user-id command""" + try: + # Create the JSON string for alternate-identifier + alternate_identifier = json.dumps({"UniqueAttribute": {"AttributePath": "UserName", "AttributeValue": username}}) + + cmd = ['aws'] + if config_profile: + cmd.extend(['--profile', config_profile]) + cmd.extend([ + 'identitystore', 'get-user-id', + '--identity-store-id', identity_store_id, + '--alternate-identifier', alternate_identifier + ]) + + print(f" Executing command: {' '.join(cmd)}") + result = subprocess.run(cmd, capture_output=True, text=True) + if result.returncode != 0: + print(f"Warning: Could not get user ID for {username}: {result.stderr}") + return None + + response = json.loads(result.stdout) + user_id = response.get('UserId') + if user_id: + print(f"Found IDC user ID for {username}: {user_id}") + return user_id + else: + print(f"Warning: No user ID found for {username}") + return None + + except Exception as e: + print(f"Warning: Error getting IDC user ID for {username}: {e}") + return None + +def get_idc_user_email(user_id, identity_store_id, config_profile=None): + """Get IDC user email using user ID""" + try: + cmd = ['aws'] + if config_profile: + cmd.extend(['--profile', config_profile]) + cmd.extend([ + 'identitystore', 'describe-user', + '--identity-store-id', identity_store_id, + '--user-id', user_id + ]) + + result = subprocess.run(cmd, capture_output=True, text=True) + if result.returncode != 0: + print(f"Warning: Could not get user details for user ID {user_id}: {result.stderr}") + return None + + user_details = json.loads(result.stdout) + emails = user_details.get('Emails', []) + + if emails: + primary_email = next((email['Value'] for email in emails if email.get('Primary', False)), emails[0]['Value']) + print(f"Found email for user ID {user_id}: {primary_email}") + return primary_email + else: + print(f"Warning: No email found for user ID {user_id}") + return None + + except Exception as e: + print(f"Warning: Error getting IDC user email for user ID {user_id}: {e}") + return None + +def generate_get_cluster_credentials_command(username, email, cluster_identifier, config_profile=None): + """Generate get-cluster-credentials command""" + profile_param = f" --profile {config_profile}" if config_profile else "" + + # The IDC user will be created as AWSIDC:email + idc_username = f"AWSIDC:{email}" + + command = f"aws{profile_param} redshift get-cluster-credentials \\\n" + command += f" --cluster-identifier {cluster_identifier} \\\n" + command += f" --db-user {email} \\\n" + command += f" --duration-seconds 3600 \\\n" + command += f" --auto-create" + + return command, idc_username + +def generate_commands(local_users, user_emails, cluster_identifier, config_profile=None, output_dir=None): + """Generate all the Redshift CLI commands""" + timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") + + if output_dir: + if not os.path.exists(output_dir): + os.makedirs(output_dir) + script_filepath = os.path.join(output_dir, f"create_redshift_idc_users_{timestamp}.sh") + else: + script_filepath = f"create_redshift_idc_users_{timestamp}.sh" + + with open(script_filepath, 'w') as script_file: + script_file.write("#!/bin/bash\n\n") + script_file.write("# Redshift get-cluster-credentials commands to create IDC users\n") + script_file.write(f"# Generated on: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n") + script_file.write("# These commands will create AWSIDC: prefixed users in Redshift\n\n") + + commands_generated = 0 + + for username in local_users: + email = user_emails.get(username) + if email: + command, idc_username = generate_get_cluster_credentials_command( + username, email, cluster_identifier, config_profile + ) + + script_file.write(f"# Local user: {username} -> IDC user: {idc_username}\n") + script_file.write(f"{command}\n\n") + commands_generated += 1 + else: + script_file.write(f"# Warning: No email found for user {username}, skipping\n\n") + + if commands_generated == 0: + script_file.write("echo \"No valid user mappings found to create IDC users.\"\n") + + # Make the file executable + os.chmod(script_filepath, 0o755) + + print(f"Generated {commands_generated} get-cluster-credentials commands in file: {script_filepath}") + return script_filepath + +def main(): + parser = argparse.ArgumentParser(description='Create Redshift IDC users from local Redshift users') + + parser.add_argument('--config', '-c', default='config.ini', help='Path to config file (default: config.ini)') + parser.add_argument('--output-dir', '-o', help='Directory to save generated scripts') + parser.add_argument('--debug', action='store_true', help='Enable debug output') + + args = parser.parse_args() + + # Load configuration + config = load_config(args.config) + + # Get required config values + try: + identity_store_id = config.get('aws', 'identity_store_id') + workgroup_name = config.get('redshift', 'host').split('.')[0] # Extract workgroup name from host + cluster_identifier = f"redshift-serverless-{workgroup_name}" + config_profile = config.get('aws', 'config_profile', fallback=None) + except Exception as e: + print(f"Error reading required configuration: {e}") + sys.exit(1) + + # Connect to Redshift + conn = connect_to_redshift(config) + + # Get local Redshift users + local_users = get_local_redshift_users(conn) + + # Close connection + conn.close() + + if not local_users: + print("No local Redshift users found to process") + return + + # Map users to their IDC email addresses + print(f"\nMapping {len(local_users)} users to IDC email addresses...") + user_emails = {} + + for username in local_users: + print(f"\nProcessing user: {username}") + print(f" Looking up in Identity Store: {identity_store_id}") + print(f" Using profile: {config_profile or 'default'}") + + # First get the user ID + user_id = get_idc_user_id(username, identity_store_id, config_profile) + if user_id: + print(f" Found user ID: {user_id}") + # Then get the email using the user ID + email = get_idc_user_email(user_id, identity_store_id, config_profile) + if email: + user_emails[username] = email + print(f" Successfully mapped: {username} -> {email}") + else: + print(f" Failed to get email for user ID: {user_id}") + else: + print(f" User '{username}' not found in Identity Center") + print(f" This means '{username}' does not exist as an IDC user") + print(f" You may need to create this user in Identity Center first") + + print(f"\nSummary: Successfully mapped {len(user_emails)} out of {len(local_users)} users to email addresses") + + if len(user_emails) == 0: + print("\nNo users were successfully mapped. This could mean:") + print(" 1. The local Redshift users don't exist in Identity Center") + print(" 2. The Identity Store ID is incorrect") + print(" 3. The AWS profile doesn't have permission to access Identity Center") + print(" 4. The usernames in Redshift don't match the usernames in Identity Center") + + if args.debug or len(user_emails) > 0: + print("\nUser mappings:") + for username, email in user_emails.items(): + print(f" {username} -> {email}") + + if len(user_emails) < len(local_users): + unmapped = set(local_users) - set(user_emails.keys()) + print("\nUnmapped users:") + for username in unmapped: + print(f" {username} (not found in Identity Center)") + + # Generate commands + generate_commands(local_users, user_emails, cluster_identifier, config_profile, args.output_dir) + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/src/LakeFormationMigrationUtility/src/old/redshift_users_to_iam.py b/src/LakeFormationMigrationUtility/src/old/redshift_users_to_iam.py new file mode 100644 index 00000000..450fe2d6 --- /dev/null +++ b/src/LakeFormationMigrationUtility/src/old/redshift_users_to_iam.py @@ -0,0 +1,265 @@ +import os +import sys +import psycopg2 +import argparse +import configparser +import re +import shlex +import secrets +import string +from datetime import datetime + +def load_config(config_file='config.ini'): + """ + Load configuration from config file (default: config.ini) + """ + if not os.path.exists(config_file): + print(f"Error: Config file '{config_file}' not found") + sys.exit(1) + + config = configparser.ConfigParser() + try: + config.read(config_file) + print(f"Loaded configuration from {config_file}") + return config + except Exception as e: + print(f"Error reading config file: {e}") + sys.exit(1) + +def connect_to_redshift(config): + """ + Establish connection to Redshift database using config + """ + try: + redshift_config = config['redshift'] + conn = psycopg2.connect( + host=redshift_config['host'], + port=int(redshift_config.get('port', 5439)), + dbname=redshift_config['dbname'], + user=redshift_config['user'], + password=redshift_config['password'] + ) + print(f"Connected to Redshift database: {redshift_config['dbname']}") + return conn + except KeyError as e: + print(f"Missing required configuration parameter: {e}") + sys.exit(1) + except Exception as e: + print(f"Error connecting to Redshift: {e}") + sys.exit(1) + +def get_redshift_users(conn): + """ + Get users from pg_user catalog table in Redshift, filtering out IAM/IAMR users in SQL + """ + users = [] + try: + cursor = conn.cursor() + # Query to get usernames from pg_user with filtering in SQL + cursor.execute(""" + SELECT usename + FROM pg_user + WHERE usesuper = 'f' + AND usename != 'rdsdb' + AND NOT (usename LIKE 'IAM:%' OR usename LIKE 'IAMR:%' OR usename LIKE 'AWSIDC:%') + ORDER BY 1; + """) + + for row in cursor: + users.append(row[0]) + + cursor.close() + print(f"Retrieved {len(users)} non-IAM users from Redshift") + return users + except Exception as e: + print(f"Error retrieving users from Redshift: {e}") + conn.close() + sys.exit(1) + +def generate_secure_password(length=16): + """ + Generate a secure random password + """ + # Include at least one of each required character type for AWS IAM password policy + letters = string.ascii_letters + digits = string.digits + special_chars = "!@#" + "$" + "%^&*()_+-=[]{}|" # Avoid escape sequence issues + password_chars = letters + digits + special_chars + + # Ensure we have at least one uppercase, one lowercase, one digit, and one special character + password = [ + secrets.choice(string.ascii_uppercase), + secrets.choice(string.ascii_lowercase), + secrets.choice(string.digits), + secrets.choice(special_chars) + ] + + # Fill the rest of the password length with random characters + password.extend(secrets.choice(password_chars) for _ in range(length - 4)) + + # Shuffle the password characters + secrets.SystemRandom().shuffle(password) + + return ''.join(password) + +def generate_iam_cli_command(username): + """ + Generate AWS CLI command to create an IAM user with proper escaping + """ + # Ensure IAM username follows IAM naming rules (alphanumeric, plus '+', '=', ',', '.', '@', '-', '_') + valid_username = re.sub(r'[^a-zA-Z0-9+=,.@\-_]', '-', username) + + # Truncate if username exceeds IAM's 64-character limit + if len(valid_username) > 64: + valid_username = valid_username[:64] + print(f"Warning: Username truncated to {valid_username} due to IAM 64-character limit") + + # Escape the original username for shell safety + escaped_original = shlex.quote(username) + + # Generate AWS CLI command with properly formatted tags + cli_command = f'aws iam create-user --user-name {valid_username} ' \ + f'--tags Key=Source,Value=Redshift Key=OriginalRedshiftUsername,Value={escaped_original}' + + return cli_command, valid_username + +def generate_policy_attachment_commands(username, policies): + """ + Generate AWS CLI commands to attach policies to an IAM user + """ + commands = [] + for policy in policies: + commands.append(f'aws iam attach-user-policy --user-name {username} --policy-arn {policy}') + return commands + +def generate_console_access_command(username): + """ + Generate AWS CLI command to create console access with password change required + """ + password = generate_secure_password() + + # Create login profile command with password reset required + command = f'aws iam create-login-profile --user-name {username} ' \ + f'--password "{password}" --password-reset-required' + + return command + +def generate_commands(redshift_users, create_console_password=True): + """ + Generate all the AWS CLI commands for IAM users + """ + commands = [] + + # List of IAM policies to attach to each user + iam_policies = [ + 'arn:aws:iam::aws:policy/AmazonRedshiftReadOnlyAccess', + 'arn:aws:iam::aws:policy/AmazonRedshiftQueryEditorV2ReadWriteSharing', + # Add more policy ARNs as needed + ] + + # Generate header comments + commands.append("#!/bin/bash\n") + commands.append("# AWS CLI Commands to create IAM users from Redshift users") + commands.append("# Generated script for creating IAM users from Redshift users") + commands.append("# Consider checking for existing IAM users first with: aws iam list-users\n") + + if create_console_password: + commands.append("# NOTE: Console access passwords are randomly generated and users will be required to change them on first login\n") + + if not redshift_users: + commands.append("echo \"No eligible Redshift users found to create IAM users.\"") + + for username in redshift_users: + # Create user command + cli_command, valid_username = generate_iam_cli_command(username) + commands.append(cli_command) + + # Create console access command only if requested + if create_console_password: + console_command = generate_console_access_command(valid_username) + commands.append(console_command) + + # Generate policy attachment commands if policies are specified + if iam_policies: + for policy_command in generate_policy_attachment_commands(valid_username, iam_policies): + commands.append(policy_command) + commands.append("") # Add a blank line for readability + + # Add some follow-up commands information + if redshift_users: + commands.append("\n# After creating users, you might want to add additional policies") + commands.append("# Example: aws iam attach-user-policy --user-name USERNAME --policy-arn POLICY_ARN") + commands.append("# To check if users were created: aws iam list-users") + + if create_console_password: + commands.append("# To check users with console access: aws iam list-users | jq '.Users[] | select(has(\"PasswordLastUsed\"))'") + + return commands + +def write_to_file(commands, output_dir=None): + """ + Write commands to a file in the specified output directory + """ + timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") + + if output_dir: + if not os.path.exists(output_dir): + os.makedirs(output_dir) + script_filepath = os.path.join(output_dir, f"create_iam_users_{timestamp}.sh") + else: + script_filepath = f"create_iam_users_{timestamp}.sh" + + with open(script_filepath, 'w') as script_file: + for command in commands: + script_file.write(f"{command}\n") + + # Make the file executable + os.chmod(script_filepath, 0o755) + + print(f"Generated AWS CLI commands in file: {script_filepath}") + return script_filepath + +def main(): + """ + Main function to process Redshift users and generate AWS IAM commands + """ + parser = argparse.ArgumentParser(description='Generate AWS CLI commands to create IAM users from Redshift users.') + + parser.add_argument('--config', '-c', default='config.ini', help='Path to config file (default: config.ini)') + parser.add_argument('--output-dir', '-o', help='Directory to save generated scripts') + parser.add_argument('--no-console', action='store_true', help='Do not create console access for users') + parser.add_argument('--debug', action='store_true', help='Enable debug output') + + args = parser.parse_args() + + try: + # Load configuration + config = load_config(args.config) + + # Connect to Redshift + conn = connect_to_redshift(config) + + # Get Redshift users (with SQL filtering) + redshift_users = get_redshift_users(conn) + + # Close the connection + conn.close() + + if args.debug: + print("\nRedshift users found:") + for user in redshift_users: + print(f" {user}") + print() + + # Generate commands + commands = generate_commands(redshift_users, not args.no_console) + + # Write commands to file + write_to_file(commands, args.output_dir) + + except Exception as e: + print(f"Error in main process: {e}") + sys.exit(1) + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/src/LakeFormationMigrationUtility/src/rs_privs_to_lf.py b/src/LakeFormationMigrationUtility/src/rs_privs_to_lf.py new file mode 100644 index 00000000..c465a7a1 --- /dev/null +++ b/src/LakeFormationMigrationUtility/src/rs_privs_to_lf.py @@ -0,0 +1,1034 @@ +import os +import sys +import psycopg2 +import argparse +import configparser +import subprocess +import json +import boto3 +from datetime import datetime + +def load_config(config_file='config.ini'): + """ + Load configuration from config file (default: config.ini) + """ + if not os.path.exists(config_file): + print(f"Error: Config file '{config_file}' not found") + sys.exit(1) + + config = configparser.ConfigParser() + try: + config.read(config_file) + return config + except Exception as e: + print(f"Error reading config file: {e}") + sys.exit(1) + +def get_secret(secret_name, region_name=None, config_profile=None): + """ + Retrieve a secret from AWS Secrets Manager + """ + try: + # Create a Boto3 session with the specified profile if provided + session_kwargs = {} + if config_profile: + session_kwargs['profile_name'] = config_profile + session = boto3.session.Session(**session_kwargs) + + # Create a Secrets Manager client + client_kwargs = {} + if region_name: + client_kwargs['region_name'] = region_name + client = session.client('secretsmanager', **client_kwargs) + + # Get the secret value + response = client.get_secret_value(SecretId=secret_name) + + # Parse the secret JSON string + if 'SecretString' in response: + secret = json.loads(response['SecretString']) + return secret + else: + print("Error: Secret value is not a string") + sys.exit(1) + except Exception as e: + print(f"Error retrieving secret from AWS Secrets Manager: {e}") + sys.exit(1) + +def connect_to_redshift(config): + """ + Establish connection to Redshift database using config and AWS Secrets Manager + """ + try: + redshift_config = config['redshift'] + + # Get region and profile from AWS section if available + region_name = None + config_profile = None + if 'aws' in config: + region_name = config['aws'].get('region') + config_profile = config['aws'].get('config_profile') + + # Get credentials from AWS Secrets Manager + secret_name = redshift_config.get('secret_name') + if not secret_name: + print("Error: 'secret_name' not found in redshift configuration") + sys.exit(1) + + secret = get_secret(secret_name, region_name, config_profile) + + # Connect to Redshift using the secret credentials + conn = psycopg2.connect( + host=redshift_config['host'], + port=int(redshift_config.get('port', 5439)), + dbname=redshift_config['dbname'], + user=secret['username'], + password=secret['password'] + ) + print(f"Connected to Redshift database: {redshift_config['dbname']}") + return conn + except KeyError as e: + print(f"Missing required configuration parameter: {e}") + sys.exit(1) + except Exception as e: + print(f"Error connecting to Redshift: {e}") + sys.exit(1) + +def get_users_with_usage_permission(conn, p_datashare_database_name=None, identity_provider_namespace='AWSIDC'): + """ + Query svv_database_privileges to get users with USAGE permission on the datashare database(s) + Only include identity_provider_namespace: prefixed users for IDC auth + """ + try: + cursor = conn.cursor() + + query = """ + SELECT DISTINCT + database_name, + identity_name + FROM + svv_database_privileges + WHERE + privilege_type IN ('USAGE', 'ALL') + AND + """ + + if p_datashare_database_name: + query += f"database_name = '{p_datashare_database_name}'" + else: + query += "database_name LIKE '%datashare%'" + + query += """ + ORDER BY + identity_name + """ + + print(f"Executing query for users with USAGE permission: {query}") + cursor.execute(query) + db_users = cursor.fetchall() + + # Create a dictionary mapping database names to lists of users + user_map = {} + prefix = f"{identity_provider_namespace}:" + + for db_name, identity_name in db_users: + # Only include identity_provider_namespace: prefixed users + if identity_name.lower().startswith(prefix.lower()): + user_map.setdefault(db_name, []).append(identity_name) + + return user_map + except Exception as e: + print(f"Error retrieving database users with USAGE permission: {e}") + conn.close() + sys.exit(1) + +def get_local_database_permissions(conn, database_name, identity_provider_namespace='AWSIDC'): + """ + Get IDC users with permissions on the local database and its tables using system tables + Returns user_map and table_grants for local database + """ + try: + cursor = conn.cursor() + + # Debug: Check current database + cursor.execute("SELECT current_database()") + current_db = cursor.fetchone()[0] + print(f"Current database: {current_db}") + + # Debug: Check available schemas + cursor.execute("SELECT schema_name FROM svv_redshift_schemas WHERE schema_name NOT IN ('information_schema', 'pg_catalog', 'pg_internal')") + schemas = cursor.fetchall() + print(f"Available schemas: {[s[0] for s in schemas]}") + + # Get all tables in the local database (exclude system schemas) + tables_query = f""" + SELECT schema_name, table_name + FROM svv_redshift_tables + WHERE database_name = '{database_name}' + AND schema_name NOT IN ('information_schema', 'pg_catalog', 'pg_internal') + ORDER BY schema_name, table_name + """ + + print(f"Executing local tables query: {tables_query}") + cursor.execute(tables_query) + table_results = cursor.fetchall() + print(f"Found {len(table_results)} tables in local database") + for schema, table in table_results[:5]: # Show first 5 tables + print(f" Table: {schema}.{table}") + + tables = [(database_name, schema, table) for schema, table in table_results] + + # Get table-level grants using system tables (includes IDC role handling) + table_grants = get_table_grants(conn, tables, identity_provider_namespace) + + # Create empty user_map since we only care about table permissions + user_map = {} + + cursor.close() + return user_map, tables, table_grants + + except Exception as e: + print(f"Error retrieving local database permissions: {e}") + conn.close() + sys.exit(1) + + + +def get_datashare_tables(conn, p_datashare_database_name=None): + """ + Get all tables in the datashare database(s) using svv_redshift_tables + """ + try: + cursor = conn.cursor() + + # Use svv_redshift_tables to get tables in datashare databases + query = """ + SELECT + database_name, + schema_name, + table_name + FROM + svv_redshift_tables + WHERE + """ + + if p_datashare_database_name: + query += f"database_name = '{p_datashare_database_name}'" + else: + query += "database_name LIKE '%datashare%'" + + query += """ + ORDER BY + database_name, schema_name, table_name + """ + + print(f"Executing query for tables: {query}") + cursor.execute(query) + tables = cursor.fetchall() + cursor.close() + + return tables + except Exception as e: + print(f"Error retrieving datashare tables: {e}") + conn.close() + sys.exit(1) + +def get_idc_group_id(role_name, identity_store_id, config_profile=None, identity_provider_namespace='AWSIDC', region_name=None): + """ + Get IDC group ID using AWS CLI get-group-id command with caching + """ + # Check cache first + if role_name in group_id_cache: + return group_id_cache[role_name] + + try: + # Remove identity provider namespace prefix if present + prefix = f"{identity_provider_namespace}:" + group_name = remove_prefix(role_name, prefix) + + # Create the JSON string for alternate-identifier + alternate_identifier = json.dumps({"UniqueAttribute": {"AttributePath": "DisplayName", "AttributeValue": group_name}}) + + cmd = ['aws'] + if config_profile: + cmd.extend(['--profile', config_profile]) + if region_name: + cmd.extend(['--region', region_name]) + cmd.extend([ + 'identitystore', 'get-group-id', + '--identity-store-id', identity_store_id, + '--alternate-identifier', alternate_identifier + ]) + + result = subprocess.run(cmd, capture_output=True, text=True) + if result.returncode != 0: + print(f"Warning: Could not get group ID for {role_name}: {result.stderr}") + group_id_cache[role_name] = None + return None + + response = json.loads(result.stdout) + group_id = response.get('GroupId') + if group_id: + print(f"Found IDC group ID for {role_name}: {group_id}") + group_id_cache[role_name] = group_id + return group_id + else: + print(f"Warning: No group ID found for {role_name}") + group_id_cache[role_name] = None + return None + + except Exception as e: + print(f"Warning: Error getting IDC group ID for {role_name}: {e}") + group_id_cache[role_name] = None + return None + +def get_idc_role_grants(conn, identity_provider_namespace='AWSIDC'): + """ + Get all roles granted to IDC roles using SVV_ROLE_GRANTS + Returns a dictionary mapping IDC role names to lists of granted roles + """ + try: + cursor = conn.cursor() + role_grants = {} + + # Create prefix for filtering + prefix = f"{identity_provider_namespace}:%" + + query = f""" + SELECT + role_name, + granted_role_name + FROM + svv_role_grants + WHERE + role_name LIKE '{prefix}' + AND NOT granted_role_name LIKE '{prefix}' + """ + + print(f"Executing query for IDC role grants: {query}") + cursor.execute(query) + results = cursor.fetchall() + + for role_name, granted_role in results: + role_grants.setdefault(role_name, []).append(granted_role) + print(f" Found role {granted_role} granted to IDC role {role_name}") + + cursor.close() + return role_grants + + except Exception as e: + print(f"Error retrieving IDC role grants: {e}") + return {} + +def get_table_grants_for_roles(conn, tables, target_roles): + """ + Get grants for specific roles on tables using SHOW GRANTS command + Returns a dictionary mapping (db_name, schema_name, table_name) to a list of (grantee, privilege_type, identity_type) tuples + Only includes the specified target roles + """ + try: + cursor = conn.cursor() + table_grants = {} + + for db_name, schema_name, table_name in tables: + full_table_name = f"{db_name}.{schema_name}.{table_name}" + print(f"Getting grants for table: {full_table_name}") + + try: + # Execute SHOW GRANTS command + query = f"SHOW GRANTS ON TABLE {full_table_name}" + cursor.execute(query) + + # Get column names from cursor description + columns = [desc[0] for desc in cursor.description] + + # Find the indices for identity_name, privilege_type, and identity_type + identity_name_idx = columns.index('identity_name') if 'identity_name' in columns else -1 + privilege_type_idx = columns.index('privilege_type') if 'privilege_type' in columns else -1 + identity_type_idx = columns.index('identity_type') if 'identity_type' in columns else -1 + + if identity_name_idx == -1 or privilege_type_idx == -1 or identity_type_idx == -1: + print(f"Warning: Could not find required columns in SHOW GRANTS result for {full_table_name}") + print(f"Available columns: {columns}") + continue + + grants = cursor.fetchall() + + # Store results in dictionary + table_key = (db_name, schema_name, table_name) + table_grants[table_key] = [] + + # Process each grant + for grant in grants: + grantee = grant[identity_name_idx] + privilege_type = grant[privilege_type_idx] + identity_type = grant[identity_type_idx] + + # Only include target roles and exclude filtered permissions + if grantee in target_roles and privilege_type not in ['RULE', 'TRIGGER', 'REFERENCES', 'TRUNCATE', 'UPDATE']: + table_grants[table_key].append((grantee, privilege_type, identity_type)) + print(f" Found grant: {grantee} ({identity_type}) has {privilege_type} on {full_table_name}") + + except Exception as e: + print(f"Warning: Could not get grants for table {full_table_name}: {e}") + # Continue with other tables + + cursor.close() + return table_grants + + except Exception as e: + print(f"Error retrieving table grants for roles: {e}") + conn.close() + sys.exit(1) + +def get_table_grants(conn, tables, identity_provider_namespace='AWSIDC'): + """ + Get grants for each table using SHOW GRANTS command + Returns a dictionary mapping (db_name, schema_name, table_name) to a list of (grantee, privilege_type, identity_type) tuples + Only include identity_provider_namespace: prefixed users/roles for IDC auth + """ + try: + cursor = conn.cursor() + table_grants = {} + + for db_name, schema_name, table_name in tables: + full_table_name = f"{db_name}.{schema_name}.{table_name}" + print(f"Getting grants for table: {full_table_name}") + + try: + # Execute SHOW GRANTS command + query = f"SHOW GRANTS ON TABLE {full_table_name}" + cursor.execute(query) + + # Get column names from cursor description + columns = [desc[0] for desc in cursor.description] + + # Find the indices for identity_name, privilege_type, and identity_type + identity_name_idx = columns.index('identity_name') if 'identity_name' in columns else -1 + privilege_type_idx = columns.index('privilege_type') if 'privilege_type' in columns else -1 + identity_type_idx = columns.index('identity_type') if 'identity_type' in columns else -1 + + if identity_name_idx == -1 or privilege_type_idx == -1 or identity_type_idx == -1: + print(f"Warning: Could not find required columns in SHOW GRANTS result for {full_table_name}") + print(f"Available columns: {columns}") + continue + + grants = cursor.fetchall() + + # Store results in dictionary + table_key = (db_name, schema_name, table_name) + table_grants.setdefault(table_key, []) + + # Define excluded permissions + excluded_permissions = ['RULE', 'TRIGGER', 'REFERENCES', 'TRUNCATE', 'UPDATE'] + prefix = f"{identity_provider_namespace}:" + + # Process each grant + for grant in grants: + grantee = grant[identity_name_idx] + privilege_type = grant[privilege_type_idx] + identity_type = grant[identity_type_idx] + + # Filter - exclude certain permissions and only include prefixed users/roles + if (grantee != 'rdsdb' and + privilege_type not in excluded_permissions and + grantee.lower().startswith(prefix.lower())): + + table_grants[table_key].append((grantee, privilege_type, identity_type)) + print(f" Found grant: {grantee} ({identity_type}) has {privilege_type} on {full_table_name}") + + except Exception as e: + print(f"Warning: Could not get grants for table {full_table_name}: {e}") + # Continue with other tables + + cursor.close() + return table_grants + + except Exception as e: + print(f"Error retrieving table grants: {e}") + conn.close() + sys.exit(1) + +def get_idc_user_id(username, identity_store_id, config_profile=None, identity_provider_namespace='AWSIDC', region_name=None): + """ + Get IDC user ID using AWS CLI get-user-id command with the correct syntax + Uses email address as the identifier + """ + try: + # Create the JSON string for alternate-identifier using primaryEmail + alternate_identifier = json.dumps({"UniqueAttribute": {"AttributePath": "emails.value", "AttributeValue": username}}) + + cmd = ['aws'] + if config_profile: + cmd.extend(['--profile', config_profile]) + if region_name: + cmd.extend(['--region', region_name]) + cmd.extend([ + 'identitystore', 'get-user-id', + '--identity-store-id', identity_store_id, + '--alternate-identifier', alternate_identifier + ]) + + result = subprocess.run(cmd, capture_output=True, text=True) + if result.returncode != 0: + print(f"Warning: Could not get user ID for {username}: {result.stderr}") + return username + + response = json.loads(result.stdout) + user_id = response.get('UserId') + if user_id: + print(f"Found IDC user ID for {username}: {user_id}") + return user_id + else: + print(f"Warning: No user ID found for {username}") + return username + + except Exception as e: + print(f"Warning: Error getting IDC user ID for {username}: {e}") + return username + +# Cache for user IDs and group IDs to avoid duplicate lookups +user_id_cache = {} +group_id_cache = {} + +def remove_prefix(text, prefix): + """ + Helper function to remove prefix from a string if it exists + """ + return text[len(prefix):] if text.lower().startswith(prefix.lower()) else text + +def get_principal_identifier(identity_name, aws_account_id, config_profile=None, identity_store_id=None, identity_provider_namespace='AWSIDC', region_name=None): + """ + Generate the principal identifier for Lake Formation permissions based on identity name for IDC users + """ + # Extract user name from the identity name if it has a prefix + prefix = f"{identity_provider_namespace}:" + username = remove_prefix(identity_name, prefix) + + if not identity_store_id: + print(f"Warning: No identity store ID provided for IDC user {username}") + return f"arn:aws:identitystore:::user/{username}" + + # Use cached user ID if available, otherwise look it up + user_id = user_id_cache.get(username) or get_idc_user_id(username, identity_store_id, config_profile, identity_provider_namespace, region_name) + user_id_cache[username] = user_id + + # Use the format with the actual user ID + return f"arn:aws:identitystore:::user/{user_id}" + +def create_lf_command(aws_account_id, profile_param, principal_identifier, resource_json, permissions_str, comment="", action="grant"): + """ + Helper function to create a Lake Formation command with consistent formatting + action can be 'grant' or 'revoke' + """ + return ( + comment + + f"aws{profile_param} lakeformation {action}-permissions \\\n" + + f" --catalog-id \"{aws_account_id}\" \\\n" + + f" --principal DataLakePrincipalIdentifier={principal_identifier} \\\n" + + f" --resource '{resource_json}' \\\n" + + f" --permissions {permissions_str}\n\n" + ) + +def create_table_resource_json(full_catalog_id, schema_name, table_name=None): + """ + Helper function to create the resource JSON for a table or schema + """ + if table_name: + # Table-level resource + return '{"Table": {"CatalogId": "' + full_catalog_id + '", "DatabaseName": "' + schema_name + '", "Name": "' + table_name + '"}}' + else: + # Schema-level resource with TableWildcard + return '{"Table": {"CatalogId": "' + full_catalog_id + '", "DatabaseName": "' + schema_name + '", "TableWildcard": {}}}' + + +def generate_lakeformation_commands(tables, user_map, aws_account_id, producer_catalog, + object_level_permissions=False, table_grants=None, config_profile=None, identity_store_id=None, conn=None, output_dir=None, + debug=False, identity_provider_namespace='AWSIDC', region_name=None): + """ + Generate AWS CLI commands for LakeFormation permissions + If object_level_permissions is True, generate table-level permissions based on SHOW GRANTS + Otherwise, generate schema-level permissions using TableWildcard syntax + """ + commands = [] + timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") + + # Get the project root directory (parent of src) + project_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + + # Create a subdirectory for this run under the project's output directory + output_base = output_dir if output_dir else os.path.join(project_root, "output") + run_dir = os.path.join(output_base, f"run_{timestamp}") + if not os.path.exists(run_dir): + os.makedirs(run_dir) + script_filepath = os.path.join(run_dir, f"lakeformation_permissions_{timestamp}.sh") + + # Create debug file for get-user-id commands if debug mode is enabled + if debug: + debug_filepath = os.path.join(run_dir, f"get_user_id_commands_{timestamp}.sh") + with open(debug_filepath, 'w') as debug_file: + debug_file.write("#!/bin/bash\n\n") + debug_file.write("# AWS CLI get-user-id commands for debugging\n") + debug_file.write(f"# Generated on: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n\n") + + # Collect all unique usernames + usernames = set() + if object_level_permissions and table_grants: + for grants in table_grants.values(): + for grantee, _, identity_type in grants: + # Only include users, not roles + if identity_type.lower() == 'user': + # Use the configured identity provider namespace + prefix = f"{identity_provider_namespace}:" + if grantee.lower().startswith(prefix.lower()): + usernames.add(grantee[len(prefix):]) + else: + usernames.add(grantee) + else: + for users in user_map.values(): + for user in users: + # Use the configured identity provider namespace + prefix = f"{identity_provider_namespace}:" + if user.lower().startswith(prefix.lower()): + usernames.add(user[len(prefix):]) + else: + usernames.add(user) + + # Write get-user-id commands + for username in sorted(usernames): + cmd = ['aws'] + if config_profile: + cmd.extend(['--profile', config_profile]) + # Create the JSON string for alternate-identifier + alternate_identifier = json.dumps({"UniqueAttribute": {"AttributePath": "emails.value", "AttributeValue": username}}) + + # Format the command with proper quoting for the shell script, with each parameter on a separate line + debug_file.write(f"# Getting user ID for {username}\n") + debug_file.write(f"aws{' --profile ' + config_profile if config_profile else ''}{' --region ' + region_name if region_name else ''} identitystore get-user-id \\\n") + debug_file.write(f" --identity-store-id {identity_store_id} \\\n") + debug_file.write(f" --alternate-identifier '{alternate_identifier}'\n\n") + + + # Format the complete CatalogId for the resource section + full_catalog_id = f"{aws_account_id}:{producer_catalog}" + + with open(script_filepath, 'w') as script_file: + script_file.write("#!/bin/bash\n\n") + script_file.write("# AWS LakeFormation permission commands generated from Redshift permissions\n") + script_file.write(f"# Generated on: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n") + script_file.write("# Authentication type: IDC\n") + script_file.write(f"# Object-level permissions: {object_level_permissions}\n\n") + + # Track how many commands we generate + commands_count = 0 + + # Track role tables + role_tables = {} + + # Check if IDC roles have other roles granted to them + idc_role_grants = {} + if conn: + idc_role_grants = get_idc_role_grants(conn, identity_provider_namespace) + + # Get table grants for the granted roles + if idc_role_grants: + all_granted_roles = set() + for granted_roles in idc_role_grants.values(): + all_granted_roles.update(granted_roles) + + if all_granted_roles: + print(f"Getting table grants for roles granted to IDC roles: {all_granted_roles}") + # Get ALL permissions for granted roles regardless of auth_type + granted_role_tables = get_table_grants_for_roles(conn, tables, all_granted_roles) + + # Debug: Show what permissions were found for granted roles + for (db, schema, table), grants in granted_role_tables.items(): + for grantee, priv, identity in grants: + if grantee in all_granted_roles: + print(f" DEBUG: Found {grantee} has {priv} on {schema}.{table}") + + # Add granted role permissions to IDC roles + for idc_role, granted_roles in idc_role_grants.items(): + for granted_role in granted_roles: + # Find tables where the granted role has permissions + for (db_name, schema_name, table_name), grants in granted_role_tables.items(): + for grantee, privilege_type, identity_type in grants: + if grantee == granted_role and privilege_type not in ['RULE', 'TRIGGER', 'REFERENCES', 'TRUNCATE', 'UPDATE']: + # Add this table to the IDC role's permissions + if idc_role not in role_tables: + role_tables[idc_role] = [] + if (schema_name, table_name) not in role_tables[idc_role]: + role_tables[idc_role].append((schema_name, table_name)) + print(f" Added table {schema_name}.{table_name} to IDC role {idc_role} via granted role {granted_role}") + + # Also add to table_grants so it gets processed in the main loop + table_key = (None, schema_name, table_name) + if table_key not in table_grants: + table_grants[table_key] = [] + # Add the IDC role as having the same permission on this table + grant_tuple = (idc_role, privilege_type, 'role') + if grant_tuple not in table_grants[table_key]: + table_grants[table_key].append(grant_tuple) + print(f" Added {idc_role} {privilege_type} grant for table {schema_name}.{table_name} to table_grants") + else: + print(f" Skipped duplicate: {idc_role} {privilege_type} grant for table {schema_name}.{table_name}") + + print(f" Processing IDC role {idc_role} with granted roles") + + # Set profile parameter for all commands + profile_param = f" --profile {config_profile}" if config_profile else "" + + if object_level_permissions and table_grants: + script_file.write("# Table-level permissions based on SHOW GRANTS results\n\n") + + # Group grants by (grantee, table) to combine permissions + grouped_grants = {} + for (db_name, schema_name, table_name), grants in table_grants.items(): + for grantee, privilege_type, identity_type in grants: + key = (grantee, db_name, schema_name, table_name, identity_type) + if key not in grouped_grants: + grouped_grants[key] = [] + grouped_grants[key].append(privilege_type) + + # Process grouped grants + for (grantee, db_name, schema_name, table_name, identity_type), privileges in grouped_grants.items(): + # Create permissions string and add DESCRIBE if any permissions exist + permissions_set = set(privileges) + if permissions_set: + permissions_set.add('DESCRIBE') + perms_str = ' '.join(f'"{perm}"' for perm in sorted(permissions_set)) + + # Handle roles + if identity_type.lower() == 'role': + # Use group ID as principal + group_id = get_idc_group_id(grantee, identity_store_id, config_profile, identity_provider_namespace, region_name) + if group_id: + principal_identifier = f"arn:aws:identitystore:::group/{group_id}" + else: + continue # Skip if group ID not found + else: + # Get principal identifier for users + principal_identifier = get_principal_identifier(grantee, aws_account_id, config_profile, identity_store_id, identity_provider_namespace, region_name) + + # Generate command with all permissions for this user/role on this table + # Add comment showing the IDC user/group name + # Use the configured identity provider namespace for comments + prefix = f"{identity_provider_namespace}:" + if identity_type.lower() == 'role': + comment = f"# IDC Group: {remove_prefix(grantee, prefix)}\n" + else: + comment = f"# IDC User Email: {remove_prefix(grantee, prefix)}\n" + + # Create resource JSON for table + resource_json = create_table_resource_json(full_catalog_id, schema_name, table_name) + + # Generate command + command = create_lf_command( + aws_account_id, + profile_param, + principal_identifier, + resource_json, + perms_str, + comment + ) + + script_file.write(command) + commands.append(command) + commands_count += 1 + + print(f"Generated {commands_count} table-level permission commands") + else: + # Get unique database-schema combinations + db_schema_map = {} + for db_name, schema_name, _ in tables: + db_schema_map.setdefault(db_name, set()).add(schema_name) + + # Generate schema-level permissions with TableWildcard + script_file.write("# Schema-level SELECT and DESCRIBE permissions for all tables in datashare database(s)\n") + script_file.write("# For users with USAGE permission on the database\n\n") + + for db_name, schemas in db_schema_map.items(): + # If we have users with USAGE permission for this database + if db_name in user_map: + for schema_name in schemas: + for identity_name in user_map[db_name]: + principal_identifier = get_principal_identifier(identity_name, aws_account_id, config_profile, identity_store_id, identity_provider_namespace, region_name) + + # Use schema name as DatabaseName parameter in the LakeFormation resource + profile_param = f" --profile {config_profile}" if config_profile else "" + # Create resource JSON for schema (TableWildcard) + resource_json = create_table_resource_json(full_catalog_id, schema_name) + + # Generate command + command = create_lf_command( + aws_account_id, + profile_param, + principal_identifier, + resource_json, + '"SELECT" "DESCRIBE"' + ) + + script_file.write(command) + commands.append(command) + commands_count += 1 + + print(f"Generated {commands_count} schema-level SELECT and DESCRIBE permission commands") + + # Create rollback script + rollback_filepath = os.path.join(run_dir, f"rollback_lakeformation_{timestamp}.sh") + with open(rollback_filepath, 'w') as rollback_file: + rollback_file.write("#!/bin/bash\n\n") + rollback_file.write("# AWS LakeFormation rollback commands\n") + rollback_file.write(f"# Generated on: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n") + rollback_file.write("# Use this script to revoke permissions created by the lakeformation_permissions script\n\n") + + # Rollback for table permissions + if object_level_permissions and table_grants: + rollback_file.write("# Revoke table-level permissions\n\n") + + # Group grants by (grantee, table) to combine permissions, just like in the main script + grouped_grants = {} + for (db_name, schema_name, table_name), grants in table_grants.items(): + for grantee, privilege_type, identity_type in grants: + key = (grantee, db_name, schema_name, table_name, identity_type) + if key not in grouped_grants: + grouped_grants[key] = [] + grouped_grants[key].append(privilege_type) + + # Process grouped grants + for (grantee, db_name, schema_name, table_name, identity_type), privileges in grouped_grants.items(): + # Create permissions string and add DESCRIBE if any permissions exist + permissions_set = set(privileges) + if permissions_set: + permissions_set.add('DESCRIBE') # Add DESCRIBE to match the main script + perms_str = ' '.join(f'"{perm}"' for perm in sorted(permissions_set)) + + # Handle roles + if identity_type.lower() == 'role': + # For IDC roles, get group ID + group_id = get_idc_group_id(grantee, identity_store_id, config_profile, identity_provider_namespace, region_name) + if group_id: + principal_identifier = f"arn:aws:identitystore:::group/{group_id}" + else: + continue # Skip if group ID not found + else: + # Get principal identifier for users + principal_identifier = get_principal_identifier(grantee, aws_account_id, config_profile, identity_store_id, identity_provider_namespace, region_name) + + # Create resource JSON for table + resource_json = create_table_resource_json(full_catalog_id, schema_name, table_name) + + # Generate revoke command with all permissions for this user/role on this table + prefix = f"{identity_provider_namespace}:" + if identity_type.lower() == 'role': + comment = f"# IDC Group: {remove_prefix(grantee, prefix)}\n" + else: + comment = f"# IDC User Email: {remove_prefix(grantee, prefix)}\n" + + revoke_cmd = create_lf_command( + aws_account_id, + profile_param, + principal_identifier, + resource_json, + perms_str, + comment, + "revoke" + ) + + rollback_file.write(revoke_cmd) + else: + # Rollback for schema-level permissions + rollback_file.write("# Revoke schema-level permissions\n\n") + for db_name, schemas in db_schema_map.items(): + if db_name in user_map: + for schema_name in schemas: + for identity_name in user_map[db_name]: + principal_identifier = get_principal_identifier(identity_name, aws_account_id, config_profile, identity_store_id, identity_provider_namespace, region_name) + # Create resource JSON for schema (TableWildcard) + resource_json = create_table_resource_json(full_catalog_id, schema_name) + + # Generate revoke command + revoke_cmd = create_lf_command( + aws_account_id, + profile_param, + principal_identifier, + resource_json, + '"SELECT" "DESCRIBE"', + "", + "revoke" + ) + + rollback_file.write(revoke_cmd) + + print(f"Generated {len(commands)} total LakeFormation commands in file: {script_filepath}") + print(f"Generated rollback script: {rollback_filepath}") + return commands + +def get_identity_provider_namespace(conn): + """ + Query SVV_IDENTITY_PROVIDERS to get the identity provider namespace for AWS IDC + """ + try: + cursor = conn.cursor() + query = "select namespc from SVV_IDENTITY_PROVIDERS where type='awsidc'" + cursor.execute(query) + result = cursor.fetchone() + cursor.close() + + if result and result[0]: + return result[0] + else: + print("Warning: No AWS IDC identity provider found in SVV_IDENTITY_PROVIDERS, using default 'AWSIDC'") + return 'AWSIDC' + except Exception as e: + print(f"Error querying SVV_IDENTITY_PROVIDERS: {e}") + print("Using default identity provider namespace: 'AWSIDC'") + return 'AWSIDC' + +def main(): + parser = argparse.ArgumentParser(description='Extract Redshift permissions and generate AWS LakeFormation commands') + + parser.add_argument('--config', '-c', default='config.ini', help='Path to config file (default: config.ini)') + parser.add_argument('--output-dir', '-o', help='Base directory to save generated scripts (default: "output")') + parser.add_argument('--debug', action='store_true', help='Enable debug output') + + args = parser.parse_args() + + # Load configuration + config = load_config(args.config) + + # Connect to Redshift + conn = connect_to_redshift(config) + + # Get parameters from config + p_datashare_database_name = None + permissions_type = 'datashare' # default + + if 'parameters' in config: + if 'datashare_database_name' in config['parameters']: + p_datashare_database_name = config['parameters']['datashare_database_name'] + if 'permissions_type' in config['parameters']: + permissions_type = config['parameters']['permissions_type'].lower() + + print(f"Permissions type: {permissions_type}") + + # Check if datashare object-level permissions are enabled + object_level_permissions = False + if 'parameters' in config and 'datashare_object_level_permissions' in config['parameters']: + object_level_permissions = config['parameters']['datashare_object_level_permissions'].lower() == 'true' + print(f"Datashare object-level permissions: {object_level_permissions}") + + # Get identity provider namespace from SVV_IDENTITY_PROVIDERS + identity_provider_namespace = get_identity_provider_namespace(conn) + print(f"Using identity provider namespace: {identity_provider_namespace}") + + # Process based on permissions_type + if permissions_type == 'local': + # Get local database name from config + local_db_name = config['redshift']['dbname'] + print(f"Processing local database permissions for: {local_db_name}") + + user_map, tables, table_grants = get_local_database_permissions(conn, local_db_name, identity_provider_namespace) + user_count = sum(len(users) for users in user_map.values()) + print(f"Found {user_count} IDC users with permissions on local database {local_db_name}") + print(f"Retrieved {len(tables)} tables from local database") + + if table_grants: + grant_count = sum(len(grants) for grants in table_grants.values()) + print(f"Retrieved {grant_count} table-level grants for IDC users/roles") + else: + # Original datashare logic + if p_datashare_database_name: + print(f"Filtering permissions for datashare database: {p_datashare_database_name}") + + # Get users with USAGE permission on the database (required to access tables) + user_map = get_users_with_usage_permission(conn, p_datashare_database_name, identity_provider_namespace) + db_count = len(user_map) + user_count = sum(len(users) for users in user_map.values()) + + print(f"Found {user_count} IDC users (with {identity_provider_namespace}: prefix) with USAGE permission across {db_count} databases") + + # Get all tables in the datashare database(s) + tables = get_datashare_tables(conn, p_datashare_database_name) + print(f"Retrieved {len(tables)} tables from datashare database(s)") + + # Get table-level grants if datashare object_level_permissions is enabled + table_grants = None + if object_level_permissions and tables: + print("Getting table-level grants using SHOW GRANTS...") + table_grants = get_table_grants(conn, tables, identity_provider_namespace) + grant_count = sum(len(grants) for grants in table_grants.values()) + + print(f"Retrieved {grant_count} table-level grants for IDC users/roles (with {identity_provider_namespace}: prefix)") + + if args.debug: + if user_map: + print("\nUsers with USAGE permission by database:") + for db_name, users in user_map.items(): + print(f" {db_name}: {users}") + + print("\nTables data (sample):") + for table in tables[:5]: # Print first 5 tables for debugging + print(f" {table}") + + # Print all databases found in tables + db_names = set([t[0] for t in tables]) + print(f"\nDatabases found in tables: {db_names}") + + # Print table grants if available + if table_grants: + print("\nTable grants (sample):") + sample_count = 0 + for table_key, grants in table_grants.items(): + if sample_count >= 5: + break + if grants: + db, schema, table = table_key + print(f" {db}.{schema}.{table}: {grants}") + sample_count += 1 + + # Generate LakeFormation commands + if tables and (user_map or (object_level_permissions and table_grants)): + if not user_map and (not table_grants or not any(table_grants.values())): + print(f"\nNo IDC users or roles (with {identity_provider_namespace}: prefix) found with permissions. No Lake Formation commands will be generated.") + return + aws_account_id = config.get('aws', 'account_id', fallback=None) + if not aws_account_id: + print("Error: AWS account ID not found in config") + sys.exit(1) + + # Get producer catalog from config + producer_catalog = config.get('aws', 'producer_catalog', fallback=None) + if not producer_catalog: + print("Error: producer_catalog not found in config") + sys.exit(1) + + # Get AWS CLI profile from config (optional) + config_profile = config.get('aws', 'config_profile', fallback=None) + if config_profile: + print(f"Using AWS CLI profile: {config_profile}") + + # Get identity store ID from config (required for IDC) + identity_store_id = config.get('aws', 'identity_store_id', fallback=None) + if not identity_store_id: + print("Warning: identity_store_id not found in config") + + # Get region from config + region_name = config.get('aws', 'region', fallback=None) + if region_name: + print(f"Using AWS region: {region_name}") + + # Generate LakeFormation commands, passing the open connection for role user lookup + generate_lakeformation_commands( + tables, user_map, aws_account_id, producer_catalog, + object_level_permissions, table_grants, config_profile, identity_store_id, conn, args.output_dir, + args.debug, identity_provider_namespace, region_name + ) + + # Now close the connection + conn.close() + else: + print("No datashare tables or users found to convert.") + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/src/LakeFormationMigrationUtility/tests/integration_test/cleanup_script_generator.py b/src/LakeFormationMigrationUtility/tests/integration_test/cleanup_script_generator.py new file mode 100644 index 00000000..a6fa369d --- /dev/null +++ b/src/LakeFormationMigrationUtility/tests/integration_test/cleanup_script_generator.py @@ -0,0 +1,466 @@ +import configparser +import os + +def generate_unified_cleanup_script(): + config = configparser.ConfigParser() + config_path = os.path.join(os.path.dirname(__file__), 'test_int_config.ini') + config.read(config_path) + + # Check auth_type to determine cleanup type + auth_type = config['aws']['auth_type'] + include_idc_cleanup = auth_type.upper() == 'IDC' + include_iam_cleanup = auth_type.upper() == 'IAM' + + cleanup_dir = os.path.join(os.path.dirname(__file__)) + os.makedirs(cleanup_dir, exist_ok=True) + cleanup_file = os.path.join(cleanup_dir, 'int_unified_cleanup.py') + + users = [ + 'test_user_admin', + 'test_user_analyst1', + 'test_user_analyst2', + 'test_user_analyst3', + 'test_user_etl1', + 'test_user_etl2', + 'test_user_adhoc' + ] + + roles = [ + 'test_role_bn_admin', + 'test_role_bn_analyst', + 'test_role_bn_etl', + 'test_role_tn_tickit_restricted', + 'test_role_bn_adhoc' + ] + + awsidc_roles = [ + 'AWSIDC:test_role_bn_admin', + 'AWSIDC:test_role_bn_analyst', + 'AWSIDC:test_role_bn_etl', + 'AWSIDC:test_role_bn_adhoc' + ] + + awsidc_users = [ + 'AWSIDC:test_user_analyst3@example.com' + ] + + groups = [ + 'test_role_bn_admin', + 'test_role_bn_analyst', + 'test_role_bn_etl', + 'test_role_bn_adhoc' + ] + + iam_users_to_delete = [ + 'test_user_admin', + 'test_user_analyst1', + 'test_user_analyst2', + 'test_user_etl1', + 'test_user_etl2' + ] + + iam_roles_to_delete = [ + 'test_user_adhoc' + ] + + iam_redshift_users = [ + 'IAM:test_user_admin', + 'IAM:test_user_analyst1', + 'IAM:test_user_analyst2', + 'IAM:test_user_etl1', + 'IAM:test_user_etl2', + 'IAMR:test_user_adhoc' + ] + + # Common imports and setup + common_imports = """import boto3 +import psycopg2 +import configparser +import os +import json + +""" + + # Common config setup + common_config = """ +def cleanup_all(): + config = configparser.ConfigParser() + config_path = os.path.join(os.path.dirname(__file__), 'test_int_config.ini') + config.read(config_path) +""" + + # Secrets Manager code + secrets_manager_code = """ + # Get credentials from Secrets Manager + secret_name = config['redshift']['secret_name'] + region = config['aws']['region'] + profile = config['aws'].get('config_profile', None) + + # Create boto3 session and clients + session = boto3.Session(profile_name=profile, region_name=region) if profile else boto3.Session(region_name=region) + secrets_client = session.client('secretsmanager') + + # Get secret value + response = secrets_client.get_secret_value(SecretId=secret_name) + secret = json.loads(response['SecretString']) + + # Create connection parameters + conn_params = { + 'host': config['redshift']['host'], + 'port': config['redshift']['port'], + 'dbname': config['redshift']['dbname'], + 'user': secret['username'], + 'password': secret['password'] + } +""" + + # Generate cleanup script content based on auth_type + if include_idc_cleanup: + cleanup_content = common_imports + common_config + """ + print("Starting unified cleanup process...\\n") + + # ===== REDSHIFT CLEANUP ===== + print("=== REDSHIFT CLEANUP ===") + try: +""" + secrets_manager_code + """ + conn = psycopg2.connect(**conn_params) + conn.autocommit = True + cursor = conn.cursor() + + # Get datashare database name + datashare_db = config['parameters']['datashare_database_name'] + object_level_permissions = config.getboolean('parameters', 'object_level_permissions') + + # Revoke permissions from test_user_analyst3 and AWSIDC:test_user_analyst3@example.com + print("Revoking permissions from test_user_analyst3 and AWSIDC:test_user_analyst3@example.com...") + try: + # Revoke permissions from test_user_analyst3 + cursor.execute(f"REVOKE USAGE ON DATABASE {datashare_db} FROM test_user_analyst3;") + if object_level_permissions: + cursor.execute(f"REVOKE USAGE ON SCHEMA {datashare_db}.tickit FROM test_user_analyst3;") + cursor.execute(f"REVOKE ALL ON ALL TABLES IN SCHEMA {datashare_db}.tickit FROM test_user_analyst3;") + print("Revoked permissions from test_user_analyst3") + + # Revoke permissions from AWSIDC:test_user_analyst3@example.com + cursor.execute(f'REVOKE USAGE ON DATABASE {datashare_db} FROM "AWSIDC:test_user_analyst3@example.com";') + if object_level_permissions: + cursor.execute(f'REVOKE USAGE ON SCHEMA {datashare_db}.tickit FROM "AWSIDC:test_user_analyst3@example.com";') + cursor.execute(f'REVOKE ALL ON ALL TABLES IN SCHEMA {datashare_db}.tickit FROM "AWSIDC:test_user_analyst3@example.com";') + print("Revoked permissions from AWSIDC:test_user_analyst3@example.com") + except Exception as e: + print(f"Error revoking permissions: {e}") + + # Revoke role relationships + print("\\nRevoking role relationships...") + try: + cursor.execute("REVOKE ROLE test_role_tn_tickit_restricted FROM ROLE test_role_bn_etl;") + print("Revoked test_role_tn_tickit_restricted from test_role_bn_etl") + cursor.execute('REVOKE ROLE test_role_tn_tickit_restricted FROM ROLE "AWSIDC:test_role_bn_etl";') + print("Revoked test_role_tn_tickit_restricted from AWSIDC:test_role_bn_etl") + except Exception as e: + print(f"Error revoking roles: {e}") + + # Drop users + print("\\nDropping users...") + users = """ + str(users) + """ + for user in users: + try: + cursor.execute(f"DROP USER IF EXISTS {user};") + print(f"Dropped user: {user}") + except Exception as e: + print(f"Error dropping user {user}: {e}") + + # Drop AWSIDC users first + print("\\nDropping AWSIDC users...") + awsidc_users = """ + str(awsidc_users) + """ + for user in awsidc_users: + try: + cursor.execute(f'DROP USER "{user}";') + print(f"Dropped AWSIDC user: {user}") + except Exception as e: + print(f"Error dropping AWSIDC user {user}: {e}") + + # Drop AWSIDC roles + print("\\nDropping AWSIDC roles...") + awsidc_roles = """ + str(awsidc_roles) + """ + for role in awsidc_roles: + try: + cursor.execute(f'DROP ROLE "{role}" FORCE;') + print(f"Dropped AWSIDC role: {role}") + except Exception as e: + print(f"Error dropping AWSIDC role {role}: {e}") + + # Drop local roles + print("\\nDropping local roles...") + roles = """ + str(roles) + """ + for role in roles: + try: + cursor.execute(f"DROP ROLE {role} FORCE;") + print(f"Dropped role: {role}") + except Exception as e: + print(f"Error dropping role {role}: {e}") + + print("Redshift cleanup completed successfully!") + except Exception as e: + print(f"Error in Redshift cleanup: {e}") + finally: + if 'conn' in locals(): + conn.close() + + # ===== IAM IDENTITY CENTER CLEANUP ===== + print("\\n=== IAM IDENTITY CENTER CLEANUP ===") + try: + # Get IAM Identity Center configuration + identity_store_id = config['aws']['identity_store_id'] + region = config['aws']['region'] + profile = config['aws'].get('config_profile', None) + + # Create boto3 session and clients + session = boto3.Session(profile_name=profile, region_name=region) if profile else boto3.Session(region_name=region) + identity_store_client = session.client('identitystore') + + # List of users and groups to delete + users = """ + str(users) + """ + groups = """ + str(groups) + """ + + # Find and delete group memberships and groups + print("Processing groups...") + for group_name in groups: + try: + # List groups to find the ID + response = identity_store_client.list_groups( + IdentityStoreId=identity_store_id, + Filters=[{ + 'AttributePath': 'DisplayName', + 'AttributeValue': group_name + }] + ) + + for group in response.get('Groups', []): + group_id = group['GroupId'] + print(f"Found group {group_name} with ID: {group_id}") + + # List group memberships + memberships = identity_store_client.list_group_memberships( + IdentityStoreId=identity_store_id, + GroupId=group_id + ) + + # Delete each membership + for membership in memberships.get('GroupMemberships', []): + identity_store_client.delete_group_membership( + IdentityStoreId=identity_store_id, + MembershipId=membership['MembershipId'] + ) + print(f"Deleted membership {membership['MembershipId']} from group {group_name}") + + # Delete the group + identity_store_client.delete_group( + IdentityStoreId=identity_store_id, + GroupId=group_id + ) + print(f"Deleted group {group_name}") + except Exception as e: + print(f"Error processing group {group_name}: {e}") + + # Find and delete users + print("\\nProcessing users...") + for username in users: + try: + # List users to find the ID + response = identity_store_client.list_users( + IdentityStoreId=identity_store_id, + Filters=[{ + 'AttributePath': 'UserName', + 'AttributeValue': username + }] + ) + + for user in response.get('Users', []): + user_id = user['UserId'] + print(f"Found user {username} with ID: {user_id}") + + # Delete the user + identity_store_client.delete_user( + IdentityStoreId=identity_store_id, + UserId=user_id + ) + print(f"Deleted user {username}") + except Exception as e: + print(f"Error processing user {username}: {e}") + + print("IAM Identity Center cleanup completed successfully!") + except Exception as e: + print(f"Error in IAM Identity Center cleanup: {e}") + + print("\\nUnified cleanup process completed!") + +if __name__ == "__main__": + cleanup_all() +""" + elif include_iam_cleanup: + cleanup_content = common_imports + common_config + """ + print("Starting IAM and Redshift cleanup process...\\n") + + # ===== REDSHIFT CLEANUP ===== + print("=== REDSHIFT CLEANUP ===") + try: +""" + secrets_manager_code + """ + conn = psycopg2.connect(**conn_params) + conn.autocommit = True + cursor = conn.cursor() + + # Get datashare database name + datashare_db = config['parameters']['datashare_database_name'] + object_level_permissions = config.getboolean('parameters', 'object_level_permissions') + + # Revoke role relationships + print("Revoking role relationships...") + try: + cursor.execute("REVOKE ROLE test_role_tn_tickit_restricted FROM ROLE test_role_bn_etl;") + print("Revoked test_role_tn_tickit_restricted from test_role_bn_etl") + except Exception as e: + print(f"Error revoking roles: {e}") + + # Skip dropping normal users when auth_type is IAM + + # Drop IAM users from Redshift + print("\\nDropping IAM users from Redshift...") + iam_redshift_users = """ + str(iam_redshift_users) + """ + for user in iam_redshift_users: + try: + cursor.execute(f'DROP USER IF EXISTS "{user}";') + print(f"Dropped IAM user from Redshift: {user}") + except Exception as e: + print(f"Error dropping IAM user {user}: {e}") + + # Drop local roles + print("\\nDropping local roles...") + roles = """ + str(roles) + """ + for role in roles: + try: + cursor.execute(f"DROP ROLE {role} FORCE;") + print(f"Dropped role: {role}") + except Exception as e: + print(f"Error dropping role {role}: {e}") + + print("Redshift cleanup completed successfully!") + except Exception as e: + print(f"Error in Redshift cleanup: {e}") + finally: + if 'conn' in locals(): + conn.close() + + # ===== IAM CLEANUP ===== + print("\\n=== IAM CLEANUP ===") + try: + # Get AWS configuration + region = config['aws']['region'] + profile = config['aws'].get('config_profile', None) + + # Create boto3 session and clients + session = boto3.Session(profile_name=profile, region_name=region) if profile else boto3.Session(region_name=region) + iam_client = session.client('iam') + + # Delete IAM users + iam_users = """ + str(iam_users_to_delete) + """ + print("Deleting IAM users...") + for username in iam_users: + try: + iam_client.delete_user(UserName=username) + print(f"Deleted IAM user: {username}") + except Exception as e: + print(f"Error deleting IAM user {username}: {e}") + + # Delete IAM roles + iam_roles = """ + str(iam_roles_to_delete) + """ + print("\\nDeleting IAM roles...") + for rolename in iam_roles: + try: + iam_client.delete_role(RoleName=rolename) + print(f"Deleted IAM role: {rolename}") + except Exception as e: + print(f"Error deleting IAM role {rolename}: {e}") + + print("IAM cleanup completed successfully!") + except Exception as e: + print(f"Error in IAM cleanup: {e}") + + print("\\nIAM and Redshift cleanup process completed!") + +if __name__ == "__main__": + cleanup_all() +""" + else: + cleanup_content = common_imports + common_config + """ + print("Starting Redshift cleanup process...\\n") + + # ===== REDSHIFT CLEANUP ===== + print("=== REDSHIFT CLEANUP ===") + try: +""" + secrets_manager_code + """ + conn = psycopg2.connect(**conn_params) + conn.autocommit = True + cursor = conn.cursor() + + # Get datashare database name + datashare_db = config['parameters']['datashare_database_name'] + object_level_permissions = config.getboolean('parameters', 'object_level_permissions') + + # Revoke permissions from test_user_analyst3 + print("Revoking permissions from test_user_analyst3...") + try: + cursor.execute(f"REVOKE USAGE ON DATABASE {datashare_db} FROM test_user_analyst3;") + if object_level_permissions: + cursor.execute(f"REVOKE USAGE ON SCHEMA {datashare_db}.tickit FROM test_user_analyst3;") + cursor.execute(f"REVOKE ALL ON ALL TABLES IN SCHEMA {datashare_db}.tickit FROM test_user_analyst3;") + print("Revoked permissions from test_user_analyst3") + except Exception as e: + print(f"Error revoking permissions from test_user_analyst3: {e}") + + # Revoke role relationships + print("\nRevoking role relationships...") + try: + cursor.execute("REVOKE ROLE test_role_tn_tickit_restricted FROM ROLE test_role_bn_etl;") + print("Revoked test_role_tn_tickit_restricted from test_role_bn_etl") + except Exception as e: + print(f"Error revoking roles: {e}") + + # Drop users + print("\\nDropping users...") + users = """ + str(users) + """ + for user in users: + try: + cursor.execute(f"DROP USER IF EXISTS {user};") + print(f"Dropped user: {user}") + except Exception as e: + print(f"Error dropping user {user}: {e}") + + # Drop local roles + print("\\nDropping local roles...") + roles = """ + str(roles) + """ + for role in roles: + try: + cursor.execute(f"DROP ROLE {role} FORCE;") + print(f"Dropped role: {role}") + except Exception as e: + print(f"Error dropping role {role}: {e}") + + print("Redshift cleanup completed successfully!") + except Exception as e: + print(f"Error in Redshift cleanup: {e}") + finally: + if 'conn' in locals(): + conn.close() + + print("\\nRedshift cleanup process completed!") + +if __name__ == "__main__": + cleanup_all() +""" + + with open(cleanup_file, 'w') as f: + f.write(cleanup_content) + + print(f"Unified cleanup script generated at: {cleanup_file}") + return cleanup_file \ No newline at end of file diff --git a/src/LakeFormationMigrationUtility/tests/integration_test/int_readme.md b/src/LakeFormationMigrationUtility/tests/integration_test/int_readme.md new file mode 100644 index 00000000..6912c402 --- /dev/null +++ b/src/LakeFormationMigrationUtility/tests/integration_test/int_readme.md @@ -0,0 +1,154 @@ +# Integration Test for Redshift to Lake Formation Migration + +## Overview + +The `test_int_redshift_to_lakeformation.py` script is an integration test that validates the complete workflow of migrating permissions from Amazon Redshift to AWS Lake Formation. It creates test users, roles, and permissions in both Redshift and IAM Identity Center, then executes the migration utility to generate Lake Formation permission commands. + +## Prerequisites + +- Python 3.6+ +- Required Python packages: `psycopg2`, `configparser`, `boto3` +- AWS CLI configured with appropriate permissions +- Admin access to Amazon Redshift cluster +- IAM Identity Center configured +- Lake Formation permissions to grant/revoke access +- AWS Secrets Manager secret containing Redshift credentials + +## Configuration + +The script uses `test_int_config.ini` for configuration. Ensure the following sections are properly configured: + +### Required Configuration Sections + +- **[redshift]**: Redshift connection details and secrets manager configuration +- **[aws]**: AWS account details, region, and IAM Identity Center configuration +- **[parameters]**: Migration parameters including database names and permission settings + +## Test Workflow + +The integration test performs the following steps in sequence: + +### 1. Create IAM Users (`create_iam_users`) +- Creates IAM users and roles for testing IAM authentication +- Only runs when `auth_type = IAM` in configuration +- **Output**: Count of IAM users and roles created + +### 2. Setup Redshift Users and Roles (`setup_redshift_users_and_roles`) +- Creates test users in Redshift (when not using IAM auth) +- Creates business roles: admin, analyst, etl, adhoc +- Creates technical role: tickit_restricted +- Grants appropriate permissions based on `object_level_permissions` setting +- **Output**: Count of Redshift users and roles created + +### 3. Setup IAM Identity Center (`setup_idc_users_and_groups`) +- Creates users and groups in IAM Identity Center +- Assigns users to appropriate groups +- Only runs when `auth_type = IDC` in configuration +- **Output**: Count of IDC users and groups created + +### 4. Create AWSIDC Roles (`create_awsidc_roles`) +- Creates AWSIDC-prefixed roles in Redshift +- Creates AWSIDC user for direct permissions testing +- Grants permissions to AWSIDC roles based on their local counterparts +- **Output**: Count of IDC roles created in Redshift + +### 5. Execute Migration Script (`execute_ds_privs_to_lf`) +- Runs the `rs_privs_to_lf.py` script with test configuration +- Generates Lake Formation permission commands +- **Output**: Script execution results and generated files + +### 6. Generate Cleanup Script (`generate_unified_cleanup_script`) +- Creates `int_unified_cleanup.py` script for resource cleanup +- Includes cleanup for Redshift, IAM, and IAM Identity Center resources + +## Test Users and Roles + +### Standard Test Users +- `test_user_admin` - Administrative user +- `test_user_analyst1`, `test_user_analyst2` - Analyst users +- `test_user_analyst3` - Standalone analyst (direct permissions) +- `test_user_etl1`, `test_user_etl2` - ETL users +- `test_user_adhoc` - Ad-hoc query user + +### Business Roles +- `test_role_bn_admin` - Full administrative access +- `test_role_bn_analyst` - Read-only access to all tables +- `test_role_bn_etl` - ETL operations access +- `test_role_bn_adhoc` - Limited access to specific tables + +### Technical Roles +- `test_role_tn_tickit_restricted` - Restricted access to specific tables + +## Usage + +### Basic Execution +```bash +python test_int_redshift_to_lakeformation.py +``` + +### Expected Output +The script provides detailed timing information and resource counts: +- Start and end times for each function +- Duration of each operation +- Count of resources created in each step +- Total elapsed time for the entire test + +### Generated Files +- Lake Formation permission scripts in timestamped output directory +- Rollback scripts for permission cleanup +- `int_unified_cleanup.py` for complete resource cleanup + +## Cleanup + +After testing, run the generated cleanup script to remove all test resources: + +```bash +python int_unified_cleanup.py +``` + +This will clean up: +- Redshift users, roles, and permissions +- IAM users and roles (when applicable) +- IAM Identity Center users and groups (when applicable) + +## Authentication Types + +### IAM Authentication (`auth_type = IAM`) +- Creates IAM users and roles +- Creates IAM-prefixed users in Redshift +- Tests IAM-based authentication flow + +### IDC Authentication (`auth_type = IDC`) +- Creates users and groups in IAM Identity Center +- Creates AWSIDC-prefixed roles in Redshift +- Tests Identity Center-based authentication flow + +## Performance Monitoring + +The script includes comprehensive timing and counting features: +- Individual function execution times +- Resource creation counts for each step +- Total test execution time +- Detailed progress reporting + +## Troubleshooting + +### Common Issues +1. **Configuration Errors**: Verify `test_int_config.ini` settings +2. **Permission Issues**: Ensure AWS credentials have required permissions +3. **Connection Failures**: Check Redshift connectivity and secrets manager access +4. **Resource Conflicts**: Run cleanup script before retesting + +### Debug Information +The script provides detailed output including: +- Resource creation confirmations +- Error messages with context +- Timing information for performance analysis +- Resource counts for validation + +## Security Considerations + +- Test credentials are stored in AWS Secrets Manager +- IAM policies should follow least-privilege principles +- Test resources should be cleaned up after use +- Review generated Lake Formation commands before production use \ No newline at end of file diff --git a/src/LakeFormationMigrationUtility/tests/integration_test/int_unified_cleanup.py b/src/LakeFormationMigrationUtility/tests/integration_test/int_unified_cleanup.py new file mode 100644 index 00000000..a148baf4 --- /dev/null +++ b/src/LakeFormationMigrationUtility/tests/integration_test/int_unified_cleanup.py @@ -0,0 +1,214 @@ +import boto3 +import psycopg2 +import configparser +import os +import json + + +def cleanup_all(): + config = configparser.ConfigParser() + config_path = os.path.join(os.path.dirname(__file__), 'test_int_config.ini') + config.read(config_path) + + print("Starting unified cleanup process...\n") + + # ===== REDSHIFT CLEANUP ===== + print("=== REDSHIFT CLEANUP ===") + try: + + # Get credentials from Secrets Manager + secret_name = config['redshift']['secret_name'] + region = config['aws']['region'] + profile = config['aws'].get('config_profile', None) + + # Create boto3 session and clients + session = boto3.Session(profile_name=profile, region_name=region) if profile else boto3.Session(region_name=region) + secrets_client = session.client('secretsmanager') + + # Get secret value + response = secrets_client.get_secret_value(SecretId=secret_name) + secret = json.loads(response['SecretString']) + + # Create connection parameters + conn_params = { + 'host': config['redshift']['host'], + 'port': config['redshift']['port'], + 'dbname': config['redshift']['dbname'], + 'user': secret['username'], + 'password': secret['password'] + } + + conn = psycopg2.connect(**conn_params) + conn.autocommit = True + cursor = conn.cursor() + + # Get datashare database name + datashare_db = config['parameters']['datashare_database_name'] + object_level_permissions = config.getboolean('parameters', 'object_level_permissions') + + # Revoke permissions from test_user_analyst3 and AWSIDC:test_user_analyst3@example.com + print("Revoking permissions from test_user_analyst3 and AWSIDC:test_user_analyst3@example.com...") + try: + # Revoke permissions from test_user_analyst3 + cursor.execute(f"REVOKE USAGE ON DATABASE {datashare_db} FROM test_user_analyst3;") + if object_level_permissions: + cursor.execute(f"REVOKE USAGE ON SCHEMA {datashare_db}.tickit FROM test_user_analyst3;") + cursor.execute(f"REVOKE ALL ON ALL TABLES IN SCHEMA {datashare_db}.tickit FROM test_user_analyst3;") + print("Revoked permissions from test_user_analyst3") + + # Revoke permissions from AWSIDC:test_user_analyst3@example.com + cursor.execute(f'REVOKE USAGE ON DATABASE {datashare_db} FROM "AWSIDC:test_user_analyst3@example.com";') + if object_level_permissions: + cursor.execute(f'REVOKE USAGE ON SCHEMA {datashare_db}.tickit FROM "AWSIDC:test_user_analyst3@example.com";') + cursor.execute(f'REVOKE ALL ON ALL TABLES IN SCHEMA {datashare_db}.tickit FROM "AWSIDC:test_user_analyst3@example.com";') + print("Revoked permissions from AWSIDC:test_user_analyst3@example.com") + except Exception as e: + print(f"Error revoking permissions: {e}") + + # Revoke role relationships + print("\nRevoking role relationships...") + try: + cursor.execute("REVOKE ROLE test_role_tn_tickit_restricted FROM ROLE test_role_bn_etl;") + print("Revoked test_role_tn_tickit_restricted from test_role_bn_etl") + cursor.execute('REVOKE ROLE test_role_tn_tickit_restricted FROM ROLE "AWSIDC:test_role_bn_etl";') + print("Revoked test_role_tn_tickit_restricted from AWSIDC:test_role_bn_etl") + except Exception as e: + print(f"Error revoking roles: {e}") + + # Drop users + print("\nDropping users...") + users = ['test_user_admin', 'test_user_analyst1', 'test_user_analyst2', 'test_user_analyst3', 'test_user_etl1', 'test_user_etl2', 'test_user_adhoc'] + for user in users: + try: + cursor.execute(f"DROP USER IF EXISTS {user};") + print(f"Dropped user: {user}") + except Exception as e: + print(f"Error dropping user {user}: {e}") + + # Drop AWSIDC users first + print("\nDropping AWSIDC users...") + awsidc_users = ['AWSIDC:test_user_analyst3@example.com'] + for user in awsidc_users: + try: + cursor.execute(f'DROP USER "{user}";') + print(f"Dropped AWSIDC user: {user}") + except Exception as e: + print(f"Error dropping AWSIDC user {user}: {e}") + + # Drop AWSIDC roles + print("\nDropping AWSIDC roles...") + awsidc_roles = ['AWSIDC:test_role_bn_admin', 'AWSIDC:test_role_bn_analyst', 'AWSIDC:test_role_bn_etl', 'AWSIDC:test_role_bn_adhoc'] + for role in awsidc_roles: + try: + cursor.execute(f'DROP ROLE "{role}" FORCE;') + print(f"Dropped AWSIDC role: {role}") + except Exception as e: + print(f"Error dropping AWSIDC role {role}: {e}") + + # Drop local roles + print("\nDropping local roles...") + roles = ['test_role_bn_admin', 'test_role_bn_analyst', 'test_role_bn_etl', 'test_role_tn_tickit_restricted', 'test_role_bn_adhoc'] + for role in roles: + try: + cursor.execute(f"DROP ROLE {role} FORCE;") + print(f"Dropped role: {role}") + except Exception as e: + print(f"Error dropping role {role}: {e}") + + print("Redshift cleanup completed successfully!") + except Exception as e: + print(f"Error in Redshift cleanup: {e}") + finally: + if 'conn' in locals(): + conn.close() + + # ===== IAM IDENTITY CENTER CLEANUP ===== + print("\n=== IAM IDENTITY CENTER CLEANUP ===") + try: + # Get IAM Identity Center configuration + identity_store_id = config['aws']['identity_store_id'] + region = config['aws']['region'] + profile = config['aws'].get('config_profile', None) + + # Create boto3 session and clients + session = boto3.Session(profile_name=profile, region_name=region) if profile else boto3.Session(region_name=region) + identity_store_client = session.client('identitystore') + + # List of users and groups to delete + users = ['test_user_admin', 'test_user_analyst1', 'test_user_analyst2', 'test_user_analyst3', 'test_user_etl1', 'test_user_etl2', 'test_user_adhoc'] + groups = ['test_role_bn_admin', 'test_role_bn_analyst', 'test_role_bn_etl', 'test_role_bn_adhoc'] + + # Find and delete group memberships and groups + print("Processing groups...") + for group_name in groups: + try: + # List groups to find the ID + response = identity_store_client.list_groups( + IdentityStoreId=identity_store_id, + Filters=[{ + 'AttributePath': 'DisplayName', + 'AttributeValue': group_name + }] + ) + + for group in response.get('Groups', []): + group_id = group['GroupId'] + print(f"Found group {group_name} with ID: {group_id}") + + # List group memberships + memberships = identity_store_client.list_group_memberships( + IdentityStoreId=identity_store_id, + GroupId=group_id + ) + + # Delete each membership + for membership in memberships.get('GroupMemberships', []): + identity_store_client.delete_group_membership( + IdentityStoreId=identity_store_id, + MembershipId=membership['MembershipId'] + ) + print(f"Deleted membership {membership['MembershipId']} from group {group_name}") + + # Delete the group + identity_store_client.delete_group( + IdentityStoreId=identity_store_id, + GroupId=group_id + ) + print(f"Deleted group {group_name}") + except Exception as e: + print(f"Error processing group {group_name}: {e}") + + # Find and delete users + print("\nProcessing users...") + for username in users: + try: + # List users to find the ID + response = identity_store_client.list_users( + IdentityStoreId=identity_store_id, + Filters=[{ + 'AttributePath': 'UserName', + 'AttributeValue': username + }] + ) + + for user in response.get('Users', []): + user_id = user['UserId'] + print(f"Found user {username} with ID: {user_id}") + + # Delete the user + identity_store_client.delete_user( + IdentityStoreId=identity_store_id, + UserId=user_id + ) + print(f"Deleted user {username}") + except Exception as e: + print(f"Error processing user {username}: {e}") + + print("IAM Identity Center cleanup completed successfully!") + except Exception as e: + print(f"Error in IAM Identity Center cleanup: {e}") + + print("\nUnified cleanup process completed!") + +if __name__ == "__main__": + cleanup_all() diff --git a/src/LakeFormationMigrationUtility/tests/integration_test/test_int_config.ini b/src/LakeFormationMigrationUtility/tests/integration_test/test_int_config.ini new file mode 100644 index 00000000..aa4403d8 --- /dev/null +++ b/src/LakeFormationMigrationUtility/tests/integration_test/test_int_config.ini @@ -0,0 +1,26 @@ +# Example values provided +[redshift] +host = your-redshift-cluster.region.redshift.amazonaws.com +port = 5439 +dbname = your-database-name +# AWS Secrets Manager secret containing Redshift credentials +secret_name = your-secret-name + +[aws] +account_id = 123456789012 +region = us-east-1 +producer_catalog = your-producer-catalog-name +# AWS CLI profile to use (optional) +config_profile = your-aws-cli-profile +# Identity Store ID for IDC user lookups +identity_store_id = d-1234567890 +iam_idc_instance_arn = arn:aws:sso:::instance/ssoins-123456a8efd4d123 + +[parameters] +# Name of database on the consumer cluster created from the datashare +datashare_database_name = your_datashare_db +# Set to true if the datashare database was created with the 'WITH PERMISSIONS' clause +datashare_object_level_permissions = true +object_level_permissions = true +# Whether to run the rollback script after the test (true) or leave permissions in place (false) +test_rollback = false \ No newline at end of file diff --git a/src/LakeFormationMigrationUtility/tests/integration_test/test_int_redshift_to_lakeformation.py b/src/LakeFormationMigrationUtility/tests/integration_test/test_int_redshift_to_lakeformation.py new file mode 100644 index 00000000..aa47ef0b --- /dev/null +++ b/src/LakeFormationMigrationUtility/tests/integration_test/test_int_redshift_to_lakeformation.py @@ -0,0 +1,622 @@ + +import configparser +import psycopg2 +import os +import boto3 +import uuid +import subprocess +import sys +import json +from datetime import datetime + +def get_redshift_credentials(config): + # Get AWS configuration + region = config['aws']['region'] + profile = config['aws'].get('config_profile', None) + secret_name = config['redshift']['secret_name'] + + # Create boto3 session and clients + session = boto3.Session(profile_name=profile, region_name=region) if profile else boto3.Session(region_name=region) + secrets_client = session.client('secretsmanager') + + try: + # Get secret value + response = secrets_client.get_secret_value(SecretId=secret_name) + secret = json.loads(response['SecretString']) + + # Create connection parameters + conn_params = { + 'host': config['redshift']['host'], + 'port': config['redshift']['port'], + 'dbname': config['redshift']['dbname'], + 'user': secret['username'], + 'password': secret['password'] + } + + return conn_params + except Exception as e: + print(f"Error retrieving Redshift credentials from Secrets Manager: {e}") + raise + +def create_iam_users(): + config = configparser.ConfigParser() + config_path = os.path.join(os.path.dirname(__file__), 'test_int_config.ini') + config.read(config_path) + + # Check auth_type - only run if IAM + auth_type = config['aws']['auth_type'] + if auth_type.upper() != 'IAM': + print("Skipping IAM users creation - auth_type is not set to IAM") + return + + # Get AWS configuration + region = config['aws']['region'] + profile = config['aws'].get('config_profile', None) + + # Create boto3 session and clients + session = boto3.Session(profile_name=profile, region_name=region) if profile else boto3.Session(region_name=region) + iam_client = session.client('iam') + + users = [ + 'test_user_admin', + 'test_user_analyst1', + 'test_user_analyst2', + 'test_user_etl1', + 'test_user_etl2' + ] + + roles = [ + 'test_user_adhoc' + ] + + users_created = 0 + roles_created = 0 + + try: + print("\n=== CREATING IAM USERS AND ROLES ===") + + # Create IAM users + for username in users: + try: + iam_client.create_user(UserName=username) + print(f"Created IAM user: {username}") + users_created += 1 + except Exception as e: + print(f"Error creating IAM user {username}: {e}") + + # Create IAM roles + for rolename in roles: + try: + assume_role_policy = { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Principal": { + "Service": "redshift.amazonaws.com" + }, + "Action": "sts:AssumeRole" + } + ] + } + iam_client.create_role( + RoleName=rolename, + AssumeRolePolicyDocument=str(assume_role_policy).replace("'", '"') + ) + print(f"Created IAM role: {rolename}") + roles_created += 1 + except Exception as e: + print(f"Error creating IAM role {rolename}: {e}") + + print(f"IAM users and roles creation completed successfully! Created {users_created} users and {roles_created} roles.") + + except Exception as e: + print(f"Error setting up IAM users: {e}") + +def setup_redshift_users_and_roles(): + config = configparser.ConfigParser() + config_path = os.path.join(os.path.dirname(__file__), 'test_int_config.ini') + config.read(config_path) + + # Check auth_type - skip user creation if IAM + auth_type = config['aws']['auth_type'] + + # Get connection parameters from Secrets Manager + conn_params = get_redshift_credentials(config) + + datashare_db = config['parameters']['datashare_database_name'] + object_level_permissions = config.getboolean('parameters', 'object_level_permissions') + + users = [ + 'test_user_admin', + 'test_user_analyst1', + 'test_user_analyst2', + 'test_user_analyst3', + 'test_user_etl1', + 'test_user_etl2', + 'test_user_adhoc' + ] + + # Define roles + roles = { + 'test_role_bn_admin': ['test_user_admin'], + 'test_role_bn_analyst': ['test_user_analyst1', 'test_user_analyst2'], + 'test_role_bn_etl': ['test_user_etl1', 'test_user_etl2'], + 'test_role_bn_adhoc': ['test_user_adhoc'] + } + + users_created = 0 + roles_created = 0 + + try: + conn = psycopg2.connect(**conn_params) + conn.autocommit = True + cursor = conn.cursor() + + # Create users only if auth_type is not IAM + if auth_type.upper() != 'IAM': + for username in users: + password = f"{username}_Pass123" + try: + cursor.execute(f"CREATE USER {username} PASSWORD '{password}';") + print(f"Created user: {username}") + users_created += 1 + except Exception as e: + print(f"Error creating user {username}: {e}") + else: + print("Skipping normal user creation - auth_type is set to IAM") + + # Create roles and assign to users + for role_name, role_users in roles.items(): + try: + cursor.execute(f"CREATE ROLE {role_name};") + print(f"Created role: {role_name}") + roles_created += 1 + + # Only grant roles to users if auth_type is not IAM + if auth_type.upper() != 'IAM': + for username in role_users: + cursor.execute(f"GRANT ROLE {role_name} TO {username};") + print(f"Granted role {role_name} to user {username}") + except Exception as e: + print(f"Error with role {role_name}: {e}") + + # Create restricted role for ETL + try: + cursor.execute("CREATE ROLE test_role_tn_tickit_restricted;") + print("Created role: test_role_tn_tickit_restricted") + roles_created += 1 + + # Grant restricted role to ETL role + cursor.execute("GRANT ROLE test_role_tn_tickit_restricted TO ROLE test_role_bn_etl;") + print("Granted test_role_tn_tickit_restricted to test_role_bn_etl") + except Exception as e: + print(f"Error creating restricted role: {e}") + + # Grant permissions to roles + try: + # Grant USAGE permissions based on object_level_permissions setting + all_roles = ['test_role_bn_admin', 'test_role_bn_analyst', 'test_role_bn_etl', 'test_role_tn_tickit_restricted', 'test_role_bn_adhoc'] + for role in all_roles: + cursor.execute(f"GRANT USAGE ON DATABASE {datashare_db} TO ROLE {role};") + + # Grant database USAGE to test_user_analyst3 + cursor.execute(f"GRANT USAGE ON DATABASE {datashare_db} TO test_user_analyst3;") + if object_level_permissions: + cursor.execute(f"GRANT USAGE ON SCHEMA {datashare_db}.tickit TO ROLE {role};") + if object_level_permissions: + print(f"Granted USAGE on database {datashare_db} and schema tickit to all roles") + else: + print(f"Granted USAGE on database {datashare_db} to all roles") + + # Only grant table permissions when object_level_permissions is true + if object_level_permissions: + # Admin role - all permissions on all tables + cursor.execute(f"GRANT ALL ON ALL TABLES IN SCHEMA {datashare_db}.tickit TO ROLE test_role_bn_admin;") + print(f"Granted ALL permissions on {datashare_db}.tickit to test_role_bn_admin") + + # Analyst role - select on all tables + cursor.execute(f"GRANT SELECT ON ALL TABLES IN SCHEMA {datashare_db}.tickit TO ROLE test_role_bn_analyst;") + print(f"Granted SELECT permissions on {datashare_db}.tickit to test_role_bn_analyst") + + # Restricted role - specific table permissions + cursor.execute(f"GRANT SELECT, UPDATE, DELETE, INSERT ON TABLE {datashare_db}.tickit.sales TO ROLE test_role_tn_tickit_restricted;") + cursor.execute(f"GRANT SELECT, UPDATE, DELETE, INSERT ON TABLE {datashare_db}.tickit.event TO ROLE test_role_tn_tickit_restricted;") + print(f"Granted specific permissions on sales and event tables to test_role_tn_tickit_restricted") + + # Adhoc role - select on sales table + cursor.execute(f"GRANT SELECT ON TABLE {datashare_db}.tickit.sales TO ROLE test_role_bn_adhoc;") + print(f"Granted SELECT permissions on sales table to test_role_bn_adhoc") + + # Direct grants to test_user_analyst3 + cursor.execute(f"GRANT USAGE ON SCHEMA {datashare_db}.tickit TO test_user_analyst3;") + cursor.execute(f"GRANT SELECT ON ALL TABLES IN SCHEMA {datashare_db}.tickit TO test_user_analyst3;") + print(f"Granted USAGE on schema and SELECT permissions on {datashare_db}.tickit to test_user_analyst3") + else: + print("Skipping table-level permissions - object_level_permissions is set to false") + except Exception as e: + print(f"Error granting permissions: {e}") + + print(f"Setup completed successfully! Created {users_created} users and {roles_created} roles.") + + except Exception as e: + print(f"Error: {e}") + finally: + if 'conn' in locals(): + conn.close() + + + +def create_iam_users_in_redshift(): + config = configparser.ConfigParser() + config_path = os.path.join(os.path.dirname(__file__), 'test_int_config.ini') + config.read(config_path) + + # Get connection parameters from Secrets Manager + conn_params = get_redshift_credentials(config) + + users = [ + 'test_user_admin', + 'test_user_analyst1', + 'test_user_analyst2', + 'test_user_etl1', + 'test_user_etl2' + ] + + # Define role mappings + role_mappings = { + 'test_role_bn_admin': ['test_user_admin'], + 'test_role_bn_analyst': ['test_user_analyst1', 'test_user_analyst2'], + 'test_role_bn_etl': ['test_user_etl1', 'test_user_etl2'], + 'test_role_bn_adhoc': ['test_user_adhoc'] + } + + try: + conn = psycopg2.connect(**conn_params) + conn.autocommit = True + cursor = conn.cursor() + + print("\n=== CREATING IAM USERS IN REDSHIFT ===") + + # Create IAM users with IAM: prefix + for username in users: + iam_username = f"IAM:{username}" + try: + cursor.execute(f'CREATE USER "{iam_username}" PASSWORD DISABLE;') + print(f"Created Redshift IAM user: {iam_username}") + except Exception as e: + print(f"Error creating Redshift IAM user {iam_username}: {e}") + + # Create IAMR: user for test_user_adhoc + try: + cursor.execute('CREATE USER "IAMR:test_user_adhoc" PASSWORD DISABLE;') + print("Created Redshift IAM role user: IAMR:test_user_adhoc") + except Exception as e: + print(f"Error creating Redshift IAM role user IAMR:test_user_adhoc: {e}") + + # Grant roles to IAM users + for role_name, role_users in role_mappings.items(): + for username in role_users: + if username == 'test_user_adhoc': + iam_username = f"IAMR:{username}" + else: + iam_username = f"IAM:{username}" + try: + cursor.execute(f'GRANT ROLE {role_name} TO "{iam_username}";') + print(f"Granted role {role_name} to {iam_username}") + except Exception as e: + print(f"Error granting role {role_name} to {iam_username}: {e}") + + print("IAM users in Redshift setup completed successfully!") + + except Exception as e: + print(f"Error setting up IAM users in Redshift: {e}") + finally: + if 'conn' in locals(): + conn.close() + +def setup_idc_users_and_groups(): + config = configparser.ConfigParser() + config_path = os.path.join(os.path.dirname(__file__), 'test_int_config.ini') + config.read(config_path) + + # Check auth_type + auth_type = config['aws']['auth_type'] + if auth_type.upper() == 'IAM': + # Create IAM users in Redshift when auth_type is IAM + create_iam_users_in_redshift() + return + + # Get IAM Identity Center configuration + identity_store_id = config['aws']['identity_store_id'] + region = config['aws']['region'] + profile = config['aws'].get('config_profile', None) + + # Create boto3 session and clients + session = boto3.Session(profile_name=profile, region_name=region) if profile else boto3.Session(region_name=region) + identity_store_client = session.client('identitystore') + + users = [ + 'test_user_admin', + 'test_user_analyst1', + 'test_user_analyst2', + 'test_user_analyst3', + 'test_user_etl1', + 'test_user_etl2', + 'test_user_adhoc' + ] + + # Define groups (same as Redshift roles) + groups = { + 'test_role_bn_admin': ['test_user_admin'], + 'test_role_bn_analyst': ['test_user_analyst1', 'test_user_analyst2'], + 'test_role_bn_etl': ['test_user_etl1', 'test_user_etl2'], + 'test_role_bn_adhoc': ['test_user_adhoc'] + } + + user_ids = {} + group_ids = {} + users_created = 0 + groups_created = 0 + + try: + # Create users in IAM Identity Center + for username in users: + try: + # Create user + response = identity_store_client.create_user( + IdentityStoreId=identity_store_id, + UserName=username, + Name={ + 'GivenName': username.split('_')[-1].capitalize(), + 'FamilyName': 'TestUser' + }, + DisplayName=username, + Emails=[{ + 'Value': f"{username}@example.com", + 'Type': 'work', + 'Primary': True + }] + ) + user_ids[username] = response['UserId'] + print(f"Created IAM Identity Center user: {username} (ID: {user_ids[username]})") + users_created += 1 + except Exception as e: + print(f"Error creating IAM Identity Center user {username}: {e}") + + # Create groups in IAM Identity Center + for group_name in groups.keys(): + try: + # Create group + response = identity_store_client.create_group( + IdentityStoreId=identity_store_id, + DisplayName=group_name, + Description=f"Group for {group_name} users" + ) + group_ids[group_name] = response['GroupId'] + print(f"Created IAM Identity Center group: {group_name} (ID: {group_ids[group_name]})") + groups_created += 1 + except Exception as e: + print(f"Error creating IAM Identity Center group {group_name}: {e}") + + # Assign users to groups + for group_name, group_users in groups.items(): + if group_name not in group_ids: + continue + + for username in group_users: + if username not in user_ids: + continue + + try: + identity_store_client.create_group_membership( + IdentityStoreId=identity_store_id, + GroupId=group_ids[group_name], + MemberId={ + 'UserId': user_ids[username] + } + ) + print(f"Added user {username} to group {group_name}") + except Exception as e: + print(f"Error adding user {username} to group {group_name}: {e}") + + print(f"IAM Identity Center setup completed successfully! Created {users_created} users and {groups_created} groups.") + + except Exception as e: + print(f"Error setting up IAM Identity Center: {e}") + + + +def create_awsidc_roles(): + config = configparser.ConfigParser() + config_path = os.path.join(os.path.dirname(__file__), 'test_int_config.ini') + config.read(config_path) + + # Check auth_type - skip if IAM + auth_type = config['aws']['auth_type'] + if auth_type.upper() == 'IAM': + print("Skipping AWSIDC roles creation - auth_type is set to IAM") + return + + # Get connection parameters from Secrets Manager + conn_params = get_redshift_credentials(config) + + datashare_db = config['parameters']['datashare_database_name'] + object_level_permissions = config.getboolean('parameters', 'object_level_permissions') + + # Define the mapping between local roles and AWSIDC roles + role_mappings = { + 'test_role_bn_admin': 'AWSIDC:test_role_bn_admin', + 'test_role_bn_analyst': 'AWSIDC:test_role_bn_analyst', + 'test_role_bn_etl': 'AWSIDC:test_role_bn_etl', + 'test_role_bn_adhoc': 'AWSIDC:test_role_bn_adhoc' + } + + awsidc_roles_created = 0 + + try: + conn = psycopg2.connect(**conn_params) + conn.autocommit = True + cursor = conn.cursor() + + print("\n=== CREATING AWSIDC ROLES ===") + + # Create AWSIDC roles + for local_role, awsidc_role in role_mappings.items(): + try: + cursor.execute(f'CREATE ROLE "{awsidc_role}";') + print(f"Created AWSIDC role: {awsidc_role}") + awsidc_roles_created += 1 + except Exception as e: + print(f"Error creating AWSIDC role {awsidc_role}: {e}") + + # Grant existing technical role to AWSIDC ETL role + try: + cursor.execute('GRANT ROLE test_role_tn_tickit_restricted TO ROLE "AWSIDC:test_role_bn_etl";') + print("Granted test_role_tn_tickit_restricted to AWSIDC:test_role_bn_etl") + except Exception as e: + print(f"Error granting technical role to AWSIDC ETL role: {e}") + + # Create AWSIDC user for test_user_analyst3@example.com + try: + cursor.execute('CREATE USER "AWSIDC:test_user_analyst3@example.com" PASSWORD DISABLE;') + print("Created AWSIDC user: AWSIDC:test_user_analyst3@example.com") + awsidc_roles_created += 1 + except Exception as e: + print(f"Error creating AWSIDC user AWSIDC:test_user_analyst3@example.com: {e}") + + # Grant permissions to AWSIDC roles based on their local counterparts + try: + # Grant USAGE permissions based on object_level_permissions setting + awsidc_roles_list = ['"AWSIDC:test_role_bn_admin"', '"AWSIDC:test_role_bn_analyst"', '"AWSIDC:test_role_bn_etl"', '"AWSIDC:test_role_bn_adhoc"'] + for role in awsidc_roles_list: + cursor.execute(f"GRANT USAGE ON DATABASE {datashare_db} TO ROLE {role};") + if object_level_permissions: + cursor.execute(f"GRANT USAGE ON SCHEMA {datashare_db}.tickit TO ROLE {role};") + + # Grant USAGE on schema to test_user_analyst3 regardless of object_level_permissions setting + cursor.execute(f'GRANT USAGE ON DATABASE {datashare_db} TO "AWSIDC:test_user_analyst3@example.com";') + if object_level_permissions: + cursor.execute(f'GRANT USAGE ON SCHEMA {datashare_db}.tickit TO "AWSIDC:test_user_analyst3@example.com";') + if object_level_permissions: + print(f"Granted USAGE on database {datashare_db} and schema tickit to all AWSIDC roles") + else: + print(f"Granted USAGE on database {datashare_db} to all AWSIDC roles") + + # Only grant table permissions when object_level_permissions is true + if object_level_permissions: + # AWSIDC Admin role - same as local admin role + cursor.execute(f'GRANT ALL ON ALL TABLES IN SCHEMA {datashare_db}.tickit TO ROLE "AWSIDC:test_role_bn_admin";') + print(f"Granted ALL permissions on {datashare_db}.tickit to AWSIDC:test_role_bn_admin") + + # AWSIDC Analyst role - same as local analyst role + cursor.execute(f'GRANT SELECT ON ALL TABLES IN SCHEMA {datashare_db}.tickit TO ROLE "AWSIDC:test_role_bn_analyst";') + print(f"Granted SELECT permissions on {datashare_db}.tickit to AWSIDC:test_role_bn_analyst") + + # AWSIDC Adhoc role - select on sales table + cursor.execute(f'GRANT SELECT ON TABLE {datashare_db}.tickit.sales TO ROLE "AWSIDC:test_role_bn_adhoc";') + print(f"Granted SELECT permissions on sales table to AWSIDC:test_role_bn_adhoc") + + # AWSIDC test_user_analyst3@example.com - direct grants + cursor.execute(f'GRANT USAGE ON SCHEMA {datashare_db}.tickit TO "AWSIDC:test_user_analyst3@example.com";') + cursor.execute(f'GRANT SELECT ON ALL TABLES IN SCHEMA {datashare_db}.tickit TO "AWSIDC:test_user_analyst3@example.com";') + print(f"Granted USAGE on schema and SELECT permissions on {datashare_db}.tickit to AWSIDC:test_user_analyst3@example.com") + else: + print("Skipping table-level permissions for AWSIDC roles - object_level_permissions is set to false") + except Exception as e: + print(f"Error granting permissions to AWSIDC roles: {e}") + + print(f"AWSIDC roles setup completed successfully! Created {awsidc_roles_created} IDC roles in Redshift.") + + except Exception as e: + print(f"Error setting up AWSIDC roles: {e}") + finally: + if 'conn' in locals(): + conn.close() + +def execute_ds_privs_to_lf(): + config_path = os.path.join(os.path.dirname(__file__), 'test_int_config.ini') + ds_script_path = os.path.join(os.path.dirname(__file__), '../../src', 'rs_privs_to_lf.py') + + try: + print("\n=== EXECUTING DS_PRIVS_TO_LF SCRIPT ===") + result = subprocess.run( + [sys.executable, ds_script_path, '--config', config_path], + capture_output=True, + text=True, + cwd=os.path.dirname(ds_script_path) + ) + + print(f"Return code: {result.returncode}") + if result.stdout: + print(f"Output:\n{result.stdout}") + if result.stderr: + print(f"Errors:\n{result.stderr}") + + if result.returncode == 0: + print("rs_privs_to_lf.py executed successfully!") + else: + print(f"rs_privs_to_lf.py execution failed with return code {result.returncode}") + + except Exception as e: + print(f"Error executing rs_privs_to_lf.py: {e}") + + + +def generate_unified_cleanup_script(): + # Import the cleanup script generator + from cleanup_script_generator import generate_unified_cleanup_script + return generate_unified_cleanup_script() + + +if __name__ == "__main__": + overall_start_time = datetime.now() + print(f"Integration test started at: {overall_start_time.strftime('%Y-%m-%d %H:%M:%S')}\n") + + # create_iam_users + start_time = datetime.now() + print(f"Starting create_iam_users at: {start_time.strftime('%H:%M:%S')}") + create_iam_users() + end_time = datetime.now() + print(f"Completed create_iam_users at: {end_time.strftime('%H:%M:%S')} (Duration: {end_time - start_time})\n") + + # setup_redshift_users_and_roles + start_time = datetime.now() + print(f"Starting setup_redshift_users_and_roles at: {start_time.strftime('%H:%M:%S')}") + setup_redshift_users_and_roles() + end_time = datetime.now() + print(f"Completed setup_redshift_users_and_roles at: {end_time.strftime('%H:%M:%S')} (Duration: {end_time - start_time})\n") + + # setup_idc_users_and_groups + start_time = datetime.now() + print(f"Starting setup_idc_users_and_groups at: {start_time.strftime('%H:%M:%S')}") + setup_idc_users_and_groups() + end_time = datetime.now() + print(f"Completed setup_idc_users_and_groups at: {end_time.strftime('%H:%M:%S')} (Duration: {end_time - start_time})\n") + + # create_awsidc_roles + start_time = datetime.now() + print(f"Starting create_awsidc_roles at: {start_time.strftime('%H:%M:%S')}") + create_awsidc_roles() + end_time = datetime.now() + print(f"Completed create_awsidc_roles at: {end_time.strftime('%H:%M:%S')} (Duration: {end_time - start_time})\n") + + # execute_ds_privs_to_lf + start_time = datetime.now() + print(f"Starting execute_ds_privs_to_lf at: {start_time.strftime('%H:%M:%S')}") + execute_ds_privs_to_lf() + end_time = datetime.now() + print(f"Completed execute_ds_privs_to_lf at: {end_time.strftime('%H:%M:%S')} (Duration: {end_time - start_time})\n") + + # generate_unified_cleanup_script + start_time = datetime.now() + print(f"Starting generate_unified_cleanup_script at: {start_time.strftime('%H:%M:%S')}") + generate_unified_cleanup_script() + end_time = datetime.now() + print(f"Completed generate_unified_cleanup_script at: {end_time.strftime('%H:%M:%S')} (Duration: {end_time - start_time})\n") + + final_end_time = datetime.now() + total_elapsed = final_end_time - overall_start_time + print(f"Integration test completed at: {final_end_time.strftime('%Y-%m-%d %H:%M:%S')}") + print(f"Total elapsed time: {total_elapsed}") + print(f"Total elapsed time (seconds): {total_elapsed.total_seconds():.2f}s") \ No newline at end of file diff --git a/src/LakeFormationMigrationUtility/tests/performance_test/perf_readme.md b/src/LakeFormationMigrationUtility/tests/performance_test/perf_readme.md new file mode 100644 index 00000000..a0503621 --- /dev/null +++ b/src/LakeFormationMigrationUtility/tests/performance_test/perf_readme.md @@ -0,0 +1,199 @@ +# Performance Test for Redshift to Lake Formation Migration + +## Overview + +The `test_perf_redshift_to_lakeformation.py` script is a performance testing tool that creates large-scale test environments to validate the scalability and performance of the Redshift to Lake Formation migration utility. It generates configurable numbers of schemas, tables, users, groups, and roles to test the migration process at scale. + +## Prerequisites + +- Python 3.6+ +- Required Python packages: `psycopg2`, `configparser`, `boto3` +- AWS CLI configured with appropriate permissions +- Admin access to Amazon Redshift cluster +- IAM Identity Center configured +- Lake Formation permissions to grant/revoke access +- AWS Secrets Manager secret containing Redshift credentials + +## Configuration + +The script uses `test_perf_config.ini` for configuration. Key performance parameters: + +### Performance Parameters +- `number_of_schemas`: Number of test schemas to create (default: 20) +- `number_of_tables_per_schema`: Number of tables per schema (default: 30) +- `list_types`: User/role types (etl, adhoc, analyst, admin) +- `number_users_per_type`: Users per type per schema (default: 2) +- `iam_idc_namespace`: Namespace for IDC roles (default: AWSIDC) + +### Required Configuration Sections +- **[redshift]**: Redshift connection details and secrets manager configuration +- **[aws]**: AWS account details, region, and IAM Identity Center configuration +- **[parameters]**: Migration parameters and performance test settings + +## Test Workflow + +The performance test executes the following operations with detailed timing and counting: + +### 1. Create Schemas and Tables (`create_schemas_and_tables`) +- Creates configurable number of test schemas in Redshift +- Creates configurable number of tables per schema +- Each table has simple structure: `id_col INTEGER, desc_col VARCHAR(100)` +- **Output**: Total schemas and tables created with timing + +### 2. Create IDC Users and Groups (`create_idc_users_and_groups`) +- Creates users and groups in IAM Identity Center for each schema and type +- Assigns users to appropriate groups +- Scales based on: `schemas × types × users_per_type` +- **Output**: Total IDC users and groups created with timing + +### 3. Create Redshift Roles (`create_redshift_roles`) +- Creates IDC-namespaced roles in Redshift for each schema and type +- Grants permissions based on role type: + - **ETL**: USAGE on schema + INSERT, UPDATE, DELETE, SELECT on tables + - **ADMIN**: ALL permissions on schema and tables + - **Others**: USAGE on schema + SELECT on tables +- **Output**: Total Redshift roles created with timing + +### 4. Execute Migration Script (`execute_rs_privs_to_lf`) +- Runs the `rs_privs_to_lf.py` script with performance test configuration +- Processes all created schemas, roles, and permissions +- **Output**: Migration script execution results and timing + +### 5. Generate Cleanup Script (`generate_cleanup_script`) +- Creates `perf_unified_cleanup.py` in the same directory +- Includes cleanup for all created resources +- **Output**: Cleanup script generation timing + +## Scale Calculations + +For default configuration (20 schemas, 30 tables/schema, 4 types, 2 users/type): +- **Schemas**: 20 +- **Tables**: 600 (20 × 30) +- **IDC Users**: 160 (20 × 4 × 2) +- **IDC Groups**: 80 (20 × 4) +- **Redshift Roles**: 80 (20 × 4) + +## Usage + +### Basic Execution +```bash +python test_perf_redshift_to_lakeformation.py +``` + +### Expected Output +The script provides comprehensive performance metrics: +- Overall test start and completion times +- Individual function execution times and durations +- Resource creation counts for each operation +- Total elapsed time in seconds + +### Sample Output Format +``` +Performance test started at: 2024-01-15 10:00:00 + +Starting create_schemas_and_tables at: 10:00:00 +Schema and table creation completed! Created 20 schemas and 600 tables. +Completed create_schemas_and_tables at: 10:05:30 (Duration: 0:05:30) + +Starting create_idc_users_and_groups at: 10:05:30 +IAM Identity Center setup completed! Created 160 users and 80 groups. +Completed create_idc_users_and_groups at: 10:12:15 (Duration: 0:06:45) + +... + +Performance test completed at: 2024-01-15 10:45:30 +Total elapsed time: 0:45:30 +Total elapsed time (seconds): 2730.00s +``` + +## Generated Files + +### Migration Output +- Lake Formation permission scripts in timestamped output directory +- Rollback scripts for permission cleanup +- Debug information and user ID lookup commands + +### Cleanup Script +- `perf_unified_cleanup.py`: Complete resource cleanup script in same directory +- Removes all Redshift schemas, tables, roles, and permissions +- Removes all IAM Identity Center users and groups + +## Performance Monitoring + +The script includes comprehensive performance tracking: +- **Function-level timing**: Start, end, and duration for each major operation +- **Resource counting**: Exact counts of all created resources +- **Overall metrics**: Total test execution time +- **Progress reporting**: Real-time status updates during execution + +## Cleanup + +After performance testing, run the generated cleanup script: + +```bash +python perf_unified_cleanup.py +``` + +This removes all test resources: +- Redshift schemas and tables (CASCADE) +- Redshift roles (FORCE) +- IAM Identity Center users and groups +- Group memberships + +## Performance Considerations + +### Scaling Factors +- **Linear scaling**: Most operations scale linearly with resource count +- **IAM Identity Center**: User/group operations may have API rate limits +- **Redshift**: Schema/table creation is typically fast +- **Migration script**: Processing time depends on permission complexity + +### Optimization Tips +- Start with smaller numbers for initial testing +- Monitor AWS service limits and quotas +- Consider running during off-peak hours for large tests +- Use appropriate instance sizes for Redshift cluster + +## Troubleshooting + +### Common Issues +1. **Timeout errors**: Reduce scale parameters for initial testing +2. **API rate limits**: IAM Identity Center operations may be throttled +3. **Resource limits**: Check AWS service quotas +4. **Memory issues**: Large-scale tests may require more memory + +### Performance Analysis +- Compare execution times across different scales +- Identify bottlenecks in specific operations +- Monitor AWS CloudWatch metrics during execution +- Use timing data to optimize configuration + +## Security Considerations + +- Test credentials stored in AWS Secrets Manager +- Use least-privilege IAM policies +- Clean up test resources promptly +- Avoid running performance tests in production environments +- Review generated Lake Formation commands before applying + +## Configuration Examples + +### Small Scale Test +```ini +number_of_schemas = 5 +number_of_tables_per_schema = 10 +number_users_per_type = 1 +``` + +### Large Scale Test +```ini +number_of_schemas = 100 +number_of_tables_per_schema = 50 +number_users_per_type = 5 +``` + +### Custom Types Test +```ini +list_types = admin, analyst, readonly, poweruser +number_users_per_type = 3 +``` \ No newline at end of file diff --git a/src/LakeFormationMigrationUtility/tests/performance_test/perf_unified_cleanup.py b/src/LakeFormationMigrationUtility/tests/performance_test/perf_unified_cleanup.py new file mode 100644 index 00000000..5b4ce524 --- /dev/null +++ b/src/LakeFormationMigrationUtility/tests/performance_test/perf_unified_cleanup.py @@ -0,0 +1,138 @@ +import boto3 +import psycopg2 +import configparser +import os +import json + +def get_redshift_credentials(config): + region = config['aws']['region'] + profile = config['aws'].get('config_profile', None) + secret_name = config['redshift']['secret_name'] + + session = boto3.Session(profile_name=profile, region_name=region) if profile else boto3.Session(region_name=region) + secrets_client = session.client('secretsmanager') + + response = secrets_client.get_secret_value(SecretId=secret_name) + secret = json.loads(response['SecretString']) + + return { + 'host': config['redshift']['host'], + 'port': config['redshift']['port'], + 'dbname': config['redshift']['dbname'], + 'user': secret['username'], + 'password': secret['password'] + } + +def cleanup_all(): + config = configparser.ConfigParser() + config_path = os.path.join(os.path.dirname(__file__), 'test_perf_config.ini') + config.read(config_path) + + print("Starting performance test cleanup...\n") + + conn_params = get_redshift_credentials(config) + conn = psycopg2.connect(**conn_params) + conn.autocommit = True + cursor = conn.cursor() + + # Drop Redshift roles + print("Dropping Redshift roles...") + list_types = [item.strip() for item in config['parameters']['list_types'].split(',')] + iam_idc_namespace = config['aws']['iam_idc_namespace'] + + for schema_num in range(1, 5 + 1): + for user_type in list_types: + role_name = f"{iam_idc_namespace}:test_schema_{schema_num}_group_{user_type}" + try: + cursor.execute(f'DROP ROLE "{role_name}" FORCE;') + print(f"Dropped role: {role_name}") + except Exception as e: + print(f"Error dropping role {role_name}: {e}") + + # Drop schemas (CASCADE will drop all tables) + print("\nDropping schemas...") + for schema_num in range(1, 5 + 1): + schema_name = f"test_schema_{schema_num}" + try: + cursor.execute(f"DROP SCHEMA {schema_name} CASCADE;") + print(f"Dropped schema: {schema_name}") + except Exception as e: + print(f"Error dropping schema {schema_name}: {e}") + + conn.close() + + # Cleanup IAM Identity Center users and groups + print("\n=== IAM IDENTITY CENTER CLEANUP ===") + identity_store_id = config['aws']['identity_store_id'] + region = config['aws']['region'] + profile = config['aws'].get('config_profile', None) + list_types = [item.strip() for item in config['parameters']['list_types'].split(',')] + number_users_per_type = config.getint('parameters', 'number_users_per_type') + + session = boto3.Session(profile_name=profile, region_name=region) if profile else boto3.Session(region_name=region) + identity_store_client = session.client('identitystore') + + for schema_num in range(1, 5 + 1): + # Delete users and group memberships + for user_type in list_types: + group_name = f"test_schema_{schema_num}_group_{user_type}" + + # Find and delete group + try: + groups_response = identity_store_client.list_groups( + IdentityStoreId=identity_store_id, + Filters=[{ + 'AttributePath': 'DisplayName', + 'AttributeValue': group_name + }] + ) + + for group in groups_response.get('Groups', []): + group_id = group['GroupId'] + + # Delete group memberships + memberships = identity_store_client.list_group_memberships( + IdentityStoreId=identity_store_id, + GroupId=group_id + ) + + for membership in memberships.get('GroupMemberships', []): + identity_store_client.delete_group_membership( + IdentityStoreId=identity_store_id, + MembershipId=membership['MembershipId'] + ) + + # Delete group + identity_store_client.delete_group( + IdentityStoreId=identity_store_id, + GroupId=group_id + ) + print(f"Deleted group: {group_name}") + except Exception as e: + print(f"Error deleting group {group_name}: {e}") + + # Delete users + for user_num in range(1, number_users_per_type + 1): + username = f"test_schema_{schema_num}_user_{user_type}_{user_num}" + try: + users_response = identity_store_client.list_users( + IdentityStoreId=identity_store_id, + Filters=[{ + 'AttributePath': 'UserName', + 'AttributeValue': username + }] + ) + + for user in users_response.get('Users', []): + identity_store_client.delete_user( + IdentityStoreId=identity_store_id, + UserId=user['UserId'] + ) + print(f"Deleted user: {username}") + except Exception as e: + print(f"Error deleting user {username}: {e}") + + print("\nPerformance test cleanup completed!") + +if __name__ == "__main__": + cleanup_all() diff --git a/src/LakeFormationMigrationUtility/tests/performance_test/test_perf_config.ini b/src/LakeFormationMigrationUtility/tests/performance_test/test_perf_config.ini new file mode 100644 index 00000000..66b5f5b5 --- /dev/null +++ b/src/LakeFormationMigrationUtility/tests/performance_test/test_perf_config.ini @@ -0,0 +1,31 @@ +# Example values provided +[redshift] +host = your-redshift-cluster.region.redshift.amazonaws.com +port = 5439 +dbname = your-database-name +# AWS Secrets Manager secret containing Redshift credentials +secret_name = your-secret-name + +[aws] +account_id = 123456789012 +region = us-east-1 +producer_catalog = your-producer-catalog-name +# AWS CLI profile to use (optional) +config_profile = your-aws-cli-profile +# Identity Store ID for IDC user lookups +identity_store_id = d-1234567890 +iam_idc_instance_arn = arn:aws:sso:::instance/ssoins-123456a8efd4d123 +iam_idc_namespace = AWSIDC + +[parameters] +# Permission source: 'datashare' for datashare permissions, 'local' for local database permissions +permissions_type = local +# Name of database on the consumer cluster created from the datashare +datashare_database_name = your_datashare_db +# Set to true if the datashare database was created with the 'WITH PERMISSIONS' clause +datashare_object_level_permissions = true +# Performance test parameters +list_types = etl, adhoc, analyst, admin +number_users_per_type = 1 +number_of_schemas = 5 +number_of_tables_per_schema = 2 diff --git a/src/LakeFormationMigrationUtility/tests/performance_test/test_perf_redshift_to_lakeformation.py b/src/LakeFormationMigrationUtility/tests/performance_test/test_perf_redshift_to_lakeformation.py new file mode 100644 index 00000000..4488eb76 --- /dev/null +++ b/src/LakeFormationMigrationUtility/tests/performance_test/test_perf_redshift_to_lakeformation.py @@ -0,0 +1,427 @@ +import configparser +import psycopg2 +import os +import boto3 +import json +import subprocess +import sys +from datetime import datetime + +def get_redshift_credentials(config): + region = config['aws']['region'] + profile = config['aws'].get('config_profile', None) + secret_name = config['redshift']['secret_name'] + + session = boto3.Session(profile_name=profile, region_name=region) if profile else boto3.Session(region_name=region) + secrets_client = session.client('secretsmanager') + + response = secrets_client.get_secret_value(SecretId=secret_name) + secret = json.loads(response['SecretString']) + + return { + 'host': config['redshift']['host'], + 'port': config['redshift']['port'], + 'dbname': config['redshift']['dbname'], + 'user': secret['username'], + 'password': secret['password'] + } + +def create_schemas_and_tables(): + config = configparser.ConfigParser() + config_path = os.path.join(os.path.dirname(__file__), 'test_perf_config.ini') + config.read(config_path) + + conn_params = get_redshift_credentials(config) + number_of_schemas = config.getint('parameters', 'number_of_schemas') + number_of_tables_per_schema = config.getint('parameters', 'number_of_tables_per_schema') + + conn = psycopg2.connect(**conn_params) + conn.autocommit = True + cursor = conn.cursor() + + print(f"Creating {number_of_schemas} schemas with {number_of_tables_per_schema} tables each...") + + for schema_num in range(1, number_of_schemas + 1): + schema_name = f"test_schema_{schema_num}" + + # Create schema + cursor.execute(f"CREATE SCHEMA {schema_name};") + print(f"Created schema: {schema_name}") + + # Create tables in schema + for table_num in range(1, number_of_tables_per_schema + 1): + table_name = f"test_schema_{schema_num}_table_{table_num}" + cursor.execute(f""" + CREATE TABLE {schema_name}.{table_name} ( + id_col INTEGER, + desc_col VARCHAR(100) + ); + """) + print(f"Created table: {schema_name}.{table_name}") + + conn.close() + total_schemas = number_of_schemas + total_tables = number_of_schemas * number_of_tables_per_schema + print(f"Schema and table creation completed! Created {total_schemas} schemas and {total_tables} tables.") + +def create_idc_users_and_groups(): + config = configparser.ConfigParser() + config_path = os.path.join(os.path.dirname(__file__), 'test_perf_config.ini') + config.read(config_path) + + identity_store_id = config['aws']['identity_store_id'] + region = config['aws']['region'] + profile = config['aws'].get('config_profile', None) + number_of_schemas = config.getint('parameters', 'number_of_schemas') + list_types = [item.strip() for item in config['parameters']['list_types'].split(',')] + number_users_per_type = config.getint('parameters', 'number_users_per_type') + + session = boto3.Session(profile_name=profile, region_name=region) if profile else boto3.Session(region_name=region) + identity_store_client = session.client('identitystore') + + print(f"Creating IAM Identity Center users and groups for {number_of_schemas} schemas...") + + for schema_num in range(1, number_of_schemas + 1): + # Create groups for each type + for user_type in list_types: + group_name = f"test_schema_{schema_num}_group_{user_type}" + try: + identity_store_client.create_group( + IdentityStoreId=identity_store_id, + DisplayName=group_name, + Description=f"Group for {user_type} users in schema {schema_num}" + ) + print(f"Created group: {group_name}") + except Exception as e: + print(f"Error creating group {group_name}: {e}") + + # Create users for each type + for user_type in list_types: + for user_num in range(1, number_users_per_type + 1): + username = f"test_schema_{schema_num}_user_{user_type}_{user_num}" + try: + response = identity_store_client.create_user( + IdentityStoreId=identity_store_id, + UserName=username, + Name={ + 'GivenName': f"{user_type}{user_num}", + 'FamilyName': f"Schema{schema_num}" + }, + DisplayName=username, + Emails=[{ + 'Value': f"{username}@example.com", + 'Type': 'work', + 'Primary': True + }] + ) + user_id = response['UserId'] + print(f"Created user: {username}") + + # Assign user to group + group_name = f"test_schema_{schema_num}_group_{user_type}" + # Find group ID + groups_response = identity_store_client.list_groups( + IdentityStoreId=identity_store_id, + Filters=[{ + 'AttributePath': 'DisplayName', + 'AttributeValue': group_name + }] + ) + + if groups_response.get('Groups'): + group_id = groups_response['Groups'][0]['GroupId'] + identity_store_client.create_group_membership( + IdentityStoreId=identity_store_id, + GroupId=group_id, + MemberId={'UserId': user_id} + ) + print(f"Assigned user {username} to group {group_name}") + + except Exception as e: + print(f"Error creating user {username}: {e}") + + total_users = number_of_schemas * len(list_types) * number_users_per_type + total_groups = number_of_schemas * len(list_types) + print(f"IAM Identity Center setup completed! Created {total_users} users and {total_groups} groups.") + +def create_redshift_roles(): + config = configparser.ConfigParser() + config_path = os.path.join(os.path.dirname(__file__), 'test_perf_config.ini') + config.read(config_path) + + conn_params = get_redshift_credentials(config) + number_of_schemas = config.getint('parameters', 'number_of_schemas') + list_types = [item.strip() for item in config['parameters']['list_types'].split(',')] + iam_idc_namespace = config['aws']['iam_idc_namespace'] + + conn = psycopg2.connect(**conn_params) + conn.autocommit = True + cursor = conn.cursor() + + print(f"Creating Redshift roles and granting permissions for {number_of_schemas} schemas...") + + for schema_num in range(1, number_of_schemas + 1): + schema_name = f"test_schema_{schema_num}" + + for user_type in list_types: + role_name = f"{iam_idc_namespace}:test_schema_{schema_num}_group_{user_type}" + + # Create role + try: + cursor.execute(f'CREATE ROLE "{role_name}";') + print(f"Created role: {role_name}") + except Exception as e: + print(f"Error creating role {role_name}: {e}") + continue + + # Grant permissions based on type + try: + if user_type == 'etl': + cursor.execute(f'GRANT USAGE ON SCHEMA {schema_name} TO ROLE "{role_name}";') + cursor.execute(f'GRANT INSERT, UPDATE, DELETE, SELECT ON ALL TABLES IN SCHEMA {schema_name} TO ROLE "{role_name}";') + print(f"Granted ETL permissions to {role_name}") + elif user_type == 'admin': + cursor.execute(f'GRANT ALL ON SCHEMA {schema_name} TO ROLE "{role_name}";') + cursor.execute(f'GRANT ALL ON ALL TABLES IN SCHEMA {schema_name} TO ROLE "{role_name}";') + print(f"Granted ADMIN permissions to {role_name}") + else: + cursor.execute(f'GRANT USAGE ON SCHEMA {schema_name} TO ROLE "{role_name}";') + cursor.execute(f'GRANT SELECT ON ALL TABLES IN SCHEMA {schema_name} TO ROLE "{role_name}";') + print(f"Granted SELECT permissions to {role_name}") + except Exception as e: + print(f"Error granting permissions to {role_name}: {e}") + + conn.close() + total_roles = number_of_schemas * len(list_types) + print(f"Redshift roles and permissions setup completed! Created {total_roles} roles.") + +def execute_rs_privs_to_lf(): + config_path = os.path.join(os.path.dirname(__file__), 'test_perf_config.ini') + rs_script_path = os.path.join(os.path.dirname(__file__), '../../src', 'rs_privs_to_lf.py') + + try: + print("\n=== EXECUTING RS_PRIVS_TO_LF SCRIPT ===") + result = subprocess.run( + [sys.executable, rs_script_path, '--config', config_path], + capture_output=True, + text=True, + cwd=os.path.dirname(rs_script_path) + ) + + print(f"Return code: {result.returncode}") + if result.stdout: + print(f"Output:\n{result.stdout}") + if result.stderr: + print(f"Errors:\n{result.stderr}") + + if result.returncode == 0: + print("rs_privs_to_lf.py executed successfully!") + else: + print(f"rs_privs_to_lf.py execution failed with return code {result.returncode}") + + except Exception as e: + print(f"Error executing rs_privs_to_lf.py: {e}") + +def generate_cleanup_script(): + config = configparser.ConfigParser() + config_path = os.path.join(os.path.dirname(__file__), 'test_perf_config.ini') + config.read(config_path) + + number_of_schemas = config.getint('parameters', 'number_of_schemas') + + cleanup_dir = os.path.dirname(__file__) + cleanup_file = os.path.join(cleanup_dir, 'perf_unified_cleanup.py') + + list_types = [item.strip() for item in config['parameters']['list_types'].split(',')] + number_users_per_type = config.getint('parameters', 'number_users_per_type') + iam_idc_namespace = config['aws']['iam_idc_namespace'] + + cleanup_content = f"""import boto3 +import psycopg2 +import configparser +import os +import json + +def get_redshift_credentials(config): + region = config['aws']['region'] + profile = config['aws'].get('config_profile', None) + secret_name = config['redshift']['secret_name'] + + session = boto3.Session(profile_name=profile, region_name=region) if profile else boto3.Session(region_name=region) + secrets_client = session.client('secretsmanager') + + response = secrets_client.get_secret_value(SecretId=secret_name) + secret = json.loads(response['SecretString']) + + return {{ + 'host': config['redshift']['host'], + 'port': config['redshift']['port'], + 'dbname': config['redshift']['dbname'], + 'user': secret['username'], + 'password': secret['password'] + }} + +def cleanup_all(): + config = configparser.ConfigParser() + config_path = os.path.join(os.path.dirname(__file__), 'test_perf_config.ini') + config.read(config_path) + + print("Starting performance test cleanup...\\n") + + conn_params = get_redshift_credentials(config) + conn = psycopg2.connect(**conn_params) + conn.autocommit = True + cursor = conn.cursor() + + # Drop Redshift roles + print("Dropping Redshift roles...") + list_types = [item.strip() for item in config['parameters']['list_types'].split(',')] + iam_idc_namespace = config['aws']['iam_idc_namespace'] + + for schema_num in range(1, {number_of_schemas} + 1): + for user_type in list_types: + role_name = f"{{iam_idc_namespace}}:test_schema_{{schema_num}}_group_{{user_type}}" + try: + cursor.execute(f'DROP ROLE "{{role_name}}" FORCE;') + print(f"Dropped role: {{role_name}}") + except Exception as e: + print(f"Error dropping role {{role_name}}: {{e}}") + + # Drop schemas (CASCADE will drop all tables) + print("\\nDropping schemas...") + for schema_num in range(1, {number_of_schemas} + 1): + schema_name = f"test_schema_{{schema_num}}" + try: + cursor.execute(f"DROP SCHEMA {{schema_name}} CASCADE;") + print(f"Dropped schema: {{schema_name}}") + except Exception as e: + print(f"Error dropping schema {{schema_name}}: {{e}}") + + conn.close() + + # Cleanup IAM Identity Center users and groups + print("\\n=== IAM IDENTITY CENTER CLEANUP ===") + identity_store_id = config['aws']['identity_store_id'] + region = config['aws']['region'] + profile = config['aws'].get('config_profile', None) + list_types = [item.strip() for item in config['parameters']['list_types'].split(',')] + number_users_per_type = config.getint('parameters', 'number_users_per_type') + + session = boto3.Session(profile_name=profile, region_name=region) if profile else boto3.Session(region_name=region) + identity_store_client = session.client('identitystore') + + for schema_num in range(1, {number_of_schemas} + 1): + # Delete users and group memberships + for user_type in list_types: + group_name = f"test_schema_{{schema_num}}_group_{{user_type}}" + + # Find and delete group + try: + groups_response = identity_store_client.list_groups( + IdentityStoreId=identity_store_id, + Filters=[{{ + 'AttributePath': 'DisplayName', + 'AttributeValue': group_name + }}] + ) + + for group in groups_response.get('Groups', []): + group_id = group['GroupId'] + + # Delete group memberships + memberships = identity_store_client.list_group_memberships( + IdentityStoreId=identity_store_id, + GroupId=group_id + ) + + for membership in memberships.get('GroupMemberships', []): + identity_store_client.delete_group_membership( + IdentityStoreId=identity_store_id, + MembershipId=membership['MembershipId'] + ) + + # Delete group + identity_store_client.delete_group( + IdentityStoreId=identity_store_id, + GroupId=group_id + ) + print(f"Deleted group: {{group_name}}") + except Exception as e: + print(f"Error deleting group {{group_name}}: {{e}}") + + # Delete users + for user_num in range(1, number_users_per_type + 1): + username = f"test_schema_{{schema_num}}_user_{{user_type}}_{{user_num}}" + try: + users_response = identity_store_client.list_users( + IdentityStoreId=identity_store_id, + Filters=[{{ + 'AttributePath': 'UserName', + 'AttributeValue': username + }}] + ) + + for user in users_response.get('Users', []): + identity_store_client.delete_user( + IdentityStoreId=identity_store_id, + UserId=user['UserId'] + ) + print(f"Deleted user: {{username}}") + except Exception as e: + print(f"Error deleting user {{username}}: {{e}}") + + print("\\nPerformance test cleanup completed!") + +if __name__ == "__main__": + cleanup_all() +""" + + with open(cleanup_file, 'w') as f: + f.write(cleanup_content) + + print(f"Cleanup script generated at: {cleanup_file}") + +if __name__ == "__main__": + overall_start_time = datetime.now() + print(f"Performance test started at: {overall_start_time.strftime('%Y-%m-%d %H:%M:%S')}\n") + + # create_schemas_and_tables + start_time = datetime.now() + print(f"Starting create_schemas_and_tables at: {start_time.strftime('%H:%M:%S')}") + create_schemas_and_tables() + end_time = datetime.now() + print(f"Completed create_schemas_and_tables at: {end_time.strftime('%H:%M:%S')} (Duration: {end_time - start_time})\n") + + # create_idc_users_and_groups + start_time = datetime.now() + print(f"Starting create_idc_users_and_groups at: {start_time.strftime('%H:%M:%S')}") + create_idc_users_and_groups() + end_time = datetime.now() + print(f"Completed create_idc_users_and_groups at: {end_time.strftime('%H:%M:%S')} (Duration: {end_time - start_time})\n") + + # create_redshift_roles + start_time = datetime.now() + print(f"Starting create_redshift_roles at: {start_time.strftime('%H:%M:%S')}") + create_redshift_roles() + end_time = datetime.now() + print(f"Completed create_redshift_roles at: {end_time.strftime('%H:%M:%S')} (Duration: {end_time - start_time})\n") + + # execute_rs_privs_to_lf + start_time = datetime.now() + print(f"Starting execute_rs_privs_to_lf at: {start_time.strftime('%H:%M:%S')}") + execute_rs_privs_to_lf() + end_time = datetime.now() + print(f"Completed execute_rs_privs_to_lf at: {end_time.strftime('%H:%M:%S')} (Duration: {end_time - start_time})\n") + + # generate_cleanup_script + start_time = datetime.now() + print(f"Starting generate_cleanup_script at: {start_time.strftime('%H:%M:%S')}") + generate_cleanup_script() + end_time = datetime.now() + print(f"Completed generate_cleanup_script at: {end_time.strftime('%H:%M:%S')} (Duration: {end_time - start_time})\n") + + final_end_time = datetime.now() + total_elapsed = final_end_time - overall_start_time + print(f"Performance test completed at: {final_end_time.strftime('%Y-%m-%d %H:%M:%S')}") + print(f"Total elapsed time: {total_elapsed}") + print(f"Total elapsed time (seconds): {total_elapsed.total_seconds():.2f}s") \ No newline at end of file From 2203e4aabb037bee6490da39c73a2ef64dcb403d Mon Sep 17 00:00:00 2001 From: Adam Gatt Date: Thu, 31 Jul 2025 15:48:58 +0100 Subject: [PATCH 44/49] File cleanup --- .../src/old/create_redshift_idc_users.py | 279 ------------------ .../src/old/redshift_users_to_iam.py | 265 ----------------- .../{int_readme.md => README.md} | 0 .../{perf_readme.md => README.md} | 0 4 files changed, 544 deletions(-) delete mode 100644 src/LakeFormationMigrationUtility/src/old/create_redshift_idc_users.py delete mode 100644 src/LakeFormationMigrationUtility/src/old/redshift_users_to_iam.py rename src/LakeFormationMigrationUtility/tests/integration_test/{int_readme.md => README.md} (100%) rename src/LakeFormationMigrationUtility/tests/performance_test/{perf_readme.md => README.md} (100%) diff --git a/src/LakeFormationMigrationUtility/src/old/create_redshift_idc_users.py b/src/LakeFormationMigrationUtility/src/old/create_redshift_idc_users.py deleted file mode 100644 index 4ccec548..00000000 --- a/src/LakeFormationMigrationUtility/src/old/create_redshift_idc_users.py +++ /dev/null @@ -1,279 +0,0 @@ -#!/usr/bin/env python3 -""" -Create Redshift IDC users script - -This script: -1. Connects to Redshift -2. Gets all local users (without IAM:/IAMR:/AWSIDC: prefixes) -3. Maps them to IAM IDC to get their email addresses -4. Creates Redshift CLI commands to create IDC users via get-cluster-credentials -""" - -import os -import sys -import psycopg2 -import argparse -import configparser -import subprocess -import json -from datetime import datetime - -def load_config(config_file='config.ini'): - """Load configuration from config file""" - if not os.path.exists(config_file): - print(f"Error: Config file '{config_file}' not found") - sys.exit(1) - - config = configparser.ConfigParser() - try: - config.read(config_file) - return config - except Exception as e: - print(f"Error reading config file: {e}") - sys.exit(1) - -def connect_to_redshift(config): - """Establish connection to Redshift database using config""" - try: - redshift_config = config['redshift'] - conn = psycopg2.connect( - host=redshift_config['host'], - port=int(redshift_config.get('port', 5439)), - dbname=redshift_config['dbname'], - user=redshift_config['user'], - password=redshift_config['password'] - ) - print(f"Connected to Redshift database: {redshift_config['dbname']}") - return conn - except Exception as e: - print(f"Error connecting to Redshift: {e}") - sys.exit(1) - -def get_local_redshift_users(conn): - """Get local Redshift users (excluding IAM/IAMR/AWSIDC prefixed users)""" - try: - cursor = conn.cursor() - cursor.execute(""" - SELECT usename - FROM pg_user - WHERE usesuper = 'f' - AND usename != 'rdsdb' - AND NOT (usename LIKE 'IAM:%' OR usename LIKE 'IAMR:%' OR usename LIKE 'AWSIDC:%') - ORDER BY usename - """) - - users = [row[0] for row in cursor.fetchall()] - cursor.close() - print(f"Found {len(users)} local Redshift users") - return users - except Exception as e: - print(f"Error retrieving users from Redshift: {e}") - sys.exit(1) - -def get_idc_user_id(username, identity_store_id, config_profile=None): - """Get IDC user ID using AWS CLI get-user-id command""" - try: - # Create the JSON string for alternate-identifier - alternate_identifier = json.dumps({"UniqueAttribute": {"AttributePath": "UserName", "AttributeValue": username}}) - - cmd = ['aws'] - if config_profile: - cmd.extend(['--profile', config_profile]) - cmd.extend([ - 'identitystore', 'get-user-id', - '--identity-store-id', identity_store_id, - '--alternate-identifier', alternate_identifier - ]) - - print(f" Executing command: {' '.join(cmd)}") - result = subprocess.run(cmd, capture_output=True, text=True) - if result.returncode != 0: - print(f"Warning: Could not get user ID for {username}: {result.stderr}") - return None - - response = json.loads(result.stdout) - user_id = response.get('UserId') - if user_id: - print(f"Found IDC user ID for {username}: {user_id}") - return user_id - else: - print(f"Warning: No user ID found for {username}") - return None - - except Exception as e: - print(f"Warning: Error getting IDC user ID for {username}: {e}") - return None - -def get_idc_user_email(user_id, identity_store_id, config_profile=None): - """Get IDC user email using user ID""" - try: - cmd = ['aws'] - if config_profile: - cmd.extend(['--profile', config_profile]) - cmd.extend([ - 'identitystore', 'describe-user', - '--identity-store-id', identity_store_id, - '--user-id', user_id - ]) - - result = subprocess.run(cmd, capture_output=True, text=True) - if result.returncode != 0: - print(f"Warning: Could not get user details for user ID {user_id}: {result.stderr}") - return None - - user_details = json.loads(result.stdout) - emails = user_details.get('Emails', []) - - if emails: - primary_email = next((email['Value'] for email in emails if email.get('Primary', False)), emails[0]['Value']) - print(f"Found email for user ID {user_id}: {primary_email}") - return primary_email - else: - print(f"Warning: No email found for user ID {user_id}") - return None - - except Exception as e: - print(f"Warning: Error getting IDC user email for user ID {user_id}: {e}") - return None - -def generate_get_cluster_credentials_command(username, email, cluster_identifier, config_profile=None): - """Generate get-cluster-credentials command""" - profile_param = f" --profile {config_profile}" if config_profile else "" - - # The IDC user will be created as AWSIDC:email - idc_username = f"AWSIDC:{email}" - - command = f"aws{profile_param} redshift get-cluster-credentials \\\n" - command += f" --cluster-identifier {cluster_identifier} \\\n" - command += f" --db-user {email} \\\n" - command += f" --duration-seconds 3600 \\\n" - command += f" --auto-create" - - return command, idc_username - -def generate_commands(local_users, user_emails, cluster_identifier, config_profile=None, output_dir=None): - """Generate all the Redshift CLI commands""" - timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") - - if output_dir: - if not os.path.exists(output_dir): - os.makedirs(output_dir) - script_filepath = os.path.join(output_dir, f"create_redshift_idc_users_{timestamp}.sh") - else: - script_filepath = f"create_redshift_idc_users_{timestamp}.sh" - - with open(script_filepath, 'w') as script_file: - script_file.write("#!/bin/bash\n\n") - script_file.write("# Redshift get-cluster-credentials commands to create IDC users\n") - script_file.write(f"# Generated on: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n") - script_file.write("# These commands will create AWSIDC: prefixed users in Redshift\n\n") - - commands_generated = 0 - - for username in local_users: - email = user_emails.get(username) - if email: - command, idc_username = generate_get_cluster_credentials_command( - username, email, cluster_identifier, config_profile - ) - - script_file.write(f"# Local user: {username} -> IDC user: {idc_username}\n") - script_file.write(f"{command}\n\n") - commands_generated += 1 - else: - script_file.write(f"# Warning: No email found for user {username}, skipping\n\n") - - if commands_generated == 0: - script_file.write("echo \"No valid user mappings found to create IDC users.\"\n") - - # Make the file executable - os.chmod(script_filepath, 0o755) - - print(f"Generated {commands_generated} get-cluster-credentials commands in file: {script_filepath}") - return script_filepath - -def main(): - parser = argparse.ArgumentParser(description='Create Redshift IDC users from local Redshift users') - - parser.add_argument('--config', '-c', default='config.ini', help='Path to config file (default: config.ini)') - parser.add_argument('--output-dir', '-o', help='Directory to save generated scripts') - parser.add_argument('--debug', action='store_true', help='Enable debug output') - - args = parser.parse_args() - - # Load configuration - config = load_config(args.config) - - # Get required config values - try: - identity_store_id = config.get('aws', 'identity_store_id') - workgroup_name = config.get('redshift', 'host').split('.')[0] # Extract workgroup name from host - cluster_identifier = f"redshift-serverless-{workgroup_name}" - config_profile = config.get('aws', 'config_profile', fallback=None) - except Exception as e: - print(f"Error reading required configuration: {e}") - sys.exit(1) - - # Connect to Redshift - conn = connect_to_redshift(config) - - # Get local Redshift users - local_users = get_local_redshift_users(conn) - - # Close connection - conn.close() - - if not local_users: - print("No local Redshift users found to process") - return - - # Map users to their IDC email addresses - print(f"\nMapping {len(local_users)} users to IDC email addresses...") - user_emails = {} - - for username in local_users: - print(f"\nProcessing user: {username}") - print(f" Looking up in Identity Store: {identity_store_id}") - print(f" Using profile: {config_profile or 'default'}") - - # First get the user ID - user_id = get_idc_user_id(username, identity_store_id, config_profile) - if user_id: - print(f" Found user ID: {user_id}") - # Then get the email using the user ID - email = get_idc_user_email(user_id, identity_store_id, config_profile) - if email: - user_emails[username] = email - print(f" Successfully mapped: {username} -> {email}") - else: - print(f" Failed to get email for user ID: {user_id}") - else: - print(f" User '{username}' not found in Identity Center") - print(f" This means '{username}' does not exist as an IDC user") - print(f" You may need to create this user in Identity Center first") - - print(f"\nSummary: Successfully mapped {len(user_emails)} out of {len(local_users)} users to email addresses") - - if len(user_emails) == 0: - print("\nNo users were successfully mapped. This could mean:") - print(" 1. The local Redshift users don't exist in Identity Center") - print(" 2. The Identity Store ID is incorrect") - print(" 3. The AWS profile doesn't have permission to access Identity Center") - print(" 4. The usernames in Redshift don't match the usernames in Identity Center") - - if args.debug or len(user_emails) > 0: - print("\nUser mappings:") - for username, email in user_emails.items(): - print(f" {username} -> {email}") - - if len(user_emails) < len(local_users): - unmapped = set(local_users) - set(user_emails.keys()) - print("\nUnmapped users:") - for username in unmapped: - print(f" {username} (not found in Identity Center)") - - # Generate commands - generate_commands(local_users, user_emails, cluster_identifier, config_profile, args.output_dir) - -if __name__ == "__main__": - main() \ No newline at end of file diff --git a/src/LakeFormationMigrationUtility/src/old/redshift_users_to_iam.py b/src/LakeFormationMigrationUtility/src/old/redshift_users_to_iam.py deleted file mode 100644 index 450fe2d6..00000000 --- a/src/LakeFormationMigrationUtility/src/old/redshift_users_to_iam.py +++ /dev/null @@ -1,265 +0,0 @@ -import os -import sys -import psycopg2 -import argparse -import configparser -import re -import shlex -import secrets -import string -from datetime import datetime - -def load_config(config_file='config.ini'): - """ - Load configuration from config file (default: config.ini) - """ - if not os.path.exists(config_file): - print(f"Error: Config file '{config_file}' not found") - sys.exit(1) - - config = configparser.ConfigParser() - try: - config.read(config_file) - print(f"Loaded configuration from {config_file}") - return config - except Exception as e: - print(f"Error reading config file: {e}") - sys.exit(1) - -def connect_to_redshift(config): - """ - Establish connection to Redshift database using config - """ - try: - redshift_config = config['redshift'] - conn = psycopg2.connect( - host=redshift_config['host'], - port=int(redshift_config.get('port', 5439)), - dbname=redshift_config['dbname'], - user=redshift_config['user'], - password=redshift_config['password'] - ) - print(f"Connected to Redshift database: {redshift_config['dbname']}") - return conn - except KeyError as e: - print(f"Missing required configuration parameter: {e}") - sys.exit(1) - except Exception as e: - print(f"Error connecting to Redshift: {e}") - sys.exit(1) - -def get_redshift_users(conn): - """ - Get users from pg_user catalog table in Redshift, filtering out IAM/IAMR users in SQL - """ - users = [] - try: - cursor = conn.cursor() - # Query to get usernames from pg_user with filtering in SQL - cursor.execute(""" - SELECT usename - FROM pg_user - WHERE usesuper = 'f' - AND usename != 'rdsdb' - AND NOT (usename LIKE 'IAM:%' OR usename LIKE 'IAMR:%' OR usename LIKE 'AWSIDC:%') - ORDER BY 1; - """) - - for row in cursor: - users.append(row[0]) - - cursor.close() - print(f"Retrieved {len(users)} non-IAM users from Redshift") - return users - except Exception as e: - print(f"Error retrieving users from Redshift: {e}") - conn.close() - sys.exit(1) - -def generate_secure_password(length=16): - """ - Generate a secure random password - """ - # Include at least one of each required character type for AWS IAM password policy - letters = string.ascii_letters - digits = string.digits - special_chars = "!@#" + "$" + "%^&*()_+-=[]{}|" # Avoid escape sequence issues - password_chars = letters + digits + special_chars - - # Ensure we have at least one uppercase, one lowercase, one digit, and one special character - password = [ - secrets.choice(string.ascii_uppercase), - secrets.choice(string.ascii_lowercase), - secrets.choice(string.digits), - secrets.choice(special_chars) - ] - - # Fill the rest of the password length with random characters - password.extend(secrets.choice(password_chars) for _ in range(length - 4)) - - # Shuffle the password characters - secrets.SystemRandom().shuffle(password) - - return ''.join(password) - -def generate_iam_cli_command(username): - """ - Generate AWS CLI command to create an IAM user with proper escaping - """ - # Ensure IAM username follows IAM naming rules (alphanumeric, plus '+', '=', ',', '.', '@', '-', '_') - valid_username = re.sub(r'[^a-zA-Z0-9+=,.@\-_]', '-', username) - - # Truncate if username exceeds IAM's 64-character limit - if len(valid_username) > 64: - valid_username = valid_username[:64] - print(f"Warning: Username truncated to {valid_username} due to IAM 64-character limit") - - # Escape the original username for shell safety - escaped_original = shlex.quote(username) - - # Generate AWS CLI command with properly formatted tags - cli_command = f'aws iam create-user --user-name {valid_username} ' \ - f'--tags Key=Source,Value=Redshift Key=OriginalRedshiftUsername,Value={escaped_original}' - - return cli_command, valid_username - -def generate_policy_attachment_commands(username, policies): - """ - Generate AWS CLI commands to attach policies to an IAM user - """ - commands = [] - for policy in policies: - commands.append(f'aws iam attach-user-policy --user-name {username} --policy-arn {policy}') - return commands - -def generate_console_access_command(username): - """ - Generate AWS CLI command to create console access with password change required - """ - password = generate_secure_password() - - # Create login profile command with password reset required - command = f'aws iam create-login-profile --user-name {username} ' \ - f'--password "{password}" --password-reset-required' - - return command - -def generate_commands(redshift_users, create_console_password=True): - """ - Generate all the AWS CLI commands for IAM users - """ - commands = [] - - # List of IAM policies to attach to each user - iam_policies = [ - 'arn:aws:iam::aws:policy/AmazonRedshiftReadOnlyAccess', - 'arn:aws:iam::aws:policy/AmazonRedshiftQueryEditorV2ReadWriteSharing', - # Add more policy ARNs as needed - ] - - # Generate header comments - commands.append("#!/bin/bash\n") - commands.append("# AWS CLI Commands to create IAM users from Redshift users") - commands.append("# Generated script for creating IAM users from Redshift users") - commands.append("# Consider checking for existing IAM users first with: aws iam list-users\n") - - if create_console_password: - commands.append("# NOTE: Console access passwords are randomly generated and users will be required to change them on first login\n") - - if not redshift_users: - commands.append("echo \"No eligible Redshift users found to create IAM users.\"") - - for username in redshift_users: - # Create user command - cli_command, valid_username = generate_iam_cli_command(username) - commands.append(cli_command) - - # Create console access command only if requested - if create_console_password: - console_command = generate_console_access_command(valid_username) - commands.append(console_command) - - # Generate policy attachment commands if policies are specified - if iam_policies: - for policy_command in generate_policy_attachment_commands(valid_username, iam_policies): - commands.append(policy_command) - commands.append("") # Add a blank line for readability - - # Add some follow-up commands information - if redshift_users: - commands.append("\n# After creating users, you might want to add additional policies") - commands.append("# Example: aws iam attach-user-policy --user-name USERNAME --policy-arn POLICY_ARN") - commands.append("# To check if users were created: aws iam list-users") - - if create_console_password: - commands.append("# To check users with console access: aws iam list-users | jq '.Users[] | select(has(\"PasswordLastUsed\"))'") - - return commands - -def write_to_file(commands, output_dir=None): - """ - Write commands to a file in the specified output directory - """ - timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") - - if output_dir: - if not os.path.exists(output_dir): - os.makedirs(output_dir) - script_filepath = os.path.join(output_dir, f"create_iam_users_{timestamp}.sh") - else: - script_filepath = f"create_iam_users_{timestamp}.sh" - - with open(script_filepath, 'w') as script_file: - for command in commands: - script_file.write(f"{command}\n") - - # Make the file executable - os.chmod(script_filepath, 0o755) - - print(f"Generated AWS CLI commands in file: {script_filepath}") - return script_filepath - -def main(): - """ - Main function to process Redshift users and generate AWS IAM commands - """ - parser = argparse.ArgumentParser(description='Generate AWS CLI commands to create IAM users from Redshift users.') - - parser.add_argument('--config', '-c', default='config.ini', help='Path to config file (default: config.ini)') - parser.add_argument('--output-dir', '-o', help='Directory to save generated scripts') - parser.add_argument('--no-console', action='store_true', help='Do not create console access for users') - parser.add_argument('--debug', action='store_true', help='Enable debug output') - - args = parser.parse_args() - - try: - # Load configuration - config = load_config(args.config) - - # Connect to Redshift - conn = connect_to_redshift(config) - - # Get Redshift users (with SQL filtering) - redshift_users = get_redshift_users(conn) - - # Close the connection - conn.close() - - if args.debug: - print("\nRedshift users found:") - for user in redshift_users: - print(f" {user}") - print() - - # Generate commands - commands = generate_commands(redshift_users, not args.no_console) - - # Write commands to file - write_to_file(commands, args.output_dir) - - except Exception as e: - print(f"Error in main process: {e}") - sys.exit(1) - -if __name__ == "__main__": - main() \ No newline at end of file diff --git a/src/LakeFormationMigrationUtility/tests/integration_test/int_readme.md b/src/LakeFormationMigrationUtility/tests/integration_test/README.md similarity index 100% rename from src/LakeFormationMigrationUtility/tests/integration_test/int_readme.md rename to src/LakeFormationMigrationUtility/tests/integration_test/README.md diff --git a/src/LakeFormationMigrationUtility/tests/performance_test/perf_readme.md b/src/LakeFormationMigrationUtility/tests/performance_test/README.md similarity index 100% rename from src/LakeFormationMigrationUtility/tests/performance_test/perf_readme.md rename to src/LakeFormationMigrationUtility/tests/performance_test/README.md From fd1963c7115b024d6e8bb854839d4c8e75bfc695 Mon Sep 17 00:00:00 2001 From: Adam Gatt Date: Thu, 31 Jul 2025 15:53:37 +0100 Subject: [PATCH 45/49] File cleanup --- src/LakeFormationMigrationUtility/{src => }/config.ini | 0 src/LakeFormationMigrationUtility/{src => }/rs_privs_to_lf.py | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename src/LakeFormationMigrationUtility/{src => }/config.ini (100%) rename src/LakeFormationMigrationUtility/{src => }/rs_privs_to_lf.py (100%) diff --git a/src/LakeFormationMigrationUtility/src/config.ini b/src/LakeFormationMigrationUtility/config.ini similarity index 100% rename from src/LakeFormationMigrationUtility/src/config.ini rename to src/LakeFormationMigrationUtility/config.ini diff --git a/src/LakeFormationMigrationUtility/src/rs_privs_to_lf.py b/src/LakeFormationMigrationUtility/rs_privs_to_lf.py similarity index 100% rename from src/LakeFormationMigrationUtility/src/rs_privs_to_lf.py rename to src/LakeFormationMigrationUtility/rs_privs_to_lf.py From f63323068eac0f297f4a628b78fdaa24e7641288 Mon Sep 17 00:00:00 2001 From: Adam Gatt Date: Thu, 31 Jul 2025 16:48:54 +0100 Subject: [PATCH 46/49] Updated readme file --- src/LakeFormationMigrationUtility/README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/LakeFormationMigrationUtility/README.md b/src/LakeFormationMigrationUtility/README.md index f23411b7..6f0cc45e 100644 --- a/src/LakeFormationMigrationUtility/README.md +++ b/src/LakeFormationMigrationUtility/README.md @@ -1,5 +1,7 @@ # Redshift Permissions to Lake Formation Migration Utility +Utility Version: 1.0 Release Date: 31-Jul-2025 + A Python script that extracts permissions from Amazon Redshift (datashares or local databases) and generates AWS Lake Formation permission commands for seamless migration to a SageMaker Lakehouse architecture. ## Overview @@ -233,3 +235,9 @@ Enable debug mode to see: - Ensure your AWS Secrets Manager secret contains the keys 'username' and 'password' - The IAM role/user running the script needs secretsmanager:GetSecretValue permission +Authors: adamgatt@amazon.co.uk, ziadwali@amazon.fr + +NOTE: This utility is continuously enhanced to close any gaps and add additional functionality. Please send your issues, feedback, and enhancement requests to the authors with subject line: “[issue/feedback/enhancement] Amazon Redshift Permissions to Lake Formation Migration Utility” + + + From 173601649d6164aae6edb01acd3cee1dd4b57757 Mon Sep 17 00:00:00 2001 From: Adam Gatt Date: Mon, 1 Sep 2025 17:02:57 +0100 Subject: [PATCH 47/49] Covered pull request review feedback. --- README.md | 4 + src/LakeFormationMigrationUtility/README.md | 32 +++++ src/LakeFormationMigrationUtility/config.ini | 26 ++-- .../rs_privs_to_lf.py | 121 ++++++++++++------ .../integration_test/test_int_config.ini | 30 ++--- .../performance_test/test_perf_config.ini | 38 +++--- 6 files changed, 166 insertions(+), 85 deletions(-) diff --git a/README.md b/README.md index 9cb575fa..233fab5d 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,10 @@ This [project](src/QMRNotificationUtility) enables a scheduled Lambda function t # Redshift to IDC migration utility Some of the existing Redshift customers rely on local users, roles, groups, and permissions, which presents a significant challenge when adopting the SageMaker Lakehouse, Lakeformation, and other cross-service integration features. This [utility](src/RedshiftIDCMigrationUtility) streamlines the process by automatically creating IDC users, groups, and roles that mirror the existing Redshift configuration. It then assigns users to the appropriate groups and grants the necessary permissions to the IDC roles, ensuring a seamless transition to the centralized identity management system. +# Redshift to Lake Formation migration utility + +This utility streamlines the process of migrating data access permissions from Amazon Redshift to AWS Lake Formation through several key functions. It automatically extracts user permissions from both Redshift datashare and local databases by analyzing table-level grants. The utility then generates the necessary AWS CLI commands to establish equivalent permissions in Lake Formation supporting AWS Identity Center (IDC) authentication. Additionally, it creates rollback scripts that enable easy cleanup of permissions if needed. + # Investigations This project includes a number of detailed investigations into various types of Redshift edge cases, nuances, and workload scenarios. diff --git a/src/LakeFormationMigrationUtility/README.md b/src/LakeFormationMigrationUtility/README.md index 6f0cc45e..ad82b106 100644 --- a/src/LakeFormationMigrationUtility/README.md +++ b/src/LakeFormationMigrationUtility/README.md @@ -20,6 +20,7 @@ This tool automates the migration of data access permissions from Amazon Redshif - **Role Inheritance**: Handles IDC roles with granted Redshift roles. This includes Redshift roles that have been granted permissions via other Redshift roles. - **Automated Scripts**: Generates executable bash scripts with AWS CLI commands - **Rollback Support**: Creates corresponding rollback scripts for permission cleanup +- **Comprehensive Logging**: Structured logging to both console and timestamped log files - **Debug Mode**: Provides detailed logging and user ID lookup commands ## Prerequisites @@ -178,6 +179,11 @@ The script generates timestamped files in the output directory: - `rollback_lakeformation_YYYYMMDD_HHMMSS.sh`: Rollback script to revoke permissions - `get_user_id_commands_YYYYMMDD_HHMMSS.sh`: Debug script for IDC user ID lookups (debug mode only) +### Log Files +- `logs/lakeformation_migration_YYYYMMDD_HHMMSS.log`: Detailed execution logs with timestamps +- Logs are automatically created in a `logs/` directory (created if it doesn't exist) +- Both console and file logging are enabled simultaneously + ### Script Structure ```bash #!/bin/bash @@ -224,9 +230,35 @@ Enable debug mode to see: - Available schemas in the database - Detailed user and table information - Sample table grants +- Enhanced logging with DEBUG level messages - User ID lookup commands for Identity Center authentication - Query execution details for troubleshooting +## Logging + +The utility provides comprehensive logging functionality: + +### Log Features +- **Dual Output**: Logs to both console and timestamped log files +- **Automatic Directory Creation**: Creates `logs/` directory if it doesn't exist +- **Structured Format**: Timestamp, log level, and message for each entry +- **Multiple Log Levels**: INFO, ERROR, WARNING, and DEBUG (with --debug flag) +- **Operation Tracking**: Logs all major operations, errors, and progress updates + +### Log File Location +- **Default**: `logs/lakeformation_migration_YYYYMMDD_HHMMSS.log` in current directory +- **With Output Directory**: `{output-dir}/logs/lakeformation_migration_YYYYMMDD_HHMMSS.log` + +### What Gets Logged +- Utility startup and version information +- Configuration loading and validation +- AWS Secrets Manager operations +- Redshift database connections +- Permission extraction progress +- Script generation results +- Error messages and troubleshooting information +- Debug details (when --debug flag is used) + ## Security Considerations - Use least-privilege IAM policies diff --git a/src/LakeFormationMigrationUtility/config.ini b/src/LakeFormationMigrationUtility/config.ini index d94bce0d..4135dcef 100644 --- a/src/LakeFormationMigrationUtility/config.ini +++ b/src/LakeFormationMigrationUtility/config.ini @@ -1,24 +1,24 @@ -# Example values provided +# Commented example values provided. Replace with values for your system. [redshift] -host = your-redshift-cluster.region.redshift.amazonaws.com -port = 5439 -dbname = your-database-name +host = #your-redshift-cluster.region.redshift.amazonaws.com +port = #5439 +dbname = #your-database-name # AWS Secrets Manager secret containing Redshift credentials -secret_name = your-secret-name +secret_name = #your-secret-name [aws] -account_id = 123456789012 -region = us-east-1 -producer_catalog = your-producer-catalog-name +account_id = #123456789012 +region = #us-east-1 +producer_catalog = #your-producer-catalog-name # AWS CLI profile to use (optional) -config_profile = your-aws-cli-profile +config_profile = #your-aws-cli-profile # Identity Store ID for IDC user lookups -identity_store_id = d-1234567890 +identity_store_id = #d-1234567890 [parameters] # Permission source: 'datashare' for datashare permissions, 'local' for local database permissions -permissions_type = local +permissions_type = #local # Name of database on the consumer cluster created from the datashare -datashare_database_name = your_datashare_db +datashare_database_name = #your_datashare_db # Set to true if the datashare database was created with the 'WITH PERMISSIONS' clause -datashare_object_level_permissions = true \ No newline at end of file +datashare_object_level_permissions = #true \ No newline at end of file diff --git a/src/LakeFormationMigrationUtility/rs_privs_to_lf.py b/src/LakeFormationMigrationUtility/rs_privs_to_lf.py index c465a7a1..f21dbbd5 100644 --- a/src/LakeFormationMigrationUtility/rs_privs_to_lf.py +++ b/src/LakeFormationMigrationUtility/rs_privs_to_lf.py @@ -6,29 +6,67 @@ import subprocess import json import boto3 +import logging from datetime import datetime +__version__ = "1.0" + +def setup_logging(debug=False, output_dir=None): + """ + Setup logging configuration + """ + # Create logs directory + if output_dir: + log_dir = os.path.join(output_dir, 'logs') + else: + log_dir = 'logs' + + os.makedirs(log_dir, exist_ok=True) + log_file = os.path.join(log_dir, f'lakeformation_migration_{datetime.now().strftime("%Y%m%d_%H%M%S")}.log') + + # Set logging level + level = logging.DEBUG if debug else logging.INFO + + # Configure logging + logging.basicConfig( + level=level, + format='%(asctime)s - %(levelname)s - %(message)s', + handlers=[ + logging.FileHandler(log_file), + logging.StreamHandler(sys.stdout) + ] + ) + + logger = logging.getLogger(__name__) + logger.info(f"Lake Formation Migration Utility v{__version__} started") + logger.info(f"Log file: {log_file}") + return logger + def load_config(config_file='config.ini'): """ Load configuration from config file (default: config.ini) """ + logger = logging.getLogger(__name__) if not os.path.exists(config_file): - print(f"Error: Config file '{config_file}' not found") + logger.error(f"Config file '{config_file}' not found") sys.exit(1) config = configparser.ConfigParser() try: config.read(config_file) + logger.info(f"Configuration loaded from {config_file}") return config except Exception as e: - print(f"Error reading config file: {e}") + logger.error(f"Error reading config file: {e}") sys.exit(1) def get_secret(secret_name, region_name=None, config_profile=None): """ Retrieve a secret from AWS Secrets Manager """ + logger = logging.getLogger(__name__) try: + logger.debug(f"Retrieving secret: {secret_name}") # Create a Boto3 session with the specified profile if provided session_kwargs = {} if config_profile: @@ -47,18 +85,20 @@ def get_secret(secret_name, region_name=None, config_profile=None): # Parse the secret JSON string if 'SecretString' in response: secret = json.loads(response['SecretString']) + logger.info(f"Successfully retrieved secret: {secret_name}") return secret else: - print("Error: Secret value is not a string") + logger.error("Secret value is not a string") sys.exit(1) except Exception as e: - print(f"Error retrieving secret from AWS Secrets Manager: {e}") + logger.error(f"Error retrieving secret from AWS Secrets Manager: {e}") sys.exit(1) def connect_to_redshift(config): """ Establish connection to Redshift database using config and AWS Secrets Manager """ + logger = logging.getLogger(__name__) try: redshift_config = config['redshift'] @@ -72,7 +112,7 @@ def connect_to_redshift(config): # Get credentials from AWS Secrets Manager secret_name = redshift_config.get('secret_name') if not secret_name: - print("Error: 'secret_name' not found in redshift configuration") + logger.error("'secret_name' not found in redshift configuration") sys.exit(1) secret = get_secret(secret_name, region_name, config_profile) @@ -83,15 +123,16 @@ def connect_to_redshift(config): port=int(redshift_config.get('port', 5439)), dbname=redshift_config['dbname'], user=secret['username'], - password=secret['password'] + password=secret['password'], + application_name=f'LakeFormationMigrationUtility-v{__version__}' ) - print(f"Connected to Redshift database: {redshift_config['dbname']}") + logger.info(f"Connected to Redshift database: {redshift_config['dbname']}") return conn except KeyError as e: - print(f"Missing required configuration parameter: {e}") + logger.error(f"Missing required configuration parameter: {e}") sys.exit(1) except Exception as e: - print(f"Error connecting to Redshift: {e}") + logger.error(f"Error connecting to Redshift: {e}") sys.exit(1) def get_users_with_usage_permission(conn, p_datashare_database_name=None, identity_provider_namespace='AWSIDC'): @@ -550,17 +591,18 @@ def generate_lakeformation_commands(tables, user_map, aws_account_id, producer_c If object_level_permissions is True, generate table-level permissions based on SHOW GRANTS Otherwise, generate schema-level permissions using TableWildcard syntax """ + logger = logging.getLogger(__name__) commands = [] timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") - # Get the project root directory (parent of src) - project_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + # Create output directory in the same location as logs + if output_dir: + output_base = output_dir + else: + output_base = '.' - # Create a subdirectory for this run under the project's output directory - output_base = output_dir if output_dir else os.path.join(project_root, "output") run_dir = os.path.join(output_base, f"run_{timestamp}") - if not os.path.exists(run_dir): - os.makedirs(run_dir) + os.makedirs(run_dir, exist_ok=True) script_filepath = os.path.join(run_dir, f"lakeformation_permissions_{timestamp}.sh") # Create debug file for get-user-id commands if debug mode is enabled @@ -736,7 +778,7 @@ def generate_lakeformation_commands(tables, user_map, aws_account_id, producer_c commands.append(command) commands_count += 1 - print(f"Generated {commands_count} table-level permission commands") + logger.info(f"Generated {commands_count} table-level permission commands") else: # Get unique database-schema combinations db_schema_map = {} @@ -772,7 +814,7 @@ def generate_lakeformation_commands(tables, user_map, aws_account_id, producer_c commands.append(command) commands_count += 1 - print(f"Generated {commands_count} schema-level SELECT and DESCRIBE permission commands") + logger.info(f"Generated {commands_count} schema-level SELECT and DESCRIBE permission commands") # Create rollback script rollback_filepath = os.path.join(run_dir, f"rollback_lakeformation_{timestamp}.sh") @@ -860,8 +902,8 @@ def generate_lakeformation_commands(tables, user_map, aws_account_id, producer_c rollback_file.write(revoke_cmd) - print(f"Generated {len(commands)} total LakeFormation commands in file: {script_filepath}") - print(f"Generated rollback script: {rollback_filepath}") + logger.info(f"Generated {len(commands)} total LakeFormation commands in file: {script_filepath}") + logger.info(f"Generated rollback script: {rollback_filepath}") return commands def get_identity_provider_namespace(conn): @@ -894,6 +936,9 @@ def main(): args = parser.parse_args() + # Setup logging + logger = setup_logging(args.debug, args.output_dir) + # Load configuration config = load_config(args.config) @@ -910,56 +955,56 @@ def main(): if 'permissions_type' in config['parameters']: permissions_type = config['parameters']['permissions_type'].lower() - print(f"Permissions type: {permissions_type}") + logger.info(f"Permissions type: {permissions_type}") # Check if datashare object-level permissions are enabled object_level_permissions = False if 'parameters' in config and 'datashare_object_level_permissions' in config['parameters']: object_level_permissions = config['parameters']['datashare_object_level_permissions'].lower() == 'true' - print(f"Datashare object-level permissions: {object_level_permissions}") + logger.info(f"Datashare object-level permissions: {object_level_permissions}") # Get identity provider namespace from SVV_IDENTITY_PROVIDERS identity_provider_namespace = get_identity_provider_namespace(conn) - print(f"Using identity provider namespace: {identity_provider_namespace}") + logger.info(f"Using identity provider namespace: {identity_provider_namespace}") # Process based on permissions_type if permissions_type == 'local': # Get local database name from config local_db_name = config['redshift']['dbname'] - print(f"Processing local database permissions for: {local_db_name}") + logger.info(f"Processing local database permissions for: {local_db_name}") user_map, tables, table_grants = get_local_database_permissions(conn, local_db_name, identity_provider_namespace) user_count = sum(len(users) for users in user_map.values()) - print(f"Found {user_count} IDC users with permissions on local database {local_db_name}") - print(f"Retrieved {len(tables)} tables from local database") + logger.info(f"Found {user_count} IDC users with permissions on local database {local_db_name}") + logger.info(f"Retrieved {len(tables)} tables from local database") if table_grants: grant_count = sum(len(grants) for grants in table_grants.values()) - print(f"Retrieved {grant_count} table-level grants for IDC users/roles") + logger.info(f"Retrieved {grant_count} table-level grants for IDC users/roles") else: # Original datashare logic if p_datashare_database_name: - print(f"Filtering permissions for datashare database: {p_datashare_database_name}") + logger.info(f"Filtering permissions for datashare database: {p_datashare_database_name}") # Get users with USAGE permission on the database (required to access tables) user_map = get_users_with_usage_permission(conn, p_datashare_database_name, identity_provider_namespace) db_count = len(user_map) user_count = sum(len(users) for users in user_map.values()) - print(f"Found {user_count} IDC users (with {identity_provider_namespace}: prefix) with USAGE permission across {db_count} databases") + logger.info(f"Found {user_count} IDC users (with {identity_provider_namespace}: prefix) with USAGE permission across {db_count} databases") # Get all tables in the datashare database(s) tables = get_datashare_tables(conn, p_datashare_database_name) - print(f"Retrieved {len(tables)} tables from datashare database(s)") + logger.info(f"Retrieved {len(tables)} tables from datashare database(s)") # Get table-level grants if datashare object_level_permissions is enabled table_grants = None if object_level_permissions and tables: - print("Getting table-level grants using SHOW GRANTS...") + logger.info("Getting table-level grants using SHOW GRANTS...") table_grants = get_table_grants(conn, tables, identity_provider_namespace) grant_count = sum(len(grants) for grants in table_grants.values()) - print(f"Retrieved {grant_count} table-level grants for IDC users/roles (with {identity_provider_namespace}: prefix)") + logger.info(f"Retrieved {grant_count} table-level grants for IDC users/roles (with {identity_provider_namespace}: prefix)") if args.debug: if user_map: @@ -990,33 +1035,33 @@ def main(): # Generate LakeFormation commands if tables and (user_map or (object_level_permissions and table_grants)): if not user_map and (not table_grants or not any(table_grants.values())): - print(f"\nNo IDC users or roles (with {identity_provider_namespace}: prefix) found with permissions. No Lake Formation commands will be generated.") + logger.warning(f"No IDC users or roles (with {identity_provider_namespace}: prefix) found with permissions. No Lake Formation commands will be generated.") return aws_account_id = config.get('aws', 'account_id', fallback=None) if not aws_account_id: - print("Error: AWS account ID not found in config") + logger.error("AWS account ID not found in config") sys.exit(1) # Get producer catalog from config producer_catalog = config.get('aws', 'producer_catalog', fallback=None) if not producer_catalog: - print("Error: producer_catalog not found in config") + logger.error("producer_catalog not found in config") sys.exit(1) # Get AWS CLI profile from config (optional) config_profile = config.get('aws', 'config_profile', fallback=None) if config_profile: - print(f"Using AWS CLI profile: {config_profile}") + logger.info(f"Using AWS CLI profile: {config_profile}") # Get identity store ID from config (required for IDC) identity_store_id = config.get('aws', 'identity_store_id', fallback=None) if not identity_store_id: - print("Warning: identity_store_id not found in config") + logger.warning("identity_store_id not found in config") # Get region from config region_name = config.get('aws', 'region', fallback=None) if region_name: - print(f"Using AWS region: {region_name}") + logger.info(f"Using AWS region: {region_name}") # Generate LakeFormation commands, passing the open connection for role user lookup generate_lakeformation_commands( @@ -1028,7 +1073,7 @@ def main(): # Now close the connection conn.close() else: - print("No datashare tables or users found to convert.") + logger.warning("No datashare tables or users found to convert.") if __name__ == "__main__": main() \ No newline at end of file diff --git a/src/LakeFormationMigrationUtility/tests/integration_test/test_int_config.ini b/src/LakeFormationMigrationUtility/tests/integration_test/test_int_config.ini index aa4403d8..fcd15557 100644 --- a/src/LakeFormationMigrationUtility/tests/integration_test/test_int_config.ini +++ b/src/LakeFormationMigrationUtility/tests/integration_test/test_int_config.ini @@ -1,26 +1,26 @@ -# Example values provided +# Commented example values provided. Replace with values for your system. [redshift] -host = your-redshift-cluster.region.redshift.amazonaws.com -port = 5439 -dbname = your-database-name +host = #your-redshift-cluster.region.redshift.amazonaws.com +port = #5439 +dbname = #your-database-name # AWS Secrets Manager secret containing Redshift credentials -secret_name = your-secret-name +secret_name = #your-secret-name [aws] -account_id = 123456789012 -region = us-east-1 -producer_catalog = your-producer-catalog-name +account_id = #123456789012 +region = #us-east-1 +producer_catalog = #your-producer-catalog-name # AWS CLI profile to use (optional) -config_profile = your-aws-cli-profile +config_profile = #your-aws-cli-profile # Identity Store ID for IDC user lookups -identity_store_id = d-1234567890 -iam_idc_instance_arn = arn:aws:sso:::instance/ssoins-123456a8efd4d123 +identity_store_id = #d-1234567890 +iam_idc_instance_arn = #arn:aws:sso:::instance/ssoins-123456a8efd4d123 [parameters] # Name of database on the consumer cluster created from the datashare -datashare_database_name = your_datashare_db +datashare_database_name = #your_datashare_db # Set to true if the datashare database was created with the 'WITH PERMISSIONS' clause -datashare_object_level_permissions = true -object_level_permissions = true +datashare_object_level_permissions = #true +object_level_permissions = #true # Whether to run the rollback script after the test (true) or leave permissions in place (false) -test_rollback = false \ No newline at end of file +test_rollback = #false \ No newline at end of file diff --git a/src/LakeFormationMigrationUtility/tests/performance_test/test_perf_config.ini b/src/LakeFormationMigrationUtility/tests/performance_test/test_perf_config.ini index 66b5f5b5..15c422a8 100644 --- a/src/LakeFormationMigrationUtility/tests/performance_test/test_perf_config.ini +++ b/src/LakeFormationMigrationUtility/tests/performance_test/test_perf_config.ini @@ -1,31 +1,31 @@ -# Example values provided +# Commented example values provided. Replace with values for your system. [redshift] -host = your-redshift-cluster.region.redshift.amazonaws.com -port = 5439 -dbname = your-database-name +host = #your-redshift-cluster.region.redshift.amazonaws.com +port = #5439 +dbname = #your-database-name # AWS Secrets Manager secret containing Redshift credentials -secret_name = your-secret-name +secret_name = #your-secret-name [aws] -account_id = 123456789012 -region = us-east-1 -producer_catalog = your-producer-catalog-name +account_id = #123456789012 +region = #us-east-1 +producer_catalog = #your-producer-catalog-name # AWS CLI profile to use (optional) -config_profile = your-aws-cli-profile +config_profile = #your-aws-cli-profile # Identity Store ID for IDC user lookups -identity_store_id = d-1234567890 -iam_idc_instance_arn = arn:aws:sso:::instance/ssoins-123456a8efd4d123 -iam_idc_namespace = AWSIDC +identity_store_id = #d-1234567890 +iam_idc_instance_arn = #arn:aws:sso:::instance/ssoins-123456a8efd4d123 +iam_idc_namespace = #AWSIDC [parameters] # Permission source: 'datashare' for datashare permissions, 'local' for local database permissions -permissions_type = local +permissions_type = #local # Name of database on the consumer cluster created from the datashare -datashare_database_name = your_datashare_db +datashare_database_name = #your_datashare_db # Set to true if the datashare database was created with the 'WITH PERMISSIONS' clause -datashare_object_level_permissions = true +datashare_object_level_permissions = #true # Performance test parameters -list_types = etl, adhoc, analyst, admin -number_users_per_type = 1 -number_of_schemas = 5 -number_of_tables_per_schema = 2 +list_types = #etl, adhoc, analyst, admin +number_users_per_type = #1 +number_of_schemas = #5 +number_of_tables_per_schema = #2 From 4884f431647fff4c8a0ff18b98ba97d880ea0c35 Mon Sep 17 00:00:00 2001 From: Adam Gatt Date: Tue, 2 Sep 2025 15:51:49 +0100 Subject: [PATCH 48/49] Added link to readme.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 233fab5d..a611b85d 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ Some of the existing Redshift customers rely on local users, roles, groups, and # Redshift to Lake Formation migration utility -This utility streamlines the process of migrating data access permissions from Amazon Redshift to AWS Lake Formation through several key functions. It automatically extracts user permissions from both Redshift datashare and local databases by analyzing table-level grants. The utility then generates the necessary AWS CLI commands to establish equivalent permissions in Lake Formation supporting AWS Identity Center (IDC) authentication. Additionally, it creates rollback scripts that enable easy cleanup of permissions if needed. +This [utility](src/LakeFormationMigrationUtility) streamlines the process of migrating data access permissions from Amazon Redshift to AWS Lake Formation through several key functions. It automatically extracts user permissions from both Redshift datashare and local databases by analyzing table-level grants. The utility then generates the necessary AWS CLI commands to establish equivalent permissions in Lake Formation supporting AWS Identity Center (IDC) authentication. Additionally, it creates rollback scripts that enable easy cleanup of permissions if needed. # Investigations From 4dc4654439aab8a4d9f949fb4893c1464955c7a3 Mon Sep 17 00:00:00 2001 From: Adam Gatt Date: Tue, 2 Sep 2025 15:57:30 +0100 Subject: [PATCH 49/49] Modified readme.md text --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a611b85d..d55bf0ac 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ Some of the existing Redshift customers rely on local users, roles, groups, and # Redshift to Lake Formation migration utility -This [utility](src/LakeFormationMigrationUtility) streamlines the process of migrating data access permissions from Amazon Redshift to AWS Lake Formation through several key functions. It automatically extracts user permissions from both Redshift datashare and local databases by analyzing table-level grants. The utility then generates the necessary AWS CLI commands to establish equivalent permissions in Lake Formation supporting AWS Identity Center (IDC) authentication. Additionally, it creates rollback scripts that enable easy cleanup of permissions if needed. +This [utility](src/LakeFormationMigrationUtility) streamlines the process of migrating data access permissions from Amazon Redshift to AWS Lake Formation for seamless migration to a SageMaker Lakehouse architecture. It automatically extracts user permissions from both Redshift datashare and local databases by analyzing table-level grants. The utility then generates the necessary AWS CLI commands to establish equivalent permissions in Lake Formation supporting AWS Identity Center (IDC) authentication. Additionally, it creates rollback scripts that enable easy cleanup of permissions if needed. # Investigations